@amboras-dev/money 0.0.0-stage → 0.1.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 +393 -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-CdnhvAda.js +199 -0
  7. package/dist/allocate-D7tm_t_o.cjs +222 -0
  8. package/dist/amount-D7dj76nH.js +200 -0
  9. package/dist/amount-DHtvZSSm.cjs +241 -0
  10. package/dist/arithmetic-Bq-8mSal.cjs +233 -0
  11. package/dist/arithmetic-C-Q_aI49.js +132 -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-BdB7LEIp.js +90 -0
  21. package/dist/format-BnA1aLJk.cjs +113 -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 +349 -0
  27. package/dist/index.d.cts +288 -0
  28. package/dist/index.d.ts +288 -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--gQWI1f2.cjs +65 -0
  35. package/dist/iso-minor-CtaiIifs.js +48 -0
  36. package/dist/medusa-CmxCni-G.js +101 -0
  37. package/dist/medusa-DuQ3-KoD.d.cts +78 -0
  38. package/dist/medusa-OJ2TJOxt.cjs +154 -0
  39. package/dist/medusa-RwqxaDGq.d.ts +78 -0
  40. package/dist/money-CIgELekG.js +3571 -0
  41. package/dist/money-CbhsT0fB.d.cts +232 -0
  42. package/dist/money-CbhsT0fB.d.ts +232 -0
  43. package/dist/money-D5-vlv0h.cjs +3960 -0
  44. package/dist/number-text-BpvN6NAo.cjs +145 -0
  45. package/dist/number-text-C82oh6JB.js +134 -0
  46. package/dist/own-D7544D3k.js +4 -0
  47. package/dist/own-oP9DXFWv.cjs +9 -0
  48. package/dist/percent-CKVI_c-m.js +20 -0
  49. package/dist/percent-Dt8vNIAW.cjs +43 -0
  50. package/dist/rate-CmeTGNex.d.ts +63 -0
  51. package/dist/rate-DGPfB_jc.cjs +217 -0
  52. package/dist/rate-lLPViBuM.js +152 -0
  53. package/dist/rate-toyS3EMf.d.cts +63 -0
  54. package/dist/reporting-5xby-Zas.d.ts +31 -0
  55. package/dist/reporting-DEM97DhQ.d.cts +31 -0
  56. package/dist/retail-BsvpNv1F.js +69 -0
  57. package/dist/retail-BwcFJcVN.d.ts +31 -0
  58. package/dist/retail-DTk2XAMM.cjs +86 -0
  59. package/dist/retail-Mqd-sPMF.d.cts +31 -0
  60. package/dist/rounding-CVAPEfq_.js +50 -0
  61. package/dist/rounding-oZ832yTD.cjs +79 -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 +28518 -0
  67. package/dist/testing.d.cts +97 -0
  68. package/dist/testing.d.ts +97 -0
  69. package/dist/testing.js +28510 -0
  70. package/dist/wire-CI3Sm1iC.js +1675 -0
  71. package/dist/wire-Cd4Q1Jmm.d.ts +269 -0
  72. package/dist/wire-DQZ6fA3c.cjs +1872 -0
  73. package/dist/wire-hWuixv3w.d.cts +269 -0
  74. package/dist/wire.cjs +35 -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,97 @@
