nfewizard-io 0.3.28 → 0.4.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.
Files changed (32) hide show
  1. package/README.md +88 -54
  2. package/dist/cjs/adapters/XmlBuilder.d.ts +2 -2
  3. package/dist/cjs/core/exceptions/ErrorContext.d.ts +39 -0
  4. package/dist/cjs/core/exceptions/JsonArrayTransporter.d.ts +21 -0
  5. package/dist/cjs/core/exceptions/logger.d.ts +22 -2
  6. package/dist/cjs/core/types/NFeWizard.d.ts +1 -0
  7. package/dist/cjs/debug.d.ts +1 -0
  8. package/dist/cjs/index.cjs +4 -4
  9. package/dist/cjs/index.cjs.map +1 -1
  10. package/dist/cjs/modules/dfe/base/BaseNFe.d.ts +3 -1
  11. package/dist/cjs/modules/dfe/base/GerarConsulta.d.ts +1 -0
  12. package/dist/cjs/modules/dfe/nfce/services/NFCEAutorizacao/NFCEAutorizacaoService.d.ts +2 -0
  13. package/dist/cjs/modules/dfe/nfe/services/NFEAutorizacao/NFEAutorizacaoService.d.ts +2 -0
  14. package/dist/cjs/modules/dfe/nfe/services/NFEDistribuicaoDFe/NFEDistribuicaoDFeService.d.ts +3 -1
  15. package/dist/cjs/modules/dfe/nfe/services/NFERecepcaoEvento/NFERecepcaoEventoService.d.ts +3 -1
  16. package/dist/cjs/modules/environment/Environment.d.ts +1 -0
  17. package/dist/esm/adapters/XmlBuilder.d.ts +2 -2
  18. package/dist/esm/core/exceptions/ErrorContext.d.ts +39 -0
  19. package/dist/esm/core/exceptions/JsonArrayTransporter.d.ts +21 -0
  20. package/dist/esm/core/exceptions/logger.d.ts +22 -2
  21. package/dist/esm/core/types/NFeWizard.d.ts +1 -0
  22. package/dist/esm/debug.d.ts +1 -0
  23. package/dist/esm/index.js +4 -4
  24. package/dist/esm/index.js.map +1 -1
  25. package/dist/esm/modules/dfe/base/BaseNFe.d.ts +3 -1
  26. package/dist/esm/modules/dfe/base/GerarConsulta.d.ts +1 -0
  27. package/dist/esm/modules/dfe/nfce/services/NFCEAutorizacao/NFCEAutorizacaoService.d.ts +2 -0
  28. package/dist/esm/modules/dfe/nfe/services/NFEAutorizacao/NFEAutorizacaoService.d.ts +2 -0
  29. package/dist/esm/modules/dfe/nfe/services/NFEDistribuicaoDFe/NFEDistribuicaoDFeService.d.ts +3 -1
  30. package/dist/esm/modules/dfe/nfe/services/NFERecepcaoEvento/NFERecepcaoEventoService.d.ts +3 -1
  31. package/dist/esm/modules/environment/Environment.d.ts +1 -0
  32. package/package.json +3 -2
package/README.md CHANGED
@@ -80,62 +80,69 @@ const nfeWizard = new NFeWizard();
80
80
 
81
81
  // Inicializar
