@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.
Files changed (200) hide show
  1. package/CHANGELOG.md +114 -0
  2. package/LICENSE +21 -0
  3. package/README.md +108 -0
  4. package/dist/adapters/fake/index.d.ts +98 -0
  5. package/dist/adapters/fake/index.d.ts.map +1 -0
  6. package/dist/adapters/fake/index.js +131 -0
  7. package/dist/adapters/fake/index.js.map +1 -0
  8. package/dist/adapters/node/index.d.ts +22 -0
  9. package/dist/adapters/node/index.d.ts.map +1 -0
  10. package/dist/adapters/node/index.js +65 -0
  11. package/dist/adapters/node/index.js.map +1 -0
  12. package/dist/adapters/node/portal.d.ts +8 -0
  13. package/dist/adapters/node/portal.d.ts.map +1 -0
  14. package/dist/adapters/node/portal.js +222 -0
  15. package/dist/adapters/node/portal.js.map +1 -0
  16. package/dist/adapters/node/response.d.ts +21 -0
  17. package/dist/adapters/node/response.d.ts.map +1 -0
  18. package/dist/adapters/node/response.js +48 -0
  19. package/dist/adapters/node/response.js.map +1 -0
  20. package/dist/audit/audit.d.ts +8 -0
  21. package/dist/audit/audit.d.ts.map +1 -0
  22. package/dist/audit/audit.js +15 -0
  23. package/dist/audit/audit.js.map +1 -0
  24. package/dist/audit/index.d.ts +2 -0
  25. package/dist/audit/index.d.ts.map +1 -0
  26. package/dist/audit/index.js +2 -0
  27. package/dist/audit/index.js.map +1 -0
  28. package/dist/auth/auth.d.ts +43 -0
  29. package/dist/auth/auth.d.ts.map +1 -0
  30. package/dist/auth/auth.js +219 -0
  31. package/dist/auth/auth.js.map +1 -0
  32. package/dist/auth/index.d.ts +3 -0
  33. package/dist/auth/index.d.ts.map +1 -0
  34. package/dist/auth/index.js +3 -0
  35. package/dist/auth/index.js.map +1 -0
  36. package/dist/auth/login-error.d.ts +8 -0
  37. package/dist/auth/login-error.d.ts.map +1 -0
  38. package/dist/auth/login-error.js +18 -0
  39. package/dist/auth/login-error.js.map +1 -0
  40. package/dist/auth/session.d.ts +31 -0
  41. package/dist/auth/session.d.ts.map +1 -0
  42. package/dist/auth/session.js +52 -0
  43. package/dist/auth/session.js.map +1 -0
  44. package/dist/cli.d.ts +3 -0
  45. package/dist/cli.d.ts.map +1 -0
  46. package/dist/cli.js +6 -0
  47. package/dist/cli.js.map +1 -0
  48. package/dist/config/config.d.ts +38 -0
  49. package/dist/config/config.d.ts.map +1 -0
  50. package/dist/config/config.js +40 -0
  51. package/dist/config/config.js.map +1 -0
  52. package/dist/config/index.d.ts +2 -0
  53. package/dist/config/index.d.ts.map +1 -0
  54. package/dist/config/index.js +2 -0
  55. package/dist/config/index.js.map +1 -0
  56. package/dist/errors/errors.d.ts +56 -0
  57. package/dist/errors/errors.d.ts.map +1 -0
  58. package/dist/errors/errors.js +62 -0
  59. package/dist/errors/errors.js.map +1 -0
  60. package/dist/errors/index.d.ts +2 -0
  61. package/dist/errors/index.d.ts.map +1 -0
  62. package/dist/errors/index.js +2 -0
  63. package/dist/errors/index.js.map +1 -0
  64. package/dist/format/format.d.ts +5 -0
  65. package/dist/format/format.d.ts.map +1 -0
  66. package/dist/format/format.js +14 -0
  67. package/dist/format/format.js.map +1 -0
  68. package/dist/format/index.d.ts +2 -0
  69. package/dist/format/index.d.ts.map +1 -0
  70. package/dist/format/index.js +2 -0
  71. package/dist/format/index.js.map +1 -0
  72. package/dist/identity/identity.d.ts +56 -0
  73. package/dist/identity/identity.d.ts.map +1 -0
  74. package/dist/identity/identity.js +93 -0
  75. package/dist/identity/identity.js.map +1 -0
  76. package/dist/identity/index.d.ts +2 -0
  77. package/dist/identity/index.d.ts.map +1 -0
  78. package/dist/identity/index.js +2 -0
  79. package/dist/identity/index.js.map +1 -0
  80. package/dist/index.d.ts +24 -0
  81. package/dist/index.d.ts.map +1 -0
  82. package/dist/index.js +24 -0
  83. package/dist/index.js.map +1 -0
  84. package/dist/node.d.ts +9 -0
  85. package/dist/node.d.ts.map +1 -0
  86. package/dist/node.js +22 -0
  87. package/dist/node.js.map +1 -0
  88. package/dist/periodo/anio.d.ts +15 -0
  89. package/dist/periodo/anio.d.ts.map +1 -0
  90. package/dist/periodo/anio.js +42 -0
  91. package/dist/periodo/anio.js.map +1 -0
  92. package/dist/periodo/index.d.ts +3 -0
  93. package/dist/periodo/index.d.ts.map +1 -0
  94. package/dist/periodo/index.js +3 -0
  95. package/dist/periodo/index.js.map +1 -0
  96. package/dist/periodo/periodo.d.ts +19 -0
  97. package/dist/periodo/periodo.d.ts.map +1 -0
  98. package/dist/periodo/periodo.js +55 -0
  99. package/dist/periodo/periodo.js.map +1 -0
  100. package/dist/portal/bte-comunas.d.ts +9 -0
  101. package/dist/portal/bte-comunas.d.ts.map +1 -0
  102. package/dist/portal/bte-comunas.js +400 -0
  103. package/dist/portal/bte-comunas.js.map +1 -0
  104. package/dist/portal/bte-emit.d.ts +70 -0
  105. package/dist/portal/bte-emit.d.ts.map +1 -0
  106. package/dist/portal/bte-emit.js +266 -0
  107. package/dist/portal/bte-emit.js.map +1 -0
  108. package/dist/portal/bte.d.ts +55 -0
  109. package/dist/portal/bte.d.ts.map +1 -0
  110. package/dist/portal/bte.js +215 -0
  111. package/dist/portal/bte.js.map +1 -0
  112. package/dist/portal/dte-public.d.ts +36 -0
  113. package/dist/portal/dte-public.d.ts.map +1 -0
  114. package/dist/portal/dte-public.js +192 -0
  115. package/dist/portal/dte-public.js.map +1 -0
  116. package/dist/portal/f22/declaraciones.d.ts +37 -0
  117. package/dist/portal/f22/declaraciones.d.ts.map +1 -0
  118. package/dist/portal/f22/declaraciones.js +86 -0
  119. package/dist/portal/f22/declaraciones.js.map +1 -0
  120. package/dist/portal/f22/grid.d.ts +14 -0
  121. package/dist/portal/f22/grid.d.ts.map +1 -0
  122. package/dist/portal/f22/grid.js +51 -0
  123. package/dist/portal/f22/grid.js.map +1 -0
  124. package/dist/portal/f22/historial.d.ts +34 -0
  125. package/dist/portal/f22/historial.d.ts.map +1 -0
  126. package/dist/portal/f22/historial.js +66 -0
  127. package/dist/portal/f22/historial.js.map +1 -0
  128. package/dist/portal/f22/index.d.ts +7 -0
  129. package/dist/portal/f22/index.d.ts.map +1 -0
  130. package/dist/portal/f22/index.js +11 -0
  131. package/dist/portal/f22/index.js.map +1 -0
  132. package/dist/portal/f22/observaciones.d.ts +20 -0
  133. package/dist/portal/f22/observaciones.d.ts.map +1 -0
  134. package/dist/portal/f22/observaciones.js +38 -0
  135. package/dist/portal/f22/observaciones.js.map +1 -0
  136. package/dist/portal/f22/shared.d.ts +32 -0
  137. package/dist/portal/f22/shared.d.ts.map +1 -0
  138. package/dist/portal/f22/shared.js +130 -0
  139. package/dist/portal/f22/shared.js.map +1 -0
  140. package/dist/portal/f22-codigos.d.ts +28 -0
  141. package/dist/portal/f22-codigos.d.ts.map +1 -0
  142. package/dist/portal/f22-codigos.js +141 -0
  143. package/dist/portal/f22-codigos.js.map +1 -0
  144. package/dist/portal/f29-codigos.d.ts +15 -0
  145. package/dist/portal/f29-codigos.d.ts.map +1 -0
  146. package/dist/portal/f29-codigos.js +552 -0
  147. package/dist/portal/f29-codigos.js.map +1 -0
  148. package/dist/portal/f29.d.ts +62 -0
  149. package/dist/portal/f29.d.ts.map +1 -0
  150. package/dist/portal/f29.js +244 -0
  151. package/dist/portal/f29.js.map +1 -0
  152. package/dist/portal/rcv.d.ts +62 -0
  153. package/dist/portal/rcv.d.ts.map +1 -0
  154. package/dist/portal/rcv.js +252 -0
  155. package/dist/portal/rcv.js.map +1 -0
  156. package/dist/portal/representacion.d.ts +24 -0
  157. package/dist/portal/representacion.d.ts.map +1 -0
  158. package/dist/portal/representacion.js +153 -0
  159. package/dist/portal/representacion.js.map +1 -0
  160. package/dist/rut/index.d.ts +2 -0
  161. package/dist/rut/index.d.ts.map +1 -0
  162. package/dist/rut/index.js +2 -0
  163. package/dist/rut/index.js.map +1 -0
  164. package/dist/rut/rut.d.ts +16 -0
  165. package/dist/rut/rut.d.ts.map +1 -0
  166. package/dist/rut/rut.js +70 -0
  167. package/dist/rut/rut.js.map +1 -0
  168. package/dist/seams/index.d.ts +126 -0
  169. package/dist/seams/index.d.ts.map +1 -0
  170. package/dist/seams/index.js +6 -0
  171. package/dist/seams/index.js.map +1 -0
  172. package/dist/tasks/auth.d.ts +16 -0
  173. package/dist/tasks/auth.d.ts.map +1 -0
  174. package/dist/tasks/auth.js +22 -0
  175. package/dist/tasks/auth.js.map +1 -0
  176. package/dist/tasks/bte.d.ts +52 -0
  177. package/dist/tasks/bte.d.ts.map +1 -0
  178. package/dist/tasks/bte.js +169 -0
  179. package/dist/tasks/bte.js.map +1 -0
  180. package/dist/tasks/dte.d.ts +9 -0
  181. package/dist/tasks/dte.d.ts.map +1 -0
  182. package/dist/tasks/dte.js +30 -0
  183. package/dist/tasks/dte.js.map +1 -0
  184. package/dist/tasks/f22.d.ts +69 -0
  185. package/dist/tasks/f22.d.ts.map +1 -0
  186. package/dist/tasks/f22.js +189 -0
  187. package/dist/tasks/f22.js.map +1 -0
  188. package/dist/tasks/f29.d.ts +67 -0
  189. package/dist/tasks/f29.d.ts.map +1 -0
  190. package/dist/tasks/f29.js +213 -0
  191. package/dist/tasks/f29.js.map +1 -0
  192. package/dist/tasks/operate.d.ts +22 -0
  193. package/dist/tasks/operate.d.ts.map +1 -0
  194. package/dist/tasks/operate.js +34 -0
  195. package/dist/tasks/operate.js.map +1 -0
  196. package/dist/tasks/rcv.d.ts +17 -0
  197. package/dist/tasks/rcv.d.ts.map +1 -0
  198. package/dist/tasks/rcv.js +76 -0
  199. package/dist/tasks/rcv.js.map +1 -0
  200. package/package.json +54 -0
