@coderoftime/fints 0.1.0 → 0.2.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 +142 -1
- package/README.md +127 -37
- package/dist/client.d.ts +48 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +199 -0
- package/dist/client.js.map +1 -0
- package/dist/core/account.d.ts +35 -7
- package/dist/core/account.d.ts.map +1 -1
- package/dist/core/account.js +84 -13
- package/dist/core/account.js.map +1 -1
- package/dist/core/amount.d.ts +2 -1
- package/dist/core/amount.d.ts.map +1 -1
- package/dist/core/amount.js +4 -1
- package/dist/core/amount.js.map +1 -1
- package/dist/core/balance.d.ts +1 -0
- package/dist/core/balance.d.ts.map +1 -1
- package/dist/core/balance.js +6 -5
- package/dist/core/balance.js.map +1 -1
- package/dist/core/bank-info.d.ts +1 -1
- package/dist/core/bank-info.js +1 -1
- package/dist/core/client.d.ts +50 -15
- package/dist/core/client.d.ts.map +1 -1
- package/dist/core/config.d.ts +28 -16
- package/dist/core/config.d.ts.map +1 -1
- package/dist/core/config.js +66 -26
- package/dist/core/config.js.map +1 -1
- package/dist/core/errors.d.ts +85 -23
- package/dist/core/errors.d.ts.map +1 -1
- package/dist/core/errors.js +112 -47
- package/dist/core/errors.js.map +1 -1
- package/dist/core/feedback.d.ts +4 -1
- package/dist/core/feedback.d.ts.map +1 -1
- package/dist/core/feedback.js +4 -1
- package/dist/core/feedback.js.map +1 -1
- package/dist/core/transaction.d.ts +6 -1
- package/dist/core/transaction.d.ts.map +1 -1
- package/dist/core/transaction.js +9 -4
- package/dist/core/transaction.js.map +1 -1
- package/dist/core/transport.d.ts +33 -6
- package/dist/core/transport.d.ts.map +1 -1
- package/dist/core/transport.js +77 -20
- package/dist/core/transport.js.map +1 -1
- package/dist/formats/camt.d.ts +24 -4
- package/dist/formats/camt.d.ts.map +1 -1
- package/dist/formats/camt.js +124 -41
- package/dist/formats/camt.js.map +1 -1
- package/dist/formats/mt940.d.ts +15 -3
- package/dist/formats/mt940.d.ts.map +1 -1
- package/dist/formats/mt940.js +161 -82
- 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 +24 -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 +6 -0
- package/dist/formats/sepa-purpose.d.ts.map +1 -1
- package/dist/formats/sepa-purpose.js +23 -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 +7 -10
- package/dist/session/dialog-runner.d.ts.map +1 -1
- package/dist/session/dialog-runner.js +15 -16
- 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 +156 -84
- 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 +33 -25
- package/dist/session/session-setup.d.ts.map +1 -1
- package/dist/session/session-setup.js +87 -65
- package/dist/session/session-setup.js.map +1 -1
- package/dist/session/session-state.d.ts +9 -6
- package/dist/session/session-state.d.ts.map +1 -1
- package/dist/session/session-state.js +52 -17
- package/dist/session/session-state.js.map +1 -1
- package/dist/session/signed-dialog.d.ts +77 -0
- package/dist/session/signed-dialog.d.ts.map +1 -0
- package/dist/session/signed-dialog.js +170 -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 +8 -4
- package/dist/session/user-prompts.d.ts.map +1 -1
- package/dist/session/user-prompts.js +34 -14
- package/dist/session/user-prompts.js.map +1 -1
- package/dist/tan/challenge.d.ts +34 -13
- package/dist/tan/challenge.d.ts.map +1 -1
- package/dist/tan/challenge.js +25 -26
- package/dist/tan/challenge.js.map +1 -1
- package/dist/tan/flicker.d.ts +7 -1
- package/dist/tan/flicker.d.ts.map +1 -1
- package/dist/tan/flicker.js +40 -6
- package/dist/tan/flicker.js.map +1 -1
- package/dist/tan/tan-image.d.ts +3 -2
- package/dist/tan/tan-image.d.ts.map +1 -1
- package/dist/tan/tan-image.js +7 -5
- package/dist/tan/tan-image.js.map +1 -1
- package/dist/tan/tan-models.d.ts +5 -1
- package/dist/tan/tan-models.d.ts.map +1 -1
- package/dist/tan/tan-models.js +10 -5
- package/dist/tan/tan-models.js.map +1 -1
- package/dist/util/async.d.ts +0 -2
- package/dist/util/async.d.ts.map +1 -1
- package/dist/util/async.js +0 -4
- package/dist/util/async.js.map +1 -1
- package/dist/util/bytes.d.ts +2 -3
- package/dist/util/bytes.d.ts.map +1 -1
- package/dist/util/bytes.js +12 -20
- 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 +9 -16
- package/dist/util/dates.d.ts.map +1 -1
- package/dist/util/dates.js +39 -19
- package/dist/util/dates.js.map +1 -1
- package/dist/util/errors.d.ts +9 -1
- package/dist/util/errors.d.ts.map +1 -1
- package/dist/util/errors.js +12 -3
- package/dist/util/errors.js.map +1 -1
- 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 +21 -4
- package/dist/util/text.d.ts.map +1 -1
- package/dist/util/text.js +42 -13
- package/dist/util/text.js.map +1 -1
- package/dist/util/xml.d.ts +4 -3
- package/dist/util/xml.d.ts.map +1 -1
- package/dist/util/xml.js +37 -26
- 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 +34 -0
- package/dist/v3/bank-connection.d.ts.map +1 -0
- package/dist/v3/bank-connection.js +58 -0
- package/dist/v3/bank-connection.js.map +1 -0
- package/dist/v3/dialog.d.ts +80 -46
- package/dist/v3/dialog.d.ts.map +1 -1
- package/dist/v3/dialog.js +162 -59
- package/dist/v3/dialog.js.map +1 -1
- package/dist/v3/message.d.ts +17 -4
- package/dist/v3/message.d.ts.map +1 -1
- package/dist/v3/message.js +62 -18
- package/dist/v3/message.js.map +1 -1
- package/dist/v3/parameter-store.d.ts +75 -0
- package/dist/v3/parameter-store.d.ts.map +1 -0
- package/dist/v3/parameter-store.js +143 -0
- package/dist/v3/parameter-store.js.map +1 -0
- package/dist/v3/parameters.d.ts +38 -12
- package/dist/v3/parameters.d.ts.map +1 -1
- package/dist/v3/parameters.js +91 -37
- package/dist/v3/parameters.js.map +1 -1
- package/dist/v3/protocol.d.ts +43 -50
- package/dist/v3/protocol.d.ts.map +1 -1
- package/dist/v3/protocol.js +58 -208
- 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 +120 -0
- package/dist/v3/queries.js.map +1 -0
- package/dist/v3/segments.d.ts +29 -12
- package/dist/v3/segments.d.ts.map +1 -1
- package/dist/v3/segments.js +65 -23
- package/dist/v3/segments.js.map +1 -1
- package/dist/v3/syntax.d.ts +65 -14
- package/dist/v3/syntax.d.ts.map +1 -1
- package/dist/v3/syntax.js +167 -101
- package/dist/v3/syntax.js.map +1 -1
- package/package.json +10 -6
- package/src/client.ts +252 -0
- package/src/core/account.ts +86 -13
- package/src/core/amount.ts +3 -1
- package/src/core/balance.ts +6 -5
- package/src/core/bank-info.ts +1 -1
- package/src/core/client.ts +52 -15
- package/src/core/config.ts +69 -28
- package/src/core/errors.ts +122 -48
- package/src/core/feedback.ts +4 -1
- package/src/core/transaction.ts +9 -4
- package/src/core/transport.ts +98 -23
- package/src/formats/camt.ts +136 -39
- package/src/formats/mt940.ts +167 -81
- package/src/formats/readers.ts +24 -31
- package/src/formats/record-budget.ts +18 -0
- package/src/formats/sepa-purpose.ts +21 -2
- package/src/index.ts +4 -2
- package/src/session/app-approval.ts +51 -38
- package/src/session/dialog-runner.ts +31 -28
- package/src/session/login-guard.ts +174 -88
- package/src/session/sepa-accounts.ts +63 -45
- package/src/session/session-setup.ts +90 -71
- package/src/session/session-state.ts +56 -22
- package/src/session/signed-dialog.ts +192 -0
- package/src/session/tan-selection.ts +50 -39
- package/src/session/user-prompts.ts +35 -16
- package/src/tan/challenge.ts +40 -31
- package/src/tan/flicker.ts +44 -6
- package/src/tan/tan-image.ts +7 -5
- package/src/tan/tan-models.ts +10 -5
- package/src/util/async.ts +0 -5
- package/src/util/bytes.ts +13 -19
- package/src/util/call-context.ts +3 -2
- package/src/util/dates.ts +41 -24
- package/src/util/errors.ts +14 -3
- package/src/util/json.ts +16 -0
- package/src/util/text.ts +42 -12
- package/src/util/xml.ts +37 -26
- package/src/v3/account-extension.ts +7 -12
- package/src/v3/bank-connection.ts +67 -0
- package/src/v3/dialog.ts +175 -91
- package/src/v3/message.ts +69 -17
- package/src/v3/parameter-store.ts +160 -0
- package/src/v3/parameters.ts +110 -37
- package/src/v3/protocol.ts +70 -253
- package/src/v3/queries.ts +190 -0
- package/src/v3/segments.ts +65 -22
- package/src/v3/syntax.ts +153 -91
- 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/core/errors.js
CHANGED
|
@@ -1,46 +1,57 @@
|
|
|
1
1
|
import { FormatError } from '../util/errors.js';
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import { nonBlank } from '../util/text.js';
|
|
3
|
+
import { endsDialog, FeedbackCodes, hasCode } from './feedback.js';
|
|
4
|
+
/**
|
|
5
|
+
* Base class of all errors the client raises about the bank and its data.
|
|
6
|
+
*
|
|
7
|
+
* Each error class states its `name`: a minifier renames classes, and `constructor.name` would show a meaningless one.
|
|
8
|
+
*/
|
|
4
9
|
export class FinTsError extends Error {
|
|
5
|
-
constructor(name, message, cause) {
|
|
6
|
-
super(message, cause === undefined ? undefined : { cause });
|
|
7
|
-
// Set explicitly: a minifier renames classes, and `constructor.name` would show a meaningless name.
|
|
8
|
-
this.name = name;
|
|
9
|
-
}
|
|
10
10
|
}
|
|
11
|
-
/**
|
|
11
|
+
/**
|
|
12
|
+
* The connection to the bank failed or returned an HTTP error.
|
|
13
|
+
*
|
|
14
|
+
* It carries no `cause`: the transport's own error may hold the message it was sending, PIN and TAN included.
|
|
15
|
+
*/
|
|
12
16
|
export class FinTsTransportError extends FinTsError {
|
|
13
|
-
|
|
17
|
+
name = 'FinTsTransportError';
|
|
18
|
+
/**
|
|
19
|
+
* The HTTP status code of the bank's answer, `undefined` where none came, for example after a timeout; the client
|
|
20
|
+
* acts on it (`FinTsTransport.post`).
|
|
21
|
+
*/
|
|
14
22
|
statusCode;
|
|
15
23
|
constructor(message, options) {
|
|
16
|
-
super(
|
|
24
|
+
super(message);
|
|
17
25
|
this.statusCode = options?.statusCode;
|
|
18
26
|
}
|
|
19
27
|
}
|
|
20
28
|
/** The bank's response could not be understood. */
|
|
21
29
|
export class FinTsProtocolError extends FinTsError {
|
|
22
|
-
|
|
23
|
-
super('FinTsProtocolError', message);
|
|
24
|
-
}
|
|
30
|
+
name = 'FinTsProtocolError';
|
|
25
31
|
}
|
|
26
32
|
/** The bank does not offer the requested business transaction. */
|
|
27
33
|
export class FinTsUnsupportedError extends FinTsError {
|
|
28
|
-
|
|
29
|
-
super('FinTsUnsupportedError', message);
|
|
30
|
-
}
|
|
34
|
+
name = 'FinTsUnsupportedError';
|
|
31
35
|
}
|
|
32
36
|
/**
|
|
33
|
-
* The
|
|
37
|
+
* The client has no TAN method or medium to log in with: the method in use needs a TAN medium the client could not
|
|
38
|
+
* learn, or the bank offers the user only TAN methods the client cannot run. Pass a medium to
|
|
39
|
+
* `FinTsClient.selectTanMethod`, or choose another method.
|
|
34
40
|
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
41
|
+
* The client does not send a login the bank would refuse for it, but the steps before, such as the synchronization or
|
|
42
|
+
* the lookup of the TAN media, may have gone out.
|
|
37
43
|
*/
|
|
44
|
+
export class FinTsTanSetupError extends FinTsError {
|
|
45
|
+
name = 'FinTsTanSetupError';
|
|
46
|
+
}
|
|
47
|
+
/** The bank rejected the request; `feedback` holds all return codes. A refused login is a `FinTsLoginRefusedError`. */
|
|
38
48
|
export class FinTsBankError extends FinTsError {
|
|
49
|
+
name = 'FinTsBankError';
|
|
39
50
|
/** All return codes of the response, warnings and successes included. */
|
|
40
51
|
feedback;
|
|
41
52
|
/** A rejection with the return codes in `feedback`; `message` defaults to the errors among them. */
|
|
42
|
-
constructor(feedback, message
|
|
43
|
-
super(
|
|
53
|
+
constructor(feedback, message) {
|
|
54
|
+
super(message ??
|
|
44
55
|
feedback
|
|
45
56
|
.filter((f) => f.isError)
|
|
46
57
|
.map((f) => f.toString())
|
|
@@ -52,27 +63,40 @@ export class FinTsBankError extends FinTsError {
|
|
|
52
63
|
return this.feedback.map((f) => f.code);
|
|
53
64
|
}
|
|
54
65
|
}
|
|
55
|
-
/**
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
66
|
+
/**
|
|
67
|
+
* The bank refused the login, so the client sends the PIN no more: every later call that would send it fails with this
|
|
68
|
+
* error without contacting the bank, also in a client restored from the saved state, until
|
|
69
|
+
* `FinTsClient.clearLoginRefusal` takes a PIN the user has entered anew; for good where the bank has changed the login
|
|
70
|
+
* data (`FinTsLoginDataChangedError`).
|
|
71
|
+
*
|
|
72
|
+
* Banks lock the access after a few failed logins, and a return code does not always tell whether the PIN was the
|
|
73
|
+
* reason, so any error in the answer to a login refuses it, also one that ends the dialog, and so does a wrong PIN
|
|
74
|
+
* wherever the bank reports it. Only where the bank names a reason the client can take care of, another TAN method or a
|
|
75
|
+
* new customer system ID, does the same call log in once more, for each reason once. The client refuses the login
|
|
76
|
+
* itself where it could not read the answers to two logins in a row, which the bank may have counted as failed
|
|
77
|
+
* attempts; `feedback` is empty then.
|
|
78
|
+
*/
|
|
79
|
+
export class FinTsLoginRefusedError extends FinTsBankError {
|
|
80
|
+
name = 'FinTsLoginRefusedError';
|
|
81
|
+
}
|
|
82
|
+
/** Wrong or blocked PIN. */
|
|
83
|
+
export class FinTsPinError extends FinTsLoginRefusedError {
|
|
84
|
+
name = 'FinTsPinError';
|
|
60
85
|
}
|
|
61
86
|
/** Invalid, expired or rejected TAN, as the bank reports it in answer to a TAN or to an approval status request. */
|
|
62
87
|
export class FinTsTanError extends FinTsBankError {
|
|
63
|
-
|
|
64
|
-
super(feedback, undefined, 'FinTsTanError');
|
|
65
|
-
}
|
|
88
|
+
name = 'FinTsTanError';
|
|
66
89
|
}
|
|
67
90
|
/**
|
|
68
91
|
* The bank has changed the user's login data and expects the new ones from now on (return code 3072).
|
|
69
92
|
*
|
|
70
|
-
* The client has ended the dialog,
|
|
71
|
-
* `loginName` replaces user ID and customer ID: pass it as `userId`, without a customer ID.
|
|
93
|
+
* The client has ended the dialog, where the bank opened one, and logs in with the old data no more. Create a new
|
|
94
|
+
* client with the new data; a `loginName` replaces user ID and customer ID: pass it as `userId`, without a customer ID.
|
|
72
95
|
*/
|
|
73
|
-
export class FinTsLoginDataChangedError extends
|
|
96
|
+
export class FinTsLoginDataChangedError extends FinTsLoginRefusedError {
|
|
97
|
+
name = 'FinTsLoginDataChangedError';
|
|
74
98
|
constructor(feedback) {
|
|
75
|
-
super(feedback, 'The bank has changed the login data'
|
|
99
|
+
super(feedback, 'The bank has changed the login data');
|
|
76
100
|
}
|
|
77
101
|
/** The new user ID (Benutzerkennung); `undefined` where the bank names none. */
|
|
78
102
|
get userId() {
|
|
@@ -88,26 +112,31 @@ export class FinTsLoginDataChangedError extends FinTsBankError {
|
|
|
88
112
|
}
|
|
89
113
|
parameter(index) {
|
|
90
114
|
const change = this.feedback.find((f) => f.code === FeedbackCodes.newLoginData);
|
|
91
|
-
|
|
92
|
-
return value === undefined || value === '' ? undefined : value;
|
|
115
|
+
return nonBlank(change?.parameters[index]);
|
|
93
116
|
}
|
|
94
117
|
}
|
|
95
|
-
/**
|
|
118
|
+
/**
|
|
119
|
+
* The bank ended the dialog, for example after a timeout; the next call logs in anew. Where the bank ends the dialog
|
|
120
|
+
* in answer to a login, the call fails with `FinTsLoginRefusedError` instead.
|
|
121
|
+
*/
|
|
96
122
|
export class FinTsDialogAbortedError extends FinTsBankError {
|
|
97
|
-
|
|
98
|
-
super(feedback, undefined, 'FinTsDialogAbortedError');
|
|
99
|
-
}
|
|
123
|
+
name = 'FinTsDialogAbortedError';
|
|
100
124
|
}
|
|
101
125
|
/** The user cancelled the TAN entry or the approval in the banking app. */
|
|
102
126
|
export class FinTsTanCancelledError extends FinTsError {
|
|
127
|
+
name = 'FinTsTanCancelledError';
|
|
103
128
|
constructor() {
|
|
104
|
-
super('
|
|
129
|
+
super('TAN entry cancelled');
|
|
105
130
|
}
|
|
106
131
|
}
|
|
107
|
-
/**
|
|
132
|
+
/**
|
|
133
|
+
* The user did not approve in the banking app in time: within the status requests the bank allows, 60 where it states
|
|
134
|
+
* none, and 10 minutes of polling at most.
|
|
135
|
+
*/
|
|
108
136
|
export class FinTsDecoupledTimeoutError extends FinTsError {
|
|
137
|
+
name = 'FinTsDecoupledTimeoutError';
|
|
109
138
|
constructor() {
|
|
110
|
-
super('
|
|
139
|
+
super('Approval on the separate device was not completed in time');
|
|
111
140
|
}
|
|
112
141
|
}
|
|
113
142
|
/**
|
|
@@ -116,10 +145,11 @@ export class FinTsDecoupledTimeoutError extends FinTsError {
|
|
|
116
145
|
* It does not extend `FinTsError`: it tells about the app's use of the client, not about the bank.
|
|
117
146
|
*/
|
|
118
147
|
export class FinTsStateError extends Error {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
148
|
+
name = 'FinTsStateError';
|
|
149
|
+
}
|
|
150
|
+
/** The error of whatever a closed client is asked to do. */
|
|
151
|
+
export function clientClosedError() {
|
|
152
|
+
return new FinTsStateError('The FinTS client is closed');
|
|
123
153
|
}
|
|
124
154
|
/**
|
|
125
155
|
* Return codes for a wrong or blocked PIN, from the FinTS return code list (Rückmeldungscodes): 9340 signature (PIN)
|
|
@@ -168,7 +198,24 @@ export function bankErrorFor(feedback, completesApproval = false) {
|
|
|
168
198
|
return new FinTsDialogAbortedError(feedback);
|
|
169
199
|
return new FinTsBankError(feedback);
|
|
170
200
|
}
|
|
171
|
-
/**
|
|
201
|
+
/**
|
|
202
|
+
* The refusal of a login whose answer carried `feedback`: `FinTsPinError` for a rejected PIN, else
|
|
203
|
+
* `FinTsLoginDataChangedError` for new login data, also next to other errors, and `FinTsLoginRefusedError` for anything
|
|
204
|
+
* else. The same for a refusal restored from the saved state, which keeps only `feedback`.
|
|
205
|
+
*
|
|
206
|
+
* New login data end the old ones for good, so the session takes care of no other reason the answer names.
|
|
207
|
+
*/
|
|
208
|
+
export function loginRefusalFor(feedback) {
|
|
209
|
+
if (feedback.some(isPinError))
|
|
210
|
+
return new FinTsPinError(feedback);
|
|
211
|
+
if (hasCode(feedback, FeedbackCodes.newLoginData))
|
|
212
|
+
return new FinTsLoginDataChangedError(feedback);
|
|
213
|
+
return new FinTsLoginRefusedError(feedback);
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Runs `parse` on data from the bank and reports malformed data as `FinTsProtocolError`, whose message leaves the data
|
|
217
|
+
* out (`FormatError`).
|
|
218
|
+
*/
|
|
172
219
|
export function parseBankData(parse) {
|
|
173
220
|
try {
|
|
174
221
|
return parse();
|
|
@@ -179,4 +226,22 @@ export function parseBankData(parse) {
|
|
|
179
226
|
throw error;
|
|
180
227
|
}
|
|
181
228
|
}
|
|
229
|
+
/**
|
|
230
|
+
* Runs `lookup`, which only completes data, such as the SEPA account list; `undefined` where the bank rejects it, so
|
|
231
|
+
* that the caller carries on without it. An aborted dialog counts as a rejection: banks end the dialog along with many.
|
|
232
|
+
* A refused login and a rejected TAN fail the call: the user must hear of them.
|
|
233
|
+
*/
|
|
234
|
+
export async function tryLookUp(lookup) {
|
|
235
|
+
try {
|
|
236
|
+
return await lookup();
|
|
237
|
+
}
|
|
238
|
+
catch (error) {
|
|
239
|
+
if (!(error instanceof FinTsBankError) ||
|
|
240
|
+
error instanceof FinTsLoginRefusedError ||
|
|
241
|
+
error instanceof FinTsTanError) {
|
|
242
|
+
throw error;
|
|
243
|
+
}
|
|
244
|
+
return undefined;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
182
247
|
//# sourceMappingURL=errors.js.map
|
package/dist/core/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/core/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/core/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,OAAO,EAAsB,MAAM,eAAe,CAAC;AAEvF;;;;GAIG;AACH,MAAM,OAAgB,UAAW,SAAQ,KAAK;CAE7C;AAED;;;;GAIG;AACH,MAAM,OAAO,mBAAoB,SAAQ,UAAU;IACxC,IAAI,GAAG,qBAAqB,CAAC;IAEtC;;;OAGG;IACM,UAAU,CAAqB;IAExC,YAAY,OAAe,EAAE,OAAiC;QAC5D,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,UAAU,GAAG,OAAO,EAAE,UAAU,CAAC;IACxC,CAAC;CACF;AAED,mDAAmD;AACnD,MAAM,OAAO,kBAAm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7
7
|
/** The bank's explanation of the code. */
|
|
8
8
|
readonly text: string;
|
|
9
|
-
/**
|
|
9
|
+
/**
|
|
10
|
+
* Values the bank adds to the code, such as the position to continue at: one character per byte the bank sent (ISO
|
|
11
|
+
* 8859-1, the FinTS character set), since the client and the app send them back as they came.
|
|
12
|
+
*/
|
|
10
13
|
readonly parameters: readonly string[];
|
|
11
14
|
constructor(init: {
|
|
12
15
|
code: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"feedback.d.ts","sourceRoot":"","sources":["../../src/core/feedback.ts"],"names":[],"mappings":"AAAA,qFAAqF;AACrF,qBAAa,aAAa;IACxB,0FAA0F;IAC1F,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB,4EAA4E;IAC5E,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAEvC,0CAA0C;IAC1C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB
|
|
1
|
+
{"version":3,"file":"feedback.d.ts","sourceRoot":"","sources":["../../src/core/feedback.ts"],"names":[],"mappings":"AAAA,qFAAqF;AACrF,qBAAa,aAAa;IACxB,0FAA0F;IAC1F,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB,4EAA4E;IAC5E,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAEvC,0CAA0C;IAC1C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB;;;OAGG;IACH,QAAQ,CAAC,UAAU,EAAE,SAAS,MAAM,EAAE,CAAC;gBAE3B,IAAI,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,UAAU,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;KAAE;IAOhH,wCAAwC;IACxC,IAAI,SAAS,IAAI,OAAO,CAEvB;IAED,qCAAqC;IACrC,IAAI,SAAS,IAAI,OAAO,CAEvB;IAED,oCAAoC;IACpC,IAAI,OAAO,IAAI,OAAO,CAErB;IAED,QAAQ,IAAI,MAAM;CAGnB;AAED,qGAAqG;AACrG,eAAO,MAAM,aAAa;IACxB,6GAA6G;;IAE7G,kHAAkH;;IAElH;;;OAGG;;IAEH,qEAAqE;;IAErE,mHAAmH;;IAEnH,4FAA4F;;IAE5F,6DAA6D;;IAE7D,sDAAsD;;IAEtD;;;OAGG;;IAEH,0HAA0H;;EAE1H,CAAC;AA0BH,4DAA4D;AAC5D,wBAAgB,OAAO,CAAC,QAAQ,EAAE,SAAS,aAAa,EAAE,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAEjF;AAED,2CAA2C;AAC3C,wBAAgB,SAAS,CAAC,QAAQ,EAAE,SAAS,aAAa,EAAE,GAAG,OAAO,CAErE;AAED,sGAAsG;AACtG,wBAAgB,aAAa,CAAC,QAAQ,EAAE,SAAS,aAAa,EAAE,GAAG,GAAG,CAAC,MAAM,CAAC,CAO7E;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,SAAS,aAAa,EAAE,GAAG,MAAM,EAAE,CAOhF;AAED,+EAA+E;AAC/E,wBAAgB,UAAU,CAAC,QAAQ,EAAE,SAAS,aAAa,EAAE,GAAG,OAAO,CAEtE;AAED,mEAAmE;AACnE,wBAAgB,YAAY,CAAC,QAAQ,EAAE,SAAS,aAAa,EAAE,GAAG,aAAa,EAAE,CAEhF"}
|
package/dist/core/feedback.js
CHANGED
|
@@ -6,7 +6,10 @@ export class FinTsFeedback {
|
|
|
6
6
|
reference;
|
|
7
7
|
/** The bank's explanation of the code. */
|
|
8
8
|
text;
|
|
9
|
-
/**
|
|
9
|
+
/**
|
|
10
|
+
* Values the bank adds to the code, such as the position to continue at: one character per byte the bank sent (ISO
|
|
11
|
+
* 8859-1, the FinTS character set), since the client and the app send them back as they came.
|
|
12
|
+
*/
|
|
10
13
|
parameters;
|
|
11
14
|
constructor(init) {
|
|
12
15
|
this.code = init.code;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"feedback.js","sourceRoot":"","sources":["../../src/core/feedback.ts"],"names":[],"mappings":"AAAA,qFAAqF;AACrF,MAAM,OAAO,aAAa;IACxB,0FAA0F;IACjF,IAAI,CAAS;IAEtB,4EAA4E;IACnE,SAAS,CAAqB;IAEvC,0CAA0C;IACjC,IAAI,CAAS;IAEtB
|
|
1
|
+
{"version":3,"file":"feedback.js","sourceRoot":"","sources":["../../src/core/feedback.ts"],"names":[],"mappings":"AAAA,qFAAqF;AACrF,MAAM,OAAO,aAAa;IACxB,0FAA0F;IACjF,IAAI,CAAS;IAEtB,4EAA4E;IACnE,SAAS,CAAqB;IAEvC,0CAA0C;IACjC,IAAI,CAAS;IAEtB;;;OAGG;IACM,UAAU,CAAoB;IAEvC,YAAY,IAAoG;QAC9G,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;QACtB,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC;QAChC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;QACtB,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,UAAU,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;IAChE,CAAC;IAED,wCAAwC;IACxC,IAAI,SAAS;QACX,OAAO,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;IACnC,CAAC;IAED,qCAAqC;IACrC,IAAI,SAAS;QACX,OAAO,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;IACnC,CAAC;IAED,oCAAoC;IACpC,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;IACnC,CAAC;IAED,QAAQ;QACN,OAAO,GAAG,IAAI,CAAC,IAAI,KAAK,IAA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,CAAC,CAAC,CAAC;AACxD,CAAC;AAED,mEAAmE;AACnE,MAAM,UAAU,YAAY,CAAC,QAAkC;IAC7D,OAAO,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;AAC9E,CAAC"}
|
|
@@ -84,8 +84,13 @@ export declare class Transaction {
|
|
|
84
84
|
readonly ultimateCreditor: string | undefined;
|
|
85
85
|
/** The party the payer acts for, where that is not the payer itself. */
|
|
86
86
|
readonly ultimateDebtor: string | undefined;
|
|
87
|
-
/**
|
|
87
|
+
/**
|
|
88
|
+
* The SEPA keywords of the purpose, keyed by keyword (EREF, KREF, MREF, CRED, SVWZ, …): those `SepaPurpose` reads. In
|
|
89
|
+
* camt, EREF, MREF and CRED are those of `endToEndId`, `mandateId` and `creditorId`, which the bank states apart,
|
|
90
|
+
* never keywords of the remittance text the payer or the payee writes.
|
|
91
|
+
*/
|
|
88
92
|
readonly purposeCodes: ReadonlyMap<string, string>;
|
|
93
|
+
/** Takes copies of the dates and purpose codes of `init`: each transaction has its own, which no other one shares. */
|
|
89
94
|
constructor(init: TransactionInit);
|
|
90
95
|
/** Whether the transaction is still pending. */
|
|
91
96
|
get isPending(): boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transaction.d.ts","sourceRoot":"","sources":["../../src/core/transaction.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAE1C,wDAAwD;AACxD,MAAM,MAAM,iBAAiB,GAAG,QAAQ,GAAG,SAAS,CAAC;AAErD,wFAAwF;AACxF,MAAM,MAAM,iBAAiB;AAC3B,0DAA0D;AACxD,MAAM;AACR,gDAAgD;GAC9C,OAAO;AACT,0BAA0B;GACxB,MAAM,CAAC;AAEX,0EAA0E;AAC1E,MAAM,WAAW,eAAe;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AwF;IACxF,QAAQ,CAAC,oBAAoB,EAAE,MAAM,GAAG,SAAS,CAAC;IAElD,wCAAwC;IACxC,QAAQ,CAAC,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC;IAExC,kDAAkD;IAClD,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAEvC,uCAAuC;IACvC,QAAQ,CAAC,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC;IAExC,6CAA6C;IAC7C,QAAQ,CAAC,iBAAiB,EAAE,MAAM,GAAG,SAAS,CAAC;IAE/C,2CAA2C;IAC3C,QAAQ,CAAC,aAAa,EAAE,MAAM,GAAG,SAAS,CAAC;IAE3C,oEAAoE;IACpE,QAAQ,CAAC,eAAe,EAAE,MAAM,GAAG,SAAS,CAAC;IAE7C,kDAAkD;IAClD,QAAQ,CAAC,iBAAiB,EAAE,MAAM,GAAG,SAAS,CAAC;IAE/C,wCAAwC;IACxC,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAEvC,wEAAwE;IACxE,QAAQ,CAAC,gBAAgB,EAAE,MAAM,GAAG,SAAS,CAAC;IAE9C,wEAAwE;IACxE,QAAQ,CAAC,cAAc,EAAE,MAAM,GAAG,SAAS,CAAC;IAE5C;;;;OAIG;IACH,QAAQ,CAAC,YAAY,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAEnD,sHAAsH;gBAC1G,IAAI,EAAE,eAAe;IA0BjC,gDAAgD;IAChD,IAAI,SAAS,IAAI,OAAO,CAEvB;IAED;;;OAGG;IACH,QAAQ,IAAI,MAAM;CAGnB"}
|
package/dist/core/transaction.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { formatIsoDate } from '../util/dates.js';
|
|
1
|
+
import { copyDate, formatIsoDate } from '../util/dates.js';
|
|
2
2
|
import { ImmutableMap } from '../util/immutable-map.js';
|
|
3
3
|
/** A single account transaction, parsed from camt.052 or MT940/MT942. */
|
|
4
4
|
export class Transaction {
|
|
@@ -49,12 +49,17 @@ export class Transaction {
|
|
|
49
49
|
ultimateCreditor;
|
|
50
50
|
/** The party the payer acts for, where that is not the payer itself. */
|
|
51
51
|
ultimateDebtor;
|
|
52
|
-
/**
|
|
52
|
+
/**
|
|
53
|
+
* The SEPA keywords of the purpose, keyed by keyword (EREF, KREF, MREF, CRED, SVWZ, …): those `SepaPurpose` reads. In
|
|
54
|
+
* camt, EREF, MREF and CRED are those of `endToEndId`, `mandateId` and `creditorId`, which the bank states apart,
|
|
55
|
+
* never keywords of the remittance text the payer or the payee writes.
|
|
56
|
+
*/
|
|
53
57
|
purposeCodes;
|
|
58
|
+
/** Takes copies of the dates and purpose codes of `init`: each transaction has its own, which no other one shares. */
|
|
54
59
|
constructor(init) {
|
|
55
60
|
this.status = init.status ?? 'booked';
|
|
56
|
-
this.bookingDate = init.bookingDate;
|
|
57
|
-
this.valueDate = init.valueDate;
|
|
61
|
+
this.bookingDate = copyDate(init.bookingDate);
|
|
62
|
+
this.valueDate = copyDate(init.valueDate);
|
|
58
63
|
this.amount = init.amount;
|
|
59
64
|
this.isReversal = init.isReversal ?? false;
|
|
60
65
|
this.bookingText = init.bookingText;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transaction.js","sourceRoot":"","sources":["../../src/core/transaction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"transaction.js","sourceRoot":"","sources":["../../src/core/transaction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AA0CxD,yEAAyE;AACzE,MAAM,OAAO,WAAW;IACtB,oDAAoD;IAC3C,MAAM,CAAoB;IAEnC;;;OAGG;IACM,WAAW,CAAmB;IAEvC,iGAAiG;IACxF,SAAS,CAAO;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CAAC;CACF"}
|
package/dist/core/transport.d.ts
CHANGED
|
@@ -3,19 +3,35 @@ export interface FinTsTransport {
|
|
|
3
3
|
/**
|
|
4
4
|
* Posts `body` to `url` and returns the response body.
|
|
5
5
|
*
|
|
6
|
-
*
|
|
6
|
+
* The client aborts `signal` once it is closed: a transport that stops the request then keeps `close` from waiting
|
|
7
|
+
* for the answer.
|
|
8
|
+
*
|
|
9
|
+
* Implementations report failures as `FinTsTransportError`, with the HTTP status as `statusCode` where the bank
|
|
10
|
+
* answered with an HTTP error: an anonymous request for the bank parameter data that fails so goes out once more,
|
|
11
|
+
* without the announcement of strong authentication, which some banks fail on. Of any other error, another
|
|
12
|
+
* `FinTsError` included, the client keeps only its message and that of its cause, as a `FinTsTransportError` without
|
|
13
|
+
* `statusCode`. `body` holds PIN and TAN in plain text: keep it out of error messages and logs.
|
|
7
14
|
*/
|
|
8
|
-
post(url: URL, body: Uint8Array, contentType: string): Promise<Uint8Array>;
|
|
15
|
+
post(url: URL, body: Uint8Array, contentType: string, signal: AbortSignal): Promise<Uint8Array>;
|
|
9
16
|
/** Releases the connection; the client calls it when it is closed. */
|
|
10
17
|
close(): void;
|
|
11
18
|
}
|
|
12
19
|
/** What `HttpTransport` takes; all optional. */
|
|
13
20
|
export interface HttpTransportOptions {
|
|
14
|
-
/**
|
|
21
|
+
/**
|
|
22
|
+
* The `fetch` to send with, for example one with a proxy agent; the global `fetch` by default.
|
|
23
|
+
*
|
|
24
|
+
* It must post to the URL it is given: an answer from another URL counts as a redirect, which fails the request. Of
|
|
25
|
+
* an answer whose `body` is no `ReadableStream`, as with node-fetch, the size can only be checked once it is read
|
|
26
|
+
* whole.
|
|
27
|
+
*/
|
|
15
28
|
fetch?: typeof fetch;
|
|
16
|
-
/**
|
|
29
|
+
/**
|
|
30
|
+
* Time for the whole exchange in milliseconds, from sending the request to the last byte of the response; 90 s. At
|
|
31
|
+
* most 2147483647 (about 24 days), the longest `setTimeout` waits.
|
|
32
|
+
*/
|
|
17
33
|
timeoutMs?: number;
|
|
18
|
-
/** Largest response accepted, so that a faulty server cannot exhaust the memory; 16 MiB. */
|
|
34
|
+
/** Largest response accepted in bytes, so that a faulty server cannot exhaust the memory; 16 MiB. */
|
|
19
35
|
maxResponseBytes?: number;
|
|
20
36
|
}
|
|
21
37
|
/**
|
|
@@ -28,10 +44,21 @@ export declare class HttpTransport implements FinTsTransport {
|
|
|
28
44
|
readonly timeoutMs: number;
|
|
29
45
|
readonly maxResponseBytes: number;
|
|
30
46
|
private readonly fetchFn;
|
|
47
|
+
/**
|
|
48
|
+
* Throws `TypeError` if `timeoutMs` is not a positive number of at most 2147483647, or `maxResponseBytes` is not a
|
|
49
|
+
* positive number.
|
|
50
|
+
*/
|
|
31
51
|
constructor(options?: HttpTransportOptions);
|
|
32
|
-
|
|
52
|
+
/** Fails with `FinTsTransportError` at the timeout or once `signal` is aborted; sends nothing if it is already. */
|
|
53
|
+
post(url: URL, body: Uint8Array, contentType: string, signal?: AbortSignal): Promise<Uint8Array>;
|
|
33
54
|
private exchange;
|
|
34
55
|
private readBody;
|
|
56
|
+
private tooLarge;
|
|
35
57
|
close(): void;
|
|
36
58
|
}
|
|
59
|
+
/**
|
|
60
|
+
* The message of a failed request, with the message of its cause: Node.js reports `fetch failed` and the reason in the
|
|
61
|
+
* cause. Only the messages, since the error may hold the request, PIN and TAN included.
|
|
62
|
+
*/
|
|
63
|
+
export declare function failureMessage(error: unknown): string;
|
|
37
64
|
//# sourceMappingURL=transport.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transport.d.ts","sourceRoot":"","sources":["../../src/core/transport.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"transport.d.ts","sourceRoot":"","sources":["../../src/core/transport.ts"],"names":[],"mappings":"AAIA,+GAA+G;AAC/G,MAAM,WAAW,cAAc;IAC7B;;;;;;;;;;;OAWG;IACH,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;IAEhG,sEAAsE;IACtE,KAAK,IAAI,IAAI,CAAC;CACf;AAED,gDAAgD;AAChD,MAAM,WAAW,oBAAoB;IACnC;;;;;;OAMG;IACH,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;IACrB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,qGAAqG;IACrG,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAKD;;;;;GAKG;AACH,qBAAa,aAAc,YAAW,cAAc;IAClD,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC;IAClC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAe;IAEvC;;;OAGG;gBACS,OAAO,GAAE,oBAAyB;IAY9C,mHAAmH;IAC7G,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC;YA2BxF,QAAQ;YA0BR,QAAQ;IAwBtB,OAAO,CAAC,QAAQ;IAIhB,KAAK,IAAI,IAAI;CAGd;AAsBD;;;GAGG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAIrD"}
|
package/dist/core/transport.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { concatBytes } from '../util/bytes.js';
|
|
2
|
+
import { invalidArgument } from '../util/errors.js';
|
|
2
3
|
import { FinTsTransportError } from './errors.js';
|
|
4
|
+
/** The longest delay `setTimeout` takes; it fires at once for a longer one, such as `Infinity`. */
|
|
5
|
+
const maxTimeoutMs = 2 ** 31 - 1;
|
|
3
6
|
/**
|
|
4
7
|
* Default `FinTsTransport`: HTTP POST with `fetch`.
|
|
5
8
|
*
|
|
@@ -10,33 +13,52 @@ export class HttpTransport {
|
|
|
10
13
|
timeoutMs;
|
|
11
14
|
maxResponseBytes;
|
|
12
15
|
fetchFn;
|
|
16
|
+
/**
|
|
17
|
+
* Throws `TypeError` if `timeoutMs` is not a positive number of at most 2147483647, or `maxResponseBytes` is not a
|
|
18
|
+
* positive number.
|
|
19
|
+
*/
|
|
13
20
|
constructor(options = {}) {
|
|
14
|
-
|
|
21
|
+
const custom = options.fetch;
|
|
22
|
+
// Called as a plain function: a browser's native `fetch` fails as a method of another object.
|
|
23
|
+
this.fetchFn = custom === undefined ? (input, init) => fetch(input, init) : (input, init) => custom(input, init);
|
|
15
24
|
this.timeoutMs = options.timeoutMs ?? 90_000;
|
|
16
25
|
this.maxResponseBytes = options.maxResponseBytes ?? 16 << 20;
|
|
26
|
+
if (!isPositive(this.timeoutMs) || this.timeoutMs > maxTimeoutMs) {
|
|
27
|
+
throw invalidArgument(`Must be a positive number of at most ${maxTimeoutMs}`, 'timeoutMs');
|
|
28
|
+
}
|
|
29
|
+
if (!isPositive(this.maxResponseBytes))
|
|
30
|
+
throw invalidArgument('Must be a positive number', 'maxResponseBytes');
|
|
17
31
|
}
|
|
18
|
-
|
|
32
|
+
/** Fails with `FinTsTransportError` at the timeout or once `signal` is aborted; sends nothing if it is already. */
|
|
33
|
+
async post(url, body, contentType, signal) {
|
|
34
|
+
if (signal?.aborted)
|
|
35
|
+
throw new FinTsTransportError('Request aborted');
|
|
19
36
|
const controller = new AbortController();
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
reject(new FinTsTransportError('Request timed out'));
|
|
26
|
-
}, this.timeoutMs);
|
|
37
|
+
// Raced with the exchange, for a `fetch` that cannot abort a request.
|
|
38
|
+
const stopped = new Promise((_, reject) => {
|
|
39
|
+
controller.signal.addEventListener('abort', () => {
|
|
40
|
+
reject(controller.signal.reason);
|
|
41
|
+
});
|
|
27
42
|
});
|
|
43
|
+
const stop = (message) => () => {
|
|
44
|
+
controller.abort(new FinTsTransportError(message));
|
|
45
|
+
};
|
|
46
|
+
const timer = setTimeout(stop('Request timed out'), this.timeoutMs);
|
|
47
|
+
const abort = stop('Request aborted');
|
|
48
|
+
signal?.addEventListener('abort', abort);
|
|
28
49
|
try {
|
|
29
|
-
return await Promise.race([this.exchange(url, body, contentType, controller.signal),
|
|
50
|
+
return await Promise.race([this.exchange(url, body, contentType, controller.signal), stopped]);
|
|
30
51
|
}
|
|
31
52
|
catch (error) {
|
|
53
|
+
if (controller.signal.aborted)
|
|
54
|
+
throw controller.signal.reason;
|
|
32
55
|
if (error instanceof FinTsTransportError)
|
|
33
56
|
throw error;
|
|
34
|
-
|
|
35
|
-
throw new FinTsTransportError('Request timed out');
|
|
36
|
-
throw new FinTsTransportError(describe(error));
|
|
57
|
+
throw new FinTsTransportError(failureMessage(error));
|
|
37
58
|
}
|
|
38
59
|
finally {
|
|
39
60
|
clearTimeout(timer);
|
|
61
|
+
signal?.removeEventListener('abort', abort);
|
|
40
62
|
}
|
|
41
63
|
}
|
|
42
64
|
async exchange(url, body, contentType, signal) {
|
|
@@ -51,8 +73,13 @@ export class HttpTransport {
|
|
|
51
73
|
if (response.type === 'opaqueredirect') {
|
|
52
74
|
throw new FinTsTransportError('The server redirects the request, which the client does not follow');
|
|
53
75
|
}
|
|
76
|
+
// A `fetch` that ignores `redirect`, as one over XMLHttpRequest does, shows a redirect it followed only here.
|
|
77
|
+
if (response.redirected || (response.url && response.url !== withoutFragment(url))) {
|
|
78
|
+
await discard(response);
|
|
79
|
+
throw new FinTsTransportError('The fetch followed a redirect: the request may have gone to another address');
|
|
80
|
+
}
|
|
54
81
|
if (response.status < 200 || response.status > 299) {
|
|
55
|
-
await response
|
|
82
|
+
await discard(response);
|
|
56
83
|
throw new FinTsTransportError(`HTTP ${response.status} ${response.statusText}`.trim(), {
|
|
57
84
|
statusCode: response.status,
|
|
58
85
|
});
|
|
@@ -60,9 +87,15 @@ export class HttpTransport {
|
|
|
60
87
|
return this.readBody(response);
|
|
61
88
|
}
|
|
62
89
|
async readBody(response) {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
90
|
+
// A `fetch` that does not stream, as one over XMLHttpRequest or node-fetch, gives no body or one of another kind.
|
|
91
|
+
const body = response.body;
|
|
92
|
+
if (typeof body?.getReader !== 'function') {
|
|
93
|
+
const bytes = new Uint8Array(await response.arrayBuffer());
|
|
94
|
+
if (bytes.length > this.maxResponseBytes)
|
|
95
|
+
throw this.tooLarge();
|
|
96
|
+
return bytes;
|
|
97
|
+
}
|
|
98
|
+
const reader = body.getReader();
|
|
66
99
|
const chunks = [];
|
|
67
100
|
let size = 0;
|
|
68
101
|
for (;;) {
|
|
@@ -73,17 +106,41 @@ export class HttpTransport {
|
|
|
73
106
|
size += value.length;
|
|
74
107
|
if (size > this.maxResponseBytes) {
|
|
75
108
|
await reader.cancel().catch(() => undefined);
|
|
76
|
-
throw
|
|
109
|
+
throw this.tooLarge();
|
|
77
110
|
}
|
|
78
111
|
}
|
|
79
112
|
return concatBytes(chunks);
|
|
80
113
|
}
|
|
114
|
+
tooLarge() {
|
|
115
|
+
return new FinTsTransportError(`Response larger than ${this.maxResponseBytes} bytes`);
|
|
116
|
+
}
|
|
81
117
|
close() {
|
|
82
118
|
// `fetch` keeps no connection the transport could release.
|
|
83
119
|
}
|
|
84
120
|
}
|
|
85
|
-
/**
|
|
86
|
-
function
|
|
121
|
+
/** `url` as `Response.url` gives it: without fragment. */
|
|
122
|
+
function withoutFragment(url) {
|
|
123
|
+
const copy = new URL(url);
|
|
124
|
+
copy.hash = '';
|
|
125
|
+
return copy.href;
|
|
126
|
+
}
|
|
127
|
+
/** Cancels the body of a response the transport rejects, unless it cannot be cancelled, as a Node.js stream cannot. */
|
|
128
|
+
async function discard(response) {
|
|
129
|
+
try {
|
|
130
|
+
await response.body?.cancel();
|
|
131
|
+
}
|
|
132
|
+
catch {
|
|
133
|
+
// The response is rejected all the same.
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
function isPositive(value) {
|
|
137
|
+
return Number.isFinite(value) && value > 0;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* The message of a failed request, with the message of its cause: Node.js reports `fetch failed` and the reason in the
|
|
141
|
+
* cause. Only the messages, since the error may hold the request, PIN and TAN included.
|
|
142
|
+
*/
|
|
143
|
+
export function failureMessage(error) {
|
|
87
144
|
if (!(error instanceof Error))
|
|
88
145
|
return String(error);
|
|
89
146
|
const cause = error.cause;
|