@albertomarturelo/cta-core 0.1.0-rc.1

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 (87) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +21 -0
  3. package/dist/accounts/match-cuenta.d.ts +7 -0
  4. package/dist/accounts/match-cuenta.d.ts.map +1 -0
  5. package/dist/accounts/match-cuenta.js +23 -0
  6. package/dist/accounts/match-cuenta.js.map +1 -0
  7. package/dist/banks/bci/config.d.ts +38 -0
  8. package/dist/banks/bci/config.d.ts.map +1 -0
  9. package/dist/banks/bci/config.js +78 -0
  10. package/dist/banks/bci/config.js.map +1 -0
  11. package/dist/banks/bci/login-flow.d.ts +37 -0
  12. package/dist/banks/bci/login-flow.d.ts.map +1 -0
  13. package/dist/banks/bci/login-flow.js +79 -0
  14. package/dist/banks/bci/login-flow.js.map +1 -0
  15. package/dist/banks/bci/reads.d.ts +33 -0
  16. package/dist/banks/bci/reads.d.ts.map +1 -0
  17. package/dist/banks/bci/reads.js +181 -0
  18. package/dist/banks/bci/reads.js.map +1 -0
  19. package/dist/dates/dates.d.ts +5 -0
  20. package/dist/dates/dates.d.ts.map +1 -0
  21. package/dist/dates/dates.js +25 -0
  22. package/dist/dates/dates.js.map +1 -0
  23. package/dist/domain/types.d.ts +43 -0
  24. package/dist/domain/types.d.ts.map +1 -0
  25. package/dist/domain/types.js +2 -0
  26. package/dist/domain/types.js.map +1 -0
  27. package/dist/errors/errors.d.ts +64 -0
  28. package/dist/errors/errors.d.ts.map +1 -0
  29. package/dist/errors/errors.js +107 -0
  30. package/dist/errors/errors.js.map +1 -0
  31. package/dist/identity/resolve-bank.d.ts +7 -0
  32. package/dist/identity/resolve-bank.d.ts.map +1 -0
  33. package/dist/identity/resolve-bank.js +13 -0
  34. package/dist/identity/resolve-bank.js.map +1 -0
  35. package/dist/index.d.ts +12 -0
  36. package/dist/index.d.ts.map +1 -0
  37. package/dist/index.js +11 -0
  38. package/dist/index.js.map +1 -0
  39. package/dist/money/money.d.ts +21 -0
  40. package/dist/money/money.d.ts.map +1 -0
  41. package/dist/money/money.js +53 -0
  42. package/dist/money/money.js.map +1 -0
  43. package/dist/movements/coverage.d.ts +12 -0
  44. package/dist/movements/coverage.d.ts.map +1 -0
  45. package/dist/movements/coverage.js +19 -0
  46. package/dist/movements/coverage.js.map +1 -0
  47. package/dist/node/banks/bci-driver.d.ts +41 -0
  48. package/dist/node/banks/bci-driver.d.ts.map +1 -0
  49. package/dist/node/banks/bci-driver.js +254 -0
  50. package/dist/node/banks/bci-driver.js.map +1 -0
  51. package/dist/node/file-session-store.d.ts +18 -0
  52. package/dist/node/file-session-store.d.ts.map +1 -0
  53. package/dist/node/file-session-store.js +106 -0
  54. package/dist/node/file-session-store.js.map +1 -0
  55. package/dist/node/http-client.d.ts +11 -0
  56. package/dist/node/http-client.d.ts.map +1 -0
  57. package/dist/node/http-client.js +25 -0
  58. package/dist/node/http-client.js.map +1 -0
  59. package/dist/node/jsonl-audit-sink.d.ts +12 -0
  60. package/dist/node/jsonl-audit-sink.d.ts.map +1 -0
  61. package/dist/node/jsonl-audit-sink.js +29 -0
  62. package/dist/node/jsonl-audit-sink.js.map +1 -0
  63. package/dist/node/package-version.d.ts +6 -0
  64. package/dist/node/package-version.d.ts.map +1 -0
  65. package/dist/node/package-version.js +23 -0
  66. package/dist/node/package-version.js.map +1 -0
  67. package/dist/node/system-clock.d.ts +5 -0
  68. package/dist/node/system-clock.d.ts.map +1 -0
  69. package/dist/node/system-clock.js +6 -0
  70. package/dist/node/system-clock.js.map +1 -0
  71. package/dist/node.d.ts +9 -0
  72. package/dist/node.d.ts.map +1 -0
  73. package/dist/node.js +12 -0
  74. package/dist/node.js.map +1 -0
  75. package/dist/seams/fakes.d.ts +51 -0
  76. package/dist/seams/fakes.d.ts.map +1 -0
  77. package/dist/seams/fakes.js +106 -0
  78. package/dist/seams/fakes.js.map +1 -0
  79. package/dist/seams/seams.d.ts +113 -0
  80. package/dist/seams/seams.d.ts.map +1 -0
  81. package/dist/seams/seams.js +2 -0
  82. package/dist/seams/seams.js.map +1 -0
  83. package/dist/tasks/tasks.d.ts +94 -0
  84. package/dist/tasks/tasks.d.ts.map +1 -0
  85. package/dist/tasks/tasks.js +225 -0
  86. package/dist/tasks/tasks.js.map +1 -0
  87. package/package.json +64 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Alberto Marturelo Lorenzo
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,21 @@
1
+ # @albertomarturelo/cta-core
2
+
3
+ Shared core of [`cta`](https://github.com/albertomarturelo/cta): read your **own**
4
+ Chilean bank accounts — balances and movements (the *cartola*) — locally, with
5
+ credentials typed only into the bank's real login page. Holds the domain, the
6
+ tasks and one driver per bank; the CLI and the MCP server are thin surfaces over it.
7
+
8
+ > ⚠️ **Pre-alpha and unofficial.** Not affiliated with, sponsored or endorsed by
9
+ > any bank. Automating access to your own account may breach your bank's terms,
10
+ > and **the bank may block your access or your device**. Provided "as is", without
11
+ > warranty (MIT). Read-only: it never moves money.
12
+
13
+ ## Entry points
14
+
15
+ - `@albertomarturelo/cta-core` — the pure, embeddable API (no Node built-ins at
16
+ import time).
17
+ - `@albertomarturelo/cta-core/node` — Node adapters and the bank drivers (Playwright
18
+ for the login; HTTP-mode reads with the login's grant, ADR-015).
19
+
20
+ Requires **Node ≥ 20**. Design and decisions:
21
+ [docs/decisions](https://github.com/albertomarturelo/cta/blob/main/docs/decisions/_index.md).
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Resolves a `--cuenta` selector against the account numbers of one bank: the
3
+ * full number (separators ignored) or its last 4 digits. Drivers call it after
4
+ * listing accounts, inside the same browser (ADR-012).
5
+ */
6
+ export declare function matchCuenta(banco: string, numeros: readonly string[], selector: string): string;
7
+ //# sourceMappingURL=match-cuenta.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"match-cuenta.d.ts","sourceRoot":"","sources":["../../src/accounts/match-cuenta.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,MAAM,EAAE,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAW/F"}
@@ -0,0 +1,23 @@
1
+ import { AmbiguousAccount, NoSuchAccount } from '../errors/errors.js';
2
+ /**
3
+ * Resolves a `--cuenta` selector against the account numbers of one bank: the
4
+ * full number (separators ignored) or its last 4 digits. Drivers call it after
5
+ * listing accounts, inside the same browser (ADR-012).
6
+ */
7
+ export function matchCuenta(banco, numeros, selector) {
8
+ const digits = (s) => s.replace(/\D/g, '');
9
+ const wanted = digits(selector);
10
+ if (wanted === '')
11
+ throw new NoSuchAccount(banco, selector);
12
+ const exact = numeros.filter((n) => digits(n) === wanted);
13
+ if (exact.length === 1)
14
+ return exact[0];
15
+ const bySuffix = wanted.length === 4 ? numeros.filter((n) => digits(n).endsWith(wanted)) : [];
16
+ if (bySuffix.length === 1)
17
+ return bySuffix[0];
18
+ const count = Math.max(exact.length, bySuffix.length);
19
+ if (count > 1)
20
+ throw new AmbiguousAccount(banco, selector, count);
21
+ throw new NoSuchAccount(banco, selector);
22
+ }
23
+ //# sourceMappingURL=match-cuenta.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"match-cuenta.js","sourceRoot":"","sources":["../../src/accounts/match-cuenta.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEtE;;;;GAIG;AACH,MAAM,UAAU,WAAW,CAAC,KAAa,EAAE,OAA0B,EAAE,QAAgB;IACrF,MAAM,MAAM,GAAG,CAAC,CAAS,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IACnD,MAAM,MAAM,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC;IAChC,IAAI,MAAM,KAAK,EAAE;QAAE,MAAM,IAAI,aAAa,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;IAC5D,MAAM,KAAK,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,MAAM,CAAC,CAAC;IAC1D,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC,CAAC,CAAE,CAAC;IACzC,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IAC9F,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,QAAQ,CAAC,CAAC,CAAE,CAAC;IAC/C,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;IACtD,IAAI,KAAK,GAAG,CAAC;QAAE,MAAM,IAAI,gBAAgB,CAAC,KAAK,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC;IAClE,MAAM,IAAI,aAAa,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;AAC3C,CAAC"}
@@ -0,0 +1,38 @@
1
+ /**
2
+ * BCI's observed wire contract for login — the ONLY place its hostnames and
3
+ * markers live (CONVENTIONS). Every value is first-hand observed and recorded in
4
+ * `docs/bank-contract/bci.md` (ADR-004).
5
+ */
6
+ export declare const BCI: {
7
+ readonly slug: "bci";
8
+ readonly code: "016";
9
+ readonly name: "Banco de Crédito e Inversiones";
10
+ readonly loginEntryUrl: "https://www.bci.cl/corporativo/banco-en-linea/personas";
11
+ readonly appHost: "www.bci.cl";
12
+ readonly loginPostPath: "/LoginJSFGenerico";
13
+ readonly homePaths: readonly ["/cl/bci/aplicaciones/contenido.jsf", "/cl/bci/aplicaciones/menu/vistas/inicio/miBanco.jsf"];
14
+ readonly orchestrator: {
15
+ readonly host: "personas.bci.cl";
16
+ readonly pathPrefix: "/web/fe-orq-mo-personas-re-v";
17
+ readonly homeSuffix: "/home";
18
+ readonly miBancoSegment: "/comp/mi_banco/";
19
+ readonly sessionCookie: "__Host-SESSIONID";
20
+ };
21
+ readonly sessionCookie: "JSESSIONID";
22
+ readonly challengeMarkers: readonly ["__cf_chl_rt_tk", "/cdn-cgi/challenge-platform/"];
23
+ readonly cookieDomainSuffix: "bci.cl";
24
+ readonly appsHost: "personas.bci.cl";
25
+ readonly saldosApp: "fe-saldosultimosmovpersonas";
26
+ readonly appPathRoots: readonly ["/nuevaWeb/", "/modernizacion/"];
27
+ readonly api: {
28
+ readonly cuentasPorRut: "https://apilocal.bci.cl/bci-produccion/api-bci/bff-saldosyultimosmovimientoswebpersonas/v3.2/cuentas-busquedas/por-rut";
29
+ readonly saldoPorCuenta: "https://apilocal.bci.cl/bci-produccion/api-bci/bff-saldosyultimosmovimientoswebpersonas/v3.2/cuentas-busquedas/por-numero-cuenta";
30
+ readonly movimientosPorCuenta: "https://apilocal.bci.cl/bci-produccion/api-bci/bff-saldosyultimosmovimientoswebpersonas/v3.2/cuentas-movimientos/por-numero-cuenta";
31
+ };
32
+ readonly movementSign: {
33
+ readonly C: "cargo";
34
+ readonly A: "abono";
35
+ };
36
+ readonly apiHeaders: readonly ["accept", "content-type", "authorization", "application-id", "channel", "reference-service", "reference-operation", "x-ibm-client-id", "origin-addr", "tracking-id"];
37
+ };
38
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../src/banks/bci/config.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,eAAO,MAAM,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAsFN,CAAC"}
@@ -0,0 +1,78 @@
1
+ /**
2
+ * BCI's observed wire contract for login — the ONLY place its hostnames and
3
+ * markers live (CONVENTIONS). Every value is first-hand observed and recorded in
4
+ * `docs/bank-contract/bci.md` (ADR-004).
5
+ */
6
+ export const BCI = {
7
+ slug: 'bci',
8
+ code: '016',
9
+ name: 'Banco de Crédito e Inversiones',
10
+ // observed at https://www.bci.cl/corporativo/banco-en-linea/personas on 2026-09-24
11
+ // (the "Banco en línea personas" page where the user types RUT and clave)
12
+ loginEntryUrl: 'https://www.bci.cl/corporativo/banco-en-linea/personas',
13
+ // observed at https://www.bci.cl/LoginJSFGenerico on 2026-09-24
14
+ // (credentials form POST target; also where the login 500 page is served)
15
+ appHost: 'www.bci.cl',
16
+ loginPostPath: '/LoginJSFGenerico',
17
+ // observed at https://www.bci.cl/cl/bci/aplicaciones/contenido.jsf on 2026-09-24
18
+ // (JSF landing after a successful login, then the miBanco home)
19
+ homePaths: [
20
+ '/cl/bci/aplicaciones/contenido.jsf',
21
+ '/cl/bci/aplicaciones/menu/vistas/inicio/miBanco.jsf',
22
+ ],
23
+ // observed at https://personas.bci.cl/web/fe-orq-mo-personas-re-v1-7/home on 2026-09-28
24
+ // (the landing after the trusted-device step moved to an orchestrator app, which
25
+ // then routes to .../comp/mi_banco/cl/bci/aplicaciones/menu/vistas/inicio/miBanco).
26
+ // The version segment ("v1-7") is expected to change, so it is not pinned.
27
+ orchestrator: {
28
+ host: 'personas.bci.cl',
29
+ pathPrefix: '/web/fe-orq-mo-personas-re-v',
30
+ homeSuffix: '/home',
31
+ miBancoSegment: '/comp/mi_banco/',
32
+ // observed on personas.bci.cl on 2026-09-28: the only session cookie at this
33
+ // landing — httpOnly, persistent; JSESSIONID on www.bci.cl no longer exists
34
+ sessionCookie: '__Host-SESSIONID',
35
+ },
36
+ // observed on www.bci.cl on 2026-09-24: set by the credentials POST, httpOnly, secure
37
+ sessionCookie: 'JSESSIONID',
38
+ // observed at https://www.bci.cl/cl/bci/aplicaciones/menu/vistas/inicio/miBanco.jsf on 2026-09-24
39
+ // (a 403 carrying these when the bank challenged a headless restore)
40
+ challengeMarkers: ['__cf_chl_rt_tk', '/cdn-cgi/challenge-platform/'],
41
+ // Only the bank's own cookies are stored; trackers are dropped.
42
+ cookieDomainSuffix: 'bci.cl',
43
+ // observed at https://personas.bci.cl/nuevaWeb/fe-saldosultimosmovpersonas/ on 2026-09-25
44
+ // (the micro-frontends' host, reached as an iframe of the JSF page)
45
+ appsHost: 'personas.bci.cl',
46
+ // observed at https://personas.bci.cl/nuevaWeb/fe-saldosultimosmovpersonas/ on 2026-09-25
47
+ // (the balances-and-latest-movements app; it sends por-rut itself on load)
48
+ saldosApp: 'fe-saldosultimosmovpersonas',
49
+ // observed on personas.bci.cl on 2026-09-25 (/nuevaWeb/) and 2026-09-28
50
+ // (/modernizacion/, loaded by the orchestrator's /comp/embedded route)
51
+ appPathRoots: ['/nuevaWeb/', '/modernizacion/'],
52
+ // observed at https://apilocal.bci.cl/bci-produccion/api-bci/bff-saldosyultimosmovimientoswebpersonas/v3.2/ on 2026-09-25
53
+ api: {
54
+ cuentasPorRut: 'https://apilocal.bci.cl/bci-produccion/api-bci/bff-saldosyultimosmovimientoswebpersonas/v3.2/cuentas-busquedas/por-rut',
55
+ saldoPorCuenta: 'https://apilocal.bci.cl/bci-produccion/api-bci/bff-saldosyultimosmovimientoswebpersonas/v3.2/cuentas-busquedas/por-numero-cuenta',
56
+ // body {numeroCuenta}; the latest movements, no range, no paging (50 seen)
57
+ movimientosPorCuenta: 'https://apilocal.bci.cl/bci-produccion/api-bci/bff-saldosyultimosmovimientoswebpersonas/v3.2/cuentas-movimientos/por-numero-cuenta',
58
+ },
59
+ // observed on cuentas-movimientos/por-numero-cuenta answers on 2026-09-25: only
60
+ // these letters. C = cargo, A = abono confirmed against the bank's app on
61
+ // 2026-09-28 (contract); others fail.
62
+ movementSign: { C: 'cargo', A: 'abono' },
63
+ // observed on apilocal.bci.cl requests of the saldos app on 2026-09-25: the
64
+ // headers it sends besides what the browser adds itself
65
+ apiHeaders: [
66
+ 'accept',
67
+ 'content-type',
68
+ 'authorization',
69
+ 'application-id',
70
+ 'channel',
71
+ 'reference-service',
72
+ 'reference-operation',
73
+ 'x-ibm-client-id',
74
+ 'origin-addr',
75
+ 'tracking-id',
76
+ ],
77
+ };
78
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../../../src/banks/bci/config.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,CAAC,MAAM,GAAG,GAAG;IACjB,IAAI,EAAE,KAAK;IACX,IAAI,EAAE,KAAK;IACX,IAAI,EAAE,gCAAgC;IAEtC,mFAAmF;IACnF,0EAA0E;IAC1E,aAAa,EAAE,wDAAwD;IAEvE,gEAAgE;IAChE,0EAA0E;IAC1E,OAAO,EAAE,YAAY;IACrB,aAAa,EAAE,mBAAmB;IAElC,iFAAiF;IACjF,gEAAgE;IAChE,SAAS,EAAE;QACT,oCAAoC;QACpC,qDAAqD;KACtD;IAED,wFAAwF;IACxF,iFAAiF;IACjF,oFAAoF;IACpF,2EAA2E;IAC3E,YAAY,EAAE;QACZ,IAAI,EAAE,iBAAiB;QACvB,UAAU,EAAE,8BAA8B;QAC1C,UAAU,EAAE,OAAO;QACnB,cAAc,EAAE,iBAAiB;QACjC,6EAA6E;QAC7E,4EAA4E;QAC5E,aAAa,EAAE,kBAAkB;KAClC;IAED,sFAAsF;IACtF,aAAa,EAAE,YAAY;IAE3B,kGAAkG;IAClG,qEAAqE;IACrE,gBAAgB,EAAE,CAAC,gBAAgB,EAAE,8BAA8B,CAAC;IAEpE,gEAAgE;IAChE,kBAAkB,EAAE,QAAQ;IAE5B,0FAA0F;IAC1F,oEAAoE;IACpE,QAAQ,EAAE,iBAAiB;IAE3B,0FAA0F;IAC1F,2EAA2E;IAC3E,SAAS,EAAE,6BAA6B;IACxC,wEAAwE;IACxE,uEAAuE;IACvE,YAAY,EAAE,CAAC,YAAY,EAAE,iBAAiB,CAAC;IAE/C,0HAA0H;IAC1H,GAAG,EAAE;QACH,aAAa,EACX,wHAAwH;QAC1H,cAAc,EACZ,kIAAkI;QACpI,2EAA2E;QAC3E,oBAAoB,EAClB,oIAAoI;KACvI;IAED,gFAAgF;IAChF,0EAA0E;IAC1E,sCAAsC;IACtC,YAAY,EAAE,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE;IAExC,4EAA4E;IAC5E,wDAAwD;IACxD,UAAU,EAAE;QACV,QAAQ;QACR,cAAc;QACd,eAAe;QACf,gBAAgB;QAChB,SAAS;QACT,mBAAmB;QACnB,qBAAqB;QACrB,iBAAiB;QACjB,aAAa;QACb,aAAa;KACd;CACO,CAAC"}
@@ -0,0 +1,37 @@
1
+ import type { StoredCookie } from '../../seams/seams.js';
2
+ /** A browser cookie as Playwright reports it (structural, no Playwright import). */
3
+ export interface BrowserCookie {
4
+ readonly name: string;
5
+ readonly value: string;
6
+ readonly domain: string;
7
+ readonly path: string;
8
+ readonly expires: number;
9
+ readonly httpOnly: boolean;
10
+ readonly secure: boolean;
11
+ readonly sameSite: 'Strict' | 'Lax' | 'None';
12
+ }
13
+ /**
14
+ * Success is decided by where the browser landed, not by a status (CONVENTIONS):
15
+ * the JSF home (2026-09-24) or the orchestrator app that replaced it as the
16
+ * landing (2026-09-28). Both are kept — a rollout may reach users unevenly.
17
+ */
18
+ export declare function isLoggedInUrl(url: string): boolean;
19
+ /**
20
+ * Classifies a decisive document response. The login uses only
21
+ * `login-server-error`: a challenge there is the user's to resolve (ADR-004).
22
+ * `challenge` serves unattended reads (restore), where nobody can resolve it.
23
+ */
24
+ export declare function classifyDocumentResponse(r: {
25
+ url: string;
26
+ status: number;
27
+ }): 'login-server-error' | 'challenge' | undefined;
28
+ /** The cookies worth storing: the bank's own domains only (ADR-006). */
29
+ export declare function bankCookies(cookies: readonly BrowserCookie[]): StoredCookie[];
30
+ /** The JSF session (2026-09-24) or the orchestrator's (2026-09-28), whichever the landing set. */
31
+ export declare function hasSessionCookie(cookies: readonly StoredCookie[]): boolean;
32
+ /** The bank's own words from an error page, verbatim; a neutral fallback if none. */
33
+ export declare function pageMessage(page: {
34
+ title?: string | undefined;
35
+ heading?: string | undefined;
36
+ }, fallback: string): string;
37
+ //# sourceMappingURL=login-flow.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"login-flow.d.ts","sourceRoot":"","sources":["../../../src/banks/bci/login-flow.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAGzD,oFAAoF;AACpF,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;IAC3B,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IACzB,QAAQ,CAAC,QAAQ,EAAE,QAAQ,GAAG,KAAK,GAAG,MAAM,CAAC;CAC9C;AAUD;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAclD;AAED;;;;GAIG;AACH,wBAAgB,wBAAwB,CAAC,CAAC,EAAE;IAC1C,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;CAChB,GAAG,oBAAoB,GAAG,WAAW,GAAG,SAAS,CAQjD;AAOD,wEAAwE;AACxE,wBAAgB,WAAW,CAAC,OAAO,EAAE,SAAS,aAAa,EAAE,GAAG,YAAY,EAAE,CAa7E;AAED,kGAAkG;AAClG,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,SAAS,YAAY,EAAE,GAAG,OAAO,CAQ1E;AAED,qFAAqF;AACrF,wBAAgB,WAAW,CACzB,IAAI,EAAE;IAAE,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,EAClE,QAAQ,EAAE,MAAM,GACf,MAAM,CAGR"}
@@ -0,0 +1,79 @@
1
+ import { BCI } from './config.js';
2
+ function parse(url) {
3
+ try {
4
+ return new URL(url);
5
+ }
6
+ catch {
7
+ return undefined;
8
+ }
9
+ }
10
+ /**
11
+ * Success is decided by where the browser landed, not by a status (CONVENTIONS):
12
+ * the JSF home (2026-09-24) or the orchestrator app that replaced it as the
13
+ * landing (2026-09-28). Both are kept — a rollout may reach users unevenly.
14
+ */
15
+ export function isLoggedInUrl(url) {
16
+ const u = parse(url);
17
+ if (!u)
18
+ return false;
19
+ if (u.hostname === BCI.appHost) {
20
+ return BCI.homePaths.includes(u.pathname);
21
+ }
22
+ const o = BCI.orchestrator;
23
+ if (u.hostname !== o.host || !u.pathname.startsWith(o.pathPrefix))
24
+ return false;
25
+ // Past the prefix: "<version>/home" or "<version>/comp/mi_banco/…".
26
+ const rest = u.pathname.slice(o.pathPrefix.length);
27
+ const version = rest.slice(0, rest.indexOf('/'));
28
+ if (!/^\d+(-\d+)*$/.test(version))
29
+ return false;
30
+ const route = rest.slice(version.length);
31
+ return route === o.homeSuffix || route.startsWith(o.miBancoSegment);
32
+ }
33
+ /**
34
+ * Classifies a decisive document response. The login uses only
35
+ * `login-server-error`: a challenge there is the user's to resolve (ADR-004).
36
+ * `challenge` serves unattended reads (restore), where nobody can resolve it.
37
+ */
38
+ export function classifyDocumentResponse(r) {
39
+ const u = parse(r.url);
40
+ if (!u)
41
+ return undefined;
42
+ if (r.status === 403 && BCI.challengeMarkers.some((m) => r.url.includes(m)))
43
+ return 'challenge';
44
+ if (r.status >= 500 && u.hostname === BCI.appHost && u.pathname === BCI.loginPostPath) {
45
+ return 'login-server-error';
46
+ }
47
+ return undefined;
48
+ }
49
+ const isBankDomain = (domain) => {
50
+ const d = domain.replace(/^\./, '');
51
+ return d === BCI.cookieDomainSuffix || d.endsWith(`.${BCI.cookieDomainSuffix}`);
52
+ };
53
+ /** The cookies worth storing: the bank's own domains only (ADR-006). */
54
+ export function bankCookies(cookies) {
55
+ return cookies
56
+ .filter((c) => isBankDomain(c.domain))
57
+ .map((c) => ({
58
+ name: c.name,
59
+ value: c.value,
60
+ domain: c.domain,
61
+ path: c.path,
62
+ expires: c.expires > 0 ? c.expires : -1,
63
+ httpOnly: c.httpOnly,
64
+ secure: c.secure,
65
+ sameSite: c.sameSite,
66
+ }));
67
+ }
68
+ /** The JSF session (2026-09-24) or the orchestrator's (2026-09-28), whichever the landing set. */
69
+ export function hasSessionCookie(cookies) {
70
+ const is = (c, name, host) => c.name === name && c.domain.replace(/^\./, '') === host && c.value !== '';
71
+ return cookies.some((c) => is(c, BCI.sessionCookie, BCI.appHost) ||
72
+ is(c, BCI.orchestrator.sessionCookie, BCI.orchestrator.host));
73
+ }
74
+ /** The bank's own words from an error page, verbatim; a neutral fallback if none. */
75
+ export function pageMessage(page, fallback) {
76
+ const clean = (s) => s?.replace(/\s+/g, ' ').trim() || undefined;
77
+ return clean(page.heading) ?? clean(page.title) ?? fallback;
78
+ }
79
+ //# sourceMappingURL=login-flow.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"login-flow.js","sourceRoot":"","sources":["../../../src/banks/bci/login-flow.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAclC,SAAS,KAAK,CAAC,GAAW;IACxB,IAAI,CAAC;QACH,OAAO,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;IACtB,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAAC,GAAW;IACvC,MAAM,CAAC,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC;IACrB,IAAI,CAAC,CAAC;QAAE,OAAO,KAAK,CAAC;IACrB,IAAI,CAAC,CAAC,QAAQ,KAAK,GAAG,CAAC,OAAO,EAAE,CAAC;QAC/B,OAAQ,GAAG,CAAC,SAA+B,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC;IACnE,CAAC;IACD,MAAM,CAAC,GAAG,GAAG,CAAC,YAAY,CAAC;IAC3B,IAAI,CAAC,CAAC,QAAQ,KAAK,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC,UAAU,CAAC;QAAE,OAAO,KAAK,CAAC;IAChF,oEAAoE;IACpE,MAAM,IAAI,GAAG,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;IACnD,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE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C,EAAE,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,IAAI,SAAS,CAAC;IAC1E,OAAO,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,QAAQ,CAAC;AAC9D,CAAC"}
@@ -0,0 +1,33 @@
1
+ import type { Cuenta, Movimiento, Saldo } from '../../domain/types.js';
2
+ import type { HttpAnswer } from '../../seams/seams.js';
3
+ /** The app's own `por-rut` answer: `{ cuentas: [{ numero, tipo }] }`. */
4
+ export declare function parseCuentas(json: unknown): Cuenta[];
5
+ /** `por-numero-cuenta`: integer pesos for `saldoDisponible`, `saldoContable`, `retenciones`. */
6
+ export declare function parseSaldo(json: unknown): Saldo;
7
+ /**
8
+ * `cuentas-movimientos/por-numero-cuenta`: `{ movimientos: [{ fechaMovimiento,
9
+ * glosa, monto: "1000.00" (unsigned), tipo: "C" | "A", … }] }`. The sign comes
10
+ * from `tipo` (mapping confirmed against the bank's app, contract); an unknown letter is never guessed.
11
+ */
12
+ export declare function parseMovimientos(json: unknown, cuenta: string): Movimiento[];
13
+ /** The saldos app's URL, under either observed root; anywhere else is not the app. */
14
+ export declare function isAppUrl(url: string, app: string): boolean;
15
+ /**
16
+ * Unix seconds of the bearer's `exp` — the ONLY claim `cta` reads (ADR-015): the
17
+ * others carry the customer's identifiers and are never decoded into anything.
18
+ */
19
+ export declare function grantExpiry(authorization: string): number;
20
+ /**
21
+ * Judges an API answer to an HTTP-mode read (ADR-015, contract "Reads from a Node
22
+ * HTTP client"): the JSON on `200`; `401` → `NotAuthenticated` (seen past `exp`);
23
+ * a challenge, a `403` or a non-JSON answer → `BankBlocked`; anything else →
24
+ * `BankError`. Decided by content as well as status (CONVENTIONS); never retried.
25
+ */
26
+ export declare function judgeApiAnswer(a: HttpAnswer): unknown;
27
+ /**
28
+ * The headers of the app's own API request that `cta` repeats for the next
29
+ * reads from the same page (ADR-012) — only the ones the app sets; the browser
30
+ * adds its own (origin, cookies, user agent) as it always does.
31
+ */
32
+ export declare function appHeaders(headers: Readonly<Record<string, string>>): Record<string, string>;
33
+ //# sourceMappingURL=reads.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reads.d.ts","sourceRoot":"","sources":["../../../src/banks/bci/reads.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAGvE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAkBvD,yEAAyE;AACzE,wBAAgB,YAAY,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,EAAE,CAcpD;AAED,gGAAgG;AAChG,wBAAgB,UAAU,CAAC,IAAI,EAAE,OAAO,GAAG,KAAK,CAiB/C;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,UAAU,EAAE,CAgC5E;AAED,sFAAsF;AACtF,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAU1D;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,aAAa,EAAE,MAAM,GAAG,MAAM,CAgBzD;AAcD;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,UAAU,GAAG,OAAO,CAqBrD;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAQ5F"}
@@ -0,0 +1,181 @@
1
+ import { toIsoDate } from '../../dates/dates.js';
2
+ import { BankBlocked, BankError, NotAuthenticated } from '../../errors/errors.js';
3
+ import { money, parseDecimalAmount } from '../../money/money.js';
4
+ import { BCI } from './config.js';
5
+ /**
6
+ * Pure reading of BCI's answers (`docs/bank-contract/bci.md`). The raw shape
7
+ * never leaves this module (CONVENTIONS: normalize at the boundary), and an
8
+ * unexpected shape is a `BankError`, never a guess.
9
+ */
10
+ const isRecord = (v) => typeof v === 'object' && v !== null && !Array.isArray(v);
11
+ const unexpected = (what) => new BankError(BCI.slug, `El banco respondió con un formato inesperado (${what}).`);
12
+ // Account numbers are digit strings.
13
+ const ACCOUNT_NUMBER = /^\d{4,20}$/;
14
+ /** The app's own `por-rut` answer: `{ cuentas: [{ numero, tipo }] }`. */
15
+ export function parseCuentas(json) {
16
+ if (!isRecord(json) || !Array.isArray(json['cuentas']))
17
+ throw unexpected('cuentas');
18
+ return json['cuentas'].map((c) => {
19
+ if (!isRecord(c) || typeof c['numero'] !== 'string' || !ACCOUNT_NUMBER.test(c['numero'])) {
20
+ throw unexpected('cuenta');
21
+ }
22
+ return {
23
+ banco: BCI.slug,
24
+ numero: c['numero'],
25
+ tipo: typeof c['tipo'] === 'string' ? c['tipo'] : '',
26
+ // Every amount of these reads is whole pesos (contract, Formats).
27
+ moneda: 'CLP',
28
+ };
29
+ });
30
+ }
31
+ /** `por-numero-cuenta`: integer pesos for `saldoDisponible`, `saldoContable`, `retenciones`. */
32
+ export function parseSaldo(json) {
33
+ if (!isRecord(json) || typeof json['numero'] !== 'string')
34
+ throw unexpected('saldo');
35
+ const pesos = (key) => {
36
+ const v = json[key];
37
+ if (typeof v !== 'number' || !Number.isInteger(v))
38
+ throw unexpected(key);
39
+ return money('CLP', v);
40
+ };
41
+ const retenciones = json['retenciones'];
42
+ return {
43
+ banco: BCI.slug,
44
+ cuenta: json['numero'],
45
+ disponible: pesos('saldoDisponible'),
46
+ contable: pesos('saldoContable'),
47
+ ...(retenciones === undefined || retenciones === null
48
+ ? {}
49
+ : { retenciones: pesos('retenciones') }),
50
+ };
51
+ }
52
+ /**
53
+ * `cuentas-movimientos/por-numero-cuenta`: `{ movimientos: [{ fechaMovimiento,
54
+ * glosa, monto: "1000.00" (unsigned), tipo: "C" | "A", … }] }`. The sign comes
55
+ * from `tipo` (mapping confirmed against the bank's app, contract); an unknown letter is never guessed.
56
+ */
57
+ export function parseMovimientos(json, cuenta) {
58
+ if (!isRecord(json) || !Array.isArray(json['movimientos']))
59
+ throw unexpected('movimientos');
60
+ return json['movimientos'].map((m) => {
61
+ if (!isRecord(m))
62
+ throw unexpected('movimiento');
63
+ const { fechaMovimiento, glosa, monto, tipo } = m;
64
+ if (typeof fechaMovimiento !== 'string' || typeof monto !== 'string') {
65
+ throw unexpected('movimiento');
66
+ }
67
+ // Own keys only: a prototype name ('toString') must not pass as a known letter.
68
+ const sign = typeof tipo === 'string' && Object.hasOwn(BCI.movementSign, tipo)
69
+ ? BCI.movementSign[tipo]
70
+ : undefined;
71
+ if (sign === undefined)
72
+ throw unexpected(`tipo de movimiento '${String(tipo)}'`);
73
+ let fecha;
74
+ let abs;
75
+ try {
76
+ fecha = toIsoDate(fechaMovimiento);
77
+ abs = parseDecimalAmount(monto, 'CLP').monto;
78
+ }
79
+ catch {
80
+ throw unexpected('fecha o monto');
81
+ }
82
+ if (abs < 0)
83
+ throw unexpected('monto con signo');
84
+ return {
85
+ banco: BCI.slug,
86
+ cuenta,
87
+ fecha,
88
+ descripcion: typeof glosa === 'string' ? glosa : '',
89
+ monto: money('CLP', sign === 'cargo' ? -abs : abs),
90
+ tipo: sign,
91
+ };
92
+ });
93
+ }
94
+ /** The saldos app's URL, under either observed root; anywhere else is not the app. */
95
+ export function isAppUrl(url, app) {
96
+ try {
97
+ const u = new URL(url);
98
+ return (u.hostname === BCI.appsHost &&
99
+ BCI.appPathRoots.some((root) => u.pathname.startsWith(`${root}${app}/`)));
100
+ }
101
+ catch {
102
+ return false;
103
+ }
104
+ }
105
+ /**
106
+ * Unix seconds of the bearer's `exp` — the ONLY claim `cta` reads (ADR-015): the
107
+ * others carry the customer's identifiers and are never decoded into anything.
108
+ */
109
+ export function grantExpiry(authorization) {
110
+ const token = authorization.replace(/^Bearer\s+/i, '');
111
+ const payload = token.split('.')[1];
112
+ let exp;
113
+ try {
114
+ // atob, not Buffer: this module stays free of Node APIs (ADR-003). The
115
+ // payload is JSON, and only `exp` (a number) is read, so bytes need no UTF-8 pass.
116
+ const b64 = (payload ?? '').replace(/-/g, '+').replace(/_/g, '/');
117
+ exp = JSON.parse(atob(b64.padEnd(Math.ceil(b64.length / 4) * 4, '=')))
118
+ .exp;
119
+ }
120
+ catch {
121
+ throw unexpected('autorización de la app');
122
+ }
123
+ if (typeof exp !== 'number' || !Number.isFinite(exp))
124
+ throw unexpected('vencimiento de la sesión');
125
+ return exp;
126
+ }
127
+ const titleOf = (html) => /<title[^>]*>([^<]*)<\/title>/i.exec(html)?.[1]?.replace(/\s+/g, ' ').trim() || undefined;
128
+ const messageOf = (json) => {
129
+ if (!isRecord(json))
130
+ return undefined;
131
+ for (const key of ['error_description', 'mensaje', 'message']) {
132
+ const v = json[key];
133
+ if (typeof v === 'string' && v.trim() !== '')
134
+ return v.trim();
135
+ }
136
+ return undefined;
137
+ };
138
+ /**
139
+ * Judges an API answer to an HTTP-mode read (ADR-015, contract "Reads from a Node
140
+ * HTTP client"): the JSON on `200`; `401` → `NotAuthenticated` (seen past `exp`);
141
+ * a challenge, a `403` or a non-JSON answer → `BankBlocked`; anything else →
142
+ * `BankError`. Decided by content as well as status (CONVENTIONS); never retried.
143
+ */
144
+ export function judgeApiAnswer(a) {
145
+ const isJson = /\bjson\b/i.test(a.contentType);
146
+ const challenged = BCI.challengeMarkers.some((m) => a.body.includes(m));
147
+ if (a.status === 401)
148
+ throw new NotAuthenticated(BCI.slug);
149
+ if (challenged || a.status === 403 || (a.status === 200 && !isJson)) {
150
+ throw new BankBlocked(BCI.slug, (isJson ? undefined : titleOf(a.body)) ??
151
+ `El banco detuvo la lectura (HTTP ${a.status}, sin datos).`);
152
+ }
153
+ let json;
154
+ try {
155
+ json = JSON.parse(a.body);
156
+ }
157
+ catch {
158
+ throw unexpected('respuesta no legible');
159
+ }
160
+ if (a.status !== 200) {
161
+ throw new BankError(BCI.slug, messageOf(json) ?? `El banco respondió ${a.status}.`);
162
+ }
163
+ return json;
164
+ }
165
+ /**
166
+ * The headers of the app's own API request that `cta` repeats for the next
167
+ * reads from the same page (ADR-012) — only the ones the app sets; the browser
168
+ * adds its own (origin, cookies, user agent) as it always does.
169
+ */
170
+ export function appHeaders(headers) {
171
+ const out = {};
172
+ for (const name of BCI.apiHeaders) {
173
+ const v = headers[name];
174
+ if (v !== undefined)
175
+ out[name] = v;
176
+ }
177
+ if (!out['authorization'])
178
+ throw unexpected('sin autorización de la app');
179
+ return out;
180
+ }
181
+ //# sourceMappingURL=reads.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reads.js","sourceRoot":"","sources":["../../../src/banks/bci/reads.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAEjD,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAClF,OAAO,EAAE,KAAK,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAEjE,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAElC;;;;GAIG;AAEH,MAAM,QAAQ,GAAG,CAAC,CAAU,EAAgC,EAAE,CAC5D,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;AAE3D,MAAM,UAAU,GAAG,CAAC,IAAY,EAAE,EAAE,CAClC,IAAI,SAAS,CAAC,GAAG,CAAC,IAAI,EAAE,iDAAiD,IAAI,IAAI,CAAC,CAAC;AAErF,qCAAqC;AACrC,MAAM,cAAc,GAAG,YAAY,CAAC;AAEpC,yEAAyE;AACzE,MAAM,UAAU,YAAY,CAAC,IAAa;IACxC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,SA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C,IAAI,EAAE,SAAS,CAAC,IAAI,CAAC,IAAI,sBAAsB,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;IACtF,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,UAAU,CAAC,OAAyC;IAClE,MAAM,GAAG,GAA2B,EAAE,CAAC;IACvC,KAAK,MAAM,IAAI,IAAI,GAAG,CAAC,UAAU,EAAE,CAAC;QAClC,MAAM,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;QACxB,IAAI,CAAC,KAAK,SAAS;YAAE,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACrC,CAAC;IACD,IAAI,CAAC,GAAG,CAAC,eAAe,CAAC;QAAE,MAAM,UAAU,CAAC,4BAA4B,CAAC,CAAC;IAC1E,OAAO,GAAG,CAAC;AACb,CAAC"}
@@ -0,0 +1,5 @@
1
+ /** A calendar date as `YYYY-MM-DD` (ADR-007). */
2
+ export type IsoDate = string;
3
+ /** Normalizes a bank date to `YYYY-MM-DD`; rejects anything that is not a real calendar date. */
4
+ export declare function toIsoDate(input: string): IsoDate;
5
+ //# sourceMappingURL=dates.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dates.d.ts","sourceRoot":"","sources":["../../src/dates/dates.ts"],"names":[],"mappings":"AAAA,iDAAiD;AACjD,MAAM,MAAM,OAAO,GAAG,MAAM,CAAC;AAS7B,iGAAiG;AACjG,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAiBhD"}
@@ -0,0 +1,25 @@
1
+ const PATTERNS = [
2
+ // ISO date or datetime: the bank's own calendar date is kept; no timezone shift.
3
+ [/^(\d{4})-(\d{2})-(\d{2})(?:T[\d:.]+(?:Z|[+-]\d{2}:?\d{2})?)?$/, (m) => [m[1], m[2], m[3]]],
4
+ // dd-mm-yyyy and dd/mm/yyyy, as Chilean bank pages render them.
5
+ [/^(\d{2})([-/])(\d{2})\2(\d{4})$/, (m) => [m[4], m[3], m[1]]],
6
+ ];
7
+ /** Normalizes a bank date to `YYYY-MM-DD`; rejects anything that is not a real calendar date. */
8
+ export function toIsoDate(input) {
9
+ const text = input.trim();
10
+ for (const [re, pick] of PATTERNS) {
11
+ const m = re.exec(text);
12
+ if (!m)
13
+ continue;
14
+ const [y, mo, d] = pick(m);
15
+ const date = new Date(Date.UTC(Number(y), Number(mo) - 1, Number(d)));
16
+ if (date.getUTCFullYear() !== Number(y) ||
17
+ date.getUTCMonth() !== Number(mo) - 1 ||
18
+ date.getUTCDate() !== Number(d)) {
19
+ throw new RangeError(`Not a calendar date: '${input}'`);
20
+ }
21
+ return `${y}-${mo}-${d}`;
22
+ }
23
+ throw new SyntaxError(`Unrecognized date format: '${input}'`);
24
+ }
25
+ //# sourceMappingURL=dates.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dates.js","sourceRoot":"","sources":["../../src/dates/dates.ts"],"names":[],"mappings":"AAGA,MAAM,QAAQ,GAA0E;IACtF,iFAAiF;IACjF,CAAC,+DAA+D,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAE,EAAE,CAAC,CAAC,CAAC,CAAE,EAAE,CAAC,CAAC,CAAC,CAAE,CAAC,CAAC;IAC/F,gEAAgE;IAChE,CAAC,iCAAiC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAE,EAAE,CAAC,CAAC,CAAC,CAAE,EAAE,CAAC,CAAC,CAAC,CAAE,CAAC,CAAC;CAClE,CAAC;AAEF,iGAAiG;AACjG,MAAM,UAAU,SAAS,CAAC,KAAa;IACrC,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;IAC1B,KAAK,MAAM,CAAC,EAAE,EAAE,IAAI,CAAC,IAAI,QAAQ,EAAE,CAAC;QAClC,MAAM,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAA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