@devlas/dte-sii 2.12.15 → 2.12.16

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.
@@ -1425,7 +1425,11 @@ class SiiCertificacion {
1425
1425
  * @returns {Promise<Object>} { success, estados, timedOut }
1426
1426
  */
1427
1427
  async waitForApproval(setsAEsperar = [], options = {}) {
1428
- const { maxIntentos = 30, intervalo = 10000, onProgress } = options;
1428
+ // maxIntentos bajado de 30 a 5 (10s c/u = 50s tope, antes 5 min): evidencia real de hoy
1429
+ // (~10 corridas) muestra que esto SIEMPRE resuelve en el intento 1-3 (10-30s) — si tarda
1430
+ // más que eso, algo anda mal en vez de ser una demora normal del SII, y esperar 5 min
1431
+ // solo posterga descubrirlo.
1432
+ const { maxIntentos = 5, intervalo = 10000, onProgress } = options;
1429
1433
  const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
1430
1434
 
1431
1435
  for (let intento = 1; intento <= maxIntentos; intento++) {
@@ -1247,6 +1247,11 @@ class CertRunner {
1247
1247
  console.log(`\n[!] Solo ${librosEnviados}/3 libros enviados. Errores: ${errores.join('; ')}`);
1248
1248
  }
1249
1249
 
1250
+ const _librosProcesados = Object.keys(resultados)
1251
+ .filter(k => k.startsWith('libro'))
1252
+ .map(k => k.slice('libro'.length).replace(/^./, c => c.toLowerCase()));
1253
+ emitProgress(STEPS.BOOKS_DONE, { libros: _librosProcesados, success: librosEnviados === 3 });
1254
+
1250
1255
  return {
1251
1256
  success: librosEnviados === 3,
1252
1257
  librosEnviados,
@@ -1809,7 +1814,10 @@ class CertRunner {
1809
1814
 
1810
1815
  if (todosAprobados) {
1811
1816
  console.log('\n ¡Todos los libros aprobados!');
1812
- return await this.avanzarSiguientePaso();
1817
+ const resultadoAvance = await this.avanzarSiguientePaso();
1818
+ const avanceActual = await this.consultarAvance().catch(() => null);
1819
+ emitProgress(STEPS.LIBROS_AVANZADOS, { etapaActual: avanceActual?.etapaActual ?? null });
1820
+ return resultadoAvance;
1813
1821
  }
1814
1822
 
1815
1823
  await sleep(intervalo);
@@ -2160,6 +2168,7 @@ class CertRunner {
2160
2168
  const intercambioDir = path.join(this.debugDir, 'intercambio');
2161
2169
  fs.mkdirSync(intercambioDir, { recursive: true });
2162
2170
 
2171
+ emitProgress(STEPS.INTERCAMBIO_START);
2163
2172
  console.log('\n' + '═'.repeat(60));
2164
2173
  console.log('FASE 7: INTERCAMBIO DE INFORMACIÓN');
2165
2174
  console.log('═'.repeat(60));
@@ -2201,6 +2210,8 @@ class CertRunner {
2201
2210
  }
2202
2211
  }
2203
2212
 
2213
+ emitProgress(STEPS.INTERCAMBIO_DESCARGADO);
2214
+
2204
2215
  // ── PASO 2: Generar XMLs de respuesta ─────────────────────
2205
2216
  console.log('\nGenerando respuestas firmadas...');
2206
2217
  const intercambioCert = new IntercambioCert({
@@ -2228,6 +2239,7 @@ class CertRunner {
2228
2239
  });
2229
2240
 
2230
2241
  if (uploadResult.success) {
2242
+ emitProgress(STEPS.INTERCAMBIO_DONE, { uploaded: true });
2231
2243
  console.log('\n' + '═'.repeat(60));
2232
2244
  console.log('[OK] INTERCAMBIO COMPLETADO');
2233
2245
  console.log('═'.repeat(60));
@@ -2802,7 +2814,10 @@ class CertRunner {
2802
2814
  console.log(`FASE 8: MUESTRAS IMPRESAS (${pdfPaths.length} PDFs)`);
2803
2815
  console.log('═'.repeat(60));
2804
2816
 
2805
- return this._subirMuestrasImpresasPortal({ pdfPaths, debugDir: pdfDir });
2817
+ emitProgress(STEPS.MUESTRAS_UPLOADING, { count: pdfPaths.length });
2818
+ const result = await this._subirMuestrasImpresasPortal({ pdfPaths, debugDir: pdfDir });
2819
+ emitProgress(STEPS.MUESTRAS_DONE, { success: result.success });
2820
+ return result;
2806
2821
  }
2807
2822
 
2808
2823
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@devlas/dte-sii",
3
- "version": "2.12.15",
3
+ "version": "2.12.16",
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",
package/utils/progress.js CHANGED
@@ -34,8 +34,9 @@ const STEPS = {
34
34
  BOOK_SKIPPED: 'BOOK_SKIPPED', // data: { book }
35
35
  BOOK_ERROR: 'BOOK_ERROR', // data: { book, error }
36
36
  BOOKS_DECLARING: 'BOOKS_DECLARING',
37
- BOOKS_DONE: 'BOOKS_DONE',
37
+ BOOKS_DONE: 'BOOKS_DONE', // data: { libros, success } al terminar la fase completa
38
38
  BOOK_PERIOD_RETRY: 'BOOK_PERIOD_RETRY', // data: { periodo, intento }
39
+ LIBROS_AVANZADOS: 'LIBROS_AVANZADOS', // data: { etapaActual } — tras avanzarSiguientePaso() post-libros
39
40
  // Avance (Fase 5)
40
41
  ADVANCE_WAITING: 'ADVANCE_WAITING',
41
42
  ADVANCE_DONE: 'ADVANCE_DONE',
@@ -47,13 +48,14 @@ const STEPS = {
47
48
  SIM_POLLING: 'SIM_POLLING', // data: { intento, max }
48
49
  SIM_DONE: 'SIM_DONE',
49
50
  // Intercambio (Fase 7)
50
- INTERCAMBIO_START: 'INTERCAMBIO_START',
51
- INTERCAMBIO_DONE: 'INTERCAMBIO_DONE',
51
+ INTERCAMBIO_START: 'INTERCAMBIO_START',
52
+ INTERCAMBIO_DESCARGADO: 'INTERCAMBIO_DESCARGADO', // set de intercambio obtenido (leído de disco o descargado)
53
+ INTERCAMBIO_DONE: 'INTERCAMBIO_DONE', // data: { uploaded }
52
54
  // Muestras impresas (Fase 8)
53
55
  MUESTRAS_START: 'MUESTRAS_START',
54
56
  MUESTRAS_PDFS: 'MUESTRAS_PDFS',
55
- MUESTRAS_UPLOADING: 'MUESTRAS_UPLOADING',
56
- MUESTRAS_DONE: 'MUESTRAS_DONE',
57
+ MUESTRAS_UPLOADING: 'MUESTRAS_UPLOADING', // data: { count }
58
+ MUESTRAS_DONE: 'MUESTRAS_DONE', // data: { success }
57
59
  // Boleta electronica
58
60
  BOLETA_START: 'BOLETA_START',
59
61
  BOLETA_SET_DOWNLOAD: 'BOLETA_SET_DOWNLOAD',