@dojocoding/hacienda-mcp 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -27802,6 +27802,1174 @@ import { z as z10 } from "zod";
27802
27802
  import { z as z32 } from "zod";
27803
27803
  import { existsSync } from "fs";
27804
27804
  import { z as z9 } from "zod";
27805
+
27806
+ // ../../shared/dist/index.js
27807
+ import { z } from "zod";
27808
+ import { z as z2 } from "zod";
27809
+ import { z as z3 } from "zod";
27810
+ import { z as z4 } from "zod";
27811
+ import { z as z5 } from "zod";
27812
+ import { z as z6 } from "zod";
27813
+ import { z as z7 } from "zod";
27814
+ import { z as z8 } from "zod";
27815
+ var Environment = {
27816
+ SANDBOX: "sandbox",
27817
+ PRODUCTION: "production"
27818
+ };
27819
+ var API_BASE_URLS = {
27820
+ [Environment.SANDBOX]: "https://api.comprobanteselectronicos.go.cr/recepcion-sandbox/v1",
27821
+ [Environment.PRODUCTION]: "https://api.comprobanteselectronicos.go.cr/recepcion/v1"
27822
+ };
27823
+ var IDP_TOKEN_URLS = {
27824
+ [Environment.SANDBOX]: "https://idp.comprobanteselectronicos.go.cr/auth/realms/rut-stag/protocol/openid-connect/token",
27825
+ [Environment.PRODUCTION]: "https://idp.comprobanteselectronicos.go.cr/auth/realms/rut/protocol/openid-connect/token"
27826
+ };
27827
+ var CLIENT_IDS = {
27828
+ [Environment.SANDBOX]: "api-stag",
27829
+ [Environment.PRODUCTION]: "api-prod"
27830
+ };
27831
+ var IDP_LOGOUT_URLS = {
27832
+ [Environment.SANDBOX]: "https://idp.comprobanteselectronicos.go.cr/auth/realms/rut-stag/protocol/openid-connect/logout",
27833
+ [Environment.PRODUCTION]: "https://idp.comprobanteselectronicos.go.cr/auth/realms/rut/protocol/openid-connect/logout"
27834
+ };
27835
+ var ECONOMIC_ACTIVITY_API_URL = "https://api.hacienda.go.cr/fe/ae";
27836
+ var DocumentTypeCode = {
27837
+ /** Factura Electronica */
27838
+ FACTURA_ELECTRONICA: "01",
27839
+ /** Nota de Debito Electronica */
27840
+ NOTA_DEBITO_ELECTRONICA: "02",
27841
+ /** Nota de Credito Electronica */
27842
+ NOTA_CREDITO_ELECTRONICA: "03",
27843
+ /** Tiquete Electronico */
27844
+ TIQUETE_ELECTRONICO: "04",
27845
+ /** Factura Electronica de Compra */
27846
+ FACTURA_ELECTRONICA_COMPRA: "05",
27847
+ /** Factura Electronica de Exportacion */
27848
+ FACTURA_ELECTRONICA_EXPORTACION: "06",
27849
+ /** Recibo Electronico de Pago (new in v4.4) */
27850
+ RECIBO_ELECTRONICO_PAGO: "07",
27851
+ /** Compra de Pago */
27852
+ COMPRA_PAGO: "08",
27853
+ /** Gasto de Viaje */
27854
+ GASTO_VIAJE: "09"
27855
+ };
27856
+ var DOCUMENT_TYPE_NAMES = {
27857
+ [DocumentTypeCode.FACTURA_ELECTRONICA]: "Factura Electr\xF3nica",
27858
+ [DocumentTypeCode.NOTA_DEBITO_ELECTRONICA]: "Nota de D\xE9bito Electr\xF3nica",
27859
+ [DocumentTypeCode.NOTA_CREDITO_ELECTRONICA]: "Nota de Cr\xE9dito Electr\xF3nica",
27860
+ [DocumentTypeCode.TIQUETE_ELECTRONICO]: "Tiquete Electr\xF3nico",
27861
+ [DocumentTypeCode.FACTURA_ELECTRONICA_COMPRA]: "Factura Electr\xF3nica de Compra",
27862
+ [DocumentTypeCode.FACTURA_ELECTRONICA_EXPORTACION]: "Factura Electr\xF3nica de Exportaci\xF3n",
27863
+ [DocumentTypeCode.RECIBO_ELECTRONICO_PAGO]: "Recibo Electr\xF3nico de Pago",
27864
+ [DocumentTypeCode.COMPRA_PAGO]: "Compra de Pago",
27865
+ [DocumentTypeCode.GASTO_VIAJE]: "Gasto de Viaje"
27866
+ };
27867
+ var MensajeReceptorCode = {
27868
+ /** Aceptado totalmente */
27869
+ ACEPTADO: "1",
27870
+ /** Aceptado parcialmente */
27871
+ ACEPTADO_PARCIALMENTE: "2",
27872
+ /** Rechazado */
27873
+ RECHAZADO: "3"
27874
+ };
27875
+ var SituationCode = {
27876
+ /** Normal */
27877
+ NORMAL: "1",
27878
+ /** Contingencia (contingency) */
27879
+ CONTINGENCIA: "2",
27880
+ /** Sin internet (no internet) */
27881
+ SIN_INTERNET: "3"
27882
+ };
27883
+ var TaxCode = {
27884
+ /** Impuesto al Valor Agregado (IVA) */
27885
+ IVA: "01",
27886
+ /** Impuesto Selectivo de Consumo */
27887
+ IMPUESTO_SELECTIVO_CONSUMO: "02",
27888
+ /** Impuesto Unico a los Combustibles */
27889
+ IMPUESTO_UNICO_COMBUSTIBLES: "03",
27890
+ /** Impuesto Especifico de Bebidas Alcoholicas */
27891
+ IMPUESTO_BEBIDAS_ALCOHOLICAS: "04",
27892
+ /** Impuesto Especifico sobre Bebidas Envasadas sin Alcohol y Jabones de Tocador */
27893
+ IMPUESTO_BEBIDAS_SIN_ALCOHOL: "05",
27894
+ /** Impuesto al Tabaco */
27895
+ IMPUESTO_TABACO: "06",
27896
+ /** IVA (calculo especial) */
27897
+ IVA_CALCULO_ESPECIAL: "07",
27898
+ /** IVA Regimen de Bienes Usados (Factor) */
27899
+ IVA_BIENES_USADOS: "08",
27900
+ /** Impuesto Especifico al Cemento */
27901
+ IMPUESTO_CEMENTO: "12",
27902
+ /** Otros */
27903
+ OTROS: "99"
27904
+ };
27905
+ var IvaRateCode = {
27906
+ /** Tarifa 0% (Exento) */
27907
+ EXENTO: "01",
27908
+ /** Tarifa reducida 1% */
27909
+ REDUCIDA_1: "02",
27910
+ /** Tarifa reducida 2% */
27911
+ REDUCIDA_2: "03",
27912
+ /** Tarifa reducida 4% */
27913
+ REDUCIDA_4: "04",
27914
+ /** Transitorio 0% */
27915
+ TRANSITORIO_0: "05",
27916
+ /** Transitorio 4% */
27917
+ TRANSITORIO_4: "06",
27918
+ /** Transitorio 8% */
27919
+ TRANSITORIO_8: "07",
27920
+ /** Tarifa general 13% */
27921
+ GENERAL_13: "08",
27922
+ /** Tarifa reducida 0.5% (new in v4.4) */
27923
+ REDUCIDA_0_5: "09",
27924
+ /** Tarifa exenta (new in v4.4) */
27925
+ TARIFA_EXENTA: "10",
27926
+ /** Tarifa 0% sin derecho a credito (new in v4.4) */
27927
+ CERO_SIN_CREDITO: "11"
27928
+ };
27929
+ var IVA_RATE_PERCENTAGES = {
27930
+ [IvaRateCode.EXENTO]: 0,
27931
+ [IvaRateCode.REDUCIDA_1]: 1,
27932
+ [IvaRateCode.REDUCIDA_2]: 2,
27933
+ [IvaRateCode.REDUCIDA_4]: 4,
27934
+ [IvaRateCode.TRANSITORIO_0]: 0,
27935
+ [IvaRateCode.TRANSITORIO_4]: 4,
27936
+ [IvaRateCode.TRANSITORIO_8]: 8,
27937
+ [IvaRateCode.GENERAL_13]: 13,
27938
+ [IvaRateCode.REDUCIDA_0_5]: 0.5,
27939
+ [IvaRateCode.TARIFA_EXENTA]: 0,
27940
+ [IvaRateCode.CERO_SIN_CREDITO]: 0
27941
+ };
27942
+ var IVA_RATE_NAMES = {
27943
+ [IvaRateCode.EXENTO]: "Exento (0%)",
27944
+ [IvaRateCode.REDUCIDA_1]: "Tarifa reducida 1%",
27945
+ [IvaRateCode.REDUCIDA_2]: "Tarifa reducida 2%",
27946
+ [IvaRateCode.REDUCIDA_4]: "Tarifa reducida 4%",
27947
+ [IvaRateCode.TRANSITORIO_0]: "Transitorio 0%",
27948
+ [IvaRateCode.TRANSITORIO_4]: "Transitorio 4%",
27949
+ [IvaRateCode.TRANSITORIO_8]: "Transitorio 8%",
27950
+ [IvaRateCode.GENERAL_13]: "Tarifa general 13%",
27951
+ [IvaRateCode.REDUCIDA_0_5]: "Tarifa reducida 0.5%",
27952
+ [IvaRateCode.TARIFA_EXENTA]: "Tarifa exenta",
27953
+ [IvaRateCode.CERO_SIN_CREDITO]: "Tarifa 0% sin derecho a cr\xE9dito"
27954
+ };
27955
+ var ExonerationType = {
27956
+ /** Compras autorizadas */
27957
+ COMPRAS_AUTORIZADAS: "01",
27958
+ /** Ventas exentas a diplomáticos */
27959
+ VENTAS_EXENTAS_DIPLOMATICOS: "02",
27960
+ /** Autorizado por ley especial */
27961
+ AUTORIZADO_LEY_ESPECIAL: "03",
27962
+ /** Exenciones de la Dirección General de Hacienda */
27963
+ EXENCIONES_DGH: "04",
27964
+ /** Transitorio V */
27965
+ TRANSITORIO_V: "05",
27966
+ /** Transitorio IX */
27967
+ TRANSITORIO_IX: "06",
27968
+ /** Transitorio XVII */
27969
+ TRANSITORIO_XVII: "07",
27970
+ /** Exoneracion Zona Franca (new in v4.4) */
27971
+ ZONA_FRANCA: "08",
27972
+ /** Exoneracion de servicios complementarios para la exportacion (new in v4.4) */
27973
+ SERVICIOS_COMPLEMENTARIOS_EXPORTACION: "09",
27974
+ /** Organo de las corporaciones municipales (new in v4.4) */
27975
+ CORPORACIONES_MUNICIPALES: "10",
27976
+ /** Exenciones DGH — autorizacion de impuesto local concreta (new in v4.4) */
27977
+ DGH_IMPUESTO_LOCAL_CONCRETA: "11",
27978
+ /** Codigo 12 — ver ANEXOS Y ESTRUCTURAS v4.4 para la descripcion oficial */
27979
+ EXONERACION_12: "12",
27980
+ /** Otros */
27981
+ OTROS: "99"
27982
+ };
27983
+ var UNITS_OF_MEASURE = [
27984
+ "1",
27985
+ "\xB4",
27986
+ "\xB4\xB4",
27987
+ "\xB0C",
27988
+ "1/m",
27989
+ "A",
27990
+ "A/m",
27991
+ "A/m\xB2",
27992
+ "Acv",
27993
+ "Al",
27994
+ "Alc",
27995
+ "B",
27996
+ "Bq",
27997
+ "C",
27998
+ "C/kg",
27999
+ "C/m\xB2",
28000
+ "C/m\xB3",
28001
+ "Cc",
28002
+ "Cd",
28003
+ "cd/m\xB2",
28004
+ "Cm",
28005
+ "cm",
28006
+ "Cu",
28007
+ "D",
28008
+ "eV",
28009
+ "F",
28010
+ "F/m",
28011
+ "Fa",
28012
+ "G",
28013
+ "Gal",
28014
+ "Gy",
28015
+ "Gy/s",
28016
+ "h",
28017
+ "H",
28018
+ "H/m",
28019
+ "Hz",
28020
+ "I",
28021
+ "J",
28022
+ "J/(kg\xB7K)",
28023
+ "J/(mol\xB7K)",
28024
+ "J/K",
28025
+ "J/kg",
28026
+ "J/m\xB3",
28027
+ "J/mol",
28028
+ "K",
28029
+ "Kat",
28030
+ "kat/m\xB3",
28031
+ "Kg",
28032
+ "kg/m\xB3",
28033
+ "Km",
28034
+ "Kw",
28035
+ "kWh",
28036
+ "L",
28037
+ "Lm",
28038
+ "Ln",
28039
+ "Lx",
28040
+ "M",
28041
+ "m/s",
28042
+ "m/s\xB2",
28043
+ "m\xB2",
28044
+ "m\xB3",
28045
+ "Min",
28046
+ "mL",
28047
+ "Mm",
28048
+ "Mol",
28049
+ "mol/m\xB3",
28050
+ "N",
28051
+ "N/m",
28052
+ "N\xB7m",
28053
+ "Np",
28054
+ "\xBA",
28055
+ "Os",
28056
+ "Otros",
28057
+ "Oz",
28058
+ "Pa",
28059
+ "Pa\xB7s",
28060
+ "Qq",
28061
+ "Rad",
28062
+ "rad/s",
28063
+ "rad/s\xB2",
28064
+ "S",
28065
+ "s",
28066
+ "Sp",
28067
+ "Spe",
28068
+ "Sr",
28069
+ "St",
28070
+ "Sv",
28071
+ "t",
28072
+ "T",
28073
+ "U",
28074
+ "Ua",
28075
+ "Unid",
28076
+ "V",
28077
+ "V/m",
28078
+ "W",
28079
+ "W/(m\xB7K)",
28080
+ "W/(m\xB2\xB7sr)",
28081
+ "W/m\xB2",
28082
+ "W/sr",
28083
+ "Wb",
28084
+ "\u03A9"
28085
+ ];
28086
+ var UnitOfMeasure = {
28087
+ /** Servicios profesionales */
28088
+ SERVICIOS_PROFESIONALES: "Sp",
28089
+ /** Otros servicios */
28090
+ OTROS_SERVICIOS: "Os",
28091
+ /** Servicios personales */
28092
+ SERVICIOS_PERSONALES: "Spe",
28093
+ /** Unidad */
28094
+ UNIDAD: "Unid",
28095
+ /** Metros */
28096
+ METROS: "M",
28097
+ /** Centimetros */
28098
+ CENTIMETROS: "cm",
28099
+ /** Kilometros */
28100
+ KILOMETROS: "Km",
28101
+ /** Kilogramos */
28102
+ KILOGRAMOS: "Kg",
28103
+ /** Gramos */
28104
+ GRAMOS: "G",
28105
+ /** Toneladas */
28106
+ TONELADAS: "t",
28107
+ /** Litros */
28108
+ LITROS: "L",
28109
+ /** Mililitros */
28110
+ MILILITROS: "mL",
28111
+ /** Metros cuadrados */
28112
+ METROS_CUADRADOS: "m\xB2",
28113
+ /** Metros cubicos */
28114
+ METROS_CUBICOS: "m\xB3",
28115
+ /** Galones */
28116
+ GALONES: "Gal",
28117
+ /** Onzas */
28118
+ ONZAS: "Oz",
28119
+ /** Horas */
28120
+ HORAS: "h",
28121
+ /** Minutos */
28122
+ MINUTOS: "Min",
28123
+ /** Segundos */
28124
+ SEGUNDOS: "s",
28125
+ /** Dias */
28126
+ DIAS: "D",
28127
+ /** Otros (especificar) */
28128
+ OTROS: "Otros"
28129
+ };
28130
+ var REFERENCE_DOC_TYPES = [
28131
+ "01",
28132
+ // Factura electronica
28133
+ "02",
28134
+ // Nota de debito electronica
28135
+ "03",
28136
+ // Nota de credito electronica
28137
+ "04",
28138
+ // Tiquete electronico
28139
+ "05",
28140
+ // Nota de despacho
28141
+ "06",
28142
+ // Contrato
28143
+ "07",
28144
+ // Procedimiento
28145
+ "08",
28146
+ // Comprobante emitido en contingencia
28147
+ "09",
28148
+ // Devolucion de mercaderia
28149
+ "10",
28150
+ // Sustituye factura rechazada por Hacienda
28151
+ "11",
28152
+ // Sustituye factura rechazada por el receptor
28153
+ "12",
28154
+ // Sustituye factura de exportacion
28155
+ "13",
28156
+ // Facturacion mes vencido
28157
+ "14",
28158
+ // Comprobante aportado por contribuyente de regimen especial
28159
+ "15",
28160
+ // Sustituye una factura electronica de compra
28161
+ "16",
28162
+ // Comprobante de proveedor no domiciliado
28163
+ "17",
28164
+ // Nota de credito a factura electronica de compra
28165
+ "18",
28166
+ // Nota de debito a factura electronica de compra
28167
+ "19",
28168
+ // Factura electronica de exportacion (April 2026 revision)
28169
+ "20",
28170
+ // Recibo electronico de pago (April 2026 revision)
28171
+ "99"
28172
+ // Otros (requiere TipoDocRefOTRO)
28173
+ ];
28174
+ var REFERENCE_CODES = [
28175
+ "01",
28176
+ // Anula documento de referencia
28177
+ "02",
28178
+ // Corrige texto de documento de referencia
28179
+ "04",
28180
+ // Referencia a otro documento
28181
+ "05",
28182
+ // Sustituye comprobante provisional por contingencia
28183
+ "06",
28184
+ "07",
28185
+ "08",
28186
+ "09",
28187
+ "10",
28188
+ "11",
28189
+ "12",
28190
+ // Nota de credito financiera por exoneracion posterior (redefined April 2026)
28191
+ "13",
28192
+ // Anula comprobante por error material (April 2026 revision)
28193
+ "14",
28194
+ // Corrige monto por error material (April 2026 revision)
28195
+ "15",
28196
+ // Sustituye comprobante por error material (April 2026 revision)
28197
+ "16",
28198
+ // Sustituye comprobante rechazado (April 2026 revision)
28199
+ "99"
28200
+ // Otros (requiere CodigoReferenciaOTRO)
28201
+ ];
28202
+ var REP_REFERENCE_CODES = [
28203
+ ...REFERENCE_CODES,
28204
+ "17"
28205
+ // Pago de comprobante (REP only, April 2026 revision)
28206
+ ];
28207
+ var DISCOUNT_CODES = [
28208
+ "01",
28209
+ "02",
28210
+ "03",
28211
+ "04",
28212
+ "05",
28213
+ "06",
28214
+ "07",
28215
+ "08",
28216
+ "09",
28217
+ "99"
28218
+ // Otros (requiere CodigoDescuentoOTRO)
28219
+ ];
28220
+ var OTHER_CHARGE_TYPES = [
28221
+ "01",
28222
+ // Contribucion parafiscal
28223
+ "02",
28224
+ // Timbre de la Cruz Roja
28225
+ "03",
28226
+ // Timbre de Benemerito Cuerpo de Bomberos
28227
+ "04",
28228
+ // Cobro de un tercero
28229
+ "05",
28230
+ // Costos de exportacion
28231
+ "06",
28232
+ // Impuesto de servicio 10%
28233
+ "07",
28234
+ // Timbre de Colegios Profesionales
28235
+ "08",
28236
+ "09",
28237
+ "10",
28238
+ "99"
28239
+ // Otros (requiere TipoDocumentoOTROS)
28240
+ ];
28241
+ var EXONERATION_INSTITUTIONS = [
28242
+ "01",
28243
+ "02",
28244
+ "03",
28245
+ "04",
28246
+ "05",
28247
+ "06",
28248
+ "07",
28249
+ "08",
28250
+ "09",
28251
+ "10",
28252
+ "11",
28253
+ "12",
28254
+ "99"
28255
+ // Otros (requiere NombreInstitucionOtros)
28256
+ ];
28257
+ var IdentificationType = {
28258
+ /** Cedula Fisica (physical person ID) — 9 digits */
28259
+ CEDULA_FISICA: "01",
28260
+ /** Cedula Juridica (legal entity ID) — 10 digits */
28261
+ CEDULA_JURIDICA: "02",
28262
+ /** DIMEX (foreign resident ID) — 11-12 digits */
28263
+ DIMEX: "03",
28264
+ /** NITE (tax ID for foreigners without DIMEX) — 10 digits */
28265
+ NITE: "04",
28266
+ /** Extranjero No Domiciliado (non-domiciled foreigner) — free-form, max 20 chars */
28267
+ EXTRANJERO_NO_DOMICILIADO: "05",
28268
+ /** No Contribuyente (non-taxpayer) — free-form, max 20 chars */
28269
+ NO_CONTRIBUYENTE: "06"
28270
+ };
28271
+ var IDENTIFICATION_TYPE_NAMES = {
28272
+ [IdentificationType.CEDULA_FISICA]: "C\xE9dula F\xEDsica",
28273
+ [IdentificationType.CEDULA_JURIDICA]: "C\xE9dula Jur\xEDdica",
28274
+ [IdentificationType.DIMEX]: "DIMEX",
28275
+ [IdentificationType.NITE]: "NITE",
28276
+ [IdentificationType.EXTRANJERO_NO_DOMICILIADO]: "Extranjero No Domiciliado",
28277
+ [IdentificationType.NO_CONTRIBUYENTE]: "No Contribuyente"
28278
+ };
28279
+ var IDENTIFICATION_LENGTHS = {
28280
+ [IdentificationType.CEDULA_FISICA]: [9],
28281
+ [IdentificationType.CEDULA_JURIDICA]: [10],
28282
+ [IdentificationType.DIMEX]: [11, 12],
28283
+ [IdentificationType.NITE]: [10]
28284
+ };
28285
+ var SaleCondition = {
28286
+ /** Contado (cash / immediate payment) */
28287
+ CONTADO: "01",
28288
+ /** Credito (credit) */
28289
+ CREDITO: "02",
28290
+ /** Consignacion */
28291
+ CONSIGNACION: "03",
28292
+ /** Apartado */
28293
+ APARTADO: "04",
28294
+ /** Arrendamiento con opcion de compra */
28295
+ ARRENDAMIENTO_OPCION_COMPRA: "05",
28296
+ /** Arrendamiento en funcion financiera */
28297
+ ARRENDAMIENTO_FUNCION_FINANCIERA: "06",
28298
+ /** Cobro a favor de un tercero */
28299
+ COBRO_FAVOR_TERCERO: "07",
28300
+ /** Servicios prestados al Estado */
28301
+ SERVICIOS_ESTADO: "08",
28302
+ /** Pago del servicio prestado al Estado — Recibo Electronico de Pago only */
28303
+ PAGO_SERVICIO_ESTADO: "09",
28304
+ /** Venta a credito en IVA hasta 90 dias (Articulo 27, LIVA) */
28305
+ VENTA_CREDITO_IVA_90_DIAS: "10",
28306
+ /** Pago de venta a credito en IVA hasta 90 dias — Recibo Electronico de Pago only */
28307
+ PAGO_VENTA_CREDITO_IVA_90_DIAS: "11",
28308
+ /** Venta de mercancia no nacionalizada */
28309
+ VENTA_MERCANCIA_NO_NACIONALIZADA: "12",
28310
+ /** Venta de bienes usados no contribuyente */
28311
+ VENTA_BIENES_USADOS_NO_CONTRIBUYENTE: "13",
28312
+ /** Arrendamiento operativo */
28313
+ ARRENDAMIENTO_OPERATIVO: "14",
28314
+ /** Arrendamiento en funcion financiera (leasing financiero) */
28315
+ ARRENDAMIENTO_FINANCIERO: "15",
28316
+ /** Otros (requiere CondicionVentaOtros) */
28317
+ OTROS: "99"
28318
+ };
28319
+ var REP_SALE_CONDITIONS = [
28320
+ SaleCondition.PAGO_SERVICIO_ESTADO,
28321
+ SaleCondition.PAGO_VENTA_CREDITO_IVA_90_DIAS
28322
+ ];
28323
+ var SALE_CONDITION_NAMES = {
28324
+ [SaleCondition.CONTADO]: "Contado",
28325
+ [SaleCondition.CREDITO]: "Cr\xE9dito",
28326
+ [SaleCondition.CONSIGNACION]: "Consignaci\xF3n",
28327
+ [SaleCondition.APARTADO]: "Apartado",
28328
+ [SaleCondition.ARRENDAMIENTO_OPCION_COMPRA]: "Arrendamiento con opci\xF3n de compra",
28329
+ [SaleCondition.ARRENDAMIENTO_FUNCION_FINANCIERA]: "Arrendamiento en funci\xF3n financiera",
28330
+ [SaleCondition.COBRO_FAVOR_TERCERO]: "Cobro a favor de un tercero",
28331
+ [SaleCondition.SERVICIOS_ESTADO]: "Servicios prestados al Estado",
28332
+ [SaleCondition.PAGO_SERVICIO_ESTADO]: "Pago del servicio prestado al Estado (REP)",
28333
+ [SaleCondition.VENTA_CREDITO_IVA_90_DIAS]: "Venta a cr\xE9dito en IVA hasta 90 d\xEDas",
28334
+ [SaleCondition.PAGO_VENTA_CREDITO_IVA_90_DIAS]: "Pago de venta a cr\xE9dito en IVA hasta 90 d\xEDas (REP)",
28335
+ [SaleCondition.VENTA_MERCANCIA_NO_NACIONALIZADA]: "Venta de mercanc\xEDa no nacionalizada",
28336
+ [SaleCondition.VENTA_BIENES_USADOS_NO_CONTRIBUYENTE]: "Venta de bienes usados no contribuyente",
28337
+ [SaleCondition.ARRENDAMIENTO_OPERATIVO]: "Arrendamiento operativo",
28338
+ [SaleCondition.ARRENDAMIENTO_FINANCIERO]: "Arrendamiento en funci\xF3n financiera (leasing)",
28339
+ [SaleCondition.OTROS]: "Otros"
28340
+ };
28341
+ var PaymentMethod = {
28342
+ /** Efectivo (cash) */
28343
+ EFECTIVO: "01",
28344
+ /** Tarjeta (card) */
28345
+ TARJETA: "02",
28346
+ /** Cheque */
28347
+ CHEQUE: "03",
28348
+ /** Transferencia - Deposito bancario */
28349
+ TRANSFERENCIA: "04",
28350
+ /** Recaudado por terceros */
28351
+ RECAUDADO_TERCEROS: "05",
28352
+ /** SINPE Movil */
28353
+ SINPE_MOVIL: "06",
28354
+ /** Plataforma Digital */
28355
+ PLATAFORMA_DIGITAL: "07",
28356
+ /** Otros (especificar en MedioPagoOtros) */
28357
+ OTROS: "99"
28358
+ };
28359
+ var PAYMENT_METHOD_NAMES = {
28360
+ [PaymentMethod.EFECTIVO]: "Efectivo",
28361
+ [PaymentMethod.TARJETA]: "Tarjeta",
28362
+ [PaymentMethod.CHEQUE]: "Cheque",
28363
+ [PaymentMethod.TRANSFERENCIA]: "Transferencia - Dep\xF3sito bancario",
28364
+ [PaymentMethod.RECAUDADO_TERCEROS]: "Recaudado por terceros",
28365
+ [PaymentMethod.SINPE_MOVIL]: "SINPE M\xF3vil",
28366
+ [PaymentMethod.PLATAFORMA_DIGITAL]: "Plataforma Digital",
28367
+ [PaymentMethod.OTROS]: "Otros"
28368
+ };
28369
+ var ProvinceCode = {
28370
+ /** San Jose */
28371
+ SAN_JOSE: "1",
28372
+ /** Alajuela */
28373
+ ALAJUELA: "2",
28374
+ /** Cartago */
28375
+ CARTAGO: "3",
28376
+ /** Heredia */
28377
+ HEREDIA: "4",
28378
+ /** Guanacaste */
28379
+ GUANACASTE: "5",
28380
+ /** Puntarenas */
28381
+ PUNTARENAS: "6",
28382
+ /** Limon */
28383
+ LIMON: "7"
28384
+ };
28385
+ var PROVINCE_NAMES = {
28386
+ [ProvinceCode.SAN_JOSE]: "San Jos\xE9",
28387
+ [ProvinceCode.ALAJUELA]: "Alajuela",
28388
+ [ProvinceCode.CARTAGO]: "Cartago",
28389
+ [ProvinceCode.HEREDIA]: "Heredia",
28390
+ [ProvinceCode.GUANACASTE]: "Guanacaste",
28391
+ [ProvinceCode.PUNTARENAS]: "Puntarenas",
28392
+ [ProvinceCode.LIMON]: "Lim\xF3n"
28393
+ };
28394
+ var CURRENCY_CODES = [
28395
+ "AED",
28396
+ "AFN",
28397
+ "ALL",
28398
+ "AMD",
28399
+ "ANG",
28400
+ "AOA",
28401
+ "ARS",
28402
+ "AUD",
28403
+ "AWG",
28404
+ "AZN",
28405
+ "BAM",
28406
+ "BBD",
28407
+ "BDT",
28408
+ "BGN",
28409
+ "BHD",
28410
+ "BIF",
28411
+ "BMD",
28412
+ "BND",
28413
+ "BOB",
28414
+ "BOV",
28415
+ "BRL",
28416
+ "BSD",
28417
+ "BTN",
28418
+ "BWP",
28419
+ "BYR",
28420
+ "BZD",
28421
+ "CAD",
28422
+ "CDF",
28423
+ "CHE",
28424
+ "CHF",
28425
+ "CHW",
28426
+ "CLF",
28427
+ "CLP",
28428
+ "CNY",
28429
+ "COP",
28430
+ "COU",
28431
+ "CRC",
28432
+ "CUC",
28433
+ "CUP",
28434
+ "CVE",
28435
+ "CZK",
28436
+ "DJF",
28437
+ "DKK",
28438
+ "DOP",
28439
+ "DZD",
28440
+ "EGP",
28441
+ "ERN",
28442
+ "ETB",
28443
+ "EUR",
28444
+ "FJD",
28445
+ "FKP",
28446
+ "GBP",
28447
+ "GEL",
28448
+ "GHS",
28449
+ "GIP",
28450
+ "GMD",
28451
+ "GNF",
28452
+ "GTQ",
28453
+ "GYD",
28454
+ "HKD",
28455
+ "HNL",
28456
+ "HRK",
28457
+ "HTG",
28458
+ "HUF",
28459
+ "IDR",
28460
+ "ILS",
28461
+ "INR",
28462
+ "IQD",
28463
+ "IRR",
28464
+ "ISK",
28465
+ "JMD",
28466
+ "JOD",
28467
+ "JPY",
28468
+ "KES",
28469
+ "KGS",
28470
+ "KHR",
28471
+ "KMF",
28472
+ "KPW",
28473
+ "KRW",
28474
+ "KWD",
28475
+ "KYD",
28476
+ "KZT",
28477
+ "LAK",
28478
+ "LBP",
28479
+ "LKR",
28480
+ "LRD",
28481
+ "LSL",
28482
+ "LYD",
28483
+ "MAD",
28484
+ "MDL",
28485
+ "MGA",
28486
+ "MKD",
28487
+ "MMK",
28488
+ "MNT",
28489
+ "MOP",
28490
+ "MRO",
28491
+ "MUR",
28492
+ "MVR",
28493
+ "MWK",
28494
+ "MXN",
28495
+ "MXV",
28496
+ "MYR",
28497
+ "MZN",
28498
+ "NAD",
28499
+ "NGN",
28500
+ "NIO",
28501
+ "NOK",
28502
+ "NPR",
28503
+ "NZD",
28504
+ "OMR",
28505
+ "PAB",
28506
+ "PEN",
28507
+ "PGK",
28508
+ "PHP",
28509
+ "PKR",
28510
+ "PLN",
28511
+ "PYG",
28512
+ "QAR",
28513
+ "RON",
28514
+ "RSD",
28515
+ "RUB",
28516
+ "RWF",
28517
+ "SAR",
28518
+ "SBD",
28519
+ "SCR",
28520
+ "SDG",
28521
+ "SEK",
28522
+ "SGD",
28523
+ "SHP",
28524
+ "SLL",
28525
+ "SOS",
28526
+ "SRD",
28527
+ "SSP",
28528
+ "STD",
28529
+ "SVC",
28530
+ "SYP",
28531
+ "SZL",
28532
+ "THB",
28533
+ "TJS",
28534
+ "TMT",
28535
+ "TND",
28536
+ "TOP",
28537
+ "TRY",
28538
+ "TTD",
28539
+ "TWD",
28540
+ "TZS",
28541
+ "UAH",
28542
+ "UGX",
28543
+ "USD",
28544
+ "USN",
28545
+ "UYI",
28546
+ "UYU",
28547
+ "UZS",
28548
+ "VEF",
28549
+ "VND",
28550
+ "VUV",
28551
+ "WST",
28552
+ "XAF",
28553
+ "XCD",
28554
+ "XDR",
28555
+ "XOF",
28556
+ "XPF",
28557
+ "XSU",
28558
+ "XUA",
28559
+ "YER",
28560
+ "ZAR",
28561
+ "ZMW",
28562
+ "ZWL"
28563
+ ];
28564
+ var TaxCodeSchema = z.enum(TaxCode);
28565
+ var IvaRateCodeSchema = z.enum(IvaRateCode);
28566
+ var ExonerationTypeSchema = z.enum(ExonerationType);
28567
+ var PaymentMethodSchema = z.enum(PaymentMethod);
28568
+ var SaleConditionSchema = z.enum(SaleCondition).exclude(["PAGO_SERVICIO_ESTADO", "PAGO_VENTA_CREDITO_IVA_90_DIAS"]);
28569
+ var TelefonoSchema = z.object({
28570
+ /** Country code (e.g., "506"). Max 3 digits. */
28571
+ codigoPais: z.string().regex(/^\d{1,3}$/),
28572
+ /** Phone number. Max 20 digits. */
28573
+ numTelefono: z.string().regex(/^\d{1,20}$/)
28574
+ });
28575
+ var UbicacionSchema = z.object({
28576
+ /** Province code (1-7). */
28577
+ provincia: z.string().regex(/^[1-7]$/),
28578
+ /** Canton code (2 digits, 01-99). */
28579
+ canton: z.string().regex(/^\d{2}$/),
28580
+ /** Distrito code (2 digits, 01-99). */
28581
+ distrito: z.string().regex(/^\d{2}$/),
28582
+ /** Barrio name (free text, 5-50 chars in v4.4 — no longer a code). Optional. */
28583
+ barrio: z.string().min(5).max(50).optional(),
28584
+ /** Additional address details. Required by the v4.4 XSD, 5-250 chars. */
28585
+ otrasSenas: z.string().min(5).max(250)
28586
+ });
28587
+ var IdentificationTypeSchema = z2.enum([
28588
+ IdentificationType.CEDULA_FISICA,
28589
+ IdentificationType.CEDULA_JURIDICA,
28590
+ IdentificationType.DIMEX,
28591
+ IdentificationType.NITE,
28592
+ IdentificationType.EXTRANJERO_NO_DOMICILIADO,
28593
+ IdentificationType.NO_CONTRIBUYENTE
28594
+ ]);
28595
+ var IdentificacionSchema = z2.object({
28596
+ /** Identification type code. */
28597
+ tipo: IdentificationTypeSchema,
28598
+ /** Identification number. */
28599
+ numero: z2.string().min(1).max(20)
28600
+ }).superRefine((data, ctx) => {
28601
+ const expectedLengths = IDENTIFICATION_LENGTHS[data.tipo];
28602
+ if (!expectedLengths) {
28603
+ return;
28604
+ }
28605
+ if (!/^\d+$/.test(data.numero)) {
28606
+ ctx.addIssue({
28607
+ code: "custom",
28608
+ message: "Must contain only digits",
28609
+ path: ["numero"]
28610
+ });
28611
+ return;
28612
+ }
28613
+ if (!expectedLengths.includes(data.numero.length)) {
28614
+ ctx.addIssue({
28615
+ code: "custom",
28616
+ message: "Identification number length does not match the expected length for the given type",
28617
+ path: ["numero"]
28618
+ });
28619
+ }
28620
+ });
28621
+ var CorreoSchema = z3.string().email().max(160);
28622
+ var EmisorSchema = z3.object({
28623
+ /** Issuer name (Nombre o Razon Social). Max 100 chars. */
28624
+ nombre: z3.string().min(1).max(100),
28625
+ /** Taxpayer identification. */
28626
+ identificacion: IdentificacionSchema,
28627
+ /** Ley 8707 fiscal registry number. Optional, max 12 chars. */
28628
+ registrofiscal8707: z3.string().max(12).optional(),
28629
+ /** Commercial name. Optional, max 80 chars. */
28630
+ nombreComercial: z3.string().max(80).optional(),
28631
+ /** Location. Required by the v4.4 XSD. */
28632
+ ubicacion: UbicacionSchema,
28633
+ /** Phone number. Optional. */
28634
+ telefono: TelefonoSchema.optional(),
28635
+ /** Email address(es) — the XSD allows up to 4. */
28636
+ correoElectronico: z3.union([CorreoSchema, z3.array(CorreoSchema).min(1).max(4)])
28637
+ });
28638
+ var ReceptorSchema = z4.object({
28639
+ /** Receiver name. Max 100 chars. */
28640
+ nombre: z4.string().min(1).max(100),
28641
+ /**
28642
+ * Taxpayer identification. Optional for Tiquete/NC/ND/FEE; foreign
28643
+ * receivers use tipo "05" (Extranjero No Domiciliado).
28644
+ */
28645
+ identificacion: IdentificacionSchema.optional(),
28646
+ /** Commercial name. Optional, max 80 chars. */
28647
+ nombreComercial: z4.string().max(80).optional(),
28648
+ /** Location. Optional. */
28649
+ ubicacion: UbicacionSchema.optional(),
28650
+ /** Foreign receiver address. Optional, 5-300 chars (v4.4). */
28651
+ otrasSenasExtranjero: z4.string().min(5).max(300).optional(),
28652
+ /** Phone number. Optional. */
28653
+ telefono: TelefonoSchema.optional(),
28654
+ /** Email address. Optional, max 160 chars. */
28655
+ correoElectronico: z4.string().email().max(160).optional()
28656
+ });
28657
+ var CodigoComercialSchema = z5.object({
28658
+ /** Code type: 01=Seller, 02=Buyer, 03=Industry, 04=Internal, 99=Other. */
28659
+ tipo: z5.enum(["01", "02", "03", "04", "99"]),
28660
+ /** Product/service code value. Max 20 chars. */
28661
+ codigo: z5.string().min(1).max(20)
28662
+ });
28663
+ var ExoneracionSchema = z5.object({
28664
+ /** Exoneration document type (TipoDocumentoEX1). */
28665
+ tipoDocumento: ExonerationTypeSchema,
28666
+ /** Free-text document type. Required when tipoDocumento is "99". */
28667
+ tipoDocumentoOtros: z5.string().min(5).max(100).optional(),
28668
+ /** Exoneration document number. 3-40 chars. */
28669
+ numeroDocumento: z5.string().min(3).max(40),
28670
+ /** Law article number. Optional, up to 6 digits. */
28671
+ articulo: z5.number().int().min(0).max(999999).optional(),
28672
+ /** Law clause (inciso) number. Optional, up to 6 digits. */
28673
+ inciso: z5.number().int().min(0).max(999999).optional(),
28674
+ /** Issuing institution code (coded in v4.4). */
28675
+ nombreInstitucion: z5.enum(EXONERATION_INSTITUTIONS),
28676
+ /** Free-text institution name. Required when nombreInstitucion is "99". */
28677
+ nombreInstitucionOtros: z5.string().min(5).max(160).optional(),
28678
+ /** Issue date (ISO 8601) — emitted as FechaEmisionEX. */
28679
+ fechaEmision: z5.string().min(1),
28680
+ /** Exonerated rate percentage (0-100) — emitted as TarifaExonerada. */
28681
+ tarifaExonerada: z5.number().min(0).max(100),
28682
+ /** Exonerated tax amount. */
28683
+ montoExoneracion: z5.number().min(0)
28684
+ });
28685
+ var ImpuestoSchema = z5.object({
28686
+ /** Tax type code. */
28687
+ codigo: TaxCodeSchema,
28688
+ /** Free-text tax type. Required when codigo is "99" (5-100 chars). */
28689
+ codigoImpuestoOtros: z5.string().min(5).max(100).optional(),
28690
+ /** IVA rate code (CodigoTarifaIVA). Required when tax code is IVA-related. */
28691
+ codigoTarifaIVA: IvaRateCodeSchema.optional(),
28692
+ /** Tax rate percentage. Optional for non-rate taxes. */
28693
+ tarifa: z5.number().min(0).max(99.99).optional(),
28694
+ /** Calculation factor for the used-goods IVA regime (code 08). */
28695
+ factorCalculoIVA: z5.number().min(0).max(9.9999).optional(),
28696
+ /** Tax amount (Monto). */
28697
+ monto: z5.number().min(0),
28698
+ /** Exoneration information. Optional. */
28699
+ exoneracion: ExoneracionSchema.optional()
28700
+ });
28701
+ var DescuentoSchema = z5.object({
28702
+ /** Discount amount. Must be positive. */
28703
+ montoDescuento: z5.number().positive(),
28704
+ /** Discount code (CodigoDescuento). Required in v4.4. */
28705
+ codigoDescuento: z5.enum(DISCOUNT_CODES),
28706
+ /** Free-text discount type. Required when codigoDescuento is "99". */
28707
+ codigoDescuentoOtros: z5.string().min(5).max(100).optional(),
28708
+ /** Reason for discount. Optional in v4.4, 3-80 chars. */
28709
+ naturalezaDescuento: z5.string().min(3).max(80).optional()
28710
+ });
28711
+ var LineaDetalleSchema = z5.object({
28712
+ /** Line number (1-based, sequential). */
28713
+ numeroLinea: z5.number().int().positive(),
28714
+ /** Customs tariff heading. Optional (NC/ND/FEE only), max 15 chars. */
28715
+ partidaArancelaria: z5.string().max(15).optional(),
28716
+ /** CABYS code — 13 digits, emitted as CodigoCABYS. */
28717
+ codigoCabys: z5.string().regex(/^\d{13}$/, "CABYS code must be exactly 13 digits"),
28718
+ /** Commercial codes. Optional, max 5. */
28719
+ codigoComercial: z5.array(CodigoComercialSchema).max(5).optional(),
28720
+ /** Quantity. Must be positive. */
28721
+ cantidad: z5.number().positive(),
28722
+ /** Unit of measure (official v4.4 catalog value). */
28723
+ unidadMedida: z5.enum(UNITS_OF_MEASURE),
28724
+ /** Transaction type code (TipoTransaccion, 01-13). Optional, v4.4. */
28725
+ tipoTransaccion: z5.enum(["01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13"]).optional(),
28726
+ /** Commercial unit of measure. Optional, max 20 chars. */
28727
+ unidadMedidaComercial: z5.string().max(20).optional(),
28728
+ /** Item description. 3-200 chars per the XSD. */
28729
+ detalle: z5.string().min(3).max(200),
28730
+ /** VIN or serial numbers. Optional, max 17 chars each. */
28731
+ numeroVINoSerie: z5.array(z5.string().min(1).max(17)).optional(),
28732
+ /** Unit price (before taxes and discounts). */
28733
+ precioUnitario: z5.number().min(0),
28734
+ /** Total line amount (cantidad * precioUnitario). */
28735
+ montoTotal: z5.number().min(0),
28736
+ /** Discounts applied. Optional, max 5. */
28737
+ descuento: z5.array(DescuentoSchema).max(5).optional(),
28738
+ /** Subtotal after discounts. */
28739
+ subTotal: z5.number().min(0),
28740
+ /** Base taxable amount. Defaults to subTotal at emission when omitted. */
28741
+ baseImponible: z5.number().min(0).optional(),
28742
+ /** Taxes applied to this line item. v4.4 requires at least one. */
28743
+ impuesto: z5.array(ImpuestoSchema).min(1),
28744
+ /** Tax assumed by issuer/factory. Optional (emitted as 0 when required). */
28745
+ impuestoAsumidoEmisorFabrica: z5.number().min(0).optional(),
28746
+ /** Net tax amount. Optional (emitted as 0 when required). */
28747
+ impuestoNeto: z5.number().min(0).optional(),
28748
+ /** Total line amount including taxes. */
28749
+ montoTotalLinea: z5.number().min(0)
28750
+ });
28751
+ var ClaveComponentsSchema = z6.object({
28752
+ /** Country code — must be "506". */
28753
+ countryCode: z6.literal("506"),
28754
+ /** Date in DDMMYY format. */
28755
+ date: z6.string().regex(/^\d{6}$/, "Date must be in DDMMYY format (6 digits)"),
28756
+ /** Taxpayer ID, zero-padded to 12 characters (alphanumeric since the April 2026 revision). */
28757
+ taxpayerId: z6.string().regex(/^[A-Za-z0-9]{12}$/, "Taxpayer ID must be exactly 12 alphanumeric characters"),
28758
+ /** Branch number, zero-padded to 3 digits. */
28759
+ branch: z6.string().regex(/^\d{3}$/, "Branch must be exactly 3 digits"),
28760
+ /** Terminal / POS number, zero-padded to 5 digits. */
28761
+ terminal: z6.string().regex(/^\d{5}$/, "Terminal must be exactly 5 digits"),
28762
+ /** Document type code (2 digits). */
28763
+ documentType: z6.enum([
28764
+ DocumentTypeCode.FACTURA_ELECTRONICA,
28765
+ DocumentTypeCode.NOTA_DEBITO_ELECTRONICA,
28766
+ DocumentTypeCode.NOTA_CREDITO_ELECTRONICA,
28767
+ DocumentTypeCode.TIQUETE_ELECTRONICO,
28768
+ DocumentTypeCode.FACTURA_ELECTRONICA_COMPRA,
28769
+ DocumentTypeCode.FACTURA_ELECTRONICA_EXPORTACION,
28770
+ DocumentTypeCode.RECIBO_ELECTRONICO_PAGO,
28771
+ DocumentTypeCode.COMPRA_PAGO,
28772
+ DocumentTypeCode.GASTO_VIAJE
28773
+ ]),
28774
+ /** Sequence number, zero-padded to 10 digits. */
28775
+ sequence: z6.string().regex(/^\d{10}$/, "Sequence must be exactly 10 digits"),
28776
+ /** Situation code (1 digit). */
28777
+ situation: z6.enum([SituationCode.NORMAL, SituationCode.CONTINGENCIA, SituationCode.SIN_INTERNET]),
28778
+ /** 8-digit security code. */
28779
+ securityCode: z6.string().regex(/^\d{8}$/, "Security code must be exactly 8 digits")
28780
+ });
28781
+ var ClaveInputSchema = z6.object({
28782
+ /** Emission date. */
28783
+ date: z6.date(),
28784
+ /** Taxpayer identification number (raw, without padding). 9-12 alphanumeric chars. */
28785
+ taxpayerId: z6.string().regex(/^[A-Za-z0-9]{9,12}$/, "Taxpayer ID must be 9-12 alphanumeric characters"),
28786
+ /** Document type code. */
28787
+ documentType: z6.enum([
28788
+ DocumentTypeCode.FACTURA_ELECTRONICA,
28789
+ DocumentTypeCode.NOTA_DEBITO_ELECTRONICA,
28790
+ DocumentTypeCode.NOTA_CREDITO_ELECTRONICA,
28791
+ DocumentTypeCode.TIQUETE_ELECTRONICO,
28792
+ DocumentTypeCode.FACTURA_ELECTRONICA_COMPRA,
28793
+ DocumentTypeCode.FACTURA_ELECTRONICA_EXPORTACION,
28794
+ DocumentTypeCode.RECIBO_ELECTRONICO_PAGO,
28795
+ DocumentTypeCode.COMPRA_PAGO,
28796
+ DocumentTypeCode.GASTO_VIAJE
28797
+ ]),
28798
+ /** Sequential document number (1 to 9999999999). */
28799
+ sequence: z6.number().int().positive().max(9999999999),
28800
+ /** Branch number. Defaults to 1. */
28801
+ branch: z6.number().int().positive().max(999).default(1),
28802
+ /** Terminal / POS number. Defaults to 1. */
28803
+ terminal: z6.number().int().positive().max(99999).default(1),
28804
+ /** Situation code. Defaults to "1" (normal). */
28805
+ situation: z6.enum([SituationCode.NORMAL, SituationCode.CONTINGENCIA, SituationCode.SIN_INTERNET]).default(SituationCode.NORMAL),
28806
+ /** 8-digit security code. Generated randomly if not provided. */
28807
+ securityCode: z6.string().regex(/^\d{8}$/, "Security code must be exactly 8 digits").optional()
28808
+ });
28809
+ var ClaveNumericaSchema = z6.string().length(50, "Clave numerica must be exactly 50 characters").regex(
28810
+ /^\d{9}[A-Za-z0-9]{12}\d{29}$/,
28811
+ "Clave must be numeric except the taxpayer-ID segment (positions 10-21), which may be alphanumeric"
28812
+ );
28813
+ var CodigoTipoMonedaSchema = z7.object({
28814
+ /** ISO 4217 currency code (official v4.4 catalog). */
28815
+ codigoMoneda: z7.enum(CURRENCY_CODES),
28816
+ /** Exchange rate to CRC. Must be positive. */
28817
+ tipoCambio: z7.number().positive()
28818
+ });
28819
+ var InformacionReferenciaSchema = z7.object({
28820
+ /** Referenced document type code (TipoDocIR). */
28821
+ tipoDoc: z7.enum(REFERENCE_DOC_TYPES),
28822
+ /** Free-text document type. Required when tipoDoc is "99" (5-100 chars). */
28823
+ tipoDocOtros: z7.string().min(5).max(100).optional(),
28824
+ /** Referenced document clave or number. Optional, max 50 chars. */
28825
+ numero: z7.string().min(1).max(50).optional(),
28826
+ /** Date of the referenced document (ISO 8601) — emitted as FechaEmisionIR. */
28827
+ fechaEmision: z7.string().min(1),
28828
+ /** Reference reason code. Optional in v4.4. */
28829
+ codigo: z7.enum(REFERENCE_CODES).optional(),
28830
+ /** Free-text reason code. Required when codigo is "99" (5-100 chars). */
28831
+ codigoOtros: z7.string().min(5).max(100).optional(),
28832
+ /** Description of the reason. Optional, max 180 chars. */
28833
+ razon: z7.string().min(1).max(180).optional()
28834
+ });
28835
+ var OtroCargoSchema = z7.object({
28836
+ /** Charge document type (TipoDocumentoOC). */
28837
+ tipoDocumento: z7.enum(OTHER_CHARGE_TYPES),
28838
+ /** Free-text charge type. Required when tipoDocumento is "99" (5-100 chars). */
28839
+ tipoDocumentoOtros: z7.string().min(5).max(100).optional(),
28840
+ /** Third-party identification. Optional. */
28841
+ identificacionTercero: IdentificacionSchema.optional(),
28842
+ /** Third-party name. Optional, 5-100 chars. */
28843
+ nombreTercero: z7.string().min(5).max(100).optional(),
28844
+ /** Detail. Max 160 chars. */
28845
+ detalle: z7.string().min(1).max(160),
28846
+ /** Percentage (PorcentajeOC). Optional. */
28847
+ porcentaje: z7.number().min(0).max(100).optional(),
28848
+ /** Charge amount (MontoCargo). */
28849
+ montoCargo: z7.number().min(0)
28850
+ });
28851
+ var MedioPagoSchema = z7.object({
28852
+ /** Payment method code (TipoMedioPago). */
28853
+ tipoMedioPago: PaymentMethodSchema,
28854
+ /** Free-text payment method. Required when tipo is "99" (3-100 chars). */
28855
+ medioPagoOtros: z7.string().min(3).max(100).optional(),
28856
+ /** Amount paid with this method (TotalMedioPago). */
28857
+ totalMedioPago: z7.number().min(0)
28858
+ });
28859
+ var TotalDesgloseImpuestoSchema = z7.object({
28860
+ /** Tax type code. */
28861
+ codigo: TaxCodeSchema,
28862
+ /** IVA rate code. Optional. */
28863
+ codigoTarifaIVA: IvaRateCodeSchema.optional(),
28864
+ /** Total tax amount for this (code, rate) pair. */
28865
+ totalMontoImpuesto: z7.number().min(0)
28866
+ });
28867
+ var ResumenFacturaSchema = z7.object({
28868
+ /** Currency information. Optional in input (builders default to CRC / 1). */
28869
+ codigoTipoMoneda: CodigoTipoMonedaSchema.optional(),
28870
+ /** Total taxable services. */
28871
+ totalServGravados: z7.number().min(0).optional(),
28872
+ /** Total exempt services. */
28873
+ totalServExentos: z7.number().min(0).optional(),
28874
+ /** Total exonerated services. */
28875
+ totalServExonerado: z7.number().min(0).optional(),
28876
+ /** Total non-subject services (v4.4). */
28877
+ totalServNoSujeto: z7.number().min(0).optional(),
28878
+ /** Total taxable merchandise. */
28879
+ totalMercanciasGravadas: z7.number().min(0).optional(),
28880
+ /** Total exempt merchandise. */
28881
+ totalMercanciasExentas: z7.number().min(0).optional(),
28882
+ /** Total exonerated merchandise. */
28883
+ totalMercExonerada: z7.number().min(0).optional(),
28884
+ /** Total non-subject merchandise (v4.4). */
28885
+ totalMercNoSujeta: z7.number().min(0).optional(),
28886
+ /** Total taxable. */
28887
+ totalGravado: z7.number().min(0).optional(),
28888
+ /** Total exempt. */
28889
+ totalExento: z7.number().min(0).optional(),
28890
+ /** Total exonerated. */
28891
+ totalExonerado: z7.number().min(0).optional(),
28892
+ /** Total non-subject (v4.4). */
28893
+ totalNoSujeto: z7.number().min(0).optional(),
28894
+ /** Total sales (before tax). */
28895
+ totalVenta: z7.number().min(0),
28896
+ /** Total discounts. */
28897
+ totalDescuentos: z7.number().min(0).optional(),
28898
+ /** Net sales (totalVenta - totalDescuentos). */
28899
+ totalVentaNeta: z7.number().min(0),
28900
+ /** Per-tax-code totals breakdown (v4.4). Optional. */
28901
+ totalDesgloseImpuesto: z7.array(TotalDesgloseImpuestoSchema).optional(),
28902
+ /** Total tax. */
28903
+ totalImpuesto: z7.number().min(0).optional(),
28904
+ /** Total tax assumed by issuer/factory (v4.4). */
28905
+ totalImpAsumEmisorFabrica: z7.number().min(0).optional(),
28906
+ /** Total IVA returned. Optional. */
28907
+ totalIVADevuelto: z7.number().min(0).optional(),
28908
+ /** Total other charges. Optional. */
28909
+ totalOtrosCargos: z7.number().min(0).optional(),
28910
+ /** Payment methods with amounts (v4.4). Up to 4 entries. */
28911
+ medioPago: z7.array(MedioPagoSchema).min(1).max(4).optional(),
28912
+ /** Grand total. */
28913
+ totalComprobante: z7.number().min(0)
28914
+ });
28915
+ var OtroContenidoSchema = z7.object({
28916
+ contenido: z7.string().min(1)
28917
+ });
28918
+ var FacturaElectronicaSchema = z7.object({
28919
+ /** 50-character clave (taxpayer segment alphanumeric since April 2026). */
28920
+ clave: z7.string().length(50).regex(/^\d{9}[A-Za-z0-9]{12}\d{29}$/),
28921
+ /** Invoicing-system provider identification (ProveedorSistemas). */
28922
+ proveedorSistemas: z7.string().min(1).max(20),
28923
+ /** Issuer economic activity code (6 digits). */
28924
+ codigoActividadEmisor: z7.string().regex(/^\d{6}$/, "Activity code must be 6 digits"),
28925
+ /** Receiver economic activity code (6 digits). Optional. */
28926
+ codigoActividadReceptor: z7.string().regex(/^\d{6}$/, "Activity code must be 6 digits").optional(),
28927
+ /** Sequential document number (20 chars). */
28928
+ numeroConsecutivo: z7.string().length(20).regex(/^\d{20}$/),
28929
+ /** Emission date (ISO 8601 with timezone). */
28930
+ fechaEmision: z7.string().min(1),
28931
+ /** Issuer information. */
28932
+ emisor: EmisorSchema,
28933
+ /** Receiver information. Required for Factura (with identification). */
28934
+ receptor: ReceptorSchema.refine((r) => r.identificacion !== void 0, {
28935
+ message: "Receptor identification is required for Factura Electronica",
28936
+ path: ["identificacion"]
28937
+ }),
28938
+ /** Sale condition (v4.4 set — REP-only payment codes excluded). */
28939
+ condicionVenta: SaleConditionSchema,
28940
+ /** Free-text sale condition. Required when condicionVenta is "99" (5-100 chars). */
28941
+ condicionVentaOtros: z7.string().min(5).max(100).optional(),
28942
+ /** Credit term in days. Required when condicionVenta is "02". */
28943
+ plazoCredito: z7.string().optional(),
28944
+ /** Line items. At least one required, max 1000. */
28945
+ detalleServicio: z7.array(LineaDetalleSchema).min(1).max(1e3),
28946
+ /** Other charges. Optional, max 15. */
28947
+ otrosCargos: z7.array(OtroCargoSchema).max(15).optional(),
28948
+ /** Invoice summary / totals. */
28949
+ resumenFactura: ResumenFacturaSchema,
28950
+ /** References to other documents. Optional, max 10. */
28951
+ informacionReferencia: z7.array(InformacionReferenciaSchema).max(10).optional(),
28952
+ /** Additional content. Optional. */
28953
+ otros: z7.array(OtroContenidoSchema).optional()
28954
+ });
28955
+ var EnvironmentSchema = z8.enum([Environment.SANDBOX, Environment.PRODUCTION]);
28956
+ var CredentialConfigSchema = z8.object({
28957
+ /** Full username. */
28958
+ username: z8.string().min(1).email().or(z8.string().min(1)),
28959
+ /** Path to the .p12 certificate file. */
28960
+ p12Path: z8.string().min(1)
28961
+ });
28962
+ var AppConfigSchema = z8.object({
28963
+ /** Active environment. */
28964
+ environment: EnvironmentSchema,
28965
+ /** Per-environment credential configuration. */
28966
+ credentials: z8.object({
28967
+ [Environment.SANDBOX]: CredentialConfigSchema.optional(),
28968
+ [Environment.PRODUCTION]: CredentialConfigSchema.optional()
28969
+ }).optional()
28970
+ });
28971
+
28972
+ // ../sdk/dist/index.js
27805
28973
  import { z as z22 } from "zod";
