@konfiqo/storefront-sdk 0.9.0 → 0.10.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
@@ -275,6 +275,26 @@ interface CartAgreements {
275
275
  documents: LegalDocument[];
276
276
  /** Hash of the shown texts (64 hex characters). Checkout refuses a stale one. */
277
277
  agreementsHash: string;
278
+ /**
279
+ * The totals the documents were filled with, for this buyer: conditions
280
+ * that need the buyer (first order, per-customer limit) are evaluated, so
281
+ * a first-order discount shows its amount or its `codeReason`, and
282
+ * `pendingCampaigns` is empty. Show these at the review step instead of the
283
+ * cart's buyer-free totals. Null on APIs older than 0.10.0's server side
284
+ * (show the cart's totals then).
285
+ */
286
+ quote: AgreementsQuote | null;
287
+ }
288
+ /** {@link CartAgreements.quote}: the same shapes as on {@link Cart}. */
289
+ interface AgreementsQuote {
290
+ subtotalMinor: number;
291
+ discountMinor: number;
292
+ shippingMinor: number;
293
+ shippingDiscountMinor: number;
294
+ totalMinor: number;
295
+ appliedCampaigns: AppliedCampaign[];
296
+ pendingCampaigns: PendingCampaign[];
297
+ codeReason: CouponReason | null;
278
298
  }
279
299
  /** The ad pixels a store configured (ids are validated by the API). */
