hnt_digest_issue_nfe_library 1.0.2 → 1.0.3
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/lib/index.js +82 -64
- package/lib/sefaz/envelope.js +9 -0
- package/lib/sefaz/ws_service.js +132 -0
- package/package.json +4 -2
package/lib/index.js
CHANGED
|
@@ -4,14 +4,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports["default"] = void 0;
|
|
7
|
-
var
|
|
7
|
+
var _ws_service = require("./sefaz/ws_service.js");
|
|
8
8
|
var _jira_service = require("./jira/jira_service.js");
|
|
9
9
|
var _build_nf_caixa_form = require("./builder/build_nf_caixa_form.js");
|
|
10
10
|
var _form_service = require("./jira/form_service.js");
|
|
11
11
|
var _constantes = require("./constantes.js");
|
|
12
12
|
var _identification_comment = require("./comments/identification_comment.js");
|
|
13
13
|
var _comment_service = require("./jira/comment_service.js");
|
|
14
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
15
14
|
function _regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = !1, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = !0, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i["return"]) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), !0), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine2(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine2(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine2(u), _regeneratorDefine2(u, o, "Generator"), _regeneratorDefine2(u, n, function () { return this; }), _regeneratorDefine2(u, "toString", function () { return "[object Generator]"; }), (_regenerator = function _regenerator() { return { w: i, m: f }; })(); }
|
|
16
15
|
function _regeneratorDefine2(e, r, n, t) { var i = Object.defineProperty; try { i({}, "", {}); } catch (e) { i = 0; } _regeneratorDefine2 = function _regeneratorDefine(e, r, n, t) { function o(r, n) { _regeneratorDefine2(e, r, function (e) { return this._invoke(r, n, e); }); } r ? i ? i(e, r, { value: n, enumerable: !t, configurable: !t, writable: !t }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2)); }, _regeneratorDefine2(e, r, n, t); }
|
|
17
16
|
function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
|
|
@@ -20,25 +19,44 @@ var pck = require('../package.json');
|
|
|
20
19
|
var version = function version() {
|
|
21
20
|
return pck.version;
|
|
22
21
|
};
|
|
23
|
-
var getSefazXML = function
|
|
24
|
-
var
|
|
25
|
-
|
|
26
|
-
certPfxPassword = _ref.certPfxPassword;
|
|
27
|
-
return _lib["default"].getSefazXML({
|
|
28
|
-
cnpjDestinatario: cnpjDestinatario,
|
|
29
|
-
chaveAcessoNF: chaveAcessoNF,
|
|
30
|
-
certPfxPassword: certPfxPassword
|
|
31
|
-
});
|
|
32
|
-
};
|
|
33
|
-
var sefazIdentification = /*#__PURE__*/function () {
|
|
34
|
-
var _ref3 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(_ref2) {
|
|
35
|
-
var cnpjDestinatario, chaveAcessoNF, certPfxPassword, n8nAccessToken, sap_cod_fornecedor, nfSAP;
|
|
22
|
+
var getSefazXML = /*#__PURE__*/function () {
|
|
23
|
+
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(_ref) {
|
|
24
|
+
var cnpjDestinatario, chaveAcessoNF, certPfxPassword, xml;
|
|
36
25
|
return _regenerator().w(function (_context) {
|
|
37
26
|
while (1) switch (_context.n) {
|
|
38
27
|
case 0:
|
|
39
|
-
cnpjDestinatario =
|
|
40
|
-
|
|
41
|
-
|
|
28
|
+
cnpjDestinatario = _ref.cnpjDestinatario, chaveAcessoNF = _ref.chaveAcessoNF, certPfxPassword = _ref.certPfxPassword;
|
|
29
|
+
if (!(!cnpjDestinatario || !chaveAcessoNF || !certPfxPassword)) {
|
|
30
|
+
_context.n = 1;
|
|
31
|
+
break;
|
|
32
|
+
}
|
|
33
|
+
throw new Error('cnpjDestinatario, chaveAcessoNF, or certPfxPassword is missing');
|
|
34
|
+
case 1:
|
|
35
|
+
_context.n = 2;
|
|
36
|
+
return (0, _ws_service.getXMLNFe)({
|
|
37
|
+
cnpjDestinatario: cnpjDestinatario,
|
|
38
|
+
chaveAcessoNF: chaveAcessoNF,
|
|
39
|
+
certPfxPassword: certPfxPassword
|
|
40
|
+
});
|
|
41
|
+
case 2:
|
|
42
|
+
xml = _context.v;
|
|
43
|
+
return _context.a(2, xml);
|
|
44
|
+
}
|
|
45
|
+
}, _callee);
|
|
46
|
+
}));
|
|
47
|
+
return function getSefazXML(_x) {
|
|
48
|
+
return _ref2.apply(this, arguments);
|
|
49
|
+
};
|
|
50
|
+
}();
|
|
51
|
+
var sefazIdentification = /*#__PURE__*/function () {
|
|
52
|
+
var _ref4 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(_ref3) {
|
|
53
|
+
var cnpjDestinatario, chaveAcessoNF, certPfxPassword, n8nAccessToken, sap_cod_fornecedor, nfSAP;
|
|
54
|
+
return _regenerator().w(function (_context2) {
|
|
55
|
+
while (1) switch (_context2.n) {
|
|
56
|
+
case 0:
|
|
57
|
+
cnpjDestinatario = _ref3.cnpjDestinatario, chaveAcessoNF = _ref3.chaveAcessoNF, certPfxPassword = _ref3.certPfxPassword, n8nAccessToken = _ref3.n8nAccessToken, sap_cod_fornecedor = _ref3.sap_cod_fornecedor;
|
|
58
|
+
_context2.n = 1;
|
|
59
|
+
return sefaz.getNFSAP({
|
|
42
60
|
cnpjDestinatario: cnpjDestinatario,
|
|
43
61
|
chaveAcessoNF: chaveAcessoNF,
|
|
44
62
|
sap_cod_fornecedor: sap_cod_fornecedor,
|
|
@@ -46,46 +64,46 @@ var sefazIdentification = /*#__PURE__*/function () {
|
|
|
46
64
|
n8nAccessToken: n8nAccessToken
|
|
47
65
|
});
|
|
48
66
|
case 1:
|
|
49
|
-
nfSAP =
|
|
50
|
-
return
|
|
67
|
+
nfSAP = _context2.v;
|
|
68
|
+
return _context2.a(2, nfSAP);
|
|
51
69
|
}
|
|
52
|
-
},
|
|
70
|
+
}, _callee2);
|
|
53
71
|
}));
|
|
54
|
-
return function sefazIdentification(
|
|
55
|
-
return
|
|
72
|
+
return function sefazIdentification(_x2) {
|
|
73
|
+
return _ref4.apply(this, arguments);
|
|
56
74
|
};
|
|
57
75
|
}();
|
|
58
76
|
var updateNFCaixaFormAnswers = /*#__PURE__*/function () {
|
|
59
|
-
var
|
|
77
|
+
var _ref6 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(_ref5) {
|
|
60
78
|
var issueKey, jiraAccessToken, nro_documento_nota_fiscal, _yield$getFormIndex, forms, nfCaixaForm, _yield$getForm, form, answers;
|
|
61
|
-
return _regenerator().w(function (
|
|
62
|
-
while (1) switch (
|
|
79
|
+
return _regenerator().w(function (_context3) {
|
|
80
|
+
while (1) switch (_context3.n) {
|
|
63
81
|
case 0:
|
|
64
|
-
issueKey =
|
|
65
|
-
|
|
82
|
+
issueKey = _ref5.issueKey, jiraAccessToken = _ref5.jiraAccessToken, nro_documento_nota_fiscal = _ref5.nro_documento_nota_fiscal;
|
|
83
|
+
_context3.n = 1;
|
|
66
84
|
return (0, _form_service.getFormIndex)(jiraAccessToken, issueKey);
|
|
67
85
|
case 1:
|
|
68
|
-
_yield$getFormIndex =
|
|
86
|
+
_yield$getFormIndex = _context3.v;
|
|
69
87
|
forms = _yield$getFormIndex.data;
|
|
70
88
|
nfCaixaForm = forms.find(function (f) {
|
|
71
89
|
return f.formTemplate.id === _constantes.NF_CAIXA_FORM_TEMPLATE_ID;
|
|
72
90
|
});
|
|
73
91
|
if (nfCaixaForm) {
|
|
74
|
-
|
|
92
|
+
_context3.n = 2;
|
|
75
93
|
break;
|
|
76
94
|
}
|
|
77
95
|
throw new Error("Not Found form nf caixa for issue ".concat(issueKey));
|
|
78
96
|
case 2:
|
|
79
|
-
|
|
97
|
+
_context3.n = 3;
|
|
80
98
|
return (0, _form_service.getForm)(jiraAccessToken, issueKey, nfCaixaForm.id);
|
|
81
99
|
case 3:
|
|
82
|
-
_yield$getForm =
|
|
100
|
+
_yield$getForm = _context3.v;
|
|
83
101
|
form = _yield$getForm.data;
|
|
84
102
|
answers = (0, _build_nf_caixa_form.buildNfCaixaForm)({
|
|
85
103
|
form: form,
|
|
86
104
|
nro_documento_nota_fiscal: nro_documento_nota_fiscal
|
|
87
105
|
});
|
|
88
|
-
|
|
106
|
+
_context3.n = 4;
|
|
89
107
|
return (0, _form_service.saveFormAnswers)({
|
|
90
108
|
accessToken: jiraAccessToken,
|
|
91
109
|
issueKey: issueKey,
|
|
@@ -93,81 +111,81 @@ var updateNFCaixaFormAnswers = /*#__PURE__*/function () {
|
|
|
93
111
|
answers: answers
|
|
94
112
|
});
|
|
95
113
|
case 4:
|
|
96
|
-
return
|
|
114
|
+
return _context3.a(2);
|
|
97
115
|
}
|
|
98
|
-
},
|
|
116
|
+
}, _callee3);
|
|
99
117
|
}));
|
|
100
|
-
return function updateNFCaixaFormAnswers(
|
|
101
|
-
return
|
|
118
|
+
return function updateNFCaixaFormAnswers(_x3) {
|
|
119
|
+
return _ref6.apply(this, arguments);
|
|
102
120
|
};
|
|
103
121
|
}();
|
|
104
122
|
var commentOnIssue = /*#__PURE__*/function () {
|
|
105
|
-
var
|
|
123
|
+
var _ref8 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4(_ref7) {
|
|
106
124
|
var issueKey, jiraAccessToken, data;
|
|
107
|
-
return _regenerator().w(function (
|
|
108
|
-
while (1) switch (
|
|
125
|
+
return _regenerator().w(function (_context4) {
|
|
126
|
+
while (1) switch (_context4.n) {
|
|
109
127
|
case 0:
|
|
110
|
-
issueKey =
|
|
111
|
-
|
|
128
|
+
issueKey = _ref7.issueKey, jiraAccessToken = _ref7.jiraAccessToken, data = _ref7.data;
|
|
129
|
+
_context4.n = 1;
|
|
112
130
|
return (0, _comment_service.postComment)(jiraAccessToken, issueKey, (0, _identification_comment.identificationComment)(data));
|
|
113
131
|
case 1:
|
|
114
132
|
console.log("commentOnIssue not implemented yet for issue ".concat(issueKey));
|
|
115
133
|
case 2:
|
|
116
|
-
return
|
|
134
|
+
return _context4.a(2);
|
|
117
135
|
}
|
|
118
|
-
},
|
|
136
|
+
}, _callee4);
|
|
119
137
|
}));
|
|
120
|
-
return function commentOnIssue(
|
|
121
|
-
return
|
|
138
|
+
return function commentOnIssue(_x4) {
|
|
139
|
+
return _ref8.apply(this, arguments);
|
|
122
140
|
};
|
|
123
141
|
}();
|
|
124
142
|
var rebuildNFCaixaIssue = /*#__PURE__*/function () {
|
|
125
|
-
var
|
|
143
|
+
var _ref0 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5(_ref9) {
|
|
126
144
|
var issueKey, jiraAccessToken, _yield$getIssue, summary, _yield$getFormIndex2, forms, formNFCaixa, formId, _yield$addForm, id, _id, _yield$getFormSimplif, answers;
|
|
127
|
-
return _regenerator().w(function (
|
|
128
|
-
while (1) switch (
|
|
145
|
+
return _regenerator().w(function (_context5) {
|
|
146
|
+
while (1) switch (_context5.n) {
|
|
129
147
|
case 0:
|
|
130
|
-
issueKey =
|
|
131
|
-
|
|
148
|
+
issueKey = _ref9.issueKey, jiraAccessToken = _ref9.jiraAccessToken;
|
|
149
|
+
_context5.n = 1;
|
|
132
150
|
return (0, _jira_service.getIssue)(jiraAccessToken, issueKey);
|
|
133
151
|
case 1:
|
|
134
|
-
_yield$getIssue =
|
|
152
|
+
_yield$getIssue = _context5.v;
|
|
135
153
|
summary = _yield$getIssue.data.fields.summary;
|
|
136
|
-
|
|
154
|
+
_context5.n = 2;
|
|
137
155
|
return (0, _form_service.getFormIndex)(jiraAccessToken, issueKey);
|
|
138
156
|
case 2:
|
|
139
|
-
_yield$getFormIndex2 =
|
|
157
|
+
_yield$getFormIndex2 = _context5.v;
|
|
140
158
|
forms = _yield$getFormIndex2.data;
|
|
141
159
|
formNFCaixa = forms.find(function (f) {
|
|
142
160
|
return f.formTemplate.id === _constantes.NF_CAIXA_FORM_TEMPLATE_ID;
|
|
143
161
|
});
|
|
144
162
|
formId = null;
|
|
145
163
|
if (formNFCaixa) {
|
|
146
|
-
|
|
164
|
+
_context5.n = 4;
|
|
147
165
|
break;
|
|
148
166
|
}
|
|
149
|
-
|
|
167
|
+
_context5.n = 3;
|
|
150
168
|
return (0, _form_service.addForm)(jiraAccessToken, issueKey, _constantes.NF_CAIXA_FORM_TEMPLATE_ID);
|
|
151
169
|
case 3:
|
|
152
|
-
_yield$addForm =
|
|
170
|
+
_yield$addForm = _context5.v;
|
|
153
171
|
id = _yield$addForm.data.id;
|
|
154
172
|
formId = id;
|
|
155
|
-
|
|
173
|
+
_context5.n = 5;
|
|
156
174
|
break;
|
|
157
175
|
case 4:
|
|
158
176
|
_id = formNFCaixa.id;
|
|
159
177
|
formId = _id;
|
|
160
178
|
case 5:
|
|
161
|
-
|
|
179
|
+
_context5.n = 6;
|
|
162
180
|
return (0, _form_service.getFormSimplifiedAnswers)({
|
|
163
181
|
accessToken: jiraAccessToken,
|
|
164
182
|
issueKey: issueKey,
|
|
165
183
|
formId: formId
|
|
166
184
|
});
|
|
167
185
|
case 6:
|
|
168
|
-
_yield$getFormSimplif =
|
|
186
|
+
_yield$getFormSimplif = _context5.v;
|
|
169
187
|
answers = _yield$getFormSimplif.data;
|
|
170
|
-
return
|
|
188
|
+
return _context5.a(2, {
|
|
171
189
|
access_code: summary,
|
|
172
190
|
sap_cod_fornecedor: answers.find(function (a) {
|
|
173
191
|
return a.fieldKey == 'sap_cod_fornecedor';
|
|
@@ -182,10 +200,10 @@ var rebuildNFCaixaIssue = /*#__PURE__*/function () {
|
|
|
182
200
|
nf_caixa_form_id: formId
|
|
183
201
|
});
|
|
184
202
|
}
|
|
185
|
-
},
|
|
203
|
+
}, _callee5);
|
|
186
204
|
}));
|
|
187
|
-
return function rebuildNFCaixaIssue(
|
|
188
|
-
return
|
|
205
|
+
return function rebuildNFCaixaIssue(_x5) {
|
|
206
|
+
return _ref0.apply(this, arguments);
|
|
189
207
|
};
|
|
190
208
|
}();
|
|
191
209
|
var _default = exports["default"] = {
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.soapEnvelope = void 0;
|
|
7
|
+
var soapEnvelope = exports.soapEnvelope = function soapEnvelope(tpAmb, cUFAutor, CNPJ, chNFe) {
|
|
8
|
+
return "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<soap12:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"\n xmlns:soap12=\"http://www.w3.org/2003/05/soap-envelope\">\n <soap12:Body>\n <nfeDistDFeInteresse xmlns=\"http://www.portalfiscal.inf.br/nfe/wsdl/NFeDistribuicaoDFe\">\n <nfeDadosMsg>\n <distDFeInt versao=\"1.01\" xmlns=\"http://www.portalfiscal.inf.br/nfe\">\n <tpAmb>".concat(tpAmb, "</tpAmb>\n <cUFAutor>").concat(cUFAutor, "</cUFAutor>\n <CNPJ>").concat(CNPJ, "</CNPJ>\n <consChNFe>\n <chNFe>").concat(chNFe, "</chNFe>\n </consChNFe>\n </distDFeInt>\n </nfeDadosMsg>\n </nfeDistDFeInteresse>\n </soap12:Body>\n</soap12:Envelope>");
|
|
9
|
+
};
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getXMLNFe = void 0;
|
|
7
|
+
var _envelope = require("./envelope.js");
|
|
8
|
+
var _nodeFs = _interopRequireDefault(require("node:fs"));
|
|
9
|
+
var _nodeHttps = _interopRequireDefault(require("node:https"));
|
|
10
|
+
var _axios = _interopRequireDefault(require("axios"));
|
|
11
|
+
var _xml2js = require("xml2js");
|
|
12
|
+
var _nodeZlib = _interopRequireDefault(require("node:zlib"));
|
|
13
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
14
|
+
function _regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = !1, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = !0, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i["return"]) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), !0), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine2(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine2(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine2(u), _regeneratorDefine2(u, o, "Generator"), _regeneratorDefine2(u, n, function () { return this; }), _regeneratorDefine2(u, "toString", function () { return "[object Generator]"; }), (_regenerator = function _regenerator() { return { w: i, m: f }; })(); }
|
|
15
|
+
function _regeneratorDefine2(e, r, n, t) { var i = Object.defineProperty; try { i({}, "", {}); } catch (e) { i = 0; } _regeneratorDefine2 = function _regeneratorDefine(e, r, n, t) { function o(r, n) { _regeneratorDefine2(e, r, function (e) { return this._invoke(r, n, e); }); } r ? i ? i(e, r, { value: n, enumerable: !t, configurable: !t, writable: !t }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2)); }, _regeneratorDefine2(e, r, n, t); }
|
|
16
|
+
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
|
|
17
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
18
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
19
|
+
function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
|
|
20
|
+
function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
|
|
21
|
+
var getXMLNFe = exports.getXMLNFe = /*#__PURE__*/function () {
|
|
22
|
+
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(_ref) {
|
|
23
|
+
var _xml$soapEnvelope, _xml$soap12Envelope, _body$nfeDistDFeInter;
|
|
24
|
+
var cnpjDestinatario, chaveAcessoNF, certPfxPassword, config, agent, url, headers, _yield$axios$post, data, xml, body, resposta, cStat, xMotivo, lote, docs, _iterator, _step, _item$$, _item$$2, item, base64, schema, nsu, gz, xmlBytes, xmlStr, _t;
|
|
25
|
+
return _regenerator().w(function (_context) {
|
|
26
|
+
while (1) switch (_context.p = _context.n) {
|
|
27
|
+
case 0:
|
|
28
|
+
cnpjDestinatario = _ref.cnpjDestinatario, chaveAcessoNF = _ref.chaveAcessoNF, certPfxPassword = _ref.certPfxPassword;
|
|
29
|
+
config = {
|
|
30
|
+
ambiente: 'producao',
|
|
31
|
+
// 'homologacao' ou 'producao'
|
|
32
|
+
url: {
|
|
33
|
+
homologacao: 'https://hom.nfe.fazenda.gov.br/NFeDistribuicaoDFe/NFeDistribuicaoDFe.asmx',
|
|
34
|
+
producao: 'https://www1.nfe.fazenda.gov.br/NFeDistribuicaoDFe/NFeDistribuicaoDFe.asmx'
|
|
35
|
+
},
|
|
36
|
+
tpAmb: 1,
|
|
37
|
+
// 1=Produção, 2=Homologação
|
|
38
|
+
cUFAutor: 35,
|
|
39
|
+
// código IBGE da UF (ex.: SP=35)
|
|
40
|
+
certPfxPath: './res/ce.pfx',
|
|
41
|
+
//americanas_sa_em_recuperacao_judicial_00776574000660.pfx
|
|
42
|
+
certPfxPassword: certPfxPassword
|
|
43
|
+
};
|
|
44
|
+
agent = new _nodeHttps["default"].Agent({
|
|
45
|
+
pfx: _nodeFs["default"].readFileSync(config.certPfxPath),
|
|
46
|
+
passphrase: config.certPfxPassword,
|
|
47
|
+
rejectUnauthorized: true
|
|
48
|
+
});
|
|
49
|
+
url = config.url[config.ambiente];
|
|
50
|
+
headers = {
|
|
51
|
+
'Content-Type': 'application/soap+xml; charset=utf-8',
|
|
52
|
+
// SOAP 1.2
|
|
53
|
+
// Alguns ambientes exigem explicitamente SoapAction:
|
|
54
|
+
'SOAPAction': 'http://www.portalfiscal.inf.br/nfe/wsdl/NFeDistribuicaoDFe/nfeDistDFeInteresse'
|
|
55
|
+
};
|
|
56
|
+
_context.n = 1;
|
|
57
|
+
return _axios["default"].post(url, (0, _envelope.soapEnvelope)(config.tpAmb, config.cUFAutor, cnpjDestinatario, chaveAcessoNF), {
|
|
58
|
+
httpsAgent: agent,
|
|
59
|
+
headers: headers,
|
|
60
|
+
timeout: 30000
|
|
61
|
+
});
|
|
62
|
+
case 1:
|
|
63
|
+
_yield$axios$post = _context.v;
|
|
64
|
+
data = _yield$axios$post.data;
|
|
65
|
+
_context.n = 2;
|
|
66
|
+
return (0, _xml2js.parseStringPromise)(data, {
|
|
67
|
+
explicitArray: false
|
|
68
|
+
});
|
|
69
|
+
case 2:
|
|
70
|
+
xml = _context.v;
|
|
71
|
+
body = ((_xml$soapEnvelope = xml['soap:Envelope']) === null || _xml$soapEnvelope === void 0 ? void 0 : _xml$soapEnvelope['soap:Body']) || ((_xml$soap12Envelope = xml['soap12:Envelope']) === null || _xml$soap12Envelope === void 0 ? void 0 : _xml$soap12Envelope['soap12:Body']);
|
|
72
|
+
resposta = body === null || body === void 0 || (_body$nfeDistDFeInter = body['nfeDistDFeInteresseResponse']) === null || _body$nfeDistDFeInter === void 0 || (_body$nfeDistDFeInter = _body$nfeDistDFeInter['nfeDistDFeInteresseResult']) === null || _body$nfeDistDFeInter === void 0 ? void 0 : _body$nfeDistDFeInter.retDistDFeInt;
|
|
73
|
+
if (resposta) {
|
|
74
|
+
_context.n = 3;
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
77
|
+
throw new Error('Retorno inesperado da SEFAZ. Verifique headers/ambiente/certificado.');
|
|
78
|
+
case 3:
|
|
79
|
+
cStat = resposta.cStat;
|
|
80
|
+
xMotivo = resposta.xMotivo;
|
|
81
|
+
console.log('Status:', cStat, '-', xMotivo);
|
|
82
|
+
|
|
83
|
+
// Quando documentos são localizados (cStat 138), virá um lote com docZip
|
|
84
|
+
lote = resposta.loteDistDFeInt;
|
|
85
|
+
if (lote !== null && lote !== void 0 && lote.docZip) {
|
|
86
|
+
_context.n = 4;
|
|
87
|
+
break;
|
|
88
|
+
}
|
|
89
|
+
console.log('Nenhum docZip retornado (pode ser apenas resumo ou nada).');
|
|
90
|
+
return _context.a(2);
|
|
91
|
+
case 4:
|
|
92
|
+
// Normalizar docZip para array
|
|
93
|
+
docs = Array.isArray(lote.docZip) ? lote.docZip : [lote.docZip];
|
|
94
|
+
_iterator = _createForOfIteratorHelper(docs);
|
|
95
|
+
_context.p = 5;
|
|
96
|
+
_iterator.s();
|
|
97
|
+
case 6:
|
|
98
|
+
if ((_step = _iterator.n()).done) {
|
|
99
|
+
_context.n = 8;
|
|
100
|
+
break;
|
|
101
|
+
}
|
|
102
|
+
item = _step.value;
|
|
103
|
+
base64 = typeof item === 'string' ? item : item._ || item.$value;
|
|
104
|
+
schema = (_item$$ = item.$) === null || _item$$ === void 0 ? void 0 : _item$$.schema;
|
|
105
|
+
nsu = (_item$$2 = item.$) === null || _item$$2 === void 0 ? void 0 : _item$$2.NSU;
|
|
106
|
+
gz = Buffer.from(base64, 'base64');
|
|
107
|
+
xmlBytes = _nodeZlib["default"].gunzipSync(gz);
|
|
108
|
+
xmlStr = xmlBytes.toString('utf-8');
|
|
109
|
+
return _context.a(2, xmlStr);
|
|
110
|
+
case 7:
|
|
111
|
+
_context.n = 6;
|
|
112
|
+
break;
|
|
113
|
+
case 8:
|
|
114
|
+
_context.n = 10;
|
|
115
|
+
break;
|
|
116
|
+
case 9:
|
|
117
|
+
_context.p = 9;
|
|
118
|
+
_t = _context.v;
|
|
119
|
+
_iterator.e(_t);
|
|
120
|
+
case 10:
|
|
121
|
+
_context.p = 10;
|
|
122
|
+
_iterator.f();
|
|
123
|
+
return _context.f(10);
|
|
124
|
+
case 11:
|
|
125
|
+
return _context.a(2);
|
|
126
|
+
}
|
|
127
|
+
}, _callee, null, [[5, 9, 10, 11]]);
|
|
128
|
+
}));
|
|
129
|
+
return function getXMLNFe(_x) {
|
|
130
|
+
return _ref2.apply(this, arguments);
|
|
131
|
+
};
|
|
132
|
+
}();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hnt_digest_issue_nfe_library",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "Read NFs from Sefaz by access key",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -17,6 +17,8 @@
|
|
|
17
17
|
"license": "ISC",
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"dotenv": "^17.2.3",
|
|
20
|
-
"
|
|
20
|
+
"axios": "^1.13.2",
|
|
21
|
+
"csvtojson": "^2.0.14",
|
|
22
|
+
"xml2js": "^0.6.2"
|
|
21
23
|
}
|
|
22
24
|
}
|