@coderoftime/fints 0.0.0-stage → 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.
Files changed (249) hide show
  1. package/CHANGELOG.md +152 -0
  2. package/LICENSE +28 -0
  3. package/README.md +246 -2
  4. package/dist/client.d.ts +48 -0
  5. package/dist/client.d.ts.map +1 -0
  6. package/dist/client.js +199 -0
  7. package/dist/client.js.map +1 -0
  8. package/dist/core/account.d.ts +168 -0
  9. package/dist/core/account.d.ts.map +1 -0
  10. package/dist/core/account.js +245 -0
  11. package/dist/core/account.js.map +1 -0
  12. package/dist/core/amount.d.ts +63 -0
  13. package/dist/core/amount.d.ts.map +1 -0
  14. package/dist/core/amount.js +192 -0
  15. package/dist/core/amount.js.map +1 -0
  16. package/dist/core/balance.d.ts +55 -0
  17. package/dist/core/balance.d.ts.map +1 -0
  18. package/dist/core/balance.js +54 -0
  19. package/dist/core/balance.js.map +1 -0
  20. package/dist/core/bank-info.d.ts +49 -0
  21. package/dist/core/bank-info.d.ts.map +1 -0
  22. package/dist/core/bank-info.js +52 -0
  23. package/dist/core/bank-info.js.map +1 -0
  24. package/dist/core/client.d.ts +161 -0
  25. package/dist/core/client.d.ts.map +1 -0
  26. package/dist/core/client.js +2 -0
  27. package/dist/core/client.js.map +1 -0
  28. package/dist/core/config.d.ts +80 -0
  29. package/dist/core/config.d.ts.map +1 -0
  30. package/dist/core/config.js +153 -0
  31. package/dist/core/config.js.map +1 -0
  32. package/dist/core/errors.d.ts +153 -0
  33. package/dist/core/errors.d.ts.map +1 -0
  34. package/dist/core/errors.js +247 -0
  35. package/dist/core/errors.js.map +1 -0
  36. package/dist/core/feedback.d.ts +72 -0
  37. package/dist/core/feedback.d.ts.map +1 -0
  38. package/dist/core/feedback.js +127 -0
  39. package/dist/core/feedback.js.map +1 -0
  40. package/dist/core/transaction.d.ts +103 -0
  41. package/dist/core/transaction.d.ts.map +1 -0
  42. package/dist/core/transaction.js +96 -0
  43. package/dist/core/transaction.js.map +1 -0
  44. package/dist/core/transport.d.ts +64 -0
  45. package/dist/core/transport.d.ts.map +1 -0
  46. package/dist/core/transport.js +149 -0
  47. package/dist/core/transport.js.map +1 -0
  48. package/dist/formats/camt.d.ts +32 -0
  49. package/dist/formats/camt.d.ts.map +1 -0
  50. package/dist/formats/camt.js +242 -0
  51. package/dist/formats/camt.js.map +1 -0
  52. package/dist/formats/mt940.d.ts +54 -0
  53. package/dist/formats/mt940.d.ts.map +1 -0
  54. package/dist/formats/mt940.js +376 -0
  55. package/dist/formats/mt940.js.map +1 -0
  56. package/dist/formats/readers.d.ts +15 -0
  57. package/dist/formats/readers.d.ts.map +1 -0
  58. package/dist/formats/readers.js +42 -0
  59. package/dist/formats/readers.js.map +1 -0
  60. package/dist/formats/record-budget.d.ts +7 -0
  61. package/dist/formats/record-budget.d.ts.map +1 -0
  62. package/dist/formats/record-budget.js +17 -0
  63. package/dist/formats/record-budget.js.map +1 -0
  64. package/dist/formats/sepa-purpose.d.ts +28 -0
  65. package/dist/formats/sepa-purpose.d.ts.map +1 -0
  66. package/dist/formats/sepa-purpose.js +89 -0
  67. package/dist/formats/sepa-purpose.js.map +1 -0
  68. package/dist/index.d.ts +28 -0
  69. package/dist/index.d.ts.map +1 -0
  70. package/dist/index.js +27 -0
  71. package/dist/index.js.map +1 -0
  72. package/dist/session/app-approval.d.ts +66 -0
  73. package/dist/session/app-approval.d.ts.map +1 -0
  74. package/dist/session/app-approval.js +226 -0
  75. package/dist/session/app-approval.js.map +1 -0
  76. package/dist/session/dialog-runner.d.ts +31 -0
  77. package/dist/session/dialog-runner.d.ts.map +1 -0
  78. package/dist/session/dialog-runner.js +111 -0
  79. package/dist/session/dialog-runner.js.map +1 -0
  80. package/dist/session/login-guard.d.ts +78 -0
  81. package/dist/session/login-guard.d.ts.map +1 -0
  82. package/dist/session/login-guard.js +181 -0
  83. package/dist/session/login-guard.js.map +1 -0
  84. package/dist/session/sepa-accounts.d.ts +40 -0
  85. package/dist/session/sepa-accounts.d.ts.map +1 -0
  86. package/dist/session/sepa-accounts.js +112 -0
  87. package/dist/session/sepa-accounts.js.map +1 -0
  88. package/dist/session/session-setup.d.ts +80 -0
  89. package/dist/session/session-setup.d.ts.map +1 -0
  90. package/dist/session/session-setup.js +182 -0
  91. package/dist/session/session-setup.js.map +1 -0
  92. package/dist/session/session-state.d.ts +50 -0
  93. package/dist/session/session-state.d.ts.map +1 -0
  94. package/dist/session/session-state.js +182 -0
  95. package/dist/session/session-state.js.map +1 -0
  96. package/dist/session/signed-dialog.d.ts +77 -0
  97. package/dist/session/signed-dialog.d.ts.map +1 -0
  98. package/dist/session/signed-dialog.js +170 -0
  99. package/dist/session/signed-dialog.js.map +1 -0
  100. package/dist/session/tan-selection.d.ts +96 -0
  101. package/dist/session/tan-selection.d.ts.map +1 -0
  102. package/dist/session/tan-selection.js +189 -0
  103. package/dist/session/tan-selection.js.map +1 -0
  104. package/dist/session/user-prompts.d.ts +65 -0
  105. package/dist/session/user-prompts.d.ts.map +1 -0
  106. package/dist/session/user-prompts.js +184 -0
  107. package/dist/session/user-prompts.js.map +1 -0
  108. package/dist/tan/challenge.d.ts +135 -0
  109. package/dist/tan/challenge.d.ts.map +1 -0
  110. package/dist/tan/challenge.js +184 -0
  111. package/dist/tan/challenge.js.map +1 -0
  112. package/dist/tan/flicker.d.ts +42 -0
  113. package/dist/tan/flicker.d.ts.map +1 -0
  114. package/dist/tan/flicker.js +296 -0
  115. package/dist/tan/flicker.js.map +1 -0
  116. package/dist/tan/tan-image.d.ts +22 -0
  117. package/dist/tan/tan-image.d.ts.map +1 -0
  118. package/dist/tan/tan-image.js +43 -0
  119. package/dist/tan/tan-image.js.map +1 -0
  120. package/dist/tan/tan-models.d.ts +149 -0
  121. package/dist/tan/tan-models.d.ts.map +1 -0
  122. package/dist/tan/tan-models.js +153 -0
  123. package/dist/tan/tan-models.js.map +1 -0
  124. package/dist/util/async.d.ts +22 -0
  125. package/dist/util/async.d.ts.map +1 -0
  126. package/dist/util/async.js +45 -0
  127. package/dist/util/async.js.map +1 -0
  128. package/dist/util/bytes.d.ts +22 -0
  129. package/dist/util/bytes.d.ts.map +1 -0
  130. package/dist/util/bytes.js +128 -0
  131. package/dist/util/bytes.js.map +1 -0
  132. package/dist/util/call-context.d.ts +12 -0
  133. package/dist/util/call-context.d.ts.map +1 -0
  134. package/dist/util/call-context.js +30 -0
  135. package/dist/util/call-context.js.map +1 -0
  136. package/dist/util/dates.d.ts +55 -0
  137. package/dist/util/dates.d.ts.map +1 -0
  138. package/dist/util/dates.js +189 -0
  139. package/dist/util/dates.js.map +1 -0
  140. package/dist/util/errors.d.ts +17 -0
  141. package/dist/util/errors.d.ts.map +1 -0
  142. package/dist/util/errors.js +24 -0
  143. package/dist/util/errors.js.map +1 -0
  144. package/dist/util/immutable-map.d.ts +16 -0
  145. package/dist/util/immutable-map.d.ts.map +1 -0
  146. package/dist/util/immutable-map.js +38 -0
  147. package/dist/util/immutable-map.js.map +1 -0
  148. package/dist/util/json.d.ts +17 -0
  149. package/dist/util/json.d.ts.map +1 -0
  150. package/dist/util/json.js +62 -0
  151. package/dist/util/json.js.map +1 -0
  152. package/dist/util/text.d.ts +37 -0
  153. package/dist/util/text.d.ts.map +1 -0
  154. package/dist/util/text.js +107 -0
  155. package/dist/util/text.js.map +1 -0
  156. package/dist/util/xml.d.ts +36 -0
  157. package/dist/util/xml.d.ts.map +1 -0
  158. package/dist/util/xml.js +194 -0
  159. package/dist/util/xml.js.map +1 -0
  160. package/dist/v3/account-extension.d.ts +25 -0
  161. package/dist/v3/account-extension.d.ts.map +1 -0
  162. package/dist/v3/account-extension.js +173 -0
  163. package/dist/v3/account-extension.js.map +1 -0
  164. package/dist/v3/bank-connection.d.ts +34 -0
  165. package/dist/v3/bank-connection.d.ts.map +1 -0
  166. package/dist/v3/bank-connection.js +58 -0
  167. package/dist/v3/bank-connection.js.map +1 -0
  168. package/dist/v3/dialog.d.ts +112 -0
  169. package/dist/v3/dialog.d.ts.map +1 -0
  170. package/dist/v3/dialog.js +241 -0
  171. package/dist/v3/dialog.js.map +1 -0
  172. package/dist/v3/message.d.ts +85 -0
  173. package/dist/v3/message.d.ts.map +1 -0
  174. package/dist/v3/message.js +303 -0
  175. package/dist/v3/message.js.map +1 -0
  176. package/dist/v3/parameter-store.d.ts +75 -0
  177. package/dist/v3/parameter-store.d.ts.map +1 -0
  178. package/dist/v3/parameter-store.js +143 -0
  179. package/dist/v3/parameter-store.js.map +1 -0
  180. package/dist/v3/parameters.d.ts +105 -0
  181. package/dist/v3/parameters.d.ts.map +1 -0
  182. package/dist/v3/parameters.js +450 -0
  183. package/dist/v3/parameters.js.map +1 -0
  184. package/dist/v3/protocol.d.ts +61 -0
  185. package/dist/v3/protocol.d.ts.map +1 -0
  186. package/dist/v3/protocol.js +113 -0
  187. package/dist/v3/protocol.js.map +1 -0
  188. package/dist/v3/queries.d.ts +51 -0
  189. package/dist/v3/queries.d.ts.map +1 -0
  190. package/dist/v3/queries.js +120 -0
  191. package/dist/v3/queries.js.map +1 -0
  192. package/dist/v3/segments.d.ts +106 -0
  193. package/dist/v3/segments.d.ts.map +1 -0
  194. package/dist/v3/segments.js +325 -0
  195. package/dist/v3/segments.js.map +1 -0
  196. package/dist/v3/syntax.d.ts +127 -0
  197. package/dist/v3/syntax.d.ts.map +1 -0
  198. package/dist/v3/syntax.js +367 -0
  199. package/dist/v3/syntax.js.map +1 -0
  200. package/package.json +67 -4
  201. package/src/client.ts +252 -0
  202. package/src/core/account.ts +323 -0
  203. package/src/core/amount.ts +211 -0
  204. package/src/core/balance.ts +85 -0
  205. package/src/core/bank-info.ts +66 -0
  206. package/src/core/client.ts +186 -0
  207. package/src/core/config.ts +182 -0
  208. package/src/core/errors.ts +277 -0
  209. package/src/core/feedback.ts +140 -0
  210. package/src/core/transaction.ts +161 -0
  211. package/src/core/transport.ts +189 -0
  212. package/src/formats/camt.ts +266 -0
  213. package/src/formats/mt940.ts +419 -0
  214. package/src/formats/readers.ts +49 -0
  215. package/src/formats/record-budget.ts +18 -0
  216. package/src/formats/sepa-purpose.ts +94 -0
  217. package/src/index.ts +70 -0
  218. package/src/session/app-approval.ts +278 -0
  219. package/src/session/dialog-runner.ts +122 -0
  220. package/src/session/login-guard.ts +221 -0
  221. package/src/session/sepa-accounts.ts +115 -0
  222. package/src/session/session-setup.ts +184 -0
  223. package/src/session/session-state.ts +204 -0
  224. package/src/session/signed-dialog.ts +192 -0
  225. package/src/session/tan-selection.ts +203 -0
  226. package/src/session/user-prompts.ts +193 -0
  227. package/src/tan/challenge.ts +261 -0
  228. package/src/tan/flicker.ts +308 -0
  229. package/src/tan/tan-image.ts +38 -0
  230. package/src/tan/tan-models.ts +252 -0
  231. package/src/util/async.ts +48 -0
  232. package/src/util/bytes.ts +129 -0
  233. package/src/util/call-context.ts +41 -0
  234. package/src/util/dates.ts +210 -0
  235. package/src/util/errors.ts +27 -0
  236. package/src/util/immutable-map.ts +47 -0
  237. package/src/util/json.ts +67 -0
  238. package/src/util/text.ts +112 -0
  239. package/src/util/xml.ts +183 -0
  240. package/src/v3/account-extension.ts +185 -0
  241. package/src/v3/bank-connection.ts +67 -0
  242. package/src/v3/dialog.ts +283 -0
  243. package/src/v3/message.ts +373 -0
  244. package/src/v3/parameter-store.ts +160 -0
  245. package/src/v3/parameters.ts +524 -0
  246. package/src/v3/protocol.ts +148 -0
  247. package/src/v3/queries.ts +190 -0
  248. package/src/v3/segments.ts +374 -0
  249. package/src/v3/syntax.ts +369 -0
