ghinfe 0.6.0 → 0.6.2

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 (110) hide show
  1. package/.env.example +24 -15
  2. package/LICENSE +21 -21
  3. package/README.md +491 -413
  4. package/docs/developer-guide.html +421 -421
  5. package/docs/openapi.yaml +428 -428
  6. package/examples/dce-homologacao.js +141 -0
  7. package/examples/emitir-nfce.js +51 -51
  8. package/examples/emitir-nfe.js +83 -83
  9. package/examples/emitir-nfse.js +46 -46
  10. package/examples/endpoints-sefaz.js +14 -14
  11. package/examples/eventos-nfe.js +49 -49
  12. package/examples/gerar-chave.js +25 -25
  13. package/examples/gerar-dace.js +59 -0
  14. package/examples/gerar-danfe.js +75 -75
  15. package/examples/gerar-dce.js +58 -0
  16. package/examples/layouts-nfse.js +51 -51
  17. package/examples/mock-sefaz.js +52 -52
  18. package/examples/nfse-eventos.js +57 -57
  19. package/examples/reforma-ibscbs.js +27 -27
  20. package/examples/reforma-nfe-xml.js +52 -52
  21. package/examples/status-sefaz.js +12 -12
  22. package/examples/validar-xsd.js +48 -48
  23. package/package.json +59 -68
  24. package/schemas/dce/PL_DCe_100a_NT2024.001/consulta/consSitDCeTiposBasico_v1.00.xsd +123 -0
  25. package/schemas/dce/PL_DCe_100a_NT2024.001/consulta/consSitDCe_v1.00.xsd +10 -0
  26. package/schemas/dce/PL_DCe_100a_NT2024.001/consulta/consStatServDCeTiposBasico_v1.00.xsd +110 -0
  27. package/schemas/dce/PL_DCe_100a_NT2024.001/consulta/consStatServDCe_v1.00.xsd +10 -0
  28. package/schemas/dce/PL_DCe_100a_NT2024.001/consulta/dceTiposBasico_v1.00.xsd +1388 -0
  29. package/schemas/dce/PL_DCe_100a_NT2024.001/consulta/retConsSitDCe_v1.00.xsd +10 -0
  30. package/schemas/dce/PL_DCe_100a_NT2024.001/consulta/retConsStatServDCe_v1.00.xsd +10 -0
  31. package/schemas/dce/PL_DCe_100a_NT2024.001/consulta/tiposGeralDCe_v1.00.xsd +712 -0
  32. package/schemas/dce/PL_DCe_100a_NT2024.001/consulta/xmldsig-core-schema_v1.01.xsd +98 -0
  33. package/schemas/dce/PL_DCe_100a_NT2024.001/dceTiposBasico_v1.00.xsd +1410 -0
  34. package/schemas/dce/PL_DCe_100a_NT2024.001/dce_v1.00.xsd +10 -0
  35. package/schemas/dce/PL_DCe_100a_NT2024.001/evento/evCancDCe_v1.00.xsd +36 -0
  36. package/schemas/dce/PL_DCe_100a_NT2024.001/evento/eventoDCeTiposBasico_v1.00.xsd +283 -0
  37. package/schemas/dce/PL_DCe_100a_NT2024.001/evento/eventoDCe_v1.00.xsd +9 -0
  38. package/schemas/dce/PL_DCe_100a_NT2024.001/evento/procEventoDCe_v1.00.xsd +10 -0
  39. package/schemas/dce/PL_DCe_100a_NT2024.001/evento/retEventoDCe_v1.00.xsd +9 -0
  40. package/schemas/dce/PL_DCe_100a_NT2024.001/evento/tiposGeralDCe_v1.00.xsd +712 -0
  41. package/schemas/dce/PL_DCe_100a_NT2024.001/evento/xmldsig-core-schema_v1.01.xsd +98 -0
  42. package/schemas/dce/PL_DCe_100a_NT2024.001/procDCe_v1.00.xsd +37 -0
  43. package/schemas/dce/PL_DCe_100a_NT2024.001/retDCe_v1.00.xsd +9 -0
  44. package/schemas/dce/PL_DCe_100a_NT2024.001/tiposGeralDCe_v1.00.xsd +712 -0
  45. package/schemas/dce/PL_DCe_100a_NT2024.001/xmldsig-core-schema_v1.01.xsd +98 -0
  46. package/schemas/nfe/PL_009_V4/enviNFe_v3.10.xsd +8 -8
  47. package/schemas/nfe/PL_009_V4/xmldsig-core-schema_v1.01.xsd +97 -97
  48. package/scripts/download-schemas.js +39 -39
  49. package/scripts/test-xsd.js +34 -34
  50. package/src/api/server.js +316 -316
  51. package/src/constants/sefaz.js +69 -69
  52. package/src/danfe/DanfeService.js +205 -205
  53. package/src/danfe/xml-extract.js +69 -69
  54. package/src/dce/builders/DCeEventoXmlBuilder.js +86 -0
  55. package/src/dce/builders/DCeXmlBuilder.js +345 -0
  56. package/src/dce/constants/dce.js +87 -0
  57. package/src/dce/dace/DaceService.js +356 -0
  58. package/src/dce/dace/dace-extract.js +114 -0
  59. package/src/dce/services/DCeService.js +263 -0
  60. package/src/dce/services/DCeSoapService.js +235 -0
  61. package/src/dce/services/DCeXmlService.js +67 -0
  62. package/src/dce/types/DCeDocument.js +106 -0
  63. package/src/dce/utils/qrcode.utils.js +59 -0
  64. package/src/errors/GhinfeError.js +13 -13
  65. package/src/errors/SefazError.js +25 -25
  66. package/src/errors/XsdValidationError.js +15 -15
  67. package/src/index.js +84 -60
  68. package/src/nfce/builders/NFCeXmlBuilder.js +178 -178
  69. package/src/nfce/constants/qrcode.js +26 -26
  70. package/src/nfce/services/NFCeService.js +188 -188
  71. package/src/nfce/services/NFCeXmlService.js +38 -38
  72. package/src/nfce/types/NFCeDocument.js +42 -42
  73. package/src/nfce/utils/qrcode.utils.js +92 -92
  74. package/src/nfe/builders/NFeEventoXmlBuilder.js +110 -110
  75. package/src/nfe/builders/NFeXmlBuilder.js +215 -215
  76. package/src/nfe/mocks/sefaz-responses.js +195 -195
  77. package/src/nfe/services/NFeEventoService.js +95 -95
  78. package/src/nfe/services/NFeService.js +196 -196
  79. package/src/nfe/services/NFeSignService.js +127 -111
  80. package/src/nfe/services/NFeSoapService.js +437 -437
  81. package/src/nfe/services/NFeXmlService.js +41 -41
  82. package/src/nfe/services/NFeXsdService.js +56 -56
  83. package/src/nfe/types/NFeDocument.js +92 -92
  84. package/src/nfe/types/NFeEvento.js +44 -44
  85. package/src/nfse/NFSeMunicipioResolver.js +42 -42
  86. package/src/nfse/builders/NFSeEventoXmlBuilder.js +92 -92
  87. package/src/nfse/builders/NFSeXmlBuilder.js +16 -16
  88. package/src/nfse/constants/municipios.js +82 -82
  89. package/src/nfse/layouts/adapters.js +202 -202
  90. package/src/nfse/mocks/nfse-responses.js +142 -142
  91. package/src/nfse/services/NFSeService.js +191 -191
  92. package/src/nfse/services/NFSeSoapService.js +232 -232
  93. package/src/nfse/services/NFSeXmlService.js +12 -12
  94. package/src/nfse/types/NFSeDocument.js +54 -54
  95. package/src/queue/NFCeQueue.js +63 -63
  96. package/src/queue/NFSeQueue.js +59 -59
  97. package/src/queue/NFeQueue.js +76 -76
  98. package/src/reforma/ibscbs.js +175 -175
  99. package/src/sefaz/SefazEndpointResolver.js +95 -95
  100. package/src/sefaz/ca/icp-brasil-raiz-v10.pem +38 -0
  101. package/src/sefaz/endpoints.registry.js +205 -205
  102. package/src/sefaz/httpsAgent.js +33 -0
  103. package/src/shared/fiscal.helpers.js +53 -53
  104. package/src/utils/certificate.utils.js +69 -47
  105. package/src/utils/chave.utils.js +205 -117
  106. package/src/utils/code128.utils.js +67 -0
  107. package/src/utils/date.utils.js +26 -26
  108. package/src/utils/xml.utils.js +44 -44
  109. package/src/validation/XsdValidator.js +133 -114
  110. package/src/validation/schemas.js +18 -14
