@facturacr/atv-sdk 2.0.0 → 2.0.1-alpha

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 (106) hide show
  1. package/.eslintignore +3 -0
  2. package/.eslintrc.js +23 -23
  3. package/.github/dependabot.yml +11 -0
  4. package/.github/workflows/ci.yml +14 -12
  5. package/README.md +9 -2
  6. package/__tests__/stubs/commonExpectedXml.xml +14 -16
  7. package/__tests__/stubs/createDocument.data.ts +18 -1
  8. package/__tests__/stubs/frontendRequest.stub.ts +0 -1
  9. package/__tests__/stubs/token.stub.ts +9 -9
  10. package/__tests__/tests/ATV/__snapshots__/create-document.test.ts.snap +1 -1
  11. package/__tests__/tests/ATV/create-document.test.ts +8 -8
  12. package/__tests__/tests/ATV/create-receptor-message.test.ts +41 -36
  13. package/dist/src/ATV/core/CreateDocFactory.d.ts +11 -3
  14. package/dist/src/ATV/core/CreateDocFactory.js +3 -3
  15. package/dist/src/ATV/core/CreateDocFactory.js.map +1 -1
  16. package/dist/src/ATV/core/Document.d.ts +2 -2
  17. package/dist/src/ATV/core/Document.js +7 -4
  18. package/dist/src/ATV/core/Document.js.map +1 -1
  19. package/dist/src/ATV/core/DocumentType.d.ts +2 -3
  20. package/dist/src/ATV/core/DocumentType.js +1 -0
  21. package/dist/src/ATV/core/DocumentType.js.map +1 -1
  22. package/dist/src/ATV/core/FullConsecutive.d.ts +2 -1
  23. package/dist/src/ATV/core/FullConsecutive.js.map +1 -1
  24. package/dist/src/ATV/core/OrderLine.js +8 -1
  25. package/dist/src/ATV/core/OrderLine.js.map +1 -1
  26. package/dist/src/ATV/core/Person.d.ts +2 -2
  27. package/dist/src/ATV/core/ReceptorConsecutive.js.map +1 -1
  28. package/dist/src/ATV/core/ReferenceInformation.js.map +1 -1
  29. package/dist/src/ATV/core/types.d.ts +3 -2
  30. package/dist/src/ATV/core/types.js.map +1 -1
  31. package/dist/src/ATV/index.d.ts +2 -2
  32. package/dist/src/ATV/index.js +2 -2
  33. package/dist/src/ATV/mappers/billDocToAtv.js +32 -26
  34. package/dist/src/ATV/mappers/billDocToAtv.js.map +1 -1
  35. package/dist/src/ATV/types.d.ts +1 -1
  36. package/dist/src/ATV/useCases/createDocument/index.js +5 -9
  37. package/dist/src/ATV/useCases/createDocument/index.js.map +1 -1
  38. package/dist/src/ATV/useCases/createDocument/types.d.ts +4 -3
  39. package/dist/src/ATV/useCases/createReceptorMessage/index.d.ts +6 -5
  40. package/dist/src/ATV/useCases/createReceptorMessage/index.js +3 -3
  41. package/dist/src/ATV/useCases/createReceptorMessage/index.js.map +1 -1
  42. package/dist/src/helpers/comprobantes.js +10 -1
  43. package/dist/src/helpers/comprobantes.js.map +1 -1
  44. package/dist/src/lib/genClave/index.d.ts +8 -1
  45. package/dist/src/lib/genClave/index.js +5 -0
  46. package/dist/src/lib/genClave/index.js.map +1 -1
  47. package/dist/src/lib/genXML/index.js +6 -4
  48. package/dist/src/lib/genXML/index.js.map +1 -1
  49. package/dist/src/lib/genXML/sigXML/index.js +7 -4
  50. package/dist/src/lib/genXML/sigXML/index.js.map +1 -1
  51. package/dist/src/services/getToken/GetToken.js +0 -3
  52. package/dist/src/services/getToken/GetToken.js.map +1 -1
  53. package/dist/src/services/getToken/__tests__/GetToken.test.js +0 -1
  54. package/dist/src/services/getToken/__tests__/GetToken.test.js.map +1 -1
  55. package/dist/src/types/facturaInterfaces.d.ts +3 -3
  56. package/dist/src/xmlSchemaHeaderMap.d.ts +70 -0
  57. package/dist/src/xmlSchemaHeaderMap.js +30 -0
  58. package/dist/src/xmlSchemaHeaderMap.js.map +1 -0
  59. package/doc/atv-structures/4.3/FacturaElectronica_V4.3.xsd.xml +1633 -478
  60. package/doc/atv-structures/4.4/TiqueteElectronico_V4.4.xsd.xml +2817 -0
  61. package/doc/json-schemas/4.4/fe.json +544 -0
  62. package/doc/json-schemas/4.4/te.json +420 -0
  63. package/doc/testing.md +27 -0
  64. package/examples/README.md +10 -35
  65. package/examples/atvAccept.ts +18 -9
  66. package/examples/consultXML.ts +1 -0
  67. package/examples/{createAndSend.ts → createAndSendFE.ts} +11 -8
  68. package/examples/createAndSendTE.ts +73 -0
  69. package/examples/createCreditNote.ts +10 -6
  70. package/examples/createDebitNote.ts +2 -0
  71. package/examples/getToken.ts +2 -0
  72. package/package.json +3 -2
  73. package/src/ATV/core/CreateDocFactory.ts +32 -23
  74. package/src/ATV/core/Document.ts +7 -7
  75. package/src/ATV/core/DocumentType.ts +10 -3
  76. package/src/ATV/core/FullConsecutive.ts +2 -1
  77. package/src/ATV/core/OrderLine.ts +7 -1
  78. package/src/ATV/core/Person.ts +2 -2
  79. package/src/ATV/core/ReceptorConsecutive.ts +16 -16
  80. package/src/ATV/core/ReferenceInformation.ts +6 -6
  81. package/src/ATV/core/types.ts +7 -6
  82. package/src/ATV/index.ts +3 -3
  83. package/src/ATV/mappers/billDocToAtv.ts +35 -15
  84. package/src/ATV/types.ts +1 -1
  85. package/src/ATV/useCases/createDocument/index.ts +8 -8
  86. package/src/ATV/useCases/createDocument/types.ts +5 -6
  87. package/src/ATV/useCases/createReceptorMessage/index.ts +94 -93
  88. package/src/helpers/comprobantes.ts +10 -1
  89. package/src/lib/genClave/index.ts +10 -3
  90. package/src/lib/genXML/index.ts +3 -1
  91. package/src/lib/genXML/sigXML/index.ts +6 -3
  92. package/src/services/getToken/GetToken.ts +0 -3
  93. package/src/services/getToken/__tests__/GetToken.test.ts +0 -1
  94. package/src/types/facturaInterfaces.ts +3 -4
  95. package/src/xmlSchemaHeaderMap.ts +37 -0
  96. package/tools/readXML.ts +2 -0
  97. package/tools/xsdToJsonSchema.ts +1 -0
  98. package/tsconfig.json +1 -0
  99. package/dist/src/ATV/core/documentNames.types.d.ts +0 -1
  100. package/dist/src/ATV/core/documentNames.types.js +0 -3
  101. package/dist/src/ATV/core/documentNames.types.js.map +0 -1
  102. package/dist/src/lib/genXML/xmlConfig.d.ts +0 -55
  103. package/dist/src/lib/genXML/xmlConfig.js +0 -42
  104. package/dist/src/lib/genXML/xmlConfig.js.map +0 -1
  105. package/src/ATV/core/documentNames.types.ts +0 -6
  106. package/src/lib/genXML/xmlConfig.ts +0 -60
