@amboras-dev/money 0.0.0-stage → 0.2.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.
Files changed (78) hide show
  1. package/README.md +401 -2
  2. package/dist/ai.cjs +185 -0
  3. package/dist/ai.d.cts +97 -0
  4. package/dist/ai.d.ts +97 -0
  5. package/dist/ai.js +175 -0
  6. package/dist/allocate-CZRg4TOP.cjs +222 -0
  7. package/dist/allocate-X7_jAtOj.js +199 -0
  8. package/dist/amount-BV0O-aN8.cjs +241 -0
  9. package/dist/amount-BoYBMgK9.js +200 -0
  10. package/dist/arithmetic-BhNwisjb.js +132 -0
  11. package/dist/arithmetic-DjT4Kzgt.cjs +233 -0
  12. package/dist/billing.cjs +184 -0
  13. package/dist/billing.d.cts +81 -0
  14. package/dist/billing.d.ts +81 -0
  15. package/dist/billing.js +175 -0
  16. package/dist/commerce.cjs +536 -0
  17. package/dist/commerce.d.cts +293 -0
  18. package/dist/commerce.d.ts +293 -0
  19. package/dist/commerce.js +516 -0
  20. package/dist/format-BdPnijvn.js +99 -0
  21. package/dist/format-DLhno7eX.cjs +128 -0
  22. package/dist/fx.cjs +407 -0
  23. package/dist/fx.d.cts +157 -0
  24. package/dist/fx.d.ts +157 -0
  25. package/dist/fx.js +374 -0
  26. package/dist/index.cjs +352 -0
  27. package/dist/index.d.cts +300 -0
  28. package/dist/index.d.ts +300 -0
  29. package/dist/index.js +276 -0
  30. package/dist/input.cjs +163 -0
  31. package/dist/input.d.cts +203 -0
  32. package/dist/input.d.ts +203 -0
  33. package/dist/input.js +153 -0
  34. package/dist/iso-minor-CqkWDxHS.js +48 -0
  35. package/dist/iso-minor-wSwJN57T.cjs +65 -0
  36. package/dist/medusa-4K8N1pUc.d.cts +87 -0
  37. package/dist/medusa-DBXJXXvF.d.ts +87 -0
  38. package/dist/medusa-DqJY1qpj.js +116 -0
  39. package/dist/medusa-lRY9xlsf.cjs +175 -0
  40. package/dist/money-B-3aFjNJ.d.cts +248 -0
  41. package/dist/money-B-3aFjNJ.d.ts +248 -0
  42. package/dist/money-B3wH_Z4S.cjs +3990 -0
  43. package/dist/money-WhnGiI00.js +3583 -0
  44. package/dist/number-text-BWu67jUq.cjs +145 -0
  45. package/dist/number-text-DE-q4jO5.js +134 -0
  46. package/dist/own-D7544D3k.js +4 -0
  47. package/dist/own-oP9DXFWv.cjs +9 -0
  48. package/dist/percent-C0InC2t2.cjs +43 -0
  49. package/dist/percent-D1VB9xXG.js +20 -0
  50. package/dist/rate-CVeMii4a.cjs +217 -0
  51. package/dist/rate-DBPiYgT1.d.ts +63 -0
  52. package/dist/rate-DicStBue.js +152 -0
  53. package/dist/rate-tqK8ijG0.d.cts +63 -0
  54. package/dist/reporting-CG-ai2sM.d.cts +31 -0
  55. package/dist/reporting-tpGJbqYp.d.ts +31 -0
  56. package/dist/retail-1mu888J1.js +69 -0
  57. package/dist/retail-C_BPLvMj.d.cts +31 -0
  58. package/dist/retail-Cml8YSKg.cjs +86 -0
  59. package/dist/retail-DRUTTQoJ.d.ts +31 -0
  60. package/dist/rounding-DHBtNCHG.cjs +79 -0
  61. package/dist/rounding-g9rvye0k.js +50 -0
  62. package/dist/sql.cjs +290 -0
  63. package/dist/sql.d.cts +147 -0
  64. package/dist/sql.d.ts +147 -0
  65. package/dist/sql.js +271 -0
  66. package/dist/testing.cjs +61995 -0
  67. package/dist/testing.d.cts +125 -0
  68. package/dist/testing.d.ts +125 -0
  69. package/dist/testing.js +61986 -0
  70. package/dist/wire-Bhuut8cW.cjs +2097 -0
  71. package/dist/wire-CaUN9Vf_.d.ts +309 -0
  72. package/dist/wire-sW0yzqth.js +1888 -0
  73. package/dist/wire-xjYXv4go.d.cts +309 -0
  74. package/dist/wire.cjs +37 -0
  75. package/dist/wire.d.cts +2 -0
  76. package/dist/wire.d.ts +2 -0
  77. package/dist/wire.js +2 -0
  78. package/package.json +158 -3
