@adminiumjs/add-on-contracts 0.3.31 → 0.3.32
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/add-on-block.d.ts +4 -0
- package/dist/add-on-block.d.ts.map +1 -1
- package/dist/contracts.d.ts +6 -0
- package/dist/contracts.d.ts.map +1 -1
- package/dist/contracts.js +16 -0
- package/dist/contracts.js.map +1 -1
- package/dist/document-render.d.ts +9 -2
- package/dist/document-render.d.ts.map +1 -1
- package/dist/document-render.js +4 -2
- package/dist/document-render.js.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/payment-demo.d.ts +99 -0
- package/dist/payment-demo.d.ts.map +1 -0
- package/dist/payment-demo.js +604 -0
- package/dist/payment-demo.js.map +1 -0
- package/dist/payment-money.d.ts +29 -0
- package/dist/payment-money.d.ts.map +1 -0
- package/dist/payment-money.js +99 -0
- package/dist/payment-money.js.map +1 -0
- package/dist/payment-provider.d.ts +605 -0
- package/dist/payment-provider.d.ts.map +1 -0
- package/dist/payment-provider.js +249 -0
- package/dist/payment-provider.js.map +1 -0
- package/dist/runtime/app-types.d.ts +17 -0
- package/dist/runtime/app-types.d.ts.map +1 -1
- package/dist/runtime/app.d.ts +2 -0
- package/dist/runtime/app.d.ts.map +1 -1
- package/dist/runtime/app.js +2 -0
- package/dist/runtime/app.js.map +1 -1
- package/dist/runtime/index.d.ts +2 -2
- package/dist/runtime/index.d.ts.map +1 -1
- package/dist/runtime/index.js +2 -1
- package/dist/runtime/index.js.map +1 -1
- package/dist/testing/index.d.ts +1 -0
- package/dist/testing/index.d.ts.map +1 -1
- package/dist/testing/index.js +1 -0
- package/dist/testing/index.js.map +1 -1
- package/dist/testing/payment-provider.d.ts +43 -0
- package/dist/testing/payment-provider.d.ts.map +1 -0
- package/dist/testing/payment-provider.js +308 -0
- package/dist/testing/payment-provider.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Decimal text ↔ a provider's smallest unit, exactly.
|
|
3
|
+
*
|
|
4
|
+
* Money never passes through a float here. A provider half converts with its
|
|
5
|
+
* OWN exponent table (Stripe treats MGA as zero-decimal; PayPal sends HUF, JPY
|
|
6
|
+
* and TWD with no decimals), so these helpers take the exponent as an argument
|
|
7
|
+
* and the table is the provider's. An amount with more non-zero decimals than
|
|
8
|
+
* the exponent allows is refused (null), never rounded: rounding a customer's
|
|
9
|
+
* amount is taking a different amount.
|
|
10
|
+
*/
|
|
11
|
+
/** "120.50" at exponent 2 → "12050". "12000.00" at 0 → "12000". "45.2505" at 3 → null. */
|
|
12
|
+
export declare function decimalToMinor(amount: string, exponent: number): string | null;
|
|
13
|
+
/** "12050" at exponent 2 → "120.50". "12000" at 0 → "12000". */
|
|
14
|
+
export declare function minorToDecimal(minor: string, exponent: number): string | null;
|
|
15
|
+
/** True when two decimal texts are the same number ("120" and "120.00"). */
|
|
16
|
+
export declare function sameAmount(a: string, b: string): boolean;
|
|
17
|
+
/** Compares two decimal texts: -1, 0 or 1. Null when either is not a decimal. */
|
|
18
|
+
export declare function compareAmounts(a: string, b: string): -1 | 0 | 1 | null;
|
|
19
|
+
/** a + b as decimal text at `exponent` places. Null when either cannot be held there. */
|
|
20
|
+
export declare function addAmounts(a: string, b: string, exponent: number): string | null;
|
|
21
|
+
/** a − b as decimal text at `exponent` places. Null when either cannot be held there or b > a. */
|
|
22
|
+
export declare function subtractAmounts(a: string, b: string, exponent: number): string | null;
|
|
23
|
+
/**
|
|
24
|
+
* ISO 4217's minor units. The demo provider's table, and a starting point a
|
|
25
|
+
* real provider OVERRIDES with its own exceptions; never the engine's
|
|
26
|
+
* authority on what a provider takes.
|
|
27
|
+
*/
|
|
28
|
+
export declare function isoExponent(currency: string): number | null;
|
|
29
|
+
//# sourceMappingURL=payment-money.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"payment-money.d.ts","sourceRoot":"","sources":["../src/payment-money.ts"],"names":[],"mappings":"AACA;;;;;;;;;GASG;AAEH,0FAA0F;AAC1F,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAW9E;AAED,gEAAgE;AAChE,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAO7E;AAED,4EAA4E;AAC5E,wBAAgB,UAAU,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO,CAUxD;AAED,iFAAiF;AACjF,wBAAgB,cAAc,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,IAAI,CAQtE;AAED,yFAAyF;AACzF,wBAAgB,UAAU,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAKhF;AAED,kGAAkG;AAClG,wBAAgB,eAAe,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAMrF;AAOD;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAK3D"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
// SPDX-License-Identifier: AGPL-3.0-only
|
|
2
|
+
/**
|
|
3
|
+
* Decimal text ↔ a provider's smallest unit, exactly.
|
|
4
|
+
*
|
|
5
|
+
* Money never passes through a float here. A provider half converts with its
|
|
6
|
+
* OWN exponent table (Stripe treats MGA as zero-decimal; PayPal sends HUF, JPY
|
|
7
|
+
* and TWD with no decimals), so these helpers take the exponent as an argument
|
|
8
|
+
* and the table is the provider's. An amount with more non-zero decimals than
|
|
9
|
+
* the exponent allows is refused (null), never rounded: rounding a customer's
|
|
10
|
+
* amount is taking a different amount.
|
|
11
|
+
*/
|
|
12
|
+
/** "120.50" at exponent 2 → "12050". "12000.00" at 0 → "12000". "45.2505" at 3 → null. */
|
|
13
|
+
export function decimalToMinor(amount, exponent) {
|
|
14
|
+
if (!Number.isInteger(exponent) || exponent < 0 || exponent > 6)
|
|
15
|
+
return null;
|
|
16
|
+
const match = /^(\d+)(?:\.(\d+))?$/.exec(amount);
|
|
17
|
+
if (match === null)
|
|
18
|
+
return null;
|
|
19
|
+
const whole = match[1] ?? '0';
|
|
20
|
+
const fraction = match[2] ?? '';
|
|
21
|
+
const kept = fraction.slice(0, exponent);
|
|
22
|
+
const rest = fraction.slice(exponent);
|
|
23
|
+
if (/[1-9]/.test(rest))
|
|
24
|
+
return null;
|
|
25
|
+
const digits = `${whole}${kept.padEnd(exponent, '0')}`.replace(/^0+(?=\d)/, '');
|
|
26
|
+
return digits === '' ? '0' : digits;
|
|
27
|
+
}
|
|
28
|
+
/** "12050" at exponent 2 → "120.50". "12000" at 0 → "12000". */
|
|
29
|
+
export function minorToDecimal(minor, exponent) {
|
|
30
|
+
if (!Number.isInteger(exponent) || exponent < 0 || exponent > 6)
|
|
31
|
+
return null;
|
|
32
|
+
if (!/^\d+$/.test(minor))
|
|
33
|
+
return null;
|
|
34
|
+
const digits = minor.replace(/^0+(?=\d)/, '');
|
|
35
|
+
if (exponent === 0)
|
|
36
|
+
return digits;
|
|
37
|
+
const padded = digits.padStart(exponent + 1, '0');
|
|
38
|
+
return `${padded.slice(0, -exponent)}.${padded.slice(-exponent)}`;
|
|
39
|
+
}
|
|
40
|
+
/** True when two decimal texts are the same number ("120" and "120.00"). */
|
|
41
|
+
export function sameAmount(a, b) {
|
|
42
|
+
const norm = (text) => {
|
|
43
|
+
const match = /^(\d+)(?:\.(\d+))?$/.exec(text);
|
|
44
|
+
if (match === null)
|
|
45
|
+
return null;
|
|
46
|
+
const whole = (match[1] ?? '0').replace(/^0+(?=\d)/, '');
|
|
47
|
+
const fraction = (match[2] ?? '').replace(/0+$/, '');
|
|
48
|
+
return fraction === '' ? whole : `${whole}.${fraction}`;
|
|
49
|
+
};
|
|
50
|
+
const left = norm(a);
|
|
51
|
+
return left !== null && left === norm(b);
|
|
52
|
+
}
|
|
53
|
+
/** Compares two decimal texts: -1, 0 or 1. Null when either is not a decimal. */
|
|
54
|
+
export function compareAmounts(a, b) {
|
|
55
|
+
const scale = 6;
|
|
56
|
+
const left = decimalToMinor(a, scale);
|
|
57
|
+
const right = decimalToMinor(b, scale);
|
|
58
|
+
if (left === null || right === null)
|
|
59
|
+
return null;
|
|
60
|
+
const x = BigInt(left);
|
|
61
|
+
const y = BigInt(right);
|
|
62
|
+
return x < y ? -1 : x > y ? 1 : 0;
|
|
63
|
+
}
|
|
64
|
+
/** a + b as decimal text at `exponent` places. Null when either cannot be held there. */
|
|
65
|
+
export function addAmounts(a, b, exponent) {
|
|
66
|
+
const left = decimalToMinor(a, exponent);
|
|
67
|
+
const right = decimalToMinor(b, exponent);
|
|
68
|
+
if (left === null || right === null)
|
|
69
|
+
return null;
|
|
70
|
+
return minorToDecimal((BigInt(left) + BigInt(right)).toString(), exponent);
|
|
71
|
+
}
|
|
72
|
+
/** a − b as decimal text at `exponent` places. Null when either cannot be held there or b > a. */
|
|
73
|
+
export function subtractAmounts(a, b, exponent) {
|
|
74
|
+
const left = decimalToMinor(a, exponent);
|
|
75
|
+
const right = decimalToMinor(b, exponent);
|
|
76
|
+
if (left === null || right === null)
|
|
77
|
+
return null;
|
|
78
|
+
const result = BigInt(left) - BigInt(right);
|
|
79
|
+
return result < 0n ? null : minorToDecimal(result.toString(), exponent);
|
|
80
|
+
}
|
|
81
|
+
const ZERO_DECIMAL = new Set([
|
|
82
|
+
'BIF', 'CLP', 'DJF', 'GNF', 'ISK', 'JPY', 'KMF', 'KRW', 'PYG', 'RWF', 'UGX', 'UYI', 'VND', 'VUV', 'XAF', 'XOF', 'XPF',
|
|
83
|
+
]);
|
|
84
|
+
const THREE_DECIMAL = new Set(['BHD', 'IQD', 'JOD', 'KWD', 'LYD', 'OMR', 'TND']);
|
|
85
|
+
/**
|
|
86
|
+
* ISO 4217's minor units. The demo provider's table, and a starting point a
|
|
87
|
+
* real provider OVERRIDES with its own exceptions; never the engine's
|
|
88
|
+
* authority on what a provider takes.
|
|
89
|
+
*/
|
|
90
|
+
export function isoExponent(currency) {
|
|
91
|
+
if (!/^[A-Z]{3}$/.test(currency))
|
|
92
|
+
return null;
|
|
93
|
+
if (ZERO_DECIMAL.has(currency))
|
|
94
|
+
return 0;
|
|
95
|
+
if (THREE_DECIMAL.has(currency))
|
|
96
|
+
return 3;
|
|
97
|
+
return 2;
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=payment-money.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"payment-money.js","sourceRoot":"","sources":["../src/payment-money.ts"],"names":[],"mappings":"AAAA,yCAAyC;AACzC;;;;;;;;;GASG;AAEH,0FAA0F;AAC1F,MAAM,UAAU,cAAc,CAAC,MAAc,EAAE,QAAgB;IAC7D,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,QAAQ,GAAG,CAAC,IAAI,QAAQ,GAAG,CAAC;QAAE,OAAO,IAAI,CAAC;IAC7E,MAAM,KAAK,GAAG,qBAAqB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACjD,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,IAAI,CAAC;IAChC,MAAM,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC;IAC9B,MAAM,QAAQ,GAAG,KAAK,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;IAChC,MAAM,IAAI,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC;IACzC,MAAM,IAAI,GAA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