@devly-cl/sii-client 0.7.1 → 0.7.11

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 (70) hide show
  1. package/README.md +84 -1
  2. package/dist/application/document-status.d.ts +5 -5
  3. package/dist/application/document-status.js +14 -9
  4. package/dist/application/dte-import-mapper.d.ts +8 -0
  5. package/dist/application/dte-import-mapper.js +25 -0
  6. package/dist/application/dte-import-model.d.ts +28 -0
  7. package/dist/application/dte-import-model.js +2 -0
  8. package/dist/application/dte-import.d.ts +37 -0
  9. package/dist/application/dte-import.js +352 -0
  10. package/dist/application/invoice-queries.d.ts +12 -6
  11. package/dist/application/invoice-queries.js +9 -5
  12. package/dist/application/issuance.d.ts +2 -2
  13. package/dist/application/issuance.js +26 -10
  14. package/dist/contracts.d.ts +32 -0
  15. package/dist/contracts.js +17 -0
  16. package/dist/domain/civil-date.d.ts +2 -0
  17. package/dist/domain/civil-date.js +10 -0
  18. package/dist/domain/document-status.d.ts +0 -4
  19. package/dist/domain/document-status.js +18 -11
  20. package/dist/domain/document.js +49 -9
  21. package/dist/domain/dte-arithmetic.d.ts +35 -0
  22. package/dist/domain/dte-arithmetic.js +78 -0
  23. package/dist/domain/dte-components.d.ts +9 -0
  24. package/dist/domain/dte-components.js +37 -0
  25. package/dist/domain/dte-detail.d.ts +111 -0
  26. package/dist/domain/dte-detail.js +2 -0
  27. package/dist/domain/dte-identity.d.ts +19 -0
  28. package/dist/domain/dte-identity.js +52 -0
  29. package/dist/domain/dte-money.d.ts +41 -0
  30. package/dist/domain/dte-money.js +81 -0
  31. package/dist/domain/dte-reconciliation-model.d.ts +87 -0
  32. package/dist/domain/dte-reconciliation-model.js +2 -0
  33. package/dist/domain/dte-reconciliation.d.ts +15 -0
  34. package/dist/domain/dte-reconciliation.js +390 -0
  35. package/dist/domain/dte-validation.d.ts +7 -0
  36. package/dist/domain/dte-validation.js +84 -0
  37. package/dist/domain/invoice-xml.d.ts +17 -57
  38. package/dist/domain/invoice-xml.js +0 -10
  39. package/dist/domain/invoicing.d.ts +30 -4
  40. package/dist/domain/invoicing.js +75 -21
  41. package/dist/domain/issued-invoice.d.ts +0 -6
  42. package/dist/domain/rcv-document.d.ts +0 -4
  43. package/dist/domain/received-invoice.d.ts +1 -4
  44. package/dist/index.d.ts +19 -9
  45. package/dist/index.js +20 -4
  46. package/dist/infrastructure/document-status-gateway.d.ts +6 -4
  47. package/dist/infrastructure/document-status-gateway.js +34 -13
  48. package/dist/infrastructure/document-status-parser.js +38 -12
  49. package/dist/infrastructure/dte-xml-mapper.d.ts +16 -0
  50. package/dist/infrastructure/dte-xml-mapper.js +381 -0
  51. package/dist/infrastructure/dte-xml.d.ts +40 -4
  52. package/dist/infrastructure/dte-xml.js +117 -196
  53. package/dist/infrastructure/facturador-gateway.d.ts +10 -7
  54. package/dist/infrastructure/facturador-gateway.js +256 -56
  55. package/dist/infrastructure/facturador.d.ts +1 -1
  56. package/dist/infrastructure/facturador.js +18 -10
  57. package/dist/infrastructure/invoice-pdf.js +10 -3
  58. package/dist/infrastructure/rcv-gateway.d.ts +7 -4
  59. package/dist/infrastructure/rcv-gateway.js +53 -12
  60. package/dist/infrastructure/rcv-normalization.d.ts +8 -1
  61. package/dist/infrastructure/rcv-normalization.js +54 -12
  62. package/dist/infrastructure/read-options.d.ts +3 -0
  63. package/dist/infrastructure/read-options.js +25 -0
  64. package/dist/infrastructure/sii-client.d.ts +98 -13
  65. package/dist/infrastructure/sii-client.js +182 -31
  66. package/dist/infrastructure/sii-http-session.d.ts +2 -2
  67. package/dist/infrastructure/sii-http-session.js +134 -37
  68. package/dist/sii-error.d.ts +5 -0
  69. package/dist/sii-error.js +39 -13
  70. package/package.json +2 -2
