@coderoftime/fints 0.1.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 +519 -1
- package/README.md +138 -40
- package/dist/client.d.ts +49 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +242 -0
- package/dist/client.js.map +1 -0
- package/dist/core/account.d.ts +46 -7
- package/dist/core/account.d.ts.map +1 -1
- package/dist/core/account.js +143 -24
- package/dist/core/account.js.map +1 -1
- package/dist/core/amount.d.ts +15 -4
- package/dist/core/amount.d.ts.map +1 -1
- package/dist/core/amount.js +46 -9
- package/dist/core/amount.js.map +1 -1
- package/dist/core/balance.d.ts +4 -0
- package/dist/core/balance.d.ts.map +1 -1
- package/dist/core/balance.js +11 -5
- package/dist/core/balance.js.map +1 -1
- package/dist/core/bank-info.d.ts +21 -4
- package/dist/core/bank-info.d.ts.map +1 -1
- package/dist/core/bank-info.js +26 -5
- package/dist/core/bank-info.js.map +1 -1
- package/dist/core/client.d.ts +81 -19
- package/dist/core/client.d.ts.map +1 -1
- package/dist/core/config.d.ts +40 -20
- package/dist/core/config.d.ts.map +1 -1
- package/dist/core/config.js +85 -30
- package/dist/core/config.js.map +1 -1
- package/dist/core/errors.d.ts +100 -26
- package/dist/core/errors.d.ts.map +1 -1
- package/dist/core/errors.js +136 -53
- package/dist/core/errors.js.map +1 -1
- package/dist/core/feedback.d.ts +11 -1
- package/dist/core/feedback.d.ts.map +1 -1
- package/dist/core/feedback.js +14 -2
- package/dist/core/feedback.js.map +1 -1
- package/dist/core/transaction.d.ts +11 -1
- package/dist/core/transaction.d.ts.map +1 -1
- package/dist/core/transaction.js +21 -4
- package/dist/core/transaction.js.map +1 -1
- package/dist/core/transport.d.ts +48 -6
- package/dist/core/transport.d.ts.map +1 -1
- package/dist/core/transport.js +126 -29
- package/dist/core/transport.js.map +1 -1
- package/dist/formats/camt.d.ts +28 -5
- package/dist/formats/camt.d.ts.map +1 -1
- package/dist/formats/camt.js +132 -50
- package/dist/formats/camt.js.map +1 -1
- package/dist/formats/mt940.d.ts +29 -5
- package/dist/formats/mt940.d.ts.map +1 -1
- package/dist/formats/mt940.js +209 -113
- package/dist/formats/mt940.js.map +1 -1
- package/dist/formats/readers.d.ts +6 -2
- package/dist/formats/readers.d.ts.map +1 -1
- package/dist/formats/readers.js +28 -29
- package/dist/formats/readers.js.map +1 -1
- package/dist/formats/record-budget.d.ts +7 -0
- package/dist/formats/record-budget.d.ts.map +1 -0
- package/dist/formats/record-budget.js +17 -0
- package/dist/formats/record-budget.js.map +1 -0
- package/dist/formats/sepa-purpose.d.ts +9 -0
- package/dist/formats/sepa-purpose.d.ts.map +1 -1
- package/dist/formats/sepa-purpose.js +32 -2
- package/dist/formats/sepa-purpose.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/session/app-approval.d.ts +11 -5
- package/dist/session/app-approval.d.ts.map +1 -1
- package/dist/session/app-approval.js +23 -12
- package/dist/session/app-approval.js.map +1 -1
- package/dist/session/dialog-runner.d.ts +11 -11
- package/dist/session/dialog-runner.d.ts.map +1 -1
- package/dist/session/dialog-runner.js +34 -19
- package/dist/session/dialog-runner.js.map +1 -1
- package/dist/session/login-guard.d.ts +54 -49
- package/dist/session/login-guard.d.ts.map +1 -1
- package/dist/session/login-guard.js +170 -83
- package/dist/session/login-guard.js.map +1 -1
- package/dist/session/sepa-accounts.d.ts +20 -14
- package/dist/session/sepa-accounts.d.ts.map +1 -1
- package/dist/session/sepa-accounts.js +62 -46
- package/dist/session/sepa-accounts.js.map +1 -1
- package/dist/session/session-setup.d.ts +41 -24
- package/dist/session/session-setup.d.ts.map +1 -1
- package/dist/session/session-setup.js +106 -63
- package/dist/session/session-setup.js.map +1 -1
- package/dist/session/session-state.d.ts +10 -6
- package/dist/session/session-state.d.ts.map +1 -1
- package/dist/session/session-state.js +72 -18
- package/dist/session/session-state.js.map +1 -1
- package/dist/session/signed-dialog.d.ts +83 -0
- package/dist/session/signed-dialog.d.ts.map +1 -0
- package/dist/session/signed-dialog.js +185 -0
- package/dist/session/signed-dialog.js.map +1 -0
- package/dist/session/tan-selection.d.ts +26 -18
- package/dist/session/tan-selection.d.ts.map +1 -1
- package/dist/session/tan-selection.js +44 -33
- package/dist/session/tan-selection.js.map +1 -1
- package/dist/session/user-prompts.d.ts +14 -5
- package/dist/session/user-prompts.d.ts.map +1 -1
- package/dist/session/user-prompts.js +53 -18
- package/dist/session/user-prompts.js.map +1 -1
- package/dist/tan/challenge.d.ts +47 -24
- package/dist/tan/challenge.d.ts.map +1 -1
- package/dist/tan/challenge.js +56 -51
- package/dist/tan/challenge.js.map +1 -1
- package/dist/tan/flicker.d.ts +11 -1
- package/dist/tan/flicker.d.ts.map +1 -1
- package/dist/tan/flicker.js +70 -24
- package/dist/tan/flicker.js.map +1 -1
- package/dist/tan/tan-image.d.ts +6 -2
- package/dist/tan/tan-image.d.ts.map +1 -1
- package/dist/tan/tan-image.js +14 -6
- package/dist/tan/tan-image.js.map +1 -1
- package/dist/tan/tan-models.d.ts +14 -2
- package/dist/tan/tan-models.d.ts.map +1 -1
- package/dist/tan/tan-models.js +24 -7
- 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 -3
- package/dist/util/async.d.ts.map +1 -1
- package/dist/util/async.js +6 -7
- package/dist/util/async.js.map +1 -1
- package/dist/util/bytes.d.ts +3 -4
- package/dist/util/bytes.d.ts.map +1 -1
- package/dist/util/bytes.js +13 -21
- package/dist/util/bytes.js.map +1 -1
- package/dist/util/call-context.d.ts.map +1 -1
- package/dist/util/call-context.js +3 -2
- package/dist/util/call-context.js.map +1 -1
- package/dist/util/dates.d.ts +6 -20
- package/dist/util/dates.d.ts.map +1 -1
- package/dist/util/dates.js +58 -28
- package/dist/util/dates.js.map +1 -1
- package/dist/util/errors.d.ts +13 -3
- package/dist/util/errors.d.ts.map +1 -1
- package/dist/util/errors.js +19 -6
- 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/json.d.ts +4 -0
- package/dist/util/json.d.ts.map +1 -1
- package/dist/util/json.js +18 -0
- package/dist/util/json.js.map +1 -1
- package/dist/util/text.d.ts +38 -5
- package/dist/util/text.d.ts.map +1 -1
- package/dist/util/text.js +90 -16
- package/dist/util/text.js.map +1 -1
- package/dist/util/xml.d.ts +9 -6
- package/dist/util/xml.d.ts.map +1 -1
- package/dist/util/xml.js +129 -56
- package/dist/util/xml.js.map +1 -1
- package/dist/v3/account-extension.d.ts.map +1 -1
- package/dist/v3/account-extension.js +7 -10
- package/dist/v3/account-extension.js.map +1 -1
- package/dist/v3/bank-connection.d.ts +54 -0
- package/dist/v3/bank-connection.d.ts.map +1 -0
- package/dist/v3/bank-connection.js +118 -0
- package/dist/v3/bank-connection.js.map +1 -0
- package/dist/v3/dialog.d.ts +84 -46
- package/dist/v3/dialog.d.ts.map +1 -1
- package/dist/v3/dialog.js +174 -60
- package/dist/v3/dialog.js.map +1 -1
- package/dist/v3/message.d.ts +32 -11
- package/dist/v3/message.d.ts.map +1 -1
- package/dist/v3/message.js +144 -83
- package/dist/v3/message.js.map +1 -1
- package/dist/v3/parameter-store.d.ts +111 -0
- package/dist/v3/parameter-store.d.ts.map +1 -0
- package/dist/v3/parameter-store.js +197 -0
- package/dist/v3/parameter-store.js.map +1 -0
- package/dist/v3/parameters.d.ts +44 -17
- package/dist/v3/parameters.d.ts.map +1 -1
- package/dist/v3/parameters.js +136 -60
- package/dist/v3/parameters.js.map +1 -1
- package/dist/v3/protocol.d.ts +50 -50
- package/dist/v3/protocol.d.ts.map +1 -1
- package/dist/v3/protocol.js +91 -210
- package/dist/v3/protocol.js.map +1 -1
- package/dist/v3/queries.d.ts +51 -0
- package/dist/v3/queries.d.ts.map +1 -0
- package/dist/v3/queries.js +128 -0
- package/dist/v3/queries.js.map +1 -0
- package/dist/v3/segments.d.ts +43 -19
- package/dist/v3/segments.d.ts.map +1 -1
- package/dist/v3/segments.js +84 -33
- package/dist/v3/segments.js.map +1 -1
- package/dist/v3/syntax.d.ts +68 -13
- package/dist/v3/syntax.d.ts.map +1 -1
- package/dist/v3/syntax.js +183 -102
- package/dist/v3/syntax.js.map +1 -1
- package/package.json +10 -6
- package/src/client.ts +293 -0
- package/src/core/account.ts +153 -24
- package/src/core/amount.ts +45 -10
- package/src/core/balance.ts +12 -5
- package/src/core/bank-info.ts +29 -5
- package/src/core/client.ts +83 -19
- package/src/core/config.ts +95 -35
- package/src/core/errors.ts +148 -54
- package/src/core/feedback.ts +16 -2
- package/src/core/transaction.ts +22 -4
- package/src/core/transport.ts +153 -32
- package/src/formats/camt.ts +153 -45
- package/src/formats/mt940.ts +244 -122
- package/src/formats/readers.ts +28 -31
- package/src/formats/record-budget.ts +18 -0
- package/src/formats/sepa-purpose.ts +29 -2
- package/src/index.ts +4 -2
- package/src/session/app-approval.ts +51 -38
- package/src/session/dialog-runner.ts +61 -31
- package/src/session/login-guard.ts +189 -87
- package/src/session/sepa-accounts.ts +63 -45
- package/src/session/session-setup.ts +105 -68
- package/src/session/session-state.ts +74 -23
- package/src/session/signed-dialog.ts +222 -0
- package/src/session/tan-selection.ts +50 -39
- package/src/session/user-prompts.ts +62 -18
- package/src/tan/challenge.ts +87 -64
- package/src/tan/flicker.ts +72 -23
- package/src/tan/tan-image.ts +15 -6
- package/src/tan/tan-models.ts +26 -7
- package/src/util/arguments.ts +40 -0
- package/src/util/async.ts +10 -9
- package/src/util/bytes.ts +14 -20
- package/src/util/call-context.ts +3 -2
- package/src/util/dates.ts +64 -33
- package/src/util/errors.ts +22 -6
- package/src/util/immutable-map.ts +15 -12
- package/src/util/inspect.ts +14 -0
- package/src/util/json.ts +16 -0
- package/src/util/text.ts +87 -15
- package/src/util/xml.ts +130 -52
- package/src/v3/account-extension.ts +7 -12
- package/src/v3/bank-connection.ts +126 -0
- package/src/v3/dialog.ts +186 -92
- package/src/v3/message.ts +140 -79
- package/src/v3/parameter-store.ts +226 -0
- package/src/v3/parameters.ts +166 -66
- package/src/v3/protocol.ts +103 -253
- package/src/v3/queries.ts +198 -0
- package/src/v3/segments.ts +86 -31
- package/src/v3/syntax.ts +172 -93
- package/dist/session/bank-connection.d.ts +0 -28
- package/dist/session/bank-connection.d.ts.map +0 -1
- package/dist/session/bank-connection.js +0 -48
- package/dist/session/bank-connection.js.map +0 -1
- package/dist/session/parameter-data.d.ts +0 -83
- package/dist/session/parameter-data.d.ts.map +0 -1
- package/dist/session/parameter-data.js +0 -68
- package/dist/session/parameter-data.js.map +0 -1
- package/dist/session/pin-tan-client.d.ts +0 -54
- package/dist/session/pin-tan-client.d.ts.map +0 -1
- package/dist/session/pin-tan-client.js +0 -153
- package/dist/session/pin-tan-client.js.map +0 -1
- package/dist/session/pin-tan-dialog.d.ts +0 -71
- package/dist/session/pin-tan-dialog.d.ts.map +0 -1
- package/dist/session/pin-tan-dialog.js +0 -124
- package/dist/session/pin-tan-dialog.js.map +0 -1
- package/dist/session/protocol.d.ts +0 -209
- package/dist/session/protocol.d.ts.map +0 -1
- package/dist/session/protocol.js +0 -75
- package/dist/session/protocol.js.map +0 -1
- package/dist/session/response-handler.d.ts +0 -48
- package/dist/session/response-handler.d.ts.map +0 -1
- package/dist/session/response-handler.js +0 -121
- package/dist/session/response-handler.js.map +0 -1
- package/dist/v3/client.d.ts +0 -24
- package/dist/v3/client.d.ts.map +0 -1
- package/dist/v3/client.js +0 -16
- package/dist/v3/client.js.map +0 -1
- package/src/session/bank-connection.ts +0 -51
- package/src/session/parameter-data.ts +0 -137
- package/src/session/pin-tan-client.ts +0 -186
- package/src/session/pin-tan-dialog.ts +0 -160
- package/src/session/protocol.ts +0 -311
- package/src/session/response-handler.ts +0 -130
- package/src/v3/client.ts +0 -29
package/src/v3/protocol.ts
CHANGED
|
@@ -1,112 +1,79 @@
|
|
|
1
1
|
// Internal to the package, and named after the FinTS specification. Documentation is where the meaning is not evident.
|
|
2
2
|
|
|
3
|
-
import type { Account } from '../core/account.js';
|
|
4
|
-
import type { Balance } from '../core/balance.js';
|
|
5
3
|
import type { MessageLogger } from '../core/client.js';
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import { hasErrors } from '../core/feedback.js';
|
|
9
|
-
import type { Transaction, TransactionFormat } from '../core/transaction.js';
|
|
4
|
+
import { requirePinLength, type FinTsConfig } from '../core/config.js';
|
|
5
|
+
import { clientClosedError } from '../core/errors.js';
|
|
10
6
|
import type { FinTsTransport } from '../core/transport.js';
|
|
11
|
-
import { camtTransactions, mt940Transactions } from '../formats/readers.js';
|
|
12
|
-
import { BankConnection, checkMessageSize } from '../session/bank-connection.js';
|
|
13
|
-
import { LoginGuard } from '../session/login-guard.js';
|
|
14
|
-
import { offeredVersion, requireBankParameters } from '../session/parameter-data.js';
|
|
15
|
-
import {
|
|
16
|
-
balanceQuery,
|
|
17
|
-
checkBeforeSigning,
|
|
18
|
-
chooseTransactions,
|
|
19
|
-
type PinTanProtocol,
|
|
20
|
-
type Query,
|
|
21
|
-
type Synchronization,
|
|
22
|
-
} from '../session/protocol.js';
|
|
23
|
-
import type { TanMedium, TanMethod } from '../tan/tan-models.js';
|
|
24
|
-
import { invalidArgument } from '../util/errors.js';
|
|
25
|
-
import { readOptionalString, type JsonObject } from '../util/json.js';
|
|
26
7
|
import { decodeBankText } from '../util/text.js';
|
|
27
|
-
import {
|
|
28
|
-
import { buildMessage, decodeTransport, encodeTransport
|
|
29
|
-
import {
|
|
30
|
-
import {
|
|
31
|
-
import
|
|
8
|
+
import { BankConnection, checkMessageSize } from './bank-connection.js';
|
|
9
|
+
import { buildMessage, decodeTransport, encodeTransport } from './message.js';
|
|
10
|
+
import type { MessageLimits, ParameterStore } from './parameter-store.js';
|
|
11
|
+
import { Segments } from './segments.js';
|
|
12
|
+
import type { SegmentSpec } from './syntax.js';
|
|
32
13
|
|
|
33
14
|
/** Customer ID the specification reserves for anonymous dialogs. */
|
|
34
15
|
const anonymousCustomerId = '9999999999';
|
|
35
16
|
|
|
36
|
-
/**
|
|
37
|
-
|
|
38
|
-
|
|
17
|
+
/**
|
|
18
|
+
* How long the request on its way when the client is closed may take, and then its dialog ends, where the transport
|
|
19
|
+
* takes the abort (`beginClose`).
|
|
20
|
+
*/
|
|
21
|
+
const closingGraceMs = 5000;
|
|
39
22
|
|
|
40
|
-
/**
|
|
41
|
-
export
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
// The message leaves out the value, which may be the PIN.
|
|
45
|
-
if (!isLatin1(text)) throw invalidArgument(`${name} contains characters FinTS 3.0 cannot send (ISO 8859-1 only)`);
|
|
46
|
-
return text;
|
|
23
|
+
/** How a message is signed: the security function of the TAN method and the customer system ID. */
|
|
24
|
+
export interface Signing3 {
|
|
25
|
+
readonly securityFunction: string;
|
|
26
|
+
readonly systemId: string;
|
|
47
27
|
}
|
|
48
28
|
|
|
49
|
-
|
|
50
|
-
|
|
29
|
+
/** Hands out the PIN for each message the protocol signs, and so decides whether one may go out. */
|
|
30
|
+
export interface PinGuard {
|
|
31
|
+
/** The PIN to sign a message with; throws instead where none may go out. */
|
|
32
|
+
readonly pin: string;
|
|
33
|
+
|
|
34
|
+
/** Counts a login signed with the PIN, the first message of a dialog, before it goes out. */
|
|
35
|
+
loginSent(): void;
|
|
51
36
|
}
|
|
52
37
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
requireMaxLength(config.productVersion, maxProductVersionLength, 'productVersion');
|
|
61
|
-
return config;
|
|
38
|
+
/**
|
|
39
|
+
* Throws if `limits` rule out a message of `size` bytes, or the length of `loginPin`, the PIN of a login: `TypeError`
|
|
40
|
+
* for the PIN, which the bank would count as a failed attempt, and `FinTsProtocolError` for the size.
|
|
41
|
+
*/
|
|
42
|
+
function checkLimits(limits: MessageLimits, size: number, loginPin: string | undefined): void {
|
|
43
|
+
if (loginPin !== undefined) requirePinLength(loginPin, limits.pinLength?.min, limits.pinLength?.max);
|
|
44
|
+
checkMessageSize(size, limits.maxMessageSize);
|
|
62
45
|
}
|
|
63
46
|
|
|
64
|
-
/**
|
|
65
|
-
function
|
|
66
|
-
return
|
|
47
|
+
/** Whether `segments` are those of a dialog end, the one message a closing client still sends. */
|
|
48
|
+
function isDialogEnd(segments: readonly SegmentSpec[]): boolean {
|
|
49
|
+
return segments.length === 1 && segments[0]!.type === 'HKEND';
|
|
67
50
|
}
|
|
68
51
|
|
|
69
|
-
/**
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
52
|
+
/**
|
|
53
|
+
* Builds, signs and posts FinTS 3.0 messages (HBCI segment syntax, PIN/TAN security) for the user `parameters.config`
|
|
54
|
+
* names, with the parameter data and IDs `parameters` keeps. Every message signed with the PIN takes it from the
|
|
55
|
+
* `PinGuard` (`post`), which keeps it from going out after a refused login.
|
|
56
|
+
*/
|
|
57
|
+
export class FinTs3Protocol {
|
|
58
|
+
private readonly config: FinTsConfig;
|
|
73
59
|
private readonly connection: BankConnection;
|
|
74
|
-
readonly loginGuard = new LoginGuard();
|
|
75
|
-
|
|
76
|
-
/** Customer system ID the bank assigned in the synchronization. */
|
|
77
|
-
systemId: string | undefined;
|
|
78
|
-
private bpd: Bpd3 | undefined;
|
|
79
|
-
private upd: Upd3 | undefined;
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Throws `TypeError` if the PIN is empty, if the PIN or login data contain characters FinTS 3.0 cannot send (ISO
|
|
83
|
-
* 8859-1 only), or the product ID or version is longer than its field in HKVVB.
|
|
84
|
-
*/
|
|
85
|
-
constructor(config: FinTsConfig, pin: string, transport?: FinTsTransport, logger?: MessageLogger) {
|
|
86
|
-
this.config = requireSendable(config);
|
|
87
|
-
this.pin = requireLatin1(requirePin(pin), 'pin');
|
|
88
|
-
this.connection = new BankConnection(config.url, transport, logger);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
get bankParameters(): Bpd3 | undefined {
|
|
92
|
-
return this.bpd;
|
|
93
|
-
}
|
|
94
60
|
|
|
95
|
-
|
|
96
|
-
return this.upd;
|
|
97
|
-
}
|
|
61
|
+
private closing = false;
|
|
98
62
|
|
|
99
|
-
/**
|
|
100
|
-
|
|
101
|
-
return this.systemId === undefined ? 'required' : 'none';
|
|
102
|
-
}
|
|
63
|
+
/** The error with which the limits last stopped a login (`stoppedLogin`). */
|
|
64
|
+
private stoppedLoginError: unknown;
|
|
103
65
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
66
|
+
constructor(
|
|
67
|
+
readonly parameters: ParameterStore,
|
|
68
|
+
private readonly guard: PinGuard,
|
|
69
|
+
transport?: FinTsTransport,
|
|
70
|
+
logger?: MessageLogger,
|
|
71
|
+
) {
|
|
72
|
+
this.config = parameters.config;
|
|
73
|
+
this.connection = new BankConnection(this.config.url, transport, logger);
|
|
108
74
|
}
|
|
109
75
|
|
|
76
|
+
/** Identification (HKIDN) and processing preparation (HKVVB), which open every dialog. */
|
|
110
77
|
initSegments(systemId: string, anonymous = false): SegmentSpec[] {
|
|
111
78
|
return [
|
|
112
79
|
Segments.identification({
|
|
@@ -117,15 +84,21 @@ export class FinTs3Protocol implements PinTanProtocol<IncomingMessage3, SegmentS
|
|
|
117
84
|
systemIdRequired: !anonymous,
|
|
118
85
|
}),
|
|
119
86
|
Segments.processingPreparation({
|
|
120
|
-
bpdVersion: this.
|
|
121
|
-
updVersion: anonymous ? 0 :
|
|
122
|
-
language: this.
|
|
87
|
+
bpdVersion: this.parameters.reportedBpdVersion,
|
|
88
|
+
updVersion: anonymous ? 0 : this.parameters.reportedUpdVersion,
|
|
89
|
+
language: this.parameters.bankParameters?.dialogLanguage ?? 0,
|
|
123
90
|
productId: this.config.productId,
|
|
124
91
|
productVersion: this.config.productVersion,
|
|
125
92
|
}),
|
|
126
93
|
];
|
|
127
94
|
}
|
|
128
95
|
|
|
96
|
+
/**
|
|
97
|
+
* Sends `segments` as message `number` of the dialog `dialogId` and returns the bank's answer, not yet parsed.
|
|
98
|
+
*
|
|
99
|
+
* With `signing` the message is signed with the PIN, which `PinGuard.pin` hands out, and the `tan`; without, it
|
|
100
|
+
* goes out unsigned, as in an anonymous dialog.
|
|
101
|
+
*/
|
|
129
102
|
async post(message: {
|
|
130
103
|
dialogId: string;
|
|
131
104
|
number: number;
|
|
@@ -133,196 +106,73 @@ export class FinTs3Protocol implements PinTanProtocol<IncomingMessage3, SegmentS
|
|
|
133
106
|
signing: Signing3 | undefined;
|
|
134
107
|
tan: string | undefined;
|
|
135
108
|
}): Promise<Uint8Array> {
|
|
109
|
+
if (this.closing && !isDialogEnd(message.segments)) throw clientClosedError();
|
|
136
110
|
const signing = message.signing;
|
|
137
|
-
|
|
111
|
+
const security =
|
|
112
|
+
signing === undefined
|
|
113
|
+
? undefined
|
|
114
|
+
: {
|
|
115
|
+
countryCode: this.config.countryCode,
|
|
116
|
+
bankCode: this.config.bankCode,
|
|
117
|
+
userId: this.config.userId,
|
|
118
|
+
systemId: signing.systemId,
|
|
119
|
+
pin: this.guard.pin,
|
|
120
|
+
securityFunction: signing.securityFunction,
|
|
121
|
+
};
|
|
122
|
+
// The first message of a signed dialog logs in: from here on the bank may count the PIN.
|
|
123
|
+
const login = security !== undefined && message.number === 1;
|
|
138
124
|
const outgoing = buildMessage({
|
|
139
125
|
dialogId: message.dialogId,
|
|
140
126
|
messageNumber: message.number,
|
|
141
127
|
segments: message.segments,
|
|
142
|
-
security
|
|
143
|
-
signing === undefined
|
|
144
|
-
? undefined
|
|
145
|
-
: {
|
|
146
|
-
countryCode: this.config.countryCode,
|
|
147
|
-
bankCode: this.config.bankCode,
|
|
148
|
-
userId: this.config.userId,
|
|
149
|
-
systemId: signing.systemId,
|
|
150
|
-
pin: this.pin,
|
|
151
|
-
securityFunction: signing.securityFunction,
|
|
152
|
-
},
|
|
128
|
+
security,
|
|
153
129
|
tan: message.tan,
|
|
154
130
|
});
|
|
155
|
-
|
|
131
|
+
this.checkOutgoing(outgoing.bytes.length, login ? security.pin : undefined);
|
|
132
|
+
this.connection.checkSendable();
|
|
156
133
|
this.connection.log('outgoing', () => outgoing.masked);
|
|
134
|
+
if (login) this.guard.loginSent();
|
|
157
135
|
const bytes = decodeTransport(await this.connection.post(encodeTransport(outgoing.bytes), 'text/plain'));
|
|
158
136
|
this.connection.log('incoming', () => decodeBankText(bytes));
|
|
159
137
|
return bytes;
|
|
160
138
|
}
|
|
161
139
|
|
|
162
|
-
keepParameterData(response: IncomingMessage3): void {
|
|
163
|
-
this.keepBankParameters(response);
|
|
164
|
-
this.upd = Upd3.fromSegments(response.segments, this.config.bankCode, this.config.countryCode) ?? this.upd;
|
|
165
|
-
this.systemId = response.find('HISYN')?.text(1) ?? this.systemId;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
private keepBankParameters(response: IncomingMessage3): void {
|
|
169
|
-
this.bpd = Bpd3.fromSegments(response.segments, this.config.bankCode) ?? this.bpd;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
/** Keeps the bank parameter data of an anonymous dialog, and nothing that belongs to a user. */
|
|
173
|
-
async fetchBankParametersAnonymously(): Promise<IncomingMessage3> {
|
|
174
|
-
const response = await this.requestBankParametersAnonymously();
|
|
175
|
-
this.keepBankParameters(response);
|
|
176
|
-
return response;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
140
|
/**
|
|
180
|
-
*
|
|
181
|
-
*
|
|
141
|
+
* Throws if the limits of the parameter data rule out a message of `size` bytes, or the length of `loginPin`, the PIN
|
|
142
|
+
* of a login (`checkLimits`). The later messages of a dialog, its end included, take the PIN the bank has accepted,
|
|
143
|
+
* whatever the parameter data it delivered since say.
|
|
182
144
|
*
|
|
183
|
-
*
|
|
145
|
+
* Remembers the error that stops a login (`stoppedLogin`): the parameter data may be outdated, as saved ones are,
|
|
146
|
+
* and new ones would come only in answer to the login they rule out.
|
|
184
147
|
*/
|
|
185
|
-
private
|
|
186
|
-
let announced: IncomingMessage3;
|
|
148
|
+
private checkOutgoing(size: number, loginPin: string | undefined): void {
|
|
187
149
|
try {
|
|
188
|
-
|
|
150
|
+
checkLimits(this.parameters.limits, size, loginPin);
|
|
189
151
|
} catch (error) {
|
|
190
|
-
if (
|
|
191
|
-
|
|
192
|
-
return this.anonymousDialog(false);
|
|
193
|
-
}
|
|
194
|
-
if (!hasErrors(announced.feedback) || announced.find('HIBPA') !== undefined) return announced;
|
|
195
|
-
return this.anonymousDialog(false);
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
private async anonymousDialog(announceSca: boolean): Promise<IncomingMessage3> {
|
|
199
|
-
const dialog = FinTs3Dialog.anonymous(this);
|
|
200
|
-
try {
|
|
201
|
-
return await dialog.requestBankParameters(announceSca);
|
|
202
|
-
} finally {
|
|
203
|
-
await dialog.end();
|
|
152
|
+
if (loginPin !== undefined) this.stoppedLoginError = error;
|
|
153
|
+
throw error;
|
|
204
154
|
}
|
|
205
155
|
}
|
|
206
156
|
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
combine(first: IncomingMessage3, second: IncomingMessage3): IncomingMessage3 {
|
|
212
|
-
return IncomingMessage3.combine(first, second);
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
// --- Business transactions ---
|
|
216
|
-
|
|
217
|
-
private version(
|
|
218
|
-
transaction: string,
|
|
219
|
-
implemented: readonly number[],
|
|
220
|
-
options: { account?: Account; requiresEntry?: boolean } = {},
|
|
221
|
-
): number | undefined {
|
|
222
|
-
return offeredVersion(this.bpd, this.upd, transaction, new Set(implemented), options);
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
tanMedia(): FinTs3Query<TanMedium[]> | undefined {
|
|
226
|
-
const version = this.version('HKTAB', [4, 5]);
|
|
227
|
-
if (version === undefined) return undefined;
|
|
228
|
-
return {
|
|
229
|
-
order: () => Segments.tanMedia(version),
|
|
230
|
-
read: (pages) => all(pages, 'HITAB').flatMap(parseTanMedia),
|
|
231
|
-
};
|
|
157
|
+
/** Whether `error` is the one with which the limits of the parameter data last stopped a login. */
|
|
158
|
+
stoppedLogin(error: unknown): boolean {
|
|
159
|
+
return this.stoppedLoginError !== undefined && this.stoppedLoginError === error;
|
|
232
160
|
}
|
|
233
161
|
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
return {
|
|
238
|
-
order: (continuation) => Segments.sepaAccounts(version, continuation),
|
|
239
|
-
read: (pages) =>
|
|
240
|
-
all(pages, 'HISPA').flatMap((s) => parseSepaAccounts(s, this.config.countryCode, this.config.bankCode)),
|
|
241
|
-
};
|
|
162
|
+
/** Whether the client is closing, so that only dialog ends go out (`beginClose`). */
|
|
163
|
+
get isClosing(): boolean {
|
|
164
|
+
return this.closing;
|
|
242
165
|
}
|
|
243
166
|
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
read: parseBalance,
|
|
254
|
-
});
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
transactions(
|
|
258
|
-
account: Account,
|
|
259
|
-
format: TransactionFormat,
|
|
260
|
-
from: Date | undefined,
|
|
261
|
-
to: Date | undefined,
|
|
262
|
-
): FinTs3Query<Transaction[]> {
|
|
263
|
-
const request = chooseTransactions(format, account, this.upd, {
|
|
264
|
-
camt: { name: 'HKCAZ', version: this.version('HKCAZ', [1], { account }) },
|
|
265
|
-
camtFormats: requireBankParameters(this.bpd).camtFormats,
|
|
266
|
-
mt940: { name: 'HKKAZ', version: this.version('HKKAZ', [6, 7], { account }) },
|
|
267
|
-
});
|
|
268
|
-
const version = request.version;
|
|
269
|
-
if (request.camt) {
|
|
270
|
-
return {
|
|
271
|
-
order: (continuation) =>
|
|
272
|
-
Segments.transactionsCamt(version, account, request.camtFormats, { from, to, continuation }),
|
|
273
|
-
// The third element group holds the booked documents, the fourth element the pending one.
|
|
274
|
-
read: (pages) =>
|
|
275
|
-
camtTransactions(
|
|
276
|
-
all(pages, 'HICAZ').flatMap((s) =>
|
|
277
|
-
s
|
|
278
|
-
.group(3)
|
|
279
|
-
.filter((d) => !d.isEmpty)
|
|
280
|
-
.map((d) => d.bytes),
|
|
281
|
-
),
|
|
282
|
-
all(pages, 'HICAZ')
|
|
283
|
-
.map((s) => s.binary(4))
|
|
284
|
-
.filter((d) => d !== undefined),
|
|
285
|
-
),
|
|
286
|
-
};
|
|
287
|
-
}
|
|
288
|
-
return {
|
|
289
|
-
order: (continuation) => Segments.transactionsMt940(version, account, { from, to, continuation }),
|
|
290
|
-
// The first element holds the booked transactions, the second the pending ones.
|
|
291
|
-
read: (pages) =>
|
|
292
|
-
mt940Transactions(
|
|
293
|
-
all(pages, 'HIKAZ')
|
|
294
|
-
.map((s) => s.binary(1))
|
|
295
|
-
.filter((d) => d !== undefined),
|
|
296
|
-
all(pages, 'HIKAZ')
|
|
297
|
-
.map((s) => s.binary(2))
|
|
298
|
-
.filter((d) => d !== undefined),
|
|
299
|
-
request.currency,
|
|
300
|
-
),
|
|
301
|
-
};
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
// --- Saved state ---
|
|
305
|
-
|
|
306
|
-
saveState(): JsonObject {
|
|
307
|
-
return {
|
|
308
|
-
systemId: this.systemId ?? null,
|
|
309
|
-
bpd: this.bpd === undefined ? null : encodeSegments(this.bpd.segments),
|
|
310
|
-
upd: this.upd === undefined ? null : encodeSegments(this.upd.segments),
|
|
311
|
-
};
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
restoreState(saved: JsonObject): void {
|
|
315
|
-
const bpd = readOptionalString(saved, 'bpd');
|
|
316
|
-
const upd = readOptionalString(saved, 'upd');
|
|
317
|
-
const restoredSystemId = readOptionalString(saved, 'systemId');
|
|
318
|
-
const restoredBpd = bpd === undefined ? undefined : Bpd3.fromSegments(decodeSegments(bpd), this.config.bankCode);
|
|
319
|
-
const restoredUpd =
|
|
320
|
-
upd === undefined
|
|
321
|
-
? undefined
|
|
322
|
-
: Upd3.fromSegments(decodeSegments(upd), this.config.bankCode, this.config.countryCode);
|
|
323
|
-
this.systemId = restoredSystemId;
|
|
324
|
-
this.bpd = restoredBpd;
|
|
325
|
-
this.upd = restoredUpd;
|
|
167
|
+
/**
|
|
168
|
+
* Sends nothing but dialog ends from now on: any other message fails with `FinTsStateError` before it goes out, so
|
|
169
|
+
* that a call under way stops at its next one. The request on its way has `closingGraceMs` to bring its answer, which
|
|
170
|
+
* counts as any other, and is aborted then; the dialog ends have as long again once it is over, and none goes out
|
|
171
|
+
* later. The client calls it as soon as it is closed, and `close` once it has ended its dialog.
|
|
172
|
+
*/
|
|
173
|
+
beginClose(): void {
|
|
174
|
+
this.closing = true;
|
|
175
|
+
this.connection.abortRequestsAfter(closingGraceMs);
|
|
326
176
|
}
|
|
327
177
|
|
|
328
178
|
close(): void {
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
// Internal to the package, and named after the FinTS specification. Documentation is where the meaning is not evident.
|
|
2
|
+
|
|
3
|
+
import type { Account } from '../core/account.js';
|
|
4
|
+
import type { Balance } from '../core/balance.js';
|
|
5
|
+
import { FinTsBankError, FinTsProtocolError, FinTsUnsupportedError } from '../core/errors.js';
|
|
6
|
+
import type { FinTsFeedback } from '../core/feedback.js';
|
|
7
|
+
import type { Transaction, TransactionFormat } from '../core/transaction.js';
|
|
8
|
+
import { camtTransactions, mt940Transactions } from '../formats/readers.js';
|
|
9
|
+
import type { TanMedium } from '../tan/tan-models.js';
|
|
10
|
+
import type { IncomingMessage3 } from './message.js';
|
|
11
|
+
import type { ParameterStore } from './parameter-store.js';
|
|
12
|
+
import { lists, offeredVersion, requireBankParameters } from './parameters.js';
|
|
13
|
+
import { balanceAccount, camtAccount, parseBalance, parseSepaAccounts, parseTanMedia, Segments } from './segments.js';
|
|
14
|
+
import type { Segment, SegmentSpec } from './syntax.js';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* A business transaction: the order to send for each page, and how to read all pages the bank sent.
|
|
18
|
+
*
|
|
19
|
+
* Where the bank does not offer the transaction, the builders of the lookups the session makes for itself, of the TAN
|
|
20
|
+
* media and the SEPA accounts, return `undefined`, and those of the app's queries, of a balance and of transactions,
|
|
21
|
+
* throw `FinTsUnsupportedError`.
|
|
22
|
+
*/
|
|
23
|
+
export interface Query<T> {
|
|
24
|
+
/** The order for the page at `continuation`; `undefined` for the first page. */
|
|
25
|
+
readonly order: (continuation: string | undefined) => SegmentSpec;
|
|
26
|
+
|
|
27
|
+
/** Reads the result; throws `FormatError` for malformed data. */
|
|
28
|
+
readonly read: (pages: readonly IncomingMessage3[]) => T;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** The segments of `type` in all `pages`. */
|
|
32
|
+
function all(pages: readonly IncomingMessage3[], type: string): Segment[] {
|
|
33
|
+
return pages.flatMap((p) => p.findAll(type));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function version(
|
|
37
|
+
parameters: ParameterStore,
|
|
38
|
+
transaction: string,
|
|
39
|
+
implemented: readonly number[],
|
|
40
|
+
options: { account?: Account; requiresEntry?: boolean } = {},
|
|
41
|
+
): number | undefined {
|
|
42
|
+
return offeredVersion(
|
|
43
|
+
parameters.bankParameters,
|
|
44
|
+
parameters.userParameters,
|
|
45
|
+
transaction,
|
|
46
|
+
new Set(implemented),
|
|
47
|
+
options,
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Lists the TAN media, and keeps the names as the bank sent them in `parameters`; `undefined` if the bank does not. */
|
|
52
|
+
export function tanMediaQuery(parameters: ParameterStore): Query<TanMedium[]> | undefined {
|
|
53
|
+
const offered = version(parameters, 'HKTAB', [4, 5]);
|
|
54
|
+
if (offered === undefined) return undefined;
|
|
55
|
+
return {
|
|
56
|
+
order: () => Segments.tanMedia(offered),
|
|
57
|
+
read: (pages) => {
|
|
58
|
+
const names = new Map<string, string>();
|
|
59
|
+
const media = all(pages, 'HITAB').flatMap((s) => parseTanMedia(s, names));
|
|
60
|
+
parameters.keepTanMediumNames(names);
|
|
61
|
+
return media;
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** Lists IBAN and BIC of the accounts; `undefined` if the bank does not offer it. */
|
|
67
|
+
export function sepaAccountsQuery(parameters: ParameterStore): Query<Account[]> | undefined {
|
|
68
|
+
const offered = version(parameters, 'HKSPA', [1, 2, 3], { requiresEntry: true });
|
|
69
|
+
if (offered === undefined) return undefined;
|
|
70
|
+
const { countryCode, bankCode } = parameters.config;
|
|
71
|
+
return {
|
|
72
|
+
order: (continuation) => Segments.sepaAccounts(offered, continuation),
|
|
73
|
+
read: (pages) => all(pages, 'HISPA').flatMap((s) => parseSepaAccounts(s, countryCode, bankCode)),
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* The balance (HISAL) of `account` in `records`: the one whose account matches. A single record must match as well,
|
|
79
|
+
* though the query asked for this one account only: it names the account it is for.
|
|
80
|
+
*
|
|
81
|
+
* Throws `FinTsBankError` with the bank's `feedback` if there is none, and `FinTsProtocolError` if none matches.
|
|
82
|
+
*
|
|
83
|
+
* @internal Exported for the tests.
|
|
84
|
+
*/
|
|
85
|
+
export function balanceRecord(
|
|
86
|
+
records: readonly Segment[],
|
|
87
|
+
account: Account,
|
|
88
|
+
feedback: readonly FinTsFeedback[],
|
|
89
|
+
): Segment {
|
|
90
|
+
if (records.length === 0) throw new FinTsBankError(feedback, 'No balance returned');
|
|
91
|
+
const match = records.find((record) => balanceAccount(record).matches(account));
|
|
92
|
+
if (match === undefined) {
|
|
93
|
+
throw new FinTsProtocolError('The bank returned balances, but none for the requested account');
|
|
94
|
+
}
|
|
95
|
+
return match;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* The balance of `account`, which the session has taken as the bank knows it, with the transactions the bank permits
|
|
100
|
+
* for it (`SepaAccounts.complete`); throws `FinTsUnsupportedError` if the bank does not report balances.
|
|
101
|
+
*/
|
|
102
|
+
export function balanceQuery(parameters: ParameterStore, account: Account): Query<Balance> {
|
|
103
|
+
const offered = version(parameters, 'HKSAL', [6, 7, 8], { account });
|
|
104
|
+
if (offered === undefined) {
|
|
105
|
+
throw new FinTsUnsupportedError('The bank reports no balance (HKSAL) for this account');
|
|
106
|
+
}
|
|
107
|
+
const nationalAllowed = requireBankParameters(parameters.bankParameters).nationalAccountAllowed;
|
|
108
|
+
return {
|
|
109
|
+
order: (continuation) => Segments.balance(offered, account, nationalAllowed, continuation),
|
|
110
|
+
read: (pages) =>
|
|
111
|
+
parseBalance(
|
|
112
|
+
balanceRecord(
|
|
113
|
+
all(pages, 'HISAL'),
|
|
114
|
+
account,
|
|
115
|
+
pages.flatMap((p) => p.feedback),
|
|
116
|
+
),
|
|
117
|
+
account,
|
|
118
|
+
),
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* The transactions of `account` in `format`, from the day of `from` to that of `to`. The session has taken `account` as
|
|
124
|
+
* the bank knows it, with the transactions the bank permits for it and its currency (`SepaAccounts.complete`).
|
|
125
|
+
*
|
|
126
|
+
* The client reads camt.052 only, so camt counts as offered only where the bank offers a camt.052 format. With `auto`
|
|
127
|
+
* the client takes camt where the bank offers it, unless MT940 can be requested for the account and the user parameter
|
|
128
|
+
* data list only MT940 transactions for it.
|
|
129
|
+
*
|
|
130
|
+
* Throws `FinTsUnsupportedError` if the bank does not offer the chosen format for the account.
|
|
131
|
+
*/
|
|
132
|
+
export function transactionsQuery(
|
|
133
|
+
parameters: ParameterStore,
|
|
134
|
+
account: Account,
|
|
135
|
+
format: TransactionFormat,
|
|
136
|
+
from: Date | undefined,
|
|
137
|
+
to: Date | undefined,
|
|
138
|
+
): Query<Transaction[]> {
|
|
139
|
+
const bpd = requireBankParameters(parameters.bankParameters);
|
|
140
|
+
const camtVersion = bpd.camtFormats.length === 0 ? undefined : version(parameters, 'HKCAZ', [1], { account });
|
|
141
|
+
const mt940Version = version(parameters, 'HKKAZ', [6, 7], { account });
|
|
142
|
+
const camt =
|
|
143
|
+
format === 'camt' ||
|
|
144
|
+
(format === 'auto' &&
|
|
145
|
+
camtVersion !== undefined &&
|
|
146
|
+
(mt940Version === undefined || lists(account, 'HKCAZ') || !lists(account, 'HKKAZ')));
|
|
147
|
+
const offered = camt ? camtVersion : mt940Version;
|
|
148
|
+
if (offered === undefined) {
|
|
149
|
+
throw new FinTsUnsupportedError(
|
|
150
|
+
`The bank offers no ${camt ? 'camt ' : ''}transactions (${camt ? 'HKCAZ' : 'HKKAZ'}) for this account`,
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
if (camt) {
|
|
154
|
+
return {
|
|
155
|
+
order: (continuation) =>
|
|
156
|
+
Segments.transactionsCamt(offered, account, bpd.nationalAccountAllowed, bpd.camtFormats, {
|
|
157
|
+
from,
|
|
158
|
+
to,
|
|
159
|
+
continuation,
|
|
160
|
+
}),
|
|
161
|
+
// The first element names the account, the third element group holds the booked documents, the fourth
|
|
162
|
+
// element the pending one: binary data, which a bank may send as text instead.
|
|
163
|
+
read: (pages) => {
|
|
164
|
+
const segments = all(pages, 'HICAZ');
|
|
165
|
+
if (!segments.every((s) => camtAccount(s).matches(account))) {
|
|
166
|
+
throw new FinTsProtocolError('The bank returned the transactions of another account than the one asked for');
|
|
167
|
+
}
|
|
168
|
+
return camtTransactions(
|
|
169
|
+
segments.flatMap((s) =>
|
|
170
|
+
s
|
|
171
|
+
.group(3)
|
|
172
|
+
.filter((d) => !d.isEmpty)
|
|
173
|
+
.map((d) => d.bytes),
|
|
174
|
+
),
|
|
175
|
+
segments.map((s) => s.bytes(4)).filter((d) => d !== undefined),
|
|
176
|
+
);
|
|
177
|
+
},
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
return {
|
|
181
|
+
order: (continuation) =>
|
|
182
|
+
Segments.transactionsMt940(offered, account, bpd.nationalAccountAllowed, { from, to, continuation }),
|
|
183
|
+
// The first element holds the booked transactions, the second the pending ones: binary data, which a bank may send
|
|
184
|
+
// as text instead. Unlike HICAZ, HIKAZ names no account, and banks write the account line of a statement (`:25:`)
|
|
185
|
+
// in many ways, so it is not compared with `account`: a strict comparison would fail every query of such a bank.
|
|
186
|
+
read: (pages) =>
|
|
187
|
+
mt940Transactions(
|
|
188
|
+
all(pages, 'HIKAZ')
|
|
189
|
+
.map((s) => s.bytes(1))
|
|
190
|
+
.filter((d) => d !== undefined),
|
|
191
|
+
all(pages, 'HIKAZ')
|
|
192
|
+
.map((s) => s.bytes(2))
|
|
193
|
+
.filter((d) => d !== undefined),
|
|
194
|
+
// The currency of statements that state none.
|
|
195
|
+
account.currency,
|
|
196
|
+
),
|
|
197
|
+
};
|
|
198
|
+
}
|