@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/dist/util/xml.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { FormatError } from './errors.js';
|
|
2
|
+
import { characterReference, nonBlank } from './text.js';
|
|
2
3
|
/**
|
|
3
4
|
* An element of a parsed XML document, looked up by local name: camt documents come with and without namespace
|
|
4
5
|
* prefixes.
|
|
@@ -10,7 +11,7 @@ export class XmlElement {
|
|
|
10
11
|
constructor(
|
|
11
12
|
/** The name without namespace prefix. */
|
|
12
13
|
localName,
|
|
13
|
-
/** The attributes by name
|
|
14
|
+
/** The attributes by name, namespace prefix and all. */
|
|
14
15
|
attributes) {
|
|
15
16
|
this.localName = localName;
|
|
16
17
|
this.attributes = attributes;
|
|
@@ -22,12 +23,13 @@ export class XmlElement {
|
|
|
22
23
|
get innerText() {
|
|
23
24
|
return this.children.map((c) => (c instanceof XmlElement ? c.innerText : c)).join('');
|
|
24
25
|
}
|
|
25
|
-
|
|
26
|
-
|
|
26
|
+
/** The attribute called `name`: an unprefixed name finds no prefixed attribute, which is of another namespace. */
|
|
27
|
+
getAttribute(name) {
|
|
28
|
+
return this.attributes.get(name);
|
|
27
29
|
}
|
|
28
30
|
/** The first child element called `localName`. */
|
|
29
31
|
child(localName) {
|
|
30
|
-
return this.
|
|
32
|
+
return this.children.find((c) => c instanceof XmlElement && c.localName === localName);
|
|
31
33
|
}
|
|
32
34
|
/** The element reached by following child names along `path`; this element for an empty path. */
|
|
33
35
|
at(path) {
|
|
@@ -35,67 +37,111 @@ export class XmlElement {
|
|
|
35
37
|
}
|
|
36
38
|
/** The trimmed text of the element at `path`, or `undefined` if it is missing or empty. */
|
|
37
39
|
textAt(path) {
|
|
38
|
-
|
|
39
|
-
return text === undefined || text === '' ? undefined : text;
|
|
40
|
+
return nonBlank(this.at(path)?.innerText);
|
|
40
41
|
}
|
|
41
|
-
/**
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
const visit = (element) => {
|
|
45
|
-
for (const c of element.childElements) {
|
|
46
|
-
if (c.localName === localName)
|
|
47
|
-
found.push(c);
|
|
48
|
-
visit(c);
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
visit(this);
|
|
52
|
-
return found;
|
|
42
|
+
/** The child elements called `localName`, in document order. */
|
|
43
|
+
childrenNamed(localName) {
|
|
44
|
+
return this.children.filter((c) => c instanceof XmlElement && c.localName === localName);
|
|
53
45
|
}
|
|
54
46
|
}
|
|
55
|
-
|
|
56
|
-
const
|
|
47
|
+
/** The characters an XML name starts with (XML 1.0, production 4). */
|
|
48
|
+
const nameStartCharacters = String.raw `:A-Z_a-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\u{10000}-\u{EFFFF}`;
|
|
49
|
+
/**
|
|
50
|
+
* An XML name (XML 1.0, production 5). The combining marks lead the class of the characters after the first: after
|
|
51
|
+
* another one, ESLint's `no-misleading-character-class` takes them for a combined character.
|
|
52
|
+
*/
|
|
53
|
+
const xmlName = String.raw `[${nameStartCharacters}][\u0300-\u036F${nameStartCharacters}\-.0-9\u00B7\u203F-\u2040]*`;
|
|
54
|
+
const namePattern = new RegExp(xmlName, 'uy');
|
|
55
|
+
/**
|
|
56
|
+
* White space to Unicode, U+0085 (NEL) among them, which separates the parts of a tag, and `<?xml` of the rest of the
|
|
57
|
+
* XML declaration, as the Dart package has it.
|
|
58
|
+
*/
|
|
59
|
+
const blank = String.raw `[\s\u0085]`;
|
|
60
|
+
const blankPattern = new RegExp(blank);
|
|
61
|
+
const attributePattern = new RegExp(String.raw `${blank}+(${xmlName})${blank}*=${blank}*(?:"([^"<]*)"|'([^'<]*)')`, 'uy');
|
|
62
|
+
/** The start of the XML declaration, whose content is not read. */
|
|
63
|
+
const declarationPattern = new RegExp(String.raw `<\?xml(?:${blank}|\?>)`, 'y');
|
|
64
|
+
/** The text of a reference after its `&`, up to the `;` that ends it. */
|
|
65
|
+
const referenceNamePattern = /[^;&\s]*/y;
|
|
57
66
|
/** The match of the sticky `pattern` at `position` in `text`. */
|
|
58
67
|
function matchAt(pattern, text, position) {
|
|
59
68
|
pattern.lastIndex = position;
|
|
60
69
|
return pattern.exec(text);
|
|
61
70
|
}
|
|
62
|
-
const predefinedEntities =
|
|
71
|
+
const predefinedEntities = new Map([
|
|
72
|
+
['amp', '&'],
|
|
73
|
+
['lt', '<'],
|
|
74
|
+
['gt', '>'],
|
|
75
|
+
['quot', '"'],
|
|
76
|
+
['apos', "'"],
|
|
77
|
+
]);
|
|
78
|
+
/** Deepest nesting of elements the parser takes: camt needs fewer than 20 levels, and `innerText` recurses. */
|
|
79
|
+
const maxDepth = 100;
|
|
80
|
+
/**
|
|
81
|
+
* Most nodes besides text a document may hold, unless it is long enough for one node per `charactersPerNode`
|
|
82
|
+
* characters: real camt spends 16 to 40 characters on each, while nodes as short as `<a/>` take a hundred times their
|
|
83
|
+
* length in memory.
|
|
84
|
+
*/
|
|
85
|
+
const maxNodes = 500_000;
|
|
86
|
+
const charactersPerNode = 16;
|
|
87
|
+
const noAttributes = new Map();
|
|
88
|
+
/** The name without namespace prefix; `:a` has none, but is no unprefixed `a` either. */
|
|
63
89
|
function localNameOf(qualified) {
|
|
64
90
|
const colon = qualified.indexOf(':');
|
|
65
|
-
return colon
|
|
91
|
+
return colon > 0 ? qualified.substring(colon + 1) : qualified;
|
|
66
92
|
}
|
|
67
|
-
/**
|
|
93
|
+
/**
|
|
94
|
+
* Resolves the character and predefined entity references in `text`; throws `FormatError` for any other, at the first.
|
|
95
|
+
* A global `replace` would find all of them before it looked at the first: a gigabyte for megabytes of `&`.
|
|
96
|
+
*/
|
|
68
97
|
function decodeEntities(text) {
|
|
69
|
-
|
|
70
|
-
|
|
98
|
+
let decoded = '';
|
|
99
|
+
let position = 0;
|
|
100
|
+
for (let ampersand = text.indexOf('&'); ampersand >= 0; ampersand = text.indexOf('&', position)) {
|
|
101
|
+
const name = matchAt(referenceNamePattern, text, ampersand + 1)[0];
|
|
102
|
+
const end = ampersand + 1 + name.length;
|
|
103
|
+
if (text.charAt(end) !== ';')
|
|
71
104
|
throw new FormatError('Invalid XML: unterminated entity reference');
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
105
|
+
decoded += text.substring(position, ampersand) + resolved(name, text.substring(ampersand, end + 1));
|
|
106
|
+
position = end + 1;
|
|
107
|
+
}
|
|
108
|
+
return position === 0 ? text : decoded + text.substring(position);
|
|
109
|
+
}
|
|
110
|
+
/** The text the `reference` called `name` stands for. */
|
|
111
|
+
function resolved(name, reference) {
|
|
112
|
+
if (name.startsWith('#')) {
|
|
113
|
+
const character = characterReference(name);
|
|
114
|
+
if (character === undefined)
|
|
115
|
+
throw new FormatError('Invalid XML character reference', reference);
|
|
116
|
+
return character;
|
|
117
|
+
}
|
|
118
|
+
const value = predefinedEntities.get(name);
|
|
119
|
+
if (value === undefined)
|
|
120
|
+
throw new FormatError('Invalid XML: unknown entity', reference);
|
|
121
|
+
return value;
|
|
86
122
|
}
|
|
87
123
|
/**
|
|
88
|
-
* Parses an XML document and returns its root element; throws `FormatError` if it is not well-formed
|
|
124
|
+
* Parses an XML document and returns its root element; throws `FormatError` if it is not well-formed, nests elements
|
|
125
|
+
* deeper than 100 levels, or holds more than 500,000 nodes besides text (elements, attributes, comments, processing
|
|
126
|
+
* instructions, the XML declaration and CDATA sections) or one per 16 characters, whichever is more.
|
|
89
127
|
*
|
|
90
128
|
* A document type declaration is refused: bank data have none, and its entities could expand without limit.
|
|
91
129
|
*/
|
|
92
130
|
export function parseXml(xml) {
|
|
93
131
|
let position = 0;
|
|
94
132
|
const stack = [];
|
|
133
|
+
const openNames = [];
|
|
95
134
|
let root;
|
|
135
|
+
let declared = false;
|
|
136
|
+
let nodes = 0;
|
|
137
|
+
const nodeLimit = Math.max(maxNodes, Math.floor(xml.length / charactersPerNode));
|
|
96
138
|
const fail = (reason) => {
|
|
97
139
|
throw new FormatError(`Invalid XML: ${reason} at position ${position}`);
|
|
98
140
|
};
|
|
141
|
+
const countNode = () => {
|
|
142
|
+
if (++nodes > nodeLimit)
|
|
143
|
+
fail(`more than ${nodeLimit} nodes`);
|
|
144
|
+
};
|
|
99
145
|
const skipPast = (terminator, what) => {
|
|
100
146
|
const end = xml.indexOf(terminator, position);
|
|
101
147
|
if (end < 0)
|
|
@@ -107,22 +153,42 @@ export function parseXml(xml) {
|
|
|
107
153
|
const textEnd = lt < 0 ? xml.length : lt;
|
|
108
154
|
if (textEnd > position) {
|
|
109
155
|
const text = xml.substring(position, textEnd);
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
156
|
+
// Blanks are dropped only where they follow no text, as between elements: kept, they would double the nodes of a
|
|
157
|
+
// document with line breaks. Between two texts they are content, and a counted node separates the two.
|
|
158
|
+
if (nonBlank(text) !== undefined || typeof stack.at(-1)?.children.at(-1) === 'string') {
|
|
159
|
+
(stack.at(-1) ?? fail('text outside the root element')).children.push(decodeEntities(text));
|
|
160
|
+
}
|
|
115
161
|
position = textEnd;
|
|
116
162
|
continue;
|
|
117
163
|
}
|
|
118
164
|
if (xml.startsWith('<?', position)) {
|
|
165
|
+
countNode();
|
|
166
|
+
if (matchAt(declarationPattern, xml, position)) {
|
|
167
|
+
if (root)
|
|
168
|
+
fail('XML declaration inside or after the root element');
|
|
169
|
+
if (declared)
|
|
170
|
+
fail('a second XML declaration');
|
|
171
|
+
declared = true;
|
|
172
|
+
}
|
|
173
|
+
else {
|
|
174
|
+
position += 2;
|
|
175
|
+
const target = matchAt(namePattern, xml, position)?.[0] ?? fail('missing processing instruction target');
|
|
176
|
+
position += target.length;
|
|
177
|
+
if (!xml.startsWith('?>', position) && !blankPattern.test(xml.charAt(position))) {
|
|
178
|
+
fail('malformed processing instruction');
|
|
179
|
+
}
|
|
180
|
+
}
|
|
119
181
|
skipPast('?>', 'processing instruction');
|
|
120
182
|
}
|
|
121
183
|
else if (xml.startsWith('<!--', position)) {
|
|
184
|
+
countNode();
|
|
185
|
+
// Past the `<!--`, whose dashes end no comment: `<!-->` starts one.
|
|
186
|
+
position += 4;
|
|
122
187
|
skipPast('-->', 'comment');
|
|
123
188
|
}
|
|
124
189
|
else if (xml.startsWith('<![CDATA[', position)) {
|
|
125
190
|
const parent = stack.at(-1) ?? fail('CDATA outside the root element');
|
|
191
|
+
countNode();
|
|
126
192
|
const start = position + 9;
|
|
127
193
|
skipPast(']]>', 'CDATA section');
|
|
128
194
|
parent.children.push(xml.substring(start, position - 3));
|
|
@@ -134,37 +200,42 @@ export function parseXml(xml) {
|
|
|
134
200
|
position += 2;
|
|
135
201
|
const name = matchAt(namePattern, xml, position)?.[0] ?? fail('missing end tag name');
|
|
136
202
|
position += name.length;
|
|
137
|
-
while (
|
|
203
|
+
while (blankPattern.test(xml.charAt(position)))
|
|
138
204
|
position++;
|
|
139
205
|
if (xml.charAt(position) !== '>')
|
|
140
206
|
fail('malformed end tag');
|
|
141
207
|
position++;
|
|
142
|
-
|
|
143
|
-
if (
|
|
208
|
+
stack.pop();
|
|
209
|
+
if (openNames.pop() !== name)
|
|
144
210
|
fail(`unexpected end tag ${name}`);
|
|
145
211
|
}
|
|
146
212
|
else {
|
|
213
|
+
if (stack.length >= maxDepth)
|
|
214
|
+
fail(`elements nested deeper than ${maxDepth} levels`);
|
|
215
|
+
countNode();
|
|
147
216
|
position++;
|
|
148
217
|
const name = matchAt(namePattern, xml, position)?.[0] ?? fail('missing element name');
|
|
149
218
|
position += name.length;
|
|
150
|
-
|
|
219
|
+
let attributes;
|
|
151
220
|
for (;;) {
|
|
152
221
|
const attribute = matchAt(attributePattern, xml, position);
|
|
153
222
|
if (!attribute)
|
|
154
223
|
break;
|
|
155
224
|
position += attribute[0].length;
|
|
225
|
+
countNode();
|
|
156
226
|
const attributeName = attribute[1];
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
227
|
+
attributes ??= new Map();
|
|
228
|
+
if (attributes.has(attributeName))
|
|
229
|
+
fail(`duplicate attribute ${attributeName}`);
|
|
230
|
+
attributes.set(attributeName, decodeEntities(attribute[2] ?? attribute[3] ?? ''));
|
|
160
231
|
}
|
|
161
|
-
while (
|
|
232
|
+
while (blankPattern.test(xml.charAt(position)))
|
|
162
233
|
position++;
|
|
163
234
|
const selfClosing = xml.startsWith('/>', position);
|
|
164
235
|
if (!selfClosing && xml.charAt(position) !== '>')
|
|
165
236
|
fail(`malformed start tag ${name}`);
|
|
166
237
|
position += selfClosing ? 2 : 1;
|
|
167
|
-
const element = new XmlElement(localNameOf(name), attributes);
|
|
238
|
+
const element = new XmlElement(localNameOf(name), attributes ?? noAttributes);
|
|
168
239
|
const parent = stack.at(-1);
|
|
169
240
|
if (parent)
|
|
170
241
|
parent.children.push(element);
|
|
@@ -172,12 +243,14 @@ export function parseXml(xml) {
|
|
|
172
243
|
fail('a second root element');
|
|
173
244
|
else
|
|
174
245
|
root = element;
|
|
175
|
-
if (!selfClosing)
|
|
246
|
+
if (!selfClosing) {
|
|
176
247
|
stack.push(element);
|
|
248
|
+
openNames.push(name);
|
|
249
|
+
}
|
|
177
250
|
}
|
|
178
251
|
}
|
|
179
252
|
if (stack.length > 0)
|
|
180
|
-
fail(`unclosed element ${
|
|
253
|
+
fail(`unclosed element ${openNames.at(-1)}`);
|
|
181
254
|
return root ?? fail('no root element');
|
|
182
255
|
}
|
|
183
256
|
//# sourceMappingURL=xml.js.map
|
package/dist/util/xml.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"xml.js","sourceRoot":"","sources":["../../src/util/xml.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"xml.js","sourceRoot":"","sources":["../../src/util/xml.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,kBAAkB,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAEzD;;;GAGG;AACH,MAAM,OAAO,UAAU;IAKV;IAEA;IANF,QAAQ,GAA4B,EAAE,CAAC;IAEhD;IACE,yCAAyC;IAChC,SAAiB;IAC1B,wDAAwD;IAC/C,UAAuC;QAFvC,cAAS,GAAT,SAAS,CAAQ;QAEjB,eAAU,GAAV,UAAU,CAA6B;IAC/C,CAAC;IAEJ,IAAI,aAAa;QACf,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,EAAmB,EAAE,CAAC,CAAC,YAAY,UAAU,CAAC,CAAC;IAC/E,CAAC;IAED,iDAAiD;IACjD,IAAI,SAAS;QACX,OAAO,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,YAAY,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACxF,CAAC;IAED,kHAAkH;IAClH,YAAY,CAAC,IAAY;QACvB,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACnC,CAAC;IAED,kDAAkD;IAClD,KAAK,CAAC,SAAiB;QACrB,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAmB,EAAE,CAAC,CAAC,YAAY,UAAU,IAAI,CAAC,CAAC,SAAS,K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AAE,KAAK,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAErE,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"account-extension.d.ts","sourceRoot":"","sources":["../../src/v3/account-extension.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,KAAK,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAErE,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAyB7C;;;GAGG;AACH,qBAAa,gBAAgB;IAEzB,kFAAkF;IAClF,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS;IAChC,oDAAoD;IACpD,QAAQ,CAAC,MAAM,EAAE,iBAAiB;IAClC,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,iFAAiF;IACjF,OAAO,CAAC,QAAQ,CAAC,eAAe;IAPlC,OAAO;IAUP;;;OAGG;IACH,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,gBAAgB,GAAG,SAAS;IAU3D,OAAO,CAAC,MAAM,CAAC,IAAI;IAgBnB,6GAA6G;IAC7G,eAAe,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,GAAG,SAAS;CAkBvD"}
|
|
@@ -3,7 +3,9 @@ import { AccountDataStatus } from '../core/account.js';
|
|
|
3
3
|
import { Amount, withMark } from '../core/amount.js';
|
|
4
4
|
import { Balance } from '../core/balance.js';
|
|
5
5
|
import { parseFintsDate, parseUtcPlusOneDateTime } from '../util/dates.js';
|
|
6
|
-
import { FormatError } from '../util/errors.js';
|
|
6
|
+
import { fail, FormatError } from '../util/errors.js';
|
|
7
|
+
import { isJsonObject } from '../util/json.js';
|
|
8
|
+
import { nonBlank } from '../util/text.js';
|
|
7
9
|
/**
|
|
8
10
|
* The account extension of the user parameter data (HIUPD "Erweiterung, kontobezogen", Formals E.3.1): JSON with the
|
|
9
11
|
* BIC, the balance, and what the bank tells about the data it holds for the account.
|
|
@@ -32,7 +34,7 @@ export class AccountExtension {
|
|
|
32
34
|
static tryParse(json) {
|
|
33
35
|
try {
|
|
34
36
|
const decoded = JSON.parse(json);
|
|
35
|
-
return
|
|
37
|
+
return isJsonObject(decoded) ? AccountExtension.read(new Json(decoded)) : undefined;
|
|
36
38
|
}
|
|
37
39
|
catch (error) {
|
|
38
40
|
if (error instanceof FormatError || error instanceof SyntaxError)
|
|
@@ -57,6 +59,7 @@ export class AccountExtension {
|
|
|
57
59
|
return undefined;
|
|
58
60
|
return new Balance({
|
|
59
61
|
account,
|
|
62
|
+
productName: account.productName,
|
|
60
63
|
booked: b.booked.amount,
|
|
61
64
|
bookedAsOf: b.booked.date,
|
|
62
65
|
bookedAsOfTime: b.booked.time,
|
|
@@ -109,12 +112,6 @@ function moment(json, defaultTime) {
|
|
|
109
112
|
return undefined;
|
|
110
113
|
return parseUtcPlusOneDateTime(json.string('Date'), time) ?? fail('Extension date or time is malformed');
|
|
111
114
|
}
|
|
112
|
-
function fail(message) {
|
|
113
|
-
throw new FormatError(message);
|
|
114
|
-
}
|
|
115
|
-
function isObject(value) {
|
|
116
|
-
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
117
|
-
}
|
|
118
115
|
/**
|
|
119
116
|
* A JSON object of the extension, read by key without regard to case: the specification itself spells some keys
|
|
120
117
|
* differently (`OverDraftLim` and `OverdraftLim`). Values of the wrong type are a `FormatError`.
|
|
@@ -134,7 +131,7 @@ class Json {
|
|
|
134
131
|
if (value === undefined || value === null)
|
|
135
132
|
return undefined;
|
|
136
133
|
if (typeof value === 'string')
|
|
137
|
-
return
|
|
134
|
+
return nonBlank(value);
|
|
138
135
|
if (typeof value === 'number')
|
|
139
136
|
return String(value);
|
|
140
137
|
throw new FormatError(`Extension element "${key}" is not text`);
|
|
@@ -153,7 +150,7 @@ class Json {
|
|
|
153
150
|
const value = this.value(key);
|
|
154
151
|
if (value === undefined || value === null)
|
|
155
152
|
return undefined;
|
|
156
|
-
if (
|
|
153
|
+
if (isJsonObject(value))
|
|
157
154
|
return new Json(value);
|
|
158
155
|
throw new FormatError(`Extension element "${key}" is not an object`);
|
|
159
156
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"account-extension.js","sourceRoot":"","sources":["../../src/v3/account-extension.ts"],"names":[],"mappings":"AAAA,uHAAuH;AAEvH,OAAO,EAAE,iBAAiB,EAAgB,MAAM,oBAAoB,CAAC;AACrE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AAC3E,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"account-extension.js","sourceRoot":"","sources":["../../src/v3/account-extension.ts"],"names":[],"mappings":"AAAA,uHAAuH;AAEvH,OAAO,EAAE,iBAAiB,EAAgB,MAAM,oBAAoB,CAAC;AACrE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AAC3E,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAqB3C;;;GAGG;AACH,MAAM,OAAO,gBAAgB;IAGhB;IAEA;IACQ;IAEA;IAPnB;IACE,kFAAkF;IACzE,GAAuB;IAChC,oDAAoD;IAC3C,MAAyB,EACjB,OAAmC;IACpD,iFAAiF;IAChE,eAAwB;QALhC,QAAG,GAAH,GAAG,CAAoB;QAEvB,WAAM,GAAN,MAAM,CAAmB;QACj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;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;CACF"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { MessageDirection, MessageLogger } from '../core/client.js';
|
|
2
|
+
import { type FinTsTransport } from '../core/transport.js';
|
|
3
|
+
/**
|
|
4
|
+
* Throws `FinTsProtocolError` if a message of `size` bytes exceeds the bank's `limit` in kilobytes (1024 bytes): the
|
|
5
|
+
* specification does not allow to send such a message.
|
|
6
|
+
*/
|
|
7
|
+
export declare function checkMessageSize(size: number, limit: number | undefined): void;
|
|
8
|
+
/** The bank's FinTS endpoint: posts messages there and reports them to the logger. */
|
|
9
|
+
export declare class BankConnection {
|
|
10
|
+
private readonly logger;
|
|
11
|
+
private readonly transport;
|
|
12
|
+
/** Where the messages go, as `FinTsConfig` checked it. */
|
|
13
|
+
private readonly href;
|
|
14
|
+
/** Aborts the requests posted since the last `abortRequestsAfter`. */
|
|
15
|
+
private requests;
|
|
16
|
+
/** How many requests are on their way. */
|
|
17
|
+
private onTheirWay;
|
|
18
|
+
/** Starts the time of the requests posted after `abortRequestsAfter`, once none posted before is on its way. */
|
|
19
|
+
private startLaterRequests;
|
|
20
|
+
/** The timers of `abortRequestsAfter`, which `close` clears. */
|
|
21
|
+
private readonly deadlines;
|
|
22
|
+
/** A connection to `url` through `transport`, an `HttpTransport` by default. */
|
|
23
|
+
constructor(url: URL, transport: FinTsTransport | undefined, logger: MessageLogger | undefined);
|
|
24
|
+
/**
|
|
25
|
+
* Posts `body` to a new copy of the URL, so that a transport that changes the one it is given changes no later
|
|
26
|
+
* request.
|
|
27
|
+
*
|
|
28
|
+
* Reports any failure of the transport as `FinTsTransportError`: a custom transport that calls `fetch` fails with a
|
|
29
|
+
* `TypeError` where the network does, and one that throws another `FinTsError`, such as `FinTsPinError`, would pass
|
|
30
|
+
* for an answer of the bank. Of such an error only the message is kept (`failureMessage`), since it may hold `body`,
|
|
31
|
+
* as the errors of HTTP clients such as axios do.
|
|
32
|
+
*
|
|
33
|
+
* Once the time `abortRequestsAfter` gives is up, it fails at once, before anything reaches the transport
|
|
34
|
+
* (`checkSendable`), and a request on its way fails then without waiting for the transport, which may ignore the
|
|
35
|
+
* abort.
|
|
36
|
+
*/
|
|
37
|
+
post(body: Uint8Array, contentType: string): Promise<Uint8Array>;
|
|
38
|
+
/**
|
|
39
|
+
* Throws the `FinTsTransportError` that `post` fails with once the time `abortRequestsAfter` gives is up; a caller
|
|
40
|
+
* checks it before it reports a message as outgoing, since such a message never goes out.
|
|
41
|
+
*/
|
|
42
|
+
checkSendable(): void;
|
|
43
|
+
/** Reports a message to the logger; `message` is only built when a logger is set. */
|
|
44
|
+
log(direction: MessageDirection, message: () => string): void;
|
|
45
|
+
/**
|
|
46
|
+
* Gives the requests on their way `graceMs` to finish, and aborts them then. Those posted later, such as the dialog
|
|
47
|
+
* ends of a closing client, have as long again from the moment the earlier ones are over or aborted, and are aborted
|
|
48
|
+
* in turn once that time is up, as is any posted after it: a bank that has stopped answering would hold them up to
|
|
49
|
+
* the transport's timeout.
|
|
50
|
+
*/
|
|
51
|
+
abortRequestsAfter(graceMs: number): void;
|
|
52
|
+
close(): void;
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=bank-connection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bank-connection.d.ts","sourceRoot":"","sources":["../../src/v3/bank-connection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAEzE,OAAO,EAAiC,KAAK,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAE1F;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,CAI9E;AAED,sFAAsF;AACtF,qBAAa,cAAc;IAsBvB,OAAO,CAAC,QAAQ,CAAC,MAAM;IArBzB,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAiB;IAE3C,0DAA0D;IAC1D,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAS;IAE9B,sEAAsE;IACtE,OAAO,CAAC,QAAQ,CAAyB;IAEzC,0CAA0C;IAC1C,OAAO,CAAC,UAAU,CAAK;IAEvB,gHAAgH;IAChH,OAAO,CAAC,kBAAkB,CAA2B;IAErD,gEAAgE;IAChE,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAuC;IAEjE,gFAAgF;gBAE9E,GAAG,EAAE,GAAG,EACR,SAAS,EAAE,cAAc,GAAG,SAAS,EACpB,MAAM,EAAE,aAAa,GAAG,SAAS;IAMpD;;;;;;;;;;;;OAYG;IACG,IAAI,CAAC,IAAI,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;IAuBtE;;;OAGG;IACH,aAAa,IAAI,IAAI;IAIrB,qFAAqF;IACrF,GAAG,CAAC,SAAS,EAAE,gBAAgB,EAAE,OAAO,EAAE,MAAM,MAAM,GAAG,IAAI;IAI7D;;;;;OAKG;IACH,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAuBzC,KAAK,IAAI,IAAI;CAId"}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { FinTsProtocolError, FinTsTransportError } from '../core/errors.js';
|
|
2
|
+
import { failureMessage, HttpTransport } from '../core/transport.js';
|
|
3
|
+
/**
|
|
4
|
+
* Throws `FinTsProtocolError` if a message of `size` bytes exceeds the bank's `limit` in kilobytes (1024 bytes): the
|
|
5
|
+
* specification does not allow to send such a message.
|
|
6
|
+
*/
|
|
7
|
+
export function checkMessageSize(size, limit) {
|
|
8
|
+
if (limit !== undefined && limit > 0 && size > limit * 1024) {
|
|
9
|
+
throw new FinTsProtocolError(`A message of ${size} bytes exceeds the bank's maximum message size of ${limit} KB`);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
/** The bank's FinTS endpoint: posts messages there and reports them to the logger. */
|
|
13
|
+
export class BankConnection {
|
|
14
|
+
logger;
|
|
15
|
+
transport;
|
|
16
|
+
/** Where the messages go, as `FinTsConfig` checked it. */
|
|
17
|
+
href;
|
|
18
|
+
/** Aborts the requests posted since the last `abortRequestsAfter`. */
|
|
19
|
+
requests = new AbortController();
|
|
20
|
+
/** How many requests are on their way. */
|
|
21
|
+
onTheirWay = 0;
|
|
22
|
+
/** Starts the time of the requests posted after `abortRequestsAfter`, once none posted before is on its way. */
|
|
23
|
+
startLaterRequests;
|
|
24
|
+
/** The timers of `abortRequestsAfter`, which `close` clears. */
|
|
25
|
+
deadlines = [];
|
|
26
|
+
/** A connection to `url` through `transport`, an `HttpTransport` by default. */
|
|
27
|
+
constructor(url, transport, logger) {
|
|
28
|
+
this.logger = logger;
|
|
29
|
+
this.href = url.href;
|
|
30
|
+
this.transport = transport ?? new HttpTransport();
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Posts `body` to a new copy of the URL, so that a transport that changes the one it is given changes no later
|
|
34
|
+
* request.
|
|
35
|
+
*
|
|
36
|
+
* Reports any failure of the transport as `FinTsTransportError`: a custom transport that calls `fetch` fails with a
|
|
37
|
+
* `TypeError` where the network does, and one that throws another `FinTsError`, such as `FinTsPinError`, would pass
|
|
38
|
+
* for an answer of the bank. Of such an error only the message is kept (`failureMessage`), since it may hold `body`,
|
|
39
|
+
* as the errors of HTTP clients such as axios do.
|
|
40
|
+
*
|
|
41
|
+
* Once the time `abortRequestsAfter` gives is up, it fails at once, before anything reaches the transport
|
|
42
|
+
* (`checkSendable`), and a request on its way fails then without waiting for the transport, which may ignore the
|
|
43
|
+
* abort.
|
|
44
|
+
*/
|
|
45
|
+
async post(body, contentType) {
|
|
46
|
+
this.checkSendable();
|
|
47
|
+
const signal = this.requests.signal;
|
|
48
|
+
let stopWaiting;
|
|
49
|
+
const aborted = new Promise((_, reject) => {
|
|
50
|
+
stopWaiting = () => {
|
|
51
|
+
reject(new FinTsTransportError('Request aborted'));
|
|
52
|
+
};
|
|
53
|
+
});
|
|
54
|
+
signal.addEventListener('abort', stopWaiting);
|
|
55
|
+
this.onTheirWay++;
|
|
56
|
+
try {
|
|
57
|
+
return await Promise.race([this.transport.post(new URL(this.href), body, contentType, signal), aborted]);
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
if (error instanceof FinTsTransportError)
|
|
61
|
+
throw error;
|
|
62
|
+
throw new FinTsTransportError(failureMessage(error));
|
|
63
|
+
}
|
|
64
|
+
finally {
|
|
65
|
+
signal.removeEventListener('abort', stopWaiting);
|
|
66
|
+
this.onTheirWay--;
|
|
67
|
+
if (this.onTheirWay === 0)
|
|
68
|
+
this.startLaterRequests?.();
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Throws the `FinTsTransportError` that `post` fails with once the time `abortRequestsAfter` gives is up; a caller
|
|
73
|
+
* checks it before it reports a message as outgoing, since such a message never goes out.
|
|
74
|
+
*/
|
|
75
|
+
checkSendable() {
|
|
76
|
+
if (this.requests.signal.aborted)
|
|
77
|
+
throw new FinTsTransportError('Request aborted');
|
|
78
|
+
}
|
|
79
|
+
/** Reports a message to the logger; `message` is only built when a logger is set. */
|
|
80
|
+
log(direction, message) {
|
|
81
|
+
this.logger?.(direction, message());
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Gives the requests on their way `graceMs` to finish, and aborts them then. Those posted later, such as the dialog
|
|
85
|
+
* ends of a closing client, have as long again from the moment the earlier ones are over or aborted, and are aborted
|
|
86
|
+
* in turn once that time is up, as is any posted after it: a bank that has stopped answering would hold them up to
|
|
87
|
+
* the transport's timeout.
|
|
88
|
+
*/
|
|
89
|
+
abortRequestsAfter(graceMs) {
|
|
90
|
+
const earlier = this.requests;
|
|
91
|
+
const later = new AbortController();
|
|
92
|
+
this.requests = later;
|
|
93
|
+
const afterGrace = (action) => {
|
|
94
|
+
this.deadlines.push(setTimeout(action, graceMs));
|
|
95
|
+
};
|
|
96
|
+
this.startLaterRequests = () => {
|
|
97
|
+
this.startLaterRequests = undefined;
|
|
98
|
+
afterGrace(() => {
|
|
99
|
+
later.abort();
|
|
100
|
+
});
|
|
101
|
+
};
|
|
102
|
+
if (this.onTheirWay === 0) {
|
|
103
|
+
this.startLaterRequests();
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
afterGrace(() => {
|
|
107
|
+
earlier.abort();
|
|
108
|
+
this.startLaterRequests?.();
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
close() {
|
|
113
|
+
for (const deadline of this.deadlines)
|
|
114
|
+
clearTimeout(deadline);
|
|
115
|
+
this.transport.close();
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
//# sourceMappingURL=bank-connection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bank-connection.js","sourceRoot":"","sources":["../../src/v3/bank-connection.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAC5E,OAAO,EAAE,cAAc,EAAE,aAAa,EAAuB,MAAM,sBAAsB,CAAC;AAE1F;;;GAGG;AACH,MAAM,UAAU,gBAAgB,CAAC,IAAY,EAAE,KAAyB;IACtE,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,GAAG,CAAC,IAAI,IAAI,GAAG,KAAK,GAAG,IAAI,EAAE,CAAC;QAC5D,MAAM,IAAI,kBAAkB,CAAC,gBAAgB,IAAI,qDAAqD,KAAK,KAAK,CAAC,CAAC;IACpH,CAAC;AACH,CAAC;AAED,sFAAsF;AACtF,MAAM,OAAO,cAAc;IAsBN;IArBF,SAAS,CAAiB;IAE3C,0DAA0D;IACzC,IAAI,CAAS;IAE9B,sEAAsE;IAC9D,QAAQ,GAAG,IAAI,eAAe,EAAE,CAAC;IAEzC,0CAA0C;IAClC,UAAU,GAAG,CAAC,CAAC;IAEvB,gHAAgH;IACxG,kBAAkB,CAA2B;IAErD,g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