280
300
  interface AdPixels {
@@ -350,6 +370,12 @@ interface Store {
350
370
  * API versions. Treat absent or null as "show no checkbox".
351
371
  */
352
372
  marketingConsent?: MarketingConsentText | null;
373
+ /**
374
+ * Whether the store has an active campaign triggered by a code. Offer the
375
+ * code field only when true. Absent on older API versions: read as `true`,
376
+ * so a storefront keeps offering the field there.
377
+ */
378
+ hasCodeCampaigns: boolean;
353
379
  }
354
380
  /** The marketing consent text served in `Store.marketingConsent`. */
355
381
  interface MarketingConsentText {
@@ -469,6 +495,34 @@ interface ProductListQuery {
469
495
  /** Items per page (default 20, 1–100). */
470
496
  pageSize?: number;
471
497
  }
498
+ /**
499
+ * Why an entered coupon code (or a campaign) did not apply:
500
+ * - `unknown`: no active campaign has this code;
501
+ * - `used_up`: a single-use code already taken, or a usage limit reached;
502
+ * - `expired` / `not_started`: outside the campaign's dates;
503
+ * - `min_subtotal`: the goods subtotal is below the campaign's minimum;
504
+ * - `first_order_only`: the campaign is for a buyer's first order;
505
+ * - `not_combinable_better`: a better campaign that cannot combine applies.
506
+ */
507
+ type CouponReason = 'expired' | 'not_started' | 'min_subtotal' | 'first_order_only' | 'used_up' | 'not_combinable_better' | 'unknown';
508
+ /** A campaign that discounted a cart or an order, as the buyer sees it. */
509
+ interface AppliedCampaign {
510
+ /** The campaign id. Present on a cart; absent on an order. */
511
+ campaignId?: string;
512
+ /** The label to show the buyer (e.g. "10% off your first order"). */
513
+ buyerLabel: string;
514
+ /** Goods discount this campaign gave, minor units. */
515
+ discountMinor: number;
516
+ /** Shipping discount this campaign gave, minor units. */
517
+ shippingDiscountMinor: number;
518
+ }
519
+ /** A campaign that waits for the buyer's details (checkout); not applied yet. */
520
+ interface PendingCampaign {
521
+ /** The campaign id. */
522
+ campaignId?: string;
523
+ /** The label to show the buyer. */
524
+ buyerLabel: string;
525
+ }
472
526
  /** Cart status. Only an `open` cart can change. */
473
527
  type CartStatus = 'open' | 'ordered' | 'expired';
474
528
  /** A priced cart line. Prices are always computed server-side. */
@@ -484,6 +538,11 @@ interface CartLine {
484
538
  variantId: string;
485
539
  /** Units, 1–99. */
486
540
  quantity: number;
541
+ /**
542
+ * The campaign discount on this line's goods, minor units. Absent on
543
+ * older APIs: the SDK reads it as 0.
544
+ */
545
+ discountMinor: number;
487
546
  /**
488
547
  * The buyer's text for this line, or null. Required: older servers omit
489
548
  * it (treat it as null there).
@@ -567,10 +626,45 @@ interface Cart {
567
626
  lines: CartLine[];
568
627
  /** Sum of line totals, minor units. */
569
628
  subtotalMinor: number;
570
- /** Shipping price, minor units. */
629
+ /**
630
+ * Campaign discount on the goods (the sum of the line discounts), minor
631
+ * units. Absent on older APIs: the SDK reads it as 0.
632
+ */
633
+ discountMinor: number;
634
+ /** Shipping price before any shipping discount, minor units. */
571
635
  shippingMinor: number;
572
- /** Total to pay, minor units. */
636
+ /**
637
+ * Campaign discount on the shipping price, minor units. Absent on older
638
+ * APIs: the SDK reads it as 0.
639
+ */
640
+ shippingDiscountMinor: number;
641
+ /**
642
+ * Total to pay, minor units: subtotal - discount + shipping - shipping
643
+ * discount.
644
+ */
573
645
  totalMinor: number;
646
+ /**
647
+ * The campaigns that discount this cart. Absent on older APIs: the SDK
648
+ * reads it as `[]`.
649
+ */
650
+ appliedCampaigns: AppliedCampaign[];
651
+ /**
652
+ * Campaigns that wait for the buyer's details at checkout (first order,
653
+ * per-customer limit, customer tier); not applied yet. Absent on older
654
+ * APIs: the SDK reads it as `[]`.
655
+ */
656
+ pendingCampaigns: PendingCampaign[];
657
+ /**
658
+ * The coupon code entered on the cart, or null. Absent on older APIs:
659
+ * the SDK reads it as null.
660
+ */
661
+ couponCode: string | null;
662
+ /**
663
+ * Why the entered code does not discount this cart now, or null (it
664
+ * applies, or no code is entered). Absent on older APIs: the SDK reads it
665
+ * as null.
666
+ */
667
+ codeReason: CouponReason | null;
574
668
  /** The selected shipping option id, or null when none (or no longer offered). */
575
669
  shippingOption: string | null;
576
670
  /** The buyer, or null before `setCustomer`. */
@@ -734,8 +828,13 @@ interface OrderLine {
734
828
  unitPriceMinor: number;
735
829
  /** Units. */
736
830
  quantity: number;
737
- /** Line total, minor units. */
831
+ /** Line total before the discount, minor units. */
738
832
  lineTotalMinor: number;
833
+ /**
834
+ * The campaign discount on this line, minor units (what a partial return
835
+ * of the line refunds less). Absent on older APIs: the SDK reads it as 0.
836
+ */
837
+ discountMinor: number;
739
838
  /** The buyer's text for this line; absent or null when there is none. */
740
839
  personalization?: string | null;
741
840
  /**
@@ -770,9 +869,15 @@ interface Order {
770
869
  currency: string;
771
870
  /** Subtotal, minor units. */
772
871
  subtotalMinor: number;
773
- /** Shipping, minor units. */
872
+ /** Shipping before any shipping discount, minor units. */
774
873
  shippingMinor: number;
775
- /** Total, minor units. */
874
+ /** Campaign discount on the goods, minor units. Absent on older APIs: the SDK reads it as 0. */
875
+ discountMinor: number;
876
+ /** Campaign discount on shipping, minor units. Absent on older APIs: the SDK reads it as 0. */
877
+ shippingDiscountMinor: number;
878
+ /** The campaigns that applied. Absent on older APIs: the SDK reads it as `[]`. */
879
+ appliedCampaigns: AppliedCampaign[];
880
+ /** Total paid, minor units. */
776
881
  totalMinor: number;
777
882
  /** When the order was placed (ISO date), or null. */
778
883
  placedAt: string | null;
@@ -1086,6 +1191,15 @@ interface StorefrontClient {
1086
1191
  updateLine(cartId: string, lineId: string, input: UpdateLineInput, options?: RequestOptions): Promise<Cart>;
1087
1192
  /** `DELETE /v1/carts/:id/lines/:lineId`: removes a line (`CartLine.id`). */
1088
1193
  removeLine(cartId: string, lineId: string, options?: RequestOptions): Promise<Cart>;
1194
+ /**
1195
+ * `PUT /v1/carts/:id/coupon`: enters a coupon code on the cart (one per
1196
+ * cart: a second replaces the first) and answers the cart priced with
1197
+ * it. Rejects `coupon_invalid` (422, `details.reason`: `unknown` or
1198
+ * `used_up`); the cart keeps its previous code then.
1199
+ */
1200
+ applyCode(cartId: string, code: string, options?: RequestOptions): Promise<Cart>;
1201
+ /** `DELETE /v1/carts/:id/coupon`: removes the cart's code. */
1202
+ removeCode(cartId: string, options?: RequestOptions): Promise<Cart>;
1089
1203
  /** `PUT /v1/carts/:id/customer`: sets the buyer. */
1090
1204
  setCustomer(cartId: string, input: CustomerInput, options?: RequestOptions): Promise<Cart>;
1091
1205
  /** `PUT /v1/carts/:id/address`: sets the shipping (and billing) address. */
@@ -1244,9 +1358,27 @@ interface StorefrontErrorDetailsMap {
1244
1358
  cart_changed: {
1245
1359
  lines: CartLine[];
1246
1360
  subtotalMinor: number;
1361
+ /** Goods discount, minor units (0 when absent). */
1362
+ discountMinor: number;
1247
1363
  shippingMinor: number;
1364
+ /** Shipping discount, minor units (0 when absent). */
1365
+ shippingDiscountMinor: number;
1248
1366
  totalMinor: number;
1249
1367
  shippingOptions: ShippingOption[];
1368
+ /** Campaigns that discount the cart now (`[]` when absent). */
1369
+ appliedCampaigns: AppliedCampaign[];
1370
+ /** Campaigns waiting for the buyer's details (`[]` when absent). */
1371
+ pendingCampaigns: PendingCampaign[];
1372
+ /** Why the entered code does not apply now, or null. */
1373
+ codeReason: CouponReason | null;
1374
+ };
1375
+ /**
1376
+ * `carts.applyCode` refused the code (422): `unknown` (no active campaign
1377
+ * has it) or `used_up` (a single-use code already taken, or its limit
1378
+ * reached). Let the buyer try another code.
1379
+ */
1380
+ coupon_invalid: {
1381
+ reason: 'unknown' | 'used_up';
1250
1382
  };
1251
1383
  /**
1252
1384
  * A personalization text is refused (400, no details) or, at checkout
@@ -1307,7 +1439,7 @@ interface StorefrontErrorDetailsMap {
1307
1439
  };
1308
1440
  }
1309
1441
  /** Error codes of the Storefront API (the `error` field of an error response). */
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';
1442
+ 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' | 'coupon_invalid' | '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';
1311
1443
  /**
1312
1444
  * Codes the SDK assigns itself:
1313
1445
  * - `rate_limited` — HTTP 429 without a known `error` code (the throttler);
@@ -1562,6 +1694,6 @@ interface TurnstileWidget {
1562
1694
  declare function renderTurnstile(element: HTMLElement, siteKey: string, options: RenderTurnstileOptions): Promise<TurnstileWidget>;
1563
1695
 
1564
1696
  /** Version of the Storefront SDK package. */
1565
- declare const SDK_VERSION = "0.9.0";
1697
+ declare const SDK_VERSION = "0.10.0";
1566
1698
 
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 };
1699
+ export { type Account, type AccountOrder, type AccountProfileInput, type AccountSession, type AdPixels, type AddLineInput, type Address, type AddressInput, type AgreementsQuote, type AnyStorefrontError, type AppliedCampaign, 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 CouponReason, 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 PendingCampaign, 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
@@ -275,6 +275,26 @@ interface CartAgreements {
275
275
  documents: LegalDocument[];
276
276
  /** Hash of the shown texts (64 hex characters). Checkout refuses a stale one. */
277
277
  agreementsHash: string;
278
+ /**
279
+ * The totals the documents were filled with, for this buyer: conditions
280
+ * that need the buyer (first order, per-customer limit) are evaluated, so
281
+ * a first-order discount shows its amount or its `codeReason`, and
282
+ * `pendingCampaigns` is empty. Show these at the review step instead of the
283
+ * cart's buyer-free totals. Null on APIs older than 0.10.0's server side
284
+ * (show the cart's totals then).
285
+ */
286
+ quote: AgreementsQuote | null;
287
+ }
288
+ /** {@link CartAgreements.quote}: the same shapes as on {@link Cart}. */
289
+ interface AgreementsQuote {
290
+ subtotalMinor: number;
291
+ discountMinor: number;
292
+ shippingMinor: number;
293
+ shippingDiscountMinor: number;
294
+ totalMinor: number;
295
+ appliedCampaigns: AppliedCampaign[];
296
+ pendingCampaigns: PendingCampaign[];
297
+ codeReason: CouponReason | null;
278
298
  }
279
299
  /** The ad pixels a store configured (ids are validated by the API). */
280
300
  interface AdPixels {
@@ -350,6 +370,12 @@ interface Store {
350
370
  * API versions. Treat absent or null as "show no checkbox".
351
371
  */
352
372
  marketingConsent?: MarketingConsentText | null;
373
+ /**
374
+ * Whether the store has an active campaign triggered by a code. Offer the
375
+ * code field only when true. Absent on older API versions: read as `true`,
376
+ * so a storefront keeps offering the field there.
377
+ */
378
+ hasCodeCampaigns: boolean;
353
379
  }
354
380
  /** The marketing consent text served in `Store.marketingConsent`. */
355
381
  interface MarketingConsentText {
@@ -469,6 +495,34 @@ interface ProductListQuery {
469
495
  /** Items per page (default 20, 1–100). */
470
496
  pageSize?: number;
471
497
  }
498
+ /**
499
+ * Why an entered coupon code (or a campaign) did not apply:
500
+ * - `unknown`: no active campaign has this code;
501
+ * - `used_up`: a single-use code already taken, or a usage limit reached;
502
+ * - `expired` / `not_started`: outside the campaign's dates;
503
+ * - `min_subtotal`: the goods subtotal is below the campaign's minimum;
504
+ * - `first_order_only`: the campaign is for a buyer's first order;
505
+ * - `not_combinable_better`: a better campaign that cannot combine applies.
506
+ */
507
+ type CouponReason = 'expired' | 'not_started' | 'min_subtotal' | 'first_order_only' | 'used_up' | 'not_combinable_better' | 'unknown';
508
+ /** A campaign that discounted a cart or an order, as the buyer sees it. */
509
+ interface AppliedCampaign {
510
+ /** The campaign id. Present on a cart; absent on an order. */
511
+ campaignId?: string;
512
+ /** The label to show the buyer (e.g. "10% off your first order"). */
513
+ buyerLabel: string;
514
+ /** Goods discount this campaign gave, minor units. */
515
+ discountMinor: number;
516
+ /** Shipping discount this campaign gave, minor units. */
517
+ shippingDiscountMinor: number;
518
+ }
519
+ /** A campaign that waits for the buyer's details (checkout); not applied yet. */
520
+ interface PendingCampaign {
521
+ /** The campaign id. */
522
+ campaignId?: string;
523
+ /** The label to show the buyer. */
524
+ buyerLabel: string;
525
+ }
472
526
  /** Cart status. Only an `open` cart can change. */
473
527
  type CartStatus = 'open' | 'ordered' | 'expired';
474
528
  /** A priced cart line. Prices are always computed server-side. */
@@ -484,6 +538,11 @@ interface CartLine {
484
538
  variantId: string;
485
539
  /** Units, 1–99. */
486
540
  quantity: number;
541
+ /**
542
+ * The campaign discount on this line's goods, minor units. Absent on
543
+ * older APIs: the SDK reads it as 0.
544
+ */
545
+ discountMinor: number;
487
546
  /**
488
547
  * The buyer's text for this line, or null. Required: older servers omit
489
548
  * it (treat it as null there).
@@ -567,10 +626,45 @@ interface Cart {
567
626
  lines: CartLine[];
568
627
  /** Sum of line totals, minor units. */
569
628
  subtotalMinor: number;
570
- /** Shipping price, minor units. */
629
+ /**
630
+ * Campaign discount on the goods (the sum of the line discounts), minor
631
+ * units. Absent on older APIs: the SDK reads it as 0.
632
+ */
633
+ discountMinor: number;
634
+ /** Shipping price before any shipping discount, minor units. */
571
635
  shippingMinor: number;
572
- /** Total to pay, minor units. */
636
+ /**
637
+ * Campaign discount on the shipping price, minor units. Absent on older
638
+ * APIs: the SDK reads it as 0.
639
+ */
640
+ shippingDiscountMinor: number;
641
+ /**
642
+ * Total to pay, minor units: subtotal - discount + shipping - shipping
643
+ * discount.
644
+ */
573
645
  totalMinor: number;
646
+ /**
647
+ * The campaigns that discount this cart. Absent on older APIs: the SDK
648
+ * reads it as `[]`.
649
+ */
650
+ appliedCampaigns: AppliedCampaign[];
651
+ /**
652
+ * Campaigns that wait for the buyer's details at checkout (first order,
653
+ * per-customer limit, customer tier); not applied yet. Absent on older
654
+ * APIs: the SDK reads it as `[]`.
655
+ */
656
+ pendingCampaigns: PendingCampaign[];
657
+ /**
658
+ * The coupon code entered on the cart, or null. Absent on older APIs:
659
+ * the SDK reads it as null.
660
+ */
661
+ couponCode: string | null;
662
+ /**
663
+ * Why the entered code does not discount this cart now, or null (it
664
+ * applies, or no code is entered). Absent on older APIs: the SDK reads it
665
+ * as null.
666
+ */
667
+ codeReason: CouponReason | null;
574
668
  /** The selected shipping option id, or null when none (or no longer offered). */
575
669
  shippingOption: string | null;
576
670
  /** The buyer, or null before `setCustomer`. */
@@ -734,8 +828,13 @@ interface OrderLine {
734
828
  unitPriceMinor: number;
735
829
  /** Units. */
736
830
  quantity: number;
737
- /** Line total, minor units. */
831
+ /** Line total before the discount, minor units. */
738
832
  lineTotalMinor: number;
833
+ /**
834
+ * The campaign discount on this line, minor units (what a partial return
835
+ * of the line refunds less). Absent on older APIs: the SDK reads it as 0.
836
+ */
837
+ discountMinor: number;
739
838
  /** The buyer's text for this line; absent or null when there is none. */
740
839
  personalization?: string | null;
741
840
  /**
@@ -770,9 +869,15 @@ interface Order {
770
869
  currency: string;
771
870
  /** Subtotal, minor units. */
772
871
  subtotalMinor: number;
773
- /** Shipping, minor units. */
872
+ /** Shipping before any shipping discount, minor units. */
774
873
  shippingMinor: number;
775
- /** Total, minor units. */
874
+ /** Campaign discount on the goods, minor units. Absent on older APIs: the SDK reads it as 0. */
875
+ discountMinor: number;
876
+ /** Campaign discount on shipping, minor units. Absent on older APIs: the SDK reads it as 0. */
877
+ shippingDiscountMinor: number;
878
+ /** The campaigns that applied. Absent on older APIs: the SDK reads it as `[]`. */
879
+ appliedCampaigns: AppliedCampaign[];
880
+ /** Total paid, minor units. */
776
881
  totalMinor: number;
777
882
  /** When the order was placed (ISO date), or null. */
778
883
  placedAt: string | null;
@@ -1086,6 +1191,15 @@ interface StorefrontClient {
1086
1191
  updateLine(cartId: string, lineId: string, input: UpdateLineInput, options?: RequestOptions): Promise<Cart>;
1087
1192
  /** `DELETE /v1/carts/:id/lines/:lineId`: removes a line (`CartLine.id`). */
1088
1193
  removeLine(cartId: string, lineId: string, options?: RequestOptions): Promise<Cart>;
1194
+ /**
1195
+ * `PUT /v1/carts/:id/coupon`: enters a coupon code on the cart (one per
1196
+ * cart: a second replaces the first) and answers the cart priced with
1197
+ * it. Rejects `coupon_invalid` (422, `details.reason`: `unknown` or
1198
+ * `used_up`); the cart keeps its previous code then.
1199
+ */
1200
+ applyCode(cartId: string, code: string, options?: RequestOptions): Promise<Cart>;
1201
+ /** `DELETE /v1/carts/:id/coupon`: removes the cart's code. */
1202
+ removeCode(cartId: string, options?: RequestOptions): Promise<Cart>;
1089
1203
  /** `PUT /v1/carts/:id/customer`: sets the buyer. */
1090
1204
  setCustomer(cartId: string, input: CustomerInput, options?: RequestOptions): Promise<Cart>;
1091
1205
  /** `PUT /v1/carts/:id/address`: sets the shipping (and billing) address. */
@@ -1244,9 +1358,27 @@ interface StorefrontErrorDetailsMap {
1244
1358
  cart_changed: {
1245
1359
  lines: CartLine[];
1246
1360
  subtotalMinor: number;
1361
+ /** Goods discount, minor units (0 when absent). */
1362
+ discountMinor: number;
1247
1363
  shippingMinor: number;
1364
+ /** Shipping discount, minor units (0 when absent). */
1365
+ shippingDiscountMinor: number;
1248
1366
  totalMinor: number;
1249
1367
  shippingOptions: ShippingOption[];
1368
+ /** Campaigns that discount the cart now (`[]` when absent). */
1369
+ appliedCampaigns: AppliedCampaign[];
1370
+ /** Campaigns waiting for the buyer's details (`[]` when absent). */
1371
+ pendingCampaigns: PendingCampaign[];
1372
+ /** Why the entered code does not apply now, or null. */
1373
+ codeReason: CouponReason | null;
1374
+ };
1375
+ /**
1376
+ * `carts.applyCode` refused the code (422): `unknown` (no active campaign
1377
+ * has it) or `used_up` (a single-use code already taken, or its limit
1378
+ * reached). Let the buyer try another code.
1379
+ */
1380
+ coupon_invalid: {
1381
+ reason: 'unknown' | 'used_up';
1250
1382
  };
1251
1383
  /**
1252
1384
  * A personalization text is refused (400, no details) or, at checkout
@@ -1307,7 +1439,7 @@ interface StorefrontErrorDetailsMap {
1307
1439
  };
1308
1440
  }
1309
1441
  /** Error codes of the Storefront API (the `error` field of an error response). */
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';
1442
+ 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' | 'coupon_invalid' | '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';
1311
1443
  /**
1312
1444
  * Codes the SDK assigns itself:
1313
1445
  * - `rate_limited` — HTTP 429 without a known `error` code (the throttler);
@@ -1562,6 +1694,6 @@ interface TurnstileWidget {
1562
1694
  declare function renderTurnstile(element: HTMLElement, siteKey: string, options: RenderTurnstileOptions): Promise<TurnstileWidget>;
1563
1695
 
1564
1696
  /** Version of the Storefront SDK package. */
1565
- declare const SDK_VERSION = "0.9.0";
1697
+ declare const SDK_VERSION = "0.10.0";
1566
1698
 
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 };
1699
+ export { type Account, type AccountOrder, type AccountProfileInput, type AccountSession, type AdPixels, type AddLineInput, type Address, type AddressInput, type AgreementsQuote, type AnyStorefrontError, type AppliedCampaign, 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 CouponReason, 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 PendingCampaign, 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 };