27806
28974
  import { z as z52 } from "zod";
27807
28975
  import { readFile, writeFile, mkdir, access, chmod } from "fs/promises";
@@ -28877,686 +30045,6 @@ function isAttribute(name2) {
28877
30045
  }
28878
30046
  }
28879
30047
 
28880
- // ../../shared/dist/index.js
28881
- import { z } from "zod";
28882
- import { z as z2 } from "zod";
28883
- import { z as z3 } from "zod";
28884
- import { z as z4 } from "zod";
28885
- import { z as z5 } from "zod";
28886
- import { z as z6 } from "zod";
28887
- import { z as z7 } from "zod";
28888
- import { z as z8 } from "zod";
28889
- var Environment = {
28890
- SANDBOX: "sandbox",
28891
- PRODUCTION: "production"
28892
- };
28893
- var API_BASE_URLS = {
28894
- [Environment.SANDBOX]: "https://api-sandbox.comprobanteselectronicos.go.cr/recepcion/v1",
28895
- [Environment.PRODUCTION]: "https://api.comprobanteselectronicos.go.cr/recepcion/v1"
28896
- };
28897
- var IDP_TOKEN_URLS = {
28898
- [Environment.SANDBOX]: "https://idp.comprobanteselectronicos.go.cr/auth/realms/rut-stag/protocol/openid-connect/token",
28899
- [Environment.PRODUCTION]: "https://idp.comprobanteselectronicos.go.cr/auth/realms/rut/protocol/openid-connect/token"
28900
- };
28901
- var CLIENT_IDS = {
28902
- [Environment.SANDBOX]: "api-stag",
28903
- [Environment.PRODUCTION]: "api-prod"
28904
- };
28905
- var IDP_LOGOUT_URLS = {
28906
- [Environment.SANDBOX]: "https://idp.comprobanteselectronicos.go.cr/auth/realms/rut-stag/protocol/openid-connect/logout",
28907
- [Environment.PRODUCTION]: "https://idp.comprobanteselectronicos.go.cr/auth/realms/rut/protocol/openid-connect/token/logout"
28908
- };
28909
- var ECONOMIC_ACTIVITY_API_URL = "https://api.hacienda.go.cr/fe/ae";
28910
- var DocumentTypeCode = {
28911
- /** Factura Electronica */
28912
- FACTURA_ELECTRONICA: "01",
28913
- /** Nota de Debito Electronica */
28914
- NOTA_DEBITO_ELECTRONICA: "02",
28915
- /** Nota de Credito Electronica */
28916
- NOTA_CREDITO_ELECTRONICA: "03",
28917
- /** Tiquete Electronico */
28918
- TIQUETE_ELECTRONICO: "04",
28919
- /** Factura Electronica de Compra */
28920
- FACTURA_ELECTRONICA_COMPRA: "05",
28921
- /** Factura Electronica de Exportacion */
28922
- FACTURA_ELECTRONICA_EXPORTACION: "06",
28923
- /** Recibo Electronico de Pago (new in v4.4) */
28924
- RECIBO_ELECTRONICO_PAGO: "07",
28925
- /** Compra de Pago */
28926
- COMPRA_PAGO: "08",
28927
- /** Gasto de Viaje */
28928
- GASTO_VIAJE: "09"
28929
- };
28930
- var DOCUMENT_TYPE_NAMES = {
28931
- [DocumentTypeCode.FACTURA_ELECTRONICA]: "Factura Electr\xF3nica",
28932
- [DocumentTypeCode.NOTA_DEBITO_ELECTRONICA]: "Nota de D\xE9bito Electr\xF3nica",
28933
- [DocumentTypeCode.NOTA_CREDITO_ELECTRONICA]: "Nota de Cr\xE9dito Electr\xF3nica",
28934
- [DocumentTypeCode.TIQUETE_ELECTRONICO]: "Tiquete Electr\xF3nico",
28935
- [DocumentTypeCode.FACTURA_ELECTRONICA_COMPRA]: "Factura Electr\xF3nica de Compra",
28936
- [DocumentTypeCode.FACTURA_ELECTRONICA_EXPORTACION]: "Factura Electr\xF3nica de Exportaci\xF3n",
28937
- [DocumentTypeCode.RECIBO_ELECTRONICO_PAGO]: "Recibo Electr\xF3nico de Pago",
28938
- [DocumentTypeCode.COMPRA_PAGO]: "Compra de Pago",
28939
- [DocumentTypeCode.GASTO_VIAJE]: "Gasto de Viaje"
28940
- };
28941
- var MensajeReceptorCode = {
28942
- /** Aceptado totalmente */
28943
- ACEPTADO: "1",
28944
- /** Aceptado parcialmente */
28945
- ACEPTADO_PARCIALMENTE: "2",
28946
- /** Rechazado */
28947
- RECHAZADO: "3"
28948
- };
28949
- var SituationCode = {
28950
- /** Normal */
28951
- NORMAL: "1",
28952
- /** Contingencia (contingency) */
28953
- CONTINGENCIA: "2",
28954
- /** Sin internet (no internet) */
28955
- SIN_INTERNET: "3"
28956
- };
28957
- var TaxCode = {
28958
- /** Impuesto al Valor Agregado (IVA) */
28959
- IVA: "01",
28960
- /** Impuesto Selectivo de Consumo */
28961
- IMPUESTO_SELECTIVO_CONSUMO: "02",
28962
- /** Impuesto Unico a los Combustibles */
28963
- IMPUESTO_UNICO_COMBUSTIBLES: "03",
28964
- /** Impuesto Especifico de Bebidas Alcoholicas */
28965
- IMPUESTO_BEBIDAS_ALCOHOLICAS: "04",
28966
- /** Impuesto Especifico sobre Bebidas Envasadas sin Alcohol y Jabones de Tocador */
28967
- IMPUESTO_BEBIDAS_SIN_ALCOHOL: "05",
28968
- /** Impuesto al Tabaco */
28969
- IMPUESTO_TABACO: "06",
28970
- /** IVA (calculo especial) */
28971
- IVA_CALCULO_ESPECIAL: "07",
28972
- /** IVA Regimen de Bienes Usados (Factor) */
28973
- IVA_BIENES_USADOS: "08",
28974
- /** Impuesto Especifico al Cemento */
28975
- IMPUESTO_CEMENTO: "12",
28976
- /** Otros */
28977
- OTROS: "99"
28978
- };
28979
- var IvaRateCode = {
28980
- /** Tarifa 0% (Exento) */
28981
- EXENTO: "01",
28982
- /** Tarifa reducida 1% */
28983
- REDUCIDA_1: "02",
28984
- /** Tarifa reducida 2% */
28985
- REDUCIDA_2: "03",
28986
- /** Tarifa reducida 4% */
28987
- REDUCIDA_4: "04",
28988
- /** Transitorio 0% */
28989
- TRANSITORIO_0: "05",
28990
- /** Transitorio 4% */
28991
- TRANSITORIO_4: "06",
28992
- /** Transitorio 8% */
28993
- TRANSITORIO_8: "07",
28994
- /** Tarifa general 13% */
28995
- GENERAL_13: "08"
28996
- };
28997
- var IVA_RATE_PERCENTAGES = {
28998
- [IvaRateCode.EXENTO]: 0,
28999
- [IvaRateCode.REDUCIDA_1]: 1,
29000
- [IvaRateCode.REDUCIDA_2]: 2,
29001
- [IvaRateCode.REDUCIDA_4]: 4,
29002
- [IvaRateCode.TRANSITORIO_0]: 0,
29003
- [IvaRateCode.TRANSITORIO_4]: 4,
29004
- [IvaRateCode.TRANSITORIO_8]: 8,
29005
- [IvaRateCode.GENERAL_13]: 13
29006
- };
29007
- var ExonerationType = {
29008
- /** Compras autorizadas */
29009
- COMPRAS_AUTORIZADAS: "01",
29010
- /** Ventas exentas a diplomáticos */
29011
- VENTAS_EXENTAS_DIPLOMATICOS: "02",
29012
- /** Autorizado por ley especial */
29013
- AUTORIZADO_LEY_ESPECIAL: "03",
29014
- /** Exenciones de la Dirección General de Hacienda */
29015
- EXENCIONES_DGH: "04",
29016
- /** Transitorio V */
29017
- TRANSITORIO_V: "05",
29018
- /** Transitorio IX */
29019
- TRANSITORIO_IX: "06",
29020
- /** Transitorio XVII */
29021
- TRANSITORIO_XVII: "07",
29022
- /** Otros */
29023
- OTROS: "99"
29024
- };
29025
- var UnitOfMeasure = {
29026
- /** Servicios profesionales (sp) */
29027
- SERVICIOS_PROFESIONALES: "Sp",
29028
- /** Metros */
29029
- METROS: "m",
29030
- /** Kilogramos */
29031
- KILOGRAMOS: "kg",
29032
- /** Segundos */
29033
- SEGUNDOS: "s",
29034
- /** Amperes */
29035
- AMPERES: "A",
29036
- /** Kelvin */
29037
- KELVIN: "K",
29038
- /** Moles */
29039
- MOLES: "mol",
29040
- /** Candelas */
29041
- CANDELAS: "cd",
29042
- /** Metros cuadrados */
29043
- METROS_CUADRADOS: "m\xB2",
29044
- /** Metros cubicos */
29045
- METROS_CUBICOS: "m\xB3",
29046
- /** Litros */
29047
- LITROS: "l",
29048
- /** Watts */
29049
- WATTS: "W",
29050
- /** Voltios */
29051
- VOLTIOS: "V",
29052
- /** Julios (Joules) */
29053
- JULIOS: "J",
29054
- /** Gramos */
29055
- GRAMOS: "g",
29056
- /** Toneladas */
29057
- TONELADAS: "t",
29058
- /** Galones */
29059
- GALONES: "Gal",
29060
- /** Unidad */
29061
- UNIDAD: "Unid",
29062
- /** Otros (especificar) */
29063
- OTROS: "Os",
29064
- /** Pulgadas */
29065
- PULGADAS: "in",
29066
- /** Centimetros */
29067
- CENTIMETROS: "cm",
29068
- /** Mililitros */
29069
- MILILITROS: "ml",
29070
- /** Onzas */
29071
- ONZAS: "oz",
29072
- /** Libras */
29073
- LIBRAS: "lb",
29074
- /** Pies */
29075
- PIES: "ft",
29076
- /** Yardas */
29077
- YARDAS: "yd",
29078
- /** Horas */
29079
- HORAS: "h",
29080
- /** Minutos */
29081
- MINUTOS: "min",
29082
- /** Dias */
29083
- DIAS: "d",
29084
- /** Cajas */
29085
- CAJAS: "Cj",
29086
- /** Paquetes */
29087
- PAQUETES: "Pq"
29088
- };
29089
- var IdentificationType = {
29090
- /** Cedula Fisica (physical person ID) — 9 digits */
29091
- CEDULA_FISICA: "01",
29092
- /** Cedula Juridica (legal entity ID) — 10 digits */
29093
- CEDULA_JURIDICA: "02",
29094
- /** DIMEX (foreign resident ID) — 11-12 digits */
29095
- DIMEX: "03",
29096
- /** NITE (tax ID for foreigners without DIMEX) — 10 digits */
29097
- NITE: "04"
29098
- };
29099
- var IDENTIFICATION_TYPE_NAMES = {
29100
- [IdentificationType.CEDULA_FISICA]: "C\xE9dula F\xEDsica",
29101
- [IdentificationType.CEDULA_JURIDICA]: "C\xE9dula Jur\xEDdica",
29102
- [IdentificationType.DIMEX]: "DIMEX",
29103
- [IdentificationType.NITE]: "NITE"
29104
- };
29105
- var IDENTIFICATION_LENGTHS = {
29106
- [IdentificationType.CEDULA_FISICA]: [9],
29107
- [IdentificationType.CEDULA_JURIDICA]: [10],
29108
- [IdentificationType.DIMEX]: [11, 12],
29109
- [IdentificationType.NITE]: [10]
29110
- };
29111
- var SaleCondition = {
29112
- /** Contado (cash / immediate payment) */
29113
- CONTADO: "01",
29114
- /** Credito (credit) */
29115
- CREDITO: "02",
29116
- /** Consignacion */
29117
- CONSIGNACION: "03",
29118
- /** Apartado */
29119
- APARTADO: "04",
29120
- /** Arrendamiento con opcion de compra */
29121
- ARRENDAMIENTO_OPCION_COMPRA: "05",
29122
- /** Arrendamiento en funcion financiera */
29123
- ARRENDAMIENTO_FUNCION_FINANCIERA: "06",
29124
- /** Cobro a favor de un tercero */
29125
- COBRO_FAVOR_TERCERO: "07",
29126
- /** Servicios prestados al Estado a credito */
29127
- SERVICIOS_ESTADO_CREDITO: "08",
29128
- /** Pago del servicio prestado al Estado */
29129
- PAGO_SERVICIO_ESTADO: "09",
29130
- /** Otros (especificar) */
29131
- OTROS: "99"
29132
- };
29133
- var SALE_CONDITION_NAMES = {
29134
- [SaleCondition.CONTADO]: "Contado",
29135
- [SaleCondition.CREDITO]: "Cr\xE9dito",
29136
- [SaleCondition.CONSIGNACION]: "Consignaci\xF3n",
29137
- [SaleCondition.APARTADO]: "Apartado",
29138
- [SaleCondition.ARRENDAMIENTO_OPCION_COMPRA]: "Arrendamiento con opci\xF3n de compra",
29139
- [SaleCondition.ARRENDAMIENTO_FUNCION_FINANCIERA]: "Arrendamiento en funci\xF3n financiera",
29140
- [SaleCondition.COBRO_FAVOR_TERCERO]: "Cobro a favor de un tercero",
29141
- [SaleCondition.SERVICIOS_ESTADO_CREDITO]: "Servicios prestados al Estado a cr\xE9dito",
29142
- [SaleCondition.PAGO_SERVICIO_ESTADO]: "Pago del servicio prestado al Estado",
29143
- [SaleCondition.OTROS]: "Otros"
29144
- };
29145
- var PaymentMethod = {
29146
- /** Efectivo (cash) */
29147
- EFECTIVO: "01",
29148
- /** Tarjeta (card) */
29149
- TARJETA: "02",
29150
- /** Cheque */
29151
- CHEQUE: "03",
29152
- /** Transferencia - Deposito bancario */
29153
- TRANSFERENCIA: "04",
29154
- /** Recaudado por terceros */
29155
- RECAUDADO_TERCEROS: "05",
29156
- /** Otros (especificar) */
29157
- OTROS: "99"
29158
- };
29159
- var PAYMENT_METHOD_NAMES = {
29160
- [PaymentMethod.EFECTIVO]: "Efectivo",
29161
- [PaymentMethod.TARJETA]: "Tarjeta",
29162
- [PaymentMethod.CHEQUE]: "Cheque",
29163
- [PaymentMethod.TRANSFERENCIA]: "Transferencia - Dep\xF3sito bancario",
29164
- [PaymentMethod.RECAUDADO_TERCEROS]: "Recaudado por terceros",
29165
- [PaymentMethod.OTROS]: "Otros"
29166
- };
29167
- var ProvinceCode = {
29168
- /** San Jose */
29169
- SAN_JOSE: "1",
29170
- /** Alajuela */
29171
- ALAJUELA: "2",
29172
- /** Cartago */
29173
- CARTAGO: "3",
29174
- /** Heredia */
29175
- HEREDIA: "4",
29176
- /** Guanacaste */
29177
- GUANACASTE: "5",
29178
- /** Puntarenas */
29179
- PUNTARENAS: "6",
29180
- /** Limon */
29181
- LIMON: "7"
29182
- };
29183
- var PROVINCE_NAMES = {
29184
- [ProvinceCode.SAN_JOSE]: "San Jos\xE9",
29185
- [ProvinceCode.ALAJUELA]: "Alajuela",
29186
- [ProvinceCode.CARTAGO]: "Cartago",
29187
- [ProvinceCode.HEREDIA]: "Heredia",
29188
- [ProvinceCode.GUANACASTE]: "Guanacaste",
29189
- [ProvinceCode.PUNTARENAS]: "Puntarenas",
29190
- [ProvinceCode.LIMON]: "Lim\xF3n"
29191
- };
29192
- var TelefonoSchema = z.object({
29193
- /** Country code (e.g., "506"). Max 3 digits. */
29194
- codigoPais: z.string().regex(/^\d{1,3}$/),
29195
- /** Phone number. Max 20 digits. */
29196
- numTelefono: z.string().regex(/^\d{1,20}$/)
29197
- });
29198
- var UbicacionSchema = z.object({
29199
- /** Province code (1-7). */
29200
- provincia: z.string().regex(/^[1-7]$/),
29201
- /** Canton code (2 digits, 01-99). */
29202
- canton: z.string().regex(/^\d{2}$/),
29203
- /** Distrito code (2 digits, 01-99). */
29204
- distrito: z.string().regex(/^\d{2}$/),
29205
- /** Barrio code (2 digits). Optional. */
29206
- barrio: z.string().regex(/^\d{2}$/).optional(),
29207
- /** Additional address details. Optional, max 250 chars. */
29208
- otrasSenas: z.string().max(250).optional()
29209
- });
29210
- var IdentificationTypeSchema = z2.enum([
29211
- IdentificationType.CEDULA_FISICA,
29212
- IdentificationType.CEDULA_JURIDICA,
29213
- IdentificationType.DIMEX,
29214
- IdentificationType.NITE
29215
- ]);
29216
- var IdentificacionSchema = z2.object({
29217
- /** Identification type code. */
29218
- tipo: IdentificationTypeSchema,
29219
- /** Identification number (digits only). */
29220
- numero: z2.string().regex(/^\d+$/, "Must contain only digits")
29221
- }).refine(
29222
- (data) => {
29223
- const expectedLengths = IDENTIFICATION_LENGTHS[data.tipo];
29224
- if (!expectedLengths) return true;
29225
- return expectedLengths.includes(data.numero.length);
29226
- },
29227
- {
29228
- message: "Identification number length does not match the expected length for the given type",
29229
- path: ["numero"]
29230
- }
29231
- );
29232
- var EmisorSchema = z3.object({
29233
- /** Issuer name (Nombre o Razon Social). Max 100 chars. */
29234
- nombre: z3.string().min(1).max(100),
29235
- /** Taxpayer identification. */
29236
- identificacion: IdentificacionSchema,
29237
- /** Commercial name. Optional, max 80 chars. */
29238
- nombreComercial: z3.string().max(80).optional(),
29239
- /** Location. Optional. */
29240
- ubicacion: UbicacionSchema.optional(),
29241
- /** Phone number. Optional. */
29242
- telefono: TelefonoSchema.optional(),
29243
- /** Fax number. Optional. */
29244
- fax: TelefonoSchema.optional(),
29245
- /** Email address. */
29246
- correoElectronico: z3.string().email().max(160)
29247
- });
29248
- var ReceptorSchema = z4.object({
29249
- /** Receiver name. Max 100 chars. */
29250
- nombre: z4.string().min(1).max(100),
29251
- /** Taxpayer identification. Optional for some doc types (e.g., Tiquete). */
29252
- identificacion: IdentificacionSchema.optional(),
29253
- /** Foreign identification number. Optional, max 20 chars. */
29254
- identificacionExtranjero: z4.string().max(20).optional(),
29255
- /** Commercial name. Optional, max 80 chars. */
29256
- nombreComercial: z4.string().max(80).optional(),
29257
- /** Location. Optional. */
29258
- ubicacion: UbicacionSchema.optional(),
29259
- /** Phone number. Optional. */
29260
- telefono: TelefonoSchema.optional(),
29261
- /** Fax number. Optional. */
29262
- fax: TelefonoSchema.optional(),
29263
- /** Email address. Optional, max 160 chars. */
29264
- correoElectronico: z4.string().email().max(160).optional()
29265
- });
29266
- var CodigoComercialSchema = z5.object({
29267
- /** Code type: 01=Seller, 02=Buyer, 03=Industry, 04=Internal, 99=Other. */
29268
- tipo: z5.enum(["01", "02", "03", "04", "99"]),
29269
- /** Product/service code value. Max 20 chars. */
29270
- codigo: z5.string().min(1).max(20)
29271
- });
29272
- var ExoneracionSchema = z5.object({
29273
- /** Exoneration document type. */
29274
- tipoDocumento: z5.enum([
29275
- ExonerationType.COMPRAS_AUTORIZADAS,
29276
- ExonerationType.VENTAS_EXENTAS_DIPLOMATICOS,
29277
- ExonerationType.AUTORIZADO_LEY_ESPECIAL,
29278
- ExonerationType.EXENCIONES_DGH,
29279
- ExonerationType.TRANSITORIO_V,
29280
- ExonerationType.TRANSITORIO_IX,
29281
- ExonerationType.TRANSITORIO_XVII,
29282
- ExonerationType.OTROS
29283
- ]),
29284
- /** Exoneration document number. Max 40 chars. */
29285
- numeroDocumento: z5.string().min(1).max(40),
29286
- /** Issuing institution name. Max 160 chars. */
29287
- nombreInstitucion: z5.string().min(1).max(160),
29288
- /** Issue date (ISO 8601). */
29289
- fechaEmision: z5.string().min(1),
29290
- /** Exoneration percentage (0-100). */
29291
- porcentajeExoneracion: z5.number().min(0).max(100),
29292
- /** Exonerated tax amount. */
29293
- montoExoneracion: z5.number().min(0)
29294
- });
29295
- var ImpuestoSchema = z5.object({
29296
- /** Tax type code. */
29297
- codigo: z5.enum([
29298
- TaxCode.IVA,
29299
- TaxCode.IMPUESTO_SELECTIVO_CONSUMO,
29300
- TaxCode.IMPUESTO_UNICO_COMBUSTIBLES,
29301
- TaxCode.IMPUESTO_BEBIDAS_ALCOHOLICAS,
29302
- TaxCode.IMPUESTO_BEBIDAS_SIN_ALCOHOL,
29303
- TaxCode.IMPUESTO_TABACO,
29304
- TaxCode.IVA_CALCULO_ESPECIAL,
29305
- TaxCode.IVA_BIENES_USADOS,
29306
- TaxCode.IMPUESTO_CEMENTO,
29307
- TaxCode.OTROS
29308
- ]),
29309
- /** IVA rate code. Required when tax code is IVA-related. */
29310
- codigoTarifa: z5.enum([
29311
- IvaRateCode.EXENTO,
29312
- IvaRateCode.REDUCIDA_1,
29313
- IvaRateCode.REDUCIDA_2,
29314
- IvaRateCode.REDUCIDA_4,
29315
- IvaRateCode.TRANSITORIO_0,
29316
- IvaRateCode.TRANSITORIO_4,
29317
- IvaRateCode.TRANSITORIO_8,
29318
- IvaRateCode.GENERAL_13
29319
- ]).optional(),
29320
- /** Tax rate percentage. */
29321
- tarifa: z5.number().min(0),
29322
- /** Tax amount. */
29323
- monto: z5.number().min(0),
29324
- /** Exoneration information. Optional. */
29325
- exoneracion: ExoneracionSchema.optional()
29326
- });
29327
- var DescuentoSchema = z5.object({
29328
- /** Discount amount. Must be positive. */
29329
- montoDescuento: z5.number().positive(),
29330
- /** Reason for discount. Max 80 chars. */
29331
- naturalezaDescuento: z5.string().min(1).max(80)
29332
- });
29333
- var LineaDetalleSchema = z5.object({
29334
- /** Line number (1-based, sequential). */
29335
- numeroLinea: z5.number().int().positive(),
29336
- /** CABYS code — 13 digits, required in v4.4. */
29337
- codigoCabys: z5.string().regex(/^\d{13}$/, "CABYS code must be exactly 13 digits"),
29338
- /** Commercial codes. Optional. */
29339
- codigoComercial: z5.array(CodigoComercialSchema).optional(),
29340
- /** Quantity. Must be positive. */
29341
- cantidad: z5.number().positive(),
29342
- /** Unit of measure. */
29343
- unidadMedida: z5.string().min(1).max(20),
29344
- /** Item description. Max 200 chars. */
29345
- detalle: z5.string().min(1).max(200),
29346
- /** Unit price (before taxes and discounts). */
29347
- precioUnitario: z5.number().min(0),
29348
- /** Total line amount (cantidad * precioUnitario). */
29349
- montoTotal: z5.number().min(0),
29350
- /** Discounts applied. Optional. */
29351
- descuento: z5.array(DescuentoSchema).optional(),
29352
- /** Subtotal after discounts. */
29353
- subTotal: z5.number().min(0),
29354
- /** Base taxable amount. Optional. */
29355
- baseImponible: z5.number().min(0).optional(),
29356
- /** Taxes applied to this line item. Optional. */
29357
- impuesto: z5.array(ImpuestoSchema).optional(),
29358
- /** Net IVA tax amount. Optional. */
29359
- impuestoNeto: z5.number().min(0).optional(),
29360
- /** Total line amount including taxes. */
29361
- montoTotalLinea: z5.number().min(0)
29362
- });
29363
- var ClaveComponentsSchema = z6.object({
29364
- /** Country code — must be "506". */
29365
- countryCode: z6.literal("506"),
29366
- /** Date in DDMMYY format. */
29367
- date: z6.string().regex(/^\d{6}$/, "Date must be in DDMMYY format (6 digits)"),
29368
- /** Taxpayer ID, zero-padded to 12 digits. */
29369
- taxpayerId: z6.string().regex(/^\d{12}$/, "Taxpayer ID must be exactly 12 digits (zero-padded)"),
29370
- /** Branch number, zero-padded to 3 digits. */
29371
- branch: z6.string().regex(/^\d{3}$/, "Branch must be exactly 3 digits"),
29372
- /** Terminal / POS number, zero-padded to 5 digits. */
29373
- terminal: z6.string().regex(/^\d{5}$/, "Terminal must be exactly 5 digits"),
29374
- /** Document type code (2 digits). */
29375
- documentType: z6.enum([
29376
- DocumentTypeCode.FACTURA_ELECTRONICA,
29377
- DocumentTypeCode.NOTA_DEBITO_ELECTRONICA,
29378
- DocumentTypeCode.NOTA_CREDITO_ELECTRONICA,
29379
- DocumentTypeCode.TIQUETE_ELECTRONICO,
29380
- DocumentTypeCode.FACTURA_ELECTRONICA_COMPRA,
29381
- DocumentTypeCode.FACTURA_ELECTRONICA_EXPORTACION,
29382
- DocumentTypeCode.RECIBO_ELECTRONICO_PAGO,
29383
- DocumentTypeCode.COMPRA_PAGO,
29384
- DocumentTypeCode.GASTO_VIAJE
29385
- ]),
29386
- /** Sequence number, zero-padded to 10 digits. */
29387
- sequence: z6.string().regex(/^\d{10}$/, "Sequence must be exactly 10 digits"),
29388
- /** Situation code (1 digit). */
29389
- situation: z6.enum([SituationCode.NORMAL, SituationCode.CONTINGENCIA, SituationCode.SIN_INTERNET]),
29390
- /** 8-digit security code. */
29391
- securityCode: z6.string().regex(/^\d{8}$/, "Security code must be exactly 8 digits")
29392
- });
29393
- var ClaveInputSchema = z6.object({
29394
- /** Emission date. */
29395
- date: z6.date(),
29396
- /** Taxpayer identification number (raw, without padding). 9-12 digits. */
29397
- taxpayerId: z6.string().regex(/^\d{9,12}$/, "Taxpayer ID must be 9-12 digits"),
29398
- /** Document type code. */
29399
- documentType: z6.enum([
29400
- DocumentTypeCode.FACTURA_ELECTRONICA,
29401
- DocumentTypeCode.NOTA_DEBITO_ELECTRONICA,
29402
- DocumentTypeCode.NOTA_CREDITO_ELECTRONICA,
29403
- DocumentTypeCode.TIQUETE_ELECTRONICO,
29404
- DocumentTypeCode.FACTURA_ELECTRONICA_COMPRA,
29405
- DocumentTypeCode.FACTURA_ELECTRONICA_EXPORTACION,
29406
- DocumentTypeCode.RECIBO_ELECTRONICO_PAGO,
29407
- DocumentTypeCode.COMPRA_PAGO,
29408
- DocumentTypeCode.GASTO_VIAJE
29409
- ]),
29410
- /** Sequential document number (1 to 9999999999). */
29411
- sequence: z6.number().int().positive().max(9999999999),
29412
- /** Branch number. Defaults to 1. */
29413
- branch: z6.number().int().positive().max(999).default(1),
29414
- /** Terminal / POS number. Defaults to 1. */
29415
- terminal: z6.number().int().positive().max(99999).default(1),
29416
- /** Situation code. Defaults to "1" (normal). */
29417
- situation: z6.enum([SituationCode.NORMAL, SituationCode.CONTINGENCIA, SituationCode.SIN_INTERNET]).default(SituationCode.NORMAL),
29418
- /** 8-digit security code. Generated randomly if not provided. */
29419
- securityCode: z6.string().regex(/^\d{8}$/, "Security code must be exactly 8 digits").optional()
29420
- });
29421
- var ClaveNumericaSchema = z6.string().length(50, "Clave numerica must be exactly 50 characters").regex(/^\d{50}$/, "Clave numerica must contain only digits");
29422
- var CodigoTipoMonedaSchema = z7.object({
29423
- /** ISO 4217 currency code (e.g., "USD", "CRC", "EUR"). */
29424
- codigoMoneda: z7.string().length(3),
29425
- /** Exchange rate to CRC. Must be positive. */
29426
- tipoCambio: z7.number().positive()
29427
- });
29428
- var InformacionReferenciaSchema = z7.object({
29429
- /** Referenced document type code. */
29430
- tipoDoc: z7.string().regex(/^\d{2}$/),
29431
- /** Referenced document clave or number. Max 50 chars. */
29432
- numero: z7.string().min(1).max(50),
29433
- /** Date of the referenced document (ISO 8601). */
29434
- fechaEmision: z7.string().min(1),
29435
- /** Reference reason code. */
29436
- codigo: z7.enum(["01", "02", "04", "05", "99"]),
29437
- /** Description of the reason. Max 180 chars. */
29438
- razon: z7.string().min(1).max(180)
29439
- });
29440
- var OtroCargoSchema = z7.object({
29441
- /** Charge document type. */
29442
- tipoDocumento: z7.string().min(1),
29443
- /** Third-party identification number. Optional. */
29444
- numeroIdentidadTercero: z7.string().optional(),
29445
- /** Third-party name. Optional, max 100 chars. */
29446
- nombreTercero: z7.string().max(100).optional(),
29447
- /** Detail. Max 160 chars. */
29448
- detalle: z7.string().min(1).max(160),
29449
- /** Percentage. Optional. */
29450
- porcentaje: z7.number().min(0).max(100).optional(),
29451
- /** Charge amount. */
29452
- montoOtroCargo: z7.number().min(0)
29453
- });
29454
- var ResumenFacturaSchema = z7.object({
29455
- /** Currency information. Optional (defaults to CRC). */
29456
- codigoTipoMoneda: CodigoTipoMonedaSchema.optional(),
29457
- /** Total taxable services. */
29458
- totalServGravados: z7.number().min(0),
29459
- /** Total exempt services. */
29460
- totalServExentos: z7.number().min(0),
29461
- /** Total exonerated services. Optional. */
29462
- totalServExonerado: z7.number().min(0).optional(),
29463
- /** Total taxable merchandise. */
29464
- totalMercanciasGravadas: z7.number().min(0),
29465
- /** Total exempt merchandise. */
29466
- totalMercanciasExentas: z7.number().min(0),
29467
- /** Total exonerated merchandise. Optional. */
29468
- totalMercExonerada: z7.number().min(0).optional(),
29469
- /** Total taxable. */
29470
- totalGravado: z7.number().min(0),
29471
- /** Total exempt. */
29472
- totalExento: z7.number().min(0),
29473
- /** Total exonerated. Optional. */
29474
- totalExonerado: z7.number().min(0).optional(),
29475
- /** Total sales (before tax). */
29476
- totalVenta: z7.number().min(0),
29477
- /** Total discounts. */
29478
- totalDescuentos: z7.number().min(0),
29479
- /** Net sales (totalVenta - totalDescuentos). */
29480
- totalVentaNeta: z7.number().min(0),
29481
- /** Total IVA tax. */
29482
- totalImpuesto: z7.number().min(0),
29483
- /** Total IVA returned. Optional. */
29484
- totalIVADevuelto: z7.number().min(0).optional(),
29485
- /** Total other charges. Optional. */
29486
- totalOtrosCargos: z7.number().min(0).optional(),
29487
- /** Grand total. */
29488
- totalComprobante: z7.number().min(0)
29489
- });
29490
- var OtroContenidoSchema = z7.object({
29491
- contenido: z7.string().min(1)
29492
- });
29493
- var SaleConditionValues = [
29494
- SaleCondition.CONTADO,
29495
- SaleCondition.CREDITO,
29496
- SaleCondition.CONSIGNACION,
29497
- SaleCondition.APARTADO,
29498
- SaleCondition.ARRENDAMIENTO_OPCION_COMPRA,
29499
- SaleCondition.ARRENDAMIENTO_FUNCION_FINANCIERA,
29500
- SaleCondition.COBRO_FAVOR_TERCERO,
29501
- SaleCondition.SERVICIOS_ESTADO_CREDITO,
29502
- SaleCondition.PAGO_SERVICIO_ESTADO,
29503
- SaleCondition.OTROS
29504
- ];
29505
- var PaymentMethodValues = [
29506
- PaymentMethod.EFECTIVO,
29507
- PaymentMethod.TARJETA,
29508
- PaymentMethod.CHEQUE,
29509
- PaymentMethod.TRANSFERENCIA,
29510
- PaymentMethod.RECAUDADO_TERCEROS,
29511
- PaymentMethod.OTROS
29512
- ];
29513
- var FacturaElectronicaSchema = z7.object({
29514
- /** 50-digit clave numerica. */
29515
- clave: z7.string().length(50).regex(/^\d{50}$/),
29516
- /** CABYS activity code. */
29517
- codigoActividad: z7.string().regex(/^\d{6}$/, "Activity code must be 6 digits"),
29518
- /** Sequential document number (20 chars). */
29519
- numeroConsecutivo: z7.string().length(20).regex(/^\d{20}$/),
29520
- /** Emission date (ISO 8601 with timezone). */
29521
- fechaEmision: z7.string().min(1),
29522
- /** Issuer information. */
29523
- emisor: EmisorSchema,
29524
- /** Receiver information. Required for Factura. */
29525
- receptor: ReceptorSchema,
29526
- /** Sale condition. */
29527
- condicionVenta: z7.enum(SaleConditionValues),
29528
- /** Credit term in days. Required when condicionVenta is "02". */
29529
- plazoCredito: z7.string().optional(),
29530
- /** Payment methods. At least one required. */
29531
- medioPago: z7.array(z7.enum(PaymentMethodValues)).min(1),
29532
- /** Line items. At least one required. */
29533
- detalleServicio: z7.array(LineaDetalleSchema).min(1),
29534
- /** Other charges. Optional. */
29535
- otrosCargos: z7.array(OtroCargoSchema).optional(),
29536
- /** Invoice summary / totals. */
29537
- resumenFactura: ResumenFacturaSchema,
29538
- /** References to other documents. Optional. */
29539
- informacionReferencia: z7.array(InformacionReferenciaSchema).optional(),
29540
- /** Additional content. Optional. */
29541
- otros: z7.array(OtroContenidoSchema).optional()
29542
- });
29543
- var EnvironmentSchema = z8.enum([Environment.SANDBOX, Environment.PRODUCTION]);
29544
- var CredentialConfigSchema = z8.object({
29545
- /** Full username. */
29546
- username: z8.string().min(1).email().or(z8.string().min(1)),
29547
- /** Path to the .p12 certificate file. */
29548
- p12Path: z8.string().min(1)
29549
- });
29550
- var AppConfigSchema = z8.object({
29551
- /** Active environment. */
29552
- environment: EnvironmentSchema,
29553
- /** Per-environment credential configuration. */
29554
- credentials: z8.object({
29555
- [Environment.SANDBOX]: CredentialConfigSchema.optional(),
29556
- [Environment.PRODUCTION]: CredentialConfigSchema.optional()
29557
- }).optional()
29558
- });
29559
-
29560
30048
  // ../sdk/dist/index.js