@@ -0,0 +1,420 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://cdn.comprobanteselectronicos.go.cr/json-schemas/v4.4/tiqueteElectronico",
4
+ "title": "TiqueteElectronico",
5
+ "type": "object",
6
+ "properties": {
7
+ "Clave": {
8
+ "type": "string",
9
+ "pattern": "^\\d{50}$"
10
+ },
11
+ "ProveedorSistemas": {
12
+ "type": "string",
13
+ "maxLength": 20
14
+ },
15
+ "CodigoActividadEmisor": {
16
+ "type": "string",
17
+ "minLength": 6,
18
+ "maxLength": 6
19
+ },
20
+ "NumeroConsecutivo": {
21
+ "type": "string",
22
+ "pattern": "^\\d{20}$"
23
+ },
24
+ "FechaEmision": {
25
+ "type": "string",
26
+ "format": "date-time"
27
+ },
28
+ "Emisor": { "$ref": "#/$defs/EmisorType" },
29
+ "Receptor": { "$ref": "#/$defs/ReceptorType" },
30
+ "CondicionVenta": {
31
+ "type": "string",
32
+ "enum": [
33
+ "01",
34
+ "02",
35
+ "03",
36
+ "04",
37
+ "05",
38
+ "06",
39
+ "07",
40
+ "08",
41
+ "10",
42
+ "13",
43
+ "14",
44
+ "15",
45
+ "99"
46
+ ]
47
+ },
48
+ "CondicionVentaOtros": {
49
+ "type": "string",
50
+ "minLength": 5,
51
+ "maxLength": 100
52
+ },
53
+ "PlazoCredito": {
54
+ "type": "integer",
55
+ "minimum": 0,
56
+ "maximum": 99999
57
+ },
58
+ "DetalleServicio": {
59
+ "type": "object",
60
+ "properties": {
61
+ "LineaDetalle": {
62
+ "type": "array",
63
+ "maxItems": 1000,
64
+ "items": { "$ref": "#/$defs/LineaDetalleType" }
65
+ }
66
+ },
67
+ "required": ["LineaDetalle"]
68
+ },
69
+ "OtrosCargos": {
70
+ "type": "array",
71
+ "maxItems": 15,
72
+ "items": { "$ref": "#/$defs/OtrosCargosType" }
73
+ },
74
+ "ResumenFactura": { "$ref": "#/$defs/ResumenFacturaType" },
75
+ "InformacionReferencia": {
76
+ "type": "array",
77
+ "maxItems": 10,
78
+ "items": { "$ref": "#/$defs/InformacionReferenciaType" }
79
+ },
80
+ "Otros": {
81
+ "type": "object",
82
+ "properties": {
83
+ "OtroTexto": {
84
+ "type": "array",
85
+ "items": { "$ref": "#/$defs/OtroContenidoType" }
86
+ },
87
+ "OtroContenido": {
88
+ "type": "array",
89
+ "items": { "$ref": "#/$defs/OtroContenidoType" }
90
+ }
91
+ }
92
+ },
93
+ "ds:Signature": {
94
+ "type": "object"
95
+ }
96
+ },
97
+ "required": [
98
+ "Clave",
99
+ "ProveedorSistemas",
100
+ "CodigoActividadEmisor",
101
+ "NumeroConsecutivo",
102
+ "FechaEmision",
103
+ "Emisor",
104
+ "CondicionVenta",
105
+ "ResumenFactura",
106
+ "ds:Signature"
107
+ ],
108
+ "$defs": {
109
+ "EmisorType": {
110
+ "type": "object",
111
+ "properties": {
112
+ "Nombre": { "type": "string", "minLength": 5, "maxLength": 100 },
113
+ "Identificacion": { "$ref": "#/$defs/IdentificacionType" },
114
+ "Registrofiscal8707": { "type": "string", "maxLength": 12 },
115
+ "NombreComercial": {
116
+ "type": "string",
117
+ "minLength": 3,
118
+ "maxLength": 80
119
+ },
120
+ "Ubicacion": { "$ref": "#/$defs/UbicacionType" },
121
+ "Telefono": { "$ref": "#/$defs/TelefonoType" },
122
+ "CorreoElectronico": {
123
+ "type": "array",
124
+ "maxItems": 4,
125
+ "items": { "type": "string", "maxLength": 160 }
126
+ }
127
+ },
128
+ "required": ["Nombre", "Identificacion", "Ubicacion", "CorreoElectronico"]
129
+ },
130
+ "ReceptorType": {
131
+ "type": "object",
132
+ "properties": {
133
+ "Nombre": { "type": "string", "minLength": 3, "maxLength": 100 },
134
+ "Identificacion": { "$ref": "#/$defs/IdentificacionType" },
135
+ "NombreComercial": {
136
+ "type": "string",
137
+ "minLength": 3,
138
+ "maxLength": 80
139
+ },
140
+ "Ubicacion": { "$ref": "#/$defs/UbicacionType" },
141
+ "OtrasSenasExtranjero": {
142
+ "type": "string",
143
+ "minLength": 5,
144
+ "maxLength": 300
145
+ },
146
+ "Telefono": { "$ref": "#/$defs/TelefonoType" },
147
+ "CorreoElectronico": { "type": "string", "maxLength": 160 }
148
+ },
149
+ "required": ["Nombre"]
150
+ },
151
+ "IdentificacionType": {
152
+ "type": "object",
153
+ "properties": {
154
+ "Tipo": {
155
+ "type": "string",
156
+ "enum": ["01", "02", "03", "04", "05", "06"]
157
+ },
158
+ "Numero": { "type": "string", "maxLength": 20 }
159
+ },
160
+ "required": ["Tipo", "Numero"]
161
+ },
162
+ "UbicacionType": {
163
+ "type": "object",
164
+ "properties": {
165
+ "Provincia": { "type": "integer", "minimum": 1, "maximum": 9 },
166
+ "Canton": { "type": "integer", "minimum": 1, "maximum": 99 },
167
+ "Distrito": { "type": "integer", "minimum": 1, "maximum": 99 },
168
+ "Barrio": { "type": "string", "minLength": 5, "maxLength": 50 },
169
+ "OtrasSenas": { "type": "string", "minLength": 5, "maxLength": 250 }
170
+ },
171
+ "required": ["Provincia", "Canton", "Distrito", "OtrasSenas"]
172
+ },
173
+ "TelefonoType": {
174
+ "type": "object",
175
+ "properties": {
176
+ "CodigoPais": { "type": "integer", "minimum": 0, "maximum": 999 },
177
+ "NumTelefono": {
178
+ "type": "integer",
179
+ "minimum": 10000000,
180
+ "maximum": 99999999999999999999
181
+ }
182
+ },
183
+ "required": ["CodigoPais", "NumTelefono"]
184
+ },
185
+ "LineaDetalleType": {
186
+ "type": "object",
187
+ "properties": {
188
+ "NumeroLinea": { "type": "integer", "minimum": 1, "maximum": 1000 },
189
+ "CodigoCABYS": { "type": "string", "minLength": 13, "maxLength": 13 },
190
+ "CodigoComercial": {
191
+ "type": "array",
192
+ "maxItems": 5,
193
+ "items": { "$ref": "#/$defs/CodigoType" }
194
+ },
195
+ "Cantidad": { "type": "number" },
196
+ "UnidadMedida": { "type": "string" },
197
+ "UnidadMedidaComercial": { "type": "string", "maxLength": 20 },
198
+ "Detalle": { "type": "string", "minLength": 3, "maxLength": 200 },
199
+ "NumeroVINoSerie": {
200
+ "type": "array",
201
+ "maxItems": 1000,
202
+ "items": { "type": "string", "maxLength": 17 }
203
+ },
204
+ "RegistroMedicamento": { "type": "string", "maxLength": 100 },
205
+ "FormaFarmaceutica": { "type": "string", "maxLength": 3 },
206
+ "DetalleSurtido": { "type": "object" }, // Nested structure omitted for brevity
207
+ "PrecioUnitario": { "$ref": "#/$defs/DecimalDineroType" },
208
+ "MontoTotal": { "$ref": "#/$defs/DecimalDineroType" },
209
+ "Descuento": {
210
+ "type": "array",
211
+ "maxItems": 5,
212
+ "items": { "$ref": "#/$defs/DescuentoType" }
213
+ },
214
+ "SubTotal": { "$ref": "#/$defs/DecimalDineroType" },
215
+ "IVACobradoFabrica": { "type": "string", "enum": ["01", "02"] },
216
+ "BaseImponible": { "$ref": "#/$defs/DecimalDineroType" },
217
+ "Impuesto": {
218
+ "type": "array",
219
+ "maxItems": 1000,
220
+ "items": { "$ref": "#/$defs/ImpuestoType" }
221
+ },
222
+ "ImpuestoAsumidoEmisorFabrica": { "$ref": "#/$defs/DecimalDineroType" },
223
+ "ImpuestoNeto": { "$ref": "#/$defs/DecimalDineroType" },
224
+ "MontoTotalLinea": { "$ref": "#/$defs/DecimalDineroType" }
225
+ },
226
+ "required": [
227
+ "NumeroLinea",
228
+ "CodigoCABYS",
229
+ "Cantidad",
230
+ "UnidadMedida",
231
+ "Detalle",
232
+ "PrecioUnitario",
233
+ "MontoTotal",
234
+ "SubTotal",
235
+ "BaseImponible",
236
+ "Impuesto",
237
+ "ImpuestoAsumidoEmisorFabrica",
238
+ "ImpuestoNeto",
239
+ "MontoTotalLinea"
240
+ ]
241
+ },
242
+ "CodigoType": {
243
+ "type": "object",
244
+ "properties": {
245
+ "Tipo": {
246
+ "type": "string",
247
+ "enum": ["01", "02", "03", "04", "99"]
248
+ },
249
+ "Codigo": { "type": "string", "maxLength": 20 }
250
+ },
251
+ "required": ["Tipo", "Codigo"]
252
+ },
253
+ "DescuentoType": {
254
+ "type": "object",
255
+ "properties": {
256
+ "MontoDescuento": { "$ref": "#/$defs/DecimalDineroType" },
257
+ "CodigoDescuento": {
258
+ "type": "string",
259
+ "enum": ["01", "02", "03", "04", "05", "06", "07", "08", "09", "99"]
260
+ },
261
+ "CodigoDescuentoOTRO": {
262
+ "type": "string",
263
+ "minLength": 5,
264
+ "maxLength": 100
265
+ },
266
+ "NaturalezaDescuento": {
267
+ "type": "string",
268
+ "minLength": 3,
269
+ "maxLength": 80
270
+ }
271
+ },
272
+ "required": ["MontoDescuento", "CodigoDescuento"]
273
+ },
274
+ "ImpuestoType": {
275
+ "type": "object",
276
+ "properties": {
277
+ "Codigo": {
278
+ "type": "string",
279
+ "enum": ["01", "02", "03", "04", "05", "06", "07", "08", "12", "99"]
280
+ },
281
+ "CodigoImpuestoOTRO": {
282
+ "type": "string",
283
+ "minLength": 5,
284
+ "maxLength": 100
285
+ },
286
+ "CodigoTarifaIVA": { "type": "string" },
287
+ "Tarifa": { "type": "number" },
288
+ "FactorCalculoIVA": { "type": "number" },
289
+ "DatosImpuestoEspecifico": { "type": "object" }, // Nested structure omitted for brevity
290
+ "Monto": { "$ref": "#/$defs/DecimalDineroType" },
291
+ "Exoneracion": { "type": "object" } // Nested structure omitted for brevity
292
+ },
293
+ "required": ["Codigo", "Monto"]
294
+ },
295
+ "OtrosCargosType": {
296
+ "type": "object",
297
+ "properties": {
298
+ "TipoDocumentoOC": { "type": "string" },
299
+ "TipoDocumentoOTROS": {
300
+ "type": "string",
301
+ "minLength": 5,
302
+ "maxLength": 100
303
+ },
304
+ "IdentificacionTercero": { "$ref": "#/$defs/IdentificacionType" },
305
+ "NombreTercero": { "type": "string", "minLength": 5, "maxLength": 100 },
306
+ "Detalle": { "type": "string", "maxLength": 160 },
307
+ "PorcentajeOC": { "type": "number" },
308
+ "MontoCargo": { "$ref": "#/$defs/DecimalDineroType" }
309
+ },
310
+ "required": ["TipoDocumentoOC", "Detalle", "MontoCargo"]
311
+ },
312
+ "ResumenFacturaType": {
313
+ "type": "object",
314
+ "properties": {
315
+ "CodigoTipoMoneda": { "$ref": "#/$defs/CodigoMonedaType" },
316
+ "TotalServGravados": { "$ref": "#/$defs/DecimalDineroType" },
317
+ "TotalServExentos": { "$ref": "#/$defs/DecimalDineroType" },
318
+ "TotalServExonerado": { "$ref": "#/$defs/DecimalDineroType" },
319
+ "TotalServNoSujeto": { "$ref": "#/$defs/DecimalDineroType" },
320
+ "TotalMercanciasGravadas": { "$ref": "#/$defs/DecimalDineroType" },
321
+ "TotalMercanciasExentas": { "$ref": "#/$defs/DecimalDineroType" },
322
+ "TotalMercExonerada": { "$ref": "#/$defs/DecimalDineroType" },
323
+ "TotalMercNoSujeta": { "$ref": "#/$defs/DecimalDineroType" },
324
+ "TotalGravado": { "$ref": "#/$defs/DecimalDineroType" },
325
+ "TotalExento": { "$ref": "#/$defs/DecimalDineroType" },
326
+ "TotalExonerado": { "$ref": "#/$defs/DecimalDineroType" },
327
+ "TotalNoSujeto": { "$ref": "#/$defs/DecimalDineroType" },
328
+ "TotalVenta": { "$ref": "#/$defs/DecimalDineroType" },
329
+ "TotalDescuentos": { "$ref": "#/$defs/DecimalDineroType" },
330
+ "TotalVentaNeta": { "$ref": "#/$defs/DecimalDineroType" },
331
+ "TotalDesgloseImpuesto": {
332
+ "type": "array",
333
+ "maxItems": 1000,
334
+ "items": { "$ref": "#/$defs/TotalDesgloseImpuestoType" }
335
+ },
336
+ "TotalImpuesto": { "$ref": "#/$defs/DecimalDineroType" },
337
+ "TotalImpAsumEmisorFabrica": { "$ref": "#/$defs/DecimalDineroType" },
338
+ "TotalIVADevuelto": { "$ref": "#/$defs/DecimalDineroType" },
339
+ "TotalOtrosCargos": { "$ref": "#/$defs/DecimalDineroType" },
340
+ "MedioPago": {
341
+ "type": "array",
342
+ "maxItems": 4,
343
+ "items": { "$ref": "#/$defs/MedioPagoType" }
344
+ },
345
+ "TotalComprobante": { "$ref": "#/$defs/DecimalDineroType" }
346
+ },
347
+ "required": [
348
+ "CodigoTipoMoneda",
349
+ "TotalVenta",
350
+ "TotalVentaNeta",
351
+ "TotalComprobante"
352
+ ]
353
+ },
354
+ "CodigoMonedaType": {
355
+ "type": "object",
356
+ "properties": {
357
+ "CodigoMoneda": { "type": "string" },
358
+ "TipoCambio": { "$ref": "#/$defs/DecimalDineroType" }
359
+ },
360
+ "required": ["CodigoMoneda", "TipoCambio"]
361
+ },
362
+ "DecimalDineroType": {
363
+ "type": "number",
364
+ "minimum": 0,
365
+ "maximum": 9999999999999.99999
366
+ },
367
+ "TotalDesgloseImpuestoType": {
368
+ "type": "object",
369
+ "properties": {
370
+ "Codigo": { "type": "string" },
371
+ "CodigoTarifaIVA": { "type": "string" },
372
+ "TotalMontoImpuesto": { "$ref": "#/$defs/DecimalDineroType" }
373
+ },
374
+ "required": ["Codigo", "TotalMontoImpuesto"]
375
+ },
376
+ "MedioPagoType": {
377
+ "type": "object",
378
+ "properties": {
379
+ "TipoMedioPago": {
380
+ "type": "string",
381
+ "enum": ["01", "02", "03", "04", "05", "06", "07", "99"]
382
+ },
383
+ "MedioPagoOtros": {
384
+ "type": "string",
385
+ "minLength": 3,
386
+ "maxLength": 100
387
+ },
388
+ "TotalMedioPago": { "$ref": "#/$defs/DecimalDineroType" }
389
+ }
390
+ },
391
+ "InformacionReferenciaType": {
392
+ "type": "object",
393
+ "properties": {
394
+ "TipoDocIR": { "type": "string" },
395
+ "TipoDocRefOTRO": {
396
+ "type": "string",
397
+ "minLength": 5,
398
+ "maxLength": 100
399
+ },
400
+ "Numero": { "type": "string", "maxLength": 50 },
401
+ "FechaEmisionIR": { "type": "string", "format": "date-time" },
402
+ "Codigo": { "type": "string" },
403
+ "CodigoReferenciaOTRO": {
404
+ "type": "string",
405
+ "minLength": 5,
406
+ "maxLength": 100
407
+ },
408
+ "Razon": { "type": "string", "maxLength": 180 }
409
+ },
410
+ "required": ["TipoDocIR", "FechaEmisionIR"]
411
+ },
412
+ "OtroContenidoType": {
413
+ "type": "object",
414
+ "properties": {
415
+ "codigo": { "type": "string" },
416
+ "value": { "type": "string", "maxLength": 500 }
417
+ }
418
+ }
419
+ }
420
+ }
package/doc/testing.md ADDED
@@ -0,0 +1,27 @@
1
+ ## Testing
2
+ Configurar .env file basado en .env.example
3
+
4
+ ```
5
+ cp .env.example .env
6
+ ```
7
+
8
+ Para probar las funcionalidades se recomienda crear un .env en donde se especifiquen datos de prueba.
9
+ ```
10
+ USERNAME_TEST= ## Provided be ATV System
11
+ PASSWORD_TEST= ## Provided be ATV System
12
+ IS_STG=1
13
+ SOURCE_P12_URI= ## Provided be ATV System
14
+ SOURCE_P12_PASSPORT= ## Provided be ATV System
15
+ SOURCE_URI_XML_OUTPUT= ## Custom OS PATH
16
+ XML_TO_CONFIRM= ## Custom OS PATH
17
+ ```
18
+ Example:
19
+ ```
20
+ USERNAME_TEST=USER@stag.comprobanteselectronicos.go.cr
21
+ PASSWORD_TEST=PASSWORD_PROVIDED_BY_ATV
22
+ IS_STG="1"
23
+ SOURCE_P12_URI=$PATH/#####.p12
24
+ SOURCE_P12_PASSPORT=1234
25
+ SOURCE_URI_XML_OUTPUT=$PATH/__test__/output/output.xml
26
+ XML_TO_CONFIRM=$PATH/__test__/input/Comprobante_Electronico_####_####.xml
27
+ ```
@@ -1,66 +1,41 @@
1
1
  # Ejemplos con implementaciones para pruebas
