node-sped-nfe 1.0.2 → 1.0.3
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 +34 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/utils/tools.d.ts +3 -6
- package/dist/utils/tools.js +22 -8
- package/package.json +5 -2
- package/saida.txt +0 -4
- package/schemas/consReciNFe_v4.00.xsd +9 -0
- package/schemas/consSitNFe_v4.00.xsd +9 -0
- package/schemas/consStatServ_v4.00.xsd +9 -0
- package/schemas/enviNFe_v4.00.xsd +9 -0
- package/schemas/inutNFe_v4.00.xsd +9 -0
- package/schemas/leiauteConsSitNFe_v4.00.xsd +502 -0
- package/schemas/leiauteConsStatServ_v4.00.xsd +98 -0
- package/schemas/leiauteInutNFe_v4.00.xsd +193 -0
- package/schemas/leiauteNFe_v4.00.xsd +7412 -0
- package/schemas/nfe_v4.00.xsd +9 -0
- package/schemas/procInutNFe_v4.00.xsd +9 -0
- package/schemas/procNFe_v4.00.xsd +9 -0
- package/schemas/retConsReciNFe_v4.00.xsd +9 -0
- package/schemas/retConsSitNFe_v4.00.xsd +9 -0
- package/schemas/retConsStatServ_v4.00.xsd +9 -0
- package/schemas/retEnviNFe_v4.00.xsd +9 -0
- package/schemas/retInutNFe_v4.00.xsd +9 -0
- package/schemas/tiposBasico_v4.00.xsd +598 -0
- package/schemas/xmldsig-core-schema_v1.01.xsd +98 -0
- package/src/index.ts +2 -2
- package/src/utils/tools.ts +29 -10
- package/testes/assinar.js +16 -0
- package/testes/nfe.js +166 -0
- package/testes/nfe.json +194 -0
- package/testes/nfe_teste.json +45 -0
package/README.md
CHANGED
@@ -44,6 +44,40 @@ Para garantir o funcionamento correto da biblioteca, certifique-se de que os seg
|
|
44
44
|
|
45
45
|
---
|
46
46
|
|
47
|
+
## 🧪 Estados Testados
|
48
|
+
|
49
|
+
A biblioteca já foi testada com sucesso nos seguintes estados brasileiros:
|
50
|
+
|
51
|
+
- ✅ MT — Mato Grosso
|
52
|
+
- ⬜ AC — Acre
|
53
|
+
- ⬜ AL — Alagoas
|
54
|
+
- ⬜ AM — Amazonas
|
55
|
+
- ⬜ AP — Amapá
|
56
|
+
- ⬜ BA — Bahia
|
57
|
+
- ⬜ CE — Ceará
|
58
|
+
- ⬜ DF — Distrito Federal
|
59
|
+
- ⬜ ES — Espírito Santo
|
60
|
+
- ⬜ GO — Goiás
|
61
|
+
- ⬜ MA — Maranhão
|
62
|
+
- ⬜ MG — Minas Gerais
|
63
|
+
- ⬜ MS — Mato Grosso do Sul
|
64
|
+
- ⬜ PA — Pará
|
65
|
+
- ⬜ PB — Paraíba
|
66
|
+
- ⬜ PE — Pernambuco
|
67
|
+
- ⬜ PI — Piauí
|
68
|
+
- ⬜ PR — Paraná
|
69
|
+
- ⬜ RJ — Rio de Janeiro
|
70
|
+
- ⬜ RN — Rio Grande do Norte
|
71
|
+
- ⬜ RO — Rondônia
|
72
|
+
- ⬜ RR — Roraima
|
73
|
+
- ⬜ RS — Rio Grande do Sul
|
74
|
+
- ⬜ SC — Santa Catarina
|
75
|
+
- ⬜ SE — Sergipe
|
76
|
+
- ⬜ SP — São Paulo
|
77
|
+
- ⬜ TO — Tocantins
|
78
|
+
|
79
|
+
Contribua com a comunidade! Testou com sucesso em algum estado? Envie um PR ou abra uma issue!
|
80
|
+
|
47
81
|
## 🚀 Começando
|
48
82
|
|
49
83
|
### 1. Instalação
|
package/dist/index.d.ts
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
import { Tools } from "./utils/tools";
|
2
|
-
import { Make } from "./utils/make";
|
1
|
+
import { Tools } from "./utils/tools.js";
|
2
|
+
import { Make } from "./utils/make.js";
|
3
3
|
export { Tools, Make };
|
package/dist/index.js
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
import { Tools } from "./utils/tools";
|
2
|
-
import { Make } from "./utils/make";
|
1
|
+
import { Tools } from "./utils/tools.js";
|
2
|
+
import { Make } from "./utils/make.js";
|
3
3
|
export { Tools, Make };
|
@@ -0,0 +1 @@
|
|
1
|
+
{"root":["../src/index.ts","../src/utils/eventos.ts","../src/utils/make.ts","../src/utils/tools.ts"],"version":"5.8.3"}
|
package/dist/utils/tools.d.ts
CHANGED
@@ -9,12 +9,9 @@ declare class Tools {
|
|
9
9
|
pfx: string;
|
10
10
|
senha: string;
|
11
11
|
});
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
compactar: boolean;
|
16
|
-
}): Promise<unknown>;
|
17
|
-
xmlSign(xmlJSON: string, data: any): Promise<unknown>;
|
12
|
+
teste(): Promise<object>;
|
13
|
+
sefazEnviaLote(xml: string, data?: any): Promise<string>;
|
14
|
+
xmlSign(xmlJSON: string, data?: any): Promise<string>;
|
18
15
|
xml2json(xml: string): Promise<object>;
|
19
16
|
json2xml(obj: object): Promise<string>;
|
20
17
|
getCertificado(): Promise<unknown>;
|
package/dist/utils/tools.js
CHANGED
@@ -18,6 +18,10 @@ import tmp from "tmp";
|
|
18
18
|
import crypto from "crypto";
|
19
19
|
import { urlServicos } from "./eventos.js";
|
20
20
|
import fs from "fs";
|
21
|
+
import path from 'path';
|
22
|
+
import { fileURLToPath } from 'url';
|
23
|
+
const __filename = fileURLToPath(import.meta.url);
|
24
|
+
const __dirname = path.dirname(__filename);
|
21
25
|
class Tools {
|
22
26
|
constructor(config = { mod: "", xmllint: 'xmllint', cUF: '51', tpAmb: 2 }, certificado = { pfx: "", senha: "" }) {
|
23
27
|
_Tools_instances.add(this);
|
@@ -26,7 +30,11 @@ class Tools {
|
|
26
30
|
XMLBuilder: {},
|
27
31
|
XMLParser: {}
|
28
32
|
});
|
29
|
-
_Tools_pem.set(this, {
|
33
|
+
_Tools_pem.set(this, {
|
34
|
+
key: "", // A chave privada extraída do PKCS#12, em formato PEM
|
35
|
+
cert: "", // O certificado extraído, em formato PEM
|
36
|
+
ca: [] // Uma lista de certificados da cadeia (se houver), ou null
|
37
|
+
});
|
30
38
|
_Tools_config.set(this, void 0);
|
31
39
|
//Configurar certificado
|
32
40
|
__classPrivateFieldSet(this, _Tools_config, config, "f");
|
@@ -41,6 +49,9 @@ class Tools {
|
|
41
49
|
parseTagValue: false, // Evita conversão automática de valores
|
42
50
|
});
|
43
51
|
}
|
52
|
+
async teste() {
|
53
|
+
return await __classPrivateFieldGet(this, _Tools_instances, "m", _Tools_certTools).call(this);
|
54
|
+
}
|
44
55
|
sefazEnviaLote(xml, data = { idLote: 1, indSinc: 0, compactar: false }) {
|
45
56
|
return new Promise(async (resvol, reject) => {
|
46
57
|
if (typeof data.idLote == "undefined")
|
@@ -104,13 +115,13 @@ class Tools {
|
|
104
115
|
}
|
105
116
|
});
|
106
117
|
}
|
107
|
-
async xmlSign(xmlJSON, data) {
|
118
|
+
async xmlSign(xmlJSON, data = { tag: "infNFe" }) {
|
108
119
|
return new Promise(async (resvol, reject) => {
|
109
120
|
if (data.tag === undefined)
|
110
121
|
data.tag = "infNFe";
|
111
122
|
//Obter a tag que ira ser assinada
|
112
123
|
let xml = await this.xml2json(xmlJSON);
|
113
|
-
let
|
124
|
+
let tempPem = await __classPrivateFieldGet(this, _Tools_instances, "m", _Tools_certTools).call(this);
|
114
125
|
const sign = crypto.createSign('RSA-SHA1'); // Correção: Alterado para RSA-SHA1
|
115
126
|
let signedInfo = {
|
116
127
|
"SignedInfo": {
|
@@ -145,10 +156,10 @@ class Tools {
|
|
145
156
|
xml.NFe.Signature = {
|
146
157
|
...signedInfo,
|
147
158
|
...{
|
148
|
-
"SignatureValue": sign.sign(
|
159
|
+
"SignatureValue": sign.sign(tempPem.key, 'base64'),
|
149
160
|
"KeyInfo": {
|
150
161
|
"X509Data": {
|
151
|
-
"X509Certificate":
|
162
|
+
"X509Certificate": tempPem.cert.replace(/-----BEGIN CERTIFICATE-----/g, '').replace(/-----END CERTIFICATE-----/g, '').replace(/\r\n/g, '')
|
152
163
|
}
|
153
164
|
},
|
154
165
|
"@xmlns": "http://www.w3.org/2000/09/xmldsig#"
|
@@ -246,7 +257,8 @@ _Tools_cert = new WeakMap(), _Tools_xmlTools = new WeakMap(), _Tools_pem = new W
|
|
246
257
|
async function _Tools_xmlValido(xml) {
|
247
258
|
const xmlFile = tmp.fileSync({ mode: 0o644, prefix: 'xml-', postfix: '.xml' });
|
248
259
|
fs.writeFileSync(xmlFile.name, xml, { encoding: 'utf8' });
|
249
|
-
const
|
260
|
+
const schemaPath = path.resolve(__dirname, '../../schemas/nfe_v4.00.xsd');
|
261
|
+
const verif = spawnSync(__classPrivateFieldGet(this, _Tools_config, "f").xmllint, ['--noout', '--schema', schemaPath, xmlFile.name], { encoding: 'utf8' });
|
250
262
|
xmlFile.removeCallback();
|
251
263
|
// Aqui, usamos o operador de encadeamento opcional (?.)
|
252
264
|
if (verif.error) {
|
@@ -258,11 +270,13 @@ async function _Tools_xmlValido(xml) {
|
|
258
270
|
return 1;
|
259
271
|
}, _Tools_certTools = function _Tools_certTools() {
|
260
272
|
return new Promise(async (resvol, reject) => {
|
261
|
-
if (__classPrivateFieldGet(this, _Tools_pem, "f") !=
|
273
|
+
if (__classPrivateFieldGet(this, _Tools_pem, "f").key != "")
|
262
274
|
resvol(__classPrivateFieldGet(this, _Tools_pem, "f"));
|
263
275
|
pem.readPkcs12(__classPrivateFieldGet(this, _Tools_cert, "f").pfx, { p12Password: __classPrivateFieldGet(this, _Tools_cert, "f").senha }, (err, myPem) => {
|
276
|
+
if (err)
|
277
|
+
return reject(err); // <-- importante!
|
264
278
|
__classPrivateFieldSet(this, _Tools_pem, myPem, "f");
|
265
|
-
resvol(
|
279
|
+
resvol(__classPrivateFieldGet(this, _Tools_pem, "f"));
|
266
280
|
});
|
267
281
|
});
|
268
282
|
};
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "node-sped-nfe",
|
3
|
-
"version": "1.0.
|
3
|
+
"version": "1.0.3",
|
4
4
|
"author": "Kalmon V. Tavares",
|
5
5
|
"type": "module",
|
6
6
|
"main": "dist/index.js",
|
@@ -13,11 +13,13 @@
|
|
13
13
|
}
|
14
14
|
},
|
15
15
|
"scripts": {
|
16
|
-
"build": "tsc"
|
16
|
+
"build": "tsc > saida.txt",
|
17
|
+
"test:nfe": "node testes/nfe.js"
|
17
18
|
},
|
18
19
|
"devDependencies": {
|
19
20
|
"@types/axios": "^0.9.36",
|
20
21
|
"@types/node": "^22.14.0",
|
22
|
+
"@types/node-forge": "^1.3.11",
|
21
23
|
"@types/pem": "^1.14.4",
|
22
24
|
"@types/tmp": "^0.2.6",
|
23
25
|
"typescript": "^5.0.0"
|
@@ -25,6 +27,7 @@
|
|
25
27
|
"dependencies": {
|
26
28
|
"crypto": "^1.0.1",
|
27
29
|
"fast-xml-parser": "^4.5.1",
|
30
|
+
"node-forge": "^1.3.1",
|
28
31
|
"pem": "^1.14.8",
|
29
32
|
"tmp": "^0.2.3",
|
30
33
|
"xml-crypto": "^6.0.0"
|
package/saida.txt
CHANGED
@@ -0,0 +1,9 @@
|
|
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>
|
@@ -0,0 +1,9 @@
|
|
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>
|
@@ -0,0 +1,9 @@
|
|
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>
|
@@ -0,0 +1,9 @@
|
|
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>
|
@@ -0,0 +1,9 @@
|
|
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>
|