@devly-cl/sii-client 0.6.0 → 0.7.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +113 -251
- package/dist/application/document-status.d.ts +13 -0
- package/dist/application/document-status.js +50 -0
- package/dist/application/invoice-queries.d.ts +11 -5
- package/dist/application/invoice-queries.js +13 -9
- package/dist/domain/company-info.d.ts +13 -0
- package/dist/domain/company-info.js +2 -0
- package/dist/domain/document-status.d.ts +93 -0
- package/dist/domain/document-status.js +69 -0
- package/dist/domain/document.d.ts +4 -0
- package/dist/domain/document.js +38 -3
- package/dist/domain/dte-reconciliation.d.ts +5 -0
- package/dist/domain/dte-reconciliation.js +351 -0
- package/dist/domain/invoice-xml.d.ts +133 -1
- package/dist/domain/invoicing.d.ts +78 -5
- package/dist/domain/invoicing.js +143 -26
- package/dist/domain/rcv-document.d.ts +17 -0
- package/dist/domain/rcv-document.js +2 -0
- package/dist/index.d.ts +9 -4
- package/dist/index.js +5 -1
- package/dist/infrastructure/document-status-gateway.d.ts +13 -0
- package/dist/infrastructure/document-status-gateway.js +127 -0
- package/dist/infrastructure/document-status-parser.d.ts +12 -0
- package/dist/infrastructure/document-status-parser.js +258 -0
- package/dist/infrastructure/dte-xml.js +148 -30
- package/dist/infrastructure/facturador-gateway.d.ts +4 -1
- package/dist/infrastructure/facturador-gateway.js +113 -15
- package/dist/infrastructure/facturador.d.ts +4 -1
- package/dist/infrastructure/facturador.js +22 -4
- package/dist/infrastructure/rcv-gateway.d.ts +3 -0
- package/dist/infrastructure/rcv-gateway.js +9 -5
- package/dist/infrastructure/rcv-normalization.d.ts +7 -0
- package/dist/infrastructure/rcv-normalization.js +9 -1
- package/dist/infrastructure/sii-client.d.ts +10 -1
- package/dist/infrastructure/sii-client.js +29 -3
- package/dist/infrastructure/sii-http-session.d.ts +5 -1
- package/dist/infrastructure/sii-http-session.js +75 -27
- package/dist/sii-error.d.ts +4 -3
- package/dist/sii-error.js +11 -4
- package/package.json +45 -45
- package/dist/domain/sii-error.d.ts +0 -27
- package/dist/domain/sii-error.js +0 -82
package/dist/domain/sii-error.js
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SiiError = void 0;
|
|
4
|
-
exports.sanitizeSiiDiagnostics = sanitizeSiiDiagnostics;
|
|
5
|
-
const STAGES = ['AUTHENTICATION', 'SESSION_CHECK', 'COMPANY_AUTHORIZATION', 'RCV_INITIALIZATION', 'RCV_SUMMARY', 'RCV_DETAIL', 'XML_COMPANY_SELECTION', 'XML_DOWNLOAD', 'XML_PARSE', 'LOGOUT', 'DOCUMENT_PREPARATION', 'DOCUMENT_REVIEW', 'DOCUMENT_SIGNING', 'DOCUMENT_SEND', 'DOCUMENT_RECOVERY'];
|
|
6
|
-
const ENDPOINTS = ['CAutInicio.cgi', 'aaSessionService/load', 'getDcvEmpresasAutorizadas', 'getDatosInicio', 'getResumen', 'getDetalleCompra', 'getDetalleVenta', 'mipeSelEmpresa.cgi', 'mipeLaunchPage.cgi', 'mipeDownLoad.cgi', 'autTermino.cgi', 'mipeGenFacEx.cgi', 'mipeDisplayPreView.cgi', 'mipeGenXMLFirma.cgi', 'getCertDigital.cgi', 'postFirmaDigital.cgi', 'mipeSendXML.cgi', 'mipeAdminDocsEmi.cgi', 'mipeGesDocEmi.cgi', 'mipeDisplayPDF.cgi'];
|
|
7
|
-
const REASONS = ['DOCUMENT_LIMIT_EXCEEDED', 'DOCUMENT_NOT_FOUND', 'EMPTY_RESPONSE', 'HTML_RESPONSE', 'PROVIDER_ERROR_PAGE', 'UNEXPECTED_PDF', 'UNEXPECTED_ARCHIVE', 'UNEXPECTED_FORMAT', 'INVALID_XML', 'XML_IDENTITY_MISMATCH', 'RESPONSE_TOO_LARGE', 'HTTP_ERROR', 'TIMEOUT', 'TRANSPORT_ERROR', 'RETRY_LATER', 'CAPTCHA_REQUIRED', 'SESSION_REQUIRED', 'LOGIN_NOT_CONFIRMED', 'PERSONAL_SESSION_REQUIRED', 'SESSION_IDENTITY_MISMATCH', 'COMPANY_NOT_AUTHORIZED', 'COMPANY_SELECTION_REQUIRED', 'PROVIDER_REJECTED', 'INVALID_RESPONSE', 'DOCUMENT_CONTENT_MISMATCH', 'CERTIFICATE_UNAVAILABLE', 'CERTIFICATE_PASSWORD_INVALID', 'CERTIFICATE_EXPIRED', 'CERTIFICATE_REVOKED', 'SIGNATURE_INVALID', 'ISSUANCE_OUTCOME_UNKNOWN'];
|
|
8
|
-
const RESPONSE_TYPES = ['XML', 'HTML', 'PDF', 'ZIP', 'JSON', 'EMPTY', 'UNKNOWN'];
|
|
9
|
-
const CONTENT_TYPES = ['application/xml', 'text/xml', 'application/octet-stream', 'text/html', 'application/pdf', 'application/zip', 'application/json', 'text/plain'];
|
|
10
|
-
function member(values, value) {
|
|
11
|
-
return typeof value === 'string' && values.some(item => item === value);
|
|
12
|
-
}
|
|
13
|
-
/** Only bounded, known protocol values cross this boundary. Never provider text or URLs. */
|
|
14
|
-
function sanitizeSiiDiagnostics(value) {
|
|
15
|
-
if (typeof value !== 'object' || value === null)
|
|
16
|
-
return undefined;
|
|
17
|
-
const raw = value;
|
|
18
|
-
if (typeof raw.traceId !== 'string' || !/^[a-f\d]{8}-[a-f\d]{4}-[a-f\d]{4}-[a-f\d]{4}-[a-f\d]{12}$/i.test(raw.traceId)
|
|
19
|
-
|| !member(STAGES, raw.stage) || !member(ENDPOINTS, raw.endpoint) || !member(REASONS, raw.reason))
|
|
20
|
-
return undefined;
|
|
21
|
-
return Object.freeze({
|
|
22
|
-
traceId: raw.traceId, stage: raw.stage, endpoint: raw.endpoint, reason: raw.reason,
|
|
23
|
-
...(member(RESPONSE_TYPES, raw.responseType) ? { responseType: raw.responseType } : {}),
|
|
24
|
-
...(member(CONTENT_TYPES, raw.contentType) ? { contentType: raw.contentType } : {}),
|
|
25
|
-
...(typeof raw.httpStatus === 'number' && Number.isInteger(raw.httpStatus) && raw.httpStatus >= 100 && raw.httpStatus <= 599 ? { httpStatus: raw.httpStatus } : {}),
|
|
26
|
-
...(typeof raw.siiMessageCode === 'string' && /^\d{2}\.\d{2}\.\d{3}\.\d{3}\.\d{3}\.\d{2}$/.test(raw.siiMessageCode) ? { siiMessageCode: raw.siiMessageCode } : {}),
|
|
27
|
-
...(typeof raw.siiResponseCode === 'number' && Number.isInteger(raw.siiResponseCode) && Math.abs(raw.siiResponseCode) <= 999999 ? { siiResponseCode: raw.siiResponseCode } : {}),
|
|
28
|
-
...(typeof raw.attempts === 'number' && Number.isInteger(raw.attempts) && raw.attempts >= 1 && raw.attempts <= 3 ? { attempts: raw.attempts } : {}),
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
const STAGE_LABELS = {
|
|
32
|
-
AUTHENTICATION: 'inicio de sesión', SESSION_CHECK: 'validación de sesión', COMPANY_AUTHORIZATION: 'autorización de empresa',
|
|
33
|
-
RCV_INITIALIZATION: 'inicio del RCV', RCV_SUMMARY: 'resumen del RCV', RCV_DETAIL: 'detalle del RCV',
|
|
34
|
-
XML_COMPANY_SELECTION: 'selección de empresa en el facturador', XML_DOWNLOAD: 'descarga del XML', XML_PARSE: 'validación del XML', LOGOUT: 'cierre de sesión',
|
|
35
|
-
DOCUMENT_PREPARATION: 'preparación del documento', DOCUMENT_REVIEW: 'revisión del documento', DOCUMENT_SIGNING: 'firma del documento', DOCUMENT_SEND: 'envío del documento', DOCUMENT_RECOVERY: 'recuperación del documento emitido',
|
|
36
|
-
};
|
|
37
|
-
const REASON_LABELS = {
|
|
38
|
-
DOCUMENT_LIMIT_EXCEEDED: 'SII rechazó la consulta porque devuelve demasiados documentos. No confirmó si el XML individual está disponible.',
|
|
39
|
-
DOCUMENT_NOT_FOUND: 'SII indicó que no encontró documentos para esta consulta.',
|
|
40
|
-
EMPTY_RESPONSE: 'SII devolvió una respuesta vacía; no se recibió ningún documento.',
|
|
41
|
-
HTML_RESPONSE: 'SII devolvió una página HTML en lugar del XML. Esto no confirma que la factura carezca de XML.',
|
|
42
|
-
PROVIDER_ERROR_PAGE: 'SII devolvió una página de error en lugar del documento solicitado.',
|
|
43
|
-
UNEXPECTED_PDF: 'SII devolvió un PDF en esta solicitud de XML. Ese archivo no permite reconstruir el detalle desde XML.',
|
|
44
|
-
UNEXPECTED_ARCHIVE: 'SII devolvió un ZIP en esta solicitud de XML; el SDK esperaba un DTE individual.',
|
|
45
|
-
UNEXPECTED_FORMAT: 'SII devolvió un formato diferente al XML solicitado.',
|
|
46
|
-
INVALID_XML: 'El XML recibido no contiene un DTE individual válido y no se guardó.',
|
|
47
|
-
XML_IDENTITY_MISMATCH: 'El XML recibido corresponde a otro documento y no se guardó.',
|
|
48
|
-
RESPONSE_TOO_LARGE: 'La respuesta de SII supera el límite permitido de 1 MiB y no se procesó.',
|
|
49
|
-
HTTP_ERROR: 'SII respondió con un error HTTP.', TIMEOUT: 'SII no respondió dentro del tiempo permitido.',
|
|
50
|
-
TRANSPORT_ERROR: 'No se pudo completar la comunicación con SII.', RETRY_LATER: 'SII pidió esperar antes de volver a consultar.',
|
|
51
|
-
CAPTCHA_REQUIRED: 'SII requiere resolver un CAPTCHA en su sitio.', SESSION_REQUIRED: 'SII requiere autenticación interactiva o una sesión válida.',
|
|
52
|
-
LOGIN_NOT_CONFIRMED: 'SII no confirmó el inicio de sesión.', PERSONAL_SESSION_REQUIRED: 'SII no confirmó una sesión personal.',
|
|
53
|
-
SESSION_IDENTITY_MISMATCH: 'La sesión de SII no corresponde al usuario solicitado.', COMPANY_NOT_AUTHORIZED: 'SII no autorizó el acceso a la empresa solicitada.',
|
|
54
|
-
COMPANY_SELECTION_REQUIRED: 'SII no confirmó la selección de empresa en el facturador.',
|
|
55
|
-
PROVIDER_REJECTED: 'SII rechazó la solicitud.', INVALID_RESPONSE: 'SII devolvió una respuesta que no cumple el contrato esperado.',
|
|
56
|
-
DOCUMENT_CONTENT_MISMATCH: 'El contenido fiscal recibido difiere del contenido aprobado. No se envió el documento.',
|
|
57
|
-
CERTIFICATE_UNAVAILABLE: 'SII no devolvió un certificado centralizado utilizable para esta identidad.',
|
|
58
|
-
CERTIFICATE_PASSWORD_INVALID: 'SII rechazó la clave del certificado centralizado.', CERTIFICATE_EXPIRED: 'El certificado centralizado está expirado.', CERTIFICATE_REVOKED: 'El certificado centralizado está revocado.',
|
|
59
|
-
SIGNATURE_INVALID: 'SII no devolvió un XML firmado válido para el documento aprobado. No se envió.',
|
|
60
|
-
ISSUANCE_OUTCOME_UNKNOWN: 'El envío comenzó pero no se confirmó su resultado. Conserve el XML y consulte el historial antes de volver a emitir; repetir puede duplicar el documento.',
|
|
61
|
-
};
|
|
62
|
-
class SiiError extends Error {
|
|
63
|
-
code;
|
|
64
|
-
httpStatus;
|
|
65
|
-
diagnostics;
|
|
66
|
-
description;
|
|
67
|
-
constructor(code, httpStatus, diagnostics) {
|
|
68
|
-
super(code); // Preserve the existing code/message contract.
|
|
69
|
-
this.code = code;
|
|
70
|
-
this.httpStatus = httpStatus;
|
|
71
|
-
this.name = 'SiiError';
|
|
72
|
-
this.diagnostics = sanitizeSiiDiagnostics(diagnostics);
|
|
73
|
-
if (this.diagnostics) {
|
|
74
|
-
const d = this.diagnostics;
|
|
75
|
-
this.description = `Falló el paso: ${STAGE_LABELS[d.stage]} (${d.endpoint}). ${REASON_LABELS[d.reason]}`
|
|
76
|
-
+ (d.httpStatus === undefined ? '' : ` HTTP ${d.httpStatus}.`)
|
|
77
|
-
+ (d.siiMessageCode ? ` Código SII: ${d.siiMessageCode}.` : '')
|
|
78
|
-
+ (d.siiResponseCode === undefined ? '' : ` Respuesta SII: ${d.siiResponseCode}.`);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
exports.SiiError = SiiError;
|