@konfiqo/storefront-sdk 0.8.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +60 -28
- package/dist/index.cjs +27 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +101 -3
- package/dist/index.d.ts +101 -3
- package/dist/index.js +27 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -722,6 +722,8 @@ type PaymentStatus = 'none' | 'pending' | 'processing' | 'succeeded' | 'failed'
|
|
|
722
722
|
type ShipmentStatus = 'requested' | 'created' | 'picked_up' | 'in_transit' | 'out_for_delivery' | 'delivered' | 'returned' | 'cancelled' | 'exception' | 'failed' | (string & {});
|
|
723
723
|
/** A line of a placed order. */
|
|
724
724
|
interface OrderLine {
|
|
725
|
+
/** Line id: send it as `lineId` when returning this line. */
|
|
726
|
+
id?: string;
|
|
725
727
|
/** Product id (what ad pixels and analytics use as item id). */
|
|
726
728
|
productId?: string | null;
|
|
727
729
|
/** Product name at order time. */
|
|
@@ -736,6 +738,12 @@ interface OrderLine {
|
|
|
736
738
|
lineTotalMinor: number;
|
|
737
739
|
/** The buyer's text for this line; absent or null when there is none. */
|
|
738
740
|
personalization?: string | null;
|
|
741
|
+
/**
|
|
742
|
+
* Units of this line the buyer can still return (the line's quantity less
|
|
743
|
+
* the units in returns that are not cancelled or rejected). 0 when the
|
|
744
|
+
* order takes no return. Absent on older APIs: treat as 0.
|
|
745
|
+
*/
|
|
746
|
+
returnableQuantity?: number;
|
|
739
747
|
}
|
|
740
748
|
/** A shipment of an order. */
|
|
741
749
|
interface OrderShipment {
|
|
@@ -778,6 +786,72 @@ interface Order {
|
|
|
778
786
|
shipments: OrderShipment[];
|
|
779
787
|
/** The legal texts the buyer accepted at checkout, as placed. */
|
|
780
788
|
agreements: LegalDocument[];
|
|
789
|
+
/**
|
|
790
|
+
* Whether the buyer may open a return now. Absent on older APIs: treat as
|
|
791
|
+
* not eligible. Show the return form only when `eligible` is true, and
|
|
792
|
+
* show the `deadline`.
|
|
793
|
+
*/
|
|
794
|
+
returnable?: OrderReturnable;
|
|
795
|
+
/** The order's returns, oldest first. Absent on older APIs: treat as empty. */
|
|
796
|
+
returns?: OrderReturn[];
|
|
797
|
+
}
|
|
798
|
+
/** Why a return cannot be opened on an order now. */
|
|
799
|
+
type ReturnBlock = 'unpaid' | 'refunded' | 'cancelled' | 'window_closed' | 'open_return' | 'too_many_returns' | 'nothing_left' | (string & {});
|
|
800
|
+
/** `Order.returnable`: whether a return can be opened, and until when. */
|
|
801
|
+
interface OrderReturnable {
|
|
802
|
+
/** The buyer may open a return now. */
|
|
803
|
+
eligible: boolean;
|
|
804
|
+
/** Why not, when `eligible` is false. */
|
|
805
|
+
reason: ReturnBlock | null;
|
|
806
|
+
/** Last moment to open a return (ISO date), or null when no deadline is known. */
|
|
807
|
+
deadline: string | null;
|
|
808
|
+
}
|
|
809
|
+
/** Why a buyer returns a line. */
|
|
810
|
+
type ReturnReason = 'changedMind' | 'defective' | 'wrongItem' | 'notAsDescribed' | 'other';
|
|
811
|
+
/** Where a return stands (the commerce module's values; new values pass through). */
|
|
812
|
+
type ReturnStatus = 'requested' | 'approved' | 'received' | 'refunded' | 'rejected' | 'cancelled' | (string & {});
|
|
813
|
+
/** One returned line of an {@link OrderReturn}. */
|
|
814
|
+
interface OrderReturnLine {
|
|
815
|
+
/** The id of the order line (`OrderLine.id`). */
|
|
816
|
+
lineId: string;
|
|
817
|
+
/** Returned units. */
|
|
818
|
+
quantity: number;
|
|
819
|
+
/** The buyer's reason (a reason this SDK does not know passes through). */
|
|
820
|
+
reason: ReturnReason | (string & {});
|
|
821
|
+
}
|
|
822
|
+
/** A return of an order, as the buyer sees it. */
|
|
823
|
+
interface OrderReturn {
|
|
824
|
+
/** Return id. */
|
|
825
|
+
id: string;
|
|
826
|
+
/** Human-readable number, `<orderNumber>-R<n>`. */
|
|
827
|
+
returnNumber: string;
|
|
828
|
+
/** Status. */
|
|
829
|
+
status: ReturnStatus;
|
|
830
|
+
/** The returned lines. */
|
|
831
|
+
lines: OrderReturnLine[];
|
|
832
|
+
/** Carrier to send the parcel with, from `approved` on; else null. */
|
|
833
|
+
carrier: string | null;
|
|
834
|
+
/** Return code to quote at the carrier, from `approved` on; else null. */
|
|
835
|
+
returnCode: string | null;
|
|
836
|
+
/** Instructions for sending the parcel back, from `approved` on; else null. */
|
|
837
|
+
instructions: string | null;
|
|
838
|
+
/** When the return was opened (ISO date), or null. */
|
|
839
|
+
requestedAt: string | null;
|
|
840
|
+
/** Amount refunded or to be refunded, minor units. */
|
|
841
|
+
refundAmountMinor: number;
|
|
842
|
+
/** Why the seller rejected the return, or null. */
|
|
843
|
+
rejectionReason: string | null;
|
|
844
|
+
}
|
|
845
|
+
/** `orders.createReturn` input. */
|
|
846
|
+
interface CreateReturnInput {
|
|
847
|
+
/** 1 to 50 lines; a line may appear once. */
|
|
848
|
+
lines: {
|
|
849
|
+
lineId: string;
|
|
850
|
+
quantity: number;
|
|
851
|
+
reason: ReturnReason;
|
|
852
|
+
}[];
|
|
853
|
+
/** A note for the seller, up to 1000 characters. */
|
|
854
|
+
note?: string;
|
|
781
855
|
}
|
|
782
856
|
/** `POST /v1/account/session`: the signed-in buyer. */
|
|
783
857
|
interface AccountSession {
|
|
@@ -1059,6 +1133,22 @@ interface StorefrontClient {
|
|
|
1059
1133
|
readonly orders: {
|
|
1060
1134
|
/** `GET /v1/orders/:id?token=`: the order, for the buyer holding its token. */
|
|
1061
1135
|
get(orderId: string, token: string, options?: RequestOptions): Promise<Order>;
|
|
1136
|
+
/**
|
|
1137
|
+
* `POST /v1/orders/:id/returns`: opens a return for the buyer holding
|
|
1138
|
+
* the order's token (sent in the body, never in the URL). Show the form
|
|
1139
|
+
* only when `order.returnable.eligible`; the server checks again.
|
|
1140
|
+
* Rejects `invalid_return` (400: a line not of this order, a repeated
|
|
1141
|
+
* line, or more units than `returnableQuantity`), `return_not_allowed`
|
|
1142
|
+
* (409, `details.reason`), `order_not_found`, `order_unavailable`.
|
|
1143
|
+
*/
|
|
1144
|
+
createReturn(orderId: string, token: string, input: CreateReturnInput, options?: RequestOptions): Promise<OrderReturn>;
|
|
1145
|
+
/**
|
|
1146
|
+
* `POST /v1/orders/:id/returns/:returnId/cancel`: withdraws a
|
|
1147
|
+
* `requested` or `approved` return. Rejects `return_not_allowed` (409)
|
|
1148
|
+
* from any other status, `return_not_found` (404) for a return of
|
|
1149
|
+
* another order.
|
|
1150
|
+
*/
|
|
1151
|
+
cancelReturn(orderId: string, returnId: string, token: string, options?: RequestOptions): Promise<OrderReturn>;
|
|
1062
1152
|
};
|
|
1063
1153
|
/**
|
|
1064
1154
|
* The signed-in buyer's account. Sign-in is by an e-mailed one-time code;
|
|
@@ -1203,13 +1293,21 @@ interface StorefrontErrorDetailsMap {
|
|
|
1203
1293
|
timeout: {
|
|
1204
1294
|
timeoutMs: number;
|
|
1205
1295
|
};
|
|
1296
|
+
/**
|
|
1297
|
+
* No return can be opened or cancelled now (409). `reason` says why when
|
|
1298
|
+
* the order does not take a return; it is absent when a cancel is refused
|
|
1299
|
+
* because the return is no longer open.
|
|
1300
|
+
*/
|
|
1301
|
+
return_not_allowed: {
|
|
1302
|
+
reason?: ReturnBlock;
|
|
1303
|
+
};
|
|
1206
1304
|
/** The server answered an error code this SDK version does not know. */
|
|
1207
1305
|
unknown_error: {
|
|
1208
1306
|
error: string | null;
|
|
1209
1307
|
};
|
|
1210
1308
|
}
|
|
1211
1309
|
/** Error codes of the Storefront API (the `error` field of an error response). */
|
|
1212
|
-
type StorefrontApiErrorCode = 'store_not_found' | 'origin_not_allowed' | 'invalid_request' | 'invalid_buyer_ip' | 'catalog_unavailable' | 'product_not_found' | 'content_not_found' | 'blog_post_not_found' | 'cart_not_found' | 'variant_not_found' | 'line_not_found' | 'insufficient_stock' | 'quantity_out_of_range' | 'too_many_lines' | 'invalid_shipping_option' | 'cart_read_only' | 'checkout_in_progress' | 'checkout_incomplete' | 'legal_not_confirmed' | 'agreements_changed' | 'cart_incomplete' | 'cart_changed' | 'invalid_personalization' | 'out_of_stock' | 'amount_out_of_range' | 'nothing_to_pay' | 'invalid_buyer_details' | 'payment_unavailable' | 'checkout_unavailable' | 'order_not_found' | 'order_unavailable' | 'media_not_found' | 'media_unavailable' | 'challenge_required' | 'challenge_failed' | 'challenge_unavailable' | 'too_many_open_orders' | 'not_signed_in' | 'invalid_code' | 'profile_required' | 'too_many_code_requests' | 'invalid_recovery_token' | 'cart_not_recoverable' | 'unavailable';
|
|
1310
|
+
type StorefrontApiErrorCode = 'store_not_found' | 'origin_not_allowed' | 'invalid_request' | 'invalid_buyer_ip' | 'catalog_unavailable' | 'product_not_found' | 'content_not_found' | 'blog_post_not_found' | 'cart_not_found' | 'variant_not_found' | 'line_not_found' | 'insufficient_stock' | 'quantity_out_of_range' | 'too_many_lines' | 'invalid_shipping_option' | 'cart_read_only' | 'checkout_in_progress' | 'checkout_incomplete' | 'legal_not_confirmed' | 'agreements_changed' | 'cart_incomplete' | 'cart_changed' | 'invalid_personalization' | 'out_of_stock' | 'amount_out_of_range' | 'nothing_to_pay' | 'invalid_buyer_details' | 'payment_unavailable' | 'checkout_unavailable' | 'order_not_found' | 'order_unavailable' | 'media_not_found' | 'media_unavailable' | 'challenge_required' | 'challenge_failed' | 'challenge_unavailable' | 'too_many_open_orders' | 'not_signed_in' | 'invalid_code' | 'profile_required' | 'too_many_code_requests' | 'invalid_recovery_token' | 'cart_not_recoverable' | 'invalid_return' | 'return_not_allowed' | 'return_not_found' | 'unavailable';
|
|
1213
1311
|
/**
|
|
1214
1312
|
* Codes the SDK assigns itself:
|
|
1215
1313
|
* - `rate_limited` — HTTP 429 without a known `error` code (the throttler);
|
|
@@ -1464,6 +1562,6 @@ interface TurnstileWidget {
|
|
|
1464
1562
|
declare function renderTurnstile(element: HTMLElement, siteKey: string, options: RenderTurnstileOptions): Promise<TurnstileWidget>;
|
|
1465
1563
|
|
|
1466
1564
|
/** Version of the Storefront SDK package. */
|
|
1467
|
-
declare const SDK_VERSION = "0.
|
|
1565
|
+
declare const SDK_VERSION = "0.9.0";
|
|
1468
1566
|
|
|
1469
|
-
export { type Account, type AccountOrder, type AccountProfileInput, type AccountSession, type AdPixels, type AddLineInput, type Address, type AddressInput, type AnyStorefrontError, BUYER_IP_HEADER, BUYER_USER_AGENT_HEADER, type BlogPost, type BlogPostList, type BlogPostSummary, type BuyerDetailField, type Cart, type CartAgreements, type CartCustomer, type CartIdStorage, type CartLine, type CartStatus, type Category, type CategoryGridSection, type CategoryList, type CheckoutChallenge, type CheckoutEmbed, type CheckoutEmbedKind, type CheckoutMissing, type CheckoutOptions, type CheckoutResult, type CheckoutResultBase, type ClosedCheckoutPage, type ClosedCheckoutResult, type ClosedPaymentMount, type ContentNode, type CookieCategory, type CookieInfo, type CookieJar, type CustomerInput, DEFAULT_TIMEOUT_MS, type EmbeddedCheckoutResult, type EmbeddedPaymentMount, type FeaturedProductsSection, type HeroSection, type KnownThemeSection, LEGAL_KEYS, type LegalDocument, type LegalKey, type MarketingConsentText, type MountPaymentOptions, type Order, type OrderLine, type OrderShipment, type OrderStatus, PUBLISHABLE_KEY_HEADER, type Pagination, type PaymentMount, type PaymentPresentation, type PaymentStatus, type Product, type ProductListQuery, type ProductPage, type ProductPersonalization, type ProductVariant, REOPEN_AGREEMENTS_HASH, type RedirectCheckoutResult, type RedirectPaymentMount, type RenderTurnstileOptions, type RequestCodeOptions, type RequestOptions, type RichTextSection, SDK_VERSION, STOREFRONT_KEY_HEADER, type SavedAddress, type SavedAddressInput, type ShipmentStatus, type ShippingOption, type ShippingOptionList, type ShippingRules, type Store, type StoreCompany, type StoreContact, type StoreContent, type StorefrontApiErrorCode, type StorefrontClient, type StorefrontClientErrorCode, type StorefrontClientOptions, StorefrontError, type StorefrontErrorCode, type StorefrontErrorDetails, type StorefrontErrorDetailsMap, THEME_FONTS, TURNSTILE_SCRIPT_URL, TURNSTILE_TOKEN_HEADER, type ThemeColors, type ThemeFont, type ThemeFooter, type ThemeHomepage, type ThemeLink, type ThemeSection, type ThemeSocial, type ThemeV1, type TurnstileApi, type TurnstileWidget, type UnknownThemeSection, type UnsupportedPaymentMount, type UpdateLineInput, type ValidationIssue, cartIdKey, clearCartId, cookieCartStorage, cookiesForHost, createStorefrontClient, formatMoney, isKnownThemeSection, isStorefrontError, loadCartId, loadTurnstile, mountPayment, onDefaultDomain, pixelsForHost, renderTurnstile, saveCartId };
|
|
1567
|
+
export { type Account, type AccountOrder, type AccountProfileInput, type AccountSession, type AdPixels, type AddLineInput, type Address, type AddressInput, type AnyStorefrontError, BUYER_IP_HEADER, BUYER_USER_AGENT_HEADER, type BlogPost, type BlogPostList, type BlogPostSummary, type BuyerDetailField, type Cart, type CartAgreements, type CartCustomer, type CartIdStorage, type CartLine, type CartStatus, type Category, type CategoryGridSection, type CategoryList, type CheckoutChallenge, type CheckoutEmbed, type CheckoutEmbedKind, type CheckoutMissing, type CheckoutOptions, type CheckoutResult, type CheckoutResultBase, type ClosedCheckoutPage, type ClosedCheckoutResult, type ClosedPaymentMount, type ContentNode, type CookieCategory, type CookieInfo, type CookieJar, type CreateReturnInput, type CustomerInput, DEFAULT_TIMEOUT_MS, type EmbeddedCheckoutResult, type EmbeddedPaymentMount, type FeaturedProductsSection, type HeroSection, type KnownThemeSection, LEGAL_KEYS, type LegalDocument, type LegalKey, type MarketingConsentText, type MountPaymentOptions, type Order, type OrderLine, type OrderReturn, type OrderReturnLine, type OrderReturnable, type OrderShipment, type OrderStatus, PUBLISHABLE_KEY_HEADER, type Pagination, type PaymentMount, type PaymentPresentation, type PaymentStatus, type Product, type ProductListQuery, type ProductPage, type ProductPersonalization, type ProductVariant, REOPEN_AGREEMENTS_HASH, type RedirectCheckoutResult, type RedirectPaymentMount, type RenderTurnstileOptions, type RequestCodeOptions, type RequestOptions, type ReturnBlock, type ReturnReason, type ReturnStatus, type RichTextSection, SDK_VERSION, STOREFRONT_KEY_HEADER, type SavedAddress, type SavedAddressInput, type ShipmentStatus, type ShippingOption, type ShippingOptionList, type ShippingRules, type Store, type StoreCompany, type StoreContact, type StoreContent, type StorefrontApiErrorCode, type StorefrontClient, type StorefrontClientErrorCode, type StorefrontClientOptions, StorefrontError, type StorefrontErrorCode, type StorefrontErrorDetails, type StorefrontErrorDetailsMap, THEME_FONTS, TURNSTILE_SCRIPT_URL, TURNSTILE_TOKEN_HEADER, type ThemeColors, type ThemeFont, type ThemeFooter, type ThemeHomepage, type ThemeLink, type ThemeSection, type ThemeSocial, type ThemeV1, type TurnstileApi, type TurnstileWidget, type UnknownThemeSection, type UnsupportedPaymentMount, type UpdateLineInput, type ValidationIssue, cartIdKey, clearCartId, cookieCartStorage, cookiesForHost, createStorefrontClient, formatMoney, isKnownThemeSection, isStorefrontError, loadCartId, loadTurnstile, mountPayment, onDefaultDomain, pixelsForHost, renderTurnstile, saveCartId };
|
package/dist/index.js
CHANGED
|
@@ -43,6 +43,9 @@ var API_CODES = /* @__PURE__ */ new Set([
|
|
|
43
43
|
"too_many_code_requests",
|
|
44
44
|
"invalid_recovery_token",
|
|
45
45
|
"cart_not_recoverable",
|
|
46
|
+
"invalid_return",
|
|
47
|
+
"return_not_allowed",
|
|
48
|
+
"return_not_found",
|
|
46
49
|
"unavailable"
|
|
47
50
|
]);
|
|
48
51
|
var ERROR_BRAND = /* @__PURE__ */ Symbol.for("@konfiqo/storefront-sdk/error");
|
|
@@ -157,6 +160,13 @@ function apiError(code, status, message, b) {
|
|
|
157
160
|
return new StorefrontError(code, status, message, {
|
|
158
161
|
status: b.status === "ordered" ? "ordered" : "expired"
|
|
159
162
|
});
|
|
163
|
+
case "return_not_allowed":
|
|
164
|
+
return new StorefrontError(
|
|
165
|
+
code,
|
|
166
|
+
status,
|
|
167
|
+
message,
|
|
168
|
+
typeof b.reason === "string" ? { reason: b.reason } : {}
|
|
169
|
+
);
|
|
160
170
|
default:
|
|
161
171
|
return new StorefrontError(
|
|
162
172
|
code,
|
|
@@ -430,6 +440,22 @@ function createStorefrontClient(options) {
|
|
|
430
440
|
get: (orderId, token, o) => get(
|
|
431
441
|
() => `/v1/orders/${seg(orderId)}?token=${encodeURIComponent(token)}`,
|
|
432
442
|
o
|
|
443
|
+
),
|
|
444
|
+
createReturn: (orderId, token, input, o) => request(
|
|
445
|
+
"POST",
|
|
446
|
+
() => `/v1/orders/${seg(orderId)}/returns`,
|
|
447
|
+
{
|
|
448
|
+
token,
|
|
449
|
+
lines: input.lines,
|
|
450
|
+
...input.note !== void 0 && { note: input.note }
|
|
451
|
+
},
|
|
452
|
+
o
|
|
453
|
+
),
|
|
454
|
+
cancelReturn: (orderId, returnId, token, o) => request(
|
|
455
|
+
"POST",
|
|
456
|
+
() => `/v1/orders/${seg(orderId)}/returns/${seg(returnId)}/cancel`,
|
|
457
|
+
{ token },
|
|
458
|
+
o
|
|
433
459
|
)
|
|
434
460
|
},
|
|
435
461
|
account: {
|
|
@@ -771,7 +797,7 @@ async function renderTurnstile(element, siteKey, options) {
|
|
|
771
797
|
}
|
|
772
798
|
|
|
773
799
|
// src/index.ts
|
|
774
|
-
var SDK_VERSION = "0.
|
|
800
|
+
var SDK_VERSION = "0.9.0";
|
|
775
801
|
export {
|
|
776
802
|
BUYER_IP_HEADER,
|
|
777
803
|
BUYER_USER_AGENT_HEADER,
|