@@ -0,0 +1,153 @@
1
+ // Representación — empresas the authenticated account can operate at SII.
2
+ // Ported from the proven Python sii-cli (portal/representacion.py); the wire
3
+ // contract is first-hand-observed, NOT a third-party library (ADR-004).
4
+ //
5
+ // SII lets ONE Clave Tributaria operate on multiple RUTs when the user is
6
+ // representante legal / a delegated user of one or more empresas (ADR-005). The
7
+ // RCV SPA's multi-RUT picker is fed by `getDcvEmpresasAutorizadas` — a JSON facade
8
+ // on the www4.sii.cl SDI envelope. SESSION-KEYED: it returns the authorizations of
9
+ // the session principal (empty `data` request); the result includes the account's
10
+ // own RUT (flagged isSelf) and IS the source of valid operate targets (ADR-005).
11
+ //
12
+ // Observed at https://www4.sii.cl/consdcvinternetui/ on 2026-06-20, confirmed
13
+ // 2026-06-26 (prod, persona-natural session): POST to EMPRESAS_URL (GET → 405);
14
+ // body `{ metaData:{namespace,conversationId,transactionId,page:null}, data:{} }`;
15
+ // conversationId = the `TOKEN` cookie on www4.sii.cl (empty value accepted). Rows
16
+ // under `data[]` carry usrEmpRut/usrEmpDv/usrEmpRutDv, razonSocONombreEmp (came
17
+ // null), usrPrivilegios. Error envelope: respEstado.codRespuesta != 0.
18
+ import { HOSTS } from '../config/index.js';
19
+ import { NotAuthenticatedError, RepresentacionError } from '../errors/index.js';
20
+ import { Rut } from '../rut/index.js';
21
+ const EMPRESAS_URL = `${HOSTS.portalApi}/consdcvinternetui/services/data/facadeService/getDcvEmpresasAutorizadas`;
22
+ const EMPRESAS_NAMESPACE = 'cl.sii.sdi.lob.diii.consdcv.data.api.interfaces.FacadeService/getDcvEmpresasAutorizadas';
23
+ // The SPA conversation token; seeds metaData.conversationId (empty value accepted).
24
+ const CONVERSATION_COOKIE = 'TOKEN';
25
+ // Same headers as the sibling RCV facades (observed): Origin = SPA host, Referer = SPA root.
26
+ const HEADERS = {
27
+ 'Content-Type': 'application/json',
28
+ Origin: HOSTS.portalApi,
29
+ Referer: `${HOSTS.portalApi}/consdcvinternetui/`,
30
+ Accept: 'application/json, text/plain, */*',
31
+ };
32
+ // Alias-tolerant field lookup; the FIRST alias per field is the observed name
33
+ // (2026-06-20). Extend with a citation when a new key surfaces.
34
+ const FIELD_ALIASES = {
35
+ rutDigits: ['usrEmpRut', 'rutEmpresa', 'empRut'],
36
+ dv: ['usrEmpDv', 'dvEmpresa', 'empDv'],
37
+ rutDv: ['usrEmpRutDv', 'rutDvEmpresa'],
38
+ razonSocial: ['razonSocONombreEmp', 'razonSocial', 'nombreEmpresa'],
39
+ privilegios: ['usrPrivilegios', 'privilegios'],
40
+ };
41
+ const aliasGet = (row, field) => {
42
+ for (const key of FIELD_ALIASES[field]) {
43
+ const value = row[key];
44
+ if (value !== undefined && value !== null)
45
+ return value;
46
+ }
47
+ return undefined;
48
+ };
49
+ const asStr = (v) => (v === null || v === undefined ? null : String(v));
50
+ function canonicalEmpresaRut(row) {
51
+ const digits = aliasGet(row, 'rutDigits');
52
+ const dv = aliasGet(row, 'dv');
53
+ if (digits !== undefined && dv !== undefined) {
54
+ try {
55
+ return Rut.parse(`${String(digits)}-${String(dv).trim()}`).canonical;
56
+ }
57
+ catch {
58
+ // fall through to the combined field
59
+ }
60
+ }
61
+ const combined = aliasGet(row, 'rutDv');
62
+ if (combined !== undefined) {
63
+ try {
64
+ return Rut.parse(String(combined)).canonical;
65
+ }
66
+ catch {
67
+ return null;
68
+ }
69
+ }
70
+ return null;
71
+ }
72
+ function buildEmpresa(row, authCanonical) {
73
+ const rut = canonicalEmpresaRut(row);
74
+ return {
75
+ rut,
76
+ razonSocial: asStr(aliasGet(row, 'razonSocial')),
77
+ privilegios: asStr(aliasGet(row, 'privilegios')),
78
+ isSelf: rut !== null && rut === authCanonical,
79
+ raw: row,
80
+ };
81
+ }
82
+ function extractRows(body) {
83
+ for (const key of ['data', 'datos', 'empresas', 'items']) {
84
+ const block = body[key];
85
+ if (Array.isArray(block) && block.every((r) => typeof r === 'object' && r !== null)) {
86
+ return block;
87
+ }
88
+ }
89
+ return [];
90
+ }
91
+ /** The shared SDI error envelope: respEstado.codRespuesta != 0 ⇒ SII signaled an
92
+ * error; return its message verbatim. */
93
+ function siiRejected(body) {
94
+ const resp = body['respEstado'];
95
+ if (typeof resp !== 'object' || resp === null)
96
+ return null;
97
+ const r = resp;
98
+ const code = r['codRespuesta'];
99
+ if (code === 0 || code === '0' || code === undefined || code === null)
100
+ return null;
101
+ return (asStr(r['msgeRespuesta'] ?? r['codError']) ?? 'SII rechazó la consulta de empresas autorizadas.');
102
+ }
103
+ function parseResponse(raw, authCanonical) {
104
+ // Empty `data[]` is a legitimate "no representations" result, NOT an error. An
105
+ // SII error envelope or a non-object response raises (never silently empty,
106
+ // which would be indistinguishable from "no representations") — ADR-004.
107
+ if (typeof raw !== 'object' || raw === null) {
108
+ throw new RepresentacionError('Respuesta inesperada de SII (no es un objeto JSON).');
109
+ }
110
+ const body = raw;
111
+ const rejected = siiRejected(body);
112
+ if (rejected)
113
+ throw new RepresentacionError(rejected);
114
+ return {
115
+ rut: authCanonical,
116
+ empresas: extractRows(body).map((r) => buildEmpresa(r, authCanonical)),
117
+ };
118
+ }
119
+ /** Fetch the operable set for the live session (empresas the account can operate).
120
+ * SESSION-KEYED — no operating-RUT arg (ADR-005). `session` must be an
121
+ * already-logged-in PortalSession. Throws `RepresentacionError` on an SII error
122
+ * envelope / non-JSON response (message verbatim, ADR-004). */
123
+ export async function fetchEmpresasAutorizadas(session, authRutCanonical) {
124
+ const conversationId = (await session.cookie(`${HOSTS.portalApi}/`, CONVERSATION_COOKIE)) ?? '';
125
+ const request = {
126
+ method: 'POST',
127
+ headers: HEADERS,
128
+ body: {
129
+ metaData: {
130
+ namespace: EMPRESAS_NAMESPACE,
131
+ conversationId,
132
+ // Opaque per-request correlation id (Web Crypto global; no node: import).
133
+ transactionId: globalThis.crypto.randomUUID(),
134
+ page: null,
135
+ },
136
+ data: {},
137
+ },
138
+ };
139
+ let raw;
140
+ try {
141
+ raw = await session.requestJson(EMPRESAS_URL, request);
142
+ }
143
+ catch (e) {
144
+ // An expired/dead session (the seam detects the login wall) is an actionable
145
+ // NotAuthenticated — let it through. Any other non-JSON / network failure becomes
146
+ // a typed RepresentacionError (ADR-004), not a raw Playwright/SyntaxError.
147
+ if (e instanceof NotAuthenticatedError)
148
+ throw e;
149
+ throw new RepresentacionError('Respuesta inesperada de SII (no es JSON).');
150
+ }
151
+ return parseResponse(raw, authRutCanonical);
152
+ }
153
+ //# sourceMappingURL=representacion.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"representacion.js","sourceRoot":"","sources":["../../src/portal/representacion.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,6EAA6E;AAC7E,wEAAwE;AACxE,EAAE;AACF,0EAA0E;AAC1E,gFAAgF;AAChF,mFAAmF;AACnF,mFAAmF;AACnF,kFAAkF;AAClF,iFAAiF;AACjF,EAAE;AACF,8EAA8E;AAC9E,gFAAgF;AAChF,mFAAmF;AACnF,kFAAkF;AAClF,gFAAgF;AAChF,uEAAuE;AACvE,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAChF,OAAO,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAGtC,MAAM,YAAY,GAAG,GAAG,KAAK,CAAC,SAAS,0EAA0E,CAAC;AAClH,MAAM,kBAAkB,GACtB,yFAAyF,CAAC;AAC5F,oFAAoF;AACpF,MAAM,mBAAmB,GAAG,OAAO,CAAC;AAEpC,6FAA6F;AAC7F,MAAM,OAAO,GAA2B;IACtC,cAAc,EAAE,kBAAkB;IAClC,MAAM,EAAE,KAAK,CAAC,SAAS;IACvB,OAAO,EAAE,GAAG,KAAK,CAAC,SAAS,qBAAqB;IAChD,MAAM,EAAE,mCAAmC;CAC5C,CAAC;AAqBF,8EAA8E;AAC9E,gEAAgE;AAChE,MAAM,aAAa,GAAG;IACpB,SAAS,EAAE,CAAC,WAAW,EAAE,YAAY,EAAE,QAAQ,CAAC;IAChD,EAAE,EAAE,CAAC,UAAU,EAAE,WAAW,EAAE,OAAO,CAAC;IACtC,KAAK,EAAE,CAAC,aAAa,EAAE,cAAc,CAAC;IACtC,WAAW,EAAE,CAAC,oBAAoB,EAAE,aAAa,EAAE,eAAe,CAAC;IACnE,WAAW,EAAE,CAAC,gBAAgB,EAAE,aAAa,CAAC;CACtC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,IAAI;aACX;YACD,IAAI,EAAE,EAAE;SACT;KACF,CAAC;IACF,IAAI,GAAY,CAAC;IACjB,IAAI,CAAC;QACH,GAAG,GAAG,MAAM,OAAO,CAAC,WAAW,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;IACzD,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,6EAA6E;QAC7E,kFAAkF;QAClF,2EAA2E;QAC3E,IAAI,CAAC,YAAY,qBAAqB;YAAE,MAAM,CAAC,CAAC;QAChD,MAAM,IAAI,mBAAmB,CAAC,2CAA2C,CAAC,CAAC;IAC7E,CAAC;IACD,OAAO,aAAa,CAAC,GAAG,EAAE,gBAAgB,CAAC,CAAC;AAC9C,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from './rut.js';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/rut/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from './rut.js';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/rut/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC"}
@@ -0,0 +1,16 @@
1
+ /** A validated Chilean RUT. Canonical internal form is `<body>-<DV>`. */
2
+ export declare class Rut {
3
+ readonly body: number;
4
+ readonly dv: string;
5
+ private constructor();
6
+ /** Parse + validate. Accepts dotted / spaced / hyphenated input. Throws on a bad DV. */
7
+ static parse(input: string): Rut;
8
+ static tryParse(input: string): Rut | null;
9
+ /** Machine-stable form: `<body>-<DV>` (e.g. `77777777-7`). */
10
+ get canonical(): string;
11
+ /** Human form with thousands separators (e.g. `77.777.777-7`). */
12
+ get formatted(): string;
13
+ equals(other: Rut): boolean;
14
+ toString(): string;
15
+ }
16
+ //# sourceMappingURL=rut.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rut.d.ts","sourceRoot":"","sources":["../../src/rut/rut.ts"],"names":[],"mappings":"AAoBA,yEAAyE;AACzE,qBAAa,GAAG;IAEZ,QAAQ,CAAC,IAAI,EAAE,MAAM;IACrB,QAAQ,CAAC,EAAE,EAAE,MAAM;IAFrB,OAAO;IAKP,wFAAwF;IACxF,MAAM,CAAC,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,GAAG;IAkBhC,MAAM,CAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,GAAG,GAAG,IAAI;IAQ1C,8DAA8D;IAC9D,IAAI,SAAS,IAAI,MAAM,CAEtB;IAED,kEAAkE;IAClE,IAAI,SAAS,IAAI,MAAM,CAGtB;IAED,MAAM,CAAC,KAAK,EAAE,GAAG,GAAG,OAAO;IAI3B,QAAQ,IAAI,MAAM;CAGnB"}
@@ -0,0 +1,70 @@
1
+ import { ValidationError } from '../errors/index.js';
2
+ const WEIGHT_RESET = 7;
3
+ /** Chilean Mod-11 check digit for a RUT body (sii-py ADR-010, in-house). */
4
+ function computeDv(body) {
5
+ let sum = 0;
6
+ let multiplier = 2;
7
+ let n = body;
8
+ while (n > 0) {
9
+ sum += (n % 10) * multiplier;
10
+ n = Math.floor(n / 10);
11
+ multiplier = multiplier === WEIGHT_RESET ? 2 : multiplier + 1;
12
+ }
13
+ const r = 11 - (sum % 11);
14
+ if (r === 11)
15
+ return '0';
16
+ if (r === 10)
17
+ return 'K';
18
+ return String(r);
19
+ }
20
+ /** A validated Chilean RUT. Canonical internal form is `<body>-<DV>`. */
21
+ export class Rut {
22
+ body;
23
+ dv;
24
+ constructor(body, dv) {
25
+ this.body = body;
26
+ this.dv = dv;
27
+ }
28
+ /** Parse + validate. Accepts dotted / spaced / hyphenated input. Throws on a bad DV. */
29
+ static parse(input) {
30
+ const cleaned = input.replace(/[.\s-]/g, '').toUpperCase();
31
+ if (cleaned.length < 2) {
32
+ throw new ValidationError(`RUT inválido: "${input}"`);
33
+ }
34
+ const dv = cleaned.slice(-1);
35
+ const bodyStr = cleaned.slice(0, -1);
36
+ if (!/^\d+$/.test(bodyStr) || !/^[0-9K]$/.test(dv)) {
37
+ throw new ValidationError(`RUT inválido: "${input}"`);
38
+ }
39
+ const body = Number(bodyStr);
40
+ const expected = computeDv(body);
41
+ if (expected !== dv) {
42
+ throw new ValidationError(`RUT con DV inválido: "${input}" (esperado -${expected})`);
43
+ }
44
+ return new Rut(body, dv);
45
+ }
46
+ static tryParse(input) {
47
+ try {
48
+ return Rut.parse(input);
49
+ }
50
+ catch {
51
+ return null;
52
+ }
53
+ }
54
+ /** Machine-stable form: `<body>-<DV>` (e.g. `77777777-7`). */
55
+ get canonical() {
56
+ return `${this.body}-${this.dv}`;
57
+ }
58
+ /** Human form with thousands separators (e.g. `77.777.777-7`). */
59
+ get formatted() {
60
+ const dotted = String(this.body).replace(/\B(?=(\d{3})+(?!\d))/g, '.');
61
+ return `${dotted}-${this.dv}`;
62
+ }
63
+ equals(other) {
64
+ return this.body === other.body && this.dv === other.dv;
65
+ }
66
+ toString() {
67
+ return this.canonical;
68
+ }
69
+ }
70
+ //# sourceMappingURL=rut.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rut.js","sourceRoot":"","sources":["../../src/rut/rut.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAErD,MAAM,YAAY,GAAG,CAAC,CAAC;AAEvB,4EAA4E;AAC5E,SAAS,SAAS,CAAC,IAAY;IAC7B,IAAI,GAAG,GAAG,CAAC,CAAC;IACZ,IAAI,UAAU,GAAG,CAAC,CAAC;IACnB,IAAI,CAAC,GAAG,IAAI,CAAC;IACb,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;QACb,GAAG,IAAI,CAAC,CAAC,GAAG,EAAE,CAAC,GAAG,UAAU,CAAC;QAC7B,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC;QACvB,UAAU,G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QAAQ,KAAK,EAAE,EAAE,CAAC;YACpB,MAAM,IAAI,eAAe,CAAC,yBAAyB,KAAK,gBAAgB,QAAQ,GAAG,CAAC,CAAC;QACvF,CAAC;QACD,OAAO,IAAI,GAAG,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;IAC3B,CAAC;IAED,MAAM,CAAC,QAAQ,CAAC,KAAa;QAC3B,IAAI,CAAC;YACH,OAAO,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QAC1B,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;IAED,8DAA8D;IAC9D,IAAI,SAAS;QACX,OAAO,GAAG,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,EAAE,EAAE,CAAC;IACnC,CAAC;IAED,kEAAkE;IAClE,IAAI,SAAS;QACX,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,uBAAuB,EAAE,GAAG,CAAC,CAAC;QACvE,OAAO,GAAG,MAAM,IAAI,IAAI,CAAC,EAAE,EAAE,CAAC;IAChC,CAAC;IAED,MAAM,CAAC,KAAU;QACf,OAAO,IAAI,CAAC,IAAI,KAAK,KAAK,CAAC,IAAI,IAAI,IAAI,CAAC,EAAE,KAAK,KAAK,CAAC,EAAE,CAAC;IAC1D,CAAC;IAED,QAAQ;QACN,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;CACF"}
@@ -0,0 +1,126 @@
1
+ export interface Clock {
2
+ now(): Date;
3
+ /** Pause for `ms` (the pacing primitive for multi-call fan-outs — rate-limit
4
+ * convention, ADR-004). Fakes resolve instantly so tests don't wait. */
5
+ sleep(ms: number): Promise<void>;
6
+ }
7
+ /** One audit receipt line. The audit module stamps `ts` and drops secret keys. */
8
+ export interface AuditEntry {
9
+ readonly action: string;
10
+ readonly result: string;
11
+ readonly rut?: string;
12
+ readonly rutAuth?: string;
13
+ readonly durationMs?: number;
14
+ readonly [extra: string]: unknown;
15
+ }
16
+ export interface AuditSink {
17
+ record(entry: AuditEntry): void;
18
+ }
19
+ /** Namespaced local JSON store. Modules use DISTINCT keys (ADR-007) so they never
20
+ * write the same file: `auth` → 'session', `identity` → 'operate'. */
21
+ export interface KeyValueStore {
22
+ read<T>(key: string): Promise<T | null>;
23
+ write<T>(key: string, value: T): Promise<void>;
24
+ delete(key: string): Promise<void>;
25
+ }
26
+ /** OS secure storage for the optional credential path (ADR-006 / ADR-008).
27
+ * Declared now; no Node adapter until the keyring increment. */
28
+ export interface SecretStore {
29
+ get(account: string): Promise<string | null>;
30
+ set(account: string, secret: string): Promise<void>;
31
+ delete(account: string): Promise<void>;
32
+ }
33
+ /** A logged-in browser context (cookies loaded). All portal reads go through
34
+ * here, so the core never imports Playwright. */
35
+ export interface JsonRequest {
36
+ readonly method?: 'GET' | 'POST';
37
+ readonly headers?: Record<string, string>;
38
+ /** JSON-serialisable request body (sent as the POST payload). */
39
+ readonly body?: unknown;
40
+ }
41
+ /** An AUTHENTICATED `x-www-form-urlencoded` request from the session (cookies ride
42
+ * along). The primitive behind the legacy HTML form-POST write flows — BHE emission
43
+ * (`loa.sii.cl` `TMBECN_*` CGIs, ADR-017) — which return HTML, not JSON. The
44
+ * authenticated peer of `PublicRequest.form` (which is session-less). */
45
+ export interface FormRequest {
46
+ readonly method?: 'GET' | 'POST';
47
+ readonly headers?: Record<string, string>;
48
+ readonly form?: Record<string, string>;
49
+ }
50
+ export interface PortalSession {
51
+ /** Navigate; returns the URL actually landed on (for URL-based auth detection). */
52
+ goto(url: string): Promise<string>;
53
+ /** Evaluate a JS expression in the page; returns its JSON-serialisable result. */
54
+ evaluate<T>(expression: string): Promise<T>;
55
+ /** Issue an authenticated JSON request from the session's browser context (the
56
+ * session cookies are sent automatically). The primitive behind the SII SPA
57
+ * JSON facades (the `www4.sii.cl` SDI endpoints — RCV, representación, …).
58
+ * Resolves the parsed JSON body; rejects on a non-JSON response. */
59
+ requestJson(url: string, options?: JsonRequest): Promise<unknown>;
60
+ /** Issue an authenticated FORM POST (`x-www-form-urlencoded`) from the session and
61
+ * return the decoded text body (charset-aware). The primitive behind the legacy
62
+ * HTML write flows — BHE emission (ADR-017) — where the CGI returns HTML, not JSON.
63
+ * Login-wall detection is URL-based (landing on `LOGIN_HOST`) → `SessionExpiredError`,
64
+ * since an HTML body is EXPECTED here (unlike `requestJson`). */
65
+ requestForm(url: string, options?: FormRequest): Promise<PublicResponse>;
66
+ /** Value of a cookie visible to `url` (e.g. the SPA conversation `TOKEN`), or
67
+ * null. Used to seed SDI request metadata. */
68
+ cookie(url: string, name: string): Promise<string | null>;
69
+ /** The cookies-only storage state to persist. */
70
+ storageState(): Promise<unknown>;
71
+ close(): Promise<void>;
72
+ }
73
+ /** An UNAUTHENTICATED public request (no session, no cookies). The basis for
74
+ * login-free consultas — the DTE-authorized public CGI (ADR-014). */
75
+ export interface PublicRequest {
76
+ readonly method?: 'GET' | 'POST';
77
+ readonly headers?: Record<string, string>;
78
+ /** `application/x-www-form-urlencoded` fields (the palena CGI takes form input). */
79
+ readonly form?: Record<string, string>;
80
+ }
81
+ export interface PublicResponse {
82
+ readonly status: number;
83
+ /** Decoded text body — the adapter decodes per the response's DECLARED charset
84
+ * (the DTE report is `text/html; charset=ISO-8859-1`), so accents survive. */
85
+ readonly body: string;
86
+ }
87
+ export interface InteractiveLoginOptions {
88
+ /** Post-login destination passed to the login URL. */
89
+ readonly destination: string;
90
+ /** Give up if the user hasn't landed off LOGIN_HOST within this budget (ms). */
91
+ readonly timeoutMs: number;
92
+ }
93
+ export interface CredentialLoginOptions {
94
+ /** Full RUT to type into the login form (`<body>-<DV>`); the page JS splits it. */
95
+ readonly rut: string;
96
+ /** The Clave Tributaria — used ONCE to fill the form, never persisted (ADR-010). */
97
+ readonly clave: string;
98
+ /** Post-login destination passed to the login URL. */
99
+ readonly destination: string;
100
+ /** Give up if we haven't landed off LOGIN_HOST within this budget (ms). */
101
+ readonly timeoutMs: number;
102
+ }
103
+ export interface PortalDriver {
104
+ /** Open a HEADED browser at the login URL; resolve with a session once the user
105
+ * lands off LOGIN_HOST. Rejects (LoginFailedError) on timeout / window close. */
106
+ interactiveLogin(options: InteractiveLoginOptions): Promise<PortalSession>;
107
+ /** HEADLESS console login (ADR-010): fill the real SII form with RUT + Clave and
108
+ * submit, resolving a session once landed off LOGIN_HOST. The Clave is used here
109
+ * and never stored (cookies-only result). CLI-only — never wired into MCP. */
110
+ credentialLogin(options: CredentialLoginOptions): Promise<PortalSession>;
111
+ /** Restore a (headless) session from persisted cookies for reads / liveness. */
112
+ restore(storageState: unknown): Promise<PortalSession>;
113
+ /** Issue an UNAUTHENTICATED request (no session, no cookies, no browser) to a
114
+ * public SII endpoint and return the decoded text body. The basis for login-free
115
+ * consultas (DTE authorized) — it neither mints nor uses a session (ADR-014). */
116
+ requestPublic(url: string, options?: PublicRequest): Promise<PublicResponse>;
117
+ }
118
+ /** The set of seams a task needs. The composition root (runtime.ts) builds it. */
119
+ export interface Runtime {
120
+ readonly clock: Clock;
121
+ readonly audit: AuditSink;
122
+ readonly store: KeyValueStore;
123
+ readonly portal: PortalDriver;
124
+ readonly secrets?: SecretStore;
125
+ }
126
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/seams/index.ts"],"names":[],"mappings":"AAKA,MAAM,WAAW,KAAK;IACpB,GAAG,IAAI,IAAI,CAAC;IACZ;6EACyE;IACzE,KAAK,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAClC;AAED,kFAAkF;AAClF,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC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,sDAAsD;IACtD,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,gFAAgF;IAChF,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;CAC5B;AAED,MAAM,WAAW,sBAAsB;IACrC,mFAAmF;IACnF,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,oFAAoF;IACpF,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,sDAAsD;IACtD,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,2EAA2E;IAC3E,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;CAC5B;AAED,MAAM,WAAW,YAAY;IAC3B;sFACkF;IAClF,gBAAgB,CAAC,OAAO,EAAE,uBAAuB,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;IAC3E;;mFAE+E;IAC/E,eAAe,CAAC,OAAO,EAAE,sBAAsB,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;IACzE,gFAAgF;IAChF,OAAO,CAAC,YAAY,EAAE,OAAO,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;IACvD;;sFAEkF;IAClF,aAAa,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;CAC9E;AAED,kFAAkF;AAClF,MAAM,WAAW,OAAO;IACtB,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAC;IAC1B,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC;IAC9B,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAC;IAC9B,QAAQ,CAAC,OAAO,CAAC,EAAE,WAAW,CAAC;CAChC"}
@@ -0,0 +1,6 @@
1
+ // Injectable seams (ADR-003): the external / non-deterministic dependencies the
2
+ // core reaches through interfaces. Node defaults live in adapters/node; in-memory
3
+ // fakes for tests live in adapters/fake. The core never imports Playwright, fs,
4
+ // or a keyring directly — only these interfaces.
5
+ export {};
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/seams/index.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAChF,kFAAkF;AAClF,gFAAgF;AAChF,iDAAiD"}
@@ -0,0 +1,16 @@
1
+ import type { AuthIdentity, AuthLoginResult, AuthLogoutResult, AuthStatusLocal } from '../auth/index.js';
2
+ import type { Runtime } from '../seams/index.js';
3
+ export declare function login(runtime: Runtime): Promise<AuthLoginResult>;
4
+ /** CLI-only (ADR-010): RUT + Clave from the console → headless login → cookies
5
+ * only. The Clave is used once and never stored. NEVER expose over MCP. */
6
+ export declare function consoleLogin(runtime: Runtime, credentials: {
7
+ rut: string;
8
+ clave: string;
9
+ }): Promise<AuthLoginResult>;
10
+ export declare function logout(runtime: Runtime): Promise<AuthLogoutResult>;
11
+ /** Pure local read (no portal call). */
12
+ export declare function authStatus(runtime: Runtime): Promise<AuthStatusLocal>;
13
+ /** Curated identity readback from the portal (needs a live session). */
14
+ export declare function statusRefresh(runtime: Runtime): Promise<AuthIdentity>;
15
+ export type { AuthIdentity, AuthLoginResult, AuthLogoutResult, AuthStatusLocal };
16
+ //# sourceMappingURL=auth.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/tasks/auth.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,YAAY,EACZ,eAAe,EACf,gBAAgB,EAChB,eAAe,EAChB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAEjD,wBAAgB,KAAK,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,eAAe,CAAC,CAEhE;AAED;4EAC4E;AAC5E,wBAAgB,YAAY,CAC1B,OAAO,EAAE,OAAO,EAChB,WAAW,EAAE;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAC1C,OAAO,CAAC,eAAe,CAAC,CAE1B;AAED,wBAAgB,MAAM,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAElE;AAED,wCAAwC;AACxC,wBAAgB,UAAU,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,eAAe,CAAC,CAErE;AAED,wEAAwE;AACxE,wBAAgB,aAAa,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,YAAY,CAAC,CAErE;AAED,YAAY,EAAE,YAAY,EAAE,eAAe,EAAE,gBAAgB,EAAE,eAAe,EAAE,CAAC"}
@@ -0,0 +1,22 @@
1
+ // Public auth API the surfaces call. Uniform: every operation takes a Runtime.
2
+ import * as auth from '../auth/index.js';
3
+ export function login(runtime) {
4
+ return auth.login(runtime);
5
+ }
6
+ /** CLI-only (ADR-010): RUT + Clave from the console → headless login → cookies
7
+ * only. The Clave is used once and never stored. NEVER expose over MCP. */
8
+ export function consoleLogin(runtime, credentials) {
9
+ return auth.consoleLogin(runtime, credentials);
10
+ }
11
+ export function logout(runtime) {
12
+ return auth.logout(runtime);
13
+ }
14
+ /** Pure local read (no portal call). */
15
+ export function authStatus(runtime) {
16
+ return auth.localStatus(runtime.store);
17
+ }
18
+ /** Curated identity readback from the portal (needs a live session). */
19
+ export function statusRefresh(runtime) {
20
+ return auth.statusRefresh(runtime);
21
+ }
22
+ //# sourceMappingURL=auth.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.js","sourceRoot":"","sources":["../../src/tasks/auth.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,OAAO,KAAK,IAAI,MAAM,kBAAkB,CAAC;AASzC,MAAM,UAAU,KAAK,CAAC,OAAgB;IACpC,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;AAC7B,CAAC;AAED;4EAC4E;AAC5E,MAAM,UAAU,YAAY,CAC1B,OAAgB,EAChB,WAA2C;IAE3C,OAAO,IAAI,CAAC,YAAY,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;AACjD,CAAC;AAED,MAAM,UAAU,MAAM,CAAC,OAAgB;IACrC,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;AAC9B,CAAC;AAED,wCAAwC;AACxC,MAAM,UAAU,UAAU,CAAC,OAAgB;IACzC,OAAO,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AACzC,CAAC;AAED,wEAAwE;AACxE,MAAM,UAAU,aAAa,CAAC,OAAgB;IAC5C,OAAO,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;AACrC,CAAC"}
@@ -0,0 +1,52 @@
1
+ import type { BteMensual, BteSide } from '../portal/bte.js';
2
+ import type { BteEmitida, BtePreview, BteRetiene } from '../portal/bte-emit.js';
3
+ import type { Runtime } from '../seams/index.js';
4
+ export type { BteBoleta, BteMensual, BteSide, BteTotales } from '../portal/bte.js';
5
+ export type { BteEmitida, BtePreview, BteRetiene, BteLineaEmision } from '../portal/bte-emit.js';
6
+ /** One month's boletas de honorarios for the session principal (ADR-005), emitidas or recibidas.
7
+ * An empty month is a clean 0-boleta result, not an error. */
8
+ export declare function bteList(runtime: Runtime, args: {
9
+ periodo: string;
10
+ side: BteSide;
11
+ }): Promise<BteMensual>;
12
+ /** The args a surface passes to emit/preview. Strings/numbers from the CLI/MCP; validated
13
+ * locally here BEFORE any session. The emisor fields (domicilio/comuna/actividad) are read
14
+ * from the live form — the caller supplies only the receptor + líneas + fecha + who-withholds. */
15
+ export interface BteEmitArgs {
16
+ readonly receptor: string;
17
+ readonly receptorNombre: string;
18
+ readonly receptorDomicilio: string;
19
+ readonly region: number;
20
+ readonly comuna: number;
21
+ readonly lineas: readonly {
22
+ readonly glosa: string;
23
+ readonly monto: number;
24
+ }[];
25
+ /** Boleta date; defaults to today. Must be within ±3 months (SII rule). */
26
+ readonly fecha?: {
27
+ readonly dia: number;
28
+ readonly mes: number;
29
+ readonly anio: number;
30
+ };
31
+ readonly retiene: BteRetiene;
32
+ readonly mostrarDetalle?: boolean;
33
+ /** Optional: also email the issued PDF to this address (emit only). */
34
+ readonly enviarA?: string;
35
+ /** Copy the emisor on the email (default true). */
36
+ readonly copiaEmisor?: boolean;
37
+ }
38
+ /** Result of an emission: the issued boleta + whether the optional email was sent. */
39
+ export interface BteEmitResult extends BteEmitida {
40
+ readonly enviado?: boolean;
41
+ }
42
+ /** PREVIEW an emission (ADR-017): run the SII flow to the confirmation step and return the
43
+ * server-computed retención/líquido WITHOUT issuing. Session-keyed (rejects a representing
44
+ * pointer). Never issues; safe to call freely. */
45
+ export declare function bteEmitPreview(runtime: Runtime, args: BteEmitArgs): Promise<BtePreview>;
46
+ /** ISSUE a boleta de honorarios (ADR-017) — a legally-binding act. Runs the full SII flow and
47
+ * returns the folio (código de barras) + PDF URL. Session-keyed. NEVER retries. The caller
48
+ * (CLI `--confirm`, MCP `confirmar`) is responsible for the explicit confirmation; this task
49
+ * assumes the confirmation was given. Optional email send. The audit receipt carries the folio
50
+ * but NEVER the receptor / monto / glosa (PII / business data). */
51
+ export declare function bteEmit(runtime: Runtime, args: BteEmitArgs): Promise<BteEmitResult>;
52
+ //# sourceMappingURL=bte.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bte.d.ts","sourceRoot":"","sources":["../../src/tasks/bte.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAO5D,OAAO,KAAK,EAEV,UAAU,EAEV,UAAU,EACV,UAAU,EACX,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAc,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAE7D,YAAY,EAAE,SAAS,EAAE,UAAU,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnF,YAAY,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,eAAe,EA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