@amboras-dev/money 0.1.0 → 0.3.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 (80) hide show
  1. package/README.md +25 -10
  2. package/dist/ai.cjs +12 -13
  3. package/dist/ai.d.cts +5 -9
  4. package/dist/ai.d.ts +5 -9
  5. package/dist/ai.js +12 -13
  6. package/dist/{allocate-D7tm_t_o.cjs → allocate-AusholrC.cjs} +3 -4
  7. package/dist/{allocate-CdnhvAda.js → allocate-BBRfdaSC.js} +3 -4
  8. package/dist/{amount-DHtvZSSm.cjs → amount-CwFzcxUl.cjs} +29 -12
  9. package/dist/{amount-D7dj76nH.js → amount-DHFOK2Yd.js} +29 -12
  10. package/dist/{arithmetic-C-Q_aI49.js → arithmetic-C97-YafD.js} +4 -5
  11. package/dist/{arithmetic-Bq-8mSal.cjs → arithmetic-D8A6IeZ0.cjs} +4 -5
  12. package/dist/billing.cjs +5 -8
  13. package/dist/billing.d.cts +1 -9
  14. package/dist/billing.d.ts +1 -9
  15. package/dist/billing.js +5 -8
  16. package/dist/commerce.cjs +15 -23
  17. package/dist/commerce.d.cts +2 -16
  18. package/dist/commerce.d.ts +2 -16
  19. package/dist/commerce.js +15 -23
  20. package/dist/{format-BnA1aLJk.cjs → format-92fzvTXY.cjs} +21 -6
  21. package/dist/{format-BdB7LEIp.js → format-BJC513u4.js} +16 -7
  22. package/dist/fx.cjs +12 -18
  23. package/dist/fx.d.cts +5 -15
  24. package/dist/fx.d.ts +5 -15
  25. package/dist/fx.js +12 -18
  26. package/dist/index.cjs +13 -12
  27. package/dist/index.d.cts +28 -22
  28. package/dist/index.d.ts +28 -22
  29. package/dist/index.js +11 -13
  30. package/dist/input.cjs +7 -10
  31. package/dist/input.d.cts +9 -16
  32. package/dist/input.d.ts +9 -16
  33. package/dist/input.js +7 -10
  34. package/dist/{iso-minor--gQWI1f2.cjs → iso-minor-DyNjT9A1.cjs} +2 -3
  35. package/dist/{iso-minor-CtaiIifs.js → iso-minor-odkY-e6I.js} +2 -3
  36. package/dist/{medusa-OJ2TJOxt.cjs → medusa-CzVK0bth.cjs} +24 -4
  37. package/dist/{medusa-DuQ3-KoD.d.cts → medusa-DofdvIgQ.d.cts} +11 -4
  38. package/dist/{medusa-RwqxaDGq.d.ts → medusa-DrbYmD2Y.d.ts} +11 -4
  39. package/dist/{medusa-CmxCni-G.js → medusa-pKGlImn9.js} +19 -5
  40. package/dist/{money-CbhsT0fB.d.cts → money-BkMeYDEW.d.cts} +19 -9
  41. package/dist/{money-CbhsT0fB.d.ts → money-BkMeYDEW.d.ts} +19 -9
  42. package/dist/{money-CIgELekG.js → money-BxbAw7BP.js} +25 -21
  43. package/dist/{money-D5-vlv0h.cjs → money-DWBjuuEK.cjs} +42 -20
  44. package/dist/{number-text-C82oh6JB.js → number-text-Bj-gZXiF.js} +3 -4
  45. package/dist/{number-text-BpvN6NAo.cjs → number-text-CWuVwrlg.cjs} +3 -4
  46. package/dist/{own-oP9DXFWv.cjs → own-C5imDkyB.cjs} +1 -2
  47. package/dist/{own-D7544D3k.js → own-DHxqIYqL.js} +1 -2
  48. package/dist/{percent-CKVI_c-m.js → percent-CB3Ixjc_.js} +2 -3
  49. package/dist/{percent-Dt8vNIAW.cjs → percent-DABHiSBs.cjs} +2 -3
  50. package/dist/{rate-CmeTGNex.d.ts → rate-BvvZUdSu.d.ts} +1 -3
  51. package/dist/{rate-toyS3EMf.d.cts → rate-CEakW3ia.d.cts} +1 -3
  52. package/dist/{rate-DGPfB_jc.cjs → rate-CEjWTATc.cjs} +3 -4
  53. package/dist/{rate-lLPViBuM.js → rate-D6S2_wgZ.js} +3 -4
  54. package/dist/{reporting-5xby-Zas.d.ts → reporting-DFNyDBdi.d.cts} +2 -4
  55. package/dist/{reporting-DEM97DhQ.d.cts → reporting-jIBILvnr.d.ts} +2 -4
  56. package/dist/{retail-BwcFJcVN.d.ts → retail-B04CjW3b.d.ts} +1 -3
  57. package/dist/{retail-DTk2XAMM.cjs → retail-CYGPU4ea.cjs} +4 -5
  58. package/dist/{retail-Mqd-sPMF.d.cts → retail-CmEyJQOH.d.cts} +1 -3
  59. package/dist/{retail-BsvpNv1F.js → retail-DXgs11ov.js} +4 -5
  60. package/dist/{rounding-oZ832yTD.cjs → rounding-4QKTRbMQ.cjs} +2 -3
  61. package/dist/{rounding-CVAPEfq_.js → rounding-CA1PVP3b.js} +2 -3
  62. package/dist/sql.cjs +9 -15
  63. package/dist/sql.d.cts +2 -12
  64. package/dist/sql.d.ts +2 -12
  65. package/dist/sql.js +9 -15
  66. package/dist/testing.cjs +72675 -12
  67. package/dist/testing.d.cts +46 -11
  68. package/dist/testing.d.ts +46 -11
  69. package/dist/testing.js +72674 -13
  70. package/dist/{wire-CI3Sm1iC.js → wire-B4QU8O3W.js} +584 -114
  71. package/dist/wire-CVNicirK.d.ts +428 -0
  72. package/dist/wire-CtNJmWVP.d.cts +428 -0
  73. package/dist/{wire-DQZ6fA3c.cjs → wire-u2tmHY0Y.cjs} +649 -113
  74. package/dist/wire.cjs +12 -1
  75. package/dist/wire.d.cts +2 -2
  76. package/dist/wire.d.ts +2 -2
  77. package/dist/wire.js +1 -2
  78. package/package.json +4 -3
  79. package/dist/wire-Cd4Q1Jmm.d.ts +0 -269
  80. package/dist/wire-hWuixv3w.d.cts +0 -269
