facturas 0.20.5 → 0.22.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.
- package/README.md +4 -2
- package/dist/{chunk-C2KX652X.mjs → chunk-5CGIRDZY.mjs} +5 -2
- package/dist/chunk-5CGIRDZY.mjs.map +1 -0
- package/dist/{chunk-VEKUMXHW.mjs → chunk-67ISWKGE.mjs} +5 -4
- package/dist/{chunk-B2M64SIK.mjs → chunk-7MNVZSW6.mjs} +13 -4
- package/dist/chunk-7MNVZSW6.mjs.map +1 -0
- package/dist/{chunk-UOIZQMA6.mjs → chunk-FSJHE4VS.mjs} +3 -3
- package/dist/{chunk-EXJMG54W.mjs → chunk-GQGYO2Z2.mjs} +4 -4
- package/dist/{chunk-YPQJRSTA.mjs → chunk-HLSFMWRT.mjs} +2 -2
- package/dist/{chunk-NT2A6YMO.mjs → chunk-Q7IURW54.mjs} +12 -1
- package/dist/chunk-Q7IURW54.mjs.map +1 -0
- package/dist/{chunk-KBEV7QTU.mjs → chunk-R4MOVPYT.mjs} +2848 -297
- package/dist/chunk-R4MOVPYT.mjs.map +1 -0
- package/dist/cli.d.ts +4 -4
- package/dist/cli.mjs +11 -11
- package/dist/cli.mjs.map +1 -1
- package/dist/{client-BgWH_jKT.d.ts → client-ghHzZdu8.d.ts} +613 -73
- package/dist/constants.d.ts +3 -0
- package/dist/constants.mjs +1 -1
- package/dist/errors.d.ts +2 -2
- package/dist/errors.mjs +3 -1
- package/dist/{fiscal-evidence-Bg4o9nxt.d.ts → fiscal-evidence-DjG8zB3o.d.ts} +21 -5
- package/dist/{index-DAC3edtw.d.ts → index-BSTxy3nN.d.ts} +1 -1
- package/dist/index.d.ts +5 -5
- package/dist/index.mjs +35 -16
- package/dist/index.mjs.map +1 -1
- package/dist/padron.d.ts +2 -2
- package/dist/padron.mjs +3 -3
- package/dist/{types-Su7QwloQ.d.ts → types-CbvsjIhf.d.ts} +14 -5
- package/dist/types.d.ts +1 -1
- package/dist/wsfe.d.ts +3 -3
- package/dist/wsfe.mjs +4 -4
- package/dist/wsmtxca.d.ts +3 -3
- package/dist/wsmtxca.mjs +4 -4
- package/package.json +1 -1
- package/dist/chunk-B2M64SIK.mjs.map +0 -1
- package/dist/chunk-C2KX652X.mjs.map +0 -1
- package/dist/chunk-KBEV7QTU.mjs.map +0 -1
- package/dist/chunk-NT2A6YMO.mjs.map +0 -1
- /package/dist/{chunk-VEKUMXHW.mjs.map → chunk-67ISWKGE.mjs.map} +0 -0
- /package/dist/{chunk-UOIZQMA6.mjs.map → chunk-FSJHE4VS.mjs.map} +0 -0
- /package/dist/{chunk-EXJMG54W.mjs.map → chunk-GQGYO2Z2.mjs.map} +0 -0
- /package/dist/{chunk-YPQJRSTA.mjs.map → chunk-HLSFMWRT.mjs.map} +0 -0
package/README.md
CHANGED
|
@@ -127,6 +127,8 @@ una reserva sin emitir.
|
|
|
127
127
|
contrato fiscal de emisión.
|
|
128
128
|
- [Notas de crédito](https://facturas-sdk.dev/guides/credit-notes): `issueCreditNote()`, modo
|
|
129
129
|
parcial y modo total.
|
|
130
|
+
- [Factura E](https://facturas-sdk.dev/guides/export): exportación de bienes y servicios por
|
|
131
|
+
WSFEX con el mismo `issue()`.
|
|
130
132
|
- [Evitar comprobantes duplicados](https://facturas-sdk.dev/guides/avoid-duplicates): claves para
|
|
131
133
|
reintentos, Postgres, Redis, archivos y memoria.
|
|
132
134
|
- [WSMTXCA para casos requeridos](https://facturas-sdk.dev/guides/wsmtxca): configuración
|
|
@@ -134,8 +136,8 @@ una reserva sin emitir.
|
|
|
134
136
|
- [Configuración](https://facturas-sdk.dev/reference/configuration): variables de entorno, opciones del
|
|
135
137
|
cliente, sesiones WSAA, logs, reintentos y límites de tiempo.
|
|
136
138
|
- [Módulos de transporte](https://facturas-sdk.dev/reference/arca-services): `client.wsfe`,
|
|
137
|
-
`client.wsmtxca` y `client.padron` para lecturas, catálogos,
|
|
138
|
-
servicio y Padrón.
|
|
139
|
+
`client.wsfex`, `client.wsmtxca` y `client.padron` para lecturas, catálogos,
|
|
140
|
+
estado del servicio y Padrón.
|
|
139
141
|
- [Errores](https://facturas-sdk.dev/reference/errors): clases de error y diagnóstico.
|
|
140
142
|
- [Referencia](https://facturas-sdk.dev/reference/public-api): constantes, API pública con semver y
|
|
141
143
|
seguridad.
|
|
@@ -8,7 +8,10 @@ var ARCA_VOUCHER_TYPES = {
|
|
|
8
8
|
NOTA_CREDITO_B: 8,
|
|
9
9
|
FACTURA_C: 11,
|
|
10
10
|
NOTA_DEBITO_C: 12,
|
|
11
|
-
NOTA_CREDITO_C: 13
|
|
11
|
+
NOTA_CREDITO_C: 13,
|
|
12
|
+
FACTURA_E: 19,
|
|
13
|
+
NOTA_DEBITO_E: 20,
|
|
14
|
+
NOTA_CREDITO_E: 21
|
|
12
15
|
};
|
|
13
16
|
var ARCA_DOCUMENT_TYPES = {
|
|
14
17
|
CUIT: 80,
|
|
@@ -117,4 +120,4 @@ export {
|
|
|
117
120
|
ARCA_FINAL_CONSUMER_IDENTIFICATION_THRESHOLD_MINOR_UNITS,
|
|
118
121
|
ARCA_INVOICE_CLASS_BY_ISSUER
|
|
119
122
|
};
|
|
120
|
-
//# sourceMappingURL=chunk-
|
|
123
|
+
//# sourceMappingURL=chunk-5CGIRDZY.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/constants.ts"],"sourcesContent":["/** Common ARCA reference data for readable userland code and examples. */\nexport const ARCA_VOUCHER_TYPES = {\n FACTURA_A: 1,\n NOTA_DEBITO_A: 2,\n NOTA_CREDITO_A: 3,\n FACTURA_B: 6,\n NOTA_DEBITO_B: 7,\n NOTA_CREDITO_B: 8,\n FACTURA_C: 11,\n NOTA_DEBITO_C: 12,\n NOTA_CREDITO_C: 13,\n FACTURA_E: 19,\n NOTA_DEBITO_E: 20,\n NOTA_CREDITO_E: 21,\n} as const;\n\n/** Common document types accepted by ARCA services. */\nexport const ARCA_DOCUMENT_TYPES = {\n CUIT: 80,\n DNI: 96,\n CONSUMIDOR_FINAL: 99,\n} as const;\n\n/**\n * ARCA's generic WSMTXCA item codes, keyed by the `matrixCode` to send.\n * RG 2904, Anexo VII: for concepts outside the issuer's main line of goods,\n * which carry their GTIN instead. Samples and promotional material use\n * `7790001001054` (Ventas varias).\n * https://www.afip.gob.ar/fe/documentos/codigosGenericosYEspecificos.xls\n */\nexport const ARCA_WSMTXCA_GENERIC_CODES = {\n \"7790001001030\": \"Descuentos y bonificaciones comerciales\",\n \"7790001001047\": \"Conceptos financieros\",\n \"7790001001054\": \"Ventas varias\",\n \"7790001001061\": \"Bienes de uso\",\n \"7790001001078\": \"Servicios prestados\",\n \"7790001001085\": \"Fletes\",\n \"7790001001092\": \"Alquileres\",\n \"7790001001115\": \"Depósito y servicios de logística\",\n \"7790001001122\": \"Repuestos y accesorios\",\n \"7790001001139\": \"Ajustes impositivos\",\n \"7790001001146\": \"Actividades comerciales no codificadas\",\n \"7790001001153\": \"Venta de material de rezago\",\n \"7790001001856\": \"Anticipos y señas\",\n} as const;\n\n/**\n * Common receiver IVA condition identifiers used by WSFE.\n * Allowed values depend on the voucher class and ARCA's live catalog.\n */\nexport const ARCA_RECEIVER_VAT_CONDITIONS = {\n RESPONSABLE_INSCRIPTO: 1,\n EXENTO: 4,\n CONSUMIDOR_FINAL: 5,\n MONOTRIBUTISTA: 6,\n IVA_NO_ALCANZADO: 15,\n} as const;\n\n/** Supported invoice concept types for WSFE requests. */\nexport const ARCA_CONCEPT_TYPES = {\n PRODUCTOS: 1,\n SERVICIOS: 2,\n PRODUCTOS_Y_SERVICIOS: 3,\n} as const;\n\n/** Common IVA rate identifiers used by WSFE. */\nexport const ARCA_VAT_RATES = {\n IVA_0: 3,\n IVA_10_5: 4,\n IVA_21: 5,\n IVA_27: 6,\n IVA_5: 8,\n IVA_2_5: 9,\n} as const;\n\n/** ISO currency codes accepted by the high-level WSFE builders. */\nexport const ISO_CURRENCIES = {\n ARS: \"ARS\",\n USD: \"USD\",\n} as const;\n\n/** ARCA currency identifiers keyed by their corresponding ISO currency. */\nexport const ARCA_CURRENCY_IDS = {\n ARS: \"PES\",\n USD: \"DOL\",\n} as const;\n\n/** Legal assertions supported by the invoice high-level API; never inferred from Padrón. */\nexport type IssuerCondition =\n | \"responsable_inscripto\"\n | \"monotributo\"\n | \"exento\"\n | \"no_alcanzado\";\nexport type ReceiverCondition = IssuerCondition | \"consumidor_final\";\nexport type VoucherClass = \"A\" | \"B\" | \"C\";\n\nexport const ARCA_RECEIVER_CONDITION_IDS = {\n responsable_inscripto: ARCA_RECEIVER_VAT_CONDITIONS.RESPONSABLE_INSCRIPTO,\n monotributo: ARCA_RECEIVER_VAT_CONDITIONS.MONOTRIBUTISTA,\n exento: ARCA_RECEIVER_VAT_CONDITIONS.EXENTO,\n consumidor_final: ARCA_RECEIVER_VAT_CONDITIONS.CONSUMIDOR_FINAL,\n no_alcanzado: ARCA_RECEIVER_VAT_CONDITIONS.IVA_NO_ALCANZADO,\n} as const satisfies Record<ReceiverCondition, number>;\n\nexport const ARCA_ISSUER_CONDITION_IDS = {\n responsable_inscripto: 1,\n monotributo: 6,\n exento: 4,\n no_alcanzado: 15,\n} as const satisfies Record<IssuerCondition, number>;\n\n/** The ARCA identifier of each issuer condition, accepted wherever a name is. */\nexport type IssuerConditionId =\n (typeof ARCA_ISSUER_CONDITION_IDS)[IssuerCondition];\n\n// RG 5866/2026, art. 1(f), effective 2026-07-01 (art. 4).\n// https://www.argentina.gob.ar/normativa/nacional/norma-427092/texto\nexport const ARCA_FINAL_CONSUMER_IDENTIFICATION_THRESHOLD_MINOR_UNITS =\n 1_000_000_000n;\n\n// WSFE v4.7, physical PDF p. 203, validations 10243/10246; issuer asserted first.\n// ARCA checks actual issuer eligibility independently at authorization.\nexport const ARCA_INVOICE_CLASS_BY_ISSUER = {\n responsable_inscripto: {\n responsable_inscripto: \"A\",\n monotributo: \"A\",\n exento: \"B\",\n consumidor_final: \"B\",\n no_alcanzado: \"B\",\n },\n monotributo: {\n responsable_inscripto: \"C\",\n monotributo: \"C\",\n exento: \"C\",\n consumidor_final: \"C\",\n no_alcanzado: \"C\",\n },\n exento: {\n responsable_inscripto: \"C\",\n monotributo: \"C\",\n exento: \"C\",\n consumidor_final: \"C\",\n no_alcanzado: \"C\",\n },\n no_alcanzado: {\n responsable_inscripto: \"C\",\n monotributo: \"C\",\n exento: \"C\",\n consumidor_final: \"C\",\n no_alcanzado: \"C\",\n },\n} as const satisfies Record<\n IssuerCondition,\n Record<ReceiverCondition, VoucherClass>\n>;\n"],"mappings":";AACO,IAAM,qBAAqB;AAAA,EAChC,WAAW;AAAA,EACX,eAAe;AAAA,EACf,gBAAgB;AAAA,EAChB,WAAW;AAAA,EACX,eAAe;AAAA,EACf,gBAAgB;AAAA,EAChB,WAAW;AAAA,EACX,eAAe;AAAA,EACf,gBAAgB;AAAA,EAChB,WAAW;AAAA,EACX,eAAe;AAAA,EACf,gBAAgB;AAClB;AAGO,IAAM,sBAAsB;AAAA,EACjC,MAAM;AAAA,EACN,KAAK;AAAA,EACL,kBAAkB;AACpB;AASO,IAAM,6BAA6B;AAAA,EACxC,iBAAiB;AAAA,EACjB,iBAAiB;AAAA,EACjB,iBAAiB;AAAA,EACjB,iBAAiB;AAAA,EACjB,iBAAiB;AAAA,EACjB,iBAAiB;AAAA,EACjB,iBAAiB;AAAA,EACjB,iBAAiB;AAAA,EACjB,iBAAiB;AAAA,EACjB,iBAAiB;AAAA,EACjB,iBAAiB;AAAA,EACjB,iBAAiB;AAAA,EACjB,iBAAiB;AACnB;AAMO,IAAM,+BAA+B;AAAA,EAC1C,uBAAuB;AAAA,EACvB,QAAQ;AAAA,EACR,kBAAkB;AAAA,EAClB,gBAAgB;AAAA,EAChB,kBAAkB;AACpB;AAGO,IAAM,qBAAqB;AAAA,EAChC,WAAW;AAAA,EACX,WAAW;AAAA,EACX,uBAAuB;AACzB;AAGO,IAAM,iBAAiB;AAAA,EAC5B,OAAO;AAAA,EACP,UAAU;AAAA,EACV,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,OAAO;AAAA,EACP,SAAS;AACX;AAGO,IAAM,iBAAiB;AAAA,EAC5B,KAAK;AAAA,EACL,KAAK;AACP;AAGO,IAAM,oBAAoB;AAAA,EAC/B,KAAK;AAAA,EACL,KAAK;AACP;AAWO,IAAM,8BAA8B;AAAA,EACzC,uBAAuB,6BAA6B;AAAA,EACpD,aAAa,6BAA6B;AAAA,EAC1C,QAAQ,6BAA6B;AAAA,EACrC,kBAAkB,6BAA6B;AAAA,EAC/C,cAAc,6BAA6B;AAC7C;AAEO,IAAM,4BAA4B;AAAA,EACvC,uBAAuB;AAAA,EACvB,aAAa;AAAA,EACb,QAAQ;AAAA,EACR,cAAc;AAChB;AAQO,IAAM,2DACX;AAIK,IAAM,+BAA+B;AAAA,EAC1C,uBAAuB;AAAA,IACrB,uBAAuB;AAAA,IACvB,aAAa;AAAA,IACb,QAAQ;AAAA,IACR,kBAAkB;AAAA,IAClB,cAAc;AAAA,EAChB;AAAA,EACA,aAAa;AAAA,IACX,uBAAuB;AAAA,IACvB,aAAa;AAAA,IACb,QAAQ;AAAA,IACR,kBAAkB;AAAA,IAClB,cAAc;AAAA,EAChB;AAAA,EACA,QAAQ;AAAA,IACN,uBAAuB;AAAA,IACvB,aAAa;AAAA,IACb,QAAQ;AAAA,IACR,kBAAkB;AAAA,IAClB,cAAc;AAAA,EAChB;AAAA,EACA,cAAc;AAAA,IACZ,uBAAuB;AAAA,IACvB,aAAa;AAAA,IACb,QAAQ;AAAA,IACR,kBAAkB;AAAA,IAClB,cAAc;AAAA,EAChB;AACF;","names":[]}
|
|
@@ -2,20 +2,20 @@ import {
|
|
|
2
2
|
parseLastAuthorizedNumber,
|
|
3
3
|
parseOptionalResponseInteger,
|
|
4
4
|
parseResponseInteger
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-HLSFMWRT.mjs";
|
|
6
6
|
import {
|
|
7
7
|
classifyArcaAuthenticationError,
|
|
8
8
|
classifyArcaAuthenticationIssues,
|
|
9
9
|
createArcaAuthenticationEvidence,
|
|
10
10
|
executeWithAuthenticationRecovery
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-7MNVZSW6.mjs";
|
|
12
12
|
import {
|
|
13
13
|
ArcaInputError,
|
|
14
14
|
ArcaInvalidSoapResponseError,
|
|
15
15
|
ArcaServiceError,
|
|
16
16
|
ArcaSoapFaultError,
|
|
17
17
|
ArcaTransportError
|
|
18
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-Q7IURW54.mjs";
|
|
19
19
|
|
|
20
20
|
// src/internal/dates.ts
|
|
21
21
|
function toIsoDate(value) {
|
|
@@ -1523,6 +1523,7 @@ function getWsfeNumericResultEntries(result, key) {
|
|
|
1523
1523
|
export {
|
|
1524
1524
|
toIsoDate,
|
|
1525
1525
|
normalizeArcaAmountToMinorUnits,
|
|
1526
|
+
serializeArcaAmount,
|
|
1526
1527
|
serializeArcaExchangeRate,
|
|
1527
1528
|
assertArcaMinorUnits,
|
|
1528
1529
|
arcaMinorUnitsToNumber,
|
|
@@ -1532,4 +1533,4 @@ export {
|
|
|
1532
1533
|
normalizeWsfeVoucherInput,
|
|
1533
1534
|
normalizeWsfeDateInput
|
|
1534
1535
|
};
|
|
1535
|
-
//# sourceMappingURL=chunk-
|
|
1536
|
+
//# sourceMappingURL=chunk-67ISWKGE.mjs.map
|
|
@@ -3,13 +3,21 @@ import {
|
|
|
3
3
|
ArcaServiceError,
|
|
4
4
|
ArcaSoapFaultError,
|
|
5
5
|
isArcaAuthenticationError
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-Q7IURW54.mjs";
|
|
7
7
|
|
|
8
8
|
// src/internal/authentication.ts
|
|
9
9
|
var WSFE_AUTHENTICATION_CODES = {
|
|
10
10
|
"600": "invalid_token",
|
|
11
11
|
"601": "missing_relationship"
|
|
12
12
|
};
|
|
13
|
+
var WSFEX_AUTHENTICATION_CODES = {
|
|
14
|
+
"1000": "invalid_token",
|
|
15
|
+
"1001": "missing_relationship"
|
|
16
|
+
};
|
|
17
|
+
var STRUCTURED_AUTHENTICATION_CODES = {
|
|
18
|
+
wsfe: WSFE_AUTHENTICATION_CODES,
|
|
19
|
+
wsfex: WSFEX_AUTHENTICATION_CODES
|
|
20
|
+
};
|
|
13
21
|
function classifyArcaAuthenticationCandidate(candidate) {
|
|
14
22
|
const providerCode = normalizeProviderCode(candidate.providerCode);
|
|
15
23
|
const reason = getStructuredAuthenticationReason(candidate.service, providerCode) ?? getTextAuthenticationReason(candidate.message);
|
|
@@ -101,10 +109,11 @@ async function executeWithAuthenticationRecovery(options) {
|
|
|
101
109
|
}
|
|
102
110
|
}
|
|
103
111
|
function getStructuredAuthenticationReason(service, providerCode) {
|
|
104
|
-
|
|
112
|
+
const codes = STRUCTURED_AUTHENTICATION_CODES[service];
|
|
113
|
+
if (!codes || providerCode === void 0) {
|
|
105
114
|
return void 0;
|
|
106
115
|
}
|
|
107
|
-
return
|
|
116
|
+
return codes[String(providerCode).trim()];
|
|
108
117
|
}
|
|
109
118
|
function getTextAuthenticationReason(message) {
|
|
110
119
|
if (!message) {
|
|
@@ -176,4 +185,4 @@ export {
|
|
|
176
185
|
createArcaAuthenticationEvidence,
|
|
177
186
|
executeWithAuthenticationRecovery
|
|
178
187
|
};
|
|
179
|
-
//# sourceMappingURL=chunk-
|
|
188
|
+
//# sourceMappingURL=chunk-7MNVZSW6.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/internal/authentication.ts"],"sourcesContent":["import {\n ArcaAuthenticationError,\n type ArcaAuthenticationReason,\n ArcaServiceError,\n ArcaSoapFaultError,\n isArcaAuthenticationError,\n} from \"../errors\";\nimport type {\n ArcaAuthenticationEvidence,\n ArcaFiscalIssue,\n} from \"../services/fiscal-evidence\";\nimport type { ArcaServiceName } from \"./types\";\n\ntype AuthenticationContext = {\n service: ArcaServiceName;\n operation: string;\n};\n\ntype AuthenticationCandidate = AuthenticationContext & {\n providerCode?: string | number;\n message?: string;\n cause?: unknown;\n};\n\ntype AuthenticationRecoveryOptions<T> = AuthenticationContext & {\n forceRefresh?: boolean;\n allowRetry?: boolean;\n execute(forceRefresh?: boolean): Promise<T>;\n};\n\nconst WSFE_AUTHENTICATION_CODES: Readonly<\n Record<string, ArcaAuthenticationReason>\n> = {\n \"600\": \"invalid_token\",\n \"601\": \"missing_relationship\",\n};\n\n// WSFEX answers every operation's token check with 1000 and a CUIT outside the\n// ticket's represented taxpayers with 1001.\nconst WSFEX_AUTHENTICATION_CODES: Readonly<\n Record<string, ArcaAuthenticationReason>\n> = {\n \"1000\": \"invalid_token\",\n \"1001\": \"missing_relationship\",\n};\n\nconst STRUCTURED_AUTHENTICATION_CODES: Partial<\n Record<ArcaServiceName, Readonly<Record<string, ArcaAuthenticationReason>>>\n> = {\n wsfe: WSFE_AUTHENTICATION_CODES,\n wsfex: WSFEX_AUTHENTICATION_CODES,\n};\n\n/** Classifies one safe provider code/message pair without inspecting object graphs. */\nexport function classifyArcaAuthenticationCandidate(\n candidate: AuthenticationCandidate\n): ArcaAuthenticationError | undefined {\n const providerCode = normalizeProviderCode(candidate.providerCode);\n const reason =\n getStructuredAuthenticationReason(candidate.service, providerCode) ??\n getTextAuthenticationReason(candidate.message);\n\n if (!reason) {\n return undefined;\n }\n\n return new ArcaAuthenticationError(\n formatAuthenticationMessage(candidate.service, candidate.operation, reason),\n {\n reason,\n service: candidate.service,\n operation: candidate.operation,\n ...(providerCode === undefined ? {} : { providerCode }),\n ...(candidate.cause === undefined ? {} : { cause: candidate.cause }),\n }\n );\n}\n\n/** Classifies supported public ARCA errors while ignoring arbitrary errors and causes. */\nexport function classifyArcaAuthenticationError(\n error: unknown,\n context: AuthenticationContext\n): ArcaAuthenticationError | undefined {\n if (isArcaAuthenticationError(error)) {\n return error;\n }\n\n if (error instanceof ArcaSoapFaultError) {\n return classifyArcaAuthenticationCandidate({\n ...context,\n providerCode: error.faultCode,\n message: error.message,\n cause: error,\n });\n }\n\n if (error instanceof ArcaServiceError) {\n const issueError = classifyArcaAuthenticationIssues(\n error.issues ?? [],\n context\n );\n if (issueError) {\n return new ArcaAuthenticationError(issueError.message, {\n reason: issueError.reason,\n service: issueError.service,\n operation: issueError.operation,\n ...(issueError.providerCode === undefined\n ? {}\n : { providerCode: issueError.providerCode }),\n cause: error,\n });\n }\n\n return classifyArcaAuthenticationCandidate({\n ...context,\n providerCode: error.serviceCode,\n message: error.message,\n cause: error,\n });\n }\n\n return undefined;\n}\n\n/** Classifies structured service issues in provider order. */\nexport function classifyArcaAuthenticationIssues(\n issues: readonly ArcaFiscalIssue[],\n context: AuthenticationContext\n): ArcaAuthenticationError | undefined {\n for (const issue of issues) {\n const authenticationError = classifyArcaAuthenticationCandidate({\n ...context,\n providerCode: issue.code,\n message: issue.message,\n });\n if (authenticationError) {\n return authenticationError;\n }\n }\n return undefined;\n}\n\n/** Converts the public error to safe serializable exact-attempt evidence. */\nexport function createArcaAuthenticationEvidence(\n error: ArcaAuthenticationError\n): ArcaAuthenticationEvidence {\n return {\n code: \"ARCA_AUTHENTICATION_ERROR\",\n reason: error.reason,\n ...(error.providerCode === undefined\n ? {}\n : { providerCode: error.providerCode }),\n };\n}\n\n/** Recreates the throwable contract from safe exact-attempt evidence. */\nexport function createArcaAuthenticationErrorFromEvidence(\n evidence: ArcaAuthenticationEvidence,\n context: AuthenticationContext\n): ArcaAuthenticationError {\n return new ArcaAuthenticationError(\n formatAuthenticationMessage(\n context.service,\n context.operation,\n evidence.reason\n ),\n {\n reason: evidence.reason,\n service: context.service,\n operation: context.operation,\n ...(evidence.providerCode === undefined\n ? {}\n : { providerCode: evidence.providerCode }),\n }\n );\n}\n\n/** Runs one convenience operation and permits one proven-safe forced refresh. */\nexport async function executeWithAuthenticationRecovery<T>(\n options: AuthenticationRecoveryOptions<T>\n): Promise<T> {\n const executeAttempt = async (forceRefresh?: boolean): Promise<T> => {\n try {\n return await options.execute(forceRefresh);\n } catch (error) {\n throw classifyArcaAuthenticationError(error, options) ?? error;\n }\n };\n\n try {\n return await executeAttempt(options.forceRefresh);\n } catch (error) {\n const allowRetry =\n options.allowRetry !== false && options.forceRefresh !== true;\n if (!(allowRetry && isArcaAuthenticationError(error))) {\n throw error;\n }\n return executeAttempt(true);\n }\n}\n\nfunction getStructuredAuthenticationReason(\n service: ArcaServiceName,\n providerCode: string | number | undefined\n): ArcaAuthenticationReason | undefined {\n const codes = STRUCTURED_AUTHENTICATION_CODES[service];\n if (!codes || providerCode === undefined) {\n return undefined;\n }\n return codes[String(providerCode).trim()];\n}\n\nfunction getTextAuthenticationReason(\n message: string | undefined\n): ArcaAuthenticationReason | undefined {\n if (!message) {\n return undefined;\n }\n const normalized = normalizeAuthenticationText(message);\n\n if (\n includesWholePhrase(\n normalized,\n \"no aparecio cuit en lista de relaciones\"\n ) ||\n includesWholePhrase(normalized, \"cuit representada no incluida en token\")\n ) {\n return \"missing_relationship\";\n }\n if (includesWholePhrase(normalized, \"computador no autorizado\")) {\n return \"unauthorized_computer\";\n }\n if (\n includesWholePhrase(normalized, \"validaciondetoken\") ||\n includesWholePhrase(normalized, \"token vencido\") ||\n includesWholePhrase(normalized, \"no se corresponden token y firma\")\n ) {\n return \"invalid_token\";\n }\n if (\n includesWholePhrase(normalized, \"no autorizado a acceder al servicio\") ||\n includesWholePhrase(normalized, \"no autorizado a acceder a los servicios\")\n ) {\n return \"authentication_rejected\";\n }\n return undefined;\n}\n\nfunction normalizeAuthenticationText(value: string): string {\n return value\n .normalize(\"NFD\")\n .replace(/\\p{Diacritic}/gu, \"\")\n .toLowerCase()\n .replace(/\\s+/g, \" \")\n .trim();\n}\n\nfunction includesWholePhrase(value: string, phrase: string): boolean {\n let searchFrom = 0;\n while (searchFrom <= value.length - phrase.length) {\n const index = value.indexOf(phrase, searchFrom);\n if (index < 0) {\n return false;\n }\n const before = value[index - 1];\n const after = value[index + phrase.length];\n if (!(isWordCharacter(before) || isWordCharacter(after))) {\n return true;\n }\n searchFrom = index + phrase.length;\n }\n return false;\n}\n\nfunction isWordCharacter(value: string | undefined): boolean {\n return value !== undefined && /[a-z0-9]/.test(value);\n}\n\nfunction normalizeProviderCode(\n providerCode: string | number | undefined\n): string | number | undefined {\n if (typeof providerCode === \"number\") {\n return Number.isFinite(providerCode) ? providerCode : undefined;\n }\n if (typeof providerCode === \"string\") {\n const normalized = providerCode.trim();\n return normalized || undefined;\n }\n return undefined;\n}\n\nfunction formatAuthenticationMessage(\n service: ArcaServiceName,\n operation: string,\n reason: ArcaAuthenticationReason\n): string {\n const descriptions: Record<ArcaAuthenticationReason, string> = {\n invalid_token: \"the token or signature was rejected\",\n unauthorized_computer: \"the certificate or computer is not authorized\",\n missing_relationship: \"the represented taxpayer relationship is missing\",\n authentication_rejected: \"the service denied authenticated access\",\n };\n return `ARCA rejected authentication for ${service}.${operation}: ${descriptions[reason]}.`;\n}\n"],"mappings":";;;;;;;;AA8BA,IAAM,4BAEF;AAAA,EACF,OAAO;AAAA,EACP,OAAO;AACT;AAIA,IAAM,6BAEF;AAAA,EACF,QAAQ;AAAA,EACR,QAAQ;AACV;AAEA,IAAM,kCAEF;AAAA,EACF,MAAM;AAAA,EACN,OAAO;AACT;AAGO,SAAS,oCACd,WACqC;AACrC,QAAM,eAAe,sBAAsB,UAAU,YAAY;AACjE,QAAM,SACJ,kCAAkC,UAAU,SAAS,YAAY,KACjE,4BAA4B,UAAU,OAAO;AAE/C,MAAI,CAAC,QAAQ;AACX,WAAO;AAAA,EACT;AAEA,SAAO,IAAI;AAAA,IACT,4BAA4B,UAAU,SAAS,UAAU,WAAW,MAAM;AAAA,IAC1E;AAAA,MACE;AAAA,MACA,SAAS,UAAU;AAAA,MACnB,WAAW,UAAU;AAAA,MACrB,GAAI,iBAAiB,SAAY,CAAC,IAAI,EAAE,aAAa;AAAA,MACrD,GAAI,UAAU,UAAU,SAAY,CAAC,IAAI,EAAE,OAAO,UAAU,MAAM;AAAA,IACpE;AA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AACjB,SAAO,cAAc,MAAM,SAAS,OAAO,QAAQ;AACjD,UAAM,QAAQ,MAAM,QAAQ,QAAQ,UAAU;AAC9C,QAAI,QAAQ,GAAG;AACb,aAAO;AAAA,IACT;AACA,UAAM,SAAS,MAAM,QAAQ,CAAC;AAC9B,UAAM,QAAQ,MAAM,QAAQ,OAAO,MAAM;AACzC,QAAI,EAAE,gBAAgB,MAAM,KAAK,gBAAgB,KAAK,IAAI;AACxD,aAAO;AAAA,IACT;AACA,iBAAa,QAAQ,OAAO;AAAA,EAC9B;AACA,SAAO;AACT;AAEA,SAAS,gBAAgB,OAAoC;AAC3D,SAAO,UAAU,UAAa,WAAW,KAAK,KAAK;AACrD;AAEA,SAAS,sBACP,cAC6B;AAC7B,MAAI,OAAO,iBAAiB,UAAU;AACpC,WAAO,OAAO,SAAS,YAAY,IAAI,eAAe;AAAA,EACxD;AACA,MAAI,OAAO,iBAAiB,UAAU;AACpC,UAAM,aAAa,aAAa,KAAK;AACrC,WAAO,cAAc;AAAA,EACvB;AACA,SAAO;AACT;AAEA,SAAS,4BACP,SACA,WACA,QACQ;AACR,QAAM,eAAyD;AAAA,IAC7D,eAAe;AAAA,IACf,uBAAuB;AAAA,IACvB,sBAAsB;AAAA,IACtB,yBAAyB;AAAA,EAC3B;AACA,SAAO,oCAAoC,OAAO,IAAI,SAAS,KAAK,aAAa,MAAM,CAAC;AAC1F;","names":[]}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
classifyArcaAuthenticationError
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-7MNVZSW6.mjs";
|
|
4
4
|
import {
|
|
5
5
|
ArcaSoapFaultError
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-Q7IURW54.mjs";
|
|
7
7
|
|
|
8
8
|
// src/services/padron.ts
|
|
9
9
|
function createPadronService(options) {
|
|
@@ -248,4 +248,4 @@ async function executePadronOperation(options, service, operation, body) {
|
|
|
248
248
|
export {
|
|
249
249
|
createPadronService
|
|
250
250
|
};
|
|
251
|
-
//# sourceMappingURL=chunk-
|
|
251
|
+
//# sourceMappingURL=chunk-FSJHE4VS.mjs.map
|
|
@@ -2,20 +2,20 @@ import {
|
|
|
2
2
|
parseLastAuthorizedNumber,
|
|
3
3
|
parseOptionalResponseInteger,
|
|
4
4
|
parseResponseInteger
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-HLSFMWRT.mjs";
|
|
6
6
|
import {
|
|
7
7
|
classifyArcaAuthenticationError,
|
|
8
8
|
classifyArcaAuthenticationIssues,
|
|
9
9
|
createArcaAuthenticationEvidence,
|
|
10
10
|
executeWithAuthenticationRecovery
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-7MNVZSW6.mjs";
|
|
12
12
|
import {
|
|
13
13
|
ArcaInputError,
|
|
14
14
|
ArcaInvalidSoapResponseError,
|
|
15
15
|
ArcaServiceError,
|
|
16
16
|
ArcaSoapFaultError,
|
|
17
17
|
ArcaTransportError
|
|
18
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-Q7IURW54.mjs";
|
|
19
19
|
|
|
20
20
|
// src/services/wsmtxca.ts
|
|
21
21
|
function createWsmtxcaService(options) {
|
|
@@ -677,4 +677,4 @@ function formatCompactDateToIso(dateValue) {
|
|
|
677
677
|
export {
|
|
678
678
|
createWsmtxcaService
|
|
679
679
|
};
|
|
680
|
-
//# sourceMappingURL=chunk-
|
|
680
|
+
//# sourceMappingURL=chunk-GQGYO2Z2.mjs.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
ArcaInvalidSoapResponseError
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-Q7IURW54.mjs";
|
|
4
4
|
|
|
5
5
|
// src/internal/response-integer.ts
|
|
6
6
|
function parseResponseInteger(value, { service, operation, field, min, max }) {
|
|
@@ -35,4 +35,4 @@ export {
|
|
|
35
35
|
parseOptionalResponseInteger,
|
|
36
36
|
parseLastAuthorizedNumber
|
|
37
37
|
};
|
|
38
|
-
//# sourceMappingURL=chunk-
|
|
38
|
+
//# sourceMappingURL=chunk-HLSFMWRT.mjs.map
|
|
@@ -94,6 +94,14 @@ var ArcaConfigurationError = class extends ArcaError {
|
|
|
94
94
|
super(message, "ARCA_CONFIGURATION_ERROR", options);
|
|
95
95
|
}
|
|
96
96
|
};
|
|
97
|
+
var ArcaLockTimeoutError = class extends ArcaError {
|
|
98
|
+
name = "ArcaLockTimeoutError";
|
|
99
|
+
reason;
|
|
100
|
+
constructor(message, options) {
|
|
101
|
+
super(message, "ARCA_LOCK_TIMEOUT", options);
|
|
102
|
+
this.reason = options.reason;
|
|
103
|
+
}
|
|
104
|
+
};
|
|
97
105
|
var ArcaInputError = class extends ArcaError {
|
|
98
106
|
name = "ArcaInputError";
|
|
99
107
|
field;
|
|
@@ -226,6 +234,8 @@ function toArcaSafeErrorMetadata(error) {
|
|
|
226
234
|
reason: error.reason,
|
|
227
235
|
providerCode: error.providerCode
|
|
228
236
|
});
|
|
237
|
+
} else if (error instanceof ArcaLockTimeoutError) {
|
|
238
|
+
Object.assign(fields, { reason: error.reason });
|
|
229
239
|
} else if (error instanceof ArcaTransportError) {
|
|
230
240
|
Object.assign(fields, {
|
|
231
241
|
statusCode: error.statusCode,
|
|
@@ -262,6 +272,7 @@ export {
|
|
|
262
272
|
createSafeErrorDiagnostic,
|
|
263
273
|
ArcaError,
|
|
264
274
|
ArcaConfigurationError,
|
|
275
|
+
ArcaLockTimeoutError,
|
|
265
276
|
ArcaInputError,
|
|
266
277
|
ArcaAuthenticationError,
|
|
267
278
|
isArcaAuthenticationError,
|
|
@@ -271,4 +282,4 @@ export {
|
|
|
271
282
|
ArcaServiceError,
|
|
272
283
|
toArcaSafeErrorMetadata
|
|
273
284
|
};
|
|
274
|
-
//# sourceMappingURL=chunk-
|
|
285
|
+
//# sourceMappingURL=chunk-Q7IURW54.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/internal/redaction.ts","../src/errors.ts"],"sourcesContent":["export const MAX_DIAGNOSTIC_PREVIEW_LENGTH = 4096;\n\nconst MAX_DIAGNOSTIC_SCALAR_LENGTH = 512;\nconst SENSITIVE_XML_ELEMENT_NAME = \"((?:[A-Za-z_][\\\\w.-]*:)?(?:Token|Sign))\";\nconst PAIRED_SENSITIVE_XML_ELEMENT = new RegExp(\n `<${SENSITIVE_XML_ELEMENT_NAME}\\\\b[^>]*>[\\\\s\\\\S]*?<\\\\/\\\\1\\\\s*>`,\n \"gi\"\n);\nconst SELF_CLOSING_SENSITIVE_XML_ELEMENT = new RegExp(\n `<${SENSITIVE_XML_ELEMENT_NAME}\\\\b[^>]*\\\\/\\\\s*>`,\n \"gi\"\n);\nconst UNTERMINATED_SENSITIVE_XML_ELEMENT = new RegExp(\n `<${SENSITIVE_XML_ELEMENT_NAME}\\\\b[^>]*>[^<]*`,\n \"gi\"\n);\n\nexport type ResponseBodyDiagnostic = {\n responseBodyLength: number;\n responseBodyPreview: string;\n};\n\nexport type SafeErrorDiagnostic = {\n errorName?: string;\n errorCode?: string;\n statusCode?: number;\n contentType?: string;\n responseBodyLength?: number;\n responseBodyPreview?: string;\n faultCode?: string;\n};\n\n/** Redacts credential-bearing XML elements and applies the global preview bound. */\nexport function redactDiagnosticPreview(\n value: string,\n requestedMaxLength = MAX_DIAGNOSTIC_PREVIEW_LENGTH\n): string {\n const maxLength = normalizePreviewLength(requestedMaxLength);\n\n return value\n .replace(\n PAIRED_SENSITIVE_XML_ELEMENT,\n (_match, tagName: string) => `<${tagName}>[REDACTED]</${tagName}>`\n )\n .replace(\n SELF_CLOSING_SENSITIVE_XML_ELEMENT,\n (_match, tagName: string) => `<${tagName}>[REDACTED]</${tagName}>`\n )\n .replace(\n UNTERMINATED_SENSITIVE_XML_ELEMENT,\n (_match, tagName: string) => `<${tagName}>[REDACTED]`\n )\n .slice(0, maxLength);\n}\n\n/** Produces the only response-body shape allowed in errors and logs. */\nexport function createResponseBodyDiagnostic(\n responseBody: string,\n requestedMaxLength = MAX_DIAGNOSTIC_PREVIEW_LENGTH\n): ResponseBodyDiagnostic {\n return {\n responseBodyLength: responseBody.length,\n responseBodyPreview: redactDiagnosticPreview(\n responseBody,\n requestedMaxLength\n ),\n };\n}\n\n/** Extracts a scalar allowlist from an error without exposing the error or cause. */\nexport function createSafeErrorDiagnostic(error: unknown): SafeErrorDiagnostic {\n if (!(error && typeof error === \"object\")) {\n return {};\n }\n\n const candidate = error as Record<string, unknown>;\n const diagnostic: SafeErrorDiagnostic = {};\n\n assignSafeString(diagnostic, \"errorName\", candidate.name);\n assignSafeString(diagnostic, \"errorCode\", candidate.code);\n assignSafeNumber(diagnostic, \"statusCode\", candidate.statusCode);\n assignSafeString(diagnostic, \"contentType\", candidate.contentType);\n assignSafeNumber(\n diagnostic,\n \"responseBodyLength\",\n candidate.responseBodyLength\n );\n if (typeof candidate.responseBodyPreview === \"string\") {\n diagnostic.responseBodyPreview = redactDiagnosticPreview(\n candidate.responseBodyPreview\n );\n }\n assignSafeString(diagnostic, \"faultCode\", candidate.faultCode);\n\n return diagnostic;\n}\n\nfunction normalizePreviewLength(requestedMaxLength: number): number {\n if (!Number.isFinite(requestedMaxLength)) {\n return MAX_DIAGNOSTIC_PREVIEW_LENGTH;\n }\n\n return Math.max(\n 0,\n Math.min(Math.trunc(requestedMaxLength), MAX_DIAGNOSTIC_PREVIEW_LENGTH)\n );\n}\n\nfunction assignSafeString<\n TKey extends \"errorName\" | \"errorCode\" | \"contentType\" | \"faultCode\",\n>(target: SafeErrorDiagnostic, key: TKey, value: unknown): void {\n if (typeof value === \"string\") {\n target[key] = redactDiagnosticPreview(value, MAX_DIAGNOSTIC_SCALAR_LENGTH);\n }\n}\n\nfunction assignSafeNumber<TKey extends \"statusCode\" | \"responseBodyLength\">(\n target: SafeErrorDiagnostic,\n key: TKey,\n value: unknown\n): void {\n if (typeof value === \"number\" && Number.isFinite(value)) {\n target[key] = value;\n }\n}\n","import { redactDiagnosticPreview } from \"./internal/redaction\";\nimport type { ArcaServiceName } from \"./internal/types\";\nimport type {\n ArcaFiscalIssue,\n ArcaFiscalResultLevel,\n ArcaFiscalResults,\n} from \"./services/fiscal-evidence\";\n\n/** Base error class for all ARCA-related errors. */\nexport class ArcaError extends Error {\n readonly code: string;\n override readonly name: string = \"ArcaError\";\n\n constructor(message: string, code = \"ARCA_ERROR\", options?: ErrorOptions) {\n super(message, options);\n this.code = code;\n }\n}\n\n/** Thrown when the ARCA client configuration is missing or invalid. */\nexport class ArcaConfigurationError extends ArcaError {\n override readonly name: string = \"ArcaConfigurationError\";\n\n constructor(message: string, options?: ErrorOptions) {\n super(message, \"ARCA_CONFIGURATION_ERROR\", options);\n }\n}\n\n/** Why a store lock was never taken: it stayed held, or the caller gave up. */\nexport type ArcaLockTimeoutReason = \"held\" | \"aborted\";\n\n/**\n * Thrown when a call gave up waiting for a store lock. Nothing was sent to\n * ARCA, and a call that waited for the sequence lock reserved nothing either,\n * so the same call can be repeated. `held` means another holder kept the lock\n * past the wait, `aborted` that the caller's `abortSignal` fired first.\n */\nexport class ArcaLockTimeoutError extends ArcaError {\n declare readonly code: \"ARCA_LOCK_TIMEOUT\";\n override readonly name: string = \"ArcaLockTimeoutError\";\n readonly reason: ArcaLockTimeoutReason;\n\n constructor(\n message: string,\n options: ErrorOptions & { reason: ArcaLockTimeoutReason }\n ) {\n super(message, \"ARCA_LOCK_TIMEOUT\", options);\n this.reason = options.reason;\n }\n}\n\n/** Stable routing codes for caller-provided input failures. */\nexport type ArcaInputErrorCode =\n | \"ARCA_INPUT_IDEMPOTENCY_MISMATCH\"\n | \"ARCA_INPUT_RESERVATION_NOT_FOUND\"\n | \"ARCA_INPUT_INVALID_DATE\"\n | \"ARCA_INPUT_DATE_OUTSIDE_WINDOW\"\n | \"ARCA_INPUT_INVALID_AMOUNT\"\n | \"ARCA_INPUT_AMOUNT_PRECISION\"\n | \"ARCA_INPUT_AMOUNT_MISMATCH\"\n | \"ARCA_INPUT_INVALID_EXCHANGE_RATE\"\n | \"ARCA_INPUT_INVALID_VALUE\"\n | \"ARCA_INPUT_MISSING_FIELD\"\n | \"ARCA_INPUT_RESERVED_FIELD\";\n\n/** The first and last day ARCA accepts, both `YYYY-MM-DD` and inclusive. */\nexport type VoucherDateWindow = { from: string; to: string };\n\nexport type ArcaInputErrorOptions = ErrorOptions & {\n code: ArcaInputErrorCode;\n field?: string;\n expected?: string;\n window?: VoucherDateWindow;\n};\n\n/**\n * Thrown when caller-provided input data is missing or invalid. From\n * `issue()`, `issueCreditNote()` or `issueDebitNote()` it means that call sent\n * no authorization request, so ARCA issued nothing for it.\n */\nexport class ArcaInputError extends ArcaError {\n declare readonly code: ArcaInputErrorCode;\n override readonly name: string = \"ArcaInputError\";\n readonly field?: string;\n readonly expected?: string;\n /** With `ARCA_INPUT_DATE_OUTSIDE_WINDOW`, the dates ARCA accepts today. */\n readonly window?: VoucherDateWindow;\n\n constructor(message: string, options: ArcaInputErrorOptions) {\n super(message, options.code, options);\n this.field = options.field;\n this.expected = options.expected;\n this.window = options.window;\n }\n}\n\n/** Stable reasons exposed for explicit ARCA authentication rejections. */\nexport type ArcaAuthenticationReason =\n | \"invalid_token\"\n | \"unauthorized_computer\"\n | \"missing_relationship\"\n | \"authentication_rejected\";\n\nexport type ArcaAuthenticationErrorOptions = ErrorOptions & {\n reason: ArcaAuthenticationReason;\n service: ArcaServiceName;\n operation: string;\n providerCode?: string | number;\n};\n\n/** Thrown when ARCA explicitly rejects credentials before an operation runs. */\nexport class ArcaAuthenticationError extends ArcaError {\n declare readonly code: \"ARCA_AUTHENTICATION_ERROR\";\n override readonly name: string = \"ArcaAuthenticationError\";\n readonly reason: ArcaAuthenticationReason;\n readonly service: ArcaServiceName;\n readonly operation: string;\n readonly providerCode?: string | number;\n\n constructor(message: string, options: ArcaAuthenticationErrorOptions) {\n super(\n redactDiagnosticPreview(message),\n \"ARCA_AUTHENTICATION_ERROR\",\n options\n );\n this.reason = options.reason;\n this.service = options.service;\n this.operation = options.operation;\n this.providerCode = normalizeProviderCode(options.providerCode);\n }\n}\n\n/** Narrows unknown failures to the explicit authentication error contract. */\nexport function isArcaAuthenticationError(\n error: unknown\n): error is ArcaAuthenticationError {\n return error instanceof ArcaAuthenticationError;\n}\n\n/** Thrown when an HTTP request to an ARCA endpoint fails at the transport level. */\nexport class ArcaTransportError extends ArcaError {\n override readonly name: string = \"ArcaTransportError\";\n readonly statusCode?: number;\n readonly contentType?: string;\n readonly responseBodyLength?: number;\n readonly responseBodyPreview?: string;\n\n constructor(\n message: string,\n options?: ErrorOptions & {\n statusCode?: number;\n contentType?: string;\n responseBodyLength?: number;\n responseBodyPreview?: string;\n }\n ) {\n super(message, \"ARCA_TRANSPORT_ERROR\", options);\n this.statusCode = options?.statusCode;\n this.contentType = options?.contentType;\n this.responseBodyLength = options?.responseBodyLength;\n this.responseBodyPreview =\n options?.responseBodyPreview === undefined\n ? undefined\n : redactDiagnosticPreview(options.responseBodyPreview);\n }\n}\n\n/** Thrown when the SOAP response contains a Fault element. */\nexport class ArcaSoapFaultError extends ArcaError {\n override readonly name: string = \"ArcaSoapFaultError\";\n readonly faultCode?: string;\n\n constructor(\n message: string,\n options?: ErrorOptions & {\n faultCode?: string;\n }\n ) {\n super(redactDiagnosticPreview(message), \"ARCA_SOAP_FAULT\", options);\n this.faultCode =\n options?.faultCode === undefined\n ? undefined\n : redactDiagnosticPreview(options.faultCode);\n }\n}\n\n/** Thrown when a response cannot be parsed as a valid SOAP envelope. */\nexport class ArcaInvalidSoapResponseError extends ArcaError {\n override readonly name: string = \"ArcaInvalidSoapResponseError\";\n readonly service?: ArcaServiceName;\n readonly operation?: string;\n readonly endpointUrl?: string;\n readonly statusCode?: number;\n readonly contentType?: string;\n readonly responseBodyLength?: number;\n readonly responseBodyPreview?: string;\n\n constructor(\n message: string,\n options?: ErrorOptions & {\n service?: ArcaServiceName;\n operation?: string;\n endpointUrl?: string;\n statusCode?: number;\n contentType?: string;\n responseBodyLength?: number;\n responseBodyPreview?: string;\n }\n ) {\n super(message, \"ARCA_INVALID_SOAP_RESPONSE\", options);\n this.service = options?.service;\n this.operation = options?.operation;\n this.endpointUrl = options?.endpointUrl;\n this.statusCode = options?.statusCode;\n this.contentType = options?.contentType;\n this.responseBodyLength = options?.responseBodyLength;\n this.responseBodyPreview =\n options?.responseBodyPreview === undefined\n ? undefined\n : redactDiagnosticPreview(options.responseBodyPreview);\n }\n}\n\n/** Thrown when an ARCA service (WSFE, WSMTXCA, Padron) returns a domain-level error. */\nexport class ArcaServiceError extends ArcaError {\n override readonly name: string = \"ArcaServiceError\";\n readonly serviceCode?: string | number;\n readonly service?: ArcaServiceName;\n readonly operation?: string;\n readonly result?: string;\n readonly resultLevel?: ArcaFiscalResultLevel;\n readonly results?: ArcaFiscalResults;\n readonly cae?: string;\n readonly issues?: readonly ArcaFiscalIssue[];\n\n constructor(\n message: string,\n options?: ErrorOptions & {\n serviceCode?: string | number;\n service?: ArcaServiceName;\n operation?: string;\n result?: string;\n resultLevel?: ArcaFiscalResultLevel;\n results?: ArcaFiscalResults;\n cae?: string;\n issues?: readonly ArcaFiscalIssue[];\n }\n ) {\n super(message, \"ARCA_SERVICE_ERROR\", options);\n this.serviceCode = options?.serviceCode;\n this.service = options?.service;\n this.operation = options?.operation;\n this.result = options?.result;\n this.resultLevel = options?.resultLevel;\n this.results = options?.results;\n this.cae = options?.cae;\n this.issues = options?.issues;\n }\n}\n\nfunction normalizeProviderCode(\n providerCode: string | number | undefined\n): string | number | undefined {\n if (typeof providerCode === \"number\") {\n return Number.isFinite(providerCode) ? providerCode : undefined;\n }\n if (typeof providerCode === \"string\") {\n return redactDiagnosticPreview(providerCode, 512);\n }\n return undefined;\n}\n\n/**\n * Narrow error evidence, safe to log or store: the typed fields the error\n * classes declare, never a cause, stack, raw response, response body preview,\n * endpoint URL, fiscal issues or CAE.\n */\nexport type ArcaSafeErrorMetadata = {\n name: string;\n message: string;\n code?: string;\n statusCode?: number;\n contentType?: string;\n service?: ArcaServiceName;\n operation?: string;\n /** ArcaAuthenticationError's or ArcaLockTimeoutError's stable reason. */\n reason?: ArcaAuthenticationReason | ArcaLockTimeoutReason;\n providerCode?: string | number;\n faultCode?: string;\n field?: string;\n expected?: string;\n window?: VoucherDateWindow;\n /** ArcaServiceError's provider code, always as a string. */\n serviceCode?: string;\n result?: string;\n resultLevel?: ArcaFiscalResultLevel;\n};\n\nexport function toArcaSafeErrorMetadata(error: unknown): ArcaSafeErrorMetadata {\n if (!(error instanceof Error)) {\n return { name: \"UnknownError\", message: String(error) };\n }\n const metadata: ArcaSafeErrorMetadata = {\n name: error.name,\n message: error.message,\n };\n if (!(error instanceof ArcaError)) {\n return metadata;\n }\n const fields: Partial<ArcaSafeErrorMetadata> = { code: error.code };\n if (error instanceof ArcaInputError) {\n Object.assign(fields, {\n field: error.field,\n expected: error.expected,\n window: error.window,\n });\n } else if (error instanceof ArcaAuthenticationError) {\n Object.assign(fields, {\n service: error.service,\n operation: error.operation,\n reason: error.reason,\n providerCode: error.providerCode,\n });\n } else if (error instanceof ArcaLockTimeoutError) {\n Object.assign(fields, { reason: error.reason });\n } else if (error instanceof ArcaTransportError) {\n Object.assign(fields, {\n statusCode: error.statusCode,\n contentType: error.contentType,\n });\n } else if (error instanceof ArcaSoapFaultError) {\n Object.assign(fields, { faultCode: error.faultCode });\n } else if (error instanceof ArcaInvalidSoapResponseError) {\n Object.assign(fields, {\n service: error.service,\n operation: error.operation,\n statusCode: error.statusCode,\n contentType: error.contentType,\n });\n } else if (error instanceof ArcaServiceError) {\n Object.assign(fields, {\n service: error.service,\n operation: error.operation,\n serviceCode:\n error.serviceCode === undefined ? undefined : String(error.serviceCode),\n result: error.result,\n resultLevel: error.resultLevel,\n });\n }\n for (const [key, value] of Object.entries(fields)) {\n if (value !== undefined) {\n (metadata as Record<string, unknown>)[key] = value;\n }\n }\n return metadata;\n}\n"],"mappings":";AAAO,IAAM,gCAAgC;AAE7C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