29561
30049
  var import_node_forge = __toESM(require_lib(), 1);
29562
30050
  var import_xmldom = __toESM(require_lib2(), 1);
@@ -59136,15 +59624,15 @@ function loadCredentials(input) {
59136
59624
  }
59137
59625
  var SANDBOX_CONFIG = Object.freeze({
59138
59626
  name: "Sandbox",
59139
- apiBaseUrl: "https://api.comprobanteselectronicos.go.cr/recepcion-sandbox/v1",
59140
- idpTokenUrl: "https://idp.comprobanteselectronicos.go.cr/auth/realms/rut-stag/protocol/openid-connect/token",
59141
- clientId: "api-stag"
59627
+ apiBaseUrl: API_BASE_URLS.sandbox,
59628
+ idpTokenUrl: IDP_TOKEN_URLS.sandbox,
59629
+ clientId: CLIENT_IDS.sandbox
59142
59630
  });
59143
59631
  var PRODUCTION_CONFIG = Object.freeze({
59144
59632
  name: "Production",
59145
- apiBaseUrl: "https://api.comprobanteselectronicos.go.cr/recepcion/v1",
59146
- idpTokenUrl: "https://idp.comprobanteselectronicos.go.cr/auth/realms/rut/protocol/openid-connect/token",
59147
- clientId: "api-prod"
59633
+ apiBaseUrl: API_BASE_URLS.production,
59634
+ idpTokenUrl: IDP_TOKEN_URLS.production,
59635
+ clientId: CLIENT_IDS.production
59148
59636
  });
