fix(dashboard, js-sdk, types, medusa): separate between delete response with and without parent (#8852)
- Separate the previous `DeleteResponse` to `DeleteResponse` and `DeleteResponseWithParent`, as not every API route's delete response returns a parent. This ensures more accurate types shown in OAS / documentation. - Use `DeleteResponse` or `DeleteResponseWithParent` in response API routes based on what they return - Remove direct usage of `DeleteResponse` in API route, and instead create a type in the `type` package specific for the route / domain. - Use the new types in the `js-sdk` and `dashboard`.
This commit is contained in:
@@ -73,7 +73,7 @@ export class ApiKey {
|
||||
}
|
||||
|
||||
async delete(id: string, headers?: ClientHeaders) {
|
||||
return await this.client.fetch<HttpTypes.DeleteResponse<"api_key">>(
|
||||
return await this.client.fetch<HttpTypes.AdminApiKeyDeleteResponse>(
|
||||
`/admin/api-keys/${id}`,
|
||||
{
|
||||
method: "DELETE",
|
||||
|
||||
@@ -71,7 +71,7 @@ export class CustomerGroup {
|
||||
}
|
||||
|
||||
async delete(id: string, headers?: ClientHeaders) {
|
||||
return await this.client.fetch<HttpTypes.DeleteResponse<"customer_group">>(
|
||||
return await this.client.fetch<HttpTypes.AdminCustomerGroupDeleteResponse>(
|
||||
`/admin/customer-groups/${id}`,
|
||||
{
|
||||
method: "DELETE",
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import {
|
||||
DeleteResponse,
|
||||
FindParams,
|
||||
HttpTypes,
|
||||
PaginatedResponse,
|
||||
@@ -69,7 +68,7 @@ export class Customer {
|
||||
}
|
||||
|
||||
async delete(id: string, headers?: ClientHeaders) {
|
||||
return this.client.fetch<DeleteResponse<"customer">>(
|
||||
return this.client.fetch<HttpTypes.AdminCustomerDeleteResponse>(
|
||||
`/admin/customers/${id}`,
|
||||
{
|
||||
method: "DELETE",
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import {
|
||||
DeleteResponse,
|
||||
FindParams,
|
||||
HttpTypes,
|
||||
PaginatedResponse,
|
||||
@@ -76,7 +75,7 @@ export class Invite {
|
||||
}
|
||||
|
||||
async delete(id: string, headers?: ClientHeaders) {
|
||||
return await this.client.fetch<DeleteResponse<"invite">>(
|
||||
return await this.client.fetch<HttpTypes.AdminInviteDeleteResponse>(
|
||||
`/admin/invites/${id}`,
|
||||
{
|
||||
method: "DELETE",
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import {
|
||||
DeleteResponse,
|
||||
FindParams,
|
||||
HttpTypes,
|
||||
PaginatedResponse,
|
||||
@@ -70,7 +69,7 @@ export class Region {
|
||||
}
|
||||
|
||||
async delete(id: string, headers?: ClientHeaders) {
|
||||
return await this.client.fetch<DeleteResponse<"region">>(
|
||||
return await this.client.fetch<HttpTypes.AdminRegionDeleteResponse>(
|
||||
`/admin/regions/${id}`,
|
||||
{
|
||||
method: "DELETE",
|
||||
|
||||
@@ -71,7 +71,7 @@ class Reservation {
|
||||
}
|
||||
|
||||
async delete(id: string, headers?: ClientHeaders) {
|
||||
return await this.client.fetch<HttpTypes.DeleteResponse<"reservation">>(
|
||||
return await this.client.fetch<HttpTypes.AdminReservationDeleteResponse>(
|
||||
`/admin/reservations/${id}`,
|
||||
{
|
||||
method: "DELETE",
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { DeleteResponse, HttpTypes, SelectParams } from "@medusajs/types"
|
||||
import { HttpTypes, SelectParams } from "@medusajs/types"
|
||||
import { Client } from "../client"
|
||||
import { ClientHeaders } from "../types"
|
||||
|
||||
@@ -59,7 +59,7 @@ export class Upload {
|
||||
}
|
||||
|
||||
async delete(id: string, headers?: ClientHeaders) {
|
||||
return this.client.fetch<DeleteResponse<"file">>(`/admin/uploads/${id}`, {
|
||||
return this.client.fetch<HttpTypes.AdminFileDeleteResponse>(`/admin/uploads/${id}`, {
|
||||
method: "DELETE",
|
||||
headers,
|
||||
})
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import {
|
||||
DeleteResponse,
|
||||
FindParams,
|
||||
HttpTypes,
|
||||
PaginatedResponse,
|
||||
@@ -206,7 +205,7 @@ export class Store {
|
||||
headers?: ClientHeaders
|
||||
) => {
|
||||
return this.client.fetch<
|
||||
DeleteResponse<"line-item", HttpTypes.StoreCart>
|
||||
HttpTypes.StoreLineItemDeleteResponse
|
||||
>(`/store/carts/${cartId}/line-items/${lineItemId}`, {
|
||||
method: "DELETE",
|
||||
headers,
|
||||
@@ -434,7 +433,7 @@ export class Store {
|
||||
},
|
||||
deleteAddress: async (addressId: string, headers?: ClientHeaders) => {
|
||||
return this.client.fetch<
|
||||
DeleteResponse<"address", HttpTypes.StoreCustomer>
|
||||
HttpTypes.StoreCustomerAddressDeleteResponse
|
||||
>(`/store/customers/me/addresses/${addressId}`, {
|
||||
method: "DELETE",
|
||||
headers,
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
export * from "./api-key"
|
||||
export * from "./responses"
|
||||
export * from "./payloads"
|
||||
export * from "./queries"
|
||||
|
||||
+3
-1
@@ -1,5 +1,5 @@
|
||||
import { ApiKeyType } from "../../../api-key"
|
||||
import { PaginatedResponse } from "../../common"
|
||||
import { DeleteResponse, PaginatedResponse } from "../../common"
|
||||
|
||||
interface AdminApiKey {
|
||||
id: string
|
||||
@@ -21,3 +21,5 @@ export interface AdminApiKeyResponse {
|
||||
export type AdminApiKeyListResponse = PaginatedResponse<{
|
||||
api_keys: AdminApiKey[]
|
||||
}>
|
||||
|
||||
export type AdminApiKeyDeleteResponse = DeleteResponse<"api_key">
|
||||
@@ -1,5 +1,5 @@
|
||||
import { CampaignBudgetTypeValues } from "../../../promotion"
|
||||
import { PaginatedResponse } from "../../common"
|
||||
import { DeleteResponse, PaginatedResponse } from "../../common"
|
||||
|
||||
export interface AdminCampaign {
|
||||
id: string
|
||||
@@ -25,3 +25,5 @@ export type AdminCampaignListResponse = PaginatedResponse<{
|
||||
export interface AdminCampaignResponse {
|
||||
campaign: AdminCampaign
|
||||
}
|
||||
|
||||
export type AdminCampaignDeleteResponse = DeleteResponse<"campaign">
|
||||
@@ -1,3 +1,4 @@
|
||||
import { DeleteResponseWithParent } from "../../common"
|
||||
import { StoreOrder } from "../../order"
|
||||
import { StoreCart } from "./entities"
|
||||
|
||||
@@ -16,4 +17,6 @@ export type StoreCompleteCartResponse = {
|
||||
} | {
|
||||
type: "order"
|
||||
order: StoreOrder
|
||||
}
|
||||
}
|
||||
|
||||
export type StoreLineItemDeleteResponse = DeleteResponseWithParent<"line-item", StoreCart>
|
||||
@@ -1,4 +1,4 @@
|
||||
export type DeleteResponse<TObject extends string, TParent = {}> = {
|
||||
export type DeleteResponse<TObject extends string> = {
|
||||
/**
|
||||
* The ID of the item that was deleted.
|
||||
*/
|
||||
@@ -13,13 +13,17 @@ export type DeleteResponse<TObject extends string, TParent = {}> = {
|
||||
* Whether the item was deleted successfully.
|
||||
*/
|
||||
deleted: boolean
|
||||
|
||||
/**
|
||||
* The parent resource of the item that was deleted, if applicable.
|
||||
*/
|
||||
parent?: TParent
|
||||
}
|
||||
|
||||
export type DeleteResponseWithParent<TObject extends string, TParent = {}> =
|
||||
DeleteResponse<TObject> &
|
||||
{
|
||||
/**
|
||||
* The parent resource of the item that was deleted, if applicable.
|
||||
*/
|
||||
parent?: TParent
|
||||
}
|
||||
|
||||
export type PaginatedResponse<T> = {
|
||||
limit: number
|
||||
offset: number
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { PaginatedResponse } from "../../common"
|
||||
import { DeleteResponse, DeleteResponseWithParent, PaginatedResponse } from "../../common"
|
||||
import { AdminCustomer, AdminCustomerAddress } from "./entities"
|
||||
|
||||
export interface AdminCustomerResponse {
|
||||
@@ -16,3 +16,12 @@ export interface AdminCustomerAddressResponse {
|
||||
export type AdminCustomerAddressListResponse = PaginatedResponse<{
|
||||
addresses: AdminCustomerAddress[]
|
||||
}>
|
||||
|
||||
export type AdminCustomerDeleteResponse = DeleteResponse<"customer">
|
||||
|
||||
export type AdminCustomerGroupDeleteResponse = DeleteResponse<"customer_group">
|
||||
|
||||
export type AdminCustomerAddressDeleteResponse = DeleteResponseWithParent<
|
||||
"customer_address",
|
||||
AdminCustomer
|
||||
>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { PaginatedResponse } from "../../common";
|
||||
import { DeleteResponseWithParent, PaginatedResponse } from "../../common";
|
||||
import { StoreCustomer, StoreCustomerAddress } from "./entities";
|
||||
|
||||
export interface StoreCustomerResponse {
|
||||
@@ -11,3 +11,5 @@ export interface StoreCustomerAddressResponse {
|
||||
|
||||
export interface StoreCustomerAddressListResponse
|
||||
extends PaginatedResponse<{ addresses: StoreCustomerAddress[] }> {}
|
||||
|
||||
export type StoreCustomerAddressDeleteResponse = DeleteResponseWithParent<"address", StoreCustomer>
|
||||
@@ -1,3 +1,4 @@
|
||||
import { DeleteResponse } from "../../common";
|
||||
import { AdminFile } from "./entities";
|
||||
|
||||
export interface AdminFileResponse {
|
||||
@@ -6,4 +7,6 @@ export interface AdminFileResponse {
|
||||
|
||||
export interface AdminFileListResponse {
|
||||
files: AdminFile[]
|
||||
}
|
||||
}
|
||||
|
||||
export type AdminFileDeleteResponse = DeleteResponse<"file">
|
||||
@@ -1,4 +1,4 @@
|
||||
import { DeleteResponse } from "../../common"
|
||||
import { DeleteResponse, DeleteResponseWithParent } from "../../common"
|
||||
import { AdminFulfillmentSet, AdminServiceZone } from "./entities"
|
||||
|
||||
export interface AdminServiceZoneResponse {
|
||||
@@ -6,7 +6,7 @@ export interface AdminServiceZoneResponse {
|
||||
}
|
||||
|
||||
export interface AdminServiceZoneDeleteResponse
|
||||
extends DeleteResponse<"service_zone", AdminFulfillmentSet> {}
|
||||
extends DeleteResponseWithParent<"service_zone", AdminFulfillmentSet> {}
|
||||
|
||||
export interface AdminFulfillmentSetResponse {
|
||||
fulfillment_set: AdminFulfillmentSet
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { DeleteResponse, PaginatedResponse } from "../../common"
|
||||
import { DeleteResponse, DeleteResponseWithParent, PaginatedResponse } from "../../common"
|
||||
import { AdminInventoryItem } from "./entities"
|
||||
|
||||
export interface AdminInventoryItemResponse {
|
||||
@@ -10,3 +10,8 @@ export type AdminInventoryItemListResponse = PaginatedResponse<{
|
||||
}>
|
||||
|
||||
export type AdminInventoryItemDeleteResponse = DeleteResponse<"inventory_item">
|
||||
|
||||
export type AdminInventoryLevelDeleteResponse = DeleteResponseWithParent<
|
||||
"inventory-level",
|
||||
AdminInventoryItem
|
||||
>
|
||||
@@ -1,4 +1,4 @@
|
||||
import { PaginatedResponse } from "../../common";
|
||||
import { DeleteResponse, PaginatedResponse } from "../../common";
|
||||
import { AdminUser } from "../../user";
|
||||
import { AdminInvite } from "./entities";
|
||||
|
||||
@@ -14,4 +14,6 @@ export type AdminAcceptInviteResponse = {
|
||||
user: AdminUser
|
||||
} | {
|
||||
message: string
|
||||
}
|
||||
}
|
||||
|
||||
export type AdminInviteDeleteResponse = DeleteResponse<"invite">
|
||||
@@ -1,4 +1,5 @@
|
||||
import { OrderChangeDTO, OrderPreviewDTO } from "../../../order"
|
||||
import { DeleteResponse } from "../../common"
|
||||
|
||||
export interface AdminOrderEditPreviewResponse {
|
||||
order_preview: OrderPreviewDTO
|
||||
@@ -8,8 +9,4 @@ export interface AdminOrderEditResponse {
|
||||
order_change: OrderChangeDTO
|
||||
}
|
||||
|
||||
export interface AdminOrderEditDeleteResponse {
|
||||
id: string
|
||||
object: "order-edit"
|
||||
deleted: true
|
||||
}
|
||||
export type AdminOrderEditDeleteResponse = DeleteResponse<"order-edit">
|
||||
|
||||
@@ -45,3 +45,5 @@ export type RefundReasonsResponse = PaginatedResponse<{
|
||||
export type AdminPaymentProviderListResponse = PaginatedResponse<{
|
||||
payment_providers: AdminPaymentProvider[]
|
||||
}>
|
||||
|
||||
export type AdminRefundReasonDeleteResponse = DeleteResponse<"refund_reason">
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { BatchMethodResponse } from "../../../common"
|
||||
import { DeleteResponse, PaginatedResponse } from "../../common"
|
||||
import { DeleteResponse, DeleteResponseWithParent, PaginatedResponse } from "../../common"
|
||||
import {
|
||||
AdminProduct,
|
||||
AdminProductOption,
|
||||
@@ -30,7 +30,7 @@ export type AdminProductVariantListResponse = PaginatedResponse<{
|
||||
}>
|
||||
|
||||
export interface AdminProductVariantDeleteResponse
|
||||
extends DeleteResponse<"variant", AdminProduct> {}
|
||||
extends DeleteResponseWithParent<"variant", AdminProduct> {}
|
||||
|
||||
export interface AdminExportProductResponse {
|
||||
transaction_id: string
|
||||
@@ -59,7 +59,7 @@ export type AdminProductOptionListResponse = PaginatedResponse<{
|
||||
}>
|
||||
|
||||
export interface AdminProductOptionDeleteResponse
|
||||
extends DeleteResponse<"product_option", AdminProduct> {}
|
||||
extends DeleteResponseWithParent<"product_option", AdminProduct> {}
|
||||
|
||||
export type AdminProductVariantInventoryResponse = AdminProductVariantInventoryLink | AdminProductVariantInventoryLink[]
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { BatchMethodResponse } from "../../../common";
|
||||
import { PaginatedResponse } from "../../common";
|
||||
import { DeleteResponse, PaginatedResponse } from "../../common";
|
||||
import {
|
||||
AdminPromotion,
|
||||
AdminPromotionRule,
|
||||
@@ -54,4 +54,6 @@ export type AdminRuleValueOptionsListResponse = {
|
||||
values: AdminRuleValueOption[]
|
||||
}
|
||||
|
||||
export type AdminPromotionRuleBatchResponse = BatchMethodResponse<AdminPromotionRule>
|
||||
export type AdminPromotionRuleBatchResponse = BatchMethodResponse<AdminPromotionRule>
|
||||
|
||||
export type AdminPromotionDeleteResponse = DeleteResponse<"promotion">
|
||||
@@ -1,4 +1,4 @@
|
||||
import { PaginatedResponse } from "../../common";
|
||||
import { DeleteResponse, PaginatedResponse } from "../../common";
|
||||
import { AdminRegion } from "./entities";
|
||||
|
||||
export interface AdminRegionResponse {
|
||||
@@ -7,4 +7,6 @@ export interface AdminRegionResponse {
|
||||
|
||||
export type AdminRegionListResponse = PaginatedResponse<{
|
||||
regions: AdminRegion[]
|
||||
}>
|
||||
}>
|
||||
|
||||
export type AdminRegionDeleteResponse = DeleteResponse<"region">
|
||||
@@ -1,4 +1,4 @@
|
||||
import { PaginatedResponse } from "../../common"
|
||||
import { DeleteResponse, PaginatedResponse } from "../../common"
|
||||
import { AdminReservation } from "./entities"
|
||||
|
||||
export interface AdminReservationResponse {
|
||||
@@ -8,3 +8,5 @@ export interface AdminReservationResponse {
|
||||
export type AdminReservationListResponse = PaginatedResponse<{
|
||||
reservations: AdminReservation[]
|
||||
}>
|
||||
|
||||
export type AdminReservationDeleteResponse = DeleteResponse<"reservation">
|
||||
@@ -1,5 +1,5 @@
|
||||
import { OrderDTO } from "../../../order"
|
||||
import { PaginatedResponse } from "../../common"
|
||||
import { DeleteResponse, PaginatedResponse } from "../../common"
|
||||
import { AdminOrderPreview } from "../../order"
|
||||
import { AdminReturn } from "./entities"
|
||||
|
||||
@@ -19,4 +19,6 @@ export interface AdminOrderReturnResponse {
|
||||
export interface AdminReturnPreviewResponse {
|
||||
order_preview: AdminOrderPreview
|
||||
return: AdminReturn
|
||||
}
|
||||
}
|
||||
|
||||
export type AdminReturnDeleteResponse = DeleteResponse<"return">
|
||||
@@ -1,4 +1,4 @@
|
||||
import { DeleteResponse, PaginatedResponse } from "../../common"
|
||||
import { DeleteResponse, DeleteResponseWithParent, PaginatedResponse } from "../../common"
|
||||
import { AdminTaxRate } from "./entities"
|
||||
|
||||
export interface AdminTaxRateResponse {
|
||||
@@ -11,3 +11,5 @@ export type AdminTaxRateListResponse = PaginatedResponse<{
|
||||
|
||||
export interface AdminTaxRateDeleteResponse
|
||||
extends DeleteResponse<"tax_rate"> {}
|
||||
|
||||
export type AdminTaxRateRuleDeleteResponse = DeleteResponseWithParent<"tax_rate_rule", AdminTaxRate>
|
||||
Reference in New Issue
Block a user