@@ -0,0 +1,98 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <!-- ***************************************************-->
3
+ <!-- *** Schema específico para assinaturas XML ***-->
4
+ <!-- *** a partir de certificados do padrão (X509) ***-->
5
+ <!-- *** ICP-Brasil - Projeto Nota Fiscal Eletrônica ***-->
6
+ <!-- ***************************************************-->
7
+ <!-- Schema for XML Signatures-->
8
+ <schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" targetNamespace="http://www.w3.org/2000/09/xmldsig#" elementFormDefault="qualified" attributeFormDefault="unqualified" version="0.1">
9
+ <element name="Signature" type="ds:SignatureType"/>
10
+ <complexType name="SignatureType">
11
+ <sequence>
12
+ <element name="SignedInfo" type="ds:SignedInfoType"/>
13
+ <element name="SignatureValue" type="ds:SignatureValueType"/>
14
+ <element name="KeyInfo" type="ds:KeyInfoType"/>
15
+ </sequence>
16
+ <attribute name="Id" type="ID" use="optional"/>
17
+ </complexType>
18
+ <complexType name="SignatureValueType">
19
+ <simpleContent>
20
+ <extension base="base64Binary">
21
+ <attribute name="Id" type="ID" use="optional"/>
22
+ </extension>
23
+ </simpleContent>
24
+ </complexType>
25
+ <complexType name="SignedInfoType">
26
+ <sequence>
27
+ <element name="CanonicalizationMethod">
28
+ <complexType>
29
+ <attribute name="Algorithm" type="anyURI" use="required" fixed="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/>
30
+ </complexType>
31
+ </element>
32
+ <element name="SignatureMethod">
33
+ <complexType>
34
+ <attribute name="Algorithm" type="anyURI" use="required" fixed="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/>
35
+ </complexType>
36
+ </element>
37
+ <element name="Reference" type="ds:ReferenceType"/>
38
+ </sequence>
39
+ <attribute name="Id" type="ID" use="optional"/>
40
+ </complexType>
41
+ <complexType name="ReferenceType">
42
+ <sequence>
43
+ <element name="Transforms" type="ds:TransformsType">
44
+ <!-- Garante a unicidade do atributo -->
45
+ <unique name="unique_Transf_Alg">
46
+ <selector xpath="./*"/>
47
+ <field xpath="@Algorithm"/>
48
+ </unique>
49
+ </element>
50
+ <element name="DigestMethod">
51
+ <complexType>
52
+ <attribute name="Algorithm" type="anyURI" use="required" fixed="http://www.w3.org/2000/09/xmldsig#sha1"/>
53
+ </complexType>
54
+ </element>
55
+ <element name="DigestValue" type="ds:DigestValueType"/>
56
+ </sequence>
57
+ <attribute name="Id" type="ID" use="optional"/>
58
+ <attribute name="URI" use="required">
59
+ <simpleType>
60
+ <restriction base="anyURI">
61
+ <minLength value="2"/>
62
+ </restriction>
63
+ </simpleType>
64
+ </attribute>
65
+ <attribute name="Type" type="anyURI" use="optional"/>
66
+ </complexType>
67
+ <complexType name="TransformsType">
68
+ <sequence>
69
+ <element name="Transform" type="ds:TransformType" minOccurs="2" maxOccurs="2"/>
70
+ </sequence>
71
+ </complexType>
72
+ <complexType name="TransformType">
73
+ <sequence minOccurs="0" maxOccurs="unbounded">
74
+ <element name="XPath" type="string"/>
75
+ </sequence>
76
+ <attribute name="Algorithm" type="ds:TTransformURI" use="required"/>
77
+ </complexType>
78
+ <complexType name="KeyInfoType">
79
+ <sequence>
80
+ <element name="X509Data" type="ds:X509DataType"/>
81
+ </sequence>
82
+ <attribute name="Id" type="ID" use="optional"/>
83
+ </complexType>
84
+ <complexType name="X509DataType">
85
+ <sequence>
86
+ <element name="X509Certificate" type="base64Binary"/>
87
+ </sequence>
88
+ </complexType>
89
+ <simpleType name="DigestValueType">
90
+ <restriction base="base64Binary"/>
91
+ </simpleType>
92
+ <simpleType name="TTransformURI">
93
+ <restriction base="anyURI">
94
+ <enumeration value="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/>
95
+ <enumeration value="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/>
96
+ </restriction>
97
+ </simpleType>
98
+ </schema>
@@ -1,9 +1,9 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.portalfiscal.inf.br/nfe" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" targetNamespace="http://www.portalfiscal.inf.br/nfe" elementFormDefault="qualified" attributeFormDefault="unqualified">
3
- <xs:include schemaLocation="leiauteNFe_v3.10.xsd"/>
4
- <xs:element name="enviNFe" type="TEnviNFe">
5
- <xs:annotation>
6
- <xs:documentation>Schema XML de validação do Pedido de Concessão de Autorização da Nota Fiscal Eletrônica</xs:documentation>
7
- </xs:annotation>
8
- </xs:element>
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.portalfiscal.inf.br/nfe" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" targetNamespace="http://www.portalfiscal.inf.br/nfe" elementFormDefault="qualified" attributeFormDefault="unqualified">
3
+ <xs:include schemaLocation="leiauteNFe_v3.10.xsd"/>
4
+ <xs:element name="enviNFe" type="TEnviNFe">
5
+ <xs:annotation>
6
+ <xs:documentation>Schema XML de validação do Pedido de Concessão de Autorização da Nota Fiscal Eletrônica</xs:documentation>
7
+ </xs:annotation>
8
+ </xs:element>
9
9
  </xs:schema>
