@devlas/dte-sii 2.5.3 → 2.5.5
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/SiiPortalAuth.js +11 -6
- package/cert/ConfigLoader.js +7 -8
- package/package.json +2 -1
package/SiiPortalAuth.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
// Copyright (c) 2026 Devlas SpA — https://devlas.cl
|
|
2
|
-
// Licencia MIT. Ver archivo LICENSE para mas detalles.
|
|
1
|
+
// Copyright (c) 2026 Devlas SpA — https://devlas.cl
|
|
2
|
+
// Licencia MIT. Ver archivo LICENSE para mas detalles.
|
|
3
3
|
/**
|
|
4
4
|
* SiiPortalAuth.js
|
|
5
5
|
*
|
|
@@ -143,7 +143,9 @@ class SiiPortalAuth {
|
|
|
143
143
|
res.on('end', () => {
|
|
144
144
|
const buf = Buffer.concat(chunks);
|
|
145
145
|
const ct = res.headers['content-type'] || '';
|
|
146
|
-
|
|
146
|
+
// Todos los hosts *.sii.cl sirven páginas ISO-8859-1; a veces no incluyen charset en Content-Type.
|
|
147
|
+
const isSiiHost = url.hostname.endsWith('.sii.cl');
|
|
148
|
+
const encoding = (isSiiHost || /iso-8859|latin-1|windows-1252/i.test(ct)) ? 'latin1' : 'utf8';
|
|
147
149
|
resolve({ status: res.statusCode, headers: res.headers, body: buf.toString(encoding), cookieJar });
|
|
148
150
|
});
|
|
149
151
|
});
|
|
@@ -411,7 +413,7 @@ class SiiPortalAuth {
|
|
|
411
413
|
static _parsearTablaEmpresa(html) {
|
|
412
414
|
const datos = {};
|
|
413
415
|
|
|
414
|
-
for (const row of html.matchAll(/<tr
|
|
416
|
+
for (const row of html.matchAll(/<tr[^>]*>[\s\S]*?<\/tr>/gi)) {
|
|
415
417
|
const celdas = [...row[0].matchAll(/<td[^>]*>([\s\S]*?)<\/td>/gi)]
|
|
416
418
|
.map(m => m[1]
|
|
417
419
|
.replace(/<[^>]+>/g, '')
|
|
@@ -428,8 +430,11 @@ class SiiPortalAuth {
|
|
|
428
430
|
if (celdas.length === 2 && celdas[0]) datos[celdas[0]] = celdas[1];
|
|
429
431
|
}
|
|
430
432
|
|
|
431
|
-
|
|
432
|
-
const
|
|
433
|
+
// Buscar por regex para ser resiliente ante variaciones de encoding / tildes
|
|
434
|
+
const fechaKey = Object.keys(datos).find(k => /fecha.*resol/i.test(k)) || null;
|
|
435
|
+
const nroKey = Object.keys(datos).find(k => /^resoluci/i.test(k) && !/fecha/i.test(k)) || null;
|
|
436
|
+
const fechaResol = fechaKey ? datos[fechaKey] : null;
|
|
437
|
+
const nroResol = nroKey ? datos[nroKey] : null;
|
|
433
438
|
|
|
434
439
|
if (fechaResol === null && nroResol === null) {
|
|
435
440
|
// Loguear los campos encontrados para diagnóstico
|
package/cert/ConfigLoader.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
// Copyright (c) 2026 Devlas SpA — https://devlas.cl
|
|
2
|
-
// Licencia MIT. Ver archivo LICENSE para mas detalles.
|
|
1
|
+
// Copyright (c) 2026 Devlas SpA — https://devlas.cl
|
|
2
|
+
// Licencia MIT. Ver archivo LICENSE para mas detalles.
|
|
3
3
|
/**
|
|
4
4
|
* ConfigLoader - Carga configuración de certificación desde .env
|
|
5
5
|
*
|
|
@@ -24,16 +24,15 @@ function loadConfig(options = {}) {
|
|
|
24
24
|
// Determinar baseDir
|
|
25
25
|
const baseDir = options.baseDir || path.resolve(__dirname, '..', '..', '..');
|
|
26
26
|
|
|
27
|
-
// Cargar .env
|
|
27
|
+
// Cargar .env (opcional — las vars pueden venir de process.env inyectadas por el proceso padre)
|
|
28
28
|
const envPath = options.envPath || path.join(baseDir, '.env');
|
|
29
29
|
|
|
30
|
-
if (
|
|
31
|
-
|
|
30
|
+
if (fs.existsSync(envPath)) {
|
|
31
|
+
require('dotenv').config({ path: envPath });
|
|
32
|
+
} else {
|
|
33
|
+
console.warn(`[ConfigLoader] .env no encontrado en ${envPath} — usando variables de entorno del proceso.`);
|
|
32
34
|
}
|
|
33
35
|
|
|
34
|
-
// Usar dotenv para cargar
|
|
35
|
-
require('dotenv').config({ path: envPath });
|
|
36
|
-
|
|
37
36
|
// Resolver rutas relativas
|
|
38
37
|
const resolvePath = (filePath) => {
|
|
39
38
|
if (!filePath) return null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@devlas/dte-sii",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.5",
|
|
4
4
|
"description": "Facturación y boletas electrónicas para el SII de Chile. Genera, timbra, firma y envía DTEs, libros electrónicos y automatiza la certificación.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "dte-sii.d.ts",
|
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@xmldom/xmldom": "^0.8.11",
|
|
33
|
+
"bwip-js": "^4.8.0",
|
|
33
34
|
"fast-xml-parser": "^5.3.3",
|
|
34
35
|
"got": "^11.8.6",
|
|
35
36
|
"node-forge": "^1.3.3",
|