@bitize/bitmde 0.17.0 → 0.18.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 +24 -0
- package/LICENSE +22 -22
- package/README.md +415 -398
- package/dist/apis/distribuicaoDFe-api.d.ts +15 -0
- package/dist/controllers/distribuicaoDFe-controller.d.ts +6 -1
- package/dist/controllers/index.d.ts +5 -0
- package/dist/helpers/distribuicaoDFe-helper.d.ts +23 -1
- package/dist/helpers/index.d.ts +15 -0
- package/lib/env/version.js +1 -1
- package/lib/helpers/distribuicaoDFe-helper.js +52 -22
- package/lib/util/gzip.js +3 -3
- package/package.json +83 -82
|
@@ -56,6 +56,11 @@ declare class DistribuicaoDFe {
|
|
|
56
56
|
nsu: string;
|
|
57
57
|
schema: string;
|
|
58
58
|
}];
|
|
59
|
+
docZipErrors: [{
|
|
60
|
+
nsu: string;
|
|
61
|
+
schema: string;
|
|
62
|
+
error: string;
|
|
63
|
+
}];
|
|
59
64
|
};
|
|
60
65
|
error: string;
|
|
61
66
|
reqXml: string;
|
|
@@ -80,6 +85,11 @@ declare class DistribuicaoDFe {
|
|
|
80
85
|
nsu: string;
|
|
81
86
|
schema: string;
|
|
82
87
|
}];
|
|
88
|
+
docZipErrors: [{
|
|
89
|
+
nsu: string;
|
|
90
|
+
schema: string;
|
|
91
|
+
error: string;
|
|
92
|
+
}];
|
|
83
93
|
};
|
|
84
94
|
error: string;
|
|
85
95
|
reqXml: string;
|
|
@@ -104,6 +114,11 @@ declare class DistribuicaoDFe {
|
|
|
104
114
|
nsu: string;
|
|
105
115
|
schema: string;
|
|
106
116
|
}];
|
|
117
|
+
docZipErrors: [{
|
|
118
|
+
nsu: string;
|
|
119
|
+
schema: string;
|
|
120
|
+
error: string;
|
|
121
|
+
}];
|
|
107
122
|
};
|
|
108
123
|
error: string;
|
|
109
124
|
reqXml: string;
|
|
@@ -4,7 +4,7 @@ declare class DistribuicaoController {
|
|
|
4
4
|
/**
|
|
5
5
|
*
|
|
6
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}>}
|
|
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}], docZipErrors:[{nsu: string,schema: string,error: string}]}, error: string, reqXml: string, resXml: string, status: number}>}
|
|
8
8
|
*/
|
|
9
9
|
static enviar(opts: any): Promise<{
|
|
10
10
|
data: {
|
|
@@ -21,6 +21,11 @@ declare class DistribuicaoController {
|
|
|
21
21
|
nsu: string;
|
|
22
22
|
schema: string;
|
|
23
23
|
}];
|
|
24
|
+
docZipErrors: [{
|
|
25
|
+
nsu: string;
|
|
26
|
+
schema: string;
|
|
27
|
+
error: string;
|
|
28
|
+
}];
|
|
24
29
|
};
|
|
25
30
|
error: string;
|
|
26
31
|
reqXml: string;
|
|
@@ -20,7 +20,7 @@ declare class DistribuicaoHelper {
|
|
|
20
20
|
/**
|
|
21
21
|
*
|
|
22
22
|
* @param {string} data
|
|
23
|
-
* @returns {Promise<{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}>}
|
|
23
|
+
* @returns {Promise<{tpAmb: string,verAplic: string,cStat: string,xMotivo: string,dhResp: string,ultNSU: string,maxNSU: string, docZip:[{xml: string,json: Object,nsu: string,schema: string}], docZipErrors:[{nsu: string,schema: string,error: string}], error: string}>}
|
|
24
24
|
*/
|
|
25
25
|
static montarResponse(data: string): Promise<{
|
|
26
26
|
tpAmb: string;
|
|
@@ -36,6 +36,28 @@ declare class DistribuicaoHelper {
|
|
|
36
36
|
nsu: string;
|
|
37
37
|
schema: string;
|
|
38
38
|
}];
|
|
39
|
+
docZipErrors: [{
|
|
40
|
+
nsu: string;
|
|
41
|
+
schema: string;
|
|
42
|
+
error: string;
|
|
43
|
+
}];
|
|
44
|
+
error: string;
|
|
45
|
+
}>;
|
|
46
|
+
/**
|
|
47
|
+
* Descompacta e interpreta um docZip sem nunca rejeitar: a falha vira
|
|
48
|
+
* um item com `error`, para não derrubar o restante do lote.
|
|
49
|
+
*
|
|
50
|
+
* @param {Object} doc
|
|
51
|
+
* @returns {Promise<{xml: string,json: Object,nsu: string,schema: string} | {nsu: string,schema: string,error: string}>}
|
|
52
|
+
*/
|
|
53
|
+
static abrirDocZip(doc: any): Promise<{
|
|
54
|
+
xml: string;
|
|
55
|
+
json: any;
|
|
56
|
+
nsu: string;
|
|
57
|
+
schema: string;
|
|
58
|
+
} | {
|
|
59
|
+
nsu: string;
|
|
60
|
+
schema: string;
|
|
39
61
|
error: string;
|
|
40
62
|
}>;
|
|
41
63
|
}
|
package/dist/helpers/index.d.ts
CHANGED
|
@@ -21,6 +21,21 @@ declare const helper: Readonly<{
|
|
|
21
21
|
nsu: string;
|
|
22
22
|
schema: string;
|
|
23
23
|
}];
|
|
24
|
+
docZipErrors: [{
|
|
25
|
+
nsu: string;
|
|
26
|
+
schema: string;
|
|
27
|
+
error: string;
|
|
28
|
+
}];
|
|
29
|
+
error: string;
|
|
30
|
+
}>;
|
|
31
|
+
abrirDocZip(doc: any): Promise<{
|
|
32
|
+
xml: string;
|
|
33
|
+
json: any;
|
|
34
|
+
nsu: string;
|
|
35
|
+
schema: string;
|
|
36
|
+
} | {
|
|
37
|
+
nsu: string;
|
|
38
|
+
schema: string;
|
|
24
39
|
error: string;
|
|
25
40
|
}>;
|
|
26
41
|
};
|
package/lib/env/version.js
CHANGED
|
@@ -7,19 +7,19 @@ let {
|
|
|
7
7
|
} = require("../util");
|
|
8
8
|
|
|
9
9
|
class DistribuicaoHelper {
|
|
10
|
-
static async enviarConsulta(e,
|
|
11
|
-
var
|
|
10
|
+
static async enviarConsulta(e, r) {
|
|
11
|
+
var t = DISTRIBUICAO[r.tpAmb], e = {
|
|
12
12
|
method: "POST",
|
|
13
13
|
data: e
|
|
14
14
|
};
|
|
15
15
|
return await new SefazService({
|
|
16
|
-
baseURL:
|
|
16
|
+
baseURL: t,
|
|
17
17
|
ca: CA,
|
|
18
|
-
cert:
|
|
19
|
-
key:
|
|
20
|
-
tpAmb:
|
|
21
|
-
requestOptions:
|
|
22
|
-
httpsOptions:
|
|
18
|
+
cert: r.cert,
|
|
19
|
+
key: r.key,
|
|
20
|
+
tpAmb: r.tpAmb,
|
|
21
|
+
requestOptions: r.requestOptions,
|
|
22
|
+
httpsOptions: r.httpsOptions
|
|
23
23
|
}).request(e);
|
|
24
24
|
}
|
|
25
25
|
static montarRequest(e) {
|
|
@@ -27,7 +27,7 @@ class DistribuicaoHelper {
|
|
|
27
27
|
return Xml.envelopar(e);
|
|
28
28
|
}
|
|
29
29
|
static async montarResponse(e) {
|
|
30
|
-
var
|
|
30
|
+
var r = {}, e = Xml.xmlToJson(e), {
|
|
31
31
|
"soap:Envelope": {
|
|
32
32
|
"soap:Body": {
|
|
33
33
|
nfeDistDFeInteresseResponse: {
|
|
@@ -37,21 +37,51 @@ class DistribuicaoHelper {
|
|
|
37
37
|
} = {}
|
|
38
38
|
} = {}
|
|
39
39
|
} = {}
|
|
40
|
-
} = (e.error && (
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
40
|
+
} = (e.error && (r.error = e.error), e);
|
|
41
|
+
let {
|
|
42
|
+
loteDistDFeInt: t = {}
|
|
43
|
+
} = e;
|
|
44
|
+
"" === t ? t = {} : "object" == typeof t && !Array.isArray(t) || (r.error = "loteDistDFeInt inválido.",
|
|
45
|
+
t = {}), t.docZip ? Array.isArray(t.docZip) || (t.docZip = [ t.docZip ]) : t.docZip = [];
|
|
46
|
+
var a, s = [], i = [];
|
|
47
|
+
for (a of await Promise.all(t.docZip.map(e => DistribuicaoHelper.abrirDocZip(e)))) (a.error ? i : s).push(a);
|
|
48
|
+
return r.tpAmb = e.tpAmb || "", r.verAplic = e.verAplic || "", r.cStat = e.cStat || "",
|
|
49
|
+
r.xMotivo = e.xMotivo || "", r.dhResp = e.dhResp || "", r.ultNSU = e.ultNSU || "",
|
|
50
|
+
r.maxNSU = e.maxNSU || "", r.docZip = s, r.docZipErrors = i, r;
|
|
51
|
+
}
|
|
52
|
+
static async abrirDocZip(e) {
|
|
53
|
+
var r = e["@_NSU"] || "", t = e["@_schema"] || "";
|
|
54
|
+
if (!e.value) return {
|
|
55
|
+
nsu: r,
|
|
56
|
+
schema: t,
|
|
57
|
+
error: "docZip sem conteúdo."
|
|
58
|
+
};
|
|
59
|
+
let a;
|
|
60
|
+
try {
|
|
61
|
+
a = await Gzip.unzip(e.value);
|
|
62
|
+
} catch (e) {
|
|
45
63
|
return {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
schema: e["@_schema"]
|
|
64
|
+
nsu: r,
|
|
65
|
+
schema: t,
|
|
66
|
+
error: "Falha ao descompactar o docZip: " + e.message
|
|
50
67
|
};
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
68
|
+
}
|
|
69
|
+
let s;
|
|
70
|
+
try {
|
|
71
|
+
s = Xml.xmlToJson(a);
|
|
72
|
+
} catch (e) {
|
|
73
|
+
return {
|
|
74
|
+
nsu: r,
|
|
75
|
+
schema: t,
|
|
76
|
+
error: "Falha ao interpretar o XML do docZip: " + e.message
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
return {
|
|
80
|
+
xml: a,
|
|
81
|
+
json: s,
|
|
82
|
+
nsu: r,
|
|
83
|
+
schema: t
|
|
84
|
+
};
|
|
55
85
|
}
|
|
56
86
|
}
|
|
57
87
|
|
package/lib/util/gzip.js
CHANGED
|
@@ -3,11 +3,11 @@ let zlib = require("zlib");
|
|
|
3
3
|
class Gzip {
|
|
4
4
|
static unzip(e) {
|
|
5
5
|
let i = Buffer.from(e, "base64");
|
|
6
|
-
return new Promise((
|
|
6
|
+
return new Promise((r, t) => {
|
|
7
7
|
zlib.unzip(i, function(e, i) {
|
|
8
|
-
e
|
|
8
|
+
if (e) return t(e);
|
|
9
9
|
e = i.toString("utf8");
|
|
10
|
-
|
|
10
|
+
r(e);
|
|
11
11
|
});
|
|
12
12
|
});
|
|
13
13
|
}
|
package/package.json
CHANGED
|
@@ -1,82 +1,83 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@bitize/bitmde",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Biblioteca para consultar notas destinadas e enviar evento de manifestação do destinatário",
|
|
5
|
-
"main": "./lib/index.js",
|
|
6
|
-
"types": "./dist/index.d.ts",
|
|
7
|
-
"exports": {
|
|
8
|
-
".": {
|
|
9
|
-
"types": "./dist/index.d.ts",
|
|
10
|
-
"require": "./lib/index.js",
|
|
11
|
-
"default": "./lib/index.js"
|
|
12
|
-
},
|
|
13
|
-
"./package.json": "./package.json"
|
|
14
|
-
},
|
|
15
|
-
"files": [
|
|
16
|
-
"lib/",
|
|
17
|
-
"dist/",
|
|
18
|
-
"CHANGELOG.md"
|
|
19
|
-
],
|
|
20
|
-
"scripts": {
|
|
21
|
-
"build": "npm run script && npm run types",
|
|
22
|
-
"script": "node ./scripts/index.js",
|
|
23
|
-
"release": "git pull && npm run build && npm publish",
|
|
24
|
-
"test": "mocha",
|
|
25
|
-
"test:ci": "mocha --ignore test/sefaz.test.js",
|
|
26
|
-
"format": "prettier --write .",
|
|
27
|
-
"format:check": "prettier --check .",
|
|
28
|
-
"certs:teste": "sh ./scripts/gerar-certificado-teste.sh",
|
|
29
|
-
"types": "npx tsc"
|
|
30
|
-
},
|
|
31
|
-
"repository": {
|
|
32
|
-
"type": "git",
|
|
33
|
-
"url": "git+https://github.com/bitize/bitmde.git"
|
|
34
|
-
},
|
|
35
|
-
"publishConfig": {
|
|
36
|
-
"access": "public"
|
|
37
|
-
},
|
|
38
|
-
"keywords": [
|
|
39
|
-
"nfe",
|
|
40
|
-
"sefaz",
|
|
41
|
-
"nota",
|
|
42
|
-
"fiscal",
|
|
43
|
-
"evento",
|
|
44
|
-
"manifestacao",
|
|
45
|
-
"destinatario",
|
|
46
|
-
"distribuicao",
|
|
47
|
-
"dfe",
|
|
48
|
-
"mde",
|
|
49
|
-
"soap",
|
|
50
|
-
"manifestacaonfe",
|
|
51
|
-
"distribuicaodfe"
|
|
52
|
-
],
|
|
53
|
-
"author": "Bitize",
|
|
54
|
-
"contributors": [
|
|
55
|
-
"Lucas Melo <lucashpmelo94@gmail.com> (autor original do node-mde)"
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
"
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
"
|
|
63
|
-
|
|
64
|
-
"
|
|
65
|
-
"
|
|
66
|
-
"
|
|
67
|
-
"
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
"@types/
|
|
72
|
-
"@types/node
|
|
73
|
-
"
|
|
74
|
-
"
|
|
75
|
-
"
|
|
76
|
-
"
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
"
|
|
81
|
-
|
|
82
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@bitize/bitmde",
|
|
3
|
+
"version": "0.18.0",
|
|
4
|
+
"description": "Biblioteca para consultar notas destinadas e enviar evento de manifestação do destinatário",
|
|
5
|
+
"main": "./lib/index.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"require": "./lib/index.js",
|
|
11
|
+
"default": "./lib/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./package.json": "./package.json"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"lib/",
|
|
17
|
+
"dist/",
|
|
18
|
+
"CHANGELOG.md"
|
|
19
|
+
],
|
|
20
|
+
"scripts": {
|
|
21
|
+
"build": "npm run script && npm run types",
|
|
22
|
+
"script": "node ./scripts/index.js",
|
|
23
|
+
"release": "git pull && npm run build && npm publish",
|
|
24
|
+
"test": "mocha",
|
|
25
|
+
"test:ci": "mocha --ignore test/sefaz.test.js",
|
|
26
|
+
"format": "prettier --write .",
|
|
27
|
+
"format:check": "prettier --check .",
|
|
28
|
+
"certs:teste": "sh ./scripts/gerar-certificado-teste.sh",
|
|
29
|
+
"types": "npx tsc"
|
|
30
|
+
},
|
|
31
|
+
"repository": {
|
|
32
|
+
"type": "git",
|
|
33
|
+
"url": "git+https://github.com/bitize/bitmde.git"
|
|
34
|
+
},
|
|
35
|
+
"publishConfig": {
|
|
36
|
+
"access": "public"
|
|
37
|
+
},
|
|
38
|
+
"keywords": [
|
|
39
|
+
"nfe",
|
|
40
|
+
"sefaz",
|
|
41
|
+
"nota",
|
|
42
|
+
"fiscal",
|
|
43
|
+
"evento",
|
|
44
|
+
"manifestacao",
|
|
45
|
+
"destinatario",
|
|
46
|
+
"distribuicao",
|
|
47
|
+
"dfe",
|
|
48
|
+
"mde",
|
|
49
|
+
"soap",
|
|
50
|
+
"manifestacaonfe",
|
|
51
|
+
"distribuicaodfe"
|
|
52
|
+
],
|
|
53
|
+
"author": "Bitize",
|
|
54
|
+
"contributors": [
|
|
55
|
+
"Lucas Melo <lucashpmelo94@gmail.com> (autor original do node-mde)",
|
|
56
|
+
"Carlos Tirabassi Jr. <carlos@bitize.com.br>"
|
|
57
|
+
],
|
|
58
|
+
"license": "MIT",
|
|
59
|
+
"bugs": {
|
|
60
|
+
"url": "https://github.com/bitize/bitmde/issues"
|
|
61
|
+
},
|
|
62
|
+
"homepage": "https://github.com/bitize/bitmde#readme",
|
|
63
|
+
"dependencies": {
|
|
64
|
+
"axios": "1.19.0",
|
|
65
|
+
"fast-xml-parser": "5.11.0",
|
|
66
|
+
"luxon": "^3.7.2",
|
|
67
|
+
"node-forge": "1.4.0",
|
|
68
|
+
"xml-crypto": "6.1.2"
|
|
69
|
+
},
|
|
70
|
+
"devDependencies": {
|
|
71
|
+
"@types/luxon": "^3.7.4",
|
|
72
|
+
"@types/node": "^26.2.0",
|
|
73
|
+
"@types/node-forge": "^1.3.14",
|
|
74
|
+
"mocha": "^11.8.0",
|
|
75
|
+
"prettier": "3.9.6",
|
|
76
|
+
"typescript": "^5.9.3",
|
|
77
|
+
"uglify-js": "^3.19.3"
|
|
78
|
+
},
|
|
79
|
+
"overrides": {
|
|
80
|
+
"diff": "^9.0.0",
|
|
81
|
+
"serialize-javascript": "^7.1.0"
|
|
82
|
+
}
|
|
83
|
+
}
|