@bitize/bitmde 0.17.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/CHANGELOG.md +431 -0
- package/LICENSE +22 -0
- package/README.md +398 -0
- package/dist/apis/distribuicaoDFe-api.d.ts +113 -0
- package/dist/apis/recepcaoEvento-api.d.ts +81 -0
- package/dist/controllers/distribuicaoDFe-controller.d.ts +30 -0
- package/dist/controllers/index.d.ts +58 -0
- package/dist/controllers/recepcaoEvento-controller.d.ts +37 -0
- package/dist/env/ca.d.ts +6 -0
- package/dist/env/distribuicao.d.ts +8 -0
- package/dist/env/evento.d.ts +18 -0
- package/dist/env/index.d.ts +8 -0
- package/dist/env/recepcao.d.ts +8 -0
- package/dist/env/uf.d.ts +1 -0
- package/dist/env/version.d.ts +1 -0
- package/dist/env/zone.d.ts +1 -0
- package/dist/helpers/distribuicaoDFe-helper.d.ts +41 -0
- package/dist/helpers/index.d.ts +74 -0
- package/dist/helpers/recepcaoEvento-helper.d.ts +48 -0
- package/dist/helpers/retorno-helper.d.ts +27 -0
- package/dist/index.d.ts +11 -0
- package/dist/schemas/distribuicaoDFe-schema.d.ts +15 -0
- package/dist/schemas/index.d.ts +37 -0
- package/dist/schemas/recepcaoEvento-schema.d.ts +21 -0
- package/dist/services/sefaz-service.d.ts +12 -0
- package/dist/util/assinatura.d.ts +12 -0
- package/dist/util/certificado.d.ts +14 -0
- package/dist/util/data.d.ts +11 -0
- package/dist/util/gzip.d.ts +10 -0
- package/dist/util/index.d.ts +32 -0
- package/dist/util/xml.d.ts +22 -0
- package/dist/util/zeroPad.d.ts +10 -0
- package/dist/validators/ambiente-validator.d.ts +19 -0
- package/dist/validators/certificado-validator.d.ts +29 -0
- package/dist/validators/chave-validator.d.ts +14 -0
- package/dist/validators/cnpjCpf-validator.d.ts +23 -0
- package/dist/validators/evento-validator.d.ts +30 -0
- package/dist/validators/index.d.ts +146 -0
- package/dist/validators/lote-validator.d.ts +35 -0
- package/dist/validators/nsu-validator.d.ts +14 -0
- package/dist/validators/uf-validator.d.ts +19 -0
- package/dist/validators/zone-validator.d.ts +19 -0
- package/lib/apis/distribuicaoDFe-api.js +64 -0
- package/lib/apis/recepcaoEvento-api.js +65 -0
- package/lib/controllers/distribuicaoDFe-controller.js +17 -0
- package/lib/controllers/index.js +6 -0
- package/lib/controllers/recepcaoEvento-controller.js +17 -0
- package/lib/env/ca.js +5 -0
- package/lib/env/distribuicao.js +8 -0
- package/lib/env/evento.js +22 -0
- package/lib/env/index.js +11 -0
- package/lib/env/recepcao.js +8 -0
- package/lib/env/uf.js +5 -0
- package/lib/env/version.js +3 -0
- package/lib/env/zone.js +5 -0
- package/lib/helpers/distribuicaoDFe-helper.js +58 -0
- package/lib/helpers/index.js +7 -0
- package/lib/helpers/recepcaoEvento-helper.js +64 -0
- package/lib/helpers/retorno-helper.js +18 -0
- package/lib/index.js +12 -0
- package/lib/schemas/distribuicaoDFe-schema.js +25 -0
- package/lib/schemas/index.js +6 -0
- package/lib/schemas/recepcaoEvento-schema.js +30 -0
- package/lib/services/sefaz-service.js +63 -0
- package/lib/util/assinatura.js +25 -0
- package/lib/util/certificado.js +21 -0
- package/lib/util/data.js +9 -0
- package/lib/util/gzip.js +16 -0
- package/lib/util/index.js +10 -0
- package/lib/util/xml.js +28 -0
- package/lib/util/zeroPad.js +7 -0
- package/lib/validators/ambiente-validator.js +19 -0
- package/lib/validators/certificado-validator.js +32 -0
- package/lib/validators/chave-validator.js +16 -0
- package/lib/validators/cnpjCpf-validator.js +23 -0
- package/lib/validators/evento-validator.js +39 -0
- package/lib/validators/index.js +13 -0
- package/lib/validators/lote-validator.js +26 -0
- package/lib/validators/nsu-validator.js +19 -0
- package/lib/validators/uf-validator.js +21 -0
- package/lib/validators/zone-validator.js +24 -0
- package/package.json +82 -0
package/README.md
ADDED
|
@@ -0,0 +1,398 @@
|
|
|
1
|
+
# Bit MD-e
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@bitize/bitmde)
|
|
4
|
+
[](https://npm-stat.com/charts.html?package=@bitize/bitmde)
|
|
5
|
+
[](https://github.com/bitize/bitmde/blob/main/LICENSE)
|
|
6
|
+
[](https://www.biterp.ai)
|
|
7
|
+
|
|
8
|
+
Biblioteca para consumo dos Web Services da Sefaz de Distribuição de DF-e e Evento de Manifestação do Destinatário.
|
|
9
|
+
|
|
10
|
+
Essa biblioteca permite consultar a relação das notas fiscais emitidas contra um determinado CNPJ/CPF e realizar o envio do evento de manifestação, podendo assim, baixar o XML da NF-e.
|
|
11
|
+
|
|
12
|
+
Desenvolvida e mantida pela equipe do **[BitERP](https://www.biterp.ai)**, onde é usada em produção para a automação da manifestação do destinatário e do download de XML de NF-e de entrada.
|
|
13
|
+
|
|
14
|
+
> Este projeto é um fork de [node-mde](https://github.com/lucashpmelo/node-mde), criado por [Lucas Melo](https://github.com/lucashpmelo), mantido pela [Bitize](https://www.biterp.ai) e publicado no npm como `@bitize/bitmde`. A API pública permanece a mesma — apenas o nome do pacote muda.
|
|
15
|
+
>
|
|
16
|
+
> **Vindo de `@bitize/bit-mde` ou de `node-mde`?** O pacote é o mesmo; só o nome mudou (`node-mde` até a 0.14.13, `@bitize/bit-mde` até a 0.16.0). Troque o nome na instalação e nos `require`/`import` — nenhuma outra alteração é necessária.
|
|
17
|
+
|
|
18
|
+
## Instalação
|
|
19
|
+
|
|
20
|
+
```sh
|
|
21
|
+
npm i @bitize/bitmde
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Pré-Requisitos
|
|
25
|
+
|
|
26
|
+
- Possuir um **Certificado A1** válido emitido por uma Autoridade Certificadora credenciada pela Infraestrutura de Chaves Públicas Brasileira – **ICP-Brasil**.
|
|
27
|
+
- O certificado pode ser usando no formato **PFX** e **Senha** _OU_ **cert.pem** e **key.pem**
|
|
28
|
+
|
|
29
|
+
## Funcionalidades
|
|
30
|
+
|
|
31
|
+
- Consultar por último NSU
|
|
32
|
+
- Retorna a relação dos Documentos Fiscais (`Resumo da NF-e`, `NF-e`, `Resumo do Evento` ou `Evento`)
|
|
33
|
+
- Consultar por chave de acesso
|
|
34
|
+
- Retorna o `XML da NF-e` ou o `Resumo da NF-e`
|
|
35
|
+
- Consultar por NSU
|
|
36
|
+
- Retorna o Documento Fiscal referente ao NSU informado, podendo ser um `Resumo`, uma `NF-e` ou um `Evento`
|
|
37
|
+
- Envio de evento
|
|
38
|
+
- Registra o evento de manifestação na nota informada (`Confirmação da Operação`, `Ciência da Operação`, `Desconhecimento da Operação` ou `Operação não Realizada`)
|
|
39
|
+
|
|
40
|
+
## Distribuição de DF-e
|
|
41
|
+
|
|
42
|
+
### Construtor
|
|
43
|
+
|
|
44
|
+
```js
|
|
45
|
+
new DistribuicaoDFe(config)
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
- `config` `<Object>`
|
|
49
|
+
- `pfx` `<Buffer>` - [OPCIONAL] - Arquivo **.pfx**. Se o `pfx` não for informado, as propriedades `cert` e `key` passam a ser obrigatórias.
|
|
50
|
+
- `passphrase` `<String>` - [OPCIONAL] - Senha do arquivo **.pfx**.
|
|
51
|
+
- `cert` `<Buffer | String>` - [OPCIONAL] - Conteúdo do _cert.pem_. Essa propriedade fica obrigatória se o `pfx` não for informado.
|
|
52
|
+
- `key` `<Buffer | String>` - [OPCIONAL] - Conteúdo do _key.pem_. Essa propriedade fica obrigatória se o `pfx` não for informado.
|
|
53
|
+
- `cUFAutor` `<String>` - [OBRIGATÓRIO] - Código da UF do autor. Consulte a tabela [códigos UF](#códigos-uf).
|
|
54
|
+
- `cnpj` `<String>` - [OPCIONAL] - CNPJ do interessado no DF-e. Se não informado um CNPJ, será obrigatório informar um CPF.
|
|
55
|
+
- `cpf` `<String>` - [OPCIONAL] - CPF do interessado no DF-e. Se não informado um CPF, será obrigatório informar um CNPJ.
|
|
56
|
+
- `tpAmb` `<String>` - [OBRIGATÓRIO] - Identificação de Ambiente. Informar `'1'` para **Produção** ou `'2'` para **Homologação**.
|
|
57
|
+
- `options` `<Object>` - [OPCIONAL]
|
|
58
|
+
- `requestOptions` `<AxiosRequestConfig>` - [OPCIONAL]
|
|
59
|
+
- `httpsOptions` `<AgentOptions>` - [OPCIONAL]
|
|
60
|
+
|
|
61
|
+
### Consulta por ultNSU
|
|
62
|
+
|
|
63
|
+
| Campo | Tipo | Tamanho | Descrição |
|
|
64
|
+
| :------- | :------: | :-----: | :----------------------------- |
|
|
65
|
+
| `ultNSU` | _string_ | 1-15 | Último NSU recebido pelo ator. |
|
|
66
|
+
|
|
67
|
+
#### Exemplo
|
|
68
|
+
|
|
69
|
+
```js
|
|
70
|
+
const { DistribuicaoDFe } = require('@bitize/bitmde')
|
|
71
|
+
const fs = require('fs')
|
|
72
|
+
|
|
73
|
+
const distribuicao = new DistribuicaoDFe({
|
|
74
|
+
pfx: fs.readFileSync('./certificado.pfx'),
|
|
75
|
+
passphrase: 'senha',
|
|
76
|
+
cnpj: '12345678901234',
|
|
77
|
+
cUFAutor: '41',
|
|
78
|
+
tpAmb: '2',
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
const consulta = await distribuicao.consultaUltNSU('000000000000000')
|
|
82
|
+
|
|
83
|
+
if (consulta.error) {
|
|
84
|
+
throw new Error(consulta.error)
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
console.log(consulta)
|
|
88
|
+
// {
|
|
89
|
+
// data: {
|
|
90
|
+
// tpAmb: '2',
|
|
91
|
+
// verAplic: '1.5.11',
|
|
92
|
+
// cStat: '138',
|
|
93
|
+
// xMotivo: 'Documento(s) localizado(s)',
|
|
94
|
+
// dhResp: '2022-06-21T10:48:14-03:00',
|
|
95
|
+
// ultNSU: '000000000000050',
|
|
96
|
+
// maxNSU: '000000000000212',
|
|
97
|
+
// docZip: [
|
|
98
|
+
// {
|
|
99
|
+
// xml: '<resNFe xmlns:xsd="http://www.w3.org/2001/XMLSchema" ... </resNFe>',
|
|
100
|
+
// json: { resNFe: { ... } },
|
|
101
|
+
// nsu: '000000000000049',
|
|
102
|
+
// schema: 'resNFe_v1.01.xsd',
|
|
103
|
+
// },
|
|
104
|
+
// {
|
|
105
|
+
// xml: '<nfeProc versao="4.00" xmlns="http://www.portalfiscal.inf.br/nfe"> ... </nfeProc>',
|
|
106
|
+
// json: { nfeProc: { ... } },
|
|
107
|
+
// nsu: '000000000000050',
|
|
108
|
+
// schema: 'procNFe_v4.00.xsd',
|
|
109
|
+
// },
|
|
110
|
+
// ],
|
|
111
|
+
// },
|
|
112
|
+
// reqXml: '<?xml version="1.0" encoding="utf-8"?> ... </soap12:Body></soap12:Envelope>',
|
|
113
|
+
// resXml: '<?xml version="1.0" encoding="utf-8"?> ... </soap:Body></soap:Envelope>',
|
|
114
|
+
// status: 200,
|
|
115
|
+
// }
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### Consulta por chNFe
|
|
119
|
+
|
|
120
|
+
| Campo | Tipo | Tamanho | Descrição |
|
|
121
|
+
| :------ | :------: | :-----: | :-------------------------- |
|
|
122
|
+
| `chNFe` | _string_ | 44 | Chave de acesso específica. |
|
|
123
|
+
|
|
124
|
+
#### Exemplo
|
|
125
|
+
|
|
126
|
+
```js
|
|
127
|
+
const { DistribuicaoDFe } = require('@bitize/bitmde')
|
|
128
|
+
const fs = require('fs')
|
|
129
|
+
|
|
130
|
+
const distribuicao = new DistribuicaoDFe({
|
|
131
|
+
pfx: fs.readFileSync('./certificado.pfx'),
|
|
132
|
+
passphrase: 'senha',
|
|
133
|
+
cnpj: '12345678901234',
|
|
134
|
+
cUFAutor: '41',
|
|
135
|
+
tpAmb: '2',
|
|
136
|
+
})
|
|
137
|
+
|
|
138
|
+
const consulta = await distribuicao.consultaChNFe(
|
|
139
|
+
'41000000000000000000000000000000000000000039'
|
|
140
|
+
)
|
|
141
|
+
|
|
142
|
+
if (consulta.error) {
|
|
143
|
+
throw new Error(consulta.error)
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
console.log(consulta)
|
|
147
|
+
// {
|
|
148
|
+
// data: {
|
|
149
|
+
// tpAmb: '2',
|
|
150
|
+
// verAplic: '1.5.11',
|
|
151
|
+
// cStat: '138',
|
|
152
|
+
// xMotivo: 'Documento localizado',
|
|
153
|
+
// dhResp: '2022-06-21T10:49:21-03:00',
|
|
154
|
+
// ultNSU: '',
|
|
155
|
+
// maxNSU: '',
|
|
156
|
+
// docZip: [
|
|
157
|
+
// {
|
|
158
|
+
// xml: '<nfeProc versao="4.00" xmlns="http://www.portalfiscal.inf.br/nfe"> ... </nfeProc>',
|
|
159
|
+
// json: { nfeProc: { ... } },
|
|
160
|
+
// nsu: '000000000000050',
|
|
161
|
+
// schema: 'procNFe_v4.00.xsd',
|
|
162
|
+
// },
|
|
163
|
+
// ],
|
|
164
|
+
// },
|
|
165
|
+
// reqXml: '<?xml version="1.0" encoding="utf-8"?> ... </soap12:Body></soap12:Envelope>',
|
|
166
|
+
// resXml: '<?xml version="1.0" encoding="utf-8"?> ... </soap:Body></soap:Envelope>',
|
|
167
|
+
// status: 200,
|
|
168
|
+
// }
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
### Consulta por NSU
|
|
172
|
+
|
|
173
|
+
| Campo | Tipo | Tamanho | Descrição |
|
|
174
|
+
| :---- | :------: | :-----: | :---------------------------------- |
|
|
175
|
+
| `NSU` | _string_ | 1-15 | Número Sequencial Único específico. |
|
|
176
|
+
|
|
177
|
+
#### Exemplo
|
|
178
|
+
|
|
179
|
+
```js
|
|
180
|
+
const { DistribuicaoDFe } = require('@bitize/bitmde')
|
|
181
|
+
const fs = require('fs')
|
|
182
|
+
|
|
183
|
+
const distribuicao = new DistribuicaoDFe({
|
|
184
|
+
pfx: fs.readFileSync('./certificado.pfx'),
|
|
185
|
+
passphrase: 'senha',
|
|
186
|
+
cnpj: '12345678901234',
|
|
187
|
+
cUFAutor: '41',
|
|
188
|
+
tpAmb: '2',
|
|
189
|
+
})
|
|
190
|
+
|
|
191
|
+
const consulta = await distribuicao.consultaNSU('000000000000049')
|
|
192
|
+
|
|
193
|
+
if (consulta.error) {
|
|
194
|
+
throw new Error(consulta.error)
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
console.log(consulta)
|
|
198
|
+
// {
|
|
199
|
+
// data: {
|
|
200
|
+
// tpAmb: '2',
|
|
201
|
+
// verAplic: '1.5.11',
|
|
202
|
+
// cStat: '138',
|
|
203
|
+
// xMotivo: 'Documento localizado',
|
|
204
|
+
// dhResp: '2022-06-21T10:50:46-03:00',
|
|
205
|
+
// ultNSU: '000000000000049',
|
|
206
|
+
// maxNSU: '000000000000212',
|
|
207
|
+
// docZip: [
|
|
208
|
+
// {
|
|
209
|
+
// xml: '<resNFe xmlns:xsd="http://www.w3.org/2001/XMLSchema" ... </resNFe>',
|
|
210
|
+
// json: { resNFe: { ... } },
|
|
211
|
+
// nsu: '000000000000049',
|
|
212
|
+
// schema: 'resNFe_v1.01.xsd',
|
|
213
|
+
// },
|
|
214
|
+
// ],
|
|
215
|
+
// },
|
|
216
|
+
// reqXml: '<?xml version="1.0" encoding="utf-8"?> ... </soap12:Body></soap12:Envelope>',
|
|
217
|
+
// resXml: '<?xml version="1.0" encoding="utf-8"?> ... </soap:Body></soap:Envelope>',
|
|
218
|
+
// status: 200,
|
|
219
|
+
// }
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
## Manifestação do Destinatário
|
|
223
|
+
|
|
224
|
+
### Construtor
|
|
225
|
+
|
|
226
|
+
```js
|
|
227
|
+
new RecepcaoEvento(config)
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
- `config` `<Object>`
|
|
231
|
+
- `pfx` `<Buffer>` - [OPCIONAL] - Arquivo **.pfx**. Se o `pfx` não for informado, as propriedades `cert` e `key` passam a ser obrigatórias.
|
|
232
|
+
- `passphrase` `<String>` - [OPCIONAL] - Senha do arquivo **.pfx**.
|
|
233
|
+
- `cert` `<Buffer | String>` - [OPCIONAL] - Conteúdo do _cert.pem_. Essa propriedade fica obrigatória se o `pfx` não for informado.
|
|
234
|
+
- `key` `<Buffer | String>` - [OPCIONAL] - Conteúdo do _key.pem_. Essa propriedade fica obrigatória se o `pfx` não for informado.
|
|
235
|
+
- `cnpj` `<String>` - [OPCIONAL] - CNPJ do interessado no DF-e. Se não informado um CNPJ, será obrigatório informar um CPF.
|
|
236
|
+
- `cpf` `<String>` - [OPCIONAL] - CPF do interessado no DF-e. Se não informado um CPF, será obrigatório informar um CNPJ.
|
|
237
|
+
- `tpAmb` `<String>` - [OBRIGATÓRIO] - Identificação de Ambiente. Informar `'1'` para **Produção** ou `'2'` para **Homologação**.
|
|
238
|
+
- `timezone` `<String>` - [OPCIONAL] - Fuso horário do autor. É utilizado `'America/Sao_Paulo'` como valor padrão. Consulte a tabela [lista de timezones](#lista-de-timezones) válidos para o Brasil.
|
|
239
|
+
- `options` `<Object>` - [OPCIONAL]
|
|
240
|
+
- `requestOptions` `<AxiosRequestConfig>` - [OPCIONAL]
|
|
241
|
+
- `httpsOptions` `<AgentOptions>` - [OPCIONAL]
|
|
242
|
+
|
|
243
|
+
### Enviar Lote de Eventos
|
|
244
|
+
|
|
245
|
+
| Campo | Tipo | Tamanho | Descrição |
|
|
246
|
+
| :------------------- | :------: | :-----: | :------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
247
|
+
| `idLote` | _string_ | 1-15 | Identificador de controle do Lote de envio do Evento. |
|
|
248
|
+
| `lote` | _array_ | 1-20 | Lista de eventos para manifestação. |
|
|
249
|
+
| `lote.chNFe` | _string_ | 44 | Chave de Acesso da NF-e vinculada ao Evento. |
|
|
250
|
+
| `lote.tpEvento` | _number_ | 6 | Código do evento: 210200 - Confirmacao da Operacao; 210210 - Ciencia da Operacao; 210220 - Desconhecimento da Operacao; 210240 - Operacao nao Realizada. |
|
|
251
|
+
| `lote.justificativa` | _string_ | 15-255 | Informar a justificativa do porque a operação não foi realizada, este campo deve ser informado somente no evento de Operação não Realizada. |
|
|
252
|
+
|
|
253
|
+
#### Exemplo
|
|
254
|
+
|
|
255
|
+
```js
|
|
256
|
+
const { RecepcaoEvento } = require('@bitize/bitmde')
|
|
257
|
+
const fs = require('fs')
|
|
258
|
+
|
|
259
|
+
const recepcao = new RecepcaoEvento({
|
|
260
|
+
pfx: fs.readFileSync('./certificado.pfx'),
|
|
261
|
+
passphrase: 'senha',
|
|
262
|
+
cnpj: '12345678901234',
|
|
263
|
+
tpAmb: '2',
|
|
264
|
+
})
|
|
265
|
+
|
|
266
|
+
const lote = [
|
|
267
|
+
{
|
|
268
|
+
chNFe: '41000000000000000000000000000000000000000040',
|
|
269
|
+
tipoEvento: 210210,
|
|
270
|
+
},
|
|
271
|
+
{
|
|
272
|
+
chNFe: '41000000000000000000000000000000000000000041',
|
|
273
|
+
tipoEvento: 210240,
|
|
274
|
+
justificativa: 'Não foi realizado a entrega correta dos itens da nota.',
|
|
275
|
+
},
|
|
276
|
+
]
|
|
277
|
+
|
|
278
|
+
const manifestacao = await recepcao.enviarEvento({
|
|
279
|
+
idLote: '1337',
|
|
280
|
+
lote: lote,
|
|
281
|
+
})
|
|
282
|
+
|
|
283
|
+
if (manifestacao.error) {
|
|
284
|
+
throw new Error(manifestacao.error)
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
console.log(manifestacao)
|
|
288
|
+
// {
|
|
289
|
+
// data: {
|
|
290
|
+
// idLote: '1337',
|
|
291
|
+
// tpAmb: '2',
|
|
292
|
+
// verAplic: 'AN_1.4.3',
|
|
293
|
+
// cOrgao: '91',
|
|
294
|
+
// cStat: '128',
|
|
295
|
+
// xMotivo: 'Lote de evento processado',
|
|
296
|
+
// infEvento: [
|
|
297
|
+
// {
|
|
298
|
+
// tpAmb: '2',
|
|
299
|
+
// verAplic: 'AN_1.4.3',
|
|
300
|
+
// cOrgao: '91',
|
|
301
|
+
// cStat: '596',
|
|
302
|
+
// xMotivo: 'Rejeicao: Evento apresentado apos o prazo permitido para o evento: [10 dias]',
|
|
303
|
+
// chNFe: '41000000000000000000000000000000000000000040',
|
|
304
|
+
// tpEvento: '210210',
|
|
305
|
+
// xEvento: 'Ciencia da Operacao',
|
|
306
|
+
// nSeqEvento: '1',
|
|
307
|
+
// CNPJDest: '',
|
|
308
|
+
// dhRegEvento: '2022-06-21T11:20:10-03:00',
|
|
309
|
+
// nProt: ''
|
|
310
|
+
// },
|
|
311
|
+
// {
|
|
312
|
+
// tpAmb: '2',
|
|
313
|
+
// verAplic: 'AN_1.4.3',
|
|
314
|
+
// cOrgao: '91',
|
|
315
|
+
// cStat: '135',
|
|
316
|
+
// xMotivo: 'Evento registrado e vinculado a NF-e',
|
|
317
|
+
// chNFe: '41000000000000000000000000000000000000000041',
|
|
318
|
+
// tpEvento: '210240',
|
|
319
|
+
// xEvento: 'Operacao nao Realizada',
|
|
320
|
+
// nSeqEvento: '1',
|
|
321
|
+
// CNPJDest: '12345678901234',
|
|
322
|
+
// dhRegEvento: '2022-06-21T11:20:10-03:00',
|
|
323
|
+
// nProt: '891220000003301'
|
|
324
|
+
// },
|
|
325
|
+
// ],
|
|
326
|
+
// },
|
|
327
|
+
// reqXml: '<?xml version="1.0" encoding="utf-8"?> ... </soap12:Body></soap12:Envelope>',
|
|
328
|
+
// resXml: '<?xml version="1.0" encoding="utf-8"?> ... </soap:Body></soap:Envelope>',
|
|
329
|
+
// status: 200,
|
|
330
|
+
// }
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
## Sobre o BitERP
|
|
334
|
+
|
|
335
|
+
O `@bitize/bitmde` é mantido pela equipe do **[BitERP](https://www.biterp.ai)**, um ERP online que automatiza a rotina fiscal, financeira e comercial de empresas brasileiras.
|
|
336
|
+
|
|
337
|
+
Dentro do BitERP, esta biblioteca é o componente responsável por:
|
|
338
|
+
|
|
339
|
+
- monitorar os documentos fiscais destinados ao CNPJ/CPF do cliente (Distribuição de DF-e);
|
|
340
|
+
- registrar a manifestação do destinatário (Ciência, Confirmação, Desconhecimento ou Operação não Realizada);
|
|
341
|
+
- baixar e armazenar o XML das NF-e de entrada.
|
|
342
|
+
|
|
343
|
+
Se você precisa disso pronto — sem manter certificado, agendamento de consulta por NSU e conciliação de notas de entrada na mão — conheça o BitERP em **[www.biterp.ai](https://www.biterp.ai)**.
|
|
344
|
+
|
|
345
|
+
## Tabelas
|
|
346
|
+
|
|
347
|
+
### Códigos UF
|
|
348
|
+
|
|
349
|
+
| UF | cUF | Estado |
|
|
350
|
+
| :--: | :--: | :---------------------- |
|
|
351
|
+
| `RO` | _11_ | **Rondônia** |
|
|
352
|
+
| `AC` | _12_ | **Acre** |
|
|
353
|
+
| `AM` | _13_ | **Amazonas** |
|
|
354
|
+
| `RR` | _14_ | **Roraima** |
|
|
355
|
+
| `PA` | _15_ | **Pará** |
|
|
356
|
+
| `AP` | _16_ | **Amapá** |
|
|
357
|
+
| `TO` | _17_ | **Tocantins** |
|
|
358
|
+
| `MA` | _21_ | **Maranhão** |
|
|
359
|
+
| `PI` | _22_ | **Piauí** |
|
|
360
|
+
| `CE` | _23_ | **Ceará** |
|
|
361
|
+
| `RN` | _24_ | **Rio Grande do Norte** |
|
|
362
|
+
| `PB` | _25_ | **Paraíba** |
|
|
363
|
+
| `PE` | _26_ | **Pernambuco** |
|
|
364
|
+
| `AL` | _27_ | **Alagoas** |
|
|
365
|
+
| `SE` | _28_ | **Sergipe** |
|
|
366
|
+
| `BA` | _29_ | **Bahia** |
|
|
367
|
+
| `MG` | _31_ | **Minas Gerais** |
|
|
368
|
+
| `ES` | _32_ | **Espírito Santo** |
|
|
369
|
+
| `RJ` | _33_ | **Rio de Janeiro** |
|
|
370
|
+
| `SP` | _35_ | **São Paulo** |
|
|
371
|
+
| `PR` | _41_ | **Paraná** |
|
|
372
|
+
| `SC` | _42_ | **Santa Catarina** |
|
|
373
|
+
| `RS` | _43_ | **Rio Grande do Sul** |
|
|
374
|
+
| `MS` | _50_ | **Mato Grosso do Sul** |
|
|
375
|
+
| `MT` | _51_ | **Mato Grosso** |
|
|
376
|
+
| `GO` | _52_ | **Goiás** |
|
|
377
|
+
| `DF` | _53_ | **Distrito Federal** |
|
|
378
|
+
|
|
379
|
+
### Lista de Timezones
|
|
380
|
+
|
|
381
|
+
| timezone | Estado | UTC |
|
|
382
|
+
| :--------------------: | :------------------------------------- | :------: |
|
|
383
|
+
| `America/Noronha` | **Fernando de Noronha** | _−02:00_ |
|
|
384
|
+
| `America/Araguaina` | **TO** | _−03:00_ |
|
|
385
|
+
| `America/Bahia` | **BA** | _−03:00_ |
|
|
386
|
+
| `America/Belem` | **AP, PA (leste)** | _−03:00_ |
|
|
387
|
+
| `America/Fortaleza` | **CE, MA, PB, PI, RN** | _−03:00_ |
|
|
388
|
+
| `America/Maceio` | **AL, SE** | _−03:00_ |
|
|
389
|
+
| `America/Recife` | **PE** | _−03:00_ |
|
|
390
|
+
| `America/Santarem` | **PA (oeste)** | _−03:00_ |
|
|
391
|
+
| `America/Sao_Paulo` | **DF, ES, GO, MG, PR, RJ, RS, SC, SP** | _−03:00_ |
|
|
392
|
+
| `America/Boa_Vista` | **RR** | _−04:00_ |
|
|
393
|
+
| `America/Campo_Grande` | **MS** | _−04:00_ |
|
|
394
|
+
| `America/Cuiaba` | **MT** | _−04:00_ |
|
|
395
|
+
| `America/Manaus` | **AM (leste)** | _−04:00_ |
|
|
396
|
+
| `America/Porto_Velho` | **RO** | _−04:00_ |
|
|
397
|
+
| `America/Eirunepe` | **AM (oeste)** | _−05:00_ |
|
|
398
|
+
| `America/Rio_Branco` | **AC** | _−05:00_ |
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
export = DistribuicaoDFe;
|
|
2
|
+
declare class DistribuicaoDFe {
|
|
3
|
+
/**
|
|
4
|
+
* @param {Object} config
|
|
5
|
+
* @param {Buffer} [config.pfx]
|
|
6
|
+
* @param {string} [config.passphrase]
|
|
7
|
+
* @param {Buffer | string} [config.cert]
|
|
8
|
+
* @param {Buffer | string} [config.key]
|
|
9
|
+
* @param {'11' | '12' | '13' | '14' | '15' | '16' | '17' | '21' | '22' | '23' | '24' | '25' | '26' | '27' | '28' | '29' | '31' | '32' | '33' | '35' | '41' | '42' | '43' | '50' | '51' | '52' | '53'} config.cUFAutor
|
|
10
|
+
* @param {string} [config.cnpj]
|
|
11
|
+
* @param {string} [config.cpf]
|
|
12
|
+
* @param {'1' | '2'} config.tpAmb
|
|
13
|
+
* @param {Object} [config.options]
|
|
14
|
+
* @param {import('axios').AxiosRequestConfig} [config.options.requestOptions]
|
|
15
|
+
* @param {import('https').AgentOptions} [config.options.httpsOptions]
|
|
16
|
+
*/
|
|
17
|
+
constructor(config: {
|
|
18
|
+
pfx?: Buffer;
|
|
19
|
+
passphrase?: string;
|
|
20
|
+
cert?: Buffer | string;
|
|
21
|
+
key?: Buffer | string;
|
|
22
|
+
cUFAutor: "11" | "12" | "13" | "14" | "15" | "16" | "17" | "21" | "22" | "23" | "24" | "25" | "26" | "27" | "28" | "29" | "31" | "32" | "33" | "35" | "41" | "42" | "43" | "50" | "51" | "52" | "53";
|
|
23
|
+
cnpj?: string;
|
|
24
|
+
cpf?: string;
|
|
25
|
+
tpAmb: "1" | "2";
|
|
26
|
+
options?: {
|
|
27
|
+
requestOptions?: import("axios").AxiosRequestConfig;
|
|
28
|
+
httpsOptions?: import("https").AgentOptions;
|
|
29
|
+
};
|
|
30
|
+
});
|
|
31
|
+
config: Readonly<{
|
|
32
|
+
cUFAutor: "11" | "12" | "13" | "14" | "15" | "16" | "17" | "21" | "22" | "23" | "24" | "25" | "26" | "27" | "28" | "29" | "31" | "32" | "33" | "35" | "41" | "42" | "43" | "50" | "51" | "52" | "53";
|
|
33
|
+
cnpj: string;
|
|
34
|
+
cpf: string;
|
|
35
|
+
tpAmb: "1" | "2";
|
|
36
|
+
cert: string;
|
|
37
|
+
key: string;
|
|
38
|
+
requestOptions: Readonly<import("axios").AxiosRequestConfig<any, any>>;
|
|
39
|
+
httpsOptions: Readonly<import("node:https").AgentOptions>;
|
|
40
|
+
}>;
|
|
41
|
+
/**
|
|
42
|
+
* @param {string} chNFe
|
|
43
|
+
*/
|
|
44
|
+
consultaChNFe(chNFe: string): Promise<{
|
|
45
|
+
data: {
|
|
46
|
+
tpAmb: string;
|
|
47
|
+
verAplic: string;
|
|
48
|
+
cStat: string;
|
|
49
|
+
xMotivo: string;
|
|
50
|
+
dhResp: string;
|
|
51
|
+
ultNSU: string;
|
|
52
|
+
maxNSU: string;
|
|
53
|
+
docZip: [{
|
|
54
|
+
xml: string;
|
|
55
|
+
json: any;
|
|
56
|
+
nsu: string;
|
|
57
|
+
schema: string;
|
|
58
|
+
}];
|
|
59
|
+
};
|
|
60
|
+
error: string;
|
|
61
|
+
reqXml: string;
|
|
62
|
+
resXml: string;
|
|
63
|
+
status: number;
|
|
64
|
+
}>;
|
|
65
|
+
/**
|
|
66
|
+
* @param {string} nsu
|
|
67
|
+
*/
|
|
68
|
+
consultaNSU(nsu: string): Promise<{
|
|
69
|
+
data: {
|
|
70
|
+
tpAmb: string;
|
|
71
|
+
verAplic: string;
|
|
72
|
+
cStat: string;
|
|
73
|
+
xMotivo: string;
|
|
74
|
+
dhResp: string;
|
|
75
|
+
ultNSU: string;
|
|
76
|
+
maxNSU: string;
|
|
77
|
+
docZip: [{
|
|
78
|
+
xml: string;
|
|
79
|
+
json: any;
|
|
80
|
+
nsu: string;
|
|
81
|
+
schema: string;
|
|
82
|
+
}];
|
|
83
|
+
};
|
|
84
|
+
error: string;
|
|
85
|
+
reqXml: string;
|
|
86
|
+
resXml: string;
|
|
87
|
+
status: number;
|
|
88
|
+
}>;
|
|
89
|
+
/**
|
|
90
|
+
* @param {string} ultNSU
|
|
91
|
+
*/
|
|
92
|
+
consultaUltNSU(ultNSU: string): Promise<{
|
|
93
|
+
data: {
|
|
94
|
+
tpAmb: string;
|
|
95
|
+
verAplic: string;
|
|
96
|
+
cStat: string;
|
|
97
|
+
xMotivo: string;
|
|
98
|
+
dhResp: string;
|
|
99
|
+
ultNSU: string;
|
|
100
|
+
maxNSU: string;
|
|
101
|
+
docZip: [{
|
|
102
|
+
xml: string;
|
|
103
|
+
json: any;
|
|
104
|
+
nsu: string;
|
|
105
|
+
schema: string;
|
|
106
|
+
}];
|
|
107
|
+
};
|
|
108
|
+
error: string;
|
|
109
|
+
reqXml: string;
|
|
110
|
+
resXml: string;
|
|
111
|
+
status: number;
|
|
112
|
+
}>;
|
|
113
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
export = RecepcaoEvento;
|
|
2
|
+
declare class RecepcaoEvento {
|
|
3
|
+
/**
|
|
4
|
+
* @param {Object} config
|
|
5
|
+
* @param {Buffer} [config.pfx]
|
|
6
|
+
* @param {string} [config.passphrase]
|
|
7
|
+
* @param {Buffer | string} [config.cert]
|
|
8
|
+
* @param {Buffer | string} [config.key]
|
|
9
|
+
* @param {string} [config.cnpj]
|
|
10
|
+
* @param {string} [config.cpf]
|
|
11
|
+
* @param {'1' | '2'} config.tpAmb
|
|
12
|
+
* @param {'America/Araguaina' | 'America/Bahia' | 'America/Belem' | 'America/Boa_Vista' | 'America/Campo_Grande' | 'America/Cuiaba' | 'America/Fortaleza' | 'America/Maceio' | 'America/Manaus' | 'America/Noronha' | 'America/Porto_Velho' | 'America/Recife' | 'America/Rio_Branco' | 'America/Sao_Paulo'} [config.timezone = 'America/Sao_Paulo']
|
|
13
|
+
* @param {Object} [config.options]
|
|
14
|
+
* @param {import('axios').AxiosRequestConfig} [config.options.requestOptions]
|
|
15
|
+
* @param {import('https').AgentOptions} [config.options.httpsOptions]
|
|
16
|
+
*/
|
|
17
|
+
constructor(config: {
|
|
18
|
+
pfx?: Buffer;
|
|
19
|
+
passphrase?: string;
|
|
20
|
+
cert?: Buffer | string;
|
|
21
|
+
key?: Buffer | string;
|
|
22
|
+
cnpj?: string;
|
|
23
|
+
cpf?: string;
|
|
24
|
+
tpAmb: "1" | "2";
|
|
25
|
+
timezone?: "America/Araguaina" | "America/Bahia" | "America/Belem" | "America/Boa_Vista" | "America/Campo_Grande" | "America/Cuiaba" | "America/Fortaleza" | "America/Maceio" | "America/Manaus" | "America/Noronha" | "America/Porto_Velho" | "America/Recife" | "America/Rio_Branco" | "America/Sao_Paulo";
|
|
26
|
+
options?: {
|
|
27
|
+
requestOptions?: import("axios").AxiosRequestConfig;
|
|
28
|
+
httpsOptions?: import("https").AgentOptions;
|
|
29
|
+
};
|
|
30
|
+
});
|
|
31
|
+
config: Readonly<{
|
|
32
|
+
cnpj: string;
|
|
33
|
+
cpf: string;
|
|
34
|
+
tpAmb: "1" | "2";
|
|
35
|
+
timezone: "America/Araguaina" | "America/Bahia" | "America/Belem" | "America/Boa_Vista" | "America/Campo_Grande" | "America/Cuiaba" | "America/Fortaleza" | "America/Maceio" | "America/Manaus" | "America/Noronha" | "America/Porto_Velho" | "America/Recife" | "America/Rio_Branco" | "America/Sao_Paulo";
|
|
36
|
+
cert: string;
|
|
37
|
+
key: string;
|
|
38
|
+
requestOptions: Readonly<import("axios").AxiosRequestConfig<any, any>>;
|
|
39
|
+
httpsOptions: Readonly<import("node:https").AgentOptions>;
|
|
40
|
+
}>;
|
|
41
|
+
/**
|
|
42
|
+
* @param {Object} options
|
|
43
|
+
* @param {string} [options.idLote = '1']
|
|
44
|
+
* @param {{chNFe: string, tipoEvento: 210200 | 210210 | 210220 | 210240, justificativa?: string}[]} options.lote
|
|
45
|
+
*/
|
|
46
|
+
enviarEvento(options: {
|
|
47
|
+
idLote?: string;
|
|
48
|
+
lote: {
|
|
49
|
+
chNFe: string;
|
|
50
|
+
tipoEvento: 210200 | 210210 | 210220 | 210240;
|
|
51
|
+
justificativa?: string;
|
|
52
|
+
}[];
|
|
53
|
+
}): Promise<{
|
|
54
|
+
data: {
|
|
55
|
+
idLote: string;
|
|
56
|
+
tpAmb: string;
|
|
57
|
+
verAplic: string;
|
|
58
|
+
cOrgao: string;
|
|
59
|
+
cStat: string;
|
|
60
|
+
xMotivo: string;
|
|
61
|
+
infEvento: [{
|
|
62
|
+
tpAmb: string;
|
|
63
|
+
verAplic: string;
|
|
64
|
+
cOrgao: string;
|
|
65
|
+
cStat: string;
|
|
66
|
+
xMotivo: string;
|
|
67
|
+
chNFe: string;
|
|
68
|
+
tpEvento: string;
|
|
69
|
+
xEvento: string;
|
|
70
|
+
nSeqEvento: string;
|
|
71
|
+
CNPJDest: string;
|
|
72
|
+
dhRegEvento: string;
|
|
73
|
+
nProt: string;
|
|
74
|
+
}];
|
|
75
|
+
};
|
|
76
|
+
error: string;
|
|
77
|
+
reqXml: string;
|
|
78
|
+
resXml: string;
|
|
79
|
+
status: number;
|
|
80
|
+
}>;
|
|
81
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
declare const _exports: typeof DistribuicaoController;
|
|
2
|
+
export = _exports;
|
|
3
|
+
declare class DistribuicaoController {
|
|
4
|
+
/**
|
|
5
|
+
*
|
|
6
|
+
* @param {Object} opts
|
|
7
|
+
* @returns {Promise<{data:{tpAmb: string,verAplic: string,cStat: string,xMotivo: string,dhResp: string,ultNSU: string,maxNSU: string, docZip:[{xml: string,json: Object,nsu: string,schema: string}]}, error: string, reqXml: string, resXml: string, status: number}>}
|
|
8
|
+
*/
|
|
9
|
+
static enviar(opts: any): Promise<{
|
|
10
|
+
data: {
|
|
11
|
+
tpAmb: string;
|
|
12
|
+
verAplic: string;
|
|
13
|
+
cStat: string;
|
|
14
|
+
xMotivo: string;
|
|
15
|
+
dhResp: string;
|
|
16
|
+
ultNSU: string;
|
|
17
|
+
maxNSU: string;
|
|
18
|
+
docZip: [{
|
|
19
|
+
xml: string;
|
|
20
|
+
json: any;
|
|
21
|
+
nsu: string;
|
|
22
|
+
schema: string;
|
|
23
|
+
}];
|
|
24
|
+
};
|
|
25
|
+
error: string;
|
|
26
|
+
reqXml: string;
|
|
27
|
+
resXml: string;
|
|
28
|
+
status: number;
|
|
29
|
+
}>;
|
|
30
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
export = controller;
|
|
2
|
+
declare const controller: Readonly<{
|
|
3
|
+
DistribuicaoController: {
|
|
4
|
+
new (): {};
|
|
5
|
+
enviar(opts: any): Promise<{
|
|
6
|
+
data: {
|
|
7
|
+
tpAmb: string;
|
|
8
|
+
verAplic: string;
|
|
9
|
+
cStat: string;
|
|
10
|
+
xMotivo: string;
|
|
11
|
+
dhResp: string;
|
|
12
|
+
ultNSU: string;
|
|
13
|
+
maxNSU: string;
|
|
14
|
+
docZip: [{
|
|
15
|
+
xml: string;
|
|
16
|
+
json: any;
|
|
17
|
+
nsu: string;
|
|
18
|
+
schema: string;
|
|
19
|
+
}];
|
|
20
|
+
};
|
|
21
|
+
error: string;
|
|
22
|
+
reqXml: string;
|
|
23
|
+
resXml: string;
|
|
24
|
+
status: number;
|
|
25
|
+
}>;
|
|
26
|
+
};
|
|
27
|
+
RecepcaoController: {
|
|
28
|
+
new (): {};
|
|
29
|
+
enviar(opts: any): Promise<{
|
|
30
|
+
data: {
|
|
31
|
+
idLote: string;
|
|
32
|
+
tpAmb: string;
|
|
33
|
+
verAplic: string;
|
|
34
|
+
cOrgao: string;
|
|
35
|
+
cStat: string;
|
|
36
|
+
xMotivo: string;
|
|
37
|
+
infEvento: [{
|
|
38
|
+
tpAmb: string;
|
|
39
|
+
verAplic: string;
|
|
40
|
+
cOrgao: string;
|
|
41
|
+
cStat: string;
|
|
42
|
+
xMotivo: string;
|
|
43
|
+
chNFe: string;
|
|
44
|
+
tpEvento: string;
|
|
45
|
+
xEvento: string;
|
|
46
|
+
nSeqEvento: string;
|
|
47
|
+
CNPJDest: string;
|
|
48
|
+
dhRegEvento: string;
|
|
49
|
+
nProt: string;
|
|
50
|
+
}];
|
|
51
|
+
};
|
|
52
|
+
error: string;
|
|
53
|
+
reqXml: string;
|
|
54
|
+
resXml: string;
|
|
55
|
+
status: number;
|
|
56
|
+
}>;
|
|
57
|
+
};
|
|
58
|
+
}>;
|