@@ -1,98 +1,98 @@
1
- <?xml version="1.0" encoding="utf-8"?>
2
- <!-- ***************************************************-->
3
- <!-- *** Schema específico para assinaturas XML ***-->
4
- <!-- *** a partir de certificados do padrão (X509) ***-->
5
- <!-- *** ICP-Brasil - Projeto Nota Fiscal Eletrônica ***-->
6
- <!-- ***************************************************-->
7
- <!-- Schema for XML Signatures-->
8
- <schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" targetNamespace="http://www.w3.org/2000/09/xmldsig#" elementFormDefault="qualified" attributeFormDefault="unqualified" version="0.1">
9
- <element name="Signature" type="ds:SignatureType"/>
10
- <complexType name="SignatureType">
11
- <sequence>
12
- <element name="SignedInfo" type="ds:SignedInfoType"/>
13
- <element name="SignatureValue" type="ds:SignatureValueType"/>
14
- <element name="KeyInfo" type="ds:KeyInfoType"/>
15
- </sequence>
16
- <attribute name="Id" type="ID" use="optional"/>
17
- </complexType>
18
- <complexType name="SignatureValueType">
19
- <simpleContent>
20
- <extension base="base64Binary">
21
- <attribute name="Id" type="ID" use="optional"/>
22
- </extension>
23
- </simpleContent>
24
- </complexType>
25
- <complexType name="SignedInfoType">
26
- <sequence>
27
- <element name="CanonicalizationMethod">
28
- <complexType>
29
- <attribute name="Algorithm" type="anyURI" use="required" fixed="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/>
30
- </complexType>
31
- </element>
32
- <element name="SignatureMethod">
33
- <complexType>
34
- <attribute name="Algorithm" type="anyURI" use="required" fixed="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/>
35
- </complexType>
36
- </element>
37
- <element name="Reference" type="ds:ReferenceType"/>
38
- </sequence>
39
- <attribute name="Id" type="ID" use="optional"/>
40
- </complexType>
41
- <complexType name="ReferenceType">
42
- <sequence>
43
- <element name="Transforms" type="ds:TransformsType">
44
- <!-- Garante a unicidade do atributo -->
45
- <unique name="unique_Transf_Alg">
46
- <selector xpath="./*"/>
47
- <field xpath="@Algorithm"/>
48
- </unique>
49
- </element>
50
- <element name="DigestMethod">
51
- <complexType>
52
- <attribute name="Algorithm" type="anyURI" use="required" fixed="http://www.w3.org/2000/09/xmldsig#sha1"/>
53
- </complexType>
54
- </element>
55
- <element name="DigestValue" type="ds:DigestValueType"/>
56
- </sequence>
57
- <attribute name="Id" type="ID" use="optional"/>
58
- <attribute name="URI" use="required">
59
- <simpleType>
60
- <restriction base="anyURI">
61
- <minLength value="2"/>
62
- </restriction>
63
- </simpleType>
64
- </attribute>
65
- <attribute name="Type" type="anyURI" use="optional"/>
66
- </complexType>
67
- <complexType name="TransformsType">
68
- <sequence>
69
- <element name="Transform" type="ds:TransformType" minOccurs="2" maxOccurs="2"/>
70
- </sequence>
71
- </complexType>
72
- <complexType name="TransformType">
73
- <sequence minOccurs="0" maxOccurs="unbounded">
74
- <element name="XPath" type="string"/>
75
- </sequence>
76
- <attribute name="Algorithm" type="ds:TTransformURI" use="required"/>
77
- </complexType>
78
- <complexType name="KeyInfoType">
79
- <sequence>
80
- <element name="X509Data" type="ds:X509DataType"/>
81
- </sequence>
82
- <attribute name="Id" type="ID" use="optional"/>
83
- </complexType>
84
- <complexType name="X509DataType">
85
- <sequence>
86
- <element name="X509Certificate" type="base64Binary"/>
87
- </sequence>
88
- </complexType>
89
- <simpleType name="DigestValueType">
90
- <restriction base="base64Binary"/>
91
- </simpleType>
92
- <simpleType name="TTransformURI">
93
- <restriction base="anyURI">
94
- <enumeration value="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/>
95
- <enumeration value="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/>
96
- </restriction>
97
- </simpleType>
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <!-- ***************************************************-->
3
+ <!-- *** Schema específico para assinaturas XML ***-->
4
+ <!-- *** a partir de certificados do padrão (X509) ***-->
5
+ <!-- *** ICP-Brasil - Projeto Nota Fiscal Eletrônica ***-->
6
+ <!-- ***************************************************-->
7
+ <!-- Schema for XML Signatures-->
8
+ <schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" targetNamespace="http://www.w3.org/2000/09/xmldsig#" elementFormDefault="qualified" attributeFormDefault="unqualified" version="0.1">
9
+ <element name="Signature" type="ds:SignatureType"/>
10
+ <complexType name="SignatureType">
11
+ <sequence>
12
+ <element name="SignedInfo" type="ds:SignedInfoType"/>
13
+ <element name="SignatureValue" type="ds:SignatureValueType"/>
14
+ <element name="KeyInfo" type="ds:KeyInfoType"/>
15
+ </sequence>
16
+ <attribute name="Id" type="ID" use="optional"/>
17
+ </complexType>
18
+ <complexType name="SignatureValueType">
19
+ <simpleContent>
20
+ <extension base="base64Binary">
21
+ <attribute name="Id" type="ID" use="optional"/>
22
+ </extension>
23
+ </simpleContent>
24
+ </complexType>
25
+ <complexType name="SignedInfoType">
26
+ <sequence>
27
+ <element name="CanonicalizationMethod">
28
+ <complexType>
29
+ <attribute name="Algorithm" type="anyURI" use="required" fixed="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/>
30
+ </complexType>
31
+ </element>
32
+ <element name="SignatureMethod">
33
+ <complexType>
34
+ <attribute name="Algorithm" type="anyURI" use="required" fixed="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/>
35
+ </complexType>
36
+ </element>
37
+ <element name="Reference" type="ds:ReferenceType"/>
38
+ </sequence>
39
+ <attribute name="Id" type="ID" use="optional"/>
40
+ </complexType>
41
+ <complexType name="ReferenceType">
42
+ <sequence>
43
+ <element name="Transforms" type="ds:TransformsType">
44
+ <!-- Garante a unicidade do atributo -->
45
+ <unique name="unique_Transf_Alg">
46
+ <selector xpath="./*"/>
47
+ <field xpath="@Algorithm"/>
48
+ </unique>
49
+ </element>
50
+ <element name="DigestMethod">
51
+ <complexType>
52
+ <attribute name="Algorithm" type="anyURI" use="required" fixed="http://www.w3.org/2000/09/xmldsig#sha1"/>
53
+ </complexType>
54
+ </element>
55
+ <element name="DigestValue" type="ds:DigestValueType"/>
56
+ </sequence>
57
+ <attribute name="Id" type="ID" use="optional"/>
58
+ <attribute name="URI" use="required">
59
+ <simpleType>
60
+ <restriction base="anyURI">
61
+ <minLength value="2"/>
62
+ </restriction>
63
+ </simpleType>
64
+ </attribute>
65
+ <attribute name="Type" type="anyURI" use="optional"/>
66
+ </complexType>
67
+ <complexType name="TransformsType">
68
+ <sequence>
69
+ <element name="Transform" type="ds:TransformType" minOccurs="2" maxOccurs="2"/>
70
+ </sequence>
71
+ </complexType>
72
+ <complexType name="TransformType">
73
+ <sequence minOccurs="0" maxOccurs="unbounded">
74
+ <element name="XPath" type="string"/>
75
+ </sequence>
76
+ <attribute name="Algorithm" type="ds:TTransformURI" use="required"/>
77
+ </complexType>
78
+ <complexType name="KeyInfoType">
79
+ <sequence>
80
+ <element name="X509Data" type="ds:X509DataType"/>
81
+ </sequence>
82
+ <attribute name="Id" type="ID" use="optional"/>
83
+ </complexType>
84
+ <complexType name="X509DataType">
85
+ <sequence>
86
+ <element name="X509Certificate" type="base64Binary"/>
87
+ </sequence>
88
+ </complexType>
89
+ <simpleType name="DigestValueType">
90
+ <restriction base="base64Binary"/>
91
+ </simpleType>
92
+ <simpleType name="TTransformURI">
93
+ <restriction base="anyURI">
94
+ <enumeration value="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/>
95
+ <enumeration value="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/>
96
+ </restriction>
97
+ </simpleType>
98
98
  </schema>