2
+ Asegurate de ejecutar la configuración inicial del proyecto.
2
3
 
3
- Configurar .env file basado en .env.example
4
+ Para probar crear y enviar factura electronica. Ejemplo:
4
5
  ```
5
- cp .env.example .env
6
+ yarn ts-node -r tsconfig-paths/register --require dotenv/config examples/createAndSendFE.ts 1
6
7
  ```
7
8
 
9
+ Para probar crear y enviar tiquete electronico. Ejemplo:
8
10
  ```
9
- yarn build
11
+ yarn ts-node -r tsconfig-paths/register --require dotenv/config examples/createAndSendTE.ts 1
10
12
  ```
11
13
 
12
- Para probar crear y enviar factura
13
- ```
14
- yarn ts-node -r tsconfig-paths/register --require dotenv/config examples/createAndSend.ts 1
15
- ```
16
-
17
- Para aceptar una factura
14
+ Para aceptar una factura. Ejemplo:
18
15
  ```
19
16
  yarn ts-node -r tsconfig-paths/register --require dotenv/config examples/atvAccept.ts
20
17
  ```
21
18
 
22
- Para crear y enviar una nota de credito
19
+ Para crear y enviar una nota de credito. Ejemplo:
23
20
  ```
24
21
  yarn ts-node -r tsconfig-paths/register --require dotenv/config examples/createCreditNote.ts
25
22
  ```
