Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Add the post-sale resources to the seller SDK

Damian Legawiecb739f404b1d2
diff --git a/packages/seller-sdk/src/seller-client.ts b/packages/seller-sdk/src/seller-client.ts
index 53849b693c..eea2131d06 100644
--- a/packages/seller-sdk/src/seller-client.ts
+++ b/packages/seller-sdk/src/seller-client.ts
@@ -2,10 +2,12 @@ import type { ListParams, PaginatedResponse, RequestFn, RequestOptions } from '@
import { transformListParams } from '@spree/sdk-core'
import type {
AuthTokens,
+ Claim,
Delivery,
DeliveryMethod,
DeliveryProfile,
DeliveryZone,
+ Exchange,
Export,
Fulfillment,
Import,
@@ -16,8 +18,10 @@ import type {
Product,
ProductType,
Profile,
+ Reason,
RequirementStatus,
RequirementSubmission,
+ Return,
SellerSummary,
ShippingLabel,
StockLocation,
@@ -562,6 +566,228 @@ export class SellerClient {
),
},
},
+
+ /**
+ * Goods coming back. The seller is merchant of record for their own
+ * child order, so approving, receiving and refunding are all theirs.
+ */
+ returns: {
+ list: (orderId: string, options?: RequestOptions): Promise<{ data: Return[] }> =>
+ this.request<{ data: Return[] }>('GET', `/orders/${orderId}/returns`, options),
+
+ get: (orderId: string, id: string, options?: RequestOptions): Promise<Return> =>
+ this.request<Return>('GET', `/orders/${orderId}/returns/${id}`, options),
+
+ create: (
+ orderId: string,
+ params: {
+ items: Array<{ fulfillment_item_id: string; quantity: number }>
+ memo?: string
+ reason_id?: string
+ stock_location_id?: string
+ },
+ options?: RequestOptions,
+ ): Promise<Return> =>
+ this.request<Return>('POST', `/orders/${orderId}/returns`, { ...options, body: params }),
+
+ approve: (orderId: string, id: string, options?: RequestOptions): Promise<Return> =>
+ this.request<Return>('PATCH', `/orders/${orderId}/returns/${id}/approve`, options),
+
+ /** `items` carries what actually arrived; omit it to receive it all. */
+ receive: (
+ orderId: string,
+ id: string,
+ params?: {
+ items?: Array<{ return_line_item_id: string; quantity: number; resellable?: boolean }>
+ },
+ options?: RequestOptions,
+ ): Promise<Return> =>
+ this.request<Return>('PATCH', `/orders/${orderId}/returns/${id}/receive`, {
+ ...options,
+ body: params,
+ }),
+
+ /** Bounded by the return, and by this order's share of a split payment. */
+ refund: (
+ orderId: string,
+ id: string,
+ params?: { amount?: string; refund_method?: 'original_payment' | 'store_credit' },
+ options?: RequestOptions,
+ ): Promise<Return> =>
+ this.request<Return>('PATCH', `/orders/${orderId}/returns/${id}/refund`, {
+ ...options,
+ body: params,
+ }),
+
+ cancel: (
+ orderId: string,
+ id: string,
+ params?: { reason?: string },
+ options?: RequestOptions,
+ ): Promise<Return> =>
+ this.request<Return>('PATCH', `/orders/${orderId}/returns/${id}/cancel`, {
+ ...options,
+ body: params,
+ }),
+ },
+
+ /** Goods swapped for different ones. */
+ exchanges: {
+ list: (orderId: string, options?: RequestOptions): Promise<{ data: Exchange[] }> =>
+ this.request<{ data: Exchange[] }>('GET', `/orders/${orderId}/exchanges`, options),
+
+ get: (orderId: string, id: string, options?: RequestOptions): Promise<Exchange> =>
+ this.request<Exchange>('GET', `/orders/${orderId}/exchanges/${id}`, options),
+
+ create: (
+ orderId: string,
+ params: {
+ items: Array<{ fulfillment_item_id: string; new_variant_id: string; quantity: number }>
+ memo?: string
+ reason_id?: string
+ stock_location_id?: string
+ },
+ options?: RequestOptions,
+ ): Promise<Exchange> =>
+ this.request<Exchange>('POST', `/orders/${orderId}/exchanges`, {
+ ...options,
+ body: params,
+ }),
+
+ approve: (orderId: string, id: string, options?: RequestOptions): Promise<Exchange> =>
+ this.request<Exchange>('PATCH', `/orders/${orderId}/exchanges/${id}/approve`, options),
+
+ receive: (
+ orderId: string,
+ id: string,
+ params?: {
+ items?: Array<{ exchange_line_item_id: string; quantity: number; resellable?: boolean }>
+ },
+ options?: RequestOptions,
+ ): Promise<Exchange> =>
+ this.request<Exchange>('PATCH', `/orders/${orderId}/exchanges/${id}/receive`, {
+ ...options,
+ body: params,
+ }),
+
+ /** Sends the replacement, settling any price difference. */
+ fulfill: (
+ orderId: string,
+ id: string,
+ params?: { refund_method?: 'original_payment' | 'store_credit' },
+ options?: RequestOptions,
+ ): Promise<Exchange> =>
+ this.request<Exchange>('PATCH', `/orders/${orderId}/exchanges/${id}/fulfill`, {
+ ...options,
+ body: params,
+ }),
+
+ cancel: (
+ orderId: string,
+ id: string,
+ params?: { reason?: string },
+ options?: RequestOptions,
+ ): Promise<Exchange> =>
+ this.request<Exchange>('PATCH', `/orders/${orderId}/exchanges/${id}/cancel`, {
+ ...options,
+ body: params,
+ }),
+ },
+
+ /**
+ * Something went wrong with a delivery, put right without necessarily
+ * asking for the goods back.
+ */
+ claims: {
+ list: (orderId: string, options?: RequestOptions): Promise<{ data: Claim[] }> =>
+ this.request<{ data: Claim[] }>('GET', `/orders/${orderId}/claims`, options),
+
+ get: (orderId: string, id: string, options?: RequestOptions): Promise<Claim> =>
+ this.request<Claim>('GET', `/orders/${orderId}/claims/${id}`, options),
+
+ create: (
+ orderId: string,
+ params: {
+ items: Array<{
+ line_item_id: string
+ quantity: number
+ description?: string
+ send_replacement?: boolean
+ replacement_variant_id?: string
+ refund_amount?: string
+ }>
+ memo?: string
+ reason_id?: string
+ },
+ options?: RequestOptions,
+ ): Promise<Claim> =>
+ this.request<Claim>('POST', `/orders/${orderId}/claims`, { ...options, body: params }),
+
+ approve: (orderId: string, id: string, options?: RequestOptions): Promise<Claim> =>
+ this.request<Claim>('PATCH', `/orders/${orderId}/claims/${id}/approve`, options),
+
+ /** Money back, a replacement shipment, or both. */
+ resolve: (
+ orderId: string,
+ id: string,
+ params: {
+ resolution: 'refund' | 'replacement' | 'refund_and_replacement'
+ refund_method?: 'original_payment' | 'store_credit'
+ amount?: string
+ replacement_line_item_ids?: string[]
+ },
+ options?: RequestOptions,
+ ): Promise<Claim> =>
+ this.request<Claim>('PATCH', `/orders/${orderId}/claims/${id}/resolve`, {
+ ...options,
+ body: params,
+ }),
+
+ deny: (
+ orderId: string,
+ id: string,
+ params?: { reason?: string },
+ options?: RequestOptions,
+ ): Promise<Claim> =>
+ this.request<Claim>('PATCH', `/orders/${orderId}/claims/${id}/deny`, {
+ ...options,
+ body: params,
+ }),
+
+ cancel: (
+ orderId: string,
+ id: string,
+ params?: { reason?: string },
+ options?: RequestOptions,
+ ): Promise<Claim> =>
+ this.request<Claim>('PATCH', `/orders/${orderId}/claims/${id}/cancel`, {
+ ...options,
+ body: params,
+ }),
+ },
+ }
+
+ /**
+ * The marketplace's own vocabularies, and the carrier registry. Read-only:
+ * a seller picks from these, the operator decides what is in them.
+ */
+ readonly returnReasons = {
+ list: (options?: RequestOptions): Promise<{ data: Reason[] }> =>
+ this.request<{ data: Reason[] }>('GET', '/return_reasons', options),
+ }
+
+ readonly claimReasons = {
+ list: (options?: RequestOptions): Promise<{ data: Reason[] }> =>
+ this.request<{ data: Reason[] }>('GET', '/claim_reasons', options),
+ }
+
+ readonly trackingCarriers = {
+ list: (options?: RequestOptions): Promise<{ data: Array<{ id: string; name: string }> }> =>
+ this.request<{ data: Array<{ id: string; name: string }> }>(
+ 'GET',
+ '/tracking_carriers',
+ options,
+ ),
}
/**
diff --git a/packages/seller-sdk/src/types/generated/Claim.ts b/packages/seller-sdk/src/types/generated/Claim.ts
new file mode 100644
index 0000000000..6530a648d5
--- /dev/null
+++ b/packages/seller-sdk/src/types/generated/Claim.ts
@@ -0,0 +1,24 @@
+// Typelizer digest d2634e126720b3c47d3438e83035dadf
+//
+// DO NOT MODIFY: This file was automatically generated by Typelizer.
+import type {Reason, ClaimLineItem} from '@/types'
+
+type Claim = {
+ id: string;
+ number: string;
+ status: string;
+ resolution: string | null;
+ order_id: string | null;
+ reason_id: string | null;
+ refund_total: string;
+ display_refund_total: string;
+ approved_at: string | null;
+ resolved_at: string | null;
+ denied_at: string | null;
+ canceled_at: string | null;
+ reason?: Reason;
+ claim_line_items?: Array<ClaimLineItem>;
+ memo: string | null;
+}
+
+export default Claim;
diff --git a/packages/seller-sdk/src/types/generated/ClaimLineItem.ts b/packages/seller-sdk/src/types/generated/ClaimLineItem.ts
new file mode 100644
index 0000000000..9e95e2d55c
--- /dev/null
+++ b/packages/seller-sdk/src/types/generated/ClaimLineItem.ts
@@ -0,0 +1,20 @@
+// Typelizer digest f35f7fc79f41f512821ba3ea89e38351
+//
+// DO NOT MODIFY: This file was automatically generated by Typelizer.
+import type {Variant} from '@/types'
+
+type ClaimLineItem = {
+ id: string;
+ quantity: number;
+ send_replacement: boolean;
+ description: string | null;
+ refund_amount: string;
+ paid_amount: string;
+ display_refund_amount: string;
+ variant_id: string | null;
+ replacement_variant_id: string | null;
+ line_item_id: string | null;
+ variant?: Variant;
+}
+
+export default ClaimLineItem;
diff --git a/packages/seller-sdk/src/types/generated/Exchange.ts b/packages/seller-sdk/src/types/generated/Exchange.ts
new file mode 100644
index 0000000000..3803fc39f7
--- /dev/null
+++ b/packages/seller-sdk/src/types/generated/Exchange.ts
@@ -0,0 +1,24 @@
+// Typelizer digest fb57f0c4ff59347626c7dc1d84815d80
+//
+// DO NOT MODIFY: This file was automatically generated by Typelizer.
+import type {Reason, ExchangeLineItem} from '@/types'
+
+type Exchange = {
+ id: string;
+ number: string;
+ status: string;
+ order_id: string | null;
+ reason_id: string | null;
+ price_difference: string;
+ display_price_difference: string;
+ approved_at: string | null;
+ received_at: string | null;
+ fulfilled_at: string | null;
+ canceled_at: string | null;
+ reason?: Reason;
+ exchange_line_items?: Array<ExchangeLineItem>;
+ memo: string | null;
+ stock_location_id: string | null;
+}
+
+export default Exchange;
diff --git a/packages/seller-sdk/src/types/generated/ExchangeLineItem.ts b/packages/seller-sdk/src/types/generated/ExchangeLineItem.ts
new file mode 100644
index 0000000000..d35cc1aa4f
--- /dev/null
+++ b/packages/seller-sdk/src/types/generated/ExchangeLineItem.ts
@@ -0,0 +1,22 @@
+// Typelizer digest 6230936c0a851435292a2454ad40dd94
+//
+// DO NOT MODIFY: This file was automatically generated by Typelizer.
+import type {Variant} from '@/types'
+
+type ExchangeLineItem = {
+ id: string;
+ quantity: number;
+ received_quantity: number;
+ resellable: boolean;
+ original_price: string;
+ new_variant_price: string;
+ price_difference: string;
+ original_variant_id: string | null;
+ new_variant_id: string | null;
+ line_item_id: string | null;
+ fulfillment_item_id: string | null;
+ original_variant?: Variant;
+ new_variant?: Variant;
+}
+
+export default ExchangeLineItem;
diff --git a/packages/seller-sdk/src/types/generated/Reason.ts b/packages/seller-sdk/src/types/generated/Reason.ts
new file mode 100644
index 0000000000..b6ee55e47e
--- /dev/null
+++ b/packages/seller-sdk/src/types/generated/Reason.ts
@@ -0,0 +1,11 @@
+// Typelizer digest 17a44e2b3ce21c3ff5cdff1bc15c647c
+//
+// DO NOT MODIFY: This file was automatically generated by Typelizer.
+
+type Reason = {
+ id: string;
+ name: string;
+ active: boolean;
+}
+
+export default Reason;
diff --git a/packages/seller-sdk/src/types/generated/Return.ts b/packages/seller-sdk/src/types/generated/Return.ts
new file mode 100644
index 0000000000..3d85796b86
--- /dev/null
+++ b/packages/seller-sdk/src/types/generated/Return.ts
@@ -0,0 +1,27 @@
+// Typelizer digest bcbe1df4490155018787c54c06415d3b
+//
+// DO NOT MODIFY: This file was automatically generated by Typelizer.
+import type {Reason, ReturnLineItem} from '@/types'
+
+type Return = {
+ id: string;
+ number: string;
+ status: string;
+ order_id: string | null;
+ reason_id: string | null;
+ refund_total: string;
+ display_refund_total: string;
+ approved_at: string | null;
+ received_at: string | null;
+ refunded_at: string | null;
+ canceled_at: string | null;
+ reason?: Reason;
+ return_line_items?: Array<ReturnLineItem>;
+ memo: string | null;
+ stock_location_id: string | null;
+ refunded_total: string;
+ refundable_total: string;
+ display_refunded_total: string;
+}
+
+export default Return;
diff --git a/packages/seller-sdk/src/types/generated/ReturnLineItem.ts b/packages/seller-sdk/src/types/generated/ReturnLineItem.ts
new file mode 100644
index 0000000000..d70a4964cd
--- /dev/null
+++ b/packages/seller-sdk/src/types/generated/ReturnLineItem.ts
@@ -0,0 +1,19 @@
+// Typelizer digest 78bd739c8744e19f6a15a92d7dcc2fe5
+//
+// DO NOT MODIFY: This file was automatically generated by Typelizer.
+import type {Variant} from '@/types'
+
+type ReturnLineItem = {
+ id: string;
+ quantity: number;
+ received_quantity: number;
+ resellable: boolean;
+ pre_tax_amount: string;
+ display_pre_tax_amount: string;
+ variant_id: string | null;
+ line_item_id: string | null;
+ fulfillment_item_id: string | null;
+ variant?: Variant;
+}
+
+export default ReturnLineItem;
diff --git a/packages/seller-sdk/src/types/generated/index.ts b/packages/seller-sdk/src/types/generated/index.ts
index f6a8b8136e..7ea7831238 100644
--- a/packages/seller-sdk/src/types/generated/index.ts
+++ b/packages/seller-sdk/src/types/generated/index.ts
@@ -1,4 +1,4 @@
-// Typelizer digest ac6e4a9037835131918bca4d055ee34e
+// Typelizer digest 1c6e6c4f7f20af237f859b4dc2616496
//
// DO NOT MODIFY: This file was automatically generated by Typelizer.
export type { default as Address } from './Address'
@@ -8,11 +8,15 @@ export type { default as OptionType } from './OptionType'
export type { default as OptionValue } from './OptionValue'
export type { default as PriceHistory } from './PriceHistory'
export type { default as Price } from './Price'
+export type { default as ClaimLineItem } from './ClaimLineItem'
+export type { default as Claim } from './Claim'
export type { default as DeliveryMethodRule } from './DeliveryMethodRule'
export type { default as DeliveryMethod } from './DeliveryMethod'
export type { default as DeliveryProfile } from './DeliveryProfile'
export type { default as Delivery } from './Delivery'
export type { default as DeliveryZone } from './DeliveryZone'
+export type { default as ExchangeLineItem } from './ExchangeLineItem'
+export type { default as Exchange } from './Exchange'
export type { default as Export } from './Export'
export type { default as FulfillmentItem } from './FulfillmentItem'
export type { default as Fulfillment } from './Fulfillment'
@@ -28,9 +32,12 @@ export type { default as Product } from './Product'
export type { default as ProductSubmission } from './ProductSubmission'
export type { default as ProductType } from './ProductType'
export type { default as Profile } from './Profile'
+export type { default as Reason } from './Reason'
export type { default as RequirementCustomField } from './RequirementCustomField'
export type { default as RequirementStatus } from './RequirementStatus'
export type { default as RequirementSubmission } from './RequirementSubmission'
+export type { default as ReturnLineItem } from './ReturnLineItem'
+export type { default as Return } from './Return'
export type { default as ShippingLabel } from './ShippingLabel'
export type { default as StockLevel } from './StockLevel'
export type { default as StockLocation } from './StockLocation'