node-sped-nfe 1.0.4 → 1.0.6

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.
Files changed (46) hide show
  1. package/README.md +2 -0
  2. package/dist/utils/eventos.d.ts +5 -1
  3. package/dist/utils/eventos.js +1459 -9
  4. package/dist/utils/extras.d.ts +2 -0
  5. package/dist/utils/extras.js +58 -0
  6. package/dist/utils/make.js +13 -123
  7. package/dist/utils/tools.d.ts +6 -3
  8. package/dist/utils/tools.js +103 -26
  9. package/exemplos/consulta.js +19 -0
  10. package/exemplos/nfce.js +165 -0
  11. package/{testes → exemplos}/nfe.js +11 -5
  12. package/exemplos/status.js +19 -0
  13. package/package.json +10 -6
  14. package/schemas/leiauteNFe_v4.00.xsd +5 -5
  15. package/src/utils/eventos.ts +1466 -11
  16. package/src/utils/extras.ts +59 -0
  17. package/src/utils/make.ts +13 -124
  18. package/src/utils/tools.ts +125 -33
  19. package/dist/tsconfig.tsbuildinfo +0 -1
  20. package/dist/utils/sefaz.d.ts +0 -1
  21. package/dist/utils/sefaz.js +0 -64
  22. package/dist/utils/xmllint.d.ts +0 -4
  23. package/dist/utils/xmllint.js +0 -234520
  24. package/saida.txt +0 -0
  25. package/src/utils/schemas/consReciNFe_v4.00.xsd +0 -9
  26. package/src/utils/schemas/consSitNFe_v4.00.xsd +0 -9
  27. package/src/utils/schemas/consStatServ_v4.00.xsd +0 -9
  28. package/src/utils/schemas/enviNFe_v4.00.xsd +0 -9
  29. package/src/utils/schemas/inutNFe_v4.00.xsd +0 -9
  30. package/src/utils/schemas/leiauteConsSitNFe_v4.00.xsd +0 -502
  31. package/src/utils/schemas/leiauteConsStatServ_v4.00.xsd +0 -98
  32. package/src/utils/schemas/leiauteInutNFe_v4.00.xsd +0 -193
  33. package/src/utils/schemas/leiauteNFe_v4.00.xsd +0 -7412
  34. package/src/utils/schemas/nfe_v4.00.xsd +0 -9
  35. package/src/utils/schemas/procInutNFe_v4.00.xsd +0 -9
  36. package/src/utils/schemas/procNFe_v4.00.xsd +0 -9
  37. package/src/utils/schemas/retConsReciNFe_v4.00.xsd +0 -9
  38. package/src/utils/schemas/retConsSitNFe_v4.00.xsd +0 -9
  39. package/src/utils/schemas/retConsStatServ_v4.00.xsd +0 -9
  40. package/src/utils/schemas/retEnviNFe_v4.00.xsd +0 -9
  41. package/src/utils/schemas/retInutNFe_v4.00.xsd +0 -9
  42. package/src/utils/schemas/tiposBasico_v4.00.xsd +0 -598
  43. package/src/utils/schemas/xmldsig-core-schema_v1.01.xsd +0 -98
  44. package/testes/assinar.js +0 -16
  45. package/testes/nfe.json +0 -194
  46. package/testes/nfe_teste.json +0 -45
@@ -0,0 +1,2 @@
1
+ declare const cUF2UF: any, UF2cUF: any;
2
+ export { cUF2UF, UF2cUF };
@@ -0,0 +1,58 @@
1
+ const cUF2UF = {
2
+ "11": "RO",
3
+ "12": "AC",
4
+ "13": "AM",
5
+ "14": "RR",
6
+ "15": "PA",
7
+ "16": "AP",
8
+ "17": "TO",
9
+ "21": "MA",
10
+ "22": "PI",
11
+ "23": "CE",
12
+ "24": "RN",
13
+ "25": "PB",
14
+ "26": "PE",
15
+ "27": "AL",
16
+ "28": "SE",
17
+ "29": "BA",
18
+ "31": "MG",
19
+ "32": "ES",
20
+ "33": "RJ",
21
+ "35": "SP",
22
+ "41": "PR",
23
+ "42": "SC",
24
+ "43": "RS",
25
+ "50": "MS",
26
+ "51": "MT",
27
+ "52": "GO",
28
+ "53": "DF"
29
+ }, UF2cUF = {
30
+ "RO": "11",
31
+ "AC": "12",
32
+ "AM": "13",
33
+ "RR": "14",
34
+ "PA": "15",
35
+ "AP": "16",
36
+ "TO": "17",
37
+ "MA": "21",
38
+ "PI": "22",
39
+ "CE": "23",
40
+ "RN": "24",
41
+ "PB": "25",
42
+ "PE": "26",
43
+ "AL": "27",
44
+ "SE": "28",
45
+ "BA": "29",
46
+ "MG": "31",
47
+ "ES": "32",
48
+ "RJ": "33",
49
+ "SP": "35",
50
+ "PR": "41",
51
+ "SC": "42",
52
+ "RS": "43",
53
+ "MS": "50",
54
+ "MT": "51",
55
+ "GO": "52",
56
+ "DF": "53"
57
+ };
58
+ export { cUF2UF, UF2cUF };
@@ -3,8 +3,10 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
3
3
  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");
4
4
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
5
5
  };
6
- var _Make_instances, _Make_NFe, _Make_ICMSTot, _Make_gerarChaveNFe, _Make_calcularDigitoVerificador, _Make_getInfoQRCodeByUF, _Make_calICMSTot;
6
+ var _Make_instances, _Make_NFe, _Make_ICMSTot, _Make_gerarChaveNFe, _Make_calcularDigitoVerificador, _Make_calICMSTot;
7
7
  import { XMLBuilder } from "fast-xml-parser";
