@devlas/dte-sii 2.5.4 → 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 CHANGED
@@ -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
- const encoding = /iso-8859|latin-1|windows-1252/i.test(ct) ? 'latin1' : 'utf8';
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
  });
@@ -428,8 +430,11 @@ class SiiPortalAuth {
428
430
  if (celdas.length === 2 && celdas[0]) datos[celdas[0]] = celdas[1];
429
431
  }
430
432
 
431
- const fechaResol = datos['Fecha Resolución'] || null;
432
- const nroResol = datos['Resolución'] !== undefined ? datos['Resolución'] : null;
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
@@ -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 (!fs.existsSync(envPath)) {
31
- throw new Error(`Archivo .env no encontrado: ${envPath}\nCopia .env.example a .env y configura tus valores.`);
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.4",
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",