@usethrottle/cart 3.16.0 → 3.17.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 CHANGED
@@ -460,6 +460,15 @@ resolvable base returns `400 image_url_unresolvable`.
460
460
  | `timeoutMs` | `30000` | Per-request abort timeout in ms. |
461
461
  | `fetch` | `globalThis.fetch` | Custom fetch implementation (e.g. `node-fetch`). |
462
462
 
463
+ ## Money
464
+
465
+ Amounts are integers in the record's minor unit. Show them with
466
+ `formatMoney(amount, cart.currency)`: this package re-exports
467
+ `@usethrottle/money` as `money` and `formatMoney` by name, plus the
468
+ `CurrencyCode` and `MoneyValue` types. `CartSessionClient.absorb(...)` is not
469
+ provided; switch currency with `POST /api/v1/cart-sessions/:id/absorb` (see the
470
+ cart-sessions docs).
471
+
463
472
  ## See also
464
473
 
465
474
  - [Checkout SDK: `@usethrottle/checkout-sdk`](https://www.npmjs.com/package/@usethrottle/checkout-sdk)
package/dist/index.cjs CHANGED
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
5
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
8
  var __export = (target, all) => {
7
9
  for (var name in all)
@@ -15,12 +17,21 @@ var __copyProps = (to, from, except, desc) => {
15
17
  }
16
18
  return to;
17
19
  };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
18
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
29
 
20
30
  // src/index.ts
21
31
  var index_exports = {};
22
32
  __export(index_exports, {
23
33
  AmountTooLargeError: () => AmountTooLargeError,
34
+ CURRENCIES: () => import_money.CURRENCIES,
24
35
  CartChangedError: () => CartChangedError,
25
36
  CartClient: () => CartClient,
26
37
  CartNotFoundError: () => CartNotFoundError,
@@ -28,7 +39,10 @@ __export(index_exports, {
28
39
  CartPricesChangedError: () => CartPricesChangedError,
29
40
  CartSessionClient: () => CartSessionClient,
30
41
  CartTimeoutError: () => CartTimeoutError,
42
+ CurrencyLockedError: () => CurrencyLockedError,
43
+ CurrencyNotAvailableInProductionError: () => CurrencyNotAvailableInProductionError,
31
44
  CurrencyNotEnabledError: () => CurrencyNotEnabledError,
45
+ CurrencyNotSupportedError: () => CurrencyNotSupportedError,
32
46
  DiscountCurrencyUnsupportedError: () => DiscountCurrencyUnsupportedError,
33
47
  LineLimitReachedError: () => LineLimitReachedError,
34
48
  LineNotPurchasableError: () => LineNotPurchasableError,
@@ -36,6 +50,7 @@ __export(index_exports, {
36
50
  LineResolverUnavailableError: () => LineResolverUnavailableError,
37
51
  PriceLockedError: () => PriceLockedError,
38
52
  QuantityUnavailableError: () => QuantityUnavailableError,
53
+ QuoteAmountsNeedReviewError: () => QuoteAmountsNeedReviewError,
39
54
  ResolvedLinesRequiredError: () => ResolvedLinesRequiredError,
40
55
  ShippingCurrencyUnsupportedError: () => ShippingCurrencyUnsupportedError,
41
56
  ShippingMethodUnavailableError: () => ShippingMethodUnavailableError,
@@ -43,8 +58,18 @@ __export(index_exports, {
43
58
  StorefrontQuoteClient: () => StorefrontQuoteClient,
44
59
  ThrottleApiError: () => ThrottleApiError,
45
60
  ThrottleError: () => import_errors2.ThrottleError,
61
+ UnknownCurrencyError: () => import_money.UnknownCurrencyError,
46
62
  cartErrorFromResponse: () => cartErrorFromResponse,
47
- isThrottleError: () => import_errors2.isThrottleError
63
+ currencySymbol: () => import_money.currencySymbol,
64
+ formatMoney: () => import_money.formatMoney,
65
+ isKnownCurrency: () => import_money.isKnownCurrency,
66
+ isThrottleError: () => import_errors2.isThrottleError,
67
+ minorUnitsOf: () => import_money.minorUnitsOf,
68
+ money: () => money,
69
+ moneyValue: () => import_money.moneyValue,
70
+ parseMoney: () => import_money.parseMoney,
71
+ toDecimalString: () => import_money.toDecimalString,
72
+ toMinor: () => import_money.toMinor
48
73
  });
49
74
  module.exports = __toCommonJS(index_exports);
50
75
 
@@ -216,6 +241,30 @@ var ShippingCurrencyUnsupportedError = class extends ThrottleApiError {
216
241
  this.shipping = d?.shipping && typeof d.shipping === "object" ? d.shipping : null;
217
242
  }
218
243
  };
244
+ var CurrencyNotSupportedError = class extends ThrottleApiError {
245
+ constructor(args) {
246
+ super(coded("currency_not_supported", 422, args));
247
+ this.name = "CurrencyNotSupportedError";
248
+ }
249
+ };
250
+ var CurrencyNotAvailableInProductionError = class extends ThrottleApiError {
251
+ constructor(args) {
252
+ super(coded("currency_not_available_in_production", 422, args));
253
+ this.name = "CurrencyNotAvailableInProductionError";
254
+ }
255
+ };
256
+ var CurrencyLockedError = class extends ThrottleApiError {
257
+ constructor(args) {
258
+ super(coded("currency_locked", 409, args));
259
+ this.name = "CurrencyLockedError";
260
+ }
261
+ };
262
+ var QuoteAmountsNeedReviewError = class extends ThrottleApiError {
263
+ constructor(args) {
264
+ super(coded("quote_amounts_need_review", 422, args));
265
+ this.name = "QuoteAmountsNeedReviewError";
266
+ }
267
+ };
219
268
  var RESOLVED_CART_ERRORS = {
220
269
  price_locked: PriceLockedError,
221
270
  quantity_unavailable: QuantityUnavailableError,
@@ -231,7 +280,11 @@ var RESOLVED_CART_ERRORS = {
231
280
  amount_too_large: AmountTooLargeError,
232
281
  cart_changed: CartChangedError,
233
282
  discount_currency_unsupported: DiscountCurrencyUnsupportedError,
234
- shipping_currency_unsupported: ShippingCurrencyUnsupportedError
283
+ shipping_currency_unsupported: ShippingCurrencyUnsupportedError,
284
+ currency_not_supported: CurrencyNotSupportedError,
285
+ currency_not_available_in_production: CurrencyNotAvailableInProductionError,
286
+ currency_locked: CurrencyLockedError,
287
+ quote_amounts_need_review: QuoteAmountsNeedReviewError
235
288
  };
236
289
  function cartErrorFromResponse(args) {
237
290
  if (args.statusCode === 409 && args.code === "cart_not_open") {
@@ -635,9 +688,14 @@ var CartSessionClient = class _CartSessionClient {
635
688
  }
636
689
  }
637
690
  };
691
+
692
+ // src/index.ts
693
+ var money = __toESM(require("@usethrottle/money"), 1);
694
+ var import_money = require("@usethrottle/money");
638
695
  // Annotate the CommonJS export names for ESM import in node:
639
696
  0 && (module.exports = {
640
697
  AmountTooLargeError,
698
+ CURRENCIES,
641
699
  CartChangedError,
642
700
  CartClient,
643
701
  CartNotFoundError,
@@ -645,7 +703,10 @@ var CartSessionClient = class _CartSessionClient {
645
703
  CartPricesChangedError,
646
704
  CartSessionClient,
647
705
  CartTimeoutError,
706
+ CurrencyLockedError,
707
+ CurrencyNotAvailableInProductionError,
648
708
  CurrencyNotEnabledError,
709
+ CurrencyNotSupportedError,
649
710
  DiscountCurrencyUnsupportedError,
650
711
  LineLimitReachedError,
651
712
  LineNotPurchasableError,
@@ -653,6 +714,7 @@ var CartSessionClient = class _CartSessionClient {
653
714
  LineResolverUnavailableError,
654
715
  PriceLockedError,
655
716
  QuantityUnavailableError,
717
+ QuoteAmountsNeedReviewError,
656
718
  ResolvedLinesRequiredError,
657
719
  ShippingCurrencyUnsupportedError,
658
720
  ShippingMethodUnavailableError,
@@ -660,6 +722,16 @@ var CartSessionClient = class _CartSessionClient {
660
722
  StorefrontQuoteClient,
661
723
  ThrottleApiError,
662
724
  ThrottleError,
725
+ UnknownCurrencyError,
663
726
  cartErrorFromResponse,
664
- isThrottleError
727
+ currencySymbol,
728
+ formatMoney,
729
+ isKnownCurrency,
730
+ isThrottleError,
731
+ minorUnitsOf,
732
+ money,
733
+ moneyValue,
734
+ parseMoney,
735
+ toDecimalString,
736
+ toMinor
665
737
  });
package/dist/index.d.cts CHANGED
@@ -1,3 +1,7 @@
1
+ import { CurrencyCode } from '@usethrottle/money';
2
+ import * as money from '@usethrottle/money';
3
+ export { money };
4
+ export { CURRENCIES, CurrencyCode, MoneyValue, UnknownCurrencyError, currencySymbol, formatMoney, isKnownCurrency, minorUnitsOf, moneyValue, parseMoney, toDecimalString, toMinor } from '@usethrottle/money';
1
5
  import { ThrottleError, ThrottleErrorArgs } from '@usethrottle/errors';
2
6
  export { ThrottleError, isThrottleError } from '@usethrottle/errors';
3
7
 
@@ -37,7 +41,7 @@ interface Cart {
37
41
  /** Lightweight captured email (no full customer record), or null. */
38
42
  customerEmail: string | null;
39
43
  status: 'open' | 'checkout' | 'converted' | 'abandoned';
40
- currency: string;
44
+ currency: CurrencyCode;
41
45
  subtotal: number;
42
46
  taxTotal: number;
43
47
  discountTotal: number;
@@ -229,7 +233,7 @@ interface SelectedShipping {
229
233
  serviceCode: string | null;
230
234
  displayName: string;
231
235
  rateAmount: number;
232
- currency: string;
236
+ currency: CurrencyCode;
233
237
  estimatedDeliveryDays: number | null;
234
238
  }
235
239
  interface AppliedDiscount {
@@ -237,7 +241,7 @@ interface AppliedDiscount {
237
241
  code: string;
238
242
  type: 'percentage' | 'fixed_amount';
239
243
  amount: number;
240
- currency: string;
244
+ currency: CurrencyCode;
241
245
  freeShipping: boolean;
242
246
  validUntil: string | null;
243
247
  snapshotHash: string;
@@ -256,7 +260,7 @@ interface TaxLine {
256
260
  rateTypeCode?: string | null;
257
261
  rate: number;
258
262
  amount: number;
259
- currency: string;
263
+ currency: CurrencyCode;
260
264
  }
261
265
  interface CartEvent {
262
266
  id: string;
@@ -383,7 +387,7 @@ interface Order {
383
387
  id: string;
384
388
  status: string;
385
389
  total: number;
386
- currency: string;
390
+ currency: CurrencyCode;
387
391
  }
388
392
  interface ShippingTaxAddress {
389
393
  countryCode?: string;
@@ -438,7 +442,7 @@ interface ShippingTaxMethod {
438
442
  type?: 'ship' | 'pickup';
439
443
  label: string;
440
444
  amount: number;
441
- currency: string;
445
+ currency: CurrencyCode;
442
446
  deliveryWindowLabel?: string | null;
443
447
  deliveryMinDays?: number | null;
444
448
  deliveryMaxDays?: number | null;
@@ -455,7 +459,7 @@ interface ShippingTaxCalculationResponse {
455
459
  source: 'off' | 'byo' | 'calculated' | 'app_based' | 'external_push';
456
460
  applicationId: string;
457
461
  workspaceId?: string;
458
- currency: string;
462
+ currency: CurrencyCode;
459
463
  configId?: string;
460
464
  configVersion?: number;
461
465
  shippingRequired: boolean;
@@ -715,7 +719,7 @@ interface CartSessionSummary {
715
719
  /** Cart total in minor units, or `0` on a finished session. */
716
720
  total: number;
717
721
  /** `null` on a finished session — there is no live cart to price. */
718
- currency: string | null;
722
+ currency: CurrencyCode | null;
719
723
  }
720
724
  interface CheckoutHandoffInput {
721
725
  returnUrl: string;
@@ -981,8 +985,8 @@ declare class LineResolverNotAvailableError extends ThrottleApiError {
981
985
  }
982
986
  /** `details` of `422 currency_not_enabled`. */
983
987
  type CurrencyNotEnabledDetails = {
984
- currency: string;
985
- enabledCurrencies: string[];
988
+ currency: CurrencyCode;
989
+ enabledCurrencies: CurrencyCode[];
986
990
  };
987
991
  /**
988
992
  * `422 currency_not_enabled`: a resolved cart must use the environment's
@@ -1078,6 +1082,31 @@ declare class ShippingCurrencyUnsupportedError extends ThrottleApiError {
1078
1082
  readonly shipping: CartShippingChange | null;
1079
1083
  constructor(args: CartErrorArgs);
1080
1084
  }
1085
+ /**
1086
+ * `422 currency_not_supported`: the code is not a supported ISO 4217 currency.
1087
+ * `details` is `{ currency, enabledCurrencies }`.
1088
+ */
1089
+ declare class CurrencyNotSupportedError extends ThrottleApiError {
1090
+ constructor(args: CartErrorArgs);
1091
+ }
1092
+ /**
1093
+ * `422 currency_not_available_in_production`: the production environment does
1094
+ * not accept this currency yet. `details` is `{ currency, enabledCurrencies }`.
1095
+ */
1096
+ declare class CurrencyNotAvailableInProductionError extends ThrottleApiError {
1097
+ constructor(args: CartErrorArgs);
1098
+ }
1099
+ /** `409 currency_locked`: the main currency can't change after the first production sale. */
1100
+ declare class CurrencyLockedError extends ThrottleApiError {
1101
+ constructor(args: CartErrorArgs);
1102
+ }
1103
+ /**
1104
+ * `422 quote_amounts_need_review`: amounts typed before the quote's currency
1105
+ * changed must be confirmed before it is issued. `details.pending` lists them.
1106
+ */
1107
+ declare class QuoteAmountsNeedReviewError extends ThrottleApiError {
1108
+ constructor(args: CartErrorArgs);
1109
+ }
1081
1110
  /**
1082
1111
  * Map a raw API error envelope to the most specific Cart SDK error class.
1083
1112
  * Falls back to {@link ThrottleApiError} for everything unrecognised.
@@ -1090,4 +1119,4 @@ declare function cartErrorFromResponse(args: {
1090
1119
  responseHeaders?: ThrottleErrorArgs['responseHeaders'];
1091
1120
  }): ThrottleApiError;
1092
1121
 
1093
- export { type AddLineItemInput, type AddResolvedLineItemInput, AmountTooLargeError, type AppliedDiscount, type Cart, type CartAddress, type CartBranding, CartChangedError, CartClient, type CartErrorArgs, type CartEvent, CartNotFoundError, CartNotOpenError, type CartPricesChangedDetails, CartPricesChangedError, type CartSession, type CartSessionCart, CartSessionClient, type CartSessionClientOptions, type CartSessionSummary, type CartShippingChange, CartTimeoutError, type CheckoutHandoff, type CheckoutHandoffInput, type CheckoutInput, type CreateCartInput, type CreateCartSessionInput, type CurrencyNotEnabledDetails, CurrencyNotEnabledError, DiscountCurrencyUnsupportedError, type ExternalShippingTaxSnapshotInput, type LegacyLineRecurring, type LineItem, type LineLimitReachedDetails, LineLimitReachedError, type LineNotPurchasableDetails, LineNotPurchasableError, type LineRecurringInput, type LineResolution, type LineResolverNotAvailableDetails, LineResolverNotAvailableError, type LineResolverUnavailableDetails, LineResolverUnavailableError, type Order, type PriceLockedDetails, PriceLockedError, type QuantityUnavailableDetails, QuantityUnavailableError, type RefusedCartLine, ResolvedLinesRequiredError, type SelectShippingInput, type SelectShippingMethodInput, type SelectedShipping, ShippingCurrencyUnsupportedError, ShippingMethodUnavailableError, ShippingQuoteUnavailableError, type ShippingTaxAddress, type ShippingTaxCalculationResponse, type ShippingTaxCartCalculateInput, type ShippingTaxMethod, type ShippingTaxQuoteInput, type ShippingTaxQuoteItem, type StoredLineRecurring, StorefrontQuoteClient, type SubscriptionInterval, type SubscriptionIntervalUnit, type TaxLine, type TaxLineInput, ThrottleApiError, type UpdateCartInput, type UpdateCartSessionInput, type UpdateLineItemInput, cartErrorFromResponse };
1122
+ export { type AddLineItemInput, type AddResolvedLineItemInput, AmountTooLargeError, type AppliedDiscount, type Cart, type CartAddress, type CartBranding, CartChangedError, CartClient, type CartErrorArgs, type CartEvent, CartNotFoundError, CartNotOpenError, type CartPricesChangedDetails, CartPricesChangedError, type CartSession, type CartSessionCart, CartSessionClient, type CartSessionClientOptions, type CartSessionSummary, type CartShippingChange, CartTimeoutError, type CheckoutHandoff, type CheckoutHandoffInput, type CheckoutInput, type CreateCartInput, type CreateCartSessionInput, CurrencyLockedError, CurrencyNotAvailableInProductionError, type CurrencyNotEnabledDetails, CurrencyNotEnabledError, CurrencyNotSupportedError, DiscountCurrencyUnsupportedError, type ExternalShippingTaxSnapshotInput, type LegacyLineRecurring, type LineItem, type LineLimitReachedDetails, LineLimitReachedError, type LineNotPurchasableDetails, LineNotPurchasableError, type LineRecurringInput, type LineResolution, type LineResolverNotAvailableDetails, LineResolverNotAvailableError, type LineResolverUnavailableDetails, LineResolverUnavailableError, type Order, type PriceLockedDetails, PriceLockedError, type QuantityUnavailableDetails, QuantityUnavailableError, QuoteAmountsNeedReviewError, type RefusedCartLine, ResolvedLinesRequiredError, type SelectShippingInput, type SelectShippingMethodInput, type SelectedShipping, ShippingCurrencyUnsupportedError, ShippingMethodUnavailableError, ShippingQuoteUnavailableError, type ShippingTaxAddress, type ShippingTaxCalculationResponse, type ShippingTaxCartCalculateInput, type ShippingTaxMethod, type ShippingTaxQuoteInput, type ShippingTaxQuoteItem, type StoredLineRecurring, StorefrontQuoteClient, type SubscriptionInterval, type SubscriptionIntervalUnit, type TaxLine, type TaxLineInput, ThrottleApiError, type UpdateCartInput, type UpdateCartSessionInput, type UpdateLineItemInput, cartErrorFromResponse };
package/dist/index.d.ts CHANGED
@@ -1,3 +1,7 @@
1
+ import { CurrencyCode } from '@usethrottle/money';
2
+ import * as money from '@usethrottle/money';
3
+ export { money };
4
+ export { CURRENCIES, CurrencyCode, MoneyValue, UnknownCurrencyError, currencySymbol, formatMoney, isKnownCurrency, minorUnitsOf, moneyValue, parseMoney, toDecimalString, toMinor } from '@usethrottle/money';
1
5
  import { ThrottleError, ThrottleErrorArgs } from '@usethrottle/errors';
2
6
  export { ThrottleError, isThrottleError } from '@usethrottle/errors';
3
7
 
@@ -37,7 +41,7 @@ interface Cart {
37
41
  /** Lightweight captured email (no full customer record), or null. */
38
42
  customerEmail: string | null;
39
43
  status: 'open' | 'checkout' | 'converted' | 'abandoned';
40
- currency: string;
44
+ currency: CurrencyCode;
41
45
  subtotal: number;
42
46
  taxTotal: number;
43
47
  discountTotal: number;
@@ -229,7 +233,7 @@ interface SelectedShipping {
229
233
  serviceCode: string | null;
230
234
  displayName: string;
231
235
  rateAmount: number;
232
- currency: string;
236
+ currency: CurrencyCode;
233
237
  estimatedDeliveryDays: number | null;
234
238
  }
235
239
  interface AppliedDiscount {
@@ -237,7 +241,7 @@ interface AppliedDiscount {
237
241
  code: string;
238
242
  type: 'percentage' | 'fixed_amount';
239
243
  amount: number;
240
- currency: string;
244
+ currency: CurrencyCode;
241
245
  freeShipping: boolean;
242
246
  validUntil: string | null;
243
247
  snapshotHash: string;
@@ -256,7 +260,7 @@ interface TaxLine {
256
260
  rateTypeCode?: string | null;
257
261
  rate: number;
258
262
  amount: number;
259
- currency: string;
263
+ currency: CurrencyCode;
260
264
  }
261
265
  interface CartEvent {
262
266
  id: string;
@@ -383,7 +387,7 @@ interface Order {
383
387
  id: string;
384
388
  status: string;
385
389
  total: number;
386
- currency: string;
390
+ currency: CurrencyCode;
387
391
  }
388
392
  interface ShippingTaxAddress {
389
393
  countryCode?: string;
@@ -438,7 +442,7 @@ interface ShippingTaxMethod {
438
442
  type?: 'ship' | 'pickup';
439
443
  label: string;
440
444
  amount: number;
441
- currency: string;
445
+ currency: CurrencyCode;
442
446
  deliveryWindowLabel?: string | null;
443
447
  deliveryMinDays?: number | null;
444
448
  deliveryMaxDays?: number | null;
@@ -455,7 +459,7 @@ interface ShippingTaxCalculationResponse {
455
459
  source: 'off' | 'byo' | 'calculated' | 'app_based' | 'external_push';
456
460
  applicationId: string;
457
461
  workspaceId?: string;
458
- currency: string;
462
+ currency: CurrencyCode;
459
463
  configId?: string;
460
464
  configVersion?: number;
461
465
  shippingRequired: boolean;
@@ -715,7 +719,7 @@ interface CartSessionSummary {
715
719
  /** Cart total in minor units, or `0` on a finished session. */
716
720
  total: number;
717
721
  /** `null` on a finished session — there is no live cart to price. */
718
- currency: string | null;
722
+ currency: CurrencyCode | null;
719
723
  }
720
724
  interface CheckoutHandoffInput {
721
725
  returnUrl: string;
@@ -981,8 +985,8 @@ declare class LineResolverNotAvailableError extends ThrottleApiError {
981
985
  }
982
986
  /** `details` of `422 currency_not_enabled`. */
983
987
  type CurrencyNotEnabledDetails = {
984
- currency: string;
985
- enabledCurrencies: string[];
988
+ currency: CurrencyCode;
989
+ enabledCurrencies: CurrencyCode[];
986
990
  };
987
991
  /**
988
992
  * `422 currency_not_enabled`: a resolved cart must use the environment's
@@ -1078,6 +1082,31 @@ declare class ShippingCurrencyUnsupportedError extends ThrottleApiError {
1078
1082
  readonly shipping: CartShippingChange | null;
1079
1083
  constructor(args: CartErrorArgs);
1080
1084
  }
1085
+ /**
1086
+ * `422 currency_not_supported`: the code is not a supported ISO 4217 currency.
1087
+ * `details` is `{ currency, enabledCurrencies }`.
1088
+ */
1089
+ declare class CurrencyNotSupportedError extends ThrottleApiError {
1090
+ constructor(args: CartErrorArgs);
1091
+ }
1092
+ /**
1093
+ * `422 currency_not_available_in_production`: the production environment does
1094
+ * not accept this currency yet. `details` is `{ currency, enabledCurrencies }`.
1095
+ */
1096
+ declare class CurrencyNotAvailableInProductionError extends ThrottleApiError {
1097
+ constructor(args: CartErrorArgs);
1098
+ }
1099
+ /** `409 currency_locked`: the main currency can't change after the first production sale. */
1100
+ declare class CurrencyLockedError extends ThrottleApiError {
1101
+ constructor(args: CartErrorArgs);
1102
+ }
1103
+ /**
1104
+ * `422 quote_amounts_need_review`: amounts typed before the quote's currency
1105
+ * changed must be confirmed before it is issued. `details.pending` lists them.
1106
+ */
1107
+ declare class QuoteAmountsNeedReviewError extends ThrottleApiError {
1108
+ constructor(args: CartErrorArgs);
1109
+ }
1081
1110
  /**
1082
1111
  * Map a raw API error envelope to the most specific Cart SDK error class.
1083
1112
  * Falls back to {@link ThrottleApiError} for everything unrecognised.
@@ -1090,4 +1119,4 @@ declare function cartErrorFromResponse(args: {
1090
1119
  responseHeaders?: ThrottleErrorArgs['responseHeaders'];
1091
1120
  }): ThrottleApiError;
1092
1121
 
1093
- export { type AddLineItemInput, type AddResolvedLineItemInput, AmountTooLargeError, type AppliedDiscount, type Cart, type CartAddress, type CartBranding, CartChangedError, CartClient, type CartErrorArgs, type CartEvent, CartNotFoundError, CartNotOpenError, type CartPricesChangedDetails, CartPricesChangedError, type CartSession, type CartSessionCart, CartSessionClient, type CartSessionClientOptions, type CartSessionSummary, type CartShippingChange, CartTimeoutError, type CheckoutHandoff, type CheckoutHandoffInput, type CheckoutInput, type CreateCartInput, type CreateCartSessionInput, type CurrencyNotEnabledDetails, CurrencyNotEnabledError, DiscountCurrencyUnsupportedError, type ExternalShippingTaxSnapshotInput, type LegacyLineRecurring, type LineItem, type LineLimitReachedDetails, LineLimitReachedError, type LineNotPurchasableDetails, LineNotPurchasableError, type LineRecurringInput, type LineResolution, type LineResolverNotAvailableDetails, LineResolverNotAvailableError, type LineResolverUnavailableDetails, LineResolverUnavailableError, type Order, type PriceLockedDetails, PriceLockedError, type QuantityUnavailableDetails, QuantityUnavailableError, type RefusedCartLine, ResolvedLinesRequiredError, type SelectShippingInput, type SelectShippingMethodInput, type SelectedShipping, ShippingCurrencyUnsupportedError, ShippingMethodUnavailableError, ShippingQuoteUnavailableError, type ShippingTaxAddress, type ShippingTaxCalculationResponse, type ShippingTaxCartCalculateInput, type ShippingTaxMethod, type ShippingTaxQuoteInput, type ShippingTaxQuoteItem, type StoredLineRecurring, StorefrontQuoteClient, type SubscriptionInterval, type SubscriptionIntervalUnit, type TaxLine, type TaxLineInput, ThrottleApiError, type UpdateCartInput, type UpdateCartSessionInput, type UpdateLineItemInput, cartErrorFromResponse };
1122
+ export { type AddLineItemInput, type AddResolvedLineItemInput, AmountTooLargeError, type AppliedDiscount, type Cart, type CartAddress, type CartBranding, CartChangedError, CartClient, type CartErrorArgs, type CartEvent, CartNotFoundError, CartNotOpenError, type CartPricesChangedDetails, CartPricesChangedError, type CartSession, type CartSessionCart, CartSessionClient, type CartSessionClientOptions, type CartSessionSummary, type CartShippingChange, CartTimeoutError, type CheckoutHandoff, type CheckoutHandoffInput, type CheckoutInput, type CreateCartInput, type CreateCartSessionInput, CurrencyLockedError, CurrencyNotAvailableInProductionError, type CurrencyNotEnabledDetails, CurrencyNotEnabledError, CurrencyNotSupportedError, DiscountCurrencyUnsupportedError, type ExternalShippingTaxSnapshotInput, type LegacyLineRecurring, type LineItem, type LineLimitReachedDetails, LineLimitReachedError, type LineNotPurchasableDetails, LineNotPurchasableError, type LineRecurringInput, type LineResolution, type LineResolverNotAvailableDetails, LineResolverNotAvailableError, type LineResolverUnavailableDetails, LineResolverUnavailableError, type Order, type PriceLockedDetails, PriceLockedError, type QuantityUnavailableDetails, QuantityUnavailableError, QuoteAmountsNeedReviewError, type RefusedCartLine, ResolvedLinesRequiredError, type SelectShippingInput, type SelectShippingMethodInput, type SelectedShipping, ShippingCurrencyUnsupportedError, ShippingMethodUnavailableError, ShippingQuoteUnavailableError, type ShippingTaxAddress, type ShippingTaxCalculationResponse, type ShippingTaxCartCalculateInput, type ShippingTaxMethod, type ShippingTaxQuoteInput, type ShippingTaxQuoteItem, type StoredLineRecurring, StorefrontQuoteClient, type SubscriptionInterval, type SubscriptionIntervalUnit, type TaxLine, type TaxLineInput, ThrottleApiError, type UpdateCartInput, type UpdateCartSessionInput, type UpdateLineItemInput, cartErrorFromResponse };
package/dist/index.js CHANGED
@@ -166,6 +166,30 @@ var ShippingCurrencyUnsupportedError = class extends ThrottleApiError {
166
166
  this.shipping = d?.shipping && typeof d.shipping === "object" ? d.shipping : null;
167
167
  }
168
168
  };
169
+ var CurrencyNotSupportedError = class extends ThrottleApiError {
170
+ constructor(args) {
171
+ super(coded("currency_not_supported", 422, args));
172
+ this.name = "CurrencyNotSupportedError";
173
+ }
174
+ };
175
+ var CurrencyNotAvailableInProductionError = class extends ThrottleApiError {
176
+ constructor(args) {
177
+ super(coded("currency_not_available_in_production", 422, args));
178
+ this.name = "CurrencyNotAvailableInProductionError";
179
+ }
180
+ };
181
+ var CurrencyLockedError = class extends ThrottleApiError {
182
+ constructor(args) {
183
+ super(coded("currency_locked", 409, args));
184
+ this.name = "CurrencyLockedError";
185
+ }
186
+ };
187
+ var QuoteAmountsNeedReviewError = class extends ThrottleApiError {
188
+ constructor(args) {
189
+ super(coded("quote_amounts_need_review", 422, args));
190
+ this.name = "QuoteAmountsNeedReviewError";
191
+ }
192
+ };
169
193
  var RESOLVED_CART_ERRORS = {
170
194
  price_locked: PriceLockedError,
171
195
  quantity_unavailable: QuantityUnavailableError,
@@ -181,7 +205,11 @@ var RESOLVED_CART_ERRORS = {
181
205
  amount_too_large: AmountTooLargeError,
182
206
  cart_changed: CartChangedError,
183
207
  discount_currency_unsupported: DiscountCurrencyUnsupportedError,
184
- shipping_currency_unsupported: ShippingCurrencyUnsupportedError
208
+ shipping_currency_unsupported: ShippingCurrencyUnsupportedError,
209
+ currency_not_supported: CurrencyNotSupportedError,
210
+ currency_not_available_in_production: CurrencyNotAvailableInProductionError,
211
+ currency_locked: CurrencyLockedError,
212
+ quote_amounts_need_review: QuoteAmountsNeedReviewError
185
213
  };
186
214
  function cartErrorFromResponse(args) {
187
215
  if (args.statusCode === 409 && args.code === "cart_not_open") {
@@ -585,8 +613,24 @@ var CartSessionClient = class _CartSessionClient {
585
613
  }
586
614
  }
587
615
  };
616
+
617
+ // src/index.ts
618
+ import * as money from "@usethrottle/money";
619
+ import {
620
+ formatMoney,
621
+ currencySymbol,
622
+ minorUnitsOf,
623
+ toDecimalString,
624
+ toMinor,
625
+ parseMoney,
626
+ moneyValue,
627
+ CURRENCIES,
628
+ isKnownCurrency,
629
+ UnknownCurrencyError
630
+ } from "@usethrottle/money";
588
631
  export {
589
632
  AmountTooLargeError,
633
+ CURRENCIES,
590
634
  CartChangedError,
591
635
  CartClient,
592
636
  CartNotFoundError,
@@ -594,7 +638,10 @@ export {
594
638
  CartPricesChangedError,
595
639
  CartSessionClient,
596
640
  CartTimeoutError,
641
+ CurrencyLockedError,
642
+ CurrencyNotAvailableInProductionError,
597
643
  CurrencyNotEnabledError,
644
+ CurrencyNotSupportedError,
598
645
  DiscountCurrencyUnsupportedError,
599
646
  LineLimitReachedError,
600
647
  LineNotPurchasableError,
@@ -602,6 +649,7 @@ export {
602
649
  LineResolverUnavailableError,
603
650
  PriceLockedError,
604
651
  QuantityUnavailableError,
652
+ QuoteAmountsNeedReviewError,
605
653
  ResolvedLinesRequiredError,
606
654
  ShippingCurrencyUnsupportedError,
607
655
  ShippingMethodUnavailableError,
@@ -609,6 +657,16 @@ export {
609
657
  StorefrontQuoteClient,
610
658
  ThrottleApiError,
611
659
  ThrottleError2 as ThrottleError,
660
+ UnknownCurrencyError,
612
661
  cartErrorFromResponse,
613
- isThrottleError
662
+ currencySymbol,
663
+ formatMoney,
664
+ isKnownCurrency,
665
+ isThrottleError,
666
+ minorUnitsOf,
667
+ money,
668
+ moneyValue,
669
+ parseMoney,
670
+ toDecimalString,
671
+ toMinor
614
672
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@usethrottle/cart",
3
- "version": "3.16.0",
3
+ "version": "3.17.0",
4
4
  "description": "Typed REST client for the Throttle Cart API.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -18,7 +18,8 @@
18
18
  "README.md"
19
19
  ],
20
20
  "dependencies": {
21
- "@usethrottle/errors": "^1.1.0"
21
+ "@usethrottle/errors": "^1.1.0",
22
+ "@usethrottle/money": "^1.0.0"
22
23
  },
23
24
  "devDependencies": {
24
25
  "tsup": "^8.0.0",
@@ -30,7 +31,7 @@
30
31
  },
31
32
  "scripts": {
32
33
  "build": "tsup",
33
- "test": "tsc --noEmit --strict --skipLibCheck --target es2022 --lib es2022,dom --module esnext --moduleResolution bundler __tests__/recurring-types.check.ts __tests__/cart-customer-detach.check.ts && vitest run",
34
+ "test": "tsc --noEmit --strict --skipLibCheck --target es2022 --lib es2022,dom --module esnext --moduleResolution bundler __tests__/recurring-types.check.ts __tests__/cart-customer-detach.check.ts __tests__/currency-types.check.ts && vitest run",
34
35
  "typecheck": "tsc --noEmit"
35
36
  }
36
37
  }