@bitize/bitmde 0.18.0 → 0.20.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 (61) hide show
  1. package/CHANGELOG.md +64 -0
  2. package/README.md +309 -4
  3. package/dist/apis/distribuicaoDFe-api.d.ts +13 -1
  4. package/dist/apis/distribuicaoNFSe-api.d.ts +176 -0
  5. package/dist/apis/manifestacaoNFSe-api.d.ts +130 -0
  6. package/dist/apis/recepcaoEvento-api.d.ts +5 -1
  7. package/dist/controllers/distribuicaoDFe-controller.d.ts +5 -1
  8. package/dist/controllers/distribuicaoNFSe-controller.d.ts +50 -0
  9. package/dist/controllers/index.d.ts +84 -0
  10. package/dist/controllers/manifestacaoNFSe-controller.d.ts +38 -0
  11. package/dist/controllers/recepcaoEvento-controller.d.ts +5 -1
  12. package/dist/env/ca.d.ts +8 -2
  13. package/dist/env/index.d.ts +5 -1
  14. package/dist/env/nfse.d.ts +32 -0
  15. package/dist/helpers/distribuicaoDFe-helper.d.ts +4 -0
  16. package/dist/helpers/distribuicaoNFSe-helper.d.ts +107 -0
  17. package/dist/helpers/index.d.ts +158 -0
  18. package/dist/helpers/manifestacaoNFSe-helper.d.ts +80 -0
  19. package/dist/helpers/recepcaoEvento-helper.d.ts +4 -0
  20. package/dist/helpers/retorno-helper.d.ts +5 -0
  21. package/dist/helpers/retornoNfse-helper.d.ts +44 -0
  22. package/dist/index.d.ts +13 -1
  23. package/dist/schemas/index.d.ts +17 -0
  24. package/dist/schemas/manifestacaoNFSe-schema.d.ts +33 -0
  25. package/dist/services/sefaz-service.d.ts +8 -1
  26. package/dist/util/assinatura.d.ts +3 -1
  27. package/dist/util/gzip.d.ts +7 -0
  28. package/dist/util/index.d.ts +2 -1
  29. package/dist/validators/chaveNfse-validator.d.ts +14 -0
  30. package/dist/validators/cnpj-validator.d.ts +19 -0
  31. package/dist/validators/index.d.ts +50 -0
  32. package/dist/validators/motivoRejeicao-validator.d.ts +23 -0
  33. package/dist/validators/nsuNfse-validator.d.ts +20 -0
  34. package/lib/apis/distribuicaoNFSe-api.js +59 -0
  35. package/lib/apis/manifestacaoNFSe-api.js +69 -0
  36. package/lib/controllers/distribuicaoNFSe-controller.js +16 -0
  37. package/lib/controllers/index.js +3 -1
  38. package/lib/controllers/manifestacaoNFSe-controller.js +25 -0
  39. package/lib/env/ca.js +3 -2
  40. package/lib/env/index.js +12 -1
  41. package/lib/env/nfse.js +24 -0
  42. package/lib/env/version.js +1 -1
  43. package/lib/helpers/distribuicaoDFe-helper.js +2 -2
  44. package/lib/helpers/distribuicaoNFSe-helper.js +128 -0
  45. package/lib/helpers/index.js +5 -2
  46. package/lib/helpers/manifestacaoNFSe-helper.js +105 -0
  47. package/lib/helpers/recepcaoEvento-helper.js +2 -2
  48. package/lib/helpers/retorno-helper.js +16 -9
  49. package/lib/helpers/retornoNfse-helper.js +31 -0
  50. package/lib/index.js +13 -1
  51. package/lib/schemas/index.js +2 -1
  52. package/lib/schemas/manifestacaoNFSe-schema.js +19 -0
  53. package/lib/services/sefaz-service.js +15 -14
  54. package/lib/util/assinatura.js +2 -2
  55. package/lib/util/gzip.js +8 -0
  56. package/lib/validators/chaveNfse-validator.js +16 -0
  57. package/lib/validators/cnpj-validator.js +21 -0
  58. package/lib/validators/index.js +5 -1
  59. package/lib/validators/motivoRejeicao-validator.js +28 -0
  60. package/lib/validators/nsuNfse-validator.js +18 -0
  61. package/package.json +10 -4