@@ -1,7 +1,8 @@
1
- import { type IssuedInvoicesQuery, type IssuedInvoicesResult } from '../domain/issued-invoice';
2
- import type { ReceivedInvoicesQuery, ReceivedInvoicesResult } from '../domain/received-invoice';
3
- import type { RcvDocumentsQuery, RcvDocumentsResult } from '../domain/rcv-document';
4
- import type { AuthorizedCompany, SummaryQuery, SiiResponse } from '../contracts';
1
+ import { type IssuedInvoicesResult } from '../domain/issued-invoice';
2
+ import type { ReceivedInvoicesResult } from '../domain/received-invoice';
3
+ import type { RcvDocumentsResult } from '../domain/rcv-document';
4
+ import type { AuthorizedCompany, IssuedInvoicesQuery, RcvDocumentsQuery, ReceivedInvoicesQuery, SiiResponse, SummaryQuery } from '../contracts';
5
+ import type { ExactDte } from '../domain/dte-money';
5
6
  import { SiiHttpSession } from './sii-http-session';
6
7
  export declare class RcvGateway {
7
8
  #private;
@@ -17,4 +18,6 @@ export declare class RcvGateway {
17
18
  receivedInvoices(input: ReceivedInvoicesQuery): Promise<ReceivedInvoicesResult>;
18
19
  issuedDocuments(input: RcvDocumentsQuery): Promise<RcvDocumentsResult>;
19
20
  receivedDocuments(input: RcvDocumentsQuery): Promise<RcvDocumentsResult>;
21
+ issuedDocumentsExact(input: RcvDocumentsQuery): Promise<ExactDte<RcvDocumentsResult>>;
22
+ receivedDocumentsExact(input: RcvDocumentsQuery): Promise<ExactDte<RcvDocumentsResult>>;
20
23
  }
@@ -16,7 +16,10 @@ class RcvGateway {
16
16
  this.session = session;
17
17
  }
18
18
  companies(identity = this.session.assertReady()) {
19
- return this.#call('getDcvEmpresasAutorizadas', { rutAutenticado: identity.rut, dvAutenticado: identity.dv });
19
+ return this.#call('getDcvEmpresasAutorizadas', {
20
+ rutAutenticado: identity.rut,
21
+ dvAutenticado: identity.dv
22
+ });
20
23
  }
21
24
  async summary({ periodo, operacion, estado = 'REGISTRO' }) {
22
25
  this.session.assertReady();
@@ -26,14 +29,38 @@ class RcvGateway {
26
29
  if (!STATES.has(estado) || (operacion === 'VENTA' && estado !== 'REGISTRO'))
27
30
  throw new TypeError('Estado inválido');
28
31
  const company = this.session.company;
29
- return this.#call('getResumen', { rutEmisor: company.rut, dvEmisor: company.dv, ptributario: periodo, estadoContab: estado, operacion });
32
+ return this.#call('getResumen', {
33
+ rutEmisor: company.rut,
34
+ dvEmisor: company.dv,
35
+ ptributario: periodo,
36
+ estadoContab: estado,
37
+ operacion
38
+ });
39
+ }
40
+ issuedInvoices(input) {
41
+ return this.#documents('VENTA', input, isInvoiceType, rcv_normalization_1.normalizeIssuedInvoice);
42
+ }
43
+ receivedInvoices(input) {
44
+ return this.#documents('COMPRA', input, isInvoiceType, rcv_normalization_1.normalizeReceivedInvoice);
45
+ }
46
+ issuedDocuments(input) {
47
+ return this.#documents('VENTA', input, isDocumentType, rcv_normalization_1.normalizeIssuedDocument);
48
+ }
49
+ receivedDocuments(input) {
50
+ return this.#documents('COMPRA', input, isDocumentType, rcv_normalization_1.normalizeReceivedDocument);
51
+ }
52
+ issuedDocumentsExact(input) {
53
+ return this.#documents('VENTA', input, isDocumentType, rcv_normalization_1.normalizeIssuedDocumentExact);
54
+ }
55
+ receivedDocumentsExact(input) {
56
+ return this.#documents('COMPRA', input, isDocumentType, rcv_normalization_1.normalizeReceivedDocumentExact);
30
57
  }
