@albertomarturelo/sii-core 0.3.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/CHANGELOG.md +114 -0
- package/LICENSE +21 -0
- package/README.md +108 -0
- package/dist/adapters/fake/index.d.ts +98 -0
- package/dist/adapters/fake/index.d.ts.map +1 -0
- package/dist/adapters/fake/index.js +131 -0
- package/dist/adapters/fake/index.js.map +1 -0
- package/dist/adapters/node/index.d.ts +22 -0
- package/dist/adapters/node/index.d.ts.map +1 -0
- package/dist/adapters/node/index.js +65 -0
- package/dist/adapters/node/index.js.map +1 -0
- package/dist/adapters/node/portal.d.ts +8 -0
- package/dist/adapters/node/portal.d.ts.map +1 -0
- package/dist/adapters/node/portal.js +222 -0
- package/dist/adapters/node/portal.js.map +1 -0
- package/dist/adapters/node/response.d.ts +21 -0
- package/dist/adapters/node/response.d.ts.map +1 -0
- package/dist/adapters/node/response.js +48 -0
- package/dist/adapters/node/response.js.map +1 -0
- package/dist/audit/audit.d.ts +8 -0
- package/dist/audit/audit.d.ts.map +1 -0
- package/dist/audit/audit.js +15 -0
- package/dist/audit/audit.js.map +1 -0
- package/dist/audit/index.d.ts +2 -0
- package/dist/audit/index.d.ts.map +1 -0
- package/dist/audit/index.js +2 -0
- package/dist/audit/index.js.map +1 -0
- package/dist/auth/auth.d.ts +43 -0
- package/dist/auth/auth.d.ts.map +1 -0
- package/dist/auth/auth.js +219 -0
- package/dist/auth/auth.js.map +1 -0
- package/dist/auth/index.d.ts +3 -0
- package/dist/auth/index.d.ts.map +1 -0
- package/dist/auth/index.js +3 -0
- package/dist/auth/index.js.map +1 -0
- package/dist/auth/login-error.d.ts +8 -0
- package/dist/auth/login-error.d.ts.map +1 -0
- package/dist/auth/login-error.js +18 -0
- package/dist/auth/login-error.js.map +1 -0
- package/dist/auth/session.d.ts +31 -0
- package/dist/auth/session.d.ts.map +1 -0
- package/dist/auth/session.js +52 -0
- package/dist/auth/session.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +6 -0
- package/dist/cli.js.map +1 -0
- package/dist/config/config.d.ts +38 -0
- package/dist/config/config.d.ts.map +1 -0
- package/dist/config/config.js +40 -0
- package/dist/config/config.js.map +1 -0
- package/dist/config/index.d.ts +2 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +2 -0
- package/dist/config/index.js.map +1 -0
- package/dist/errors/errors.d.ts +56 -0
- package/dist/errors/errors.d.ts.map +1 -0
- package/dist/errors/errors.js +62 -0
- package/dist/errors/errors.js.map +1 -0
- package/dist/errors/index.d.ts +2 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/errors/index.js +2 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/format/format.d.ts +5 -0
- package/dist/format/format.d.ts.map +1 -0
- package/dist/format/format.js +14 -0
- package/dist/format/format.js.map +1 -0
- package/dist/format/index.d.ts +2 -0
- package/dist/format/index.d.ts.map +1 -0
- package/dist/format/index.js +2 -0
- package/dist/format/index.js.map +1 -0
- package/dist/identity/identity.d.ts +56 -0
- package/dist/identity/identity.d.ts.map +1 -0
- package/dist/identity/identity.js +93 -0
- package/dist/identity/identity.js.map +1 -0
- package/dist/identity/index.d.ts +2 -0
- package/dist/identity/index.d.ts.map +1 -0
- package/dist/identity/index.js +2 -0
- package/dist/identity/index.js.map +1 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +24 -0
- package/dist/index.js.map +1 -0
- package/dist/node.d.ts +9 -0
- package/dist/node.d.ts.map +1 -0
- package/dist/node.js +22 -0
- package/dist/node.js.map +1 -0
- package/dist/periodo/anio.d.ts +15 -0
- package/dist/periodo/anio.d.ts.map +1 -0
- package/dist/periodo/anio.js +42 -0
- package/dist/periodo/anio.js.map +1 -0
- package/dist/periodo/index.d.ts +3 -0
- package/dist/periodo/index.d.ts.map +1 -0
- package/dist/periodo/index.js +3 -0
- package/dist/periodo/index.js.map +1 -0
- package/dist/periodo/periodo.d.ts +19 -0
- package/dist/periodo/periodo.d.ts.map +1 -0
- package/dist/periodo/periodo.js +55 -0
- package/dist/periodo/periodo.js.map +1 -0
- package/dist/portal/bte-comunas.d.ts +9 -0
- package/dist/portal/bte-comunas.d.ts.map +1 -0
- package/dist/portal/bte-comunas.js +400 -0
- package/dist/portal/bte-comunas.js.map +1 -0
- package/dist/portal/bte-emit.d.ts +70 -0
- package/dist/portal/bte-emit.d.ts.map +1 -0
- package/dist/portal/bte-emit.js +266 -0
- package/dist/portal/bte-emit.js.map +1 -0
- package/dist/portal/bte.d.ts +55 -0
- package/dist/portal/bte.d.ts.map +1 -0
- package/dist/portal/bte.js +215 -0
- package/dist/portal/bte.js.map +1 -0
- package/dist/portal/dte-public.d.ts +36 -0
- package/dist/portal/dte-public.d.ts.map +1 -0
- package/dist/portal/dte-public.js +192 -0
- package/dist/portal/dte-public.js.map +1 -0
- package/dist/portal/f22/declaraciones.d.ts +37 -0
- package/dist/portal/f22/declaraciones.d.ts.map +1 -0
- package/dist/portal/f22/declaraciones.js +86 -0
- package/dist/portal/f22/declaraciones.js.map +1 -0
- package/dist/portal/f22/grid.d.ts +14 -0
- package/dist/portal/f22/grid.d.ts.map +1 -0
- package/dist/portal/f22/grid.js +51 -0
- package/dist/portal/f22/grid.js.map +1 -0
- package/dist/portal/f22/historial.d.ts +34 -0
- package/dist/portal/f22/historial.d.ts.map +1 -0
- package/dist/portal/f22/historial.js +66 -0
- package/dist/portal/f22/historial.js.map +1 -0
- package/dist/portal/f22/index.d.ts +7 -0
- package/dist/portal/f22/index.d.ts.map +1 -0
- package/dist/portal/f22/index.js +11 -0
- package/dist/portal/f22/index.js.map +1 -0
- package/dist/portal/f22/observaciones.d.ts +20 -0
- package/dist/portal/f22/observaciones.d.ts.map +1 -0
- package/dist/portal/f22/observaciones.js +38 -0
- package/dist/portal/f22/observaciones.js.map +1 -0
- package/dist/portal/f22/shared.d.ts +32 -0
- package/dist/portal/f22/shared.d.ts.map +1 -0
- package/dist/portal/f22/shared.js +130 -0
- package/dist/portal/f22/shared.js.map +1 -0
- package/dist/portal/f22-codigos.d.ts +28 -0
- package/dist/portal/f22-codigos.d.ts.map +1 -0
- package/dist/portal/f22-codigos.js +141 -0
- package/dist/portal/f22-codigos.js.map +1 -0
- package/dist/portal/f29-codigos.d.ts +15 -0
- package/dist/portal/f29-codigos.d.ts.map +1 -0
- package/dist/portal/f29-codigos.js +552 -0
- package/dist/portal/f29-codigos.js.map +1 -0
- package/dist/portal/f29.d.ts +62 -0
- package/dist/portal/f29.d.ts.map +1 -0
- package/dist/portal/f29.js +244 -0
- package/dist/portal/f29.js.map +1 -0
- package/dist/portal/rcv.d.ts +62 -0
- package/dist/portal/rcv.d.ts.map +1 -0
- package/dist/portal/rcv.js +252 -0
- package/dist/portal/rcv.js.map +1 -0
- package/dist/portal/representacion.d.ts +24 -0
- package/dist/portal/representacion.d.ts.map +1 -0
- package/dist/portal/representacion.js +153 -0
- package/dist/portal/representacion.js.map +1 -0
- package/dist/rut/index.d.ts +2 -0
- package/dist/rut/index.d.ts.map +1 -0
- package/dist/rut/index.js +2 -0
- package/dist/rut/index.js.map +1 -0
- package/dist/rut/rut.d.ts +16 -0
- package/dist/rut/rut.d.ts.map +1 -0
- package/dist/rut/rut.js +70 -0
- package/dist/rut/rut.js.map +1 -0
- package/dist/seams/index.d.ts +126 -0
- package/dist/seams/index.d.ts.map +1 -0
- package/dist/seams/index.js +6 -0
- package/dist/seams/index.js.map +1 -0
- package/dist/tasks/auth.d.ts +16 -0
- package/dist/tasks/auth.d.ts.map +1 -0
- package/dist/tasks/auth.js +22 -0
- package/dist/tasks/auth.js.map +1 -0
- package/dist/tasks/bte.d.ts +52 -0
- package/dist/tasks/bte.d.ts.map +1 -0
- package/dist/tasks/bte.js +169 -0
- package/dist/tasks/bte.js.map +1 -0
- package/dist/tasks/dte.d.ts +9 -0
- package/dist/tasks/dte.d.ts.map +1 -0
- package/dist/tasks/dte.js +30 -0
- package/dist/tasks/dte.js.map +1 -0
- package/dist/tasks/f22.d.ts +69 -0
- package/dist/tasks/f22.d.ts.map +1 -0
- package/dist/tasks/f22.js +189 -0
- package/dist/tasks/f22.js.map +1 -0
- package/dist/tasks/f29.d.ts +67 -0
- package/dist/tasks/f29.d.ts.map +1 -0
- package/dist/tasks/f29.js +213 -0
- package/dist/tasks/f29.js.map +1 -0
- package/dist/tasks/operate.d.ts +22 -0
- package/dist/tasks/operate.d.ts.map +1 -0
- package/dist/tasks/operate.js +34 -0
- package/dist/tasks/operate.js.map +1 -0
- package/dist/tasks/rcv.d.ts +17 -0
- package/dist/tasks/rcv.d.ts.map +1 -0
- package/dist/tasks/rcv.js +76 -0
- package/dist/tasks/rcv.js.map +1 -0
- package/package.json +54 -0
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
// Public BTE/BHE task API the surfaces call (ADR-003). Boletas de Honorarios Electrónicas,
|
|
2
|
+
// read-only. `bteList(periodo, side)` returns one month's boletas (emitidas or recibidas).
|
|
3
|
+
//
|
|
4
|
+
// SESSION-KEYED (ADR-005, confirmed live #62): the BHE CGIs authorize by the session PRINCIPAL
|
|
5
|
+
// (`rut_arrastre` does NOT reach a represented empresa), so this reads ONLY self and REJECTS a
|
|
6
|
+
// representing operate pointer UP FRONT with an actionable "log in as the empresa" message —
|
|
7
|
+
// it ignores the pointer and takes NO `--rut`. The período is validated locally BEFORE any
|
|
8
|
+
// session. Pagination is paced via `Clock.sleep` (ADR-004); the facade reads inline JS maps via
|
|
9
|
+
// `PortalSession.goto`/`evaluate` (not the SDI-JSON path).
|
|
10
|
+
import { withSession } from '../auth/index.js';
|
|
11
|
+
import { recordAudit } from '../audit/index.js';
|
|
12
|
+
import { readOperateState } from '../identity/index.js';
|
|
13
|
+
import { Periodo } from '../periodo/index.js';
|
|
14
|
+
import { Rut } from '../rut/index.js';
|
|
15
|
+
import { BteError, ValidationError } from '../errors/index.js';
|
|
16
|
+
import { DEFAULT_SETTINGS } from '../config/index.js';
|
|
17
|
+
import { fetchBteMensual } from '../portal/bte.js';
|
|
18
|
+
import { assertRegionComuna, emitBteEmision, enviarBteEmision, previewBteEmision, } from '../portal/bte-emit.js';
|
|
19
|
+
/** Inter-page pace (ms) for the monthly pagination fan-out — never hammer SII (ADR-004). */
|
|
20
|
+
const pacingMs = () => Math.round(1000 / DEFAULT_SETTINGS.rateLimitRps);
|
|
21
|
+
function audit(runtime, action, result, extra) {
|
|
22
|
+
recordAudit(runtime, { action, result, ...extra });
|
|
23
|
+
}
|
|
24
|
+
/** Reject a representing operate pointer BEFORE opening a session (ADR-005, session-keyed). The
|
|
25
|
+
* empresa RUT is already user-visible (`operate --list`), so it is safe to echo; the razón social
|
|
26
|
+
* is PII and is NOT included. No operate state → defer to `withSession` (raises NotAuthenticated). */
|
|
27
|
+
async function assertSelfOperating(runtime) {
|
|
28
|
+
const op = await readOperateState(runtime.store);
|
|
29
|
+
if (op && op.operatingRut !== op.selfRut) {
|
|
30
|
+
throw new BteError(`Las boletas de honorarios son session-keyed: el SII autoriza por el titular de la sesión, ` +
|
|
31
|
+
`no por el RUT operado (${Rut.parse(op.operatingRut).formatted}). Para las BHE de esa empresa, ` +
|
|
32
|
+
'inicia sesión como ella (`sii auth logout` y luego `sii auth login`).');
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
/** One month's boletas de honorarios for the session principal (ADR-005), emitidas or recibidas.
|
|
36
|
+
* An empty month is a clean 0-boleta result, not an error. */
|
|
37
|
+
export async function bteList(runtime, args) {
|
|
38
|
+
const periodo = Periodo.parse(args.periodo); // fail fast on a bad período — no session opened
|
|
39
|
+
await assertSelfOperating(runtime);
|
|
40
|
+
const start = runtime.clock.now().getTime();
|
|
41
|
+
try {
|
|
42
|
+
const res = await withSession(runtime, async (session, ctx) => fetchBteMensual(session, { rut: Rut.parse(ctx.sessionRut), periodo, side: args.side }, // session-keyed: the principal
|
|
43
|
+
() => runtime.clock.sleep(pacingMs())));
|
|
44
|
+
audit(runtime, 'bte_list', 'ok', {
|
|
45
|
+
rut: res.rut,
|
|
46
|
+
period: periodo.canonical,
|
|
47
|
+
side: args.side,
|
|
48
|
+
durationMs: runtime.clock.now().getTime() - start,
|
|
49
|
+
});
|
|
50
|
+
return res;
|
|
51
|
+
}
|
|
52
|
+
catch (e) {
|
|
53
|
+
audit(runtime, 'bte_list', 'failed', { period: periodo.canonical, side: args.side });
|
|
54
|
+
throw e;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
const MAX_LINEAS = 4;
|
|
58
|
+
/** Validate + normalize the emit args into a `BteEmisionInput` (parsed RUT, checked montos,
|
|
59
|
+
* region/comuna, fecha within ±3 months). Throws before any SII call. */
|
|
60
|
+
function validateEmit(runtime, args) {
|
|
61
|
+
const receptor = Rut.parse(args.receptor); // Mod-11 — a malformed RUT never reaches SII
|
|
62
|
+
if (args.receptorNombre.trim() === '')
|
|
63
|
+
throw new ValidationError('Falta el nombre del receptor.');
|
|
64
|
+
if (args.receptorDomicilio.trim() === '')
|
|
65
|
+
throw new ValidationError('Falta el domicilio del receptor.');
|
|
66
|
+
if (args.lineas.length < 1 || args.lineas.length > MAX_LINEAS) {
|
|
67
|
+
throw new ValidationError(`Indica entre 1 y ${MAX_LINEAS} líneas de honorarios.`);
|
|
68
|
+
}
|
|
69
|
+
const lineas = args.lineas.map((l, i) => {
|
|
70
|
+
if (l.glosa.trim() === '')
|
|
71
|
+
throw new ValidationError(`Falta la glosa de la línea ${i + 1}.`);
|
|
72
|
+
if (!Number.isInteger(l.monto) || l.monto <= 0) {
|
|
73
|
+
throw new ValidationError(`Monto inválido en la línea ${i + 1}: ${l.monto} (entero positivo, en pesos).`);
|
|
74
|
+
}
|
|
75
|
+
return { glosa: l.glosa.trim(), monto: l.monto };
|
|
76
|
+
});
|
|
77
|
+
assertRegionComuna(args.region, args.comuna);
|
|
78
|
+
const fecha = resolveFecha(runtime, args.fecha);
|
|
79
|
+
return {
|
|
80
|
+
receptor,
|
|
81
|
+
receptorNombre: args.receptorNombre.trim(),
|
|
82
|
+
receptorDomicilio: args.receptorDomicilio.trim(),
|
|
83
|
+
region: args.region,
|
|
84
|
+
comuna: args.comuna,
|
|
85
|
+
lineas,
|
|
86
|
+
fecha,
|
|
87
|
+
retiene: args.retiene,
|
|
88
|
+
...(args.mostrarDetalle !== undefined ? { mostrarDetalle: args.mostrarDetalle } : {}),
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
/** Default the boleta date to today; enforce the SII ±3-month window (via the Clock seam). */
|
|
92
|
+
function resolveFecha(runtime, fecha) {
|
|
93
|
+
const now = runtime.clock.now();
|
|
94
|
+
const f = fecha ?? { dia: now.getDate(), mes: now.getMonth() + 1, anio: now.getFullYear() };
|
|
95
|
+
const target = new Date(f.anio, f.mes - 1, f.dia);
|
|
96
|
+
if (Number.isNaN(target.getTime()) ||
|
|
97
|
+
target.getMonth() !== f.mes - 1 ||
|
|
98
|
+
target.getDate() !== f.dia) {
|
|
99
|
+
throw new ValidationError(`Fecha de boleta inválida: ${f.anio}-${f.mes}-${f.dia}.`);
|
|
100
|
+
}
|
|
101
|
+
const min = new Date(now.getTime());
|
|
102
|
+
min.setMonth(min.getMonth() - 3);
|
|
103
|
+
const max = new Date(now.getTime());
|
|
104
|
+
max.setMonth(max.getMonth() + 3);
|
|
105
|
+
if (target < min || target > max) {
|
|
106
|
+
throw new ValidationError('La fecha de la boleta debe estar dentro de ±3 meses respecto de hoy (regla del SII).');
|
|
107
|
+
}
|
|
108
|
+
return f;
|
|
109
|
+
}
|
|
110
|
+
/** PREVIEW an emission (ADR-017): run the SII flow to the confirmation step and return the
|
|
111
|
+
* server-computed retención/líquido WITHOUT issuing. Session-keyed (rejects a representing
|
|
112
|
+
* pointer). Never issues; safe to call freely. */
|
|
113
|
+
export async function bteEmitPreview(runtime, args) {
|
|
114
|
+
const input = validateEmit(runtime, args); // fail fast — no session on bad input
|
|
115
|
+
await assertSelfOperating(runtime);
|
|
116
|
+
const start = runtime.clock.now().getTime();
|
|
117
|
+
let emisorRut;
|
|
118
|
+
try {
|
|
119
|
+
const preview = await withSession(runtime, async (session, ctx) => {
|
|
120
|
+
emisorRut = Rut.parse(ctx.sessionRut).canonical; // the emisor = self (safe to audit)
|
|
121
|
+
return previewBteEmision(session, Rut.parse(ctx.sessionRut), input);
|
|
122
|
+
});
|
|
123
|
+
// Receipt carries only the emisor RUT (self) — never the receptor / monto / glosa.
|
|
124
|
+
audit(runtime, 'bte_emit_preview', 'ok', {
|
|
125
|
+
...(emisorRut ? { rut: emisorRut } : {}),
|
|
126
|
+
durationMs: runtime.clock.now().getTime() - start,
|
|
127
|
+
});
|
|
128
|
+
return preview;
|
|
129
|
+
}
|
|
130
|
+
catch (e) {
|
|
131
|
+
audit(runtime, 'bte_emit_preview', 'failed', {});
|
|
132
|
+
throw e;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
/** ISSUE a boleta de honorarios (ADR-017) — a legally-binding act. Runs the full SII flow and
|
|
136
|
+
* returns the folio (código de barras) + PDF URL. Session-keyed. NEVER retries. The caller
|
|
137
|
+
* (CLI `--confirm`, MCP `confirmar`) is responsible for the explicit confirmation; this task
|
|
138
|
+
* assumes the confirmation was given. Optional email send. The audit receipt carries the folio
|
|
139
|
+
* but NEVER the receptor / monto / glosa (PII / business data). */
|
|
140
|
+
export async function bteEmit(runtime, args) {
|
|
141
|
+
const input = validateEmit(runtime, args);
|
|
142
|
+
await assertSelfOperating(runtime);
|
|
143
|
+
const start = runtime.clock.now().getTime();
|
|
144
|
+
try {
|
|
145
|
+
const result = await withSession(runtime, async (session, ctx) => {
|
|
146
|
+
const self = Rut.parse(ctx.sessionRut);
|
|
147
|
+
const emitida = await emitBteEmision(session, self, input);
|
|
148
|
+
if (args.enviarA !== undefined && args.enviarA.trim() !== '') {
|
|
149
|
+
const { enviado } = await enviarBteEmision(session, {
|
|
150
|
+
codBarras: emitida.codBarras,
|
|
151
|
+
email: args.enviarA.trim(),
|
|
152
|
+
...(args.copiaEmisor !== undefined ? { copiaEmisor: args.copiaEmisor } : {}),
|
|
153
|
+
});
|
|
154
|
+
return { ...emitida, enviado };
|
|
155
|
+
}
|
|
156
|
+
return emitida;
|
|
157
|
+
});
|
|
158
|
+
audit(runtime, 'bte_emit', 'ok', {
|
|
159
|
+
folio: result.codBarras, // the emisor's own boleta id (no counterparty PII)
|
|
160
|
+
durationMs: runtime.clock.now().getTime() - start,
|
|
161
|
+
});
|
|
162
|
+
return result;
|
|
163
|
+
}
|
|
164
|
+
catch (e) {
|
|
165
|
+
audit(runtime, 'bte_emit', 'failed', {});
|
|
166
|
+
throw e;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
//# sourceMappingURL=bte.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bte.js","sourceRoot":"","sources":["../../src/tasks/bte.ts"],"names":[],"mappings":"AAAA,2FAA2F;AAC3F,2FAA2F;AAC3F,EAAE;AACF,+FAA+F;AAC/F,+FAA+F;AAC/F,6FAA6F;AAC7F,2FAA2F;AAC3F,gGAAgG;AAChG,2DAA2D;AAC3D,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9C,OAAO,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AACtC,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAC/D,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAEnD,OAAO,EACL,kBAAkB,EAClB,cAAc,EACd,gBAAgB,EAChB,iBAAiB,GAClB,MAAM,uBAAuB,CAAC;AAa/B,4FAA4F;AAC5F,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,CAAC;QACX,KAAK,CAAC,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,EAAE,CAAC,CAAC;QACzC,MAAM,CAAC,CAAC;IACV,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { DteAutorizados } from '../portal/dte-public.js';
|
|
2
|
+
import type { Runtime } from '../seams/index.js';
|
|
3
|
+
export type { DteAutorizados, DteAutorizado } from '../portal/dte-public.js';
|
|
4
|
+
interface DteAuthorizedArgs {
|
|
5
|
+
/** RUT to query (e.g. "12345670-K") — any RUT; public consulta. Mod-11-validated. */
|
|
6
|
+
readonly rut: string;
|
|
7
|
+
}
|
|
8
|
+
export declare function dteAuthorized(runtime: Runtime, args: DteAuthorizedArgs): Promise<DteAutorizados>;
|
|
9
|
+
//# sourceMappingURL=dte.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dte.d.ts","sourceRoot":"","sources":["../../src/tasks/dte.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAC9D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAEjD,YAAY,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAE7E,UAAU,iBAAiB;IACzB,qFAAqF;IACrF,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;CACtB;AAED,wBAAsB,aAAa,CACjC,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,iBAAiB,GACtB,OAAO,CAAC,cAAc,CAAC,CAmBzB"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// Public DTE task API the surfaces call (ADR-003). Unlike rcv/f22/f29, `dteAuthorized`
|
|
2
|
+
// is PUBLIC and login-free: it does NOT use `withSession` and works for ANY RUT
|
|
3
|
+
// (counterparties included) without a session — the consulta touches no account, an
|
|
4
|
+
// in-bounds class of access (ADR-004 ToS carve-out / ADR-014). The RUT is Mod-11-validated
|
|
5
|
+
// locally BEFORE any request so a malformed RUT never becomes a wasted call.
|
|
6
|
+
import { recordAudit } from '../audit/index.js';
|
|
7
|
+
import { Rut } from '../rut/index.js';
|
|
8
|
+
import { fetchDteAutorizados } from '../portal/dte-public.js';
|
|
9
|
+
export async function dteAuthorized(runtime, args) {
|
|
10
|
+
const rut = Rut.parse(args.rut); // fail fast on a bad RUT — no request issued
|
|
11
|
+
const start = runtime.clock.now().getTime();
|
|
12
|
+
try {
|
|
13
|
+
const res = await fetchDteAutorizados(runtime.portal, rut);
|
|
14
|
+
// Both authorized and not-authorized are valid outcomes → result "ok". Audit records
|
|
15
|
+
// rut=<subject> with NO rutAuth: there is no authenticated principal (ADR-014).
|
|
16
|
+
recordAudit(runtime, {
|
|
17
|
+
action: 'dte_autorizados',
|
|
18
|
+
result: 'ok',
|
|
19
|
+
rut: res.rut,
|
|
20
|
+
autorizado: res.autorizado,
|
|
21
|
+
durationMs: runtime.clock.now().getTime() - start,
|
|
22
|
+
});
|
|
23
|
+
return res;
|
|
24
|
+
}
|
|
25
|
+
catch (e) {
|
|
26
|
+
recordAudit(runtime, { action: 'dte_autorizados', result: 'failed', rut: rut.canonical });
|
|
27
|
+
throw e;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=dte.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dte.js","sourceRoot":"","sources":["../../src/tasks/dte.ts"],"names":[],"mappings":"AAAA,uFAAuF;AACvF,gFAAgF;AAChF,oFAAoF;AACpF,2FAA2F;AAC3F,6EAA6E;AAC7E,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AACtC,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAW9D,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,OAAgB,EAChB,IAAuB;IAEvB,MAAM,GAAG,GAAG,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,6CAA6C;IAC9E,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,OAAO,EAAE,CAAC;IAC5C,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,MAAM,mBAAmB,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QAC3D,qFAAqF;QACrF,gFAAgF;QAChF,WAAW,CAAC,OAAO,EAAE;YACnB,MAAM,EAAE,iBAAiB;YACzB,MAAM,EAAE,IAAI;YACZ,GAAG,EAAE,GAAG,CAAC,GAAG;YACZ,UAAU,EAAE,GAAG,CAAC,UAAU;YAC1B,UAAU,EAAE,OAAO,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,OAAO,EAAE,GAAG,KAAK;SAClD,CAAC,CAAC;QACH,OAAO,GAAG,CAAC;IACb,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,WAAW,CAAC,OAAO,EAAE,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,CAAC,SAAS,EAAE,CAAC,CAAC;QAC1F,MAAM,CAAC,CAAC;IACV,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import type { EventoF22, F22Declaraciones, F22Estado, ObservacionF22 } from '../portal/f22/index.js';
|
|
2
|
+
import type { Runtime } from '../seams/index.js';
|
|
3
|
+
export type { DeclaracionF22, CodigoF22, EventoF22, ObservacionF22, F22Declaraciones, F22Estado, F22Grupos, } from '../portal/f22/index.js';
|
|
4
|
+
/** One year of F22 status overview (estado, no código grid). */
|
|
5
|
+
export interface F22Overview {
|
|
6
|
+
readonly rut: string;
|
|
7
|
+
/** One entry per year, most recent first. */
|
|
8
|
+
readonly anios: readonly F22Declaraciones[];
|
|
9
|
+
}
|
|
10
|
+
/** Full F22 readback for one año: the selected declaración's folio/estado + the curated
|
|
11
|
+
* código grid (identity/bank PII excluded). Session principal (ADR-005). The grid is the
|
|
12
|
+
* same `f22Compacto` either way; with `full` we ALSO attach the contador `grupos` split
|
|
13
|
+
* (ingresos / deducciones / retenciones·PPM·créditos / resultado / otros, #27). Without
|
|
14
|
+
* `full` there is no `grupos` — the default output is unchanged. */
|
|
15
|
+
export declare function f22Status(runtime: Runtime, args: {
|
|
16
|
+
anio: string | number;
|
|
17
|
+
folio?: string;
|
|
18
|
+
full?: boolean;
|
|
19
|
+
}): Promise<F22Estado>;
|
|
20
|
+
/** Multi-year estado overview: the last `years` años (default 5, most recent first),
|
|
21
|
+
* estado only (one `buscaDeclVgte` per year, paced), under ONE session. Session
|
|
22
|
+
* principal (ADR-005). A not-yet-filed / missing year is a clean `tieneDeclaracion:false`. */
|
|
23
|
+
export declare function f22Overview(runtime: Runtime, args?: {
|
|
24
|
+
years?: number;
|
|
25
|
+
}): Promise<F22Overview>;
|
|
26
|
+
/** F22 observaciones (inconsistencias) for one año: resolve the folio (vigente, or
|
|
27
|
+
* `--folio`) via `buscaDeclVgte`, then read its observaciones via `situacionObservacion`
|
|
28
|
+
* (código + glosa + ayuda URL). Session principal (ADR-005), paced; empty/no-declaración
|
|
29
|
+
* is a clean "sin observaciones", NOT an error. */
|
|
30
|
+
export interface F22Observaciones {
|
|
31
|
+
readonly rut: string;
|
|
32
|
+
readonly anio: string;
|
|
33
|
+
readonly tieneDeclaracion: boolean;
|
|
34
|
+
readonly folio: string | null;
|
|
35
|
+
readonly observaciones: readonly ObservacionF22[];
|
|
36
|
+
}
|
|
37
|
+
export declare function f22Observaciones(runtime: Runtime, args: {
|
|
38
|
+
anio: string | number;
|
|
39
|
+
folio?: string;
|
|
40
|
+
}): Promise<F22Observaciones>;
|
|
41
|
+
/** F22 historial (eventos) for one año: the per-declaración event timeline (declaración
|
|
42
|
+
* recibida, devolución autorizada, giros, rectificatorias…). DEFAULT reads EVERY folio of
|
|
43
|
+
* the año (rectificatorias included — "todos sus folios"); `--folio` scopes to one. Events
|
|
44
|
+
* are aggregated across folios and sorted most-recent-first. Session principal (ADR-005),
|
|
45
|
+
* paced; no-declaración / empty is a clean "sin eventos", NOT an error.
|
|
46
|
+
*
|
|
47
|
+
* PER-FOLIO RESILIENCE: SII's `buscaEventos` can fail on ONE folio while others succeed —
|
|
48
|
+
* observed live (AT 2026): the vigente folio returned its events, a superseded folio
|
|
49
|
+
* returned a server-side parse error (`"For input string: …"`). Since the default fans out
|
|
50
|
+
* over every folio, one folio's `F22Error` MUST NOT bury the rest — it is captured verbatim
|
|
51
|
+
* in `foliosConError` (ADR-004: surfaced, never hidden, never retried) while the good folios'
|
|
52
|
+
* events still come back. A session-level failure (NotAuthenticated/SessionExpired) is NOT an
|
|
53
|
+
* F22Error, so it still aborts the whole read. */
|
|
54
|
+
export interface F22Historial {
|
|
55
|
+
readonly rut: string;
|
|
56
|
+
readonly anio: string;
|
|
57
|
+
readonly tieneDeclaracion: boolean;
|
|
58
|
+
readonly folios: readonly string[];
|
|
59
|
+
readonly eventos: readonly EventoF22[];
|
|
60
|
+
readonly foliosConError: readonly {
|
|
61
|
+
folio: string;
|
|
62
|
+
error: string;
|
|
63
|
+
}[];
|
|
64
|
+
}
|
|
65
|
+
export declare function f22Historial(runtime: Runtime, args: {
|
|
66
|
+
anio: string | number;
|
|
67
|
+
folio?: string;
|
|
68
|
+
}): Promise<F22Historial>;
|
|
69
|
+
//# sourceMappingURL=f22.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"f22.d.ts","sourceRoot":"","sources":["../../src/tasks/f22.ts"],"names":[],"mappings":"AAqBA,OAAO,KAAK,EACV,SAAS,EACT,gBAAgB,EAChB,SAAS,EACT,cAAc,EACf,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,EAAc,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAE7D,YAAY,EACV,cAAc,EACd,SAAS,EACT,SAAS,EACT,cAAc,EAC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AE,MAAM,CAAC;IACtB,QAAQ,CAAC,gBAAgB,EAAE,OAAO,CAAC;IACnC,QAAQ,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC;IACnC,QAAQ,CAAC,OAAO,EAAE,SAAS,SAAS,EAAE,CAAC;IACvC,QAAQ,CAAC,cAAc,EAAE,SAAS;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;CACtE;AAED,wBAAsB,YAAY,CAChC,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE;IAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,GAC9C,OAAO,CAAC,YAAY,CAAC,CAiEvB"}
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
// Public F22 task API the surfaces call (ADR-003). Wraps the portal facade in
|
|
2
|
+
// `withSession` and writes one audit receipt. F22 is SESSION-KEYED (ADR-005): it
|
|
3
|
+
// authorizes by the session principal, IGNORES the operate pointer, and takes NO
|
|
4
|
+
// `--rut` — a represented empresa's F22 is reached by being in the empresa's session
|
|
5
|
+
// (logout→login), confirmed live (the body RUT returns a clean negative, not the
|
|
6
|
+
// empresa's F22). The año is validated locally BEFORE any session.
|
|
7
|
+
import { withSession } from '../auth/index.js';
|
|
8
|
+
import { recordAudit } from '../audit/index.js';
|
|
9
|
+
import { Anio } from '../periodo/index.js';
|
|
10
|
+
import { Rut } from '../rut/index.js';
|
|
11
|
+
import { F22Error, ValidationError } from '../errors/index.js';
|
|
12
|
+
import { DEFAULT_SETTINGS } from '../config/index.js';
|
|
13
|
+
import { eventoDateKey, fetchF22Declaraciones, fetchF22Grid, fetchF22Historial, fetchF22Observaciones, groupCodigos, pickVigenteFolio, } from '../portal/f22/index.js';
|
|
14
|
+
const DEFAULT_OVERVIEW_YEARS = 5;
|
|
15
|
+
const MAX_OVERVIEW_YEARS = 10;
|
|
16
|
+
/** Inter-request pace (ms) for multi-POST fan-outs — never hammer SII (ADR-004). */
|
|
17
|
+
const pacingMs = () => Math.round(1000 / DEFAULT_SETTINGS.rateLimitRps);
|
|
18
|
+
function audit(runtime, action, result, extra) {
|
|
19
|
+
recordAudit(runtime, { action, result, ...extra });
|
|
20
|
+
}
|
|
21
|
+
/** Full F22 readback for one año: the selected declaración's folio/estado + the curated
|
|
22
|
+
* código grid (identity/bank PII excluded). Session principal (ADR-005). The grid is the
|
|
23
|
+
* same `f22Compacto` either way; with `full` we ALSO attach the contador `grupos` split
|
|
24
|
+
* (ingresos / deducciones / retenciones·PPM·créditos / resultado / otros, #27). Without
|
|
25
|
+
* `full` there is no `grupos` — the default output is unchanged. */
|
|
26
|
+
export async function f22Status(runtime, args) {
|
|
27
|
+
const anio = Anio.parse(args.anio); // fail fast on a bad year — no session opened
|
|
28
|
+
const start = runtime.clock.now().getTime();
|
|
29
|
+
try {
|
|
30
|
+
const estado = await withSession(runtime, async (session, ctx) => {
|
|
31
|
+
const rut = Rut.parse(ctx.sessionRut); // session-keyed: ALWAYS the principal
|
|
32
|
+
const decls = await fetchF22Declaraciones(session, { rut, anio });
|
|
33
|
+
const folio = args.folio ?? pickVigenteFolio(decls.declaraciones);
|
|
34
|
+
if (folio === null) {
|
|
35
|
+
return { ...decls, folio: null, estado: null, codigos: [] };
|
|
36
|
+
}
|
|
37
|
+
await runtime.clock.sleep(pacingMs()); // pace the 2nd POST
|
|
38
|
+
const codigos = await fetchF22Grid(session, { rut, anio, folio });
|
|
39
|
+
const selected = decls.declaraciones.find((d) => d.folio === folio);
|
|
40
|
+
const base = { ...decls, folio, estado: selected?.estado ?? null, codigos };
|
|
41
|
+
return args.full ? { ...base, grupos: groupCodigos(codigos) } : base;
|
|
42
|
+
});
|
|
43
|
+
audit(runtime, 'f22_estado', 'ok', {
|
|
44
|
+
rut: estado.rut,
|
|
45
|
+
period: anio.canonical,
|
|
46
|
+
durationMs: runtime.clock.now().getTime() - start,
|
|
47
|
+
});
|
|
48
|
+
return estado;
|
|
49
|
+
}
|
|
50
|
+
catch (e) {
|
|
51
|
+
audit(runtime, 'f22_estado', 'failed', { period: anio.canonical });
|
|
52
|
+
throw e;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/** Multi-year estado overview: the last `years` años (default 5, most recent first),
|
|
56
|
+
* estado only (one `buscaDeclVgte` per year, paced), under ONE session. Session
|
|
57
|
+
* principal (ADR-005). A not-yet-filed / missing year is a clean `tieneDeclaracion:false`. */
|
|
58
|
+
export async function f22Overview(runtime, args = {}) {
|
|
59
|
+
const years = Math.min(Math.max(Math.trunc(args.years ?? DEFAULT_OVERVIEW_YEARS), 1), MAX_OVERVIEW_YEARS);
|
|
60
|
+
const currentYear = runtime.clock.now().getFullYear();
|
|
61
|
+
const anios = Array.from({ length: years }, (_, i) => Anio.of(currentYear - i));
|
|
62
|
+
const start = runtime.clock.now().getTime();
|
|
63
|
+
try {
|
|
64
|
+
const result = await withSession(runtime, async (session, ctx) => {
|
|
65
|
+
const rut = Rut.parse(ctx.sessionRut);
|
|
66
|
+
const out = [];
|
|
67
|
+
for (let i = 0; i < anios.length; i++) {
|
|
68
|
+
if (i > 0)
|
|
69
|
+
await runtime.clock.sleep(pacingMs()); // pace between years
|
|
70
|
+
out.push(await fetchF22Declaraciones(session, { rut, anio: anios[i] }));
|
|
71
|
+
}
|
|
72
|
+
return { rut: rut.canonical, anios: out };
|
|
73
|
+
});
|
|
74
|
+
audit(runtime, 'f22_overview', 'ok', {
|
|
75
|
+
rut: result.rut,
|
|
76
|
+
years,
|
|
77
|
+
durationMs: runtime.clock.now().getTime() - start,
|
|
78
|
+
});
|
|
79
|
+
return result;
|
|
80
|
+
}
|
|
81
|
+
catch (e) {
|
|
82
|
+
audit(runtime, 'f22_overview', 'failed', { years });
|
|
83
|
+
throw e;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
export async function f22Observaciones(runtime, args) {
|
|
87
|
+
const anio = Anio.parse(args.anio); // fail fast on a bad year — no session opened
|
|
88
|
+
// `situacionObservacion` posts `folio` as a NUMBER (observed); reject a non-numeric
|
|
89
|
+
// `--folio` here so a malformed value fails fast instead of silently posting
|
|
90
|
+
// `folio:null` (Number("abc")=NaN → JSON null). Validate before opening a session.
|
|
91
|
+
if (args.folio !== undefined && !/^\d+$/.test(args.folio)) {
|
|
92
|
+
throw new ValidationError(`Folio inválido: "${args.folio}" (debe ser numérico).`);
|
|
93
|
+
}
|
|
94
|
+
const start = runtime.clock.now().getTime();
|
|
95
|
+
try {
|
|
96
|
+
const result = await withSession(runtime, async (session, ctx) => {
|
|
97
|
+
const rut = Rut.parse(ctx.sessionRut); // session-keyed: ALWAYS the principal
|
|
98
|
+
const decls = await fetchF22Declaraciones(session, { rut, anio });
|
|
99
|
+
const folio = args.folio ?? pickVigenteFolio(decls.declaraciones);
|
|
100
|
+
const base = {
|
|
101
|
+
rut: rut.canonical,
|
|
102
|
+
anio: anio.canonical,
|
|
103
|
+
tieneDeclaracion: decls.tieneDeclaracion,
|
|
104
|
+
};
|
|
105
|
+
if (folio === null) {
|
|
106
|
+
return { ...base, folio: null, observaciones: [] };
|
|
107
|
+
}
|
|
108
|
+
await runtime.clock.sleep(pacingMs()); // pace the 2nd POST
|
|
109
|
+
const observaciones = await fetchF22Observaciones(session, { rut, anio, folio });
|
|
110
|
+
return { ...base, folio, observaciones };
|
|
111
|
+
});
|
|
112
|
+
audit(runtime, 'f22_observaciones', 'ok', {
|
|
113
|
+
rut: result.rut,
|
|
114
|
+
period: anio.canonical,
|
|
115
|
+
durationMs: runtime.clock.now().getTime() - start,
|
|
116
|
+
});
|
|
117
|
+
return result;
|
|
118
|
+
}
|
|
119
|
+
catch (e) {
|
|
120
|
+
audit(runtime, 'f22_observaciones', 'failed', { period: anio.canonical });
|
|
121
|
+
throw e;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
export async function f22Historial(runtime, args) {
|
|
125
|
+
const anio = Anio.parse(args.anio); // fail fast on a bad year — no session opened
|
|
126
|
+
// `buscaEventos` posts `folio` as a string but SII rejects a non-numeric one; validate a
|
|
127
|
+
// `--folio` override before opening a session (consistent with observaciones).
|
|
128
|
+
if (args.folio !== undefined && !/^\d+$/.test(args.folio)) {
|
|
129
|
+
throw new ValidationError(`Folio inválido: "${args.folio}" (debe ser numérico).`);
|
|
130
|
+
}
|
|
131
|
+
const start = runtime.clock.now().getTime();
|
|
132
|
+
try {
|
|
133
|
+
const result = await withSession(runtime, async (session, ctx) => {
|
|
134
|
+
const rut = Rut.parse(ctx.sessionRut); // session-keyed: ALWAYS the principal
|
|
135
|
+
const decls = await fetchF22Declaraciones(session, { rut, anio });
|
|
136
|
+
// All distinct folios of the año (most carry one; rectificatorias add more), or the
|
|
137
|
+
// single `--folio` override.
|
|
138
|
+
const folios = args.folio !== undefined
|
|
139
|
+
? [args.folio]
|
|
140
|
+
: [
|
|
141
|
+
...new Set(decls.declaraciones.map((d) => d.folio).filter((f) => f !== null)),
|
|
142
|
+
];
|
|
143
|
+
const base = {
|
|
144
|
+
rut: rut.canonical,
|
|
145
|
+
anio: anio.canonical,
|
|
146
|
+
tieneDeclaracion: decls.tieneDeclaracion,
|
|
147
|
+
};
|
|
148
|
+
const eventos = [];
|
|
149
|
+
const foliosConError = [];
|
|
150
|
+
for (const folio of folios) {
|
|
151
|
+
await runtime.clock.sleep(pacingMs()); // pace each buscaEventos POST (ADR-004)
|
|
152
|
+
try {
|
|
153
|
+
eventos.push(...(await fetchF22Historial(session, { rut, anio, folio })));
|
|
154
|
+
}
|
|
155
|
+
catch (e) {
|
|
156
|
+
// A single folio's SII error (F22Error) is recorded verbatim and skipped — it must
|
|
157
|
+
// not bury the other folios' events. A session-level failure is NOT an F22Error and
|
|
158
|
+
// propagates (aborting the whole read, as it should).
|
|
159
|
+
if (e instanceof F22Error) {
|
|
160
|
+
foliosConError.push({ folio, error: e.message });
|
|
161
|
+
continue;
|
|
162
|
+
}
|
|
163
|
+
throw e;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
// Most-recent-first across every folio read. SII serves each folio's events
|
|
167
|
+
// oldest-first (chronological), so within the SAME date the later-collected event is
|
|
168
|
+
// the more recent — tiebreak by wire position DESC. Without it, same-day events (e.g. a
|
|
169
|
+
// rectificatoria's "enviada" then "aceptada", both 28/06) would print envío→aceptación,
|
|
170
|
+
// the reverse of most-recent-first. Decorate-sort-undecorate keeps it deterministic.
|
|
171
|
+
const ordered = eventos
|
|
172
|
+
.map((e, i) => ({ e, i }))
|
|
173
|
+
.sort((a, b) => eventoDateKey(b.e.fecha) - eventoDateKey(a.e.fecha) || b.i - a.i)
|
|
174
|
+
.map((d) => d.e);
|
|
175
|
+
return { ...base, folios, eventos: ordered, foliosConError };
|
|
176
|
+
});
|
|
177
|
+
audit(runtime, 'f22_historial', 'ok', {
|
|
178
|
+
rut: result.rut,
|
|
179
|
+
period: anio.canonical,
|
|
180
|
+
durationMs: runtime.clock.now().getTime() - start,
|
|
181
|
+
});
|
|
182
|
+
return result;
|
|
183
|
+
}
|
|
184
|
+
catch (e) {
|
|
185
|
+
audit(runtime, 'f22_historial', 'failed', { period: anio.canonical });
|
|
186
|
+
throw e;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
//# sourceMappingURL=f22.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"f22.js","sourceRoot":"","sources":["../../src/tasks/f22.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,iFAAiF;AACjF,iFAAiF;AACjF,qFAAqF;AACrF,iFAAiF;AACjF,mEAAmE;AACnE,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAC3C,OAAO,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AACtC,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,oBA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ACnB,OAAO,EAAE,GAAG,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,CAAC;QAC/D,CAAC,CAAC,CAAC;QACH,KAAK,CAAC,OAAO,EAAE,eAAe,EAAE,IAAI,EAAE;YACpC,GAAG,EAAE,MAAM,CAAC,GAAG;YACf,MAAM,EAAE,IAAI,CAAC,SAAS;YACtB,UAAU,EAAE,OAAO,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,OAAO,EAAE,GAAG,KAAK;SAClD,CAAC,CAAC;QACH,OAAO,MAAM,CAAC;IAChB,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,KAAK,CAAC,OAAO,EAAE,eAAe,EAAE,QAAQ,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC;QACtE,MAAM,CAAC,CAAC;IACV,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { F29Estado } from '../portal/f29.js';
|
|
2
|
+
import type { F29Grupo } from '../portal/f29-codigos.js';
|
|
3
|
+
import type { Runtime } from '../seams/index.js';
|
|
4
|
+
export type { CodigoF29, DeclaracionEstadoF29, F29Estado, F29Propuesta } from '../portal/f29.js';
|
|
5
|
+
export { F29_GRUPO_LABELS } from '../portal/f29-codigos.js';
|
|
6
|
+
export type { F29Grupo } from '../portal/f29-codigos.js';
|
|
7
|
+
/** One F29 line: the código, its observed glosa + form sign, and the value. */
|
|
8
|
+
export interface LineaF29 {
|
|
9
|
+
readonly codigo: string;
|
|
10
|
+
readonly glosa: string | null;
|
|
11
|
+
readonly valor: number | null;
|
|
12
|
+
readonly signo: string;
|
|
13
|
+
}
|
|
14
|
+
export interface F29Formulario {
|
|
15
|
+
readonly rut: string;
|
|
16
|
+
readonly periodo: string;
|
|
17
|
+
/** Fase 1 is always 'propuesta' (SII's suggestion). Fase 2 adds 'presentada' (the filed form). */
|
|
18
|
+
readonly fuente: 'propuesta';
|
|
19
|
+
readonly tienePropuesta: boolean;
|
|
20
|
+
/** The propuesta códigos labeled + bucketed by the form's sections (debitos / creditos /
|
|
21
|
+
* retenciones / otros / totales). An unobserved código lands in `otros` — surfaced, never
|
|
22
|
+
* hidden (anti-allowlist). */
|
|
23
|
+
readonly grupos: Record<F29Grupo, readonly LineaF29[]>;
|
|
24
|
+
}
|
|
25
|
+
/** IVA propuesta of one período, labeled + grouped (the contador-readable breakdown).
|
|
26
|
+
* `fuente: 'propuesta'` — SII's suggestion, not the filed form (that is Fase 2). */
|
|
27
|
+
export declare function f29Formulario(runtime: Runtime, args: {
|
|
28
|
+
periodo: string;
|
|
29
|
+
}): Promise<F29Formulario>;
|
|
30
|
+
/** The presented/saved F29 records of one período (estado, folio, fecha, total). Session
|
|
31
|
+
* principal (ADR-005). Empty is a clean "nada presentado", not an error. */
|
|
32
|
+
export declare function f29Status(runtime: Runtime, args: {
|
|
33
|
+
periodo: string;
|
|
34
|
+
}): Promise<F29Estado>;
|
|
35
|
+
/** One month of the overview: the vigente declaración's estado/folio/fecha + the declared
|
|
36
|
+
* `total` ("lo que pagué"). A month with no declaración is a clean empty row. */
|
|
37
|
+
export interface MesF29 {
|
|
38
|
+
readonly periodo: string;
|
|
39
|
+
readonly tieneDeclaracion: boolean;
|
|
40
|
+
readonly estado: string | null;
|
|
41
|
+
readonly folio: number | null;
|
|
42
|
+
readonly fecha: string | null;
|
|
43
|
+
readonly total: number | null;
|
|
44
|
+
}
|
|
45
|
+
export interface F29Overview {
|
|
46
|
+
readonly rut: string;
|
|
47
|
+
readonly desde: string;
|
|
48
|
+
readonly hasta: string;
|
|
49
|
+
readonly meses: readonly MesF29[];
|
|
50
|
+
}
|
|
51
|
+
/** Overview range input. ONE semantics for every surface (the policy lives here,
|
|
52
|
+
* not in the CLI/MCP — they pass their raw args through):
|
|
53
|
+
* - `anio` (YYYY) — or a bare-`YYYY` `desde` — → the whole calendar year
|
|
54
|
+
* (an explicit `hasta` may narrow it);
|
|
55
|
+
* - `desde` (YYYY-MM) alone → that single month;
|
|
56
|
+
* - nothing → the current calendar year to date (via the injected Clock).
|
|
57
|
+
* Props admit `undefined` so surfaces forward optional args verbatim
|
|
58
|
+
* (exactOptionalPropertyTypes-friendly). */
|
|
59
|
+
export interface F29OverviewArgs {
|
|
60
|
+
readonly desde?: string | undefined;
|
|
61
|
+
readonly hasta?: string | undefined;
|
|
62
|
+
readonly anio?: string | undefined;
|
|
63
|
+
}
|
|
64
|
+
/** Per-month F29 position across a date range, from the presented-declaración estado: each month's
|
|
65
|
+
* vigente estado/folio/fecha + the declared `total`. Session principal (ADR-005), paced. */
|
|
66
|
+
export declare function f29Overview(runtime: Runtime, args?: F29OverviewArgs): Promise<F29Overview>;
|
|
67
|
+
//# sourceMappingURL=f29.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"f29.d.ts","sourceRoot":"","sources":["../../src/tasks/f29.ts"],"names":[],"mappings":"AAqBA,OAAO,KAAK,EAAmC,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAEnF,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,KAAK,EAAqB,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAEpE,YAAY,EAAE,SAAS,EAAE,oBAAoB,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AACjG,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,YAAY,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AA4BzD,+EAA+E;AAC/E,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,aAA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