@albertomarturelo/sii-core 0.7.0 → 0.8.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 CHANGED
@@ -4,6 +4,78 @@ All notable changes to `@albertomarturelo/sii-core` are documented here. The for
4
4
  loosely based on [Keep a Changelog](https://keepachangelog.com/); the package is
5
5
  pre-1.0, so MINOR bumps may carry breaking changes (pin or use `~` downstream).
6
6
 
7
+ ## 0.8.0 — 2026-09-09
8
+
9
+ ### Added
10
+
11
+ - **The Portal MIPYME DTE surface — borradores, preview and emitted documents (#90, #91,
12
+ ADR-023).** SII's own FREE facturación portal (`Portal001` CGIs), reached with the Clave
13
+ alone. New tasks: `dteEmpresas`, `dteBorradorList`, `dteBorradorSave`,
14
+ `dteBorradorDelete`, `dtePreviewPdf`, `dteEmitidos`, `dtePdf`, plus `TIPOS_DTE` and
15
+ `MAX_ITEMS`. DTE **33** and **34** wired; more types arrive as a `--tipo` parameter, not
16
+ as new verbs (ADR-024).
17
+ - **BORRADORES ONLY — emission is deliberately out of scope (ADR-023).** Signing on this
18
+ portal is SERVER-SIDE (`mipeGenXMLFirma.cgi`, no certificado digital required), so a
19
+ Clave alone would be enough to issue a legally binding factura. `mipeGenXMLFirma.cgi` is
20
+ never called from this codebase, and a test asserts its absence from the compiled output.
21
+ Everything needed to *prepare* a document is automated; the one irreversible click stays
22
+ with a human in SII's own UI, one navigation away from any borrador this writes.
23
+ - **A third authorization mode: EMPRESA-KEYED (ADR-023).** Besides body-RUT (RCV) and
24
+ session-keyed (F22/F29/BTE), the MIPYME portal keeps its OWN authorized-empresa list
25
+ (`mipeSelEmpresa.cgi` — the empresas that registered this user as *usuario autorizado*),
26
+ which is neither the operate pointer's operable set nor the session principal. `empresa`
27
+ is validated against that LIVE list and re-selected before every operation, since the
28
+ choice scopes the form, the borrador CRUD and the listing. An unknown RUT fails with the
29
+ available list.
30
+ - **Single-empresa accounts resolve instead of failing (#95).** Such an account gets no
31
+ chooser at all — SII answers a JS launcher — so the empresa is read off the form's DTE
32
+ header box and nothing is POSTed. `parseChooser` returns a `launcher` / `chooser` /
33
+ `sinAutorizacion` shape rather than assuming a `<select>`.
34
+ - **SII's own validator judges the document, in-page, before anything is POSTed
35
+ (ADR-023).** The factura form ships `validaFacEx()`; it is run via `evaluate` with
36
+ `window.alert` captured, and its Spanish refusals surface VERBATIM (ADR-004). It produces
37
+ exactly the refusals the server would bounce, so an invalid document never costs a round
38
+ trip — posting past it was observed to redirect back to the form with the same alert.
39
+ - **A draft is a write, but not a destructive one (ADR-023).** `dteBorradorSave` is
40
+ reversible and legally inert, so it carries no double-entry confirm and no
41
+ `destructiveHint` — that ceremony (ADR-017) is for the irreversible step. The DELETE is
42
+ gated instead.
43
+ - **The preview PDF and the emitted document follow the ADR-022 descriptor contract.**
44
+ `mipePreView.cgi` (stamped "VISTA PREVIA · DOCUMENTO NO VALIDO", no folio) and
45
+ `mipeDisplayPDF.cgi?DHDR_CODIGO=` are fetched with `requestBinary`, written through
46
+ `FileSink`, and the task returns `{path, archivo, bytes, …}` — never the bytes. The local
47
+ filename is composed here: SII's `Content-Disposition` carries only the RUT.
48
+ - **`PortalSession.requestForm`** now backs the borrador CRUD (`mipeGrabaBorrador` /
49
+ `mipeEliminaBorrador`, `ES_BORR=TRUE`); the borradores listing is a bare JSON array on
50
+ www4 with no SDI envelope, and the emitted listing is ISO-8859-1 HTML whose rows are
51
+ MALFORMED — SII never closes the receptor cell — so it is parsed by anchor + `<td` split,
52
+ never with a strict parser.
53
+ - **PII posture.** Curated rows, **NO `raw`** anywhere on this surface (a row is counterparty
54
+ identity, ADR-004). The audit records the empresa RUT, the borrador id or folio and row
55
+ counts — never the counterparty, the amounts or free text.
56
+
57
+ ### Fixed
58
+
59
+ - **`parseEmitidas` no longer drops blank cells before mapping the row by index (#92).** A
60
+ `PRV` (vista previa) document has no folio, so its folio cell comes back blank; filtering
61
+ it slid every later column one place left — fecha into folio
62
+ (`Number('2026-09-08')` ⇒ `NaN` ⇒ `null` once serialised), monto into fecha, estado into
63
+ monto — producing a plausible row with the values under the wrong names and raising
64
+ nothing. Cells now map positionally, a blank one reads as `null`, and a row whose cell
65
+ count is not EXACTLY the observed seven raises "scraper roto" (exact rather than a
66
+ minimum: a blank cell *before* the receptor RUT shifts the row just as badly). `cellText`
67
+ folds `&nbsp;` into whitespace so a spacer-only cell is a blank cell. Shipped unreleased,
68
+ so no published version carried the mislabelling.
69
+
70
+ ### Changed
71
+
72
+ - **Surfaces are named by SII artifact (ADR-024).** The MIPYME work landed under a
73
+ `factura` verb and was folded into `dte` before release: a factura is DTE 33, and the
74
+ artifact already had a verb. `portal/factura.ts` → `portal/dte-mipyme.ts`,
75
+ `tasks/factura.ts` → `tasks/dte.ts`. Nothing published ever exposed `factura`, so this
76
+ breaks no consumer. `ROADMAP.md` § "Where a new surface goes" is now the placement table
77
+ a new verb is checked against.
78
+
7
79
  ## 0.7.0 — 2026-08-31
8
80
 
9
81
  ### Breaking
@@ -15,6 +15,16 @@ export declare const HOSTS: {
15
15
  * the SDI-JSON facade. The `.sii.cl` session cookie SSO-carries here (observed
16
16
  * 2026-06-30). Session-keyed (`rut_arrastre` = the principal). (#20 / ADR-004) */
17
17
  readonly bheCgi: "https://loa.sii.cl/cgi_IMT";
18
+ /** MIPYME — the SII's FREE facturación electrónica portal (`Portal001` CGIs). The
19
+ * factura form (`mipeGenFacEx.cgi`), the borrador CRUD (`mipeGrabaBorrador.cgi` /
20
+ * `mipeEliminaBorrador.cgi`), the preview (`mipeDisplayPreView.cgi`) and the empresa
21
+ * chooser (`mipeSelEmpresa.cgi`) all live here. The `.sii.cl` session cookie
22
+ * SSO-carries (observed 2026-09-08). EMPRESA-KEYED: the working empresa is chosen by
23
+ * POSTing `mipeSelEmpresa.cgi`, not by the operate pointer. (#89 / ADR-023) */
24
+ readonly mipeCgi: "https://www1.sii.cl/cgi-bin/Portal001";
25
+ /** Static assets of the same MIPYME portal (`PreViewFrame.html`, the JS). Separate from
26
+ * `mipeCgi` because it is NOT under `/cgi-bin`. (#89 / ADR-023) */
27
+ readonly mipeStatic: "https://www1.sii.cl/Portal001";
18
28
  /** SISPAD — peticiones administrativas. A GWT-RPC app: `text/x-gwt-rpc` POST to
19
29
  * `/sispadinternet/peticion` returns a `//OK[…]` object graph; reached via
20
30
  * `PortalSession.requestText` (a cold authenticated POST), NOT the SDI-JSON facade.
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/config/config.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,KAAK;IAChB,2FAA2F;;IAE3F,+FAA+F;;IAE/F,8FAA8F;;IAE9F,gGAAgG;;;IAGhG,+DAA+D;;IAE/D;;;uFAGmF;;IAEnF;;;;0BAIsB;;IAEtB;6FACyF;;;CAGjF,CAAC;AAEX,+EAA+E;AAC/E,eAAO,MAAM,UAAU,iBAAiB,CAAC;AAEzC,yCAAyC;AACzC,eAAO,MAAM,SAAS,QAAqC,CAAC;AAE5D,oFAAoF;AACpF,eAAO,MAAM,UAAU,QAAsC,CAAC;AAE9D,MAAM,WAAW,QAAQ;IACvB,sEAAsE;IACtE,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,8CAA8C;IAC9C,QAAQ,CAAC,iBAAiB,EAAE,MAAM,CAAC;CACpC;AAED,eAAO,MAAM,gBAAgB,EAAE,QAG9B,CAAC;AAEF,yFAAyF;AACzF,wBAAgB,QAAQ,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAEpD"}
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/config/config.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,KAAK;IAChB,2FAA2F;;IAE3F,+FAA+F;;IAE/F,8FAA8F;;IAE9F,gGAAgG;;;IAGhG,+DAA+D;;IAE/D;;;uFAGmF;;IAEnF;;;;;oFAKgF;;IAEhF;wEACoE;;IAEpE;;;;0BAIsB;;IAEtB;6FACyF;;;CAGjF,CAAC;AAEX,+EAA+E;AAC/E,eAAO,MAAM,UAAU,iBAAiB,CAAC;AAEzC,yCAAyC;AACzC,eAAO,MAAM,SAAS,QAAqC,CAAC;AAE5D,oFAAoF;AACpF,eAAO,MAAM,UAAU,QAAsC,CAAC;AAE9D,MAAM,WAAW,QAAQ;IACvB,sEAAsE;IACtE,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,8CAA8C;IAC9C,QAAQ,CAAC,iBAAiB,EAAE,MAAM,CAAC;CACpC;AAED,eAAO,MAAM,gBAAgB,EAAE,QAG9B,CAAC;AAEF,yFAAyF;AACzF,wBAAgB,QAAQ,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAEpD"}
@@ -18,6 +18,16 @@ export const HOSTS = {
18
18
  * the SDI-JSON facade. The `.sii.cl` session cookie SSO-carries here (observed
19
19
  * 2026-06-30). Session-keyed (`rut_arrastre` = the principal). (#20 / ADR-004) */
20
20
  bheCgi: 'https://loa.sii.cl/cgi_IMT',
21
+ /** MIPYME — the SII's FREE facturación electrónica portal (`Portal001` CGIs). The
22
+ * factura form (`mipeGenFacEx.cgi`), the borrador CRUD (`mipeGrabaBorrador.cgi` /
23
+ * `mipeEliminaBorrador.cgi`), the preview (`mipeDisplayPreView.cgi`) and the empresa
24
+ * chooser (`mipeSelEmpresa.cgi`) all live here. The `.sii.cl` session cookie
25
+ * SSO-carries (observed 2026-09-08). EMPRESA-KEYED: the working empresa is chosen by
26
+ * POSTing `mipeSelEmpresa.cgi`, not by the operate pointer. (#89 / ADR-023) */
27
+ mipeCgi: 'https://www1.sii.cl/cgi-bin/Portal001',
28
+ /** Static assets of the same MIPYME portal (`PreViewFrame.html`, the JS). Separate from
29
+ * `mipeCgi` because it is NOT under `/cgi-bin`. (#89 / ADR-023) */
30
+ mipeStatic: 'https://www1.sii.cl/Portal001',
21
31
  /** SISPAD — peticiones administrativas. A GWT-RPC app: `text/x-gwt-rpc` POST to
22
32
  * `/sispadinternet/peticion` returns a `//OK[…]` object graph; reached via
23
33
  * `PortalSession.requestText` (a cold authenticated POST), NOT the SDI-JSON facade.
@@ -1 +1 @@
1
- {"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/config/config.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,gFAAgF;AAChF,6DAA6D;AAE7D,MAAM,CAAC,MAAM,KAAK,GAAG;IACnB,2FAA2F;IAC3F,KAAK,EAAE,sBAAsB;IAC7B,+FAA+F;IAC/F,SAAS,EAAE,mDAAmD;IAC9D,8FAA8F;IAC9F,UAAU,EAAE,6BAA6B;IACzC,gGAAgG;IAChG,KAAK,EAAE,6CAA6C;IACpD,MAAM,EAAE,oBAAoB;IAC5B,+DAA+D;IAC/D,SAAS,EAAE,qBAAqB;IAChC;;;uFAGmF;IACnF,MAAM,EAAE,4BAA4B;IACpC;;;;0BAIsB;IACtB,MAAM,EAAE,oCAAoC;IAC5C;6FACyF;IACzF,KAAK,EAAE,uBAAuB;IAC9B,UAAU,EAAE,sDAAsD;CAC1D,CAAC;AAEX,+EAA+E;AAC/E,MAAM,CAAC,MAAM,UAAU,GAAG,cAAc,CAAC;AAEzC,yCAAyC;AACzC,MAAM,CAAC,MAAM,SAAS,GAAG,GAAG,KAAK,CAAC,KAAK,GAAG,KAAK,CAAC,SAAS,EAAE,CAAC;AAE5D,oFAAoF;AACpF,MAAM,CAAC,MAAM,UAAU,GAAG,GAAG,KAAK,CAAC,KAAK,GAAG,KAAK,CAAC,UAAU,EAAE,CAAC;AAS9D,MAAM,CAAC,MAAM,gBAAgB,GAAa;IACxC,YAAY,EAAE,CAAC;IACf,iBAAiB,EAAE,EAAE;CACtB,CAAC;AAEF,yFAAyF;AACzF,MAAM,UAAU,QAAQ,CAAC,WAAmB;IAC1C,OAAO,GAAG,SAAS,IAAI,WAAW,EAAE,CAAC;AACvC,CAAC"}
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/config/config.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,gFAAgF;AAChF,6DAA6D;AAE7D,MAAM,CAAC,MAAM,KAAK,GAAG;IACnB,2FAA2F;IAC3F,KAAK,EAAE,sBAAsB;IAC7B,+FAA+F;IAC/F,SAAS,EAAE,mDAAmD;IAC9D,8FAA8F;IAC9F,UAAU,EAAE,6BAA6B;IACzC,gGAAgG;IAChG,KAAK,EAAE,6CAA6C;IACpD,MAAM,EAAE,oBAAoB;IAC5B,+DAA+D;IAC/D,SAAS,EAAE,qBAAqB;IAChC;;;uFAGmF;IACnF,MAAM,EAAE,4BAA4B;IACpC;;;;;oFAKgF;IAChF,OAAO,EAAE,uCAAuC;IAChD;wEACoE;IACpE,UAAU,EAAE,+BAA+B;IAC3C;;;;0BAIsB;IACtB,MAAM,EAAE,oCAAoC;IAC5C;6FACyF;IACzF,KAAK,EAAE,uBAAuB;IAC9B,UAAU,EAAE,sDAAsD;CAC1D,CAAC;AAEX,+EAA+E;AAC/E,MAAM,CAAC,MAAM,UAAU,GAAG,cAAc,CAAC;AAEzC,yCAAyC;AACzC,MAAM,CAAC,MAAM,SAAS,GAAG,GAAG,KAAK,CAAC,KAAK,GAAG,KAAK,CAAC,SAAS,EAAE,CAAC;AAE5D,oFAAoF;AACpF,MAAM,CAAC,MAAM,UAAU,GAAG,GAAG,KAAK,CAAC,KAAK,GAAG,KAAK,CAAC,UAAU,EAAE,CAAC;AAS9D,MAAM,CAAC,MAAM,gBAAgB,GAAa;IACxC,YAAY,EAAE,CAAC;IACf,iBAAiB,EAAE,EAAE;CACtB,CAAC;AAEF,yFAAyF;AACzF,MAAM,UAAU,QAAQ,CAAC,WAAmB;IAC1C,OAAO,GAAG,SAAS,IAAI,WAAW,EAAE,CAAC;AACvC,CAAC"}
@@ -58,7 +58,11 @@ export declare class PeticionesError extends SiiError {
58
58
  * the network/CGI failed, a non-200 came back, or the portal HTML changed shape
59
59
  * ("scraper roto"). A RUT that is simply not a DTE emisor is NOT this error: it is a
60
60
  * clean negative result (`autorizado: false` + SII's verbatim message). Fail loud,
61
- * never retry (ADR-004 / ADR-014). */
61
+ * never retry (ADR-004 / ADR-014).
62
+ * Also the MIPYME portal surface (ADR-023 / ADR-024): SII rejected a borrador operation, its
63
+ * own client-side validator refused the document (surfaced VERBATIM), or the portal form
64
+ * changed shape. Empresa-keyed. Never retried after a SII error; a `LOGIN_HOST` bounce is
65
+ * `SessionExpiredError`, not this. */
62
66
  export declare class DteError extends SiiError {
63
67
  }
64
68
  //# sourceMappingURL=errors.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/errors/errors.ts"],"names":[],"mappings":"AAIA,qBAAa,QAAS,SAAQ,KAAK;gBACrB,OAAO,EAAE,MAAM;CAI5B;AAED,mEAAmE;AACnE,qBAAa,qBAAsB,SAAQ,QAAQ;CAAG;AAEtD;;iEAEiE;AACjE,qBAAa,mBAAoB,SAAQ,qBAAqB;CAAG;AAEjE;+BAC+B;AAC/B,qBAAa,gBAAiB,SAAQ,QAAQ;CAAG;AAEjD,mFAAmF;AACnF,qBAAa,cAAe,SAAQ,QAAQ;CAAG;AAE/C,oFAAoF;AACpF,qBAAa,uBAAwB,SAAQ,QAAQ;CAAG;AAExD,mFAAmF;AACnF,qBAAa,eAAgB,SAAQ,QAAQ;CAAG;AAEhD;8EAC8E;AAC9E,qBAAa,mBAAoB,SAAQ,QAAQ;CAAG;AAEpD;uFACuF;AACvF,qBAAa,QAAS,SAAQ,QAAQ;CAAG;AAEzC;8EAC8E;AAC9E,qBAAa,QAAS,SAAQ,QAAQ;CAAG;AAEzC;;;wFAGwF;AACxF,qBAAa,QAAS,SAAQ,QAAQ;CAAG;AAEzC;;;eAGe;AACf,qBAAa,QAAS,SAAQ,QAAQ;CAAG;AAEzC;;;;;gFAKgF;AAChF,qBAAa,eAAgB,SAAQ,QAAQ;CAAG;AAEhD;;;;uCAIuC;AACvC,qBAAa,QAAS,SAAQ,QAAQ;CAAG"}
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/errors/errors.ts"],"names":[],"mappings":"AAIA,qBAAa,QAAS,SAAQ,KAAK;gBACrB,OAAO,EAAE,MAAM;CAI5B;AAED,mEAAmE;AACnE,qBAAa,qBAAsB,SAAQ,QAAQ;CAAG;AAEtD;;iEAEiE;AACjE,qBAAa,mBAAoB,SAAQ,qBAAqB;CAAG;AAEjE;+BAC+B;AAC/B,qBAAa,gBAAiB,SAAQ,QAAQ;CAAG;AAEjD,mFAAmF;AACnF,qBAAa,cAAe,SAAQ,QAAQ;CAAG;AAE/C,oFAAoF;AACpF,qBAAa,uBAAwB,SAAQ,QAAQ;CAAG;AAExD,mFAAmF;AACnF,qBAAa,eAAgB,SAAQ,QAAQ;CAAG;AAEhD;8EAC8E;AAC9E,qBAAa,mBAAoB,SAAQ,QAAQ;CAAG;AAEpD;uFACuF;AACvF,qBAAa,QAAS,SAAQ,QAAQ;CAAG;AAEzC;8EAC8E;AAC9E,qBAAa,QAAS,SAAQ,QAAQ;CAAG;AAEzC;;;wFAGwF;AACxF,qBAAa,QAAS,SAAQ,QAAQ;CAAG;AAEzC;;;eAGe;AACf,qBAAa,QAAS,SAAQ,QAAQ;CAAG;AAEzC;;;;;gFAKgF;AAChF,qBAAa,eAAgB,SAAQ,QAAQ;CAAG;AAEhD;;;;;;;;uCAQuC;AACvC,qBAAa,QAAS,SAAQ,QAAQ;CAAG"}
@@ -64,7 +64,11 @@ export class PeticionesError extends SiiError {
64
64
  * the network/CGI failed, a non-200 came back, or the portal HTML changed shape
65
65
  * ("scraper roto"). A RUT that is simply not a DTE emisor is NOT this error: it is a
66
66
  * clean negative result (`autorizado: false` + SII's verbatim message). Fail loud,
67
- * never retry (ADR-004 / ADR-014). */
67
+ * never retry (ADR-004 / ADR-014).
68
+ * Also the MIPYME portal surface (ADR-023 / ADR-024): SII rejected a borrador operation, its
69
+ * own client-side validator refused the document (surfaced VERBATIM), or the portal form
70
+ * changed shape. Empresa-keyed. Never retried after a SII error; a `LOGIN_HOST` bounce is
71
+ * `SessionExpiredError`, not this. */
68
72
  export class DteError extends SiiError {
69
73
  }
70
74
  //# sourceMappingURL=errors.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/errors/errors.ts"],"names":[],"mappings":"AAAA,2FAA2F;AAC3F,2EAA2E;AAC3E,kEAAkE;AAElE,MAAM,OAAO,QAAS,SAAQ,KAAK;IACjC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC;IAC9B,CAAC;CACF;AAED,mEAAmE;AACnE,MAAM,OAAO,qBAAsB,SAAQ,QAAQ;CAAG;AAEtD;;iEAEiE;AACjE,MAAM,OAAO,mBAAoB,SAAQ,qBAAqB;CAAG;AAEjE;+BAC+B;AAC/B,MAAM,OAAO,gBAAiB,SAAQ,QAAQ;CAAG;AAEjD,mFAAmF;AACnF,MAAM,OAAO,cAAe,SAAQ,QAAQ;CAAG;AAE/C,oFAAoF;AACpF,MAAM,OAAO,uBAAwB,SAAQ,QAAQ;CAAG;AAExD,mFAAmF;AACnF,MAAM,OAAO,eAAgB,SAAQ,QAAQ;CAAG;AAEhD;8EAC8E;AAC9E,MAAM,OAAO,mBAAoB,SAAQ,QAAQ;CAAG;AAEpD;uFACuF;AACvF,MAAM,OAAO,QAAS,SAAQ,QAAQ;CAAG;AAEzC;8EAC8E;AAC9E,MAAM,OAAO,QAAS,SAAQ,QAAQ;CAAG;AAEzC;;;wFAGwF;AACxF,MAAM,OAAO,QAAS,SAAQ,QAAQ;CAAG;AAEzC;;;eAGe;AACf,MAAM,OAAO,QAAS,SAAQ,QAAQ;CAAG;AAEzC;;;;;gFAKgF;AAChF,MAAM,OAAO,eAAgB,SAAQ,QAAQ;CAAG;AAEhD;;;;uCAIuC;AACvC,MAAM,OAAO,QAAS,SAAQ,QAAQ;CAAG"}
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/errors/errors.ts"],"names":[],"mappings":"AAAA,2FAA2F;AAC3F,2EAA2E;AAC3E,kEAAkE;AAElE,MAAM,OAAO,QAAS,SAAQ,KAAK;IACjC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC;IAC9B,CAAC;CACF;AAED,mEAAmE;AACnE,MAAM,OAAO,qBAAsB,SAAQ,QAAQ;CAAG;AAEtD;;iEAEiE;AACjE,MAAM,OAAO,mBAAoB,SAAQ,qBAAqB;CAAG;AAEjE;+BAC+B;AAC/B,MAAM,OAAO,gBAAiB,SAAQ,QAAQ;CAAG;AAEjD,mFAAmF;AACnF,MAAM,OAAO,cAAe,SAAQ,QAAQ;CAAG;AAE/C,oFAAoF;AACpF,MAAM,OAAO,uBAAwB,SAAQ,QAAQ;CAAG;AAExD,mFAAmF;AACnF,MAAM,OAAO,eAAgB,SAAQ,QAAQ;CAAG;AAEhD;8EAC8E;AAC9E,MAAM,OAAO,mBAAoB,SAAQ,QAAQ;CAAG;AAEpD;uFACuF;AACvF,MAAM,OAAO,QAAS,SAAQ,QAAQ;CAAG;AAEzC;8EAC8E;AAC9E,MAAM,OAAO,QAAS,SAAQ,QAAQ;CAAG;AAEzC;;;wFAGwF;AACxF,MAAM,OAAO,QAAS,SAAQ,QAAQ;CAAG;AAEzC;;;eAGe;AACf,MAAM,OAAO,QAAS,SAAQ,QAAQ;CAAG;AAEzC;;;;;gFAKgF;AAChF,MAAM,OAAO,eAAgB,SAAQ,QAAQ;CAAG;AAEhD;;;;;;;;uCAQuC;AACvC,MAAM,OAAO,QAAS,SAAQ,QAAQ;CAAG"}
package/dist/index.d.ts CHANGED
@@ -10,9 +10,9 @@ export { f22Status, f22Overview, f22Observaciones, f22Historial } from './tasks/
10
10
  export type { F22Estado, F22Declaraciones, F22Overview, F22Observaciones, F22Historial, F22Grupos, DeclaracionF22, CodigoF22, EventoF22, ObservacionF22, } from './tasks/f22.js';
11
11
  export { f29Formulario, f29Overview, f29Pdf, f29Status, F29_GRUPO_LABELS, F29_PDF_TIPOS, F29_PDF_TIPO_ARGS, } from './tasks/f29.js';
12
12
  export type { F29Formulario, F29Overview, F29OverviewArgs, MesF29, LineaF29, F29Grupo, F29Estado, F29Propuesta, CodigoF29, DeclaracionEstadoF29, DocumentoF29, F29PdfArgs, F29PdfResult, F29PdfTipo, F29PdfTipoArg, } from './tasks/f29.js';
13
- export { dteAuthorized } from './tasks/dte.js';
14
- export type { DteAutorizados, DteAutorizado } from './tasks/dte.js';
15
13
  export { bteList, bteEmitPreview, bteEmit } from './tasks/bte.js';
14
+ export { dteAuthorized, dteEmpresas, dteBorradorList, dteBorradorSave, dteBorradorDelete, dtePreviewPdf, dteEmitidos, dtePdf, TIPOS_DTE, MAX_ITEMS, } from './tasks/dte.js';
15
+ export type { DteAutorizados, DteAutorizado, DteBorradorArgs, DteBorradorRow, DteBorradorSaved, DteEmpresa, DteItem, DtePreviewDoc, DteEmitido, DteEmitidoDoc, DteEmitidosFiltro, EstadoEmitido, DteSelectAviso, DteTotales, FormaPago, TipoDte, } from './tasks/dte.js';
16
16
  export type { BteMensual, BteBoleta, BteTotales, BteSide, BteEmitArgs, BteEmitResult, BteEmitida, BtePreview, BteRetiene, BteLineaEmision, } from './tasks/bte.js';
17
17
  export { peticionesList } from './tasks/peticiones.js';
18
18
  export type { PeticionesResult, Peticion, EstadoPeticion } from './tasks/peticiones.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACnF,YAAY,EACV,YAAY,EACZ,eAAe,EACf,gBAAgB,EAChB,eAAe,EACf,UAAU,GACX,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,OAAO,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BAAgB,CAAC;AACxB,YAAY,EACV,UAAU,EACV,SAAS,EACT,UAAU,EACV,OAAO,EACP,WAAW,EACX,aAAa,EACb,UAAU,EACV,UAAU,EACV,UAAU,EACV,eAAe,GAChB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,YAAY,EAAE,gBAAgB,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAKxF,YAAY,EACV,UAAU,EACV,SAAS,EACT,KAAK,EACL,sBAAsB,EACtB,uBAAuB,EACvB,aAAa,EACb,YAAY,EACZ,aAAa,EACb,OAAO,EACP,WAAW,GACZ,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AACrC,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACtD,cAAc,mBAAmB,CAAC;AAGlC,OAAO,KAAK,OAAO,MAAM,0BAA0B,CAAC"}
package/dist/index.js CHANGED
@@ -11,8 +11,8 @@ export { describeOperating, formatOperableEntry } from './identity/index.js';
11
11
  export { rcvSummary, rcvList, rcvListAll } from './tasks/rcv.js';
12
12
  export { f22Status, f22Overview, f22Observaciones, f22Historial } from './tasks/f22.js';
13
13
  export { f29Formulario, f29Overview, f29Pdf, f29Status, F29_GRUPO_LABELS, F29_PDF_TIPOS, F29_PDF_TIPO_ARGS, } from './tasks/f29.js';
14
- export { dteAuthorized } from './tasks/dte.js';
15
14
  export { bteList, bteEmitPreview, bteEmit } from './tasks/bte.js';
15
+ export { dteAuthorized, dteEmpresas, dteBorradorList, dteBorradorSave, dteBorradorDelete, dtePreviewPdf, dteEmitidos, dtePdf, TIPOS_DTE, MAX_ITEMS, } from './tasks/dte.js';
16
16
  export { peticionesList } from './tasks/peticiones.js';
17
17
  // --- shared primitives ---
18
18
  export { Rut } from './rut/index.js';
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,iGAAiG;AACjG,gFAAgF;AAChF,6EAA6E;AAE7E,uCAAuC;AACvC,mFAAmF;AACnF,mGAAmG;AACnG,gDAAgD;AAChD,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAQnF,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAEzF,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAE7E,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAUjE,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAaxF,OAAO,EACL,aAAa,EACb,WAAW,EACX,MAAM,EACN,SAAS,EACT,gBAAgB,EAChB,aAAa,EACb,iBAAiB,GAClB,MAAM,gBAAgB,CAAC;AAkBxB,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAE/C,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAalE,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAmBvD,4BAA4B;AAC5B,OAAO,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AACrC,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,KAAK,EAAE,UAAU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;AAC3D,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACtD,cAAc,mBAAmB,CAAC;AAElC,2EAA2E;AAC3E,OAAO,KAAK,OAAO,MAAM,0BAA0B,CAAC"}
@@ -0,0 +1,228 @@
1
+ import { Rut } from '../rut/index.js';
2
+ import type { PortalSession } from '../seams/index.js';
3
+ /** The DTE types the MIPYME portal exposes as their own `mipeLaunchPage` OPCION (observed
4
+ * 2026-09-08 on sii.cl/servicios_online/1039-1183.html). Only 33/34 are wired here — the
5
+ * others need their own live capture before their extra fields can be trusted. */
6
+ export declare const TIPOS_DTE: {
7
+ readonly 33: "Factura electrónica";
8
+ readonly 34: "Factura no afecta o exenta electrónica";
9
+ };
10
+ export type TipoDte = keyof typeof TIPOS_DTE;
11
+ export declare const isTipoDte: (n: number) => n is TipoDte;
12
+ /** SII's `EFXP_FMA_PAGO` codes (observed in the form's `<select>`). */
13
+ export declare const FORMA_PAGO: {
14
+ readonly contado: "1";
15
+ readonly credito: "2";
16
+ readonly sin_costo: "3";
17
+ };
18
+ export type FormaPago = keyof typeof FORMA_PAGO;
19
+ /** The grid's hard ceiling — the form's own `cantTotCol` (observed). */
20
+ export declare const MAX_ITEMS = 10;
21
+ /** An empresa the authenticated user may invoice for, as offered by `mipeSelEmpresa.cgi`. */
22
+ export interface DteEmpresa {
23
+ readonly rut: string;
24
+ readonly nombre: string;
25
+ }
26
+ export interface DteReceptor {
27
+ readonly rut: string;
28
+ readonly dv: string;
29
+ readonly razonSocial: string;
30
+ readonly direccion: string;
31
+ readonly comuna: string;
32
+ readonly ciudad: string;
33
+ readonly giro: string;
34
+ readonly contacto?: string;
35
+ }
36
+ export interface DteItem {
37
+ readonly nombre: string;
38
+ readonly descripcion?: string;
39
+ readonly cantidad: number;
40
+ readonly unidad?: string;
41
+ readonly precioUnitario: number;
42
+ readonly descuentoPct?: number;
43
+ }
44
+ /** Everything the caller supplies. The EMISOR block (razón social, giro, domicilio, acteco,
45
+ * sucursal) is read from the live form — except `ciudadEmisor`, which SII leaves BLANK yet
46
+ * its own validation demands, so the caller must provide it (observed 2026-09-08). */
47
+ export interface DteBorradorInput {
48
+ readonly empresa: string;
49
+ readonly tipoDte: TipoDte;
50
+ readonly fechaEmision: string;
51
+ readonly ciudadEmisor: string;
52
+ readonly receptor: DteReceptor;
53
+ readonly items: readonly DteItem[];
54
+ readonly formaPago: FormaPago;
55
+ /** Set to UPDATE an existing borrador in place; omit to create a new one. */
56
+ readonly borradorId?: string;
57
+ }
58
+ /** Server-side totals, computed by the form's own JS (so the arithmetic is SII's, not ours). */
59
+ export interface DteTotales {
60
+ readonly neto: number;
61
+ readonly iva: number;
62
+ readonly total: number;
63
+ }
64
+ /** SII's `ESTADO` filter values on the emitted listing (observed in the form's <select>). */
65
+ export declare const ESTADO_EMITIDO: {
66
+ readonly emitido: "EMI";
67
+ readonly preview: "PRV";
68
+ };
69
+ export type EstadoEmitido = keyof typeof ESTADO_EMITIDO;
70
+ /** Filters the emitted listing accepts, all optional (observed as query params). */
71
+ export interface DteEmitidosFiltro {
72
+ readonly tipoDoc?: number;
73
+ readonly estado?: EstadoEmitido;
74
+ readonly folio?: number;
75
+ readonly receptor?: string;
76
+ readonly desde?: string;
77
+ readonly hasta?: string;
78
+ readonly pagina?: number;
79
+ }
80
+ /** One emitted DTE — CURATED, no `raw` (the row is receptor identity, ADR-004). */
81
+ export interface DteEmitido {
82
+ /** `DHDR_CODIGO` — SII's internal id and the key the PDF is fetched by. */
83
+ readonly codigo: string;
84
+ readonly receptorRut: string | null;
85
+ readonly receptorNombre: string | null;
86
+ readonly tipoDteDesc: string | null;
87
+ readonly folio: number | null;
88
+ readonly fecha: string | null;
89
+ readonly monto: number | null;
90
+ readonly estado: string | null;
91
+ }
92
+ /** One row of the borradores list — CURATED. */
93
+ export interface DteBorradorRow {
94
+ readonly id: string;
95
+ readonly tipoDte: number;
96
+ readonly tipoDteDesc: string;
97
+ readonly fecha: string | null;
98
+ readonly receptorRut: string | null;
99
+ readonly receptorNombre: string | null;
100
+ readonly emisorNombre: string | null;
101
+ readonly iva: number | null;
102
+ readonly total: number | null;
103
+ }
104
+ /** What `mipeSelEmpresa.cgi` answers. THREE shapes observed, decided by how many empresas list
105
+ * the account as "usuario autorizado":
106
+ * * `chooser` — two or more: the `RUT_EMP` select (observed 2026-09-08).
107
+ * * `sinAutorizacion` — none: the same select with an EMPTY `<optgroup>` (observed 2026-09-09
108
+ * on an empresa account that is not itself a usuario autorizado).
109
+ * * `launcher` — exactly one: NO chooser at all — a 593-byte JS shim titled
110
+ * "Facturacion Electronica - Launcher" whose `start_pop()` jumps straight
111
+ * to the destination. The session is ALREADY scoped to that empresa, so
112
+ * there is nothing to POST (observed 2026-09-09, #95, for BOTH wired DTE
113
+ * types: `OPCION=33` and `OPCION=34` answer the identical shim). */
114
+ export type ChooserShape = {
115
+ readonly kind: 'chooser';
116
+ readonly empresas: DteEmpresa[];
117
+ } | {
118
+ readonly kind: 'sinAutorizacion';
119
+ } | {
120
+ readonly kind: 'launcher';
121
+ };
122
+ /** Classify the chooser response. Read the `<option value="RUT">NOMBRE RUT` rows when there is
123
+ * a select: SII closes neither the `<option>` nor quotes the label, so match up to the next
124
+ * `<` or newline (observed). A page that is none of the three shapes is "scraper roto". */
125
+ export declare function parseChooser(html: string): ChooserShape;
126
+ /** Read the message out of SII's server-side rejection page: a 200 "Redireccionando" document
127
+ * whose script is `alert('…')` followed by `window.history.go(-1)` (observed 2026-09-08).
128
+ * Returns the alert text with its escaped newlines turned into separators, or null. */
129
+ export declare function serverAlert(html: string): string | null;
130
+ export declare function latin1FormBody(fields: Iterable<readonly [string, string]>): string;
131
+ /** The `name`s of the `VIEW` form inside `PreViewFrame.html` — the EXACT field set the iframe
132
+ * posts to the PDF CGI, in order (observed 2026-09-08: 239 inputs, matching the browser's own
133
+ * request byte-for-byte in count). Read from SII's frame at runtime so an upstream edit is
134
+ * followed rather than drifting against a hardcoded list. */
135
+ export declare function frameFields(html: string): {
136
+ name: string;
137
+ value: string;
138
+ }[];
139
+ /** `content-type` says PDF AND the body starts with the `%PDF` magic. Status is never a
140
+ * success signal here — SII answers 200 for its own error page (ADR-022). */
141
+ export declare function isPdfBytes(bytes: Uint8Array, contentType: string | null): boolean;
142
+ /** Also relay SII's generic failure page ("Error al contribuyente"), which carries a support
143
+ * code rather than a validation message — it is a SII-side refusal, not our bad input. */
144
+ export declare function contribuyenteError(bytes: Uint8Array, contentType: string | null): string | null;
145
+ /** A receptor field SII renders as a <select> where the requested value matched no option.
146
+ * SII's own selection was KEPT (assigning a non-matching value blanks the select — observed
147
+ * 2026-09-08), and `opciones` lists what it actually offers so a caller can choose a real one. */
148
+ export interface DteSelectAviso {
149
+ readonly campo: string;
150
+ readonly solicitado: string;
151
+ readonly usado: string;
152
+ readonly opciones: readonly string[];
153
+ }
154
+ /** A filled, SII-validated form: the exact body to POST plus the totals SII computed. */
155
+ export interface DteFilled {
156
+ readonly fields: Record<string, string>;
157
+ readonly totales: DteTotales;
158
+ /** Non-fatal: <select> fields where SII's own option was kept. Surfaced to the user. */
159
+ readonly avisos: readonly DteSelectAviso[];
160
+ }
161
+ /** The empresas the authenticated user may invoice for. This is the MIPYME "usuario
162
+ * autorizado" list — its own value domain, NOT the operate pointer's operable set. On a
163
+ * single-empresa account (no chooser) it is the one empresa the portal scoped the session to. */
164
+ export declare function fetchEmpresas(session: PortalSession, tipoDte: TipoDte, sleep?: () => Promise<void>): Promise<DteEmpresa[]>;
165
+ /** Resolve `rut` against the live authorized list and select it. Returns the matched empresa so
166
+ * callers can echo SII's own razón social. An unknown RUT fails with the list (ADR-005 style). */
167
+ export declare function resolveAndSelectEmpresa(session: PortalSession, rut: Rut, tipoDte: TipoDte, sleep?: () => Promise<void>): Promise<DteEmpresa>;
168
+ /** Load the factura form for `empresa` (a fresh one, or an existing borrador) and fill it with
169
+ * `input`, letting SII's own client-side validator pass judgement. Returns the POST-ready body
170
+ * + SII's computed totals, which every downstream CGI (graba / elimina / preview) consumes. */
171
+ export declare function fillFactura(session: PortalSession, empresa: DteEmpresa, input: DteBorradorInput): Promise<DteFilled>;
172
+ /** Serialize an EXISTING borrador's form without changing it — the body `mipeEliminaBorrador`
173
+ * needs (the CGI takes the whole form back, keyed by `EHDR_CODIGO`). Totals come from the
174
+ * form as SII rendered it. */
175
+ export declare function loadBorrador(session: PortalSession, empresa: DteEmpresa, tipoDte: TipoDte, borradorId: string): Promise<DteFilled>;
176
+ /** Persist the filled form as a borrador (create, or update when `EHDR_CODIGO` is set).
177
+ * `ES_BORR=TRUE` is what tells the CGI this is a draft, not a document to sign (observed). */
178
+ export declare function grabaBorrador(session: PortalSession, filled: DteFilled): Promise<void>;
179
+ /** Delete a borrador. SII takes the WHOLE form back, keyed by `EHDR_CODIGO` (observed). */
180
+ export declare function eliminaBorrador(session: PortalSession, filled: DteFilled): Promise<void>;
181
+ /** Repair SII's DOUBLE-ENCODED text. `listaBorrador` declares `charset=ISO-8859-1` but serves
182
+ * UTF-8 bytes of an ALREADY-mojibaked string: "Á" arrives as `C3 83 C2 81`, i.e. UTF-8 of
183
+ * ("Ã", U+0081) — so a correct UTF-8 decode still yields "Fundación" / "Ñuñoa" (observed
184
+ * 2026-09-08). Undo the extra layer by re-encoding the decoded string as Latin-1 and decoding
185
+ * it as UTF-8 again. Applied ONLY when the string carries the tell-tale `Ã`/`Â` + continuation
186
+ * pair AND the round trip decodes cleanly, so legitimately-accented text is left untouched.
187
+ * This only fixes what we DISPLAY — nothing sent to SII is altered. */
188
+ export declare function repairMojibake(v: string): string;
189
+ /** The borradores of the CURRENTLY SELECTED empresa. A plain JSON array (no SDI `respEstado`
190
+ * envelope — observed), served ISO-8859-1; the seam decodes it. Rows carry ~250 mostly-null
191
+ * form columns; only the listing columns are curated (no `raw` — the row is receptor +
192
+ * emisor identity, i.e. PII, ADR-004). */
193
+ export declare function fetchBorradores(session: PortalSession): Promise<DteBorradorRow[]>;
194
+ /** Parse the emitted-documents table. The markup is MALFORMED — SII leaves the receptor cell
195
+ * unclosed (`<td>64000001-5 <td>NOMBRE</td>`, observed 2026-09-08) — so rows are split on the
196
+ * `mipeGesDocEmi.cgi?...CODIGO=` anchor and cells on `<td`, never with a strict parser.
197
+ *
198
+ * Cells map POSITIONALLY and a blank one is NEVER dropped. A `PRV` (vista previa) document has
199
+ * no folio; dropping that cell before indexing slid every later column one place left — fecha
200
+ * into folio, monto into fecha, estado into monto — producing a plausible row with the values
201
+ * under the wrong names and no error at all (#92). A row that does not carry the known cells is
202
+ * a changed portal, so it raises instead of realigning silently. */
203
+ export declare function parseEmitidas(html: string): DteEmitido[];
204
+ /** The DTEs already emitted by the selected empresa. Read-only: this touches nothing and
205
+ * cannot issue a document (ADR-023). Every filter is optional; SII takes them as query
206
+ * params and answers ISO-8859-1 HTML (observed 2026-09-08). */
207
+ export declare function fetchEmitidas(session: PortalSession, filtro?: DteEmitidosFiltro): Promise<DteEmitido[]>;
208
+ /** The PDF of an ALREADY EMITTED document, by its listing `codigo` (`DHDR_CODIGO`). A plain
209
+ * authenticated GET — far simpler than the borrador preview, which needs the review page and
210
+ * the iframe's own form. Success is decided by `content-type` + `%PDF` magic, NEVER by HTTP
211
+ * status: SII answers 200 for its error page and for the login-wall bounce too (ADR-022). */
212
+ export declare function fetchEmitidaPdf(session: PortalSession, codigo: string): Promise<Uint8Array>;
213
+ /** Fetch the PREVIEW PDF of a filled (unsigned) document — the "Validar y visualizar" path.
214
+ *
215
+ * TWO hops, both first-hand-observed 2026-09-08:
216
+ * 1. POST the VIEW_EFXP body to `mipeDisplayPreView.cgi` → the review page, whose
217
+ * `PreViewDTE` form carries the document as ~245 HIDDEN inputs.
218
+ * 2. POST that `PreViewDTE` body to `mipePreView.cgi` → `application/pdf`.
219
+ *
220
+ * Hop 2 is the PDF the portal embeds in its `framePdf` iframe: the document stamped
221
+ * "VISTA PREVIA / DOCUMENTO NO VALIDO", folio NOT assigned. Reaching the review page is NOT
222
+ * signing it — its `Firmar` button posts to `mipeGenXMLFirma.cgi`, which this module never
223
+ * calls (ADR-023).
224
+ *
225
+ * Success is decided by `content-type` + the `%PDF` magic, NEVER by HTTP status — SII answers
226
+ * 200 for its own error page and for the login-wall bounce too (the ADR-022 rule). */
227
+ export declare function fetchPreviewPdf(session: PortalSession, filled: DteFilled, sleep?: () => Promise<void>): Promise<Uint8Array>;
228
+ //# sourceMappingURL=dte-mipyme.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dte-mipyme.d.ts","sourceRoot":"","sources":["../../src/portal/dte-mipyme.ts"],"names":[],"mappings":"AA2BA,OAAO,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AACtC,OAAO,KAAK,EAAE,aAAa,EAAkB,MAAM,mBAAmB,CAAC;AAgCvE;;mFAEmF;AACnF,eAAO,MAAM,SAAS;;;CAGZ,CAAC;AACX,MAAM,MAAM,OAAO,GAAG,MAAM,OAAO,SAAS,CAAC;AAE7C,eAAO,MAAM,SAAS,GAAI,GAAG,MAAM,KAAG,CAAC,IAAI,OAA+B,CAAC;AAE3E,uEAAuE;AACvE,eAAO,MAAM,UAAU;;;;CAA0D,CAAC;AAClF,MAAM,MAAM,SAAS,GAAG,MAAM,OAAO,UAAU,CAAC;AAEhD,wEAAwE;AACxE,eAAO,MAAM,SAAS,KAAK,CAAC;AAE5B,6FAA6F;AAC7F,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,MAAM,EAAE,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