@owlmeans/payment 0.1.18-rc.47 → 0.1.18-rc.49
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 +21 -21
- package/agent-meta/manifest.json +2 -2
- package/agent-meta/skills/entitlements/SKILL.md +7 -6
- package/agent-meta/skills/payment/SKILL.md +130 -118
- package/build/checkout/index.d.ts +1 -0
- package/build/checkout/index.d.ts.map +1 -1
- package/build/checkout/index.js.map +1 -1
- package/build/checkout/narrow/types.d.ts +25 -0
- package/build/checkout/narrow/types.d.ts.map +1 -0
- package/build/checkout/narrow/types.js +2 -0
- package/build/checkout/narrow/types.js.map +1 -0
- package/build/checkout/narrow.d.ts +4 -18
- package/build/checkout/narrow.d.ts.map +1 -1
- package/build/checkout/narrow.js +43 -54
- package/build/checkout/narrow.js.map +1 -1
- package/build/checkout/types.d.ts +2 -2
- package/build/checkout/types.d.ts.map +1 -1
- package/build/consts.d.ts +2 -0
- package/build/consts.d.ts.map +1 -1
- package/build/consts.js +2 -0
- package/build/consts.js.map +1 -1
- package/build/consumer/consts.local.d.ts +3 -0
- package/build/consumer/consts.local.d.ts.map +1 -1
- package/build/consumer/consts.local.js +9 -0
- package/build/consumer/consts.local.js.map +1 -1
- package/build/consumer/copy/types.d.ts +56 -0
- package/build/consumer/copy/types.d.ts.map +1 -0
- package/build/consumer/copy/types.js +2 -0
- package/build/consumer/copy/types.js.map +1 -0
- package/build/consumer/copy.d.ts +8 -40
- package/build/consumer/copy.d.ts.map +1 -1
- package/build/consumer/copy.js +75 -100
- package/build/consumer/copy.js.map +1 -1
- package/build/consumer/deadline/types.d.ts +30 -0
- package/build/consumer/deadline/types.d.ts.map +1 -0
- package/build/consumer/deadline/types.js +2 -0
- package/build/consumer/deadline/types.js.map +1 -0
- package/build/consumer/deadline.d.ts +6 -21
- package/build/consumer/deadline.d.ts.map +1 -1
- package/build/consumer/deadline.js +40 -51
- package/build/consumer/deadline.js.map +1 -1
- package/build/consumer/fifo/types.d.ts +17 -0
- package/build/consumer/fifo/types.d.ts.map +1 -0
- package/build/consumer/fifo/types.js +2 -0
- package/build/consumer/fifo/types.js.map +1 -0
- package/build/consumer/fifo.d.ts +3 -13
- package/build/consumer/fifo.d.ts.map +1 -1
- package/build/consumer/fifo.js +30 -30
- package/build/consumer/fifo.js.map +1 -1
- package/build/consumer/index.d.ts +6 -0
- package/build/consumer/index.d.ts.map +1 -1
- package/build/consumer/index.js.map +1 -1
- package/build/consumer/policy/types.d.ts +20 -0
- package/build/consumer/policy/types.d.ts.map +1 -0
- package/build/consumer/policy/types.js +2 -0
- package/build/consumer/policy/types.js.map +1 -0
- package/build/consumer/policy.d.ts +6 -12
- package/build/consumer/policy.d.ts.map +1 -1
- package/build/consumer/policy.js +63 -65
- package/build/consumer/policy.js.map +1 -1
- package/build/consumer/refund/types.d.ts +27 -0
- package/build/consumer/refund/types.d.ts.map +1 -0
- package/build/consumer/refund/types.js +2 -0
- package/build/consumer/refund/types.js.map +1 -0
- package/build/consumer/refund.d.ts +5 -20
- package/build/consumer/refund.d.ts.map +1 -1
- package/build/consumer/refund.js +85 -96
- package/build/consumer/refund.js.map +1 -1
- package/build/consumer/refusal.d.ts.map +1 -1
- package/build/consumer/refusal.js +2 -7
- package/build/consumer/refusal.js.map +1 -1
- package/build/consumer/revive/types.d.ts +19 -0
- package/build/consumer/revive/types.d.ts.map +1 -0
- package/build/consumer/revive/types.js +2 -0
- package/build/consumer/revive/types.js.map +1 -0
- package/build/consumer/revive.d.ts +8 -8
- package/build/consumer/revive.d.ts.map +1 -1
- package/build/consumer/revive.js +37 -23
- package/build/consumer/revive.js.map +1 -1
- package/build/consumer/types.d.ts +6 -6
- package/build/consumer/types.d.ts.map +1 -1
- package/build/consumer/types.local.d.ts +2 -1
- package/build/consumer/types.local.d.ts.map +1 -1
- package/build/countries.d.ts +0 -1
- package/build/countries.d.ts.map +1 -1
- package/build/countries.js +0 -1
- package/build/countries.js.map +1 -1
- package/build/entitled.d.ts +14 -0
- package/build/entitled.d.ts.map +1 -0
- package/build/entitled.js +17 -0
- package/build/entitled.js.map +1 -0
- package/build/entitlement/types.d.ts +29 -0
- package/build/entitlement/types.d.ts.map +1 -0
- package/build/entitlement/types.js +2 -0
- package/build/entitlement/types.js.map +1 -0
- package/build/entitlement.d.ts +6 -33
- package/build/entitlement.d.ts.map +1 -1
- package/build/entitlement.js +55 -79
- package/build/entitlement.js.map +1 -1
- package/build/estimate/types.d.ts +34 -0
- package/build/estimate/types.d.ts.map +1 -0
- package/build/estimate/types.js +2 -0
- package/build/estimate/types.js.map +1 -0
- package/build/estimate.d.ts +6 -26
- package/build/estimate.d.ts.map +1 -1
- package/build/estimate.js +61 -77
- package/build/estimate.js.map +1 -1
- package/build/i18n.js +25 -25
- package/build/i18n.js.map +1 -1
- package/build/index.d.ts +8 -0
- package/build/index.d.ts.map +1 -1
- package/build/index.js +1 -0
- package/build/index.js.map +1 -1
- package/build/limit/types.d.ts +44 -0
- package/build/limit/types.d.ts.map +1 -0
- package/build/limit/types.js +2 -0
- package/build/limit/types.js.map +1 -0
- package/build/limit.d.ts +10 -28
- package/build/limit.d.ts.map +1 -1
- package/build/limit.js +79 -89
- package/build/limit.js.map +1 -1
- package/build/pricing/types.d.ts +13 -0
- package/build/pricing/types.d.ts.map +1 -0
- package/build/pricing/types.js +2 -0
- package/build/pricing/types.js.map +1 -0
- package/build/pricing.d.ts +7 -1
- package/build/pricing.d.ts.map +1 -1
- package/build/pricing.js +70 -59
- package/build/pricing.js.map +1 -1
- package/build/promo/types.d.ts +14 -0
- package/build/promo/types.d.ts.map +1 -0
- package/build/promo/types.js +2 -0
- package/build/promo/types.js.map +1 -0
- package/build/promo.d.ts +5 -9
- package/build/promo.d.ts.map +1 -1
- package/build/promo.js +17 -18
- package/build/promo.js.map +1 -1
- package/build/regions/types.d.ts +32 -0
- package/build/regions/types.d.ts.map +1 -0
- package/build/regions/types.js +2 -0
- package/build/regions/types.js.map +1 -0
- package/build/regions.d.ts +7 -21
- package/build/regions.d.ts.map +1 -1
- package/build/regions.js +39 -46
- package/build/regions.js.map +1 -1
- package/build/service.d.ts.map +1 -1
- package/build/service.js +9 -9
- package/build/service.js.map +1 -1
- package/build/view/types.d.ts +33 -0
- package/build/view/types.d.ts.map +1 -0
- package/build/view/types.js +2 -0
- package/build/view/types.js.map +1 -0
- package/build/view.d.ts +7 -24
- package/build/view.d.ts.map +1 -1
- package/build/view.js +69 -81
- package/build/view.js.map +1 -1
- package/package.json +11 -11
- package/src/checkout/index.ts +1 -0
- package/src/checkout/narrow/types.ts +27 -0
- package/src/checkout/narrow.ts +53 -58
- package/src/checkout/types.ts +1 -1
- package/src/consts.ts +3 -0
- package/src/consumer/consts.local.ts +11 -0
- package/src/consumer/copy/types.ts +54 -0
- package/src/consumer/copy.ts +93 -106
- package/src/consumer/deadline/types.ts +30 -0
- package/src/consumer/deadline.ts +45 -48
- package/src/consumer/fifo/types.ts +17 -0
- package/src/consumer/fifo.ts +33 -37
- package/src/consumer/index.ts +6 -0
- package/src/consumer/policy/types.ts +20 -0
- package/src/consumer/policy.ts +57 -51
- package/src/consumer/refund/types.ts +27 -0
- package/src/consumer/refund.ts +97 -101
- package/src/consumer/refusal.ts +2 -8
- package/src/consumer/revive/types.ts +23 -0
- package/src/consumer/revive.ts +56 -32
- package/src/consumer/types.local.ts +1 -1
- package/src/consumer/types.ts +4 -3
- package/src/countries.ts +0 -3
- package/src/entitled.ts +20 -0
- package/src/entitlement/types.ts +29 -0
- package/src/entitlement.ts +66 -85
- package/src/estimate/types.ts +34 -0
- package/src/estimate.ts +69 -77
- package/src/i18n.ts +26 -25
- package/src/index.ts +8 -1
- package/src/limit/types.ts +41 -0
- package/src/limit.ts +102 -96
- package/src/pricing/types.ts +13 -0
- package/src/pricing.ts +94 -71
- package/src/promo/types.ts +18 -0
- package/src/promo.ts +31 -26
- package/src/regions/types.ts +42 -0
- package/src/regions.ts +59 -48
- package/src/service.ts +9 -11
- package/src/view/types.ts +39 -0
- package/src/view.ts +98 -97
- package/tests/checkout-narrow.spec.ts +19 -19
- package/tests/consumer-copy.spec.ts +90 -90
- package/tests/consumer-deadline.spec.ts +21 -22
- package/tests/consumer-fifo.spec.ts +12 -12
- package/tests/consumer-refund.spec.ts +27 -29
- package/tests/consumer-regions.spec.ts +39 -39
- package/tests/consumer-wire.spec.ts +12 -11
- package/tests/contract.spec.ts +3 -3
- package/tests/entitlement.spec.ts +25 -25
- package/tests/estimate.spec.ts +26 -26
- package/tests/limit.spec.ts +33 -36
- package/tests/pricing.spec.ts +10 -13
- package/tests/view.spec.ts +24 -24
package/build/limit.js
CHANGED
|
@@ -1,97 +1,87 @@
|
|
|
1
1
|
import { LimitKind, LimitWindow, CAPABILITY_LIMIT_SCOPE, LIFETIME_WINDOW, OCCUPANCY_WINDOW } from './consts.js';
|
|
2
|
-
import {
|
|
2
|
+
import { entitlementParamHelper } from './entitlement.js';
|
|
3
3
|
import { LimitMisdeclared } from './errors.js';
|
|
4
4
|
const pad = (value) => String(value).padStart(2, '0');
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
case LimitWindow.Month:
|
|
22
|
-
return month;
|
|
23
|
-
case LimitWindow.Day:
|
|
24
|
-
return `${month}-${pad(at.getUTCDate())}`;
|
|
5
|
+
export const createPlanLimitHelper = () => {
|
|
6
|
+
const windowKeyOf = (kind, window, at = new Date()) => {
|
|
7
|
+
switch (kind) {
|
|
8
|
+
case LimitKind.Lifetime:
|
|
9
|
+
return LIFETIME_WINDOW;
|
|
10
|
+
case LimitKind.Occupancy:
|
|
11
|
+
return OCCUPANCY_WINDOW;
|
|
12
|
+
case LimitKind.Window: {
|
|
13
|
+
const month = `${at.getUTCFullYear()}-${pad(at.getUTCMonth() + 1)}`;
|
|
14
|
+
switch (window) {
|
|
15
|
+
case LimitWindow.Month:
|
|
16
|
+
return month;
|
|
17
|
+
case LimitWindow.Day:
|
|
18
|
+
return `${month}-${pad(at.getUTCDate())}`;
|
|
19
|
+
}
|
|
20
|
+
throw new LimitMisdeclared(`window:${window ?? 'missing'}`);
|
|
25
21
|
}
|
|
26
|
-
throw new LimitMisdeclared(`window:${window ?? 'missing'}`);
|
|
27
22
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
return { start: new Date(Date.UTC(year, month, 1)), resetsAt: new Date(Date.UTC(year, month + 1, 1)) };
|
|
43
|
-
case LimitWindow.Day: {
|
|
44
|
-
const day = at.getUTCDate();
|
|
45
|
-
return {
|
|
46
|
-
start: new Date(Date.UTC(year, month, day)), resetsAt: new Date(Date.UTC(year, month, day + 1)),
|
|
47
|
-
};
|
|
23
|
+
throw new LimitMisdeclared(`kind:${kind}`);
|
|
24
|
+
};
|
|
25
|
+
const windowBoundsOf = (window, at = new Date()) => {
|
|
26
|
+
const year = at.getUTCFullYear();
|
|
27
|
+
const month = at.getUTCMonth();
|
|
28
|
+
switch (window) {
|
|
29
|
+
case LimitWindow.Month:
|
|
30
|
+
return { start: new Date(Date.UTC(year, month, 1)), resetsAt: new Date(Date.UTC(year, month + 1, 1)) };
|
|
31
|
+
case LimitWindow.Day: {
|
|
32
|
+
const day = at.getUTCDate();
|
|
33
|
+
return {
|
|
34
|
+
start: new Date(Date.UTC(year, month, day)), resetsAt: new Date(Date.UTC(year, month, day + 1)),
|
|
35
|
+
};
|
|
36
|
+
}
|
|
48
37
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
* capability and answers `false`.
|
|
83
|
-
*/
|
|
84
|
-
export const capabilityOf = (view, param) => {
|
|
85
|
-
if (view == null) {
|
|
86
|
-
return false;
|
|
87
|
-
}
|
|
88
|
-
// One set per row, so two grants of one permission are two chances — exactly as the declared
|
|
89
|
-
// sets they were built from.
|
|
90
|
-
const sets = view.capabilities
|
|
91
|
-
.filter(capability => capability.granted)
|
|
92
|
-
.map(capability => ({
|
|
93
|
-
scope: capability.scope, permissions: { [capability.permission]: capability.value },
|
|
94
|
-
}));
|
|
95
|
-
return hasEntitlement(sets, param);
|
|
38
|
+
throw new LimitMisdeclared(`window:${window}`);
|
|
39
|
+
};
|
|
40
|
+
const formatLimitParam = (key, atLeast) => entitlementParamHelper.formatEntitlementParam({ scope: CAPABILITY_LIMIT_SCOPE, permission: key, atLeast });
|
|
41
|
+
const parseLimitParam = (param) => {
|
|
42
|
+
if (typeof param !== 'string') {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
const parsed = entitlementParamHelper.parseEntitlementParam(param);
|
|
46
|
+
if (parsed.scope !== CAPABILITY_LIMIT_SCOPE || parsed.permission === '') {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
const atLeast = parsed.atLeast ?? 1;
|
|
50
|
+
if (!Number.isFinite(atLeast) || atLeast <= 0) {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
return { key: parsed.permission, atLeast };
|
|
54
|
+
};
|
|
55
|
+
const hasLimitRoom = (limit, atLeast = 1) => limit != null && limit.remaining >= atLeast;
|
|
56
|
+
const limitOf = (view, key) => view?.limits.find(limit => limit.key === key) ?? null;
|
|
57
|
+
const capabilityOf = (view, param) => {
|
|
58
|
+
if (view == null) {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
// One set per row, so two grants of one permission are two chances — exactly as the declared
|
|
62
|
+
// sets they were built from.
|
|
63
|
+
const sets = view.capabilities
|
|
64
|
+
.filter(capability => capability.granted)
|
|
65
|
+
.map(capability => ({
|
|
66
|
+
scope: capability.scope, permissions: { [capability.permission]: capability.value },
|
|
67
|
+
}));
|
|
68
|
+
return entitlementParamHelper.hasEntitlement(sets, param);
|
|
69
|
+
};
|
|
70
|
+
return { windowKeyOf, windowBoundsOf, formatLimitParam, parseLimitParam, hasLimitRoom, limitOf, capabilityOf };
|
|
96
71
|
};
|
|
72
|
+
export const planLimitHelper = createPlanLimitHelper();
|
|
73
|
+
/** @deprecated compat:factory-refactor — use `planLimitHelper.windowKeyOf(…)` */
|
|
74
|
+
export const windowKeyOf = (kind, window, at) => planLimitHelper.windowKeyOf(kind, window, at);
|
|
75
|
+
/** @deprecated compat:factory-refactor — use `planLimitHelper.windowBoundsOf(…)` */
|
|
76
|
+
export const windowBoundsOf = (window, at) => planLimitHelper.windowBoundsOf(window, at);
|
|
77
|
+
/** @deprecated compat:factory-refactor — use `planLimitHelper.formatLimitParam(…)` */
|
|
78
|
+
export const formatLimitParam = (key, atLeast) => planLimitHelper.formatLimitParam(key, atLeast);
|
|
79
|
+
/** @deprecated compat:factory-refactor — use `planLimitHelper.parseLimitParam(…)` */
|
|
80
|
+
export const parseLimitParam = (param) => planLimitHelper.parseLimitParam(param);
|
|
81
|
+
/** @deprecated compat:factory-refactor — use `planLimitHelper.hasLimitRoom(…)` */
|
|
82
|
+
export const hasLimitRoom = (limit, atLeast) => planLimitHelper.hasLimitRoom(limit, atLeast);
|
|
83
|
+
/** @deprecated compat:factory-refactor — use `planLimitHelper.limitOf(…)` */
|
|
84
|
+
export const limitOf = (view, key) => planLimitHelper.limitOf(view, key);
|
|
85
|
+
/** @deprecated compat:factory-refactor — use `planLimitHelper.capabilityOf(…)` */
|
|
86
|
+
export const capabilityOf = (view, param) => planLimitHelper.capabilityOf(view, param);
|
|
97
87
|
//# sourceMappingURL=limit.js.map
|
package/build/limit.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"limit.js","sourceRoot":"","sources":["../src/limit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,sBAAsB,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAC/G,OAAO,EAAE,sBAAsB,EAAE,
|
|
1
|
+
{"version":3,"file":"limit.js","sourceRoot":"","sources":["../src/limit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,sBAAsB,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAC/G,OAAO,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAA;AACzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAK9C,MAAM,GAAG,GAAG,CAAC,KAAa,EAAU,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAA;AAErE,MAAM,CAAC,MAAM,qBAAqB,GAAG,GAAoB,EAAE;IACzD,MAAM,WAAW,GAAG,CAClB,IAAe,EAAE,MAA2B,EAAE,EAAE,GAAS,IAAI,IAAI,EAAE,EAC3D,EAAE;QACV,QAAQ,IAAI,EAAE,CAAC;YACb,KAAK,SAAS,CAAC,QAAQ;gBACrB,OAAO,eAAe,CAAA;YACxB,KAAK,SAAS,CAAC,SAAS;gBACtB,OAAO,gBAAgB,CAAA;YACzB,KAAK,SAAS,CAAC,MAAM,EAAE,CAAC;gBACtB,MAAM,KAAK,GAAG,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,EAAU,EAAE,CACxE,eAAe,CAAC,gBAAgB,CAAC,GAAG,EAAE,OAAO,CAAC,CAAA;AAEhD,qFAAqF;AACrF,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,KAAa,EAAqB,EAAE,CAAC,eAAe,CAAC,eAAe,CAAC,KAAK,CAAC,CAAA;AAE3G,kFAAkF;AAClF,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,KAAmC,EAAE,OAAgB,EAAW,EAAE,CAC7F,eAAe,CAAC,YAAY,CAAC,KAAK,EAAE,OAAO,CAAC,CAAA;AAE9C,6EAA6E;AAC7E,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,IAAwC,EAAE,GAAW,EAAoB,EAAE,CACjG,eAAe,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAA;AAEpC,kFAAkF;AAClF,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,IAAwC,EAAE,KAAa,EAAW,EAAE,CAC/F,eAAe,CAAC,YAAY,CAAC,IAAI,EAAE,KAAK,CAAC,CAAA"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { AmountCheckoutPolicy, QuantityCheckoutPolicy } from '../types.js';
|
|
2
|
+
/** The checkout policies' invariants and the charge an amount grosses up to. */
|
|
3
|
+
export interface CheckoutPricingHelper {
|
|
4
|
+
/** @throws PaymentError (`checkout-policy:amount`, `checkout-policy:presets`) for an invalid policy. */
|
|
5
|
+
assertAmountCheckoutPolicy: (policy: AmountCheckoutPolicy) => AmountCheckoutPolicy;
|
|
6
|
+
/** @throws PaymentError (`checkout-policy:quantity`) for an invalid policy. */
|
|
7
|
+
assertQuantityCheckoutPolicy: (policy: QuantityCheckoutPolicy) => QuantityCheckoutPolicy;
|
|
8
|
+
/** @throws PaymentError (`checkout-amount:*`) for an amount the policy does not allow. */
|
|
9
|
+
assertCheckoutAmount: (policy: AmountCheckoutPolicy, amountMinor: number) => number;
|
|
10
|
+
/** Gross up a net credit value so the configured adjustment remains outside the credit grant. */
|
|
11
|
+
chargeAmountMinor: (amountMinor: number, policy: Pick<AmountCheckoutPolicy, 'fixedMinor' | 'rateBps'>) => number;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/pricing/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAA;AAE/E,gFAAgF;AAChF,MAAM,WAAW,qBAAqB;IACpC,wGAAwG;IACxG,0BAA0B,EAAE,CAAC,MAAM,EAAE,oBAAoB,KAAK,oBAAoB,CAAA;IAClF,+EAA+E;IAC/E,4BAA4B,EAAE,CAAC,MAAM,EAAE,sBAAsB,KAAK,sBAAsB,CAAA;IACxF,0FAA0F;IAC1F,oBAAoB,EAAE,CAAC,MAAM,EAAE,oBAAoB,EAAE,WAAW,EAAE,MAAM,KAAK,MAAM,CAAA;IACnF,iGAAiG;IACjG,iBAAiB,EAAE,CAAC,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,oBAAoB,EAAE,YAAY,GAAG,SAAS,CAAC,KAAK,MAAM,CAAA;CACjH"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/pricing/types.ts"],"names":[],"mappings":""}
|
package/build/pricing.d.ts
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import type { AmountCheckoutPolicy, QuantityCheckoutPolicy } from './types.js';
|
|
2
|
+
import type { CheckoutPricingHelper } from './pricing/types.js';
|
|
3
|
+
export declare const createCheckoutPricingHelper: () => CheckoutPricingHelper;
|
|
4
|
+
export declare const checkoutPricingHelper: CheckoutPricingHelper;
|
|
5
|
+
/** @deprecated compat:factory-refactor — use `checkoutPricingHelper.assertAmountCheckoutPolicy(…)` */
|
|
2
6
|
export declare const assertAmountCheckoutPolicy: (policy: AmountCheckoutPolicy) => AmountCheckoutPolicy;
|
|
7
|
+
/** @deprecated compat:factory-refactor — use `checkoutPricingHelper.assertQuantityCheckoutPolicy(…)` */
|
|
3
8
|
export declare const assertQuantityCheckoutPolicy: (policy: QuantityCheckoutPolicy) => QuantityCheckoutPolicy;
|
|
9
|
+
/** @deprecated compat:factory-refactor — use `checkoutPricingHelper.assertCheckoutAmount(…)` */
|
|
4
10
|
export declare const assertCheckoutAmount: (policy: AmountCheckoutPolicy, amountMinor: number) => number;
|
|
5
|
-
/**
|
|
11
|
+
/** @deprecated compat:factory-refactor — use `checkoutPricingHelper.chargeAmountMinor(…)` */
|
|
6
12
|
export declare const chargeAmountMinor: (amountMinor: number, policy: Pick<AmountCheckoutPolicy, 'fixedMinor' | 'rateBps'>) => number;
|
|
7
13
|
//# sourceMappingURL=pricing.d.ts.map
|
package/build/pricing.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pricing.d.ts","sourceRoot":"","sources":["../src/pricing.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,oBAAoB,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAA;
|
|
1
|
+
{"version":3,"file":"pricing.d.ts","sourceRoot":"","sources":["../src/pricing.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,oBAAoB,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAA;AAC9E,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAA;AAI/D,eAAO,MAAM,2BAA2B,QAAO,qBAoF9C,CAAA;AAED,eAAO,MAAM,qBAAqB,uBAAgC,CAAA;AAElE,sGAAsG;AACtG,eAAO,MAAM,0BAA0B,WAAY,oBAAoB,KAAG,oBAChB,CAAA;AAE1D,wGAAwG;AACxG,eAAO,MAAM,4BAA4B,WAAY,sBAAsB,KAAG,sBAClB,CAAA;AAE5D,gGAAgG;AAChG,eAAO,MAAM,oBAAoB,WAAY,oBAAoB,eAAe,MAAM,KAAG,MACxB,CAAA;AAEjE,6FAA6F;AAC7F,eAAO,MAAM,iBAAiB,gBACf,MAAM,UAAU,IAAI,CAAC,oBAAoB,EAAE,YAAY,GAAG,SAAS,CAAC,KAChF,MAAsE,CAAA"}
|
package/build/pricing.js
CHANGED
|
@@ -1,63 +1,74 @@
|
|
|
1
1
|
import { PaymentError } from './errors.js';
|
|
2
2
|
const integer = (value) => Number.isSafeInteger(value);
|
|
3
|
-
export const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
3
|
+
export const createCheckoutPricingHelper = () => {
|
|
4
|
+
const assertAmountCheckoutPolicy = (policy) => {
|
|
5
|
+
if (!integer(policy.minimumMinor)
|
|
6
|
+
|| !integer(policy.maximumMinor)
|
|
7
|
+
|| !integer(policy.defaultMinor)
|
|
8
|
+
|| !integer(policy.fixedMinor)
|
|
9
|
+
|| !integer(policy.rateBps)
|
|
10
|
+
|| policy.minimumMinor < 0
|
|
11
|
+
|| policy.minimumMinor > policy.defaultMinor
|
|
12
|
+
|| policy.defaultMinor > policy.maximumMinor
|
|
13
|
+
|| policy.fixedMinor < 0
|
|
14
|
+
|| policy.rateBps < 0
|
|
15
|
+
|| policy.rateBps >= 10_000
|
|
16
|
+
|| policy.currency.trim().length !== 3) {
|
|
17
|
+
throw new PaymentError('checkout-policy:amount');
|
|
18
|
+
}
|
|
19
|
+
const presets = new Set(policy.presetsMinor);
|
|
20
|
+
if (presets.size !== policy.presetsMinor.length
|
|
21
|
+
|| policy.presetsMinor.some(value => !integer(value) || value < policy.minimumMinor || value > policy.maximumMinor)) {
|
|
22
|
+
throw new PaymentError('checkout-policy:presets');
|
|
23
|
+
}
|
|
24
|
+
return policy;
|
|
25
|
+
};
|
|
26
|
+
const assertQuantityCheckoutPolicy = (policy) => {
|
|
27
|
+
if (!integer(policy.minimum)
|
|
28
|
+
|| !integer(policy.maximum)
|
|
29
|
+
|| !integer(policy.default)
|
|
30
|
+
|| policy.minimum < 1
|
|
31
|
+
|| policy.minimum > policy.default
|
|
32
|
+
|| policy.default > policy.maximum) {
|
|
33
|
+
throw new PaymentError('checkout-policy:quantity');
|
|
34
|
+
}
|
|
35
|
+
return policy;
|
|
36
|
+
};
|
|
37
|
+
const assertCheckoutAmount = (policy, amountMinor) => {
|
|
38
|
+
assertAmountCheckoutPolicy(policy);
|
|
39
|
+
if (!integer(amountMinor)) {
|
|
40
|
+
throw new PaymentError('checkout-amount:integer');
|
|
41
|
+
}
|
|
42
|
+
if (amountMinor < policy.minimumMinor) {
|
|
43
|
+
throw new PaymentError('checkout-amount:minimum');
|
|
44
|
+
}
|
|
45
|
+
if (amountMinor > policy.maximumMinor) {
|
|
46
|
+
throw new PaymentError('checkout-amount:maximum');
|
|
47
|
+
}
|
|
48
|
+
return amountMinor;
|
|
49
|
+
};
|
|
50
|
+
const chargeAmountMinor = (amountMinor, policy) => {
|
|
51
|
+
const adjusted = amountMinor + policy.fixedMinor;
|
|
52
|
+
const numerator = adjusted * 10_000;
|
|
53
|
+
if (!integer(amountMinor) || !integer(policy.fixedMinor) || !integer(policy.rateBps)
|
|
54
|
+
|| amountMinor < 0 || policy.fixedMinor < 0 || policy.rateBps < 0 || policy.rateBps >= 10_000
|
|
55
|
+
|| !integer(adjusted) || !integer(numerator)) {
|
|
56
|
+
throw new PaymentError('checkout-charge');
|
|
57
|
+
}
|
|
58
|
+
const charge = Math.ceil(numerator / (10_000 - policy.rateBps));
|
|
59
|
+
if (!integer(charge))
|
|
60
|
+
throw new PaymentError('checkout-charge');
|
|
61
|
+
return charge;
|
|
62
|
+
};
|
|
63
|
+
return { assertAmountCheckoutPolicy, assertQuantityCheckoutPolicy, assertCheckoutAmount, chargeAmountMinor };
|
|
62
64
|
};
|
|
65
|
+
export const checkoutPricingHelper = createCheckoutPricingHelper();
|
|
66
|
+
/** @deprecated compat:factory-refactor — use `checkoutPricingHelper.assertAmountCheckoutPolicy(…)` */
|
|
67
|
+
export const assertAmountCheckoutPolicy = (policy) => checkoutPricingHelper.assertAmountCheckoutPolicy(policy);
|
|
68
|
+
/** @deprecated compat:factory-refactor — use `checkoutPricingHelper.assertQuantityCheckoutPolicy(…)` */
|
|
69
|
+
export const assertQuantityCheckoutPolicy = (policy) => checkoutPricingHelper.assertQuantityCheckoutPolicy(policy);
|
|
70
|
+
/** @deprecated compat:factory-refactor — use `checkoutPricingHelper.assertCheckoutAmount(…)` */
|
|
71
|
+
export const assertCheckoutAmount = (policy, amountMinor) => checkoutPricingHelper.assertCheckoutAmount(policy, amountMinor);
|
|
72
|
+
/** @deprecated compat:factory-refactor — use `checkoutPricingHelper.chargeAmountMinor(…)` */
|
|
73
|
+
export const chargeAmountMinor = (amountMinor, policy) => checkoutPricingHelper.chargeAmountMinor(amountMinor, policy);
|
|
63
74
|
//# sourceMappingURL=pricing.js.map
|
package/build/pricing.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pricing.js","sourceRoot":"","sources":["../src/pricing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"pricing.js","sourceRoot":"","sources":["../src/pricing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAI1C,MAAM,OAAO,GAAG,CAAC,KAAa,EAAW,EAAE,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,CAAA;AAEvE,MAAM,CAAC,MAAM,2BAA2B,GAAG,GAA0B,EAAE;IACrE,MAAM,0BAA0B,GAAG,CACjC,MAA4B,EACN,EAAE;QACxB,IACE,CAAC,OAAO,CAAC,MAAM,CAAC,YAAY,CAAC;eAC1B,CAAC,OAAO,CAAC,MAAM,CAAC,YAAY,CAAC;eAC7B,CAAC,OAAO,CAAC,MAAM,CAAC,YAAY,CAAC;eAC7B,CAAC,OAAO,CAAC,MAAM,CAAC,UAAU,CAAC;eAC3B,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC;eACxB,MAAM,CAAC,YAAY,GAAG,CAAC;eACvB,MAAM,CAAC,YAAY,GAAG,MAAM,CAAC,YAAY;eACzC,MAAM,CAAC,YAAY,GAAG,MAAM,CAAC,YAAY;eACzC,MAAM,CAAC,UAAU,GAAG,CAAC;eACrB,MAAM,CAAC,OAAO,GAAG,CAAC;eAClB,MAAM,CAAC,OAAO,IAAI,MAAM;eACxB,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC,EACtC,CAAC;YACD,MAAM,IAAI,YAAY,CAAC,wBAAwB,CAAC,CAAA;QAClD,CAAC;QAED,MAAM,OAAO,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,YAAY,CAAC,CAAA;QAC5C,IACE,OAAO,CAAC,IAAI,KAAK,MAAM,CAAC,YAAY,CAAC,MAAM;eACxC,MAAM,CAAC,YAAY,CAAC,IAA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5D,gGAAgG;AAChG,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,MAA4B,EAAE,WAAmB,EAAU,EAAE,CAChG,qBAAqB,CAAC,oBAAoB,CAAC,MAAM,EAAE,WAAW,CAAC,CAAA;AAEjE,6FAA6F;AAC7F,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAC/B,WAAmB,EAAE,MAA4D,EACzE,EAAE,CAAC,qBAAqB,CAAC,iBAAiB,CAAC,WAAW,EAAE,MAAM,CAAC,CAAA"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { PromoDeclaration, PromoView } from '../types.js';
|
|
2
|
+
/** Whether a promo is in force, and how a UI inscribes it. */
|
|
3
|
+
export interface PromoHelper {
|
|
4
|
+
/**
|
|
5
|
+
* Whether a grant behind a promo is in force.
|
|
6
|
+
*
|
|
7
|
+
* No promo ⇒ always. Otherwise while `at < until`, or — with `grandfather` — for a subscription
|
|
8
|
+
* created before `until`. `at === until` is already over.
|
|
9
|
+
*/
|
|
10
|
+
promoActive: (promo: PromoDeclaration | null | undefined, subscribedAt: Date | null | undefined, at?: Date) => boolean;
|
|
11
|
+
/** What a UI needs to inscribe a promo: `undefined` when the grant has none. */
|
|
12
|
+
promoViewOf: (promo: PromoDeclaration | null | undefined, subscribedAt: Date | null | undefined, at?: Date) => PromoView | undefined;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/promo/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAE9D,8DAA8D;AAC9D,MAAM,WAAW,WAAW;IAC1B;;;;;OAKG;IACH,WAAW,EAAE,CACX,KAAK,EAAE,gBAAgB,GAAG,IAAI,GAAG,SAAS,EAAE,YAAY,EAAE,IAAI,GAAG,IAAI,GAAG,SAAS,EAAE,EAAE,CAAC,EAAE,IAAI,KACzF,OAAO,CAAA;IACZ,gFAAgF;IAChF,WAAW,EAAE,CACX,KAAK,EAAE,gBAAgB,GAAG,IAAI,GAAG,SAAS,EAAE,YAAY,EAAE,IAAI,GAAG,IAAI,GAAG,SAAS,EAAE,EAAE,CAAC,EAAE,IAAI,KACzF,SAAS,GAAG,SAAS,CAAA;CAC3B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/promo/types.ts"],"names":[],"mappings":""}
|
package/build/promo.d.ts
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
import type { PromoDeclaration
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
* created before `until`. `at === until` is already over.
|
|
7
|
-
*/
|
|
1
|
+
import type { PromoDeclaration } from './types.js';
|
|
2
|
+
import type { PromoHelper } from './promo/types.js';
|
|
3
|
+
export declare const createPromoHelper: () => PromoHelper;
|
|
4
|
+
export declare const promoHelper: PromoHelper;
|
|
5
|
+
/** @deprecated compat:factory-refactor — use `promoHelper.promoActive(…)` */
|
|
8
6
|
export declare const promoActive: (promo: PromoDeclaration | null | undefined, subscribedAt: Date | null | undefined, at?: Date) => boolean;
|
|
9
|
-
/** What a UI needs to inscribe a promo: `undefined` when the grant has none. */
|
|
10
|
-
export declare const promoViewOf: (promo: PromoDeclaration | null | undefined, subscribedAt: Date | null | undefined, at?: Date) => PromoView | undefined;
|
|
11
7
|
//# sourceMappingURL=promo.d.ts.map
|
package/build/promo.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"promo.d.ts","sourceRoot":"","sources":["../src/promo.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,
|
|
1
|
+
{"version":3,"file":"promo.d.ts","sourceRoot":"","sources":["../src/promo.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAa,MAAM,YAAY,CAAA;AAC7D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAUnD,eAAO,MAAM,iBAAiB,QAAO,WA2BpC,CAAA;AAED,eAAO,MAAM,WAAW,aAAsB,CAAA;AAE9C,6EAA6E;AAC7E,eAAO,MAAM,WAAW,UACf,gBAAgB,GAAG,IAAI,GAAG,SAAS,gBAAgB,IAAI,GAAG,IAAI,GAAG,SAAS,OAAO,IAAI,KAC3F,OAA2D,CAAA"}
|
package/build/promo.js
CHANGED
|
@@ -4,23 +4,22 @@
|
|
|
4
4
|
* promo is never in force.
|
|
5
5
|
*/
|
|
6
6
|
const timeOf = (value) => value == null ? Number.NaN : value instanceof Date ? value.getTime() : new Date(value).getTime();
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
export const promoViewOf = (promo, subscribedAt, at = new Date()) => promo == null ? undefined : {
|
|
22
|
-
until: new Date(timeOf(promo.until)),
|
|
23
|
-
grandfathered: grandfathers(promo, subscribedAt),
|
|
24
|
-
active: promoActive(promo, subscribedAt, at),
|
|
7
|
+
export const createPromoHelper = () => {
|
|
8
|
+
const grandfathers = (promo, subscribedAt) => promo.grandfather === true && timeOf(subscribedAt) < timeOf(promo.until);
|
|
9
|
+
const promoActive = (promo, subscribedAt, at = new Date()) => {
|
|
10
|
+
if (promo == null) {
|
|
11
|
+
return true;
|
|
12
|
+
}
|
|
13
|
+
return timeOf(at) < timeOf(promo.until) || grandfathers(promo, subscribedAt);
|
|
14
|
+
};
|
|
15
|
+
const promoViewOf = (promo, subscribedAt, at = new Date()) => promo == null ? undefined : {
|
|
16
|
+
until: new Date(timeOf(promo.until)),
|
|
17
|
+
grandfathered: grandfathers(promo, subscribedAt),
|
|
18
|
+
active: promoActive(promo, subscribedAt, at),
|
|
19
|
+
};
|
|
20
|
+
return { promoActive, promoViewOf };
|
|
25
21
|
};
|
|
22
|
+
export const promoHelper = createPromoHelper();
|
|
23
|
+
/** @deprecated compat:factory-refactor — use `promoHelper.promoActive(…)` */
|
|
24
|
+
export const promoActive = (promo, subscribedAt, at) => promoHelper.promoActive(promo, subscribedAt, at);
|
|
26
25
|
//# sourceMappingURL=promo.js.map
|
package/build/promo.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"promo.js","sourceRoot":"","sources":["../src/promo.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"promo.js","sourceRoot":"","sources":["../src/promo.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,MAAM,MAAM,GAAG,CAAC,KAAgD,EAAU,EAAE,CAC1E,KAAK,IAAI,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,YAAY,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC,OAAO,EAAE,CAAA;AAElG,MAAM,CAAC,MAAM,iBAAiB,GAAG,GAAgB,EAAE;IACjD,MAAM,YAAY,GAAG,CAAC,KAAuB,EAAE,YAAqC,EAAW,EAAE,CAC/F,KAAK,CAAC,WAAW,KAAK,IAAI,IAAI,MAAM,CAAC,YAAY,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;IAE1E,MAAM,WAAW,GAAG,CAClB,KAA0C,EAC1C,YAAqC,EACrC,EAAE,GAAS,IAAI,IAAI,EAAE,EACZ,EAAE;QACX,IAAI,KAAK,IAAI,IAAI,EAAE,CAAC;YAClB,OAAO,IAAI,CAAA;QACb,CAAC;QAED,OAAO,MAAM,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,YAAY,CAAC,KAAK,EAAE,YAAY,CAAC,CAAA;IAC9E,CAAC,CAAA;IAED,MAAM,WAAW,GAAG,CAClB,KAA0C,EAC1C,YAAqC,EACrC,EAAE,GAAS,IAAI,IAAI,EAAE,EACE,EAAE,CAAC,KAAK,IAAI,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC;QACtD,KAAK,EAAE,IAAI,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QACpC,aAAa,EAAE,YAAY,CAAC,KAAK,EAAE,YAAY,CAAC;QAChD,MAAM,EAAE,WAAW,CAAC,KAAK,EAAE,YAAY,EAAE,EAAE,CAAC;KAC7C,CAAA;IAED,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,CAAA;AACrC,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,WAAW,GAAG,iBAAiB,EAAE,CAAA;AAE9C,6EAA6E;AAC7E,MAAM,CAAC,MAAM,WAAW,GAAG,CACzB,KAA0C,EAAE,YAAqC,EAAE,EAAS,EACnF,EAAE,CAAC,WAAW,CAAC,WAAW,CAAC,KAAK,EAAE,YAAY,EAAE,EAAE,CAAC,CAAA"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { ConsumerRegion } from '../consts.js';
|
|
2
|
+
import type { ConsumerRightsPolicy } from '../types.js';
|
|
3
|
+
import type { RegionPolicy } from '../types.local.js';
|
|
4
|
+
/** The consumer region of a billing country and what it decides: scope, currency and legal language. */
|
|
5
|
+
export interface ConsumerRegionHelper {
|
|
6
|
+
/** A member state of the EU (not a territory with its own code). */
|
|
7
|
+
isEuCountry: (country: string | null | undefined) => boolean;
|
|
8
|
+
/** A member state of the EEA: the EU's 27 plus Iceland, Liechtenstein and Norway. */
|
|
9
|
+
isEeaCountry: (country: string | null | undefined) => boolean;
|
|
10
|
+
/**
|
|
11
|
+
* The consumer region of a billing country: `Eu` inside the policy's territories (the default
|
|
12
|
+
* ones without a policy), `Other` outside, `null` when the country is unknown.
|
|
13
|
+
*/
|
|
14
|
+
regionOf: (country: string | null | undefined, policy?: RegionPolicy) => ConsumerRegion | null;
|
|
15
|
+
/**
|
|
16
|
+
* Whether a buyer has the consumer rights: a known country decides by the policy's territories;
|
|
17
|
+
* without one, a known region decides; with neither, `unknownCountry: 'protect'` (the default) puts
|
|
18
|
+
* the buyer in scope — the safe side.
|
|
19
|
+
*/
|
|
20
|
+
inScope: (region: ConsumerRegion | null | undefined, country: string | null | undefined, policy?: Pick<ConsumerRightsPolicy, 'countries' | 'unknownCountry'> | null) => boolean;
|
|
21
|
+
/**
|
|
22
|
+
* The currency a region is charged in (lowercase ISO 4217): the policy's currency for the region,
|
|
23
|
+
* an unknown region reading as `Eu`; `fallback` when the policy names none.
|
|
24
|
+
*/
|
|
25
|
+
chargeCurrencyOf: (region: ConsumerRegion | null | undefined, policy: Pick<ConsumerRightsPolicy, 'currencies'> | null | undefined, fallback: string) => string;
|
|
26
|
+
/**
|
|
27
|
+
* The language of a billing country's legal copy: the policy's own map, then
|
|
28
|
+
* `COUNTRY_LANGUAGES`, then `fallback`, then the policy's default language, then `en`.
|
|
29
|
+
*/
|
|
30
|
+
billingLanguageOf: (country: string | null | undefined, policy?: Pick<ConsumerRightsPolicy, 'languages' | 'defaultLanguage'> | null, fallback?: string) => string;
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/regions/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAClD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAA;AACvD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAErD,wGAAwG;AACxG,MAAM,WAAW,oBAAoB;IACnC,oEAAoE;IACpE,WAAW,EAAE,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,KAAK,OAAO,CAAA;IAC5D,qFAAqF;IACrF,YAAY,EAAE,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,KAAK,OAAO,CAAA;IAC7D;;;OAGG;IACH,QAAQ,EAAE,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EAAE,MAAM,CAAC,EAAE,YAAY,KAAK,cAAc,GAAG,IAAI,CAAA;IAC9F;;;;OAIG;IACH,OAAO,EAAE,CACP,MAAM,EAAE,cAAc,GAAG,IAAI,GAAG,SAAS,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EAC7E,MAAM,CAAC,EAAE,IAAI,CAAC,oBAAoB,EAAE,WAAW,GAAG,gBAAgB,CAAC,GAAG,IAAI,KACvE,OAAO,CAAA;IACZ;;;OAGG;IACH,gBAAgB,EAAE,CAChB,MAAM,EAAE,cAAc,GAAG,IAAI,GAAG,SAAS,EAAE,MAAM,EAAE,IAAI,CAAC,oBAAoB,EAAE,YAAY,CAAC,GAAG,IAAI,GAAG,SAAS,EAC9G,QAAQ,EAAE,MAAM,KACb,MAAM,CAAA;IACX;;;OAGG;IACH,iBAAiB,EAAE,CACjB,OAAO,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EAClC,MAAM,CAAC,EAAE,IAAI,CAAC,oBAAoB,EAAE,WAAW,GAAG,iBAAiB,CAAC,GAAG,IAAI,EAC3E,QAAQ,CAAC,EAAE,MAAM,KACd,MAAM,CAAA;CACZ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/regions/types.ts"],"names":[],"mappings":""}
|
package/build/regions.d.ts
CHANGED
|
@@ -1,29 +1,15 @@
|
|
|
1
1
|
import { ConsumerRegion } from './consts.js';
|
|
2
2
|
import type { ConsumerRightsPolicy } from './types.js';
|
|
3
3
|
import type { RegionPolicy } from './types.local.js';
|
|
4
|
-
|
|
5
|
-
export declare const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* The consumer region of a billing country: `Eu` inside the policy's territories (the default
|
|
10
|
-
* ones without a policy), `Other` outside, `null` when the country is unknown.
|
|
11
|
-
*/
|
|
4
|
+
import type { ConsumerRegionHelper } from './regions/types.js';
|
|
5
|
+
export declare const createConsumerRegionHelper: () => ConsumerRegionHelper;
|
|
6
|
+
export declare const consumerRegionHelper: ConsumerRegionHelper;
|
|
7
|
+
/** @deprecated compat:factory-refactor — use `consumerRegionHelper.regionOf(…)` */
|
|
12
8
|
export declare const regionOf: (country: string | null | undefined, policy?: RegionPolicy) => ConsumerRegion | null;
|
|
13
|
-
/**
|
|
14
|
-
* Whether a buyer has the consumer rights: a known country decides by the policy's territories;
|
|
15
|
-
* without one, a known region decides; with neither, `unknownCountry: 'protect'` (the default) puts
|
|
16
|
-
* the buyer in scope — the safe side.
|
|
17
|
-
*/
|
|
9
|
+
/** @deprecated compat:factory-refactor — use `consumerRegionHelper.inScope(…)` */
|
|
18
10
|
export declare const inScope: (region: ConsumerRegion | null | undefined, country: string | null | undefined, policy?: Pick<ConsumerRightsPolicy, 'countries' | 'unknownCountry'> | null) => boolean;
|
|
19
|
-
/**
|
|
20
|
-
* The currency a region is charged in (lowercase ISO 4217): the policy's currency for the region,
|
|
21
|
-
* an unknown region reading as `Eu`; `fallback` when the policy names none.
|
|
22
|
-
*/
|
|
11
|
+
/** @deprecated compat:factory-refactor — use `consumerRegionHelper.chargeCurrencyOf(…)` */
|
|
23
12
|
export declare const chargeCurrencyOf: (region: ConsumerRegion | null | undefined, policy: Pick<ConsumerRightsPolicy, 'currencies'> | null | undefined, fallback: string) => string;
|
|
24
|
-
/**
|
|
25
|
-
* The language of a billing country's legal copy: the policy's own map, then
|
|
26
|
-
* `COUNTRY_LANGUAGES`, then `fallback`, then the policy's default language, then `en`.
|
|
27
|
-
*/
|
|
13
|
+
/** @deprecated compat:factory-refactor — use `consumerRegionHelper.billingLanguageOf(…)` */
|
|
28
14
|
export declare const billingLanguageOf: (country: string | null | undefined, policy?: Pick<ConsumerRightsPolicy, 'languages' | 'defaultLanguage'> | null, fallback?: string) => string;
|
|
29
15
|
//# sourceMappingURL=regions.d.ts.map
|