node-sped-nfe 1.1.3 → 1.1.4
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/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/utils/eventos.js +72 -6
- package/dist/utils/extras.d.ts +3 -1
- package/dist/utils/extras.js +21 -1
- package/dist/utils/make.js +8 -8
- package/dist/utils/tools.d.ts +1 -1
- package/dist/utils/tools.js +14 -11
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/dist/utils/eventos.js
CHANGED
@@ -628,14 +628,46 @@ const urlEventos400 = {
|
|
628
628
|
"cUF": "23"
|
629
629
|
},
|
630
630
|
"ES": {
|
631
|
+
"mod55": {
|
632
|
+
"producao": {
|
633
|
+
"NFeStatusServico": "https://nfe.svrs.rs.gov.br/ws/NfeStatusServico/NfeStatusServico4.asmx",
|
634
|
+
"NFeAutorizacao": "https://nfe.svrs.rs.gov.br/ws/NfeAutorizacao/NFeAutorizacao4.asmx",
|
635
|
+
"NFeRetAutorizacao": "https://nfe.svrs.rs.gov.br/ws/NfeRetAutorizacao/NFeRetAutorizacao4.asmx",
|
636
|
+
"NFeInutilizacao": "https://nfe.svrs.rs.gov.br/ws/nfeinutilizacao/nfeinutilizacao4.asmx",
|
637
|
+
"NFeConsultaProtocolo": "https://nfe.svrs.rs.gov.br/ws/NfeConsulta/NfeConsulta4.asmx",
|
638
|
+
"RecepcaoEvento": "https://nfe.svrs.rs.gov.br/ws/recepcaoevento/recepcaoevento4.asmx",
|
639
|
+
"NFeConsultaCadastro": "https://cad.svrs.rs.gov.br/ws/cadconsultacadastro/cadconsultacadastro4.asmx"
|
640
|
+
},
|
641
|
+
"homologacao": {
|
642
|
+
"NFeStatusServico": "https://nfe-homologacao.svrs.rs.gov.br/ws/NfeStatusServico/NfeStatusServico4.asmx",
|
643
|
+
"NFeAutorizacao": "https://nfe-homologacao.svrs.rs.gov.br/ws/NfeAutorizacao/NfeAutorizacao4.asmx",
|
644
|
+
"NFeRetAutorizacao": "https://nfe-homologacao.svrs.rs.gov.br/ws/NfeRetAutorizacao/NfeRetAutorizacao4.asmx",
|
645
|
+
"NFeInutilizacao": "https://nfe-homologacao.svrs.rs.gov.br/ws/nfeinutilizacao/nfeinutilizacao4.asmx",
|
646
|
+
"NFeConsultaProtocolo": "https://nfe-homologacao.svrs.rs.gov.br/ws/NfeConsulta/NfeConsulta4.asmx",
|
647
|
+
"RecepcaoEvento": "https://nfe-homologacao.svrs.rs.gov.br/ws/recepcaoevento/recepcaoevento4.asmx",
|
648
|
+
"NFeConsultaCadastro": "https://cad-homologacao.svrs.rs.gov.br/ws/cadconsultacadastro/cadconsultacadastro4.asmx"
|
649
|
+
}
|
650
|
+
},
|
631
651
|
"mod65": {
|
632
652
|
"producao": {
|
633
|
-
"
|
634
|
-
"
|
653
|
+
"NFeStatusServico": "https://nfce.svrs.rs.gov.br/ws/NfeStatusServico/NfeStatusServico2.asmx",
|
654
|
+
"NFeAutorizacao": "https://nfce.svrs.rs.gov.br/ws/NfeAutorizacao/NFeAutorizacao.asmx",
|
655
|
+
"NFeRetAutorizacao": "https://nfce.svrs.rs.gov.br/ws/NfeRetAutorizacao/NFeRetAutorizacao.asmx",
|
656
|
+
"NFeInutilizacao": "https://nfce.svrs.rs.gov.br/ws/nfeinutilizacao/nfeinutilizacao2.asmx",
|
657
|
+
"NFeConsultaProtocolo": "https://nfce.svrs.rs.gov.br/ws/NfeConsulta/NfeConsulta2.asmx",
|
658
|
+
"RecepcaoEvento": "https://nfce.svrs.rs.gov.br/ws/recepcaoevento/recepcaoevento.asmx",
|
659
|
+
"NFeConsultaQR": "http://app.sefaz.es.gov.br/ConsultaNFCe",
|
660
|
+
"urlChave": "http://app.sefaz.es.gov.br/ConsultaNFCe"
|
635
661
|
},
|
636
662
|
"homologacao": {
|
637
|
-
"
|
638
|
-
"
|
663
|
+
"NFeStatusServico": "https://nfce-homologacao.svrs.rs.gov.br/ws/NfeStatusServico/NfeStatusServico2.asmx",
|
664
|
+
"NFeAutorizacao": "https://nfce-homologacao.svrs.rs.gov.br/ws/NfeAutorizacao/NFeAutorizacao.asmx",
|
665
|
+
"NFeRetAutorizacao": "https://nfce-homologacao.svrs.rs.gov.br/ws/NfeRetAutorizacao/NFeRetAutorizacao.asmx",
|
666
|
+
"NFeInutilizacao": "https://nfce-homologacao.svrs.rs.gov.br/ws/nfeinutilizacao/nfeinutilizacao2.asmx",
|
667
|
+
"NFeConsultaProtocolo": "https://nfce-homologacao.svrs.rs.gov.br/ws/NfeConsulta/NfeConsulta2.asmx",
|
668
|
+
"RecepcaoEvento": "https://nfce-homologacao.svrs.rs.gov.br/ws/recepcaoevento/recepcaoevento.asmx",
|
669
|
+
"NFeConsultaQR": "http://app.sefaz.es.gov.br/ConsultaNFCe",
|
670
|
+
"urlChave": "http://app.sefaz.es.gov.br/ConsultaNFCe"
|
639
671
|
}
|
640
672
|
},
|
641
673
|
"cUF": "32"
|
@@ -771,12 +803,46 @@ const urlEventos400 = {
|
|
771
803
|
"SE": {
|
772
804
|
"mod65": {
|
773
805
|
"producao": {
|
806
|
+
"NFeAutorizacao": "https://www.nfce.se.gov.br/ws/NFeAutorizacao4.asmx",
|
807
|
+
"NFeRetAutorizacao": "https://www.nfce.se.gov.br/ws/NFeRetAutorizacao4.asmx",
|
808
|
+
"NFeInutilizacao": "https://www.nfce.se.gov.br/ws/NFeInutilizacao4.asmx",
|
809
|
+
"NFeConsultaProtocolo": "https://www.nfce.se.gov.br/ws/NFeConsultaProtocolo4.asmx",
|
810
|
+
"NFeStatusServico": "https://www.nfce.se.gov.br/ws/NFeStatusServico4.asmx",
|
811
|
+
"RecepcaoEvento": "https://www.nfce.se.gov.br/ws/RecepcaoEvento4.asmx",
|
812
|
+
"NFeConsultaCadastro": "https://www.nfce.se.gov.br/ws/CadConsultaCadastro4.asmx",
|
774
813
|
"NFeConsultaQR": "http://www.nfce.se.gov.br/nfce/qrcode",
|
775
814
|
"urlChave": "http://www.nfce.se.gov.br/nfce/consulta"
|
776
815
|
},
|
777
816
|
"homologacao": {
|
778
|
-
"
|
779
|
-
"
|
817
|
+
"NFeAutorizacao": "https://www.hom.nfce.se.gov.br/ws/NFeAutorizacao4.asmx",
|
818
|
+
"NFeRetAutorizacao": "https://www.hom.nfce.se.gov.br/ws/NFeRetAutorizacao4.asmx",
|
819
|
+
"NFeInutilizacao": "https://www.hom.nfce.se.gov.br/ws/NFeInutilizacao4.asmx",
|
820
|
+
"NFeConsultaProtocolo": "https://www.hom.nfce.se.gov.br/ws/NFeConsultaProtocolo4.asmx",
|
821
|
+
"NFeStatusServico": "https://www.hom.nfce.se.gov.br/ws/NFeStatusServico4.asmx",
|
822
|
+
"RecepcaoEvento": "https://www.hom.nfce.se.gov.br/ws/RecepcaoEvento4.asmx",
|
823
|
+
"NFeConsultaCadastro": "https://www.hom.nfce.se.gov.br/ws/CadConsultaCadastro4.asmx",
|
824
|
+
"NFeConsultaQR": "http://www.hom.nfce.se.gov.br/nfce/qrcode",
|
825
|
+
"urlChave": "http://www.hom.nfce.se.gov.br/nfce/consulta"
|
826
|
+
}
|
827
|
+
},
|
828
|
+
"mod55": {
|
829
|
+
"producao": {
|
830
|
+
"NFeStatusServico": "https://nfe.svrs.rs.gov.br/ws/NfeStatusServico/NfeStatusServico4.asmx",
|
831
|
+
"NFeAutorizacao": "https://nfe.svrs.rs.gov.br/ws/NfeAutorizacao/NFeAutorizacao4.asmx",
|
832
|
+
"NFeConsultaProtocolo": "https://nfe.svrs.rs.gov.br/ws/NfeConsulta/NfeConsulta4.asmx",
|
833
|
+
"NFeInutilizacao": "https://nfe.svrs.rs.gov.br/ws/nfeinutilizacao/nfeinutilizacao4.asmx",
|
834
|
+
"NFeRetAutorizacao": "https://nfe.svrs.rs.gov.br/ws/NfeRetAutorizacao/NFeRetAutorizacao4.asmx",
|
835
|
+
"RecepcaoEvento": "https://nfe.svrs.rs.gov.br/ws/recepcaoevento/recepcaoevento4.asmx",
|
836
|
+
"NFeConsultaCadastro": "https://cad.svrs.rs.gov.br/ws/cadconsultacadastro/cadconsultacadastro4.asmx"
|
837
|
+
},
|
838
|
+
"homologacao": {
|
839
|
+
"NFeStatusServico": "https://nfe-homologacao.svrs.rs.gov.br/ws/NfeStatusServico/NfeStatusServico4.asmx",
|
840
|
+
"NFeAutorizacao": "https://nfe-homologacao.svrs.rs.gov.br/ws/NfeAutorizacao/NFeAutorizacao4.asmx",
|
841
|
+
"NFeConsultaProtocolo": "https://nfe-homologacao.svrs.rs.gov.br/ws/NfeConsulta/NfeConsulta4.asmx",
|
842
|
+
"NFeInutilizacao": "https://nfe-homologacao.svrs.rs.gov.br/ws/nfeinutilizacao/nfeinutilizacao4.asmx",
|
843
|
+
"NFeRetAutorizacao": "https://nfe-homologacao.svrs.rs.gov.br/ws/NfeRetAutorizacao/NFeRetAutorizacao4.asmx",
|
844
|
+
"RecepcaoEvento": "https://nfe-homologacao.svrs.rs.gov.br/ws/recepcaoevento/recepcaoevento4.asmx",
|
845
|
+
"NFeConsultaCadastro": "https://cad-homologacao.svrs.rs.gov.br/ws/cadconsultacadastro/cadconsultacadastro4.asmx"
|
780
846
|
}
|
781
847
|
},
|
782
848
|
"cUF": "28"
|
package/dist/utils/extras.d.ts
CHANGED
package/dist/utils/extras.js
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
import { XMLParser, XMLBuilder } from "fast-xml-parser";
|
1
2
|
const cUF2UF = {
|
2
3
|
"11": "RO",
|
3
4
|
"12": "AC",
|
@@ -272,4 +273,23 @@ const impEstrutura = (imposto) => {
|
|
272
273
|
};
|
273
274
|
imposto = configStruct(imposto, gStruct);
|
274
275
|
};
|
275
|
-
|
276
|
+
const xml2json = (xml) => {
|
277
|
+
return new Promise((resvol, reject) => {
|
278
|
+
let XMLPar = new XMLParser({
|
279
|
+
ignoreAttributes: false,
|
280
|
+
attributeNamePrefix: "@",
|
281
|
+
parseTagValue: false, // Evita conversão automática de valores
|
282
|
+
});
|
283
|
+
resvol(XMLPar.parse(xml));
|
284
|
+
});
|
285
|
+
};
|
286
|
+
const json2xml = (obj) => {
|
287
|
+
return new Promise((resvol, reject) => {
|
288
|
+
let XMLBuil = new XMLBuilder({
|
289
|
+
ignoreAttributes: false,
|
290
|
+
attributeNamePrefix: "@",
|
291
|
+
});
|
292
|
+
resvol(XMLBuil.build(obj));
|
293
|
+
});
|
294
|
+
};
|
295
|
+
export { cUF2UF, UF2cUF, json2xml, xml2json };
|
package/dist/utils/make.js
CHANGED
@@ -572,14 +572,14 @@ class Make {
|
|
572
572
|
}
|
573
573
|
}
|
574
574
|
_Make_NFe = new WeakMap(), _Make_ICMSTot = new WeakMap(), _Make_instances = new WeakSet(), _Make_gerarChaveNFe = function _Make_gerarChaveNFe() {
|
575
|
-
const chaveSemDV = __classPrivateFieldGet(this, _Make_NFe, "f").infNFe.ide.cUF
|
575
|
+
const chaveSemDV = `${__classPrivateFieldGet(this, _Make_NFe, "f").infNFe.ide.cUF}`.padStart(2, '0') + // Código da UF (2 dígitos)
|
576
576
|
__classPrivateFieldGet(this, _Make_NFe, "f").infNFe.ide.dhEmi.substring(2, 4) + __classPrivateFieldGet(this, _Make_NFe, "f").infNFe.ide.dhEmi.substring(5, 7) + // Ano e Mês da emissão (AAMM, 4 dígitos)
|
577
|
-
__classPrivateFieldGet(this, _Make_NFe, "f").infNFe.emit.CNPJ
|
578
|
-
__classPrivateFieldGet(this, _Make_NFe, "f").infNFe.ide.mod
|
579
|
-
__classPrivateFieldGet(this, _Make_NFe, "f").infNFe.ide.serie
|
580
|
-
__classPrivateFieldGet(this, _Make_NFe, "f").infNFe.ide.nNF
|
581
|
-
__classPrivateFieldGet(this, _Make_NFe, "f").infNFe.ide.tpEmis
|
582
|
-
__classPrivateFieldGet(this, _Make_NFe, "f").infNFe.ide.cNF
|
577
|
+
`${__classPrivateFieldGet(this, _Make_NFe, "f").infNFe.emit.CNPJ}`.padStart(14, '0') + // CNPJ do emitente (14 dígitos)
|
578
|
+
`${__classPrivateFieldGet(this, _Make_NFe, "f").infNFe.ide.mod}`.padStart(2, '0') + // Modelo da NF (2 dígitos)
|
579
|
+
`${__classPrivateFieldGet(this, _Make_NFe, "f").infNFe.ide.serie}`.padStart(3, '0') + // Série da NF (3 dígitos)
|
580
|
+
`${__classPrivateFieldGet(this, _Make_NFe, "f").infNFe.ide.nNF}`.padStart(9, '0') + // Número da NF (9 dígitos)
|
581
|
+
`${__classPrivateFieldGet(this, _Make_NFe, "f").infNFe.ide.tpEmis}`.padStart(1, '0') + // Tipo de Emissão (1 dígito)
|
582
|
+
`${__classPrivateFieldGet(this, _Make_NFe, "f").infNFe.ide.cNF}`.padStart(8, '0'); // Código Numérico da NF (8 dígitos)
|
583
583
|
__classPrivateFieldGet(this, _Make_NFe, "f").infNFe.ide.cDV = __classPrivateFieldGet(this, _Make_instances, "m", _Make_calcularDigitoVerificador).call(this, chaveSemDV);
|
584
584
|
return `${chaveSemDV}${__classPrivateFieldGet(this, _Make_NFe, "f").infNFe.ide.cDV}`;
|
585
585
|
}, _Make_calcularDigitoVerificador = function _Make_calcularDigitoVerificador(key) {
|
@@ -604,7 +604,7 @@ _Make_NFe = new WeakMap(), _Make_ICMSTot = new WeakMap(), _Make_instances = new
|
|
604
604
|
}, _Make_calICMSTot = function _Make_calICMSTot(obj) {
|
605
605
|
Object.keys(obj).map(key => {
|
606
606
|
if (__classPrivateFieldGet(this, _Make_ICMSTot, "f")[key] !== undefined) {
|
607
|
-
__classPrivateFieldGet(this, _Make_ICMSTot, "f")[key] +=
|
607
|
+
__classPrivateFieldGet(this, _Make_ICMSTot, "f")[key] += (obj[key]) * 1;
|
608
608
|
}
|
609
609
|
});
|
610
610
|
};
|
package/dist/utils/tools.d.ts
CHANGED
package/dist/utils/tools.js
CHANGED
@@ -20,10 +20,11 @@ import fs from "fs";
|
|
20
20
|
import path from 'path';
|
21
21
|
import { fileURLToPath } from 'url';
|
22
22
|
import pem from 'pem';
|
23
|
+
import { cUF2UF } from "./extras.js";
|
23
24
|
const __filename = fileURLToPath(import.meta.url);
|
24
25
|
const __dirname = path.dirname(__filename);
|
25
26
|
class Tools {
|
26
|
-
constructor(config = { mod: "", xmllint: 'xmllint', UF: '', tpAmb: 2, CSC: "", CSCid: "", versao: "4.00", timeout: 30, openssl:
|
27
|
+
constructor(config = { mod: "", xmllint: 'xmllint', UF: '', tpAmb: 2, CSC: "", CSCid: "", versao: "4.00", timeout: 30, openssl: null }, certificado = { pfx: "", senha: "" }) {
|
27
28
|
_Tools_instances.add(this);
|
28
29
|
_Tools_cert.set(this, void 0);
|
29
30
|
_Tools_xmlTools.set(this, {
|
@@ -50,7 +51,7 @@ class Tools {
|
|
50
51
|
if (typeof config.xmllint == "undefined")
|
51
52
|
config.xmllint = 'xmllint';
|
52
53
|
if (typeof config.openssl == "undefined")
|
53
|
-
config.openssl =
|
54
|
+
config.openssl = null;
|
54
55
|
//Configurar certificado
|
55
56
|
__classPrivateFieldSet(this, _Tools_config, config, "f");
|
56
57
|
__classPrivateFieldSet(this, _Tools_cert, certificado, "f");
|
@@ -217,12 +218,11 @@ class Tools {
|
|
217
218
|
if (!chNFe || chNFe.length !== 44) {
|
218
219
|
return reject("consultarNFe(chNFe) -> chave inválida!");
|
219
220
|
}
|
220
|
-
|
221
|
-
|
221
|
+
let cUF = `${chNFe}`.substring(0, 2);
|
222
|
+
let UF = cUF2UF[cUF];
|
223
|
+
let mod = `${chNFe}`.substring(20, 22);
|
222
224
|
if (typeof __classPrivateFieldGet(this, _Tools_config, "f").tpAmb === "undefined")
|
223
225
|
throw "consultarNFe({...tpAmb}) -> não definido!";
|
224
|
-
if (typeof __classPrivateFieldGet(this, _Tools_config, "f").mod === "undefined")
|
225
|
-
throw "consultarNFe({...mod}) -> não definido!";
|
226
226
|
let consSitNFe = {
|
227
227
|
"@xmlns": "http://www.portalfiscal.inf.br/nfe",
|
228
228
|
"@versao": "4.00",
|
@@ -249,8 +249,9 @@ class Tools {
|
|
249
249
|
// Validação do XML interno (opcional)
|
250
250
|
__classPrivateFieldGet(this, _Tools_instances, "m", _Tools_xmlValido).call(this, builder.build({ consSitNFe }), `consSitNFe_v${__classPrivateFieldGet(this, _Tools_config, "f").versao}`);
|
251
251
|
const xml = builder.build(xmlObj);
|
252
|
-
let tempUF = urlEventos(
|
253
|
-
|
252
|
+
let tempUF = urlEventos(UF, __classPrivateFieldGet(this, _Tools_config, "f").versao);
|
253
|
+
console.log(tempUF);
|
254
|
+
const url = tempUF[`mod${mod}`][(__classPrivateFieldGet(this, _Tools_config, "f").tpAmb == 1 ? "producao" : "homologacao")].NFeConsultaProtocolo;
|
254
255
|
const req = https.request(url, {
|
255
256
|
method: 'POST',
|
256
257
|
headers: {
|
@@ -387,9 +388,11 @@ async function _Tools_xmlValido(xml, xsd) {
|
|
387
388
|
return new Promise(async (resvol, reject) => {
|
388
389
|
if (__classPrivateFieldGet(this, _Tools_pem, "f").key != "")
|
389
390
|
resvol(__classPrivateFieldGet(this, _Tools_pem, "f"));
|
390
|
-
|
391
|
-
|
392
|
-
|
391
|
+
if (__classPrivateFieldGet(this, _Tools_config, "f").openssl != null) {
|
392
|
+
pem.config({
|
393
|
+
pathOpenSSL: __classPrivateFieldGet(this, _Tools_config, "f").openssl
|
394
|
+
});
|
395
|
+
}
|
393
396
|
pem.readPkcs12(__classPrivateFieldGet(this, _Tools_cert, "f").pfx, { p12Password: __classPrivateFieldGet(this, _Tools_cert, "f").senha }, (err, myPem) => {
|
394
397
|
if (err)
|
395
398
|
return reject(err); // <-- importante!
|