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.
- package/.env.example +24 -15
- package/LICENSE +21 -21
- package/README.md +491 -413
- package/docs/developer-guide.html +421 -421
- package/docs/openapi.yaml +428 -428
- package/examples/dce-homologacao.js +141 -0
- package/examples/emitir-nfce.js +51 -51
- package/examples/emitir-nfe.js +83 -83
- package/examples/emitir-nfse.js +46 -46
- package/examples/endpoints-sefaz.js +14 -14
- package/examples/eventos-nfe.js +49 -49
- package/examples/gerar-chave.js +25 -25
- package/examples/gerar-dace.js +59 -0
- package/examples/gerar-danfe.js +75 -75
- package/examples/gerar-dce.js +58 -0
- package/examples/layouts-nfse.js +51 -51
- package/examples/mock-sefaz.js +52 -52
- package/examples/nfse-eventos.js +57 -57
- package/examples/reforma-ibscbs.js +27 -27
- package/examples/reforma-nfe-xml.js +52 -52
- package/examples/status-sefaz.js +12 -12
- package/examples/validar-xsd.js +48 -48
- package/package.json +59 -68
- package/schemas/dce/PL_DCe_100a_NT2024.001/consulta/consSitDCeTiposBasico_v1.00.xsd +123 -0
- package/schemas/dce/PL_DCe_100a_NT2024.001/consulta/consSitDCe_v1.00.xsd +10 -0
- package/schemas/dce/PL_DCe_100a_NT2024.001/consulta/consStatServDCeTiposBasico_v1.00.xsd +110 -0
- package/schemas/dce/PL_DCe_100a_NT2024.001/consulta/consStatServDCe_v1.00.xsd +10 -0
- package/schemas/dce/PL_DCe_100a_NT2024.001/consulta/dceTiposBasico_v1.00.xsd +1388 -0
- package/schemas/dce/PL_DCe_100a_NT2024.001/consulta/retConsSitDCe_v1.00.xsd +10 -0
- package/schemas/dce/PL_DCe_100a_NT2024.001/consulta/retConsStatServDCe_v1.00.xsd +10 -0
- package/schemas/dce/PL_DCe_100a_NT2024.001/consulta/tiposGeralDCe_v1.00.xsd +712 -0
- package/schemas/dce/PL_DCe_100a_NT2024.001/consulta/xmldsig-core-schema_v1.01.xsd +98 -0
- package/schemas/dce/PL_DCe_100a_NT2024.001/dceTiposBasico_v1.00.xsd +1410 -0
- package/schemas/dce/PL_DCe_100a_NT2024.001/dce_v1.00.xsd +10 -0
- package/schemas/dce/PL_DCe_100a_NT2024.001/evento/evCancDCe_v1.00.xsd +36 -0
- package/schemas/dce/PL_DCe_100a_NT2024.001/evento/eventoDCeTiposBasico_v1.00.xsd +283 -0
- package/schemas/dce/PL_DCe_100a_NT2024.001/evento/eventoDCe_v1.00.xsd +9 -0
- package/schemas/dce/PL_DCe_100a_NT2024.001/evento/procEventoDCe_v1.00.xsd +10 -0
- package/schemas/dce/PL_DCe_100a_NT2024.001/evento/retEventoDCe_v1.00.xsd +9 -0
- package/schemas/dce/PL_DCe_100a_NT2024.001/evento/tiposGeralDCe_v1.00.xsd +712 -0
- package/schemas/dce/PL_DCe_100a_NT2024.001/evento/xmldsig-core-schema_v1.01.xsd +98 -0
- package/schemas/dce/PL_DCe_100a_NT2024.001/procDCe_v1.00.xsd +37 -0
- package/schemas/dce/PL_DCe_100a_NT2024.001/retDCe_v1.00.xsd +9 -0
- package/schemas/dce/PL_DCe_100a_NT2024.001/tiposGeralDCe_v1.00.xsd +712 -0
- package/schemas/dce/PL_DCe_100a_NT2024.001/xmldsig-core-schema_v1.01.xsd +98 -0
- package/schemas/nfe/PL_009_V4/enviNFe_v3.10.xsd +8 -8
- package/schemas/nfe/PL_009_V4/xmldsig-core-schema_v1.01.xsd +97 -97
- package/scripts/download-schemas.js +39 -39
- package/scripts/test-xsd.js +34 -34
- package/src/api/server.js +316 -316
- package/src/constants/sefaz.js +69 -69
- package/src/danfe/DanfeService.js +205 -205
- package/src/danfe/xml-extract.js +69 -69
- package/src/dce/builders/DCeEventoXmlBuilder.js +86 -0
- package/src/dce/builders/DCeXmlBuilder.js +345 -0
- package/src/dce/constants/dce.js +87 -0
- package/src/dce/dace/DaceService.js +356 -0
- package/src/dce/dace/dace-extract.js +114 -0
- package/src/dce/services/DCeService.js +263 -0
- package/src/dce/services/DCeSoapService.js +235 -0
- package/src/dce/services/DCeXmlService.js +67 -0
- package/src/dce/types/DCeDocument.js +106 -0
- package/src/dce/utils/qrcode.utils.js +59 -0
- package/src/errors/GhinfeError.js +13 -13
- package/src/errors/SefazError.js +25 -25
- package/src/errors/XsdValidationError.js +15 -15
- package/src/index.js +84 -60
- package/src/nfce/builders/NFCeXmlBuilder.js +178 -178
- package/src/nfce/constants/qrcode.js +26 -26
- package/src/nfce/services/NFCeService.js +188 -188
- package/src/nfce/services/NFCeXmlService.js +38 -38
- package/src/nfce/types/NFCeDocument.js +42 -42
- package/src/nfce/utils/qrcode.utils.js +92 -92
- package/src/nfe/builders/NFeEventoXmlBuilder.js +110 -110
- package/src/nfe/builders/NFeXmlBuilder.js +215 -215
- package/src/nfe/mocks/sefaz-responses.js +195 -195
- package/src/nfe/services/NFeEventoService.js +95 -95
- package/src/nfe/services/NFeService.js +196 -196
- package/src/nfe/services/NFeSignService.js +127 -111
- package/src/nfe/services/NFeSoapService.js +437 -437
- package/src/nfe/services/NFeXmlService.js +41 -41
- package/src/nfe/services/NFeXsdService.js +56 -56
- package/src/nfe/types/NFeDocument.js +92 -92
- package/src/nfe/types/NFeEvento.js +44 -44
- package/src/nfse/NFSeMunicipioResolver.js +42 -42
- package/src/nfse/builders/NFSeEventoXmlBuilder.js +92 -92
- package/src/nfse/builders/NFSeXmlBuilder.js +16 -16
- package/src/nfse/constants/municipios.js +82 -82
- package/src/nfse/layouts/adapters.js +202 -202
- package/src/nfse/mocks/nfse-responses.js +142 -142
- package/src/nfse/services/NFSeService.js +191 -191
- package/src/nfse/services/NFSeSoapService.js +232 -232
- package/src/nfse/services/NFSeXmlService.js +12 -12
- package/src/nfse/types/NFSeDocument.js +54 -54
- package/src/queue/NFCeQueue.js +63 -63
- package/src/queue/NFSeQueue.js +59 -59
- package/src/queue/NFeQueue.js +76 -76
- package/src/reforma/ibscbs.js +175 -175
- package/src/sefaz/SefazEndpointResolver.js +95 -95
- package/src/sefaz/ca/icp-brasil-raiz-v10.pem +38 -0
- package/src/sefaz/endpoints.registry.js +205 -205
- package/src/sefaz/httpsAgent.js +33 -0
- package/src/shared/fiscal.helpers.js +53 -53
- package/src/utils/certificate.utils.js +69 -47
- package/src/utils/chave.utils.js +205 -117
- package/src/utils/code128.utils.js +67 -0
- package/src/utils/date.utils.js +26 -26
- package/src/utils/xml.utils.js +44 -44
- package/src/validation/XsdValidator.js +133 -114
- package/src/validation/schemas.js +18 -14
|
@@ -1,205 +1,205 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Mapeamento UF → autorizador SEFAZ (NF-e/NFC-e).
|
|
3
|
-
* Fonte: Manual de Orientação do Contribuinte / tabela de autorizadores.
|
|
4
|
-
*/
|
|
5
|
-
export const UF_AUTORIZADOR = {
|
|
6
|
-
AC: 'SVRS', AL: 'SVRS', AM: 'AM', AP: 'SVRS', BA: 'BA',
|
|
7
|
-
CE: 'SVRS', DF: 'SVRS', ES: 'SVRS', GO: 'GO', MA: 'SVAN',
|
|
8
|
-
MG: 'MG', MS: 'MS', MT: 'MT', PA: 'SVAN', PB: 'SVRS',
|
|
9
|
-
PE: 'PE', PI: 'SVRS', PR: 'PR', RJ: 'SVRS', RN: 'SVRS',
|
|
10
|
-
RO: 'SVRS', RR: 'SVRS', RS: 'RS', SC: 'SVRS', SE: 'SVRS',
|
|
11
|
-
SP: 'SP', TO: 'SVRS',
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
/** Tipos de webservice SEFAZ. */
|
|
15
|
-
export const SEFAZ_SERVICO = {
|
|
16
|
-
AUTORIZACAO: 'autorizacao',
|
|
17
|
-
RET_AUTORIZACAO: 'retAutorizacao',
|
|
18
|
-
CONSULTA: 'consulta',
|
|
19
|
-
EVENTO: 'evento',
|
|
20
|
-
INUTILIZACAO: 'inutilizacao',
|
|
21
|
-
STATUS: 'status',
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Endpoints por autorizador e ambiente.
|
|
26
|
-
* ambiente: 1=Produção, 2=Homologação
|
|
27
|
-
*/
|
|
28
|
-
export const AUTORIZADOR_ENDPOINTS = {
|
|
29
|
-
SVRS: {
|
|
30
|
-
1: {
|
|
31
|
-
autorizacao: 'https://nfe.svrs.rs.gov.br/ws/NfeAutorizacao/NFeAutorizacao4.asmx',
|
|
32
|
-
retAutorizacao: 'https://nfe.svrs.rs.gov.br/ws/NfeRetAutorizacao/NFeRetAutorizacao4.asmx',
|
|
33
|
-
consulta: 'https://nfe.svrs.rs.gov.br/ws/NfeConsulta/NfeConsulta4.asmx',
|
|
34
|
-
evento: 'https://nfe.svrs.rs.gov.br/ws/recepcaoevento/ReceptionEvent4.asmx',
|
|
35
|
-
inutilizacao: 'https://nfe.svrs.rs.gov.br/ws/nfeinutilizacao/nfeinutilizacao4.asmx',
|
|
36
|
-
status: 'https://nfe.svrs.rs.gov.br/ws/NfeStatusServico/NfeStatusServico4.asmx',
|
|
37
|
-
},
|
|
38
|
-
2: {
|
|
39
|
-
autorizacao: 'https://nfe-homologacao.svrs.rs.gov.br/ws/NfeAutorizacao/NFeAutorizacao4.asmx',
|
|
40
|
-
retAutorizacao: 'https://nfe-homologacao.svrs.rs.gov.br/ws/NfeRetAutorizacao/NFeRetAutorizacao4.asmx',
|
|
41
|
-
consulta: 'https://nfe-homologacao.svrs.rs.gov.br/ws/NfeConsulta/NfeConsulta4.asmx',
|
|
42
|
-
evento: 'https://nfe-homologacao.svrs.rs.gov.br/ws/recepcaoevento/ReceptionEvent4.asmx',
|
|
43
|
-
inutilizacao: 'https://nfe-homologacao.svrs.rs.gov.br/ws/nfeinutilizacao/nfeinutilizacao4.asmx',
|
|
44
|
-
status: 'https://nfe-homologacao.svrs.rs.gov.br/ws/NfeStatusServico/NfeStatusServico4.asmx',
|
|
45
|
-
},
|
|
46
|
-
},
|
|
47
|
-
SVAN: {
|
|
48
|
-
1: {
|
|
49
|
-
autorizacao: 'https://www.sefazvirtual.fazenda.gov.br/NFeAutorizacao4/NFeAutorizacao4.asmx',
|
|
50
|
-
retAutorizacao: 'https://www.sefazvirtual.fazenda.gov.br/NFeRetAutorizacao4/NFeRetAutorizacao4.asmx',
|
|
51
|
-
consulta: 'https://www.sefazvirtual.fazenda.gov.br/NFeConsultaProtocolo4/NFeConsultaProtocolo4.asmx',
|
|
52
|
-
evento: 'https://www.sefazvirtual.fazenda.gov.br/NFeRecepcaoEvento4/NFeRecepcaoEvento4.asmx',
|
|
53
|
-
inutilizacao: 'https://www.sefazvirtual.fazenda.gov.br/NFeInutilizacao4/NFeInutilizacao4.asmx',
|
|
54
|
-
status: 'https://www.sefazvirtual.fazenda.gov.br/NFeStatusServico4/NFeStatusServico4.asmx',
|
|
55
|
-
},
|
|
56
|
-
2: {
|
|
57
|
-
autorizacao: 'https://hom.sefazvirtual.fazenda.gov.br/NFeAutorizacao4/NFeAutorizacao4.asmx',
|
|
58
|
-
retAutorizacao: 'https://hom.sefazvirtual.fazenda.gov.br/NFeRetAutorizacao4/NFeRetAutorizacao4.asmx',
|
|
59
|
-
consulta: 'https://hom.sefazvirtual.fazenda.gov.br/NFeConsultaProtocolo4/NFeConsultaProtocolo4.asmx',
|
|
60
|
-
evento: 'https://hom.sefazvirtual.fazenda.gov.br/NFeRecepcaoEvento4/NFeRecepcaoEvento4.asmx',
|
|
61
|
-
inutilizacao: 'https://hom.sefazvirtual.fazenda.gov.br/NFeInutilizacao4/NFeInutilizacao4.asmx',
|
|
62
|
-
status: 'https://hom.sefazvirtual.fazenda.gov.br/NFeStatusServico4/NFeStatusServico4.asmx',
|
|
63
|
-
},
|
|
64
|
-
},
|
|
65
|
-
SP: {
|
|
66
|
-
1: {
|
|
67
|
-
autorizacao: 'https://nfe.fazenda.sp.gov.br/ws/nfeautorizacao4.asmx',
|
|
68
|
-
retAutorizacao: 'https://nfe.fazenda.sp.gov.br/ws/nferetautorizacao4.asmx',
|
|
69
|
-
consulta: 'https://nfe.fazenda.sp.gov.br/ws/nfeconsultaprotocolo4.asmx',
|
|
70
|
-
evento: 'https://nfe.fazenda.sp.gov.br/ws/nferecepcaoevento4.asmx',
|
|
71
|
-
inutilizacao: 'https://nfe.fazenda.sp.gov.br/ws/nfeinutilizacao4.asmx',
|
|
72
|
-
status: 'https://nfe.fazenda.sp.gov.br/ws/nfestatusservico4.asmx',
|
|
73
|
-
},
|
|
74
|
-
2: {
|
|
75
|
-
autorizacao: 'https://homologacao.nfe.fazenda.sp.gov.br/ws/nfeautorizacao4.asmx',
|
|
76
|
-
retAutorizacao: 'https://homologacao.nfe.fazenda.sp.gov.br/ws/nferetautorizacao4.asmx',
|
|
77
|
-
consulta: 'https://homologacao.nfe.fazenda.sp.gov.br/ws/nfeconsultaprotocolo4.asmx',
|
|
78
|
-
evento: 'https://homologacao.nfe.fazenda.sp.gov.br/ws/nferecepcaoevento4.asmx',
|
|
79
|
-
inutilizacao: 'https://homologacao.nfe.fazenda.sp.gov.br/ws/nfeinutilizacao4.asmx',
|
|
80
|
-
status: 'https://homologacao.nfe.fazenda.sp.gov.br/ws/nfestatusservico4.asmx',
|
|
81
|
-
},
|
|
82
|
-
},
|
|
83
|
-
MG: {
|
|
84
|
-
1: {
|
|
85
|
-
autorizacao: 'https://nfe.fazenda.mg.gov.br/nfe2/services/NFeAutorizacao4',
|
|
86
|
-
retAutorizacao: 'https://nfe.fazenda.mg.gov.br/nfe2/services/NFeRetAutorizacao4',
|
|
87
|
-
consulta: 'https://nfe.fazenda.mg.gov.br/nfe2/services/NFeConsultaProtocolo4',
|
|
88
|
-
evento: 'https://nfe.fazenda.mg.gov.br/nfe2/services/NFeRecepcaoEvento4',
|
|
89
|
-
inutilizacao: 'https://nfe.fazenda.mg.gov.br/nfe2/services/NFeInutilizacao4',
|
|
90
|
-
status: 'https://nfe.fazenda.mg.gov.br/nfe2/services/NFeStatusServico4',
|
|
91
|
-
},
|
|
92
|
-
2: {
|
|
93
|
-
autorizacao: 'https://hnfe.fazenda.mg.gov.br/nfe2/services/NFeAutorizacao4',
|
|
94
|
-
retAutorizacao: 'https://hnfe.fazenda.mg.gov.br/nfe2/services/NFeRetAutorizacao4',
|
|
95
|
-
consulta: 'https://hnfe.fazenda.mg.gov.br/nfe2/services/NFeConsultaProtocolo4',
|
|
96
|
-
evento: 'https://hnfe.fazenda.mg.gov.br/nfe2/services/NFeRecepcaoEvento4',
|
|
97
|
-
inutilizacao: 'https://hnfe.fazenda.mg.gov.br/nfe2/services/NFeInutilizacao4',
|
|
98
|
-
status: 'https://hnfe.fazenda.mg.gov.br/nfe2/services/NFeStatusServico4',
|
|
99
|
-
},
|
|
100
|
-
},
|
|
101
|
-
PR: {
|
|
102
|
-
1: {
|
|
103
|
-
autorizacao: 'https://nfe.sefa.pr.gov.br/nfe/NFeAutorizacao4',
|
|
104
|
-
retAutorizacao: 'https://nfe.sefa.pr.gov.br/nfe/NFeRetAutorizacao4',
|
|
105
|
-
consulta: 'https://nfe.sefa.pr.gov.br/nfe/NFeConsultaProtocolo4',
|
|
106
|
-
evento: 'https://nfe.sefa.pr.gov.br/nfe/NFeRecepcaoEvento4',
|
|
107
|
-
inutilizacao: 'https://nfe.sefa.pr.gov.br/nfe/NFeInutilizacao4',
|
|
108
|
-
status: 'https://nfe.sefa.pr.gov.br/nfe/NFeStatusServico4',
|
|
109
|
-
},
|
|
110
|
-
2: {
|
|
111
|
-
autorizacao: 'https://homologacao.nfe.sefa.pr.gov.br/nfe/NFeAutorizacao4',
|
|
112
|
-
retAutorizacao: 'https://homologacao.nfe.sefa.pr.gov.br/nfe/NFeRetAutorizacao4',
|
|
113
|
-
consulta: 'https://homologacao.nfe.sefa.pr.gov.br/nfe/NFeConsultaProtocolo4',
|
|
114
|
-
evento: 'https://homologacao.nfe.sefa.pr.gov.br/nfe/NFeRecepcaoEvento4',
|
|
115
|
-
inutilizacao: 'https://homologacao.nfe.sefa.pr.gov.br/nfe/NFeInutilizacao4',
|
|
116
|
-
status: 'https://homologacao.nfe.sefa.pr.gov.br/nfe/NFeStatusServico4',
|
|
117
|
-
},
|
|
118
|
-
},
|
|
119
|
-
RS: {
|
|
120
|
-
1: {
|
|
121
|
-
autorizacao: 'https://nfe.sefazrs.rs.gov.br/ws/NfeAutorizacao/NFeAutorizacao4.asmx',
|
|
122
|
-
retAutorizacao: 'https://nfe.sefazrs.rs.gov.br/ws/NfeRetAutorizacao/NFeRetAutorizacao4.asmx',
|
|
123
|
-
consulta: 'https://nfe.sefazrs.rs.gov.br/ws/NfeConsulta/NfeConsulta4.asmx',
|
|
124
|
-
evento: 'https://nfe.sefazrs.rs.gov.br/ws/recepcaoevento/ReceptionEvent4.asmx',
|
|
125
|
-
inutilizacao: 'https://nfe.sefazrs.rs.gov.br/ws/nfeinutilizacao/nfeinutilizacao4.asmx',
|
|
126
|
-
status: 'https://nfe.sefazrs.rs.gov.br/ws/NfeStatusServico/NfeStatusServico4.asmx',
|
|
127
|
-
},
|
|
128
|
-
2: {
|
|
129
|
-
autorizacao: 'https://nfe-homologacao.sefazrs.rs.gov.br/ws/NfeAutorizacao/NFeAutorizacao4.asmx',
|
|
130
|
-
retAutorizacao: 'https://nfe-homologacao.sefazrs.rs.gov.br/ws/NfeRetAutorizacao/NFeRetAutorizacao4.asmx',
|
|
131
|
-
consulta: 'https://nfe-homologacao.sefazrs.rs.gov.br/ws/NfeConsulta/NfeConsulta4.asmx',
|
|
132
|
-
evento: 'https://nfe-homologacao.sefazrs.rs.gov.br/ws/recepcaoevento/ReceptionEvent4.asmx',
|
|
133
|
-
inutilizacao: 'https://nfe-homologacao.sefazrs.rs.gov.br/ws/nfeinutilizacao/nfeinutilizacao4.asmx',
|
|
134
|
-
status: 'https://nfe-homologacao.sefazrs.rs.gov.br/ws/NfeStatusServico/NfeStatusServico4.asmx',
|
|
135
|
-
},
|
|
136
|
-
},
|
|
137
|
-
MS: {
|
|
138
|
-
1: {
|
|
139
|
-
autorizacao: 'https://nfe.sefaz.ms.gov.br/ws/NfeAutorizacao4',
|
|
140
|
-
evento: 'https://nfe.sefaz.ms.gov.br/ws/NfeRecepcaoEvento4',
|
|
141
|
-
consulta: 'https://nfe.sefaz.ms.gov.br/ws/NfeConsulta4',
|
|
142
|
-
status: 'https://nfe.sefaz.ms.gov.br/ws/NfeStatusServico4',
|
|
143
|
-
},
|
|
144
|
-
2: {
|
|
145
|
-
autorizacao: 'https://homologacao.nfe.ms.gov.br/ws/NfeAutorizacao4',
|
|
146
|
-
evento: 'https://homologacao.nfe.ms.gov.br/ws/NfeRecepcaoEvento4',
|
|
147
|
-
consulta: 'https://homologacao.nfe.ms.gov.br/ws/NfeConsulta4',
|
|
148
|
-
status: 'https://homologacao.nfe.ms.gov.br/ws/NfeStatusServico4',
|
|
149
|
-
},
|
|
150
|
-
},
|
|
151
|
-
MT: {
|
|
152
|
-
1: {
|
|
153
|
-
autorizacao: 'https://nfe.sefaz.mt.gov.br/nfews/v2/services/NfeAutorizacao4',
|
|
154
|
-
evento: 'https://nfe.sefaz.mt.gov.br/nfews/v2/services/RecepcaoEvento4',
|
|
155
|
-
consulta: 'https://nfe.sefaz.mt.gov.br/nfews/v2/services/NfeConsulta4',
|
|
156
|
-
},
|
|
157
|
-
2: {
|
|
158
|
-
autorizacao: 'https://homologacao.sefaz.mt.gov.br/nfews/v2/services/NfeAutorizacao4',
|
|
159
|
-
evento: 'https://homologacao.sefaz.mt.gov.br/nfews/v2/services/RecepcaoEvento4',
|
|
160
|
-
consulta: 'https://homologacao.sefaz.mt.gov.br/nfews/v2/services/NfeConsulta4',
|
|
161
|
-
},
|
|
162
|
-
},
|
|
163
|
-
GO: {
|
|
164
|
-
1: {
|
|
165
|
-
autorizacao: 'https://nfe.sefaz.go.gov.br/nfe/services/NFeAutorizacao4',
|
|
166
|
-
evento: 'https://nfe.sefaz.go.gov.br/nfe/services/NFeRecepcaoEvento4',
|
|
167
|
-
consulta: 'https://nfe.sefaz.go.gov.br/nfe/services/NFeConsultaProtocolo4',
|
|
168
|
-
},
|
|
169
|
-
2: {
|
|
170
|
-
autorizacao: 'https://homolog.sefaz.go.gov.br/nfe/services/NFeAutorizacao4',
|
|
171
|
-
evento: 'https://homolog.sefaz.go.gov.br/nfe/services/NFeRecepcaoEvento4',
|
|
172
|
-
consulta: 'https://homolog.sefaz.go.gov.br/nfe/services/NFeConsultaProtocolo4',
|
|
173
|
-
},
|
|
174
|
-
},
|
|
175
|
-
AM: {
|
|
176
|
-
1: {
|
|
177
|
-
autorizacao: 'https://nfe.sefaz.am.gov.br/services2/services/NfeAutorizacao4',
|
|
178
|
-
evento: 'https://nfe.sefaz.am.gov.br/services2/services/RecepcaoEvento4',
|
|
179
|
-
},
|
|
180
|
-
2: {
|
|
181
|
-
autorizacao: 'https://homnfe.sefaz.am.gov.br/services2/services/NfeAutorizacao4',
|
|
182
|
-
evento: 'https://homnfe.sefaz.am.gov.br/services2/services/RecepcaoEvento4',
|
|
183
|
-
},
|
|
184
|
-
},
|
|
185
|
-
BA: {
|
|
186
|
-
1: {
|
|
187
|
-
autorizacao: 'https://nfe.sefaz.ba.gov.br/webservices/NFeAutorizacao4/NFeAutorizacao4.asmx',
|
|
188
|
-
evento: 'https://nfe.sefaz.ba.gov.br/webservices/NFeRecepcaoEvento4/NFeRecepcaoEvento4.asmx',
|
|
189
|
-
},
|
|
190
|
-
2: {
|
|
191
|
-
autorizacao: 'https://hnfe.sefaz.ba.gov.br/webservices/NFeAutorizacao4/NFeAutorizacao4.asmx',
|
|
192
|
-
evento: 'https://hnfe.sefaz.ba.gov.br/webservices/NFeRecepcaoEvento4/NFeRecepcaoEvento4.asmx',
|
|
193
|
-
},
|
|
194
|
-
},
|
|
195
|
-
PE: {
|
|
196
|
-
1: {
|
|
197
|
-
autorizacao: 'https://nfe.sefaz.pe.gov.br/nfe-service/services/NFeAutorizacao4',
|
|
198
|
-
evento: 'https://nfe.sefaz.pe.gov.br/nfe-service/services/NFeRecepcaoEvento4',
|
|
199
|
-
},
|
|
200
|
-
2: {
|
|
201
|
-
autorizacao: 'https://nfehomolog.sefaz.pe.gov.br/nfe-service/services/NFeAutorizacao4',
|
|
202
|
-
evento: 'https://nfehomolog.sefaz.pe.gov.br/nfe-service/services/NFeRecepcaoEvento4',
|
|
203
|
-
},
|
|
204
|
-
},
|
|
205
|
-
};
|
|
1
|
+
/**
|
|
2
|
+
* Mapeamento UF → autorizador SEFAZ (NF-e/NFC-e).
|
|
3
|
+
* Fonte: Manual de Orientação do Contribuinte / tabela de autorizadores.
|
|
4
|
+
*/
|
|
5
|
+
export const UF_AUTORIZADOR = {
|
|
6
|
+
AC: 'SVRS', AL: 'SVRS', AM: 'AM', AP: 'SVRS', BA: 'BA',
|
|
7
|
+
CE: 'SVRS', DF: 'SVRS', ES: 'SVRS', GO: 'GO', MA: 'SVAN',
|
|
8
|
+
MG: 'MG', MS: 'MS', MT: 'MT', PA: 'SVAN', PB: 'SVRS',
|
|
9
|
+
PE: 'PE', PI: 'SVRS', PR: 'PR', RJ: 'SVRS', RN: 'SVRS',
|
|
10
|
+
RO: 'SVRS', RR: 'SVRS', RS: 'RS', SC: 'SVRS', SE: 'SVRS',
|
|
11
|
+
SP: 'SP', TO: 'SVRS',
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
/** Tipos de webservice SEFAZ. */
|
|
15
|
+
export const SEFAZ_SERVICO = {
|
|
16
|
+
AUTORIZACAO: 'autorizacao',
|
|
17
|
+
RET_AUTORIZACAO: 'retAutorizacao',
|
|
18
|
+
CONSULTA: 'consulta',
|
|
19
|
+
EVENTO: 'evento',
|
|
20
|
+
INUTILIZACAO: 'inutilizacao',
|
|
21
|
+
STATUS: 'status',
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Endpoints por autorizador e ambiente.
|
|
26
|
+
* ambiente: 1=Produção, 2=Homologação
|
|
27
|
+
*/
|
|
28
|
+
export const AUTORIZADOR_ENDPOINTS = {
|
|
29
|
+
SVRS: {
|
|
30
|
+
1: {
|
|
31
|
+
autorizacao: 'https://nfe.svrs.rs.gov.br/ws/NfeAutorizacao/NFeAutorizacao4.asmx',
|
|
32
|
+
retAutorizacao: 'https://nfe.svrs.rs.gov.br/ws/NfeRetAutorizacao/NFeRetAutorizacao4.asmx',
|
|
33
|
+
consulta: 'https://nfe.svrs.rs.gov.br/ws/NfeConsulta/NfeConsulta4.asmx',
|
|
34
|
+
evento: 'https://nfe.svrs.rs.gov.br/ws/recepcaoevento/ReceptionEvent4.asmx',
|
|
35
|
+
inutilizacao: 'https://nfe.svrs.rs.gov.br/ws/nfeinutilizacao/nfeinutilizacao4.asmx',
|
|
36
|
+
status: 'https://nfe.svrs.rs.gov.br/ws/NfeStatusServico/NfeStatusServico4.asmx',
|
|
37
|
+
},
|
|
38
|
+
2: {
|
|
39
|
+
autorizacao: 'https://nfe-homologacao.svrs.rs.gov.br/ws/NfeAutorizacao/NFeAutorizacao4.asmx',
|
|
40
|
+
retAutorizacao: 'https://nfe-homologacao.svrs.rs.gov.br/ws/NfeRetAutorizacao/NFeRetAutorizacao4.asmx',
|
|
41
|
+
consulta: 'https://nfe-homologacao.svrs.rs.gov.br/ws/NfeConsulta/NfeConsulta4.asmx',
|
|
42
|
+
evento: 'https://nfe-homologacao.svrs.rs.gov.br/ws/recepcaoevento/ReceptionEvent4.asmx',
|
|
43
|
+
inutilizacao: 'https://nfe-homologacao.svrs.rs.gov.br/ws/nfeinutilizacao/nfeinutilizacao4.asmx',
|
|
44
|
+
status: 'https://nfe-homologacao.svrs.rs.gov.br/ws/NfeStatusServico/NfeStatusServico4.asmx',
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
SVAN: {
|
|
48
|
+
1: {
|
|
49
|
+
autorizacao: 'https://www.sefazvirtual.fazenda.gov.br/NFeAutorizacao4/NFeAutorizacao4.asmx',
|
|
50
|
+
retAutorizacao: 'https://www.sefazvirtual.fazenda.gov.br/NFeRetAutorizacao4/NFeRetAutorizacao4.asmx',
|
|
51
|
+
consulta: 'https://www.sefazvirtual.fazenda.gov.br/NFeConsultaProtocolo4/NFeConsultaProtocolo4.asmx',
|
|
52
|
+
evento: 'https://www.sefazvirtual.fazenda.gov.br/NFeRecepcaoEvento4/NFeRecepcaoEvento4.asmx',
|
|
53
|
+
inutilizacao: 'https://www.sefazvirtual.fazenda.gov.br/NFeInutilizacao4/NFeInutilizacao4.asmx',
|
|
54
|
+
status: 'https://www.sefazvirtual.fazenda.gov.br/NFeStatusServico4/NFeStatusServico4.asmx',
|
|
55
|
+
},
|
|
56
|
+
2: {
|
|
57
|
+
autorizacao: 'https://hom.sefazvirtual.fazenda.gov.br/NFeAutorizacao4/NFeAutorizacao4.asmx',
|
|
58
|
+
retAutorizacao: 'https://hom.sefazvirtual.fazenda.gov.br/NFeRetAutorizacao4/NFeRetAutorizacao4.asmx',
|
|
59
|
+
consulta: 'https://hom.sefazvirtual.fazenda.gov.br/NFeConsultaProtocolo4/NFeConsultaProtocolo4.asmx',
|
|
60
|
+
evento: 'https://hom.sefazvirtual.fazenda.gov.br/NFeRecepcaoEvento4/NFeRecepcaoEvento4.asmx',
|
|
61
|
+
inutilizacao: 'https://hom.sefazvirtual.fazenda.gov.br/NFeInutilizacao4/NFeInutilizacao4.asmx',
|
|
62
|
+
status: 'https://hom.sefazvirtual.fazenda.gov.br/NFeStatusServico4/NFeStatusServico4.asmx',
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
SP: {
|
|
66
|
+
1: {
|
|
67
|
+
autorizacao: 'https://nfe.fazenda.sp.gov.br/ws/nfeautorizacao4.asmx',
|
|
68
|
+
retAutorizacao: 'https://nfe.fazenda.sp.gov.br/ws/nferetautorizacao4.asmx',
|
|
69
|
+
consulta: 'https://nfe.fazenda.sp.gov.br/ws/nfeconsultaprotocolo4.asmx',
|
|
70
|
+
evento: 'https://nfe.fazenda.sp.gov.br/ws/nferecepcaoevento4.asmx',
|
|
71
|
+
inutilizacao: 'https://nfe.fazenda.sp.gov.br/ws/nfeinutilizacao4.asmx',
|
|
72
|
+
status: 'https://nfe.fazenda.sp.gov.br/ws/nfestatusservico4.asmx',
|
|
73
|
+
},
|
|
74
|
+
2: {
|
|
75
|
+
autorizacao: 'https://homologacao.nfe.fazenda.sp.gov.br/ws/nfeautorizacao4.asmx',
|
|
76
|
+
retAutorizacao: 'https://homologacao.nfe.fazenda.sp.gov.br/ws/nferetautorizacao4.asmx',
|
|
77
|
+
consulta: 'https://homologacao.nfe.fazenda.sp.gov.br/ws/nfeconsultaprotocolo4.asmx',
|
|
78
|
+
evento: 'https://homologacao.nfe.fazenda.sp.gov.br/ws/nferecepcaoevento4.asmx',
|
|
79
|
+
inutilizacao: 'https://homologacao.nfe.fazenda.sp.gov.br/ws/nfeinutilizacao4.asmx',
|
|
80
|
+
status: 'https://homologacao.nfe.fazenda.sp.gov.br/ws/nfestatusservico4.asmx',
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
MG: {
|
|
84
|
+
1: {
|
|
85
|
+
autorizacao: 'https://nfe.fazenda.mg.gov.br/nfe2/services/NFeAutorizacao4',
|
|
86
|
+
retAutorizacao: 'https://nfe.fazenda.mg.gov.br/nfe2/services/NFeRetAutorizacao4',
|
|
87
|
+
consulta: 'https://nfe.fazenda.mg.gov.br/nfe2/services/NFeConsultaProtocolo4',
|
|
88
|
+
evento: 'https://nfe.fazenda.mg.gov.br/nfe2/services/NFeRecepcaoEvento4',
|
|
89
|
+
inutilizacao: 'https://nfe.fazenda.mg.gov.br/nfe2/services/NFeInutilizacao4',
|
|
90
|
+
status: 'https://nfe.fazenda.mg.gov.br/nfe2/services/NFeStatusServico4',
|
|
91
|
+
},
|
|
92
|
+
2: {
|
|
93
|
+
autorizacao: 'https://hnfe.fazenda.mg.gov.br/nfe2/services/NFeAutorizacao4',
|
|
94
|
+
retAutorizacao: 'https://hnfe.fazenda.mg.gov.br/nfe2/services/NFeRetAutorizacao4',
|
|
95
|
+
consulta: 'https://hnfe.fazenda.mg.gov.br/nfe2/services/NFeConsultaProtocolo4',
|
|
96
|
+
evento: 'https://hnfe.fazenda.mg.gov.br/nfe2/services/NFeRecepcaoEvento4',
|
|
97
|
+
inutilizacao: 'https://hnfe.fazenda.mg.gov.br/nfe2/services/NFeInutilizacao4',
|
|
98
|
+
status: 'https://hnfe.fazenda.mg.gov.br/nfe2/services/NFeStatusServico4',
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
PR: {
|
|
102
|
+
1: {
|
|
103
|
+
autorizacao: 'https://nfe.sefa.pr.gov.br/nfe/NFeAutorizacao4',
|
|
104
|
+
retAutorizacao: 'https://nfe.sefa.pr.gov.br/nfe/NFeRetAutorizacao4',
|
|
105
|
+
consulta: 'https://nfe.sefa.pr.gov.br/nfe/NFeConsultaProtocolo4',
|
|
106
|
+
evento: 'https://nfe.sefa.pr.gov.br/nfe/NFeRecepcaoEvento4',
|
|
107
|
+
inutilizacao: 'https://nfe.sefa.pr.gov.br/nfe/NFeInutilizacao4',
|
|
108
|
+
status: 'https://nfe.sefa.pr.gov.br/nfe/NFeStatusServico4',
|
|
109
|
+
},
|
|
110
|
+
2: {
|
|
111
|
+
autorizacao: 'https://homologacao.nfe.sefa.pr.gov.br/nfe/NFeAutorizacao4',
|
|
112
|
+
retAutorizacao: 'https://homologacao.nfe.sefa.pr.gov.br/nfe/NFeRetAutorizacao4',
|
|
113
|
+
consulta: 'https://homologacao.nfe.sefa.pr.gov.br/nfe/NFeConsultaProtocolo4',
|
|
114
|
+
evento: 'https://homologacao.nfe.sefa.pr.gov.br/nfe/NFeRecepcaoEvento4',
|
|
115
|
+
inutilizacao: 'https://homologacao.nfe.sefa.pr.gov.br/nfe/NFeInutilizacao4',
|
|
116
|
+
status: 'https://homologacao.nfe.sefa.pr.gov.br/nfe/NFeStatusServico4',
|
|
117
|
+
},
|
|
118
|
+
},
|
|
119
|
+
RS: {
|
|
120
|
+
1: {
|
|
121
|
+
autorizacao: 'https://nfe.sefazrs.rs.gov.br/ws/NfeAutorizacao/NFeAutorizacao4.asmx',
|
|
122
|
+
retAutorizacao: 'https://nfe.sefazrs.rs.gov.br/ws/NfeRetAutorizacao/NFeRetAutorizacao4.asmx',
|
|
123
|
+
consulta: 'https://nfe.sefazrs.rs.gov.br/ws/NfeConsulta/NfeConsulta4.asmx',
|
|
124
|
+
evento: 'https://nfe.sefazrs.rs.gov.br/ws/recepcaoevento/ReceptionEvent4.asmx',
|
|
125
|
+
inutilizacao: 'https://nfe.sefazrs.rs.gov.br/ws/nfeinutilizacao/nfeinutilizacao4.asmx',
|
|
126
|
+
status: 'https://nfe.sefazrs.rs.gov.br/ws/NfeStatusServico/NfeStatusServico4.asmx',
|
|
127
|
+
},
|
|
128
|
+
2: {
|
|
129
|
+
autorizacao: 'https://nfe-homologacao.sefazrs.rs.gov.br/ws/NfeAutorizacao/NFeAutorizacao4.asmx',
|
|
130
|
+
retAutorizacao: 'https://nfe-homologacao.sefazrs.rs.gov.br/ws/NfeRetAutorizacao/NFeRetAutorizacao4.asmx',
|
|
131
|
+
consulta: 'https://nfe-homologacao.sefazrs.rs.gov.br/ws/NfeConsulta/NfeConsulta4.asmx',
|
|
132
|
+
evento: 'https://nfe-homologacao.sefazrs.rs.gov.br/ws/recepcaoevento/ReceptionEvent4.asmx',
|
|
133
|
+
inutilizacao: 'https://nfe-homologacao.sefazrs.rs.gov.br/ws/nfeinutilizacao/nfeinutilizacao4.asmx',
|
|
134
|
+
status: 'https://nfe-homologacao.sefazrs.rs.gov.br/ws/NfeStatusServico/NfeStatusServico4.asmx',
|
|
135
|
+
},
|
|
136
|
+
},
|
|
137
|
+
MS: {
|
|
138
|
+
1: {
|
|
139
|
+
autorizacao: 'https://nfe.sefaz.ms.gov.br/ws/NfeAutorizacao4',
|
|
140
|
+
evento: 'https://nfe.sefaz.ms.gov.br/ws/NfeRecepcaoEvento4',
|
|
141
|
+
consulta: 'https://nfe.sefaz.ms.gov.br/ws/NfeConsulta4',
|
|
142
|
+
status: 'https://nfe.sefaz.ms.gov.br/ws/NfeStatusServico4',
|
|
143
|
+
},
|
|
144
|
+
2: {
|
|
145
|
+
autorizacao: 'https://homologacao.nfe.ms.gov.br/ws/NfeAutorizacao4',
|
|
146
|
+
evento: 'https://homologacao.nfe.ms.gov.br/ws/NfeRecepcaoEvento4',
|
|
147
|
+
consulta: 'https://homologacao.nfe.ms.gov.br/ws/NfeConsulta4',
|
|
148
|
+
status: 'https://homologacao.nfe.ms.gov.br/ws/NfeStatusServico4',
|
|
149
|
+
},
|
|
150
|
+
},
|
|
151
|
+
MT: {
|
|
152
|
+
1: {
|
|
153
|
+
autorizacao: 'https://nfe.sefaz.mt.gov.br/nfews/v2/services/NfeAutorizacao4',
|
|
154
|
+
evento: 'https://nfe.sefaz.mt.gov.br/nfews/v2/services/RecepcaoEvento4',
|
|
155
|
+
consulta: 'https://nfe.sefaz.mt.gov.br/nfews/v2/services/NfeConsulta4',
|
|
156
|
+
},
|
|
157
|
+
2: {
|
|
158
|
+
autorizacao: 'https://homologacao.sefaz.mt.gov.br/nfews/v2/services/NfeAutorizacao4',
|
|
159
|
+
evento: 'https://homologacao.sefaz.mt.gov.br/nfews/v2/services/RecepcaoEvento4',
|
|
160
|
+
consulta: 'https://homologacao.sefaz.mt.gov.br/nfews/v2/services/NfeConsulta4',
|
|
161
|
+
},
|
|
162
|
+
},
|
|
163
|
+
GO: {
|
|
164
|
+
1: {
|
|
165
|
+
autorizacao: 'https://nfe.sefaz.go.gov.br/nfe/services/NFeAutorizacao4',
|
|
166
|
+
evento: 'https://nfe.sefaz.go.gov.br/nfe/services/NFeRecepcaoEvento4',
|
|
167
|
+
consulta: 'https://nfe.sefaz.go.gov.br/nfe/services/NFeConsultaProtocolo4',
|
|
168
|
+
},
|
|
169
|
+
2: {
|
|
170
|
+
autorizacao: 'https://homolog.sefaz.go.gov.br/nfe/services/NFeAutorizacao4',
|
|
171
|
+
evento: 'https://homolog.sefaz.go.gov.br/nfe/services/NFeRecepcaoEvento4',
|
|
172
|
+
consulta: 'https://homolog.sefaz.go.gov.br/nfe/services/NFeConsultaProtocolo4',
|
|
173
|
+
},
|
|
174
|
+
},
|
|
175
|
+
AM: {
|
|
176
|
+
1: {
|
|
177
|
+
autorizacao: 'https://nfe.sefaz.am.gov.br/services2/services/NfeAutorizacao4',
|
|
178
|
+
evento: 'https://nfe.sefaz.am.gov.br/services2/services/RecepcaoEvento4',
|
|
179
|
+
},
|
|
180
|
+
2: {
|
|
181
|
+
autorizacao: 'https://homnfe.sefaz.am.gov.br/services2/services/NfeAutorizacao4',
|
|
182
|
+
evento: 'https://homnfe.sefaz.am.gov.br/services2/services/RecepcaoEvento4',
|
|
183
|
+
},
|
|
184
|
+
},
|
|
185
|
+
BA: {
|
|
186
|
+
1: {
|
|
187
|
+
autorizacao: 'https://nfe.sefaz.ba.gov.br/webservices/NFeAutorizacao4/NFeAutorizacao4.asmx',
|
|
188
|
+
evento: 'https://nfe.sefaz.ba.gov.br/webservices/NFeRecepcaoEvento4/NFeRecepcaoEvento4.asmx',
|
|
189
|
+
},
|
|
190
|
+
2: {
|
|
191
|
+
autorizacao: 'https://hnfe.sefaz.ba.gov.br/webservices/NFeAutorizacao4/NFeAutorizacao4.asmx',
|
|
192
|
+
evento: 'https://hnfe.sefaz.ba.gov.br/webservices/NFeRecepcaoEvento4/NFeRecepcaoEvento4.asmx',
|
|
193
|
+
},
|
|
194
|
+
},
|
|
195
|
+
PE: {
|
|
196
|
+
1: {
|
|
197
|
+
autorizacao: 'https://nfe.sefaz.pe.gov.br/nfe-service/services/NFeAutorizacao4',
|
|
198
|
+
evento: 'https://nfe.sefaz.pe.gov.br/nfe-service/services/NFeRecepcaoEvento4',
|
|
199
|
+
},
|
|
200
|
+
2: {
|
|
201
|
+
autorizacao: 'https://nfehomolog.sefaz.pe.gov.br/nfe-service/services/NFeAutorizacao4',
|
|
202
|
+
evento: 'https://nfehomolog.sefaz.pe.gov.br/nfe-service/services/NFeRecepcaoEvento4',
|
|
203
|
+
},
|
|
204
|
+
},
|
|
205
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import https from 'https';
|
|
3
|
+
import tls from 'tls';
|
|
4
|
+
import path from 'path';
|
|
5
|
+
import { fileURLToPath } from 'url';
|
|
6
|
+
import { loadPfxCertificate } from '../utils/certificate.utils.js';
|
|
7
|
+
|
|
8
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Raiz ICP-Brasil v10 (ITI). Os web services da SEFAZ usam cadeias ICP-Brasil,
|
|
12
|
+
* que não fazem parte do repositório de confiança padrão do Node.
|
|
13
|
+
*/
|
|
14
|
+
export const ICP_BRASIL_RAIZ_V10 = fs.readFileSync(path.join(__dirname, 'ca/icp-brasil-raiz-v10.pem'), 'utf8');
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Cria https.Agent com autenticação mútua (TLS 1.2+) usando o certificado A1.
|
|
18
|
+
* @param {{ pfx: Buffer|string, senha: string }} certificado
|
|
19
|
+
* @param {{ ca?: string|string[], keepAlive?: boolean }} [options]
|
|
20
|
+
* ca: CAs adicionais; as raízes padrão do Node e a ICP-Brasil v10 são sempre incluídas
|
|
21
|
+
*/
|
|
22
|
+
export function criarHttpsAgentSefaz(certificado, options = {}) {
|
|
23
|
+
const { privateKeyPem, certificatePem } = loadPfxCertificate(certificado.pfx, certificado.senha);
|
|
24
|
+
const extras = [options.ca ?? []].flat();
|
|
25
|
+
|
|
26
|
+
return new https.Agent({
|
|
27
|
+
key: privateKeyPem,
|
|
28
|
+
cert: certificatePem,
|
|
29
|
+
ca: [...tls.rootCertificates, ICP_BRASIL_RAIZ_V10, ...extras],
|
|
30
|
+
minVersion: 'TLSv1.2',
|
|
31
|
+
keepAlive: options.keepAlive ?? true,
|
|
32
|
+
});
|
|
33
|
+
}
|
|
@@ -1,53 +1,53 @@
|
|
|
1
|
-
import { UF_IBGE } from '../constants/sefaz.js';
|
|
2
|
-
import { appendIBSCBS } from '../reforma/ibscbs.js';
|
|
3
|
-
|
|
4
|
-
/** @param {string} uf */
|
|
5
|
-
export function codigoUf(uf) {
|
|
6
|
-
return UF_IBGE[uf?.toUpperCase()] ?? '35';
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
/** @param {number} value @param {number} decimals */
|
|
10
|
-
export function formatDecimal(value, decimals) {
|
|
11
|
-
return Number(value).toFixed(decimals);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* @param {import('xmlbuilder2').XMLBuilder} parent
|
|
16
|
-
* @param {string} tag
|
|
17
|
-
* @param {import('../nfe/types/NFeDocument.js').NFeEndereco} endereco
|
|
18
|
-
*/
|
|
19
|
-
export function appendEndereco(parent, tag, endereco) {
|
|
20
|
-
const node = parent.ele(tag);
|
|
21
|
-
node.ele('xLgr').txt(endereco.logradouro).up();
|
|
22
|
-
node.ele('nro').txt(endereco.numero).up();
|
|
23
|
-
if (endereco.complemento) node.ele('xCpl').txt(endereco.complemento).up();
|
|
24
|
-
node.ele('xBairro').txt(endereco.bairro).up();
|
|
25
|
-
node.ele('cMun').txt(endereco.codigoMunicipio).up();
|
|
26
|
-
node.ele('xMun').txt(endereco.municipio).up();
|
|
27
|
-
node.ele('UF').txt(endereco.uf).up();
|
|
28
|
-
node.ele('CEP').txt(endereco.cep.replace(/\D/g, '')).up();
|
|
29
|
-
if (endereco.telefone) node.ele('fone').txt(endereco.telefone.replace(/\D/g, '')).up();
|
|
30
|
-
node.up();
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* @param {import('xmlbuilder2').XMLBuilder} impostoNode
|
|
35
|
-
* @param {import('../nfe/types/NFeDocument.js').NFeItem} item
|
|
36
|
-
*/
|
|
37
|
-
export function appendImpostosItem(impostoNode, item) {
|
|
38
|
-
const icms = impostoNode.ele('ICMS').ele('ICMS00');
|
|
39
|
-
icms.ele('orig').txt('0').up();
|
|
40
|
-
icms.ele('CST').txt(item.cst ?? '00').up();
|
|
41
|
-
icms.ele('modBC').txt('0').up();
|
|
42
|
-
icms.ele('vBC').txt(formatDecimal(item.valorTotal, 2)).up();
|
|
43
|
-
icms.ele('pICMS').txt(formatDecimal(item.aliquotaIcms ?? 0, 4)).up();
|
|
44
|
-
icms.ele('vICMS').txt(formatDecimal(item.valorIcms ?? 0, 2)).up();
|
|
45
|
-
icms.up().up();
|
|
46
|
-
|
|
47
|
-
impostoNode.ele('PIS').ele('PISNT').ele('CST').txt('07').up().up().up();
|
|
48
|
-
impostoNode.ele('COFINS').ele('COFINSNT').ele('CST').txt('07').up().up().up();
|
|
49
|
-
|
|
50
|
-
if (item.reforma) {
|
|
51
|
-
appendIBSCBS(impostoNode, item.reforma);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
1
|
+
import { UF_IBGE } from '../constants/sefaz.js';
|
|
2
|
+
import { appendIBSCBS } from '../reforma/ibscbs.js';
|
|
3
|
+
|
|
4
|
+
/** @param {string} uf */
|
|
5
|
+
export function codigoUf(uf) {
|
|
6
|
+
return UF_IBGE[uf?.toUpperCase()] ?? '35';
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/** @param {number} value @param {number} decimals */
|
|
10
|
+
export function formatDecimal(value, decimals) {
|
|
11
|
+
return Number(value).toFixed(decimals);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @param {import('xmlbuilder2').XMLBuilder} parent
|
|
16
|
+
* @param {string} tag
|
|
17
|
+
* @param {import('../nfe/types/NFeDocument.js').NFeEndereco} endereco
|
|
18
|
+
*/
|
|
19
|
+
export function appendEndereco(parent, tag, endereco) {
|
|
20
|
+
const node = parent.ele(tag);
|
|
21
|
+
node.ele('xLgr').txt(endereco.logradouro).up();
|
|
22
|
+
node.ele('nro').txt(endereco.numero).up();
|
|
23
|
+
if (endereco.complemento) node.ele('xCpl').txt(endereco.complemento).up();
|
|
24
|
+
node.ele('xBairro').txt(endereco.bairro).up();
|
|
25
|
+
node.ele('cMun').txt(endereco.codigoMunicipio).up();
|
|
26
|
+
node.ele('xMun').txt(endereco.municipio).up();
|
|
27
|
+
node.ele('UF').txt(endereco.uf).up();
|
|
28
|
+
node.ele('CEP').txt(endereco.cep.replace(/\D/g, '')).up();
|
|
29
|
+
if (endereco.telefone) node.ele('fone').txt(endereco.telefone.replace(/\D/g, '')).up();
|
|
30
|
+
node.up();
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* @param {import('xmlbuilder2').XMLBuilder} impostoNode
|
|
35
|
+
* @param {import('../nfe/types/NFeDocument.js').NFeItem} item
|
|
36
|
+
*/
|
|
37
|
+
export function appendImpostosItem(impostoNode, item) {
|
|
38
|
+
const icms = impostoNode.ele('ICMS').ele('ICMS00');
|
|
39
|
+
icms.ele('orig').txt('0').up();
|
|
40
|
+
icms.ele('CST').txt(item.cst ?? '00').up();
|
|
41
|
+
icms.ele('modBC').txt('0').up();
|
|
42
|
+
icms.ele('vBC').txt(formatDecimal(item.valorTotal, 2)).up();
|
|
43
|
+
icms.ele('pICMS').txt(formatDecimal(item.aliquotaIcms ?? 0, 4)).up();
|
|
44
|
+
icms.ele('vICMS').txt(formatDecimal(item.valorIcms ?? 0, 2)).up();
|
|
45
|
+
icms.up().up();
|
|
46
|
+
|
|
47
|
+
impostoNode.ele('PIS').ele('PISNT').ele('CST').txt('07').up().up().up();
|
|
48
|
+
impostoNode.ele('COFINS').ele('COFINSNT').ele('CST').txt('07').up().up().up();
|
|
49
|
+
|
|
50
|
+
if (item.reforma) {
|
|
51
|
+
appendIBSCBS(impostoNode, item.reforma);
|
|
52
|
+
}
|
|
53
|
+
}
|