@@ -1,39 +1,39 @@
1
- /**
2
- * Baixa schemas XSD oficiais NF-e/NFC-e (PL_009_V4) do repositório nfephp-org/sped-nfe.
3
- * Execute: node scripts/download-schemas.js
4
- */
5
- import fs from 'fs';
6
- import path from 'path';
7
- import { fileURLToPath } from 'url';
8
-
9
- const __dirname = path.dirname(fileURLToPath(import.meta.url));
10
- const OUT_DIR = path.resolve(__dirname, '../schemas/nfe/PL_009_V4');
11
- const BASE = 'https://raw.githubusercontent.com/nfephp-org/sped-nfe/master/schemes/PL_009_V4';
12
-
13
- const FILES = [
14
- 'nfe_v4.00.xsd',
15
- 'leiauteNFe_v4.00.xsd',
16
- 'tiposBasico_v4.00.xsd',
17
- 'xmldsig-core-schema_v1.01.xsd',
18
- 'enviNFe_v4.00.xsd',
19
- 'inutNFe_v4.00.xsd',
20
- 'consReciNFe_v4.00.xsd',
21
- 'consSitNFe_v4.00.xsd',
22
- 'consStatServ_v4.00.xsd',
23
- ];
24
-
25
- fs.mkdirSync(OUT_DIR, { recursive: true });
26
-
27
- for (const file of FILES) {
28
- const url = `${BASE}/${file}`;
29
- const dest = path.join(OUT_DIR, file);
30
- const res = await fetch(url);
31
- if (!res.ok) {
32
- console.warn(`⚠ Não foi possível baixar: ${file}`);
33
- continue;
34
- }
35
- fs.writeFileSync(dest, await res.text());
36
- console.log(`✓ ${file}`);
37
- }
38
-
39
- console.log(`\nSchemas salvos em: ${OUT_DIR}`);
1
+ /**
2
+ * Baixa schemas XSD oficiais NF-e/NFC-e (PL_009_V4) do repositório nfephp-org/sped-nfe.
3
+ * Execute: node scripts/download-schemas.js
4
+ */
5
+ import fs from 'fs';
6
+ import path from 'path';
7
+ import { fileURLToPath } from 'url';
8
+
9
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
10
+ const OUT_DIR = path.resolve(__dirname, '../schemas/nfe/PL_009_V4');
11
+ const BASE = 'https://raw.githubusercontent.com/nfephp-org/sped-nfe/master/schemes/PL_009_V4';
12
+
13
+ const FILES = [
14
+ 'nfe_v4.00.xsd',
15
+ 'leiauteNFe_v4.00.xsd',
16
+ 'tiposBasico_v4.00.xsd',
17
+ 'xmldsig-core-schema_v1.01.xsd',
18
+ 'enviNFe_v4.00.xsd',
19
+ 'inutNFe_v4.00.xsd',
20
+ 'consReciNFe_v4.00.xsd',
21
+ 'consSitNFe_v4.00.xsd',
22
+ 'consStatServ_v4.00.xsd',
23
+ ];
24
+
25
+ fs.mkdirSync(OUT_DIR, { recursive: true });
26
+
27
+ for (const file of FILES) {
28
+ const url = `${BASE}/${file}`;
29
+ const dest = path.join(OUT_DIR, file);
30
+ const res = await fetch(url);
31
+ if (!res.ok) {
32
+ console.warn(`⚠ Não foi possível baixar: ${file}`);
33
+ continue;
34
+ }
35
+ fs.writeFileSync(dest, await res.text());
36
+ console.log(`✓ ${file}`);
37
+ }
38
+
39
+ console.log(`\nSchemas salvos em: ${OUT_DIR}`);
@@ -1,34 +1,34 @@
1
- import libxmljs from 'libxmljs2';
2
- import fs from 'fs';
3
- import path from 'path';
4
- import { pathToFileURL } from 'url';
5
- import { NFeService } from '../src/index.js';
6
-
7
- const dir = path.resolve('schemas/nfe/PL_009_V4');
8
- const baseUrl = pathToFileURL(dir + path.sep).href;
9
- const xsd = libxmljs.parseXml(fs.readFileSync(path.join(dir, 'nfe_v4.00.xsd'), 'utf8'), { baseUrl });
10
-
11
- const documento = {
12
- chaveAcesso: '35260712345678000199550010000000011000000011',
13
- ambiente: 2,
14
- ide: { uf: 'SP', codigoMunicipio: '3550308', serie: 1, numero: 1 },
15
- emitente: {
16
- cnpj: '12345678000199', razaoSocial: 'EMPRESA EXEMPLO LTDA', ie: '123456789012', crt: '3',
17
- endereco: { logradouro: 'Rua Exemplo', numero: '100', bairro: 'Centro', codigoMunicipio: '3550308', municipio: 'Sao Paulo', uf: 'SP', cep: '01001000' },
18
- },
19
- destinatario: {
20
- cpf: '12345678909', razaoSocial: 'CONSUMIDOR', indIEDest: 9,
21
- endereco: { logradouro: 'Rua B', numero: '2', bairro: 'Centro', codigoMunicipio: '3550308', municipio: 'Sao Paulo', uf: 'SP', cep: '01001000' },
22
- },
23
- itens: [{ codigo: '001', descricao: 'PRODUTO TESTE', ncm: '84713012', cfop: '5102', unidade: 'UN', quantidade: 1, valorUnitario: 100, valorTotal: 100 }],
24
- };
25
-
26
- let xml = new NFeService().gerarXml(documento);
27
- const id = `NFe${documento.chaveAcesso}`;
28
- const stub = `<Signature xmlns="http://www.w3.org/2000/09/xmldsig#"><SignedInfo><CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/><SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/><Reference URI="#${id}"><Transforms><Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/><Transform Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/></Transforms><DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/><DigestValue>ZHVtbXk=</DigestValue></Reference></SignedInfo><SignatureValue>ZHVtbXk=</SignatureValue><KeyInfo><X509Data><X509Certificate>ZHVtbXk=</X509Certificate></X509Data></KeyInfo></Signature>`;
29
- xml = xml.replace('</NFe>', `${stub}</NFe>`);
30
-
31
- const doc = libxmljs.parseXml(xml);
32
- const valid = doc.validate(xsd);
33
- console.log('valid:', valid);
34
- if (!valid) doc.validationErrors.forEach((e) => console.log(e.message));
1
+ import libxmljs from 'libxmljs2';
2
+ import fs from 'fs';
3
+ import path from 'path';
4
+ import { pathToFileURL } from 'url';
5
+ import { NFeService } from '../src/index.js';
6
+
7
+ const dir = path.resolve('schemas/nfe/PL_009_V4');
8
+ const baseUrl = pathToFileURL(dir + path.sep).href;
9
+ const xsd = libxmljs.parseXml(fs.readFileSync(path.join(dir, 'nfe_v4.00.xsd'), 'utf8'), { baseUrl });
10
+
11
+ const documento = {
12
+ chaveAcesso: '35260712345678000199550010000000011000000011',
13
+ ambiente: 2,
14
+ ide: { uf: 'SP', codigoMunicipio: '3550308', serie: 1, numero: 1 },
15
+ emitente: {
16
+ cnpj: '12345678000199', razaoSocial: 'EMPRESA EXEMPLO LTDA', ie: '123456789012', crt: '3',
17
+ endereco: { logradouro: 'Rua Exemplo', numero: '100', bairro: 'Centro', codigoMunicipio: '3550308', municipio: 'Sao Paulo', uf: 'SP', cep: '01001000' },
18
+ },
19
+ destinatario: {
20
+ cpf: '12345678909', razaoSocial: 'CONSUMIDOR', indIEDest: 9,
21
+ endereco: { logradouro: 'Rua B', numero: '2', bairro: 'Centro', codigoMunicipio: '3550308', municipio: 'Sao Paulo', uf: 'SP', cep: '01001000' },
22
+ },
23
+ itens: [{ codigo: '001', descricao: 'PRODUTO TESTE', ncm: '84713012', cfop: '5102', unidade: 'UN', quantidade: 1, valorUnitario: 100, valorTotal: 100 }],
24
+ };
25
+
26
+ let xml = new NFeService().gerarXml(documento);
27
+ const id = `NFe${documento.chaveAcesso}`;
28
+ const stub = `<Signature xmlns="http://www.w3.org/2000/09/xmldsig#"><SignedInfo><CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/><SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/><Reference URI="#${id}"><Transforms><Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/><Transform Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/></Transforms><DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/><DigestValue>ZHVtbXk=</DigestValue></Reference></SignedInfo><SignatureValue>ZHVtbXk=</SignatureValue><KeyInfo><X509Data><X509Certificate>ZHVtbXk=</X509Certificate></X509Data></KeyInfo></Signature>`;
29
+ xml = xml.replace('</NFe>', `${stub}</NFe>`);
30
+
31
+ const doc = libxmljs.parseXml(xml);
32
+ const valid = doc.validate(xsd);
33
+ console.log('valid:', valid);
34
+ if (!valid) doc.validationErrors.forEach((e) => console.log(e.message));