@usethrottle/mcp 0.4.1 → 0.4.3

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/lib.cjs CHANGED
@@ -20,13 +20,24 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/lib.ts
21
21
  var lib_exports = {};
22
22
  __export(lib_exports, {
23
+ CURRENCIES: () => CURRENCIES,
23
24
  ThrottleClient: () => ThrottleClient,
25
+ UnknownCurrencyError: () => UnknownCurrencyError,
24
26
  VERSION: () => VERSION,
25
27
  buildInstructions: () => buildInstructions,
26
28
  createServer: () => createServer,
29
+ currencySymbol: () => currencySymbol,
30
+ formatMoney: () => formatMoney,
31
+ isKnownCurrency: () => isKnownCurrency,
27
32
  loadContractIndex: () => loadContractIndex,
28
33
  loadDocsIndex: () => loadDocsIndex,
29
- registerableActions: () => registerableActions
34
+ minorUnitsOf: () => minorUnitsOf,
35
+ money: () => dist_exports,
36
+ moneyValue: () => moneyValue,
37
+ parseMoney: () => parseMoney,
38
+ registerableActions: () => registerableActions,
39
+ toDecimalString: () => toDecimalString,
40
+ toMinor: () => toMinor
30
41
  });
31
42
  module.exports = __toCommonJS(lib_exports);
32
43
 