26
23
 
27
- Para probar genJson HeaderXML
24
+ Para probar genJson HeaderXML. Ejemplo:
28
25
  ```
29
26
  yarn ts-node -r tsconfig-paths/register --require dotenv/config examples/genBasicXML.ts
30
27
  ```
31
28
 
32
- Generar la clave
29
+ Generar la clave. Ejemplo:
33
30
  ```
34
31
  yarn ts-node -r tsconfig-paths/register--require dotenv/config examples/getClave.ts
35
32
  ```
36
33
 
37
- Para obtener un token
34
+ Para obtener un token. Ejemplo:
38
35
  ```
39
36
  yarn ts-node -r tsconfig-paths/register --require dotenv/config examples/getToken.ts
40
37
  ```
41
38
 
42
- ## Testing
43
- Para probar las funcionalidades se recomienda crear un .env en donde se especifiquen datos de prueba.
44
- ```
45
- USERNAME_TEST= ## Provided be ATV System
46
- PASSWORD_TEST= ## Provided be ATV System
47
- IS_STG=1
48
- SOURCE_P12_URI= ## Provided be ATV System
49
- SOURCE_P12_PASSPORT= ## Provided be ATV System
50
- SOURCE_URI_XML_OUTPUT= ## Custom OS PATH
51
- XML_TO_CONFIRM= ## Custom OS PATH
52
- ```
53
- Example:
54
- ```
55
- USERNAME_TEST=USER@stag.comprobanteselectronicos.go.cr
56
- PASSWORD_TEST=PASSWORD_PROVIDED_BY_ATV
57
- IS_STG="1"
58
- SOURCE_P12_URI=$PATH/#####.p12
59
- SOURCE_P12_PASSPORT=1234
60
- SOURCE_URI_XML_OUTPUT=$PATH/__test__/output/output.xml
61
- XML_TO_CONFIRM=$PATH/__test__/input/Comprobante_Electronico_####_####.xml
62
- ```
63
-
64
39
  ## Tools
