fintecia 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +134 -2
- package/dist/auth/deviceFlow.d.ts +53 -0
- package/dist/auth/deviceFlow.js +83 -0
- package/dist/auth/deviceFlow.js.map +1 -0
- package/dist/auth/firebaseConfig.d.ts +40 -0
- package/dist/auth/firebaseConfig.js +54 -0
- package/dist/auth/firebaseConfig.js.map +1 -0
- package/dist/auth/session.d.ts +20 -0
- package/dist/auth/session.js +25 -0
- package/dist/auth/session.js.map +1 -0
- package/dist/fiel/decode.d.ts +10 -0
- package/dist/fiel/decode.js +17 -0
- package/dist/fiel/decode.js.map +1 -0
- package/dist/fiel/fiel.d.ts +35 -0
- package/dist/fiel/fiel.js +39 -0
- package/dist/fiel/fiel.js.map +1 -0
- package/dist/fiel/store.d.ts +33 -0
- package/dist/fiel/store.js +61 -0
- package/dist/fiel/store.js.map +1 -0
- package/dist/fin/read.d.ts +19 -0
- package/dist/fin/read.js +54 -0
- package/dist/fin/read.js.map +1 -0
- package/dist/glossary.d.ts +17 -0
- package/dist/glossary.js +160 -0
- package/dist/glossary.js.map +1 -0
- package/dist/handlers.d.ts +38 -0
- package/dist/handlers.js +302 -0
- package/dist/handlers.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +121 -0
- package/dist/index.js.map +1 -0
- package/dist/keychain/keychain.d.ts +14 -0
- package/dist/keychain/keychain.js +150 -0
- package/dist/keychain/keychain.js.map +1 -0
- package/dist/onboard/cli.d.ts +1 -0
- package/dist/onboard/cli.js +13 -0
- package/dist/onboard/cli.js.map +1 -0
- package/dist/onboard/server.d.ts +8 -0
- package/dist/onboard/server.js +395 -0
- package/dist/onboard/server.js.map +1 -0
- package/dist/public/data/debts.fixture.json +4 -0
- package/dist/public/data/efos.fixture.json +8 -0
- package/dist/public/efos.d.ts +28 -0
- package/dist/public/efos.js +45 -0
- package/dist/public/efos.js.map +1 -0
- package/dist/public/lookup.d.ts +35 -0
- package/dist/public/lookup.js +45 -0
- package/dist/public/lookup.js.map +1 -0
- package/dist/public/verify.d.ts +37 -0
- package/dist/public/verify.js +61 -0
- package/dist/public/verify.js.map +1 -0
- package/dist/sat/artifacts.d.ts +33 -0
- package/dist/sat/artifacts.js +69 -0
- package/dist/sat/artifacts.js.map +1 -0
- package/dist/sat/descarga.d.ts +44 -0
- package/dist/sat/descarga.js +108 -0
- package/dist/sat/descarga.js.map +1 -0
- package/dist/sat/fielProvider.d.ts +28 -0
- package/dist/sat/fielProvider.js +22 -0
- package/dist/sat/fielProvider.js.map +1 -0
- package/dist/sat/jobs.d.ts +47 -0
- package/dist/sat/jobs.js +40 -0
- package/dist/sat/jobs.js.map +1 -0
- package/dist/sat/keychainFielProvider.d.ts +17 -0
- package/dist/sat/keychainFielProvider.js +36 -0
- package/dist/sat/keychainFielProvider.js.map +1 -0
- package/dist/sat/parse.d.ts +33 -0
- package/dist/sat/parse.js +55 -0
- package/dist/sat/parse.js.map +1 -0
- package/dist/sat/upload.d.ts +42 -0
- package/dist/sat/upload.js +67 -0
- package/dist/sat/upload.js.map +1 -0
- package/dist/telemetry/client.d.ts +32 -0
- package/dist/telemetry/client.js +53 -0
- package/dist/telemetry/client.js.map +1 -0
- package/dist/telemetry/installId.d.ts +1 -0
- package/dist/telemetry/installId.js +36 -0
- package/dist/telemetry/installId.js.map +1 -0
- package/dist/tools.d.ts +24 -0
- package/dist/tools.js +189 -0
- package/dist/tools.js.map +1 -0
- package/package.json +64 -4
|
@@ -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
|
+
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AAC,CAAC;oBACvD,CAAC;oBAAC,OAAO,GAAG,EAAE,CAAC;wBACb,iBAAiB,GAAG,KAAK,CAAC;wBAC1B,aAAa,GAAI,GAAa,CAAC,OAAO,CAAC;oBACzC,CAAC;oBACD,IAAI,CAAC,GAAG,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE,iBAAiB,EAAE,aAAa,EAAE,CAAC,CAAC;gBAC3E,CAAC;gBAAC,OAAO,GAAG,EAAE,CAAC;oBACb,IAAI,CAAC,GAAG,EAAE,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAG,GAAa,CAAC,OAAO,EAAE,CAAC,CAAC;gBAC1D,CAAC;gBACD,OAAO;YACT,CAAC;YAED,IAAI,CAAC,GAAG,EAAE,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,CAAC,CAAC;QAC/C,CAAC,CACF,CAAC;QAEF,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,WAAW,EAAE,GAAG,EAAE;YACjC,MAAM,IAAI,GAAG,MAAM,CAAC,OAAO,EAAE,CAAC;YAC9B,IAAI,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;gBACrC,OAAO,CAAC,EAAE,MAAM,EAAE,GAAG,EAAE,oBAAoB,IAAI,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;YAC5D,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
[
|
|
2
|
+
{ "rfc": "AAA080808HL8", "nombre": "ASESORES EN AVALÚOS Y ACTIVOS, S.A. DE C.V.", "situacion": "sentencia_favorable", "oficio": "500-05-2018-16632" },
|
|
3
|
+
{ "rfc": "AAA091014835", "nombre": "AQUAERIS ACUACULTURA Y ARQUITECTURA SUSTENTABLE, S.C.", "situacion": "desvirtuado", "oficio": "500-05-2016-38728" },
|
|
4
|
+
{ "rfc": "AAA100303L51", "nombre": "INGENIOS SANTOS, S.A. DE C.V.", "situacion": "desvirtuado", "oficio": "500-05-2017-38736" },
|
|
5
|
+
{ "rfc": "AAA120730823", "nombre": "ASESORES Y ADMINISTRADORES AGRICOLAS, S. DE R.L. DE C.V.", "situacion": "definitivo", "oficio": "500-05-2016-38728" },
|
|
6
|
+
{ "rfc": "AAC120810NCA", "nombre": "AAA ASESORIA Y CAPACITACION EMPRESARIAL, S.C.", "situacion": "definitivo", "oficio": "500-05-2018-29883" },
|
|
7
|
+
{ "rfc": "AAC1805044A8", "nombre": "ASESORES ACOST, S.C.", "situacion": "presunto", "oficio": "500-05-00-00-00-2026-21664" }
|
|
8
|
+
]
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SAT 69-B (EFOS) lookup — contribuyentes con operaciones presuntamente
|
|
3
|
+
* inexistentes. Public, no auth. The full list is refreshed from the SAT open
|
|
4
|
+
* data (or a mirror); a small fixture is bundled so the tool works out of the
|
|
5
|
+
* box for testing.
|
|
6
|
+
*
|
|
7
|
+
* Correctness-critical: a false "not on the list" is dangerous. Normalize the
|
|
8
|
+
* RFC (uppercase, no whitespace) before lookup.
|
|
9
|
+
*/
|
|
10
|
+
export type EfosSituacion = "presunto" | "definitivo" | "desvirtuado" | "sentencia_favorable";
|
|
11
|
+
export interface EfosEntry {
|
|
12
|
+
rfc: string;
|
|
13
|
+
nombre: string;
|
|
14
|
+
situacion: EfosSituacion;
|
|
15
|
+
/** Oficio de notificación (SAT), si se conoce. */
|
|
16
|
+
oficio?: string;
|
|
17
|
+
/** Fecha de publicación (ISO YYYY-MM-DD), si se conoce. */
|
|
18
|
+
fechaPublicacion?: string;
|
|
19
|
+
}
|
|
20
|
+
export declare function normalizeRfc(rfc: string): string;
|
|
21
|
+
export declare class EfosLookup {
|
|
22
|
+
private readonly byRfc;
|
|
23
|
+
constructor(entries: EfosEntry[]);
|
|
24
|
+
check(rfc: string): EfosEntry | null;
|
|
25
|
+
get size(): number;
|
|
26
|
+
/** Build an EfosLookup from raw JSON (array of EfosEntry). */
|
|
27
|
+
static fromJson(json: unknown): EfosLookup;
|
|
28
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SAT 69-B (EFOS) lookup — contribuyentes con operaciones presuntamente
|
|
3
|
+
* inexistentes. Public, no auth. The full list is refreshed from the SAT open
|
|
4
|
+
* data (or a mirror); a small fixture is bundled so the tool works out of the
|
|
5
|
+
* box for testing.
|
|
6
|
+
*
|
|
7
|
+
* Correctness-critical: a false "not on the list" is dangerous. Normalize the
|
|
8
|
+
* RFC (uppercase, no whitespace) before lookup.
|
|
9
|
+
*/
|
|
10
|
+
export function normalizeRfc(rfc) {
|
|
11
|
+
return rfc.trim().toUpperCase();
|
|
12
|
+
}
|
|
13
|
+
export class EfosLookup {
|
|
14
|
+
byRfc;
|
|
15
|
+
constructor(entries) {
|
|
16
|
+
this.byRfc = new Map(entries.map((e) => [normalizeRfc(e.rfc), e]));
|
|
17
|
+
}
|
|
18
|
+
check(rfc) {
|
|
19
|
+
return this.byRfc.get(normalizeRfc(rfc)) ?? null;
|
|
20
|
+
}
|
|
21
|
+
get size() {
|
|
22
|
+
return this.byRfc.size;
|
|
23
|
+
}
|
|
24
|
+
/** Build an EfosLookup from raw JSON (array of EfosEntry). */
|
|
25
|
+
static fromJson(json) {
|
|
26
|
+
if (!Array.isArray(json)) {
|
|
27
|
+
throw new Error("EFOS data must be an array");
|
|
28
|
+
}
|
|
29
|
+
const entries = json.map((e) => {
|
|
30
|
+
const item = e;
|
|
31
|
+
if (typeof item.rfc !== "string" || typeof item.situacion !== "string") {
|
|
32
|
+
throw new Error("EFOS entry missing rfc/situacion");
|
|
33
|
+
}
|
|
34
|
+
return {
|
|
35
|
+
rfc: item.rfc,
|
|
36
|
+
nombre: item.nombre ?? "",
|
|
37
|
+
situacion: item.situacion,
|
|
38
|
+
oficio: item.oficio,
|
|
39
|
+
fechaPublicacion: item.fechaPublicacion,
|
|
40
|
+
};
|
|
41
|
+
});
|
|
42
|
+
return new EfosLookup(entries);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=efos.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"efos.js","sourceRoot":"","sources":["../../src/public/efos.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAkBH,MAAM,UAAU,YAAY,CAAC,GAAW;IACtC,OAAO,GAAG,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;AAClC,CAAC;AAED,MAAM,OAAO,UAAU;IACJ,KAAK,CAAyB;IAE/C,YAAY,OAAoB;QAC9B,IAAI,CAAC,KAAK,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;IACrE,CAAC;IAED,KAAK,CAAC,GAAW;QACf,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,IAAI,IAAI,CAAC;IACnD,CAAC;IAED,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;IACzB,CAAC;IAED,8DAA8D;IAC9D,MAAM,CAAC,QAAQ,CAAC,IAAa;QAC3B,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;YACzB,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;QAChD,CAAC;QACD,MAAM,OAAO,GAAgB,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;YAC1C,MAAM,IAAI,GAAG,CAAuB,CAAC;YACrC,IAAI,OAAO,IAAI,CAAC,GAAG,KAAK,QAAQ,IAAI,OAAO,IAAI,CAAC,SAAS,KAAK,QAAQ,EAAE,CAAC;gBACvE,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAC;YACtD,CAAC;YACD,OAAO;gBACL,GAAG,EAAE,IAAI,CAAC,GAAG;gBACb,MAAM,EAAE,IAAI,CAAC,MAAM,IAAI,EAAE;gBACzB,SAAS,EAAE,IAAI,CAAC,SAA0B;gBAC1C,MAAM,EAAE,IAAI,CAAC,MAAM;gBACnB,gBAAgB,EAAE,IAAI,CAAC,gBAAgB;aACxC,CAAC;QACJ,CAAC,CAAC,CAAC;QACH,OAAO,IAAI,UAAU,CAAC,OAAO,CAAC,CAAC;IACjC,CAAC;CACF"}
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
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 function normalizeRfc(rfc) {
|
|
10
|
+
return rfc.trim().toUpperCase();
|
|
11
|
+
}
|
|
12
|
+
export class PublicLookupClient {
|
|
13
|
+
config;
|
|
14
|
+
constructor(config) {
|
|
15
|
+
this.config = config;
|
|
16
|
+
}
|
|
17
|
+
fetch(input, init) {
|
|
18
|
+
const fn = this.config.fetchFn ?? fetch;
|
|
19
|
+
return fn(input, init);
|
|
20
|
+
}
|
|
21
|
+
async get(path, rfc) {
|
|
22
|
+
const idToken = await this.config.getAuthToken();
|
|
23
|
+
if (!idToken) {
|
|
24
|
+
throw new Error("Iniciá sesión primero (fintecia_login) antes de consultar listados del SAT.");
|
|
25
|
+
}
|
|
26
|
+
const res = await this.fetch(`${this.config.baseUrl}${path}?rfc=${encodeURIComponent(rfc)}`, {
|
|
27
|
+
method: "GET",
|
|
28
|
+
headers: { authorization: `Bearer ${idToken}` },
|
|
29
|
+
});
|
|
30
|
+
if (res.status === 429) {
|
|
31
|
+
throw new Error("Rate limit excedido, reintentá en unos segundos.");
|
|
32
|
+
}
|
|
33
|
+
if (!res.ok) {
|
|
34
|
+
throw new Error(`lookup ${path} failed: ${res.status}`);
|
|
35
|
+
}
|
|
36
|
+
return (await res.json());
|
|
37
|
+
}
|
|
38
|
+
async checkEfos(rfc) {
|
|
39
|
+
return this.get("/api/v1/public/efos", normalizeRfc(rfc));
|
|
40
|
+
}
|
|
41
|
+
async checkDebts(rfc) {
|
|
42
|
+
return this.get("/api/v1/public/debts", normalizeRfc(rfc));
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=lookup.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lookup.js","sourceRoot":"","sources":["../../src/public/lookup.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,MAAM,UAAU,YAAY,CAAC,GAAW;IACtC,OAAO,GAAG,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;AAClC,CAAC;AAgBD,MAAM,OAAO,kBAAkB;IACA;IAA7B,YAA6B,MAAgC;QAAhC,WAAM,GAAN,MAAM,CAA0B;IAAG,CAAC;IAEzD,KAAK,CAAC,KAAa,EAAE,IAAkB;QAC7C,MAAM,EAAE,GAAG,IAAI,CAAC,MAAM,CAAC,OAAO,IAAI,KAAK,CAAC;QACxC,OAAO,EAAE,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IACzB,CAAC;IAEO,KAAK,CAAC,GAAG,CACf,IAAY,EACZ,GAAW;QAEX,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE,CAAC;QACjD,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,MAAM,IAAI,KAAK,CACb,6EAA6E,CAC9E,CAAC;QACJ,CAAC;QACD,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,KAAK,CAC1B,GAAG,IAAI,CAAC,MAAM,CAAC,OAAO,GAAG,IAAI,QAAQ,kBAAkB,CAAC,GAAG,CAAC,EAAE,EAC9D;YACE,MAAM,EAAE,KAAK;YACb,OAAO,EAAE,EAAE,aAAa,EAAE,UAAU,OAAO,EAAE,EAAE;SAChD,CACF,CAAC;QACF,IAAI,GAAG,CAAC,MAAM,KAAK,GAAG,EAAE,CAAC;YACvB,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC,CAAC;QACtE,CAAC;QACD,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC;YACZ,MAAM,IAAI,KAAK,CAAC,UAAU,IAAI,YAAY,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC;QAC1D,CAAC;QACD,OAAO,CAAC,MAAM,GAAG,CAAC,IAAI,EAAE,CAAmD,CAAC;IAC9E,CAAC;IAED,KAAK,CAAC,SAAS,CAAC,GAAW;QACzB,OAAO,IAAI,CAAC,GAAG,CAAC,qBAAqB,EAAE,YAAY,CAAC,GAAG,CAAC,CAAC,CAAC;IAC5D,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,GAAW;QAC1B,OAAO,IAAI,CAAC,GAAG,CAAC,sBAAsB,EAAE,YAAY,CAAC,GAAG,CAAC,CAAC,CAAC;IAC7D,CAAC;CACF"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SAT ConsultaCFDIService — verifies a CFDI's status (vigente/cancelado/no
|
|
3
|
+
* encontrado) plus whether the emitter is on the 69-B/EFOS list
|
|
4
|
+
* (ValidacionEFOS). Public SOAP service, no auth, no FIEL.
|
|
5
|
+
*
|
|
6
|
+
* The QR on a CFDI encodes the 4 fields (emisor RFC, receptor RFC, total,
|
|
7
|
+
* UUID) as `?re=..&rr=..&tt=..&id=..` — the "expresión impresa".
|
|
8
|
+
*/
|
|
9
|
+
export interface ConsultaInput {
|
|
10
|
+
uuid?: string;
|
|
11
|
+
emisorRfc?: string;
|
|
12
|
+
receptorRfc?: string;
|
|
13
|
+
total?: number;
|
|
14
|
+
xmlBase64?: string;
|
|
15
|
+
}
|
|
16
|
+
export interface ConsultaResult {
|
|
17
|
+
estado: string;
|
|
18
|
+
codigoEstatus: string;
|
|
19
|
+
esCancelable?: string;
|
|
20
|
+
estatusCancelacion?: string;
|
|
21
|
+
validacionEfos?: string;
|
|
22
|
+
}
|
|
23
|
+
/** Build the QR "expresión impresa" from the 4 fields. */
|
|
24
|
+
export declare function buildExpresionImpresa(i: {
|
|
25
|
+
emisorRfc: string;
|
|
26
|
+
receptorRfc: string;
|
|
27
|
+
total: number;
|
|
28
|
+
uuid: string;
|
|
29
|
+
}): string;
|
|
30
|
+
export declare function buildConsultaEnvelope(expresionImpresa: string): string;
|
|
31
|
+
/** Parse the SOAP response into a ConsultaResult (pure, testable). */
|
|
32
|
+
export declare function parseConsultaResponse(xml: string): ConsultaResult;
|
|
33
|
+
export declare class VerificationClient {
|
|
34
|
+
private readonly fetchFn;
|
|
35
|
+
constructor(fetchFn?: typeof fetch);
|
|
36
|
+
consulta(expresionImpresa: string): Promise<ConsultaResult>;
|
|
37
|
+
}
|