8
+ import { urlEventos } from "./eventos.js";
9
+ import { cUF2UF } from "./extras.js";
8
10
  //Classe da nota fiscal
9
11
  class Make {
10
12
  constructor() {
@@ -125,6 +127,9 @@ class Make {
125
127
  obj[cont] = { '@nItem': obj[cont]['@nItem'], prod: obj[cont], imposto: {} };
126
128
  delete obj[cont].prod['@nItem'];
127
129
  }
130
+ //Primeiro item + NFCe + Homologação
131
+ if (cont == 0 && __classPrivateFieldGet(this, _Make_NFe, "f").infNFe.ide.mod == 65 && __classPrivateFieldGet(this, _Make_NFe, "f").infNFe.ide.tpAmb == 2)
132
+ obj[cont].prod.xProd = "NOTA FISCAL EMITIDA EM AMBIENTE DE HOMOLOGACAO - SEM VALOR FISCAL";
128
133
  obj[cont].prod.qCom = (obj[cont].prod.qCom * 1).toFixed(4);
129
134
  obj[cont].prod.vUnCom = (obj[cont].prod.vUnCom * 1).toFixed(10);
130
135
  obj[cont].prod.vProd = (obj[cont].prod.vProd * 1).toFixed(2);
@@ -511,11 +516,13 @@ class Make {
511
516
  if (__classPrivateFieldGet(this, _Make_NFe, "f").infNFe[`@Id`] == null)
512
517
  __classPrivateFieldGet(this, _Make_NFe, "f").infNFe[`@Id`] = `NFe${__classPrivateFieldGet(this, _Make_instances, "m", _Make_gerarChaveNFe).call(this)}`;
513
518
  //Adicionar QrCode
514
- if (__classPrivateFieldGet(this, _Make_NFe, "f").infNFe.ide.mod == 55) {
515
- /*this.#NFe.infNFeSupl = {
516
- qrCode: "",
517
- urlChave: ""
518
- }*/
519
+ if (__classPrivateFieldGet(this, _Make_NFe, "f").infNFe.ide.mod == 65) {
520
+ //Como ja temos cUF, usamo dados do extras para convere em UF e achar os dados de url!
521
+ let tempUF = urlEventos(cUF2UF[__classPrivateFieldGet(this, _Make_NFe, "f").infNFe.ide.cUF], __classPrivateFieldGet(this, _Make_NFe, "f").infNFe['@versao']);
522
+ __classPrivateFieldGet(this, _Make_NFe, "f").infNFeSupl = {
523
+ qrCode: tempUF.mod65[__classPrivateFieldGet(this, _Make_NFe, "f").infNFe.ide.tpAmb == 1 ? 'producao' : 'homologacao'].NFeConsultaQR,
524
+ urlChave: tempUF.mod65[__classPrivateFieldGet(this, _Make_NFe, "f").infNFe.ide.tpAmb == 1 ? 'producao' : 'homologacao'].urlChave
525
+ };
519
526
  }
520
527
  let tempBuild = new XMLBuilder({
521
528
  ignoreAttributes: false,
@@ -554,123 +561,6 @@ _Make_NFe = new WeakMap(), _Make_ICMSTot = new WeakMap(), _Make_instances = new
554
561
  vdigit = 0;
555
562
  }
556
563
  return vdigit.toString();
557
- }, _Make_getInfoQRCodeByUF = function _Make_getInfoQRCodeByUF(uf, amb) {
558
- if (__classPrivateFieldGet(this, _Make_NFe, "f").infNFe.ide.tpAmb) {
559
- switch (__classPrivateFieldGet(this, _Make_NFe, "f").infNFe.ide.cUF) {
560
- case 'AC':
561
- return { urlChave: 'www.sefaznet.ac.gov.br/nfce/consulta', urlQRCode: 'http://www.sefaznet.ac.gov.br/nfce/qrcode' };
562
- case 'AL':
563
- return { urlChave: 'www.sefaz.al.gov.br/nfce/consulta', urlQRCode: 'http://nfce.sefaz.al.gov.br/QRCode/consultarNFCe.jsp' };
564
- case 'AP':
565
- return { urlChave: 'www.sefaz.ap.gov.br/nfce/consulta', urlQRCode: 'https://www.sefaz.ap.gov.br/nfce/nfcep.php' };
566
- case 'AM':
567
- return { urlChave: 'www.sefaz.am.gov.br/nfce/consulta', urlQRCode: 'http://sistemas.sefaz.am.gov.br/nfceweb/consultarNFCe.jsp' };
568
- case 'BA':
569
- return { urlChave: 'www.sefaz.ba.gov.br/nfce/consulta', urlQRCode: 'http://nfe.sefaz.ba.gov.br/servicos/nfce/modulos/geral/NFCEC_consulta_chave_acesso.aspx' };
570
- case 'CE':
571
- return { urlChave: 'www.sefaz.ce.gov.br/nfce/consulta', urlQRCode: 'http://nfce.sefaz.ce.gov.br/pages/ShowNFCe.html' };
572
- case 'DF':
573
- return { urlChave: 'www.fazenda.df.gov.br/nfce/consulta', urlQRCode: 'http://dec.fazenda.df.gov.br/ConsultarNFCe.aspx' };
574
- case 'ES':
575
- return { urlChave: 'www.sefaz.es.gov.br/nfce/consulta', urlQRCode: 'http://app.sefaz.es.gov.br/ConsultaNFCe/qrcode.aspx' };
576
- case 'GO':
577
- return { urlChave: 'www.sefaz.go.gov.br/nfce/consulta', urlQRCode: 'http://nfe.sefaz.go.gov.br/nfeweb/sites/nfce/danfeNFCe' };
578
- case 'MA':
579
- return { urlChave: 'www.sefaz.ma.gov.br/nfce/consulta', urlQRCode: 'http://www.nfce.sefaz.ma.gov.br/portal/consultarNFCe.jsp' };
580
- case 'MG':
581
- return { urlChave: 'http://nfce.fazenda.mg.gov.br/portalnfce', urlQRCode: 'https://nfce.fazenda.mg.gov.br/portalnfce/sistema/qrcode.xhtml' };
582
- case 'MS':
583
- return { urlChave: 'http://www.dfe.ms.gov.br/nfce/consulta', urlQRCode: 'http://www.dfe.ms.gov.br/nfce/qrcode' };
584
- case '51': //MT
585
- return { urlChave: 'http://www.sefaz.mt.gov.br/nfce/consultanfce', urlQRCode: 'http://www.sefaz.mt.gov.br/nfce/consultanfce' };
586
- case 'PA':
587
- return { urlChave: 'www.sefa.pa.gov.br/nfce/consulta', urlQRCode: 'https://appnfc.sefa.pa.gov.br/portal/view/consultas/nfce/nfceForm.seam' };
588
- case 'PB':
589
- return { urlChave: 'www.receita.pb.gov.br/nfce/consulta', urlQRCode: 'http://www.receita.pb.gov.br/nfce' };
590
- case 'PE':
591
- return { urlChave: 'nfce.sefaz.pe.gov.br/nfce/consulta', urlQRCode: 'http://nfce.sefaz.pe.gov.br/nfce-web/consultarNFCe' };
592
- case 'PI':
593
- return { urlChave: 'www.sefaz.pi.gov.br/nfce/consulta', urlQRCode: 'http://www.sefaz.pi.gov.br/nfce/qrcode' };
594
- case 'PR':
595
- return { urlChave: 'http://www.fazenda.pr.gov.br/nfce/consulta', urlQRCode: 'http://www.fazenda.pr.gov.br/nfce/qrcode/' };
596
- case 'RJ':
597
- return { urlChave: 'www.fazenda.rj.gov.br/nfce/consulta', urlQRCode: 'http://www4.fazenda.rj.gov.br/consultaNFCe/QRCode' };
598
- case 'RN':
599
- return { urlChave: 'www.set.rn.gov.br/nfce/consulta', urlQRCode: 'http://nfce.set.rn.gov.br/consultarNFCe.aspx' };
600
- case 'RO':
601
- return { urlChave: 'www.sefin.ro.gov.br/nfce/consulta', urlQRCode: 'http://www.nfce.sefin.ro.gov.br/consultanfce/consulta.jsp' };
602
- case 'RS':
603
- return { urlChave: 'www.sefaz.rs.gov.br/nfce/consulta', urlQRCode: 'https://www.sefaz.rs.gov.br/NFCE/NFCE-COM.aspx' };
604
- case 'RR':
605
- return { urlChave: 'www.sefaz.rr.gov.br/nfce/consulta', urlQRCode: 'https://www.sefaz.rr.gov.br/nfce/servlet/qrcode' };
606
- case 'SE':
607
- return { urlChave: 'http://www.nfce.se.gov.br/nfce/consulta', urlQRCode: 'http://www.nfce.se.gov.br/portal/consultarNFCe.jsp' };
608
- case 'SP':
609
- return { urlChave: 'https://www.nfce.fazenda.sp.gov.br/consulta', urlQRCode: 'https://www.nfce.fazenda.sp.gov.br/qrcode' };
610
- case 'TO':
611
- return { urlChave: 'www.sefaz.to.gov.br/nfce/consulta', urlQRCode: 'http://www.sefaz.to.gov.br/nfce/qrcode' };
612
- default:
613
- throw new Error('URL do QRCode não encontrada pelo UF (' + uf + ') informado.');
614
- }
615
- }
616
- else {
617
- switch (__classPrivateFieldGet(this, _Make_NFe, "f").infNFe.ide.cUF) {
618
- case 'AC':
619
- return { urlChave: 'www.sefaznet.ac.gov.br/nfce/consulta', urlQRCode: 'http://hml.sefaznet.ac.gov.br/nfce/qrcode' };
620
- case 'AL':
621
- return { urlChave: 'www.sefaz.al.gov.br/nfce/consulta', urlQRCode: 'http://nfce.sefaz.al.gov.br/QRCode/consultarNFCe.jsp' };
622
- case 'AP':
623
- return { urlChave: 'www.sefaz.ap.gov.br/nfce/consulta', urlQRCode: 'https://www.sefaz.ap.gov.br/nfcehml/nfce.php' };
624
- case 'AM':
625
- return { urlChave: 'https://sistemas.sefaz.am.gov.br/nfceweb-hom/formConsulta.do', urlQRCode: 'https://sistemas.sefaz.am.gov.br/nfceweb-hom/consultarNFCe.jsp' };
626
- case 'BA':
627
- return { urlChave: 'http://hinternet.sefaz.ba.gov.br/nfce/consulta', urlQRCode: 'http://hnfe.sefaz.ba.gov.br/servicos/nfce/modulos/geral/NFCEC_consulta_chave_acesso.aspx' };
628
- case 'CE':
629
- return { urlChave: 'www.sefaz.ce.gov.br/nfce/consulta', urlQRCode: 'http://nfceh.sefaz.ce.gov.br/pages/ShowNFCe.html' };
630
- case 'DF':
631
- return { urlChave: 'www.fazenda.df.gov.br/nfce/consulta', urlQRCode: 'http://dec.fazenda.df.gov.br/ConsultarNFCe.aspx' };
632
- case 'ES':
633
- return { urlChave: 'www.sefaz.es.gov.br/nfce/consulta', urlQRCode: 'http://homologacao.sefaz.es.gov.br/ConsultaNFCe/qrcode.aspx' };
634
- case 'GO':
635
- return { urlChave: 'http://www.nfce.go.gov.br/post/ver/214413/consulta-nfc-e-homologacao', urlQRCode: 'http://homolog.sefaz.go.gov.br/nfeweb/sites/nfce/danfeNFCe' };
636
- case 'MA':
637
- return { urlChave: 'www.sefaz.ma.gov.br/nfce/consulta', urlQRCode: 'http://www.hom.nfce.sefaz.ma.gov.br/portal/consultarNFCe.jsp' };
638
- case 'MG':
639
- return { urlChave: 'http://hnfce.fazenda.mg.gov.br/portalnfce', urlQRCode: 'https://nfce.fazenda.mg.gov.br/portalnfce/sistema/qrcode.xhtml' };
640
- case 'MS':
641
- return { urlChave: 'http://www.dfe.ms.gov.br/nfce/consulta', urlQRCode: 'http://www.dfe.ms.gov.br/nfce/qrcode' };
642
- case '51': //MT
643
- return { urlChave: 'http://homologacao.sefaz.mt.gov.br/nfce/consultanfce', urlQRCode: 'http://homologacao.sefaz.mt.gov.br/nfce/consultanfce' };
644
- case 'PA':
645
- return { urlChave: 'www.sefa.pa.gov.br/nfce/consulta', urlQRCode: 'https://appnfc.sefa.pa.gov.br/portal-homologacao/view/consultas/nfce/nfceForm.seam' };
646
- case 'PB':
647
- return { urlChave: 'www.receita.pb.gov.br/nfcehom', urlQRCode: 'http://www.receita.pb.gov.br/nfcehom' };
648
- case 'PE':
649
- return { urlChave: 'nfce.sefaz.pe.gov.br/nfce/consulta', urlQRCode: 'http://nfcehomolog.sefaz.pe.gov.br/nfce-web/consultarNFCe' };
650
- case 'PI':
651
- return { urlChave: 'www.sefaz.pi.gov.br/nfce/consulta', urlQRCode: 'http://www.sefaz.pi.gov.br/nfce/qrcode' };
652
- case 'PR':
653
- return { urlChave: 'http://www.fazenda.pr.gov.br/nfce/consulta', urlQRCode: 'http://www.fazenda.pr.gov.br/nfce/qrcode/' };
654
- case 'RJ':
655
- return { urlChave: 'www.fazenda.rj.gov.br/nfce/consulta', urlQRCode: 'http://www4.fazenda.rj.gov.br/consultaNFCe/QRCode' };
656
- case 'RN':
657
- return { urlChave: 'www.set.rn.gov.br/nfce/consulta', urlQRCode: 'http://hom.nfce.set.rn.gov.br/consultarNFCe.aspx' };
658
- case 'RO':
659
- return { urlChave: 'www.sefin.ro.gov.br/nfce/consulta', urlQRCode: 'http://www.nfce.sefin.ro.gov.br/consultanfce/consulta.jsp' };
660
- case 'RS':
661
- return { urlChave: 'www.sefaz.rs.gov.br/nfce/consulta', urlQRCode: 'https://www.sefaz.rs.gov.br/NFCE/NFCE-COM.aspx' };
662
- case 'RR':
663
- return { urlChave: 'www.sefaz.rr.gov.br/nfce/consulta', urlQRCode: 'http://200.174.88.103:8080/nfce/servlet/qrcode' };
664
- case 'SE':
665
- return { urlChave: 'http://www.hom.nfe.se.gov.br/nfce/consulta', urlQRCode: 'http://www.hom.nfe.se.gov.br/portal/consultarNFCe.jsp' };
666
- case 'SP':
667
- return { urlChave: 'https://www.homologacao.nfce.fazenda.sp.gov.br/consulta', urlQRCode: 'https://www.homologacao.nfce.fazenda.sp.gov.br/qrcode' };
668
- case 'TO':
669
- return { urlChave: 'http://homologacao.sefaz.to.gov.br/nfce/consulta.jsf', urlQRCode: 'http://homologacao.sefaz.to.gov.br/nfce/qrcode' };
670
- default:
671
- throw new Error('URL do QRCode não encontrada pelo UF (' + uf + ') informado.');
672
- }
673
- }
674
564
  }, _Make_calICMSTot = function _Make_calICMSTot(obj) {
675
565
  Object.keys(obj).map(key => {
676
566
  if (__classPrivateFieldGet(this, _Make_ICMSTot, "f")[key] !== undefined) {
@@ -3,18 +3,21 @@ declare class Tools {
3
3
  constructor(config?: {
4
4
  mod: string;
5
5
  xmllint: string;
6
- cUF: string;
6
+ UF: string;
7
7
  tpAmb: number;
8
+ CSC: string;
9
+ CSCid: string;
10
+ versao: string;
8
11
  }, certificado?: {
9
12
  pfx: string;
10
13
  senha: string;
11
14
  });
12
- teste(): Promise<object>;
13
15
  sefazEnviaLote(xml: string, data?: any): Promise<string>;
14
16
  xmlSign(xmlJSON: string, data?: any): Promise<string>;
15
17
  xml2json(xml: string): Promise<object>;
16
18
  json2xml(obj: object): Promise<string>;
17
19
  getCertificado(): Promise<unknown>;
18
- sefazStatus(): Promise<unknown>;
20
+ consultarNFe(chNFe: string): Promise<string>;
21
+ sefazStatus(): Promise<string>;
19
22
  }
20
23
  export { Tools };
@@ -9,21 +9,21 @@ 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_xmlTools, _Tools_pem, _Tools_config, _Tools_xmlValido, _Tools_certTools;
12
+ var _Tools_instances, _Tools_cert, _Tools_xmlTools, _Tools_pem, _Tools_config, _Tools_gerarQRCodeNFCe, _Tools_xmlValido, _Tools_certTools;
13
13
  import { XMLParser, XMLBuilder } from "fast-xml-parser";
14
- import pem from "pem";
15
14
  import https from "https";
16
15
  import { spawnSync } from "child_process";
17
16
  import tmp from "tmp";
18
17
  import crypto from "crypto";
19
- import { urlServicos } from "./eventos.js";
18
+ import { urlEventos } from "./eventos.js";
20
19
  import fs from "fs";
21
20
  import path from 'path';
22
21
  import { fileURLToPath } from 'url';
22
+ import pem from 'pem';
23
23
  const __filename = fileURLToPath(import.meta.url);
24
24
  const __dirname = path.dirname(__filename);
25
25
  class Tools {
26
- constructor(config = { mod: "", xmllint: 'xmllint', cUF: '51', tpAmb: 2 }, certificado = { pfx: "", senha: "" }) {
26
+ constructor(config = { mod: "", xmllint: 'xmllint', UF: '', tpAmb: 2, CSC: "", CSCid: "", versao: "4.00" }, certificado = { pfx: "", senha: "" }) {
27
27
  _Tools_instances.add(this);
28
28
  _Tools_cert.set(this, void 0);
29
29
  _Tools_xmlTools.set(this, {
@@ -49,9 +49,6 @@ class Tools {
49
49
  parseTagValue: false, // Evita conversão automática de valores
50
50
  });
51
51
  }
52
- async teste() {
53
- return await __classPrivateFieldGet(this, _Tools_instances, "m", _Tools_certTools).call(this);
54
- }
55
52
  sefazEnviaLote(xml, data = { idLote: 1, indSinc: 0, compactar: false }) {
56
53
  return new Promise(async (resvol, reject) => {
57
54
  if (typeof data.idLote == "undefined")
@@ -83,9 +80,9 @@ class Tools {
83
80
  },
84
81
  };
85
82
  let xmlLote = await this.json2xml(jsonXmlLote);
86
- fs.writeFileSync("testes/nfe_guara_sign_lote.xml", xmlLote, { encoding: "utf8" });
87
83
  try {
88
- const req = https.request(urlServicos[`${__classPrivateFieldGet(this, _Tools_config, "f").cUF}`][`mod_${__classPrivateFieldGet(this, _Tools_config, "f").mod}`].NFeAutorizacao[(__classPrivateFieldGet(this, _Tools_config, "f").tpAmb == 1 ? "producao" : "homologacao")], {
84
+ let tempUF = urlEventos(__classPrivateFieldGet(this, _Tools_config, "f").UF, __classPrivateFieldGet(this, _Tools_config, "f").versao);
85
+ const req = https.request(tempUF[`mod${__classPrivateFieldGet(this, _Tools_config, "f").mod}`][(__classPrivateFieldGet(this, _Tools_config, "f").tpAmb == 1 ? "producao" : "homologacao")].NFeAutorizacao, {
89
86
  ...{
90
87
  method: 'POST',
91
88
  headers: {
@@ -165,8 +162,11 @@ class Tools {
165
162
  "@xmlns": "http://www.w3.org/2000/09/xmldsig#"
166
163
  }
167
164
  };
165
+ if (xml.NFe.infNFe.ide.mod == 65) {
166
+ 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);
167
+ }
168
168
  this.json2xml(xml).then(async (res) => {
169
- __classPrivateFieldGet(this, _Tools_instances, "m", _Tools_xmlValido).call(this, res);
169
+ __classPrivateFieldGet(this, _Tools_instances, "m", _Tools_xmlValido).call(this, res, 'nfe_v4.00');
170
170
  resvol(res);
171
171
  }).catch(err => {
172
172
  reject(err);
@@ -185,32 +185,95 @@ class Tools {
185
185
  }
186
186
  async getCertificado() {
187
187
  return new Promise(async (resvol, reject) => {
188
- await __classPrivateFieldGet(this, _Tools_instances, "m", _Tools_certTools).call(this).then(resvol).catch(reject);
188
+ __classPrivateFieldGet(this, _Tools_instances, "m", _Tools_certTools).call(this).then(resvol).catch(reject);
189
+ });
190
+ }
191
+ consultarNFe(chNFe) {
192
+ return new Promise(async (resolve, reject) => {
193
+ if (!chNFe || chNFe.length !== 44) {
194
+ return reject("consultarNFe(chNFe) -> chave inválida!");
195
+ }
196
+ if (typeof __classPrivateFieldGet(this, _Tools_config, "f").UF === "undefined")
197
+ throw "consultarNFe({...UF}) -> não definido!";
198
+ if (typeof __classPrivateFieldGet(this, _Tools_config, "f").tpAmb === "undefined")
199
+ throw "consultarNFe({...tpAmb}) -> não definido!";
200
+ if (typeof __classPrivateFieldGet(this, _Tools_config, "f").mod === "undefined")
201
+ throw "consultarNFe({...mod}) -> não definido!";
202
+ let consSitNFe = {
203
+ "@xmlns": "http://www.portalfiscal.inf.br/nfe",
204
+ "@versao": "4.00",
205
+ "tpAmb": __classPrivateFieldGet(this, _Tools_config, "f").tpAmb,
206
+ "xServ": "CONSULTAR",
207
+ "chNFe": chNFe
208
+ };
209
+ let xmlObj = {
210
+ "soap:Envelope": {
211
+ "@xmlns:soap": "http://www.w3.org/2003/05/soap-envelope",
212
+ "@xmlns:nfe": "http://www.portalfiscal.inf.br/nfe/wsdl/NFeConsultaProtocolo4",
213
+ "soap:Body": {
214
+ "nfe:nfeDadosMsg": {
215
+ "consSitNFe": consSitNFe
216
+ }
217
+ }
218
+ }
219
+ };
220
+ try {
221
+ const builder = new XMLBuilder({
222
+ ignoreAttributes: false,
223
+ attributeNamePrefix: "@"
224
+ });
225
+ // Validação do XML interno (opcional)
226
+ __classPrivateFieldGet(this, _Tools_instances, "m", _Tools_xmlValido).call(this, builder.build({ consSitNFe }), 'consSitNFe_v4.00');
227
+ const xml = builder.build(xmlObj);
228
+ let tempUF = urlEventos(__classPrivateFieldGet(this, _Tools_config, "f").UF, __classPrivateFieldGet(this, _Tools_config, "f").versao);
229
+ const url = tempUF[`mod${__classPrivateFieldGet(this, _Tools_config, "f").mod}`][(__classPrivateFieldGet(this, _Tools_config, "f").tpAmb == 1 ? "producao" : "homologacao")].NFeConsultaProtocolo;
230
+ const req = https.request(url, {
231
+ method: 'POST',
232
+ headers: {
233
+ 'Content-Type': 'application/soap+xml; charset=utf-8',
234
+ 'Content-Length': xml.length,
235
+ },
236
+ rejectUnauthorized: false,
237
+ ...await __classPrivateFieldGet(this, _Tools_instances, "m", _Tools_certTools).call(this)
238
+ }, (res) => {
239
+ let data = '';
240
+ res.on('data', (chunk) => data += chunk);
241
+ res.on('end', () => resolve(data));
242
+ });
243
+ req.on('error', (err) => reject(err));
244
+ req.write(xml);
245
+ req.end();
246
+ }
247
+ catch (err) {
248
+ reject(err);
249
+ }
189
250
  });
190
251
  }
191
252
  //Consulta status sefaz
192
253
  async sefazStatus() {
193
254
  return new Promise(async (resvol, reject) => {
194
- await __classPrivateFieldGet(this, _Tools_instances, "m", _Tools_certTools).call(this);
195
- if (typeof __classPrivateFieldGet(this, _Tools_config, "f").cUF == "undefined")
196
- throw "sefazStatus({...cUF}) -> não definido!";
255
+ if (typeof __classPrivateFieldGet(this, _Tools_config, "f").UF == "undefined")
256
+ throw "sefazStatus({...UF}) -> não definido!";
197
257
  if (typeof __classPrivateFieldGet(this, _Tools_config, "f").tpAmb == "undefined")
198
258
  throw "sefazStatus({...tpAmb}) -> não definido!";
199
259
  if (typeof __classPrivateFieldGet(this, _Tools_config, "f").mod == "undefined")
200
260
  throw "sefazStatus({...mod}) -> não definido!";
261
+ let tempUF = urlEventos(__classPrivateFieldGet(this, _Tools_config, "f").UF, __classPrivateFieldGet(this, _Tools_config, "f").versao);
262
+ //Separado para validar o corpo da consulta
263
+ let consStatServ = {
264
+ "@versao": "4.00",
265
+ "@xmlns": "http://www.portalfiscal.inf.br/nfe",
266
+ "tpAmb": __classPrivateFieldGet(this, _Tools_config, "f").tpAmb,
267
+ "cUF": tempUF.cUF,
268
+ "xServ": "STATUS"
269
+ };
201
270
  let xmlObj = {
202
271
  "soap:Envelope": {
203
272
  "@xmlns:soap": "http://www.w3.org/2003/05/soap-envelope",
204
273
  "@xmlns:nfe": "http://www.portalfiscal.inf.br/nfe/wsdl/NFeStatusServico4",
205
274
  "soap:Body": {
206
275
  "nfe:nfeDadosMsg": {
207
- "consStatServ": {
208
- "@versao": "4.00",
209
- "@xmlns": "http://www.portalfiscal.inf.br/nfe",
210
- "tpAmb": __classPrivateFieldGet(this, _Tools_config, "f").tpAmb,
211
- "cUF": __classPrivateFieldGet(this, _Tools_config, "f").cUF,
212
- "xServ": "STATUS"
213
- }
276
+ consStatServ
214
277
  }
215
278
  }
216
279
  }
@@ -220,8 +283,11 @@ class Tools {
220
283
  ignoreAttributes: false,
221
284
  attributeNamePrefix: "@"
222
285
  });
286
+ //Validação
287
+ __classPrivateFieldGet(this, _Tools_instances, "m", _Tools_xmlValido).call(this, tempBuild.build({ consStatServ }), 'consStatServ_v4.00');
288
+ let tempUF = urlEventos(__classPrivateFieldGet(this, _Tools_config, "f").UF, __classPrivateFieldGet(this, _Tools_config, "f").versao);
223
289
  let xml = tempBuild.build(xmlObj);
224
- const req = https.request(urlServicos[`${__classPrivateFieldGet(this, _Tools_config, "f").cUF}`][`mod_${__classPrivateFieldGet(this, _Tools_config, "f").mod}`].NfeStatusServico[(__classPrivateFieldGet(this, _Tools_config, "f").tpAmb == 1 ? "producao" : "homologacao")], {
290
+ const req = https.request(tempUF[`mod${__classPrivateFieldGet(this, _Tools_config, "f").mod}`][(__classPrivateFieldGet(this, _Tools_config, "f").tpAmb == 1 ? "producao" : "homologacao")].NFeStatusServico, {
225
291
  ...{
226
292
  method: 'POST',
227
293
  headers: {
@@ -230,7 +296,7 @@ class Tools {
230
296
  },
231
297
  rejectUnauthorized: false
232
298
  },
233
- ...__classPrivateFieldGet(this, _Tools_pem, "f")
299
+ ...await __classPrivateFieldGet(this, _Tools_instances, "m", _Tools_certTools).call(this)
234
300
  }, (res) => {
235
301
  let data = '';
236
302
  res.on('data', (chunk) => {
@@ -252,12 +318,23 @@ class Tools {
252
318
  });
253
319
  }
254
320
  }
255
- _Tools_cert = new WeakMap(), _Tools_xmlTools = new WeakMap(), _Tools_pem = new WeakMap(), _Tools_config = new WeakMap(), _Tools_instances = new WeakSet(), _Tools_xmlValido =
321
+ _Tools_cert = new WeakMap(), _Tools_xmlTools = new WeakMap(), _Tools_pem = new WeakMap(), _Tools_config = new WeakMap(), _Tools_instances = new WeakSet(), _Tools_gerarQRCodeNFCe = function _Tools_gerarQRCodeNFCe(NFe, versaoQRCode = "2", idCSC, CSC) {
322
+ let s = '|', concat, hash;
323
+ if (NFe.infNFe.ide.tpEmis == 1) {
324
+ concat = [NFe.infNFe['@Id'].replace("NFe", ""), versaoQRCode, NFe.infNFe.ide.tpAmb, Number(idCSC)].join(s);
325
+ }
326
+ else {
327
+ let hexDigestValue = Buffer.from(NFe.Signature.SignedInfo.Reference.DigestValue).toString('hex');
328
+ concat = [NFe.infNFe['@Id'].replace("NFe", ""), versaoQRCode, NFe.infNFe.ide.tpAmb, NFe.infNFe.ide.dhEmi, NFe.infNFe.total.ICMSTot.vNF, hexDigestValue, Number(idCSC)].join(s);
329
+ }
330
+ hash = crypto.createHash('sha1').update(concat + CSC).digest('hex');
331
+ return NFe.infNFeSupl.qrCode + '?p=' + concat + s + hash;
332
+ }, _Tools_xmlValido =
256
333
  //Validar XML da NFe, somente apos assinar
257
- async function _Tools_xmlValido(xml) {
334
+ async function _Tools_xmlValido(xml, xsd) {
258
335
  const xmlFile = tmp.fileSync({ mode: 0o644, prefix: 'xml-', postfix: '.xml' });
259
336
  fs.writeFileSync(xmlFile.name, xml, { encoding: 'utf8' });
260
- const schemaPath = path.resolve(__dirname, '../../schemas/nfe_v4.00.xsd');
337
+ const schemaPath = path.resolve(__dirname, `../../schemas/${xsd}.xsd`);
261
338
  const verif = spawnSync(__classPrivateFieldGet(this, _Tools_config, "f").xmllint, ['--noout', '--schema', schemaPath, xmlFile.name], { encoding: 'utf8' });
262
339
  xmlFile.removeCallback();
263
340
  // Aqui, usamos o operador de encadeamento opcional (?.)
@@ -0,0 +1,19 @@
1
+ import { Tools } from "../dist/index.js"
2
+ import fs from "fs";
3
+
4
+ let myTools = new Tools({ //Configuração de habiente e sistema
5
+ mod: '55',
6
+ tpAmb: 1,
7
+ UF: 'MT',
8
+ versao: "4.00",
9
+
10
+ //Optativo: Leia sobre Requisitos.
11
+ xmllint: `../libxml2-2.9.3-win32-x86_64/bin/xmllint.exe`
12
+ }, { //Certificado digital
13
+ pfx: '../certificado.pfx',
14
+ senha: fs.readFileSync('../senha.txt', { encoding: "utf8" }),
15
+ });
16
+
17
+ myTools.consultarNFe("CHAVE DA NFE").then(res => {
18
+ console.log(res);
19
+ })
@@ -0,0 +1,165 @@
1
+ import { Make, Tools } from "../dist/index.js"
2
+ import fs from "fs";
3
+
4
+
5
+ // temp = {senha, CSC, CSCid}
6
+ let temp = JSON.parse(fs.readFileSync('../certificado2.json', { encoding: "utf8" }))
7
+ let myTools = new Tools({ //Configuração de habiente e sistema
8
+ mod: '65',
9
+ tpAmb: 2,
10
+ cUF: '51',
11
+ CSC: temp.CSC,
12
+ CSCid: temp.CSCid,
13
+
14
+ //Optativo: Leia sobre Requisitos.
15
+ xmllint: `../libxml2-2.9.3-win32-x86_64/bin/xmllint.exe`
16
+ }, { //Certificado digital
17
+ pfx: '../certificado2.pfx',
18
+ senha: temp.senha,
19
+ });
20
+
21
+ let NFe = new Make();
22
+ NFe.tagInfNFe({ Id: null, versao: '4.00' });
23
+ NFe.tagIde({
24
+ cUF: "51",
25
+ cNF: "00002023",
26
+ natOp: "VENDA",
27
+ mod: "65",
28
+ serie: "0",
29
+ nNF: "248",
30
+ dhEmi: NFe.formatData(),
31
+ tpNF: "1",
32
+ idDest: "1",
33
+ cMunFG: "5106257",
34
+ tpImp: "4",
35
+ tpEmis: "1",
36
+ cDV: "1",
37
+ tpAmb: "2",
38
+ finNFe: "1",
39
+ indFinal: "1",
40
+ indPres: "1",
41
+ indIntermed: "0",
42
+ procEmi: "0",
43
+ verProc: "4.13"
44
+ });
45
+ NFe.tagEmit({
46
+ CNPJ: "47506306000188",
47
+ xNome: "47.506.306 KALMON VALADAO TAVARES",
48
+ xFant: "GUARA DEV",
49
+ IE: "139551956",
50
+ CRT: "1"
51
+ });
52
+ NFe.tagEnderEmit({
53
+ xLgr: "AV. Para",
54
+ nro: "138",
55
+ xBairro: "Uniao",
56
+ cMun: "5106257",
57
+ xMun: "Nova Xavantina",
58
+ UF: "MT",
59
+ CEP: "78690000",
60
+ cPais: "1058",
61
+ xPais: "BRASIL",
62
+ fone: "66981352912"
63
+ });
64
+ NFe.tagDest({
65
+ CPF: "00000000000",
66
+ xNome: "JOAO PAULO DA SILVA",
67
+ indIEDest: "9",
68
+ });
69
+ NFe.tagProd([
70
+ {
71
+ cProd: "126",
72
+ cEAN: "SEM GTIN",
73
+ xProd: "CABOS MICROFONE DMX XR CANON BALANCEADO 20 METROS",
74
+ NCM: "85044010",
75
+ CFOP: "5102",
76
+ uCom: "UNID",
77
+ qCom: "3.0000",
78
+ vUnCom: "132.0000000000",
79
+ vProd: "396.00",
80
+ cEANTrib: "SEM GTIN",
81
+ uTrib: "UNID",
82
+ qTrib: "3.0000",
83
+ vUnTrib: "132.0000000000",
84
+ indTot: "1"
85
+ },
86
+ {
87
+ cProd: "129",
88
+ cEAN: "SEM GTIN",
89
+ xProd: "CABO P2 PARA P10 CELULAR MESA DE SOM CAIXA DE SOM 25 METRO",
90
+ NCM: "85044010",
91
+ CFOP: "5102",
92
+ uCom: "UNID",
93
+ qCom: "2.0000",
94
+ vUnCom: "218.0000000000",
95
+ vProd: "436.00",
96
+ cEANTrib: "SEM GTIN",
97
+ uTrib: "UNID",
98
+ qTrib: "2.0000",
99
+ vUnTrib: "218.0000000000",
100
+ indTot: "1",
101
+ },
102
+ {
103
+ "cProd": 127,
104
+ "cEAN": "SEM GTIN",
105
+ "xProd": "CABO DE MICROFONE XLR FEMEA PARA P10 MONO 20 METROS CIRILO CABOS",
106
+ "NCM": 85044010,
107
+ "CFOP": 5102,
108
+ "uCom": "UNID",
109
+ "qCom": 2,
110
+ "vUnCom": 185,
111
+ "vProd": 370,
112
+ "cEANTrib": "SEM GTIN",
113
+ "uTrib": "UNID",
114
+ "qTrib": 2,
115
+ "vUnTrib": 185,
116
+ "vDesc": 38,
117
+ "indTot": 1
118
+ },
119
+ {
120
+ "cProd": 128,
121
+ "cEAN": "SEM GTIN",
122
+ "xProd": "CABO DE AUDIO P10 X P10 MONO BLINDADO 5 METROS",
123
+ "NCM": 85044010,
124
+ "CFOP": 5102,
125
+ "uCom": "UNID",
126
+ "qCom": 2,
127
+ "vUnCom": 18,
128
+ "vProd": 36,
129
+ "cEANTrib": "SEM GTIN",
130
+ "uTrib": "UNID",
131
+ "qTrib": 2,
132
+ "vUnTrib": 18,
133
+ "indTot": 1
134
+ }
135
+ ]);
136
+
137
+ //Setor o imposto de cada produto.
138
+ [0, 1, 2, 3].map((value, index) => {
139
+ NFe.tagProdICMSSN(index, { orig: "0", CSOSN: "400" })
140
+ NFe.tagProdPIS(index, { CST: "49", qBCProd: "0.0000", vAliqProd: "0.0000", vPIS: "0.00" })
141
+ NFe.tagProdCOFINS(index, { CST: "49", qBCProd: "0.0000", vAliqProd: "0.0000", vCOFINS: "0.00" })
142
+ });
143
+ NFe.tagICMSTot();
144
+ NFe.tagTransp({ modFrete: 9 });
145
+ NFe.tagDetPag([{ indPag: 0, tPag: 17, vPag: "1200.00" }]);
146
+ NFe.tagTroco("0.00");
147
+ NFe.tagInfRespTec({ CNPJ: "47506306000188", xContato: "Guara Dev", email: "admin@guaradev.com", fone: "5566999638922" })
148
+ fs.writeFileSync("testes/nfe.xml", NFe.xml(), { encoding: "utf-8" });
149
+
150
+ //NFe.xml() = retorna o XML gerado ate o momento.
151
+ // myTools.xmlSign(..) = Assina o xml utlizando o certificado declarado em new Tools.
152
+ myTools.xmlSign(NFe.xml()).then(async xmlSign => {
153
+ fs.writeFileSync("testes/nfe_sign.xml", xmlSign, { encoding: "utf-8" });
154
+ myTools.sefazEnviaLote(xmlSign, { indSinc: 1 }).then(res => {
155
+ console.log(res)
156
+ })
157
+ }).catch(err => {
158
+ console.log(err)
159
+ })
160
+
161
+ /*
162
+ myTools.sefazStatus().then(res => {
163
+ console.log(res)
164
+ });
165
+ */