65
40
  Para usar readXML establecer en .env
66
41
  ```
@@ -1,11 +1,10 @@
1
1
  import fs from 'fs'
2
- import { createDocumentInputExample } from '@test/stubs/createDocument.data'
2
+ import { FEInputExample } from '@test/stubs/createDocument.data'
3
3
  import { ATV } from '../dist/src'
4
4
  import { PersonProps } from 'dist/src/ATV/core/Person'
5
5
  import { AceptationStates } from 'dist/src/ATV/core/types'
6
6
  import { parseElectronicBillXML } from '@src/lib/genXML'
7
7
 
8
-
9
8
  const IS_STG = process.env.IS_STG
10
9
  const USERNAME_TEST = process.env.USERNAME_TEST
11
10
  const PASSWORD_TEST = process.env.PASSWORD_TEST
@@ -20,14 +19,16 @@ if (!SOURCE_P12_PASSPORT || !SOURCE_P12_URI) {
20
19
  }
21
20
 
22
21
  const pem = fs.readFileSync(SOURCE_P12_URI, 'binary')
22
+ // @ts-expect-error migration - for example purposes
23
23
  const receivedDocumentXML = fs.readFileSync(XML_TO_CONFIRM, 'utf-8')
24
24
 
25
25
  // TODO: dynamic param --identifier 1 args[x]
26
- createDocumentInputExample.consecutiveIdentifier = process.env.TEST_CONSECUTIVE
27
- createDocumentInputExample.emitter.identifier.id = process.env.EMITTER_IDENTIFIER_ID as string;
28
- createDocumentInputExample.emitter.identifier.type = process.env.EMITTER_IDENTIFIER_TYPE as PersonProps['identifier']['type'];
26
+ // @ts-expect-error migration - for example purposes
27
+ FEInputExample.consecutiveIdentifier = process.env.TEST_CONSECUTIVE
28
+ FEInputExample.emitter.identifier.id = process.env.EMITTER_IDENTIFIER_ID as string
29
+ FEInputExample.emitter.identifier.type = process.env.EMITTER_IDENTIFIER_TYPE as PersonProps['identifier']['type']
29
30
 
30
- console.log('requestStub consecutivo', createDocumentInputExample.consecutiveIdentifier)
31
+ console.log('requestStub consecutivo', FEInputExample.consecutiveIdentifier)
31
32
 
32
33
  function getConfimation(atv: ATV, token: string, location: string, ms: number): Promise<any> {
33
34
  return new Promise((resolve, reject): any => {
@@ -48,7 +49,9 @@ function getConfimation(atv: ATV, token: string, location: string, ms: number):
48
49
  async function main(): Promise<void> {
49
50
  const atv = new ATV({}, 'stg')
50
51
  const tokenData = await atv.getToken({
52
+ // @ts-expect-error migration - for example purposes
51
53
  username: USERNAME_TEST,
54
+ // @ts-expect-error migration - for example purposes
52
55
  password: PASSWORD_TEST
53
56
  })
54
57
  const electronillBillRaw = parseElectronicBillXML(receivedDocumentXML)
@@ -58,28 +61,34 @@ async function main(): Promise<void> {
58
61
  clave: electronillBillRaw.Clave,
59
62
  emitterIdentifier: electronillBillRaw.Emisor.Identificacion.Numero,
60
63
  emitterIdentifierType: electronillBillRaw.Emisor.Identificacion.Tipo,
64
+ // @ts-expect-error migration - for example purposes
61
65
  receptorIdentifier: electronillBillRaw.Receptor.Identificacion.Numero,
66
+ // @ts-expect-error migration - for example purposes
62
67
  receptorIdentifierType: electronillBillRaw.Receptor.Identificacion.Tipo,
68
+ // @ts-expect-error migration - for example purposes
63
69
  documentIssueDate: new Date(electronillBillRaw.FechaEmision),
64
- activityCode: electronillBillRaw.CodigoActividad,
70
+ activityCode: electronillBillRaw.CodigoActividadEmisor,
71
+ // @ts-expect-error migration - for example purposes
65
72
  taxCondition: electronillBillRaw.CondicionVenta,
66
73
  totalTaxes: electronillBillRaw.ResumenFactura.TotalImpuesto,
67
- totalSale: electronillBillRaw.ResumenFactura.TotalVenta,
74
+ totalSale: electronillBillRaw.ResumenFactura.TotalVenta,
68
75
  branch: '01',
69
76
  terminal: '01',
70
77
  consecutive: '01',
71
78
  token: tokenData.accessToken,
72
79
  signatureOptions: {
73
80
  buffer: pem,
81
+ // @ts-expect-error migration - for example purposes
74
82
  password: SOURCE_P12_PASSPORT
75
83
  }
76
84
  })
77
- console.log('extraData', extraData);
85
+ console.log('extraData', extraData)
78
86
  const response = await atv.sendDocument(command)
79
87
  if (response.errorCause) {
80
88
  console.log('error response', response)
81
89
  return
82
90
  }
91
+ // @ts-expect-error pending-to-fix migration
83
92
  const confirmationResponse = await getConfimation(atv, tokenData.accessToken, response.location, 2000)
84
93
  console.log({ MensajeHacienda: confirmationResponse.confirmation })
85
94
  }
@@ -18,6 +18,7 @@ async function main(): Promise<any> {
18
18
  username: USERNAME_TEST,
19
19
  password: PASSWORD_TEST
20
20
  })
21
+ // @ts-expect-error migration - for example purposes
21
22
  const secondResponse = await sendToCustomURL(token.data.access_token, location).catch((err) => {
22
23
  const response = err.response || {}
23
24
  const header = response.headers || {}
@@ -1,10 +1,8 @@
1
1
  import fs from 'fs'
2
- import { createDocumentInputExample } from '@test/stubs/createDocument.data'
2
+ import { FEInputExample } from '@test/stubs/createDocument.data'
3
3
  import { ATV } from '../dist/src'
4
4
  import { PersonProps } from 'dist/src/ATV/core/Person'
5
5
 
6
-
7
- const IS_STG = process.env.IS_STG
8
6
  const USERNAME_TEST = process.env.USERNAME_TEST
9
7
  const PASSWORD_TEST = process.env.PASSWORD_TEST
10
8
 
@@ -21,11 +19,12 @@ const paramConsecutive = process.argv[2]
21
19
  console.log('paramConsecutive', paramConsecutive)
22
20
 
23
21
  // TODO: dynamic param --identifier 1 args[x]
24
- createDocumentInputExample.consecutiveIdentifier = paramConsecutive || process.env.TEST_CONSECUTIVE
25
- createDocumentInputExample.emitter.identifier.id = process.env.EMITTER_IDENTIFIER_ID as string
26
- createDocumentInputExample.emitter.identifier.type = process.env.EMITTER_IDENTIFIER_TYPE as PersonProps['identifier']['type']
22
+ // @ts-expect-error migration - for example purposes
23
+ FEInputExample.consecutiveIdentifier = paramConsecutive || process.env.TEST_CONSECUTIVE
24
+ FEInputExample.emitter.identifier.id = process.env.EMITTER_IDENTIFIER_ID as string
25
+ FEInputExample.emitter.identifier.type = process.env.EMITTER_IDENTIFIER_TYPE as PersonProps['identifier']['type']
27
26
 
28
- console.log('requestStub consecutivo', createDocumentInputExample.consecutiveIdentifier)
27
+ console.log('requestStub consecutivo', FEInputExample.consecutiveIdentifier)
29
28
 
30
29
  function getConfimation(atv: ATV, token: string, location: string, ms: number): Promise<any> {
31
30
  return new Promise((resolve, reject): any => {
@@ -46,14 +45,17 @@ function getConfimation(atv: ATV, token: string, location: string, ms: number):
46
45
  async function main(): Promise<void> {
47
46
  const atv = new ATV({}, 'stg')
48
47
  const tokenData = await atv.getToken({
48
+ // @ts-expect-error migration - for example purposes
49
49
  username: USERNAME_TEST,
50
+ // @ts-expect-error migration - for example purposes
50
51
  password: PASSWORD_TEST
51
52
  })
52
53
  const { command, extraData } = await atv.createDocumentCommand({
53
- document: createDocumentInputExample,
54
+ document: FEInputExample,
54
55
  token: tokenData.accessToken,
55
56
  signatureOptions: {
56
57
  buffer: pem,
58
+ // @ts-expect-error migration - for example purposes
57
59
  password: SOURCE_P12_PASSPORT
58
60
  }
59
61
  })
@@ -63,6 +65,7 @@ async function main(): Promise<void> {
63
65
  console.log('error response', response)
64
66
  return
65
67
  }
68
+ // @ts-expect-error pending-to-fix migration
66
69
  const confirmationResponse = await getConfimation(atv, tokenData.accessToken, response.location, 2000)
67
70
  console.log({ MensajeHacienda: confirmationResponse.confirmation })
68
71
  }