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,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.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() {
|
@@ -516,9 +517,11 @@ class Make {
|
|
516
517
|
__classPrivateFieldGet(this, _Make_NFe, "f").infNFe[`@Id`] = `NFe${__classPrivateFieldGet(this, _Make_instances, "m", _Make_gerarChaveNFe).call(this)}`;
|
517
518
|
//Adicionar QrCode
|
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']);
|
519
522
|
__classPrivateFieldGet(this, _Make_NFe, "f").infNFeSupl = {
|
520
|
-
qrCode:
|
521
|
-
urlChave:
|
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
|
522
525
|
};
|
523
526
|
}
|
524
527
|
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;
|
@@ -16,6 +17,7 @@ declare class Tools {
|
|
16
17
|
xml2json(xml: string): Promise<object>;
|
17
18
|
json2xml(obj: object): Promise<string>;
|
18
19
|
getCertificado(): Promise<unknown>;
|
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: {
|
@@ -187,20 +188,83 @@ class Tools {
|
|
187
188
|
__classPrivateFieldGet(this, _Tools_instances, "m", _Tools_certTools).call(this).then(resvol).catch(reject);
|
188
189
|
});
|
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
|
+
}
|
250
|
+
});
|
251
|
+
}
|
190
252
|
//Consulta status sefaz
|
191
253
|
async sefazStatus() {
|
192
254
|
return new Promise(async (resvol, reject) => {
|
193
|
-
if (typeof __classPrivateFieldGet(this, _Tools_config, "f").
|
194
|
-
throw "sefazStatus({...
|
255
|
+
if (typeof __classPrivateFieldGet(this, _Tools_config, "f").UF == "undefined")
|
256
|
+
throw "sefazStatus({...UF}) -> não definido!";
|
195
257
|
if (typeof __classPrivateFieldGet(this, _Tools_config, "f").tpAmb == "undefined")
|
196
258
|
throw "sefazStatus({...tpAmb}) -> não definido!";
|
197
259
|
if (typeof __classPrivateFieldGet(this, _Tools_config, "f").mod == "undefined")
|
198
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
|
199
263
|
let consStatServ = {
|
200
264
|
"@versao": "4.00",
|
201
265
|
"@xmlns": "http://www.portalfiscal.inf.br/nfe",
|
202
266
|
"tpAmb": __classPrivateFieldGet(this, _Tools_config, "f").tpAmb,
|
203
|
-
"cUF":
|
267
|
+
"cUF": tempUF.cUF,
|
204
268
|
"xServ": "STATUS"
|
205
269
|
};
|
206
270
|
let xmlObj = {
|
@@ -219,10 +283,11 @@ class Tools {
|
|
219
283
|
ignoreAttributes: false,
|
220
284
|
attributeNamePrefix: "@"
|
221
285
|
});
|
222
|
-
|
286
|
+
//Validação
|
223
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);
|
224
289
|
let xml = tempBuild.build(xmlObj);
|
225
|
-
const req = https.request(
|
290
|
+
const req = https.request(tempUF[`mod${__classPrivateFieldGet(this, _Tools_config, "f").mod}`][(__classPrivateFieldGet(this, _Tools_config, "f").tpAmb == 1 ? "producao" : "homologacao")].NFeStatusServico, {
|
226
291
|
...{
|
227
292
|
method: 'POST',
|
228
293
|
headers: {
|
@@ -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
|
+
})
|
package/exemplos/nfe.js
CHANGED
@@ -4,7 +4,8 @@ import fs from "fs";
|
|
4
4
|
let myTools = new Tools({ //Configuração de habiente e sistema
|
5
5
|
mod: '55',
|
6
6
|
tpAmb: 2,
|
7
|
-
|
7
|
+
UF: 'MT',
|
8
|
+
versao: '4.00',
|
8
9
|
|
9
10
|
//Optativo: Leia sobre Requisitos.
|
10
11
|
xmllint: `../libxml2-2.9.3-win32-x86_64/bin/xmllint.exe`
|
@@ -151,12 +152,12 @@ NFe.tagTransp({ modFrete: 9 });
|
|
151
152
|
NFe.tagDetPag([{ indPag: 0, tPag: 17, vPag: "1200.00" }]);
|
152
153
|
NFe.tagTroco("0.00");
|
153
154
|
NFe.tagInfRespTec({ CNPJ: "47506306000188", xContato: "Guara Dev", email: "admin@guaradev.com", fone: "5566999638922" })
|
154
|
-
fs.writeFileSync("nfe.xml", NFe.xml(), { encoding: "utf-8" });
|
155
|
+
fs.writeFileSync("testes/nfe.xml", NFe.xml(), { encoding: "utf-8" });
|
155
156
|
|
156
157
|
//NFe.xml() = retorna o XML gerado ate o momento.
|
157
158
|
// myTools.xmlSign(..) = Assina o xml utlizando o certificado declarado em new Tools.
|
158
159
|
myTools.xmlSign(NFe.xml()).then(async xmlSign => {
|
159
|
-
fs.writeFileSync("nfe_sign.xml", xmlSign, { encoding: "utf-8" });
|
160
|
+
fs.writeFileSync("testes/nfe_sign.xml", xmlSign, { encoding: "utf-8" });
|
160
161
|
myTools.sefazEnviaLote(xmlSign, { indSinc: 1 }).then(res => {
|
161
162
|
console.log(res)
|
162
163
|
})
|
package/exemplos/status.js
CHANGED
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "node-sped-nfe",
|
3
|
-
"version": "1.0.
|
3
|
+
"version": "1.0.6",
|
4
4
|
"author": "Kalmon V. Tavares",
|
5
5
|
"type": "module",
|
6
6
|
"main": "dist/index.js",
|
@@ -28,7 +28,9 @@
|
|
28
28
|
|
29
29
|
"t:status": "node exemplos/status.js",
|
30
30
|
"t:nfe": "node exemplos/nfe.js",
|
31
|
-
"t:nfce": "node exemplos/nfce.js"
|
31
|
+
"t:nfce": "node exemplos/nfce.js",
|
32
|
+
|
33
|
+
"t:consult": "node testes/consulta.js"
|
32
34
|
},
|
33
35
|
"devDependencies": {
|
34
36
|
"@types/axios": "^0.9.36",
|