node-sped-nfe 1.0.4 → 1.0.5

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/src/utils/make.ts CHANGED
@@ -1,5 +1,6 @@
1
1
 
2
2
  import { XMLParser, XMLBuilder, XMLValidator } from "fast-xml-parser";
3
+ import { qrCodeUrls } from "./eventos.js"
3
4
 
4
5
  //Classe da nota fiscal
5
6
  class Make {
@@ -128,6 +129,7 @@ class Make {
128
129
  tagProd(obj: any) {
129
130
  //Abrir tag de imposto
130
131
  for (let cont = 0; cont < obj.length; cont++) {
132
+
131
133
  if (obj[cont]['@nItem'] === undefined) {
132
134
  obj[cont] = { '@nItem': cont + 1, prod: obj[cont], imposto: {} };
133
135
  } else {
@@ -135,6 +137,9 @@ class Make {
135
137
  delete obj[cont].prod['@nItem'];
136
138
  }
137
139
 
140
+ //Primeiro item + NFCe + Homologação
141
+ if(cont==0 && this.#NFe.infNFe.ide.mod == 65 && this.#NFe.infNFe.ide.tpAmb == 2 ) obj[cont].prod.xProd = "NOTA FISCAL EMITIDA EM AMBIENTE DE HOMOLOGACAO - SEM VALOR FISCAL";
142
+
138
143
  obj[cont].prod.qCom = (obj[cont].prod.qCom * 1).toFixed(4)
139
144
  obj[cont].prod.vUnCom = (obj[cont].prod.vUnCom * 1).toFixed(10)
140
145
  obj[cont].prod.vProd = (obj[cont].prod.vProd * 1).toFixed(2)
@@ -634,11 +639,11 @@ class Make {
634
639
  if (this.#NFe.infNFe[`@Id`] == null) this.#NFe.infNFe[`@Id`] = `NFe${this.#gerarChaveNFe()}`;
635
640
 
636
641
  //Adicionar QrCode
637
- if (this.#NFe.infNFe.ide.mod == 55) {
638
- /*this.#NFe.infNFeSupl = {
639
- qrCode: "",
640
- urlChave: ""
641
- }*/
642
+ if (this.#NFe.infNFe.ide.mod == 65) {
643
+ this.#NFe.infNFeSupl = {
644
+ qrCode: qrCodeUrls[this.#NFe.infNFe.ide.tpAmb==1 ? 'producao' : 'homologacao'][`${this.#NFe.infNFe.ide.cUF}`].urlQRCode,
645
+ urlChave: qrCodeUrls[this.#NFe.infNFe.ide.tpAmb==1 ? 'producao' : 'homologacao'][`${this.#NFe.infNFe.ide.cUF}`].urlChave
646
+ }
642
647
  }
643
648
 
644
649
  let tempBuild = new XMLBuilder({
@@ -647,126 +652,7 @@ class Make {
647
652
  });
648
653
  return tempBuild.build({ NFe: this.#NFe });
649
654
  }
650
-
651
- #getInfoQRCodeByUF(uf: any, amb: any) {
652
- if (this.#NFe.infNFe.ide.tpAmb) {
653
- switch (this.#NFe.infNFe.ide.cUF) {
654
- case 'AC':
655
- return { urlChave: 'www.sefaznet.ac.gov.br/nfce/consulta', urlQRCode: 'http://www.sefaznet.ac.gov.br/nfce/qrcode' };
656
- case 'AL':
657
- return { urlChave: 'www.sefaz.al.gov.br/nfce/consulta', urlQRCode: 'http://nfce.sefaz.al.gov.br/QRCode/consultarNFCe.jsp' };
658
- case 'AP':
659
- return { urlChave: 'www.sefaz.ap.gov.br/nfce/consulta', urlQRCode: 'https://www.sefaz.ap.gov.br/nfce/nfcep.php' };
660
- case 'AM':
661
- return { urlChave: 'www.sefaz.am.gov.br/nfce/consulta', urlQRCode: 'http://sistemas.sefaz.am.gov.br/nfceweb/consultarNFCe.jsp' };
662
- case 'BA':
663
- return { urlChave: 'www.sefaz.ba.gov.br/nfce/consulta', urlQRCode: 'http://nfe.sefaz.ba.gov.br/servicos/nfce/modulos/geral/NFCEC_consulta_chave_acesso.aspx' };
664
- case 'CE':
665
- return { urlChave: 'www.sefaz.ce.gov.br/nfce/consulta', urlQRCode: 'http://nfce.sefaz.ce.gov.br/pages/ShowNFCe.html' };
666
- case 'DF':
667
- return { urlChave: 'www.fazenda.df.gov.br/nfce/consulta', urlQRCode: 'http://dec.fazenda.df.gov.br/ConsultarNFCe.aspx' };
668
- case 'ES':
669
- return { urlChave: 'www.sefaz.es.gov.br/nfce/consulta', urlQRCode: 'http://app.sefaz.es.gov.br/ConsultaNFCe/qrcode.aspx' };
670
- case 'GO':
671
- return { urlChave: 'www.sefaz.go.gov.br/nfce/consulta', urlQRCode: 'http://nfe.sefaz.go.gov.br/nfeweb/sites/nfce/danfeNFCe' };
672
- case 'MA':
673
- return { urlChave: 'www.sefaz.ma.gov.br/nfce/consulta', urlQRCode: 'http://www.nfce.sefaz.ma.gov.br/portal/consultarNFCe.jsp' };
674
- case 'MG':
675
- return { urlChave: 'http://nfce.fazenda.mg.gov.br/portalnfce', urlQRCode: 'https://nfce.fazenda.mg.gov.br/portalnfce/sistema/qrcode.xhtml' };
676
- case 'MS':
677
- return { urlChave: 'http://www.dfe.ms.gov.br/nfce/consulta', urlQRCode: 'http://www.dfe.ms.gov.br/nfce/qrcode' };
678
- case '51': //MT
679
- return { urlChave: 'http://www.sefaz.mt.gov.br/nfce/consultanfce', urlQRCode: 'http://www.sefaz.mt.gov.br/nfce/consultanfce' };
680
- case 'PA':
681
- return { urlChave: 'www.sefa.pa.gov.br/nfce/consulta', urlQRCode: 'https://appnfc.sefa.pa.gov.br/portal/view/consultas/nfce/nfceForm.seam' };
682
- case 'PB':
683
- return { urlChave: 'www.receita.pb.gov.br/nfce/consulta', urlQRCode: 'http://www.receita.pb.gov.br/nfce' };
684
- case 'PE':
685
- return { urlChave: 'nfce.sefaz.pe.gov.br/nfce/consulta', urlQRCode: 'http://nfce.sefaz.pe.gov.br/nfce-web/consultarNFCe' };
686
- case 'PI':
687
- return { urlChave: 'www.sefaz.pi.gov.br/nfce/consulta', urlQRCode: 'http://www.sefaz.pi.gov.br/nfce/qrcode' };
688
- case 'PR':
689
- return { urlChave: 'http://www.fazenda.pr.gov.br/nfce/consulta', urlQRCode: 'http://www.fazenda.pr.gov.br/nfce/qrcode/' };
690
- case 'RJ':
691
- return { urlChave: 'www.fazenda.rj.gov.br/nfce/consulta', urlQRCode: 'http://www4.fazenda.rj.gov.br/consultaNFCe/QRCode' };
692
- case 'RN':
693
- return { urlChave: 'www.set.rn.gov.br/nfce/consulta', urlQRCode: 'http://nfce.set.rn.gov.br/consultarNFCe.aspx' };
694
- case 'RO':
695
- return { urlChave: 'www.sefin.ro.gov.br/nfce/consulta', urlQRCode: 'http://www.nfce.sefin.ro.gov.br/consultanfce/consulta.jsp' };
696
- case 'RS':
697
- return { urlChave: 'www.sefaz.rs.gov.br/nfce/consulta', urlQRCode: 'https://www.sefaz.rs.gov.br/NFCE/NFCE-COM.aspx' };
698
- case 'RR':
699
- return { urlChave: 'www.sefaz.rr.gov.br/nfce/consulta', urlQRCode: 'https://www.sefaz.rr.gov.br/nfce/servlet/qrcode' };
700
- case 'SE':
701
- return { urlChave: 'http://www.nfce.se.gov.br/nfce/consulta', urlQRCode: 'http://www.nfce.se.gov.br/portal/consultarNFCe.jsp' };
702
- case 'SP':
703
- return { urlChave: 'https://www.nfce.fazenda.sp.gov.br/consulta', urlQRCode: 'https://www.nfce.fazenda.sp.gov.br/qrcode' };
704
- case 'TO':
705
- return { urlChave: 'www.sefaz.to.gov.br/nfce/consulta', urlQRCode: 'http://www.sefaz.to.gov.br/nfce/qrcode' };
706
- default:
707
- throw new Error('URL do QRCode não encontrada pelo UF (' + uf + ') informado.');
708
- }
709
- }
710
- else {
711
- switch (this.#NFe.infNFe.ide.cUF) {
712
- case 'AC':
713
- return { urlChave: 'www.sefaznet.ac.gov.br/nfce/consulta', urlQRCode: 'http://hml.sefaznet.ac.gov.br/nfce/qrcode' };
714
- case 'AL':
715
- return { urlChave: 'www.sefaz.al.gov.br/nfce/consulta', urlQRCode: 'http://nfce.sefaz.al.gov.br/QRCode/consultarNFCe.jsp' };
716
- case 'AP':
717
- return { urlChave: 'www.sefaz.ap.gov.br/nfce/consulta', urlQRCode: 'https://www.sefaz.ap.gov.br/nfcehml/nfce.php' };
718
- case 'AM':
719
- return { urlChave: 'https://sistemas.sefaz.am.gov.br/nfceweb-hom/formConsulta.do', urlQRCode: 'https://sistemas.sefaz.am.gov.br/nfceweb-hom/consultarNFCe.jsp' };
720
- case 'BA':
721
- return { urlChave: 'http://hinternet.sefaz.ba.gov.br/nfce/consulta', urlQRCode: 'http://hnfe.sefaz.ba.gov.br/servicos/nfce/modulos/geral/NFCEC_consulta_chave_acesso.aspx' };
722
- case 'CE':
723
- return { urlChave: 'www.sefaz.ce.gov.br/nfce/consulta', urlQRCode: 'http://nfceh.sefaz.ce.gov.br/pages/ShowNFCe.html' };
724
- case 'DF':
725
- return { urlChave: 'www.fazenda.df.gov.br/nfce/consulta', urlQRCode: 'http://dec.fazenda.df.gov.br/ConsultarNFCe.aspx' };
726
- case 'ES':
727
- return { urlChave: 'www.sefaz.es.gov.br/nfce/consulta', urlQRCode: 'http://homologacao.sefaz.es.gov.br/ConsultaNFCe/qrcode.aspx' };
728
- case 'GO':
729
- return { urlChave: 'http://www.nfce.go.gov.br/post/ver/214413/consulta-nfc-e-homologacao', urlQRCode: 'http://homolog.sefaz.go.gov.br/nfeweb/sites/nfce/danfeNFCe' };
730
- case 'MA':
731
- return { urlChave: 'www.sefaz.ma.gov.br/nfce/consulta', urlQRCode: 'http://www.hom.nfce.sefaz.ma.gov.br/portal/consultarNFCe.jsp' };
732
- case 'MG':
733
- return { urlChave: 'http://hnfce.fazenda.mg.gov.br/portalnfce', urlQRCode: 'https://nfce.fazenda.mg.gov.br/portalnfce/sistema/qrcode.xhtml' };
734
- case 'MS':
735
- return { urlChave: 'http://www.dfe.ms.gov.br/nfce/consulta', urlQRCode: 'http://www.dfe.ms.gov.br/nfce/qrcode' };
736
- case '51': //MT
737
- return { urlChave: 'http://homologacao.sefaz.mt.gov.br/nfce/consultanfce', urlQRCode: 'http://homologacao.sefaz.mt.gov.br/nfce/consultanfce' };
738
- case 'PA':
739
- return { urlChave: 'www.sefa.pa.gov.br/nfce/consulta', urlQRCode: 'https://appnfc.sefa.pa.gov.br/portal-homologacao/view/consultas/nfce/nfceForm.seam' };
740
- case 'PB':
741
- return { urlChave: 'www.receita.pb.gov.br/nfcehom', urlQRCode: 'http://www.receita.pb.gov.br/nfcehom' };
742
- case 'PE':
743
- return { urlChave: 'nfce.sefaz.pe.gov.br/nfce/consulta', urlQRCode: 'http://nfcehomolog.sefaz.pe.gov.br/nfce-web/consultarNFCe' };
744
- case 'PI':
745
- return { urlChave: 'www.sefaz.pi.gov.br/nfce/consulta', urlQRCode: 'http://www.sefaz.pi.gov.br/nfce/qrcode' };
746
- case 'PR':
747
- return { urlChave: 'http://www.fazenda.pr.gov.br/nfce/consulta', urlQRCode: 'http://www.fazenda.pr.gov.br/nfce/qrcode/' };
748
- case 'RJ':
749
- return { urlChave: 'www.fazenda.rj.gov.br/nfce/consulta', urlQRCode: 'http://www4.fazenda.rj.gov.br/consultaNFCe/QRCode' };
750
- case 'RN':
751
- return { urlChave: 'www.set.rn.gov.br/nfce/consulta', urlQRCode: 'http://hom.nfce.set.rn.gov.br/consultarNFCe.aspx' };
752
- case 'RO':
753
- return { urlChave: 'www.sefin.ro.gov.br/nfce/consulta', urlQRCode: 'http://www.nfce.sefin.ro.gov.br/consultanfce/consulta.jsp' };
754
- case 'RS':
755
- return { urlChave: 'www.sefaz.rs.gov.br/nfce/consulta', urlQRCode: 'https://www.sefaz.rs.gov.br/NFCE/NFCE-COM.aspx' };
756
- case 'RR':
757
- return { urlChave: 'www.sefaz.rr.gov.br/nfce/consulta', urlQRCode: 'http://200.174.88.103:8080/nfce/servlet/qrcode' };
758
- case 'SE':
759
- return { urlChave: 'http://www.hom.nfe.se.gov.br/nfce/consulta', urlQRCode: 'http://www.hom.nfe.se.gov.br/portal/consultarNFCe.jsp' };
760
- case 'SP':
761
- return { urlChave: 'https://www.homologacao.nfce.fazenda.sp.gov.br/consulta', urlQRCode: 'https://www.homologacao.nfce.fazenda.sp.gov.br/qrcode' };
762
- case 'TO':
763
- return { urlChave: 'http://homologacao.sefaz.to.gov.br/nfce/consulta.jsf', urlQRCode: 'http://homologacao.sefaz.to.gov.br/nfce/qrcode' };
764
- default:
765
- throw new Error('URL do QRCode não encontrada pelo UF (' + uf + ') informado.');
766
- }
767
- }
768
- }
769
-
655
+
770
656
  #calICMSTot(obj: any) {
771
657
  Object.keys(obj).map(key => {
772
658
  if (this.#ICMSTot[key] !== undefined) {
@@ -1,5 +1,4 @@
1
- import { XMLParser, XMLBuilder, XMLValidator } from "fast-xml-parser";
2
- import pem from "pem";
1
+ import { XMLParser, XMLBuilder } from "fast-xml-parser";
3
2
  import https from "https";
4
3
  import { spawnSync, SpawnSyncReturns } from "child_process"
5
4
  import tmp from "tmp"
@@ -8,6 +7,9 @@ import { urlServicos } from "./eventos.js"
8
7
  import fs from "fs"
9
8
  import path from 'path';
10
9
  import { fileURLToPath } from 'url';
10
+ import pem from 'pem';
11
+
12
+
11
13
 
12
14
  const __filename = fileURLToPath(import.meta.url);
13
15
  const __dirname = path.dirname(__filename);
@@ -38,9 +40,11 @@ class Tools {
38
40
  xmllint: string;
39
41
  cUF: string;
40
42
  tpAmb: number;
43
+ CSC: string;
44
+ CSCid: string;
41
45
  };
42
46
 
43
- constructor(config = { mod: "", xmllint: 'xmllint', cUF: '51', tpAmb: 2 }, certificado = { pfx: "", senha: "" }) {
47
+ constructor(config = { mod: "", xmllint: 'xmllint', cUF: '51', tpAmb: 2, CSC: "", CSCid: "" }, certificado = { pfx: "", senha: "" }) {
44
48
  //Configurar certificado
45
49
  this.#config = config;
46
50
  this.#cert = certificado;
@@ -55,10 +59,6 @@ class Tools {
55
59
  });
56
60
  }
57
61
 
58
- async teste() {
59
- return await this.#certTools()
60
- }
61
-
62
62
  sefazEnviaLote(xml: string, data: any = { idLote: 1, indSinc: 0, compactar: false }): Promise<string> {
63
63
  return new Promise(async (resvol, reject) => {
64
64
  if (typeof data.idLote == "undefined") data.idLote = 1;
@@ -88,7 +88,6 @@ class Tools {
88
88
  },
89
89
  }
90
90
  let xmlLote = await this.json2xml(jsonXmlLote);
91
- fs.writeFileSync("testes/nfe_guara_sign_lote.xml", xmlLote, { encoding: "utf8" });
92
91
  try {
93
92
  const req = https.request(urlServicos[`${this.#config.cUF}`][`mod_${this.#config.mod}`].NFeAutorizacao[(this.#config.tpAmb == 1 ? "producao" : "homologacao")], {
94
93
  ...{
@@ -175,8 +174,14 @@ class Tools {
175
174
  "@xmlns": "http://www.w3.org/2000/09/xmldsig#"
176
175
  }
177
176
  }
177
+
178
+
179
+ if (xml.NFe.infNFe.ide.mod == 65) {
180
+ xml.NFe.infNFeSupl.qrCode = this.#gerarQRCodeNFCe(xml.NFe, "2", this.#config.CSCid, this.#config.CSC)
181
+ }
182
+
178
183
  this.json2xml(xml).then(async res => {
179
- this.#xmlValido(res);
184
+ this.#xmlValido(res, 'nfe_v4.00');
180
185
  resvol(res);
181
186
  }).catch(err => {
182
187
  reject(err)
@@ -184,6 +189,20 @@ class Tools {
184
189
  })
185
190
  }
186
191
 
192
+ #gerarQRCodeNFCe(NFe: any, versaoQRCode: string = "2", idCSC: string, CSC: string) {
193
+ let s = '|',
194
+ concat,
195
+ hash;
196
+ if (NFe.infNFe.ide.tpEmis == 1) {
197
+ concat = [NFe.infNFe['@Id'].replace("NFe", ""), versaoQRCode, NFe.infNFe.ide.tpAmb, Number(idCSC)].join(s);
198
+ } else {
199
+ let hexDigestValue = Buffer.from(NFe.Signature.SignedInfo.Reference.DigestValue).toString('hex');
200
+ concat = [NFe.infNFe['@Id'].replace("NFe", ""), versaoQRCode, NFe.infNFe.ide.tpAmb, NFe.infNFe.ide.dhEmi, NFe.infNFe.total.ICMSTot.vNF, hexDigestValue, Number(idCSC)].join(s);
201
+ }
202
+ hash = crypto.createHash('sha1').update(concat + CSC).digest('hex');
203
+ return NFe.infNFeSupl.qrCode + '?p=' + concat + s + hash;
204
+ }
205
+
187
206
  async xml2json(xml: string): Promise<object> {
188
207
  return new Promise((resvol, reject) => {
189
208
  resvol(this.#xmlTools.XMLParser.parse(xml))
@@ -198,32 +217,34 @@ class Tools {
198
217
 
199
218
  async getCertificado() {
200
219
  return new Promise(async (resvol, reject) => {
201
- await this.#certTools().then(resvol).catch(reject)
220
+ this.#certTools().then(resvol).catch(reject)
202
221
  })
203
222
  }
204
223
 
205
224
  //Consulta status sefaz
206
- async sefazStatus() {
225
+ async sefazStatus(): Promise<string> {
207
226
  return new Promise(async (resvol, reject) => {
208
- await this.#certTools();
209
227
 
210
228
  if (typeof this.#config.cUF == "undefined") throw "sefazStatus({...cUF}) -> não definido!";
211
229
  if (typeof this.#config.tpAmb == "undefined") throw "sefazStatus({...tpAmb}) -> não definido!";
212
230
  if (typeof this.#config.mod == "undefined") throw "sefazStatus({...mod}) -> não definido!";
213
231
 
232
+ //Separado para validar o corpo da consulta
233
+ let consStatServ = {
234
+ "@versao": "4.00",
235
+ "@xmlns": "http://www.portalfiscal.inf.br/nfe",
236
+ "tpAmb": this.#config.tpAmb,
237
+ "cUF": this.#config.cUF,
238
+ "xServ": "STATUS"
239
+ }
240
+
214
241
  let xmlObj = {
215
242
  "soap:Envelope": {
216
243
  "@xmlns:soap": "http://www.w3.org/2003/05/soap-envelope",
217
244
  "@xmlns:nfe": "http://www.portalfiscal.inf.br/nfe/wsdl/NFeStatusServico4",
218
245
  "soap:Body": {
219
246
  "nfe:nfeDadosMsg": {
220
- "consStatServ": {
221
- "@versao": "4.00",
222
- "@xmlns": "http://www.portalfiscal.inf.br/nfe",
223
- "tpAmb": this.#config.tpAmb,
224
- "cUF": this.#config.cUF,
225
- "xServ": "STATUS"
226
- }
247
+ consStatServ
227
248
  }
228
249
  }
229
250
  }
@@ -234,9 +255,11 @@ class Tools {
234
255
  ignoreAttributes: false,
235
256
  attributeNamePrefix: "@"
236
257
  });
237
- let xml = tempBuild.build(xmlObj);
238
258
 
239
- const req = https.request(urlServicos[`${this.#config.cUF}`][`mod_${this.#config.mod}`].NfeStatusServico[(this.#config.tpAmb == 1 ? "producao" : "homologacao")], {
259
+ //Validação
260
+ this.#xmlValido(tempBuild.build({ consStatServ }), 'consStatServ_v4.00');
261
+ let xml = tempBuild.build(xmlObj);
262
+ const req = https.request(urlServicos[`${this.#config.cUF}`][`mod_${this.#config.mod}`].NFeStatusServico[(this.#config.tpAmb == 1 ? "producao" : "homologacao")], {
240
263
  ...{
241
264
  method: 'POST',
242
265
  headers: {
@@ -245,7 +268,7 @@ class Tools {
245
268
  },
246
269
  rejectUnauthorized: false
247
270
  },
248
- ...this.#pem
271
+ ...await this.#certTools()
249
272
  }, (res) => {
250
273
  let data = '';
251
274
 
@@ -272,11 +295,10 @@ class Tools {
272
295
 
273
296
 
274
297
  //Validar XML da NFe, somente apos assinar
275
- async #xmlValido(xml: string) {
298
+ async #xmlValido(xml: string, xsd: string) {
276
299
  const xmlFile = tmp.fileSync({ mode: 0o644, prefix: 'xml-', postfix: '.xml' });
277
300
  fs.writeFileSync(xmlFile.name, xml, { encoding: 'utf8' });
278
-
279
- const schemaPath = path.resolve(__dirname, '../../schemas/nfe_v4.00.xsd');
301
+ const schemaPath = path.resolve(__dirname, `../../schemas/${xsd}.xsd`);
280
302
  const verif: SpawnSyncReturns<string> = spawnSync(
281
303
  this.#config.xmllint,
282
304
  ['--noout', '--schema', schemaPath, xmlFile.name],
@@ -291,13 +313,9 @@ class Tools {
291
313
  } else if (!verif.stderr.includes(".xml validates")) {
292
314
  throw new Error(verif.stderr);
293
315
  }
294
-
295
316
  return 1;
296
317
  }
297
318
 
298
-
299
-
300
- //Extrair dados do certificado pem
301
319
  #certTools(): Promise<object> {
302
320
  return new Promise(async (resvol, reject) => {
303
321
  if (this.#pem.key != "") resvol(this.#pem);
@@ -1 +0,0 @@
1
- {"root":["../src/index.ts","../src/utils/eventos.ts","../src/utils/make.ts","../src/utils/tools.ts"],"version":"5.8.3"}
@@ -1 +0,0 @@
1
- export {};
@@ -1,64 +0,0 @@
1
- import axios from "axios";
2
- import https from "https";
3
- class Instance {
4
- constructor(opts) {
5
- const { baseURL, ca, cert, key } = opts;
6
- const AgentOptions = Object.assign({
7
- cert: cert,
8
- key: key,
9
- ca: ca,
10
- }, { ...opts.httpsOptions });
11
- const httpsAgent = new https.Agent(AgentOptions);
12
- const requestOptions = Object.assign({
13
- baseURL: baseURL,
14
- headers: {
15
- 'User-Agent': `node-nfe/1.0`,
16
- 'Content-Type': 'application/soap+xml; charset=utf-8',
17
- },
18
- httpsAgent: httpsAgent,
19
- timeout: 60000,
20
- }, { ...opts.requestOptions });
21
- const instance = axios.create({
22
- ...requestOptions,
23
- });
24
- this.instance = instance;
25
- }
26
- /**
27
- * @returns {Promise<{status: number, data: string}>}
28
- */
29
- async request(config) {
30
- try {
31
- const response = await this.instance(config);
32
- const { status, data } = response;
33
- return { status, data };
34
- }
35
- catch (error) {
36
- if (error.response) {
37
- const { status, data } = error.response;
38
- return { status, data };
39
- }
40
- else if (error.request) {
41
- if (error.code === 'ECONNABORTED') {
42
- const retorno = {
43
- status: 504,
44
- data: `<error>${error.message || error}</error>`,
45
- };
46
- return retorno;
47
- }
48
- const retorno = {
49
- status: 502,
50
- data: `<error>${error.message || error}</error>`,
51
- };
52
- return retorno;
53
- }
54
- else {
55
- const retorno = {
56
- status: 500,
57
- data: `<error>${error.message || error}</error>`,
58
- };
59
- return retorno;
60
- }
61
- }
62
- }
63
- }
64
- module.exports = Instance;
@@ -1,4 +0,0 @@
1
- declare const validateXML: (options: any) => {
2
- errors: any;
3
- };
4
- export { validateXML };