node-sped-nfe 1.0.4 → 1.0.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/README.md +2 -0
- package/dist/utils/eventos.d.ts +4 -1
- package/dist/utils/eventos.js +770 -9
- package/dist/utils/make.js +10 -123
- package/dist/utils/tools.d.ts +3 -2
- package/dist/utils/tools.js +34 -22
- package/exemplos/nfce.js +165 -0
- package/{testes → exemplos}/nfe.js +7 -2
- package/exemplos/status.js +18 -0
- package/package.json +8 -6
- package/schemas/leiauteNFe_v4.00.xsd +5 -5
- package/src/utils/eventos.ts +772 -11
- package/src/utils/make.ts +11 -125
- package/src/utils/tools.ts +47 -29
- package/dist/tsconfig.tsbuildinfo +0 -1
- package/dist/utils/sefaz.d.ts +0 -1
- package/dist/utils/sefaz.js +0 -64
- package/dist/utils/xmllint.d.ts +0 -4
- package/dist/utils/xmllint.js +0 -234520
- package/saida.txt +0 -0
- package/testes/assinar.js +0 -16
- package/testes/nfe.json +0 -194
- package/testes/nfe_teste.json +0 -45
package/dist/utils/make.js
CHANGED
@@ -3,8 +3,9 @@ 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,
|
6
|
+
var _Make_instances, _Make_NFe, _Make_ICMSTot, _Make_gerarChaveNFe, _Make_calcularDigitoVerificador, _Make_calICMSTot;
|
7
7
|
import { XMLBuilder } from "fast-xml-parser";
|
8
|
+
import { qrCodeUrls } from "./eventos.js";
|
8
9
|
//Classe da nota fiscal
|
9
10
|
class Make {
|
10
11
|
constructor() {
|
@@ -125,6 +126,9 @@ class Make {
|
|
125
126
|
obj[cont] = { '@nItem': obj[cont]['@nItem'], prod: obj[cont], imposto: {} };
|
126
127
|
delete obj[cont].prod['@nItem'];
|
127
128
|
}
|
129
|
+
//Primeiro item + NFCe + Homologação
|
130
|
+
if (cont == 0 && __classPrivateFieldGet(this, _Make_NFe, "f").infNFe.ide.mod == 65 && __classPrivateFieldGet(this, _Make_NFe, "f").infNFe.ide.tpAmb == 2)
|
131
|
+
obj[cont].prod.xProd = "NOTA FISCAL EMITIDA EM AMBIENTE DE HOMOLOGACAO - SEM VALOR FISCAL";
|
128
132
|
obj[cont].prod.qCom = (obj[cont].prod.qCom * 1).toFixed(4);
|
129
133
|
obj[cont].prod.vUnCom = (obj[cont].prod.vUnCom * 1).toFixed(10);
|
130
134
|
obj[cont].prod.vProd = (obj[cont].prod.vProd * 1).toFixed(2);
|
@@ -511,11 +515,11 @@ class Make {
|
|
511
515
|
if (__classPrivateFieldGet(this, _Make_NFe, "f").infNFe[`@Id`] == null)
|
512
516
|
__classPrivateFieldGet(this, _Make_NFe, "f").infNFe[`@Id`] = `NFe${__classPrivateFieldGet(this, _Make_instances, "m", _Make_gerarChaveNFe).call(this)}`;
|
513
517
|
//Adicionar QrCode
|
514
|
-
if (__classPrivateFieldGet(this, _Make_NFe, "f").infNFe.ide.mod ==
|
515
|
-
|
516
|
-
qrCode: "",
|
517
|
-
urlChave: ""
|
518
|
-
}
|
518
|
+
if (__classPrivateFieldGet(this, _Make_NFe, "f").infNFe.ide.mod == 65) {
|
519
|
+
__classPrivateFieldGet(this, _Make_NFe, "f").infNFeSupl = {
|
520
|
+
qrCode: qrCodeUrls[__classPrivateFieldGet(this, _Make_NFe, "f").infNFe.ide.tpAmb == 1 ? 'producao' : 'homologacao'][`${__classPrivateFieldGet(this, _Make_NFe, "f").infNFe.ide.cUF}`].urlQRCode,
|
521
|
+
urlChave: qrCodeUrls[__classPrivateFieldGet(this, _Make_NFe, "f").infNFe.ide.tpAmb == 1 ? 'producao' : 'homologacao'][`${__classPrivateFieldGet(this, _Make_NFe, "f").infNFe.ide.cUF}`].urlChave
|
522
|
+
};
|
519
523
|
}
|
520
524
|
let tempBuild = new XMLBuilder({
|
521
525
|
ignoreAttributes: false,
|
@@ -554,123 +558,6 @@ _Make_NFe = new WeakMap(), _Make_ICMSTot = new WeakMap(), _Make_instances = new
|
|
554
558
|
vdigit = 0;
|
555
559
|
}
|
556
560
|
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
561
|
}, _Make_calICMSTot = function _Make_calICMSTot(obj) {
|
675
562
|
Object.keys(obj).map(key => {
|
676
563
|
if (__classPrivateFieldGet(this, _Make_ICMSTot, "f")[key] !== undefined) {
|
package/dist/utils/tools.d.ts
CHANGED
@@ -5,16 +5,17 @@ declare class Tools {
|
|
5
5
|
xmllint: string;
|
6
6
|
cUF: string;
|
7
7
|
tpAmb: number;
|
8
|
+
CSC: string;
|
9
|
+
CSCid: string;
|
8
10
|
}, certificado?: {
|
9
11
|
pfx: string;
|
10
12
|
senha: string;
|
11
13
|
});
|
12
|
-
teste(): Promise<object>;
|
13
14
|
sefazEnviaLote(xml: string, data?: any): Promise<string>;
|
14
15
|
xmlSign(xmlJSON: string, data?: any): Promise<string>;
|
15
16
|
xml2json(xml: string): Promise<object>;
|
16
17
|
json2xml(obj: object): Promise<string>;
|
17
18
|
getCertificado(): Promise<unknown>;
|
18
|
-
sefazStatus(): Promise<
|
19
|
+
sefazStatus(): Promise<string>;
|
19
20
|
}
|
20
21
|
export { Tools };
|
package/dist/utils/tools.js
CHANGED
@@ -9,9 +9,8 @@ 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";
|
@@ -20,10 +19,11 @@ import { urlServicos } 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', cUF: '51', tpAmb: 2, CSC: "", CSCid: "" }, 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,7 +80,6 @@ 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
84
|
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")], {
|
89
85
|
...{
|
@@ -165,8 +161,11 @@ class Tools {
|
|
165
161
|
"@xmlns": "http://www.w3.org/2000/09/xmldsig#"
|
166
162
|
}
|
167
163
|
};
|
164
|
+
if (xml.NFe.infNFe.ide.mod == 65) {
|
165
|
+
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);
|
166
|
+
}
|
168
167
|
this.json2xml(xml).then(async (res) => {
|
169
|
-
__classPrivateFieldGet(this, _Tools_instances, "m", _Tools_xmlValido).call(this, res);
|
168
|
+
__classPrivateFieldGet(this, _Tools_instances, "m", _Tools_xmlValido).call(this, res, 'nfe_v4.00');
|
170
169
|
resvol(res);
|
171
170
|
}).catch(err => {
|
172
171
|
reject(err);
|
@@ -185,32 +184,32 @@ class Tools {
|
|
185
184
|
}
|
186
185
|
async getCertificado() {
|
187
186
|
return new Promise(async (resvol, reject) => {
|
188
|
-
|
187
|
+
__classPrivateFieldGet(this, _Tools_instances, "m", _Tools_certTools).call(this).then(resvol).catch(reject);
|
189
188
|
});
|
190
189
|
}
|
191
190
|
//Consulta status sefaz
|
192
191
|
async sefazStatus() {
|
193
192
|
return new Promise(async (resvol, reject) => {
|
194
|
-
await __classPrivateFieldGet(this, _Tools_instances, "m", _Tools_certTools).call(this);
|
195
193
|
if (typeof __classPrivateFieldGet(this, _Tools_config, "f").cUF == "undefined")
|
196
194
|
throw "sefazStatus({...cUF}) -> não definido!";
|
197
195
|
if (typeof __classPrivateFieldGet(this, _Tools_config, "f").tpAmb == "undefined")
|
198
196
|
throw "sefazStatus({...tpAmb}) -> não definido!";
|
199
197
|
if (typeof __classPrivateFieldGet(this, _Tools_config, "f").mod == "undefined")
|
200
198
|
throw "sefazStatus({...mod}) -> não definido!";
|
199
|
+
let consStatServ = {
|
200
|
+
"@versao": "4.00",
|
201
|
+
"@xmlns": "http://www.portalfiscal.inf.br/nfe",
|
202
|
+
"tpAmb": __classPrivateFieldGet(this, _Tools_config, "f").tpAmb,
|
203
|
+
"cUF": __classPrivateFieldGet(this, _Tools_config, "f").cUF,
|
204
|
+
"xServ": "STATUS"
|
205
|
+
};
|
201
206
|
let xmlObj = {
|
202
207
|
"soap:Envelope": {
|
203
208
|
"@xmlns:soap": "http://www.w3.org/2003/05/soap-envelope",
|
204
209
|
"@xmlns:nfe": "http://www.portalfiscal.inf.br/nfe/wsdl/NFeStatusServico4",
|
205
210
|
"soap:Body": {
|
206
211
|
"nfe:nfeDadosMsg": {
|
207
|
-
|
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
|
-
}
|
212
|
+
consStatServ
|
214
213
|
}
|
215
214
|
}
|
216
215
|
}
|
@@ -220,8 +219,10 @@ class Tools {
|
|
220
219
|
ignoreAttributes: false,
|
221
220
|
attributeNamePrefix: "@"
|
222
221
|
});
|
222
|
+
fs.writeFileSync("testes/status.xml", tempBuild.build({ consStatServ }));
|
223
|
+
__classPrivateFieldGet(this, _Tools_instances, "m", _Tools_xmlValido).call(this, tempBuild.build({ consStatServ }), 'consStatServ_v4.00');
|
223
224
|
let xml = tempBuild.build(xmlObj);
|
224
|
-
const req = https.request(urlServicos[`${__classPrivateFieldGet(this, _Tools_config, "f").cUF}`][`mod_${__classPrivateFieldGet(this, _Tools_config, "f").mod}`].
|
225
|
+
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")], {
|
225
226
|
...{
|
226
227
|
method: 'POST',
|
227
228
|
headers: {
|
@@ -230,7 +231,7 @@ class Tools {
|
|
230
231
|
},
|
231
232
|
rejectUnauthorized: false
|
232
233
|
},
|
233
|
-
...__classPrivateFieldGet(this,
|
234
|
+
...await __classPrivateFieldGet(this, _Tools_instances, "m", _Tools_certTools).call(this)
|
234
235
|
}, (res) => {
|
235
236
|
let data = '';
|
236
237
|
res.on('data', (chunk) => {
|
@@ -252,12 +253,23 @@ class Tools {
|
|
252
253
|
});
|
253
254
|
}
|
254
255
|
}
|
255
|
-
_Tools_cert = new WeakMap(), _Tools_xmlTools = new WeakMap(), _Tools_pem = new WeakMap(), _Tools_config = new WeakMap(), _Tools_instances = new WeakSet(),
|
256
|
+
_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) {
|
257
|
+
let s = '|', concat, hash;
|
258
|
+
if (NFe.infNFe.ide.tpEmis == 1) {
|
259
|
+
concat = [NFe.infNFe['@Id'].replace("NFe", ""), versaoQRCode, NFe.infNFe.ide.tpAmb, Number(idCSC)].join(s);
|
260
|
+
}
|
261
|
+
else {
|
262
|
+
let hexDigestValue = Buffer.from(NFe.Signature.SignedInfo.Reference.DigestValue).toString('hex');
|
263
|
+
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);
|
264
|
+
}
|
265
|
+
hash = crypto.createHash('sha1').update(concat + CSC).digest('hex');
|
266
|
+
return NFe.infNFeSupl.qrCode + '?p=' + concat + s + hash;
|
267
|
+
}, _Tools_xmlValido =
|
256
268
|
//Validar XML da NFe, somente apos assinar
|
257
|
-
async function _Tools_xmlValido(xml) {
|
269
|
+
async function _Tools_xmlValido(xml, xsd) {
|
258
270
|
const xmlFile = tmp.fileSync({ mode: 0o644, prefix: 'xml-', postfix: '.xml' });
|
259
271
|
fs.writeFileSync(xmlFile.name, xml, { encoding: 'utf8' });
|
260
|
-
const schemaPath = path.resolve(__dirname,
|
272
|
+
const schemaPath = path.resolve(__dirname, `../../schemas/${xsd}.xsd`);
|
261
273
|
const verif = spawnSync(__classPrivateFieldGet(this, _Tools_config, "f").xmllint, ['--noout', '--schema', schemaPath, xmlFile.name], { encoding: 'utf8' });
|
262
274
|
xmlFile.removeCallback();
|
263
275
|
// Aqui, usamos o operador de encadeamento opcional (?.)
|
package/exemplos/nfce.js
ADDED
@@ -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
|
+
*/
|
@@ -1,12 +1,12 @@
|
|
1
1
|
import { Make, Tools } from "../dist/index.js"
|
2
2
|
import fs from "fs";
|
3
|
-
//let xml = fs.readFileSync("./nfe.xml", { encoding: "utf-8" });
|
4
|
-
//fs.writeFileSync("./nfe.json", JSON.stringify(convert(xml, { format: 'object' })), { encoding: "utf-8" });
|
5
3
|
|
6
4
|
let myTools = new Tools({ //Configuração de habiente e sistema
|
7
5
|
mod: '55',
|
8
6
|
tpAmb: 2,
|
9
7
|
cUF: '51',
|
8
|
+
|
9
|
+
//Optativo: Leia sobre Requisitos.
|
10
10
|
xmllint: `../libxml2-2.9.3-win32-x86_64/bin/xmllint.exe`
|
11
11
|
}, { //Certificado digital
|
12
12
|
pfx: '../certificado.pfx',
|
@@ -139,6 +139,8 @@ NFe.tagProd([
|
|
139
139
|
"indTot": 1
|
140
140
|
}
|
141
141
|
]);
|
142
|
+
|
143
|
+
//Setor o imposto de cada produto.
|
142
144
|
[0, 1, 2, 3].map((value, index) => {
|
143
145
|
NFe.tagProdICMSSN(index, { orig: "0", CSOSN: "400" })
|
144
146
|
NFe.tagProdPIS(index, { CST: "49", qBCProd: "0.0000", vAliqProd: "0.0000", vPIS: "0.00" })
|
@@ -150,6 +152,9 @@ NFe.tagDetPag([{ indPag: 0, tPag: 17, vPag: "1200.00" }]);
|
|
150
152
|
NFe.tagTroco("0.00");
|
151
153
|
NFe.tagInfRespTec({ CNPJ: "47506306000188", xContato: "Guara Dev", email: "admin@guaradev.com", fone: "5566999638922" })
|
152
154
|
fs.writeFileSync("nfe.xml", NFe.xml(), { encoding: "utf-8" });
|
155
|
+
|
156
|
+
//NFe.xml() = retorna o XML gerado ate o momento.
|
157
|
+
// myTools.xmlSign(..) = Assina o xml utlizando o certificado declarado em new Tools.
|
153
158
|
myTools.xmlSign(NFe.xml()).then(async xmlSign => {
|
154
159
|
fs.writeFileSync("nfe_sign.xml", xmlSign, { encoding: "utf-8" });
|
155
160
|
myTools.sefazEnviaLote(xmlSign, { indSinc: 1 }).then(res => {
|
@@ -0,0 +1,18 @@
|
|
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: '65',
|
6
|
+
tpAmb: 2,
|
7
|
+
cUF: '51',
|
8
|
+
|
9
|
+
//Optativo: Leia sobre Requisitos.
|
10
|
+
xmllint: `../libxml2-2.9.3-win32-x86_64/bin/xmllint.exe`
|
11
|
+
}, { //Certificado digital
|
12
|
+
pfx: '../certificado.pfx',
|
13
|
+
senha: fs.readFileSync('../senha.txt', { encoding: "utf8" }),
|
14
|
+
});
|
15
|
+
|
16
|
+
myTools.sefazStatus().then(res=>{
|
17
|
+
console.log(res)
|
18
|
+
})
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "node-sped-nfe",
|
3
|
-
"version": "1.0.
|
3
|
+
"version": "1.0.5",
|
4
4
|
"author": "Kalmon V. Tavares",
|
5
5
|
"type": "module",
|
6
6
|
"main": "dist/index.js",
|
@@ -25,7 +25,10 @@
|
|
25
25
|
},
|
26
26
|
"scripts": {
|
27
27
|
"build": "tsc > saida.txt",
|
28
|
-
|
28
|
+
|
29
|
+
"t:status": "node exemplos/status.js",
|
30
|
+
"t:nfe": "node exemplos/nfe.js",
|
31
|
+
"t:nfce": "node exemplos/nfce.js"
|
29
32
|
},
|
30
33
|
"devDependencies": {
|
31
34
|
"@types/axios": "^0.9.36",
|
@@ -33,18 +36,17 @@
|
|
33
36
|
"@types/node-forge": "^1.3.11",
|
34
37
|
"@types/pem": "^1.14.4",
|
35
38
|
"@types/tmp": "^0.2.6",
|
39
|
+
"@types/xmldom": "^0.1.34",
|
36
40
|
"typescript": "^5.0.0"
|
37
41
|
},
|
38
42
|
"dependencies": {
|
39
43
|
"crypto": "^1.0.1",
|
40
44
|
"fast-xml-parser": "^4.5.1",
|
41
|
-
"node-forge": "^1.3.1",
|
42
45
|
"pem": "^1.14.8",
|
43
|
-
"tmp": "^0.2.3"
|
44
|
-
"xml-crypto": "^6.0.0"
|
46
|
+
"tmp": "^0.2.3"
|
45
47
|
},
|
46
48
|
"repository": {
|
47
49
|
"type": "git",
|
48
50
|
"url": "https://github.com/kalmonv/node-sped-nfe.git"
|
49
51
|
}
|
50
|
-
}
|
52
|
+
}
|
@@ -17,7 +17,7 @@
|
|
17
17
|
<!-- PL_009l_NT2023_002_v100 - Alteração de Schema para evitar caracteres inválidos -->
|
18
18
|
<!-- PL_009m_NT2019_001_v155 - Inclusão de campos para Crédito Presumido e Redução da base de cálculo -->
|
19
19
|
<!-- PL_009m_NT2023_004_v101 - Informações de Pagamentos e Outros -->
|
20
|
-
<!--
|
20
|
+
<!-- PL_009p_NT2024_003_v103 - Produtos agropecuários -->
|
21
21
|
<xs:schema xmlns="http://www.portalfiscal.inf.br/nfe" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:editix="http://www.portalfiscal.inf.br/nfe" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.portalfiscal.inf.br/nfe" elementFormDefault="qualified" attributeFormDefault="unqualified">
|
22
22
|
<xs:import namespace="http://www.w3.org/2000/09/xmldsig#" schemaLocation="xmldsig-core-schema_v1.01.xsd"/>
|
23
23
|
<xs:include schemaLocation="tiposBasico_v4.00.xsd"/>
|
@@ -6292,7 +6292,7 @@ tipo de ato concessório:
|
|
6292
6292
|
</xs:annotation>
|
6293
6293
|
<xs:complexType>
|
6294
6294
|
<xs:choice>
|
6295
|
-
<xs:element name="defensivo">
|
6295
|
+
<xs:element name="defensivo" maxOccurs="20">
|
6296
6296
|
<xs:annotation>
|
6297
6297
|
<xs:documentation>Defensivo Agrícola / Agrotóxico</xs:documentation>
|
6298
6298
|
</xs:annotation>
|
@@ -6303,8 +6303,8 @@ tipo de ato concessório:
|
|
6303
6303
|
<xs:documentation>Número do Receituário ou Receita do Defensivo / Agrotóxico</xs:documentation>
|
6304
6304
|
</xs:annotation>
|
6305
6305
|
<xs:simpleType>
|
6306
|
-
<xs:restriction base="
|
6307
|
-
<xs:maxLength value="
|
6306
|
+
<xs:restriction base="TString">
|
6307
|
+
<xs:maxLength value="30"/>
|
6308
6308
|
<xs:minLength value="1"/>
|
6309
6309
|
</xs:restriction>
|
6310
6310
|
</xs:simpleType>
|
@@ -6340,7 +6340,7 @@ tipo de ato concessório:
|
|
6340
6340
|
</xs:restriction>
|
6341
6341
|
</xs:simpleType>
|
6342
6342
|
</xs:element>
|
6343
|
-
<xs:element name="UFGuia" type="TUfEmi"
|
6343
|
+
<xs:element name="UFGuia" type="TUfEmi"/>
|
6344
6344
|
<xs:element name="serieGuia" minOccurs="0">
|
6345
6345
|
<xs:annotation>
|
6346
6346
|
<xs:documentation>Série da Guia</xs:documentation>
|