@@ -94,6 +105,8 @@ add("Customers", "customers", ["read", "write"], { read: "View customers", write
94
105
  add("Customers", "customer_pii", ["read"], { read: "View customer PII" }, { sensitive: true });
95
106
  add("Customers", "customer_addresses", ["read", "write"], { read: "View addresses", write: "Manage addresses" });
96
107
  add("Customers", "customer_payment_methods", ["read", "write"], { read: "View stored cards", write: "Manage stored cards" }, { sensitive: true });
108
+ add("Customers", "customer_tokens", ["read"], { read: "Check shoppers' sign-in tokens" });
109
+ add("Customers", "customer_directory", ["read"], { read: "Find customers by name or email" }, { sensitive: true });
97
110
  add(
98
111
  "Customer accounts",
99
112
  "customer_accounts",
@@ -226,6 +239,7 @@ var EVENT_SCOPE_OVERRIDES = {
226
239
  "subscription.invoice_refunded": "payment_refunds:read",
227
240
  "payment.disputed": "payment_disputes:read",
228
241
  "payment.dispute_cleared": "payment_disputes:read",
242
+ "payment.dispute_lost": "payment_disputes:read",
229
243
  "fulfillment.digital.delivered": "fulfillment_digital:read"
230
244
  };
231
245
  var PREFIX_RULES = [
@@ -534,7 +548,7 @@ var ACTIONS = [
534
548
  {
535
549
  id: "search_customers",
536
550
  title: "Search customers",
537
- description: "Find customers by name, email or external id, or list them by creation date. Over an OAuth connection (ChatGPT, Claude) text search is not available \u2014 list by date instead \u2014 because every field it could match is withheld there.",
551
+ description: "Find customers by name, company, email or external id, or list them by creation date. Over an OAuth connection (ChatGPT, Claude) text search is not available \u2014 list by date instead \u2014 because every field it could match is withheld there.",
538
552
  kind: "read",
539
553
  scopes: ["customers:read"],
540
554
  input: [
@@ -1379,7 +1393,7 @@ var ACTIONS = [
1379
1393
  {
1380
1394
  id: "create_customer",
1381
1395
  title: "Create a customer",
1382
- description: "Create a customer record. Use search_customers first if the buyer may already exist \u2014 this does not de-duplicate by email.",
1396
+ description: "Create a customer record. Email and externalId are each unique per application: a value that already belongs to a customer fails with 409 customer_already_exists rather than returning the existing record, so use search_customers first if the buyer may already exist.",
1383
1397
  kind: "write",
1384
1398
  scopes: ["customers:write"],
1385
1399
  input: [
@@ -1457,7 +1471,7 @@ var ACTIONS = [
1457
1471
  {
1458
1472
  id: "create_checkout_link",
1459
1473
  title: "Create a checkout link",
1460
- description: "Build a cart from line items and return a hosted checkout URL the buyer can pay at. Prices are in minor units (2500 = $25.00).",
1474
+ description: "Build a cart from line items and return a hosted checkout URL the buyer can pay at. Prices are integers in the minor units of the cart currency (2500 = 25.00 in a two-decimal currency).",
1461
1475
  kind: "write",
1462
1476
  scopes: ["carts:write", "cart_items:write", "checkout_sessions:write"],
1463
1477
  input: [
@@ -1611,6 +1625,29 @@ var ACTIONS = [
1611
1625
  channels: ["mcp", "zapier", "make", "n8n"],
1612
1626
  idempotent: true
1613
1627
  },
1628
+ {
1629
+ id: "set_subscription_payment_method",
1630
+ title: "Change a subscription's card",
1631
+ description: "Set the saved card one subscription renews on. Only that subscription moves; the customer's default card and their other subscriptions stay as they are. Nothing is charged now.",
1632
+ kind: "write",
1633
+ scopes: ["subscriptions:write"],
1634
+ input: [
1635
+ { name: "id", type: "string", required: true, description: "Subscription id." },
1636
+ {
1637
+ name: "paymentMethodId",
1638
+ type: "string",
1639
+ required: true,
1640
+ description: "One of the subscription customer's saved cards (GET /api/v1/customers/:id/payment-methods): active and in date."
1641
+ }
1642
+ ],
1643
+ requests: [{ method: "PATCH", path: "/api/v1/subscriptions/:id/payment-method" }],
1644
+ channels: ["mcp", "zapier", "make", "n8n"],
1645
+ idempotent: true,
1646
+ guardrails: [
1647
+ "Changes which card future renewals charge. Confirm the subscription and the card (brand, last four) with the user first.",
1648
+ "409 payment_method_unusable: the card is not this customer's active, in-date saved card. 409 invalid_state: the subscription is cancelled or completed."
1649
+ ]
1650
+ },
1614
1651
  {
1615
1652
  id: "cancel_subscription",
1616
1653
  title: "Cancel a subscription",
@@ -2449,6 +2486,14 @@ var HANDLERS = {
2449
2486
  idempotencyKey: `mcp-manage-subscription-${id}-${action}-${Date.now()}`
2450
2487
  });
2451
2488
  },
2489
+ set_subscription_payment_method: async (ctx, args) => {
2490
+ const id = String(args.id);
2491
+ return ctx.client.patch(`/api/v1/subscriptions/${id}/payment-method`, {
2492
+ // `id` is the path parameter; the body is `.strict()`.
2493
+ body: { paymentMethodId: args.paymentMethodId },
2494
+ idempotencyKey: `mcp-set-subscription-card-${id}-${String(args.paymentMethodId)}-${Date.now()}`
2495
+ });
2496
+ },
2452
2497
  create_quote: async (ctx, args) => {
2453
2498
  const items = Array.isArray(args.items) ? args.items : [];
2454
2499
  if (args.netN !== void 0 && items.some((item) => item && item.recurring)) {
@@ -2713,6 +2758,7 @@ var DISPLAY_QUALIFIERS = [
2713
2758
  "Payment processing",
2714
2759
  "Disputed",
2715
2760
  "Authorization expired",
2761
+ "Chargeback lost",
2716
2762
  "Returned",
2717
2763
  "Partially returned",
2718
2764
  "Delivered",
@@ -2790,6 +2836,8 @@ var PAYMENT = {
2790
2836
  cardBrand: S,
2791
2837
  disputed: S,
2792
2838
  disputeOpenedAt: S,
2839
+ disputeOutcome: S,
2840
+ disputeClosedAt: S,
2793
2841
  errorCode: S,
2794
2842
  netN: S,
2795
2843
  netNSource: S,
@@ -2852,6 +2900,10 @@ var SUBSCRIPTION = {
2852
2900
  pendingIntervalCount: S,
2853
2901
  scheduleTotal: S,
2854
2902
  nextPaymentAmount: S,
2903
+ // A physical subscription (0236): the method is an enum, and the ship-to is
2904
+ // kept to its country like every other address here.
2905
+ deliveryMethod: S,
2906
+ shippingAddress: ADDRESS,
2855
2907
  paymentSchedule: [{
2856
2908
  index: S,
2857
2909
  amount: S,
@@ -3228,7 +3280,7 @@ var OAUTH_PROJECTIONS = {
3228
3280
  };
3229
3281
 
3230
3282
  // src/server.ts
3231
- var VERSION = true ? "0.4.1" : "0.0.0-dev";
3283
+ var VERSION = true ? "0.4.3" : "0.0.0-dev";
3232
3284
  function registerableActions(policy) {
3233
3285
  const isProduction = policy.identity.environment.providerEnvironment === "production";
3234
3286
  return actionsForChannel("mcp").filter((action) => {
@@ -3257,7 +3309,7 @@ function buildInstructions(identity, actions, policy) {
3257
3309
  '- The application can vary per call: pass "applicationId" on a read or analytics tool to reach a different application in this workspace, and call list_applications to see which ones this connection can reach. Omitting applicationId uses the application this connection was authorized for.',
3258
3310
  "- Every analytics result covers exactly ONE application and names it in `application`. Say which application a figure describes. If the user asks about their business as a whole and this connection reaches more than one application, do not answer from the default alone \u2014 call list_applications, then query each and add them up, or ask which application they mean.",
3259
3311
  '- List tools return { data, pagination }. When pagination.hasMore is true, pass pagination.cursor back as "cursor" rather than raising "limit".',
3260
- "- Amounts are integer minor units (2500 = $25.00).",
3312
+ "- Amounts are integer minor units of the record's currency (2500 = 25.00 in a two-decimal currency; JPY has none, KWD has three).",
3261
3313
  "- Throttle rejects snake_case on public request bodies. Before writing integration code, confirm shapes with describe_endpoint and check bodies with validate_payload instead of guessing field names.",
3262
3314
  "- API errors come back as text with a stable code. On insufficient_scopes, tell the user which scope to add \u2014 do not retry.",
3263
3315
  "- Analytics results may mark a section `omitted`. That means UNKNOWN, never zero. When `grantable` is false the data cannot be read over this connection at all \u2014 say so rather than reporting an absence."
@@ -3394,14 +3446,332 @@ function loadDocsIndex() {
3394
3446
  function loadContractIndex() {
3395
3447
  return loadIndex("contract-index.json", { generatedAt: "", operations: [] }, "contract");
3396
3448
  }
3449
+
3450
+ // ../money/dist/index.js
3451
+ var dist_exports = {};
3452
+ __export(dist_exports, {
3453
+ CURRENCIES: () => CURRENCIES,
3454
+ UNCONFIRMED_EXPONENT_CODES: () => UNCONFIRMED_EXPONENT_CODES,
3455
+ UnknownCurrencyError: () => UnknownCurrencyError,
3456
+ currencySymbol: () => currencySymbol,
3457
+ formatMoney: () => formatMoney,
3458
+ isEnableableCurrency: () => isEnableableCurrency,
3459
+ isKnownCurrency: () => isKnownCurrency,
3460
+ minorUnitsOf: () => minorUnitsOf,
3461
+ moneyValue: () => moneyValue,
3462
+ parseMoney: () => parseMoney,
3463
+ toDecimalString: () => toDecimalString,
3464
+ toMinor: () => toMinor
3465
+ });
3466
+ var CURRENCY_ROWS = [
3467
+ ["AED", 2, "AED", false],
3468
+ ["AFN", 2, "AFN", false],
3469
+ ["ALL", 2, "ALL", false],
3470
+ ["AMD", 2, "AMD", false],
3471
+ ["AOA", 2, "AOA", false],
3472
+ ["ARS", 2, "ARS", false],
3473
+ ["AUD", 2, "A$", false],
3474
+ ["AWG", 2, "AWG", false],
3475
+ ["AZN", 2, "AZN", false],
3476
+ ["BAM", 2, "BAM", false],
3477
+ ["BBD", 2, "BBD", false],
3478
+ ["BDT", 2, "BDT", false],
3479
+ ["BHD", 3, "BHD", false],
3480
+ ["BIF", 0, "BIF", false],
3481
+ ["BMD", 2, "BMD", false],
3482
+ ["BND", 2, "BND", false],
3483
+ ["BOB", 2, "BOB", false],
3484
+ ["BOV", 2, "BOV", true],
3485
+ ["BRL", 2, "R$", false],
3486
+ ["BSD", 2, "BSD", false],
3487
+ ["BTN", 2, "BTN", false],
3488
+ ["BWP", 2, "BWP", false],
3489
+ ["BYN", 2, "BYN", false],
3490
+ ["BZD", 2, "BZD", false],
3491
+ ["CAD", 2, "CA$", false],
3492
+ ["CDF", 2, "CDF", false],
3493
+ ["CHE", 2, "CHE", true],
3494
+ ["CHF", 2, "CHF", false],
3495
+ ["CHW", 2, "CHW", true],
3496
+ ["CLF", 4, "CLF", true],
3497
+ ["CLP", 0, "CLP", false],
3498
+ ["CNY", 2, "CN\xA5", false],
3499
+ ["COP", 2, "COP", false],
3500
+ ["COU", 2, "COU", true],
3501
+ ["CRC", 2, "CRC", false],
3502
+ ["CUP", 2, "CUP", false],
3503
+ ["CVE", 2, "CVE", false],
3504
+ ["CZK", 2, "CZK", false],
3505
+ ["DJF", 0, "DJF", false],
3506
+ ["DKK", 2, "DKK", false],
3507
+ ["DOP", 2, "DOP", false],
3508
+ ["DZD", 2, "DZD", false],
3509
+ ["EGP", 2, "EGP", false],
3510
+ ["ERN", 2, "ERN", false],
3511
+ ["ETB", 2, "ETB", false],
3512
+ ["EUR", 2, "\u20AC", false],
3513
+ ["FJD", 2, "FJD", false],
3514
+ ["FKP", 2, "FKP", false],
3515
+ ["GBP", 2, "\xA3", false],
3516
+ ["GEL", 2, "GEL", false],
3517
+ ["GHS", 2, "GHS", false],
3518
+ ["GIP", 2, "GIP", false],
3519
+ ["GMD", 2, "GMD", false],
3520
+ ["GNF", 0, "GNF", false],
3521
+ ["GTQ", 2, "GTQ", false],
3522
+ ["GYD", 2, "GYD", false],
3523
+ ["HKD", 2, "HK$", false],
3524
+ ["HNL", 2, "HNL", false],
3525
+ ["HTG", 2, "HTG", false],
3526
+ ["HUF", 2, "HUF", false],
3527
+ ["IDR", 2, "IDR", false],
3528
+ ["ILS", 2, "\u20AA", false],
3529
+ ["INR", 2, "\u20B9", false],
3530
+ ["IQD", 3, "IQD", false],
3531
+ ["IRR", 2, "IRR", false],
3532
+ ["ISK", 0, "ISK", false],
3533
+ ["JMD", 2, "JMD", false],
3534
+ ["JOD", 3, "JOD", false],
3535
+ ["JPY", 0, "\xA5", false],
3536
+ ["KES", 2, "KES", false],
3537
+ ["KGS", 2, "KGS", false],
3538
+ ["KHR", 2, "KHR", false],
3539
+ ["KMF", 0, "KMF", false],
3540
+ ["KPW", 2, "KPW", false],
3541
+ ["KRW", 0, "\u20A9", false],
3542
+ ["KWD", 3, "KWD", false],
3543
+ ["KYD", 2, "KYD", false],
3544
+ ["KZT", 2, "KZT", false],
3545
+ ["LAK", 2, "LAK", false],
3546
+ ["LBP", 2, "LBP", false],
3547
+ ["LKR", 2, "LKR", false],
3548
+ ["LRD", 2, "LRD", false],
3549
+ ["LSL", 2, "LSL", false],
3550
+ ["LYD", 3, "LYD", false],
3551
+ ["MAD", 2, "MAD", false],
3552
+ ["MDL", 2, "MDL", false],
3553
+ ["MGA", 2, "MGA", false],
3554
+ ["MKD", 2, "MKD", false],
3555
+ ["MMK", 2, "MMK", false],
3556
+ ["MNT", 2, "MNT", false],
3557
+ ["MOP", 2, "MOP", false],
3558
+ ["MRU", 2, "MRU", false],
3559
+ ["MUR", 2, "MUR", false],
3560
+ ["MVR", 2, "MVR", false],
3561
+ ["MWK", 2, "MWK", false],
3562
+ ["MXN", 2, "MX$", false],
3563
+ ["MXV", 2, "MXV", true],
3564
+ ["MYR", 2, "MYR", false],
3565
+ ["MZN", 2, "MZN", false],
3566
+ ["NAD", 2, "NAD", false],
3567
+ ["NGN", 2, "NGN", false],
3568
+ ["NIO", 2, "NIO", false],
3569
+ ["NOK", 2, "NOK", false],
3570
+ ["NPR", 2, "NPR", false],
3571
+ ["NZD", 2, "NZ$", false],
3572
+ ["OMR", 3, "OMR", false],
3573
+ ["PAB", 2, "PAB", false],
3574
+ ["PEN", 2, "PEN", false],
3575
+ ["PGK", 2, "PGK", false],
3576
+ ["PHP", 2, "\u20B1", false],
3577
+ ["PKR", 2, "PKR", false],
3578
+ ["PLN", 2, "PLN", false],
3579
+ ["PYG", 0, "PYG", false],
3580
+ ["QAR", 2, "QAR", false],
3581
+ ["RON", 2, "RON", false],
3582
+ ["RSD", 2, "RSD", false],
3583
+ ["RUB", 2, "RUB", false],
3584
+ ["RWF", 0, "RWF", false],
3585
+ ["SAR", 2, "SAR", false],
3586
+ ["SBD", 2, "SBD", false],
3587
+ ["SCR", 2, "SCR", false],
3588
+ ["SDG", 2, "SDG", false],
3589
+ ["SEK", 2, "SEK", false],
3590
+ ["SGD", 2, "SGD", false],
3591
+ ["SHP", 2, "SHP", false],
3592
+ ["SLE", 2, "SLE", false],
3593
+ ["SOS", 2, "SOS", false],
3594
+ ["SRD", 2, "SRD", false],
3595
+ ["SSP", 2, "SSP", false],
3596
+ ["STN", 2, "STN", false],
3597
+ ["SVC", 2, "SVC", false],
3598
+ ["SYP", 2, "SYP", false],
3599
+ ["SZL", 2, "SZL", false],
3600
+ ["THB", 2, "THB", false],
3601
+ ["TJS", 2, "TJS", false],
3602
+ ["TMT", 2, "TMT", false],
3603
+ ["TND", 3, "TND", false],
3604
+ ["TOP", 2, "TOP", false],
3605
+ ["TRY", 2, "TRY", false],
3606
+ ["TTD", 2, "TTD", false],
3607
+ ["TWD", 2, "NT$", false],
3608
+ ["TZS", 2, "TZS", false],
3609
+ ["UAH", 2, "UAH", false],
3610
+ ["UGX", 0, "UGX", false],
3611
+ ["USD", 2, "$", false],
3612
+ ["USN", 2, "USN", true],
3613
+ ["UYI", 0, "UYI", true],
3614
+ ["UYU", 2, "UYU", false],
3615
+ ["UYW", 4, "UYW", true],
3616
+ ["UZS", 2, "UZS", false],
3617
+ ["VED", 2, "VED", false],
3618
+ ["VES", 2, "VES", false],
3619
+ ["VND", 0, "\u20AB", false],
3620
+ ["VUV", 0, "VUV", false],
3621
+ ["WST", 2, "WST", false],
3622
+ ["XAD", 2, "XAD", true],
3623
+ ["XAF", 0, "FCFA", false],
3624
+ ["XCD", 2, "EC$", false],
3625
+ ["XCG", 2, "Cg.", false],
3626
+ ["XOF", 0, "F\u202FCFA", false],
3627
+ ["XPF", 0, "CFPF", false],
3628
+ ["YER", 2, "YER", false],
3629
+ ["ZAR", 2, "ZAR", false],
3630
+ ["ZMW", 2, "ZMW", false],
3631
+ ["ZWG", 2, "ZWG", false]
3632
+ ];
3633
+ var UnknownCurrencyError = class extends Error {
3634
+ constructor(currency) {
3635
+ super(`Unknown currency code: ${currency}`);
3636
+ this.code = "unknown_currency";
3637
+ this.name = "UnknownCurrencyError";
3638
+ this.currency = currency;
3639
+ }
3640
+ };
3641
+ var BY_CODE = new Map(
3642
+ CURRENCY_ROWS.map(([code, minorUnits, symbol, fund]) => [code, { minorUnits, symbol, fund }])
3643
+ );
3644
+ var CURRENCIES = Object.freeze(
3645
+ CURRENCY_ROWS.map(([code, minorUnits, symbol]) => Object.freeze({ code, minorUnits, symbol }))
3646
+ );
3647
+ var UNCONFIRMED = /* @__PURE__ */ new Set(["COP", "HUF", "IDR", "ISK", "TWD", "UGX"]);
3648
+ var UNCONFIRMED_EXPONENT_CODES = Object.freeze({
3649
+ has: (code) => UNCONFIRMED.has(code),
3650
+ get size() {
3651
+ return UNCONFIRMED.size;
3652
+ },
3653
+ forEach: (fn, thisArg) => UNCONFIRMED.forEach((v) => fn.call(thisArg, v, v, UNCONFIRMED_EXPONENT_CODES)),
3654
+ keys: () => UNCONFIRMED.keys(),
3655
+ values: () => UNCONFIRMED.values(),
3656
+ entries: () => UNCONFIRMED.entries(),
3657
+ [Symbol.iterator]: () => UNCONFIRMED.values()
3658
+ });
3659
+ function currencyRow(code) {
3660
+ return BY_CODE.get(code);
3661
+ }
3662
+ function isKnownCurrency(code) {
3663
+ return BY_CODE.has(code);
3664
+ }
3665
+ function minorUnitsOf(code) {
3666
+ const row = BY_CODE.get(code);
3667
+ if (row === void 0) throw new UnknownCurrencyError(code);
3668
+ return row.minorUnits;
3669
+ }
3670
+ function isEnableableCurrency(code) {
3671
+ const row = BY_CODE.get(code);
3672
+ return row !== void 0 && row.minorUnits !== 4 && !row.fund && !UNCONFIRMED.has(code);
3673
+ }
3674
+ var NBSP = "\xA0";
3675
+ function normalizeCode(code) {
3676
+ return typeof code === "string" ? code.trim().toUpperCase() : "";
3677
+ }
3678
+ function displayExponent(normalizedCode) {
3679
+ return currencyRow(normalizedCode)?.minorUnits ?? 2;
3680
+ }
3681
+ function roundHalfAwayFromZero(n) {
3682
+ return n < 0 ? -Math.round(-n) : Math.round(n);
3683
+ }
3684
+ function decimalDigits(abs, exponent, grouped) {
3685
+ const raw = Number.isSafeInteger(abs) ? String(abs) : BigInt(abs).toString();
3686
+ const padded = raw.padStart(exponent + 1, "0");
3687
+ const cut = padded.length - exponent;
3688
+ let integer = padded.slice(0, cut);
3689
+ if (grouped) integer = integer.replace(/\B(?=(\d{3})+(?!\d))/g, ",");
3690
+ return exponent === 0 ? integer : `${integer}.${padded.slice(cut)}`;
3691
+ }
3692
+ function formatMoney(minor, code, opts) {
3693
+ if (typeof minor !== "number" || !Number.isFinite(minor)) return "\u2014";
3694
+ const c = normalizeCode(code);
3695
+ const row = currencyRow(c);
3696
+ const n = roundHalfAwayFromZero(minor);
3697
+ const sign = n < 0 ? "-" : "";
3698
+ const digits = decimalDigits(Math.abs(n), row?.minorUnits ?? 2, true);
3699
+ if (c === "") return sign + digits;
3700
+ if (row === void 0) return `${sign}${digits}${NBSP}${c}`;
3701
+ const separator = new RegExp("\\p{Sc}$", "u").test(row.symbol) ? "" : NBSP;
3702
+ const text = `${sign}${row.symbol}${separator}${digits}`;
3703
+ return opts?.display === "symbol-code" && row.symbol !== c ? `${text}${NBSP}${c}` : text;
3704
+ }
3705
+ function currencySymbol(code) {
3706
+ const c = normalizeCode(code);
3707
+ return currencyRow(c)?.symbol ?? c;
3708
+ }
3709
+ function toDecimalString(minor, code) {
3710
+ if (typeof minor !== "number" || !Number.isFinite(minor)) return "";
3711
+ const n = roundHalfAwayFromZero(minor);
3712
+ const sign = n < 0 ? "-" : "";
3713
+ return sign + decimalDigits(Math.abs(n), displayExponent(normalizeCode(code)), false);
3714
+ }
3715
+ function moneyValue(amount, currency) {
3716
+ return { amount, currency: normalizeCode(currency), display: formatMoney(amount, currency) };
3717
+ }
3718
+ function toMinorUnits(negative, integer, fraction, exponent) {
3719
+ if (fraction.length > exponent) return null;
3720
+ const n = Number(integer + fraction.padEnd(exponent, "0"));
3721
+ if (!Number.isSafeInteger(n)) return null;
3722
+ return negative && n !== 0 ? -n : n;
3723
+ }
3724
+ function toMinor(decimal, code) {
3725
+ const text = typeof decimal === "number" ? String(decimal) : typeof decimal === "string" ? decimal : "";
3726
+ const m = /^(-?)(\d+)(?:\.(\d+))?$/.exec(text);
3727
+ if (m === null) return null;
3728
+ return toMinorUnits(m[1] === "-", m[2], m[3] ?? "", displayExponent(normalizeCode(code)));
3729
+ }
3730
+ var SPACE = /^[ \u00A0]/;
3731
+ var TRAILING_SPACE = /[ \u00A0]$/;
3732
+ var AMOUNT = /^([1-9]\d{0,2}(?:,\d{3})+|\d+)(?:\.(\d+))?$/;
3733
+ function withoutMarker(text, markers) {
3734
+ for (const marker of markers) {
3735
+ if (text.startsWith(marker)) return text.slice(marker.length).replace(SPACE, "");
3736
+ }
3737
+ for (const marker of markers) {
3738
+ if (text.endsWith(marker)) return text.slice(0, text.length - marker.length).replace(TRAILING_SPACE, "");
3739
+ }
3740
+ return text;
3741
+ }
3742
+ function parseMoney(text, code) {
3743
+ if (typeof text !== "string") return null;
3744
+ const c = normalizeCode(code);
3745
+ let rest = text.trim();
3746
+ const negative = rest.startsWith("-");
3747
+ if (negative) rest = rest.slice(1);
3748
+ if (c !== "") {
3749
+ const symbol = currencySymbol(c);
3750
+ rest = withoutMarker(rest, symbol === c ? [c] : [symbol, c]);
3751
+ }
3752
+ const m = AMOUNT.exec(rest);
3753
+ if (m === null) return null;
3754
+ return toMinorUnits(negative, m[1].replace(/,/g, ""), m[2] ?? "", displayExponent(c));
3755
+ }
3397
3756
  // Annotate the CommonJS export names for ESM import in node:
3398
3757
  0 && (module.exports = {
3758
+ CURRENCIES,
3399
3759
  ThrottleClient,
3760
+ UnknownCurrencyError,
3400
3761
  VERSION,
3401
3762
  buildInstructions,
3402
3763
  createServer,
3764
+ currencySymbol,
3765
+ formatMoney,
3766
+ isKnownCurrency,
3403
3767
  loadContractIndex,
3404
3768
  loadDocsIndex,
3405
- registerableActions
3769
+ minorUnitsOf,
3770
+ money,
3771
+ moneyValue,
3772
+ parseMoney,
3773
+ registerableActions,
3774
+ toDecimalString,
3775
+ toMinor
3406
3776
  });
3407
3777
  //# sourceMappingURL=lib.cjs.map