@@ -11,7 +11,7 @@ class Instance {
11
11
  cert: a,
12
12
  key: r,
13
13
  ca: s,
14
- rejectUnauthorized: !1
14
+ rejectUnauthorized: !0
15
15
  }, {
16
16
  ...t.httpsOptions
17
17
  }), r = new https.Agent(a), s = Object.assign({
@@ -33,29 +33,30 @@ class Instance {
33
33
  try {
34
34
  var {
35
35
  status: s,
36
- data: t
36
+ data: a
37
37
  } = await this.instance(e);
38
38
  return {
39
39
  status: s,
40
- data: t
40
+ data: a
41
41
  };
42
42
  } catch (t) {
43
- return t.response ? ({
43
+ return t && t.response ? ({
44
44
  status: e,
45
45
  data: s
46
46
  } = t.response, {
47
47
  status: e,
48
48
  data: s
49
- }) : t.request ? "ECONNABORTED" === t.code ? {
50
- status: 504,
51
- data: `<error>${t.message || t}</error>`
52
- } : {
53
- status: 502,
54
- data: `<error>${t.message || t}</error>`
55
- } : {
56
- status: 500,
57
- data: `<error>${t.message || t}</error>`
58
- };
49
+ }) : ({
50
+ code: a,
51
+ message: e
52
+ } = t || {}, {
53
+ status: 0,
54
+ data: "",
55
+ transportError: {
56
+ code: a ? String(a) : "ERR_DESCONHECIDO",
57
+ message: e ? String(e) : String(t)
58
+ }
59
+ });
59
60
  }
60
61
  }
61
62
  }
@@ -1,8 +1,8 @@
1
1
  let SignedXml = require("xml-crypto").SignedXml;
2
2
 
3
3
  class Assinatura {
4
- static assinarXml(e, t, a) {
5
- var r = "//*[local-name(.)='infEvento']", i = [ "http://www.w3.org/2000/09/xmldsig#enveloped-signature", "http://www.w3.org/TR/2001/REC-xml-c14n-20010315" ], t = new SignedXml({
4
+ static assinarXml(e, t, a, r = "infEvento") {
5
+ var r = `//*[local-name(.)='${r}']`, i = [ "http://www.w3.org/2000/09/xmldsig#enveloped-signature", "http://www.w3.org/TR/2001/REC-xml-c14n-20010315" ], t = new SignedXml({
6
6
  privateKey: t,
7
7
  publicCert: e,
8
8
  canonicalizationAlgorithm: i[1],
package/lib/util/gzip.js CHANGED
@@ -1,6 +1,14 @@
1
1
  let zlib = require("zlib");
2
2
 
3
3
  class Gzip {
4
+ static zip(e) {
5
+ return new Promise((r, t) => {
6
+ zlib.gzip(Buffer.from(e, "utf8"), function(e, i) {
7
+ if (e) return t(e);
8
+ r(i.toString("base64"));
9
+ });
10
+ });
11
+ }
4
12
  static unzip(e) {
5
13
  let i = Buffer.from(e, "base64");
6
14
  return new Promise((r, t) => {
@@ -0,0 +1,16 @@
1
+ class ChaveNfseValidator {
2
+ constructor(e) {
3
+ this.chave = e, this.error = "";
4
+ }
5
+ isValid() {
6
+ return this.chave ? (this.chave = String(this.chave), !!/^[0-9]{50}$/.test(this.chave) || !(this.error = "Chave da NFS-e com tamanho incorreto.")) : !(this.error = "Chave da NFS-e não informada.");
7
+ }
8
+ getValues() {
9
+ return this.chave;
10
+ }
11
+ getError() {
12
+ return this.error;
13
+ }
14
+ }
15
+
16
+ module.exports = Object.freeze(ChaveNfseValidator);
@@ -0,0 +1,21 @@
1
+ let FORMATO_CNPJ = /^[0-9A-Z]{12}[0-9]{2}$/;
2
+
3
+ class CnpjValidator {
4
+ constructor(r) {
5
+ r = r.cnpj;
6
+ this.cnpj = r, this.error = "";
7
+ }
8
+ isValid() {
9
+ return this.cnpj ? (this.cnpj = String(this.cnpj).toUpperCase(), !!FORMATO_CNPJ.test(this.cnpj) || !(this.error = "CNPJ com formato inválido.")) : !(this.error = "CNPJ não informado.");
10
+ }
11
+ getValues() {
12
+ return {
13
+ cnpj: this.cnpj
14
+ };
15
+ }
16
+ getError() {
17
+ return this.error;
18
+ }
19
+ }
20
+
21
+ module.exports = Object.freeze(CnpjValidator);
@@ -1,10 +1,14 @@
1
- let AmbienteValidator = require("./ambiente-validator"), CertificadoValidator = require("./certificado-validator"), ChaveValidator = require("./chave-validator"), CnpjCpfValidator = require("./cnpjCpf-validator"), EventoValidator = require("./evento-validator"), LoteValidator = require("./lote-validator"), NsuValidator = require("./nsu-validator"), UfValidator = require("./uf-validator"), ZoneValidator = require("./zone-validator"), validator = Object.freeze({
1
+ let AmbienteValidator = require("./ambiente-validator"), CertificadoValidator = require("./certificado-validator"), ChaveNfseValidator = require("./chaveNfse-validator"), ChaveValidator = require("./chave-validator"), CnpjCpfValidator = require("./cnpjCpf-validator"), CnpjValidator = require("./cnpj-validator"), EventoValidator = require("./evento-validator"), LoteValidator = require("./lote-validator"), MotivoRejeicaoValidator = require("./motivoRejeicao-validator"), NsuNfseValidator = require("./nsuNfse-validator"), NsuValidator = require("./nsu-validator"), UfValidator = require("./uf-validator"), ZoneValidator = require("./zone-validator"), validator = Object.freeze({
2
2
  AmbienteValidator: AmbienteValidator,
3
3
  CertificadoValidator: CertificadoValidator,
4
+ ChaveNfseValidator: ChaveNfseValidator,
4
5
  ChaveValidator: ChaveValidator,
5
6
  CnpjCpfValidator: CnpjCpfValidator,
7
+ CnpjValidator: CnpjValidator,
6
8
  EventoValidator: EventoValidator,
7
9
  LoteValidator: LoteValidator,
10
+ MotivoRejeicaoValidator: MotivoRejeicaoValidator,
11
+ NsuNfseValidator: NsuNfseValidator,
8
12
  NsuValidator: NsuValidator,
9
13
  UfValidator: UfValidator,
10
14
  ZoneValidator: ZoneValidator
@@ -0,0 +1,28 @@
1
+ let MOTIVOS = [ "1", "2", "3", "4", "5", "9" ];
2
+
3
+ class MotivoRejeicaoValidator {
4
+ constructor(o) {
5
+ var {
6
+ cMotivo: o,
7
+ xMotivo: t
8
+ } = o || {};
9
+ this.cMotivo = o, this.xMotivo = t, this.error = "";
10
+ }
11
+ isValid() {
12
+ var o;
13
+ return null == this.cMotivo || "" === this.cMotivo ? !(this.error = "Motivo da rejeição não informado.") : (this.cMotivo = String(this.cMotivo),
14
+ MOTIVOS.includes(this.cMotivo) ? (o = null == this.xMotivo ? "" : String(this.xMotivo).trim(),
15
+ this.xMotivo = o || void 0, "9" !== this.cMotivo || this.xMotivo ? !this.xMotivo || !(o.length < 15 || 255 < o.length) || !(this.error = "Descrição do motivo com tamanho incorreto.") : !(this.error = "Descrição do motivo obrigatória para o motivo 9 (Outros).")) : !(this.error = "Motivo da rejeição deve conter um dos valores: 1, 2, 3, 4, 5 ou 9"));
16
+ }
17
+ getValues() {
18
+ return {
19
+ cMotivo: this.cMotivo,
20
+ xMotivo: this.xMotivo
21
+ };
22
+ }
23
+ getError() {
24
+ return this.error;
25
+ }
26
+ }
27
+
28
+ module.exports = Object.freeze(MotivoRejeicaoValidator);
@@ -0,0 +1,18 @@
1
+ class NsuNfseValidator {
2
+ constructor(s, r = {}) {
3
+ this.nsu = s, this.positivo = Boolean(r.positivo), this.error = "";
4
+ }
5
+ isValid() {
6
+ return null == this.nsu || "" === this.nsu ? !(this.error = "NSU não informado.") : (this.nsu = String(this.nsu),
7
+ /^[0-9]+$/.test(this.nsu) ? 15 < this.nsu.length ? !(this.error = "NSU com tamanho incorreto.") : (this.nsu = this.nsu.replace(/^0+(?=[0-9])/, ""),
8
+ !this.positivo || "0" !== this.nsu || !(this.error = "NSU deve ser maior que zero.")) : !(this.error = "NSU deve conter apenas números."));
9
+ }
10
+ getValues() {
11
+ return this.nsu;
12
+ }
13
+ getError() {
14
+ return this.error;
15
+ }
16
+ }
17
+
18
+ module.exports = Object.freeze(NsuNfseValidator);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
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",
3
+ "version": "0.20.0",
4
+ "description": "Biblioteca para consultar notas destinadas e enviar evento de manifestação do destinatário, e para a distribuição de NFS-e Nacional pelo ADN",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./dist/index.d.ts",
7
7
  "exports": {
@@ -22,7 +22,7 @@
22
22
  "script": "node ./scripts/index.js",
23
23
  "release": "git pull && npm run build && npm publish",
24
24
  "test": "mocha",
25
- "test:ci": "mocha --ignore test/sefaz.test.js",
25
+ "test:ci": "mocha --ignore test/sefaz.test.js --ignore test/tls-sefaz.test.js",
26
26
  "format": "prettier --write .",
27
27
  "format:check": "prettier --check .",
28
28
  "certs:teste": "sh ./scripts/gerar-certificado-teste.sh",
@@ -48,7 +48,10 @@
48
48
  "mde",
49
49
  "soap",
50
50
  "manifestacaonfe",
51
- "distribuicaodfe"
51
+ "distribuicaodfe",
52
+ "nfse",
53
+ "nfse-nacional",
54
+ "adn"
52
55
  ],
53
56
  "author": "Bitize",
54
57
  "contributors": [
@@ -56,6 +59,9 @@
56
59
  "Carlos Tirabassi Jr. <carlos@bitize.com.br>"
57
60
  ],
58
61
  "license": "MIT",
62
+ "engines": {
63
+ "node": ">=22"
64
+ },
59
65
  "bugs": {
60
66
  "url": "https://github.com/bitize/bitmde/issues"
61
67
  },