node-sped-nfe 1.2.3 → 1.2.32

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.
@@ -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["nfeDistDFeInteresseResponse"]["nfeDistDFeInteresseResult"]["retDistDFeInt"];
322
+ var docZips = jXml["nfeDistDFeInteresseResult"]["retDistDFeInt"];
323
323
  if (typeof docZips['loteDistDFeInt'] == "undefined")
324
324
  return resolve([]);
325
325
  docZips = docZips["loteDistDFeInt"]['docZip'];
@@ -14,7 +14,7 @@ class Make {
14
14
  _Make_NFe.set(this, {
15
15
  "@xmlns": "http://www.portalfiscal.inf.br/nfe",
16
16
  infNFe: {
17
- "@xmlns": "http://www.portalfiscal.inf.br/nfe",
17
+ //"@xmlns": "http://www.portalfiscal.inf.br/nfe",
18
18
  }
19
19
  });
20
20
  _Make_ICMSTot.set(this, {
@@ -554,7 +554,7 @@ class Make {
554
554
  if (__classPrivateFieldGet(this, _Make_NFe, "f").infNFe[`@Id`] == null)
555
555
  __classPrivateFieldGet(this, _Make_NFe, "f").infNFe[`@Id`] = `NFe${__classPrivateFieldGet(this, _Make_instances, "m", _Make_gerarChaveNFe).call(this)}`;
556
556
  //Adicionar QrCode
557
- if (__classPrivateFieldGet(this, _Make_NFe, "f").infNFe.ide.mod == 65) {
557
+ if (__classPrivateFieldGet(this, _Make_NFe, "f").infNFe.ide.mod * 1 == 65) {
558
558
  //Como ja temos cUF, vamos usar o extras.cUF2UF
559
559
  let tempUF = urlEventos(cUF2UF[__classPrivateFieldGet(this, _Make_NFe, "f").infNFe.ide.cUF], __classPrivateFieldGet(this, _Make_NFe, "f").infNFe['@versao']);
560
560
  __classPrivateFieldGet(this, _Make_NFe, "f").infNFeSupl = {
@@ -9,7 +9,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
9
9
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
10
10
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
11
  };
12
- var _Tools_instances, _Tools_cert, _Tools_pem, _Tools_config, _Tools_getSignature, _Tools_gerarQRCodeNFCe, _Tools_descEvento, _Tools_xmlValido, _Tools_certTools;
12
+ var _Tools_instances, _Tools_cert, _Tools_pem, _Tools_config, _Tools_getSignature, _Tools_gerarQRCodeNFCe, _Tools_descEvento, _Tools_xmlValido, _Tools_certTools, _Tools_limparSoap;
13
13
  import { XMLBuilder } from "fast-xml-parser";
14
14
  import https from "https";
15
15
  import { spawnSync } from "child_process";
@@ -101,10 +101,13 @@ class Tools {
101
101
  res.on('data', (chunk) => {
102
102
  data += chunk;
103
103
  });
104
- res.on('end', () => {
105
- xml2json(data).then((jRes) => {
106
- json2xml(jRes['soapenv:Envelope']?.['soapenv:Body']?.['nfeResultMsg'] || jRes['soap:Envelope']?.['soap:Body']?.['nfeResultMsg']).then(resolve).catch(reject);
107
- });
104
+ res.on('end', async () => {
105
+ try {
106
+ resolve(await __classPrivateFieldGet(this, _Tools_instances, "m", _Tools_limparSoap).call(this, data));
107
+ }
108
+ catch (error) {
109
+ resolve(data);
110
+ }
108
111
  });
109
112
  });
110
113
  req.setTimeout(__classPrivateFieldGet(this, _Tools_config, "f").timeout * 1000, () => {
@@ -131,8 +134,9 @@ class Tools {
131
134
  data.tag = "infNFe";
132
135
  var xml = await this.xml2json(xmlJSON);
133
136
  if (data.tag == "infNFe") {
134
- if (xml.NFe.infNFe.ide.mod == 65) {
137
+ if (xml.NFe.infNFe.ide.mod * 1 == 65) {
135
138
  xml.NFe.infNFeSupl.qrCode = __classPrivateFieldGet(this, _Tools_instances, "m", _Tools_gerarQRCodeNFCe).call(this, xml.NFe, "2", __classPrivateFieldGet(this, _Tools_config, "f").CSCid, __classPrivateFieldGet(this, _Tools_config, "f").CSC);
139
+ xmlJSON = await json2xml(xml);
136
140
  }
137
141
  xml.NFe = {
138
142
  ...xml.NFe,
@@ -215,10 +219,13 @@ class Tools {
215
219
  }, (res) => {
216
220
  let data = '';
217
221
  res.on('data', (chunk) => data += chunk);
218
- res.on('end', () => {
219
- xml2json(data).then((jRes) => {
220
- json2xml(jRes['soapenv:Envelope']?.['soapenv:Body']?.['nfeResultMsg'] || jRes['soap:Envelope']?.['soap:Body']?.['nfeResultMsg']).then(resolve).catch(reject);
221
- });
222
+ res.on('end', async () => {
223
+ try {
224
+ resolve(await __classPrivateFieldGet(this, _Tools_instances, "m", _Tools_limparSoap).call(this, data));
225
+ }
226
+ catch (error) {
227
+ resolve(data);
228
+ }
222
229
  });
223
230
  });
224
231
  req.setTimeout(__classPrivateFieldGet(this, _Tools_config, "f").timeout * 1000, () => {
@@ -343,10 +350,13 @@ class Tools {
343
350
  res.on('data', (chunk) => {
344
351
  data += chunk;
345
352
  });
346
- res.on('end', () => {
347
- xml2json(data).then((jRes) => {
348
- json2xml(jRes['soapenv:Envelope']?.['soapenv:Body']?.['nfeResultMsg'] || jRes['soap:Envelope']?.['soap:Body']?.['nfeResultMsg']).then(resolve).catch(reject);
349
- });
353
+ res.on('end', async () => {
354
+ try {
355
+ resolve(await __classPrivateFieldGet(this, _Tools_instances, "m", _Tools_limparSoap).call(this, data));
356
+ }
357
+ catch (error) {
358
+ resolve(data);
359
+ }
350
360
  });
351
361
  });
352
362
  req.setTimeout(__classPrivateFieldGet(this, _Tools_config, "f").timeout * 1000, () => {
@@ -431,10 +441,13 @@ class Tools {
431
441
  res.on('data', (chunk) => {
432
442
  data += chunk;
433
443
  });
434
- res.on('end', () => {
435
- xml2json(data).then((jRes) => {
436
- json2xml(jRes['soapenv:Envelope']?.['soapenv:Body']?.['nfeResultMsg'] || jRes['soap:Envelope']?.['soap:Body']?.['nfeResultMsg']).then(resolve).catch(reject);
437
- });
444
+ res.on('end', async () => {
445
+ try {
446
+ resolve(await __classPrivateFieldGet(this, _Tools_instances, "m", _Tools_limparSoap).call(this, data));
447
+ }
448
+ catch (error) {
449
+ resolve(data);
450
+ }
438
451
  });
439
452
  });
440
453
  req.setTimeout(__classPrivateFieldGet(this, _Tools_config, "f").timeout * 1000, () => {
@@ -508,10 +521,13 @@ class Tools {
508
521
  res.on('data', (chunk) => {
509
522
  data += chunk;
510
523
  });
511
- res.on('end', () => {
512
- xml2json(data).then((jRes) => {
513
- json2xml(jRes['soapenv:Envelope']?.['soapenv:Body']?.['nfeResultMsg'] || jRes['soap:Envelope']?.['soap:Body']?.['nfeResultMsg']).then(resolve).catch(reject);
514
- });
524
+ res.on('end', async () => {
525
+ try {
526
+ resolve(await __classPrivateFieldGet(this, _Tools_instances, "m", _Tools_limparSoap).call(this, data));
527
+ }
528
+ catch (error) {
529
+ resolve(data);
530
+ }
515
531
  });
516
532
  });
517
533
  req.setTimeout(__classPrivateFieldGet(this, _Tools_config, "f").timeout * 1000, () => {
@@ -632,5 +648,29 @@ async function _Tools_xmlValido(xml, xsd) {
632
648
  resvol(__classPrivateFieldGet(this, _Tools_pem, "f"));
633
649
  });
634
650
  });
651
+ }, _Tools_limparSoap =
652
+ //Remove coisas inuteis da resposta do sefaz
653
+ async function _Tools_limparSoap(xml) {
654
+ const clear = [
655
+ 'soapenv:Envelope',
656
+ 'soapenv:Body',
657
+ 'nfeResultMsg',
658
+ 'soap:Envelope',
659
+ 'soap:Body',
660
+ 'nfeResultMsg',
661
+ 'nfeDistDFeInteresseResponse'
662
+ ];
663
+ let jXml = await xml2json(xml);
664
+ let index = 0;
665
+ while (index < clear.length) {
666
+ if (typeof jXml[clear[index]] !== "undefined") {
667
+ jXml = jXml[clear[index]];
668
+ index = 0; // reinicia a busca no novo nível
669
+ }
670
+ else {
671
+ index++;
672
+ }
673
+ }
674
+ return await json2xml(jXml);
635
675
  };
636
676
  export { Tools };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-sped-nfe",
3
- "version": "1.2.3",
3
+ "version": "1.2.32",
4
4
  "author": "Kalmon V. Tavares",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",