@facturacr/atv-sdk 0.0.0-beta → 0.0.2-beta
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 +7 -0
- package/.github/ISSUE_TEMPLATE/bug_report.md +38 -0
- package/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
- package/.github/pull_request_template.md +7 -0
- package/.github/workflows/ci.yml +3 -3
- package/CODE_OF_CONDUCT.md +128 -0
- package/LICENSE +21 -0
- package/README.md +8 -1
- package/__tests__/stubs/dummyKeys/README.md +19 -0
- package/__tests__/stubs/frontendRequest.stub.ts +6 -5
- package/__tests__/stubs/token.stub.ts +18 -0
- package/__tests__/tests/electronicBill.test.ts +28 -0
- package/__tests__/{unit → tests}/getClave.test.ts +2 -2
- package/__tests__/tests/lib/getClave.test.ts +11 -0
- package/__tests__/tests/services/getToken.test.ts +15 -0
- package/atv-structures/4.3/FacturaElectronicaExportacion_V4.3.xsd.xml +1747 -0
- package/atv-structures/4.3/FacturaElectronica_V4.3.xsd.xml +1781 -0
- package/dist/__tests__/stubs/frontendRequest.stub.d.ts +3 -0
- package/dist/__tests__/stubs/frontendRequest.stub.js +61 -0
- package/dist/__tests__/stubs/frontendRequest.stub.js.map +1 -0
- package/dist/__tests__/stubs/token.stub.d.ts +17 -0
- package/dist/__tests__/stubs/token.stub.js +21 -0
- package/dist/__tests__/stubs/token.stub.js.map +1 -0
- package/dist/__tests__/tests/electronicBill.test.d.ts +1 -0
- package/dist/__tests__/tests/electronicBill.test.js +38 -0
- package/dist/__tests__/tests/electronicBill.test.js.map +1 -0
- package/dist/__tests__/tests/getClave.test.d.ts +1 -0
- package/dist/__tests__/tests/getClave.test.js +15 -0
- package/dist/__tests__/tests/getClave.test.js.map +1 -0
- package/dist/__tests__/tests/getToken.test.d.ts +0 -0
- package/dist/__tests__/tests/getToken.test.js +28 -0
- package/dist/__tests__/tests/getToken.test.js.map +1 -0
- package/dist/__tests__/tests/lib/getClave.test.d.ts +1 -0
- package/dist/__tests__/tests/lib/getClave.test.js +15 -0
- package/dist/__tests__/tests/lib/getClave.test.js.map +1 -0
- package/dist/__tests__/tests/services/getToken.test.d.ts +1 -0
- package/dist/__tests__/tests/services/getToken.test.js +27 -0
- package/dist/__tests__/tests/services/getToken.test.js.map +1 -0
- package/dist/examples/confirmXML.d.ts +1 -0
- package/dist/examples/confirmXML.js +89 -0
- package/dist/examples/confirmXML.js.map +1 -0
- package/dist/examples/consultXML.d.ts +1 -0
- package/dist/examples/consultXML.js +55 -0
- package/dist/examples/consultXML.js.map +1 -0
- package/dist/examples/createAndSend.d.ts +1 -0
- package/dist/examples/createAndSend.js +78 -0
- package/dist/examples/createAndSend.js.map +1 -0
- package/dist/examples/createCreditNote.d.ts +1 -0
- package/dist/examples/createCreditNote.js +52 -0
- package/dist/examples/createCreditNote.js.map +1 -0
- package/dist/examples/createDebitNote.d.ts +1 -0
- package/dist/examples/createDebitNote.js +52 -0
- package/dist/examples/createDebitNote.js.map +1 -0
- package/dist/examples/genBasicXML.d.ts +1 -0
- package/dist/examples/genBasicXML.js +44 -0
- package/dist/examples/genBasicXML.js.map +1 -0
- package/dist/examples/getClave.d.ts +1 -0
- package/dist/examples/getClave.js +12 -0
- package/dist/examples/getClave.js.map +1 -0
- package/dist/examples/getToken.d.ts +1 -0
- package/dist/examples/getToken.js +22 -0
- package/dist/examples/getToken.js.map +1 -0
- package/dist/src/confirmXML.d.ts +8 -0
- package/dist/src/confirmXML.js +44 -0
- package/dist/src/confirmXML.js.map +1 -0
- package/dist/src/creditNote.d.ts +14 -0
- package/dist/src/creditNote.js +77 -0
- package/dist/src/creditNote.js.map +1 -0
- package/dist/src/data/codigoMoneda.d.ts +1 -0
- package/dist/src/data/codigoMoneda.js +184 -0
- package/dist/src/data/codigoMoneda.js.map +1 -0
- package/dist/src/data/exoneracion.d.ts +1 -0
- package/dist/src/data/exoneracion.js +15 -0
- package/dist/src/data/exoneracion.js.map +1 -0
- package/dist/src/data/impuestos.d.ts +25 -0
- package/dist/src/data/impuestos.js +51 -0
- package/dist/src/data/impuestos.js.map +1 -0
- package/dist/src/data/tipoCedula.d.ts +7 -0
- package/dist/src/data/tipoCedula.js +17 -0
- package/dist/src/data/tipoCedula.js.map +1 -0
- package/dist/src/data/tipoDocumento.d.ts +26 -0
- package/dist/src/data/tipoDocumento.js +30 -0
- package/dist/src/data/tipoDocumento.js.map +1 -0
- package/dist/src/data/unidadesMedida.d.ts +5 -0
- package/dist/src/data/unidadesMedida.js +141 -0
- package/dist/src/data/unidadesMedida.js.map +1 -0
- package/dist/src/debitNote.d.ts +14 -0
- package/dist/src/debitNote.js +77 -0
- package/dist/src/debitNote.js.map +1 -0
- package/dist/src/electronicBill.d.ts +3 -0
- package/dist/src/electronicBill.js +61 -0
- package/dist/src/electronicBill.js.map +1 -0
- package/dist/src/helpers/comprobantes.d.ts +7 -0
- package/dist/src/helpers/comprobantes.js +92 -0
- package/dist/src/helpers/comprobantes.js.map +1 -0
- package/dist/src/index.d.ts +7 -0
- package/dist/src/index.js +42 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/lib/genClave/index.d.ts +9 -0
- package/dist/src/lib/genClave/index.js +119 -0
- package/dist/src/lib/genClave/index.js.map +1 -0
- package/dist/src/lib/genJSON/confirmXML.d.ts +7 -0
- package/dist/src/lib/genJSON/confirmXML.js +46 -0
- package/dist/src/lib/genJSON/confirmXML.js.map +1 -0
- package/dist/src/lib/genJSON/index.d.ts +3 -0
- package/dist/src/lib/genJSON/index.js +133 -0
- package/dist/src/lib/genJSON/index.js.map +1 -0
- package/dist/src/lib/genXML/index.d.ts +7 -0
- package/dist/src/lib/genXML/index.js +51 -0
- package/dist/src/lib/genXML/index.js.map +1 -0
- package/dist/src/lib/genXML/sigXML/genKeysAndCert.d.ts +6 -0
- package/dist/src/lib/genXML/sigXML/genKeysAndCert.js +77 -0
- package/dist/src/lib/genXML/sigXML/genKeysAndCert.js.map +1 -0
- package/dist/src/lib/genXML/sigXML/index.d.ts +1 -0
- package/dist/src/lib/genXML/sigXML/index.js +86 -0
- package/dist/src/lib/genXML/sigXML/index.js.map +1 -0
- package/dist/src/lib/genXML/xmlConfig.d.ts +55 -0
- package/dist/src/lib/genXML/xmlConfig.js +36 -0
- package/dist/src/lib/genXML/xmlConfig.js.map +1 -0
- package/dist/src/services/getToken/index.d.ts +3 -0
- package/dist/src/services/getToken/index.js +22 -0
- package/dist/src/services/getToken/index.js.map +1 -0
- package/dist/src/services/send/index.d.ts +2 -0
- package/dist/src/services/send/index.js +40 -0
- package/dist/src/services/send/index.js.map +1 -0
- package/dist/src/types/xml/notaDeCredito.d.ts +21 -0
- package/dist/src/types/xml/notaDeCredito.js +3 -0
- package/dist/src/types/xml/notaDeCredito.js.map +1 -0
- package/dist/src/types/xml/notaDeDebito.d.ts +21 -0
- package/dist/src/types/xml/notaDeDebito.js +3 -0
- package/dist/src/types/xml/notaDeDebito.js.map +1 -0
- package/examples/README.md +54 -0
- package/{test/examples → examples}/createAndSend.ts +16 -12
- package/{test/examples → examples}/createCreditNote.ts +3 -3
- package/{test/examples → examples}/createDebitNote.ts +3 -3
- package/{test/examples → examples}/genBasicXML.ts +2 -2
- package/{test/examples → examples}/getClave.ts +2 -2
- package/examples/getToken.ts +15 -0
- package/jest.config.js +20 -3
- package/package.json +15 -18
- package/src/ATV.ts +28 -0
- package/src/confirmXML.ts +4 -4
- package/src/creditNote.ts +9 -9
- package/src/data/codigoMoneda.ts +180 -0
- package/src/data/exoneracion.ts +11 -0
- package/src/data/impuestos.ts +26 -0
- package/src/data/tipoCedula.ts +8 -0
- package/src/data/unidadesMedida.ts +99 -0
- package/src/debitNote.ts +9 -9
- package/src/electronicBill.ts +17 -9
- package/src/helpers/comprobantes.ts +7 -7
- package/src/lib/genClave/index.ts +7 -7
- package/src/lib/genJSON/confirmXML.ts +2 -2
- package/src/lib/genJSON/index.ts +23 -21
- package/src/lib/genXML/index.ts +3 -9
- package/src/lib/genXML/sigXML/genKeysAndCert.ts +1 -5
- package/src/lib/genXML/sigXML/index.ts +1 -1
- package/src/lib/genXML/xmlConfig.ts +14 -1
- package/src/services/getToken/GetToken.ts +54 -0
- package/src/services/getToken/__tests__/GetToken.test.ts +82 -0
- package/src/services/getToken/index.ts +1 -1
- package/src/services/getToken/types.ts +30 -0
- package/src/services/send/index.ts +2 -2
- package/src/types/{facturaInterfaces.ts → facturaInterfaces.d.ts} +18 -1
- package/src/types/globalInterfaces.d.ts +5 -2
- package/src/types/xml/notaDeCredito.ts +1 -1
- package/src/types/xml/notaDeDebito.ts +1 -1
- package/{test/tools → tools}/strToClave.ts +1 -1
- package/tools/xsdToJsonSchema.ts +108 -0
- package/tsconfig.json +5 -2
- package/test/examples/README.md +0 -43
- package/test/examples/getToken.ts +0 -18
- /package/__tests__/{unit → tests}/getToken.test.ts +0 -0
- /package/{test/examples → examples}/confirmXML.ts +0 -0
- /package/{test/examples → examples}/consultXML.ts +0 -0
- /package/{test/tools → tools}/readXML.ts +0 -0
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
export const enumCodigoMonedaType = [
|
|
2
|
+
'AED',
|
|
3
|
+
'AFN',
|
|
4
|
+
'ALL',
|
|
5
|
+
'AMD',
|
|
6
|
+
'ANG',
|
|
7
|
+
'AOA',
|
|
8
|
+
'ARS',
|
|
9
|
+
'AUD',
|
|
10
|
+
'AWG',
|
|
11
|
+
'AZN',
|
|
12
|
+
'BAM',
|
|
13
|
+
'BBD',
|
|
14
|
+
'BDT',
|
|
15
|
+
'BGN',
|
|
16
|
+
'BHD',
|
|
17
|
+
'BIF',
|
|
18
|
+
'BMD',
|
|
19
|
+
'BND',
|
|
20
|
+
'BOB',
|
|
21
|
+
'BOV',
|
|
22
|
+
'BRL',
|
|
23
|
+
'BSD',
|
|
24
|
+
'BTN',
|
|
25
|
+
'BWP',
|
|
26
|
+
'BYR',
|
|
27
|
+
'BZD',
|
|
28
|
+
'CAD',
|
|
29
|
+
'CDF',
|
|
30
|
+
'CHE',
|
|
31
|
+
'CHF',
|
|
32
|
+
'CHW',
|
|
33
|
+
'CLF',
|
|
34
|
+
'CLP',
|
|
35
|
+
'CNY',
|
|
36
|
+
'COP',
|
|
37
|
+
'COU',
|
|
38
|
+
'CRC',
|
|
39
|
+
'CUC',
|
|
40
|
+
'CUP',
|
|
41
|
+
'CVE',
|
|
42
|
+
'CZK',
|
|
43
|
+
'DJF',
|
|
44
|
+
'DKK',
|
|
45
|
+
'DOP',
|
|
46
|
+
'DZD',
|
|
47
|
+
'EGP',
|
|
48
|
+
'ERN',
|
|
49
|
+
'ETB',
|
|
50
|
+
'EUR',
|
|
51
|
+
'FJD',
|
|
52
|
+
'FKP',
|
|
53
|
+
'GBP',
|
|
54
|
+
'GEL',
|
|
55
|
+
'GHS',
|
|
56
|
+
'GIP',
|
|
57
|
+
'GMD',
|
|
58
|
+
'GNF',
|
|
59
|
+
'GTQ',
|
|
60
|
+
'GYD',
|
|
61
|
+
'HKD',
|
|
62
|
+
'HNL',
|
|
63
|
+
'HRK',
|
|
64
|
+
'HTG',
|
|
65
|
+
'HUF',
|
|
66
|
+
'IDR',
|
|
67
|
+
'ILS',
|
|
68
|
+
'INR',
|
|
69
|
+
'IQD',
|
|
70
|
+
'IRR',
|
|
71
|
+
'ISK',
|
|
72
|
+
'JMD',
|
|
73
|
+
'JOD',
|
|
74
|
+
'JPY',
|
|
75
|
+
'KES',
|
|
76
|
+
'KGS',
|
|
77
|
+
'KHR',
|
|
78
|
+
'KMF',
|
|
79
|
+
'KPW',
|
|
80
|
+
'KRW',
|
|
81
|
+
'KWD',
|
|
82
|
+
'KYD',
|
|
83
|
+
'KZT',
|
|
84
|
+
'LAK',
|
|
85
|
+
'LBP',
|
|
86
|
+
'LKR',
|
|
87
|
+
'LRD',
|
|
88
|
+
'LSL',
|
|
89
|
+
'LYD',
|
|
90
|
+
'MAD',
|
|
91
|
+
'MDL',
|
|
92
|
+
'MGA',
|
|
93
|
+
'MKD',
|
|
94
|
+
'MMK',
|
|
95
|
+
'MNT',
|
|
96
|
+
'MOP',
|
|
97
|
+
'MRO',
|
|
98
|
+
'MUR',
|
|
99
|
+
'MVR',
|
|
100
|
+
'MWK',
|
|
101
|
+
'MXN',
|
|
102
|
+
'MXV',
|
|
103
|
+
'MYR',
|
|
104
|
+
'MZN',
|
|
105
|
+
'NAD',
|
|
106
|
+
'NGN',
|
|
107
|
+
'NIO',
|
|
108
|
+
'NOK',
|
|
109
|
+
'NPR',
|
|
110
|
+
'NZD',
|
|
111
|
+
'OMR',
|
|
112
|
+
'PAB',
|
|
113
|
+
'PEN',
|
|
114
|
+
'PGK',
|
|
115
|
+
'PHP',
|
|
116
|
+
'PKR',
|
|
117
|
+
'PLN',
|
|
118
|
+
'PYG',
|
|
119
|
+
'QAR',
|
|
120
|
+
'RON',
|
|
121
|
+
'RSD',
|
|
122
|
+
'RUB',
|
|
123
|
+
'RWF',
|
|
124
|
+
'SAR',
|
|
125
|
+
'SBD',
|
|
126
|
+
'SCR',
|
|
127
|
+
'SDG',
|
|
128
|
+
'SEK',
|
|
129
|
+
'SGD',
|
|
130
|
+
'SHP',
|
|
131
|
+
'SLL',
|
|
132
|
+
'SOS',
|
|
133
|
+
'SRD',
|
|
134
|
+
'SSP',
|
|
135
|
+
'STD',
|
|
136
|
+
'SVC',
|
|
137
|
+
'SYP',
|
|
138
|
+
'SZL',
|
|
139
|
+
'THB',
|
|
140
|
+
'TJS',
|
|
141
|
+
'TMT',
|
|
142
|
+
'TND',
|
|
143
|
+
'TOP',
|
|
144
|
+
'TRY',
|
|
145
|
+
'TTD',
|
|
146
|
+
'TWD',
|
|
147
|
+
'TZS',
|
|
148
|
+
'UAH',
|
|
149
|
+
'UGX',
|
|
150
|
+
'USD',
|
|
151
|
+
'USN',
|
|
152
|
+
'UYI',
|
|
153
|
+
'UYU',
|
|
154
|
+
'UZS',
|
|
155
|
+
'VEF',
|
|
156
|
+
'VND',
|
|
157
|
+
'VUV',
|
|
158
|
+
'WST',
|
|
159
|
+
'XAF',
|
|
160
|
+
'XAG',
|
|
161
|
+
'XAU',
|
|
162
|
+
'XBA',
|
|
163
|
+
'XBB',
|
|
164
|
+
'XBC',
|
|
165
|
+
'XBD',
|
|
166
|
+
'XCD',
|
|
167
|
+
'XDR',
|
|
168
|
+
'XOF',
|
|
169
|
+
'XPD',
|
|
170
|
+
'XPF',
|
|
171
|
+
'XPT',
|
|
172
|
+
'XSU',
|
|
173
|
+
'XTS',
|
|
174
|
+
'XUA',
|
|
175
|
+
'XXX',
|
|
176
|
+
'YER',
|
|
177
|
+
'ZAR',
|
|
178
|
+
'ZMW',
|
|
179
|
+
'ZWL'
|
|
180
|
+
]
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// Tipo de documento de exoneración o autorización.
|
|
2
|
+
export const enumExoneracionType = [
|
|
3
|
+
'01', // Compras Autorizadas
|
|
4
|
+
'02', // Ventas exentas a diplomáticos
|
|
5
|
+
'03', // Autorizado por Ley Especial
|
|
6
|
+
'04', // Exenciones Dirección General de Hacienda
|
|
7
|
+
'05', // Transitorio V
|
|
8
|
+
'06', // Transitorio IX
|
|
9
|
+
'07', // Transitorio XVII
|
|
10
|
+
'99' // Otros
|
|
11
|
+
]
|
package/src/data/impuestos.ts
CHANGED
|
@@ -21,3 +21,29 @@ export const tipoDocumento = {
|
|
|
21
21
|
desc: 'Servicio'
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
|
+
|
|
25
|
+
// Código del impuesto
|
|
26
|
+
export const enumImpuestoTypeCodigo = [
|
|
27
|
+
'01', // Impuesto al valor agregado
|
|
28
|
+
'02', // Impuesto Selectivo de Consumo
|
|
29
|
+
'03', // Impuesto único a los combustivos
|
|
30
|
+
'04', // Impuesto específico de bebidas alcohólicas
|
|
31
|
+
'05', // Impuesto específico sobre las bebidas envasadas sin contenido alcohólico y jabones de tocador
|
|
32
|
+
'06', // Impuesto a los productos de tabaco
|
|
33
|
+
'07', // IVA (cálculo especial)
|
|
34
|
+
'08', // IVA Regimen de Bienes Usados (Factor)
|
|
35
|
+
'12', // Impuesto Especifico al cemento
|
|
36
|
+
'99' // Otros
|
|
37
|
+
]
|
|
38
|
+
|
|
39
|
+
// Código de la tarifa del impuesto.
|
|
40
|
+
export const enumImpuestoTypeCodigoTarifa = [
|
|
41
|
+
'01', // Tarifa 0% (Exento),
|
|
42
|
+
'02', // Tarifa Reducida 1%
|
|
43
|
+
'03', // Tarifa reducida 2%
|
|
44
|
+
'04', // Tarifa reducida 4%
|
|
45
|
+
'05', // Transitorio 0%
|
|
46
|
+
'06', // Transitorio 4%
|
|
47
|
+
'07', // Transitorio 8%
|
|
48
|
+
'08' // Tarifa General 13%
|
|
49
|
+
]
|
package/src/data/tipoCedula.ts
CHANGED
|
@@ -38,3 +38,102 @@ export const unidadesDeMedida = [
|
|
|
38
38
|
description: 'Metro cuadrado'
|
|
39
39
|
}
|
|
40
40
|
]
|
|
41
|
+
|
|
42
|
+
export const enumUnidadDeMedidaType = [
|
|
43
|
+
'Al',
|
|
44
|
+
'Alc',
|
|
45
|
+
'Cm',
|
|
46
|
+
'I',
|
|
47
|
+
'Os',
|
|
48
|
+
'Sp',
|
|
49
|
+
'Spe',
|
|
50
|
+
'St',
|
|
51
|
+
'd',
|
|
52
|
+
'm',
|
|
53
|
+
'kg',
|
|
54
|
+
's',
|
|
55
|
+
'A',
|
|
56
|
+
'K',
|
|
57
|
+
'mol',
|
|
58
|
+
'cd',
|
|
59
|
+
'm²',
|
|
60
|
+
'm³',
|
|
61
|
+
'm/s',
|
|
62
|
+
'm/s²',
|
|
63
|
+
'1/m',
|
|
64
|
+
'kg/m³',
|
|
65
|
+
'A/m²',
|
|
66
|
+
'A/m',
|
|
67
|
+
'mol/m³',
|
|
68
|
+
'cd/m²',
|
|
69
|
+
'1',
|
|
70
|
+
'rad',
|
|
71
|
+
'sr',
|
|
72
|
+
'Hz',
|
|
73
|
+
'N',
|
|
74
|
+
'Pa',
|
|
75
|
+
'J',
|
|
76
|
+
'W',
|
|
77
|
+
'C',
|
|
78
|
+
'V',
|
|
79
|
+
'F',
|
|
80
|
+
'Ω',
|
|
81
|
+
'S',
|
|
82
|
+
'Wb',
|
|
83
|
+
'T',
|
|
84
|
+
'H',
|
|
85
|
+
'°C',
|
|
86
|
+
'lm',
|
|
87
|
+
'lx',
|
|
88
|
+
'Bq',
|
|
89
|
+
'Gy',
|
|
90
|
+
'Sv',
|
|
91
|
+
'kat',
|
|
92
|
+
'Pa·s',
|
|
93
|
+
'N·m',
|
|
94
|
+
'N/m',
|
|
95
|
+
'rad/s',
|
|
96
|
+
'rad/s²',
|
|
97
|
+
'W/m²',
|
|
98
|
+
'J/K',
|
|
99
|
+
'J/(kg·K)',
|
|
100
|
+
'J/kg',
|
|
101
|
+
'W/(m·K)',
|
|
102
|
+
'J/m³',
|
|
103
|
+
'V/m',
|
|
104
|
+
'C/m³',
|
|
105
|
+
'C/m²',
|
|
106
|
+
'F/m',
|
|
107
|
+
'H/m',
|
|
108
|
+
'J/mol',
|
|
109
|
+
'J/(mol·K)',
|
|
110
|
+
'C/kg',
|
|
111
|
+
'Gy/s',
|
|
112
|
+
'W/sr',
|
|
113
|
+
'W/(m²·sr)',
|
|
114
|
+
'kat/m³',
|
|
115
|
+
'min',
|
|
116
|
+
'h',
|
|
117
|
+
'd',
|
|
118
|
+
'º',
|
|
119
|
+
'´',
|
|
120
|
+
'´´',
|
|
121
|
+
'L',
|
|
122
|
+
't',
|
|
123
|
+
'Np',
|
|
124
|
+
'B',
|
|
125
|
+
'eV',
|
|
126
|
+
'u',
|
|
127
|
+
'ua',
|
|
128
|
+
'Unid',
|
|
129
|
+
'Gal',
|
|
130
|
+
'g',
|
|
131
|
+
'Km',
|
|
132
|
+
'Kw',
|
|
133
|
+
'ln',
|
|
134
|
+
'cm',
|
|
135
|
+
'mL',
|
|
136
|
+
'mm',
|
|
137
|
+
'Oz',
|
|
138
|
+
'Otros'
|
|
139
|
+
]
|
package/src/debitNote.ts
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { NotaDebitoContenedor } from '
|
|
3
|
-
import { genXML } from '
|
|
4
|
-
import { send } from '
|
|
5
|
-
import { genClaveObj, genString, parseOptions } from '
|
|
1
|
+
import { ClientPayload, XmlOpt } from '@src/types/globalInterfaces'
|
|
2
|
+
import { NotaDebitoContenedor } from '@src/types/xml/notaDeDebito'
|
|
3
|
+
import { genXML } from '@src/lib/genXML/index'
|
|
4
|
+
import { send } from '@src/services/send/index'
|
|
5
|
+
import { genClaveObj, genString, parseOptions } from '@src/lib/genClave/index'
|
|
6
6
|
import {
|
|
7
7
|
getBillResum,
|
|
8
8
|
getReceiver,
|
|
9
9
|
getSender,
|
|
10
10
|
getSimpleReceiver,
|
|
11
11
|
getSimpleSender
|
|
12
|
-
} from '
|
|
12
|
+
} from '@src/helpers/comprobantes'
|
|
13
13
|
|
|
14
14
|
const VOUCHER_TYPE = 'ND'
|
|
15
15
|
|
|
16
16
|
export function parseCreditNote(options: {
|
|
17
|
-
frontEndRequest:
|
|
17
|
+
frontEndRequest: ClientPayload;
|
|
18
18
|
consecutivo: string;
|
|
19
19
|
clave: string;
|
|
20
20
|
date: Date;
|
|
@@ -41,7 +41,7 @@ export function parseCreditNote(options: {
|
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
function sendMessage(options: {
|
|
44
|
-
frontEndRequest:
|
|
44
|
+
frontEndRequest: ClientPayload;
|
|
45
45
|
token: string;
|
|
46
46
|
clave: string;
|
|
47
47
|
date: Date;
|
|
@@ -65,7 +65,7 @@ function sendMessage(options: {
|
|
|
65
65
|
|
|
66
66
|
export default async (options: {
|
|
67
67
|
token: string;
|
|
68
|
-
frontEndRequest:
|
|
68
|
+
frontEndRequest: ClientPayload;
|
|
69
69
|
xmlOpt: XmlOpt;
|
|
70
70
|
}): Promise<any> => {
|
|
71
71
|
const date = new Date()
|
package/src/electronicBill.ts
CHANGED
|
@@ -1,13 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { genClaveObj, genString, parseOptions } from '
|
|
3
|
-
import genJSON from '
|
|
4
|
-
import { send } from '
|
|
1
|
+
import { ClientPayload, FinalMessagePerson } from '@src/types/globalInterfaces'
|
|
2
|
+
import { genClaveObj, genString, parseOptions } from '@src/lib/genClave/index'
|
|
3
|
+
import genJSON from '@src/lib/genJSON/index'
|
|
4
|
+
import { send } from '@src/services/send/index'
|
|
5
5
|
|
|
6
6
|
const DEFAULT_VALUES = {
|
|
7
7
|
tipoIdentificacion: '01'
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
const encodeXML = (xmlStr: string): string => {
|
|
11
|
+
const buffer = Buffer.from(xmlStr)
|
|
12
|
+
return buffer.toString('base64')
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function getSender(frontEndRequest: ClientPayload): FinalMessagePerson {
|
|
11
16
|
const sender = frontEndRequest.Emisor
|
|
12
17
|
return {
|
|
13
18
|
tipoIdentificacion: sender.Identificacion.Tipo || DEFAULT_VALUES.tipoIdentificacion,
|
|
@@ -15,7 +20,7 @@ function getSender(frontEndRequest: FrontEndRequest): FinalMessagePerson {
|
|
|
15
20
|
}
|
|
16
21
|
}
|
|
17
22
|
|
|
18
|
-
function getReceiver(frontEndRequest:
|
|
23
|
+
function getReceiver(frontEndRequest: ClientPayload): FinalMessagePerson {
|
|
19
24
|
const receiver = frontEndRequest.Receptor
|
|
20
25
|
return {
|
|
21
26
|
tipoIdentificacion: receiver.Identificacion.Tipo || DEFAULT_VALUES.tipoIdentificacion,
|
|
@@ -23,7 +28,7 @@ function getReceiver(frontEndRequest: FrontEndRequest): FinalMessagePerson {
|
|
|
23
28
|
}
|
|
24
29
|
}
|
|
25
30
|
|
|
26
|
-
export default async (token, frontEndRequest:
|
|
31
|
+
export default async (token, frontEndRequest: ClientPayload, xmlOpt): Promise<any> => {
|
|
27
32
|
const parsedOpts = parseOptions(frontEndRequest)
|
|
28
33
|
const claveObj = genClaveObj(parsedOpts)
|
|
29
34
|
const claveStr = genString(claveObj)
|
|
@@ -38,11 +43,14 @@ export default async (token, frontEndRequest: FrontEndRequest, xmlOpt): Promise<
|
|
|
38
43
|
fecha: date.toISOString(),
|
|
39
44
|
emisor: getSender(frontEndRequest),
|
|
40
45
|
receptor: getReceiver(frontEndRequest),
|
|
41
|
-
comprobanteXml: XML
|
|
46
|
+
comprobanteXml: encodeXML(XML)
|
|
42
47
|
}
|
|
43
|
-
|
|
48
|
+
const response = send(token, finalMesage).catch((err) => {
|
|
44
49
|
const response = err.response || {}
|
|
45
50
|
const header = response.headers || {}
|
|
51
|
+
console.log('response status code', err.response.status)
|
|
46
52
|
console.log('x-error-cause', header['x-error-cause'])
|
|
47
53
|
})
|
|
54
|
+
|
|
55
|
+
return response
|
|
48
56
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Resumen, Persona } from '
|
|
1
|
+
import { ClientPayload, FinalMessagePerson } from '@src/types/globalInterfaces'
|
|
2
|
+
import { Resumen, Persona } from '@src/types/facturaInterfaces'
|
|
3
3
|
|
|
4
4
|
const DEFAULT_VALUES = {
|
|
5
5
|
key: 0,
|
|
@@ -9,7 +9,7 @@ const DEFAULT_VALUES = {
|
|
|
9
9
|
tipoIdentificacion: '01'
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
export function getSimpleSender(frontEndRequest:
|
|
12
|
+
export function getSimpleSender(frontEndRequest: ClientPayload): FinalMessagePerson {
|
|
13
13
|
const sender = frontEndRequest.Emisor
|
|
14
14
|
return {
|
|
15
15
|
tipoIdentificacion: sender.Identificacion.Tipo || DEFAULT_VALUES.tipoIdentificacion,
|
|
@@ -17,7 +17,7 @@ export function getSimpleSender(frontEndRequest: FrontEndRequest): FinalMessageP
|
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
export function getSimpleReceiver(frontEndRequest:
|
|
20
|
+
export function getSimpleReceiver(frontEndRequest: ClientPayload): FinalMessagePerson {
|
|
21
21
|
const receiver = frontEndRequest.Receptor
|
|
22
22
|
return {
|
|
23
23
|
tipoIdentificacion: receiver.Identificacion.Tipo || DEFAULT_VALUES.tipoIdentificacion,
|
|
@@ -30,7 +30,7 @@ function calculateTaxes(billTotal: number, billTaxes: number): number {
|
|
|
30
30
|
return billTotal * taxes
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
export function getBillResum(frontEndRequest:
|
|
33
|
+
export function getBillResum(frontEndRequest: ClientPayload): Resumen {
|
|
34
34
|
const taxes = calculateTaxes(frontEndRequest.total, frontEndRequest.impuesto)
|
|
35
35
|
return {
|
|
36
36
|
CodigoTipoMoneda: {
|
|
@@ -53,7 +53,7 @@ export function getBillResum(frontEndRequest: FrontEndRequest): Resumen {
|
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
export function getSender(frontEndRequest:
|
|
56
|
+
export function getSender(frontEndRequest: ClientPayload): Persona {
|
|
57
57
|
const sender = frontEndRequest.Emisor
|
|
58
58
|
return {
|
|
59
59
|
Nombre: sender.Nombre,
|
|
@@ -75,7 +75,7 @@ export function getSender(frontEndRequest: FrontEndRequest): Persona {
|
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
-
export function getReceiver(frontEndRequest:
|
|
78
|
+
export function getReceiver(frontEndRequest: ClientPayload): Persona {
|
|
79
79
|
const receiver = frontEndRequest.Receptor
|
|
80
80
|
return {
|
|
81
81
|
Nombre: receiver.Nombre,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ClaveOpts, Clave, ClaveFecha, Consecutivo } from '
|
|
2
|
-
import {
|
|
3
|
-
import { tipoDocumento } from '
|
|
1
|
+
import { ClaveOpts, Clave, ClaveFecha, Consecutivo } from '@src/lib/genClave/interfaces'
|
|
2
|
+
import { ClientPayload, FinalMessagePerson } from '@src/types/globalInterfaces'
|
|
3
|
+
import { tipoDocumento } from '@src/data/tipoDocumento'
|
|
4
4
|
|
|
5
5
|
const DEFAULT_VALUES = {
|
|
6
6
|
tipoDocumento: '01',
|
|
@@ -19,7 +19,7 @@ function getConsecutivo(opts: {
|
|
|
19
19
|
sucursal: opts.sucursal || '001',
|
|
20
20
|
terminal: opts.terminal || '00001',
|
|
21
21
|
tipoDocumento: tipoDocNum.code || '01',
|
|
22
|
-
consecutivo: opts.consecutivo
|
|
22
|
+
consecutivo: String(opts.consecutivo).padStart(10, '0')
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
|
|
@@ -28,7 +28,7 @@ export function consecutivoStr(consecutivoObj: any): string {
|
|
|
28
28
|
return Object.values(cons).join('')
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
function getSender(frontEndRequest:
|
|
31
|
+
function getSender(frontEndRequest: ClientPayload): FinalMessagePerson {
|
|
32
32
|
const sender = frontEndRequest.Emisor
|
|
33
33
|
return {
|
|
34
34
|
tipoIdentificacion: sender.Identificacion.Tipo || DEFAULT_VALUES.tipoIdentificacion,
|
|
@@ -107,7 +107,7 @@ export function stringToClave(claveStr: string): Clave {
|
|
|
107
107
|
}
|
|
108
108
|
}
|
|
109
109
|
|
|
110
|
-
export function parseOptions(frontEndRequest:
|
|
110
|
+
export function parseOptions(frontEndRequest: ClientPayload): ClaveOpts {
|
|
111
111
|
const sender = getSender(frontEndRequest)
|
|
112
112
|
return {
|
|
113
113
|
cedulaEmisor: sender.numeroIdentificacion,
|
|
@@ -122,7 +122,7 @@ export function parseOptions(frontEndRequest: FrontEndRequest): ClaveOpts {
|
|
|
122
122
|
}
|
|
123
123
|
}
|
|
124
124
|
|
|
125
|
-
export function getClave(frontEndRequest:
|
|
125
|
+
export function getClave(frontEndRequest: ClientPayload): string {
|
|
126
126
|
const claveOptions = parseOptions(frontEndRequest)
|
|
127
127
|
return genClave(claveOptions)
|
|
128
128
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { MensajeReceptorContenedor } from '
|
|
2
|
-
import { tipoDocumento } from '
|
|
1
|
+
import { MensajeReceptorContenedor } from '@src/types/xml/mensajeReceptor'
|
|
2
|
+
import { tipoDocumento } from '@src/data/tipoDocumento'
|
|
3
3
|
|
|
4
4
|
export function getMsjObj(opts: {
|
|
5
5
|
fullInvoice: any;
|
package/src/lib/genJSON/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { FacturaElectronicaContenedor, Resumen, Persona, Impuesto, LineaDetalle } from '
|
|
3
|
-
import { genXML } from '
|
|
1
|
+
import { ClientPayload } from '@src/types/globalInterfaces'
|
|
2
|
+
import { FacturaElectronicaContenedor, Resumen, Persona, Impuesto, LineaDetalle } from '@src/types/facturaInterfaces'
|
|
3
|
+
import { genXML } from '@src/lib/genXML'
|
|
4
4
|
|
|
5
5
|
// Default XML Values
|
|
6
6
|
const DEFAULT_VALUES = {
|
|
@@ -44,7 +44,7 @@ function getBillResum(lines: LineaDetalle[]): Resumen {
|
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
function getSender(frontEndRequest:
|
|
47
|
+
function getSender(frontEndRequest: ClientPayload): Persona {
|
|
48
48
|
const sender = frontEndRequest.Emisor
|
|
49
49
|
return {
|
|
50
50
|
Nombre: sender.Nombre,
|
|
@@ -91,7 +91,7 @@ function setLinesDefaults(lines: LineaDetalle[]): LineaDetalle[] {
|
|
|
91
91
|
})
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
-
function getReceiver(frontEndRequest:
|
|
94
|
+
function getReceiver(frontEndRequest: ClientPayload): Persona {
|
|
95
95
|
const receiver = frontEndRequest.Receptor
|
|
96
96
|
return {
|
|
97
97
|
Nombre: receiver.Nombre,
|
|
@@ -104,26 +104,28 @@ function getReceiver(frontEndRequest: FrontEndRequest): Persona {
|
|
|
104
104
|
}
|
|
105
105
|
}
|
|
106
106
|
|
|
107
|
-
export default async (frontEndRequest:
|
|
107
|
+
export default async (frontEndRequest: ClientPayload, date: any, clave: string, consecutivo: string, options: any): Promise<any> => {
|
|
108
108
|
const receiver = getReceiver(frontEndRequest)
|
|
109
109
|
const sender = getSender(frontEndRequest)
|
|
110
110
|
const lines = setLinesDefaults(frontEndRequest.LineasDetalle)
|
|
111
|
+
const key = frontEndRequest.facturaElectronicaType || 'FacturaElectronica'
|
|
112
|
+
const body = {
|
|
113
|
+
Clave: clave,
|
|
114
|
+
CodigoActividad: frontEndRequest.actividad.padStart(6, '0'),
|
|
115
|
+
NumeroConsecutivo: consecutivo,
|
|
116
|
+
FechaEmision: date,
|
|
117
|
+
Emisor: sender,
|
|
118
|
+
Receptor: receiver,
|
|
119
|
+
CondicionVenta: '01',
|
|
120
|
+
MedioPago: '01',
|
|
121
|
+
DetalleServicio: {
|
|
122
|
+
LineaDetalle: lines
|
|
123
|
+
},
|
|
124
|
+
ResumenFactura: getBillResum(lines)
|
|
125
|
+
}
|
|
111
126
|
const factura: FacturaElectronicaContenedor = {
|
|
112
|
-
|
|
113
|
-
Clave: clave,
|
|
114
|
-
CodigoActividad: frontEndRequest.actividad.padStart(6, '0'),
|
|
115
|
-
NumeroConsecutivo: consecutivo,
|
|
116
|
-
FechaEmision: date,
|
|
117
|
-
Emisor: sender,
|
|
118
|
-
Receptor: receiver,
|
|
119
|
-
CondicionVenta: '01',
|
|
120
|
-
MedioPago: '01',
|
|
121
|
-
DetalleServicio: {
|
|
122
|
-
LineaDetalle: lines
|
|
123
|
-
},
|
|
124
|
-
ResumenFactura: getBillResum(lines)
|
|
125
|
-
}
|
|
127
|
+
[key]: body
|
|
126
128
|
}
|
|
127
|
-
const XML = await genXML(
|
|
129
|
+
const XML = await genXML(key, factura, options)
|
|
128
130
|
return XML
|
|
129
131
|
}
|
package/src/lib/genXML/index.ts
CHANGED
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
import { j2xParser, parse } from 'fast-xml-parser'
|
|
2
|
-
import { declaration, defaultOptions, xmlExtructures } from '
|
|
3
|
-
import sigXML from '
|
|
4
|
-
|
|
5
|
-
const encodeXML = (xmlStr: string): string => {
|
|
6
|
-
const buffer = Buffer.from(xmlStr)
|
|
7
|
-
return buffer.toString('base64')
|
|
8
|
-
}
|
|
2
|
+
import { declaration, defaultOptions, xmlExtructures } from '@src/lib/genXML/xmlConfig'
|
|
3
|
+
import sigXML from '@src/lib/genXML/sigXML/index'
|
|
9
4
|
|
|
10
5
|
export const objToXML = (xmlStructure: string, obj: object): string => {
|
|
11
6
|
const parser = new j2xParser(defaultOptions) // eslint-disable-line new-cap
|
|
@@ -23,8 +18,7 @@ export async function genXML(xmlStructure: string, obj: object, options?: {
|
|
|
23
18
|
const xml = objToXML(xmlStructure, obj)
|
|
24
19
|
if (!options) return xml
|
|
25
20
|
const signedXML = await sigXML(xml, options.buffer, options.password)
|
|
26
|
-
|
|
27
|
-
return encodeXML(signedXML)
|
|
21
|
+
return signedXML
|
|
28
22
|
}
|
|
29
23
|
|
|
30
24
|
export const xmlToJson = (xml: string): any => {
|
|
@@ -21,11 +21,7 @@ function preparePems(privatePem, publicPem, certPem): any {
|
|
|
21
21
|
|
|
22
22
|
function fromBase64(base64Text: string): any {
|
|
23
23
|
base64Text = base64Text.replace(/\n/g, '').replace(/\r/g, '').replace(/\t/g, '').replace(/\s/g, '')
|
|
24
|
-
|
|
25
|
-
return this.FromBinary(atob(base64Text))
|
|
26
|
-
} else {
|
|
27
|
-
return new Uint8Array(Buffer.from(base64Text, 'base64')).buffer
|
|
28
|
-
}
|
|
24
|
+
return new Uint8Array(Buffer.from(base64Text, 'base64')).buffer
|
|
29
25
|
}
|
|
30
26
|
|
|
31
27
|
function convertFromBase64(pems): any {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Application, SignedXml, Parse, OptionsXAdES } from 'xadesjs'
|
|
2
2
|
import { Crypto } from '@peculiar/webcrypto'
|
|
3
|
-
import { genKeysAndCert } from '
|
|
3
|
+
import { genKeysAndCert } from '@src/lib/genXML/sigXML/genKeysAndCert'
|
|
4
4
|
import { XMLSerializer } from 'xmldom-alpha'
|
|
5
5
|
|
|
6
6
|
function addSigToXML(xml: Document, signature: any): string {
|