@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,93 @@
1
+ import { ValidationError } from '../errors/index.js';
2
+ import { Rut } from '../rut/index.js';
3
+ // Distinct KeyValueStore key (ADR-007) — never shares a file with `auth`'s 'session'.
4
+ const OPERATE_KEY = 'operate';
5
+ export async function readOperateState(store) {
6
+ return store.read(OPERATE_KEY);
7
+ }
8
+ /** Initialise on login: operatingRut defaults to self, operable cached. */
9
+ export async function initOperateState(store, input) {
10
+ const state = {
11
+ selfRut: input.selfRut,
12
+ accountType: input.accountType,
13
+ operatingRut: input.selfRut,
14
+ operable: input.operable,
15
+ };
16
+ await store.write(OPERATE_KEY, state);
17
+ return state;
18
+ }
19
+ export async function clearOperateState(store) {
20
+ await store.delete(OPERATE_KEY);
21
+ }
22
+ /** Validate + canonicalise an operate target against the cached operable set —
23
+ * SELECTS, never mints (ADR-005). Throws `ValidationError` for an empresa account
24
+ * (no operate capability) or a RUT outside the operable set. Shared by the
25
+ * persistent `operate` command AND the per-call `--rut` override so both enforce the
26
+ * same value-domain (CONVENTIONS: `--rut` is the operable set, not a separate concept). */
27
+ export function resolveOperableTarget(state, target) {
28
+ if (state.accountType === 'empresa') {
29
+ throw new ValidationError('Una cuenta empresa no puede operar a nombre de otra.');
30
+ }
31
+ const parsed = Rut.parse(target);
32
+ if (!state.operable.some((e) => e.rut === parsed.canonical)) {
33
+ throw new ValidationError(`RUT ${parsed.formatted} no está en el conjunto operable. Revisa los RUT autorizados con \`sii operate --list\`.`);
34
+ }
35
+ return parsed.canonical;
36
+ }
37
+ /** Set the operating RUT, validated against the cached operable set. SELECTS,
38
+ * never mints (ADR-005). Accepts any RUT format. */
39
+ export async function setOperatingRut(store, target) {
40
+ const state = await readOperateState(store);
41
+ if (!state) {
42
+ throw new ValidationError('No hay sesión activa. Ejecuta `sii auth login` primero.');
43
+ }
44
+ const next = { ...state, operatingRut: resolveOperableTarget(state, target) };
45
+ await store.write(OPERATE_KEY, next);
46
+ return next;
47
+ }
48
+ /** Reset the operating RUT back to self. */
49
+ export async function clearOperatingRut(store) {
50
+ const state = await readOperateState(store);
51
+ if (!state) {
52
+ throw new ValidationError('No hay sesión activa. Ejecuta `sii auth login` primero.');
53
+ }
54
+ const next = { ...state, operatingRut: state.selfRut };
55
+ await store.write(OPERATE_KEY, next);
56
+ return next;
57
+ }
58
+ export function operatingContext(state) {
59
+ const isSelf = state.operatingRut === state.selfRut;
60
+ const entry = state.operable.find((e) => e.rut === state.operatingRut);
61
+ return {
62
+ operatingRut: state.operatingRut,
63
+ selfRut: state.selfRut,
64
+ isSelf,
65
+ razonSocial: entry?.razonSocial ?? null,
66
+ };
67
+ }
68
+ /** Render the operating context as the shared `Operando como …` display line
69
+ * (the CLI STDERR header / `operate` output and the MCP `sii://operating`
70
+ * resource + `operate` tool used to carry verbatim copies of this). The razón
71
+ * social only appears for a represented empresa — never for self (own-name PII
72
+ * stays off the line). */
73
+ export function describeOperating(ctx) {
74
+ if (ctx.isSelf)
75
+ return `Operando como tú mismo: ${Rut.parse(ctx.operatingRut).formatted}.`;
76
+ const name = ctx.razonSocial ? ` (${ctx.razonSocial})` : '';
77
+ return `Operando como ${Rut.parse(ctx.operatingRut).formatted}${name}.`;
78
+ }
79
+ /** Render one operable entry as a single display line (shared by CLI `operate --list`
80
+ * and the MCP `operate list=true` tool, so the format stays in one place):
81
+ * `<rut>[ <razón social>][ (tú mismo, operando ahora)]`. Razón social falls back to
82
+ * the RUT when SII returned no name — omit it then so the RUT isn't repeated. */
83
+ export function formatOperableEntry(entry, operatingRut) {
84
+ const marks = [
85
+ entry.isSelf ? 'tú mismo' : null,
86
+ entry.rut === operatingRut ? 'operando ahora' : null,
87
+ ]
88
+ .filter(Boolean)
89
+ .join(', ');
90
+ const name = entry.razonSocial && entry.razonSocial !== entry.rut ? ` ${entry.razonSocial}` : '';
91
+ return `${Rut.parse(entry.rut).formatted}${name}${marks ? ` (${marks})` : ''}`;
92
+ }
93
+ //# sourceMappingURL=identity.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"identity.js","sourceRoot":"","sources":["../../src/identity/identity.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAsBtC,sFAAsF;AACtF,MAAM,WAAW,GAAG,SAAS,CAAC;AAE9B,MAAM,CAAC,KAAK,UAAU,gBAAgB,CA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AC,MAAM;QAAE,OAAO,2BAA2B,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC,SAAS,GAAG,CAAC;IAC3F,MAAM,IAAI,GAAG,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,WAAW,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;IAC5D,OAAO,iBAAiB,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC,SAAS,GAAG,IAAI,GAAG,CAAC;AAC1E,CAAC;AAED;;;kFAGkF;AAClF,MAAM,UAAU,mBAAmB,CAAC,KAAoB,EAAE,YAAoB;IAC5E,MAAM,KAAK,GAAG;QACZ,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI;QAChC,KAAK,CAAC,GAAG,KAAK,YAAY,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,IAAI;KACrD;SACE,MAAM,CAAC,OAAO,CAAC;SACf,IAAI,CAAC,IAAI,CAAC,CAAC;IACd,MAAM,IAAI,GAAG,KAAK,CAAC,WAAW,IAAI,KAAK,CAAC,WAAW,KAAK,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IACjG,OAAO,GAAG,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,SAAS,GAAG,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,KAAK,KAAK,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;AACjF,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from './identity.js';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/identity/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from './identity.js';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/identity/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC"}
@@ -0,0 +1,24 @@
1
+ export { login, logout, authStatus, statusRefresh } from './tasks/auth.js';
2
+ export type { AuthIdentity, AuthLoginResult, AuthLogoutResult, AuthStatusLocal, } from './tasks/auth.js';
3
+ export { operate, operateSelf, operatingStatus, listOperable } from './tasks/operate.js';
4
+ export type { OperateResult, OperableList } from './tasks/operate.js';
5
+ export { describeOperating, formatOperableEntry } from './identity/index.js';
6
+ export type { OperatingContext, OperableEntry } from './identity/index.js';
7
+ export { rcvSummary, rcvList } from './tasks/rcv.js';
8
+ export type { RcvResumen, RcvResumenRow, RcvDetalle, RcvDetalleDoc, RcvSide } from './tasks/rcv.js';
9
+ export { f22Status, f22Overview, f22Observaciones, f22Historial } from './tasks/f22.js';
10
+ export type { F22Estado, F22Declaraciones, F22Overview, F22Observaciones, F22Historial, F22Grupos, DeclaracionF22, CodigoF22, EventoF22, ObservacionF22, } from './tasks/f22.js';
11
+ export { f29Formulario, f29Overview, f29Status, F29_GRUPO_LABELS } from './tasks/f29.js';
12
+ export type { F29Formulario, F29Overview, F29OverviewArgs, MesF29, LineaF29, F29Grupo, F29Estado, F29Propuesta, CodigoF29, DeclaracionEstadoF29, } from './tasks/f29.js';
13
+ export { dteAuthorized } from './tasks/dte.js';
14
+ export type { DteAutorizados, DteAutorizado } from './tasks/dte.js';
15
+ export { bteList, bteEmitPreview, bteEmit } from './tasks/bte.js';
16
+ export type { BteMensual, BteBoleta, BteTotales, BteSide, BteEmitArgs, BteEmitResult, BteEmitida, BtePreview, BteRetiene, BteLineaEmision, } from './tasks/bte.js';
17
+ export type { AuditEntry, AuditSink, Clock, CredentialLoginOptions, InteractiveLoginOptions, KeyValueStore, PortalDriver, PortalSession, Runtime, SecretStore, } from './seams/index.js';
18
+ export { Rut } from './rut/index.js';
19
+ export { formatMoney, formatRut } from './format/index.js';
20
+ export { Periodo, Anio } from './periodo/index.js';
21
+ export { HOSTS, LOGIN_HOST } from './config/index.js';
22
+ export * from './errors/index.js';
23
+ export * as testing from './adapters/fake/index.js';
24
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +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,iBAAiB,CAAC;AAC3E,YAAY,EACV,YAAY,EACZ,eAAe,EACf,gBAAgB,EAChB,eAAe,GAChB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACzF,YAAY,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACtE,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC7E,YAAY,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAC3E,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AACrD,YAAY,EAAE,UAAU,EAAE,aAAa,EAAE,UAAU,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AACpG,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACxF,YAAY,EACV,SAAS,EACT,gBAAgB,EAChB,WAAW,EACX,gBAAgB,EAChB,YAAY,EACZ,SAAS,EACT,cAAc,EACd,SAAS,EACT,SAAS,EACT,cAAc,GACf,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AACzF,YAAY,EACV,aAAa,EACb,WAAW,EACX,eAAe,EACf,MAAM,EACN,QAAQ,EACR,QAAQ,EACR,SAAS,EACT,YAAY,EACZ,SAAS,EACT,oBAAoB,GACrB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/C,YAAY,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AACpE,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAClE,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;AAKxB,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 ADDED
@@ -0,0 +1,24 @@
1
+ // Public API of @albertomarturelo/sii-core. Surfaces (CLI, MCP) import ONLY from here — the task
2
+ // layer plus the seam interfaces + the runtime factory (ADR-003). Reaching into
3
+ // a sub-module (auth/portal/identity internals) from a surface is forbidden.
4
+ // --- tasks: the public operations ---
5
+ // NOTE: `consoleLogin` (takes a Clave) is intentionally NOT here — it lives in the
6
+ // CLI-only subpath `@albertomarturelo/sii-core/cli`, so the MCP server (which imports this barrel)
7
+ // cannot wire a password-taking task (ADR-006).
8
+ export { login, logout, authStatus, statusRefresh } from './tasks/auth.js';
9
+ export { operate, operateSelf, operatingStatus, listOperable } from './tasks/operate.js';
10
+ export { describeOperating, formatOperableEntry } from './identity/index.js';
11
+ export { rcvSummary, rcvList } from './tasks/rcv.js';
12
+ export { f22Status, f22Overview, f22Observaciones, f22Historial } from './tasks/f22.js';
13
+ export { f29Formulario, f29Overview, f29Status, F29_GRUPO_LABELS } from './tasks/f29.js';
14
+ export { dteAuthorized } from './tasks/dte.js';
15
+ export { bteList, bteEmitPreview, bteEmit } from './tasks/bte.js';
16
+ // --- shared primitives ---
17
+ export { Rut } from './rut/index.js';
18
+ export { formatMoney, formatRut } from './format/index.js';
19
+ export { Periodo, Anio } from './periodo/index.js';
20
+ export { HOSTS, LOGIN_HOST } from './config/index.js';
21
+ export * from './errors/index.js';
22
+ // --- testing helpers: in-memory fakes for surface / integration tests ---
23
+ export * as testing from './adapters/fake/index.js';
24
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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,iBAAiB,CAAC;AAO3E,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,MAAM,gBAAgB,CAAC;AAErD,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAaxF,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAazF,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAE/C,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AA8BlE,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,EAAE,MAAM,mBAAmB,CAAC;AACtD,cAAc,mBAAmB,CAAC;AAElC,2EAA2E;AAC3E,OAAO,KAAK,OAAO,MAAM,0BAA0B,CAAC"}
package/dist/node.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ import type { Runtime } from './seams/index.js';
2
+ export { FileAuditSink, FileKeyValueStore, SII_DIR, SystemClock } from './adapters/node/index.js';
3
+ export { PlaywrightPortalDriver } from './adapters/node/portal.js';
4
+ /** Composition root: the Node default adapters, any seam replaceable (ADR-016).
5
+ * e.g. `createNodeRuntime({ audit: myAuditSink })` keeps the other three defaults.
6
+ * The default portal is the Playwright driver — its `playwright` OPTIONAL peer is
7
+ * loaded lazily on first use, so composing (or overriding `portal`) never needs it. */
8
+ export declare function createNodeRuntime(overrides?: Partial<Runtime>): Runtime;
9
+ //# sourceMappingURL=node.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../src/node.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAEhD,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAClG,OAAO,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AAEnE;;;wFAGwF;AACxF,wBAAgB,iBAAiB,CAAC,SAAS,GAAE,OAAO,CAAC,OAAO,CAAM,GAAG,OAAO,CAQ3E"}
package/dist/node.js ADDED
@@ -0,0 +1,22 @@
1
+ // Composition subpath `@albertomarturelo/sii-core/node` (ADR-016): the Node default
2
+ // adapters plus the composition root. Kept OFF the main barrel so importing the
3
+ // library's tasks/primitives never evaluates node:* or playwright — a consumer
4
+ // that injects its own seams (ADR-003) stays free of them entirely.
5
+ import { FileAuditSink, FileKeyValueStore, SystemClock } from './adapters/node/index.js';
6
+ import { PlaywrightPortalDriver } from './adapters/node/portal.js';
7
+ export { FileAuditSink, FileKeyValueStore, SII_DIR, SystemClock } from './adapters/node/index.js';
8
+ export { PlaywrightPortalDriver } from './adapters/node/portal.js';
9
+ /** Composition root: the Node default adapters, any seam replaceable (ADR-016).
10
+ * e.g. `createNodeRuntime({ audit: myAuditSink })` keeps the other three defaults.
11
+ * The default portal is the Playwright driver — its `playwright` OPTIONAL peer is
12
+ * loaded lazily on first use, so composing (or overriding `portal`) never needs it. */
13
+ export function createNodeRuntime(overrides = {}) {
14
+ return {
15
+ clock: new SystemClock(),
16
+ audit: new FileAuditSink(),
17
+ store: new FileKeyValueStore(),
18
+ portal: new PlaywrightPortalDriver(),
19
+ ...overrides,
20
+ };
21
+ }
22
+ //# sourceMappingURL=node.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node.js","sourceRoot":"","sources":["../src/node.ts"],"names":[],"mappings":"AAAA,oFAAoF;AACpF,gFAAgF;AAChF,+EAA+E;AAC/E,oEAAoE;AACpE,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACzF,OAAO,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AAGnE,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAClG,OAAO,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AAEnE;;;wFAGwF;AACxF,MAAM,UAAU,iBAAiB,CAAC,YAA8B,EAAE;IAChE,OAAO;QACL,KAAK,EAAE,IAAI,WAAW,EAAE;QACxB,KAAK,EAAE,IAAI,aAAa,EAAE;QAC1B,KAAK,EAAE,IAAI,iBAAiB,EAAE;QAC9B,MAAM,EAAE,IAAI,sBAAsB,EAAE;QACpC,GAAG,SAAS;KACb,CAAC;AACJ,CAAC"}
@@ -0,0 +1,15 @@
1
+ /** A validated **año tributario** (tax year), canonical `YYYY`. Sibling of `Periodo`
2
+ * (which is month-granularity, YYYYMM) for the annual surfaces. SII semantics: AT N
3
+ * reports año comercial N−1's income (AT 2025 = rentas 2024). The value is passed to
4
+ * SII's `periodo` field verbatim — no adjustment here. */
5
+ export declare class Anio {
6
+ readonly value: number;
7
+ private constructor();
8
+ /** Parse + validate a 4-digit year (string or number). */
9
+ static parse(input: string | number): Anio;
10
+ static of(year: number): Anio;
11
+ static tryParse(input: string | number): Anio | null;
12
+ /** Canonical `YYYY` — what SII's F22 `periodo` field takes. */
13
+ get canonical(): string;
14
+ }
15
+ //# sourceMappingURL=anio.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"anio.d.ts","sourceRoot":"","sources":["../../src/periodo/anio.ts"],"names":[],"mappings":"AAOA;;;2DAG2D;AAC3D,qBAAa,IAAI;IACK,QAAQ,CAAC,KAAK,EAAE,MAAM;IAA1C,OAAO;IAEP,0DAA0D;IAC1D,MAAM,CAAC,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAQ1C,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAS7B,MAAM,CAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,IAAI;IAQpD,+DAA+D;IAC/D,IAAI,SAAS,IAAI,MAAM,CAEtB;CACF"}
@@ -0,0 +1,42 @@
1
+ import { ValidationError } from '../errors/index.js';
2
+ // Tax years for the annual surfaces (F22 renta). SII's electronic renta era is
3
+ // recent; bound loosely and let SII reject truly out-of-range years server-side.
4
+ const MIN_YEAR = 2000;
5
+ const MAX_YEAR = 2100;
6
+ /** A validated **año tributario** (tax year), canonical `YYYY`. Sibling of `Periodo`
7
+ * (which is month-granularity, YYYYMM) for the annual surfaces. SII semantics: AT N
8
+ * reports año comercial N−1's income (AT 2025 = rentas 2024). The value is passed to
9
+ * SII's `periodo` field verbatim — no adjustment here. */
10
+ export class Anio {
11
+ value;
12
+ constructor(value) {
13
+ this.value = value;
14
+ }
15
+ /** Parse + validate a 4-digit year (string or number). */
16
+ static parse(input) {
17
+ const s = String(input).trim();
18
+ if (!/^\d{4}$/.test(s)) {
19
+ throw new ValidationError(`Año tributario inválido: "${input}" (esperado YYYY).`);
20
+ }
21
+ return Anio.of(Number(s));
22
+ }
23
+ static of(year) {
24
+ if (!Number.isInteger(year) || year < MIN_YEAR || year > MAX_YEAR) {
25
+ throw new ValidationError(`Año tributario fuera de rango: ${year} (${MIN_YEAR}–${MAX_YEAR}).`);
26
+ }
27
+ return new Anio(year);
28
+ }
29
+ static tryParse(input) {
30
+ try {
31
+ return Anio.parse(input);
32
+ }
33
+ catch {
34
+ return null;
35
+ }
36
+ }
37
+ /** Canonical `YYYY` — what SII's F22 `periodo` field takes. */
38
+ get canonical() {
39
+ return String(this.value);
40
+ }
41
+ }
42
+ //# sourceMappingURL=anio.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"anio.js","sourceRoot":"","sources":["../../src/periodo/anio.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAErD,+EAA+E;AAC/E,iFAAiF;AACjF,MAAM,QAAQ,GAAG,IAAI,CAAC;AACtB,MAAM,QAAQ,GAAG,IAAI,CAAC;AAEtB;;;2DAG2D;AAC3D,MAAM,OAAO,IAAI;IACc;IAA7B,YAA6B,KAAa;QAAb,UAAK,GAAL,KAAK,CAAQ;IAAG,CAAC;IAE9C,0DAA0D;IAC1D,MAAM,CAAC,KAAK,CAAC,KAAsB;QACjC,MAAM,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,CAAC;QAC/B,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;YACvB,MAAM,IAAI,eAAe,CAAC,6BAA6B,KAAK,oBAAoB,CAAC,CAAC;QACpF,CAAC;QACD,OAAO,IAAI,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;IAC5B,CAAC;IAED,MAAM,CAAC,EAAE,CAAC,IAAY;QACpB,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,IAAI,GAAG,QAAQ,IAAI,IAAI,GAAG,QAAQ,EAAE,CAAC;YAClE,MAAM,IAAI,eAAe,CACvB,kCAAkC,IAAI,KAAK,QAAQ,IAAI,QAAQ,IAAI,CACpE,CAAC;QACJ,CAAC;QACD,OAAO,IAAI,IAAI,CAAC,IAAI,CAAC,CAAC;IACxB,CAAC;IAED,MAAM,CAAC,QAAQ,CAAC,KAAsB;QACpC,IAAI,CAAC;YACH,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QAC3B,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;IAED,+DAA+D;IAC/D,IAAI,SAAS;QACX,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC5B,CAAC;CACF"}
@@ -0,0 +1,3 @@
1
+ export * from './periodo.js';
2
+ export * from './anio.js';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/periodo/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC"}
@@ -0,0 +1,3 @@
1
+ export * from './periodo.js';
2
+ export * from './anio.js';
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/periodo/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC"}
@@ -0,0 +1,19 @@
1
+ /** A validated tax period at month granularity. Canonical machine form is `YYYYMM`
2
+ * (what SII's portal payloads expect, e.g. RCV `ptributario`). In-house — mirrors
3
+ * the `Rut` primitive's shape (parse / canonical / formatted). */
4
+ export declare class Periodo {
5
+ readonly year: number;
6
+ readonly month: number;
7
+ private constructor();
8
+ /** Parse + validate. Accepts `YYYYMM`, and `YYYY-MM` / `YYYY/MM` / `YYYY.MM` with a
9
+ * one- OR two-digit month (`2026-5` and `2026-05` both → May 2026). */
10
+ static parse(input: string): Periodo;
11
+ /** Build from numeric year + month, validating both. */
12
+ static of(year: number, month: number): Periodo;
13
+ static tryParse(input: string): Periodo | null;
14
+ /** Machine form SII expects: `YYYYMM` (e.g. `202606`). */
15
+ get canonical(): string;
16
+ /** Human form `YYYY-MM` (e.g. `2026-06`). */
17
+ get formatted(): string;
18
+ }
19
+ //# sourceMappingURL=periodo.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"periodo.d.ts","sourceRoot":"","sources":["../../src/periodo/periodo.ts"],"names":[],"mappings":"AAOA;;mEAEmE;AACnE,qBAAa,OAAO;IAEhB,QAAQ,CAAC,IAAI,EAAE,MAAM;IACrB,QAAQ,CAAC,KAAK,EAAE,MAAM;IAFxB,OAAO;IAKP;4EACwE;IACxE,MAAM,CAAC,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;IAUpC,wDAAwD;IACxD,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO;IAY/C,MAAM,CAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,GAAG,IAAI;IAQ9C,0DAA0D;IAC1D,IAAI,SAAS,IAAI,MAAM,CAEtB;IAED,6CAA6C;IAC7C,IAAI,SAAS,IAAI,MAAM,CAEtB;CACF"}
@@ -0,0 +1,55 @@
1
+ import { ValidationError } from '../errors/index.js';
2
+ // SII's RCV launched Aug 2017; allow a generous margin and let SII reject truly
3
+ // out-of-range periods server-side (verbatim). The bounds only catch typos locally.
4
+ const MIN_YEAR = 2000;
5
+ const MAX_YEAR = 2100;
6
+ /** A validated tax period at month granularity. Canonical machine form is `YYYYMM`
7
+ * (what SII's portal payloads expect, e.g. RCV `ptributario`). In-house — mirrors
8
+ * the `Rut` primitive's shape (parse / canonical / formatted). */
9
+ export class Periodo {
10
+ year;
11
+ month;
12
+ constructor(year, month) {
13
+ this.year = year;
14
+ this.month = month;
15
+ }
16
+ /** Parse + validate. Accepts `YYYYMM`, and `YYYY-MM` / `YYYY/MM` / `YYYY.MM` with a
17
+ * one- OR two-digit month (`2026-5` and `2026-05` both → May 2026). */
18
+ static parse(input) {
19
+ const trimmed = input.trim();
20
+ const sep = /^(\d{4})[-/.](\d{1,2})$/.exec(trimmed);
21
+ if (sep)
22
+ return Periodo.of(Number(sep[1]), Number(sep[2]));
23
+ if (/^\d{6}$/.test(trimmed)) {
24
+ return Periodo.of(Number(trimmed.slice(0, 4)), Number(trimmed.slice(4)));
25
+ }
26
+ throw new ValidationError(`Período inválido: "${input}" (esperado YYYYMM o YYYY-MM).`);
27
+ }
28
+ /** Build from numeric year + month, validating both. */
29
+ static of(year, month) {
30
+ if (!Number.isInteger(month) || month < 1 || month > 12) {
31
+ throw new ValidationError(`Período con mes inválido: ${month} (esperado 1–12).`);
32
+ }
33
+ if (!Number.isInteger(year) || year < MIN_YEAR || year > MAX_YEAR) {
34
+ throw new ValidationError(`Período con año fuera de rango: ${year} (${MIN_YEAR}–${MAX_YEAR}).`);
35
+ }
36
+ return new Periodo(year, month);
37
+ }
38
+ static tryParse(input) {
39
+ try {
40
+ return Periodo.parse(input);
41
+ }
42
+ catch {
43
+ return null;
44
+ }
45
+ }
46
+ /** Machine form SII expects: `YYYYMM` (e.g. `202606`). */
47
+ get canonical() {
48
+ return `${String(this.year).padStart(4, '0')}${String(this.month).padStart(2, '0')}`;
49
+ }
50
+ /** Human form `YYYY-MM` (e.g. `2026-06`). */
51
+ get formatted() {
52
+ return `${String(this.year).padStart(4, '0')}-${String(this.month).padStart(2, '0')}`;
53
+ }
54
+ }
55
+ //# sourceMappingURL=periodo.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"periodo.js","sourceRoot":"","sources":["../../src/periodo/periodo.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAErD,gFAAgF;AAChF,oFAAoF;AACpF,MAAM,QAAQ,GAAG,IAAI,CAAC;AACtB,MAAM,QAAQ,GAAG,IAAI,CAAC;AAEtB;;mEAEmE;AACnE,MAAM,OAAO,OAAO;IAEP;IACA;IAFX,YACW,IAAY,EACZ,KAAa;QADb,SAAI,GAAJ,IAAI,CAAQ;QACZ,UAAK,GAAL,KAAK,CAAQ;IACrB,CAAC;IAEJ;4EACwE;IACxE,MAAM,CAAC,KAAK,CAAC,KAAa;QACxB,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;QAC7B,MAAM,GAAG,GAAG,yBAAyB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACpD,IAAI,GAAG;YAAE,OAAO,OAAO,CAAC,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAC3D,IAAI,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;YAC5B,OAAO,OAAO,CAAC,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,O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,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC;IACxF,CAAC;CACF"}
@@ -0,0 +1,9 @@
1
+ /** region index (1–16) → { comuna code → NAME } (SII internal codes, exactly as the form). */
2
+ export declare const COMUNAS: Readonly<Record<number, Readonly<Record<number, string>>>>;
3
+ /** A valid SII region index for BHE emission (1–16). */
4
+ export declare function isRegion(cod: number): boolean;
5
+ /** The comuna code belongs to the region (both must be the SII codes from GLB_comunas.js). */
6
+ export declare function comunaInRegion(region: number, comuna: number): boolean;
7
+ /** The comuna NAME the form sends as txt_comuna_destinatario, or null if the pair is unknown. */
8
+ export declare function comunaName(region: number, comuna: number): string | null;
9
+ //# sourceMappingURL=bte-comunas.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bte-comunas.d.ts","sourceRoot":"","sources":["../../src/portal/bte-comunas.ts"],"names":[],"mappings":"AAOA,8FAA8F;AAC9F,eAAO,MAAM,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,CA2X9E,CAAC;AAEF,wDAAwD;AACxD,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAE7C;AAED,8FAA8F;AAC9F,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAEtE;AAED,iGAAiG;AACjG,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAExE"}