@usethrottle/mcp 0.4.4 → 0.5.1

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/mcp.js CHANGED
@@ -826,7 +826,7 @@ var ACTIONS = [
826
826
  {
827
827
  id: "receivables_aging",
828
828
  title: "Receivables aging",
829
- description: 'Outstanding receivables bucketed by age \u2014 answers "what is overdue and by how long".',
829
+ description: 'Outstanding receivables bucketed by age \u2014 answers "what is overdue and by how long". Totals come back per currency in byCurrency, never summed across currencies.',
830
830
  kind: "read",
831
831
  scopes: ["invoices:read"],
832
832
  input: [
@@ -972,7 +972,7 @@ var ACTIONS = [
972
972
  {
973
973
  id: "list_abandoned_carts",
974
974
  title: "List abandoned carts",
975
- description: "Carts that were started but never finalized, with recovery status \u2014 the abandoned-cart recovery list.",
975
+ description: "Carts that were started but never finalized, with recovery status \u2014 the abandoned-cart recovery list. The summary value comes back per currency in byCurrency, never summed.",
976
976
  kind: "read",
977
977
  scopes: ["carts:read"],
978
978
  input: [
@@ -1213,7 +1213,7 @@ var ACTIONS = [
1213
1213
  {
1214
1214
  id: "get_sales_timeseries",
1215
1215
  title: "Sales over time",
1216
- description: `Order count and gross revenue bucketed by day, week or month over any date range, in the merchant's timezone, optionally compared to the previous period or the same range last year. Use this for "how much did we sell on/last/between\u2026" instead of paging search_orders and adding it up.`,
1216
+ description: `Order count and gross revenue bucketed by day, week or month over any date range, in the merchant's timezone, optionally compared to the previous period or the same range last year. Use this for "how much did we sell on/last/between\u2026" instead of paging search_orders. Amounts come back per currency in byCurrency, never as one total; report each currency separately.`,
1217
1217
  kind: "read",
1218
1218
  scopes: ["orders:read"],
1219
1219
  input: [
@@ -1238,7 +1238,7 @@ var ACTIONS = [
1238
1238
  {
1239
1239
  id: "get_business_summary",
1240
1240
  title: "Business summary",
1241
- description: "How are we doing? Orders/revenue, subscription MRR, receivables and quotes pipeline over a date range, compared to the immediately preceding window of equal length. Note: period=week|month|quarter means the TRAILING 7/30/90 days, not a calendar period \u2014 pass from/to for calendar months.",
1241
+ description: "How are we doing? Orders/revenue, subscription MRR, receivables and quotes pipeline over a date range, compared to the immediately preceding window of equal length. Note: period=week|month|quarter means the TRAILING 7/30/90 days, not a calendar period \u2014 pass from/to for calendar months. Money comes back per currency in byCurrency (revenue, MRR, receivables, quotes), never summed across currencies; report each currency separately.",
1242
1242
  kind: "read",
1243
1243
  scopes: [],
1244
1244
  sectionScopes: ["orders:read", "subscriptions:read", "invoices:read", "quotes:read"],
@@ -1270,7 +1270,7 @@ var ACTIONS = [
1270
1270
  {
1271
1271
  id: "get_top_products",
1272
1272
  title: "Top products",
1273
- description: "Best-selling products over a date range, by revenue or units sold. Line items come from the merchant's own cart payload, so a product is identified by its external reference id when present and by name otherwise. The response carries both the top-N rows (by the chosen sort) and range-wide totals across every matching product, so you can compute what share of total revenue/units the top N represent.",
1273
+ description: "Best-selling products over a date range, by revenue or units sold. Line items come from the merchant's own cart payload, so a product is identified by its external reference id when present and by name otherwise. The response carries both the top-N rows (by the chosen sort) and range-wide totals across every matching product, so you can compute what share of total revenue/units the top N represent. Revenue is per currency (byCurrency on each row and in the totals); rows rank by the main currency, and revenue is never summed across currencies.",
1274
1274
  kind: "read",
1275
1275
  scopes: ["orders:read"],
1276
1276
  input: [
@@ -1295,7 +1295,7 @@ var ACTIONS = [
1295
1295
  {
1296
1296
  id: "get_attention_digest",
1297
1297
  title: "Attention digest",
1298
- description: "What needs attention right now? Open disputes, subscriptions in dunning, overdue Net-N invoices, and webhooks with degraded delivery health \u2014 a point-in-time snapshot, not a time range.",
1298
+ description: "What needs attention right now? Open disputes, subscriptions in dunning, overdue Net-N invoices, and webhooks with degraded delivery health \u2014 a point-in-time snapshot, not a time range. Dispute and overdue-invoice amounts come back per currency in byCurrency, never summed.",
1299
1299
  kind: "read",
1300
1300
  scopes: [],
1301
1301
  sectionScopes: ["payment_disputes:read", "subscriptions:read", "invoices:read", "webhook_deliveries:read"],
@@ -1316,7 +1316,7 @@ var ACTIONS = [
1316
1316
  {
1317
1317
  id: "get_customer_growth",
1318
1318
  title: "Customer growth",
1319
- description: "Customer growth over a date range: signups per day/week/month, how many orders came from first-time versus returning customers, and the highest-value customers in the window.",
1319
+ description: "Customer growth over a date range: signups per day/week/month, how many orders came from first-time versus returning customers, and the highest-value customers in the window. Revenue is per currency in byCurrency (top customers rank by the main currency); customer counts stay all-currency.",
1320
1320
  kind: "read",
1321
1321
  scopes: ["customers:read"],
1322
1322
  input: [
@@ -1344,7 +1344,7 @@ var ACTIONS = [
1344
1344
  {
1345
1345
  id: "get_revenue_breakdown",
1346
1346
  title: "Revenue breakdown",
1347
- description: "Revenue split by one dimension over a date range \u2014 payment method, order source, or currency. Amounts are gross; refunds are not deducted.",
1347
+ description: "Revenue split by one dimension over a date range \u2014 payment method, order source, or currency. Amounts are gross; refunds are not deducted. Amounts are per currency in byCurrency; with dimension=currency each row carries only its own currency.",
1348
1348
  kind: "read",
1349
1349
  scopes: ["orders:read"],
1350
1350
  input: [
@@ -1401,7 +1401,7 @@ var ACTIONS = [
1401
1401
  {
1402
1402
  id: "get_subscription_movement",
1403
1403
  title: "Subscription movement",
1404
- description: "Subscription movement over a date range: new subscriptions, cancellations and net MRR change per day/week/month. Figures are reconstructed from subscription timestamps, not a stored historical snapshot.",
1404
+ description: "Subscription movement over a date range: new subscriptions, cancellations and net MRR change per day/week/month. Figures are reconstructed from subscription timestamps, not a stored historical snapshot. MRR change is per currency in byCurrency, never summed across currencies.",
1405
1405
  kind: "read",
1406
1406
  scopes: ["subscriptions:read"],
1407
1407
  input: [
@@ -1419,15 +1419,15 @@ var ACTIONS = [
1419
1419
  requests: [{ method: "GET", path: "/api/v1/analytics/subscriptions" }],
1420
1420
  channels: ["mcp", "zapier", "make", "n8n"],
1421
1421
  guardrails: [
1422
- "newSubscriptions, churnedSubscriptions and mrrDeltaCents are reconstructed per bucket from subscription created_at/cancelled_at timestamps, not a stored historical MRR snapshot \u2014 never present this series as an audited historical MRR ledger.",
1423
- "mrrDeltaCents for a bucket only credits subscriptions created in that bucket that are still active right now, and only debits subscriptions cancelled in that bucket that already existed when it started. A subscription created AND cancelled inside the same bucket still counts toward both newSubscriptions and churnedSubscriptions but contributes 0 to mrrDeltaCents.",
1424
- "totals is the sum over the full series (the series is never truncated), so totals.newSubscriptions/.churnedSubscriptions/.netMrrDeltaCents always equal the corresponding sums of series[]."
1422
+ "newSubscriptions, churnedSubscriptions and the MRR change (byCurrency) are reconstructed per bucket from subscription created_at/cancelled_at timestamps, not a stored historical MRR snapshot \u2014 never present this series as an audited historical MRR ledger.",
1423
+ "The MRR change for a bucket only credits subscriptions created in that bucket that are still active right now, and only debits subscriptions cancelled in that bucket that already existed when it started. A subscription created AND cancelled inside the same bucket still counts toward both newSubscriptions and churnedSubscriptions but contributes 0 to the MRR change.",
1424
+ "totals is the sum over the full series (the series is never truncated), so totals.newSubscriptions/.churnedSubscriptions always equal the corresponding sums of series[], and totals.byCurrency[] equals the per-currency sums of series[].byCurrency."
1425
1425
  ]
1426
1426
  },
1427
1427
  {
1428
1428
  id: "get_discount_performance",
1429
1429
  title: "Discount performance",
1430
- description: "Discount code performance over a date range: redemption count, revenue on discounted orders, and total discount given per code.",
1430
+ description: "Discount code performance over a date range: redemption count, revenue on discounted orders, and total discount given per code. Revenue and discount given are per currency in byCurrency; codes rank by the main currency.",
1431
1431
  kind: "read",
1432
1432
  scopes: ["discounts:read"],
1433
1433
  input: [
@@ -1445,9 +1445,9 @@ var ACTIONS = [
1445
1445
  requests: [{ method: "GET", path: "/api/v1/analytics/discounts" }],
1446
1446
  channels: ["mcp", "zapier", "make", "n8n"],
1447
1447
  guardrails: [
1448
- 'discountedRevenueCents and discountGivenCents are DIFFERENT measures: discountedRevenueCents is the gross order total on orders that redeemed the code; discountGivenCents is the discount amount taken off those same orders. Never describe discountedRevenueCents as "given away" or discountGivenCents as revenue.',
1449
- "Only orders with status <> draft and a gross-eligible payment_status are counted; refunds are not deducted from discountedRevenueCents, because that needs payment_refunds:read.",
1450
- "rows are the top N codes by discount given; totals is a SEPARATE whole-range aggregate (not a reduction over rows), so totals.redemptions / totals.discountGivenCents stay valid even when rows is truncated by limit."
1448
+ 'In byCurrency, amount (discounted revenue) and discountGiven are DIFFERENT measures: amount is the gross order total on orders that redeemed the code; discountGiven is the discount amount taken off those same orders. Never describe the amount as "given away" or discountGiven as revenue.',
1449
+ "Only orders with status <> draft and a gross-eligible payment_status are counted; refunds are not deducted from the discounted revenue amount, because that needs payment_refunds:read.",
1450
+ "rows are the top N codes by discount given; totals is a SEPARATE whole-range aggregate (not a reduction over rows), so totals.redemptions / totals.byCurrency[].discountGiven stay valid even when rows is truncated by limit."
1451
1451
  ]
1452
1452
  },
1453
1453
  // ------------------------------------------------------------ sandbox write
@@ -2659,12 +2659,574 @@ function applyModifiers(field, type) {
2659
2659
  return field.default === void 0 ? described.optional() : described.default(field.default);
2660
2660
  }
2661
2661
 
2662
+ // ../money/dist/index.js
2663
+ var CURRENCY_ROWS = [
2664
+ ["AED", 2, "AED", false],
2665
+ ["AFN", 2, "AFN", false],
2666
+ ["ALL", 2, "ALL", false],
2667
+ ["AMD", 2, "AMD", false],
2668
+ ["AOA", 2, "AOA", false],
2669
+ ["ARS", 2, "ARS", false],
2670
+ ["AUD", 2, "A$", false],
2671
+ ["AWG", 2, "AWG", false],
2672
+ ["AZN", 2, "AZN", false],
2673
+ ["BAM", 2, "BAM", false],
2674
+ ["BBD", 2, "BBD", false],
2675
+ ["BDT", 2, "BDT", false],
2676
+ ["BHD", 3, "BHD", false],
2677
+ ["BIF", 0, "BIF", false],
2678
+ ["BMD", 2, "BMD", false],
2679
+ ["BND", 2, "BND", false],
2680
+ ["BOB", 2, "BOB", false],
2681
+ ["BOV", 2, "BOV", true],
2682
+ ["BRL", 2, "R$", false],
2683
+ ["BSD", 2, "BSD", false],
2684
+ ["BTN", 2, "BTN", false],
2685
+ ["BWP", 2, "BWP", false],
2686
+ ["BYN", 2, "BYN", false],
2687
+ ["BZD", 2, "BZD", false],
2688
+ ["CAD", 2, "CA$", false],
2689
+ ["CDF", 2, "CDF", false],
2690
+ ["CHE", 2, "CHE", true],
2691
+ ["CHF", 2, "CHF", false],
2692
+ ["CHW", 2, "CHW", true],
2693
+ ["CLF", 4, "CLF", true],
2694
+ ["CLP", 0, "CLP", false],
2695
+ ["CNY", 2, "CN\xA5", false],
2696
+ ["COP", 2, "COP", false],
2697
+ ["COU", 2, "COU", true],
2698
+ ["CRC", 2, "CRC", false],
2699
+ ["CUP", 2, "CUP", false],
2700
+ ["CVE", 2, "CVE", false],
2701
+ ["CZK", 2, "CZK", false],
2702
+ ["DJF", 0, "DJF", false],
2703
+ ["DKK", 2, "DKK", false],
2704
+ ["DOP", 2, "DOP", false],
2705
+ ["DZD", 2, "DZD", false],
2706
+ ["EGP", 2, "EGP", false],
2707
+ ["ERN", 2, "ERN", false],
2708
+ ["ETB", 2, "ETB", false],
2709
+ ["EUR", 2, "\u20AC", false],
2710
+ ["FJD", 2, "FJD", false],
2711
+ ["FKP", 2, "FKP", false],
2712
+ ["GBP", 2, "\xA3", false],
2713
+ ["GEL", 2, "GEL", false],
2714
+ ["GHS", 2, "GHS", false],
2715
+ ["GIP", 2, "GIP", false],
2716
+ ["GMD", 2, "GMD", false],
2717
+ ["GNF", 0, "GNF", false],
2718
+ ["GTQ", 2, "GTQ", false],
2719
+ ["GYD", 2, "GYD", false],
2720
+ ["HKD", 2, "HK$", false],
2721
+ ["HNL", 2, "HNL", false],
2722
+ ["HTG", 2, "HTG", false],
2723
+ ["HUF", 2, "HUF", false],
2724
+ ["IDR", 2, "IDR", false],
2725
+ ["ILS", 2, "\u20AA", false],
2726
+ ["INR", 2, "\u20B9", false],
2727
+ ["IQD", 3, "IQD", false],
2728
+ ["IRR", 2, "IRR", false],
2729
+ ["ISK", 0, "ISK", false],
2730
+ ["JMD", 2, "JMD", false],
2731
+ ["JOD", 3, "JOD", false],
2732
+ ["JPY", 0, "\xA5", false],
2733
+ ["KES", 2, "KES", false],
2734
+ ["KGS", 2, "KGS", false],
2735
+ ["KHR", 2, "KHR", false],
2736
+ ["KMF", 0, "KMF", false],
2737
+ ["KPW", 2, "KPW", false],
2738
+ ["KRW", 0, "\u20A9", false],
2739
+ ["KWD", 3, "KWD", false],
2740
+ ["KYD", 2, "KYD", false],
2741
+ ["KZT", 2, "KZT", false],
2742
+ ["LAK", 2, "LAK", false],
2743
+ ["LBP", 2, "LBP", false],
2744
+ ["LKR", 2, "LKR", false],
2745
+ ["LRD", 2, "LRD", false],
2746
+ ["LSL", 2, "LSL", false],
2747
+ ["LYD", 3, "LYD", false],
2748
+ ["MAD", 2, "MAD", false],
2749
+ ["MDL", 2, "MDL", false],
2750
+ ["MGA", 2, "MGA", false],
2751
+ ["MKD", 2, "MKD", false],
2752
+ ["MMK", 2, "MMK", false],
2753
+ ["MNT", 2, "MNT", false],
2754
+ ["MOP", 2, "MOP", false],
2755
+ ["MRU", 2, "MRU", false],
2756
+ ["MUR", 2, "MUR", false],
2757
+ ["MVR", 2, "MVR", false],
2758
+ ["MWK", 2, "MWK", false],
2759
+ ["MXN", 2, "MX$", false],
2760
+ ["MXV", 2, "MXV", true],
2761
+ ["MYR", 2, "MYR", false],
2762
+ ["MZN", 2, "MZN", false],
2763
+ ["NAD", 2, "NAD", false],
2764
+ ["NGN", 2, "NGN", false],
2765
+ ["NIO", 2, "NIO", false],
2766
+ ["NOK", 2, "NOK", false],
2767
+ ["NPR", 2, "NPR", false],
2768
+ ["NZD", 2, "NZ$", false],
2769
+ ["OMR", 3, "OMR", false],
2770
+ ["PAB", 2, "PAB", false],
2771
+ ["PEN", 2, "PEN", false],
2772
+ ["PGK", 2, "PGK", false],
2773
+ ["PHP", 2, "\u20B1", false],
2774
+ ["PKR", 2, "PKR", false],
2775
+ ["PLN", 2, "PLN", false],
2776
+ ["PYG", 0, "PYG", false],
2777
+ ["QAR", 2, "QAR", false],
2778
+ ["RON", 2, "RON", false],
2779
+ ["RSD", 2, "RSD", false],
2780
+ ["RUB", 2, "RUB", false],
2781
+ ["RWF", 0, "RWF", false],
2782
+ ["SAR", 2, "SAR", false],
2783
+ ["SBD", 2, "SBD", false],
2784
+ ["SCR", 2, "SCR", false],
2785
+ ["SDG", 2, "SDG", false],
2786
+ ["SEK", 2, "SEK", false],
2787
+ ["SGD", 2, "SGD", false],
2788
+ ["SHP", 2, "SHP", false],
2789
+ ["SLE", 2, "SLE", false],
2790
+ ["SOS", 2, "SOS", false],
2791
+ ["SRD", 2, "SRD", false],
2792
+ ["SSP", 2, "SSP", false],
2793
+ ["STN", 2, "STN", false],
2794
+ ["SVC", 2, "SVC", false],
2795
+ ["SYP", 2, "SYP", false],
2796
+ ["SZL", 2, "SZL", false],
2797
+ ["THB", 2, "THB", false],
2798
+ ["TJS", 2, "TJS", false],
2799
+ ["TMT", 2, "TMT", false],
2800
+ ["TND", 3, "TND", false],
2801
+ ["TOP", 2, "TOP", false],
2802
+ ["TRY", 2, "TRY", false],
2803
+ ["TTD", 2, "TTD", false],
2804
+ ["TWD", 2, "NT$", false],
2805
+ ["TZS", 2, "TZS", false],
2806
+ ["UAH", 2, "UAH", false],
2807
+ ["UGX", 0, "UGX", false],
2808
+ ["USD", 2, "$", false],
2809
+ ["USN", 2, "USN", true],
2810
+ ["UYI", 0, "UYI", true],
2811
+ ["UYU", 2, "UYU", false],
2812
+ ["UYW", 4, "UYW", true],
2813
+ ["UZS", 2, "UZS", false],
2814
+ ["VED", 2, "VED", false],
2815
+ ["VES", 2, "VES", false],
2816
+ ["VND", 0, "\u20AB", false],
2817
+ ["VUV", 0, "VUV", false],
2818
+ ["WST", 2, "WST", false],
2819
+ ["XAD", 2, "XAD", true],
2820
+ ["XAF", 0, "FCFA", false],
2821
+ ["XCD", 2, "EC$", false],
2822
+ ["XCG", 2, "Cg.", false],
2823
+ ["XOF", 0, "F\u202FCFA", false],
2824
+ ["XPF", 0, "CFPF", false],
2825
+ ["YER", 2, "YER", false],
2826
+ ["ZAR", 2, "ZAR", false],
2827
+ ["ZMW", 2, "ZMW", false],
2828
+ ["ZWG", 2, "ZWG", false]
2829
+ ];
2830
+ var BY_CODE = new Map(
2831
+ CURRENCY_ROWS.map(([code, minorUnits, symbol, fund]) => [code, { minorUnits, symbol, fund }])
2832
+ );
2833
+ var CURRENCIES = Object.freeze(
2834
+ CURRENCY_ROWS.map(([code, minorUnits, symbol]) => Object.freeze({ code, minorUnits, symbol }))
2835
+ );
2836
+ var UNCONFIRMED = /* @__PURE__ */ new Set([
2837
+ "AFN",
2838
+ "BTN",
2839
+ "CDF",
2840
+ "CLP",
2841
+ "COP",
2842
+ "CVE",
2843
+ "ERN",
2844
+ "HUF",
2845
+ "IDR",
2846
+ "IRR",
2847
+ "ISK",
2848
+ "KPW",
2849
+ "LBP",
2850
+ "LRD",
2851
+ "LSL",
2852
+ "MGA",
2853
+ "SDG",
2854
+ "SSP",
2855
+ "SYP",
2856
+ "TJS",
2857
+ "TMT",
2858
+ "TWD",
2859
+ "UGX",
2860
+ "VED",
2861
+ "VES",
2862
+ "ZWG"
2863
+ ]);
2864
+ var UNCONFIRMED_EXPONENT_CODES = Object.freeze({
2865
+ has: (code) => UNCONFIRMED.has(code),
2866
+ get size() {
2867
+ return UNCONFIRMED.size;
2868
+ },
2869
+ forEach: (fn, thisArg) => UNCONFIRMED.forEach((v) => fn.call(thisArg, v, v, UNCONFIRMED_EXPONENT_CODES)),
2870
+ keys: () => UNCONFIRMED.keys(),
2871
+ values: () => UNCONFIRMED.values(),
2872
+ entries: () => UNCONFIRMED.entries(),
2873
+ [Symbol.iterator]: () => UNCONFIRMED.values()
2874
+ });
2875
+ function currencyRow(code) {
2876
+ return BY_CODE.get(code);
2877
+ }
2878
+ function isKnownCurrency(code) {
2879
+ return BY_CODE.has(code);
2880
+ }
2881
+ var NBSP = "\xA0";
2882
+ function normalizeCode(code) {
2883
+ return typeof code === "string" ? code.trim().toUpperCase() : "";
2884
+ }
2885
+ function roundHalfAwayFromZero(n) {
2886
+ return n < 0 ? -Math.round(-n) : Math.round(n);
2887
+ }
2888
+ function decimalDigits(abs, exponent, grouped) {
2889
+ const raw = Number.isSafeInteger(abs) ? String(abs) : BigInt(abs).toString();
2890
+ const padded = raw.padStart(exponent + 1, "0");
2891
+ const cut = padded.length - exponent;
2892
+ let integer = padded.slice(0, cut);
2893
+ if (grouped) integer = integer.replace(/\B(?=(\d{3})+(?!\d))/g, ",");
2894
+ return exponent === 0 ? integer : `${integer}.${padded.slice(cut)}`;
2895
+ }
2896
+ function formatMoney(minor, code, opts) {
2897
+ if (typeof minor !== "number" || !Number.isFinite(minor)) return "\u2014";
2898
+ const c = normalizeCode(code);
2899
+ const row = currencyRow(c);
2900
+ const n = roundHalfAwayFromZero(minor);
2901
+ const sign = n < 0 ? "-" : "";
2902
+ const digits = decimalDigits(Math.abs(n), row?.minorUnits ?? 2, true);
2903
+ if (c === "") return sign + digits;
2904
+ if (row === void 0) return `${sign}${digits}${NBSP}${c}`;
2905
+ const separator = new RegExp("\\p{Sc}$", "u").test(row.symbol) ? "" : NBSP;
2906
+ const text = `${sign}${row.symbol}${separator}${digits}`;
2907
+ return opts?.display === "symbol-code" && row.symbol !== c ? `${text}${NBSP}${c}` : text;
2908
+ }
2909
+ function moneyValue(amount, currency) {
2910
+ return { amount, currency: normalizeCode(currency), display: formatMoney(amount, currency) };
2911
+ }
2912
+
2913
+ // src/money.ts
2914
+ var M = "money";
2915
+ var DROP = "drop";
2916
+ var MK = (values) => ({ __moneyKeyed: values });
2917
+ var CURRENCY_OF = (sibling, spec) => ({ __currencyOf: { sibling, spec } });
2918
+ var DROP_WHEN = (field, equals) => ({ __dropWhen: { field, equals } });
2919
+ var ORDERS_WINDOW = { grossCents: DROP, avgOrderCents: DROP, refundsCents: DROP, netCents: DROP };
2920
+ var QUOTE_BUCKET = { totalCents: DROP };
2921
+ var LINE_ITEM = {
2922
+ unitPrice: M,
2923
+ subtotal: M,
2924
+ discountAmount: M,
2925
+ taxAmount: M,
2926
+ total: M,
2927
+ // amount: a trial line's renewal price; schedule: per-unit installment amounts.
2928
+ recurring: { amount: M, scheduleUnitTotal: M, schedule: [{ amount: M }] }
2929
+ };
2930
+ var ORDER = {
2931
+ subtotal: M,
2932
+ discountTotal: M,
2933
+ shippingTotal: M,
2934
+ taxTotal: M,
2935
+ total: M,
2936
+ capturedAmount: M,
2937
+ refundedAmount: M,
2938
+ compAmount: M,
2939
+ shippingMethod: { amount: M },
2940
+ lineItems: [LINE_ITEM],
2941
+ // MC4-R93: what order creation writes into metadata (commerce-orders).
2942
+ // `appliedDiscount.amount` is the order's own discount, in its currency. The
2943
+ // F-6 `discountScope.value` is the code's config copied as it was: on a fixed
2944
+ // code, the main-currency amount (500 USD on a EUR order), so it is dropped;
2945
+ // a percentage code's value is its percent and stays.
2946
+ metadata: {
2947
+ discountScope: { value: DROP_WHEN("type", "fixed_amount") },
2948
+ appliedDiscount: { amount: M }
2949
+ }
2950
+ };
2951
+ var PAYMENT = { amount: M, capturedAmount: M, usdAmountMinor: DROP };
2952
+ var TRANSACTION = { amount: M };
2953
+ var RETURN = { refundAmount: M, items: [{ amount: M }] };
2954
+ var FULFILLMENT = { detail: { shippingCost: M, insuranceAmount: M } };
2955
+ var SUBSCRIPTION = {
2956
+ amount: M,
2957
+ pendingAmount: M,
2958
+ scheduleTotal: M,
2959
+ nextPaymentAmount: M,
2960
+ paymentSchedule: [{ amount: M, discount: M, net: M }],
2961
+ renewalIssue: { charge: { amount: M } }
2962
+ };
2963
+ var QUOTE_ITEM = {
2964
+ unitPrice: M,
2965
+ subtotal: M,
2966
+ discountAmount: M,
2967
+ taxAmount: M,
2968
+ total: M,
2969
+ recurring: { schedule: [{ amount: M }] }
2970
+ };
2971
+ var QUOTE_REVISION = {
2972
+ subtotal: M,
2973
+ discountTotal: M,
2974
+ shippingTotal: M,
2975
+ taxTotal: M,
2976
+ total: M,
2977
+ depositAmount: M,
2978
+ shippingFlatAmount: M,
2979
+ // MC4-R82: a fixed deposit's `value` is a minor-unit amount (unlabelled, and
2980
+ // `depositAmount` carries it); a percent deposit's `value` is its percent and stays.
2981
+ paymentTerms: { deposit: { value: DROP_WHEN("type", "fixed") } },
2982
+ items: [QUOTE_ITEM],
2983
+ acceptanceSelections: { effectiveTotal: M }
2984
+ };
2985
+ var QUOTE_SUMMARY = { total: M, acceptance: { effectiveTotal: M, effectiveGoodsTotal: M } };
2986
+ var QUOTE = {
2987
+ ...QUOTE_SUMMARY,
2988
+ revisions: [QUOTE_REVISION],
2989
+ // `revision_issued` records the total, `accepted` the effective total, `price_overridden` the new prices.
2990
+ timeline: [{ data: { total: M, effectiveTotal: M, items: [{ unitPrice: M }] } }]
2991
+ };
2992
+ var INVOICE = {
2993
+ subtotal: M,
2994
+ taxTotal: M,
2995
+ shippingTotal: M,
2996
+ discountTotal: M,
2997
+ total: M,
2998
+ amountRefunded: M,
2999
+ billingSnapshot: {
3000
+ lineItems: [{ unitPrice: M, taxAmount: M, discountAmount: M, total: M }],
3001
+ totals: {
3002
+ subtotal: M,
3003
+ taxTotal: M,
3004
+ shippingTotal: M,
3005
+ discountTotal: M,
3006
+ total: M,
3007
+ orderTotal: M,
3008
+ amountPaid: M,
3009
+ compWaived: M,
3010
+ balanceDue: M
3011
+ }
3012
+ }
3013
+ };
3014
+ var DISCOUNT = {
3015
+ value: DROP_WHEN("type", "fixed_amount"),
3016
+ // `min_order`: the legacy alias legacyMinimumOf still reads on old rows.
3017
+ conditions: { minOrder: DROP, min_order: DROP },
3018
+ amounts: MK({ value: M, minOrder: M })
3019
+ };
3020
+ var CART = {
3021
+ subtotal: M,
3022
+ taxTotal: M,
3023
+ discountTotal: M,
3024
+ shippingTotal: M,
3025
+ total: M,
3026
+ lineItems: [LINE_ITEM],
3027
+ items: [LINE_ITEM],
3028
+ appliedDiscount: { amount: M },
3029
+ selectedShipping: { rateAmount: M },
3030
+ taxLines: [{ amount: M }]
3031
+ };
3032
+ var EVENT_DATA = {
3033
+ amount: M,
3034
+ capturedAmount: M,
3035
+ subtotal: M,
3036
+ taxTotal: M,
3037
+ shippingTotal: M,
3038
+ discountTotal: M,
3039
+ total: M,
3040
+ compAmount: M,
3041
+ refundedAmount: M,
3042
+ paymentAmount: M,
3043
+ amountRefunded: M,
3044
+ totalRefunded: M,
3045
+ refundAmount: M,
3046
+ totalAmount: M,
3047
+ unitPrice: M,
3048
+ rateAmount: M,
3049
+ scheduleTotal: M,
3050
+ nextPaymentAmount: M,
3051
+ order: { ...ORDER, items: [LINE_ITEM] },
3052
+ payment: PAYMENT,
3053
+ subscription: SUBSCRIPTION,
3054
+ previous: { amount: M },
3055
+ pending: { amount: M },
3056
+ recurring: { amount: M },
3057
+ cart: CART,
3058
+ lineItems: [LINE_ITEM],
3059
+ items: [{ ...LINE_ITEM, amount: M }],
3060
+ quote: QUOTE_SUMMARY,
3061
+ revision: QUOTE_REVISION,
3062
+ charge: { amount: M, amountCents: M }
3063
+ };
3064
+ var EVENT = { data: EVENT_DATA };
3065
+ var DELIVERY = { payload: { data: EVENT_DATA } };
3066
+ var SESSION = {
3067
+ recurringTerms: { firstChargeAmountMinor: M },
3068
+ subscriptions: [{ amount: M, firstChargeAmount: M, schedule: [{ net: M }] }]
3069
+ };
3070
+ var page2 = (row) => ({ data: [row] });
3071
+ var MONEY_SPECS = {
3072
+ search_orders: page2(ORDER),
3073
+ get_order: {
3074
+ order: ORDER,
3075
+ payments: [PAYMENT],
3076
+ returns: CURRENCY_OF("order", [RETURN]),
3077
+ fulfillments: CURRENCY_OF("order", [FULFILLMENT])
3078
+ },
3079
+ search_payments: page2(PAYMENT),
3080
+ get_payment: { payment: PAYMENT, transactions: [TRANSACTION] },
3081
+ get_customer: { subscriptions: [SUBSCRIPTION] },
3082
+ list_subscriptions: page2(SUBSCRIPTION),
3083
+ get_subscription: SUBSCRIPTION,
3084
+ search_quotes: page2(QUOTE_SUMMARY),
3085
+ get_quote: QUOTE,
3086
+ list_invoices: page2(INVOICE),
3087
+ get_invoice: INVOICE,
3088
+ search_discounts: page2(DISCOUNT),
3089
+ get_discount: DISCOUNT,
3090
+ search_events: page2(EVENT),
3091
+ list_webhook_deliveries: page2(DELIVERY),
3092
+ get_webhook_delivery: DELIVERY,
3093
+ explain_checkout_failure: {
3094
+ session: SESSION,
3095
+ cart: CART,
3096
+ events: [EVENT],
3097
+ recentWebhookDeliveries: [DELIVERY]
3098
+ },
3099
+ // Writes that return a record. Each added line item echoes its cart's
3100
+ // `currency`; the sibling cart's is the fallback for one that does not.
3101
+ seed_test_data: { cart: CART, lineItems: CURRENCY_OF("cart", [LINE_ITEM]), order: ORDER },
3102
+ create_quote: { quote: QUOTE_SUMMARY, revision: QUOTE_REVISION, items: [QUOTE_ITEM] },
3103
+ manage_subscription: SUBSCRIPTION,
3104
+ set_subscription_payment_method: SUBSCRIPTION,
3105
+ // GET /api/v1/stores: `settings.shipping` is stamped with its own currency
3106
+ // (MC1-R74); an unstamped one takes the store's.
3107
+ list_applications: [{ settings: { shipping: { flatRateCents: M, freeThresholdCents: M } } }],
3108
+ // ---------------------------------------------------------------- analytics
3109
+ get_sales_timeseries: {
3110
+ totalGrossCents: DROP,
3111
+ series: [{ grossCents: DROP }],
3112
+ comparison: { totalGrossCents: DROP }
3113
+ },
3114
+ get_business_summary: {
3115
+ orders: { current: ORDERS_WINDOW, previous: ORDERS_WINDOW, deltaPct: DROP },
3116
+ subscriptions: { mrr: { currentCents: DROP, periodStartCents: DROP, deltaPct: DROP } },
3117
+ receivables: { outstandingCents: DROP },
3118
+ quotes: { sent: QUOTE_BUCKET, accepted: QUOTE_BUCKET, expired: QUOTE_BUCKET, declined: QUOTE_BUCKET }
3119
+ },
3120
+ get_attention_digest: {
3121
+ disputes: { totalCents: DROP },
3122
+ overdueInvoices: { totalCents: DROP }
3123
+ },
3124
+ get_top_products: {
3125
+ rows: [{ revenueCents: DROP }],
3126
+ totals: { revenueCents: DROP }
3127
+ },
3128
+ get_customer_growth: {
3129
+ topCustomers: [{ revenueCents: DROP }],
3130
+ totals: { revenueCents: DROP }
3131
+ },
3132
+ get_revenue_breakdown: {
3133
+ rows: [{ grossCents: DROP }],
3134
+ totals: { grossCents: DROP }
3135
+ },
3136
+ get_subscription_movement: {
3137
+ series: [{ mrrDeltaCents: DROP }],
3138
+ totals: { netMrrDeltaCents: DROP }
3139
+ },
3140
+ get_discount_performance: {
3141
+ rows: [{ discountedRevenueCents: DROP, discountGivenCents: DROP }],
3142
+ totals: { discountedRevenueCents: DROP, discountGivenCents: DROP }
3143
+ },
3144
+ receivables_aging: {
3145
+ buckets: [{ total_amount: DROP }],
3146
+ total_outstanding_amount: DROP
3147
+ },
3148
+ // The handler returns `{ carts, summary }`; `summary` is the
3149
+ // /abandoned-carts/summary payload, or optional()'s unavailable string.
3150
+ list_abandoned_carts: {
3151
+ carts: [{ total: M }],
3152
+ summary: { abandonedValue: DROP }
3153
+ }
3154
+ };
3155
+ var isPlainObject3 = (v) => !!v && typeof v === "object" && !Array.isArray(v);
3156
+ var join = (path, key) => path ? `${path}.${key}` : key;
3157
+ function knownCode(v) {
3158
+ if (typeof v !== "string") return void 0;
3159
+ const code = v.trim().toUpperCase();
3160
+ return isKnownCurrency(code) ? code : void 0;
3161
+ }
3162
+ function walk2(spec, value, currency, path, unwrapped) {
3163
+ if (spec === DROP) return value;
3164
+ if (spec === M) {
3165
+ if (typeof value !== "number") return value;
3166
+ if (!currency) {
3167
+ unwrapped.push(path);
3168
+ return value;
3169
+ }
3170
+ return moneyValue(value, currency);
3171
+ }
3172
+ if (Array.isArray(spec)) {
3173
+ if (!Array.isArray(value)) return value;
3174
+ return value.map((item, i) => walk2(spec[0], item, currency, `${path}[${i}]`, unwrapped));
3175
+ }
3176
+ if ("__currencyOf" in spec || "__dropWhen" in spec) {
3177
+ throw new Error(`money spec at "${path}": CURRENCY_OF and DROP_WHEN are only valid as an object child`);
3178
+ }
3179
+ if (!isPlainObject3(value)) return value;
3180
+ if ("__moneyKeyed" in spec) {
3181
+ const inner = spec.__moneyKeyed;
3182
+ return Object.fromEntries(
3183
+ Object.entries(value).map(([code, item]) => [
3184
+ code,
3185
+ walk2(inner, item, knownCode(code), join(path, code), unwrapped)
3186
+ ])
3187
+ );
3188
+ }
3189
+ const own = "currency" in value ? knownCode(value.currency) : currency;
3190
+ const out = { ...value };
3191
+ for (const [key, child] of Object.entries(spec)) {
3192
+ if (!(key in value)) continue;
3193
+ if (child === DROP) {
3194
+ delete out[key];
3195
+ continue;
3196
+ }
3197
+ if (typeof child === "object" && "__dropWhen" in child) {
3198
+ const { field, equals } = child.__dropWhen;
3199
+ if (value[field] === equals) delete out[key];
3200
+ continue;
3201
+ }
3202
+ if (typeof child === "object" && "__currencyOf" in child) {
3203
+ const { sibling, spec: inner } = child.__currencyOf;
3204
+ const record = value[sibling];
3205
+ const siblingCurrency = isPlainObject3(record) ? knownCode(record.currency) : void 0;
3206
+ out[key] = walk2(inner, value[key], siblingCurrency, join(path, key), unwrapped);
3207
+ continue;
3208
+ }
3209
+ out[key] = walk2(child, value[key], own, join(path, key), unwrapped);
3210
+ }
3211
+ return out;
3212
+ }
3213
+ function applyMoneySpec(spec, value) {
3214
+ const unwrapped = [];
3215
+ return { value: walk2(spec, value, void 0, "", unwrapped), unwrapped };
3216
+ }
3217
+ function decorateMoney(actionId, value) {
3218
+ const spec = MONEY_SPECS[actionId];
3219
+ return spec ? applyMoneySpec(spec, value) : { value, unwrapped: [] };
3220
+ }
3221
+
2662
3222
  // src/projection.ts
2663
3223
  var S = "scalar";
2664
3224
  var T = "text";
2665
3225
  var PASS = "pass";
2666
3226
  var section = (shape) => ({ __section: shape });
2667
3227
  var oneOf = (values) => ({ __oneOf: new Set(values) });
3228
+ var mapOf = (shape) => ({ __map: shape });
3229
+ var CURRENCY_KEY = /^[A-Z]{3}$/;
2668
3230
  function isPrimitive(value) {
2669
3231
  return value === null || ["string", "number", "boolean"].includes(typeof value);
2670
3232
  }
@@ -2683,6 +3245,12 @@ function project(value, shape) {
2683
3245
  if (!isPrimitive(value)) return void 0;
2684
3246
  return typeof value === "string" && !shape.__oneOf.has(value) ? null : value;
2685
3247
  }
3248
+ if ("__map" in shape) {
3249
+ if (value === null) return null;
3250
+ if (typeof value !== "object" || Array.isArray(value)) return void 0;
3251
+ const entries = Object.entries(value).filter(([code]) => CURRENCY_KEY.test(code)).map(([code, item]) => [code, project(item, shape.__map)]).filter(([, projected]) => projected !== void 0);
3252
+ return Object.fromEntries(entries);
3253
+ }
2686
3254
  if (Array.isArray(shape)) {
2687
3255
  return Array.isArray(value) ? value.map((item) => project(item, shape[0])) : void 0;
2688
3256
  }
@@ -2702,8 +3270,10 @@ function project(value, shape) {
2702
3270
  }
2703
3271
  return out;
2704
3272
  }
3273
+ var MONEY = { amount: S, currency: S, display: T };
3274
+ var byCurrency = (extra = {}) => [{ ...MONEY, ...extra }];
2705
3275
  var PAGINATION = { cursor: S, nextCursor: S, hasMore: S };
2706
- var page2 = (row) => ({ data: [row], pagination: PAGINATION });
3276
+ var page3 = (row) => ({ data: [row], pagination: PAGINATION });
2707
3277
  var ADDRESS = { countryCode: S };
2708
3278
  var CUSTOMER_REF = { id: S };
2709
3279
  var APPLICATION = { id: S, name: T, slug: S };
@@ -2738,23 +3308,23 @@ var LINE_RECURRING = {
2738
3308
  intervalCount: S,
2739
3309
  totalPayments: S,
2740
3310
  trialDays: S,
2741
- // A custom installment schedule: amounts and gaps are numbers and unit tokens, no free text.
2742
- schedule: [{ amount: S, intervalUnit: S, intervalCount: S }]
3311
+ // A custom installment schedule: amounts are money, gaps are numbers and unit tokens, no free text.
3312
+ schedule: [{ amount: MONEY, intervalUnit: S, intervalCount: S }]
2743
3313
  };
2744
- var LINE_ITEM = {
3314
+ var LINE_ITEM2 = {
2745
3315
  id: S,
2746
3316
  type: S,
2747
3317
  quantity: S,
2748
- unitPrice: S,
2749
- subtotal: S,
2750
- discountAmount: S,
2751
- taxAmount: S,
2752
- total: S,
3318
+ unitPrice: MONEY,
3319
+ subtotal: MONEY,
3320
+ discountAmount: MONEY,
3321
+ taxAmount: MONEY,
3322
+ total: MONEY,
2753
3323
  // amount = renewal price on a trial line (whose unitPrice is 0); count = the old display mirror.
2754
- recurring: { ...LINE_RECURRING, amount: S, count: S, scheduleUnitTotal: S },
3324
+ recurring: { ...LINE_RECURRING, amount: MONEY, count: S, scheduleUnitTotal: MONEY },
2755
3325
  subscriptionId: S
2756
3326
  };
2757
- var ORDER = {
3327
+ var ORDER2 = {
2758
3328
  id: S,
2759
3329
  orderNumber: S,
2760
3330
  status: S,
@@ -2763,14 +3333,14 @@ var ORDER = {
2763
3333
  type: S,
2764
3334
  source: S,
2765
3335
  currency: S,
2766
- subtotal: S,
2767
- discountTotal: S,
2768
- shippingTotal: S,
2769
- taxTotal: S,
2770
- total: S,
2771
- capturedAmount: S,
2772
- refundedAmount: S,
2773
- compAmount: S,
3336
+ subtotal: MONEY,
3337
+ discountTotal: MONEY,
3338
+ shippingTotal: MONEY,
3339
+ taxTotal: MONEY,
3340
+ total: MONEY,
3341
+ capturedAmount: MONEY,
3342
+ refundedAmount: MONEY,
3343
+ compAmount: MONEY,
2774
3344
  onHold: S,
2775
3345
  taxReverseCharge: S,
2776
3346
  customerId: S,
@@ -2780,20 +3350,20 @@ var ORDER = {
2780
3350
  shippingAddress: ADDRESS,
2781
3351
  billingAddress: ADDRESS,
2782
3352
  fulfillmentSummary: { itemsFulfilled: S, itemsRemaining: S, itemsTotal: S },
2783
- lineItems: [LINE_ITEM],
3353
+ lineItems: [LINE_ITEM2],
2784
3354
  createdAt: S,
2785
3355
  completedAt: S,
2786
3356
  cancelledAt: S,
2787
3357
  closedAt: S
2788
3358
  };
2789
- var PAYMENT = {
3359
+ var PAYMENT2 = {
2790
3360
  id: S,
2791
3361
  orderId: S,
2792
3362
  status: S,
2793
3363
  method: S,
2794
3364
  processor: S,
2795
- amount: S,
2796
- capturedAmount: S,
3365
+ amount: MONEY,
3366
+ capturedAmount: MONEY,
2797
3367
  currency: S,
2798
3368
  cardBrand: S,
2799
3369
  disputed: S,
@@ -2808,17 +3378,17 @@ var PAYMENT = {
2808
3378
  voidedAt: S,
2809
3379
  createdAt: S
2810
3380
  };
2811
- var RETURN = {
3381
+ var RETURN2 = {
2812
3382
  id: S,
2813
3383
  orderId: S,
2814
3384
  status: S,
2815
3385
  restock: S,
2816
- refundAmount: S,
3386
+ refundAmount: MONEY,
2817
3387
  refundPaymentId: S,
2818
3388
  createdAt: S,
2819
3389
  items: [{ lineItemId: S, quantity: S }]
2820
3390
  };
2821
- var FULFILLMENT = {
3391
+ var FULFILLMENT2 = {
2822
3392
  id: S,
2823
3393
  orderId: S,
2824
3394
  type: S,
@@ -2828,12 +3398,12 @@ var FULFILLMENT = {
2828
3398
  detail: { carrier: T, serviceLevel: T, trackingNumber: T, trackingUrl: T, shippedAt: S, estimatedDelivery: S, actualDelivery: S }
2829
3399
  };
2830
3400
  var CUSTOMER = { id: S, netN: S, acceptsMarketing: S, createdAt: S };
2831
- var SUBSCRIPTION = {
3401
+ var SUBSCRIPTION2 = {
2832
3402
  id: S,
2833
3403
  status: S,
2834
3404
  planName: T,
2835
3405
  planReference: T,
2836
- amount: S,
3406
+ amount: MONEY,
2837
3407
  currency: S,
2838
3408
  interval: S,
2839
3409
  quantity: S,
@@ -2855,22 +3425,22 @@ var SUBSCRIPTION = {
2855
3425
  failureCount: S,
2856
3426
  pendingPlanName: T,
2857
3427
  pendingPlanReference: T,
2858
- pendingAmount: S,
3428
+ pendingAmount: MONEY,
2859
3429
  pendingInterval: S,
2860
3430
  pendingQuantity: S,
2861
3431
  pendingIntervalUnit: S,
2862
3432
  pendingIntervalCount: S,
2863
- scheduleTotal: S,
2864
- nextPaymentAmount: S,
3433
+ scheduleTotal: MONEY,
3434
+ nextPaymentAmount: MONEY,
2865
3435
  // A physical subscription (0236): the method is an enum, and the ship-to is
2866
3436
  // kept to its country like every other address here.
2867
3437
  deliveryMethod: S,
2868
3438
  shippingAddress: ADDRESS,
2869
3439
  paymentSchedule: [{
2870
3440
  index: S,
2871
- amount: S,
2872
- discount: S,
2873
- net: S,
3441
+ amount: MONEY,
3442
+ discount: MONEY,
3443
+ net: MONEY,
2874
3444
  intervalUnit: S,
2875
3445
  intervalCount: S,
2876
3446
  status: S,
@@ -2878,13 +3448,13 @@ var SUBSCRIPTION = {
2878
3448
  }],
2879
3449
  createdAt: S
2880
3450
  };
2881
- var QUOTE_SUMMARY = {
3451
+ var QUOTE_SUMMARY2 = {
2882
3452
  id: S,
2883
3453
  quoteNumber: S,
2884
3454
  status: S,
2885
3455
  source: S,
2886
3456
  currency: S,
2887
- total: S,
3457
+ total: MONEY,
2888
3458
  customerId: S,
2889
3459
  orderId: S,
2890
3460
  expiresAt: S,
@@ -2892,18 +3462,18 @@ var QUOTE_SUMMARY = {
2892
3462
  declinedAt: S,
2893
3463
  createdAt: S
2894
3464
  };
2895
- var QUOTE = {
2896
- ...QUOTE_SUMMARY,
3465
+ var QUOTE2 = {
3466
+ ...QUOTE_SUMMARY2,
2897
3467
  revisions: [{
2898
3468
  id: S,
2899
3469
  revisionNumber: S,
2900
3470
  state: S,
2901
- subtotal: S,
2902
- discountTotal: S,
2903
- shippingTotal: S,
2904
- taxTotal: S,
2905
- total: S,
2906
- depositAmount: S,
3471
+ subtotal: MONEY,
3472
+ discountTotal: MONEY,
3473
+ shippingTotal: MONEY,
3474
+ taxTotal: MONEY,
3475
+ total: MONEY,
3476
+ depositAmount: MONEY,
2907
3477
  shippingMode: S,
2908
3478
  issuedAt: S,
2909
3479
  expiresAt: S,
@@ -2911,11 +3481,11 @@ var QUOTE = {
2911
3481
  items: [{
2912
3482
  type: S,
2913
3483
  quantity: S,
2914
- unitPrice: S,
2915
- subtotal: S,
2916
- discountAmount: S,
2917
- taxAmount: S,
2918
- total: S,
3484
+ unitPrice: MONEY,
3485
+ subtotal: MONEY,
3486
+ discountAmount: MONEY,
3487
+ taxAmount: MONEY,
3488
+ total: MONEY,
2919
3489
  optional: S,
2920
3490
  optionalSelected: S,
2921
3491
  recurring: LINE_RECURRING
@@ -2925,7 +3495,7 @@ var QUOTE = {
2925
3495
  comments: [{ authorType: S, visibility: S, createdAt: S }],
2926
3496
  timeline: [{ type: S, actorType: S, createdAt: S }]
2927
3497
  };
2928
- var INVOICE = {
3498
+ var INVOICE2 = {
2929
3499
  id: S,
2930
3500
  number: S,
2931
3501
  status: S,
@@ -2933,12 +3503,12 @@ var INVOICE = {
2933
3503
  sourceId: S,
2934
3504
  customerId: S,
2935
3505
  currency: S,
2936
- subtotal: S,
2937
- discountTotal: S,
2938
- shippingTotal: S,
2939
- taxTotal: S,
2940
- total: S,
2941
- amountRefunded: S,
3506
+ subtotal: MONEY,
3507
+ discountTotal: MONEY,
3508
+ shippingTotal: MONEY,
3509
+ taxTotal: MONEY,
3510
+ total: MONEY,
3511
+ amountRefunded: MONEY,
2942
3512
  issuedAt: S,
2943
3513
  dueAt: S,
2944
3514
  periodStart: S,
@@ -2947,12 +3517,12 @@ var INVOICE = {
2947
3517
  billingSnapshot: {
2948
3518
  planName: T,
2949
3519
  period: { start: S, end: S },
2950
- lineItems: [{ quantity: S, unitPrice: S, discountAmount: S, taxAmount: S, total: S }],
2951
- totals: { currency: S, subtotal: S, discountTotal: S, shippingTotal: S, taxTotal: S, total: S },
3520
+ lineItems: [{ quantity: S, unitPrice: MONEY, discountAmount: MONEY, taxAmount: MONEY, total: MONEY }],
3521
+ totals: { currency: S, subtotal: MONEY, discountTotal: MONEY, shippingTotal: MONEY, taxTotal: MONEY, total: MONEY },
2952
3522
  payment: { method: S, brand: S, status: S }
2953
3523
  }
2954
3524
  };
2955
- var DISCOUNT = {
3525
+ var DISCOUNT2 = {
2956
3526
  id: S,
2957
3527
  code: T,
2958
3528
  name: T,
@@ -2964,9 +3534,13 @@ var DISCOUNT = {
2964
3534
  usageCount: S,
2965
3535
  usageLimit: S,
2966
3536
  maxRedemptionsPerCustomer: S,
2967
- createdAt: S
3537
+ createdAt: S,
3538
+ // Per currency, main one included. The decorator drops a fixed discount's legacy `value`
3539
+ // (MC4-R77), so this is where its amount is. A percentage discount's `amounts` hold only
3540
+ // a minimum, so `value` is money whenever it is present.
3541
+ amounts: mapOf({ value: MONEY, minOrder: MONEY })
2968
3542
  };
2969
- var EVENT = {
3543
+ var EVENT2 = {
2970
3544
  id: S,
2971
3545
  type: S,
2972
3546
  entityType: S,
@@ -2976,18 +3550,18 @@ var EVENT = {
2976
3550
  status: S,
2977
3551
  previousStatus: S,
2978
3552
  action: S,
2979
- amount: S,
3553
+ amount: MONEY,
2980
3554
  currency: S,
2981
3555
  attempt: S,
2982
3556
  orderId: S,
2983
3557
  paymentId: S,
2984
- order: { id: S, orderNumber: S, status: S, paymentStatus: S, currency: S, total: S },
2985
- payment: { id: S, orderId: S, status: S, method: S, amount: S, currency: S },
2986
- subscription: { id: S, status: S, planName: T, amount: S, currency: S, interval: S },
3558
+ order: { id: S, orderNumber: S, status: S, paymentStatus: S, currency: S, total: MONEY },
3559
+ payment: { id: S, orderId: S, status: S, method: S, amount: MONEY, currency: S },
3560
+ subscription: { id: S, status: S, planName: T, amount: MONEY, currency: S, interval: S },
2987
3561
  fulfillment: { id: S, orderId: S, type: S, status: S }
2988
3562
  }
2989
3563
  };
2990
- var DELIVERY = {
3564
+ var DELIVERY2 = {
2991
3565
  id: S,
2992
3566
  endpointId: S,
2993
3567
  eventId: S,
@@ -3000,8 +3574,11 @@ var DELIVERY = {
3000
3574
  createdAt: S,
3001
3575
  replayOf: S
3002
3576
  };
3003
- var MONEY_COUNT = { count: S, totalCents: S };
3004
- var ORDER_PERIOD = { orderCount: S, grossCents: S, netCents: S, refundsCents: S, avgOrderCents: S };
3577
+ var COUNT_BY_CURRENCY = { count: S, byCurrency: byCurrency({ count: S }) };
3578
+ var ORDER_PERIOD = {
3579
+ orderCount: S,
3580
+ byCurrency: byCurrency({ orderCount: S, avgOrder: MONEY, refunds: MONEY, net: MONEY })
3581
+ };
3005
3582
  var OAUTH_PROJECTIONS = {
3006
3583
  whoami: {
3007
3584
  type: S,
@@ -3013,36 +3590,37 @@ var OAUTH_PROJECTIONS = {
3013
3590
  search_docs: PASS,
3014
3591
  describe_endpoint: PASS,
3015
3592
  validate_payload: PASS,
3016
- search_orders: page2(ORDER),
3593
+ search_orders: page3(ORDER2),
3017
3594
  get_order: {
3018
- order: ORDER,
3019
- payments: section([PAYMENT]),
3020
- returns: section([RETURN]),
3021
- fulfillments: section([FULFILLMENT])
3595
+ order: ORDER2,
3596
+ payments: section([PAYMENT2]),
3597
+ returns: section([RETURN2]),
3598
+ fulfillments: section([FULFILLMENT2])
3022
3599
  },
3023
- search_customers: page2(CUSTOMER),
3600
+ search_customers: page3(CUSTOMER),
3024
3601
  get_customer: {
3025
3602
  customer: CUSTOMER,
3026
3603
  addresses: section([{ id: S, isDefault: S, ...ADDRESS }]),
3027
- subscriptions: section([SUBSCRIPTION])
3604
+ subscriptions: section([SUBSCRIPTION2])
3028
3605
  },
3029
- list_subscriptions: page2(SUBSCRIPTION),
3030
- get_subscription: SUBSCRIPTION,
3031
- search_quotes: page2(QUOTE_SUMMARY),
3032
- get_quote: QUOTE,
3033
- list_invoices: page2(INVOICE),
3034
- get_invoice: INVOICE,
3606
+ list_subscriptions: page3(SUBSCRIPTION2),
3607
+ get_subscription: SUBSCRIPTION2,
3608
+ search_quotes: page3(QUOTE_SUMMARY2),
3609
+ get_quote: QUOTE2,
3610
+ list_invoices: page3(INVOICE2),
3611
+ get_invoice: INVOICE2,
3035
3612
  receivables_aging: {
3036
- buckets: [{ key: S, label: T, count: S, total_amount: S }],
3037
- total_outstanding_amount: S,
3038
- total_outstanding_count: S
3613
+ currency: S,
3614
+ buckets: [{ key: S, label: T, count: S, byCurrency: byCurrency({ count: S }) }],
3615
+ total_outstanding_count: S,
3616
+ byCurrency: byCurrency({ count: S })
3039
3617
  },
3040
- search_discounts: page2(DISCOUNT),
3041
- get_discount: DISCOUNT,
3042
- search_payments: page2(PAYMENT),
3618
+ search_discounts: page3(DISCOUNT2),
3619
+ get_discount: DISCOUNT2,
3620
+ search_payments: page3(PAYMENT2),
3043
3621
  get_payment: {
3044
- payment: PAYMENT,
3045
- transactions: section([{ id: S, type: S, status: S, amount: S, currency: S, createdAt: S }])
3622
+ payment: PAYMENT2,
3623
+ transactions: section([{ id: S, type: S, status: S, amount: MONEY, currency: S, createdAt: S }])
3046
3624
  },
3047
3625
  list_abandoned_carts: {
3048
3626
  carts: section([{
@@ -3051,14 +3629,20 @@ var OAUTH_PROJECTIONS = {
3051
3629
  currency: S,
3052
3630
  itemCount: S,
3053
3631
  recoveryStatus: S,
3054
- total: S,
3632
+ total: MONEY,
3055
3633
  customer: { id: S }
3056
3634
  }]),
3057
- summary: section({ abandonedCount: S, abandonedValue: S, recoveryEmailsSent: S, sinceDays: S })
3635
+ summary: section({
3636
+ abandonedCount: S,
3637
+ currency: S,
3638
+ byCurrency: byCurrency({ count: S }),
3639
+ recoveryEmailsSent: S,
3640
+ sinceDays: S
3641
+ })
3058
3642
  },
3059
- search_events: page2(EVENT),
3060
- list_webhook_deliveries: page2(DELIVERY),
3061
- get_webhook_delivery: DELIVERY,
3643
+ search_events: page3(EVENT2),
3644
+ list_webhook_deliveries: page3(DELIVERY2),
3645
+ get_webhook_delivery: DELIVERY2,
3062
3646
  explain_checkout_failure: {
3063
3647
  note: T,
3064
3648
  hint: T,
@@ -3083,13 +3667,13 @@ var OAUTH_PROJECTIONS = {
3083
3667
  planName: T,
3084
3668
  trialDays: S,
3085
3669
  currency: S,
3086
- firstChargeAmountMinor: S
3670
+ firstChargeAmountMinor: MONEY
3087
3671
  },
3088
3672
  hasSubscriptions: S,
3089
3673
  // One entry per subscription line. No `name`: it is the line's name.
3090
3674
  subscriptions: [{
3091
3675
  lineItemId: S,
3092
- amount: S,
3676
+ amount: MONEY,
3093
3677
  quantity: S,
3094
3678
  interval: S,
3095
3679
  intervalUnit: S,
@@ -3100,27 +3684,27 @@ var OAUTH_PROJECTIONS = {
3100
3684
  planChargedToday: S,
3101
3685
  taxApplies: S,
3102
3686
  scheduleGapUnits: [S],
3103
- schedule: [{ net: S, dueAt: S }]
3687
+ schedule: [{ net: MONEY, dueAt: S }]
3104
3688
  }]
3105
3689
  },
3106
3690
  cart: section({
3107
3691
  id: S,
3108
3692
  status: S,
3109
3693
  currency: S,
3110
- subtotal: S,
3111
- discountTotal: S,
3112
- shippingTotal: S,
3113
- taxTotal: S,
3114
- total: S,
3694
+ subtotal: MONEY,
3695
+ discountTotal: MONEY,
3696
+ shippingTotal: MONEY,
3697
+ taxTotal: MONEY,
3698
+ total: MONEY,
3115
3699
  itemCount: S,
3116
- items: [LINE_ITEM],
3117
- lineItems: [LINE_ITEM]
3700
+ items: [LINE_ITEM2],
3701
+ lineItems: [LINE_ITEM2]
3118
3702
  }),
3119
- events: [EVENT],
3703
+ events: [EVENT2],
3120
3704
  eventsUnavailable: T,
3121
- recentWebhookDeliveries: section([DELIVERY])
3705
+ recentWebhookDeliveries: section([DELIVERY2])
3122
3706
  },
3123
- list_extension_installations: page2({
3707
+ list_extension_installations: page3({
3124
3708
  id: S,
3125
3709
  extensionId: S,
3126
3710
  extensionName: T,
@@ -3163,27 +3747,38 @@ var OAUTH_PROJECTIONS = {
3163
3747
  },
3164
3748
  get_workspace_settings: { name: T, slug: S, brandColor: S, logoUrl: T, onboardingCompletedAt: S },
3165
3749
  // What happened and to which record; not which team member did it.
3166
- get_audit_log: page2({ id: S, action: S, resourceType: S, resourceId: S, createdAt: S }),
3750
+ get_audit_log: page3({ id: S, action: S, resourceType: S, resourceId: S, createdAt: S }),
3167
3751
  list_applications: [{ id: S, name: T, slug: S, currency: S, isActive: S }],
3168
3752
  // Analytics: computed aggregates, listed field by field all the same.
3169
3753
  get_business_summary: {
3170
3754
  period: S,
3755
+ currency: S,
3171
3756
  range: RANGE,
3172
- orders: section({ current: ORDER_PERIOD, previous: ORDER_PERIOD, deltaPct: S }),
3757
+ orders: section({
3758
+ current: ORDER_PERIOD,
3759
+ previous: ORDER_PERIOD,
3760
+ deltaByCurrency: [{ currency: S, deltaPct: S }]
3761
+ }),
3173
3762
  subscriptions: section({
3174
- mrr: { currentCents: S, periodStartCents: S, deltaPct: S },
3763
+ mrr: { byCurrency: byCurrency({ periodStart: MONEY, deltaPct: S }) },
3175
3764
  newSubscriptions: S,
3176
3765
  cancelledSubscriptions: S,
3177
3766
  churnRate: S,
3178
3767
  note: T
3179
3768
  }),
3180
- receivables: section({ outstandingCents: S, outstandingCount: S }),
3181
- quotes: section({ sent: MONEY_COUNT, accepted: MONEY_COUNT, declined: MONEY_COUNT, expired: MONEY_COUNT })
3769
+ receivables: section({ outstandingCount: S, byCurrency: byCurrency({ count: S }) }),
3770
+ quotes: section({
3771
+ sent: COUNT_BY_CURRENCY,
3772
+ accepted: COUNT_BY_CURRENCY,
3773
+ declined: COUNT_BY_CURRENCY,
3774
+ expired: COUNT_BY_CURRENCY
3775
+ })
3182
3776
  },
3183
3777
  get_attention_digest: {
3184
- disputes: section({ open: S, totalCents: S }),
3778
+ currency: S,
3779
+ disputes: section({ open: S, byCurrency: byCurrency({ count: S }) }),
3185
3780
  subscriptionsInDunning: section(S),
3186
- overdueInvoices: section(MONEY_COUNT),
3781
+ overdueInvoices: section(COUNT_BY_CURRENCY),
3187
3782
  unhealthyWebhooks: section([{ endpointId: S, failureRate: S, attempts7d: S }])
3188
3783
  },
3189
3784
  get_sales_timeseries: {
@@ -3192,30 +3787,33 @@ var OAUTH_PROJECTIONS = {
3192
3787
  currency: S,
3193
3788
  days: S,
3194
3789
  note: T,
3195
- series: [{ date: S, grossCents: S, orders: S }],
3196
- totalGrossCents: S,
3197
- totalOrders: S
3790
+ series: [{ date: S, orders: S, paidOrders: S, byCurrency: byCurrency({ paidOrders: S }) }],
3791
+ totalOrders: S,
3792
+ totalPaidOrders: S,
3793
+ byCurrency: byCurrency({ paidOrders: S })
3198
3794
  },
3199
3795
  // get_top_products has no entry, so it is not offered over OAuth: it ranks
3200
3796
  // products by line-item reference id or name, which a buyer can type.
3201
3797
  get_customer_growth: {
3202
3798
  application: APPLICATION,
3203
3799
  range: RANGE,
3800
+ currency: S,
3204
3801
  note: T,
3205
3802
  topBy: S,
3206
3803
  signups: { total: S, series: [{ date: S, signups: S }] },
3207
3804
  ordersByCustomerType: { newCustomerOrders: S, returningCustomerOrders: S },
3208
3805
  // The ranking, by id: a top customer's name and email stay behind.
3209
- topCustomers: [{ customerId: S, orderCount: S, revenueCents: S }],
3210
- totals: { customerCount: S, orderCount: S, revenueCents: S }
3806
+ topCustomers: [{ customerId: S, orderCount: S, byCurrency: byCurrency({ orderCount: S }) }],
3807
+ totals: { customerCount: S, orderCount: S, byCurrency: byCurrency({ orderCount: S, customerCount: S }) }
3211
3808
  },
3212
3809
  get_revenue_breakdown: {
3213
3810
  application: APPLICATION,
3214
3811
  range: RANGE,
3812
+ currency: S,
3215
3813
  dimension: S,
3216
3814
  note: T,
3217
- rows: [{ key: S, orderCount: S, grossCents: S }],
3218
- totals: { orderCount: S, grossCents: S }
3815
+ rows: [{ key: S, orderCount: S, byCurrency: byCurrency({ orderCount: S }) }],
3816
+ totals: { orderCount: S, byCurrency: byCurrency({ orderCount: S }) }
3219
3817
  },
3220
3818
  get_funnel_conversion: {
3221
3819
  application: APPLICATION,
@@ -3228,21 +3826,28 @@ var OAUTH_PROJECTIONS = {
3228
3826
  get_subscription_movement: {
3229
3827
  application: APPLICATION,
3230
3828
  range: RANGE,
3829
+ currency: S,
3231
3830
  note: T,
3232
- series: [{ date: S, newSubscriptions: S, churnedSubscriptions: S, mrrDeltaCents: S }],
3233
- totals: { newSubscriptions: S, churnedSubscriptions: S, netMrrDeltaCents: S }
3831
+ series: [{ date: S, newSubscriptions: S, churnedSubscriptions: S, byCurrency: byCurrency() }],
3832
+ totals: { newSubscriptions: S, churnedSubscriptions: S, byCurrency: byCurrency() }
3234
3833
  },
3235
3834
  get_discount_performance: {
3236
3835
  application: APPLICATION,
3237
3836
  range: RANGE,
3837
+ currency: S,
3238
3838
  note: T,
3239
- rows: [{ discountId: S, code: T, redemptions: S, discountedRevenueCents: S, discountGivenCents: S }],
3240
- totals: { redemptions: S, discountedRevenueCents: S, discountGivenCents: S }
3839
+ rows: [{
3840
+ discountId: S,
3841
+ code: T,
3842
+ redemptions: S,
3843
+ byCurrency: byCurrency({ redemptions: S, discountGiven: MONEY })
3844
+ }],
3845
+ totals: { redemptions: S, byCurrency: byCurrency({ redemptions: S, discountGiven: MONEY }) }
3241
3846
  }
3242
3847
  };
3243
3848
 
3244
3849
  // src/server.ts
3245
- var VERSION = true ? "0.4.4" : "0.0.0-dev";
3850
+ var VERSION = true ? "0.5.1" : "0.0.0-dev";
3246
3851
  function registerableActions(policy) {
3247
3852
  const isProduction = policy.identity.environment.providerEnvironment === "production";
3248
3853
  return actionsForChannel("mcp").filter((action) => {
@@ -3269,9 +3874,9 @@ function buildInstructions(identity, actions, policy) {
3269
3874
  "Conventions:",
3270
3875
  "- The workspace and environment are fixed for this session and cannot be switched from inside a tool call. Call whoami if you need to state where you are.",
3271
3876
  '- 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.',
3272
- "- 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.",
3877
+ "- 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 report each application's figures separately, per currency, or ask which application they mean; never add amounts across applications or currencies.",
3273
3878
  '- List tools return { data, pagination }. When pagination.hasMore is true, pass pagination.cursor back as "cursor" rather than raising "limit".',
3274
- "- Amounts are integer minor units of the record's currency (2500 = 25.00 in a two-decimal currency; JPY has none, KWD has three).",
3879
+ "- Money values are `{ amount, currency, display }`: `amount` is integer minor units of `currency` (its ISO 4217 exponent), and `display` is the formatted string to show. Totals come back per currency as arrays; never add amounts in different currencies, and never convert them.",
3275
3880
  "- 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.",
3276
3881
  "- API errors come back as text with a stable code. On insufficient_scopes, tell the user which scope to add \u2014 do not retry.",
3277
3882
  "- 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."
@@ -3355,7 +3960,7 @@ function createServer(options) {
3355
3960
  isError: true
3356
3961
  };
3357
3962
  }
3358
- const result = stripRawProcessorData(await handler(ctx, args ?? {}));
3963
+ const result = decorateMoney(action.id, stripRawProcessorData(await handler(ctx, args ?? {}))).value;
3359
3964
  const shown = redactPii ? redactShopperPii(project(result, OAUTH_PROJECTIONS[action.id])) : result;
3360
3965
  return { content: [{ type: "text", text: formatResult(shown) }] };
3361
3966
  } catch (error) {