31
- issuedInvoices(input) { return this.#documents('VENTA', input, isInvoiceType, rcv_normalization_1.normalizeIssuedInvoice); }
32
- receivedInvoices(input) { return this.#documents('COMPRA', input, isInvoiceType, rcv_normalization_1.normalizeReceivedInvoice); }
33
- issuedDocuments(input) { return this.#documents('VENTA', input, isDocumentType, rcv_normalization_1.normalizeIssuedDocument); }
34
- receivedDocuments(input) { return this.#documents('COMPRA', input, isDocumentType, rcv_normalization_1.normalizeReceivedDocument); }
35
58
  async #documents(operation, input, supported, normalize) {
36
59
  this.session.assertReady();
60
+ (0, issued_invoice_1.assertPeriod)(input.periodo);
61
+ const { tokenRecaptcha = 't-o-k-e-n-web' } = input;
62
+ if (typeof tokenRecaptcha !== 'string' || !tokenRecaptcha.trim())
63
+ throw new TypeError('tokenRecaptcha inválido');
37
64
  const detailMethod = operation === 'COMPRA' ? 'getDetalleCompra' : 'getDetalleVenta';
38
65
  try {
39
66
  return await (0, invoice_queries_1.readDocuments)({
@@ -57,11 +84,17 @@ class RcvGateway {
57
84
  return [{ documentType: type, count }];
58
85
  });
59
86
  },
60
- details: async (type, tokenRecaptcha) => {
87
+ details: async (type) => {
61
88
  const company = this.session.company;
62
89
  const details = await this.#call(detailMethod, {
63
- rutEmisor: company.rut, dvEmisor: company.dv, ptributario: input.periodo,
64
- codTipoDoc: String(type), operacion: operation === 'COMPRA' ? 'COMPRA' : '', estadoContab: operation === 'COMPRA' ? 'REGISTRO' : '', accionRecaptcha: operation === 'COMPRA' ? 'RCV_DETC' : 'RCV_DETV', tokenRecaptcha,
90
+ rutEmisor: company.rut,
91
+ dvEmisor: company.dv,
92
+ ptributario: input.periodo,
93
+ codTipoDoc: String(type),
94
+ operacion: operation === 'COMPRA' ? 'COMPRA' : '',
95
+ estadoContab: operation === 'COMPRA' ? 'REGISTRO' : '',
96
+ accionRecaptcha: operation === 'COMPRA' ? 'RCV_DETC' : 'RCV_DETV',
97
+ tokenRecaptcha,
65
98
  });
66
99
  try {
67
100
  return details.data.map(row => normalize(row, company.formatted, input.periodo, type));
@@ -70,7 +103,7 @@ class RcvGateway {
70
103
  throw this.session.failure('SII_INVALID_RESPONSE', detailMethod, 'INVALID_RESPONSE');
71
104
  }
72
105
  },
73
- }, input);
106
+ }, { periodo: input.periodo });
74
107
  }
75
108
  catch (error) {
76
109
  if (error instanceof invoice_queries_1.InvoiceQueryError)
@@ -101,8 +134,16 @@ class RcvGateway {
101
134
  const { conversationId: _secret, ...metaData } = rawMeta;
102
135
  return { ...result, data: rows, metaData };
103
136
  }, {
104
- method: 'POST', headers: { 'Content-Type': 'application/json', Accept: 'application/json, text/plain, */*', Referer: sii_http_session_1.RCV },
105
- body: JSON.stringify({ metaData: { namespace: NAMESPACE + method, conversationId: token, transactionId: (0, node_crypto_1.randomUUID)(), page: null }, data }),
137
+ method: 'POST',
138
+ headers: { 'Content-Type': 'application/json', Accept: 'application/json, text/plain, */*', Referer: sii_http_session_1.RCV },
139
+ body: JSON.stringify({
140
+ metaData: {
141
+ namespace: NAMESPACE + method,
142
+ conversationId: token,
143
+ transactionId: (0, node_crypto_1.randomUUID)(),
144
+ page: null
145
+ }, data
146
+ }),
106
147
  }, true);
107
148
  }
108
149
  }
@@ -1,11 +1,18 @@
1
- import type { IssuedInvoice, InvoiceDocumentType } from '../domain/issued-invoice';
1
+ import type { InvoiceDocumentType, IssuedInvoice } from '../domain/issued-invoice';
2
2
  import type { ReceivedInvoice } from '../domain/received-invoice';
3
3
  import type { RcvDocumentType } from '../domain/rcv-document';
4
+ import { type ExactDte } from '../domain/dte-money';
4
5
  /** Campos del proveedor validados; emisor y periodo vienen de la consulta autorizada. */
5
6
  export declare function normalizeIssuedInvoice(row: Record<string, unknown>, issuerRut: string, period: string, type: InvoiceDocumentType): IssuedInvoice;
6
7
  export declare function normalizeIssuedDocument<D extends RcvDocumentType>(row: Record<string, unknown>, issuerRut: string, period: string, type: D): Omit<IssuedInvoice, 'documentType'> & {
7
8
  documentType: D;
8
9
  };
