@usethrottle/cart 3.16.0 → 3.18.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,11 @@ __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
+ CurrencyNotPayableError: () => CurrencyNotPayableError,
46
+ CurrencyNotSupportedError: () => CurrencyNotSupportedError,
32
47
  DiscountCurrencyUnsupportedError: () => DiscountCurrencyUnsupportedError,
33
48
  LineLimitReachedError: () => LineLimitReachedError,
34
49
  LineNotPurchasableError: () => LineNotPurchasableError,
@@ -36,6 +51,7 @@ __export(index_exports, {
36
51
  LineResolverUnavailableError: () => LineResolverUnavailableError,
37
52
  PriceLockedError: () => PriceLockedError,
38
53
  QuantityUnavailableError: () => QuantityUnavailableError,
54
+ QuoteAmountsNeedReviewError: () => QuoteAmountsNeedReviewError,
39
55
  ResolvedLinesRequiredError: () => ResolvedLinesRequiredError,
40
56
  ShippingCurrencyUnsupportedError: () => ShippingCurrencyUnsupportedError,
41
57
  ShippingMethodUnavailableError: () => ShippingMethodUnavailableError,
@@ -43,8 +59,18 @@ __export(index_exports, {
43
59
  StorefrontQuoteClient: () => StorefrontQuoteClient,
44
60
  ThrottleApiError: () => ThrottleApiError,
45
61
  ThrottleError: () => import_errors2.ThrottleError,
62
+ UnknownCurrencyError: () => import_money.UnknownCurrencyError,
46
63
  cartErrorFromResponse: () => cartErrorFromResponse,
47
- isThrottleError: () => import_errors2.isThrottleError
64
+ currencySymbol: () => import_money.currencySymbol,
65
+ formatMoney: () => import_money.formatMoney,
66
+ isKnownCurrency: () => import_money.isKnownCurrency,
67
+ isThrottleError: () => import_errors2.isThrottleError,
68
+ minorUnitsOf: () => import_money.minorUnitsOf,
69
+ money: () => money,
70
+ moneyValue: () => import_money.moneyValue,
71
+ parseMoney: () => import_money.parseMoney,
72
+ toDecimalString: () => import_money.toDecimalString,
73
+ toMinor: () => import_money.toMinor
48
74
  });
49
75
  module.exports = __toCommonJS(index_exports);
50
76
 
@@ -216,6 +242,41 @@ var ShippingCurrencyUnsupportedError = class extends ThrottleApiError {
216
242
  this.shipping = d?.shipping && typeof d.shipping === "object" ? d.shipping : null;
217
243
  }
218
244
  };
245
+ var CurrencyNotSupportedError = class extends ThrottleApiError {
246
+ constructor(args) {
247
+ super(coded("currency_not_supported", 422, args));
248
+ this.name = "CurrencyNotSupportedError";
249
+ }
250
+ };
251
+ var CurrencyNotAvailableInProductionError = class extends ThrottleApiError {
252
+ constructor(args) {
253
+ super(coded("currency_not_available_in_production", 422, args));
254
+ this.name = "CurrencyNotAvailableInProductionError";
255
+ }
256
+ };
257
+ var CurrencyNotPayableError = class extends ThrottleApiError {
258
+ currency;
259
+ payableCurrencies;
260
+ constructor(args) {
261
+ super(coded("currency_not_payable", 422, args));
262
+ this.name = "CurrencyNotPayableError";
263
+ const d = args.details;
264
+ this.currency = str(d?.currency);
265
+ this.payableCurrencies = Array.isArray(d?.payableCurrencies) ? d.payableCurrencies.filter((c) => typeof c === "string") : [];
266
+ }
267
+ };
268
+ var CurrencyLockedError = class extends ThrottleApiError {
269
+ constructor(args) {
270
+ super(coded("currency_locked", 409, args));
271
+ this.name = "CurrencyLockedError";
272
+ }
273
+ };
274
+ var QuoteAmountsNeedReviewError = class extends ThrottleApiError {
275
+ constructor(args) {
276
+ super(coded("quote_amounts_need_review", 422, args));
277
+ this.name = "QuoteAmountsNeedReviewError";
278
+ }
279
+ };
219
280
  var RESOLVED_CART_ERRORS = {
220
281
  price_locked: PriceLockedError,
221
282
  quantity_unavailable: QuantityUnavailableError,
@@ -231,7 +292,12 @@ var RESOLVED_CART_ERRORS = {
231
292
  amount_too_large: AmountTooLargeError,
232
293
  cart_changed: CartChangedError,
233
294
  discount_currency_unsupported: DiscountCurrencyUnsupportedError,
234
- shipping_currency_unsupported: ShippingCurrencyUnsupportedError
295
+ shipping_currency_unsupported: ShippingCurrencyUnsupportedError,
296
+ currency_not_supported: CurrencyNotSupportedError,
297
+ currency_not_available_in_production: CurrencyNotAvailableInProductionError,
298
+ currency_not_payable: CurrencyNotPayableError,
299
+ currency_locked: CurrencyLockedError,
300
+ quote_amounts_need_review: QuoteAmountsNeedReviewError
235
301
  };
236
302
  function cartErrorFromResponse(args) {
237
303
  if (args.statusCode === 409 && args.code === "cart_not_open") {
@@ -635,9 +701,14 @@ var CartSessionClient = class _CartSessionClient {
635
701
  }
636
702
  }
637
703
  };
704
+
705
+ // src/index.ts
706
+ var money = __toESM(require("@usethrottle/money"), 1);
707
+ var import_money = require("@usethrottle/money");
638
708
  // Annotate the CommonJS export names for ESM import in node:
639
709
  0 && (module.exports = {
640
710
  AmountTooLargeError,
711
+ CURRENCIES,
641
712
  CartChangedError,
642
713
  CartClient,
643
714
  CartNotFoundError,
@@ -645,7 +716,11 @@ var CartSessionClient = class _CartSessionClient {
645
716
  CartPricesChangedError,
646
717
  CartSessionClient,
647
718
  CartTimeoutError,
719
+ CurrencyLockedError,
720
+ CurrencyNotAvailableInProductionError,
648
721
  CurrencyNotEnabledError,
722
+ CurrencyNotPayableError,
723
+ CurrencyNotSupportedError,
649
724
  DiscountCurrencyUnsupportedError,
650
725
  LineLimitReachedError,
651
726
  LineNotPurchasableError,
@@ -653,6 +728,7 @@ var CartSessionClient = class _CartSessionClient {
653
728
  LineResolverUnavailableError,
654
729
  PriceLockedError,
655
730
  QuantityUnavailableError,
731
+ QuoteAmountsNeedReviewError,
656
732
  ResolvedLinesRequiredError,
657
733
  ShippingCurrencyUnsupportedError,
658
734
  ShippingMethodUnavailableError,
@@ -660,6 +736,16 @@ var CartSessionClient = class _CartSessionClient {
660
736
  StorefrontQuoteClient,
661
737
  ThrottleApiError,
662
738
  ThrottleError,
739
+ UnknownCurrencyError,
663
740
  cartErrorFromResponse,
664
- isThrottleError
741
+ currencySymbol,
742
+ formatMoney,
743
+ isKnownCurrency,
744
+ isThrottleError,
745
+ minorUnitsOf,
746
+ money,
747
+ moneyValue,
748
+ parseMoney,
749
+ toDecimalString,
750
+ toMinor
665
751
  });
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,41 @@ 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
+ /**
1100
+ * `422 currency_not_payable`: the store cannot take payment in this currency
1101
+ * (payment path). `details` is `{ currency, payableCurrencies }`; a missing or
1102
+ * malformed `details` yields `currency: null` and `payableCurrencies: []`.
1103
+ */
1104
+ declare class CurrencyNotPayableError extends ThrottleApiError {
1105
+ readonly currency: string | null;
1106
+ readonly payableCurrencies: string[];
1107
+ constructor(args: CartErrorArgs);
1108
+ }
1109
+ /** `409 currency_locked`: the main currency can't change after the first production sale. */
1110
+ declare class CurrencyLockedError extends ThrottleApiError {
1111
+ constructor(args: CartErrorArgs);
1112
+ }
1113
+ /**
1114
+ * `422 quote_amounts_need_review`: amounts typed before the quote's currency
1115
+ * changed must be confirmed before it is issued. `details.pending` lists them.
1116
+ */
1117
+ declare class QuoteAmountsNeedReviewError extends ThrottleApiError {
1118
+ constructor(args: CartErrorArgs);
1119
+ }
1081
1120
  /**
1082
1121
  * Map a raw API error envelope to the most specific Cart SDK error class.
1083
1122
  * Falls back to {@link ThrottleApiError} for everything unrecognised.
@@ -1090,4 +1129,4 @@ declare function cartErrorFromResponse(args: {
1090
1129
  responseHeaders?: ThrottleErrorArgs['responseHeaders'];
1091
1130
  }): ThrottleApiError;
1092
1131
 
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 };
1132
+ 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, CurrencyNotPayableError, 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,41 @@ 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
+ /**
1100
+ * `422 currency_not_payable`: the store cannot take payment in this currency
1101
+ * (payment path). `details` is `{ currency, payableCurrencies }`; a missing or
1102
+ * malformed `details` yields `currency: null` and `payableCurrencies: []`.
1103
+ */
1104
+ declare class CurrencyNotPayableError extends ThrottleApiError {
1105
+ readonly currency: string | null;
1106
+ readonly payableCurrencies: string[];
1107
+ constructor(args: CartErrorArgs);
1108
+ }
1109
+ /** `409 currency_locked`: the main currency can't change after the first production sale. */
1110
+ declare class CurrencyLockedError extends ThrottleApiError {
1111
+ constructor(args: CartErrorArgs);
1112
+ }
1113
+ /**
1114
+ * `422 quote_amounts_need_review`: amounts typed before the quote's currency
1115
+ * changed must be confirmed before it is issued. `details.pending` lists them.
1116
+ */
1117
+ declare class QuoteAmountsNeedReviewError extends ThrottleApiError {
1118
+ constructor(args: CartErrorArgs);
1119
+ }
1081
1120
  /**
1082
1121
  * Map a raw API error envelope to the most specific Cart SDK error class.
1083
1122
  * Falls back to {@link ThrottleApiError} for everything unrecognised.
@@ -1090,4 +1129,4 @@ declare function cartErrorFromResponse(args: {
1090
1129
  responseHeaders?: ThrottleErrorArgs['responseHeaders'];
1091
1130
  }): ThrottleApiError;
1092
1131
 
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 };
1132
+ 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, CurrencyNotPayableError, 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,41 @@ 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 CurrencyNotPayableError = class extends ThrottleApiError {
182
+ currency;
183
+ payableCurrencies;
184
+ constructor(args) {
185
+ super(coded("currency_not_payable", 422, args));
186
+ this.name = "CurrencyNotPayableError";
187
+ const d = args.details;
188
+ this.currency = str(d?.currency);
189
+ this.payableCurrencies = Array.isArray(d?.payableCurrencies) ? d.payableCurrencies.filter((c) => typeof c === "string") : [];
190
+ }
191
+ };
192
+ var CurrencyLockedError = class extends ThrottleApiError {
193
+ constructor(args) {
194
+ super(coded("currency_locked", 409, args));
195
+ this.name = "CurrencyLockedError";
196
+ }
197
+ };
198
+ var QuoteAmountsNeedReviewError = class extends ThrottleApiError {
199
+ constructor(args) {
200
+ super(coded("quote_amounts_need_review", 422, args));
201
+ this.name = "QuoteAmountsNeedReviewError";
202
+ }
203
+ };
169
204
  var RESOLVED_CART_ERRORS = {
170
205
  price_locked: PriceLockedError,
171
206
  quantity_unavailable: QuantityUnavailableError,
@@ -181,7 +216,12 @@ var RESOLVED_CART_ERRORS = {
181
216
  amount_too_large: AmountTooLargeError,
182
217
  cart_changed: CartChangedError,
183
218
  discount_currency_unsupported: DiscountCurrencyUnsupportedError,
184
- shipping_currency_unsupported: ShippingCurrencyUnsupportedError
219
+ shipping_currency_unsupported: ShippingCurrencyUnsupportedError,
220
+ currency_not_supported: CurrencyNotSupportedError,
221
+ currency_not_available_in_production: CurrencyNotAvailableInProductionError,
222
+ currency_not_payable: CurrencyNotPayableError,
223
+ currency_locked: CurrencyLockedError,
224
+ quote_amounts_need_review: QuoteAmountsNeedReviewError
185
225
  };
186
226
  function cartErrorFromResponse(args) {
187
227
  if (args.statusCode === 409 && args.code === "cart_not_open") {
@@ -585,8 +625,24 @@ var CartSessionClient = class _CartSessionClient {
585
625
  }
586
626
  }
587
627
  };
628
+
629
+ // src/index.ts
630
+ import * as money from "@usethrottle/money";
631
+ import {
632
+ formatMoney,
633
+ currencySymbol,
634
+ minorUnitsOf,
635
+ toDecimalString,
636
+ toMinor,
637
+ parseMoney,
638
+ moneyValue,
639
+ CURRENCIES,
640
+ isKnownCurrency,
641
+ UnknownCurrencyError
642
+ } from "@usethrottle/money";
588
643
  export {
589
644
  AmountTooLargeError,
645
+ CURRENCIES,
590
646
  CartChangedError,
591
647
  CartClient,
592
648
  CartNotFoundError,
@@ -594,7 +650,11 @@ export {
594
650
  CartPricesChangedError,
595
651
  CartSessionClient,
596
652
  CartTimeoutError,
653
+ CurrencyLockedError,
654
+ CurrencyNotAvailableInProductionError,
597
655
  CurrencyNotEnabledError,
656
+ CurrencyNotPayableError,
657
+ CurrencyNotSupportedError,
598
658
  DiscountCurrencyUnsupportedError,
599
659
  LineLimitReachedError,
600
660
  LineNotPurchasableError,
@@ -602,6 +662,7 @@ export {
602
662
  LineResolverUnavailableError,
603
663
  PriceLockedError,
604
664
  QuantityUnavailableError,
665
+ QuoteAmountsNeedReviewError,
605
666
  ResolvedLinesRequiredError,
606
667
  ShippingCurrencyUnsupportedError,
607
668
  ShippingMethodUnavailableError,
@@ -609,6 +670,16 @@ export {
609
670
  StorefrontQuoteClient,
610
671
  ThrottleApiError,
611
672
  ThrottleError2 as ThrottleError,
673
+ UnknownCurrencyError,
612
674
  cartErrorFromResponse,
613
- isThrottleError
675
+ currencySymbol,
676
+ formatMoney,
677
+ isKnownCurrency,
678
+ isThrottleError,
679
+ minorUnitsOf,
680
+ money,
681
+ moneyValue,
682
+ parseMoney,
683
+ toDecimalString,
684
+ toMinor
614
685
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@usethrottle/cart",
3
- "version": "3.16.0",
3
+ "version": "3.18.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.1.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
  }