node-sped-nfe 1.0.5 → 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.
- 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.js +6 -3
- package/dist/utils/tools.d.ts +3 -1
- package/dist/utils/tools.js +73 -8
- package/exemplos/consulta.js +19 -0
- package/exemplos/nfe.js +4 -3
- package/exemplos/status.js +2 -1
- package/package.json +4 -2
- package/src/utils/eventos.ts +800 -106
- package/src/utils/extras.ts +59 -0
- package/src/utils/make.ts +9 -6
- package/src/utils/tools.ts +83 -9
- 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,59 @@
|
|
1
|
+
const cUF2UF: any = {
|
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
|
+
},
|
30
|
+
UF2cUF: any = {
|
31
|
+
"RO": "11",
|
32
|
+
"AC": "12",
|
33
|
+
"AM": "13",
|
34
|
+
"RR": "14",
|
35
|
+
"PA": "15",
|
36
|
+
"AP": "16",
|
37
|
+
"TO": "17",
|
38
|
+
"MA": "21",
|
39
|
+
"PI": "22",
|
40
|
+
"CE": "23",
|
41
|
+
"RN": "24",
|
42
|
+
"PB": "25",
|
43
|
+
"PE": "26",
|
44
|
+
"AL": "27",
|
45
|
+
"SE": "28",
|
46
|
+
"BA": "29",
|
47
|
+
"MG": "31",
|
48
|
+
"ES": "32",
|
49
|
+
"RJ": "33",
|
50
|
+
"SP": "35",
|
51
|
+
"PR": "41",
|
52
|
+
"SC": "42",
|
53
|
+
"RS": "43",
|
54
|
+
"MS": "50",
|
55
|
+
"MT": "51",
|
56
|
+
"GO": "52",
|
57
|
+
"DF": "53"
|
58
|
+
};
|
59
|
+
export { cUF2UF, UF2cUF }
|
package/src/utils/make.ts
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
|
2
2
|
import { XMLParser, XMLBuilder, XMLValidator } from "fast-xml-parser";
|
3
|
-
import {
|
3
|
+
import { urlEventos } from "./eventos.js"
|
4
|
+
import { cUF2UF } from "./extras.js"
|
4
5
|
|
5
6
|
//Classe da nota fiscal
|
6
7
|
class Make {
|
@@ -129,7 +130,7 @@ class Make {
|
|
129
130
|
tagProd(obj: any) {
|
130
131
|
//Abrir tag de imposto
|
131
132
|
for (let cont = 0; cont < obj.length; cont++) {
|
132
|
-
|
133
|
+
|
133
134
|
if (obj[cont]['@nItem'] === undefined) {
|
134
135
|
obj[cont] = { '@nItem': cont + 1, prod: obj[cont], imposto: {} };
|
135
136
|
} else {
|
@@ -138,7 +139,7 @@ class Make {
|
|
138
139
|
}
|
139
140
|
|
140
141
|
//Primeiro item + NFCe + Homologação
|
141
|
-
if(cont==0 && this.#NFe.infNFe.ide.mod == 65 && this.#NFe.infNFe.ide.tpAmb == 2
|
142
|
+
if (cont == 0 && this.#NFe.infNFe.ide.mod == 65 && this.#NFe.infNFe.ide.tpAmb == 2) obj[cont].prod.xProd = "NOTA FISCAL EMITIDA EM AMBIENTE DE HOMOLOGACAO - SEM VALOR FISCAL";
|
142
143
|
|
143
144
|
obj[cont].prod.qCom = (obj[cont].prod.qCom * 1).toFixed(4)
|
144
145
|
obj[cont].prod.vUnCom = (obj[cont].prod.vUnCom * 1).toFixed(10)
|
@@ -640,9 +641,11 @@ class Make {
|
|
640
641
|
|
641
642
|
//Adicionar QrCode
|
642
643
|
if (this.#NFe.infNFe.ide.mod == 65) {
|
644
|
+
//Como ja temos cUF, usamo dados do extras para convere em UF e achar os dados de url!
|
645
|
+
let tempUF = urlEventos(cUF2UF[this.#NFe.infNFe.ide.cUF], this.#NFe.infNFe['@versao']);
|
643
646
|
this.#NFe.infNFeSupl = {
|
644
|
-
qrCode:
|
645
|
-
urlChave:
|
647
|
+
qrCode: tempUF.mod65[this.#NFe.infNFe.ide.tpAmb == 1 ? 'producao' : 'homologacao'].NFeConsultaQR,
|
648
|
+
urlChave: tempUF.mod65[this.#NFe.infNFe.ide.tpAmb == 1 ? 'producao' : 'homologacao'].urlChave
|
646
649
|
}
|
647
650
|
}
|
648
651
|
|
@@ -652,7 +655,7 @@ class Make {
|
|
652
655
|
});
|
653
656
|
return tempBuild.build({ NFe: this.#NFe });
|
654
657
|
}
|
655
|
-
|
658
|
+
|
656
659
|
#calICMSTot(obj: any) {
|
657
660
|
Object.keys(obj).map(key => {
|
658
661
|
if (this.#ICMSTot[key] !== undefined) {
|
package/src/utils/tools.ts
CHANGED
@@ -3,7 +3,7 @@ import https from "https";
|
|
3
3
|
import { spawnSync, SpawnSyncReturns } from "child_process"
|
4
4
|
import tmp from "tmp"
|
5
5
|
import crypto from "crypto";
|
6
|
-
import {
|
6
|
+
import { urlEventos } from "./eventos.js"
|
7
7
|
import fs from "fs"
|
8
8
|
import path from 'path';
|
9
9
|
import { fileURLToPath } from 'url';
|
@@ -38,13 +38,14 @@ class Tools {
|
|
38
38
|
#config: {
|
39
39
|
mod: string;
|
40
40
|
xmllint: string;
|
41
|
-
|
41
|
+
UF: string;
|
42
42
|
tpAmb: number;
|
43
43
|
CSC: string;
|
44
44
|
CSCid: string;
|
45
|
+
versao: string;
|
45
46
|
};
|
46
47
|
|
47
|
-
constructor(config = { mod: "", xmllint: 'xmllint',
|
48
|
+
constructor(config = { mod: "", xmllint: 'xmllint', UF: '', tpAmb: 2, CSC: "", CSCid: "", versao: "4.00" }, certificado = { pfx: "", senha: "" }) {
|
48
49
|
//Configurar certificado
|
49
50
|
this.#config = config;
|
50
51
|
this.#cert = certificado;
|
@@ -89,7 +90,8 @@ class Tools {
|
|
89
90
|
}
|
90
91
|
let xmlLote = await this.json2xml(jsonXmlLote);
|
91
92
|
try {
|
92
|
-
|
93
|
+
let tempUF = urlEventos(this.#config.UF, this.#config.versao);
|
94
|
+
const req = https.request(tempUF[`mod${this.#config.mod}`][(this.#config.tpAmb == 1 ? "producao" : "homologacao")].NFeAutorizacao, {
|
93
95
|
...{
|
94
96
|
method: 'POST',
|
95
97
|
headers: {
|
@@ -181,7 +183,7 @@ class Tools {
|
|
181
183
|
}
|
182
184
|
|
183
185
|
this.json2xml(xml).then(async res => {
|
184
|
-
this.#xmlValido(res,
|
186
|
+
this.#xmlValido(res, `nfe_${this.#config.versao}`);
|
185
187
|
resvol(res);
|
186
188
|
}).catch(err => {
|
187
189
|
reject(err)
|
@@ -221,20 +223,91 @@ class Tools {
|
|
221
223
|
})
|
222
224
|
}
|
223
225
|
|
226
|
+
consultarNFe(chNFe: string): Promise<string> {
|
227
|
+
return new Promise(async (resolve, reject) => {
|
228
|
+
if (!chNFe || chNFe.length !== 44) {
|
229
|
+
return reject("consultarNFe(chNFe) -> chave inválida!");
|
230
|
+
}
|
231
|
+
|
232
|
+
if (typeof this.#config.UF === "undefined") throw "consultarNFe({...UF}) -> não definido!";
|
233
|
+
if (typeof this.#config.tpAmb === "undefined") throw "consultarNFe({...tpAmb}) -> não definido!";
|
234
|
+
if (typeof this.#config.mod === "undefined") throw "consultarNFe({...mod}) -> não definido!";
|
235
|
+
|
236
|
+
let consSitNFe = {
|
237
|
+
"@xmlns": "http://www.portalfiscal.inf.br/nfe",
|
238
|
+
"@versao": "4.00",
|
239
|
+
"tpAmb": this.#config.tpAmb,
|
240
|
+
"xServ": "CONSULTAR",
|
241
|
+
"chNFe": chNFe
|
242
|
+
};
|
243
|
+
|
244
|
+
let xmlObj = {
|
245
|
+
"soap:Envelope": {
|
246
|
+
"@xmlns:soap": "http://www.w3.org/2003/05/soap-envelope",
|
247
|
+
"@xmlns:nfe": "http://www.portalfiscal.inf.br/nfe/wsdl/NFeConsultaProtocolo4",
|
248
|
+
"soap:Body": {
|
249
|
+
"nfe:nfeDadosMsg": {
|
250
|
+
"consSitNFe": consSitNFe
|
251
|
+
}
|
252
|
+
}
|
253
|
+
}
|
254
|
+
};
|
255
|
+
|
256
|
+
try {
|
257
|
+
const builder = new XMLBuilder({
|
258
|
+
ignoreAttributes: false,
|
259
|
+
attributeNamePrefix: "@"
|
260
|
+
});
|
261
|
+
|
262
|
+
// Validação do XML interno (opcional)
|
263
|
+
this.#xmlValido(builder.build({ consSitNFe }), `consSitNFe_v${this.#config.versao}`);
|
264
|
+
|
265
|
+
const xml = builder.build(xmlObj);
|
266
|
+
|
267
|
+
let tempUF = urlEventos(this.#config.UF, this.#config.versao);
|
268
|
+
|
269
|
+
const url = tempUF[`mod${this.#config.mod}`][(this.#config.tpAmb == 1 ? "producao" : "homologacao")].NFeConsultaProtocolo;
|
270
|
+
|
271
|
+
const req = https.request(url, {
|
272
|
+
method: 'POST',
|
273
|
+
headers: {
|
274
|
+
'Content-Type': 'application/soap+xml; charset=utf-8',
|
275
|
+
'Content-Length': xml.length,
|
276
|
+
},
|
277
|
+
rejectUnauthorized: false,
|
278
|
+
...await this.#certTools()
|
279
|
+
}, (res) => {
|
280
|
+
let data = '';
|
281
|
+
res.on('data', (chunk) => data += chunk);
|
282
|
+
res.on('end', () => resolve(data));
|
283
|
+
});
|
284
|
+
|
285
|
+
req.on('error', (err) => reject(err));
|
286
|
+
|
287
|
+
req.write(xml);
|
288
|
+
req.end();
|
289
|
+
} catch (err) {
|
290
|
+
reject(err);
|
291
|
+
}
|
292
|
+
});
|
293
|
+
}
|
294
|
+
|
224
295
|
//Consulta status sefaz
|
225
296
|
async sefazStatus(): Promise<string> {
|
226
297
|
return new Promise(async (resvol, reject) => {
|
227
298
|
|
228
|
-
if (typeof this.#config.
|
299
|
+
if (typeof this.#config.UF == "undefined") throw "sefazStatus({...UF}) -> não definido!";
|
229
300
|
if (typeof this.#config.tpAmb == "undefined") throw "sefazStatus({...tpAmb}) -> não definido!";
|
230
301
|
if (typeof this.#config.mod == "undefined") throw "sefazStatus({...mod}) -> não definido!";
|
231
302
|
|
303
|
+
let tempUF = urlEventos(this.#config.UF, this.#config.versao);
|
304
|
+
|
232
305
|
//Separado para validar o corpo da consulta
|
233
306
|
let consStatServ = {
|
234
307
|
"@versao": "4.00",
|
235
308
|
"@xmlns": "http://www.portalfiscal.inf.br/nfe",
|
236
309
|
"tpAmb": this.#config.tpAmb,
|
237
|
-
"cUF":
|
310
|
+
"cUF": tempUF.cUF,
|
238
311
|
"xServ": "STATUS"
|
239
312
|
}
|
240
313
|
|
@@ -257,9 +330,10 @@ class Tools {
|
|
257
330
|
});
|
258
331
|
|
259
332
|
//Validação
|
260
|
-
this.#xmlValido(tempBuild.build({ consStatServ }),
|
333
|
+
this.#xmlValido(tempBuild.build({ consStatServ }), `consStatServ_v${this.#config.versao}`);
|
334
|
+
let tempUF = urlEventos(this.#config.UF, this.#config.versao);
|
261
335
|
let xml = tempBuild.build(xmlObj);
|
262
|
-
const req = https.request(
|
336
|
+
const req = https.request(tempUF[`mod${this.#config.mod}`][(this.#config.tpAmb == 1 ? "producao" : "homologacao")].NFeStatusServico, {
|
263
337
|
...{
|
264
338
|
method: 'POST',
|
265
339
|
headers: {
|
@@ -1,9 +0,0 @@
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
-
<xs:schema xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns="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">
|
3
|
-
<xs:include schemaLocation="leiauteNFe_v4.00.xsd"/>
|
4
|
-
<xs:element name="consReciNFe" type="TConsReciNFe">
|
5
|
-
<xs:annotation>
|
6
|
-
<xs:documentation>Schema XML de validação do Pedido de Consulta do Recido do Lote de Notas Fiscais Eletrônicas</xs:documentation>
|
7
|
-
</xs:annotation>
|
8
|
-
</xs:element>
|
9
|
-
</xs:schema>
|
@@ -1,9 +0,0 @@
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
-
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.portalfiscal.inf.br/nfe" targetNamespace="http://www.portalfiscal.inf.br/nfe" elementFormDefault="qualified" attributeFormDefault="unqualified">
|
3
|
-
<xs:include schemaLocation="leiauteConsSitNFe_v4.00.xsd"/>
|
4
|
-
<xs:element name="consSitNFe" type="TConsSitNFe">
|
5
|
-
<xs:annotation>
|
6
|
-
<xs:documentation>Schema de validação XML dp Pedido de Consulta da Situação Atual da Nota Fiscal Eletrônica</xs:documentation>
|
7
|
-
</xs:annotation>
|
8
|
-
</xs:element>
|
9
|
-
</xs:schema>
|
@@ -1,9 +0,0 @@
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
-
<xs:schema xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns="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">
|
3
|
-
<xs:include schemaLocation="leiauteConsStatServ_v4.00.xsd"/>
|
4
|
-
<xs:element name="consStatServ" type="TConsStatServ">
|
5
|
-
<xs:annotation>
|
6
|
-
<xs:documentation>Schema XML de validação do Pedido de Consulta do Status do Serviço</xs:documentation>
|
7
|
-
</xs:annotation>
|
8
|
-
</xs:element>
|
9
|
-
</xs:schema>
|
@@ -1,9 +0,0 @@
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
-
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.portalfiscal.inf.br/nfe" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" targetNamespace="http://www.portalfiscal.inf.br/nfe" elementFormDefault="qualified" attributeFormDefault="unqualified">
|
3
|
-
<xs:include schemaLocation="leiauteNFe_v4.00.xsd"/>
|
4
|
-
<xs:element name="enviNFe" type="TEnviNFe">
|
5
|
-
<xs:annotation>
|
6
|
-
<xs:documentation>Schema XML de validação do Pedido de Concessão de Autorização da Nota Fiscal Eletrônica</xs:documentation>
|
7
|
-
</xs:annotation>
|
8
|
-
</xs:element>
|
9
|
-
</xs:schema>
|
@@ -1,9 +0,0 @@
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
-
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.portalfiscal.inf.br/nfe" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" targetNamespace="http://www.portalfiscal.inf.br/nfe" elementFormDefault="qualified" attributeFormDefault="unqualified">
|
3
|
-
<xs:include schemaLocation="leiauteInutNFe_v4.00.xsd"/>
|
4
|
-
<xs:element name="inutNFe" type="TInutNFe">
|
5
|
-
<xs:annotation>
|
6
|
-
<xs:documentation>Schema XML de validação do Pedido de Inutilização de Numeração da Nota Fiscal Eletrônica</xs:documentation>
|
7
|
-
</xs:annotation>
|
8
|
-
</xs:element>
|
9
|
-
</xs:schema>
|