10
+ export declare function normalizeIssuedDocumentExact<D extends RcvDocumentType>(row: Record<string, unknown>, issuerRut: string, period: string, type: D): ExactDte<Omit<IssuedInvoice, 'documentType'>> & {
11
+ documentType: D;
12
+ };
13
+ export declare function normalizeReceivedDocumentExact<D extends RcvDocumentType>(row: Record<string, unknown>, receiverRut: string, period: string, type: D): ExactDte<Omit<ReceivedInvoice, 'documentType'>> & {
14
+ documentType: D;
15
+ };
9
16
  /** In purchases detRutDoc identifies the supplier; the authorized company is the receiver. */
10
17
  export declare function normalizeReceivedInvoice(row: Record<string, unknown>, receiverRut: string, period: string, type: InvoiceDocumentType): ReceivedInvoice;
11
18
  export declare function normalizeReceivedDocument<D extends RcvDocumentType>(row: Record<string, unknown>, receiverRut: string, period: string, type: D): Omit<ReceivedInvoice, 'documentType'> & {
@@ -2,15 +2,22 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.normalizeIssuedInvoice = normalizeIssuedInvoice;
4
4
  exports.normalizeIssuedDocument = normalizeIssuedDocument;
5
+ exports.normalizeIssuedDocumentExact = normalizeIssuedDocumentExact;
6
+ exports.normalizeReceivedDocumentExact = normalizeReceivedDocumentExact;
5
7
  exports.normalizeReceivedInvoice = normalizeReceivedInvoice;
6
8
  exports.normalizeReceivedDocument = normalizeReceivedDocument;
9
+ const civil_date_1 = require("../domain/civil-date");
7
10
  const rut_1 = require("../domain/rut");
11
+ const dte_money_1 = require("../domain/dte-money");
12
+ const dte_identity_1 = require("../domain/dte-identity");
8
13
  function integer(value) {
9
14
  if (typeof value !== 'number' || !Number.isSafeInteger(value) || value < 0)
10
15
  throw new TypeError('SII_INVALID_RESPONSE');
11
16
  return value;
12
17
  }
13
- function nullableAmount(value) { return value == null ? null : integer(value); }
18
+ function nullableAmount(value) {
19
+ return value == null ? null : integer(value);
20
+ }
14
21
  function date(value) {
15
22
  if (typeof value !== 'string')
16
23
  throw new TypeError('SII_INVALID_RESPONSE');
@@ -19,18 +26,28 @@ function date(value) {
19
26
  const [year, month, day] = iso ? [iso[1], iso[2], iso[3]] : local ? [local[3], local[2], local[1]] : [];
20
27
  if (!year || !month || !day)
21
28
  throw new TypeError('SII_INVALID_RESPONSE');
22
- const y = Number(year), m = Number(month), d = Number(day);
23
- const days = [31, y % 4 === 0 && (y % 100 !== 0 || y % 400 === 0) ? 29 : 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
24
- if (y < 1 || m < 1 || m > 12 || d < 1 || d > days[m - 1])
29
+ const normalized = `${year}-${month}-${day}`;
30
+ if (Number(year) < 1 || !(0, civil_date_1.isCivilDate)(normalized))
25
31
  throw new TypeError('SII_INVALID_RESPONSE');
26
- return `${year}-${month}-${day}`;
32
+ return normalized;
27
33
  }
28
34
  /** Campos del proveedor validados; emisor y periodo vienen de la consulta autorizada. */
29
35
  function normalizeIssuedInvoice(row, issuerRut, period, type) {
30
36
  return normalizeIssuedDocument(row, issuerRut, period, type);
31
37
  }
32
38
  function normalizeIssuedDocument(row, issuerRut, period, type) {
33
- if (row.detTipoDoc !== type || integer(row.detNroDoc) === 0 || integer(row.detRutDoc) === 0 || typeof row.detDvDoc !== 'string' || !/^[\dKk]$/.test(row.detDvDoc)) {
39
+ integer(row.detNroDoc);
40
+ for (const value of [row.detMntNeto, row.detMntExe, row.detMntIVA])
41
+ nullableAmount(value);
42
+ integer(row.detMntTotal);
43
+ return {
44
+ ...(0, dte_money_1.withNumberDteAmounts)(normalizeIssuedDocumentExact(row, issuerRut, period, type)),
45
+ documentType: type
46
+ };
47
+ }
48
+ function normalizeIssuedDocumentExact(row, issuerRut, period, type) {
49
+ const folio = typeof row.detNroDoc === 'string' ? (0, dte_identity_1.normalizeDteFolio)(row.detNroDoc) : (0, dte_identity_1.normalizeDteFolio)(String(integer(row.detNroDoc)));
50
+ if (row.detTipoDoc !== type || integer(row.detRutDoc) === 0 || typeof row.detDvDoc !== 'string' || !/^[\dKk]$/.test(row.detDvDoc)) {
34
51
  throw new TypeError('SII_INVALID_RESPONSE');
35
52
  }
36
53
  if (row.detRznSoc != null && typeof row.detRznSoc !== 'string')
@@ -43,11 +60,30 @@ function normalizeIssuedDocument(row, issuerRut, period, type) {
43
60
  throw new TypeError('SII_INVALID_RESPONSE');
44
61
  }
45
62
  return {
46
- issuerRut, documentType: type, folio: String(row.detNroDoc), issuedDate: date(row.detFchDoc),
47
- receiverRut, receiverName: typeof row.detRznSoc === 'string' ? row.detRznSoc.trim() || null : null,
48
- netAmount: nullableAmount(row.detMntNeto), exemptAmount: nullableAmount(row.detMntExe),
49
- vatAmount: nullableAmount(row.detMntIVA), totalAmount: integer(row.detMntTotal),
50
- siiBranchCode: row.detCdgSIISucur == null ? null : String(integer(row.detCdgSIISucur)), rcvPeriod: period,
63
+ issuerRut,
64
+ documentType: type,
65
+ folio,
66
+ issuedDate: date(row.detFchDoc),
67
+ receiverRut,
68
+ receiverName: typeof row.detRznSoc === 'string' ? row.detRznSoc.trim() || null : null,
69
+ netAmount: row.detMntNeto == null ? null : (0, dte_money_1.exactDteMoney)(row.detMntNeto),
70
+ exemptAmount: row.detMntExe == null ? null : (0, dte_money_1.exactDteMoney)(row.detMntExe),
71
+ vatAmount: row.detMntIVA == null ? null : (0, dte_money_1.exactDteMoney)(row.detMntIVA),
72
+ totalAmount: (0, dte_money_1.exactDteMoney)(row.detMntTotal),
73
+ siiBranchCode: row.detCdgSIISucur == null ? null : String(integer(row.detCdgSIISucur)),
74
+ rcvPeriod: period,
75
+ };
76
+ }
77
+ function normalizeReceivedDocumentExact(row, receiverRut, period, type) {
78
+ if (row.detTipoDoc != null && row.detTipoDoc !== type)
79
+ throw new TypeError('SII_INVALID_RESPONSE');
80
+ const invoice = normalizeIssuedDocumentExact({ ...row, detTipoDoc: type }, receiverRut, period, type);
81
+ return {
82
+ ...invoice,
83
+ issuerRut: invoice.receiverRut,
84
+ issuerName: invoice.receiverName,
85
+ receiverRut,
86
+ receiverName: null
51
87
  };
52
88
  }
53
89
  /** In purchases detRutDoc identifies the supplier; the authorized company is the receiver. */
@@ -59,5 +95,11 @@ function normalizeReceivedDocument(row, receiverRut, period, type) {
59
95
  if (row.detTipoDoc != null && row.detTipoDoc !== type)
60
96
  throw new TypeError('SII_INVALID_RESPONSE');
61
97
  const invoice = normalizeIssuedDocument({ ...row, detTipoDoc: type }, receiverRut, period, type);
62
- return { ...invoice, issuerRut: invoice.receiverRut, issuerName: invoice.receiverName, receiverRut, receiverName: null };
98
+ return {
99
+ ...invoice,
100
+ issuerRut: invoice.receiverRut,
101
+ issuerName: invoice.receiverName,
102
+ receiverRut,
103
+ receiverName: null
104
+ };
63
105
  }
@@ -0,0 +1,3 @@
1
+ import type { DocumentQueryOptions, DteXmlReadOptions } from '../contracts';
2
+ export declare function assertDteXmlReadOptions(options?: DteXmlReadOptions): void;
3
+ export declare function assertDocumentQueryOptions(options?: DocumentQueryOptions): void;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.assertDteXmlReadOptions = assertDteXmlReadOptions;
4
+ exports.assertDocumentQueryOptions = assertDocumentQueryOptions;
5
+ function assertOptions(value, allowed, message) {
6
+ if (!value || typeof value !== 'object')
7
+ throw new TypeError(message);
8
+ const prototype = Object.getPrototypeOf(value);
9
+ if (prototype !== Object.prototype && prototype !== null || Reflect.ownKeys(value).some(key => typeof key !== 'string' || !allowed.includes(key) || !Object.hasOwn(Object.getOwnPropertyDescriptor(value, key) ?? {}, 'value')))
10
+ throw new TypeError(message);
11
+ }
12
+ function assertDteXmlReadOptions(options) {
13
+ if (options === undefined)
14
+ return;
15
+ assertOptions(options, ['reconcile'], 'Opciones de lectura XML inválidas');
16
+ if (options.reconcile !== undefined && typeof options.reconcile !== 'boolean')
17
+ throw new TypeError('Conciliación XML inválida');
18
+ }
19
+ function assertDocumentQueryOptions(options) {
20
+ if (options === undefined)
21
+ return;
22
+ assertOptions(options, ['signal'], 'Opciones de consulta documental inválidas');
23
+ if (options.signal !== undefined && !(options.signal instanceof AbortSignal))
24
+ throw new TypeError('Señal de consulta documental inválida');
25
+ }
@@ -1,13 +1,14 @@
1
1
  import { type PreparedDocument, type SentDocument } from '../domain/document';
2
- import { type DocumentStatusQuery, type DocumentStatusResult, type RecipientEventsQuery, type RecipientEventsResult, type DocumentQueryOptions } from '../domain/document-status';
2
+ import { type DocumentStatusQuery, type DocumentStatusResult, type RecipientEventsQuery, type RecipientEventsResult } from '../domain/document-status';
3
3
  import type { InvoiceInput } from '../domain/invoicing';
4
4
  import type { CompanyInfo } from '../domain/company-info';
5
- import type { IssuedInvoicesQuery, IssuedInvoicesResult } from '../domain/issued-invoice';
6
- import type { ReceivedInvoicesQuery, ReceivedInvoicesResult } from '../domain/received-invoice';
7
- import type { RcvDocumentsQuery, RcvDocumentsResult } from '../domain/rcv-document';
8
- import type { IssuedInvoiceXmlQuery, ReceivedInvoiceXmlQuery, InvoiceXmlResult, IssuedDocumentXmlQuery, ReceivedDocumentXmlQuery, IssuedDocumentXmlResult } from '../domain/invoice-xml';
9
- import type { AuthorizedCompany, SummaryQuery, SiiResponse, SiiClientOptions, SiiCredentials, SiiSession, IssuedInvoicePdfQuery, ReceivedInvoicePdfQuery, PdfDownloadOptions, InvoicePdfResult } from '../contracts';
5
+ import type { IssuedInvoicesResult } from '../domain/issued-invoice';
6
+ import type { ReceivedInvoicesResult } from '../domain/received-invoice';
7
+ import type { RcvDocumentsResult } from '../domain/rcv-document';
8
+ import type { ExactDteDocumentXmlResult, InvoiceXmlResult, IssuedDocumentXmlQuery, IssuedDocumentXmlResult, IssuedInvoiceXmlQuery, ReceivedDocumentXmlQuery, ReceivedInvoiceXmlQuery } from '../domain/invoice-xml';
9
+ import type { AuthorizedCompany, DocumentQueryOptions, DteXmlReadOptions, InvoicePdfResult, IssuedInvoicePdfQuery, IssuedInvoicesQuery, PdfDownloadOptions, RcvDocumentsQuery, ReceivedInvoicePdfQuery, ReceivedInvoicesQuery, SiiClientOptions, SiiCredentials, SiiResponse, SiiSession, SummaryQuery } from '../contracts';
10
10
  import { type SignDocumentInput } from '../application/issuance';
11
+ import type { ExactDte } from '../domain/dte-money';
11
12
  export { SiiError } from '../sii-error';
12
13
  export type * from '../contracts';
13
14
  export type { PreparedDocument, SignedDocument, SentDocument, DocumentoPreparado, DocumentoFirmado, DocumentoEnviado } from '../domain/document';
@@ -16,28 +17,112 @@ export type { SignDocumentInput, FirmaDocumento } from '../application/issuance'
16
17
  export declare class SiiClient {
17
18
  #private;
18
19
  constructor(options: SiiClientOptions);
20
+ /**
21
+ * Autentica acceso personal y comprueba que la identidad puede operar sobre la empresa fijada en la instancia.
22
+ * Credenciales sólo en memoria; login no se reintenta automáticamente.
23
+ */
19
24
  login(credentials: SiiCredentials): Promise<SiiSession>;
25
+ /**
26
+ * Consulta las empresas autorizadas para la sesión personal. La autorización de actor, tenant y recurso pertenece al consumidor.
27
+ */
20
28
  getAuthorizedCompanies(): Promise<SiiResponse<AuthorizedCompany>>;
29
+ /**
30
+ * Consulta razón social, direcciones y giros observados del RUT indicado, sin preparar ni emitir facturas.
31
+ */
21
32
  getCompanyInfo(rut: string): Promise<CompanyInfo>;
33
+ /**
34
+ * Consulta el resumen RCV de toda la empresa para un período YYYYMM. El consumidor debe autorizar este alcance agregado.
35
+ */
22
36
  getSummary(input: SummaryQuery): Promise<SiiResponse>;
37
+ /**
38
+ * Consulta facturas emitidas 33/34 en RCV; complete indica si los detalles observados cubren el resumen del proveedor.
39
+ */
23
40
  getIssuedInvoices(input: IssuedInvoicesQuery): Promise<IssuedInvoicesResult>;
41
+ /**
42
+ * Consulta facturas recibidas 33/34 en RCV; complete=false exige tratar el resultado como parcial.
43
+ */
24
44
  getReceivedInvoices(input: ReceivedInvoicesQuery): Promise<ReceivedInvoicesResult>;
45
+ /**
46
+ * Consulta documentos emitidos 33/34/61 en RCV, con identidades normalizadas y cobertura explícita.
47
+ */
25
48
  getIssuedDocuments(input: RcvDocumentsQuery): Promise<RcvDocumentsResult>;
49
+ /**
50
+ * Consulta documentos recibidos 33/34/61 en RCV; cada emisor conserva su identidad fiscal.
51
+ */
26
52
  getReceivedDocuments(input: RcvDocumentsQuery): Promise<RcvDocumentsResult>;
27
- getIssuedInvoiceXml(input: IssuedInvoiceXmlQuery): Promise<InvoiceXmlResult>;
28
- getReceivedInvoiceXml(input: ReceivedInvoiceXmlQuery): Promise<InvoiceXmlResult>;
29
- getIssuedDocumentXml(input: IssuedDocumentXmlQuery): Promise<IssuedDocumentXmlResult>;
30
- getReceivedDocumentXml(input: ReceivedDocumentXmlQuery): Promise<IssuedDocumentXmlResult>;
53
+ /**
54
+ * Consulta RCV emitido con importes enteros exactos como strings; mantiene las mismas reglas de autorización y cobertura.
55
+ */
56
+ getIssuedDocumentsExact(input: RcvDocumentsQuery): Promise<ExactDte<RcvDocumentsResult>>;
57
+ /**
58
+ * Consulta RCV recibido con importes enteros exactos como strings, sin convertir primero los números fuente a Number.
59
+ */
60
+ getReceivedDocumentsExact(input: RcvDocumentsQuery): Promise<ExactDte<RcvDocumentsResult>>;
61
+ /**
62
+ * Descarga XML de factura emitida 33/34 y comprueba su identidad.
63
+ * @param options reconcile=false omite la interpretación aritmética; por defecto conserva el comportamiento histórico.
64
+ */
65
+ getIssuedInvoiceXml(input: IssuedInvoiceXmlQuery, options?: DteXmlReadOptions): Promise<InvoiceXmlResult>;
66
+ /**
67
+ * Descarga XML de factura recibida 33/34 y comprueba emisor, receptor, tipo y folio.
68
+ * @param options reconcile=false entrega los datos declarados sin conciliación; identidad y autorización siguen siendo obligatorias.
69
+ */
70
+ getReceivedInvoiceXml(input: ReceivedInvoiceXmlQuery, options?: DteXmlReadOptions): Promise<InvoiceXmlResult>;
71
+ /**
72
+ * Descarga XML emitido 33/34/61, con encabezado fiscal e importes numéricos seguros.
73
+ * @param options reconcile=false permite leer hechos sin exigir una referencia fiscal interpretable para una nota de crédito.
74
+ */
75
+ getIssuedDocumentXml(input: IssuedDocumentXmlQuery, options?: DteXmlReadOptions): Promise<IssuedDocumentXmlResult>;
76
+ /**
77
+ * Descarga XML recibido 33/34/61 y comprueba también que la empresa autorizada es su receptor.
78
+ * @param options reconcile=false omite conciliación y requisitos de interpretación de referencias; conserva controles técnicos y de identidad.
79
+ */
80
+ getReceivedDocumentXml(input: ReceivedDocumentXmlQuery, options?: DteXmlReadOptions): Promise<IssuedDocumentXmlResult>;
81
+ /**
82
+ * Descarga XML emitido 33/34/61 conservando importes de hasta 18 dígitos como strings exactos.
83
+ * @param options reconcile=false omite el intento de conciliación numérica; los bytes originales se conservan.
84
+ */
85
+ getIssuedDocumentXmlExact(input: IssuedDocumentXmlQuery, options?: DteXmlReadOptions): Promise<ExactDteDocumentXmlResult>;
86
+ /**
87
+ * Descarga XML recibido 33/34/61 con importes exactos y comprobación de emisor y receptor.
88
+ * @param options reconcile=false devuelve sólo los hechos declarados; no modifica precios, cantidades ni bytes.
89
+ */
90
+ getReceivedDocumentXmlExact(input: ReceivedDocumentXmlQuery, options?: DteXmlReadOptions): Promise<ExactDteDocumentXmlResult>;
91
+ /**
92
+ * Descarga PDF emitido 33/34 como stream, después de verificar empresa e identidad en el historial del proveedor.
93
+ */
31
94
  getIssuedInvoicePdf(input: IssuedInvoicePdfQuery, options?: PdfDownloadOptions): Promise<InvoicePdfResult>;
95
+ /**
96
+ * Descarga PDF recibido 33/34 como stream y verifica también al proveedor solicitado. El consumidor debe consumir o cerrar el stream.
97
+ */
32
98
  getReceivedInvoicePdf(input: ReceivedInvoicePdfQuery, options?: PdfDownloadOptions): Promise<InvoicePdfResult>;
99
+ /**
100
+ * Consulta evidencia del documento recibida por el SII. fiscalVerdict permanece NOT_OBSERVED; no acredita aceptación tributaria.
101
+ */
33
102
  getDocumentStatus(input: DocumentStatusQuery, options?: DocumentQueryOptions): Promise<DocumentStatusResult>;
103
+ /**
104
+ * Consulta eventos del receptor verificando identidad y acceso en el rol solicitado. Un reporte de pago no registra un pago en el consumidor.
105
+ */
34
106
  getDocumentRecipientEvents(input: RecipientEventsQuery, options?: DocumentQueryOptions): Promise<RecipientEventsResult>;
107
+ /**
108
+ * Valida y prepara una factura tipo 33 para aprobación, sin firmarla ni enviarla. La preparación es de uso único y vence a los cinco minutos.
109
+ */
35
110
  prepareInvoice(input: InvoiceInput): Promise<PreparedDocument>;
111
+ /**
112
+ * Prepara una nota de crédito de anulación contra una factura tipo 33 original. Conserva las comprobaciones estrictas de contenido.
113
+ */
36
114
  prepareCancellationCreditNote(input: {
37
115
  factura: IssuedInvoiceXmlQuery;
38
116
  issuedDate: string;
39
117
  }): Promise<PreparedDocument>;
118
+ /**
119
+ * Firma y envía exclusivamente el contenido preparado y aprobado.
120
+ * Exige beforeSend para respaldar documento e identidad antes del envío; no reintenta escrituras ante resultados desconocidos.
121
+ */
40
122
  signAndSend(input: SignDocumentInput): Promise<SentDocument>;
123
+ /**
124
+ * Espera operaciones pendientes, cierra la sesión remota y libera recursos. Puede rechazar con SII_LOGOUT_FAILED aunque la limpieza local termine.
125
+ */
41
126
  dispose(): Promise<void>;
42
127
  /** @deprecated Use getAuthorizedCompanies. */
43
128
  getEmpresasAutorizadas(): Promise<SiiResponse<AuthorizedCompany>>;
@@ -48,11 +133,11 @@ export declare class SiiClient {
48
133
  /** @deprecated Use getReceivedInvoices. */
49
134
  getFacturasRecibidas(input: ReceivedInvoicesQuery): Promise<ReceivedInvoicesResult>;
50
135
  /** @deprecated Use getIssuedInvoiceXml. */
51
- getXmlFacturaEmitida(input: IssuedInvoiceXmlQuery): Promise<InvoiceXmlResult>;
136
+ getXmlFacturaEmitida(input: IssuedInvoiceXmlQuery, options?: DteXmlReadOptions): Promise<InvoiceXmlResult>;
52
137
  /** @deprecated Use getReceivedInvoiceXml. */
53
- getXmlFacturaRecibida(input: ReceivedInvoiceXmlQuery): Promise<InvoiceXmlResult>;
138
+ getXmlFacturaRecibida(input: ReceivedInvoiceXmlQuery, options?: DteXmlReadOptions): Promise<InvoiceXmlResult>;
54
139
  /** @deprecated Use getIssuedDocumentXml. */
55
- getXmlDocumentoEmitido(input: IssuedDocumentXmlQuery): Promise<IssuedDocumentXmlResult>;
140
+ getXmlDocumentoEmitido(input: IssuedDocumentXmlQuery, options?: DteXmlReadOptions): Promise<IssuedDocumentXmlResult>;
56
141
  /** @deprecated Use prepareInvoice. */
57
142
  prepararFactura(input: InvoiceInput): Promise<PreparedDocument>;
58
143
  /** @deprecated Use prepareCancellationCreditNote. */