@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,78 @@
1
+ import { FinTsLoginRefusedError, type FinTsBankError } from '../core/errors.js';
2
+ import { type FinTsFeedback } from '../core/feedback.js';
3
+ import type { TanMethod } from '../tan/tan-models.js';
4
+ import type { PinGuard } from '../v3/protocol.js';
5
+ /**
6
+ * The kind of request a bank response answers, which decides what its errors mean for the login (`LoginGuard.judge`)
7
+ * and whether they can reject a TAN:
8
+ * - `login`: the login that opens a dialog, which carries no order;
9
+ * - `order`: an order in a dialog the bank has opened;
10
+ * - `approval`: a message that completes an approval, the TAN or the question whether the user approved in the app.
11
+ */
12
+ export type RequestKind = 'login' | 'order' | 'approval';
13
+ /**
14
+ * A reason for a refused login that the session can take care of by itself, after which it logs in once more: the user
15
+ * may not use the TAN method the login was signed with, or the bank no longer accepts the customer system ID.
16
+ */
17
+ export type RefusalReason = 'tanMethodNotAllowed' | 'systemIdRejected';
18
+ /** What the saved state keeps of the guard: the return codes of the bank's refusal, and `unreadLogins`. */
19
+ export interface LoginGuardState {
20
+ readonly refusal: readonly FinTsFeedback[] | undefined;
21
+ readonly unreadLogins: number;
22
+ }
23
+ /**
24
+ * Holds the PIN and hands it out only while no login is refused (`pin`), so that a retrying app cannot lock the user's
25
+ * access. `FinTsLoginRefusedError` tells which logins count as refused; `judge` decides it for each answer.
26
+ *
27
+ * A refusal counts at once and fails closed: only `remedied` lifts it, within the call that met it (`runCall`), once
28
+ * the session has taken care of a reason it names, each reason once per call, so that a call sends at most three
29
+ * logins the bank refuses. A refusal that outlasts the call is final, and the guard forgets the PIN; only a PIN the
30
+ * user enters anew lifts it (`replacePin`), unless it brings new login data.
31
+ */
32
+ export declare class LoginGuard implements PinGuard {
33
+ #private;
34
+ private refusalValue;
35
+ /** The TAN method of the login `refusalValue` refused, which a restored refusal does not tell. */
36
+ private refusedMethod;
37
+ /** Logins sent since the bank last took the PIN whose answer the client has not read. */
38
+ private unreadLogins;
39
+ /** The refusal of `maxUnreadLogins` unread logins, kept so that `check` throws the same error each time. */
40
+ private unreadLoginsRefusal;
41
+ /** The reasons `remedied` has lifted a refusal for in the running call. */
42
+ private readonly pardonedReasons;
43
+ constructor(pin: string);
44
+ /** The PIN to sign a message with; throws the refusal instead (`check`), and `FinTsStateError` once closed. */
45
+ get pin(): string;
46
+ /** Throws the refusal, if there is one. */
47
+ check(): void;
48
+ /** The bank's refusal, else that of `maxUnreadLogins` unread logins; `undefined` while there is none. */
49
+ get refusal(): FinTsLoginRefusedError | undefined;
50
+ /** Counts a login signed with the PIN as unread until `judge` reads its answer. */
51
+ loginSent(): void;
52
+ /**
53
+ * Judges `error`, if the answer to a request of `kind` in a dialog signed with `method` has one: returns the refusal
54
+ * of the login it amounts to, and records it unless the guard holds one already. Any error refuses a login; after the
55
+ * login only one that refuses it itself, a rejected PIN or new login data, since the bank checked the PIN before.
56
+ */
57
+ judge(error: FinTsBankError | undefined, kind: RequestKind, method: TanMethod): FinTsLoginRefusedError | undefined;
58
+ /** Runs `call`, one call of the client; a refusal that outlasts it is final, and the next call remedies anew. */
59
+ runCall<T>(call: () => Promise<T>): Promise<T>;
60
+ /**
61
+ * Runs `attempt`, which may log in, and runs it once more each time `remedy` takes care of a reason the refusal it
62
+ * failed with names; `remedy` gets the reason and the TAN method of the refused login, and returns whether it could.
63
+ */
64
+ remedied<T>(attempt: () => Promise<T>, remedy: (reason: RefusalReason, rejected: TanMethod) => Promise<boolean>): Promise<T>;
65
+ /**
66
+ * Signs with `pin` from now on, a PIN the user has entered anew and the protocol can send, and lifts the refusal.
67
+ * Throws the refusal instead where it brings new login data, which end the old ones for good.
68
+ */
69
+ replacePin(pin: string): void;
70
+ /** Forgets the PIN; the client calls it once it is closed. */
71
+ close(): void;
72
+ saveState(): LoginGuardState;
73
+ /** Restores what `saveState` returned; a restored refusal is final. */
74
+ restoreState(saved: LoginGuardState): void;
75
+ private liftRefusal;
76
+ private forgetPinIfRefused;
77
+ }
78
+ //# sourceMappingURL=login-guard.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"login-guard.d.ts","sourceRoot":"","sources":["../../src/session/login-guard.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,sBAAsB,EAGtB,KAAK,cAAc,EACpB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAA+C,KAAK,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACtG,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,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,EAAE,SAAS,KAAK,OAAO,CAAC,OAAO,CAAC,GACvE,OAAO,CAAC,CAAC,CAAC;IAoBb;;;OAGG;IACH,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAQ7B,8DAA8D;IAC9D,KAAK,IAAI,IAAI;IAIb,SAAS,IAAI,eAAe;IAI5B,uEAAuE;IACvE,YAAY,CAAC,KAAK,EAAE,eAAe,GAAG,IAAI;IAM1C,OAAO,CAAC,WAAW;IAKnB,OAAO,CAAC,kBAAkB;CAG3B"}
@@ -0,0 +1,181 @@
1
+ import { clientClosedError, FinTsLoginDataChangedError, FinTsLoginRefusedError, FinTsPinError, loginRefusalFor, } from '../core/errors.js';
2
+ import { allowedTanMethodsIn, FeedbackCodes, hasCode } from '../core/feedback.js';
3
+ /**
4
+ * Logins in a row whose answer the client could not read, after which it sends the PIN no more: one may be a glitch of
5
+ * the connection, but with two the client would not learn of a wrong PIN before the bank locks the access.
6
+ */
7
+ const maxUnreadLogins = 2;
8
+ /**
9
+ * Holds the PIN and hands it out only while no login is refused (`pin`), so that a retrying app cannot lock the user's
10
+ * access. `FinTsLoginRefusedError` tells which logins count as refused; `judge` decides it for each answer.
11
+ *
12
+ * A refusal counts at once and fails closed: only `remedied` lifts it, within the call that met it (`runCall`), once
13
+ * the session has taken care of a reason it names, each reason once per call, so that a call sends at most three
14
+ * logins the bank refuses. A refusal that outlasts the call is final, and the guard forgets the PIN; only a PIN the
15
+ * user enters anew lifts it (`replacePin`), unless it brings new login data.
16
+ */
17
+ export class LoginGuard {
18
+ // ECMAScript private, so that neither `util.inspect` nor `JSON.stringify` of the client reaches it.
19
+ #pin;
20
+ refusalValue;
21
+ /** The TAN method of the login `refusalValue` refused, which a restored refusal does not tell. */
22
+ refusedMethod;
23
+ /** Logins sent since the bank last took the PIN whose answer the client has not read. */
24
+ unreadLogins = 0;
25
+ /** The refusal of `maxUnreadLogins` unread logins, kept so that `check` throws the same error each time. */
26
+ unreadLoginsRefusal;
27
+ /** The reasons `remedied` has lifted a refusal for in the running call. */
28
+ pardonedReasons = new Set();
29
+ constructor(pin) {
30
+ this.#pin = pin;
31
+ }
32
+ /** The PIN to sign a message with; throws the refusal instead (`check`), and `FinTsStateError` once closed. */
33
+ get pin() {
34
+ this.check();
35
+ if (this.#pin === undefined)
36
+ throw clientClosedError();
37
+ return this.#pin;
38
+ }
39
+ /** Throws the refusal, if there is one. */
40
+ check() {
41
+ const refusal = this.refusal;
42
+ if (refusal !== undefined)
43
+ throw refusal;
44
+ }
45
+ /** The bank's refusal, else that of `maxUnreadLogins` unread logins; `undefined` while there is none. */
46
+ get refusal() {
47
+ if (this.refusalValue !== undefined || this.unreadLogins < maxUnreadLogins)
48
+ return this.refusalValue;
49
+ this.unreadLoginsRefusal ??= new FinTsLoginRefusedError([], `The answers to the last ${maxUnreadLogins} logins were lost or unreadable, and the bank may have counted them ` +
50
+ 'as failed attempts');
51
+ return this.unreadLoginsRefusal;
52
+ }
53
+ /** Counts a login signed with the PIN as unread until `judge` reads its answer. */
54
+ loginSent() {
55
+ this.unreadLogins++;
56
+ }
57
+ /**
58
+ * Judges `error`, if the answer to a request of `kind` in a dialog signed with `method` has one: returns the refusal
59
+ * of the login it amounts to, and records it unless the guard holds one already. Any error refuses a login; after the
60
+ * login only one that refuses it itself, a rejected PIN or new login data, since the bank checked the PIN before.
61
+ */
62
+ judge(error, kind, method) {
63
+ const refused = error instanceof FinTsLoginRefusedError || (error !== undefined && kind === 'login');
64
+ if (kind === 'login')
65
+ this.unreadLogins = refused ? Math.max(0, this.unreadLogins - 1) : 0;
66
+ if (!refused)
67
+ return undefined;
68
+ const refusal = loginRefusalFor(error.feedback);
69
+ if (this.refusalValue === undefined) {
70
+ this.refusalValue = refusal;
71
+ this.refusedMethod = method;
72
+ }
73
+ return refusal;
74
+ }
75
+ /** Runs `call`, one call of the client; a refusal that outlasts it is final, and the next call remedies anew. */
76
+ async runCall(call) {
77
+ try {
78
+ return await call();
79
+ }
80
+ finally {
81
+ this.pardonedReasons.clear();
82
+ this.forgetPinIfRefused();
83
+ }
84
+ }
85
+ /**
86
+ * Runs `attempt`, which may log in, and runs it once more each time `remedy` takes care of a reason the refusal it
87
+ * failed with names; `remedy` gets the reason and the TAN method of the refused login, and returns whether it could.
88
+ */
89
+ async remedied(attempt, remedy) {
90
+ // A refusal of an earlier call stops the attempt before it sends the PIN; there is nothing to remedy.
91
+ if (this.refusal !== undefined)
92
+ return attempt();
93
+ for (;;) {
94
+ try {
95
+ return await attempt();
96
+ }
97
+ catch (error) {
98
+ const refusal = this.refusalValue;
99
+ const rejected = this.refusedMethod;
100
+ // Only the bank's refusal the guard holds names reasons; any other error, a second refusal too, fails the call.
101
+ if (refusal === undefined || error !== refusal || rejected === undefined)
102
+ throw error;
103
+ const reason = remediableReasons(refusal, rejected).find((r) => !this.pardonedReasons.has(r));
104
+ if (reason === undefined || !(await remedy(reason, rejected)))
105
+ throw error;
106
+ this.pardonedReasons.add(reason);
107
+ // A closed client keeps the refusal.
108
+ if (this.#pin !== undefined)
109
+ this.liftRefusal();
110
+ }
111
+ }
112
+ }
113
+ /**
114
+ * Signs with `pin` from now on, a PIN the user has entered anew and the protocol can send, and lifts the refusal.
115
+ * Throws the refusal instead where it brings new login data, which end the old ones for good.
116
+ */
117
+ replacePin(pin) {
118
+ if (this.refusalValue instanceof FinTsLoginDataChangedError)
119
+ throw this.refusalValue;
120
+ this.#pin = pin;
121
+ this.liftRefusal();
122
+ this.unreadLogins = 0;
123
+ this.unreadLoginsRefusal = undefined;
124
+ }
125
+ /** Forgets the PIN; the client calls it once it is closed. */
126
+ close() {
127
+ this.#pin = undefined;
128
+ }
129
+ saveState() {
130
+ return { refusal: this.refusalValue?.feedback, unreadLogins: this.unreadLogins };
131
+ }
132
+ /** Restores what `saveState` returned; a restored refusal is final. */
133
+ restoreState(saved) {
134
+ if (saved.refusal !== undefined)
135
+ this.refusalValue = loginRefusalFor(saved.refusal);
136
+ this.unreadLogins = Math.max(0, saved.unreadLogins);
137
+ this.forgetPinIfRefused();
138
+ }
139
+ liftRefusal() {
140
+ this.refusalValue = undefined;
141
+ this.refusedMethod = undefined;
142
+ }
143
+ forgetPinIfRefused() {
144
+ if (this.refusal !== undefined)
145
+ this.#pin = undefined;
146
+ }
147
+ }
148
+ /**
149
+ * The reasons `refusal`, of a login signed with `method`, names that the session can take care of: a TAN method the
150
+ * refusal names as not allowed (`refusesMethod`), and 9391. None for a rejected PIN or new login data.
151
+ */
152
+ function remediableReasons(refusal, method) {
153
+ if (refusal instanceof FinTsPinError || refusal instanceof FinTsLoginDataChangedError)
154
+ return [];
155
+ const reasons = [];
156
+ if (refusesMethod(refusal.feedback, method))
157
+ reasons.push('tanMethodNotAllowed');
158
+ if (hasCode(refusal.feedback, FeedbackCodes.newSystemIdRequired))
159
+ reasons.push('systemIdRejected');
160
+ return reasons;
161
+ }
162
+ /** Error codes that only say that the message failed, not why: 9050 (the message contains errors) and 9800. */
163
+ const unspecificErrors = new Set(['9050', FeedbackCodes.dialogAborted]);
164
+ /**
165
+ * Whether `feedback`, which refuses a login signed with `method`, names the method as the reason: a 3920 that lists the
166
+ * methods the user may use without it, or 9075 after the one-step method.
167
+ *
168
+ * Only the return codes of the refusal itself count: TAN methods listed earlier say nothing about this login. Banks
169
+ * list two-step methods only, so a 3920 always leaves the one-step method out, also where the login succeeds. After
170
+ * the one-step method a 3920 counts only where the bank names no other error than an unspecific one: any other, such
171
+ * as "Anmeldung fehlgeschlagen", may be about the PIN.
172
+ */
173
+ function refusesMethod(feedback, method) {
174
+ if (method.isOneStep && hasCode(feedback, FeedbackCodes.scaRequired))
175
+ return true;
176
+ const allowed = allowedTanMethodsIn(feedback);
177
+ if (allowed.length === 0 || allowed.includes(method.securityFunction))
178
+ return false;
179
+ return !method.isOneStep || feedback.every((f) => !f.isError || unspecificErrors.has(f.code));
180
+ }
181
+ //# sourceMappingURL=login-guard.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"login-guard.js","sourceRoot":"","sources":["../../src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Q,EAAE,aAAa,CAAC,WAAW,CAAC;QAAE,OAAO,IAAI,CAAC;IAClF,MAAM,OAAO,GAAG,mBAAmB,CAAC,QAAQ,CAAC,CAAC;IAC9C,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,IAAI,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,gBAAgB,CAAC;QAAE,OAAO,KAAK,CAAC;IACpF,OAAO,CAAC,MAAM,CAAC,SAAS,IAAI,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,OAAO,IAAI,gBAAgB,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;AAChG,CAAC"}
@@ -0,0 +1,40 @@
1
+ import { Account } from '../core/account.js';
2
+ import type { ParameterStore } from '../v3/parameter-store.js';
3
+ import type { DialogRunner } from './dialog-runner.js';
4
+ import type { SessionState } from './session-state.js';
5
+ /**
6
+ * IBAN and BIC of the user's accounts, from the bank's SEPA account list where the user parameter data lack them
7
+ * (Formals F.3.4), and the accounts the app passes completed from both.
8
+ *
9
+ * The list is read once per version of the user parameter data and kept in the saved state. Under version 0, which
10
+ * holds for one dialog only (Formals E.2), without user parameter data, or where the bank rejects the list, also by
11
+ * ending the dialog, or names no account in it, it is kept for this client only: an empty list completes nothing, and
12
+ * saved it would outlast a fault of a single answer until the bank changes its user parameter data.
13
+ */
14
+ export declare class SepaAccounts {
15
+ private readonly parameters;
16
+ private readonly state;
17
+ private readonly dialogs;
18
+ /**
19
+ * The list this client keeps unsaved, with the version of the user parameter data it was read under; empty where the
20
+ * bank rejected it or named no account.
21
+ */
22
+ private unsaved;
23
+ constructor(parameters: ParameterStore, state: SessionState, dialogs: DialogRunner);
24
+ /** The accounts of the user parameter data completed with IBAN and BIC, then the accounts only the list names. */
25
+ completedAccounts(): Promise<Account[]>;
26
+ /**
27
+ * `account` as the bank knows it: the one of `completedAccounts` it matches, with what the bank states of it first,
28
+ * so that an account the app has built itself, such as from an IBAN alone, goes out with the account number, the
29
+ * sub-account and the BIC the bank's orders take, and the currency of its statements. Where the bank names none it
30
+ * matches, only what identifies `account`, and its currency: the rest, such as the transactions it permits, only the
31
+ * bank can state.
32
+ *
33
+ * Throws `FinTsUnsupportedError` for such an account where the user parameter data list all permitted transactions:
34
+ * they permit nothing for an account they leave out, and the client cannot tell it from a mistyped one.
35
+ */
36
+ complete(account: Account): Promise<Account>;
37
+ /** The list, read in the session's dialog, whose start delivers the user parameter data it is cached for. */
38
+ private list;
39
+ }
40
+ //# sourceMappingURL=sepa-accounts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sepa-accounts.d.ts","sourceRoot":"","sources":["../../src/session/sepa-accounts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAgB,MAAM,oBAAoB,CAAC;AAE3D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAE/D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAEvD;;;;;;;;GAQG;AACH,qBAAa,YAAY;IAQrB,OAAO,CAAC,QAAQ,CAAC,UAAU;IAC3B,OAAO,CAAC,QAAQ,CAAC,KAAK;IACtB,OAAO,CAAC,QAAQ,CAAC,OAAO;IAT1B;;;OAGG;IACH,OAAO,CAAC,OAAO,CAA+E;gBAG3E,UAAU,EAAE,cAAc,EAC1B,KAAK,EAAE,YAAY,EACnB,OAAO,EAAE,YAAY;IAGxC,kHAAkH;IAC5G,iBAAiB,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;IAW7C;;;;;;;;;OASG;IACG,QAAQ,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;IA2BlD,6GAA6G;YAC/F,IAAI;CA0BnB"}
@@ -0,0 +1,112 @@
1
+ import { Account, AccountIndex } from '../core/account.js';
2
+ import { FinTsUnsupportedError, tryLookUp } from '../core/errors.js';
3
+ import { sepaAccountsQuery } from '../v3/queries.js';
4
+ /**
5
+ * IBAN and BIC of the user's accounts, from the bank's SEPA account list where the user parameter data lack them
6
+ * (Formals F.3.4), and the accounts the app passes completed from both.
7
+ *
8
+ * The list is read once per version of the user parameter data and kept in the saved state. Under version 0, which
9
+ * holds for one dialog only (Formals E.2), without user parameter data, or where the bank rejects the list, also by
10
+ * ending the dialog, or names no account in it, it is kept for this client only: an empty list completes nothing, and
11
+ * saved it would outlast a fault of a single answer until the bank changes its user parameter data.
12
+ */
13
+ export class SepaAccounts {
14
+ parameters;
15
+ state;
16
+ dialogs;
17
+ /**
18
+ * The list this client keeps unsaved, with the version of the user parameter data it was read under; empty where the
19
+ * bank rejected it or named no account.
20
+ */
21
+ unsaved;
22
+ constructor(parameters, state, dialogs) {
23
+ this.parameters = parameters;
24
+ this.state = state;
25
+ this.dialogs = dialogs;
26
+ }
27
+ /** The accounts of the user parameter data completed with IBAN and BIC, then the accounts only the list names. */
28
+ async completedAccounts() {
29
+ const sepa = await this.list();
30
+ const accounts = this.parameters.userParameters?.accounts ?? [];
31
+ const listed = new AccountIndex(sepa);
32
+ const known = new AccountIndex(accounts);
33
+ return [
34
+ ...accounts.map((account) => withSepaDetails(account, listed.find(account))),
35
+ ...sepa.filter((s) => known.find(s) === undefined),
36
+ ];
37
+ }
38
+ /**
39
+ * `account` as the bank knows it: the one of `completedAccounts` it matches, with what the bank states of it first,
40
+ * so that an account the app has built itself, such as from an IBAN alone, goes out with the account number, the
41
+ * sub-account and the BIC the bank's orders take, and the currency of its statements. Where the bank names none it
42
+ * matches, only what identifies `account`, and its currency: the rest, such as the transactions it permits, only the
43
+ * bank can state.
44
+ *
45
+ * Throws `FinTsUnsupportedError` for such an account where the user parameter data list all permitted transactions:
46
+ * they permit nothing for an account they leave out, and the client cannot tell it from a mistyped one.
47
+ */
48
+ async complete(account) {
49
+ const known = (await this.completedAccounts()).find((a) => account.matches(a));
50
+ if (known !== undefined) {
51
+ // A sub-account belongs to the account number it comes with.
52
+ const national = known.accountNumber === undefined ? account : known;
53
+ return known.copyWith({
54
+ accountNumber: national.accountNumber,
55
+ subAccount: national.subAccount,
56
+ iban: known.iban ?? account.iban,
57
+ bic: known.bic ?? account.bic,
58
+ currency: known.currency ?? account.currency,
59
+ });
60
+ }
61
+ if (this.parameters.userParameters?.listsAllTransactions === true) {
62
+ throw new FinTsUnsupportedError("The bank does not name this account among the user's, and so permits nothing");
63
+ }
64
+ return new Account({
65
+ accountNumber: account.accountNumber,
66
+ subAccount: account.subAccount,
67
+ bankCode: account.bankCode,
68
+ countryCode: account.countryCode,
69
+ iban: account.iban,
70
+ bic: account.bic,
71
+ currency: account.currency,
72
+ });
73
+ }
74
+ /** The list, read in the session's dialog, whose start delivers the user parameter data it is cached for. */
75
+ async list() {
76
+ await this.dialogs.open();
77
+ const upd = this.parameters.userParameters;
78
+ if (upd !== undefined &&
79
+ upd.accounts.length > 0 &&
80
+ upd.accounts.every((a) => a.iban !== undefined && a.bic !== undefined)) {
81
+ return [];
82
+ }
83
+ const updVersion = upd?.version;
84
+ const saved = this.state.sepaAccounts(updVersion);
85
+ if (saved !== undefined)
86
+ return saved;
87
+ if (this.unsaved !== undefined && this.unsaved.updVersion === updVersion)
88
+ return this.unsaved.accounts;
89
+ const query = sepaAccountsQuery(this.parameters);
90
+ if (query === undefined)
91
+ return [];
92
+ // Where the bank rejects the list, also by ending the dialog, the accounts stay as the user parameter data state
93
+ // them: asked again, a bank that ends the dialog in answer would cost each call a login.
94
+ const accounts = await tryLookUp(() => this.dialogs.query(() => query));
95
+ if (accounts !== undefined && accounts.length > 0 && updVersion !== undefined && updVersion > 0) {
96
+ this.state.cacheSepaAccounts(accounts, updVersion);
97
+ }
98
+ else {
99
+ this.unsaved = { updVersion, accounts: accounts ?? [] };
100
+ }
101
+ return accounts ?? [];
102
+ }
103
+ }
104
+ /**
105
+ * A copy of `account`, which shares no date with the user parameter data, with the IBAN and BIC of `match`, its entry
106
+ * in the SEPA account list, if any.
107
+ */
108
+ function withSepaDetails(account, match) {
109
+ // A BIC of the list takes precedence over the one of the user parameter data (Formals E.3.1.1, "BIC").
110
+ return account.copyWith({ iban: account.iban ?? match?.iban, bic: match?.bic ?? account.bic });
111
+ }
112
+ //# sourceMappingURL=sepa-accounts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sepa-accounts.js","sourceRoot":"","sources":["../../src/session/sepa-accounts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EAAE,qBAAqB,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAErE,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAIrD;;;;;;;;GAQG;AACH,MAAM,OAAO,YAAY;IAQJ;IACA;IACA;IATnB;;;OAGG;IACK,OAAO,CAA+E;IAE9F,YACmB,UAA0B,EAC1B,KAAmB,EACnB,OAAqB;QAFrB,eAAU,GAAV,UAAU,CAAgB;QAC1B,UAAK,GAAL,KAAK,CAAc;QACnB,YAAO,GAAP,OAAO,CAAc;IACrC,CAAC;IAEJ,kHAAkH;IAClH,KAAK,CAAC,iBAAiB;QACrB,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,IAAI,EAAE,CAAC;QAC/B,MAAM,QAAQ,GAAG,IAAI,CAAC,UAAU,CAAC,cAAc,EAAE,QAAQ,IAAI,EAAE,CAAC;QAChE,MAAM,MAAM,GAAG,IAAI,YAAY,CAAC,IAAI,CAAC,CAAC;QACtC,MAAM,KAAK,GAAG,IAAI,YAAY,CAAC,QAAQ,CAAC,CAAC;QACzC,OAAO;YACL,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,eAAe,CAAC,OAAO,EAAE,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;YAC5E,GAAG,IAAI,CAAC,MAAM,CAAC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ChG,IAAI,CAAC,KAAK,CAAC,iBAAiB,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;QACrD,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,OAAO,GAAG,EAAE,UAAU,EAAE,QAAQ,EAAE,QAAQ,IAAI,EAAE,EAAE,CAAC;QAC1D,CAAC;QACD,OAAO,QAAQ,IAAI,EAAE,CAAC;IACxB,CAAC;CACF;AAED;;;GAGG;AACH,SAAS,eAAe,CAAC,OAAgB,EAAE,KAA0B;IACnE,uGAAuG;IACvG,OAAO,OAAO,CAAC,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,IAAI,KAAK,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;AACjG,CAAC"}
@@ -0,0 +1,80 @@
1
+ import type { BankInfo } from '../core/bank-info.js';
2
+ import type { TanMedium, TanMethod } from '../tan/tan-models.js';
3
+ import type { FinTs3Protocol } from '../v3/protocol.js';
4
+ import { SignedDialog, type SessionParts } from './signed-dialog.js';
5
+ import type { TanSelection } from './tan-selection.js';
6
+ /**
7
+ * What has to be settled before a login: the bank parameter data, the synchronization, and through `TanSelection` the
8
+ * TAN method and medium. Each of the dialogs this takes serves one purpose only.
9
+ *
10
+ * Where the bank refuses a login for a reason the session can take care of, `remedied` does so and logs in again.
11
+ */
12
+ export declare class SessionSetup {
13
+ private readonly session;
14
+ private readonly protocol;
15
+ private readonly tans;
16
+ constructor(session: SessionParts, protocol: FinTs3Protocol, tans: TanSelection);
17
+ /**
18
+ * The bank's general information: from an anonymous dialog where the bank answers one, else from the synchronization.
19
+ * No TAN method or medium is chosen for it.
20
+ */
21
+ bankInfo(): Promise<BankInfo>;
22
+ /** The TAN methods the bank allows for this user, which the synchronization reports. */
23
+ methods(): Promise<TanMethod[]>;
24
+ /**
25
+ * Settles what is still open: the bank parameter data, the synchronization, the TAN method and medium. Returns the TAN
26
+ * media it looked up to choose the medium; `undefined` where it looked up none, or the bank listed none.
27
+ */
28
+ prepare(): Promise<TanMedium[] | undefined>;
29
+ /** A new dialog signed with the TAN method and medium in use, once `prepare` has settled them. */
30
+ newDialog(): Promise<SignedDialog>;
31
+ /** Runs `attempt`, which may log in, once more after each refused login `remedy` takes care of. */
32
+ remedied<T>(attempt: () => Promise<T>): Promise<T>;
33
+ /**
34
+ * Takes care of `reason`, given for refusing a login signed with `rejected`, with another TAN method or a new
35
+ * synchronization; returns whether it could.
36
+ */
37
+ private remedy;
38
+ /**
39
+ * Loads the bank parameter data if they are missing, then synchronizes if that is due.
40
+ *
41
+ * The bank parameter data come first, from an anonymous dialog: the dialogs signed with the PIN need them for the
42
+ * dialog language, the PIN length and the TAN methods (PIN/TAN B.4.3.1, Formals C.3.1.3). A bank that does not answer
43
+ * anonymously delivers them with the synchronization.
44
+ *
45
+ * After a refused login it throws the refusal right away, before the user is asked for a TAN method or medium.
46
+ */
47
+ private loadParameters;
48
+ /**
49
+ * Asks for the bank parameter data without logging in, keeps them where there are none from a dialog signed with the
50
+ * PIN (`ParameterStore.keepAnonymous`), and passes the bank's messages on: all an anonymous dialog tells, since the
51
+ * TAN methods it lists are not those of a user. A bank that does not answer anonymously is no error, but a failed
52
+ * connection is: the synchronization would only wait for the same server again.
53
+ */
54
+ private fetchBankParametersAnonymously;
55
+ /**
56
+ * Asks for the bank parameter data in an anonymous dialog that announces strong customer authentication; a bank that
57
+ * rejects the announcement, with a return code or by failing on it, is asked again without it.
58
+ *
59
+ * A timeout or a broken connection is not a reason to ask again: it would only double the wait.
60
+ */
61
+ private requestBankParametersAnonymously;
62
+ private anonymousDialog;
63
+ /**
64
+ * Runs the synchronization, a login in a dialog of its own, while there is no customer system ID, without which no
65
+ * regular dialog starts. It runs before the TAN method and medium are settled (`TanSelection.synchronizationDialog`
66
+ * tells which method signs it).
67
+ */
68
+ private synchronizeIfDue;
69
+ /**
70
+ * The TAN media of the method in use; `undefined` if the bank does not list them or rejects the list, after which the
71
+ * client reports a missing medium before the login.
72
+ *
73
+ * The lookup runs in a dialog of its own, whose start asks for the list, since the regular dialog start needs the
74
+ * medium the list tells (PIN/TAN B.4.3.1.3).
75
+ */
76
+ private lookUpTanMedia;
77
+ /** Runs `use` in `dialog`, a dialog of its own, and ends it afterwards, however `use` ends. */
78
+ private once;
79
+ }
80
+ //# sourceMappingURL=session-setup.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session-setup.d.ts","sourceRoot":"","sources":["../../src/session/session-setup.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAGrD,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAIjE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAGxD,OAAO,EAAE,YAAY,EAAE,KAAK,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACrE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAEvD;;;;;GAKG;AACH,qBAAa,YAAY;IAErB,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,QAAQ;IACzB,OAAO,CAAC,QAAQ,CAAC,IAAI;gBAFJ,OAAO,EAAE,YAAY,EACrB,QAAQ,EAAE,cAAc,EACxB,IAAI,EAAE,YAAY;IAGrC;;;OAGG;IACG,QAAQ,IAAI,OAAO,CAAC,QAAQ,CAAC;IAMnC,wFAAwF;IAClF,OAAO,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;IAKrC;;;OAGG;IACG,OAAO,IAAI,OAAO,CAAC,SAAS,EAAE,GAAG,SAAS,CAAC;IASjD,kGAAkG;IAC5F,SAAS,IAAI,OAAO,CAAC,YAAY,CAAC;IAKxC,mGAAmG;IACnG,QAAQ,CAAC,CAAC,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO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