1
+ import { L as DecimalText, R as RoundingMode, b as StorageScale, r as Money, y as FractionDigits } from "./money-CbhsT0fB.cjs";
2
+ import { K as PspId } from "./wire-hWuixv3w.cjs";
3
+ //#region src/testing/check-wire-digits.d.ts
4
+ /**
5
+ * Mismatch messages (empty when consistent) between `psp`'s encoder and `documented(code)`, the
6
+ * decimal count the PSP's documentation gives for each currency it takes (undefined: the
7
+ * documentation does not list it). Gated PSPs are probed under the iso-minor-v2 convention.
8
+ */
9
+ export declare function checkWireDigits(psp: PspId, documented: (code: string) => FractionDigits | undefined): string[];
10
+ //#endregion
11
+ //#region src/testing/fixtures.d.ts
12
+ /** One currency of a class, with the facts a test should assert about it. */
13
+ interface CurrencyCase {
14
+ readonly code: string;
15
+ readonly storageScale: StorageScale;
16
+ readonly storageDigits: FractionDigits;
17
+ readonly displayDigits: FractionDigits;
18
+ readonly historic: boolean;
19
+ /** Why it is here. */
20
+ readonly why: string;
21
+ }
22
+ /** One currency per class the storage, display and wire rules distinguish. */
23
+ export declare const CURRENCY_CASES: readonly CurrencyCase[];
24
+ /** A Medusa amount shape with what `readStored(shape, 'USD', lenient)` and `readStoredDecimal(shape, lenient)` give. */
25
+ interface MedusaAmountShape {
26
+ readonly name: string;
27
+ readonly value: unknown;
28
+ /** `readStored(value, 'USD', { mode: 'lenient' })?.amount ?? null`. */
29
+ readonly stored: number | null;
30
+ /** `readStoredDecimal(value, { mode: 'lenient' })`. */
31
+ readonly decimal: string | null;
32
+ }
33
+ /** Every amount shape Medusa hands over, and the two text spellings that must not read as numbers. */
34
+ export declare const MEDUSA_AMOUNT_SHAPES: readonly MedusaAmountShape[];
35
+ /** `decimalRound(input, { scale, rounding })` must give `expected`. */
36
+ interface RoundingVector {
37
+ readonly input: string;
38
+ readonly scale: number;
39
+ readonly rounding: RoundingMode;
40
+ readonly expected: DecimalText;
41
+ readonly why: string;
42
+ }
43
+ /** The rounding cases float code got wrong, and the tie rules. */
44
+ export declare const ROUNDING_VECTORS: readonly RoundingVector[];
45
+ /** NBSP and narrow NBSP (ICU puts them in some locales' currency output) as plain spaces. */
46
+ export declare function normalizeIntlSpaces(s: string): string;
47
+ /** A sample amount for previews and email samples: `fromMajor(major, currency, { precision: 'round' })` (KWD 12.5 is 12500 stored). */
48
+ export declare function sampleMoney(currency: string, major: number | string): Money;
49
+ //#endregion
50
+ //#region src/testing/golden-destinations.d.ts
51
+ /** `destinationAmount(dest, money(stored, currency), { as })`: `expected` null means it returns undefined; `error` means it throws that code. */
52
+ interface DestinationAmountVector {
53
+ readonly dest: string;
54
+ readonly stored: number;
55
+ readonly currency: string;
56
+ readonly as?: 'number' | 'string';
57
+ readonly expected: {
58
+ readonly value: number | string;
59
+ readonly currency: string;
60
+ } | null;
61
+ readonly error: 'wire_unsupported' | null;
62
+ }
63
+ /** `feedPrice(money(stored, currency))` or `googleMicros(money(stored, currency))` must give `expected`. */
64
+ interface DestinationTextVector {
65
+ readonly stored: number;
66
+ readonly currency: string;
67
+ readonly expected: string;
68
+ }
69
+ /** Expectations for `destinationAmount`, `feedPrice` and `googleMicros`. */
70
+ export declare const DESTINATION_GOLDEN_VECTORS: {
71
+ readonly destinationAmount: readonly DestinationAmountVector[];
72
+ readonly feedPrice: readonly DestinationTextVector[];
73
+ readonly googleMicros: readonly DestinationTextVector[];
74
+ };
75
+ //#endregion
76
+ //#region src/testing/golden-psp.d.ts
77
+ type GoldenPspId = 'stripe' | 'adyen' | 'razorpay' | 'paystack' | 'momo' | 'vnpay' | 'paypal' | 'mollie' | 'airwallex' | 'iyzico' | 'authorize-net' | 'payoo';
78
+ /**
79
+ * One encode as Medusa does it today: `wire` for a sent amount, or `error` and `wire: null` for a refusal: the
80
+ * codec's verbatim message, or, for a positive amount whose wire rounds to 0, a description containing
81
+ * `' rounds to 0 at '` (`SUB_UNIT_REFUSAL`). That refusal is package policy, not Medusa behaviour: Medusa puts 0
82
+ * on the wire at initiate for Stripe and Adyen, and for Razorpay, PayPal and Airwallex everywhere; it refuses at
83
+ * refund and capture for Stripe and Adyen, and in Mollie, iyzico and Authorize.Net.
84
+ */
85
+ interface GoldenVector {
86
+ readonly psp: GoldenPspId;
87
+ readonly currency: string;
88
+ /** Gated PSPs: the session's convention; null for PSPs without a cutover. */
89
+ readonly convention: 'iso-minor-v2' | 'pre-cutover' | null;
90
+ readonly stored: number;
91
+ readonly wire: number | string | null;
92
+ readonly error: string | null;
93
+ }
94
+ /** Wire bytes for every PSP x presented currency x storage amount (18900 vectors). */
95
+ export declare const PSP_GOLDEN_VECTORS: readonly GoldenVector[];
96
+ //#endregion
97
+ export type { CurrencyCase, DestinationAmountVector, DestinationTextVector, GoldenPspId, GoldenVector, MedusaAmountShape, RoundingVector };
@@ -0,0 +1,97 @@
1
+ import { L as DecimalText, R as RoundingMode, b as StorageScale, r as Money, y as FractionDigits } from "./money-CbhsT0fB.js";
2
+ import { K as PspId } from "./wire-Cd4Q1Jmm.js";
3
+ //#region src/testing/check-wire-digits.d.ts
4
+ /**
5
+ * Mismatch messages (empty when consistent) between `psp`'s encoder and `documented(code)`, the
6
+ * decimal count the PSP's documentation gives for each currency it takes (undefined: the
7
+ * documentation does not list it). Gated PSPs are probed under the iso-minor-v2 convention.
8
+ */
9
+ export declare function checkWireDigits(psp: PspId, documented: (code: string) => FractionDigits | undefined): string[];
10
+ //#endregion
11
+ //#region src/testing/fixtures.d.ts
12
+ /** One currency of a class, with the facts a test should assert about it. */
13
+ interface CurrencyCase {
14
+ readonly code: string;
15
+ readonly storageScale: StorageScale;
16
+ readonly storageDigits: FractionDigits;
17
+ readonly displayDigits: FractionDigits;
18
+ readonly historic: boolean;
19
+ /** Why it is here. */
20
+ readonly why: string;
21
+ }
22
+ /** One currency per class the storage, display and wire rules distinguish. */
23
+ export declare const CURRENCY_CASES: readonly CurrencyCase[];
24
+ /** A Medusa amount shape with what `readStored(shape, 'USD', lenient)` and `readStoredDecimal(shape, lenient)` give. */
25
+ interface MedusaAmountShape {
26
+ readonly name: string;
27
+ readonly value: unknown;
28
+ /** `readStored(value, 'USD', { mode: 'lenient' })?.amount ?? null`. */
29
+ readonly stored: number | null;
30
+ /** `readStoredDecimal(value, { mode: 'lenient' })`. */
31
+ readonly decimal: string | null;
32
+ }
33
+ /** Every amount shape Medusa hands over, and the two text spellings that must not read as numbers. */
34
+ export declare const MEDUSA_AMOUNT_SHAPES: readonly MedusaAmountShape[];
35
+ /** `decimalRound(input, { scale, rounding })` must give `expected`. */
36
+ interface RoundingVector {
37
+ readonly input: string;
38
+ readonly scale: number;
39
+ readonly rounding: RoundingMode;
40
+ readonly expected: DecimalText;
41
+ readonly why: string;
42
+ }
43
+ /** The rounding cases float code got wrong, and the tie rules. */
44
+ export declare const ROUNDING_VECTORS: readonly RoundingVector[];
45
+ /** NBSP and narrow NBSP (ICU puts them in some locales' currency output) as plain spaces. */
46
+ export declare function normalizeIntlSpaces(s: string): string;
47
+ /** A sample amount for previews and email samples: `fromMajor(major, currency, { precision: 'round' })` (KWD 12.5 is 12500 stored). */
48
+ export declare function sampleMoney(currency: string, major: number | string): Money;
49
+ //#endregion
50
+ //#region src/testing/golden-destinations.d.ts
51
+ /** `destinationAmount(dest, money(stored, currency), { as })`: `expected` null means it returns undefined; `error` means it throws that code. */
52
+ interface DestinationAmountVector {
53
+ readonly dest: string;
54
+ readonly stored: number;
55
+ readonly currency: string;
56
+ readonly as?: 'number' | 'string';
57
+ readonly expected: {
58
+ readonly value: number | string;
59
+ readonly currency: string;
60
+ } | null;
61
+ readonly error: 'wire_unsupported' | null;
62
+ }
63
+ /** `feedPrice(money(stored, currency))` or `googleMicros(money(stored, currency))` must give `expected`. */
64
+ interface DestinationTextVector {
65
+ readonly stored: number;
66
+ readonly currency: string;
67
+ readonly expected: string;
68
+ }
69
+ /** Expectations for `destinationAmount`, `feedPrice` and `googleMicros`. */
70
+ export declare const DESTINATION_GOLDEN_VECTORS: {
71
+ readonly destinationAmount: readonly DestinationAmountVector[];
72
+ readonly feedPrice: readonly DestinationTextVector[];
73
+ readonly googleMicros: readonly DestinationTextVector[];
74
+ };
75
+ //#endregion
76
+ //#region src/testing/golden-psp.d.ts
77
+ type GoldenPspId = 'stripe' | 'adyen' | 'razorpay' | 'paystack' | 'momo' | 'vnpay' | 'paypal' | 'mollie' | 'airwallex' | 'iyzico' | 'authorize-net' | 'payoo';
78
+ /**
79
+ * One encode as Medusa does it today: `wire` for a sent amount, or `error` and `wire: null` for a refusal: the
80
+ * codec's verbatim message, or, for a positive amount whose wire rounds to 0, a description containing
81
+ * `' rounds to 0 at '` (`SUB_UNIT_REFUSAL`). That refusal is package policy, not Medusa behaviour: Medusa puts 0
82
+ * on the wire at initiate for Stripe and Adyen, and for Razorpay, PayPal and Airwallex everywhere; it refuses at
83
+ * refund and capture for Stripe and Adyen, and in Mollie, iyzico and Authorize.Net.
84
+ */
85
+ interface GoldenVector {
86
+ readonly psp: GoldenPspId;
87
+ readonly currency: string;
88
+ /** Gated PSPs: the session's convention; null for PSPs without a cutover. */
89
+ readonly convention: 'iso-minor-v2' | 'pre-cutover' | null;
90
+ readonly stored: number;
91
+ readonly wire: number | string | null;
92
+ readonly error: string | null;
93
+ }
94
+ /** Wire bytes for every PSP x presented currency x storage amount (18900 vectors). */
95
+ export declare const PSP_GOLDEN_VECTORS: readonly GoldenVector[];
96
+ //#endregion
97
+ export type { CurrencyCase, DestinationAmountVector, DestinationTextVector, GoldenPspId, GoldenVector, MedusaAmountShape, RoundingVector };