@@ -0,0 +1,63 @@
1
+ /** A money amount stored as an integer number of `scale`-digit minor units. */
2
+ export declare class Amount {
3
+ /** The amount in units of 10^-`scale` of the currency, negative for a debit: 1234 with scale 2 is 12.34. */
4
+ readonly minorUnits: number;
5
+ /** Number of decimal places `minorUnits` has, from 0 to 5. */
6
+ readonly scale: number;
7
+ /** ISO 4217 currency code, for example `EUR`. */
8
+ readonly currency: string;
9
+ /**
10
+ * An amount of `minorUnits` with `scale` decimal places; throws `RangeError` for a `scale` outside 0 to 5, and for
11
+ * `minorUnits` that are no integer or beyond 2^53 - 1 in either direction, about 90 trillion at two decimal places.
12
+ */
13
+ constructor(minorUnits: number, scale: number, currency: string);
14
+ /**
15
+ * Parses a number as banks send it: digits with at most one decimal separator, `,` (FinTS 3.0, MT940) or `.` (camt),
16
+ * and no thousands separators.
17
+ *
18
+ * The amount has the decimal places of the `currency`'s minor unit (ISO 4217): two for most currencies, none for
19
+ * `JPY`, three for `KWD`. It has more where the value has more significant digits. So `100,` in `EUR` is `100.00`, in
20
+ * `JPY` `100`.
21
+ *
22
+ * Throws `FormatError` for anything else, so that `1.234,56` in bank data is an error, not a guess, and for more than
23
+ * five decimal places (trailing zeros aside) or more than 15 digits.
24
+ */
25
+ static parseDecimal(value: string, currency: string): Amount;
26
+ /** The amount as a floating-point number, which cannot hold every decimal fraction exactly; do not calculate with it. */
27
+ get value(): number;
28
+ /** Whether the amount is below zero. */
29
+ get isNegative(): boolean;
30
+ /** Whether the amount is zero. */
31
+ get isZero(): boolean;
32
+ /** This amount with the opposite sign. */
33
+ negate(): Amount;
34
+ /** This amount without its sign. */
35
+ abs(): Amount;
36
+ /**
37
+ * The sum with `other`, at the larger of the two scales; throws `TypeError` for another currency and `RangeError` for
38
+ * a sum beyond what an amount holds.
39
+ */
40
+ add(other: Amount): Amount;
41
+ /** The difference to `other`; throws `TypeError` for another currency. */
42
+ subtract(other: Amount): Amount;
43
+ /** Compares by value, whatever the scales; throws `TypeError` for another currency. */
44
+ compareTo(other: Amount): number;
45
+ /** Whether `other` is the same amount in the same currency, whatever the `scale`: 1.50 equals 1.500. */
46
+ equals(other: unknown): boolean;
47
+ /** Formats the amount without currency, for example `-12.50`. */
48
+ toDecimalString(decimalSeparator?: string): string;
49
+ toString(): string;
50
+ /** The minor units of both amounts at the larger scale, as `bigint`s, since the factor could leave the safe range. */
51
+ private atCommonScale;
52
+ private rescale;
53
+ private compareValue;
54
+ private checkCurrency;
55
+ }
56
+ /**
57
+ * `amount` as a credit (unchanged) or a debit (negated), by the bank's credit/debit `mark`.
58
+ *
59
+ * Throws `FormatError` for any other `mark`, `undefined` included: a missing mark must not be read as a credit. It does
60
+ * as well for a negative `amount`, whose sign the mark would turn: the mark alone gives the direction.
61
+ */
62
+ export declare function withMark(amount: Amount, mark: string | undefined, credit: string, debit: string): Amount;
63
+ //# sourceMappingURL=amount.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"amount.d.ts","sourceRoot":"","sources":["../../src/core/amount.ts"],"names":[],"mappings":"AAmDA,+EAA+E;AAC/E,qBAAa,MAAM;IACjB,4GAA4G;IAC5G,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAE5B,8DAA8D;IAC9D,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IAEvB,iDAAiD;IACjD,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAE1B;;;OAGG;gBACS,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM;IAW/D;;;;;;;;;;OAUG;IACH,MAAM,CAAC,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM;IAmB5D,yHAAyH;IACzH,IAAI,KAAK,IAAI,MAAM,CAElB;IAED,wCAAwC;IACxC,IAAI,UAAU,IAAI,OAAO,CAExB;IAED,kCAAkC;IAClC,IAAI,MAAM,IAAI,OAAO,CAEpB;IAED,0CAA0C;IAC1C,MAAM,IAAI,MAAM;IAIhB,oCAAoC;IACpC,GAAG,IAAI,MAAM;IAIb;;;OAGG;IACH,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;IAU1B,0EAA0E;IAC1E,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;IAI/B,uFAAuF;IACvF,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;IAKhC,wGAAwG;IACxG,MAAM,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO;IAI/B,iEAAiE;IACjE,eAAe,CAAC,gBAAgB,SAAM,GAAG,MAAM;IAU/C,QAAQ,IAAI,MAAM;IAIlB,sHAAsH;IACtH,OAAO,CAAC,aAAa;IAKrB,OAAO,CAAC,OAAO;IAIf,OAAO,CAAC,YAAY;IAMpB,OAAO,CAAC,aAAa;CAItB;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAKxG"}
@@ -0,0 +1,192 @@
1
+ import { FormatError } from '../util/errors.js';
2
+ /** Most decimal places an amount has: ISO 20022, the widest of the bank formats, allows five. */
3
+ const maxScale = 5;
4
+ /** Largest `minorUnits` an amount holds: 2^53 - 1, which JavaScript numbers represent exactly. */
5
+ const maxMinorUnits = Number.MAX_SAFE_INTEGER;
6
+ const powersOfTen = [1, 10, 100, 1000, 10000, 100000];
7
+ /** Most digits a parsed amount has: few enough that the sum of two parsed amounts still fits. */
8
+ const maxDigits = 15;
9
+ const decimal = /^([+-]?)(\d*)(?:[.,](\d*))?$/;
10
+ /** Decimal places of the minor unit of `currency` (ISO 4217): two, except for the currencies listed here. */
11
+ function minorUnitDigits(currency) {
12
+ switch (currency) {
13
+ case 'BIF':
14
+ case 'CLP':
15
+ case 'DJF':
16
+ case 'GNF':
17
+ case 'ISK':
18
+ case 'JPY':
19
+ case 'KMF':
20
+ case 'KRW':
21
+ case 'PYG':
22
+ case 'RWF':
23
+ case 'UGX':
24
+ case 'UYI':
25
+ case 'VND':
26
+ case 'VUV':
27
+ case 'XAF':
28
+ case 'XOF':
29
+ case 'XPF':
30
+ return 0;
31
+ case 'BHD':
32
+ case 'IQD':
33
+ case 'JOD':
34
+ case 'KWD':
35
+ case 'LYD':
36
+ case 'OMR':
37
+ case 'TND':
38
+ return 3;
39
+ case 'CLF':
40
+ case 'UYW':
41
+ return 4;
42
+ default:
43
+ return 2;
44
+ }
45
+ }
46
+ /** A money amount stored as an integer number of `scale`-digit minor units. */
47
+ export class Amount {
48
+ /** The amount in units of 10^-`scale` of the currency, negative for a debit: 1234 with scale 2 is 12.34. */
49
+ minorUnits;
50
+ /** Number of decimal places `minorUnits` has, from 0 to 5. */
51
+ scale;
52
+ /** ISO 4217 currency code, for example `EUR`. */
53
+ currency;
54
+ /**
55
+ * An amount of `minorUnits` with `scale` decimal places; throws `RangeError` for a `scale` outside 0 to 5, and for
56
+ * `minorUnits` that are no integer or beyond 2^53 - 1 in either direction, about 90 trillion at two decimal places.
57
+ */
58
+ constructor(minorUnits, scale, currency) {
59
+ if (!Number.isInteger(scale) || scale < 0 || scale > maxScale) {
60
+ throw new RangeError(`scale must be an integer from 0 to ${maxScale}: ${scale}`);
61
+ }
62
+ if (!Number.isSafeInteger(minorUnits))
63
+ throw new RangeError(`minorUnits out of range: ${minorUnits}`);
64
+ // No negative zero, which would format as `-0.00`.
65
+ this.minorUnits = minorUnits === 0 ? 0 : minorUnits;
66
+ this.scale = scale;
67
+ this.currency = currency;
68
+ }
69
+ /**
70
+ * Parses a number as banks send it: digits with at most one decimal separator, `,` (FinTS 3.0, MT940) or `.` (camt),
71
+ * and no thousands separators.
72
+ *
73
+ * The amount has the decimal places of the `currency`'s minor unit (ISO 4217): two for most currencies, none for
74
+ * `JPY`, three for `KWD`. It has more where the value has more significant digits. So `100,` in `EUR` is `100.00`, in
75
+ * `JPY` `100`.
76
+ *
77
+ * Throws `FormatError` for anything else, so that `1.234,56` in bank data is an error, not a guess, and for more than
78
+ * five decimal places (trailing zeros aside) or more than 15 digits.
79
+ */
80
+ static parseDecimal(value, currency) {
81
+ const match = decimal.exec(value.trim());
82
+ const whole = match?.[2] ?? '';
83
+ let fraction = match?.[3] ?? '';
84
+ if (!match || (whole === '' && fraction === ''))
85
+ throw new FormatError('Invalid amount', value);
86
+ const minorDigits = minorUnitDigits(currency);
87
+ while (fraction.length > minorDigits && fraction.endsWith('0')) {
88
+ fraction = fraction.substring(0, fraction.length - 1);
89
+ }
90
+ fraction = fraction.padEnd(minorDigits, '0');
91
+ const digits = `${whole.replace(/^0+/, '')}${fraction}`;
92
+ if (fraction.length > maxScale || digits.length > maxDigits) {
93
+ throw new FormatError(`Amount with more than ${maxScale} decimal places or ${maxDigits} digits`, value);
94
+ }
95
+ // Nothing is left of a zero without decimal places, such as `0` in `JPY`.
96
+ const units = digits === '' ? 0 : Number(digits);
97
+ return new Amount(match[1] === '-' ? -units : units, fraction.length, currency);
98
+ }
99
+ /** The amount as a floating-point number, which cannot hold every decimal fraction exactly; do not calculate with it. */
100
+ get value() {
101
+ return this.minorUnits / powersOfTen[this.scale];
102
+ }
103
+ /** Whether the amount is below zero. */
104
+ get isNegative() {
105
+ return this.minorUnits < 0;
106
+ }
107
+ /** Whether the amount is zero. */
108
+ get isZero() {
109
+ return this.minorUnits === 0;
110
+ }
111
+ /** This amount with the opposite sign. */
112
+ negate() {
113
+ return new Amount(-this.minorUnits, this.scale, this.currency);
114
+ }
115
+ /** This amount without its sign. */
116
+ abs() {
117
+ return this.isNegative ? this.negate() : this;
118
+ }
119
+ /**
120
+ * The sum with `other`, at the larger of the two scales; throws `TypeError` for another currency and `RangeError` for
121
+ * a sum beyond what an amount holds.
122
+ */
123
+ add(other) {
124
+ this.checkCurrency(other);
125
+ const [mine, theirs] = this.atCommonScale(other);
126
+ const sum = mine + theirs;
127
+ const limit = BigInt(maxMinorUnits);
128
+ if (sum > limit || sum < -limit)
129
+ throw new RangeError(`The sum of ${this.toString()} and ${other.toString()} is too large for an Amount`);
130
+ return new Amount(Number(sum), Math.max(this.scale, other.scale), this.currency);
131
+ }
132
+ /** The difference to `other`; throws `TypeError` for another currency. */
133
+ subtract(other) {
134
+ return this.add(other.negate());
135
+ }
136
+ /** Compares by value, whatever the scales; throws `TypeError` for another currency. */
137
+ compareTo(other) {
138
+ this.checkCurrency(other);
139
+ return this.compareValue(other);
140
+ }
141
+ /** Whether `other` is the same amount in the same currency, whatever the `scale`: 1.50 equals 1.500. */
142
+ equals(other) {
143
+ return other instanceof Amount && other.currency === this.currency && this.compareValue(other) === 0;
144
+ }
145
+ /** Formats the amount without currency, for example `-12.50`. */
146
+ toDecimalString(decimalSeparator = '.') {
147
+ const digits = Math.abs(this.minorUnits)
148
+ .toString()
149
+ .padStart(this.scale + 1, '0');
150
+ const whole = digits.substring(0, digits.length - this.scale);
151
+ const fraction = digits.substring(digits.length - this.scale);
152
+ const sign = this.isNegative ? '-' : '';
153
+ return this.scale === 0 ? `${sign}${whole}` : `${sign}${whole}${decimalSeparator}${fraction}`;
154
+ }
155
+ toString() {
156
+ return `${this.toDecimalString()} ${this.currency}`;
157
+ }
158
+ /** The minor units of both amounts at the larger scale, as `bigint`s, since the factor could leave the safe range. */
159
+ atCommonScale(other) {
160
+ const target = Math.max(this.scale, other.scale);
161
+ return [this.rescale(target), other.rescale(target)];
162
+ }
163
+ rescale(target) {
164
+ return BigInt(this.minorUnits) * BigInt(powersOfTen[target - this.scale]);
165
+ }
166
+ compareValue(other) {
167
+ if (this.scale === other.scale)
168
+ return Math.sign(this.minorUnits - other.minorUnits);
169
+ const [mine, theirs] = this.atCommonScale(other);
170
+ return mine === theirs ? 0 : mine < theirs ? -1 : 1;
171
+ }
172
+ checkCurrency(other) {
173
+ if (other.currency !== this.currency)
174
+ throw new TypeError(`Currency mismatch: ${this.currency} vs ${other.currency}`);
175
+ }
176
+ }
177
+ /**
178
+ * `amount` as a credit (unchanged) or a debit (negated), by the bank's credit/debit `mark`.
179
+ *
180
+ * Throws `FormatError` for any other `mark`, `undefined` included: a missing mark must not be read as a credit. It does
181
+ * as well for a negative `amount`, whose sign the mark would turn: the mark alone gives the direction.
182
+ */
183
+ export function withMark(amount, mark, credit, debit) {
184
+ if (amount.isNegative)
185
+ throw new FormatError('Negative amount with a credit/debit mark', amount.toString());
186
+ if (mark === credit)
187
+ return amount;
188
+ if (mark === debit)
189
+ return amount.negate();
190
+ throw new FormatError(`Credit/debit mark is neither "${credit}" nor "${debit}"`, mark);
191
+ }
192
+ //# sourceMappingURL=amount.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"amount.js","sourceRoot":"","sources":["../../src/core/amount.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,iGAAiG;AACjG,MAAM,QAAQ,GAAG,CAAC,CAAC;AAEnB,kGAAkG;AAClG,MAAM,aAAa,GAAG,MAAM,CAAC,gBAAgB,CAAC;AAC9C,MAAM,WAAW,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;AAEtD,iGAAiG;AACjG,MAAM,SAAS,GAAG,EAAE,CAAC;AAErB,MAAM,OAAO,GAAG,8BAA8B,CAAC;AAE/C,6GAA6G;AAC7G,SAAS,eAAe,CAAC,QAAgB;IACvC,QAAQ,QAAQ,EAAE,CAAC;QACjB,KAAK,KAAK,CAAC;QACX,KAAK,KAAK,CAAC;QACX,KAAK,KAAK,CAAC;QACX,KAAK,KAAK,CAAC;QACX,KAAK,KAAK,CAAC;QACX,KAAK,KAAK,CAAC;QACX,KAAK,KAAK,CAAC;QACX,KAAK,KAAK,CAAC;QACX,KAAK,KAAK,CAAC;QACX,KAAK,KAAK,CAAC;QACX,KAAK,KAAK,CAAC;QACX,KAAK,KAAK,CAAC;QACX,KAAK,KAAK,CAAC;QACX,KAAK,KAAK,CAAC;QACX,KAAK,KAAK,CAAC;QACX,KAAK,KAAK,CAAC;QACX,KAAK,KAAK;YACR,OAAO,CAAC,CAAC;QACX,KAAK,KAAK,CAAC;QACX,KAAK,KAAK,CAAC;QACX,KAAK,KAAK,CAAC;QACX,KAAK,KAAK,CAAC;QACX,KAAK,KAAK,CAAC;QACX,KAAK,KAAK,CAAC;QACX,KAAK,KAAK;YACR,OAAO,CAAC,CAAC;QACX,KAAK,KAAK,CAAC;QACX,KAAK,KAAK;YAC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K,GAAG,EAAE,IAAI,CAAC,CAAC;AACzF,CAAC"}
@@ -0,0 +1,55 @@
1
+ import type { Account } from './account.js';
2
+ import type { Amount } from './amount.js';
3
+ /** What `Balance` takes; the bank states the amounts it knows. */
4
+ export interface BalanceInit {
5
+ account: Account;
6
+ booked: Amount;
7
+ bookedAsOf: Date;
8
+ bookedAsOfTime?: Date | undefined;
9
+ pending?: Amount | undefined;
10
+ creditLine?: Amount | undefined;
11
+ available?: Amount | undefined;
12
+ used?: Amount | undefined;
13
+ overdraft?: Amount | undefined;
14
+ bookingDate?: Date | undefined;
15
+ bookingTime?: Date | undefined;
16
+ productName?: string | undefined;
17
+ }
18
+ /** Account balance as reported by the bank. */
19
+ export declare class Balance {
20
+ /** The account the balance belongs to. */
21
+ readonly account: Account;
22
+ /** Booked balance; negative when overdrawn. */
23
+ readonly booked: Amount;
24
+ /**
25
+ * The calendar day the bank states with the booked balance: the day it transmitted the balance, which need not be the
26
+ * day the balance was booked (`bookingDate`). A local `Date` at midnight.
27
+ */
28
+ readonly bookedAsOf: Date;
29
+ /** The exact moment of `bookedAsOf`, where the bank states the time of day as well; `undefined` otherwise. */
30
+ readonly bookedAsOfTime: Date | undefined;
31
+ /** Balance of pending (not yet booked) transactions, if the bank reports it. */
32
+ readonly pending: Amount | undefined;
33
+ /** Arranged overdraft limit. */
34
+ readonly creditLine: Amount | undefined;
35
+ /** Amount currently available for payments. */
36
+ readonly available: Amount | undefined;
37
+ /** Amount already drawn on the account's limit. */
38
+ readonly used: Amount | undefined;
39
+ /** Amount by which the account exceeds its limit. */
40
+ readonly overdraft: Amount | undefined;
41
+ /** The calendar day the booked balance was booked (Buchungszeitpunkt), where the bank states it. */
42
+ readonly bookingDate: Date | undefined;
43
+ /** The exact moment of `bookingDate`, where the bank states the time of day as well; `undefined` otherwise. */
44
+ readonly bookingTime: Date | undefined;
45
+ /** The bank's name for the account, for example `Girokonto`. */
46
+ readonly productName: string | undefined;
47
+ /** Takes copies of the dates of `init`: each balance has its own, which no other one shares. */
48
+ constructor(init: BalanceInit);
49
+ /**
50
+ * The account, as `Account.toString` shows it, and the date; no amount, so that logs and crash reports do not collect
51
+ * account data.
52
+ */
53
+ toString(): string;
54
+ }
55
+ //# sourceMappingURL=balance.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"balance.d.ts","sourceRoot":"","sources":["../../src/core/balance.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAE1C,kEAAkE;AAClE,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,IAAI,CAAC;IACjB,cAAc,CAAC,EAAE,IAAI,GAAG,SAAS,CAAC;IAClC,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC/B,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1B,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC/B,WAAW,CAAC,EAAE,IAAI,GAAG,SAAS,CAAC;IAC/B,WAAW,CAAC,EAAE,IAAI,GAAG,SAAS,CAAC;IAC/B,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAClC;AAED,+CAA+C;AAC/C,qBAAa,OAAO;IAClB,0CAA0C;IAC1C,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAE1B,+CAA+C;IAC/C,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAExB;;;OAGG;IACH,QAAQ,CAAC,UAAU,EAAE,IAAI,CAAC;IAE1B,8GAA8G;IAC9G,QAAQ,CAAC,cAAc,EAAE,IAAI,GAAG,SAAS,CAAC;IAE1C,gFAAgF;IAChF,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IAErC,gCAAgC;IAChC,QAAQ,CAAC,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC;IAExC,+CAA+C;IAC/C,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAEvC,mDAAmD;IACnD,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;IAElC,qDAAqD;IACrD,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAEvC,oGAAoG;IACpG,QAAQ,CAAC,WAAW,EAAE,IAAI,GAAG,SAAS,CAAC;IAEvC,+GAA+G;IAC/G,QAAQ,CAAC,WAAW,EAAE,IAAI,GAAG,SAAS,CAAC;IAEvC,gEAAgE;IAChE,QAAQ,CAAC,WAAW,EAAE,MAAM,GAAG,SAAS,CAAC;IAEzC,gGAAgG;gBACpF,IAAI,EAAE,WAAW;IAe7B;;;OAGG;IACH,QAAQ,IAAI,MAAM;CAGnB"}
@@ -0,0 +1,54 @@
1
+ import { copyDate, formatIsoDate } from '../util/dates.js';
2
+ /** Account balance as reported by the bank. */
3
+ export class Balance {
4
+ /** The account the balance belongs to. */
5
+ account;
6
+ /** Booked balance; negative when overdrawn. */
7
+ booked;
8
+ /**
9
+ * The calendar day the bank states with the booked balance: the day it transmitted the balance, which need not be the
10
+ * day the balance was booked (`bookingDate`). A local `Date` at midnight.
11
+ */
12
+ bookedAsOf;
13
+ /** The exact moment of `bookedAsOf`, where the bank states the time of day as well; `undefined` otherwise. */
14
+ bookedAsOfTime;
15
+ /** Balance of pending (not yet booked) transactions, if the bank reports it. */
16
+ pending;
17
+ /** Arranged overdraft limit. */
18
+ creditLine;
19
+ /** Amount currently available for payments. */
20
+ available;
21
+ /** Amount already drawn on the account's limit. */
22
+ used;
23
+ /** Amount by which the account exceeds its limit. */
24
+ overdraft;
25
+ /** The calendar day the booked balance was booked (Buchungszeitpunkt), where the bank states it. */
26
+ bookingDate;
27
+ /** The exact moment of `bookingDate`, where the bank states the time of day as well; `undefined` otherwise. */
28
+ bookingTime;
29
+ /** The bank's name for the account, for example `Girokonto`. */
30
+ productName;
31
+ /** Takes copies of the dates of `init`: each balance has its own, which no other one shares. */
32
+ constructor(init) {
33
+ this.account = init.account;
34
+ this.booked = init.booked;
35
+ this.bookedAsOf = copyDate(init.bookedAsOf);
36
+ this.bookedAsOfTime = copyDate(init.bookedAsOfTime);
37
+ this.pending = init.pending;
38
+ this.creditLine = init.creditLine;
39
+ this.available = init.available;
40
+ this.used = init.used;
41
+ this.overdraft = init.overdraft;
42
+ this.bookingDate = copyDate(init.bookingDate);
43
+ this.bookingTime = copyDate(init.bookingTime);
44
+ this.productName = init.productName;
45
+ }
46
+ /**
47
+ * The account, as `Account.toString` shows it, and the date; no amount, so that logs and crash reports do not collect
48
+ * account data.
49
+ */
50
+ toString() {
51
+ return `Balance(${this.account.toString()}, ${formatIsoDate(this.bookedAsOf)})`;
52
+ }
53
+ }
54
+ //# sourceMappingURL=balance.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"balance.js","sourceRoot":"","sources":["../../src/core/balance.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAoB3D,+CAA+C;AAC/C,MAAM,OAAO,OAAO;IAClB,0CAA0C;IACjC,OAAO,CAAU;IAE1B,+CAA+C;IACtC,MAAM,CAAS;IAExB;;;OAGG;IACM,UAAU,CAAO;IAE1B,8GAA8G;IACrG,cAAc,CAAmB;IAE1C,gFAAgF;IACvE,OAAO,CAAqB;IAErC,gCAAgC;IACvB,UAAU,CAAqB;IAExC,+CAA+C;IACtC,SAAS,CAAqB;IAEvC,mDAAmD;IAC1C,IAAI,CAAqB;IAElC,qDAAqD;IAC5C,SAAS,CAAqB;IAEvC,oGAAoG;IAC3F,WAAW,CAAmB;IAEvC,+GAA+G;IACtG,WAAW,CAAmB;IAEvC,gEAAgE;IACvD,WAAW,CAAqB;IAEzC,gGAAgG;IAChG,YAAY,IAAiB;QAC3B,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC;QAC5B,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;QAC1B,IAAI,CAAC,UAAU,GAAG,QAAQ,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAC5C,IAAI,CAAC,cAAc,GAAG,QAAQ,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;QACpD,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC;QAC5B,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC;QAClC,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC;QAChC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;QACtB,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC;QAChC,IAAI,CAAC,WAAW,GAAG,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;QAC9C,IAAI,CAAC,WAAW,GAAG,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;QAC9C,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,WAAW,CAAC;IACtC,CAAC;IAED;;;OAGG;IACH,QAAQ;QACN,OAAO,WAAW,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,KAAK,aAAa,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC;IAClF,CAAC;CACF"}
@@ -0,0 +1,49 @@
1
+ /** General bank information from the bank parameter data (BPD). */
2
+ export declare class BankInfo {
3
+ /** German bank code (BLZ). */
4
+ readonly bankCode: string;
5
+ /** The bank's name. */
6
+ readonly name: string | undefined;
7
+ /** Version of the bank parameter data this information comes from. */
8
+ readonly bpdVersion: number;
9
+ /** FinTS versions the bank supports, as it names them. */
10
+ readonly supportedVersions: readonly string[];
11
+ /** Languages the bank's messages come in, as codes the bank defines. */
12
+ readonly languages: readonly string[];
13
+ /** Largest message in kilobytes (1024 bytes) the bank accepts; the client sends nothing larger. */
14
+ readonly maxMessageSize: number | undefined;
15
+ /**
16
+ * Time in seconds before which a client must not send a life-indicator message to keep an idle dialog open, `0` for
17
+ * none (HIBPA, Formals C.9). This client sends no such messages.
18
+ */
19
+ readonly minTimeout: number | undefined;
20
+ /**
21
+ * Time in seconds after which the bank will likely end a dialog without messages, `0` for no limit (HIBPA, Formals
22
+ * C.9). The client starts a new dialog for a call after that time, or after 5 minutes where the bank states none.
23
+ */
24
+ readonly maxTimeout: number | undefined;
25
+ constructor(init: {
26
+ bankCode: string;
27
+ name?: string | undefined;
28
+ bpdVersion: number;
29
+ supportedVersions?: readonly string[];
30
+ languages?: readonly string[];
31
+ maxMessageSize?: number | undefined;
32
+ minTimeout?: number | undefined;
33
+ maxTimeout?: number | undefined;
34
+ });
35
+ }
36
+ /** Free-text message sent by the bank during login. */
37
+ export declare class BankMessage {
38
+ /** What the message is about. */
39
+ readonly subject: string;
40
+ /** The message itself. */
41
+ readonly text: string;
42
+ constructor(
43
+ /** What the message is about. */
44
+ subject: string,
45
+ /** The message itself. */
46
+ text: string);
47
+ toString(): string;
48
+ }
49
+ //# sourceMappingURL=bank-info.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bank-info.d.ts","sourceRoot":"","sources":["../../src/core/bank-info.ts"],"names":[],"mappings":"AAAA,mEAAmE;AACnE,qBAAa,QAAQ;IACnB,8BAA8B;IAC9B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAE1B,uBAAuB;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;IAElC,sEAAsE;IACtE,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAE5B,0DAA0D;IAC1D,QAAQ,CAAC,iBAAiB,EAAE,SAAS,MAAM,EAAE,CAAC;IAE9C,wEAAwE;IACxE,QAAQ,CAAC,SAAS,EAAE,SAAS,MAAM,EAAE,CAAC;IAEtC,mGAAmG;IACnG,QAAQ,CAAC,cAAc,EAAE,MAAM,GAAG,SAAS,CAAC;IAE5C;;;OAGG;IACH,QAAQ,CAAC,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC;IAExC;;;OAGG;IACH,QAAQ,CAAC,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC;gBAE5B,IAAI,EAAE;QAChB,QAAQ,EAAE,MAAM,CAAC;QACjB,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;QAC1B,UAAU,EAAE,MAAM,CAAC;QACnB,iBAAiB,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;QACtC,SAAS,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;QAC9B,cAAc,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;QACpC,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;QAChC,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;KACjC;CAUF;AAED,uDAAuD;AACvD,qBAAa,WAAW;IAEpB,iCAAiC;IACjC,QAAQ,CAAC,OAAO,EAAE,MAAM;IACxB,0BAA0B;IAC1B,QAAQ,CAAC,IAAI,EAAE,MAAM;;IAHrB,iCAAiC;IACxB,OAAO,EAAE,MAAM;IACxB,0BAA0B;IACjB,IAAI,EAAE,MAAM;IAGvB,QAAQ,IAAI,MAAM;CAGnB"}
@@ -0,0 +1,52 @@
1
+ /** General bank information from the bank parameter data (BPD). */
2
+ export class BankInfo {
3
+ /** German bank code (BLZ). */
4
+ bankCode;
5
+ /** The bank's name. */
6
+ name;
7
+ /** Version of the bank parameter data this information comes from. */
8
+ bpdVersion;
9
+ /** FinTS versions the bank supports, as it names them. */
10
+ supportedVersions;
11
+ /** Languages the bank's messages come in, as codes the bank defines. */
12
+ languages;
13
+ /** Largest message in kilobytes (1024 bytes) the bank accepts; the client sends nothing larger. */
14
+ maxMessageSize;
15
+ /**
16
+ * Time in seconds before which a client must not send a life-indicator message to keep an idle dialog open, `0` for
17
+ * none (HIBPA, Formals C.9). This client sends no such messages.
18
+ */
19
+ minTimeout;
20
+ /**
21
+ * Time in seconds after which the bank will likely end a dialog without messages, `0` for no limit (HIBPA, Formals
22
+ * C.9). The client starts a new dialog for a call after that time, or after 5 minutes where the bank states none.
23
+ */
24
+ maxTimeout;
25
+ constructor(init) {
26
+ this.bankCode = init.bankCode;
27
+ this.name = init.name;
28
+ this.bpdVersion = init.bpdVersion;
29
+ this.supportedVersions = Object.freeze([...(init.supportedVersions ?? [])]);
30
+ this.languages = Object.freeze([...(init.languages ?? [])]);
31
+ this.maxMessageSize = init.maxMessageSize;
32
+ this.minTimeout = init.minTimeout;
33
+ this.maxTimeout = init.maxTimeout;
34
+ }
35
+ }
36
+ /** Free-text message sent by the bank during login. */
37
+ export class BankMessage {
38
+ subject;
39
+ text;
40
+ constructor(
41
+ /** What the message is about. */
42
+ subject,
43
+ /** The message itself. */
44
+ text) {
45
+ this.subject = subject;
46
+ this.text = text;
47
+ }
48
+ toString() {
49
+ return `${this.subject}: ${this.text}`;
50
+ }
51
+ }
52
+ //# sourceMappingURL=bank-info.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bank-info.js","sourceRoot":"","sources":["../../src/core/bank-info.ts"],"names":[],"mappings":"AAAA,mEAAmE;AACnE,MAAM,OAAO,QAAQ;IACnB,8BAA8B;IACrB,QAAQ,CAAS;IAE1B,uBAAuB;IACd,IAAI,CAAqB;IAElC,sEAAsE;IAC7D,UAAU,CAAS;IAE5B,0DAA0D;IACjD,iBAAiB,CAAoB;IAE9C,wEAAwE;IAC/D,SAAS,CAAoB;IAEtC,mGAAmG;IAC1F,cAAc,CAAqB;IAE5C;;;OAGG;IACM,UAAU,CAAqB;IAExC;;;OAGG;IACM,UAAU,CAAqB;IAExC,YAAY,IASX;QACC,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC;QAC9B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC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