@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.
Files changed (82) hide show
  1. package/CHANGELOG.md +431 -0
  2. package/LICENSE +22 -0
  3. package/README.md +398 -0
  4. package/dist/apis/distribuicaoDFe-api.d.ts +113 -0
  5. package/dist/apis/recepcaoEvento-api.d.ts +81 -0
  6. package/dist/controllers/distribuicaoDFe-controller.d.ts +30 -0
  7. package/dist/controllers/index.d.ts +58 -0
  8. package/dist/controllers/recepcaoEvento-controller.d.ts +37 -0
  9. package/dist/env/ca.d.ts +6 -0
  10. package/dist/env/distribuicao.d.ts +8 -0
  11. package/dist/env/evento.d.ts +18 -0
  12. package/dist/env/index.d.ts +8 -0
  13. package/dist/env/recepcao.d.ts +8 -0
  14. package/dist/env/uf.d.ts +1 -0
  15. package/dist/env/version.d.ts +1 -0
  16. package/dist/env/zone.d.ts +1 -0
  17. package/dist/helpers/distribuicaoDFe-helper.d.ts +41 -0
  18. package/dist/helpers/index.d.ts +74 -0
  19. package/dist/helpers/recepcaoEvento-helper.d.ts +48 -0
  20. package/dist/helpers/retorno-helper.d.ts +27 -0
  21. package/dist/index.d.ts +11 -0
  22. package/dist/schemas/distribuicaoDFe-schema.d.ts +15 -0
  23. package/dist/schemas/index.d.ts +37 -0
  24. package/dist/schemas/recepcaoEvento-schema.d.ts +21 -0
  25. package/dist/services/sefaz-service.d.ts +12 -0
  26. package/dist/util/assinatura.d.ts +12 -0
  27. package/dist/util/certificado.d.ts +14 -0
  28. package/dist/util/data.d.ts +11 -0
  29. package/dist/util/gzip.d.ts +10 -0
  30. package/dist/util/index.d.ts +32 -0
  31. package/dist/util/xml.d.ts +22 -0
  32. package/dist/util/zeroPad.d.ts +10 -0
  33. package/dist/validators/ambiente-validator.d.ts +19 -0
  34. package/dist/validators/certificado-validator.d.ts +29 -0
  35. package/dist/validators/chave-validator.d.ts +14 -0
  36. package/dist/validators/cnpjCpf-validator.d.ts +23 -0
  37. package/dist/validators/evento-validator.d.ts +30 -0
  38. package/dist/validators/index.d.ts +146 -0
  39. package/dist/validators/lote-validator.d.ts +35 -0
  40. package/dist/validators/nsu-validator.d.ts +14 -0
  41. package/dist/validators/uf-validator.d.ts +19 -0
  42. package/dist/validators/zone-validator.d.ts +19 -0
  43. package/lib/apis/distribuicaoDFe-api.js +64 -0
  44. package/lib/apis/recepcaoEvento-api.js +65 -0
  45. package/lib/controllers/distribuicaoDFe-controller.js +17 -0
  46. package/lib/controllers/index.js +6 -0
  47. package/lib/controllers/recepcaoEvento-controller.js +17 -0
  48. package/lib/env/ca.js +5 -0
  49. package/lib/env/distribuicao.js +8 -0
  50. package/lib/env/evento.js +22 -0
  51. package/lib/env/index.js +11 -0
  52. package/lib/env/recepcao.js +8 -0
  53. package/lib/env/uf.js +5 -0
  54. package/lib/env/version.js +3 -0
  55. package/lib/env/zone.js +5 -0
  56. package/lib/helpers/distribuicaoDFe-helper.js +58 -0
  57. package/lib/helpers/index.js +7 -0
  58. package/lib/helpers/recepcaoEvento-helper.js +64 -0
  59. package/lib/helpers/retorno-helper.js +18 -0
  60. package/lib/index.js +12 -0
  61. package/lib/schemas/distribuicaoDFe-schema.js +25 -0
  62. package/lib/schemas/index.js +6 -0
  63. package/lib/schemas/recepcaoEvento-schema.js +30 -0
  64. package/lib/services/sefaz-service.js +63 -0
  65. package/lib/util/assinatura.js +25 -0
  66. package/lib/util/certificado.js +21 -0
  67. package/lib/util/data.js +9 -0
  68. package/lib/util/gzip.js +16 -0
  69. package/lib/util/index.js +10 -0
  70. package/lib/util/xml.js +28 -0
  71. package/lib/util/zeroPad.js +7 -0
  72. package/lib/validators/ambiente-validator.js +19 -0
  73. package/lib/validators/certificado-validator.js +32 -0
  74. package/lib/validators/chave-validator.js +16 -0
  75. package/lib/validators/cnpjCpf-validator.js +23 -0
  76. package/lib/validators/evento-validator.js +39 -0
  77. package/lib/validators/index.js +13 -0
  78. package/lib/validators/lote-validator.js +26 -0
  79. package/lib/validators/nsu-validator.js +19 -0
  80. package/lib/validators/uf-validator.js +21 -0
  81. package/lib/validators/zone-validator.js +24 -0
  82. package/package.json +82 -0
