node-sped-nfe 1.1.9 → 1.2.1

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 CHANGED
@@ -50,6 +50,7 @@ Toda a documentação completa com guias, exemplos, status SEFAZ e muito mais es
50
50
  | Consulta Status do Serviço SEFAZ | ✅ |
51
51
  | Consulta Situação de NF-e/NFC-e | ✅ |
52
52
  | Consulta NF-e/NFC-e emitidas contra (DistNFe) | ✅ |
53
+ | Download NF-e/NFC-e emitidas contra (DistNFe) | ✅ |
53
54
  | Cancelamento de NFe/NFCe emitida (110111) | ✅ |
54
55
  | Carta correção de NFe/NFCe emitida (110110) | ✅ |
55
56
  | Manifestação de Destinatário - Ciência da Operação (210210) | ✅ |
@@ -319,7 +319,7 @@ const docZip = async (xml, retorno = "original") => {
319
319
  };
320
320
  const jXml = await xml2json(xml);
321
321
  try {
322
- var docZips = jXml["soap:Envelope"]["soap:Body"]["nfeDistDFeInteresseResponse"]["nfeDistDFeInteresseResult"]["retDistDFeInt"];
322
+ var docZips = jXml["nfeDistDFeInteresseResponse"]["nfeDistDFeInteresseResult"]["retDistDFeInt"];
323
323
  if (typeof docZips['loteDistDFeInt'] == "undefined")
324
324
  return resolve([]);
325
325
  docZips = docZips["loteDistDFeInt"]['docZip'];
@@ -30,8 +30,9 @@ declare class Tools {
30
30
  textoCorrecao?: string | undefined;
31
31
  sequencial?: number | undefined;
32
32
  }): Promise<string>;
33
- sefazDistDFe({ ultNSU }: {
33
+ sefazDistDFe({ ultNSU, chNFe }: {
34
34
  ultNSU?: string;
35
+ chNFe?: string;
35
36
  }): Promise<string>;
36
37
  sefazStatus(): Promise<string>;
37
38
  validarNFe(xml: string): Promise<any>;
@@ -54,7 +54,7 @@ class Tools {
54
54
  __classPrivateFieldSet(this, _Tools_cert, certificado, "f");
55
55
  }
56
56
  sefazEnviaLote(xml, data = { idLote: 1, indSinc: 0, compactar: false }) {
57
- return new Promise(async (resvol, reject) => {
57
+ return new Promise(async (resolve, reject) => {
58
58
  if (typeof data.idLote == "undefined")
59
59
  data.idLote = 1;
60
60
  if (typeof data.indSinc == "undefined")
@@ -102,7 +102,9 @@ class Tools {
102
102
  data += chunk;
103
103
  });
104
104
  res.on('end', () => {
105
- resvol(data);
105
+ xml2json(data).then((jRes) => {
106
+ json2xml(jRes['soap:Envelope']['soap:Body']).then(resolve).catch(reject);
107
+ });
106
108
  });
107
109
  });
108
110
  req.setTimeout(__classPrivateFieldGet(this, _Tools_config, "f").timeout * 1000, () => {
@@ -213,7 +215,11 @@ class Tools {
213
215
  }, (res) => {
214
216
  let data = '';
215
217
  res.on('data', (chunk) => data += chunk);
216
- res.on('end', () => resolve(data));
218
+ res.on('end', () => {
219
+ xml2json(data).then((jRes) => {
220
+ json2xml(jRes['soap:Envelope']['soap:Body']).then(resolve).catch(reject);
221
+ });
222
+ });
217
223
  });
218
224
  req.setTimeout(__classPrivateFieldGet(this, _Tools_config, "f").timeout * 1000, () => {
219
225
  reject({
@@ -334,7 +340,9 @@ class Tools {
334
340
  data += chunk;
335
341
  });
336
342
  res.on('end', () => {
337
- resolve(data);
343
+ xml2json(data).then((jRes) => {
344
+ json2xml(jRes['soap:Envelope']['soap:Body']).then(resolve).catch(reject);
345
+ });
338
346
  });
339
347
  });
340
348
  req.setTimeout(__classPrivateFieldGet(this, _Tools_config, "f").timeout * 1000, () => {
@@ -359,9 +367,11 @@ class Tools {
359
367
  }
360
368
  });
361
369
  }
362
- async sefazDistDFe({ ultNSU = "000000000000000" }) {
370
+ async sefazDistDFe({ ultNSU = undefined, chNFe = undefined }) {
363
371
  return new Promise(async (resolve, reject) => {
364
372
  try {
373
+ if (!chNFe && !ultNSU)
374
+ throw "sefazDistDFe({chNFe|ultNSU})";
365
375
  if (!__classPrivateFieldGet(this, _Tools_config, "f").CNPJ)
366
376
  throw "CNPJ não definido!";
367
377
  if (__classPrivateFieldGet(this, _Tools_config, "f").CNPJ.length !== 14)
@@ -375,9 +385,12 @@ class Tools {
375
385
  "tpAmb": 1, // 1 = produção, 2 = homologação
376
386
  "cUFAutor": UF2cUF[__classPrivateFieldGet(this, _Tools_config, "f").UF], // "AN" - Ambiente Nacional
377
387
  "CNPJ": __classPrivateFieldGet(this, _Tools_config, "f").CNPJ,
378
- "distNSU": {
379
- "ultNSU": `${ultNSU}`.padStart(15, '0')
380
- }
388
+ ...(typeof ultNSU != "undefined" ?
389
+ { "distNSU": { "ultNSU": `${ultNSU}`.padStart(15, '0') } } :
390
+ {}),
391
+ ...(typeof chNFe != "undefined" ?
392
+ { "consChNFe": { "chNFe": chNFe } } :
393
+ {})
381
394
  }
382
395
  });
383
396
  await __classPrivateFieldGet(this, _Tools_instances, "m", _Tools_xmlValido).call(this, xmlSing, `distDFeInt_v1.01`).catch(reject); //Validar corpo
@@ -415,7 +428,9 @@ class Tools {
415
428
  data += chunk;
416
429
  });
417
430
  res.on('end', () => {
418
- resolve(data);
431
+ xml2json(data).then((jRes) => {
432
+ json2xml(jRes['soap:Envelope']['soap:Body']).then(resolve).catch(reject);
433
+ });
419
434
  });
420
435
  });
421
436
  req.setTimeout(__classPrivateFieldGet(this, _Tools_config, "f").timeout * 1000, () => {
@@ -438,7 +453,7 @@ class Tools {
438
453
  }
439
454
  //Consulta status sefaz
440
455
  async sefazStatus() {
441
- return new Promise(async (resvol, reject) => {
456
+ return new Promise(async (resolve, reject) => {
442
457
  if (typeof __classPrivateFieldGet(this, _Tools_config, "f").UF == "undefined")
443
458
  throw "sefazStatus({...UF}) -> não definido!";
444
459
  if (typeof __classPrivateFieldGet(this, _Tools_config, "f").tpAmb == "undefined")
@@ -490,7 +505,9 @@ class Tools {
490
505
  data += chunk;
491
506
  });
492
507
  res.on('end', () => {
493
- resvol(data);
508
+ xml2json(data).then((jRes) => {
509
+ json2xml(jRes['soap:Envelope']['soap:Body']).then(resolve).catch(reject);
510
+ });
494
511
  });
495
512
  });
496
513
  req.setTimeout(__classPrivateFieldGet(this, _Tools_config, "f").timeout * 1000, () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-sped-nfe",
3
- "version": "1.1.9",
3
+ "version": "1.2.1",
4
4
  "author": "Kalmon V. Tavares",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",