fintecia 0.0.0-stage → 1.0.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 (74) hide show
  1. package/README.md +134 -2
  2. package/dist/auth/firebaseConfig.d.ts +40 -0
  3. package/dist/auth/firebaseConfig.js +54 -0
  4. package/dist/auth/firebaseConfig.js.map +1 -0
  5. package/dist/auth/session.d.ts +20 -0
  6. package/dist/auth/session.js +25 -0
  7. package/dist/auth/session.js.map +1 -0
  8. package/dist/fiel/decode.d.ts +10 -0
  9. package/dist/fiel/decode.js +17 -0
  10. package/dist/fiel/decode.js.map +1 -0
  11. package/dist/fiel/fiel.d.ts +35 -0
  12. package/dist/fiel/fiel.js +39 -0
  13. package/dist/fiel/fiel.js.map +1 -0
  14. package/dist/fiel/store.d.ts +33 -0
  15. package/dist/fiel/store.js +61 -0
  16. package/dist/fiel/store.js.map +1 -0
  17. package/dist/fin/read.d.ts +19 -0
  18. package/dist/fin/read.js +54 -0
  19. package/dist/fin/read.js.map +1 -0
  20. package/dist/glossary.d.ts +17 -0
  21. package/dist/glossary.js +160 -0
  22. package/dist/glossary.js.map +1 -0
  23. package/dist/handlers.d.ts +38 -0
  24. package/dist/handlers.js +302 -0
  25. package/dist/handlers.js.map +1 -0
  26. package/dist/index.d.ts +2 -0
  27. package/dist/index.js +121 -0
  28. package/dist/index.js.map +1 -0
  29. package/dist/keychain/keychain.d.ts +14 -0
  30. package/dist/keychain/keychain.js +150 -0
  31. package/dist/keychain/keychain.js.map +1 -0
  32. package/dist/onboard/cli.d.ts +1 -0
  33. package/dist/onboard/cli.js +13 -0
  34. package/dist/onboard/cli.js.map +1 -0
  35. package/dist/onboard/server.d.ts +8 -0
  36. package/dist/onboard/server.js +395 -0
  37. package/dist/onboard/server.js.map +1 -0
  38. package/dist/public/lookup.d.ts +35 -0
  39. package/dist/public/lookup.js +45 -0
  40. package/dist/public/lookup.js.map +1 -0
  41. package/dist/public/verify.d.ts +37 -0
  42. package/dist/public/verify.js +61 -0
  43. package/dist/public/verify.js.map +1 -0
  44. package/dist/sat/artifacts.d.ts +33 -0
  45. package/dist/sat/artifacts.js +69 -0
  46. package/dist/sat/artifacts.js.map +1 -0
  47. package/dist/sat/descarga.d.ts +44 -0
  48. package/dist/sat/descarga.js +108 -0
  49. package/dist/sat/descarga.js.map +1 -0
  50. package/dist/sat/fielProvider.d.ts +28 -0
  51. package/dist/sat/fielProvider.js +22 -0
  52. package/dist/sat/fielProvider.js.map +1 -0
  53. package/dist/sat/jobs.d.ts +47 -0
  54. package/dist/sat/jobs.js +40 -0
  55. package/dist/sat/jobs.js.map +1 -0
  56. package/dist/sat/keychainFielProvider.d.ts +17 -0
  57. package/dist/sat/keychainFielProvider.js +36 -0
  58. package/dist/sat/keychainFielProvider.js.map +1 -0
  59. package/dist/sat/parse.d.ts +33 -0
  60. package/dist/sat/parse.js +55 -0
  61. package/dist/sat/parse.js.map +1 -0
  62. package/dist/sat/upload.d.ts +42 -0
  63. package/dist/sat/upload.js +67 -0
  64. package/dist/sat/upload.js.map +1 -0
  65. package/dist/telemetry/client.d.ts +32 -0
  66. package/dist/telemetry/client.js +53 -0
  67. package/dist/telemetry/client.js.map +1 -0
  68. package/dist/telemetry/installId.d.ts +1 -0
  69. package/dist/telemetry/installId.js +36 -0
  70. package/dist/telemetry/installId.js.map +1 -0
  71. package/dist/tools.d.ts +24 -0
  72. package/dist/tools.js +189 -0
  73. package/dist/tools.js.map +1 -0
  74. package/package.json +64 -4