@@ -0,0 +1,146 @@
1
+ export = validator;
2
+ declare const validator: Readonly<{
3
+ AmbienteValidator: {
4
+ new (config: {
5
+ tpAmb: "1" | "2";
6
+ }): {
7
+ tpAmb: "1" | "2";
8
+ error: string;
9
+ isValid(): boolean;
10
+ getValues(): {
11
+ tpAmb: "1" | "2";
12
+ };
13
+ getError(): string;
14
+ };
15
+ };
16
+ CertificadoValidator: {
17
+ new (config: {
18
+ pfx?: Buffer;
19
+ passphrase?: string;
20
+ cert?: Buffer | string;
21
+ key?: Buffer | string;
22
+ }): {
23
+ pfx: Buffer<ArrayBufferLike>;
24
+ passphrase: string;
25
+ cert: string | Buffer<ArrayBufferLike>;
26
+ key: string | Buffer<ArrayBufferLike>;
27
+ error: string;
28
+ isValid(): boolean;
29
+ getValues(): {
30
+ cert: string;
31
+ key: string;
32
+ };
33
+ getError(): string;
34
+ };
35
+ };
36
+ ChaveValidator: {
37
+ new (chave: string): {
38
+ chave: string;
39
+ error: string;
40
+ isValid(): boolean;
41
+ getValues(): string;
42
+ getError(): string;
43
+ };
44
+ };
45
+ CnpjCpfValidator: {
46
+ new (config: {
47
+ cnpj?: string;
48
+ cpf?: string;
49
+ }): {
50
+ cnpj: string;
51
+ cpf: string;
52
+ error: string;
53
+ isValid(): boolean;
54
+ getValues(): {
55
+ cnpj: string;
56
+ cpf: string;
57
+ };
58
+ getError(): string;
59
+ };
60
+ };
61
+ EventoValidator: {
62
+ new (evento: {
63
+ chNFe: string;
64
+ tipoEvento: 210200 | 210210 | 210220 | 210240;
65
+ justificativa?: string;
66
+ }): {
67
+ chNFe: string;
68
+ tipoEvento: 210200 | 210210 | 210220 | 210240;
69
+ justificativa: string;
70
+ error: string;
71
+ isValid(): boolean;
72
+ tpEvento: number;
73
+ descEvento: string;
74
+ getValues(): {
75
+ chNFe: string;
76
+ justificativa: string;
77
+ tpEvento: number;
78
+ descEvento: string;
79
+ };
80
+ getError(): string;
81
+ };
82
+ };
83
+ LoteValidator: {
84
+ new (config: {
85
+ idLote?: string;
86
+ lote: {
87
+ chNFe: string;
88
+ tipoEvento: 210200 | 210210 | 210220 | 210240;
89
+ justificativa?: string;
90
+ }[];
91
+ }): {
92
+ idLote: string;
93
+ lote: {
94
+ chNFe: string;
95
+ tipoEvento: 210200 | 210210 | 210220 | 210240;
96
+ justificativa?: string;
97
+ }[];
98
+ error: string;
99
+ isValid(): boolean;
100
+ getValues(): {
101
+ idLote: string;
102
+ lote: {
103
+ chNFe: string;
104
+ tipoEvento: 210200 | 210210 | 210220 | 210240;
105
+ justificativa?: string;
106
+ }[];
107
+ };
108
+ getError(): string;
109
+ };
110
+ };
111
+ NsuValidator: {
112
+ new (nsu: string): {
113
+ nsu: string;
114
+ error: string;
115
+ isValid(): boolean;
116
+ getValues(): string;
117
+ getError(): string;
118
+ };
119
+ };
120
+ UfValidator: {
121
+ new (config: {
122
+ 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";
123
+ }): {
124
+ 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";
125
+ error: string;
126
+ isValid(): boolean;
127
+ getValues(): {
128
+ 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";
129
+ };
130
+ getError(): string;
131
+ };
132
+ };
133
+ ZoneValidator: {
134
+ new (config: {
135
+ 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";
136
+ }): {
137
+ 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";
138
+ error: string;
139
+ isValid(): boolean;
140
+ getValues(): {
141
+ 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";
142
+ };
143
+ getError(): string;
144
+ };
145
+ };
146
+ }>;
@@ -0,0 +1,35 @@
1
+ declare const _exports: typeof LoteValidator;
2
+ export = _exports;
3
+ declare class LoteValidator {
4
+ /**
5
+ *
6
+ * @param {Object} config
7
+ * @param {string} [config.idLote]
8
+ * @param {{chNFe: string, tipoEvento: 210200 | 210210 | 210220 | 210240, justificativa?: string}[]} config.lote
9
+ */
10
+ constructor(config: {
11
+ idLote?: string;
12
+ lote: {
13
+ chNFe: string;
14
+ tipoEvento: 210200 | 210210 | 210220 | 210240;
15
+ justificativa?: string;
16
+ }[];
17
+ });
18
+ idLote: string;
19
+ lote: {
20
+ chNFe: string;
21
+ tipoEvento: 210200 | 210210 | 210220 | 210240;
22
+ justificativa?: string;
23
+ }[];
24
+ error: string;
25
+ isValid(): boolean;
26
+ getValues(): {
27
+ idLote: string;
28
+ lote: {
29
+ chNFe: string;
30
+ tipoEvento: 210200 | 210210 | 210220 | 210240;
31
+ justificativa?: string;
32
+ }[];
33
+ };
34
+ getError(): string;
35
+ }
@@ -0,0 +1,14 @@
1
+ declare const _exports: typeof NsuValidator;
2
+ export = _exports;
3
+ declare class NsuValidator {
4
+ /**
5
+ *
6
+ * @param {string} nsu
7
+ */
8
+ constructor(nsu: string);
9
+ nsu: string;
10
+ error: string;
11
+ isValid(): boolean;
12
+ getValues(): string;
13
+ getError(): string;
14
+ }
@@ -0,0 +1,19 @@
1
+ declare const _exports: typeof UfValidator;
2
+ export = _exports;
3
+ declare class UfValidator {
4
+ /**
5
+ *
6
+ * @param {Object} config
7
+ * @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
8
+ */
9
+ constructor(config: {
10
+ 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";
11
+ });
12
+ 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";
13
+ error: string;
14
+ isValid(): boolean;
15
+ getValues(): {
16
+ 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";
17
+ };
18
+ getError(): string;
19
+ }
@@ -0,0 +1,19 @@
1
+ declare const _exports: typeof ZoneValidator;
2
+ export = _exports;
3
+ declare class ZoneValidator {
4
+ /**
5
+ *
6
+ * @param {Object} config
7
+ * @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']
8
+ */
9
+ constructor(config: {
10
+ 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";
11
+ });
12
+ 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";
13
+ error: string;
14
+ isValid(): boolean;
15
+ getValues(): {
16
+ 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";
17
+ };
18
+ getError(): string;
19
+ }
@@ -0,0 +1,64 @@
1
+ let DistribuicaoController = require("../controllers").DistribuicaoController, {
2
+ AmbienteValidator,
3
+ CertificadoValidator,
4
+ ChaveValidator,
5
+ CnpjCpfValidator,
6
+ NsuValidator,
7
+ UfValidator
8
+ } = require("../validators");
9
+
10
+ class DistribuicaoDFe {
11
+ constructor(r) {
12
+ var {
13
+ requestOptions: e = {},
14
+ httpsOptions: t = {}
15
+ } = r.options || {}, i = new CertificadoValidator(r), o = new AmbienteValidator(r), a = new CnpjCpfValidator(r), r = new UfValidator(r);
16
+ if (!i.isValid()) throw new Error(i.getError());
17
+ if (!o.isValid()) throw new Error(o.getError());
18
+ if (!a.isValid()) throw new Error(a.getError());
19
+ if (!r.isValid()) throw new Error(r.getError());
20
+ var {
21
+ cert: i,
22
+ key: l
23
+ } = i.getValues(), o = o.getValues().tpAmb, {
24
+ cnpj: a,
25
+ cpf: s
26
+ } = a.getValues(), r = r.getValues().cUFAutor;
27
+ this.config = Object.freeze({
28
+ cUFAutor: r,
29
+ cnpj: a,
30
+ cpf: s,
31
+ tpAmb: o,
32
+ cert: i,
33
+ key: l,
34
+ requestOptions: Object.freeze(e),
35
+ httpsOptions: Object.freeze(t)
36
+ }), Object.freeze(this);
37
+ }
38
+ consultaChNFe(r) {
39
+ var e, r = new ChaveValidator(r);
40
+ if (r.isValid()) return e = r.getValues(), e = {
41
+ ...this.config,
42
+ chNFe: e
43
+ }, DistribuicaoController.enviar(e);
44
+ throw new Error(r.getError());
45
+ }
46
+ consultaNSU(r) {
47
+ var e, r = new NsuValidator(r);
48
+ if (r.isValid()) return e = r.getValues(), e = {
49
+ ...this.config,
50
+ nsu: e
51
+ }, DistribuicaoController.enviar(e);
52
+ throw new Error(r.getError());
53
+ }
54
+ consultaUltNSU(r) {
55
+ var e, r = new NsuValidator(r);
56
+ if (r.isValid()) return e = r.getValues(), e = {
57
+ ...this.config,
58
+ ultNSU: e
59
+ }, DistribuicaoController.enviar(e);
60
+ throw new Error(r.getError());
61
+ }
62
+ }
63
+
64
+ module.exports = DistribuicaoDFe;
@@ -0,0 +1,65 @@
1
+ let RecepcaoController = require("../controllers").RecepcaoController, Data = require("../util").Data, {
2
+ AmbienteValidator,
3
+ CertificadoValidator,
4
+ CnpjCpfValidator,
5
+ EventoValidator,
6
+ LoteValidator,
7
+ ZoneValidator
8
+ } = require("../validators");
9
+
10
+ class RecepcaoEvento {
11
+ constructor(e) {
12
+ var {
13
+ requestOptions: t = {},
14
+ httpsOptions: r = {}
15
+ } = e.options || {}, o = new CertificadoValidator(e), a = new AmbienteValidator(e), i = new CnpjCpfValidator(e), e = new ZoneValidator(e);
16
+ if (!o.isValid()) throw new Error(o.getError());
17
+ if (!a.isValid()) throw new Error(a.getError());
18
+ if (!i.isValid()) throw new Error(i.getError());
19
+ if (!e.isValid()) throw new Error(e.getError());
20
+ var {
21
+ cert: o,
22
+ key: n
23
+ } = o.getValues(), a = a.getValues().tpAmb, {
24
+ cnpj: i,
25
+ cpf: l
26
+ } = i.getValues(), e = e.getValues().timezone;
27
+ this.config = Object.freeze({
28
+ cnpj: i,
29
+ cpf: l,
30
+ tpAmb: a,
31
+ timezone: e,
32
+ cert: o,
33
+ key: n,
34
+ requestOptions: Object.freeze(t),
35
+ httpsOptions: Object.freeze(r)
36
+ }), Object.freeze(this);
37
+ }
38
+ enviarEvento(e) {
39
+ let n = {
40
+ ...this.config
41
+ };
42
+ e = new LoteValidator(e);
43
+ if (!e.isValid()) throw new Error(e.getError());
44
+ let {
45
+ idLote: l,
46
+ lote: t
47
+ } = e.getValues();
48
+ e = t.map(e => {
49
+ var t, r, o, a, i = {}, e = new EventoValidator(e);
50
+ if (e.isValid()) return {
51
+ chNFe: t,
52
+ justificativa: r,
53
+ tpEvento: o,
54
+ descEvento: a
55
+ } = e.getValues(), r && (i.xJust = r), i.idLote = l, i.nSeqEvento = "1",
56
+ i.cOrgao = "91", i.tpAmb = n.tpAmb, i.cnpj = n.cnpj, i.cpf = n.cpf,
57
+ i.tpEvento = o, i.descEvento = a, i.chNFe = t, i.infEventoId = `ID${o}${t}01`,
58
+ i.dhEvento = Data.toFormat(new Date(), n.timezone), i;
59
+ throw new Error(e.getError());
60
+ });
61
+ return n.idLote = l, n.eventos = e, RecepcaoController.enviar(n);
62
+ }
63
+ }
64
+
65
+ module.exports = RecepcaoEvento;
@@ -0,0 +1,17 @@
1
+ let {
2
+ DistribuicaoHelper,
3
+ RetornoHelper
4
+ } = require("../helpers");
5
+
6
+ class DistribuicaoController {
7
+ static async enviar(e) {
8
+ var r = DistribuicaoHelper.montarRequest(e), e = await DistribuicaoHelper.enviarConsulta(r, e), t = await DistribuicaoHelper.montarResponse(e.data);
9
+ return RetornoHelper.montarRetorno({
10
+ json: t,
11
+ data: r,
12
+ retornoSefaz: e
13
+ });
14
+ }
15
+ }
16
+
17
+ module.exports = Object.freeze(DistribuicaoController);
@@ -0,0 +1,6 @@
1
+ let DistribuicaoController = require("./distribuicaoDFe-controller"), RecepcaoController = require("./recepcaoEvento-controller"), controller = Object.freeze({
2
+ DistribuicaoController: DistribuicaoController,
3
+ RecepcaoController: RecepcaoController
4
+ });
5
+
6
+ module.exports = controller;
@@ -0,0 +1,17 @@
1
+ let {
2
+ RecepcaoHelper,
3
+ RetornoHelper
4
+ } = require("../helpers");
5
+
6
+ class RecepcaoController {
7
+ static async enviar(e) {
8
+ var r = RecepcaoHelper.montarRequest(e), e = await RecepcaoHelper.enviarEvento(r, e), o = RecepcaoHelper.montarResponse(e.data);
9
+ return RetornoHelper.montarRetorno({
10
+ json: o,
11
+ data: r,
12
+ retornoSefaz: e
13
+ });
14
+ }
15
+ }
16
+
17
+ module.exports = Object.freeze(RecepcaoController);
package/lib/env/ca.js ADDED
@@ -0,0 +1,5 @@
1
+ let CA = [ "-----BEGIN CERTIFICATE-----\r\nMIIHAjCCBOqgAwIBAgIJAJVIeKgiEmNTMA0GCSqGSIb3DQEBDQUAMIGYMQswCQYD\r\nVQQGEwJCUjETMBEGA1UECgwKSUNQLUJyYXNpbDE9MDsGA1UECww0SW5zdGl0dXRv\r\nIE5hY2lvbmFsIGRlIFRlY25vbG9naWEgZGEgSW5mb3JtYWNhbyAtIElUSTE1MDMG\r\nA1UEAwwsQXV0b3JpZGFkZSBDZXJ0aWZpY2Fkb3JhIFJhaXogQnJhc2lsZWlyYSB2\r\nMTAwHhcNMjAwMzEyMTkzMTQyWhcNMzIwNzAxMTIwMDU5WjCBjDELMAkGA1UEBhMC\r\nQlIxEzARBgNVBAoMCklDUC1CcmFzaWwxNTAzBgNVBAsMLEF1dG9yaWRhZGUgQ2Vy\r\ndGlmaWNhZG9yYSBSYWl6IEJyYXNpbGVpcmEgdjEwMTEwLwYDVQQDDChBdXRvcmlk\r\nYWRlIENlcnRpZmljYWRvcmEgZG8gU0VSUFJPIFNTTHYxMIICIjANBgkqhkiG9w0B\r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Yk2xC7+Izef8fSc3XdJDuPSbcDpWukzyCDtSEH\r\nisLiGEtIbYRiPsF3czlQPsnIEVoTTCWxHCH1zYR6zScSv18Qh69qVe2J40K5jZoP\r\nGEOhq/oKhVJQAdvAFW5Odp7mF3Tk9nivjjsctJSxY26LFiV5GRV+07SSse4ti0aO\r\njO5PLg5SWjfcOtBG2rz02EIvQAmLcb0kGBtfdj0lW/w=\r\n-----END CERTIFICATE-----\r\n" ];
2
+
3
+ module.exports = {
4
+ CA: CA
5
+ };
@@ -0,0 +1,8 @@
1
+ let DISTRIBUICAO = {
2
+ 1: "https://www1.nfe.fazenda.gov.br/NFeDistribuicaoDFe/NFeDistribuicaoDFe.asmx?wsdl",
3
+ 2: "https://hom1.nfe.fazenda.gov.br/NFeDistribuicaoDFe/NFeDistribuicaoDFe.asmx?wsdl"
4
+ };
5
+
6
+ module.exports = {
7
+ DISTRIBUICAO: DISTRIBUICAO
8
+ };
@@ -0,0 +1,22 @@
1
+ let EVENTOS = {
2
+ 210200: {
3
+ tpEvento: 210200,
4
+ descEvento: "Confirmacao da Operacao"
5
+ },
6
+ 210210: {
7
+ tpEvento: 210210,
8
+ descEvento: "Ciencia da Operacao"
9
+ },
10
+ 210220: {
11
+ tpEvento: 210220,
12
+ descEvento: "Desconhecimento da Operacao"
13
+ },
14
+ 210240: {
15
+ tpEvento: 210240,
16
+ descEvento: "Operacao nao Realizada"
17
+ }
18
+ };
19
+
20
+ module.exports = {
21
+ EVENTOS: EVENTOS
22
+ };
@@ -0,0 +1,11 @@
1
+ let CA = require("./ca").CA, DISTRIBUICAO = require("./distribuicao").DISTRIBUICAO, EVENTOS = require("./evento").EVENTOS, RECEPCAO = require("./recepcao").RECEPCAO, CODIGOS_UF = require("./uf").CODIGOS_UF, VERSION = require("./version").VERSION, ZONES = require("./zone").ZONES;
2
+
3
+ module.exports = {
4
+ CA: CA,
5
+ CODIGOS_UF: CODIGOS_UF,
6
+ DISTRIBUICAO: DISTRIBUICAO,
7
+ EVENTOS: EVENTOS,
8
+ RECEPCAO: RECEPCAO,
9
+ VERSION: VERSION,
10
+ ZONES: ZONES
11
+ };
@@ -0,0 +1,8 @@
1
+ let RECEPCAO = {
2
+ 1: "https://www1.nfe.fazenda.gov.br/NFeRecepcaoEvento4/NFeRecepcaoEvento4.asmx?wsdl",
3
+ 2: "https://hom1.nfe.fazenda.gov.br/NFeRecepcaoEvento4/NFeRecepcaoEvento4.asmx?wsdl"
4
+ };
5
+
6
+ module.exports = {
7
+ RECEPCAO: RECEPCAO
8
+ };
package/lib/env/uf.js ADDED
@@ -0,0 +1,5 @@
1
+ let CODIGOS_UF = [ "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" ];
2
+
3
+ module.exports = {
4
+ CODIGOS_UF: CODIGOS_UF
5
+ };
@@ -0,0 +1,3 @@
1
+ module.exports = {
2
+ VERSION: "0.17.0"
3
+ };
@@ -0,0 +1,5 @@
1
+ let ZONES = [ "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" ];
2
+
3
+ module.exports = {
4
+ ZONES: ZONES
5
+ };
@@ -0,0 +1,58 @@
1
+ let {
2
+ CA,
3
+ DISTRIBUICAO
4
+ } = require("../env"), DistribuicaoSchema = require("../schemas").DistribuicaoSchema, SefazService = require("../services/sefaz-service"), {
5
+ Gzip,
6
+ Xml
7
+ } = require("../util");
8
+
9
+ class DistribuicaoHelper {
10
+ static async enviarConsulta(e, t) {
11
+ var r = DISTRIBUICAO[t.tpAmb], e = {
12
+ method: "POST",
13
+ data: e
14
+ };
15
+ return await new SefazService({
16
+ baseURL: r,
17
+ ca: CA,
18
+ cert: t.cert,
19
+ key: t.key,
20
+ tpAmb: t.tpAmb,
21
+ requestOptions: t.requestOptions,
22
+ httpsOptions: t.httpsOptions
23
+ }).request(e);
24
+ }
25
+ static montarRequest(e) {
26
+ e = DistribuicaoSchema.montarSchema(e), e = Xml.jsonToXml(e);
27
+ return Xml.envelopar(e);
28
+ }
29
+ static async montarResponse(e) {
30
+ var t = {}, e = Xml.xmlToJson(e), {
31
+ "soap:Envelope": {
32
+ "soap:Body": {
33
+ nfeDistDFeInteresseResponse: {
34
+ nfeDistDFeInteresseResult: {
35
+ retDistDFeInt: e = {}
36
+ } = {}
37
+ } = {}
38
+ } = {}
39
+ } = {}
40
+ } = (e.error && (t.error = e.error), e), {
41
+ loteDistDFeInt: r = {}
42
+ } = e, r = (r.docZip ? Array.isArray(r.docZip) || (r.docZip = [ r.docZip ]) : r.docZip = [],
43
+ await Promise.all(r.docZip.map(async e => {
44
+ var t = await Gzip.unzip(e.value);
45
+ return {
46
+ xml: t,
47
+ json: Xml.xmlToJson(t),
48
+ nsu: e["@_NSU"],
49
+ schema: e["@_schema"]
50
+ };
51
+ })));
52
+ return t.tpAmb = e.tpAmb || "", t.verAplic = e.verAplic || "", t.cStat = e.cStat || "",
53
+ t.xMotivo = e.xMotivo || "", t.dhResp = e.dhResp || "", t.ultNSU = e.ultNSU || "",
54
+ t.maxNSU = e.maxNSU || "", t.docZip = r, t;
55
+ }
56
+ }
57
+
58
+ module.exports = Object.freeze(DistribuicaoHelper);
@@ -0,0 +1,7 @@
1
+ let DistribuicaoHelper = require("./distribuicaoDFe-helper"), RecepcaoHelper = require("./recepcaoEvento-helper"), RetornoHelper = require("./retorno-helper"), helper = Object.freeze({
2
+ DistribuicaoHelper: DistribuicaoHelper,
3
+ RecepcaoHelper: RecepcaoHelper,
4
+ RetornoHelper: RetornoHelper
5
+ });
6
+
7
+ module.exports = helper;
@@ -0,0 +1,64 @@
1
+ let {
2
+ CA,
3
+ RECEPCAO
4
+ } = require("../env"), RecepcaoSchema = require("../schemas").RecepcaoSchema, SefazService = require("../services/sefaz-service"), {
5
+ Assinatura,
6
+ Xml
7
+ } = require("../util");
8
+
9
+ class RecepcaoHelper {
10
+ static async enviarEvento(e, t) {
11
+ var o = RECEPCAO[t.tpAmb], e = {
12
+ method: "POST",
13
+ data: e
14
+ };
15
+ return await new SefazService({
16
+ baseURL: o,
17
+ ca: CA,
18
+ cert: t.cert,
19
+ key: t.key,
20
+ tpAmb: t.tpAmb,
21
+ requestOptions: t.requestOptions,
22
+ httpsOptions: t.httpsOptions
23
+ }).request(e);
24
+ }
25
+ static montarRequest(t) {
26
+ var e = t.eventos.map(e => {
27
+ e = RecepcaoSchema.montarSchema(e), e = Xml.jsonToXml(e);
28
+ return Assinatura.assinarXml(t.cert, t.key, e);
29
+ }), e = `<nfeDadosMsg xmlns="http://www.portalfiscal.inf.br/nfe/wsdl/NFeRecepcaoEvento4"><envEvento xmlns="http://www.portalfiscal.inf.br/nfe" versao="1.00"><idLote>${t.idLote}</idLote>${e.reduce((e, t) => e += t.substring(t.indexOf('<evento versao="1.00">'), t.indexOf("</envEvento>")), "")}</envEvento></nfeDadosMsg>`;
30
+ return Xml.envelopar(e);
31
+ }
32
+ static montarResponse(e) {
33
+ var t = {}, e = Xml.xmlToJson(e), {
34
+ "soap:Envelope": {
35
+ "soap:Body": {
36
+ nfeRecepcaoEventoNFResult: {
37
+ retEnvEvento: e = {}
38
+ } = {}
39
+ } = {}
40
+ } = {}
41
+ } = (e.error && (t.error = e.error), e);
42
+ return e.retEvento ? Array.isArray(e.retEvento) || (e.retEvento = [ e.retEvento ]) : e.retEvento = [],
43
+ t.idLote = e.idLote || "", t.tpAmb = e.tpAmb || "", t.verAplic = e.verAplic || "",
44
+ t.cOrgao = e.cOrgao || "", t.cStat = e.cStat || "", t.xMotivo = e.xMotivo || "",
45
+ t.infEvento = e.retEvento.map(({
46
+ infEvento: e
47
+ }) => ({
48
+ tpAmb: e.tpAmb || "",
49
+ verAplic: e.verAplic || "",
50
+ cOrgao: e.cOrgao || "",
51
+ cStat: e.cStat || "",
52
+ xMotivo: e.xMotivo || "",
53
+ chNFe: e.chNFe || "",
54
+ tpEvento: e.tpEvento || "",
55
+ xEvento: e.xEvento || "",
56
+ nSeqEvento: e.nSeqEvento || "",
57
+ CNPJDest: e.CNPJDest || "",
58
+ dhRegEvento: e.dhRegEvento || "",
59
+ nProt: e.nProt || ""
60
+ })), t;
61
+ }
62
+ }
63
+
64
+ module.exports = Object.freeze(RecepcaoHelper);
@@ -0,0 +1,18 @@
1
+ class RetornoHelper {
2
+ static montarRetorno(r) {
3
+ var {
4
+ json: r,
5
+ data: e,
6
+ retornoSefaz: t
7
+ } = r, e = {
8
+ data: r,
9
+ reqXml: e,
10
+ resXml: t.data,
11
+ status: t.status
12
+ };
13
+ return r.error && (e.data = {}, e.error = r.error), 2 < Math.floor(t.status / 100) && !r.error && (e.data = {},
14
+ e.error = t.data), e;
15
+ }
16
+ }
17
+
18
+ module.exports = Object.freeze(RetornoHelper);