@coderoftime/fints 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +377 -0
- package/README.md +31 -23
- package/dist/client.d.ts +3 -2
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +52 -9
- package/dist/client.js.map +1 -1
- package/dist/core/account.d.ts +15 -4
- package/dist/core/account.d.ts.map +1 -1
- package/dist/core/account.js +84 -36
- package/dist/core/account.js.map +1 -1
- package/dist/core/amount.d.ts +13 -3
- package/dist/core/amount.d.ts.map +1 -1
- package/dist/core/amount.js +42 -8
- package/dist/core/amount.js.map +1 -1
- package/dist/core/balance.d.ts +3 -0
- package/dist/core/balance.d.ts.map +1 -1
- package/dist/core/balance.js +5 -0
- package/dist/core/balance.js.map +1 -1
- package/dist/core/bank-info.d.ts +20 -3
- package/dist/core/bank-info.d.ts.map +1 -1
- package/dist/core/bank-info.js +25 -4
- package/dist/core/bank-info.js.map +1 -1
- package/dist/core/client.d.ts +42 -15
- package/dist/core/client.d.ts.map +1 -1
- package/dist/core/config.d.ts +15 -7
- package/dist/core/config.d.ts.map +1 -1
- package/dist/core/config.js +29 -14
- package/dist/core/config.js.map +1 -1
- package/dist/core/errors.d.ts +17 -5
- package/dist/core/errors.d.ts.map +1 -1
- package/dist/core/errors.js +25 -7
- package/dist/core/errors.js.map +1 -1
- package/dist/core/feedback.d.ts +7 -0
- package/dist/core/feedback.d.ts.map +1 -1
- package/dist/core/feedback.js +10 -1
- package/dist/core/feedback.js.map +1 -1
- package/dist/core/transaction.d.ts +5 -0
- package/dist/core/transaction.d.ts.map +1 -1
- package/dist/core/transaction.js +12 -0
- package/dist/core/transaction.js.map +1 -1
- package/dist/core/transport.d.ts +22 -7
- package/dist/core/transport.d.ts.map +1 -1
- package/dist/core/transport.js +51 -11
- package/dist/core/transport.js.map +1 -1
- package/dist/formats/camt.d.ts +7 -4
- package/dist/formats/camt.d.ts.map +1 -1
- package/dist/formats/camt.js +53 -54
- package/dist/formats/camt.js.map +1 -1
- package/dist/formats/mt940.d.ts +18 -6
- package/dist/formats/mt940.d.ts.map +1 -1
- package/dist/formats/mt940.js +83 -66
- package/dist/formats/mt940.js.map +1 -1
- package/dist/formats/readers.d.ts.map +1 -1
- package/dist/formats/readers.js +6 -2
- package/dist/formats/readers.js.map +1 -1
- package/dist/formats/sepa-purpose.d.ts +7 -4
- package/dist/formats/sepa-purpose.d.ts.map +1 -1
- package/dist/formats/sepa-purpose.js +18 -9
- package/dist/formats/sepa-purpose.js.map +1 -1
- package/dist/session/dialog-runner.d.ts +5 -2
- package/dist/session/dialog-runner.d.ts.map +1 -1
- package/dist/session/dialog-runner.js +23 -7
- package/dist/session/dialog-runner.js.map +1 -1
- package/dist/session/login-guard.d.ts +4 -4
- package/dist/session/login-guard.d.ts.map +1 -1
- package/dist/session/login-guard.js +29 -14
- package/dist/session/login-guard.js.map +1 -1
- package/dist/session/session-setup.d.ts +14 -5
- package/dist/session/session-setup.d.ts.map +1 -1
- package/dist/session/session-setup.js +30 -9
- package/dist/session/session-setup.js.map +1 -1
- package/dist/session/session-state.d.ts +4 -3
- package/dist/session/session-state.d.ts.map +1 -1
- package/dist/session/session-state.js +28 -9
- package/dist/session/session-state.js.map +1 -1
- package/dist/session/signed-dialog.d.ts +19 -13
- package/dist/session/signed-dialog.d.ts.map +1 -1
- package/dist/session/signed-dialog.js +45 -30
- package/dist/session/signed-dialog.js.map +1 -1
- package/dist/session/user-prompts.d.ts +6 -1
- package/dist/session/user-prompts.d.ts.map +1 -1
- package/dist/session/user-prompts.js +19 -4
- package/dist/session/user-prompts.js.map +1 -1
- package/dist/tan/challenge.d.ts +15 -13
- package/dist/tan/challenge.d.ts.map +1 -1
- package/dist/tan/challenge.js +32 -26
- package/dist/tan/challenge.js.map +1 -1
- package/dist/tan/flicker.d.ts +5 -1
- package/dist/tan/flicker.d.ts.map +1 -1
- package/dist/tan/flicker.js +42 -30
- package/dist/tan/flicker.js.map +1 -1
- package/dist/tan/tan-image.d.ts +4 -1
- package/dist/tan/tan-image.d.ts.map +1 -1
- package/dist/tan/tan-image.js +8 -2
- package/dist/tan/tan-image.js.map +1 -1
- package/dist/tan/tan-models.d.ts +9 -1
- package/dist/tan/tan-models.d.ts.map +1 -1
- package/dist/tan/tan-models.js +14 -2
- package/dist/tan/tan-models.js.map +1 -1
- package/dist/util/arguments.d.ts +13 -0
- package/dist/util/arguments.d.ts.map +1 -0
- package/dist/util/arguments.js +40 -0
- package/dist/util/arguments.js.map +1 -0
- package/dist/util/async.d.ts +4 -1
- package/dist/util/async.d.ts.map +1 -1
- package/dist/util/async.js +6 -3
- package/dist/util/async.js.map +1 -1
- package/dist/util/bytes.d.ts +1 -1
- package/dist/util/bytes.d.ts.map +1 -1
- package/dist/util/bytes.js +3 -3
- package/dist/util/bytes.js.map +1 -1
- package/dist/util/dates.d.ts +3 -10
- package/dist/util/dates.d.ts.map +1 -1
- package/dist/util/dates.js +49 -39
- package/dist/util/dates.js.map +1 -1
- package/dist/util/errors.d.ts +5 -3
- package/dist/util/errors.d.ts.map +1 -1
- package/dist/util/errors.js +8 -4
- package/dist/util/errors.js.map +1 -1
- package/dist/util/immutable-map.d.ts +5 -2
- package/dist/util/immutable-map.d.ts.map +1 -1
- package/dist/util/immutable-map.js +15 -12
- package/dist/util/immutable-map.js.map +1 -1
- package/dist/util/inspect.d.ts +11 -0
- package/dist/util/inspect.d.ts.map +1 -0
- package/dist/util/inspect.js +14 -0
- package/dist/util/inspect.js.map +1 -0
- package/dist/util/text.d.ts +18 -2
- package/dist/util/text.d.ts.map +1 -1
- package/dist/util/text.js +50 -5
- package/dist/util/text.js.map +1 -1
- package/dist/util/xml.d.ts +6 -4
- package/dist/util/xml.d.ts.map +1 -1
- package/dist/util/xml.js +106 -44
- package/dist/util/xml.js.map +1 -1
- package/dist/v3/bank-connection.d.ts +23 -3
- package/dist/v3/bank-connection.d.ts.map +1 -1
- package/dist/v3/bank-connection.js +66 -6
- package/dist/v3/bank-connection.js.map +1 -1
- package/dist/v3/dialog.d.ts +6 -2
- package/dist/v3/dialog.d.ts.map +1 -1
- package/dist/v3/dialog.js +20 -9
- package/dist/v3/dialog.js.map +1 -1
- package/dist/v3/message.d.ts +18 -10
- package/dist/v3/message.d.ts.map +1 -1
- package/dist/v3/message.js +92 -75
- package/dist/v3/message.js.map +1 -1
- package/dist/v3/parameter-store.d.ts +43 -7
- package/dist/v3/parameter-store.d.ts.map +1 -1
- package/dist/v3/parameter-store.js +69 -15
- package/dist/v3/parameter-store.js.map +1 -1
- package/dist/v3/parameters.d.ts +12 -11
- package/dist/v3/parameters.d.ts.map +1 -1
- package/dist/v3/parameters.js +57 -35
- package/dist/v3/parameters.js.map +1 -1
- package/dist/v3/protocol.d.ts +16 -9
- package/dist/v3/protocol.d.ts.map +1 -1
- package/dist/v3/protocol.js +57 -26
- package/dist/v3/protocol.js.map +1 -1
- package/dist/v3/queries.d.ts +2 -2
- package/dist/v3/queries.d.ts.map +1 -1
- package/dist/v3/queries.js +24 -16
- package/dist/v3/queries.js.map +1 -1
- package/dist/v3/segments.d.ts +18 -11
- package/dist/v3/segments.d.ts.map +1 -1
- package/dist/v3/segments.js +30 -21
- package/dist/v3/segments.js.map +1 -1
- package/dist/v3/syntax.d.ts +15 -11
- package/dist/v3/syntax.d.ts.map +1 -1
- package/dist/v3/syntax.js +30 -15
- package/dist/v3/syntax.js.map +1 -1
- package/package.json +1 -1
- package/src/client.ts +58 -17
- package/src/core/account.ts +91 -35
- package/src/core/amount.ts +42 -9
- package/src/core/balance.ts +6 -0
- package/src/core/bank-info.ts +28 -4
- package/src/core/client.ts +42 -15
- package/src/core/config.ts +37 -18
- package/src/core/errors.ts +27 -7
- package/src/core/feedback.ts +12 -1
- package/src/core/transaction.ts +13 -0
- package/src/core/transport.ts +62 -16
- package/src/formats/camt.ts +62 -51
- package/src/formats/mt940.ts +114 -78
- package/src/formats/readers.ts +6 -2
- package/src/formats/sepa-purpose.ts +17 -9
- package/src/session/dialog-runner.ts +34 -7
- package/src/session/login-guard.ts +29 -13
- package/src/session/session-setup.ts +27 -9
- package/src/session/session-state.ts +25 -8
- package/src/session/signed-dialog.ts +60 -30
- package/src/session/user-prompts.ts +28 -3
- package/src/tan/challenge.ts +50 -36
- package/src/tan/flicker.ts +40 -29
- package/src/tan/tan-image.ts +9 -2
- package/src/tan/tan-models.ts +16 -2
- package/src/util/arguments.ts +40 -0
- package/src/util/async.ts +10 -4
- package/src/util/bytes.ts +3 -3
- package/src/util/dates.ts +52 -38
- package/src/util/errors.ts +9 -4
- package/src/util/immutable-map.ts +15 -12
- package/src/util/inspect.ts +14 -0
- package/src/util/text.ts +47 -5
- package/src/util/xml.ts +105 -38
- package/src/v3/bank-connection.ts +65 -6
- package/src/v3/dialog.ts +18 -8
- package/src/v3/message.ts +81 -72
- package/src/v3/parameter-store.ts +82 -16
- package/src/v3/parameters.ts +68 -41
- package/src/v3/protocol.ts +61 -28
- package/src/v3/queries.ts +26 -18
- package/src/v3/segments.ts +32 -20
- package/src/v3/syntax.ts +31 -14
package/dist/client.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Account } from './core/account.js';
|
|
1
2
|
import { FinTsConfig, requirePin } from './core/config.js';
|
|
2
3
|
import { FinTsStateError, FinTsUnsupportedError } from './core/errors.js';
|
|
3
4
|
import { DialogRunner } from './session/dialog-runner.js';
|
|
@@ -8,6 +9,7 @@ import { restoreSession, saveSession } from './session/session-state.js';
|
|
|
8
9
|
import { TanSelection } from './session/tan-selection.js';
|
|
9
10
|
import { UserPrompts } from './session/user-prompts.js';
|
|
10
11
|
import { TanMedium } from './tan/tan-models.js';
|
|
12
|
+
import { optionalString, requireString } from './util/arguments.js';
|
|
11
13
|
import { SerialExecutor } from './util/async.js';
|
|
12
14
|
import { CallContext } from './util/call-context.js';
|
|
13
15
|
import { calendarDay, notAfterToday } from './util/dates.js';
|
|
@@ -17,6 +19,24 @@ import { FinTs3Protocol } from './v3/protocol.js';
|
|
|
17
19
|
import { balanceQuery, tanMediaQuery, transactionsQuery } from './v3/queries.js';
|
|
18
20
|
/** A token of the client call running now, so that a call from inside its callbacks is recognized. */
|
|
19
21
|
const runningCalls = new CallContext();
|
|
22
|
+
/**
|
|
23
|
+
* `transport`, `undefined` for `null`; throws `TypeError` unless it is neither or has the functions of a
|
|
24
|
+
* `FinTsTransport`.
|
|
25
|
+
*/
|
|
26
|
+
function optionalTransport(transport) {
|
|
27
|
+
if (transport === undefined || transport === null)
|
|
28
|
+
return undefined;
|
|
29
|
+
const candidate = transport;
|
|
30
|
+
if (typeof candidate.post !== 'function' || typeof candidate.close !== 'function') {
|
|
31
|
+
throw invalidArgument('Must have the functions post and close', 'transport');
|
|
32
|
+
}
|
|
33
|
+
return transport;
|
|
34
|
+
}
|
|
35
|
+
/** Throws `TypeError` for anything but an `Account`, such as one written to JSON and read back. */
|
|
36
|
+
function requireAccount(account) {
|
|
37
|
+
if (!(account instanceof Account))
|
|
38
|
+
throw invalidArgument('Must be an Account', 'account');
|
|
39
|
+
}
|
|
20
40
|
/**
|
|
21
41
|
* The calendar day of `bound`, the `name` bound of a `TransactionQuery`: the bank takes dates without time of day.
|
|
22
42
|
* Throws `TypeError` for anything but a valid `Date`, such as an Invalid Date, which would go out as `0NaNNaNNaN`.
|
|
@@ -28,6 +48,17 @@ function requestedDay(bound, name) {
|
|
|
28
48
|
throw invalidArgument('Not a valid Date', name);
|
|
29
49
|
return calendarDay(bound);
|
|
30
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* The format a `TransactionQuery` asks for with `format`: `auto` where it is `undefined`. Throws `TypeError` for anything
|
|
53
|
+
* but a `TransactionFormat`, such as `'CAMT'` or `null`.
|
|
54
|
+
*/
|
|
55
|
+
function requestedFormat(format) {
|
|
56
|
+
if (format === undefined)
|
|
57
|
+
return 'auto';
|
|
58
|
+
if (format === 'auto' || format === 'mt940' || format === 'camt')
|
|
59
|
+
return format;
|
|
60
|
+
throw invalidArgument("Must be 'auto', 'mt940' or 'camt'", 'format');
|
|
61
|
+
}
|
|
31
62
|
/** FinTS 3.0 PIN/TAN client, the version German banks use. */
|
|
32
63
|
export class FinTs3Client {
|
|
33
64
|
// A call such as `getBalance` runs through these parts:
|
|
@@ -65,15 +96,17 @@ export class FinTs3Client {
|
|
|
65
96
|
*
|
|
66
97
|
* Throws `TypeError` if the configuration is invalid, as the constructor of `FinTsConfig` tells, or the PIN is empty,
|
|
67
98
|
* begins or ends with a blank, or has characters FinTS 3.0 cannot send: it uses ISO 8859-1, so `€` and most
|
|
68
|
-
* non-Latin letters are not possible.
|
|
99
|
+
* non-Latin letters are not possible. Throws `TypeError` as well for an option of another type than
|
|
100
|
+
* `FinTsClientOptions` names, as `FinTsClientOptions` tells.
|
|
69
101
|
*/
|
|
70
102
|
constructor(init) {
|
|
71
103
|
const config = init.config instanceof FinTsConfig ? init.config : new FinTsConfig(init.config);
|
|
104
|
+
const { state, transport } = init.options;
|
|
72
105
|
this.#prompts = new UserPrompts(init.options);
|
|
73
106
|
this.#guard = new LoginGuard(requirePin(init.pin));
|
|
74
107
|
this.#parameters = new ParameterStore(config);
|
|
75
|
-
this.#protocol = new FinTs3Protocol(this.#parameters, this.#guard,
|
|
76
|
-
this.#sessionState = restoreSession(
|
|
108
|
+
this.#protocol = new FinTs3Protocol(this.#parameters, this.#guard, optionalTransport(transport), this.#prompts.logger);
|
|
109
|
+
this.#sessionState = restoreSession(optionalString(state, 'state'), this.#parameters, this.#guard);
|
|
77
110
|
this.#tans = new TanSelection(this.#protocol, this.#sessionState, this.#prompts);
|
|
78
111
|
const session = {
|
|
79
112
|
parameters: this.#parameters,
|
|
@@ -97,10 +130,13 @@ export class FinTs3Client {
|
|
|
97
130
|
get selectedTanMedium() {
|
|
98
131
|
return this.#sessionState.tanMedium;
|
|
99
132
|
}
|
|
100
|
-
selectTanMethod(securityFunction, tanMedium) {
|
|
133
|
+
async selectTanMethod(securityFunction, tanMedium) {
|
|
134
|
+
// Checked before the dialog ends; an async method, so that every argument error is a rejection.
|
|
135
|
+
const method = requireString(securityFunction, 'securityFunction');
|
|
136
|
+
const medium = optionalString(tanMedium, 'tanMedium');
|
|
101
137
|
return this.#serialized(async () => {
|
|
102
138
|
await this.#dialogs.end();
|
|
103
|
-
this.#tans.select(
|
|
139
|
+
this.#tans.select(method, medium);
|
|
104
140
|
});
|
|
105
141
|
}
|
|
106
142
|
clearLoginRefusal(pin) {
|
|
@@ -134,7 +170,9 @@ export class FinTs3Client {
|
|
|
134
170
|
getAccounts() {
|
|
135
171
|
return this.#serialized(() => this.#sepa.completedAccounts());
|
|
136
172
|
}
|
|
137
|
-
getBalance(account) {
|
|
173
|
+
async getBalance(account) {
|
|
174
|
+
// Checked before the call waits for others; an async method, so that every argument error is a rejection.
|
|
175
|
+
requireAccount(account);
|
|
138
176
|
return this.#serialized(async () => {
|
|
139
177
|
const completed = await this.#sepa.complete(account);
|
|
140
178
|
// The dialog start delivers the user parameter data, which may carry the complete balance: then the client must
|
|
@@ -146,14 +184,16 @@ export class FinTs3Client {
|
|
|
146
184
|
}
|
|
147
185
|
async getTransactions(account, query = {}) {
|
|
148
186
|
// Checked before the call waits for others; an async method, so that every argument error is a rejection.
|
|
187
|
+
requireAccount(account);
|
|
149
188
|
const firstDay = requestedDay(query.from, 'from');
|
|
150
189
|
const lastDay = requestedDay(query.to, 'to');
|
|
151
190
|
if (firstDay !== undefined && lastDay !== undefined && firstDay.getTime() > lastDay.getTime()) {
|
|
152
191
|
throw invalidArgument('`from` lies on a day after `to`', 'from');
|
|
153
192
|
}
|
|
193
|
+
const format = requestedFormat(query.format);
|
|
154
194
|
return this.#serialized(async () => {
|
|
155
195
|
const completed = await this.#sepa.complete(account);
|
|
156
|
-
const transactions = await this.#dialogs.query(() => transactionsQuery(this.#parameters, completed,
|
|
196
|
+
const transactions = await this.#dialogs.query(() => transactionsQuery(this.#parameters, completed, format, notAfterToday(firstDay), notAfterToday(lastDay)));
|
|
157
197
|
// A stable sort, so that transactions of the same day keep the bank's order.
|
|
158
198
|
return transactions.sort((a, b) => (a.bookingDate ?? a.valueDate).getTime() - (b.bookingDate ?? b.valueDate).getTime());
|
|
159
199
|
});
|
|
@@ -185,9 +225,12 @@ export class FinTs3Client {
|
|
|
185
225
|
const call = {};
|
|
186
226
|
this.#runningCall = call;
|
|
187
227
|
try {
|
|
188
|
-
return await runningCalls.run(call, () => this.#guard.runCall(() => {
|
|
228
|
+
return await runningCalls.run(call, () => this.#guard.runCall(async () => {
|
|
229
|
+
this.#prompts.checkOpen();
|
|
230
|
+
const result = await this.#prompts.reportingCallbackErrors(action);
|
|
231
|
+
// Also where the last answer arrived after `close`: a closed client hands out no account data.
|
|
189
232
|
this.#prompts.checkOpen();
|
|
190
|
-
return
|
|
233
|
+
return result;
|
|
191
234
|
}));
|
|
192
235
|
}
|
|
193
236
|
finally {
|
package/dist/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAI5C,OAAO,EAAE,WAAW,EAAE,UAAU,EAAwB,MAAM,kBAAkB,CAAC;AACjF,OAAO,EAAE,eAAe,EAAE,qBAAqB,EAA+B,MAAM,kBAAkB,CAAC;AAGvG,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,WAAW,EAAqB,MAAM,4BAA4B,CAAC;AAC5F,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,O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AO,OAAO,CAAC,MAAM,CAAC,IAAI,eAAe,CAAC,8DAA8D,CAAC,CAAC,CAAC;QAC7G,CAAC;QACD,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,IAAI,EAAE;YAChC,MAAM,IAAI,GAAG,EAAE,CAAC;YAChB,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC;YACzB,IAAI,CAAC;gBACH,OAAO,MAAM,YAAY,CAAC,GAAG,CAAC,IAAI,EAAE,GAAG,EAAE,CACvC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,IAAI,EAAE;oBAC7B,IAAI,CAAC,QAAQ,CAAC,SAAS,EAAE,CAAC;oBAC1B,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,uBAAuB,CAAC,MAAM,CAAC,CAAC;oBACnE,+FAA+F;oBAC/F,IAAI,CAAC,QAAQ,CAAC,SAAS,EAAE,CAAC;oBAC1B,OAAO,MAAM,CAAC;gBAChB,CAAC,CAAC,CACH,CAAC;YACJ,CAAC;oBAAS,CAAC;gBACT,IAAI,CAAC,YAAY,GAAG,SAAS,CAAC;YAChC,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;CACF"}
|
package/dist/core/account.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { inspectCustom } from '../util/inspect.js';
|
|
1
2
|
/** Account kind derived from the FinTS account type code. */
|
|
2
3
|
export type AccountCategory =
|
|
3
4
|
/** Current account (type codes 1 to 9). */
|
|
@@ -88,7 +89,12 @@ export declare class Account {
|
|
|
88
89
|
readonly allowedTransactionsComplete: boolean;
|
|
89
90
|
/** What the bank tells about the data it holds for the account, where it does. */
|
|
90
91
|
readonly dataStatus: AccountDataStatus | undefined;
|
|
91
|
-
/**
|
|
92
|
+
/**
|
|
93
|
+
* Takes copies of the permitted transactions and the data status of `init`, which no other account shares.
|
|
94
|
+
*
|
|
95
|
+
* Throws `TypeError` for a detail of another type than `AccountInit` names, such as a number as `bankCode` or
|
|
96
|
+
* `accountNumber`, or a missing `bankCode`; `null` counts as a detail not given. The message leaves out the value.
|
|
97
|
+
*/
|
|
92
98
|
constructor(init: AccountInit);
|
|
93
99
|
/** The kind of account, derived from `typeCode`. */
|
|
94
100
|
get category(): AccountCategory;
|
|
@@ -107,17 +113,17 @@ export declare class Account {
|
|
|
107
113
|
* collect account data.
|
|
108
114
|
*/
|
|
109
115
|
toString(): string;
|
|
116
|
+
/** What Node.js's `util.inspect` and `console.log` show: `toString`, not the fields. */
|
|
117
|
+
[inspectCustom](): string;
|
|
110
118
|
}
|
|
111
119
|
/**
|
|
112
120
|
* Accounts by IBAN and by national account, to find the first one an account `matches` without comparing it with each:
|
|
113
121
|
* a bank may list tens of thousands.
|
|
114
|
-
*
|
|
115
|
-
* Bank and country codes count as they are, where `matches` takes an empty one for any: the accounts a bank lists state
|
|
116
|
-
* both.
|
|
117
122
|
*/
|
|
118
123
|
export declare class AccountIndex {
|
|
119
124
|
private readonly accounts;
|
|
120
125
|
private readonly byIban;
|
|
126
|
+
/** By national account, under its bank and country code and under `null` for any of each, as `matches` takes them. */
|
|
121
127
|
private readonly byNational;
|
|
122
128
|
/** Those without IBAN only: an account with IBAN matches one with IBAN by that alone. */
|
|
123
129
|
private readonly byNationalWithoutIban;
|
|
@@ -164,5 +170,10 @@ export declare class AccountDataStatus {
|
|
|
164
170
|
get mt940TransactionsId(): string | undefined;
|
|
165
171
|
/** The ID of the transactions the bank holds as camt, its entry for `HKCAZ` in `inventory`. */
|
|
166
172
|
get camtTransactionsId(): string | undefined;
|
|
173
|
+
/**
|
|
174
|
+
* What Node.js's `util.inspect` and `console.log` show: the queries `inventory` holds an ID for, not the IDs, which
|
|
175
|
+
* mark the user's data.
|
|
176
|
+
*/
|
|
177
|
+
[inspectCustom](): string;
|
|
167
178
|
}
|
|
168
179
|
//# sourceMappingURL=account.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"account.d.ts","sourceRoot":"","sources":["../../src/core/account.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"account.d.ts","sourceRoot":"","sources":["../../src/core/account.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAKnD,6DAA6D;AAC7D,MAAM,MAAM,eAAe;AACzB,2CAA2C;AACzC,UAAU;AACZ,kCAAkC;GAChC,SAAS;AACX,qCAAqC;GACnC,cAAc;AAChB,qCAAqC;GACnC,YAAY;AACd,+BAA+B;GAC7B,MAAM;AACR,sCAAsC;GACpC,YAAY;AACd,+BAA+B;GAC7B,MAAM;AACR,wCAAwC;GACtC,aAAa;AACf,4BAA4B;GAC1B,WAAW;AACb,2BAA2B;GACzB,OAAO;AACT,oCAAoC;GAClC,SAAS,CAAC;AAoBd,kEAAkE;AAClE,MAAM,WAAW,WAAW;IAC1B,aAAa,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACnC,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACjC,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1B,GAAG,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACzB,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC/B,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACjC,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,mBAAmB,CAAC,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,CAAC;IACpD,2BAA2B,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAClD,UAAU,CAAC,EAAE,iBAAiB,GAAG,SAAS,CAAC;CAC5C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,CAE3C;IAED;;;OAGG;IACH,CAAC,aAAa,CAAC,IAAI,MAAM;CAG1B"}
|
package/dist/core/account.js
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
|
+
import { optionalBoolean, optionalInteger, optionalString, requireString } from '../util/arguments.js';
|
|
1
2
|
import { copyDate } from '../util/dates.js';
|
|
3
|
+
import { invalidArgument } from '../util/errors.js';
|
|
2
4
|
import { ImmutableMap } from '../util/immutable-map.js';
|
|
5
|
+
import { inspectCustom } from '../util/inspect.js';
|
|
6
|
+
import { isString } from '../util/json.js';
|
|
3
7
|
import { maskedId, nonBlank } from '../util/text.js';
|
|
4
8
|
import { defaultCountryCode } from './config.js';
|
|
5
9
|
const categoriesByTens = [
|
|
@@ -68,22 +72,28 @@ export class Account {
|
|
|
68
72
|
allowedTransactionsComplete;
|
|
69
73
|
/** What the bank tells about the data it holds for the account, where it does. */
|
|
70
74
|
dataStatus;
|
|
71
|
-
/**
|
|
75
|
+
/**
|
|
76
|
+
* Takes copies of the permitted transactions and the data status of `init`, which no other account shares.
|
|
77
|
+
*
|
|
78
|
+
* Throws `TypeError` for a detail of another type than `AccountInit` names, such as a number as `bankCode` or
|
|
79
|
+
* `accountNumber`, or a missing `bankCode`; `null` counts as a detail not given. The message leaves out the value.
|
|
80
|
+
*/
|
|
72
81
|
constructor(init) {
|
|
73
|
-
this.accountNumber = init.accountNumber;
|
|
74
|
-
this.subAccount = init.subAccount;
|
|
75
|
-
this.bankCode = init.bankCode;
|
|
76
|
-
this.countryCode = init.countryCode ?? defaultCountryCode;
|
|
77
|
-
this.iban = electronicFormat(init.iban);
|
|
78
|
-
this.bic = electronicFormat(init.bic);
|
|
79
|
-
this.customerId = init.customerId;
|
|
80
|
-
this.currency = init.currency;
|
|
81
|
-
this.ownerName = init.ownerName;
|
|
82
|
-
this.productName = init.productName;
|
|
83
|
-
this.typeCode = init.typeCode;
|
|
84
|
-
this.allowedTransactions = Object.freeze(
|
|
85
|
-
this.allowedTransactionsComplete =
|
|
86
|
-
|
|
82
|
+
this.accountNumber = optionalString(init.accountNumber, 'accountNumber');
|
|
83
|
+
this.subAccount = optionalString(init.subAccount, 'subAccount');
|
|
84
|
+
this.bankCode = requireString(init.bankCode, 'bankCode');
|
|
85
|
+
this.countryCode = optionalString(init.countryCode, 'countryCode') ?? defaultCountryCode;
|
|
86
|
+
this.iban = electronicFormat(optionalString(init.iban, 'iban'));
|
|
87
|
+
this.bic = electronicFormat(optionalString(init.bic, 'bic'));
|
|
88
|
+
this.customerId = optionalString(init.customerId, 'customerId');
|
|
89
|
+
this.currency = optionalString(init.currency, 'currency');
|
|
90
|
+
this.ownerName = optionalString(init.ownerName, 'ownerName');
|
|
91
|
+
this.productName = optionalString(init.productName, 'productName');
|
|
92
|
+
this.typeCode = optionalInteger(init.typeCode, 'typeCode');
|
|
93
|
+
this.allowedTransactions = Object.freeze(segmentIds(init.allowedTransactions));
|
|
94
|
+
this.allowedTransactionsComplete =
|
|
95
|
+
optionalBoolean(init.allowedTransactionsComplete, 'allowedTransactionsComplete') ?? false;
|
|
96
|
+
this.dataStatus = copiedDataStatus(init.dataStatus);
|
|
87
97
|
}
|
|
88
98
|
/** The kind of account, derived from `typeCode`. */
|
|
89
99
|
get category() {
|
|
@@ -137,12 +147,34 @@ export class Account {
|
|
|
137
147
|
];
|
|
138
148
|
return `Account(${parts.join(', ')})`;
|
|
139
149
|
}
|
|
150
|
+
/** What Node.js's `util.inspect` and `console.log` show: `toString`, not the fields. */
|
|
151
|
+
[inspectCustom]() {
|
|
152
|
+
return this.toString();
|
|
153
|
+
}
|
|
140
154
|
}
|
|
141
155
|
/**
|
|
142
|
-
* An IBAN or BIC in the form the bank sends and compares, without blanks and in capitals;
|
|
156
|
+
* An IBAN or BIC in the form the bank sends and compares, without blanks, U+0085 (NEL) among them, and in capitals;
|
|
157
|
+
* `undefined` for blanks only.
|
|
143
158
|
*/
|
|
144
159
|
function electronicFormat(code) {
|
|
145
|
-
return nonBlank(code?.replace(
|
|
160
|
+
return nonBlank(code?.replace(/[\s\u0085]/g, '').toUpperCase());
|
|
161
|
+
}
|
|
162
|
+
/** A copy of `ids`, none for `undefined` or `null`; throws `TypeError` unless they are an array of strings. */
|
|
163
|
+
function segmentIds(ids) {
|
|
164
|
+
if (ids === undefined || ids === null)
|
|
165
|
+
return [];
|
|
166
|
+
if (!Array.isArray(ids) || !ids.every(isString)) {
|
|
167
|
+
throw invalidArgument('Must be an array of strings', 'allowedTransactions');
|
|
168
|
+
}
|
|
169
|
+
return [...ids];
|
|
170
|
+
}
|
|
171
|
+
/** A copy of `status`, none for `undefined` or `null`; throws `TypeError` unless it is an `AccountDataStatus`. */
|
|
172
|
+
function copiedDataStatus(status) {
|
|
173
|
+
if (status === undefined || status === null)
|
|
174
|
+
return undefined;
|
|
175
|
+
if (!(status instanceof AccountDataStatus))
|
|
176
|
+
throw invalidArgument('Must be an AccountDataStatus', 'dataStatus');
|
|
177
|
+
return new AccountDataStatus(status);
|
|
146
178
|
}
|
|
147
179
|
function sameOrUnstated(a, b) {
|
|
148
180
|
return a === '' || b === '' || a === b;
|
|
@@ -154,45 +186,54 @@ function nationalNumber(account) {
|
|
|
154
186
|
/**
|
|
155
187
|
* Accounts by IBAN and by national account, to find the first one an account `matches` without comparing it with each:
|
|
156
188
|
* a bank may list tens of thousands.
|
|
157
|
-
*
|
|
158
|
-
* Bank and country codes count as they are, where `matches` takes an empty one for any: the accounts a bank lists state
|
|
159
|
-
* both.
|
|
160
189
|
*/
|
|
161
190
|
export class AccountIndex {
|
|
162
191
|
accounts;
|
|
163
192
|
byIban = new Map();
|
|
193
|
+
/** By national account, under its bank and country code and under `null` for any of each, as `matches` takes them. */
|
|
164
194
|
byNational = new Map();
|
|
165
195
|
/** Those without IBAN only: an account with IBAN matches one with IBAN by that alone. */
|
|
166
196
|
byNationalWithoutIban = new Map();
|
|
167
197
|
constructor(accounts) {
|
|
168
198
|
this.accounts = accounts;
|
|
169
199
|
accounts.forEach((account, i) => {
|
|
170
|
-
const national = nationalKey(account);
|
|
171
200
|
if (account.iban !== undefined)
|
|
172
201
|
keepFirst(this.byIban, account.iban, i);
|
|
173
|
-
|
|
202
|
+
const number = nationalNumber(account);
|
|
203
|
+
if (number === undefined)
|
|
174
204
|
return;
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
205
|
+
for (const bankCode of [account.bankCode, null]) {
|
|
206
|
+
for (const countryCode of [account.countryCode, null]) {
|
|
207
|
+
const national = nationalKey(number, account.subAccount, bankCode, countryCode);
|
|
208
|
+
keepFirst(this.byNational, national, i);
|
|
209
|
+
if (account.iban === undefined)
|
|
210
|
+
keepFirst(this.byNationalWithoutIban, national, i);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
178
213
|
});
|
|
179
214
|
}
|
|
180
215
|
/** The first of the accounts that `account` matches. */
|
|
181
216
|
find(account) {
|
|
182
|
-
const
|
|
217
|
+
const number = nationalNumber(account);
|
|
183
218
|
const byNational = account.iban === undefined ? this.byNational : this.byNationalWithoutIban;
|
|
184
|
-
const found = [
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
219
|
+
const found = [account.iban === undefined ? undefined : this.byIban.get(account.iban)];
|
|
220
|
+
if (number !== undefined) {
|
|
221
|
+
for (const bankCode of codesMatching(account.bankCode)) {
|
|
222
|
+
for (const countryCode of codesMatching(account.countryCode)) {
|
|
223
|
+
found.push(byNational.get(nationalKey(number, account.subAccount, bankCode, countryCode)));
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
const positions = found.filter((i) => i !== undefined);
|
|
228
|
+
return positions.length === 0 ? undefined : this.accounts[Math.min(...positions)];
|
|
189
229
|
}
|
|
190
230
|
}
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
return
|
|
194
|
-
|
|
195
|
-
|
|
231
|
+
/** The keys of the codes that `code` matches: an empty one matches any, and a stated one also an empty one. */
|
|
232
|
+
function codesMatching(code) {
|
|
233
|
+
return code === '' ? [null] : [code, ''];
|
|
234
|
+
}
|
|
235
|
+
function nationalKey(number, subAccount, bankCode, countryCode) {
|
|
236
|
+
return JSON.stringify([number, subAccount ?? '', bankCode, countryCode]);
|
|
196
237
|
}
|
|
197
238
|
function keepFirst(index, key, position) {
|
|
198
239
|
if (!index.has(key))
|
|
@@ -241,5 +282,12 @@ export class AccountDataStatus {
|
|
|
241
282
|
get camtTransactionsId() {
|
|
242
283
|
return this.inventory.get('HKCAZ');
|
|
243
284
|
}
|
|
285
|
+
/**
|
|
286
|
+
* What Node.js's `util.inspect` and `console.log` show: the queries `inventory` holds an ID for, not the IDs, which
|
|
287
|
+
* mark the user's data.
|
|
288
|
+
*/
|
|
289
|
+
[inspectCustom]() {
|
|
290
|
+
return `AccountDataStatus(${[...this.inventory.keys()].join(', ')})`;
|
|
291
|
+
}
|
|
244
292
|
}
|
|
245
293
|
//# sourceMappingURL=account.js.map
|
package/dist/core/account.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"account.js","sourceRoot":"","sources":["../../src/core/account.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AA2BjD,MAAM,gBAAgB,GAA+B;IACnD,UAAU;IACV,SAAS;IACT,cAAc;IACd,YAAY;IACZ,MAAM;IACN,YAAY;IACZ,MAAM;IACN,aAAa;IACb,WAAW;CACZ,CAAC;AAEF,mGAAmG;AACnG,SAAS,iBAAiB,CAAC,IAAwB;IACjD,IAAI,IAAI,KAAK,SAAS,IAAI,IAAI,GAAG,CAAC;QAAE,OAAO,SAAS,CAAC;IACrD,OAAO,gBAAgB,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,GAAG,EAAE,C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C;IAC7E,CAAC;IAED,gGAAgG;IAChG,IAAI,mBAAmB;QACrB,OAAO,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IACrC,CAAC;IAED,+FAA+F;IAC/F,IAAI,kBAAkB;QACpB,OAAO,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IACrC,CAAC;IAED;;;OAGG;IACH,CAAC,aAAa,CAAC;QACb,OAAO,qBAAqB,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC;IACvE,CAAC;CACF"}
|
package/dist/core/amount.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { inspectCustom } from '../util/inspect.js';
|
|
1
2
|
/** A money amount stored as an integer number of `scale`-digit minor units. */
|
|
2
3
|
export declare class Amount {
|
|
3
4
|
/** The amount in units of 10^-`scale` of the currency, negative for a debit: 1234 with scale 2 is 12.34. */
|
|
@@ -9,6 +10,8 @@ export declare class Amount {
|
|
|
9
10
|
/**
|
|
10
11
|
* An amount of `minorUnits` with `scale` decimal places; throws `RangeError` for a `scale` outside 0 to 5, and for
|
|
11
12
|
* `minorUnits` that are no integer or beyond 2^53 - 1 in either direction, about 90 trillion at two decimal places.
|
|
13
|
+
* Throws `TypeError` for `minorUnits` or `scale` that are no number, such as `'1234'`, and a `currency` that is no
|
|
14
|
+
* string.
|
|
12
15
|
*/
|
|
13
16
|
constructor(minorUnits: number, scale: number, currency: string);
|
|
14
17
|
/**
|
|
@@ -19,8 +22,9 @@ export declare class Amount {
|
|
|
19
22
|
* `JPY`, three for `KWD`. It has more where the value has more significant digits. So `100,` in `EUR` is `100.00`, in
|
|
20
23
|
* `JPY` `100`.
|
|
21
24
|
*
|
|
22
|
-
* Throws `FormatError` for anything else, so that `1.234,56` in bank data is an error, not a guess,
|
|
23
|
-
* five decimal places (trailing zeros aside) or more than 15 digits
|
|
25
|
+
* Throws `FormatError` for anything else, so that `1.234,56` in bank data is an error, not a guess, for more than
|
|
26
|
+
* five decimal places (trailing zeros aside) or more than 15 digits, and for more than 64 characters, zeros included
|
|
27
|
+
* and surrounding blanks aside. Throws `TypeError` for a `value` or `currency` that is no string.
|
|
24
28
|
*/
|
|
25
29
|
static parseDecimal(value: string, currency: string): Amount;
|
|
26
30
|
/** The amount as a floating-point number, which cannot hold every decimal fraction exactly; do not calculate with it. */
|
|
@@ -47,12 +51,18 @@ export declare class Amount {
|
|
|
47
51
|
/** Formats the amount without currency, for example `-12.50`. */
|
|
48
52
|
toDecimalString(decimalSeparator?: string): string;
|
|
49
53
|
toString(): string;
|
|
54
|
+
/** What Node.js's `util.inspect` and `console.log` show: `toString`, not the fields. */
|
|
55
|
+
[inspectCustom](): string;
|
|
50
56
|
/** The minor units of both amounts at the larger scale, as `bigint`s, since the factor could leave the safe range. */
|
|
51
57
|
private atCommonScale;
|
|
52
|
-
private rescale;
|
|
53
58
|
private compareValue;
|
|
54
59
|
private checkCurrency;
|
|
55
60
|
}
|
|
61
|
+
/**
|
|
62
|
+
* Whether `parts` are all in the currency of `total` and add up to exactly `total`; unlike `add`, also where a sum on
|
|
63
|
+
* the way lies beyond what an amount holds.
|
|
64
|
+
*/
|
|
65
|
+
export declare function addsUpTo(parts: readonly Amount[], total: Amount): boolean;
|
|
56
66
|
/**
|
|
57
67
|
* `amount` as a credit (unchanged) or a debit (negated), by the bank's credit/debit `mark`.
|
|
58
68
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"amount.d.ts","sourceRoot":"","sources":["../../src/core/amount.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"amount.d.ts","sourceRoot":"","sources":["../../src/core/amount.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAuDnD,+EAA+E;AAC/E,qBAAa,MAAM;IACjB,4GAA4G;IAC5G,QAAQ,CAAC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AE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAKxG"}
|
package/dist/core/amount.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { requireString } from '../util/arguments.js';
|
|
2
|
+
import { FormatError, invalidArgument } from '../util/errors.js';
|
|
3
|
+
import { inspectCustom } from '../util/inspect.js';
|
|
4
|
+
import { trimBlanks } from '../util/text.js';
|
|
2
5
|
/** Most decimal places an amount has: ISO 20022, the widest of the bank formats, allows five. */
|
|
3
6
|
const maxScale = 5;
|
|
4
7
|
/** Largest `minorUnits` an amount holds: 2^53 - 1, which JavaScript numbers represent exactly. */
|
|
@@ -6,6 +9,8 @@ const maxMinorUnits = Number.MAX_SAFE_INTEGER;
|
|
|
6
9
|
const powersOfTen = [1, 10, 100, 1000, 10000, 100000];
|
|
7
10
|
/** Most digits a parsed amount has: few enough that the sum of two parsed amounts still fits. */
|
|
8
11
|
const maxDigits = 15;
|
|
12
|
+
/** Most characters a parsed value has: room for the zeros banks pad amounts with besides `maxDigits` digits. */
|
|
13
|
+
const maxLength = 64;
|
|
9
14
|
const decimal = /^([+-]?)(\d*)(?:[.,](\d*))?$/;
|
|
10
15
|
/** Decimal places of the minor unit of `currency` (ISO 4217): two, except for the currencies listed here. */
|
|
11
16
|
function minorUnitDigits(currency) {
|
|
@@ -54,8 +59,15 @@ export class Amount {
|
|
|
54
59
|
/**
|
|
55
60
|
* An amount of `minorUnits` with `scale` decimal places; throws `RangeError` for a `scale` outside 0 to 5, and for
|
|
56
61
|
* `minorUnits` that are no integer or beyond 2^53 - 1 in either direction, about 90 trillion at two decimal places.
|
|
62
|
+
* Throws `TypeError` for `minorUnits` or `scale` that are no number, such as `'1234'`, and a `currency` that is no
|
|
63
|
+
* string.
|
|
57
64
|
*/
|
|
58
65
|
constructor(minorUnits, scale, currency) {
|
|
66
|
+
if (typeof minorUnits !== 'number')
|
|
67
|
+
throw invalidArgument('Must be a number', 'minorUnits');
|
|
68
|
+
if (typeof scale !== 'number')
|
|
69
|
+
throw invalidArgument('Must be a number', 'scale');
|
|
70
|
+
requireString(currency, 'currency');
|
|
59
71
|
if (!Number.isInteger(scale) || scale < 0 || scale > maxScale) {
|
|
60
72
|
throw new RangeError(`scale must be an integer from 0 to ${maxScale}: ${scale}`);
|
|
61
73
|
}
|
|
@@ -74,11 +86,16 @@ export class Amount {
|
|
|
74
86
|
* `JPY`, three for `KWD`. It has more where the value has more significant digits. So `100,` in `EUR` is `100.00`, in
|
|
75
87
|
* `JPY` `100`.
|
|
76
88
|
*
|
|
77
|
-
* Throws `FormatError` for anything else, so that `1.234,56` in bank data is an error, not a guess,
|
|
78
|
-
* five decimal places (trailing zeros aside) or more than 15 digits
|
|
89
|
+
* Throws `FormatError` for anything else, so that `1.234,56` in bank data is an error, not a guess, for more than
|
|
90
|
+
* five decimal places (trailing zeros aside) or more than 15 digits, and for more than 64 characters, zeros included
|
|
91
|
+
* and surrounding blanks aside. Throws `TypeError` for a `value` or `currency` that is no string.
|
|
79
92
|
*/
|
|
80
93
|
static parseDecimal(value, currency) {
|
|
81
|
-
const
|
|
94
|
+
const trimmed = trimBlanks(requireString(value, 'value'));
|
|
95
|
+
requireString(currency, 'currency');
|
|
96
|
+
if (trimmed.length > maxLength)
|
|
97
|
+
throw new FormatError(`Amount longer than ${maxLength} characters`, value);
|
|
98
|
+
const match = decimal.exec(trimmed);
|
|
82
99
|
const whole = match?.[2] ?? '';
|
|
83
100
|
let fraction = match?.[3] ?? '';
|
|
84
101
|
if (!match || (whole === '' && fraction === ''))
|
|
@@ -155,13 +172,14 @@ export class Amount {
|
|
|
155
172
|
toString() {
|
|
156
173
|
return `${this.toDecimalString()} ${this.currency}`;
|
|
157
174
|
}
|
|
175
|
+
/** What Node.js's `util.inspect` and `console.log` show: `toString`, not the fields. */
|
|
176
|
+
[inspectCustom]() {
|
|
177
|
+
return this.toString();
|
|
178
|
+
}
|
|
158
179
|
/** The minor units of both amounts at the larger scale, as `bigint`s, since the factor could leave the safe range. */
|
|
159
180
|
atCommonScale(other) {
|
|
160
181
|
const target = Math.max(this.scale, other.scale);
|
|
161
|
-
return [this
|
|
162
|
-
}
|
|
163
|
-
rescale(target) {
|
|
164
|
-
return BigInt(this.minorUnits) * BigInt(powersOfTen[target - this.scale]);
|
|
182
|
+
return [unitsAtScale(this, target), unitsAtScale(other, target)];
|
|
165
183
|
}
|
|
166
184
|
compareValue(other) {
|
|
167
185
|
if (this.scale === other.scale)
|
|
@@ -174,6 +192,22 @@ export class Amount {
|
|
|
174
192
|
throw new TypeError(`Currency mismatch: ${this.currency} vs ${other.currency}`);
|
|
175
193
|
}
|
|
176
194
|
}
|
|
195
|
+
function unitsAtScale(amount, scale) {
|
|
196
|
+
return BigInt(amount.minorUnits) * BigInt(powersOfTen[scale - amount.scale]);
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Whether `parts` are all in the currency of `total` and add up to exactly `total`; unlike `add`, also where a sum on
|
|
200
|
+
* the way lies beyond what an amount holds.
|
|
201
|
+
*/
|
|
202
|
+
export function addsUpTo(parts, total) {
|
|
203
|
+
let sum = 0n;
|
|
204
|
+
for (const part of parts) {
|
|
205
|
+
if (part.currency !== total.currency)
|
|
206
|
+
return false;
|
|
207
|
+
sum += unitsAtScale(part, maxScale);
|
|
208
|
+
}
|
|
209
|
+
return sum === unitsAtScale(total, maxScale);
|
|
210
|
+
}
|
|
177
211
|
/**
|
|
178
212
|
* `amount` as a credit (unchanged) or a debit (negated), by the bank's credit/debit `mark`.
|
|
179
213
|
*
|