@@ -0,0 +1,14 @@
1
+ /**
2
+ * OS keychain abstraction — stores the FIEL password so `cfdi_download` can
3
+ * sign without re-prompting. The .cer/.key live in FileFielStore; only the
4
+ * PASSWORD is keychain-held (the OS secure store is the one place it may be
5
+ * persisted). Fallback (no keyring) returns null → re-prompt via onboarding.
6
+ */
7
+ export interface Keychain {
8
+ set(key: string, secret: string): Promise<void>;
9
+ get(key: string): Promise<string | null>;
10
+ delete(key: string): Promise<void>;
11
+ }
12
+ /** Pure platform → adapter selection (unit-testable). */
13
+ export declare function detectKeychain(platform: NodeJS.Platform): Keychain;
14
+ export declare function fielKeychainKey(rfc: string): string;
@@ -0,0 +1,150 @@
1
+ import { execFile, execFileSync } from "node:child_process";
2
+ import { existsSync } from "node:fs";
3
+ import { promisify } from "node:util";
4
+ const execFileAsync = promisify(execFile);
5
+ const SERVICE = "fintecia-mcp";
6
+ /** macOS Keychain via `security` CLI. */
7
+ class MacKeychain {
8
+ async set(key, secret) {
9
+ await execFileAsync("security", [
10
+ "add-generic-password",
11
+ "-a", key,
12
+ "-s", SERVICE,
13
+ "-w", secret,
14
+ "-U",
15
+ ]);
16
+ }
17
+ async get(key) {
18
+ try {
19
+ const { stdout } = await execFileAsync("security", [
20
+ "find-generic-password",
21
+ "-a", key,
22
+ "-s", SERVICE,
23
+ "-w",
24
+ ]);
25
+ return stdout.trim() || null;
26
+ }
27
+ catch {
28
+ return null;
29
+ }
30
+ }
31
+ async delete(key) {
32
+ await execFileAsync("security", [
33
+ "delete-generic-password",
34
+ "-a", key,
35
+ "-s", SERVICE,
36
+ ]).catch(() => { });
37
+ }
38
+ }
39
+ /** Windows DPAPI via PowerShell (ProtectData / UnprotectData). */
40
+ class WinKeychain {
41
+ async set(key, secret) {
42
+ const b64 = Buffer.from(secret, "utf8").toString("base64");
43
+ await execFileAsync("powershell", [
44
+ "-NoProfile", "-Command",
45
+ `Add-Type -AssemblyName System.Security; ` +
46
+ `[IO.File]::WriteAllBytes($env:LOCALAPPDATA + '\\fintecia-${sanitizeWin(key)}', ` +
47
+ `[Security.Cryptography.ProtectedData]::Protect([Text.Encoding]::UTF8.GetBytes('${b64}'), $null, 'CurrentUser'))`,
48
+ ]);
49
+ }
50
+ async get(key) {
51
+ try {
52
+ const { stdout } = await execFileAsync("powershell", [
53
+ "-NoProfile", "-Command",
54
+ `Add-Type -AssemblyName System.Security; ` +
55
+ `$b=[Security.Cryptography.ProtectedData]::Unprotect([IO.File]::ReadAllBytes($env:LOCALAPPDATA + '\\fintecia-${sanitizeWin(key)}'), $null, 'CurrentUser'); ` +
56
+ `[Text.Encoding]::UTF8.GetString($b)`,
57
+ ]);
58
+ const b64 = stdout.trim();
59
+ return b64 ? Buffer.from(b64, "base64").toString("utf8") : null;
60
+ }
61
+ catch {
62
+ return null;
63
+ }
64
+ }
65
+ async delete(key) {
66
+ await execFileAsync("powershell", [
67
+ "-NoProfile", "-Command",
68
+ `Remove-Item ($env:LOCALAPPDATA + '\\fintecia-${sanitizeWin(key)}') -ErrorAction SilentlyContinue`,
69
+ ]).catch(() => { });
70
+ }
71
+ }
72
+ /** Linux libsecret via `secret-tool`. */
73
+ class LinuxKeychain {
74
+ async set(key, secret) {
75
+ // Throw on failure (consistent with Mac/Win): the caller must surface the
76
+ // keyring error instead of silently dropping the password and leaving the
77
+ // FIEL in an unrecoverable "stored but no password" state.
78
+ execFileSync("secret-tool", [
79
+ "store", "--label=fintecia-mcp", "service", SERVICE, "account", key,
80
+ ], { input: secret, env: secretToolEnv() });
81
+ }
82
+ async get(key) {
83
+ try {
84
+ const { stdout } = await execFileAsync("secret-tool", [
85
+ "lookup", "service", SERVICE, "account", key,
86
+ ], { env: secretToolEnv() });
87
+ return stdout.trim() || null;
88
+ }
89
+ catch {
90
+ return null;
91
+ }
92
+ }
93
+ async delete(key) {
94
+ await execFileAsync("secret-tool", [
95
+ "clear", "service", SERVICE, "account", key,
96
+ ], { env: secretToolEnv() }).catch(() => { });
97
+ }
98
+ }
99
+ /**
100
+ * Environment for `secret-tool` calls. The MCP server often runs without the
101
+ * desktop session's `DBUS_SESSION_BUS_ADDRESS` (e.g. launched from a headless
102
+ * Inspector), so libsecret tries to autolaunch D-Bus — which needs X11
103
+ * `$DISPLAY` and fails with "Cannot autolaunch D-Bus without X11 $DISPLAY".
104
+ * Point it at the conventional systemd user bus instead when the socket exists.
105
+ */
106
+ function secretToolEnv() {
107
+ if (process.env.DBUS_SESSION_BUS_ADDRESS)
108
+ return process.env;
109
+ const uid = typeof process.getuid === "function" ? process.getuid() : undefined;
110
+ if (uid === undefined)
111
+ return process.env;
112
+ const bus = `/run/user/${uid}/bus`;
113
+ try {
114
+ if (existsSync(bus)) {
115
+ return { ...process.env, DBUS_SESSION_BUS_ADDRESS: `unix:path=${bus}` };
116
+ }
117
+ }
118
+ catch {
119
+ /* ignore — fall through to the unmodified env */
120
+ }
121
+ return process.env;
122
+ }
123
+ /** No keyring available (e.g. headless Linux): nothing is persisted. */
124
+ class NullKeychain {
125
+ async set() { }
126
+ async get() {
127
+ return null;
128
+ }
129
+ async delete() { }
130
+ }
131
+ /** Pure platform → adapter selection (unit-testable). */
132
+ export function detectKeychain(platform) {
133
+ switch (platform) {
134
+ case "darwin":
135
+ return new MacKeychain();
136
+ case "win32":
137
+ return new WinKeychain();
138
+ case "linux":
139
+ return new LinuxKeychain();
140
+ default:
141
+ return new NullKeychain();
142
+ }
143
+ }
144
+ export function fielKeychainKey(rfc) {
145
+ return `fiel:${rfc.toUpperCase()}`;
146
+ }
147
+ function sanitizeWin(key) {
148
+ return key.replace(/[^A-Za-z0-9-]/g, "-");
149
+ }
150
+ //# sourceMappingURL=keychain.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"keychain.js","sourceRoot":"","sources":["../../src/keychain/keychain.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAC5D,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEtC,MAAM,aAAa,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAC;AAe1C,MAAM,OAAO,GAAG,cAAc,CAAC;AAE/B,yCAAyC;AACzC,MAAM,WAAW;IACf,KAAK,CAAC,GAAG,CAAC,GAAW,EAAE,MAAc;QACnC,MAAM,aAAa,CAAC,UAAU,EAAE;YAC9B,sBAAsB;YACtB,IAAI,EAAE,GAAG;YACT,IAAI,EAAE,O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3B,KAAK,OAAO;YACV,OAAO,IAAI,aAAa,EAAE,CAAC;QAC7B;YACE,OAAO,IAAI,YAAY,EAAE,CAAC;IAC9B,CAAC;AACH,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,GAAW;IACzC,OAAO,QAAQ,GAAG,CAAC,WAAW,EAAE,EAAE,CAAC;AACrC,CAAC;AAED,SAAS,WAAW,CAAC,GAAW;IAC9B,OAAO,GAAG,CAAC,OAAO,CAAC,gBAAgB,EAAE,GAAG,CAAC,CAAC;AAC5C,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,13 @@
1
+ // CLI entry for the onboarding (web local): Google sign-in (loopback) + FIEL.
2
+ // Usage: npm run onboard
3
+ import { startOnboardServer } from "./server.js";
4
+ import { FileFielStore } from "../fiel/store.js";
5
+ import { SessionStore } from "../auth/session.js";
6
+ const store = new FileFielStore();
7
+ const session = new SessionStore();
8
+ const { url } = await startOnboardServer(store, session, (s) => {
9
+ console.log(`Sesión iniciada (idToken ${s.idToken.slice(0, 8)}…).`);
10
+ });
11
+ console.log(`Abriendo onboarding en ${url}`);
12
+ console.log("Pegá esa URL en tu navegador: iniciá sesión con Google y cargá .cer + .key + contraseña.");
13
+ //# sourceMappingURL=cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.js","sourceRoot":"","sources":["../../src/onboard/cli.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,yBAAyB;AACzB,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,MAAM,KAAK,GAAG,IAAI,aAAa,EAAE,CAAC;AAClC,MAAM,OAAO,GAAG,IAAI,YAAY,EAAE,CAAC;AAEnC,MAAM,EAAE,GAAG,EAAE,GAAG,MAAM,kBAAkB,CAAC,KAAK,EAAE,OAAO,EAAE,CAAC,CAAC,EAAE,EAAE;IAC7D,OAAO,CAAC,GAAG,CAAC,4BAA4B,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC;AACtE,CAAC,CAAC,CAAC;AAEH,OAAO,CAAC,GAAG,CAAC,0BAA0B,GAAG,EAAE,CAAC,CAAC;AAC7C,OAAO,CAAC,GAAG,CAAC,0FAA0F,CAAC,CAAC"}
@@ -0,0 +1,8 @@
1
+ import { type Server } from "node:http";
2
+ import type { FielStore } from "../fiel/store.js";
3
+ import { SessionStore, type AuthSession } from "../auth/session.js";
4
+ import { type Keychain } from "../keychain/keychain.js";
5
+ export declare function startOnboardServer(store: FielStore, session?: SessionStore, onAuth?: (s: AuthSession) => void, keychain?: Keychain): Promise<{
6
+ server: Server;
7
+ url: string;
8
+ }>;
@@ -0,0 +1,395 @@
1
+ import { createServer, } from "node:http";
2
+ import { inspectFiel } from "../fiel/fiel.js";
3
+ import { decodeFileForFiel } from "../fiel/decode.js";
4
+ import { FIREBASE_WEB_CONFIG, isLocal, AUTH_EMULATOR_URL } from "../auth/firebaseConfig.js";
5
+ import { SessionStore } from "../auth/session.js";
6
+ import { detectKeychain, fielKeychainKey } from "../keychain/keychain.js";
7
+ import { saveFielPassword } from "../sat/keychainFielProvider.js";
8
+ /**
9
+ * Onboarding web-local server (127.0.0.1 only). Two responsibilities:
10
+ * 1. Load the e-firma (.cer + .key + password) -> validate + store locally.
11
+ * 2. Loopback OAuth: the page signs in with Google (+ MFA) via the Firebase
12
+ * Web SDK and POSTs the tokens back to this server, which stores them in
13
+ * the SessionStore. The password / tokens never leave the process.
14
+ */
15
+ function html(config, localAuthUrl) {
16
+ return `<!doctype html><html lang="es"><head><meta charset="utf-8">
17
+ <meta name="viewport" content="width=device-width, initial-scale=1">
18
+ <title>Fintecia — Conectar</title>
19
+ <style>
20
+ :root {
21
+ --brand: #0B57D0;
22
+ --brand-hover: #0842A0;
23
+ --bg: #F6F8FC;
24
+ --card: #FFFFFF;
25
+ --text: #1F2937;
26
+ --muted: #6B7280;
27
+ --border: #E5E7EB;
28
+ --success: #1B873B;
29
+ --success-bg: #EAF6EE;
30
+ --error: #B3261E;
31
+ --error-bg: #FBECEB;
32
+ }
33
+ * { box-sizing: border-box; margin: 0; padding: 0; }
34
+ body {
35
+ font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
36
+ background: var(--bg);
37
+ color: var(--text);
38
+ min-height: 100vh;
39
+ display: flex; align-items: center; justify-content: center;
40
+ padding: 24px;
41
+ }
42
+ .card {
43
+ background: var(--card);
44
+ border: 1px solid var(--border);
45
+ border-radius: 16px;
46
+ box-shadow: 0 8px 32px rgba(11, 87, 208, 0.08);
47
+ max-width: 440px; width: 100%;
48
+ padding: 36px 32px 32px;
49
+ }
50
+ .logo {
51
+ width: 40px; height: 40px; border-radius: 10px;
52
+ background: var(--brand); color: #fff;
53
+ display: flex; align-items: center; justify-content: center;
54
+ font-weight: 800; font-size: 18px; margin-bottom: 16px;
55
+ }
56
+ h1 { font-size: 22px; font-weight: 700; letter-spacing: -0.02em; }
57
+ .subtitle { color: var(--muted); font-size: 14px; line-height: 1.5; margin: 6px 0 28px; }
58
+ .step { font-size: 12px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); margin: 24px 0 10px; }
59
+ .btn {
60
+ display: flex; align-items: center; justify-content: center; gap: 10px;
61
+ width: 100%; padding: 12px 16px; border-radius: 10px;
62
+ font-size: 15px; font-weight: 600; font-family: inherit; cursor: pointer;
63
+ border: 1px solid var(--border); background: #fff; color: var(--text);
64
+ transition: background .15s, border-color .15s;
65
+ }
66
+ .btn:hover { background: #F3F6FC; border-color: #CBD5E1; }
67
+ .btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
68
+ .btn-primary:hover { background: var(--brand-hover); border-color: var(--brand-hover); }
69
+ .g { width: 18px; height: 18px; }
70
+ label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
71
+ .file, input[type="password"] {
72
+ width: 100%; padding: 10px 12px; border: 1px solid var(--border);
73
+ border-radius: 8px; font-size: 14px; margin-bottom: 16px; background: #fff;
74
+ color: var(--text); font-family: inherit;
75
+ }
76
+ input[type="file"] { padding: 8px; color: var(--muted); }
77
+ input[type="file"]::file-selector-button {
78
+ border: 1px solid var(--border); border-radius: 6px; background: #F3F6FC;
79
+ padding: 6px 12px; margin-right: 10px; font-size: 13px; font-weight: 600;
80
+ cursor: pointer; color: var(--text); font-family: inherit;
81
+ }
82
+ .status {
83
+ display: none; margin-top: 14px; padding: 12px 14px; border-radius: 8px;
84
+ font-size: 14px; line-height: 1.4; word-break: break-word;
85
+ }
86
+ .status.show { display: block; }
87
+ .status.ok { background: var(--success-bg); color: var(--success); }
88
+ .status.err { background: var(--error-bg); color: var(--error); }
89
+ .status.info { background: #EDF3FC; color: var(--brand); }
90
+ .hint { font-size: 12px; color: var(--muted); line-height: 1.5; margin-top: 18px; }
91
+ .divider { border: none; border-top: 1px solid var(--border); margin: 20px 0 0; }
92
+ .efirma-item { border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; margin-bottom: 12px; }
93
+ .efirma-rfc { font-weight: 700; font-size: 15px; }
94
+ .efirma-status { font-size: 13px; margin: 4px 0 10px; }
95
+ .efirma-status.ok { color: var(--success); }
96
+ .efirma-status.warn { color: #B45309; }
97
+ </style>
98
+ </head><body>
99
+ <div class="card">
100
+ <div id="screenLogin">
101
+ <div class="logo">F</div>
102
+ <h1>Conectá tu cuenta</h1>
103
+ <p class="subtitle">Iniciá sesión con Google para continuar. Tus llaves nunca salen de esta máquina.</p>
104
+
105
+ <button id="signin" class="btn">
106
+ <svg class="g" viewBox="0 0 24 24"><path fill="#4285F4" d="M23.5 12.27c0-.85-.08-1.66-.22-2.45H12v4.64h6.45a5.52 5.52 0 0 1-2.4 3.62v3h3.88c2.27-2.09 3.57-5.17 3.57-8.81z"/><path fill="#34A853" d="M12 24c3.24 0 5.96-1.07 7.94-2.91l-3.88-3c-1.08.72-2.45 1.15-4.06 1.15-3.12 0-5.77-2.11-6.71-4.95H1.28v3.1A12 12 0 0 0 12 24z"/><path fill="#FBBC05" d="M5.29 14.29a7.2 7.2 0 0 1 0-4.58v-3.1H1.28a12 12 0 0 0 0 10.78l4.01-3.1z"/><path fill="#EA4335" d="M12 4.76c1.76 0 3.34.6 4.58 1.79l3.44-3.44A11.98 11.98 0 0 0 1.28 6.61l4.01 3.1C6.23 6.87 8.88 4.76 12 4.76z"/></svg>
107
+ Iniciar sesión con Google
108
+ </button>
109
+ <div id="authStatus" class="status"></div>
110
+ </div>
111
+
112
+ <div id="screenList" style="display:none">
113
+ <div class="logo">F</div>
114
+ <h1>Tus e-firmas</h1>
115
+ <p class="subtitle">Estas son las e-firmas guardadas en esta máquina.</p>
116
+ <div id="efirmaList"></div>
117
+ <button id="addFirma" class="btn btn-primary">Agregar otra e-firma</button>
118
+ <p class="hint">Ya podés cerrar esta ventana y volver al agente para pedir tus facturas.</p>
119
+ <div id="listOut" class="status"></div>
120
+ </div>
121
+
122
+ <div id="screenAdd" style="display:none">
123
+ <div class="logo">F</div>
124
+ <h1>Conectá tu e-firma</h1>
125
+ <p class="subtitle">Subí tu certificado y llave privada para que el agente pueda descargar tus facturas.</p>
126
+ <form id="f">
127
+ <label for="cer">Certificado (.cer)</label>
128
+ <input class="file" id="cer" type="file" accept=".cer,.pem,.crt">
129
+ <label for="key">Llave privada (.key)</label>
130
+ <input class="file" id="key" type="file" accept=".key,.pem">
131
+ <label for="pass">Contraseña de la llave</label>
132
+ <input id="pass" type="password" autocomplete="off" placeholder="••••••••">
133
+ <button type="submit" class="btn btn-primary">Guardar e-firma</button>
134
+ </form>
135
+ <button id="backToList" class="btn" style="margin-top:12px">← Volver</button>
136
+ <div id="out" class="status"></div>
137
+ <p class="hint">La contraseña se guarda solo en el keyring del sistema (llaves del OS) para firmar tus descargas. Nunca se sube ni sale de esta máquina.</p>
138
+ </div>
139
+ </div>
140
+
141
+ <script src="https://www.gstatic.com/firebasejs/10.14.0/firebase-app-compat.js"></script>
142
+ <script src="https://www.gstatic.com/firebasejs/10.14.0/firebase-auth-compat.js"></script>
143
+ <script>
144
+ firebase.initializeApp(${JSON.stringify(config)});
145
+ ${localAuthUrl ? `firebase.auth().useEmulator(${JSON.stringify(localAuthUrl)});` : ''}
146
+ const auth = firebase.auth();
147
+
148
+ const $ = (id) => document.getElementById(id);
149
+ const status = (el, text, kind) => { el.textContent = text; el.className = "status show " + kind; };
150
+
151
+ $("signin").addEventListener("click", async () => {
152
+ status($("authStatus"), "Iniciando sesión…", "info");
153
+ try {
154
+ const result = await signIn(auth);
155
+ const idToken = await result.user.getIdToken();
156
+ const refreshToken = result.user.refreshToken;
157
+ const res = await fetch("/auth", {
158
+ method: "POST",
159
+ headers: { "content-type": "application/json" },
160
+ body: JSON.stringify({ idToken, refreshToken }),
161
+ });
162
+ const body = await res.json();
163
+ if (body.ok) {
164
+ await refreshList();
165
+ } else {
166
+ status($("authStatus"), "No se pudo iniciar sesión: " + (body.error || "error"), "err");
167
+ }
168
+ } catch (err) {
169
+ status($("authStatus"), "No se pudo iniciar sesión: " + (err.code || err.message || err), "err");
170
+ }
171
+ });
172
+
173
+ // No MFA (TOTP) in the MCP: it's an acquisition channel and read-only, so
174
+ // sign-in is a plain Google popup. The user's own Google 2FA (if any) is
175
+ // handled by Google, not Fintecia (S3: "Sin MFA en el MCP").
176
+ function signIn(a) {
177
+ return a.signInWithPopup(new firebase.auth.GoogleAuthProvider());
178
+ }
179
+
180
+ const read = (file) => new Promise((res, rej) => {
181
+ const r = new FileReader();
182
+ r.onload = () => res(String(r.result).split(',')[1] ?? '');
183
+ r.onerror = () => rej(r.error);
184
+ r.readAsDataURL(file);
185
+ });
186
+
187
+ $("f").addEventListener("submit", async (e) => {
188
+ e.preventDefault();
189
+ status($("out"), "Validando…", "info");
190
+ try {
191
+ const cerB64 = await read($("cer").files[0]);
192
+ const keyB64 = await read($("key").files[0]);
193
+ const res = await fetch("/fiel", {
194
+ method: "POST",
195
+ headers: { "content-type": "application/json" },
196
+ body: JSON.stringify({ cerB64, keyB64, password: $("pass").value }),
197
+ });
198
+ const body = await res.json();
199
+ if (body.ok) {
200
+ if (body.passwordPersisted === false) {
201
+ status($("listOut"), "E-firma válida · RFC " + body.rfc + ". PERO no pude guardar la contraseña en el keyring (" + (body.keychainError || "keyring no disponible") + "). Re-ingresala en la lista.", "err");
202
+ }
203
+ $("f").reset();
204
+ await refreshList();
205
+ } else {
206
+ status($("out"), "No se pudo validar: " + (body.error || "error"), "err");
207
+ }
208
+ } catch (err) {
209
+ status($("out"), "No se pudo validar: " + String(err), "err");
210
+ }
211
+ });
212
+
213
+ const screens = ["screenLogin", "screenList", "screenAdd"];
214
+ function showScreen(id) {
215
+ for (const s of screens) $(s).style.display = s === id ? "block" : "none";
216
+ }
217
+
218
+ async function refreshList() {
219
+ const res = await fetch("/efirmas");
220
+ const body = await res.json();
221
+ const efirmas = body.efirmas || [];
222
+ if (efirmas.length === 0) { showScreen("screenAdd"); return; }
223
+ renderList(efirmas);
224
+ showScreen("screenList");
225
+ }
226
+
227
+ function renderList(efirmas) {
228
+ const el = $("efirmaList");
229
+ el.innerHTML = "";
230
+ for (const e of efirmas) {
231
+ const item = document.createElement("div");
232
+ item.className = "efirma-item";
233
+ const rfc = document.createElement("div");
234
+ rfc.className = "efirma-rfc";
235
+ rfc.textContent = e.rfc;
236
+ const st = document.createElement("div");
237
+ st.className = "efirma-status " + (e.hasPassword ? "ok" : "warn");
238
+ st.textContent = e.hasPassword ? "✓ lista para usar" : "⚠ falta la contraseña";
239
+ item.appendChild(rfc);
240
+ item.appendChild(st);
241
+ if (!e.hasPassword) {
242
+ const btn = document.createElement("button");
243
+ btn.className = "btn";
244
+ btn.textContent = "Re-ingresar contraseña";
245
+ btn.addEventListener("click", () => relink(e.rfc));
246
+ item.appendChild(btn);
247
+ }
248
+ el.appendChild(item);
249
+ }
250
+ }
251
+
252
+ $("addFirma").addEventListener("click", () => showScreen("screenAdd"));
253
+ $("backToList").addEventListener("click", () => refreshList());
254
+
255
+ async function relink(rfc) {
256
+ const password = prompt("Contraseña de la llave para " + rfc + ":");
257
+ if (!password) return;
258
+ const res = await fetch("/refiel", {
259
+ method: "POST",
260
+ headers: { "content-type": "application/json" },
261
+ body: JSON.stringify({ rfc, password }),
262
+ });
263
+ const body = await res.json();
264
+ if (body.ok && body.passwordPersisted !== false) {
265
+ status($("listOut"), "Contraseña guardada para " + rfc + ".", "ok");
266
+ await refreshList();
267
+ } else if (body.ok) {
268
+ status($("listOut"), "Contraseña válida pero NO pude guardarla en el keyring: " + (body.keychainError || "keyring no disponible"), "err");
269
+ } else {
270
+ status($("listOut"), "No se pudo: " + (body.error || "error"), "err");
271
+ }
272
+ }
273
+ </script></body></html>`;
274
+ }
275
+ async function readBody(req) {
276
+ let body = "";
277
+ for await (const chunk of req)
278
+ body += chunk;
279
+ return body;
280
+ }
281
+ export function startOnboardServer(store, session = new SessionStore(), onAuth = () => { }, keychain = detectKeychain(process.platform)) {
282
+ return new Promise((resolve) => {
283
+ const server = createServer(async (req, res) => {
284
+ const send = (status, body) => {
285
+ res.writeHead(status, { "content-type": "application/json" });
286
+ res.end(JSON.stringify(body));
287
+ };
288
+ if (req.method === "GET" && req.url === "/") {
289
+ res.writeHead(200, { "content-type": "text/html; charset=utf-8" });
290
+ res.end(html(FIREBASE_WEB_CONFIG, isLocal ? AUTH_EMULATOR_URL : null));
291
+ return;
292
+ }
293
+ if (req.method === "POST" && req.url === "/auth") {
294
+ try {
295
+ const { idToken, refreshToken } = JSON.parse(await readBody(req));
296
+ if (!idToken || !refreshToken) {
297
+ send(400, { ok: false, error: "missing tokens" });
298
+ return;
299
+ }
300
+ const s = { idToken, refreshToken };
301
+ session.set(s);
302
+ onAuth(s);
303
+ send(200, { ok: true });
304
+ }
305
+ catch (err) {
306
+ send(400, { ok: false, error: err.message });
307
+ }
308
+ return;
309
+ }
310
+ if (req.method === "POST" && req.url === "/fiel") {
311
+ if (!session.idToken) {
312
+ send(401, { ok: false, error: "iniciá sesión primero (Google)" });
313
+ return;
314
+ }
315
+ try {
316
+ const { cerB64, keyB64, password } = JSON.parse(await readBody(req));
317
+ const cer = decodeFileForFiel(cerB64, 'cert');
318
+ const key = decodeFileForFiel(keyB64, 'key');
319
+ const { info } = inspectFiel(cer, key, password);
320
+ await store.store({ rfc: info.rfc, certPem: info.pem, keyPem: key });
321
+ // The FIEL is stored regardless; the keychain write is best-effort
322
+ // and reported separately so the user can act when the keyring is
323
+ // unavailable (instead of a silent "success" that breaks signing).
324
+ let passwordPersisted = true;
325
+ let keychainError = null;
326
+ try {
327
+ await saveFielPassword(keychain, info.rfc, password);
328
+ }
329
+ catch (err) {
330
+ passwordPersisted = false;
331
+ keychainError = err.message;
332
+ }
333
+ send(200, { ok: true, rfc: info.rfc, passwordPersisted, keychainError });
334
+ }
335
+ catch (err) {
336
+ send(400, { ok: false, error: err.message });
337
+ }
338
+ return;
339
+ }
340
+ if (req.method === "GET" && req.url === "/efirmas") {
341
+ if (!session.idToken) {
342
+ send(401, { ok: false, error: "iniciá sesión primero (Google)" });
343
+ return;
344
+ }
345
+ const rfcs = await store.list();
346
+ const efirmas = await Promise.all(rfcs.map(async (rfc) => ({
347
+ rfc,
348
+ hasPassword: (await keychain.get(fielKeychainKey(rfc))) !== null,
349
+ })));
350
+ send(200, { efirmas });
351
+ return;
352
+ }
353
+ if (req.method === "POST" && req.url === "/refiel") {
354
+ if (!session.idToken) {
355
+ send(401, { ok: false, error: "iniciá sesión primero (Google)" });
356
+ return;
357
+ }
358
+ try {
359
+ const { rfc, password } = JSON.parse(await readBody(req));
360
+ const creds = await store.load(rfc);
361
+ if (!creds) {
362
+ send(404, { ok: false, error: `No hay e-firma guardada para el RFC ${rfc}` });
363
+ return;
364
+ }
365
+ // Re-validate the stored .cer/.key against the re-entered password,
366
+ // then re-persist the password (the keychain write may have failed
367
+ // on the original onboarding).
368
+ const { info } = inspectFiel(creds.certPem, creds.keyPem, password);
369
+ let passwordPersisted = true;
370
+ let keychainError = null;
371
+ try {
372
+ await saveFielPassword(keychain, info.rfc, password);
373
+ }
374
+ catch (err) {
375
+ passwordPersisted = false;
376
+ keychainError = err.message;
377
+ }
378
+ send(200, { ok: true, rfc: info.rfc, passwordPersisted, keychainError });
379
+ }
380
+ catch (err) {
381
+ send(400, { ok: false, error: err.message });
382
+ }
383
+ return;
384
+ }
385
+ send(404, { ok: false, error: "not found" });
386
+ });
387
+ server.listen(0, "127.0.0.1", () => {
388
+ const addr = server.address();
389
+ if (addr && typeof addr === "object") {
390
+ resolve({ server, url: `http://127.0.0.1:${addr.port}` });
391
+ }
392
+ });
393
+ });
394
+ }
395
+ //# sourceMappingURL=server.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.js","sourceRoot":"","sources":["../../src/onboard/server.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,GAIb,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAEtD,OAAO,EAAE,mBAAmB,EAAE,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC5F,OAAO,EAAE,YAAY,EAAoB,MAAM,oBAAoB,CAAC;AACpE,OAAO,EAAiB,cAAc,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AACzF,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAElE;;;;;;GAMG;AAEH,SAAS,IAAI,CAAC,MAA8B,EAAE,YAA2B;IACvE,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;yBAgIgB,IAAI,CAAC,SAAS,CAAC,MAAM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AAI,EAAE,EAAE,CAAC,CAAC;YAC5D,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Backend-backed lookups for the SAT public lists (69-B + art. 69).
3
+ *
4
+ * The lists live in the Fintecia backend (Firestore, refreshed monthly); the
5
+ * MCP is a thin client. These lookups REQUIRE a logged-in session (ID token)
6
+ * per the "auth, not e-firma" rule — there is NO local fixture in production
7
+ * (a fixture would answer with stale/sample data and never hit the backend).
8
+ */
9
+ export declare function normalizeRfc(rfc: string): string;
10
+ export interface SatListEntry {
11
+ rfc: string;
12
+ nombre: string;
13
+ situacion: string;
14
+ oficio?: string;
15
+ fechaPublicacion?: string;
16
+ }
17
+ export interface PublicLookupClientConfig {
18
+ baseUrl: string;
19
+ getAuthToken: () => Promise<string | null>;
20
+ fetchFn?: typeof fetch;
21
+ }
22
+ export declare class PublicLookupClient {
23
+ private readonly config;
24
+ constructor(config: PublicLookupClientConfig);
25
+ private fetch;
26
+ private get;
27
+ checkEfos(rfc: string): Promise<{
28
+ found: boolean;
29
+ entry: SatListEntry | null;
30
+ }>;
31
+ checkDebts(rfc: string): Promise<{
32
+ found: boolean;
33
+ entry: SatListEntry | null;
34
+ }>;
35
+ }