nfe-lib-node 1.0.0
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 +87 -0
- package/package.json +41 -0
package/README.md
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
# nfe-lib-node 🚀
|
|
2
|
+
|
|
3
|
+
Uma biblioteca Node.js em TypeScript para emissão de Nota Fiscal Eletrônica (NF-e) focada em simplicidade, segurança e sem dependência de serviços terceiros (SaaS).
|
|
4
|
+
|
|
5
|
+
Pague apenas os seus impostos, não pela emissão! 😉
|
|
6
|
+
|
|
7
|
+
## 📦 Instalação
|
|
8
|
+
|
|
9
|
+
Como o projeto está no início, faça o clone e instale as dependências localmente:
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
git clone https://github.com/SEU_USUARIO/nfe-lib-node.git
|
|
13
|
+
cd nfe-lib-node
|
|
14
|
+
npm install
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## 🚀 Como usar
|
|
18
|
+
|
|
19
|
+
A arquitetura foi pensada para ser o mais simples possível. Você só precisa do seu Certificado Digital A1 (`.pfx`).
|
|
20
|
+
|
|
21
|
+
### 1. Consultar Status do Serviço (SEFAZ)
|
|
22
|
+
|
|
23
|
+
```typescript
|
|
24
|
+
import { NFe, Certificado } from 'nfe-lib-node';
|
|
25
|
+
import fs from 'fs';
|
|
26
|
+
|
|
27
|
+
async function testarSefaz() {
|
|
28
|
+
const certificado = new Certificado(fs.readFileSync('./certificado.pfx'), 'SENHA_DO_CERTIFICADO');
|
|
29
|
+
const nfe = new NFe({ uf: 'DF', ambiente: 'homologacao', certificado });
|
|
30
|
+
|
|
31
|
+
const status = await nfe.consultarStatus();
|
|
32
|
+
console.log(status.xml);
|
|
33
|
+
}
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### 2. Emitir uma NF-e (Autorização)
|
|
37
|
+
|
|
38
|
+
A biblioteca foca na infraestrutura (Assinatura XMLDSig e SOAP). Você fornece um objeto com a estrutura da SEFAZ, e a biblioteca cuida da dor de cabeça da criptografia:
|
|
39
|
+
|
|
40
|
+
```typescript
|
|
41
|
+
import { NFe, Certificado, DadosNFe } from 'nfe-lib-node';
|
|
42
|
+
import fs from 'fs';
|
|
43
|
+
|
|
44
|
+
async function emitirNota() {
|
|
45
|
+
const certificado = new Certificado(fs.readFileSync('./certificado.pfx'), 'SENHA_DO_CERTIFICADO');
|
|
46
|
+
const nfe = new NFe({ uf: 'DF', ambiente: 'homologacao', certificado });
|
|
47
|
+
|
|
48
|
+
const nota: DadosNFe = {
|
|
49
|
+
infNFe: {
|
|
50
|
+
'@Id': 'NFe5326...',
|
|
51
|
+
'@versao': '4.00',
|
|
52
|
+
ide: { /* ... */ },
|
|
53
|
+
emit: { /* ... */ },
|
|
54
|
+
dest: { /* ... */ },
|
|
55
|
+
det: { /* ... */ },
|
|
56
|
+
total: { /* ... */ },
|
|
57
|
+
transp: { /* ... */ },
|
|
58
|
+
pag: { /* ... */ }
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const resposta = await nfe.emitir(nota);
|
|
63
|
+
console.log(resposta.xml); // Autorizado!
|
|
64
|
+
}
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
testarSefaz();
|
|
68
|
+
|
|
69
|
+
## 🛡️ Segurança
|
|
70
|
+
|
|
71
|
+
* **Nunca** faça commit do seu arquivo `.pfx` ou da sua senha para o GitHub.
|
|
72
|
+
* O arquivo `.gitignore` já vem configurado para ignorar extensões de certificados por padrão.
|
|
73
|
+
|
|
74
|
+
## 🤝 Contribuições
|
|
75
|
+
|
|
76
|
+
Este projeto está no início (Fase 1: Comunicação Base). As próximas etapas envolvem a construção dos Builders de XML e a Assinatura Digital (XMLDSig). Toda contribuição da comunidade Node.js brasileira é bem-vinda!
|
|
77
|
+
|
|
78
|
+
## 👨💻 Autor
|
|
79
|
+
|
|
80
|
+
Criado e idealizado por **Rafael Conrado**.
|
|
81
|
+
Se você curtiu o projeto, me dê um "Alô" nas redes:
|
|
82
|
+
* [GitHub - @rafconrado](https://github.com/rafconrado)
|
|
83
|
+
* [LinkedIn](https://www.linkedin.com/in/rafconradoo/)
|
|
84
|
+
|
|
85
|
+
## 📝 Licença
|
|
86
|
+
|
|
87
|
+
MIT License
|
package/package.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "nfe-lib-node",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Biblioteca Node.js para emissão, assinatura e comunicação com webservices de NF-e (SEFAZ)",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist",
|
|
10
|
+
"README.md"
|
|
11
|
+
],
|
|
12
|
+
"scripts": {
|
|
13
|
+
"build": "tsc",
|
|
14
|
+
"prepublishOnly": "npm run build",
|
|
15
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
16
|
+
},
|
|
17
|
+
"keywords": [
|
|
18
|
+
"nfe",
|
|
19
|
+
"sefaz",
|
|
20
|
+
"xml",
|
|
21
|
+
"xmldsig",
|
|
22
|
+
"soap",
|
|
23
|
+
"nota-fiscal"
|
|
24
|
+
],
|
|
25
|
+
"author": "Rafael Conrado",
|
|
26
|
+
"license": "MIT",
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@xmldom/xmldom": "^0.9.12",
|
|
29
|
+
"axios": "^1.20.0",
|
|
30
|
+
"node-forge": "^1.4.0",
|
|
31
|
+
"xml-crypto": "^6.3.0",
|
|
32
|
+
"xmlbuilder2": "^4.0.3"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@types/node": "^26.6.2",
|
|
36
|
+
"@types/node-forge": "^1.3.14",
|
|
37
|
+
"@types/xml-crypto": "^1.4.6",
|
|
38
|
+
"ts-node": "^10.9.2",
|
|
39
|
+
"typescript": "^7.0.2"
|
|
40
|
+
}
|
|
41
|
+
}
|