node-sped-nfe 1.0.5 → 1.0.7
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/LICENSE.md +188 -0
- package/dist/utils/eventos.d.ts +2 -1
- package/dist/utils/eventos.js +794 -105
- package/dist/utils/extras.d.ts +2 -0
- package/dist/utils/extras.js +58 -0
- package/dist/utils/make.d.ts +1 -1
- package/dist/utils/make.js +36 -12
- package/dist/utils/tools.d.ts +4 -2
- package/dist/utils/tools.js +77 -10
- package/docs/xml.md +81 -81
- package/exemplos/consulta.js +19 -0
- package/exemplos/nfe.js +4 -3
- package/exemplos/status.js +2 -1
- package/package.json +5 -2
- package/src/utils/eventos.ts +800 -106
- package/src/utils/extras.ts +59 -0
- package/src/utils/make.ts +63 -19
- package/src/utils/tools.ts +88 -11
- package/src/utils/schemas/consReciNFe_v4.00.xsd +0 -9
- package/src/utils/schemas/consSitNFe_v4.00.xsd +0 -9
- package/src/utils/schemas/consStatServ_v4.00.xsd +0 -9
- package/src/utils/schemas/enviNFe_v4.00.xsd +0 -9
- package/src/utils/schemas/inutNFe_v4.00.xsd +0 -9
- package/src/utils/schemas/leiauteConsSitNFe_v4.00.xsd +0 -502
- package/src/utils/schemas/leiauteConsStatServ_v4.00.xsd +0 -98
- package/src/utils/schemas/leiauteInutNFe_v4.00.xsd +0 -193
- package/src/utils/schemas/leiauteNFe_v4.00.xsd +0 -7412
- package/src/utils/schemas/nfe_v4.00.xsd +0 -9
- package/src/utils/schemas/procInutNFe_v4.00.xsd +0 -9
- package/src/utils/schemas/procNFe_v4.00.xsd +0 -9
- package/src/utils/schemas/retConsReciNFe_v4.00.xsd +0 -9
- package/src/utils/schemas/retConsSitNFe_v4.00.xsd +0 -9
- package/src/utils/schemas/retConsStatServ_v4.00.xsd +0 -9
- package/src/utils/schemas/retEnviNFe_v4.00.xsd +0 -9
- package/src/utils/schemas/retInutNFe_v4.00.xsd +0 -9
- package/src/utils/schemas/tiposBasico_v4.00.xsd +0 -598
- package/src/utils/schemas/xmldsig-core-schema_v1.01.xsd +0 -98
@@ -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 };
|
package/dist/utils/make.d.ts
CHANGED
@@ -16,7 +16,7 @@ declare class Make {
|
|
16
16
|
tagAutXML(obj: any): void;
|
17
17
|
tagProd(obj: any): void;
|
18
18
|
tagCreditoPresumidoProd(obj: any): void;
|
19
|
-
taginfAdProd(obj: any): void;
|
19
|
+
taginfAdProd(index: any, obj: any): void;
|
20
20
|
tagCEST(obj: any): void;
|
21
21
|
tagRECOPI(obj: any): void;
|
22
22
|
tagAdi(obj: any): void;
|
package/dist/utils/make.js
CHANGED
@@ -5,7 +5,8 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
5
5
|
};
|
6
6
|
var _Make_instances, _Make_NFe, _Make_ICMSTot, _Make_gerarChaveNFe, _Make_calcularDigitoVerificador, _Make_calICMSTot;
|
7
7
|
import { XMLBuilder } from "fast-xml-parser";
|
8
|
-
import {
|
8
|
+
import { urlEventos } from "./eventos.js";
|
9
|
+
import { cUF2UF } from "./extras.js";
|
9
10
|
//Classe da nota fiscal
|
10
11
|
class Make {
|
11
12
|
constructor() {
|
@@ -62,19 +63,34 @@ class Make {
|
|
62
63
|
});
|
63
64
|
}
|
64
65
|
tagRefNFe(obj) {
|
65
|
-
|
66
|
+
if (typeof __classPrivateFieldGet(this, _Make_NFe, "f").infNFe.ide.NFref == "undefined") {
|
67
|
+
__classPrivateFieldGet(this, _Make_NFe, "f").infNFe.ide.NFref = new Array();
|
68
|
+
}
|
69
|
+
__classPrivateFieldGet(this, _Make_NFe, "f").infNFe.ide.NFref.push({ refNFe: obj });
|
66
70
|
}
|
67
71
|
tagRefNF(obj) {
|
68
|
-
|
72
|
+
if (typeof __classPrivateFieldGet(this, _Make_NFe, "f").infNFe.ide.NFref == "undefined") {
|
73
|
+
__classPrivateFieldGet(this, _Make_NFe, "f").infNFe.ide.NFref = new Array();
|
74
|
+
}
|
75
|
+
__classPrivateFieldGet(this, _Make_NFe, "f").infNFe.ide.NFref.push({ refNF: obj });
|
69
76
|
}
|
70
77
|
tagRefNFP(obj) {
|
71
|
-
|
78
|
+
if (typeof __classPrivateFieldGet(this, _Make_NFe, "f").infNFe.ide.NFref == "undefined") {
|
79
|
+
__classPrivateFieldGet(this, _Make_NFe, "f").infNFe.ide.NFref = new Array();
|
80
|
+
}
|
81
|
+
__classPrivateFieldGet(this, _Make_NFe, "f").infNFe.ide.NFref.push({ refNFP: obj });
|
72
82
|
}
|
73
83
|
tagRefCTe(obj) {
|
74
|
-
|
84
|
+
if (typeof __classPrivateFieldGet(this, _Make_NFe, "f").infNFe.ide.NFref == "undefined") {
|
85
|
+
__classPrivateFieldGet(this, _Make_NFe, "f").infNFe.ide.NFref = new Array();
|
86
|
+
}
|
87
|
+
__classPrivateFieldGet(this, _Make_NFe, "f").infNFe.ide.NFref.push({ refCTe: obj });
|
75
88
|
}
|
76
89
|
tagRefECF(obj) {
|
77
|
-
|
90
|
+
if (typeof __classPrivateFieldGet(this, _Make_NFe, "f").infNFe.ide.NFref == "undefined") {
|
91
|
+
__classPrivateFieldGet(this, _Make_NFe, "f").infNFe.ide.NFref = new Array();
|
92
|
+
}
|
93
|
+
__classPrivateFieldGet(this, _Make_NFe, "f").infNFe.ide.NFref.push({ refECF: obj });
|
78
94
|
}
|
79
95
|
tagEmit(obj) {
|
80
96
|
__classPrivateFieldGet(this, _Make_NFe, "f").infNFe.emit = new Object();
|
@@ -110,10 +126,16 @@ class Make {
|
|
110
126
|
});
|
111
127
|
}
|
112
128
|
tagRetirada(obj) {
|
113
|
-
|
129
|
+
__classPrivateFieldGet(this, _Make_NFe, "f").infNFe.retirada = {};
|
130
|
+
Object.keys(obj).forEach(key => {
|
131
|
+
__classPrivateFieldGet(this, _Make_NFe, "f").infNFe.retirada[key] = obj[key];
|
132
|
+
});
|
114
133
|
}
|
115
134
|
tagAutXML(obj) {
|
116
|
-
|
135
|
+
if (typeof __classPrivateFieldGet(this, _Make_NFe, "f").infNFe.autXML == "undefined") {
|
136
|
+
__classPrivateFieldGet(this, _Make_NFe, "f").infNFe.autXML = new Array();
|
137
|
+
}
|
138
|
+
__classPrivateFieldGet(this, _Make_NFe, "f").infNFe.autXML.push(obj);
|
117
139
|
}
|
118
140
|
//tagprod
|
119
141
|
tagProd(obj) {
|
@@ -144,8 +166,8 @@ class Make {
|
|
144
166
|
tagCreditoPresumidoProd(obj) {
|
145
167
|
throw "não implementado!";
|
146
168
|
}
|
147
|
-
taginfAdProd(obj) {
|
148
|
-
|
169
|
+
taginfAdProd(index, obj) {
|
170
|
+
__classPrivateFieldGet(this, _Make_NFe, "f").infNFe.det[index].infAdProd = obj;
|
149
171
|
}
|
150
172
|
tagCEST(obj) {
|
151
173
|
throw "não implementado!";
|
@@ -516,9 +538,11 @@ class Make {
|
|
516
538
|
__classPrivateFieldGet(this, _Make_NFe, "f").infNFe[`@Id`] = `NFe${__classPrivateFieldGet(this, _Make_instances, "m", _Make_gerarChaveNFe).call(this)}`;
|
517
539
|
//Adicionar QrCode
|
518
540
|
if (__classPrivateFieldGet(this, _Make_NFe, "f").infNFe.ide.mod == 65) {
|
541
|
+
//Como ja temos cUF, vamos usar o extras.cUF2UF
|
542
|
+
let tempUF = urlEventos(cUF2UF[__classPrivateFieldGet(this, _Make_NFe, "f").infNFe.ide.cUF], __classPrivateFieldGet(this, _Make_NFe, "f").infNFe['@versao']);
|
519
543
|
__classPrivateFieldGet(this, _Make_NFe, "f").infNFeSupl = {
|
520
|
-
qrCode:
|
521
|
-
urlChave:
|
544
|
+
qrCode: tempUF.mod65[__classPrivateFieldGet(this, _Make_NFe, "f").infNFe.ide.tpAmb == 1 ? 'producao' : 'homologacao'].NFeConsultaQR, //Este não e o valor final, vamos utilizar apenas para carregar os dados que vão ser utlizados no make
|
545
|
+
urlChave: tempUF.mod65[__classPrivateFieldGet(this, _Make_NFe, "f").infNFe.ide.tpAmb == 1 ? 'producao' : 'homologacao'].urlChave
|
522
546
|
};
|
523
547
|
}
|
524
548
|
let tempBuild = new XMLBuilder({
|
package/dist/utils/tools.d.ts
CHANGED
@@ -3,10 +3,11 @@ declare class Tools {
|
|
3
3
|
constructor(config?: {
|
4
4
|
mod: string;
|
5
5
|
xmllint: string;
|
6
|
-
|
6
|
+
UF: string;
|
7
7
|
tpAmb: number;
|
8
8
|
CSC: string;
|
9
9
|
CSCid: string;
|
10
|
+
versao: string;
|
10
11
|
}, certificado?: {
|
11
12
|
pfx: string;
|
12
13
|
senha: string;
|
@@ -15,7 +16,8 @@ declare class Tools {
|
|
15
16
|
xmlSign(xmlJSON: string, data?: any): Promise<string>;
|
16
17
|
xml2json(xml: string): Promise<object>;
|
17
18
|
json2xml(obj: object): Promise<string>;
|
18
|
-
getCertificado(): Promise<
|
19
|
+
getCertificado(): Promise<object>;
|
20
|
+
consultarNFe(chNFe: string): Promise<string>;
|
19
21
|
sefazStatus(): Promise<string>;
|
20
22
|
}
|
21
23
|
export { Tools };
|
package/dist/utils/tools.js
CHANGED
@@ -15,7 +15,7 @@ import https from "https";
|
|
15
15
|
import { spawnSync } from "child_process";
|
16
16
|
import tmp from "tmp";
|
17
17
|
import crypto from "crypto";
|
18
|
-
import {
|
18
|
+
import { urlEventos } from "./eventos.js";
|
19
19
|
import fs from "fs";
|
20
20
|
import path from 'path';
|
21
21
|
import { fileURLToPath } from 'url';
|
@@ -23,7 +23,7 @@ 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',
|
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, {
|
@@ -81,7 +81,8 @@ class Tools {
|
|
81
81
|
};
|
82
82
|
let xmlLote = await this.json2xml(jsonXmlLote);
|
83
83
|
try {
|
84
|
-
|
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, {
|
85
86
|
...{
|
86
87
|
method: 'POST',
|
87
88
|
headers: {
|
@@ -165,7 +166,7 @@ class Tools {
|
|
165
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);
|
166
167
|
}
|
167
168
|
this.json2xml(xml).then(async (res) => {
|
168
|
-
__classPrivateFieldGet(this, _Tools_instances, "m", _Tools_xmlValido).call(this, res,
|
169
|
+
__classPrivateFieldGet(this, _Tools_instances, "m", _Tools_xmlValido).call(this, res, `nfe_v${__classPrivateFieldGet(this, _Tools_config, "f").versao}`);
|
169
170
|
resvol(res);
|
170
171
|
}).catch(err => {
|
171
172
|
reject(err);
|
@@ -182,25 +183,90 @@ class Tools {
|
|
182
183
|
resvol(__classPrivateFieldGet(this, _Tools_xmlTools, "f").XMLBuilder.build(obj));
|
183
184
|
});
|
184
185
|
}
|
186
|
+
//Obter certificado
|
185
187
|
async getCertificado() {
|
186
188
|
return new Promise(async (resvol, reject) => {
|
187
189
|
__classPrivateFieldGet(this, _Tools_instances, "m", _Tools_certTools).call(this).then(resvol).catch(reject);
|
188
190
|
});
|
189
191
|
}
|
192
|
+
//Consulta NFe
|
193
|
+
consultarNFe(chNFe) {
|
194
|
+
return new Promise(async (resolve, reject) => {
|
195
|
+
if (!chNFe || chNFe.length !== 44) {
|
196
|
+
return reject("consultarNFe(chNFe) -> chave inválida!");
|
197
|
+
}
|
198
|
+
if (typeof __classPrivateFieldGet(this, _Tools_config, "f").UF === "undefined")
|
199
|
+
throw "consultarNFe({...UF}) -> não definido!";
|
200
|
+
if (typeof __classPrivateFieldGet(this, _Tools_config, "f").tpAmb === "undefined")
|
201
|
+
throw "consultarNFe({...tpAmb}) -> não definido!";
|
202
|
+
if (typeof __classPrivateFieldGet(this, _Tools_config, "f").mod === "undefined")
|
203
|
+
throw "consultarNFe({...mod}) -> não definido!";
|
204
|
+
let consSitNFe = {
|
205
|
+
"@xmlns": "http://www.portalfiscal.inf.br/nfe",
|
206
|
+
"@versao": "4.00",
|
207
|
+
"tpAmb": __classPrivateFieldGet(this, _Tools_config, "f").tpAmb,
|
208
|
+
"xServ": "CONSULTAR",
|
209
|
+
"chNFe": chNFe
|
210
|
+
};
|
211
|
+
let xmlObj = {
|
212
|
+
"soap:Envelope": {
|
213
|
+
"@xmlns:soap": "http://www.w3.org/2003/05/soap-envelope",
|
214
|
+
"@xmlns:nfe": "http://www.portalfiscal.inf.br/nfe/wsdl/NFeConsultaProtocolo4",
|
215
|
+
"soap:Body": {
|
216
|
+
"nfe:nfeDadosMsg": {
|
217
|
+
"consSitNFe": consSitNFe
|
218
|
+
}
|
219
|
+
}
|
220
|
+
}
|
221
|
+
};
|
222
|
+
try {
|
223
|
+
const builder = new XMLBuilder({
|
224
|
+
ignoreAttributes: false,
|
225
|
+
attributeNamePrefix: "@"
|
226
|
+
});
|
227
|
+
// Validação do XML interno (opcional)
|
228
|
+
__classPrivateFieldGet(this, _Tools_instances, "m", _Tools_xmlValido).call(this, builder.build({ consSitNFe }), `consSitNFe_v${__classPrivateFieldGet(this, _Tools_config, "f").versao}`);
|
229
|
+
const xml = builder.build(xmlObj);
|
230
|
+
let tempUF = urlEventos(__classPrivateFieldGet(this, _Tools_config, "f").UF, __classPrivateFieldGet(this, _Tools_config, "f").versao);
|
231
|
+
const url = tempUF[`mod${__classPrivateFieldGet(this, _Tools_config, "f").mod}`][(__classPrivateFieldGet(this, _Tools_config, "f").tpAmb == 1 ? "producao" : "homologacao")].NFeConsultaProtocolo;
|
232
|
+
const req = https.request(url, {
|
233
|
+
method: 'POST',
|
234
|
+
headers: {
|
235
|
+
'Content-Type': 'application/soap+xml; charset=utf-8',
|
236
|
+
'Content-Length': xml.length,
|
237
|
+
},
|
238
|
+
rejectUnauthorized: false,
|
239
|
+
...await __classPrivateFieldGet(this, _Tools_instances, "m", _Tools_certTools).call(this)
|
240
|
+
}, (res) => {
|
241
|
+
let data = '';
|
242
|
+
res.on('data', (chunk) => data += chunk);
|
243
|
+
res.on('end', () => resolve(data));
|
244
|
+
});
|
245
|
+
req.on('error', (err) => reject(err));
|
246
|
+
req.write(xml);
|
247
|
+
req.end();
|
248
|
+
}
|
249
|
+
catch (err) {
|
250
|
+
reject(err);
|
251
|
+
}
|
252
|
+
});
|
253
|
+
}
|
190
254
|
//Consulta status sefaz
|
191
255
|
async sefazStatus() {
|
192
256
|
return new Promise(async (resvol, reject) => {
|
193
|
-
if (typeof __classPrivateFieldGet(this, _Tools_config, "f").
|
194
|
-
throw "sefazStatus({...
|
257
|
+
if (typeof __classPrivateFieldGet(this, _Tools_config, "f").UF == "undefined")
|
258
|
+
throw "sefazStatus({...UF}) -> não definido!";
|
195
259
|
if (typeof __classPrivateFieldGet(this, _Tools_config, "f").tpAmb == "undefined")
|
196
260
|
throw "sefazStatus({...tpAmb}) -> não definido!";
|
197
261
|
if (typeof __classPrivateFieldGet(this, _Tools_config, "f").mod == "undefined")
|
198
262
|
throw "sefazStatus({...mod}) -> não definido!";
|
263
|
+
let tempUF = urlEventos(__classPrivateFieldGet(this, _Tools_config, "f").UF, __classPrivateFieldGet(this, _Tools_config, "f").versao);
|
264
|
+
//Separado para validar o corpo da consulta
|
199
265
|
let consStatServ = {
|
200
266
|
"@versao": "4.00",
|
201
267
|
"@xmlns": "http://www.portalfiscal.inf.br/nfe",
|
202
268
|
"tpAmb": __classPrivateFieldGet(this, _Tools_config, "f").tpAmb,
|
203
|
-
"cUF":
|
269
|
+
"cUF": tempUF.cUF,
|
204
270
|
"xServ": "STATUS"
|
205
271
|
};
|
206
272
|
let xmlObj = {
|
@@ -219,10 +285,11 @@ class Tools {
|
|
219
285
|
ignoreAttributes: false,
|
220
286
|
attributeNamePrefix: "@"
|
221
287
|
});
|
222
|
-
|
223
|
-
__classPrivateFieldGet(this, _Tools_instances, "m", _Tools_xmlValido).call(this, tempBuild.build({ consStatServ }),
|
288
|
+
//Validação
|
289
|
+
__classPrivateFieldGet(this, _Tools_instances, "m", _Tools_xmlValido).call(this, tempBuild.build({ consStatServ }), `consStatServ_v${__classPrivateFieldGet(this, _Tools_config, "f").versao}`);
|
290
|
+
let tempUF = urlEventos(__classPrivateFieldGet(this, _Tools_config, "f").UF, __classPrivateFieldGet(this, _Tools_config, "f").versao);
|
224
291
|
let xml = tempBuild.build(xmlObj);
|
225
|
-
const req = https.request(
|
292
|
+
const req = https.request(tempUF[`mod${__classPrivateFieldGet(this, _Tools_config, "f").mod}`][(__classPrivateFieldGet(this, _Tools_config, "f").tpAmb == 1 ? "producao" : "homologacao")].NFeStatusServico, {
|
226
293
|
...{
|
227
294
|
method: 'POST',
|
228
295
|
headers: {
|