@konfiqo/storefront-sdk 0.7.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/dist/index.d.cts CHANGED
@@ -343,6 +343,20 @@ interface Store {
343
343
  * versions: treat every host as a custom domain.)
344
344
  */
345
345
  defaultDomainSuffix?: string;
346
+ /**
347
+ * The marketing consent text the checkout shows next to an unticked box,
348
+ * with its version (`v1-tr`, `v1-en`). Send `version` as
349
+ * `consentTextVersion` when the buyer ticks the box. Absent on older
350
+ * API versions. Treat absent or null as "show no checkbox".
351
+ */
352
+ marketingConsent?: MarketingConsentText | null;
353
+ }
354
+ /** The marketing consent text served in `Store.marketingConsent`. */
355
+ interface MarketingConsentText {
356
+ /** Version of the text; send it with a tick as `consentTextVersion`. */
357
+ version: string;
358
+ /** The text to show next to the box, in the store's language. */
359
+ text: string;
346
360
  }
347
361
  /** A node of the active category tree. */
348
362
  interface Category {
@@ -605,6 +619,20 @@ interface CustomerInput {
605
619
  * one already on the cart is kept.
606
620
  */
607
621
  identityNumber?: string;
622
+ /**
623
+ * Whether the buyer ticked the marketing consent box. Never pre-tick it:
624
+ * the box starts unticked and only the buyer's own action sets it. Omitted
625
+ * or `false` records no consent. With `true`, also send
626
+ * `consentTextVersion`.
627
+ */
628
+ marketingConsent?: boolean;
629
+ /**
630
+ * The `version` of `store.marketingConsent` that was shown next to the
631
+ * tick. Required with `marketingConsent: true`: a missing or unknown
632
+ * version is refused as `invalid_request` with
633
+ * `path: "consentTextVersion"`.
634
+ */
635
+ consentTextVersion?: string;
608
636
  }
609
637
  /** Body of `carts.setAddress`. */
610
638
  interface AddressInput {
@@ -694,6 +722,8 @@ type PaymentStatus = 'none' | 'pending' | 'processing' | 'succeeded' | 'failed'
694
722
  type ShipmentStatus = 'requested' | 'created' | 'picked_up' | 'in_transit' | 'out_for_delivery' | 'delivered' | 'returned' | 'cancelled' | 'exception' | 'failed' | (string & {});
695
723
  /** A line of a placed order. */
696
724
  interface OrderLine {
725
+ /** Line id: send it as `lineId` when returning this line. */
726
+ id?: string;
697
727
  /** Product id (what ad pixels and analytics use as item id). */
698
728
  productId?: string | null;
699
729
  /** Product name at order time. */
@@ -708,6 +738,12 @@ interface OrderLine {
708
738
  lineTotalMinor: number;
709
739
  /** The buyer's text for this line; absent or null when there is none. */
710
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;
711
747
  }
712
748
  /** A shipment of an order. */
713
749
  interface OrderShipment {
@@ -750,6 +786,72 @@ interface Order {
750
786
  shipments: OrderShipment[];
751
787
  /** The legal texts the buyer accepted at checkout, as placed. */
752
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;
753
855
  }
754
856
  /** `POST /v1/account/session`: the signed-in buyer. */
755
857
  interface AccountSession {
@@ -812,6 +914,8 @@ declare const STOREFRONT_KEY_HEADER = "x-konfiqo-storefront-key";
812
914
  declare const TURNSTILE_TOKEN_HEADER = "x-konfiqo-turnstile-token";
813
915
  /** Header carrying the buyer's IP (only with a server key or the trusted storefront key). */
814
916
  declare const BUYER_IP_HEADER = "x-konfiqo-buyer-ip";
917
+ /** Header carrying the buyer's user agent (only with a server key or the trusted storefront key). */
918
+ declare const BUYER_USER_AGENT_HEADER = "x-konfiqo-buyer-user-agent";
815
919
  /** Per-call options, accepted as the last argument of every method. */
816
920
  interface RequestOptions {
817
921
  /**
@@ -904,6 +1008,14 @@ interface StorefrontClientOptions {
904
1008
  * client per incoming request on the server.
905
1009
  */
906
1010
  buyerIp?: string;
1011
+ /**
1012
+ * The buyer's browser user agent, sent as `x-konfiqo-buyer-user-agent`
1013
+ * so the store can record it with the buyer's marketing consent. Optional,
1014
+ * and ignored without `serverKey` or `trustedStorefrontKey` (the API
1015
+ * trusts it from a keyed caller only, like `buyerIp`). Pass the
1016
+ * `User-Agent` header of the incoming request.
1017
+ */
1018
+ buyerUserAgent?: string;
907
1019
  }
908
1020
  /**
909
1021
  * A typed client of the Storefront API (`/v1`).
@@ -1021,6 +1133,22 @@ interface StorefrontClient {
1021
1133
  readonly orders: {
1022
1134
  /** `GET /v1/orders/:id?token=`: the order, for the buyer holding its token. */
1023
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>;
1024
1152
  };
1025
1153
  /**
1026
1154
  * The signed-in buyer's account. Sign-in is by an e-mailed one-time code;
@@ -1165,13 +1293,21 @@ interface StorefrontErrorDetailsMap {
1165
1293
  timeout: {
1166
1294
  timeoutMs: number;
1167
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
+ };
1168
1304
  /** The server answered an error code this SDK version does not know. */
1169
1305
  unknown_error: {
1170
1306
  error: string | null;
1171
1307
  };
1172
1308
  }
1173
1309
  /** Error codes of the Storefront API (the `error` field of an error response). */
1174
- 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';
1175
1311
  /**
1176
1312
  * Codes the SDK assigns itself:
1177
1313
  * - `rate_limited` — HTTP 429 without a known `error` code (the throttler);
@@ -1426,6 +1562,6 @@ interface TurnstileWidget {
1426
1562
  declare function renderTurnstile(element: HTMLElement, siteKey: string, options: RenderTurnstileOptions): Promise<TurnstileWidget>;
1427
1563
 
1428
1564
  /** Version of the Storefront SDK package. */
1429
- declare const SDK_VERSION = "0.7.0";
1565
+ declare const SDK_VERSION = "0.9.0";
1430
1566
 
1431
- export { type Account, type AccountOrder, type AccountProfileInput, type AccountSession, type AdPixels, type AddLineInput, type Address, type AddressInput, type AnyStorefrontError, BUYER_IP_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 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.d.ts CHANGED
@@ -343,6 +343,20 @@ interface Store {
343
343
  * versions: treat every host as a custom domain.)
344
344
  */
345
345
  defaultDomainSuffix?: string;
346
+ /**
347
+ * The marketing consent text the checkout shows next to an unticked box,
348
+ * with its version (`v1-tr`, `v1-en`). Send `version` as
349
+ * `consentTextVersion` when the buyer ticks the box. Absent on older
350
+ * API versions. Treat absent or null as "show no checkbox".
351
+ */
352
+ marketingConsent?: MarketingConsentText | null;
353
+ }
354
+ /** The marketing consent text served in `Store.marketingConsent`. */
355
+ interface MarketingConsentText {
356
+ /** Version of the text; send it with a tick as `consentTextVersion`. */
357
+ version: string;
358
+ /** The text to show next to the box, in the store's language. */
359
+ text: string;
346
360
  }
347
361
  /** A node of the active category tree. */
348
362
  interface Category {
@@ -605,6 +619,20 @@ interface CustomerInput {
605
619
  * one already on the cart is kept.
606
620
  */
607
621
  identityNumber?: string;
622
+ /**
623
+ * Whether the buyer ticked the marketing consent box. Never pre-tick it:
624
+ * the box starts unticked and only the buyer's own action sets it. Omitted
625
+ * or `false` records no consent. With `true`, also send
626
+ * `consentTextVersion`.
627
+ */
628
+ marketingConsent?: boolean;
629
+ /**
630
+ * The `version` of `store.marketingConsent` that was shown next to the
631
+ * tick. Required with `marketingConsent: true`: a missing or unknown
632
+ * version is refused as `invalid_request` with
633
+ * `path: "consentTextVersion"`.
634
+ */
635
+ consentTextVersion?: string;
608
636
  }
609
637
  /** Body of `carts.setAddress`. */
610
638
  interface AddressInput {
@@ -694,6 +722,8 @@ type PaymentStatus = 'none' | 'pending' | 'processing' | 'succeeded' | 'failed'
694
722
  type ShipmentStatus = 'requested' | 'created' | 'picked_up' | 'in_transit' | 'out_for_delivery' | 'delivered' | 'returned' | 'cancelled' | 'exception' | 'failed' | (string & {});
695
723
  /** A line of a placed order. */
696
724
  interface OrderLine {
725
+ /** Line id: send it as `lineId` when returning this line. */
726
+ id?: string;
697
727
  /** Product id (what ad pixels and analytics use as item id). */
698
728
  productId?: string | null;
699
729
  /** Product name at order time. */
@@ -708,6 +738,12 @@ interface OrderLine {
708
738
  lineTotalMinor: number;
709
739
  /** The buyer's text for this line; absent or null when there is none. */
710
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;
711
747
  }
712
748
  /** A shipment of an order. */
713
749
  interface OrderShipment {
@@ -750,6 +786,72 @@ interface Order {
750
786
  shipments: OrderShipment[];
751
787
  /** The legal texts the buyer accepted at checkout, as placed. */
752
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;
753
855
  }
754
856
  /** `POST /v1/account/session`: the signed-in buyer. */
755
857
  interface AccountSession {
@@ -812,6 +914,8 @@ declare const STOREFRONT_KEY_HEADER = "x-konfiqo-storefront-key";
812
914
  declare const TURNSTILE_TOKEN_HEADER = "x-konfiqo-turnstile-token";
813
915
  /** Header carrying the buyer's IP (only with a server key or the trusted storefront key). */
814
916
  declare const BUYER_IP_HEADER = "x-konfiqo-buyer-ip";
917
+ /** Header carrying the buyer's user agent (only with a server key or the trusted storefront key). */
918
+ declare const BUYER_USER_AGENT_HEADER = "x-konfiqo-buyer-user-agent";
815
919
  /** Per-call options, accepted as the last argument of every method. */
816
920
  interface RequestOptions {
817
921
  /**
@@ -904,6 +1008,14 @@ interface StorefrontClientOptions {
904
1008
  * client per incoming request on the server.
905
1009
  */
906
1010
  buyerIp?: string;
1011
+ /**
1012
+ * The buyer's browser user agent, sent as `x-konfiqo-buyer-user-agent`
1013
+ * so the store can record it with the buyer's marketing consent. Optional,
1014
+ * and ignored without `serverKey` or `trustedStorefrontKey` (the API
1015
+ * trusts it from a keyed caller only, like `buyerIp`). Pass the
1016
+ * `User-Agent` header of the incoming request.
1017
+ */
1018
+ buyerUserAgent?: string;
907
1019
  }
908
1020
  /**
909
1021
  * A typed client of the Storefront API (`/v1`).
@@ -1021,6 +1133,22 @@ interface StorefrontClient {
1021
1133
  readonly orders: {
1022
1134
  /** `GET /v1/orders/:id?token=`: the order, for the buyer holding its token. */
1023
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>;
1024
1152
  };
1025
1153
  /**
1026
1154
  * The signed-in buyer's account. Sign-in is by an e-mailed one-time code;
@@ -1165,13 +1293,21 @@ interface StorefrontErrorDetailsMap {
1165
1293
  timeout: {
1166
1294
  timeoutMs: number;
1167
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
+ };
1168
1304
  /** The server answered an error code this SDK version does not know. */
1169
1305
  unknown_error: {
1170
1306
  error: string | null;
1171
1307
  };
1172
1308
  }
1173
1309
  /** Error codes of the Storefront API (the `error` field of an error response). */
1174
- 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';
1175
1311
  /**
1176
1312
  * Codes the SDK assigns itself:
1177
1313
  * - `rate_limited` — HTTP 429 without a known `error` code (the throttler);
@@ -1426,6 +1562,6 @@ interface TurnstileWidget {
1426
1562
  declare function renderTurnstile(element: HTMLElement, siteKey: string, options: RenderTurnstileOptions): Promise<TurnstileWidget>;
1427
1563
 
1428
1564
  /** Version of the Storefront SDK package. */
1429
- declare const SDK_VERSION = "0.7.0";
1565
+ declare const SDK_VERSION = "0.9.0";
1430
1566
 
1431
- export { type Account, type AccountOrder, type AccountProfileInput, type AccountSession, type AdPixels, type AddLineInput, type Address, type AddressInput, type AnyStorefrontError, BUYER_IP_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 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,
@@ -174,6 +184,7 @@ var STOREFRONT_KEY_HEADER = "x-konfiqo-storefront-key";
174
184
  var SERVER_KEY_HEADER = "x-konfiqo-server-key";
175
185
  var TURNSTILE_TOKEN_HEADER = "x-konfiqo-turnstile-token";
176
186
  var BUYER_IP_HEADER = "x-konfiqo-buyer-ip";
187
+ var BUYER_USER_AGENT_HEADER = "x-konfiqo-buyer-user-agent";
177
188
  var REOPEN_AGREEMENTS_HASH = "0".repeat(64);
178
189
  function seg(v) {
179
190
  if (typeof v !== "string" || v === "" || v === "." || v === "..") {
@@ -238,6 +249,10 @@ function createStorefrontClient(options) {
238
249
  baseHeaders[STOREFRONT_KEY_HEADER] = options.trustedStorefrontKey;
239
250
  baseHeaders[BUYER_IP_HEADER] = buyerIp;
240
251
  }
252
+ const buyerUserAgent = options.buyerUserAgent?.trim();
253
+ if (buyerUserAgent && (options.serverKey !== void 0 || options.trustedStorefrontKey !== void 0)) {
254
+ baseHeaders[BUYER_USER_AGENT_HEADER] = buyerUserAgent;
255
+ }
241
256
  async function request(method, path, body, callOptions, extraHeaders = {}, flags = {}) {
242
257
  const url = `${baseUrl}${path()}`;
243
258
  const callerSignal = callOptions?.signal;
@@ -425,6 +440,22 @@ function createStorefrontClient(options) {
425
440
  get: (orderId, token, o) => get(
426
441
  () => `/v1/orders/${seg(orderId)}?token=${encodeURIComponent(token)}`,
427
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
428
459
  )
429
460
  },
430
461
  account: {
@@ -766,9 +797,10 @@ async function renderTurnstile(element, siteKey, options) {
766
797
  }
767
798
 
768
799
  // src/index.ts
769
- var SDK_VERSION = "0.7.0";
800
+ var SDK_VERSION = "0.9.0";
770
801
  export {
771
802
  BUYER_IP_HEADER,
803
+ BUYER_USER_AGENT_HEADER,
772
804
  DEFAULT_TIMEOUT_MS,
773
805
  LEGAL_KEYS,
774
806
  PUBLISHABLE_KEY_HEADER,