@@ -0,0 +1,309 @@
1
+ import { b as FractionDigits, g as CurrencyCode, i as Money, o as StoredAmount, t as FractionalMoney, z as RoundingMode } from "./money-B-3aFjNJ.cjs";
2
+ //#region src/wire/anet.d.ts
3
+ /**
4
+ * The first `"<field>": <decimal>` (quoted or not) in a raw JSON body, verbatim: `JSON.parse`
5
+ * would turn the gateway's `43.00` into `43`. The value is the whole JSON token, held to
6
+ * `parseDecimal`'s `'plain'` grammar (`1e3` or `"43.10abc"` is not a decimal literal).
7
+ * Undefined when absent; there is no lossy fallback.
8
+ */
9
+ declare function jsonDecimalLiteral(rawBody: string, field: string): string | undefined;
10
+ /**
11
+ * What an unsettled Authorize.Net transaction can still be reversed for: the settle amount when
12
+ * present and above zero (exact), else `authAmount ?? settleAmount` (settle is `'0.00'`, not
13
+ * absent, for voided or unsettled transactions). Undefined when both are absent.
14
+ */
15
+ interface AuthorizeNetAmounts {
16
+ settleAmount?: string | null;
17
+ authAmount?: string | null;
18
+ }
19
+ declare function authorizeNetReversibleAmount(details: AuthorizeNetAmounts): string | undefined;
20
+ //#endregion
21
+ //#region src/wire/descriptors.d.ts
22
+ type PspId = 'stripe' | 'adyen' | 'razorpay' | 'paystack' | 'momo' | 'vnpay' | 'paypal' | 'mollie' | 'airwallex' | 'iyzico' | 'authorize-net' | 'payoo';
23
+ /** ISO minor units, marker-gated decode: a payment created before the cutover holds storage units at the PSP. */
24
+ type GatedPsp = 'stripe' | 'adyen' | 'razorpay' | 'paystack' | 'momo';
25
+ /** Gated PSPs whose encode is gated too; MoMo and Paystack always encode ISO minor units. */
26
+ type EncodeGatedPsp = 'stripe' | 'adyen' | 'razorpay';
27
+ type IsoMinorPsp = GatedPsp | 'vnpay';
28
+ type MajorStringPsp = 'paypal' | 'mollie' | 'iyzico' | 'authorize-net';
29
+ type MajorNumberPsp = 'airwallex' | 'payoo';
30
+ /** What a PSP receives: major-unit text for PayPal, Mollie, iyzico and Authorize.Net, a number for the rest. */
31
+ type WireAmount<P extends PspId> = P extends MajorStringPsp ? string : number;
32
+ /** Every PSP id, in a stable order. */
33
+ declare const PSP_IDS: readonly PspId[];
34
+ //#endregion
35
+ //#region src/wire/marker.d.ts
36
+ declare const WIRE_SCALE_KEY = "amboras_wire_scale";
37
+ declare const WIRE_SCALE_ISO_MINOR_V2 = "iso-minor-v2";
38
+ declare const WIRE_SCALE_MARKER: Readonly<{
39
+ amboras_wire_scale: 'iso-minor-v2';
40
+ }>;
41
+ /** Which convention a payment was created under. Use the two singletons; build one with `conventionOf`. */
42
+ type Convention = {
43
+ readonly kind: 'iso-minor-v2';
44
+ } | {
45
+ readonly kind: 'pre-cutover';
46
+ };
47
+ declare const ISO_MINOR_V2: Convention;
48
+ declare const PRE_CUTOVER: Convention;
49
+ /**
50
+ * `ISO_MINOR_V2` iff ANY record is a non-null object whose `amboras_wire_scale` is strictly
51
+ * `'iso-minor-v2'` (a Stripe charge OR its PaymentIntent); else `PRE_CUTOVER`. Reads already
52
+ * fetched records only: it never queries (FORCE RLS would hide the row and the marker with it).
53
+ */
54
+ declare function conventionOf(...records: unknown[]): Convention;
55
+ //#endregion
56
+ //#region src/wire/breakdown.d.ts
57
+ /**
58
+ * `total` and its `parts` (same currency, non-negative, adding up to `total`) as integer wire
59
+ * amounts whose sum is exactly `encodeWire(psp, total)`: the wire total split by largest
60
+ * remainder over the stored parts. Throws `currency_mismatch`, `amount_invalid` (parts that do not
61
+ * add up, or a negative part) or whatever `encodeWire` refuses.
62
+ */
63
+ declare function wireBreakdown(psp: IsoMinorPsp, total: Money, parts: Readonly<Record<string, Money>>, convention: Convention): {
64
+ total: number;
65
+ parts: Record<string, number>;
66
+ };
67
+ //#endregion
68
+ //#region src/wire/codec.d.ts
69
+ /** Whether `psp` takes `currency` (any case, historic codes included). Never throws for a bad code. */
70
+ declare function pspSupportsCurrency(psp: PspId, currency: string): boolean;
71
+ /**
72
+ * Every currency `psp` takes. Provider-only codes a PSP table lists (Adyen offshore CNH) are left
73
+ * out: they are not ISO 4217 currencies, no store sells in them and no Money can carry them.
74
+ */
75
+ declare function pspCurrencies(psp: PspId): ReadonlySet<CurrencyCode>;
76
+ /**
77
+ * `currency` as a CurrencyCode `psp` takes. Empty throws `currency_missing` (`[<Tag>] Cannot
78
+ * scale an amount without a currency code; ...`); anything the PSP does not take throws
79
+ * `wire_unsupported` with the provider's own message.
80
+ */
81
+ declare function assertPspCurrency(psp: PspId, currency: unknown): CurrencyCode;
82
+ /** `'VND'` for the single-currency providers (MoMo, Payoo, VNPay), else null. */
83
+ declare function pspDefaultCurrency(psp: PspId): CurrencyCode | null;
84
+ /**
85
+ * Stored units per wire unit for an ISO-minor PSP: the PSP's override (Stripe ISK/UGX, Adyen
86
+ * ISK/CLP, Razorpay MGA, Paystack XOF, VNPay VND give 1; Adyen IDR/CVE give 100), else
87
+ * `storageScale / 10^storageDigits` (100 for a zero-decimal currency, else 1).
88
+ */
89
+ declare function wireFactor(psp: IsoMinorPsp, currency: string): 1 | 100;
90
+ /**
91
+ * Fraction digits of `psp`'s wire amount: its digit table, else (ISO-minor PSPs) the digits
92
+ * its factor implies, else (iyzico, Authorize.Net, Payoo) the display digits. Null when the
93
+ * PSP does not take the currency.
94
+ */
95
+ declare function pspWireDigits(psp: PspId, currency: string): FractionDigits | null;
96
+ /** The PSP's minimum charge in `currency` (Paystack USD 2.00), or null when it has none. */
97
+ declare function pspMinimumAmount(psp: PspId, currency: string): Money | null;
98
+ interface EncodeWireOptions {
99
+ /** Names the amount in refusals: `[<Tag>] Invalid <label>: <amount>`. Default `'amount'`; refunds pass `'refund amount'`. */
100
+ label?: string;
101
+ /** Allow a zero amount (verification, comparisons). Negative amounts are always refused. */
102
+ allowZero?: boolean;
103
+ }
104
+ /**
105
+ * A stored amount as `psp` receives it. `m` is a Money or a FractionalMoney (Medusa's unrounded
106
+ * session totals, 107.8175). In order: the currency must pass the PSP's Medusa amount facade
107
+ * (`wire_unsupported` with the facade's message: Razorpay only its exponent table, Paystack no
108
+ * zero-decimal code but XOF, MoMo, Payoo and VNPay only VND; every other PSP scales any currency,
109
+ * so call `assertPspCurrency` for eligibility); the amount must be positive (`wire_refused`
110
+ * `[<Tag>] Invalid <label>: <amount>`, zero allowed with `allowZero`); Stripe and Adyen round a
111
+ * fractional amount half-up to a whole storage unit first; Stripe, Adyen and Razorpay on a
112
+ * pre-cutover payment send the stored integer as is (Razorpay refuses unless its factor is 1, and
113
+ * refuses a fractional amount, which has no stored integer; MoMo and Paystack encode ignore the
114
+ * convention, as today); the whole-unit rules refuse fractions of a dong (MoMo, Payoo, VNPay) or a
115
+ * franc (Paystack XOF), naming the amount as held; then, rounding once and exactly, ISO minor
116
+ * `half-up(S / wireFactor)` (Razorpay three-decimal floored to steps of 10), or major units at the
117
+ * PSP's wire digits, half-up, as fixed-point text (a number for Airwallex and Payoo). A positive
118
+ * amount whose wire rounds to zero is refused (`wire_refused`), with `allowZero` too.
119
+ * This is package policy, safer than Medusa today: Medusa puts 0 on the wire at initiate for
120
+ * Stripe and Adyen, and for Razorpay, PayPal and Airwallex everywhere; it refuses at refund and
121
+ * capture for Stripe and Adyen, and in Mollie, iyzico and Authorize.Net; Razorpay and Paystack
122
+ * read a zero refund as a full one. Otherwise byte-identical to Medusa's codecs for every Money.
123
+ */
124
+ declare function encodeWire<P extends EncodeGatedPsp>(psp: P, m: Money | FractionalMoney, options: EncodeWireOptions & {
125
+ convention: Convention;
126
+ }): WireAmount<P>;
127
+ declare function encodeWire<P extends Exclude<PspId, EncodeGatedPsp>>(psp: P, m: Money | FractionalMoney, options?: EncodeWireOptions): WireAmount<P>;
128
+ /**
129
+ * A PSP wire amount as Money: ISO minor `half-up(w x wireFactor)` (pre-cutover: `half-up(w)`, the
130
+ * PSP already held storage units), major `half-up(w x storageScale)`. `wire` is a finite number
131
+ * or strict decimal text (`/^-?\d+(\.\d+)?$/`: no `''`, exponent or hex), else `amount_invalid`.
132
+ * Signed, except VNPay, where anything but a positive whole number is no amount (`amount_invalid`).
133
+ * The currency is required (`currency_missing`), must be known (`currency_invalid`), must not be
134
+ * provider-only (Adyen CNH: `wire_unsupported`), and must pass the PSP's Medusa inbound gate
135
+ * (`wire_unsupported` with its message: Razorpay only its exponent table, Paystack no
136
+ * zero-decimal code but XOF, MoMo, Payoo and VNPay only VND). Other PSPs read any currency (a PSP
137
+ * may report a settlement currency).
138
+ */
139
+ declare function decodeWire<P extends GatedPsp>(psp: P, wire: unknown, currency: string, convention: Convention): Money;
140
+ declare function decodeWire<P extends Exclude<PspId, GatedPsp>>(psp: P, wire: unknown, currency: string): Money;
141
+ interface TryDecodeWireOptions {
142
+ /** Required for gated PSPs (Stripe, Adyen, Razorpay, Paystack, MoMo): without it the result is undefined. */
143
+ convention?: Convention;
144
+ /** Accept a negative wire amount (balance transactions, reversals). Default false; never for VNPay. */
145
+ allowNegative?: boolean;
146
+ }
147
+ /**
148
+ * `decodeWire` that never throws: undefined wherever it would throw (null, undefined, `''`,
149
+ * whitespace, unparseable or unsafe input, a missing, unknown or provider-only currency, one the
150
+ * PSP's inbound gate refuses, VNPay's "no amount", an unknown PSP, a gated PSP without
151
+ * `convention`: no hidden default) and for a negative amount unless `allowNegative`.
152
+ */
153
+ declare function tryDecodeWire(psp: PspId, wire: unknown, currency: unknown, options?: TryDecodeWireOptions): Money | undefined;
154
+ //#endregion
155
+ //#region src/wire/compare.d.ts
156
+ interface SameWireAmountOptions {
157
+ /** Required for gated PSPs (Stripe, Adyen, Razorpay, Paystack, MoMo); without it the answer is false. */
158
+ convention?: Convention;
159
+ /**
160
+ * Also accept the ISO-digit spelling held by a session created before the PSP digit tables
161
+ * (PayPal, Mollie, Airwallex HUF/TWD...): the expected amount in major units at its display
162
+ * digits, half-up (HUF 44.50 went as `'45'`). Major-unit PSPs only.
163
+ */
164
+ acceptLegacyIsoDigits?: boolean;
165
+ /**
166
+ * The PSP only ever reports decimal text (Mollie, PayPal): a reported (or `requested`) value
167
+ * that is not a string is not its amount, whatever number it holds.
168
+ */
169
+ textOnly?: boolean;
170
+ /** When given, it must be the same currency as `expected` (any case). */
171
+ reportedCurrency?: unknown;
172
+ /** Paystack fee pass-through: the amount the buyer was asked for. */
173
+ requested?: unknown;
174
+ /**
175
+ * `'exact'` (default), or `'requested-exact-collected-covers'`: `requested` is exactly the
176
+ * expected amount and the collected `reported` covers it.
177
+ */
178
+ policy?: 'exact' | 'requested-exact-collected-covers';
179
+ }
180
+ /**
181
+ * Whether a PSP-reported amount is `expected`, a Money or a FractionalMoney (Medusa's unrounded
182
+ * session total). The expected wire is `encodeWire(psp, expected, { convention, allowZero: true })`
183
+ * (a refusal means false); the reported one must decode exactly (strict like `tryDecodeWire`:
184
+ * never `''` or an exponent, no negatives, and never a fraction of a storage unit) to the same
185
+ * stored amount, so `'44.00'` matches a sent `'44'` and Airwallex `43.004` does not match `43`.
186
+ * Never throws.
187
+ */
188
+ declare function sameWireAmount(psp: PspId, reported: unknown, expected: Money | FractionalMoney, options?: SameWireAmountOptions): boolean;
189
+ /**
190
+ * One unit of the PSP's last wire digit, as Money: for ISO-minor PSPs `decodeWire(psp, 1)` (the
191
+ * factor on an iso-minor-v2 payment, 1 storage unit on a pre-cutover one; gated PSPs need the
192
+ * convention), for major PSPs `10^-wireDigits` major. The tolerance for `excessOver`.
193
+ */
194
+ declare function oneWireUnit(psp: PspId, currency: string, convention?: Convention): Money;
195
+ /** The wire amount as it goes into Redis skip keys and idempotency keys: `String(wire)`, byte for byte. */
196
+ declare function wireKeyPart(wire: number | string): string;
197
+ //#endregion
198
+ //#region src/data/destinations.d.ts
199
+ type DestinationId = 'meta' | 'ga4' | 'google-ads' | 'tiktok' | 'snapchat' | 'pinterest' | 'klaviyo' | 'omnisend' | 'omnisend-viewed-product' | 'mailchimp' | 'goaffpro' | 'profitmetrics' | 'pixi' | 'flow' | 'sendcloud' | 'shipstation' | 'shiprocket' | 'shipbob' | 'printful' | 'ahamove' | 'amazon-mcf' | 'skydropx' | 'royal-mail' | 'sevdesk' | 'shopify-ajax';
200
+ //#endregion
201
+ //#region src/wire/destinations.d.ts
202
+ interface DestinationValue {
203
+ readonly value: number | string;
204
+ readonly currency: string;
205
+ }
206
+ /**
207
+ * `m` as `dest` wants it: major units at the display digits (half-up) as a number or text per
208
+ * destination (`as` overrides), or integer "cents" for Shopify AJAX and Omnisend `viewed product`;
209
+ * the currency upper- or lower-case per destination. Undefined when the destination must not get
210
+ * this amount (Meta: not positive; GA4, Google Ads, TikTok, Snapchat, Pinterest and marketing:
211
+ * negative). Throws `wire_unsupported` for a currency the destination's unit is not defined for.
212
+ */
213
+ declare function destinationAmount(dest: DestinationId, m: Money, options?: {
214
+ as?: 'number' | 'string';
215
+ }): DestinationValue | undefined;
216
+ /** A shopping-feed price: `'12.345 KWD'`, `'1200 JPY'`, `'19.99 USD'` (display digits, half-up). */
217
+ declare function feedPrice(m: Money): string;
218
+ /** Google micros (major x 10^6) as integer text, exactly: USD 1999 gives `'19990000'`. */
219
+ declare function googleMicros(m: Money): string;
220
+ interface EventMoney {
221
+ readonly value: number;
222
+ readonly currency: string;
223
+ }
224
+ /** First-party analytics money: the stored integer and the lower-case code (the ClickHouse `Int64` contract). */
225
+ declare function eventMoney(m: Money): EventMoney;
226
+ //#endregion
227
+ //#region src/wire/presentment.d.ts
228
+ interface PspPresentment {
229
+ /** Every currency some account of the PSP can present: the union over account countries. */
230
+ readonly currencies: ReadonlySet<CurrencyCode>;
231
+ /** Currencies only accounts registered in these countries can present (Stripe KWD: AE; PayPal BRL: BR). */
232
+ readonly currencyRequiresAccountCountry: ReadonlyMap<CurrencyCode, ReadonlySet<string>>;
233
+ /** Account countries limited to these currencies (Airwallex cards on a US or MX account). */
234
+ readonly accountCountryAllowsOnly: ReadonlyMap<string, ReadonlySet<CurrencyCode>>;
235
+ }
236
+ /**
237
+ * The PSP's presentment rules, as data: the union of currencies some account can charge, the
238
+ * currencies that need an account in particular countries, and the account countries limited to
239
+ * a list. For capability declarations that hold the rules themselves; `pspPresentmentCurrencies`
240
+ * applies them to one account. Fresh collections on every call. An unknown PSP throws
241
+ * `wire_unsupported`.
242
+ */
243
+ declare function pspPresentment(psp: PspId): PspPresentment;
244
+ /**
245
+ * The currencies `psp` lets an account present (charge buyers in). Without `accountCountry`, the
246
+ * union over every account country; with it (ISO 3166 alpha-2, any case), only what an account
247
+ * registered there can charge: Stripe's three-decimal five need a UAE account, PayPal's BRL, CNY
248
+ * and MYR an in-country one, Airwallex cards on a US account take its documented 76 and on an MX
249
+ * account MXN only. Not `pspCurrencies`, which is what the codec scales and the facade lets
250
+ * through (Stripe's adds every two-decimal ISO code it accepts on the wire).
251
+ */
252
+ declare function pspPresentmentCurrencies(psp: PspId, options?: {
253
+ accountCountry?: string;
254
+ }): ReadonlySet<CurrencyCode>;
255
+ //#endregion
256
+ //#region src/wire/provider-amount.d.ts
257
+ interface ProviderAmountOptions {
258
+ /** Accept a negative amount (refunds, credits). Default false. */
259
+ allowNegative?: boolean;
260
+ /** Default `'.'`; `'auto'` decides from the text (see the core separator engine). */
261
+ decimalSeparator?: '.' | ',' | 'auto';
262
+ /** Read the first number and ignore the rest (`'22.67 + KDV'`). Default false. */
263
+ allowTrailingText?: boolean;
264
+ /** Rounding to the currency's storage digits (and the 'auto' whole-unit rounding). Default `'half-up'`. */
265
+ rounding?: RoundingMode;
266
+ }
267
+ /**
268
+ * A provider's major-unit amount (finite number, or text read by the separator engine, which
269
+ * strips the currency's symbol and code) as Money, rounded once to the storage digits. Null on
270
+ * anything invalid (empty, unparseable, non-finite, negative without `allowNegative`, too large,
271
+ * unknown currency), never 0.
272
+ */
273
+ declare function parseProviderAmount(value: unknown, currency: string, options?: ProviderAmountOptions): Money | null;
274
+ //#endregion
275
+ //#region src/wire/providers.d.ts
276
+ /** RBI e-mandate cap Razorpay token registrations carry as `max_amount`: INR 15,000 (1,500,000 paise = stored). */
277
+ declare const RAZORPAY_AFA_FREE_CAP: Money;
278
+ /**
279
+ * The symbolic charge a saved-card setup makes: Paystack one major unit, Razorpay one INR (any
280
+ * other currency is `wire_unsupported`), Mollie one smallest wire unit (`'0.01'`, `'1'` for ISK
281
+ * and JPY), Adyen zero. Vault charges are always new, so the iso-minor-v2 convention applies.
282
+ */
283
+ declare function verificationCharge(psp: 'paystack' | 'razorpay' | 'mollie' | 'adyen', currency: string): {
284
+ wire: number | string;
285
+ money: Money;
286
+ };
287
+ /**
288
+ * iyzico's price spelling, on the text (no float): canonical decimal (no trailing fraction zeros),
289
+ * then `'.0'` when there is no `.` (`'10.50'` gives `'10.5'`, `'10.00'` gives `'10.0'`). Text that
290
+ * is not a plain decimal throws `parse`.
291
+ */
292
+ declare function iyzicoPrice(wire: string): string;
293
+ //#endregion
294
+ //#region src/wire/slot.d.ts
295
+ interface SlotMoney {
296
+ readonly amount: StoredAmount;
297
+ /** Lower-case, as Medusa spells it. */
298
+ readonly currency_code: string;
299
+ }
300
+ /** `m` for a slot context's `money` key. */
301
+ declare function slotMoney(m: Money): SlotMoney;
302
+ /**
303
+ * The money a slot context carries: `context.money` when it is valid, else the legacy
304
+ * `total ?? price` with the first known of `currency_code`, `currency`, read leniently (numbers, numeric text,
305
+ * Medusa BigNumber shapes). Undefined when the amount or the currency is missing or unreadable.
306
+ */
307
+ declare function readSlotMoney(context: unknown): SlotMoney | undefined;
308
+ //#endregion
309
+ export { jsonDecimalLiteral as $, pspMinimumAmount as A, WIRE_SCALE_KEY as B, EncodeWireOptions as C, encodeWire as D, decodeWire as E, wireBreakdown as F, IsoMinorPsp as G, conventionOf as H, Convention as I, PSP_IDS as J, MajorNumberPsp as K, ISO_MINOR_V2 as L, pspWireDigits as M, tryDecodeWire as N, pspCurrencies as O, wireFactor as P, authorizeNetReversibleAmount as Q, PRE_CUTOVER as R, wireKeyPart as S, assertPspCurrency as T, EncodeGatedPsp as U, WIRE_SCALE_MARKER as V, GatedPsp as W, WireAmount as X, PspId as Y, AuthorizeNetAmounts as Z, googleMicros as _, iyzicoPrice as a, oneWireUnit as b, parseProviderAmount as c, pspPresentmentCurrencies as d, DestinationValue as f, feedPrice as g, eventMoney as h, RAZORPAY_AFA_FREE_CAP as i, pspSupportsCurrency as j, pspDefaultCurrency as k, PspPresentment as l, destinationAmount as m, readSlotMoney as n, verificationCharge as o, EventMoney as p, MajorStringPsp as q, slotMoney as r, ProviderAmountOptions as s, SlotMoney as t, pspPresentment as u, DestinationId as v, TryDecodeWireOptions as w, sameWireAmount as x, SameWireAmountOptions as y, WIRE_SCALE_ISO_MINOR_V2 as z };
package/dist/wire.cjs ADDED
@@ -0,0 +1,37 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_wire = require("./wire-Bhuut8cW.cjs");
3
+ exports.ISO_MINOR_V2 = require_wire.ISO_MINOR_V2;
4
+ exports.PRE_CUTOVER = require_wire.PRE_CUTOVER;
5
+ exports.PSP_IDS = require_wire.PSP_IDS;
6
+ exports.RAZORPAY_AFA_FREE_CAP = require_wire.RAZORPAY_AFA_FREE_CAP;
7
+ exports.WIRE_SCALE_ISO_MINOR_V2 = require_wire.WIRE_SCALE_ISO_MINOR_V2;
8
+ exports.WIRE_SCALE_KEY = require_wire.WIRE_SCALE_KEY;
9
+ exports.WIRE_SCALE_MARKER = require_wire.WIRE_SCALE_MARKER;
10
+ exports.assertPspCurrency = require_wire.assertPspCurrency;
11
+ exports.authorizeNetReversibleAmount = require_wire.authorizeNetReversibleAmount;
12
+ exports.conventionOf = require_wire.conventionOf;
13
+ exports.decodeWire = require_wire.decodeWire;
14
+ exports.destinationAmount = require_wire.destinationAmount;
15
+ exports.encodeWire = require_wire.encodeWire;
16
+ exports.eventMoney = require_wire.eventMoney;
17
+ exports.feedPrice = require_wire.feedPrice;
18
+ exports.googleMicros = require_wire.googleMicros;
19
+ exports.iyzicoPrice = require_wire.iyzicoPrice;
20
+ exports.jsonDecimalLiteral = require_wire.jsonDecimalLiteral;
21
+ exports.oneWireUnit = require_wire.oneWireUnit;
22
+ exports.parseProviderAmount = require_wire.parseProviderAmount;
23
+ exports.pspCurrencies = require_wire.pspCurrencies;
24
+ exports.pspDefaultCurrency = require_wire.pspDefaultCurrency;
25
+ exports.pspMinimumAmount = require_wire.pspMinimumAmount;
26
+ exports.pspPresentment = require_wire.pspPresentment;
27
+ exports.pspPresentmentCurrencies = require_wire.pspPresentmentCurrencies;
28
+ exports.pspSupportsCurrency = require_wire.pspSupportsCurrency;
29
+ exports.pspWireDigits = require_wire.pspWireDigits;
30
+ exports.readSlotMoney = require_wire.readSlotMoney;
31
+ exports.sameWireAmount = require_wire.sameWireAmount;
32
+ exports.slotMoney = require_wire.slotMoney;
33
+ exports.tryDecodeWire = require_wire.tryDecodeWire;
34
+ exports.verificationCharge = require_wire.verificationCharge;
35
+ exports.wireBreakdown = require_wire.wireBreakdown;
36
+ exports.wireFactor = require_wire.wireFactor;
37
+ exports.wireKeyPart = require_wire.wireKeyPart;
@@ -0,0 +1,2 @@
1
+ import { $ as jsonDecimalLiteral, A as pspMinimumAmount, B as WIRE_SCALE_KEY, C as EncodeWireOptions, D as encodeWire, E as decodeWire, F as wireBreakdown, G as IsoMinorPsp, H as conventionOf, I as Convention, J as PSP_IDS, K as MajorNumberPsp, L as ISO_MINOR_V2, M as pspWireDigits, N as tryDecodeWire, O as pspCurrencies, P as wireFactor, Q as authorizeNetReversibleAmount, R as PRE_CUTOVER, S as wireKeyPart, T as assertPspCurrency, U as EncodeGatedPsp, V as WIRE_SCALE_MARKER, W as GatedPsp, X as WireAmount, Y as PspId, Z as AuthorizeNetAmounts, _ as googleMicros, a as iyzicoPrice, b as oneWireUnit, c as parseProviderAmount, d as pspPresentmentCurrencies, f as DestinationValue, g as feedPrice, h as eventMoney, i as RAZORPAY_AFA_FREE_CAP, j as pspSupportsCurrency, k as pspDefaultCurrency, l as PspPresentment, m as destinationAmount, n as readSlotMoney, o as verificationCharge, p as EventMoney, q as MajorStringPsp, r as slotMoney, s as ProviderAmountOptions, t as SlotMoney, u as pspPresentment, v as DestinationId, w as TryDecodeWireOptions, x as sameWireAmount, y as SameWireAmountOptions, z as WIRE_SCALE_ISO_MINOR_V2 } from "./wire-xjYXv4go.cjs";
2
+ export { type AuthorizeNetAmounts, type Convention, type DestinationId, type DestinationValue, type EncodeGatedPsp, type EncodeWireOptions, type EventMoney, type GatedPsp, ISO_MINOR_V2, type IsoMinorPsp, type MajorNumberPsp, type MajorStringPsp, PRE_CUTOVER, PSP_IDS, type ProviderAmountOptions, type PspId, type PspPresentment, RAZORPAY_AFA_FREE_CAP, type SameWireAmountOptions, type SlotMoney, type TryDecodeWireOptions, WIRE_SCALE_ISO_MINOR_V2, WIRE_SCALE_KEY, WIRE_SCALE_MARKER, type WireAmount, assertPspCurrency, authorizeNetReversibleAmount, conventionOf, decodeWire, destinationAmount, encodeWire, eventMoney, feedPrice, googleMicros, iyzicoPrice, jsonDecimalLiteral, oneWireUnit, parseProviderAmount, pspCurrencies, pspDefaultCurrency, pspMinimumAmount, pspPresentment, pspPresentmentCurrencies, pspSupportsCurrency, pspWireDigits, readSlotMoney, sameWireAmount, slotMoney, tryDecodeWire, verificationCharge, wireBreakdown, wireFactor, wireKeyPart };
package/dist/wire.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ import { $ as jsonDecimalLiteral, A as pspMinimumAmount, B as WIRE_SCALE_KEY, C as EncodeWireOptions, D as encodeWire, E as decodeWire, F as wireBreakdown, G as IsoMinorPsp, H as conventionOf, I as Convention, J as PSP_IDS, K as MajorNumberPsp, L as ISO_MINOR_V2, M as pspWireDigits, N as tryDecodeWire, O as pspCurrencies, P as wireFactor, Q as authorizeNetReversibleAmount, R as PRE_CUTOVER, S as wireKeyPart, T as assertPspCurrency, U as EncodeGatedPsp, V as WIRE_SCALE_MARKER, W as GatedPsp, X as WireAmount, Y as PspId, Z as AuthorizeNetAmounts, _ as googleMicros, a as iyzicoPrice, b as oneWireUnit, c as parseProviderAmount, d as pspPresentmentCurrencies, f as DestinationValue, g as feedPrice, h as eventMoney, i as RAZORPAY_AFA_FREE_CAP, j as pspSupportsCurrency, k as pspDefaultCurrency, l as PspPresentment, m as destinationAmount, n as readSlotMoney, o as verificationCharge, p as EventMoney, q as MajorStringPsp, r as slotMoney, s as ProviderAmountOptions, t as SlotMoney, u as pspPresentment, v as DestinationId, w as TryDecodeWireOptions, x as sameWireAmount, y as SameWireAmountOptions, z as WIRE_SCALE_ISO_MINOR_V2 } from "./wire-CaUN9Vf_.js";
2
+ export { type AuthorizeNetAmounts, type Convention, type DestinationId, type DestinationValue, type EncodeGatedPsp, type EncodeWireOptions, type EventMoney, type GatedPsp, ISO_MINOR_V2, type IsoMinorPsp, type MajorNumberPsp, type MajorStringPsp, PRE_CUTOVER, PSP_IDS, type ProviderAmountOptions, type PspId, type PspPresentment, RAZORPAY_AFA_FREE_CAP, type SameWireAmountOptions, type SlotMoney, type TryDecodeWireOptions, WIRE_SCALE_ISO_MINOR_V2, WIRE_SCALE_KEY, WIRE_SCALE_MARKER, type WireAmount, assertPspCurrency, authorizeNetReversibleAmount, conventionOf, decodeWire, destinationAmount, encodeWire, eventMoney, feedPrice, googleMicros, iyzicoPrice, jsonDecimalLiteral, oneWireUnit, parseProviderAmount, pspCurrencies, pspDefaultCurrency, pspMinimumAmount, pspPresentment, pspPresentmentCurrencies, pspSupportsCurrency, pspWireDigits, readSlotMoney, sameWireAmount, slotMoney, tryDecodeWire, verificationCharge, wireBreakdown, wireFactor, wireKeyPart };
package/dist/wire.js ADDED
@@ -0,0 +1,2 @@
1
+ import { A as WIRE_SCALE_KEY, C as pspSupportsCurrency, D as ISO_MINOR_V2, E as wireFactor, F as jsonDecimalLiteral, M as conventionOf, N as PSP_IDS, O as PRE_CUTOVER, P as authorizeNetReversibleAmount, S as pspMinimumAmount, T as tryDecodeWire, _ as assertPspCurrency, a as verificationCharge, b as pspCurrencies, c as pspPresentmentCurrencies, d as feedPrice, f as googleMicros, g as wireBreakdown, h as wireKeyPart, i as iyzicoPrice, j as WIRE_SCALE_MARKER, k as WIRE_SCALE_ISO_MINOR_V2, l as destinationAmount, m as sameWireAmount, n as slotMoney, o as parseProviderAmount, p as oneWireUnit, r as RAZORPAY_AFA_FREE_CAP, s as pspPresentment, t as readSlotMoney, u as eventMoney, v as decodeWire, w as pspWireDigits, x as pspDefaultCurrency, y as encodeWire } from "./wire-sW0yzqth.js";
2
+ export { ISO_MINOR_V2, PRE_CUTOVER, PSP_IDS, RAZORPAY_AFA_FREE_CAP, WIRE_SCALE_ISO_MINOR_V2, WIRE_SCALE_KEY, WIRE_SCALE_MARKER, assertPspCurrency, authorizeNetReversibleAmount, conventionOf, decodeWire, destinationAmount, encodeWire, eventMoney, feedPrice, googleMicros, iyzicoPrice, jsonDecimalLiteral, oneWireUnit, parseProviderAmount, pspCurrencies, pspDefaultCurrency, pspMinimumAmount, pspPresentment, pspPresentmentCurrencies, pspSupportsCurrency, pspWireDigits, readSlotMoney, sameWireAmount, slotMoney, tryDecodeWire, verificationCharge, wireBreakdown, wireFactor, wireKeyPart };
package/package.json CHANGED
@@ -1,6 +1,161 @@
1
1
  {
2
2
  "name": "@amboras-dev/money",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.2.0",
4
+ "description": "Money for Amboras: the storage rule (x100 for every currency, x1000 for seven), a generated currency registry, exact decimal arithmetic, Medusa amount parsing, PSP wire codecs, SQL builders, FX, commerce and billing math, agent-tool money and text entry. Zero dependencies.",
5
+ "license": "UNLICENSED",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/Ecomcoder/amboras-core.git",
9
+ "directory": "packages/money"
10
+ },
11
+ "type": "module",
12
+ "main": "./dist/index.cjs",
13
+ "module": "./dist/index.js",
14
+ "types": "./dist/index.d.cts",
15
+ "exports": {
16
+ ".": {
17
+ "import": {
18
+ "types": "./dist/index.d.ts",
19
+ "default": "./dist/index.js"
20
+ },
21
+ "require": {
22
+ "types": "./dist/index.d.cts",
23
+ "default": "./dist/index.cjs"
24
+ }
25
+ },
26
+ "./wire": {
27
+ "import": {
28
+ "types": "./dist/wire.d.ts",
29
+ "default": "./dist/wire.js"
30
+ },
31
+ "require": {
32
+ "types": "./dist/wire.d.cts",
33
+ "default": "./dist/wire.cjs"
34
+ }
35
+ },
36
+ "./sql": {
37
+ "import": {
38
+ "types": "./dist/sql.d.ts",
39
+ "default": "./dist/sql.js"
40
+ },
41
+ "require": {
42
+ "types": "./dist/sql.d.cts",
43
+ "default": "./dist/sql.cjs"
44
+ }
45
+ },
46
+ "./fx": {
47
+ "import": {
48
+ "types": "./dist/fx.d.ts",
49
+ "default": "./dist/fx.js"
50
+ },
51
+ "require": {
52
+ "types": "./dist/fx.d.cts",
53
+ "default": "./dist/fx.cjs"
54
+ }
55
+ },
56
+ "./commerce": {
57
+ "import": {
58
+ "types": "./dist/commerce.d.ts",
59
+ "default": "./dist/commerce.js"
60
+ },
61
+ "require": {
62
+ "types": "./dist/commerce.d.cts",
63
+ "default": "./dist/commerce.cjs"
64
+ }
65
+ },
66
+ "./billing": {
67
+ "import": {
68
+ "types": "./dist/billing.d.ts",
69
+ "default": "./dist/billing.js"
70
+ },
71
+ "require": {
72
+ "types": "./dist/billing.d.cts",
73
+ "default": "./dist/billing.cjs"
74
+ }
75
+ },
76
+ "./ai": {
77
+ "import": {
78
+ "types": "./dist/ai.d.ts",
79
+ "default": "./dist/ai.js"
80
+ },
81
+ "require": {
82
+ "types": "./dist/ai.d.cts",
83
+ "default": "./dist/ai.cjs"
84
+ }
85
+ },
86
+ "./input": {
87
+ "import": {
88
+ "types": "./dist/input.d.ts",
89
+ "default": "./dist/input.js"
90
+ },
91
+ "require": {
92
+ "types": "./dist/input.d.cts",
93
+ "default": "./dist/input.cjs"
94
+ }
95
+ },
96
+ "./testing": {
97
+ "import": {
98
+ "types": "./dist/testing.d.ts",
99
+ "default": "./dist/testing.js"
100
+ },
101
+ "require": {
102
+ "types": "./dist/testing.d.cts",
103
+ "default": "./dist/testing.cjs"
104
+ }
105
+ },
106
+ "./package.json": "./package.json"
107
+ },
108
+ "typesVersions": {
109
+ "*": {
110
+ "wire": [
111
+ "./dist/wire.d.cts"
112
+ ],
113
+ "sql": [
114
+ "./dist/sql.d.cts"
115
+ ],
116
+ "fx": [
117
+ "./dist/fx.d.cts"
118
+ ],
119
+ "commerce": [
120
+ "./dist/commerce.d.cts"
121
+ ],
122
+ "billing": [
123
+ "./dist/billing.d.cts"
124
+ ],
125
+ "ai": [
126
+ "./dist/ai.d.cts"
127
+ ],
128
+ "input": [
129
+ "./dist/input.d.cts"
130
+ ],
131
+ "testing": [
132
+ "./dist/testing.d.cts"
133
+ ]
134
+ }
135
+ },
136
+ "files": [
137
+ "dist"
138
+ ],
139
+ "sideEffects": false,
140
+ "engines": {
141
+ "node": ">=20"
142
+ },
143
+ "publishConfig": {
144
+ "access": "public"
145
+ },
146
+ "devDependencies": {
147
+ "@vitest/coverage-v8": "3.2.7",
148
+ "fast-check": "4.3.0",
149
+ "tsdown": "0.23.0",
150
+ "typescript": "5.9.3",
151
+ "vitest": "3.2.7"
152
+ },
153
+ "scripts": {
154
+ "build": "tsdown",
155
+ "typecheck": "tsc --noEmit",
156
+ "test": "vitest run --coverage",
157
+ "currencies": "node scripts/gen-currency-data.mjs",
158
+ "currencies:check": "node scripts/gen-currency-data.mjs --check",
159
+ "golden": "node scripts/gen-golden-vectors.mjs"
160
+ }
6
161
  }