@classytic/primitives 0.18.0 → 0.20.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/CHANGELOG.md +906 -715
- package/README.md +160 -159
- package/dist/approval.d.mts +49 -10
- package/dist/approval.mjs +44 -10
- package/dist/bank-transaction.d.mts +1 -1
- package/dist/cadence-BFQVC1Qp.d.mts +107 -0
- package/dist/cadence.d.mts +1 -92
- package/dist/cadence.mjs +133 -4
- package/dist/calendar-B6fm-FbR.d.mts +46 -0
- package/dist/calendar.d.mts +1 -45
- package/dist/canonical.mjs +17 -0
- package/dist/context.d.mts +28 -1
- package/dist/currency.d.mts +2 -2
- package/dist/currency.mjs +134 -19
- package/dist/event-infra.d.mts +1 -34
- package/dist/event-infra.mjs +16 -46
- package/dist/idempotency.d.mts +253 -0
- package/dist/idempotency.mjs +226 -0
- package/dist/memory-outbox.d.mts +64 -0
- package/dist/memory-outbox.mjs +172 -0
- package/dist/monetization.d.mts +195 -0
- package/dist/monetization.mjs +79 -0
- package/dist/money-DPo9fLBi.d.mts +347 -0
- package/dist/money.d.mts +1 -140
- package/dist/money.mjs +6 -15
- package/dist/outbox.d.mts +49 -1
- package/dist/outbox.mjs +64 -1
- package/dist/payment-events.d.mts +132 -4
- package/dist/payment-events.mjs +22 -2
- package/dist/payment-gateway.d.mts +210 -7
- package/dist/payment-gateway.mjs +18 -1
- package/dist/period.d.mts +138 -7
- package/dist/period.mjs +316 -5
- package/dist/person-parse.d.mts +82 -0
- package/dist/person-parse.mjs +109 -0
- package/dist/proration.d.mts +76 -0
- package/dist/proration.mjs +132 -0
- package/dist/sla-policy.d.mts +1 -1
- package/dist/state-machine.mjs +13 -0
- package/dist/suspension.d.mts +1 -1
- package/dist/timezone-tlG7ygwx.d.mts +114 -0
- package/dist/timezone.d.mts +2 -100
- package/dist/timezone.mjs +38 -3
- package/dist/unit-cost-rate.d.mts +1 -2
- package/package.json +244 -224
- package/dist/currency-BCJnJBlb.d.mts +0 -119
package/package.json
CHANGED
|
@@ -1,224 +1,244 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@classytic/primitives",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Framework-agnostic TypeScript primitives shared across Classytic packages — Money, events, pagination, tenant config, and other building blocks.",
|
|
5
|
-
"author": "Classytic",
|
|
6
|
-
"license": "MIT",
|
|
7
|
-
"homepage": "https://www.npmjs.com/package/@classytic/primitives",
|
|
8
|
-
"bugs": {
|
|
9
|
-
"url": "https://github.com/classytic/primitives/issues"
|
|
10
|
-
},
|
|
11
|
-
"repository": {
|
|
12
|
-
"type": "git",
|
|
13
|
-
"url": "git+https://github.com/classytic/primitives.git"
|
|
14
|
-
},
|
|
15
|
-
"publishConfig": {
|
|
16
|
-
"access": "public"
|
|
17
|
-
},
|
|
18
|
-
"type": "module",
|
|
19
|
-
"sideEffects": false,
|
|
20
|
-
"engines": {
|
|
21
|
-
"node": ">=22"
|
|
22
|
-
},
|
|
23
|
-
"exports": {
|
|
24
|
-
"./money": {
|
|
25
|
-
"types": "./dist/money.d.mts",
|
|
26
|
-
"default": "./dist/money.mjs"
|
|
27
|
-
},
|
|
28
|
-
"./currency": {
|
|
29
|
-
"types": "./dist/currency.d.mts",
|
|
30
|
-
"default": "./dist/currency.mjs"
|
|
31
|
-
},
|
|
32
|
-
"./unit-cost-rate": {
|
|
33
|
-
"types": "./dist/unit-cost-rate.d.mts",
|
|
34
|
-
"default": "./dist/unit-cost-rate.mjs"
|
|
35
|
-
},
|
|
36
|
-
"./address": {
|
|
37
|
-
"types": "./dist/address.d.mts",
|
|
38
|
-
"default": "./dist/address.mjs"
|
|
39
|
-
},
|
|
40
|
-
"./period": {
|
|
41
|
-
"types": "./dist/period.d.mts",
|
|
42
|
-
"default": "./dist/period.mjs"
|
|
43
|
-
},
|
|
44
|
-
"./calendar": {
|
|
45
|
-
"types": "./dist/calendar.d.mts",
|
|
46
|
-
"default": "./dist/calendar.mjs"
|
|
47
|
-
},
|
|
48
|
-
"./timezone": {
|
|
49
|
-
"types": "./dist/timezone.d.mts",
|
|
50
|
-
"default": "./dist/timezone.mjs"
|
|
51
|
-
},
|
|
52
|
-
"./reference": {
|
|
53
|
-
"types": "./dist/reference.d.mts",
|
|
54
|
-
"default": "./dist/reference.mjs"
|
|
55
|
-
},
|
|
56
|
-
"./context": {
|
|
57
|
-
"types": "./dist/context.d.mts",
|
|
58
|
-
"default": "./dist/context.mjs"
|
|
59
|
-
},
|
|
60
|
-
"./events": {
|
|
61
|
-
"types": "./dist/events.d.mts",
|
|
62
|
-
"default": "./dist/events.mjs"
|
|
63
|
-
},
|
|
64
|
-
"./
|
|
65
|
-
"types": "./dist/
|
|
66
|
-
"default": "./dist/
|
|
67
|
-
},
|
|
68
|
-
"./
|
|
69
|
-
"types": "./dist/
|
|
70
|
-
"default": "./dist/
|
|
71
|
-
},
|
|
72
|
-
"./
|
|
73
|
-
"types": "./dist/
|
|
74
|
-
"default": "./dist/
|
|
75
|
-
},
|
|
76
|
-
"./
|
|
77
|
-
"types": "./dist/
|
|
78
|
-
"default": "./dist/
|
|
79
|
-
},
|
|
80
|
-
"./
|
|
81
|
-
"types": "./dist/
|
|
82
|
-
"default": "./dist/
|
|
83
|
-
},
|
|
84
|
-
"./
|
|
85
|
-
"types": "./dist/
|
|
86
|
-
"default": "./dist/
|
|
87
|
-
},
|
|
88
|
-
"./
|
|
89
|
-
"types": "./dist/
|
|
90
|
-
"default": "./dist/
|
|
91
|
-
},
|
|
92
|
-
"./
|
|
93
|
-
"types": "./dist/
|
|
94
|
-
"default": "./dist/
|
|
95
|
-
},
|
|
96
|
-
"./
|
|
97
|
-
"types": "./dist/
|
|
98
|
-
"default": "./dist/
|
|
99
|
-
},
|
|
100
|
-
"./
|
|
101
|
-
"types": "./dist/
|
|
102
|
-
"default": "./dist/
|
|
103
|
-
},
|
|
104
|
-
"./
|
|
105
|
-
"types": "./dist/
|
|
106
|
-
"default": "./dist/
|
|
107
|
-
},
|
|
108
|
-
"./
|
|
109
|
-
"types": "./dist/
|
|
110
|
-
"default": "./dist/
|
|
111
|
-
},
|
|
112
|
-
"./
|
|
113
|
-
"types": "./dist/
|
|
114
|
-
"default": "./dist/
|
|
115
|
-
},
|
|
116
|
-
"./
|
|
117
|
-
"types": "./dist/
|
|
118
|
-
"default": "./dist/
|
|
119
|
-
},
|
|
120
|
-
"./
|
|
121
|
-
"types": "./dist/
|
|
122
|
-
"default": "./dist/
|
|
123
|
-
},
|
|
124
|
-
"./
|
|
125
|
-
"types": "./dist/
|
|
126
|
-
"default": "./dist/
|
|
127
|
-
},
|
|
128
|
-
"./
|
|
129
|
-
"types": "./dist/
|
|
130
|
-
"default": "./dist/
|
|
131
|
-
},
|
|
132
|
-
"./
|
|
133
|
-
"types": "./dist/
|
|
134
|
-
"default": "./dist/
|
|
135
|
-
},
|
|
136
|
-
"./payment-
|
|
137
|
-
"types": "./dist/payment-
|
|
138
|
-
"default": "./dist/payment-
|
|
139
|
-
},
|
|
140
|
-
"./
|
|
141
|
-
"types": "./dist/
|
|
142
|
-
"default": "./dist/
|
|
143
|
-
},
|
|
144
|
-
"./status
|
|
145
|
-
"types": "./dist/status
|
|
146
|
-
"default": "./dist/status
|
|
147
|
-
},
|
|
148
|
-
"./
|
|
149
|
-
"types": "./dist/
|
|
150
|
-
"default": "./dist/
|
|
151
|
-
},
|
|
152
|
-
"./
|
|
153
|
-
"types": "./dist/
|
|
154
|
-
"default": "./dist/
|
|
155
|
-
},
|
|
156
|
-
"./
|
|
157
|
-
"types": "./dist/
|
|
158
|
-
"default": "./dist/
|
|
159
|
-
},
|
|
160
|
-
"./
|
|
161
|
-
"types": "./dist/
|
|
162
|
-
"default": "./dist/
|
|
163
|
-
},
|
|
164
|
-
"./
|
|
165
|
-
"types": "./dist/
|
|
166
|
-
"default": "./dist/
|
|
167
|
-
},
|
|
168
|
-
"./
|
|
169
|
-
|
|
170
|
-
"
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
"
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
"
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
"
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
"
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
"
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
"
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
"
|
|
206
|
-
"
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
"
|
|
210
|
-
"
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
"
|
|
214
|
-
"
|
|
215
|
-
"
|
|
216
|
-
"
|
|
217
|
-
"
|
|
218
|
-
"
|
|
219
|
-
"
|
|
220
|
-
"
|
|
221
|
-
"
|
|
222
|
-
"
|
|
223
|
-
|
|
224
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@classytic/primitives",
|
|
3
|
+
"version": "0.20.0",
|
|
4
|
+
"description": "Framework-agnostic TypeScript primitives shared across Classytic packages — Money, events, pagination, tenant config, and other building blocks.",
|
|
5
|
+
"author": "Classytic",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"homepage": "https://www.npmjs.com/package/@classytic/primitives",
|
|
8
|
+
"bugs": {
|
|
9
|
+
"url": "https://github.com/classytic/primitives/issues"
|
|
10
|
+
},
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/classytic/primitives.git"
|
|
14
|
+
},
|
|
15
|
+
"publishConfig": {
|
|
16
|
+
"access": "public"
|
|
17
|
+
},
|
|
18
|
+
"type": "module",
|
|
19
|
+
"sideEffects": false,
|
|
20
|
+
"engines": {
|
|
21
|
+
"node": ">=22"
|
|
22
|
+
},
|
|
23
|
+
"exports": {
|
|
24
|
+
"./money": {
|
|
25
|
+
"types": "./dist/money.d.mts",
|
|
26
|
+
"default": "./dist/money.mjs"
|
|
27
|
+
},
|
|
28
|
+
"./currency": {
|
|
29
|
+
"types": "./dist/currency.d.mts",
|
|
30
|
+
"default": "./dist/currency.mjs"
|
|
31
|
+
},
|
|
32
|
+
"./unit-cost-rate": {
|
|
33
|
+
"types": "./dist/unit-cost-rate.d.mts",
|
|
34
|
+
"default": "./dist/unit-cost-rate.mjs"
|
|
35
|
+
},
|
|
36
|
+
"./address": {
|
|
37
|
+
"types": "./dist/address.d.mts",
|
|
38
|
+
"default": "./dist/address.mjs"
|
|
39
|
+
},
|
|
40
|
+
"./period": {
|
|
41
|
+
"types": "./dist/period.d.mts",
|
|
42
|
+
"default": "./dist/period.mjs"
|
|
43
|
+
},
|
|
44
|
+
"./calendar": {
|
|
45
|
+
"types": "./dist/calendar.d.mts",
|
|
46
|
+
"default": "./dist/calendar.mjs"
|
|
47
|
+
},
|
|
48
|
+
"./timezone": {
|
|
49
|
+
"types": "./dist/timezone.d.mts",
|
|
50
|
+
"default": "./dist/timezone.mjs"
|
|
51
|
+
},
|
|
52
|
+
"./reference": {
|
|
53
|
+
"types": "./dist/reference.d.mts",
|
|
54
|
+
"default": "./dist/reference.mjs"
|
|
55
|
+
},
|
|
56
|
+
"./context": {
|
|
57
|
+
"types": "./dist/context.d.mts",
|
|
58
|
+
"default": "./dist/context.mjs"
|
|
59
|
+
},
|
|
60
|
+
"./events": {
|
|
61
|
+
"types": "./dist/events.d.mts",
|
|
62
|
+
"default": "./dist/events.mjs"
|
|
63
|
+
},
|
|
64
|
+
"./memory-outbox": {
|
|
65
|
+
"types": "./dist/memory-outbox.d.mts",
|
|
66
|
+
"default": "./dist/memory-outbox.mjs"
|
|
67
|
+
},
|
|
68
|
+
"./event-infra": {
|
|
69
|
+
"types": "./dist/event-infra.d.mts",
|
|
70
|
+
"default": "./dist/event-infra.mjs"
|
|
71
|
+
},
|
|
72
|
+
"./outbox": {
|
|
73
|
+
"types": "./dist/outbox.d.mts",
|
|
74
|
+
"default": "./dist/outbox.mjs"
|
|
75
|
+
},
|
|
76
|
+
"./result": {
|
|
77
|
+
"types": "./dist/result.d.mts",
|
|
78
|
+
"default": "./dist/result.mjs"
|
|
79
|
+
},
|
|
80
|
+
"./brand": {
|
|
81
|
+
"types": "./dist/brand.d.mts",
|
|
82
|
+
"default": "./dist/brand.mjs"
|
|
83
|
+
},
|
|
84
|
+
"./split-allocation": {
|
|
85
|
+
"types": "./dist/split-allocation.d.mts",
|
|
86
|
+
"default": "./dist/split-allocation.mjs"
|
|
87
|
+
},
|
|
88
|
+
"./approval": {
|
|
89
|
+
"types": "./dist/approval.d.mts",
|
|
90
|
+
"default": "./dist/approval.mjs"
|
|
91
|
+
},
|
|
92
|
+
"./idempotency": {
|
|
93
|
+
"types": "./dist/idempotency.d.mts",
|
|
94
|
+
"default": "./dist/idempotency.mjs"
|
|
95
|
+
},
|
|
96
|
+
"./cadence": {
|
|
97
|
+
"types": "./dist/cadence.d.mts",
|
|
98
|
+
"default": "./dist/cadence.mjs"
|
|
99
|
+
},
|
|
100
|
+
"./hold": {
|
|
101
|
+
"types": "./dist/hold.d.mts",
|
|
102
|
+
"default": "./dist/hold.mjs"
|
|
103
|
+
},
|
|
104
|
+
"./sla": {
|
|
105
|
+
"types": "./dist/sla.d.mts",
|
|
106
|
+
"default": "./dist/sla.mjs"
|
|
107
|
+
},
|
|
108
|
+
"./shelf-life": {
|
|
109
|
+
"types": "./dist/shelf-life.d.mts",
|
|
110
|
+
"default": "./dist/shelf-life.mjs"
|
|
111
|
+
},
|
|
112
|
+
"./person": {
|
|
113
|
+
"types": "./dist/person.d.mts",
|
|
114
|
+
"default": "./dist/person.mjs"
|
|
115
|
+
},
|
|
116
|
+
"./person-parse": {
|
|
117
|
+
"types": "./dist/person-parse.d.mts",
|
|
118
|
+
"default": "./dist/person-parse.mjs"
|
|
119
|
+
},
|
|
120
|
+
"./identity-verification": {
|
|
121
|
+
"types": "./dist/identity-verification.d.mts",
|
|
122
|
+
"default": "./dist/identity-verification.mjs"
|
|
123
|
+
},
|
|
124
|
+
"./otp": {
|
|
125
|
+
"types": "./dist/otp.d.mts",
|
|
126
|
+
"default": "./dist/otp.mjs"
|
|
127
|
+
},
|
|
128
|
+
"./state-machine": {
|
|
129
|
+
"types": "./dist/state-machine.d.mts",
|
|
130
|
+
"default": "./dist/state-machine.mjs"
|
|
131
|
+
},
|
|
132
|
+
"./bank-transaction": {
|
|
133
|
+
"types": "./dist/bank-transaction.d.mts",
|
|
134
|
+
"default": "./dist/bank-transaction.mjs"
|
|
135
|
+
},
|
|
136
|
+
"./payment-gateway": {
|
|
137
|
+
"types": "./dist/payment-gateway.d.mts",
|
|
138
|
+
"default": "./dist/payment-gateway.mjs"
|
|
139
|
+
},
|
|
140
|
+
"./payment-method-kind": {
|
|
141
|
+
"types": "./dist/payment-method-kind.d.mts",
|
|
142
|
+
"default": "./dist/payment-method-kind.mjs"
|
|
143
|
+
},
|
|
144
|
+
"./payment-allocation-status": {
|
|
145
|
+
"types": "./dist/payment-allocation-status.d.mts",
|
|
146
|
+
"default": "./dist/payment-allocation-status.mjs"
|
|
147
|
+
},
|
|
148
|
+
"./monetization": {
|
|
149
|
+
"types": "./dist/monetization.d.mts",
|
|
150
|
+
"default": "./dist/monetization.mjs"
|
|
151
|
+
},
|
|
152
|
+
"./proration": {
|
|
153
|
+
"types": "./dist/proration.d.mts",
|
|
154
|
+
"default": "./dist/proration.mjs"
|
|
155
|
+
},
|
|
156
|
+
"./payment-events": {
|
|
157
|
+
"types": "./dist/payment-events.d.mts",
|
|
158
|
+
"default": "./dist/payment-events.mjs"
|
|
159
|
+
},
|
|
160
|
+
"./phone": {
|
|
161
|
+
"types": "./dist/phone.d.mts",
|
|
162
|
+
"default": "./dist/phone.mjs"
|
|
163
|
+
},
|
|
164
|
+
"./status-history": {
|
|
165
|
+
"types": "./dist/status-history.d.mts",
|
|
166
|
+
"default": "./dist/status-history.mjs"
|
|
167
|
+
},
|
|
168
|
+
"./condition": {
|
|
169
|
+
"types": "./dist/condition.d.mts",
|
|
170
|
+
"default": "./dist/condition.mjs"
|
|
171
|
+
},
|
|
172
|
+
"./mixin": {
|
|
173
|
+
"types": "./dist/mixin.d.mts",
|
|
174
|
+
"default": "./dist/mixin.mjs"
|
|
175
|
+
},
|
|
176
|
+
"./sla-policy": {
|
|
177
|
+
"types": "./dist/sla-policy.d.mts",
|
|
178
|
+
"default": "./dist/sla-policy.mjs"
|
|
179
|
+
},
|
|
180
|
+
"./retention": {
|
|
181
|
+
"types": "./dist/retention.d.mts",
|
|
182
|
+
"default": "./dist/retention.mjs"
|
|
183
|
+
},
|
|
184
|
+
"./canonical": {
|
|
185
|
+
"types": "./dist/canonical.d.mts",
|
|
186
|
+
"default": "./dist/canonical.mjs"
|
|
187
|
+
},
|
|
188
|
+
"./package.json": "./package.json",
|
|
189
|
+
"./state-diagram": {
|
|
190
|
+
"types": "./dist/state-diagram.d.mts",
|
|
191
|
+
"default": "./dist/state-diagram.mjs"
|
|
192
|
+
},
|
|
193
|
+
"./suspension": {
|
|
194
|
+
"types": "./dist/suspension.d.mts",
|
|
195
|
+
"default": "./dist/suspension.mjs"
|
|
196
|
+
},
|
|
197
|
+
"./subject": {
|
|
198
|
+
"types": "./dist/subject.d.mts",
|
|
199
|
+
"default": "./dist/subject.mjs"
|
|
200
|
+
}
|
|
201
|
+
},
|
|
202
|
+
"files": [
|
|
203
|
+
"dist",
|
|
204
|
+
"README.md",
|
|
205
|
+
"CHANGELOG.md",
|
|
206
|
+
"LICENSE"
|
|
207
|
+
],
|
|
208
|
+
"scripts": {
|
|
209
|
+
"build": "tsdown",
|
|
210
|
+
"dev": "tsdown --watch",
|
|
211
|
+
"typecheck": "tsc --noEmit",
|
|
212
|
+
"lint": "biome check src/ tests/",
|
|
213
|
+
"lint:fix": "biome check --write src/ tests/",
|
|
214
|
+
"test": "vitest run --project unit --project integration",
|
|
215
|
+
"test:unit": "vitest run --project unit",
|
|
216
|
+
"test:integration": "vitest run --project integration",
|
|
217
|
+
"test:all": "vitest run",
|
|
218
|
+
"test:watch": "vitest --project unit --project integration",
|
|
219
|
+
"test:smoke": "node tests/smoke/smoke.mjs",
|
|
220
|
+
"push": "classytic-push",
|
|
221
|
+
"prepublishOnly": "npm run typecheck && npm run test && npm run build && npm run test:smoke",
|
|
222
|
+
"release": "npm run build && npm run typecheck && npm publish --access public"
|
|
223
|
+
},
|
|
224
|
+
"devDependencies": {
|
|
225
|
+
"@biomejs/biome": "^2.4.9",
|
|
226
|
+
"@classytic/dev-tools": "^0.2.0",
|
|
227
|
+
"@types/node": "^25.5.0",
|
|
228
|
+
"tsdown": "^0.21.7",
|
|
229
|
+
"typescript": "^5.7.0",
|
|
230
|
+
"vitest": "^3.0.0"
|
|
231
|
+
},
|
|
232
|
+
"keywords": [
|
|
233
|
+
"typescript",
|
|
234
|
+
"types",
|
|
235
|
+
"primitives",
|
|
236
|
+
"money",
|
|
237
|
+
"currency",
|
|
238
|
+
"pagination",
|
|
239
|
+
"domain-event",
|
|
240
|
+
"tenant",
|
|
241
|
+
"classytic",
|
|
242
|
+
"commerce"
|
|
243
|
+
]
|
|
244
|
+
}
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
import { t as Brand } from "./brand-LLXqoh5J.mjs";
|
|
2
|
-
|
|
3
|
-
//#region src/money/currency.d.ts
|
|
4
|
-
/**
|
|
5
|
-
* ISO 4217 currency code (3 uppercase letters).
|
|
6
|
-
*
|
|
7
|
-
* Branded `string` — any 3-letter string is structurally valid, but the brand
|
|
8
|
-
* prevents accidental mixing with raw strings. Use {@link toCurrencyCode} to
|
|
9
|
-
* construct one safely.
|
|
10
|
-
*/
|
|
11
|
-
type CurrencyCode = Brand<string, 'CurrencyCode'>;
|
|
12
|
-
/**
|
|
13
|
-
* Common ISO 4217 codes. Non-exhaustive — add more at the consumer level if
|
|
14
|
-
* needed. Listed here because shared-types ships with these by default.
|
|
15
|
-
*/
|
|
16
|
-
declare const CURRENCIES: {
|
|
17
|
-
readonly USD: "USD";
|
|
18
|
-
readonly EUR: "EUR";
|
|
19
|
-
readonly GBP: "GBP";
|
|
20
|
-
readonly JPY: "JPY";
|
|
21
|
-
readonly CNY: "CNY";
|
|
22
|
-
readonly INR: "INR";
|
|
23
|
-
readonly BDT: "BDT";
|
|
24
|
-
readonly AED: "AED";
|
|
25
|
-
readonly SAR: "SAR";
|
|
26
|
-
readonly PKR: "PKR";
|
|
27
|
-
readonly NPR: "NPR";
|
|
28
|
-
readonly LKR: "LKR";
|
|
29
|
-
readonly MYR: "MYR";
|
|
30
|
-
readonly SGD: "SGD";
|
|
31
|
-
readonly AUD: "AUD";
|
|
32
|
-
readonly CAD: "CAD";
|
|
33
|
-
readonly CHF: "CHF";
|
|
34
|
-
readonly HKD: "HKD";
|
|
35
|
-
readonly THB: "THB";
|
|
36
|
-
readonly IDR: "IDR";
|
|
37
|
-
};
|
|
38
|
-
/**
|
|
39
|
-
* Number of minor units per major unit for common currencies.
|
|
40
|
-
*
|
|
41
|
-
* ISO 4217 defines most currencies with 2 decimal places (cents). A few are
|
|
42
|
-
* zero-decimal (JPY, KRW) or three-decimal (BHD, KWD, JOD). When a currency
|
|
43
|
-
* isn't in this table, {@link minorUnitFactor} returns 100 as the safe default.
|
|
44
|
-
*/
|
|
45
|
-
declare const MINOR_UNIT_FACTOR: Readonly<Record<string, number>>;
|
|
46
|
-
/**
|
|
47
|
-
* ISO 4217 format — 3 uppercase letters. Exported so consumers can embed
|
|
48
|
-
* the SAME pattern in JSON-Schema-representable validators (zod `.regex`,
|
|
49
|
-
* Mongoose `match`, OpenAPI `pattern`) instead of hand-rolling a copy:
|
|
50
|
-
* `.refine(isCurrencyCode)` validates at runtime but is dropped by
|
|
51
|
-
* `z.toJSONSchema`, losing the constraint from generated API docs.
|
|
52
|
-
* `isCurrencyCode` / `toCurrencyCode` remain the runtime API.
|
|
53
|
-
*/
|
|
54
|
-
declare const CURRENCY_PATTERN: RegExp;
|
|
55
|
-
/**
|
|
56
|
-
* Narrow a raw string to a {@link CurrencyCode}. Returns `null` if the string
|
|
57
|
-
* is not a valid ISO 4217 format (3 uppercase letters). This does not verify
|
|
58
|
-
* the code is registered with ISO — use your own whitelist for that.
|
|
59
|
-
*/
|
|
60
|
-
declare function toCurrencyCode(value: string): CurrencyCode | null;
|
|
61
|
-
/** Type predicate for `unknown` input. */
|
|
62
|
-
declare function isCurrencyCode(value: unknown): value is CurrencyCode;
|
|
63
|
-
/**
|
|
64
|
-
* Minor units per major unit (e.g. 100 for USD, 1 for JPY, 1000 for KWD).
|
|
65
|
-
* Falls back to 100 when the currency is unknown — matches the ISO 4217 default.
|
|
66
|
-
*/
|
|
67
|
-
declare function minorUnitFactor(currency: string): number;
|
|
68
|
-
/**
|
|
69
|
-
* Frozen FX conversion record — the cost of record for cross-currency
|
|
70
|
-
* transactions. Stored alongside a base-currency amount at the seam where
|
|
71
|
-
* currency crossed (procurement receipt, landed-cost entry, foreign refund).
|
|
72
|
-
*
|
|
73
|
-
* Invariant: once written, never mutated. Revaluation is a new snapshot on
|
|
74
|
-
* a new document — rewriting an existing snapshot corrupts audit history.
|
|
75
|
-
*
|
|
76
|
-
* `rate` is expressed as: 1 sourceCurrency = rate * baseCurrency
|
|
77
|
-
* (e.g. USD→BDT at 110 means rate = 110, so sourceAmount 10 USD → baseAmount 1100 BDT).
|
|
78
|
-
* This matches how banks quote — the source is the "from" currency.
|
|
79
|
-
*/
|
|
80
|
-
interface FxSnapshot {
|
|
81
|
-
/** Currency the transaction was invoiced / quoted in. ISO 4217. */
|
|
82
|
-
sourceCurrency: string;
|
|
83
|
-
/** Organisation's functional currency the base amount is expressed in. */
|
|
84
|
-
baseCurrency: string;
|
|
85
|
-
/** 1 unit of sourceCurrency equals this many units of baseCurrency. */
|
|
86
|
-
rate: number;
|
|
87
|
-
/** When the rate was captured — NOT when the document was last touched. */
|
|
88
|
-
snapshotAt: Date;
|
|
89
|
-
/**
|
|
90
|
-
* Optional provenance tag — e.g. 'manual', 'bangladesh-bank',
|
|
91
|
-
* 'openexchangerates.org', 'supplier-invoice'. Free-form; hosts use it for
|
|
92
|
-
* audit filtering and re-pricing policy.
|
|
93
|
-
*/
|
|
94
|
-
source?: string;
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* Apply an {@link FxSnapshot} to a source-currency amount. Returns the
|
|
98
|
-
* equivalent base-currency amount. No rounding — callers that persist into
|
|
99
|
-
* an integer minor-unit column must round explicitly with a deterministic
|
|
100
|
-
* rule (`Math.round`, banker's rounding, floor for duty-conservative
|
|
101
|
-
* postings, etc.).
|
|
102
|
-
*/
|
|
103
|
-
declare function convertWithSnapshot(sourceAmount: number, fx: FxSnapshot): number;
|
|
104
|
-
/**
|
|
105
|
-
* Reverse an {@link FxSnapshot} — reconstruct the source-currency amount
|
|
106
|
-
* from a stored base amount. Useful for reporting "cost in original
|
|
107
|
-
* currency". Not round-trip safe under rounding; prefer storing the
|
|
108
|
-
* original source amount alongside the base amount when audit fidelity
|
|
109
|
-
* matters.
|
|
110
|
-
*/
|
|
111
|
-
declare function reverseWithSnapshot(baseAmount: number, fx: FxSnapshot): number;
|
|
112
|
-
/**
|
|
113
|
-
* Structural validation — checks shape only. Does NOT verify the rate is
|
|
114
|
-
* economically sensible (8.5 USD→BDT would pass this check). Host-level
|
|
115
|
-
* guards / anomaly detection handle that.
|
|
116
|
-
*/
|
|
117
|
-
declare function isFxSnapshot(value: unknown): value is FxSnapshot;
|
|
118
|
-
//#endregion
|
|
119
|
-
export { MINOR_UNIT_FACTOR as a, isFxSnapshot as c, toCurrencyCode as d, FxSnapshot as i, minorUnitFactor as l, CURRENCY_PATTERN as n, convertWithSnapshot as o, CurrencyCode as r, isCurrencyCode as s, CURRENCIES as t, reverseWithSnapshot as u };
|