59149
59637
  var ENVIRONMENT_CONFIGS = Object.freeze({
59150
59638
  [
@@ -59354,31 +59842,15 @@ var TokenManager = class {
59354
59842
  }
59355
59843
  };
59356
59844
  var COUNTRY_CODE = "506";
59357
- var DocumentType = /* @__PURE__ */ ((DocumentType2) => {
59358
- DocumentType2["FACTURA_ELECTRONICA"] = "01";
59359
- DocumentType2["NOTA_DEBITO"] = "02";
59360
- DocumentType2["NOTA_CREDITO"] = "03";
59361
- DocumentType2["TIQUETE_ELECTRONICO"] = "04";
59362
- DocumentType2["CONFIRMACION_ACEPTACION"] = "05";
59363
- DocumentType2["CONFIRMACION_ACEPTACION_PARCIAL"] = "06";
59364
- DocumentType2["CONFIRMACION_RECHAZO"] = "07";
59365
- DocumentType2["FACTURA_COMPRA"] = "08";
59366
- DocumentType2["FACTURA_EXPORTACION"] = "09";
59367
- return DocumentType2;
59368
- })(DocumentType || {});
59369
- var Situation = /* @__PURE__ */ ((Situation2) => {
59370
- Situation2["NORMAL"] = "1";
59371
- Situation2["CONTINGENCIA"] = "2";
59372
- Situation2["SIN_INTERNET"] = "3";
59373
- return Situation2;
59374
- })(Situation || {});
59845
+ var DocumentType = DocumentTypeCode;
59846
+ var Situation = SituationCode;
59375
59847
  var CLAVE_LENGTH = 50;
59376
59848
  var VALID_DOCUMENT_TYPES = new Set(Object.values(DocumentType));
59377
59849
  var VALID_SITUATIONS = new Set(Object.values(Situation));
59378
59850
  var ClaveInputSchema2 = z22.object({
59379
59851
  date: z22.date({ message: "date must be a valid Date object" }),
59380
- taxpayerId: z22.string({ message: "taxpayerId must be a string" }).regex(/^\d{1,12}$/, {
59381
- message: "taxpayerId must be a numeric string between 1 and 12 digits long"
59852
+ taxpayerId: z22.string({ message: "taxpayerId must be a string" }).regex(/^[A-Za-z0-9]{1,12}$/, {
59853
+ message: "taxpayerId must be an alphanumeric string between 1 and 12 characters long"
59382
59854
  }),
59383
59855
  branch: z22.string().regex(/^\d{1,3}$/, {
59384
59856
  message: "branch must be a numeric string between 1 and 3 digits long"
@@ -59460,8 +59932,10 @@ function parseClave(clave) {
59460
59932
  if (clave.length !== 50) {
59461
59933
  throw new Error(`Clave must be exactly 50 characters, got ${clave.length}`);
59462
59934
  }
59463
- if (!/^\d{50}$/.test(clave)) {
59464
- throw new Error("Clave must contain only digits (0-9)");
59935
+ if (!/^\d{9}[A-Za-z0-9]{12}\d{29}$/.test(clave)) {
59936
+ throw new Error(
59937
+ "Clave must be numeric except for the taxpayer-ID segment (positions 10-21), which may be alphanumeric"
59938
+ );
59465
59939
  }
59466
59940
  const countryCode = clave.slice(0, 3);
59467
59941
  const dateRaw = clave.slice(3, 9);
@@ -60018,14 +60492,14 @@ async function getNextSequence(docType, branch = DEFAULT_BRANCH, pos = DEFAULT_P
60018
60492
  var HACIENDA_NAMESPACE_BASE = "https://cdn.comprobanteselectronicos.go.cr/xml-schemas/v4.4";
60019
60493
  var XSI_NAMESPACE = "http://www.w3.org/2001/XMLSchema-instance";
60020
60494
  var SCHEMA_FRAGMENTS = {
60021
- FacturaElectronica: "FacturaElectronica",
60022
- NotaCreditoElectronica: "NotaCreditoElectronica",
60023
- NotaDebitoElectronica: "NotaDebitoElectronica",
60024
- TiqueteElectronico: "TiqueteElectronico",
60025
- FacturaElectronicaCompra: "FacturaElectronicaCompra",
60026
- FacturaElectronicaExportacion: "FacturaElectronicaExportacion",
60027
- ReciboElectronicoPago: "ReciboElectronicoPago",
60028
- MensajeReceptor: "MensajeReceptor"
60495
+ FacturaElectronica: "facturaElectronica",
60496
+ NotaCreditoElectronica: "notaCreditoElectronica",
60497
+ NotaDebitoElectronica: "notaDebitoElectronica",
60498
+ TiqueteElectronico: "tiqueteElectronico",
60499
+ FacturaElectronicaCompra: "facturaElectronicaCompra",
60500
+ FacturaElectronicaExportacion: "facturaElectronicaExportacion",
60501
+ ReciboElectronicoPago: "reciboElectronicoPago",
60502
+ MensajeReceptor: "mensajeReceptor"
60029
60503
  };
60030
60504
  function getNamespaceUri(schemaName) {
60031
60505
  return `${HACIENDA_NAMESPACE_BASE}/${schemaName}`;
@@ -60053,7 +60527,7 @@ function buildXml(rootName, data, options) {
60053
60527
  "@_xmlns:xsi": XSI_NAMESPACE
60054
60528
  };
60055
60529
  if (includeSchemaLocation) {
60056
- rootAttributes["@_xsi:schemaLocation"] = `${namespace} ${schemaFragment}_V.4.4.xsd`;
60530
+ rootAttributes["@_xsi:schemaLocation"] = `${namespace} ${rootName}_V4.4.xsd`;
60057
60531
  }
60058
60532
  const xmlObject = {
60059
60533
  "?xml": {
@@ -60085,36 +60559,38 @@ function calculateLineItemTotals(item) {
60085
60559
  const baseImponible = subTotal;
60086
60560
  const calculatedTaxes = [];
60087
60561
  let impuestoNeto = 0;
60088
- if (item.impuesto && item.impuesto.length > 0) {
60089
- for (const tax of item.impuesto) {
60090
- const fullTaxAmount = round5(subTotal * tax.tarifa / 100);
60091
- let taxAmount = fullTaxAmount;
60092
- let exoneracion;
60093
- if (tax.exoneracion) {
60094
- const exonerationPortion = round5(
60095
- fullTaxAmount * tax.exoneracion.porcentajeExoneracion / 100
60562
+ const taxInputs = item.impuesto && item.impuesto.length > 0 ? item.impuesto : [{ codigo: TaxCode.IVA, codigoTarifaIVA: "01", tarifa: 0 }];
60563
+ for (const tax of taxInputs) {
60564
+ const fullTaxAmount = round5(subTotal * tax.tarifa / 100);
60565
+ let taxAmount = fullTaxAmount;
60566
+ let exoneracion;
60567
+ if (tax.exoneracion) {
60568
+ if (typeof tax.exoneracion.tarifaExonerada !== "number") {
60569
+ throw new TypeError(
60570
+ "exoneracion.tarifaExonerada must be a number (v4.4). The v4.3 field porcentajeExoneracion was replaced by tarifaExonerada (exonerated tariff percentage points, 0..tarifa)."
60096
60571
  );
60097
- taxAmount = round5(fullTaxAmount - exonerationPortion);
60098
- exoneracion = {
60099
- tipoDocumento: tax.exoneracion.tipoDocumento,
60100
- numeroDocumento: tax.exoneracion.numeroDocumento,
60101
- nombreInstitucion: tax.exoneracion.nombreInstitucion,
60102
- fechaEmision: tax.exoneracion.fechaEmision,
60103
- porcentajeExoneracion: tax.exoneracion.porcentajeExoneracion,
60104
- montoExoneracion: exonerationPortion
60105
- };
60106
60572
  }
60107
- const calculatedTax = {
60108
- codigo: tax.codigo,
60109
- tarifa: tax.tarifa,
60110
- monto: fullTaxAmount,
60111
- ...tax.codigoTarifa ? { codigoTarifa: tax.codigoTarifa } : {},
60112
- ...exoneracion ? { exoneracion } : {}
60573
+ const exonerationPortion = round5(subTotal * tax.exoneracion.tarifaExonerada / 100);
60574
+ taxAmount = round5(Math.max(0, fullTaxAmount - exonerationPortion));
60575
+ exoneracion = {
60576
+ tipoDocumento: tax.exoneracion.tipoDocumento,
60577
+ numeroDocumento: tax.exoneracion.numeroDocumento,
60578
+ nombreInstitucion: tax.exoneracion.nombreInstitucion,
60579
+ fechaEmision: tax.exoneracion.fechaEmision,
60580
+ tarifaExonerada: tax.exoneracion.tarifaExonerada,
60581
+ montoExoneracion: exonerationPortion
60113
60582
  };
60114
- calculatedTaxes.push(calculatedTax);
60115
- if (IVA_TAX_CODES.includes(tax.codigo)) {
60116
- impuestoNeto = round5(impuestoNeto + taxAmount);
60117
- }
60583
+ }
60584
+ const calculatedTax = {
60585
+ codigo: tax.codigo,
60586
+ tarifa: tax.tarifa,
60587
+ monto: fullTaxAmount,
60588
+ ...tax.codigoTarifaIVA ? { codigoTarifaIVA: tax.codigoTarifaIVA } : {},
60589
+ ...exoneracion ? { exoneracion } : {}
60590
+ };
60591
+ calculatedTaxes.push(calculatedTax);
60592
+ if (IVA_TAX_CODES.includes(tax.codigo)) {
60593
+ impuestoNeto = round5(impuestoNeto + taxAmount);
60118
60594
  }
60119
60595
  }
60120
60596
  impuestoNeto = round5(impuestoNeto);
@@ -60128,6 +60604,7 @@ function calculateLineItemTotals(item) {
60128
60604
  precioUnitario: item.precioUnitario,
60129
60605
  montoTotal,
60130
60606
  subTotal,
60607
+ impuesto: calculatedTaxes,
60131
60608
  montoTotalLinea,
60132
60609
  esServicio: item.esServicio ?? false
60133
60610
  };
@@ -60137,11 +60614,9 @@ function calculateLineItemTotals(item) {
60137
60614
  if (item.descuento && item.descuento.length > 0) {
60138
60615
  result.descuento = item.descuento;
60139
60616
  }
60140
- if (calculatedTaxes.length > 0) {
60141
- result.impuesto = calculatedTaxes;
60142
- result.baseImponible = baseImponible;
60143
- result.impuestoNeto = impuestoNeto;
60144
- }
60617
+ result.impuesto = calculatedTaxes;
60618
+ result.baseImponible = baseImponible;
60619
+ result.impuestoNeto = impuestoNeto;
60145
60620
  return result;
60146
60621
  }
60147
60622
  function classifyLineItem(item) {
@@ -60157,9 +60632,9 @@ function classifyLineItem(item) {
60157
60632
  if (hasExoneration) {
60158
60633
  let totalExonerado = 0;
60159
60634
  for (const tax of item.impuesto) {
60160
- if (tax.exoneracion) {
60635
+ if (tax.exoneracion && tax.tarifa !== void 0 && tax.tarifa > 0) {
60161
60636
  totalExonerado = round5(
60162
- totalExonerado + subTotal * tax.exoneracion.porcentajeExoneracion / 100
60637
+ totalExonerado + subTotal * tax.exoneracion.tarifaExonerada / tax.tarifa
60163
60638
  );
60164
60639
  }
60165
60640
  }
@@ -60204,6 +60679,23 @@ function calculateInvoiceSummary(items, otrosCargos) {
60204
60679
  totalImpuesto = round5(totalImpuesto + item.impuestoNeto);
60205
60680
  }
60206
60681
  }
60682
+ const desglose = /* @__PURE__ */ new Map();
60683
+ for (const item of items) {
60684
+ for (const tax of item.impuesto) {
60685
+ const netAmount = round5(Math.max(0, tax.monto - (tax.exoneracion?.montoExoneracion ?? 0)));
60686
+ const key = `${tax.codigo}|${tax.codigoTarifaIVA ?? ""}`;
60687
+ const existing = desglose.get(key);
60688
+ if (existing) {
60689
+ existing.totalMontoImpuesto = round5(existing.totalMontoImpuesto + netAmount);
60690
+ } else {
60691
+ desglose.set(key, {
60692
+ codigo: tax.codigo,
60693
+ ...tax.codigoTarifaIVA ? { codigoTarifaIVA: tax.codigoTarifaIVA } : {},
60694
+ totalMontoImpuesto: netAmount
60695
+ });
60696
+ }
60697
+ }
60698
+ }
60207
60699
  const totalGravado = round5(totalServGravados + totalMercanciasGravadas);
60208
60700
  const totalExento = round5(totalServExentos + totalMercanciasExentas);
60209
60701
  const totalExonerado = round5(totalServExonerado + totalMercExonerada);
@@ -60224,6 +60716,7 @@ function calculateInvoiceSummary(items, otrosCargos) {
60224
60716
  totalVenta,
60225
60717
  totalDescuentos,
60226
60718
  totalVentaNeta,
60719
+ totalDesgloseImpuesto: [...desglose.values()],
60227
60720
  totalImpuesto,
60228
60721
  totalComprobante
60229
60722
  };
@@ -60233,77 +60726,154 @@ var IVA_TAX_CODES2 = [
60233
60726
  TaxCode.IVA_CALCULO_ESPECIAL,
60234
60727
  TaxCode.IVA_BIENES_USADOS
60235
60728
  ];
60236
- function buildEmisorXml(emisor) {
60729
+ var DOCUMENT_VARIANTS = {
60730
+ FacturaElectronica: {
60731
+ codigoActividadEmisor: "required",
60732
+ codigoActividadReceptor: true,
60733
+ lineaConCabys: true,
60734
+ lineaConBaseImponible: true,
60735
+ lineaConImpuestoNeto: true,
60736
+ lineaConImpuestoAsumido: "required",
60737
+ lineaConPartidaArancelaria: false,
60738
+ lineaCompleta: true,
60739
+ cuerpoCompleto: true
60740
+ },
60741
+ TiqueteElectronico: {
60742
+ codigoActividadEmisor: "required",
60743
+ codigoActividadReceptor: false,
60744
+ lineaConCabys: true,
60745
+ lineaConBaseImponible: true,
60746
+ lineaConImpuestoNeto: true,
60747
+ lineaConImpuestoAsumido: "required",
60748
+ lineaConPartidaArancelaria: false,
60749
+ lineaCompleta: true,
60750
+ cuerpoCompleto: true
60751
+ },
60752
+ NotaCreditoElectronica: {
60753
+ codigoActividadEmisor: "optional",
60754
+ codigoActividadReceptor: true,
60755
+ lineaConCabys: true,
60756
+ lineaConBaseImponible: true,
60757
+ lineaConImpuestoNeto: true,
60758
+ lineaConImpuestoAsumido: "optional",
60759
+ lineaConPartidaArancelaria: true,
60760
+ lineaCompleta: true,
60761
+ cuerpoCompleto: true
60762
+ },
60763
+ NotaDebitoElectronica: {
60764
+ codigoActividadEmisor: "optional",
60765
+ codigoActividadReceptor: true,
60766
+ lineaConCabys: true,
60767
+ lineaConBaseImponible: true,
60768
+ lineaConImpuestoNeto: true,
60769
+ lineaConImpuestoAsumido: "optional",
60770
+ lineaConPartidaArancelaria: true,
60771
+ lineaCompleta: true,
60772
+ cuerpoCompleto: true
60773
+ },
60774
+ FacturaElectronicaCompra: {
60775
+ codigoActividadEmisor: "optional",
60776
+ codigoActividadReceptor: true,
60777
+ lineaConCabys: true,
60778
+ lineaConBaseImponible: true,
60779
+ lineaConImpuestoNeto: true,
60780
+ lineaConImpuestoAsumido: "optional",
60781
+ lineaConPartidaArancelaria: false,
60782
+ lineaCompleta: true,
60783
+ cuerpoCompleto: true
60784
+ },
60785
+ FacturaElectronicaExportacion: {
60786
+ codigoActividadEmisor: "required",
60787
+ codigoActividadReceptor: false,
60788
+ lineaConCabys: true,
60789
+ lineaConBaseImponible: false,
60790
+ lineaConImpuestoNeto: false,
60791
+ lineaConImpuestoAsumido: "none",
60792
+ lineaConPartidaArancelaria: true,
60793
+ lineaCompleta: true,
60794
+ cuerpoCompleto: true
60795
+ },
60796
+ ReciboElectronicoPago: {
60797
+ codigoActividadEmisor: "none",
60798
+ codigoActividadReceptor: false,
60799
+ lineaConCabys: false,
60800
+ lineaConBaseImponible: false,
60801
+ lineaConImpuestoNeto: true,
60802
+ lineaConImpuestoAsumido: "none",
60803
+ lineaConPartidaArancelaria: false,
60804
+ lineaCompleta: false,
60805
+ cuerpoCompleto: false
60806
+ }
60807
+ };
60808
+ function buildIdentificacionXml(identificacion) {
60809
+ return {
60810
+ Tipo: identificacion.tipo,
60811
+ Numero: identificacion.numero
60812
+ };
60813
+ }
60814
+ function buildEmisorXml(emisor, minimal = false) {
60237
60815
  const result = {
60238
60816
  Nombre: emisor.nombre,
60239
- Identificacion: {
60240
- Tipo: emisor.identificacion.tipo,
60241
- Numero: emisor.identificacion.numero
60242
- }
60817
+ Identificacion: buildIdentificacionXml(emisor.identificacion)
60243
60818
  };
60244
- if (emisor.nombreComercial) {
60245
- result.NombreComercial = emisor.nombreComercial;
60246
- }
60247
- if (emisor.ubicacion) {
60819
+ if (!minimal) {
60820
+ if (emisor.registrofiscal8707) {
60821
+ result.Registrofiscal8707 = emisor.registrofiscal8707;
60822
+ }
60823
+ if (emisor.nombreComercial) {
60824
+ result.NombreComercial = emisor.nombreComercial;
60825
+ }
60826
+ if (!emisor.ubicacion) {
60827
+ throw new Error(
60828
+ "emisor.ubicacion is required by the v4.4 schemas (provincia, canton, distrito, otrasSenas)"
60829
+ );
60830
+ }
60248
60831
  result.Ubicacion = {
60249
60832
  Provincia: emisor.ubicacion.provincia,
60250
60833
  Canton: emisor.ubicacion.canton,
60251
60834
  Distrito: emisor.ubicacion.distrito,
60252
60835
  ...emisor.ubicacion.barrio ? { Barrio: emisor.ubicacion.barrio } : {},
60253
- ...emisor.ubicacion.otrasSenas ? { OtrasSenas: emisor.ubicacion.otrasSenas } : {}
60254
- };
60255
- }
60256
- if (emisor.telefono) {
60257
- result.Telefono = {
60258
- CodigoPais: emisor.telefono.codigoPais,
60259
- NumTelefono: emisor.telefono.numTelefono
60260
- };
60261
- }
60262
- if (emisor.fax) {
60263
- result.Fax = {
60264
- CodigoPais: emisor.fax.codigoPais,
60265
- NumTelefono: emisor.fax.numTelefono
60836
+ OtrasSenas: emisor.ubicacion.otrasSenas
60266
60837
  };
60838
+ if (emisor.telefono) {
60839
+ result.Telefono = {
60840
+ CodigoPais: emisor.telefono.codigoPais,
60841
+ NumTelefono: emisor.telefono.numTelefono
60842
+ };
60843
+ }
60267
60844
  }
60268
60845
  result.CorreoElectronico = emisor.correoElectronico;
60269
60846
  return result;
60270
60847
  }
60271
- function buildReceptorXml(receptor) {
60848
+ function buildReceptorXml(receptor, minimal = false) {
60272
60849
  const result = {
60273
60850
  Nombre: receptor.nombre
60274
60851
  };
60275
60852
  if (receptor.identificacion) {
60276
- result.Identificacion = {
60277
- Tipo: receptor.identificacion.tipo,
60278
- Numero: receptor.identificacion.numero
60279
- };
60280
- }
60281
- if (receptor.identificacionExtranjero) {
60282
- result.IdentificacionExtranjero = receptor.identificacionExtranjero;
60283
- }
60284
- if (receptor.nombreComercial) {
60285
- result.NombreComercial = receptor.nombreComercial;
60853
+ result.Identificacion = buildIdentificacionXml(receptor.identificacion);
60286
60854
  }
60287
- if (receptor.ubicacion) {
60288
- result.Ubicacion = {
60289
- Provincia: receptor.ubicacion.provincia,
60290
- Canton: receptor.ubicacion.canton,
60291
- Distrito: receptor.ubicacion.distrito,
60292
- ...receptor.ubicacion.barrio ? { Barrio: receptor.ubicacion.barrio } : {},
60293
- ...receptor.ubicacion.otrasSenas ? { OtrasSenas: receptor.ubicacion.otrasSenas } : {}
60294
- };
60295
- }
60296
- if (receptor.telefono) {
60297
- result.Telefono = {
60298
- CodigoPais: receptor.telefono.codigoPais,
60299
- NumTelefono: receptor.telefono.numTelefono
60300
- };
60301
- }
60302
- if (receptor.fax) {
60303
- result.Fax = {
60304
- CodigoPais: receptor.fax.codigoPais,
60305
- NumTelefono: receptor.fax.numTelefono
60306
- };
60855
+ if (!minimal) {
60856
+ if (receptor.nombreComercial) {
60857
+ result.NombreComercial = receptor.nombreComercial;
60858
+ }
60859
+ if (receptor.ubicacion) {
60860
+ result.Ubicacion = {
60861
+ Provincia: receptor.ubicacion.provincia,
60862
+ Canton: receptor.ubicacion.canton,
60863
+ Distrito: receptor.ubicacion.distrito,
60864
+ ...receptor.ubicacion.barrio ? { Barrio: receptor.ubicacion.barrio } : {},
60865
+ OtrasSenas: receptor.ubicacion.otrasSenas
60866
+ };
60867
+ }
60868
+ if (receptor.otrasSenasExtranjero) {
60869
+ result.OtrasSenasExtranjero = receptor.otrasSenasExtranjero;
60870
+ }
60871
+ if (receptor.telefono) {
60872
+ result.Telefono = {
60873
+ CodigoPais: receptor.telefono.codigoPais,
60874
+ NumTelefono: receptor.telefono.numTelefono
60875
+ };
60876
+ }
60307
60877
  }
60308
60878
  if (receptor.correoElectronico) {
60309
60879
  result.CorreoElectronico = receptor.correoElectronico;
@@ -60314,19 +60884,32 @@ function buildImpuestoXml(impuesto) {
60314
60884
  const result = {
60315
60885
  Codigo: impuesto.codigo
60316
60886
  };
60317
- if (impuesto.codigoTarifa) {
60318
- result.CodigoTarifa = impuesto.codigoTarifa;
60887
+ if (impuesto.codigoImpuestoOtros) {
60888
+ result.CodigoImpuestoOTRO = impuesto.codigoImpuestoOtros;
60889
+ }
60890
+ if (impuesto.codigoTarifaIVA) {
60891
+ result.CodigoTarifaIVA = impuesto.codigoTarifaIVA;
60892
+ }
60893
+ if (impuesto.tarifa !== void 0) {
60894
+ result.Tarifa = impuesto.tarifa;
60895
+ }
60896
+ if (impuesto.factorCalculoIVA !== void 0) {
60897
+ result.FactorCalculoIVA = impuesto.factorCalculoIVA;
60319
60898
  }
60320
- result.Tarifa = impuesto.tarifa;
60321
60899
  result.Monto = impuesto.monto;
60322
60900
  if (impuesto.exoneracion) {
60901
+ const exo = impuesto.exoneracion;
60323
60902
  result.Exoneracion = {
60324
- TipoDocumento: impuesto.exoneracion.tipoDocumento,
60325
- NumeroDocumento: impuesto.exoneracion.numeroDocumento,
60326
- NombreInstitucion: impuesto.exoneracion.nombreInstitucion,
60327
- FechaEmision: impuesto.exoneracion.fechaEmision,
60328
- PorcentajeExoneracion: impuesto.exoneracion.porcentajeExoneracion,
60329
- MontoExoneracion: impuesto.exoneracion.montoExoneracion
60903
+ TipoDocumentoEX1: exo.tipoDocumento,
60904
+ ...exo.tipoDocumentoOtros ? { TipoDocumentoOTRO: exo.tipoDocumentoOtros } : {},
60905
+ NumeroDocumento: exo.numeroDocumento,
60906
+ ...exo.articulo !== void 0 ? { Articulo: exo.articulo } : {},
60907
+ ...exo.inciso !== void 0 ? { Inciso: exo.inciso } : {},
60908
+ NombreInstitucion: exo.nombreInstitucion,
60909
+ ...exo.nombreInstitucionOtros ? { NombreInstitucionOtros: exo.nombreInstitucionOtros } : {},
60910
+ FechaEmisionEX: exo.fechaEmision,
60911
+ TarifaExonerada: exo.tarifaExonerada,
60912
+ MontoExoneracion: exo.montoExoneracion
60330
60913
  };
60331
60914
  }
60332
60915
  return result;
@@ -60334,96 +60917,134 @@ function buildImpuestoXml(impuesto) {
60334
60917
  function buildDescuentoXml(descuento) {
60335
60918
  return {
60336
60919
  MontoDescuento: descuento.montoDescuento,
60337
- NaturalezaDescuento: descuento.naturalezaDescuento
60920
+ CodigoDescuento: descuento.codigoDescuento,
60921
+ ...descuento.codigoDescuentoOtros ? { CodigoDescuentoOTRO: descuento.codigoDescuentoOtros } : {},
60922
+ ...descuento.naturalezaDescuento ? { NaturalezaDescuento: descuento.naturalezaDescuento } : {}
60338
60923
  };
60339
60924
  }
60340
- function buildLineaDetalleXml(linea) {
60925
+ function buildLineaDetalleXml(linea, variant = DOCUMENT_VARIANTS.FacturaElectronica) {
60341
60926
  const result = {
60342
- NumeroLinea: linea.numeroLinea,
60343
- Codigo: linea.codigoCabys
60927
+ NumeroLinea: linea.numeroLinea
60344
60928
  };
60345
- if (linea.codigoComercial && linea.codigoComercial.length > 0) {
60346
- result.CodigoComercial = linea.codigoComercial.map((c) => ({
60347
- Tipo: c.tipo,
60348
- Codigo: c.codigo
60349
- }));
60929
+ if (variant.lineaConPartidaArancelaria && linea.partidaArancelaria) {
60930
+ result.PartidaArancelaria = linea.partidaArancelaria;
60931
+ }
60932
+ if (variant.lineaConCabys) {
60933
+ result.CodigoCABYS = linea.codigoCabys;
60934
+ }
60935
+ if (variant.lineaCompleta) {
60936
+ if (linea.codigoComercial && linea.codigoComercial.length > 0) {
60937
+ result.CodigoComercial = linea.codigoComercial.map((c) => ({
60938
+ Tipo: c.tipo,
60939
+ Codigo: c.codigo
60940
+ }));
60941
+ }
60942
+ result.Cantidad = linea.cantidad;
60943
+ result.UnidadMedida = linea.unidadMedida;
60944
+ if (linea.tipoTransaccion) {
60945
+ result.TipoTransaccion = linea.tipoTransaccion;
60946
+ }
60947
+ if (linea.unidadMedidaComercial) {
60948
+ result.UnidadMedidaComercial = linea.unidadMedidaComercial;
60949
+ }
60350
60950
  }
60351
- result.Cantidad = linea.cantidad;
60352
- result.UnidadMedida = linea.unidadMedida;
60353
60951
  result.Detalle = linea.detalle;
60354
- result.PrecioUnitario = linea.precioUnitario;
60952
+ if (variant.lineaCompleta) {
60953
+ if (linea.numeroVINoSerie && linea.numeroVINoSerie.length > 0) {
60954
+ result.NumeroVINoSerie = linea.numeroVINoSerie;
60955
+ }
60956
+ result.PrecioUnitario = linea.precioUnitario;
60957
+ }
60355
60958
  result.MontoTotal = linea.montoTotal;
60356
- if (linea.descuento && linea.descuento.length > 0) {
60959
+ if (variant.lineaCompleta && linea.descuento && linea.descuento.length > 0) {
60357
60960
  result.Descuento = linea.descuento.map((d) => buildDescuentoXml(d));
60358
60961
  }
60359
60962
  result.SubTotal = linea.subTotal;
60360
- if (linea.baseImponible !== void 0) {
60361
- result.BaseImponible = linea.baseImponible;
60963
+ if (variant.lineaConBaseImponible) {
60964
+ result.BaseImponible = linea.baseImponible ?? linea.subTotal;
60362
60965
  }
60363
60966
  if (linea.impuesto && linea.impuesto.length > 0) {
60364
60967
  result.Impuesto = linea.impuesto.map((t) => buildImpuestoXml(t));
60365
60968
  }
60366
- if (linea.impuestoNeto !== void 0) {
60367
- result.ImpuestoNeto = linea.impuestoNeto;
60969
+ if (variant.lineaConImpuestoAsumido === "required") {
60970
+ result.ImpuestoAsumidoEmisorFabrica = linea.impuestoAsumidoEmisorFabrica ?? 0;
60971
+ } else if (variant.lineaConImpuestoAsumido === "optional" && linea.impuestoAsumidoEmisorFabrica !== void 0) {
60972
+ result.ImpuestoAsumidoEmisorFabrica = linea.impuestoAsumidoEmisorFabrica;
60973
+ }
60974
+ if (variant.lineaConImpuestoNeto) {
60975
+ result.ImpuestoNeto = linea.impuestoNeto ?? 0;
60368
60976
  }
60369
60977
  result.MontoTotalLinea = linea.montoTotalLinea;
60370
60978
  return result;
60371
60979
  }
60372
60980
  function buildResumenFacturaXml(resumen) {
60373
- const result = {};
60374
- if (resumen.codigoTipoMoneda) {
60375
- result.CodigoTipoMoneda = {
60376
- CodigoMoneda: resumen.codigoTipoMoneda.codigoMoneda,
60377
- TipoCambio: resumen.codigoTipoMoneda.tipoCambio
60378
- };
60379
- }
60380
- result.TotalServGravados = resumen.totalServGravados;
60381
- result.TotalServExentos = resumen.totalServExentos;
60382
- if (resumen.totalServExonerado !== void 0 && resumen.totalServExonerado > 0) {
60383
- result.TotalServExonerado = resumen.totalServExonerado;
60384
- }
60385
- result.TotalMercanciasGravadas = resumen.totalMercanciasGravadas;
60386
- result.TotalMercanciasExentas = resumen.totalMercanciasExentas;
60387
- if (resumen.totalMercExonerada !== void 0 && resumen.totalMercExonerada > 0) {
60388
- result.TotalMercExonerada = resumen.totalMercExonerada;
60389
- }
60390
- result.TotalGravado = resumen.totalGravado;
60391
- result.TotalExento = resumen.totalExento;
60392
- if (resumen.totalExonerado !== void 0 && resumen.totalExonerado > 0) {
60393
- result.TotalExonerado = resumen.totalExonerado;
60394
- }
60981
+ const result = {
60982
+ CodigoTipoMoneda: {
60983
+ CodigoMoneda: resumen.codigoTipoMoneda?.codigoMoneda ?? "CRC",
60984
+ TipoCambio: resumen.codigoTipoMoneda?.tipoCambio ?? 1
60985
+ }
60986
+ };
60987
+ const optionalTotal = (key, value) => {
60988
+ if (value !== void 0) {
60989
+ result[key] = value;
60990
+ }
60991
+ };
60992
+ optionalTotal("TotalServGravados", resumen.totalServGravados);
60993
+ optionalTotal("TotalServExentos", resumen.totalServExentos);
60994
+ optionalTotal("TotalServExonerado", resumen.totalServExonerado);
60995
+ optionalTotal("TotalServNoSujeto", resumen.totalServNoSujeto);
60996
+ optionalTotal("TotalMercanciasGravadas", resumen.totalMercanciasGravadas);
60997
+ optionalTotal("TotalMercanciasExentas", resumen.totalMercanciasExentas);
60998
+ optionalTotal("TotalMercExonerada", resumen.totalMercExonerada);
60999
+ optionalTotal("TotalMercNoSujeta", resumen.totalMercNoSujeta);
61000
+ optionalTotal("TotalGravado", resumen.totalGravado);
61001
+ optionalTotal("TotalExento", resumen.totalExento);
61002
+ optionalTotal("TotalExonerado", resumen.totalExonerado);
61003
+ optionalTotal("TotalNoSujeto", resumen.totalNoSujeto);
60395
61004
  result.TotalVenta = resumen.totalVenta;
60396
- result.TotalDescuentos = resumen.totalDescuentos;
61005
+ optionalTotal("TotalDescuentos", resumen.totalDescuentos);
60397
61006
  result.TotalVentaNeta = resumen.totalVentaNeta;
60398
- result.TotalImpuesto = resumen.totalImpuesto;
60399
- if (resumen.totalIVADevuelto !== void 0 && resumen.totalIVADevuelto > 0) {
60400
- result.TotalIVADevuelto = resumen.totalIVADevuelto;
61007
+ if (resumen.totalDesgloseImpuesto && resumen.totalDesgloseImpuesto.length > 0) {
61008
+ result.TotalDesgloseImpuesto = resumen.totalDesgloseImpuesto.map((d) => ({
61009
+ Codigo: d.codigo,
61010
+ ...d.codigoTarifaIVA ? { CodigoTarifaIVA: d.codigoTarifaIVA } : {},
61011
+ TotalMontoImpuesto: d.totalMontoImpuesto
61012
+ }));
60401
61013
  }
60402
- if (resumen.totalOtrosCargos !== void 0 && resumen.totalOtrosCargos > 0) {
60403
- result.TotalOtrosCargos = resumen.totalOtrosCargos;
61014
+ optionalTotal("TotalImpuesto", resumen.totalImpuesto);
61015
+ optionalTotal("TotalImpAsumEmisorFabrica", resumen.totalImpAsumEmisorFabrica);
61016
+ optionalTotal("TotalIVADevuelto", resumen.totalIVADevuelto);
61017
+ optionalTotal("TotalOtrosCargos", resumen.totalOtrosCargos);
61018
+ if (resumen.medioPago && resumen.medioPago.length > 0) {
61019
+ result.MedioPago = resumen.medioPago.map((m) => ({
61020
+ TipoMedioPago: m.tipoMedioPago,
61021
+ ...m.medioPagoOtros ? { MedioPagoOtros: m.medioPagoOtros } : {},
61022
+ TotalMedioPago: m.totalMedioPago
61023
+ }));
60404
61024
  }
60405
61025
  result.TotalComprobante = resumen.totalComprobante;
60406
61026
  return result;
60407
61027
  }
60408
61028
  function buildOtrosCargosXml(otrosCargos) {
60409
- return {
60410
- OtroCargo: otrosCargos.map((c) => ({
60411
- TipoDocumento: c.tipoDocumento,
60412
- ...c.numeroIdentidadTercero ? { NumeroIdentidadTercero: c.numeroIdentidadTercero } : {},
60413
- ...c.nombreTercero ? { NombreTercero: c.nombreTercero } : {},
60414
- Detalle: c.detalle,
60415
- ...c.porcentaje !== void 0 ? { Porcentaje: c.porcentaje } : {},
60416
- MontoOtroCargo: c.montoOtroCargo
60417
- }))
60418
- };
61029
+ return otrosCargos.map((c) => ({
61030
+ TipoDocumentoOC: c.tipoDocumento,
61031
+ ...c.tipoDocumentoOtros ? { TipoDocumentoOTROS: c.tipoDocumentoOtros } : {},
61032
+ ...c.identificacionTercero ? { IdentificacionTercero: buildIdentificacionXml(c.identificacionTercero) } : {},
61033
+ ...c.nombreTercero ? { NombreTercero: c.nombreTercero } : {},
61034
+ Detalle: c.detalle,
61035
+ ...c.porcentaje !== void 0 ? { PorcentajeOC: c.porcentaje } : {},
61036
+ MontoCargo: c.montoCargo
61037
+ }));
60419
61038
  }
60420
61039
  function buildInformacionReferenciaXml(refs) {
60421
61040
  return refs.map((ref) => ({
60422
- TipoDoc: ref.tipoDoc,
60423
- Numero: ref.numero,
60424
- FechaEmision: ref.fechaEmision,
60425
- Codigo: ref.codigo,
60426
- Razon: ref.razon
61041
+ TipoDocIR: ref.tipoDoc,
61042
+ ...ref.tipoDocOtros ? { TipoDocRefOTRO: ref.tipoDocOtros } : {},
61043
+ ...ref.numero ? { Numero: ref.numero } : {},
61044
+ FechaEmisionIR: ref.fechaEmision,
61045
+ ...ref.codigo ? { Codigo: ref.codigo } : {},
61046
+ ...ref.codigoOtros ? { CodigoReferenciaOTRO: ref.codigoOtros } : {},
61047
+ ...ref.razon ? { Razon: ref.razon } : {}
60427
61048
  }));
60428
61049
  }
60429
61050
  function buildOtrosXml(otros) {
@@ -60433,39 +61054,66 @@ function buildOtrosXml(otros) {
60433
61054
  }))
60434
61055
  };
60435
61056
  }
60436
- function buildStandardDocumentBody(input) {
61057
+ function buildStandardDocumentBody(input, variant = DOCUMENT_VARIANTS.FacturaElectronica) {
61058
+ const minimalParties = !variant.cuerpoCompleto;
61059
+ const legacy = input;
61060
+ if (legacy.codigoActividad !== void 0) {
61061
+ throw new Error(
61062
+ "codigoActividad was renamed to codigoActividadEmisor in v4.4 (with optional codigoActividadReceptor)"
61063
+ );
61064
+ }
61065
+ if (legacy.medioPago !== void 0) {
61066
+ throw new Error(
61067
+ "medioPago moved into resumenFactura.medioPago in v4.4 (entries of { tipoMedioPago, totalMedioPago })"
61068
+ );
61069
+ }
60437
61070
  const data = {
60438
61071
  Clave: input.clave,
60439
- CodigoActividad: input.codigoActividad,
60440
- NumeroConsecutivo: input.numeroConsecutivo,
60441
- FechaEmision: input.fechaEmision,
60442
- Emisor: buildEmisorXml(input.emisor)
61072
+ ProveedorSistemas: input.proveedorSistemas
60443
61073
  };
61074
+ if (variant.codigoActividadEmisor === "required" && !input.codigoActividadEmisor) {
61075
+ throw new Error("codigoActividadEmisor is required for this document type (v4.4)");
61076
+ }
61077
+ if (variant.codigoActividadEmisor !== "none" && input.codigoActividadEmisor) {
61078
+ data.CodigoActividadEmisor = input.codigoActividadEmisor;
61079
+ }
61080
+ if (variant.codigoActividadReceptor && input.codigoActividadReceptor) {
61081
+ data.CodigoActividadReceptor = input.codigoActividadReceptor;
61082
+ }
61083
+ data.NumeroConsecutivo = input.numeroConsecutivo;
61084
+ data.FechaEmision = input.fechaEmision;
61085
+ data.Emisor = buildEmisorXml(input.emisor, minimalParties);
60444
61086
  if (input.receptor) {
60445
- data.Receptor = buildReceptorXml(input.receptor);
61087
+ data.Receptor = buildReceptorXml(input.receptor, minimalParties);
60446
61088
  }
60447
61089
  data.CondicionVenta = input.condicionVenta;
60448
- if (input.plazoCredito) {
60449
- data.PlazoCredito = input.plazoCredito;
61090
+ if (variant.cuerpoCompleto) {
61091
+ if (input.condicionVentaOtros) {
61092
+ data.CondicionVentaOtros = input.condicionVentaOtros;
61093
+ }
61094
+ if (input.plazoCredito) {
61095
+ data.PlazoCredito = input.plazoCredito;
61096
+ }
60450
61097
  }
60451
- data.MedioPago = input.medioPago;
60452
61098
  data.DetalleServicio = {
60453
- LineaDetalle: input.detalleServicio.map((line) => buildLineaDetalleXml(line))
61099
+ LineaDetalle: input.detalleServicio.map(
61100
+ (line) => buildLineaDetalleXml(line, variant)
61101
+ )
60454
61102
  };
60455
- if (input.otrosCargos && input.otrosCargos.length > 0) {
61103
+ if (variant.cuerpoCompleto && input.otrosCargos && input.otrosCargos.length > 0) {
60456
61104
  data.OtrosCargos = buildOtrosCargosXml(input.otrosCargos);
60457
61105
  }
60458
61106
  data.ResumenFactura = buildResumenFacturaXml(input.resumenFactura);
60459
61107
  if (input.informacionReferencia && input.informacionReferencia.length > 0) {
60460
61108
  data.InformacionReferencia = buildInformacionReferenciaXml(input.informacionReferencia);
60461
61109
  }
60462
- if (input.otros && input.otros.length > 0) {
61110
+ if (variant.cuerpoCompleto && input.otros && input.otros.length > 0) {
60463
61111
  data.Otros = buildOtrosXml(input.otros);
60464
61112
  }
60465
61113
  return data;
60466
61114
  }
60467
61115
  function buildFacturaXml(input) {
60468
- const data = buildStandardDocumentBody(input);
61116
+ const data = buildStandardDocumentBody(input, DOCUMENT_VARIANTS.FacturaElectronica);
60469
61117
  return buildXml("FacturaElectronica", data);
60470
61118
  }
60471
61119
  var LEVEL_NAMES = {
@@ -60682,17 +61330,18 @@ async function lookupTaxpayer(id, options) {
60682
61330
  // src/tools/create-invoice.ts
60683
61331
  var ImpuestoInputSchema = z10.object({
60684
61332
  codigo: z10.string().describe('Tax type code (e.g. "01" for IVA)'),
60685
- codigoTarifa: z10.string().optional().describe('IVA rate code (e.g. "08" for 13%)'),
61333
+ codigoTarifaIVA: z10.string().optional().describe('IVA rate code (e.g. "08" for 13%)'),
60686
61334
  tarifa: z10.number().describe("Tax rate percentage (e.g. 13 for 13%)")
60687
61335
  });
60688
61336
  var DescuentoInputSchema = z10.object({
60689
61337
  montoDescuento: z10.number().positive().describe("Discount amount"),
61338
+ codigoDescuento: z10.string().default("01").describe('Discount code (v4.4 CodigoDescuento). Defaults to "01"'),
60690
61339
  naturalezaDescuento: z10.string().describe("Reason for discount")
60691
61340
  });
60692
61341
  var LineItemInputSchema = z10.object({
60693
61342
  codigoCabys: z10.string().describe("CABYS code (13 digits)"),
60694
61343
  cantidad: z10.number().positive().describe("Quantity"),
60695
- unidadMedida: z10.string().describe('Unit of measure (e.g. "Unid", "Sp", "kg")'),
61344
+ unidadMedida: z10.enum(UNITS_OF_MEASURE).describe('Unit of measure from the official v4.4 catalog (e.g. "Unid", "Sp", "Kg", "h")'),
60696
61345
  detalle: z10.string().describe("Item description (max 200 chars)"),
60697
61346
  precioUnitario: z10.number().min(0).describe("Unit price before taxes"),
60698
61347
  esServicio: z10.boolean().optional().describe("Whether this is a service (true) or merchandise (false). Defaults to false"),
@@ -60703,10 +61352,18 @@ var IdentificacionInputSchema = z10.object({
60703
61352
  tipo: z10.string().describe('ID type: "01"=Fisica, "02"=Juridica, "03"=DIMEX, "04"=NITE'),
60704
61353
  numero: z10.string().describe("ID number (digits only)")
60705
61354
  });
61355
+ var UbicacionInputSchema = z10.object({
61356
+ provincia: z10.string().regex(/^[1-7]$/).describe("Province code (1-7)"),
61357
+ canton: z10.string().regex(/^\d{2}$/).describe("Canton code (2 digits)"),
61358
+ distrito: z10.string().regex(/^\d{2}$/).describe("District code (2 digits)"),
61359
+ barrio: z10.string().min(5).max(50).optional().describe("Barrio name (free text 5-50 chars in v4.4; no longer a 2-digit code)"),
61360
+ otrasSenas: z10.string().min(5).max(250).describe("Address details (5-250 chars, required in v4.4)")
61361
+ });
60706
61362
  var EmisorInputSchema = z10.object({
60707
61363
  nombre: z10.string().describe("Issuer name (max 100 chars)"),
60708
61364
  identificacion: IdentificacionInputSchema.describe("Taxpayer identification"),
60709
61365
  nombreComercial: z10.string().optional().describe("Commercial name"),
61366
+ ubicacion: UbicacionInputSchema.describe("Issuer location (required in v4.4)"),
60710
61367
  correoElectronico: z10.string().describe("Email address")
60711
61368
  });
60712
61369
  var ReceptorInputSchema = z10.object({
@@ -60717,9 +61374,14 @@ var ReceptorInputSchema = z10.object({
60717
61374
  var CreateInvoiceInputSchema = z10.object({
60718
61375
  emisor: EmisorInputSchema.describe("Invoice issuer (emisor)"),
60719
61376
  receptor: ReceptorInputSchema.describe("Invoice receiver (receptor)"),
60720
- codigoActividad: z10.string().describe("CABYS activity code (6 digits)"),
61377
+ proveedorSistemas: z10.string().optional().describe(
61378
+ "Invoicing-system provider ID (ProveedorSistemas, v4.4). Defaults to the emisor's ID number"
61379
+ ),
61380
+ codigoActividadEmisor: z10.string().describe("Issuer economic activity code (6 digits)"),
60721
61381
  condicionVenta: z10.string().default("01").describe('Sale condition code: "01"=Cash, "02"=Credit, etc. Defaults to "01"'),
60722
- medioPago: z10.array(z10.string()).default(["01"]).describe('Payment methods: ["01"]=Cash, ["02"]=Card, etc. Defaults to ["01"]'),
61382
+ medioPago: z10.string().default("01").describe(
61383
+ 'Payment method: "01"=Cash, "02"=Card, "04"=Transfer, "06"=SINPE Movil. Defaults to "01"'
61384
+ ),
60723
61385
  lineItems: z10.array(LineItemInputSchema).min(1).describe("Invoice line items (at least one required)"),
60724
61386
  plazoCredito: z10.string().optional().describe("Credit term in days (required when condicionVenta is 02)")
60725
61387
  });
@@ -60730,7 +61392,8 @@ function registerCreateInvoiceTool(server) {
60730
61392
  {
60731
61393
  emisor: EmisorInputSchema,
60732
61394
  receptor: ReceptorInputSchema,
60733
- codigoActividad: CreateInvoiceInputSchema.shape.codigoActividad,
61395
+ proveedorSistemas: CreateInvoiceInputSchema.shape.proveedorSistemas,
61396
+ codigoActividadEmisor: CreateInvoiceInputSchema.shape.codigoActividadEmisor,
60734
61397
  condicionVenta: CreateInvoiceInputSchema.shape.condicionVenta,
60735
61398
  medioPago: CreateInvoiceInputSchema.shape.medioPago,
60736
61399
  lineItems: CreateInvoiceInputSchema.shape.lineItems,
@@ -60773,7 +61436,8 @@ function registerCreateInvoiceTool(server) {
60773
61436
  }));
60774
61437
  const factura = {
60775
61438
  clave,
60776
- codigoActividad: args.codigoActividad,
61439
+ proveedorSistemas: args.proveedorSistemas ?? args.emisor.identificacion.numero,
61440
+ codigoActividadEmisor: args.codigoActividadEmisor,
60777
61441
  numeroConsecutivo,
60778
61442
  fechaEmision,
60779
61443
  emisor: {
@@ -60783,6 +61447,7 @@ function registerCreateInvoiceTool(server) {
60783
61447
  numero: args.emisor.identificacion.numero
60784
61448
  },
60785
61449
  ...args.emisor.nombreComercial ? { nombreComercial: args.emisor.nombreComercial } : {},
61450
+ ubicacion: args.emisor.ubicacion,
60786
61451
  correoElectronico: args.emisor.correoElectronico
60787
61452
  },
60788
61453
  receptor: {
@@ -60797,7 +61462,6 @@ function registerCreateInvoiceTool(server) {
60797
61462
  },
60798
61463
  condicionVenta: args.condicionVenta,
60799
61464
  ...args.plazoCredito ? { plazoCredito: args.plazoCredito } : {},
60800
- medioPago: args.medioPago,
60801
61465
  detalleServicio,
60802
61466
  resumenFactura: {
60803
61467
  totalServGravados: summary.totalServGravados,
@@ -60812,7 +61476,14 @@ function registerCreateInvoiceTool(server) {
60812
61476
  totalVenta: summary.totalVenta,
60813
61477
  totalDescuentos: summary.totalDescuentos,
60814
61478
  totalVentaNeta: summary.totalVentaNeta,
61479
+ totalDesgloseImpuesto: summary.totalDesgloseImpuesto,
60815
61480
  totalImpuesto: summary.totalImpuesto,
61481
+ medioPago: [
61482
+ {
61483
+ tipoMedioPago: args.medioPago,
61484
+ totalMedioPago: summary.totalComprobante
61485
+ }
61486
+ ],
60816
61487
  totalComprobante: summary.totalComprobante
60817
61488
  }
60818
61489
  };
@@ -61114,7 +61785,7 @@ function registerDraftInvoiceTool(server) {
61114
61785
  receptorIdTipo: z12.string().optional().describe('Receiver ID type (optional): "01"=Fisica, "02"=Juridica, "03"=DIMEX, "04"=NITE'),
61115
61786
  receptorIdNumero: z12.string().optional().describe("Receiver identification number (optional)"),
61116
61787
  receptorEmail: z12.string().optional().describe("Receiver email address (optional)"),
61117
- codigoActividad: z12.string().default("620100").describe("CABYS activity code (6 digits). Defaults to 620100 (IT services)"),
61788
+ codigoActividadEmisor: z12.string().default("620100").describe("Issuer economic activity code (6 digits). Defaults to 620100 (IT services)"),
61118
61789
  description: z12.string().default("Servicio profesional").describe("Default line item description"),
61119
61790
  amount: z12.number().default(0).describe("Default line item amount (price). Set to 0 to leave as placeholder"),
61120
61791
  includeIva: z12.boolean().default(true).describe("Whether to include 13% IVA tax. Defaults to true")
@@ -61128,15 +61799,7 @@ function registerDraftInvoiceTool(server) {
61128
61799
  precioUnitario: args.amount,
61129
61800
  esServicio: true
61130
61801
  };
61131
- if (args.includeIva) {
61132
- lineItem.impuesto = [
61133
- {
61134
- codigo: "01",
61135
- codigoTarifa: "08",
61136
- tarifa: 13
61137
- }
61138
- ];
61139
- }
61802
+ lineItem.impuesto = args.includeIva ? [{ codigo: "01", codigoTarifaIVA: "08", tarifa: 13 }] : [{ codigo: "01", codigoTarifaIVA: "01", tarifa: 0 }];
61140
61803
  const draft = {
61141
61804
  emisor: {
61142
61805
  nombre: args.emisorNombre,
@@ -61144,6 +61807,12 @@ function registerDraftInvoiceTool(server) {
61144
61807
  tipo: args.emisorIdTipo,
61145
61808
  numero: args.emisorIdNumero
61146
61809
  },
61810
+ ubicacion: {
61811
+ provincia: "1",
61812
+ canton: "01",
61813
+ distrito: "01",
61814
+ otrasSenas: "<<COMPLETE_ISSUER_ADDRESS>>"
61815
+ },
61147
61816
  correoElectronico: args.emisorEmail
61148
61817
  },
61149
61818
  receptor: {
@@ -61156,9 +61825,10 @@ function registerDraftInvoiceTool(server) {
61156
61825
  } : {},
61157
61826
  ...args.receptorEmail ? { correoElectronico: args.receptorEmail } : {}
61158
61827
  },
61159
- codigoActividad: args.codigoActividad,
61828
+ proveedorSistemas: args.emisorIdNumero,
61829
+ codigoActividadEmisor: args.codigoActividadEmisor,
61160
61830
  condicionVenta: "01",
61161
- medioPago: ["01"],
61831
+ medioPago: "01",
61162
61832
  lineItems: [lineItem]
61163
61833
  };
61164
61834
  const idTypeName = IDENTIFICATION_TYPE_NAMES[args.emisorIdTipo] ?? args.emisorIdTipo;
@@ -61171,7 +61841,7 @@ function registerDraftInvoiceTool(server) {
61171
61841
  ``,
61172
61842
  `Emisor: ${args.emisorNombre} (${idTypeName}: ${args.emisorIdNumero})`,
61173
61843
  `Receptor: ${args.receptorNombre}`,
61174
- `Activity: ${args.codigoActividad}`,
61844
+ `Activity: ${args.codigoActividadEmisor}`,
61175
61845
  `Sale Condition: Contado (cash)`,
61176
61846
  `Payment: Efectivo (cash)`,
61177
61847
  args.includeIva ? `IVA: 13% included` : `IVA: not included`,
@@ -61208,12 +61878,12 @@ var FACTURA_SCHEMA = {
61208
61878
  title: "Factura Electronica (Costa Rica)",
61209
61879
  description: "Schema for creating a Factura Electronica via the create_invoice tool. This describes the input format accepted by the tool.",
61210
61880
  type: "object",
61211
- required: ["emisor", "receptor", "codigoActividad", "lineItems"],
61881
+ required: ["emisor", "receptor", "codigoActividadEmisor", "lineItems"],
61212
61882
  properties: {
61213
61883
  emisor: {
61214
61884
  type: "object",
61215
61885
  description: "Invoice issuer (emisor) information",
61216
- required: ["nombre", "identificacion", "correoElectronico"],
61886
+ required: ["nombre", "identificacion", "ubicacion", "correoElectronico"],
61217
61887
  properties: {
61218
61888
  nombre: {
61219
61889
  type: "string",
@@ -61226,8 +61896,8 @@ var FACTURA_SCHEMA = {
61226
61896
  properties: {
61227
61897
  tipo: {
61228
61898
  type: "string",
61229
- enum: ["01", "02", "03", "04"],
61230
- description: "01=Cedula Fisica, 02=Cedula Juridica, 03=DIMEX, 04=NITE"
61899
+ enum: ["01", "02", "03", "04", "05", "06"],
61900
+ description: "01=Cedula Fisica, 02=Cedula Juridica, 03=DIMEX, 04=NITE, 05=Extranjero No Domiciliado, 06=No Contribuyente (05/06 new in v4.4)"
61231
61901
  },
61232
61902
  numero: {
61233
61903
  type: "string",
@@ -61241,6 +61911,32 @@ var FACTURA_SCHEMA = {
61241
61911
  maxLength: 80,
61242
61912
  description: "Commercial name (optional)"
61243
61913
  },
61914
+ ubicacion: {
61915
+ type: "object",
61916
+ required: ["provincia", "canton", "distrito", "otrasSenas"],
61917
+ description: "Issuer location (required by the v4.4 schemas)",
61918
+ properties: {
61919
+ provincia: { type: "string", pattern: "^[1-7]$", description: "Province code (1-7)" },
61920
+ canton: { type: "string", pattern: "^\\d{2}$", description: "Canton code (2 digits)" },
61921
+ distrito: {
61922
+ type: "string",
61923
+ pattern: "^\\d{2}$",
61924
+ description: "District code (2 digits)"
61925
+ },
61926
+ barrio: {
61927
+ type: "string",
61928
+ minLength: 5,
61929
+ maxLength: 50,
61930
+ description: "Barrio name (free text 5-50 chars in v4.4; no longer a 2-digit code)"
61931
+ },
61932
+ otrasSenas: {
61933
+ type: "string",
61934
+ minLength: 5,
61935
+ maxLength: 250,
61936
+ description: "Address details (5-250 chars, required)"
61937
+ }
61938
+ }
61939
+ },
61244
61940
  correoElectronico: {
61245
61941
  type: "string",
61246
61942
  format: "email",
@@ -61279,25 +61975,27 @@ var FACTURA_SCHEMA = {
61279
61975
  }
61280
61976
  }
61281
61977
  },
61282
- codigoActividad: {
61978
+ proveedorSistemas: {
61979
+ type: "string",
61980
+ maxLength: 20,
61981
+ description: "Invoicing-system provider ID (v4.4 ProveedorSistemas). Defaults to the emisor's ID number"
61982
+ },
61983
+ codigoActividadEmisor: {
61283
61984
  type: "string",
61284
61985
  pattern: "^\\d{6}$",
61285
- description: "CABYS economic activity code (6 digits)"
61986
+ description: "Issuer economic activity code (6 digits, v4.4 CodigoActividadEmisor)"
61286
61987
  },
61287
61988
  condicionVenta: {
61288
61989
  type: "string",
61289
- enum: ["01", "02", "03", "04", "05", "06", "07", "08", "09", "99"],
61990
+ enum: ["01", "02", "03", "04", "05", "06", "07", "08", "10", "12", "13", "14", "15", "99"],
61290
61991
  default: "01",
61291
- description: "Sale condition: 01=Cash, 02=Credit, 03=Consignment, 04=Layaway, 99=Other"
61992
+ description: "Sale condition (v4.4): 01=Cash, 02=Credit, 03=Consignment, 04=Layaway, 99=Other"
61292
61993
  },
61293
61994
  medioPago: {
61294
- type: "array",
61295
- items: {
61296
- type: "string",
61297
- enum: ["01", "02", "03", "04", "05", "99"]
61298
- },
61299
- default: ["01"],
61300
- description: "Payment methods: 01=Cash, 02=Card, 03=Check, 04=Transfer, 05=Third-party, 99=Other"
61995
+ type: "string",
61996
+ enum: ["01", "02", "03", "04", "05", "06", "07", "99"],
61997
+ default: "01",
61998
+ description: "Payment method (v4.4, emitted inside ResumenFactura with the total): 01=Cash, 02=Card, 03=Check, 04=Transfer, 05=Third-party, 06=SINPE Movil, 07=Digital platform, 99=Other"
61301
61999
  },
61302
62000
  plazoCredito: {
61303
62001
  type: "string",
@@ -61324,7 +62022,7 @@ var FACTURA_SCHEMA = {
61324
62022
  },
61325
62023
  unidadMedida: {
61326
62024
  type: "string",
61327
- description: 'Unit of measure: "Sp"=Service, "Unid"=Unit, "kg"=Kilogram, "m"=Meter, etc.'
62025
+ description: 'Unit of measure (official v4.4 catalog casing): "Sp"=Service, "Unid"=Unit, "Kg"=Kilogram, "M"=Meter, "L"=Liter, "h"=Hour, etc.'
61328
62026
  },
61329
62027
  detalle: {
61330
62028
  type: "string",
@@ -61352,9 +62050,9 @@ var FACTURA_SCHEMA = {
61352
62050
  type: "string",
61353
62051
  description: "Tax code: 01=IVA, 02=Selective, etc."
61354
62052
  },
61355
- codigoTarifa: {
62053
+ codigoTarifaIVA: {
61356
62054
  type: "string",
61357
- description: "IVA rate code: 01=0%, 02=1%, 03=2%, 04=4%, 08=13%"
62055
+ description: "IVA rate code (v4.4 CodigoTarifaIVA): 01=0%, 02=1%, 03=2%, 04=4%, 08=13%, 09=0.5%, 10=exempt, 11=0% without credit"
61358
62056
  },
61359
62057
  tarifa: {
61360
62058
  type: "number",
@@ -61368,15 +62066,19 @@ var FACTURA_SCHEMA = {
61368
62066
  description: "Discounts",
61369
62067
  items: {
61370
62068
  type: "object",
61371
- required: ["montoDescuento", "naturalezaDescuento"],
62069
+ required: ["montoDescuento", "codigoDescuento"],
61372
62070
  properties: {
61373
62071
  montoDescuento: {
61374
62072
  type: "number",
61375
62073
  description: "Discount amount"
61376
62074
  },
62075
+ codigoDescuento: {
62076
+ type: "string",
62077
+ description: 'Discount code (v4.4 CodigoDescuento, "01".."09" or "99")'
62078
+ },
61377
62079
  naturalezaDescuento: {
61378
62080
  type: "string",
61379
- description: "Reason for discount"
62081
+ description: "Reason for discount (optional in v4.4)"
61380
62082
  }
61381
62083
  }
61382
62084
  }
@@ -61571,8 +62273,6 @@ var TAX_REFERENCE = {
61571
62273
  description: "Square meters"
61572
62274
  },
61573
62275
  { code: UnitOfMeasure.METROS_CUBICOS, name: "Metros cubicos", description: "Cubic meters" },
61574
- { code: UnitOfMeasure.CAJAS, name: "Cajas", description: "Boxes" },
61575
- { code: UnitOfMeasure.PAQUETES, name: "Paquetes", description: "Packages" },
61576
62276
  { code: UnitOfMeasure.GALONES, name: "Galones", description: "Gallons" },
61577
62277
  { code: UnitOfMeasure.OTROS, name: "Otros", description: "Other (specify)" }
61578
62278
  ],