@@ -1,14 +1,11 @@
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
1
+ import { R as DecimalText, b as FractionDigits, i as Money, x as StorageScale, z as RoundingMode } from "./money-BkMeYDEW.cjs";
2
+ import { mt as PspId } from "./wire-CtNJmWVP.cjs";
4
3
  /**
5
4
  * Mismatch messages (empty when consistent) between `psp`'s encoder and `documented(code)`, the
6
5
  * decimal count the PSP's documentation gives for each currency it takes (undefined: the
7
6
  * documentation does not list it). Gated PSPs are probed under the iso-minor-v2 convention.
8
7
  */
9
8
  export declare function checkWireDigits(psp: PspId, documented: (code: string) => FractionDigits | undefined): string[];
10
- //#endregion
11
- //#region src/testing/fixtures.d.ts
12
9
  /** One currency of a class, with the facts a test should assert about it. */
13
10
  interface CurrencyCase {
14
11
  readonly code: string;
@@ -46,8 +43,6 @@ export declare const ROUNDING_VECTORS: readonly RoundingVector[];
46
43
  export declare function normalizeIntlSpaces(s: string): string;
47
44
  /** A sample amount for previews and email samples: `fromMajor(major, currency, { precision: 'round' })` (KWD 12.5 is 12500 stored). */
48
45
  export declare function sampleMoney(currency: string, major: number | string): Money;
49
- //#endregion
50
- //#region src/testing/golden-destinations.d.ts
51
46
  /** `destinationAmount(dest, money(stored, currency), { as })`: `expected` null means it returns undefined; `error` means it throws that code. */
52
47
  interface DestinationAmountVector {
53
48
  readonly dest: string;
@@ -72,8 +67,6 @@ export declare const DESTINATION_GOLDEN_VECTORS: {
72
67
  readonly feedPrice: readonly DestinationTextVector[];
73
68
  readonly googleMicros: readonly DestinationTextVector[];
74
69
  };
75
- //#endregion
76
- //#region src/testing/golden-psp.d.ts
77
70
  type GoldenPspId = 'stripe' | 'adyen' | 'razorpay' | 'paystack' | 'momo' | 'vnpay' | 'paypal' | 'mollie' | 'airwallex' | 'iyzico' | 'authorize-net' | 'payoo';
78
71
  /**
79
72
  * One encode as Medusa does it today: `wire` for a sent amount, or `error` and `wire: null` for a refusal: the
@@ -93,5 +86,47 @@ interface GoldenVector {
93
86
  }
94
87
  /** Wire bytes for every PSP x presented currency x storage amount (18900 vectors). */
95
88
  export declare const PSP_GOLDEN_VECTORS: readonly GoldenVector[];
96
- //#endregion
97
- export type { CurrencyCase, DestinationAmountVector, DestinationTextVector, GoldenPspId, GoldenVector, MedusaAmountShape, RoundingVector };
89
+ /**
90
+ * Where the package departs on purpose from what the codec does with a fractional amount:
91
+ * `'sub-unit'` a positive amount whose wire is 0 is refused (`error` contains `SUB_UNIT_REFUSAL`);
92
+ * `'exact-half-up'` a tie at the wire digits that Medusa's float `toFixed` rounded down is rounded
93
+ * half-up exactly; `'real-amount'` a refusal that named a `toFixed` neighbour of the amount names
94
+ * the amount as held.
95
+ */
96
+ type FractionalPolicy = 'sub-unit' | 'exact-half-up' | 'real-amount';
97
+ /**
98
+ * One encode of a FRACTIONAL storage amount (Medusa keeps unrounded totals): `wire` and `error` are
99
+ * what encodeWire gives; where it departs from the codec on purpose, `policy` says why and `medusa`
100
+ * holds the codec's own wire or message.
101
+ */
102
+ interface FractionalGoldenVector {
103
+ readonly psp: GoldenPspId;
104
+ readonly currency: string;
105
+ readonly convention: GoldenVector['convention'];
106
+ /** The storage amount as canonical decimal text (`'107.8175'`). */
107
+ readonly stored: string;
108
+ readonly wire: number | string | null;
109
+ readonly error: string | null;
110
+ readonly policy: FractionalPolicy | null;
111
+ readonly medusa: number | string | null;
112
+ }
113
+ /** Fractional storage amounts for every PSP x presented currency (10500 vectors). */
114
+ export declare const PSP_FRACTIONAL_GOLDEN_VECTORS: readonly FractionalGoldenVector[];
115
+ /**
116
+ * One amount as Medusa's pre-0.2.0 float codec spelled it, for a PSP it encoded in floating point
117
+ * (`(stored / storageScale).toFixed(digits)` on a double): `wire` is what the adapter sent (a number
118
+ * for Airwallex and Payoo), `iso` its `legacyIsoMajorString` (the same at the display digits). At an
119
+ * exact tie the double can sit below it, so USD `'1072.5'` is `'10.72'` where encodeWire sends
120
+ * `'10.73'`; `sameWireAmount(..., { acceptLegacyFloatRounding: true })` accepts these spellings.
121
+ */
122
+ interface LegacyFloatGoldenVector {
123
+ readonly psp: GoldenPspId;
124
+ readonly currency: string;
125
+ /** The storage amount as decimal text (`'1072.5'`). */
126
+ readonly stored: string;
127
+ readonly wire: number | string;
128
+ readonly iso: string;
129
+ }
130
+ /** Medusa's float spellings for every float PSP x presented currency x amount (7589 vectors). */
131
+ export declare const PSP_LEGACY_FLOAT_GOLDEN_VECTORS: readonly LegacyFloatGoldenVector[];
132
+ export type { CurrencyCase, DestinationAmountVector, DestinationTextVector, FractionalGoldenVector, FractionalPolicy, GoldenPspId, GoldenVector, LegacyFloatGoldenVector, MedusaAmountShape, RoundingVector };
package/dist/testing.d.ts CHANGED
@@ -1,14 +1,11 @@
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
1
+ import { R as DecimalText, b as FractionDigits, i as Money, x as StorageScale, z as RoundingMode } from "./money-BkMeYDEW.js";
2
+ import { mt as PspId } from "./wire-CVNicirK.js";
4
3
  /**
5
4
  * Mismatch messages (empty when consistent) between `psp`'s encoder and `documented(code)`, the
6
5
  * decimal count the PSP's documentation gives for each currency it takes (undefined: the
7
6
  * documentation does not list it). Gated PSPs are probed under the iso-minor-v2 convention.
8
7
  */
9
8
  export declare function checkWireDigits(psp: PspId, documented: (code: string) => FractionDigits | undefined): string[];
10
- //#endregion
11
- //#region src/testing/fixtures.d.ts
12
9
  /** One currency of a class, with the facts a test should assert about it. */
13
10
  interface CurrencyCase {
14
11
  readonly code: string;
@@ -46,8 +43,6 @@ export declare const ROUNDING_VECTORS: readonly RoundingVector[];
46
43
  export declare function normalizeIntlSpaces(s: string): string;
47
44
  /** A sample amount for previews and email samples: `fromMajor(major, currency, { precision: 'round' })` (KWD 12.5 is 12500 stored). */
48
45
  export declare function sampleMoney(currency: string, major: number | string): Money;
49
- //#endregion
50
- //#region src/testing/golden-destinations.d.ts
51
46
  /** `destinationAmount(dest, money(stored, currency), { as })`: `expected` null means it returns undefined; `error` means it throws that code. */
52
47
  interface DestinationAmountVector {
53
48
  readonly dest: string;
@@ -72,8 +67,6 @@ export declare const DESTINATION_GOLDEN_VECTORS: {
72
67
  readonly feedPrice: readonly DestinationTextVector[];
73
68
  readonly googleMicros: readonly DestinationTextVector[];
74
69
  };
75
- //#endregion
76
- //#region src/testing/golden-psp.d.ts
77
70
  type GoldenPspId = 'stripe' | 'adyen' | 'razorpay' | 'paystack' | 'momo' | 'vnpay' | 'paypal' | 'mollie' | 'airwallex' | 'iyzico' | 'authorize-net' | 'payoo';
78
71
  /**
79
72
  * One encode as Medusa does it today: `wire` for a sent amount, or `error` and `wire: null` for a refusal: the
@@ -93,5 +86,47 @@ interface GoldenVector {
93
86
  }
94
87
  /** Wire bytes for every PSP x presented currency x storage amount (18900 vectors). */
95
88
  export declare const PSP_GOLDEN_VECTORS: readonly GoldenVector[];
96
- //#endregion
97
- export type { CurrencyCase, DestinationAmountVector, DestinationTextVector, GoldenPspId, GoldenVector, MedusaAmountShape, RoundingVector };
89
+ /**
90
+ * Where the package departs on purpose from what the codec does with a fractional amount:
91
+ * `'sub-unit'` a positive amount whose wire is 0 is refused (`error` contains `SUB_UNIT_REFUSAL`);
92
+ * `'exact-half-up'` a tie at the wire digits that Medusa's float `toFixed` rounded down is rounded
93
+ * half-up exactly; `'real-amount'` a refusal that named a `toFixed` neighbour of the amount names
94
+ * the amount as held.
95
+ */
96
+ type FractionalPolicy = 'sub-unit' | 'exact-half-up' | 'real-amount';
97
+ /**
98
+ * One encode of a FRACTIONAL storage amount (Medusa keeps unrounded totals): `wire` and `error` are
99
+ * what encodeWire gives; where it departs from the codec on purpose, `policy` says why and `medusa`
100
+ * holds the codec's own wire or message.
101
+ */
102
+ interface FractionalGoldenVector {
103
+ readonly psp: GoldenPspId;
104
+ readonly currency: string;
105
+ readonly convention: GoldenVector['convention'];
106
+ /** The storage amount as canonical decimal text (`'107.8175'`). */
107
+ readonly stored: string;
108
+ readonly wire: number | string | null;
109
+ readonly error: string | null;
110
+ readonly policy: FractionalPolicy | null;
111
+ readonly medusa: number | string | null;
112
+ }
113
+ /** Fractional storage amounts for every PSP x presented currency (10500 vectors). */
114
+ export declare const PSP_FRACTIONAL_GOLDEN_VECTORS: readonly FractionalGoldenVector[];
115
+ /**
116
+ * One amount as Medusa's pre-0.2.0 float codec spelled it, for a PSP it encoded in floating point
117
+ * (`(stored / storageScale).toFixed(digits)` on a double): `wire` is what the adapter sent (a number
118
+ * for Airwallex and Payoo), `iso` its `legacyIsoMajorString` (the same at the display digits). At an
119
+ * exact tie the double can sit below it, so USD `'1072.5'` is `'10.72'` where encodeWire sends
120
+ * `'10.73'`; `sameWireAmount(..., { acceptLegacyFloatRounding: true })` accepts these spellings.
121
+ */
122
+ interface LegacyFloatGoldenVector {
123
+ readonly psp: GoldenPspId;
124
+ readonly currency: string;
125
+ /** The storage amount as decimal text (`'1072.5'`). */
126
+ readonly stored: string;
127
+ readonly wire: number | string;
128
+ readonly iso: string;
129
+ }
130
+ /** Medusa's float spellings for every float PSP x presented currency x amount (7589 vectors). */
131
+ export declare const PSP_LEGACY_FLOAT_GOLDEN_VECTORS: readonly LegacyFloatGoldenVector[];
132
+ export type { CurrencyCase, DestinationAmountVector, DestinationTextVector, FractionalGoldenVector, FractionalPolicy, GoldenPspId, GoldenVector, LegacyFloatGoldenVector, MedusaAmountShape, RoundingVector };