@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.
- package/README.md +401 -2
- package/dist/ai.cjs +185 -0
- package/dist/ai.d.cts +97 -0
- package/dist/ai.d.ts +97 -0
- package/dist/ai.js +175 -0
- package/dist/allocate-CZRg4TOP.cjs +222 -0
- package/dist/allocate-X7_jAtOj.js +199 -0
- package/dist/amount-BV0O-aN8.cjs +241 -0
- package/dist/amount-BoYBMgK9.js +200 -0
- package/dist/arithmetic-BhNwisjb.js +132 -0
- package/dist/arithmetic-DjT4Kzgt.cjs +233 -0
- package/dist/billing.cjs +184 -0
- package/dist/billing.d.cts +81 -0
- package/dist/billing.d.ts +81 -0
- package/dist/billing.js +175 -0
- package/dist/commerce.cjs +536 -0
- package/dist/commerce.d.cts +293 -0
- package/dist/commerce.d.ts +293 -0
- package/dist/commerce.js +516 -0
- package/dist/format-BdPnijvn.js +99 -0
- package/dist/format-DLhno7eX.cjs +128 -0
- package/dist/fx.cjs +407 -0
- package/dist/fx.d.cts +157 -0
- package/dist/fx.d.ts +157 -0
- package/dist/fx.js +374 -0
- package/dist/index.cjs +352 -0
- package/dist/index.d.cts +300 -0
- package/dist/index.d.ts +300 -0
- package/dist/index.js +276 -0
- package/dist/input.cjs +163 -0
- package/dist/input.d.cts +203 -0
- package/dist/input.d.ts +203 -0
- package/dist/input.js +153 -0
- package/dist/iso-minor-CqkWDxHS.js +48 -0
- package/dist/iso-minor-wSwJN57T.cjs +65 -0
- package/dist/medusa-4K8N1pUc.d.cts +87 -0
- package/dist/medusa-DBXJXXvF.d.ts +87 -0
- package/dist/medusa-DqJY1qpj.js +116 -0
- package/dist/medusa-lRY9xlsf.cjs +175 -0
- package/dist/money-B-3aFjNJ.d.cts +248 -0
- package/dist/money-B-3aFjNJ.d.ts +248 -0
- package/dist/money-B3wH_Z4S.cjs +3990 -0
- package/dist/money-WhnGiI00.js +3583 -0
- package/dist/number-text-BWu67jUq.cjs +145 -0
- package/dist/number-text-DE-q4jO5.js +134 -0
- package/dist/own-D7544D3k.js +4 -0
- package/dist/own-oP9DXFWv.cjs +9 -0
- package/dist/percent-C0InC2t2.cjs +43 -0
- package/dist/percent-D1VB9xXG.js +20 -0
- package/dist/rate-CVeMii4a.cjs +217 -0
- package/dist/rate-DBPiYgT1.d.ts +63 -0
- package/dist/rate-DicStBue.js +152 -0
- package/dist/rate-tqK8ijG0.d.cts +63 -0
- package/dist/reporting-CG-ai2sM.d.cts +31 -0
- package/dist/reporting-tpGJbqYp.d.ts +31 -0
- package/dist/retail-1mu888J1.js +69 -0
- package/dist/retail-C_BPLvMj.d.cts +31 -0
- package/dist/retail-Cml8YSKg.cjs +86 -0
- package/dist/retail-DRUTTQoJ.d.ts +31 -0
- package/dist/rounding-DHBtNCHG.cjs +79 -0
- package/dist/rounding-g9rvye0k.js +50 -0
- package/dist/sql.cjs +290 -0
- package/dist/sql.d.cts +147 -0
- package/dist/sql.d.ts +147 -0
- package/dist/sql.js +271 -0
- package/dist/testing.cjs +61995 -0
- package/dist/testing.d.cts +125 -0
- package/dist/testing.d.ts +125 -0
- package/dist/testing.js +61986 -0
- package/dist/wire-Bhuut8cW.cjs +2097 -0
- package/dist/wire-CaUN9Vf_.d.ts +309 -0
- package/dist/wire-sW0yzqth.js +1888 -0
- package/dist/wire-xjYXv4go.d.cts +309 -0
- package/dist/wire.cjs +37 -0
- package/dist/wire.d.cts +2 -0
- package/dist/wire.d.ts +2 -0
- package/dist/wire.js +2 -0
- package/package.json +158 -3
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { R as DecimalText, b as FractionDigits, i as Money, x as StorageScale, z as RoundingMode } from "./money-B-3aFjNJ.cjs";
|
|
2
|
+
import { Y as PspId } from "./wire-xjYXv4go.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
|
+
//#region src/testing/golden-psp-fractional.d.ts
|
|
98
|
+
/**
|
|
99
|
+
* Where the package departs on purpose from what the codec does with a fractional amount:
|
|
100
|
+
* `'sub-unit'` a positive amount whose wire is 0 is refused (`error` contains `SUB_UNIT_REFUSAL`);
|
|
101
|
+
* `'exact-half-up'` a tie at the wire digits that Medusa's float `toFixed` rounded down is rounded
|
|
102
|
+
* half-up exactly; `'real-amount'` a refusal that named a `toFixed` neighbour of the amount names
|
|
103
|
+
* the amount as held.
|
|
104
|
+
*/
|
|
105
|
+
type FractionalPolicy = 'sub-unit' | 'exact-half-up' | 'real-amount';
|
|
106
|
+
/**
|
|
107
|
+
* One encode of a FRACTIONAL storage amount (Medusa keeps unrounded totals): `wire` and `error` are
|
|
108
|
+
* what encodeWire gives; where it departs from the codec on purpose, `policy` says why and `medusa`
|
|
109
|
+
* holds the codec's own wire or message.
|
|
110
|
+
*/
|
|
111
|
+
interface FractionalGoldenVector {
|
|
112
|
+
readonly psp: GoldenPspId;
|
|
113
|
+
readonly currency: string;
|
|
114
|
+
readonly convention: GoldenVector['convention'];
|
|
115
|
+
/** The storage amount as canonical decimal text (`'107.8175'`). */
|
|
116
|
+
readonly stored: string;
|
|
117
|
+
readonly wire: number | string | null;
|
|
118
|
+
readonly error: string | null;
|
|
119
|
+
readonly policy: FractionalPolicy | null;
|
|
120
|
+
readonly medusa: number | string | null;
|
|
121
|
+
}
|
|
122
|
+
/** Fractional storage amounts for every PSP x presented currency (10500 vectors). */
|
|
123
|
+
export declare const PSP_FRACTIONAL_GOLDEN_VECTORS: readonly FractionalGoldenVector[];
|
|
124
|
+
//#endregion
|
|
125
|
+
export type { CurrencyCase, DestinationAmountVector, DestinationTextVector, FractionalGoldenVector, FractionalPolicy, GoldenPspId, GoldenVector, MedusaAmountShape, RoundingVector };
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { R as DecimalText, b as FractionDigits, i as Money, x as StorageScale, z as RoundingMode } from "./money-B-3aFjNJ.js";
|
|
2
|
+
import { Y as PspId } from "./wire-CaUN9Vf_.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
|
+
//#region src/testing/golden-psp-fractional.d.ts
|
|
98
|
+
/**
|
|
99
|
+
* Where the package departs on purpose from what the codec does with a fractional amount:
|
|
100
|
+
* `'sub-unit'` a positive amount whose wire is 0 is refused (`error` contains `SUB_UNIT_REFUSAL`);
|
|
101
|
+
* `'exact-half-up'` a tie at the wire digits that Medusa's float `toFixed` rounded down is rounded
|
|
102
|
+
* half-up exactly; `'real-amount'` a refusal that named a `toFixed` neighbour of the amount names
|
|
103
|
+
* the amount as held.
|
|
104
|
+
*/
|
|
105
|
+
type FractionalPolicy = 'sub-unit' | 'exact-half-up' | 'real-amount';
|
|
106
|
+
/**
|
|
107
|
+
* One encode of a FRACTIONAL storage amount (Medusa keeps unrounded totals): `wire` and `error` are
|
|
108
|
+
* what encodeWire gives; where it departs from the codec on purpose, `policy` says why and `medusa`
|
|
109
|
+
* holds the codec's own wire or message.
|
|
110
|
+
*/
|
|
111
|
+
interface FractionalGoldenVector {
|
|
112
|
+
readonly psp: GoldenPspId;
|
|
113
|
+
readonly currency: string;
|
|
114
|
+
readonly convention: GoldenVector['convention'];
|
|
115
|
+
/** The storage amount as canonical decimal text (`'107.8175'`). */
|
|
116
|
+
readonly stored: string;
|
|
117
|
+
readonly wire: number | string | null;
|
|
118
|
+
readonly error: string | null;
|
|
119
|
+
readonly policy: FractionalPolicy | null;
|
|
120
|
+
readonly medusa: number | string | null;
|
|
121
|
+
}
|
|
122
|
+
/** Fractional storage amounts for every PSP x presented currency (10500 vectors). */
|
|
123
|
+
export declare const PSP_FRACTIONAL_GOLDEN_VECTORS: readonly FractionalGoldenVector[];
|
|
124
|
+
//#endregion
|
|
125
|
+
export type { CurrencyCase, DestinationAmountVector, DestinationTextVector, FractionalGoldenVector, FractionalPolicy, GoldenPspId, GoldenVector, MedusaAmountShape, RoundingVector };
|