82
82
  await nfeWizard.NFE_LoadEnvironment({
83
- config: {
84
- dfe: {
85
- baixarXMLDistribuicao: true,
86
- pathXMLDistribuicao: "tmp/DistribuicaoDFe",
87
- armazenarXMLAutorizacao: true,
88
- pathXMLAutorizacao: "tmp/Autorizacao",
89
- armazenarXMLRetorno: true,
90
- pathXMLRetorno: "tmp/RequestLogs",
91
- armazenarXMLConsulta: true,
92
- pathXMLConsulta: "tmp/RequestLogs",
93
- armazenarXMLConsultaComTagSoap: false,
94
- armazenarRetornoEmJSON: true,
95
- pathRetornoEmJSON: "tmp/DistribuicaoDFe",
96
-
97
- pathCertificado: "certificado.pfx",
98
- senhaCertificado: "123456",
99
- UF: "SP",
100
- CPFCNPJ: "99999999999999",
101
- },
102
- nfe: {
103
- ambiente: 2,
104
- versaoDF: "4.00",
105
- },
106
- email: {
107
- host: 'smtp.example.com',
108
- port: 587,
109
- secure: false,
110
- auth: {
111
- user: 'seu-email@example.com',
112
- pass: 'sua-senha'
83
+ config: {
84
+ dfe: {
85
+ baixarXMLDistribuicao: true,
86
+ pathXMLDistribuicao: "tmp/DistribuicaoDFe",
87
+ armazenarXMLAutorizacao: true,
88
+ pathXMLAutorizacao: "tmp/Autorizacao",
89
+ armazenarXMLRetorno: true,
90
+ pathXMLRetorno: "tmp/RequestLogs",
91
+ armazenarXMLConsulta: true,
92
+ pathXMLConsulta: "tmp/RequestLogs",
93
+ armazenarXMLConsultaComTagSoap: false,
94
+ armazenarRetornoEmJSON: false,
95
+ pathRetornoEmJSON: "tmp/DistribuicaoDFe",
96
+
97
+ pathCertificado: "certificado.pfx",
98
+ senhaCertificado: "1234",
99
+ UF: "SP",
100
+ CPFCNPJ: "99999999999999",
113
101
  },
114
- emailParams: {
115
- from: '"Seu Nome" <seu-email@example.com>',
116
- to: 'destinatario@example.com',
117
- }
118
- },
119
- lib: {
120
- connection: {
121
- timeout: 30000,
102
+ nfe: {
103
+ ambiente: 2,
104
+ versaoDF: "4.00",
105
+ idCSC: 1,
106
+ tokenCSC: '99999999-9999-9999-9999-999999999999'
107
+ },
108
+ email: {
109
+ host: 'mail.provider.com.br',
110
+ port: 465,
111
+ secure: true,
112
+ auth: {
113
+ user: 'nfe.example@email.com.br',
114
+ pass: '123456'
115
+ },
116
+ emailParams: {
117
+ from: 'Company <noreply.company@email.com>',
118
+ to: 'customer.name@email.com.br',
119
+ }
122
120
  },
123
- useOpenSSL: false,
124
- useForSchemaValidation: 'validateSchemaJsBased',
121
+ lib: {
122
+ connection: {
123
+ timeout: 30000,
124
+ },
125
+ log: {
126
+ exibirLogNoConsole: true,
127
+ armazenarLogs: true,
128
+ pathLogs: 'tmp/Logs'
129
+ },
130
+ useOpenSSL: false,
131
+ useForSchemaValidation: 'validateSchemaJsBased',
132
+ }
125
133
  }
134
+ });
135
+
136
+ // Exemplo de Utilização
137
+ const chaveNFe: DFePorChaveNFe = {
138
+ cUFAutor: 35,
139
+ CNPJ: '99999999999999',
140
+ consChNFe: {
141
+ chNFe: '00000000000000000000000000000000000000000000'
142
+ },
126
143
  }
127
- });
128
-
129
- // Exemplo de Utilização
130
- const chaveNFe: DFePorChaveNFe = {
131
- cUFAutor: 35,
132
- CNPJ: '99999999999999',
133
- consChNFe: {
134
- chNFe: '00000000000000000000000000000000000000000000'
135
- },
136
- }
137
144
 
138
- await nfeWizard.NFE_DistribuicaoDFePorChave(chaveNFe);
145
+ await nfeWizard.NFE_DistribuicaoDFePorChave(chaveNFe);
139
146
  ```
140
147
 
141
148
  ## Documentação
@@ -162,14 +169,40 @@ await nfeWizard.NFE_DistribuicaoDFePorChave(chaveNFe);
162
169
  {
163
170
  "type": "node",
164
171
  "request": "launch",
165
- "name": "Launch Program",
172
+ "name": "Debug NFe Wizard",
166
173
  "skipFiles": [
167
174
  "<node_internals>/**"
168
175
  ],
169
- "program": "${workspaceFolder}/src/index.ts",
176
+ "program": "${workspaceFolder}/src/testes.ts",
177
+ "runtimeExecutable": "${workspaceFolder}/node_modules/.bin/tsx",
178
+ "runtimeArgs": [],
179
+ "console": "integratedTerminal",
180
+ "env": {
181
+ "NODE_ENV": "development"
182
+ },
183
+ "sourceMaps": true,
184
+ "restart": true,
185
+ "protocol": "inspector",
170
186
  "outFiles": [
171
187
  "${workspaceFolder}/**/*.js"
188
+ ]
189
+ },
190
+ {
191
+ "type": "node",
192
+ "request": "launch",
193
+ "name": "Debug com ts-node",
194
+ "skipFiles": [
195
+ "<node_internals>/**"
196
+ ],
197
+ "program": "${workspaceFolder}/src/testes.ts",
198
+ "runtimeArgs": [
199
+ "--loader", "ts-node/esm"
172
200
  ],
201
+ "console": "integratedTerminal",
202
+ "env": {
203
+ "NODE_ENV": "development",
204
+ "NODE_OPTIONS": "--loader ts-node/esm"
205
+ },
173
206
  "sourceMaps": true
174
207
  }
175
208
  ]
@@ -256,6 +289,7 @@ Agradecemos aos seguintes desenvolvedores por suas contribuições ao projeto:
256
289
  <td align="center"><a href="https://github.com/dliocode"><img src="https://github.com/dliocode.png" width="50px;" style="border-radius:50%" alt=""/><br /><sub><b>dliocode</b></sub></a></td>
257
290
  <td align="center"><a href="https://github.com/ThalesAugusto0"><img src="https://github.com/ThalesAugusto0.png" width="50px;" style="border-radius:50%" alt=""/><br /><sub><b>ThalesAugusto0</b></sub></a></td>
258
291
  <td align="center"><a href="https://github.com/cassioseffrin"><img src="https://github.com/cassioseffrin.png" width="50px;" style="border-radius:50%" alt=""/><br /><sub><b>cassioseffrin</b></sub></a></td>
292
+ <td align="center"><a href="https://www.linkedin.com/company/infinitedev/?originalSubdomain=br"><img src="https://media.licdn.com/dms/image/v2/C4D0BAQHwL-vRW4A0zw/company-logo_200_200/company-logo_200_200/0/1677157135085/infinitedev_logo?e=1756339200&v=beta&t=QH9t_R-s9-g-RDh-BM1eiu3eaO_d-F60Hk0xy6dy0M4" width="50px;" style="border-radius:50%" alt=""/><br /><sub><b>InfiniteDev</b></sub></a></td>
259
293
  </tr>
260
294
  </table>
261
295
 
@@ -268,7 +302,7 @@ Agradecemos imensamente aos nossos patrocinadores pela sua generosidade.
268
302
  <table>
269
303
  <tr>
270
304
  <td align="center"><a href="https://github.com/italosll"><img src="https://github.com/italosll.png" width="50px;" style="border-radius:50%" alt=""/><br /><sub><b>italosll</b></sub></a></td>
271
- <!-- Adicione mais contribuidores conforme necessário -->
305
+ <td align="center"><a href="https://www.linkedin.com/company/infinitedev/?originalSubdomain=br"><img src="https://media.licdn.com/dms/image/v2/C4D0BAQHwL-vRW4A0zw/company-logo_200_200/company-logo_200_200/0/1677157135085/infinitedev_logo?e=1756339200&v=beta&t=QH9t_R-s9-g-RDh-BM1eiu3eaO_d-F60Hk0xy6dy0M4" width="50px;" style="border-radius:50%" alt=""/><br /><sub><b>InfiniteDev</b></sub></a></td>
272
306
  </tr>
273
307
  </table>
274
308
 
@@ -18,11 +18,11 @@ declare class XmlBuilder {
18
18
  /**
19
19
  * Método que converte Objeto em XML
20
20
  */
21
- serializeXml<T>(obj: T, rootTag: string): string;
21
+ serializeXml<T>(obj: T, rootTag: string, metodo?: string): string;
22
22
  /**
23
23
  * Método genérico para geração do XML
24
24
  */
25
- gerarXml<T>(xmlObject: T, rootTag: string): string;
25
+ gerarXml<T>(xmlObject: T, rootTag: string, metodo?: string): string;
26
26
  /**
27
27
  * Método utilizado para cirar um envelop SOAP - Formato de mensagem para serviço SOAP (como o da SEFAZ)
28
28
  */
@@ -0,0 +1,39 @@
1
+ export interface ErrorContext {
2
+ context: string;
3
+ method?: string;
4
+ webServiceUrl?: string;
5
+ xmlConsultaSize?: number;
6
+ responseStatus?: number;
7
+ responseData?: string;
8
+ httpStatus?: number;
9
+ httpStatusText?: string;
10
+ timeout?: number;
11
+ [key: string]: any;
12
+ }
13
+ export declare class NFeError extends Error {
14
+ readonly context: ErrorContext;
15
+ readonly originalError: Error;
16
+ readonly timestamp: Date;
17
+ constructor(message: string, originalError: Error, context: ErrorContext);
18
+ /**
19
+ * Método estático para criar erro a partir de exception do axios
20
+ */
21
+ static fromAxiosError(error: any, context: ErrorContext): NFeError;
22
+ /**
23
+ * Método estático para criar erro de conversão XML
24
+ */
25
+ static fromXmlError(error: Error, xmlData: string, method: string): NFeError;
26
+ /**
27
+ * Método estático para criar erro de rejeição SEFAZ
28
+ */
29
+ static fromSefazRejection(motivo: string, responseData: any, method: string): NFeError;
30
+ /**
31
+ * Log do erro com todas as informações contextuais
32
+ */
33
+ logError(): void;
34
+ /**
35
+ * Determina se deve ser logado como warning (ex: rejeições SEFAZ esperadas)
36
+ */
37
+ private shouldLogAsWarning;
38
+ private static detectXmlType;
39
+ }
@@ -0,0 +1,21 @@
1
+ import Transport from 'winston-transport';
2
+ import winston from 'winston';
3
+ export declare class JsonArrayTransport extends Transport {
4
+ private filename;
5
+ private dirname;
6
+ private maxsize;
7
+ private maxFiles;
8
+ private logFormat;
9
+ constructor(options: {
10
+ filename: string;
11
+ dirname?: string;
12
+ maxsize?: number;
13
+ maxFiles?: number;
14
+ level?: string;
15
+ format?: winston.Logform.Format;
16
+ });
17
+ private get fullPath();
18
+ log(info: any, callback: () => void): void;
19
+ private writeToFile;
20
+ private rotateFile;
21
+ }
@@ -1,2 +1,22 @@
1
- import winston from 'winston';
2
- export declare const logger: winston.Logger;
1
+ export interface LoggerConfig {
2
+ exibirLogNoConsole: boolean;
3
+ armazenarLogs: boolean;
4
+ pathLogs?: string;
5
+ }
6
+ declare class AppLogger {
7
+ private static instance;
8
+ private logger;
9
+ private isInitialized;
10
+ private constructor();
11
+ static getInstance(): AppLogger;
12
+ private filterOnly;
13
+ private filterExcluding;
14
+ initialize(config: LoggerConfig): void;
15
+ info(message: string, meta?: any): void;
16
+ warn(message: string, meta?: any): void;
17
+ error(message: string, error?: Error | any, meta?: any): void;
18
+ debug(message: string, meta?: any): void;
19
+ http(message: string, meta?: any): void;
20
+ }
21
+ export declare const logger: AppLogger;
22
+ export {};
@@ -158,6 +158,7 @@ export type NFeWizardProps = {
158
158
  log?: {
159
159
  exibirLogNoConsole?: boolean;
160
160
  armazenarLogs?: boolean;
161
+ pathLogs?: string;
161
162
  };
162
163
  /**
163
164
  * @param {boolean} useOpenSSL - Define se a lib deve utilizar métodos que fazem uso do OpenSSL ou não
@@ -0,0 +1 @@
1
+ export {};