facturas 0.17.0 → 0.19.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 +2 -2
- package/dist/{chunk-MS4SSSYU.mjs → chunk-4RD5VQWC.mjs} +4 -28
- package/dist/chunk-4RD5VQWC.mjs.map +1 -0
- package/dist/{chunk-BYEP3ABS.mjs → chunk-EZ4HA3LC.mjs} +45 -5
- package/dist/{chunk-BYEP3ABS.mjs.map → chunk-EZ4HA3LC.mjs.map} +1 -1
- package/dist/{chunk-EXECWJEC.mjs → chunk-MRBFLBWX.mjs} +66 -6
- package/dist/chunk-MRBFLBWX.mjs.map +1 -0
- package/dist/{chunk-KD2WT535.mjs → chunk-OORNZFI5.mjs} +22 -9
- package/dist/chunk-OORNZFI5.mjs.map +1 -0
- package/dist/{chunk-BNZECHTS.mjs → chunk-U3HODOOP.mjs} +154 -25
- package/dist/chunk-U3HODOOP.mjs.map +1 -0
- package/dist/{chunk-PHXH34L6.mjs → chunk-WPHD2GQJ.mjs} +2 -2
- package/dist/cli.d.ts +2 -2
- package/dist/cli.mjs +7 -7
- package/dist/cli.mjs.map +1 -1
- package/dist/{client-DFRttmTZ.d.ts → client-D1IH1NCf.d.ts} +22 -4
- package/dist/errors.d.ts +1 -1
- package/dist/errors.mjs +1 -1
- package/dist/{fiscal-evidence-Cecw1s05.d.ts → fiscal-evidence-B6UTFGmY.d.ts} +18 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.mjs +6 -6
- package/dist/padron.d.ts +28 -1
- package/dist/padron.mjs +2 -2
- package/dist/wsfe.d.ts +9 -13
- package/dist/wsfe.mjs +3 -3
- package/dist/wsmtxca.d.ts +2 -17
- package/dist/wsmtxca.mjs +3 -3
- package/package.json +2 -2
- package/dist/chunk-BNZECHTS.mjs.map +0 -1
- package/dist/chunk-EXECWJEC.mjs.map +0 -1
- package/dist/chunk-KD2WT535.mjs.map +0 -1
- package/dist/chunk-MS4SSSYU.mjs.map +0 -1
- /package/dist/{chunk-PHXH34L6.mjs.map → chunk-WPHD2GQJ.mjs.map} +0 -0
package/README.md
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
</div>
|
|
10
10
|
|
|
11
|
-
SDK de
|
|
11
|
+
SDK de TypeScript para facturación electrónica con ARCA / AFIP. Emití facturas,
|
|
12
12
|
notas de crédito y notas de débito, y consultá el Padrón con una sola API.
|
|
13
13
|
|
|
14
14
|
- **Solo ESM**, Node.js **>= 22**
|
|
@@ -72,7 +72,7 @@ El detalle está en [Facturas](https://facturas-sdk.dev/guides/invoices).
|
|
|
72
72
|
|
|
73
73
|
## Reintentos seguros
|
|
74
74
|
|
|
75
|
-
ARCA no recibe una clave de idempotencia
|
|
75
|
+
ARCA no recibe una clave de idempotencia. Si una respuesta se
|
|
76
76
|
pierde, no puede distinguir un reintento de una emisión nueva. `facturas` te
|
|
77
77
|
permite guardar cada intento en un `store` con el ID estable de tu venta. Al
|
|
78
78
|
repetir esa clave, consulta el número reservado en vez de empezar otra emisión.
|
|
@@ -3,14 +3,14 @@ import {
|
|
|
3
3
|
classifyArcaAuthenticationIssues,
|
|
4
4
|
createArcaAuthenticationEvidence,
|
|
5
5
|
executeWithAuthenticationRecovery
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-WPHD2GQJ.mjs";
|
|
7
7
|
import {
|
|
8
8
|
ArcaInputError,
|
|
9
9
|
ArcaInvalidSoapResponseError,
|
|
10
10
|
ArcaServiceError,
|
|
11
11
|
ArcaSoapFaultError,
|
|
12
12
|
ArcaTransportError
|
|
13
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-EZ4HA3LC.mjs";
|
|
14
14
|
|
|
15
15
|
// src/services/wsmtxca.ts
|
|
16
16
|
function createWsmtxcaService(options) {
|
|
@@ -247,35 +247,11 @@ function createWsmtxcaService(options) {
|
|
|
247
247
|
raw
|
|
248
248
|
};
|
|
249
249
|
}
|
|
250
|
-
async function getVoucher(input) {
|
|
251
|
-
const lookup = await lookupVoucher(input);
|
|
252
|
-
if (lookup.kind === "not_found") {
|
|
253
|
-
throw createWsmtxcaServiceError(lookup.operation, lookup.errors);
|
|
254
|
-
}
|
|
255
|
-
const invoiceDate = lookup.voucher.invoiceDate;
|
|
256
|
-
if (!invoiceDate) {
|
|
257
|
-
throw new ArcaServiceError(
|
|
258
|
-
formatWsmtxcaIssues(lookup.observations)[0] ?? "WSMTXCA did not return the voucher issue date",
|
|
259
|
-
{
|
|
260
|
-
service: "wsmtxca",
|
|
261
|
-
operation: lookup.operation,
|
|
262
|
-
issues: lookup.observations
|
|
263
|
-
}
|
|
264
|
-
);
|
|
265
|
-
}
|
|
266
|
-
return {
|
|
267
|
-
invoiceDate,
|
|
268
|
-
voucher: lookup.voucher.raw,
|
|
269
|
-
messages: formatWsmtxcaIssues(lookup.observations),
|
|
270
|
-
raw: lookup.raw
|
|
271
|
-
};
|
|
272
|
-
}
|
|
273
250
|
return {
|
|
274
251
|
issue,
|
|
275
252
|
getLastAuthorizedVoucher,
|
|
276
253
|
getSalesPoints,
|
|
277
|
-
lookupVoucher
|
|
278
|
-
getVoucher
|
|
254
|
+
lookupVoucher
|
|
279
255
|
};
|
|
280
256
|
}
|
|
281
257
|
function createWsmtxcaAuth(representedTaxId, token, sign) {
|
|
@@ -655,4 +631,4 @@ function formatCompactDateToIso(dateValue) {
|
|
|
655
631
|
export {
|
|
656
632
|
createWsmtxcaService
|
|
657
633
|
};
|
|
658
|
-
//# sourceMappingURL=chunk-
|
|
634
|
+
//# sourceMappingURL=chunk-4RD5VQWC.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/services/wsmtxca.ts"],"sourcesContent":["import {\n ArcaInputError,\n ArcaInvalidSoapResponseError,\n ArcaServiceError,\n ArcaSoapFaultError,\n ArcaTransportError,\n} from \"../errors\";\nimport {\n classifyArcaAuthenticationError,\n classifyArcaAuthenticationIssues,\n createArcaAuthenticationEvidence,\n executeWithAuthenticationRecovery,\n} from \"../internal/authentication\";\nimport type { ArcaClientConfig, ArcaRepresentedTaxId } from \"../internal/types\";\nimport type { SoapTransport } from \"../soap\";\nimport type { WsaaAuthModule } from \"../wsaa\";\nimport type {\n ArcaAuthorizationIndeterminateReason,\n ArcaAuthorizationOutcome,\n ArcaFiscalIssue,\n ArcaVoucherLookupResult,\n} from \"./fiscal-evidence\";\n\n/** Input for {@link WsmtxcaService.issue}: one WSMTXCA voucher request. */\nexport type WsmtxcaIssueInput = {\n representedTaxId?: ArcaRepresentedTaxId;\n data: Record<string, unknown>;\n forceRefresh?: boolean;\n /** Aborts login, submission and consultation with the caller's deadline. */\n abortSignal?: AbortSignal;\n};\n\n/** Structured evidence from one exact WSMTXCA authorization attempt. */\nexport type WsmtxcaAuthorizationOutcome = ArcaAuthorizationOutcome<\"wsmtxca\">;\n\n/** Result of querying the last authorized voucher number. */\nexport type WsmtxcaLastAuthorizedVoucherResult = {\n voucherNumber: number;\n raw: Record<string, unknown>;\n};\n\n/** A point of sale enabled for WSMTXCA. */\nexport type WsmtxcaSalesPoint = {\n number: number;\n blocked: boolean;\n deletedAt?: string;\n};\n\n/** Result of querying WSMTXCA points of sale. */\nexport type WsmtxcaSalesPointsResult = {\n salesPoints: WsmtxcaSalesPoint[];\n raw: Record<string, unknown>;\n};\n\n/** Typed provider fields used to match one exact WSMTXCA voucher. */\nexport type WsmtxcaVoucherInfo = {\n voucherNumber?: number;\n invoiceDate?: string;\n salesPoint?: number;\n voucherType?: number;\n concept?: number;\n documentType?: number;\n documentNumber?: string;\n receiverVatConditionId?: number;\n totalAmount?: number;\n subtotalAmount?: number;\n taxableAmount?: number;\n nonTaxableAmount?: number;\n exemptAmount?: number;\n taxAmount?: number;\n vatAmount?: number;\n currencyId?: string;\n exchangeRate?: number;\n cae?: string;\n caeExpiry?: string;\n raw: Record<string, unknown>;\n};\n\n/** Typed exact-voucher consultation result for WSMTXCA. */\nexport type WsmtxcaVoucherLookupOutcome = ArcaVoucherLookupResult<\n WsmtxcaVoucherInfo,\n \"wsmtxca\"\n>;\n\n/** WSMTXCA electronic invoicing service (Factura de Crédito Electrónica). */\nexport type WsmtxcaService = {\n /**\n * Issues one exact voucher: a single autorizarComprobante without transport\n * retries, returning structured evidence instead of throwing.\n */\n issue(input: WsmtxcaIssueInput): Promise<WsmtxcaAuthorizationOutcome>;\n /** Returns the last authorized voucher number for the given sales point and type. */\n getLastAuthorizedVoucher(input: {\n representedTaxId?: ArcaRepresentedTaxId;\n voucherType: number;\n salesPoint: number;\n forceRefresh?: boolean;\n abortSignal?: AbortSignal;\n }): Promise<WsmtxcaLastAuthorizedVoucherResult>;\n /** Returns the points of sale enabled for WSMTXCA. */\n getSalesPoints(input?: {\n representedTaxId?: ArcaRepresentedTaxId;\n forceRefresh?: boolean;\n }): Promise<WsmtxcaSalesPointsResult>;\n /** Consults one exact voucher and normalizes WSMTXCA error 1503 to `not_found`. */\n lookupVoucher(input: {\n representedTaxId?: ArcaRepresentedTaxId;\n voucherType: number;\n salesPoint: number;\n voucherNumber: number;\n forceRefresh?: boolean;\n abortSignal?: AbortSignal;\n }): Promise<WsmtxcaVoucherLookupOutcome>;\n};\n\nexport type CreateWsmtxcaServiceOptions = {\n config: ArcaClientConfig;\n auth: WsaaAuthModule;\n soap: SoapTransport;\n};\n\n/** Creates a WSMTXCA service instance wired with authentication and SOAP transport. */\nexport function createWsmtxcaService(\n options: CreateWsmtxcaServiceOptions\n): WsmtxcaService {\n async function executeWsmtxcaAuthenticatedOperation(\n operation: WsmtxcaOperation,\n input: {\n representedTaxId?: ArcaRepresentedTaxId;\n forceRefresh?: boolean;\n abortSignal?: AbortSignal;\n },\n body: Record<string, unknown> = {},\n retries?: number\n ) {\n const auth = await options.auth.login(\"wsmtxca\", {\n representedTaxId: input.representedTaxId,\n forceRefresh: input.forceRefresh,\n abortSignal: input.abortSignal,\n });\n const response = await options.soap.execute<\n Record<string, unknown>,\n Record<string, unknown>\n >({\n service: \"wsmtxca\",\n operation,\n ...(retries === undefined ? {} : { retries }),\n signal: input.abortSignal,\n bodyElementName: `${operation}Request`,\n bodyElementNamespaceMode: \"prefix\",\n body: {\n // WSMTXCA request types use an XML sequence with authentication first.\n authRequest: createWsmtxcaAuth(\n input.representedTaxId ?? options.config.taxId,\n auth.token,\n auth.sign\n ),\n ...body,\n },\n });\n\n return unwrapWsmtxcaOperationResponse(response.result, operation);\n }\n\n async function executeWsmtxcaAuthorization({\n representedTaxId,\n data,\n forceRefresh,\n abortSignal,\n }: WsmtxcaIssueInput): Promise<{\n outcome: WsmtxcaAuthorizationOutcome;\n error?: unknown;\n }> {\n if (Object.hasOwn(data, \"authRequest\")) {\n throw new ArcaInputError(\n 'WSMTXCA authorization data cannot include the reserved top-level field \"authRequest\".',\n {\n code: \"ARCA_INPUT_RESERVED_FIELD\",\n field: \"data.authRequest\",\n expected: \"omitted because facturas manages authentication fields\",\n }\n );\n }\n\n try {\n const raw = await executeWsmtxcaAuthenticatedOperation(\n \"autorizarComprobante\",\n { representedTaxId, forceRefresh, abortSignal },\n data,\n 0\n );\n return { outcome: classifyWsmtxcaAuthorization(raw) };\n } catch (error) {\n return {\n outcome: createWsmtxcaIndeterminateOutcome(error),\n error,\n };\n }\n }\n\n async function issue(\n input: WsmtxcaIssueInput\n ): Promise<WsmtxcaAuthorizationOutcome> {\n return (await executeWsmtxcaAuthorization(input)).outcome;\n }\n\n function getLastAuthorizedVoucher({\n representedTaxId,\n voucherType,\n salesPoint,\n forceRefresh,\n abortSignal,\n }: {\n representedTaxId?: ArcaRepresentedTaxId;\n voucherType: number;\n salesPoint: number;\n forceRefresh?: boolean;\n abortSignal?: AbortSignal;\n }): Promise<WsmtxcaLastAuthorizedVoucherResult> {\n return executeWithAuthenticationRecovery({\n service: \"wsmtxca\",\n operation: \"consultarUltimoComprobanteAutorizado\",\n forceRefresh,\n execute: (attemptForceRefresh) =>\n getLastAuthorizedVoucherOnce({\n representedTaxId,\n voucherType,\n salesPoint,\n forceRefresh: attemptForceRefresh,\n abortSignal,\n }),\n });\n }\n\n async function getLastAuthorizedVoucherOnce({\n representedTaxId,\n voucherType,\n salesPoint,\n forceRefresh,\n abortSignal,\n }: {\n representedTaxId?: ArcaRepresentedTaxId;\n voucherType: number;\n salesPoint: number;\n forceRefresh?: boolean;\n abortSignal?: AbortSignal;\n }): Promise<WsmtxcaLastAuthorizedVoucherResult> {\n const operation = \"consultarUltimoComprobanteAutorizado\";\n const raw = await executeWsmtxcaAuthenticatedOperation(\n operation,\n { representedTaxId, forceRefresh, abortSignal },\n {\n consultaUltimoComprobanteAutorizadoRequest: {\n codigoTipoComprobante: voucherType,\n numeroPuntoVenta: salesPoint,\n },\n }\n );\n const errors = extractWsmtxcaIssues(raw, operation, \"error\");\n\n if (errors.length > 0 && errors.every((issue) => issue.code === \"1502\")) {\n return { voucherNumber: 0, raw };\n }\n if (errors.length > 0) {\n throw createWsmtxcaServiceError(operation, errors);\n }\n\n return {\n voucherNumber: parseWsmtxcaVoucherNumber(\n raw.numeroComprobante ?? raw.cbteNro ?? raw.nroComprobante,\n \"WSMTXCA did not return the last authorized voucher number\",\n true\n ),\n raw,\n };\n }\n\n function getSalesPoints({\n representedTaxId,\n forceRefresh,\n }: {\n representedTaxId?: ArcaRepresentedTaxId;\n forceRefresh?: boolean;\n } = {}): Promise<WsmtxcaSalesPointsResult> {\n return executeWithAuthenticationRecovery({\n service: \"wsmtxca\",\n operation: \"consultarPuntosVenta\",\n forceRefresh,\n execute: (attemptForceRefresh) =>\n getSalesPointsOnce({\n representedTaxId,\n forceRefresh: attemptForceRefresh,\n }),\n });\n }\n\n async function getSalesPointsOnce({\n representedTaxId,\n forceRefresh,\n }: {\n representedTaxId?: ArcaRepresentedTaxId;\n forceRefresh?: boolean;\n }): Promise<WsmtxcaSalesPointsResult> {\n const operation = \"consultarPuntosVenta\";\n const raw = await executeWsmtxcaAuthenticatedOperation(operation, {\n representedTaxId,\n forceRefresh,\n });\n throwForWsmtxcaOperationErrors(operation, raw);\n const rawSalesPoints = toRecord(raw.arrayPuntosVenta)?.puntoVenta;\n const entries = Array.isArray(rawSalesPoints)\n ? rawSalesPoints\n : rawSalesPoints\n ? [rawSalesPoints]\n : [];\n const salesPoints = entries.flatMap((entry) => {\n const record = toRecord(entry);\n const number = parseOptionalPositiveInteger(record?.numeroPuntoVenta);\n if (number === undefined) {\n return [];\n }\n const deletedAt = normalizeWsmtxcaResponseDate(record?.fechaBaja);\n return [\n {\n number,\n blocked: String(record?.bloqueado ?? \"N\").toUpperCase() === \"S\",\n ...(deletedAt === undefined ? {} : { deletedAt }),\n },\n ];\n });\n\n return { salesPoints, raw };\n }\n\n function lookupVoucher({\n representedTaxId,\n voucherType,\n salesPoint,\n voucherNumber,\n forceRefresh,\n abortSignal,\n }: {\n representedTaxId?: ArcaRepresentedTaxId;\n voucherType: number;\n salesPoint: number;\n voucherNumber: number;\n forceRefresh?: boolean;\n abortSignal?: AbortSignal;\n }): Promise<WsmtxcaVoucherLookupOutcome> {\n return executeWithAuthenticationRecovery({\n service: \"wsmtxca\",\n operation: \"consultarComprobante\",\n forceRefresh,\n execute: (attemptForceRefresh) =>\n lookupVoucherOnce({\n representedTaxId,\n voucherType,\n salesPoint,\n voucherNumber,\n forceRefresh: attemptForceRefresh,\n abortSignal,\n }),\n });\n }\n\n async function lookupVoucherOnce({\n representedTaxId,\n voucherType,\n salesPoint,\n voucherNumber,\n forceRefresh,\n abortSignal,\n }: {\n representedTaxId?: ArcaRepresentedTaxId;\n voucherType: number;\n salesPoint: number;\n voucherNumber: number;\n forceRefresh?: boolean;\n abortSignal?: AbortSignal;\n }): Promise<WsmtxcaVoucherLookupOutcome> {\n const operation = \"consultarComprobante\";\n const raw = await executeWsmtxcaAuthenticatedOperation(\n operation,\n { representedTaxId, forceRefresh, abortSignal },\n {\n consultaComprobanteRequest: {\n codigoTipoComprobante: voucherType,\n numeroPuntoVenta: salesPoint,\n numeroComprobante: voucherNumber,\n },\n }\n );\n const errors = extractWsmtxcaIssues(raw, operation, \"error\");\n const observations = extractWsmtxcaIssues(raw, operation, \"observation\");\n\n if (errors.length > 0 && errors.every((issue) => issue.code === \"1503\")) {\n return {\n kind: \"not_found\",\n service: \"wsmtxca\",\n operation,\n errors,\n observations,\n raw,\n };\n }\n if (errors.length > 0) {\n throw createWsmtxcaServiceError(operation, errors);\n }\n\n const voucher = extractWsmtxcaVoucherPayload(raw);\n if (voucher === raw && !toRecord(raw.comprobante)) {\n throw new ArcaServiceError(\n \"WSMTXCA did not return the voucher issue date\",\n {\n service: \"wsmtxca\",\n operation,\n issues: observations,\n }\n );\n }\n\n return {\n kind: \"found\",\n service: \"wsmtxca\",\n operation,\n voucher: mapWsmtxcaVoucherInfo(voucher),\n observations,\n raw,\n };\n }\n\n return {\n issue,\n getLastAuthorizedVoucher,\n getSalesPoints,\n lookupVoucher,\n };\n}\n\nfunction createWsmtxcaAuth(\n representedTaxId: number | string,\n token: string,\n sign: string\n) {\n return {\n token,\n sign,\n cuitRepresentada: Number.parseInt(String(representedTaxId), 10),\n };\n}\n\nfunction toRecord(value: unknown): Record<string, unknown> | undefined {\n return value && typeof value === \"object\" && !Array.isArray(value)\n ? (value as Record<string, unknown>)\n : undefined;\n}\n\ntype WsmtxcaOperation =\n | \"autorizarComprobante\"\n | \"consultarUltimoComprobanteAutorizado\"\n | \"consultarPuntosVenta\"\n | \"consultarComprobante\";\n\nfunction unwrapWsmtxcaOperationResponse(\n response: unknown,\n operation: WsmtxcaOperation\n) {\n const responseRecord = toRecord(response) ?? {};\n\n if (operation === \"autorizarComprobante\") {\n return (\n toRecord(responseRecord.autorizarComprobanteResponse) ??\n toRecord(responseRecord.autorizarComprobanteResult) ??\n toRecord(responseRecord.comprobanteCAEResponse) ??\n toRecord(responseRecord.comprobanteCAEReponse) ??\n responseRecord\n );\n }\n\n if (operation === \"consultarComprobante\") {\n return (\n toRecord(responseRecord.consultarComprobanteResponse) ??\n toRecord(responseRecord.consultaComprobanteResponse) ??\n toRecord(responseRecord.consultarComprobanteResult) ??\n responseRecord\n );\n }\n\n if (operation === \"consultarPuntosVenta\") {\n return (\n toRecord(responseRecord.consultarPuntosVentaResponse) ??\n toRecord(responseRecord.consultarPuntosVentaResult) ??\n responseRecord\n );\n }\n\n return (\n toRecord(responseRecord.consultarUltimoComprobanteAutorizadoResponse) ??\n toRecord(responseRecord.consultaUltimoComprobanteAutorizadoResponse) ??\n toRecord(responseRecord.consultarUltimoComprobanteAutorizadoResult) ??\n responseRecord\n );\n}\n\nfunction extractWsmtxcaAuthorizationPayload(raw: Record<string, unknown>) {\n return (\n toRecord(raw.comprobanteResponse) ??\n toRecord(raw.comprobanteCAEResponse) ??\n toRecord(raw.comprobanteCAEReponse) ??\n raw\n );\n}\n\nfunction extractWsmtxcaVoucherPayload(raw: Record<string, unknown>) {\n return (\n toRecord(raw.comprobanteResponse) ??\n toRecord(raw.comprobante) ??\n toRecord(raw.cmp) ??\n raw\n );\n}\n\nfunction classifyWsmtxcaAuthorization(\n raw: Record<string, unknown>\n): WsmtxcaAuthorizationOutcome {\n const operation = \"autorizarComprobante\";\n const payload = extractWsmtxcaAuthorizationPayload(raw);\n const result = normalizeWsmtxcaResult(raw.resultado ?? payload.resultado);\n const cae = normalizeWsmtxcaString(\n payload.CAE ?? payload.codigoAutorizacion ?? raw.codigoAutorizacion\n );\n const caeExpiry = normalizeWsmtxcaResponseDate(\n payload.fechaVencimientoCAE ??\n payload.fechaVencimiento ??\n raw.fechaVencimiento\n );\n const voucherNumber = parseOptionalPositiveInteger(\n payload.numeroComprobante ?? raw.numeroComprobante\n );\n const errors = extractWsmtxcaIssues(raw, operation, \"error\");\n const observations = extractWsmtxcaIssues(raw, operation, \"observation\");\n const base = {\n service: \"wsmtxca\" as const,\n operation,\n results: createWsmtxcaResults(result),\n errors,\n observations,\n raw,\n };\n\n const authenticationOutcome = createWsmtxcaAuthenticationOutcome({\n base,\n result,\n cae,\n voucherNumber,\n });\n if (authenticationOutcome) {\n return authenticationOutcome;\n }\n\n if (\n (result === \"A\" || result === \"O\") &&\n cae &&\n voucherNumber !== undefined &&\n errors.length === 0\n ) {\n return {\n ...base,\n kind: \"authorized\",\n result,\n resultLevel: \"operation\",\n cae,\n ...(caeExpiry === undefined ? {} : { caeExpiry }),\n voucherNumber,\n };\n }\n\n if (result === \"R\" && !cae && errors.length > 0) {\n return {\n ...base,\n kind: \"rejected\",\n result: \"R\",\n resultLevel: \"operation\",\n };\n }\n\n const outcome: WsmtxcaAuthorizationOutcome = {\n ...base,\n kind: \"indeterminate\",\n reason:\n (result === \"R\" && Boolean(cae)) ||\n ((result === \"A\" || result === \"O\") && Boolean(errors.length))\n ? \"contradictory_response\"\n : \"incomplete_response\",\n ...(result === undefined ? {} : { result }),\n ...(result === undefined ? {} : { resultLevel: \"operation\" }),\n };\n assignWsmtxcaValue(outcome, \"cae\", cae);\n assignWsmtxcaValue(outcome, \"caeExpiry\", caeExpiry);\n assignWsmtxcaValue(outcome, \"voucherNumber\", voucherNumber);\n return outcome;\n}\n\nfunction createWsmtxcaAuthenticationOutcome({\n base,\n result,\n cae,\n voucherNumber,\n}: {\n base: {\n service: \"wsmtxca\";\n operation: string;\n results: ReturnType<typeof createWsmtxcaResults>;\n errors: ArcaFiscalIssue[];\n observations: ArcaFiscalIssue[];\n raw: Record<string, unknown>;\n };\n result?: string;\n cae?: string;\n voucherNumber?: number;\n}): WsmtxcaAuthorizationOutcome | undefined {\n const authenticationError = classifyArcaAuthenticationIssues(base.errors, {\n service: base.service,\n operation: base.operation,\n });\n if (\n !authenticationError ||\n result === \"A\" ||\n result === \"O\" ||\n cae ||\n voucherNumber !== undefined\n ) {\n return undefined;\n }\n\n return {\n ...base,\n kind: \"indeterminate\",\n reason: \"authentication_rejected\",\n authentication: createArcaAuthenticationEvidence(authenticationError),\n ...(result === undefined ? {} : { result }),\n ...(result === undefined ? {} : { resultLevel: \"operation\" }),\n };\n}\n\nfunction createWsmtxcaIndeterminateOutcome(\n error: unknown\n): WsmtxcaAuthorizationOutcome {\n const authenticationError = classifyArcaAuthenticationError(error, {\n service: \"wsmtxca\",\n operation: \"autorizarComprobante\",\n });\n return {\n kind: \"indeterminate\",\n service: \"wsmtxca\",\n operation: \"autorizarComprobante\",\n results: {},\n reason: authenticationError\n ? \"authentication_rejected\"\n : getWsmtxcaIndeterminateReason(error),\n ...(authenticationError\n ? {\n authentication: createArcaAuthenticationEvidence(authenticationError),\n }\n : {}),\n errors: [],\n observations: [],\n };\n}\n\nfunction getWsmtxcaIndeterminateReason(\n error: unknown\n): ArcaAuthorizationIndeterminateReason {\n if (error instanceof ArcaTransportError) {\n return \"transport_error\";\n }\n if (error instanceof ArcaSoapFaultError) {\n return \"soap_fault\";\n }\n if (error instanceof ArcaInvalidSoapResponseError) {\n return \"invalid_response\";\n }\n return \"unexpected_error\";\n}\n\nfunction createWsmtxcaResults(operationResult?: string) {\n const results: { operation?: string } = {};\n assignWsmtxcaValue(results, \"operation\", operationResult);\n return results;\n}\n\nfunction createWsmtxcaServiceError(\n operation: string,\n issues: ArcaFiscalIssue[]\n) {\n const authenticationError = classifyArcaAuthenticationIssues(issues, {\n service: \"wsmtxca\",\n operation,\n });\n if (authenticationError) {\n return authenticationError;\n }\n\n const firstIssue = issues[0];\n return new ArcaServiceError(\n formatWsmtxcaIssues(issues).join(\" | \") ||\n \"WSMTXCA returned a service error\",\n {\n service: \"wsmtxca\",\n operation,\n ...(firstIssue?.code === undefined\n ? {}\n : { serviceCode: firstIssue.code }),\n issues,\n }\n );\n}\n\nfunction throwForWsmtxcaOperationErrors(\n operation: string,\n raw: Record<string, unknown>\n): void {\n const errors = extractWsmtxcaIssues(raw, operation, \"error\");\n if (errors.length > 0) {\n throw createWsmtxcaServiceError(operation, errors);\n }\n}\n\nfunction extractWsmtxcaIssues(\n raw: Record<string, unknown>,\n operation: string,\n source: \"error\" | \"observation\"\n): ArcaFiscalIssue[] {\n const container = toRecord(\n source === \"error\" ? raw.arrayErrores : raw.arrayObservaciones\n );\n return normalizeWsmtxcaIssueEntries(container?.codigoDescripcion).map(\n (entry) => ({\n service: \"wsmtxca\",\n operation,\n source,\n category:\n source === \"observation\"\n ? \"observation\"\n : operation === \"autorizarComprobante\"\n ? \"business\"\n : \"unknown\",\n ...(entry.code === undefined ? {} : { code: entry.code }),\n message: entry.message,\n ...(operation === \"autorizarComprobante\"\n ? { resultLevel: \"operation\" as const }\n : {}),\n })\n );\n}\n\nfunction normalizeWsmtxcaIssueEntries(value: unknown) {\n const entries = Array.isArray(value) ? value : value ? [value] : [];\n return entries.map((entry) => {\n const record = toRecord(entry) ?? {};\n const code = record.codigo;\n const description = record.descripcion;\n return {\n ...(code === undefined || code === null ? {} : { code: String(code) }),\n message:\n description === undefined || description === null\n ? \"Unknown WSMTXCA issue\"\n : String(description),\n };\n });\n}\n\nfunction formatWsmtxcaIssues(issues: ArcaFiscalIssue[]): string[] {\n return issues.map((issue) => {\n const prefix = issue.source === \"error\" ? \"Error\" : \"Obs\";\n return `${prefix}${issue.code ? ` ${issue.code}` : \"\"}: ${issue.message}`;\n });\n}\n\nfunction mapWsmtxcaVoucherInfo(\n raw: Record<string, unknown>\n): WsmtxcaVoucherInfo {\n const voucher: WsmtxcaVoucherInfo = { raw };\n const invoiceDate = normalizeWsmtxcaResponseDate(\n raw.fechaEmision ?? raw.fecha ?? raw.CbteFch\n );\n const cae = normalizeWsmtxcaString(raw.codigoAutorizacion ?? raw.CAE);\n const caeExpiry = normalizeWsmtxcaResponseDate(\n raw.fechaVencimiento ?? raw.fechaVencimientoCAE\n );\n const vatAmount = sumWsmtxcaVatAmounts(raw.arraySubtotalesIVA);\n\n assignWsmtxcaValue(\n voucher,\n \"voucherNumber\",\n parseOptionalPositiveInteger(raw.numeroComprobante)\n );\n assignWsmtxcaValue(voucher, \"invoiceDate\", invoiceDate);\n assignWsmtxcaValue(\n voucher,\n \"salesPoint\",\n parseOptionalPositiveInteger(raw.numeroPuntoVenta)\n );\n assignWsmtxcaValue(\n voucher,\n \"voucherType\",\n parseOptionalPositiveInteger(raw.codigoTipoComprobante)\n );\n assignWsmtxcaValue(\n voucher,\n \"concept\",\n parseOptionalNumber(raw.codigoConcepto)\n );\n assignWsmtxcaValue(\n voucher,\n \"documentType\",\n parseOptionalNumber(raw.codigoTipoDocumento)\n );\n assignWsmtxcaValue(\n voucher,\n \"documentNumber\",\n normalizeWsmtxcaString(raw.numeroDocumento)\n );\n assignWsmtxcaValue(\n voucher,\n \"receiverVatConditionId\",\n parseOptionalNumber(raw.condicionIVAReceptor)\n );\n assignWsmtxcaValue(\n voucher,\n \"totalAmount\",\n parseOptionalNumber(raw.importeTotal)\n );\n assignWsmtxcaValue(\n voucher,\n \"subtotalAmount\",\n parseOptionalNumber(raw.importeSubtotal)\n );\n assignWsmtxcaValue(\n voucher,\n \"taxableAmount\",\n parseOptionalNumber(raw.importeGravado)\n );\n assignWsmtxcaValue(\n voucher,\n \"nonTaxableAmount\",\n parseOptionalNumber(raw.importeNoGravado)\n );\n assignWsmtxcaValue(\n voucher,\n \"exemptAmount\",\n parseOptionalNumber(raw.importeExento)\n );\n // A voucher issued without tributes carries neither the amount nor the\n // detail, and its tribute amount is zero.\n assignWsmtxcaValue(\n voucher,\n \"taxAmount\",\n parseOptionalNumber(raw.importeOtrosTributos) ??\n (raw.arrayOtrosTributos === undefined ? 0 : undefined)\n );\n assignWsmtxcaValue(voucher, \"vatAmount\", vatAmount);\n assignWsmtxcaValue(\n voucher,\n \"currencyId\",\n normalizeWsmtxcaString(raw.codigoMoneda)\n );\n assignWsmtxcaValue(\n voucher,\n \"exchangeRate\",\n parseOptionalNumber(raw.cotizacionMoneda)\n );\n assignWsmtxcaValue(voucher, \"cae\", cae);\n assignWsmtxcaValue(voucher, \"caeExpiry\", caeExpiry);\n\n return voucher;\n}\n\nfunction sumWsmtxcaVatAmounts(value: unknown): number | undefined {\n const subtotals = toRecord(value)?.subtotalIVA;\n const entries = Array.isArray(subtotals)\n ? subtotals\n : subtotals\n ? [subtotals]\n : [];\n const amounts = entries\n .map((entry) => parseOptionalNumber(toRecord(entry)?.importe))\n .filter((amount): amount is number => amount !== undefined);\n return amounts.length > 0\n ? amounts.reduce((total, amount) => total + amount, 0)\n : undefined;\n}\n\nfunction parseWsmtxcaVoucherNumber(\n value: unknown,\n message: string,\n allowZero = false\n) {\n const parsed = Number.parseInt(String(value ?? \"\"), 10);\n if (!Number.isFinite(parsed) || (allowZero ? parsed < 0 : parsed <= 0)) {\n throw new ArcaServiceError(message, {\n service: \"wsmtxca\",\n });\n }\n return parsed;\n}\n\nfunction parseOptionalPositiveInteger(value: unknown): number | undefined {\n const parsed = Number.parseInt(String(value ?? \"\"), 10);\n return Number.isFinite(parsed) && parsed > 0 ? parsed : undefined;\n}\n\nfunction parseOptionalNumber(value: unknown): number | undefined {\n if (value === undefined || value === null || value === \"\") {\n return undefined;\n }\n const parsed = Number(value);\n return Number.isFinite(parsed) ? parsed : undefined;\n}\n\nfunction normalizeWsmtxcaResult(value: unknown): string | undefined {\n if (typeof value !== \"string\") {\n return undefined;\n }\n const normalized = value.trim().toUpperCase();\n return normalized || undefined;\n}\n\nfunction normalizeWsmtxcaString(value: unknown): string | undefined {\n if (value === undefined || value === null) {\n return undefined;\n }\n const normalized = String(value).trim();\n return normalized || undefined;\n}\n\nfunction assignWsmtxcaValue<TTarget, TKey extends keyof TTarget>(\n target: TTarget,\n key: TKey,\n value: TTarget[TKey] | undefined\n) {\n if (value !== undefined) {\n target[key] = value;\n }\n}\n\nfunction normalizeWsmtxcaResponseDate(value: unknown): string | undefined {\n if (typeof value === \"number\" && Number.isInteger(value)) {\n return formatCompactDateToIso(value);\n }\n\n if (typeof value !== \"string\") {\n return undefined;\n }\n\n const trimmed = value.trim();\n if (!trimmed) {\n return undefined;\n }\n\n if (/^\\d{8}$/.test(trimmed)) {\n return formatCompactDateToIso(Number.parseInt(trimmed, 10));\n }\n\n if (/^\\d{4}-\\d{2}-\\d{2}/.test(trimmed)) {\n return trimmed.slice(0, 10);\n }\n\n return undefined;\n}\n\nfunction formatCompactDateToIso(dateValue?: number | null): string | undefined {\n if (!dateValue) {\n return undefined;\n }\n\n const raw = String(dateValue);\n if (raw.length !== 8) {\n return undefined;\n }\n\n return `${raw.slice(0, 4)}-${raw.slice(4, 6)}-${raw.slice(6, 8)}`;\n}\n"],"mappings":";;;;;;;;;;;;;;;AA0HO,SAAS,qBACd,SACgB;AAChB,iBAAe,qCACb,WACA,OAKA,OAAgC,CAAC,GACjC,SACA;AACA,UAAM,OAAO,MAAM,QAAQ,KAAK,MAAM,WAAW;AAAA,MAC/C,kBAAkB,MAAM;AAAA,MACxB,cAAc,MAAM;AAAA,MACpB,aAAa,MAAM;AAAA,IACrB,CAAC;AACD,UAAM,WAAW,MAAM,QAAQ,KAAK,QAGlC;AAAA,MACA,SAAS;AAAA,MACT;AAAA,MACA,GAAI,YAAY,SAAY,CAAC,IAAI,EAAE,QAAQ;AAAA,MAC3C,QAAQ,MAAM;AAAA,MACd,iBAAiB,GAAG,SAAS;AAAA,MAC7B,0BAA0B;AAAA,MAC1B,MAAM;AAAA;AAAA,QAEJ,aAAa;AAAA,UACX,MAAM,oBAAoB,QAAQ,OAAO;AAAA,UACzC,KAAK;AAAA,UACL,KAAK;AAAA,QACP;AAAA,QACA,GAAG;AAAA,MACL;AAAA,IACF,CAAC;AAED,WAAO,+BAA+B,SAAS,QAAQ,SAAS;AAAA,EAClE;AAEA,iBAAe,4BAA4B;AAAA,IACzC;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,GAGG;AACD,QAAI,OAAO,OAAO,MAAM,aAAa,GAAG;AACtC,YAAM,IAAI;AAAA,QACR;AAAA,QACA;AAAA,UACE,MAAM;AAAA,UACN,OAAO;AAAA,UACP,UAAU;AAAA,QACZ;AAAA,MACF;AAAA,IACF;AAEA,QAAI;AACF,YAAM,MAAM,MAAM;AAAA,QAChB;AAAA,QACA,EAAE,kBAAkB,cAAc,YAAY;AAAA,QAC9C;AAAA,QACA;AAAA,MACF;AACA,aAAO,EAAE,S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O;AACT;AAEA,SAAS,uBAAuB,WAA+C;AAC7E,MAAI,CAAC,WAAW;AACd,WAAO;AAAA,EACT;AAEA,QAAM,MAAM,OAAO,SAAS;AAC5B,MAAI,IAAI,WAAW,GAAG;AACpB,WAAO;AAAA,EACT;AAEA,SAAO,GAAG,IAAI,MAAM,GAAG,CAAC,CAAC,IAAI,IAAI,MAAM,GAAG,CAAC,CAAC,IAAI,IAAI,MAAM,GAAG,CAAC,CAAC;AACjE;","names":["issue"]}
|
|
@@ -202,12 +202,52 @@ function toArcaSafeErrorMetadata(error) {
|
|
|
202
202
|
if (!(error instanceof Error)) {
|
|
203
203
|
return { name: "UnknownError", message: String(error) };
|
|
204
204
|
}
|
|
205
|
-
|
|
205
|
+
const metadata = {
|
|
206
206
|
name: error.name,
|
|
207
|
-
message: error.message
|
|
208
|
-
...error instanceof ArcaError ? { code: error.code } : {},
|
|
209
|
-
...error instanceof ArcaTransportError && error.statusCode !== void 0 ? { statusCode: error.statusCode } : {}
|
|
207
|
+
message: error.message
|
|
210
208
|
};
|
|
209
|
+
if (!(error instanceof ArcaError)) {
|
|
210
|
+
return metadata;
|
|
211
|
+
}
|
|
212
|
+
const fields = { code: error.code };
|
|
213
|
+
if (error instanceof ArcaInputError) {
|
|
214
|
+
Object.assign(fields, { field: error.field, expected: error.expected });
|
|
215
|
+
} else if (error instanceof ArcaAuthenticationError) {
|
|
216
|
+
Object.assign(fields, {
|
|
217
|
+
service: error.service,
|
|
218
|
+
operation: error.operation,
|
|
219
|
+
reason: error.reason,
|
|
220
|
+
providerCode: error.providerCode
|
|
221
|
+
});
|
|
222
|
+
} else if (error instanceof ArcaTransportError) {
|
|
223
|
+
Object.assign(fields, {
|
|
224
|
+
statusCode: error.statusCode,
|
|
225
|
+
contentType: error.contentType
|
|
226
|
+
});
|
|
227
|
+
} else if (error instanceof ArcaSoapFaultError) {
|
|
228
|
+
Object.assign(fields, { faultCode: error.faultCode });
|
|
229
|
+
} else if (error instanceof ArcaInvalidSoapResponseError) {
|
|
230
|
+
Object.assign(fields, {
|
|
231
|
+
service: error.service,
|
|
232
|
+
operation: error.operation,
|
|
233
|
+
statusCode: error.statusCode,
|
|
234
|
+
contentType: error.contentType
|
|
235
|
+
});
|
|
236
|
+
} else if (error instanceof ArcaServiceError) {
|
|
237
|
+
Object.assign(fields, {
|
|
238
|
+
service: error.service,
|
|
239
|
+
operation: error.operation,
|
|
240
|
+
serviceCode: error.serviceCode === void 0 ? void 0 : String(error.serviceCode),
|
|
241
|
+
result: error.result,
|
|
242
|
+
resultLevel: error.resultLevel
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
for (const [key, value] of Object.entries(fields)) {
|
|
246
|
+
if (value !== void 0) {
|
|
247
|
+
metadata[key] = value;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
return metadata;
|
|
211
251
|
}
|
|
212
252
|
|
|
213
253
|
export {
|
|
@@ -224,4 +264,4 @@ export {
|
|
|
224
264
|
ArcaServiceError,
|
|
225
265
|
toArcaSafeErrorMetadata
|
|
226
266
|
};
|
|
227
|
-
//# sourceMappingURL=chunk-
|
|
267
|
+
//# sourceMappingURL=chunk-EZ4HA3LC.mjs.map
|
|
@@ -1 +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/** 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_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\nexport type ArcaInputErrorOptions = ErrorOptions & {\n code: ArcaInputErrorCode;\n field?: string;\n expected?: string;\n};\n\n/** Thrown when caller-provided input data is missing or invalid. */\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\n constructor(message: string, options: ArcaInputErrorOptions) {\n super(message, options.code, options);\n this.field = options.field;\n this.expected = options.expected;\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/** Narrow error evidence: never includes a cause, raw response or stack. */\nexport type ArcaSafeErrorMetadata = {\n name: string;\n message: string;\n code?: string;\n statusCode?: number;\n};\n\nexport function toArcaSafeErrorMetadata(error: unknown): ArcaSafeErrorMetadata {\n if (!(error instanceof Error)) {\n return { name: \"UnknownError\", message: String(error) };\n }\n return {\n name: error.name,\n message: error.message,\n ...(error instanceof ArcaError ? { code: error.code } : {}),\n ...(error instanceof ArcaTransportError && error.statusCode !== undefined\n ? { statusCode: error.statusCode }\n : {}),\n };\n}\n"],"mappings":";AAAO,IAAM,gCAAgC;AAE7C,IAAM,+BAA+B;AACrC,IAAM,6BAA6B;AACnC,IAAM,+BAA+B,IAAI;AAAA,EACvC,IAAI,0BAA0B;AAAA,EAC9B;AACF;AACA,IAAM,qCAAqC,IAAI;AAAA,EAC7C,IAAI,0BAA0B;AAAA,EAC9B;AACF;AACA,IAAM,qCAAqC,IAAI;AAAA,EAC7C,IAAI,0BAA0B;AAAA,EAC9B;AACF;AAkBO,SAAS,wBACd,OACA,qBAAqB,+BACb;AACR,QAAM,YAAY,uBAAuB,kBAAkB;AAE3D,SAAO,MACJ;AAAA,IACC;AAAA,IACA,CAAC,QAAQ,YAAoB,IAAI,OAAO,gBAAgB,OAAO;AAAA,EACjE,EACC;AAAA,IACC;AAAA,IACA,CAAC,QAAQ,YAAoB,IAAI,OAAO,gBAAgB,OAAO;AAAA,EACjE,EACC;AAAA,IACC;AAAA,IACA,CAAC,QAAQ,YAAoB,IAAI,OAAO;AAAA,EAC1C,EACC,MAAM,GAAG,SAAS;AACvB;AAGO,SAAS,6BACd,cACA,qBAAqB,+BACG;AACxB,SAAO;AAAA,IACL,oBAAoB,aAAa;AAAA,IACjC,qBAAqB;AAAA,MACnB;AAAA,MACA;AAAA,IACF;AAAA,EACF;AACF;AAGO,SAAS,0BAA0B,OAAqC;AAC7E,MAAI,EAAE,SAAS,OAAO,UAAU,WAAW;AACzC,WAAO,CAAC;AAAA,EACV;AAEA,QAAM,YAAY;AAClB,QAAM,aAAkC,CAAC;AAEzC,mBAAiB,YAAY,aAAa,UAAU,IAAI;AACxD,mBAAiB,YAAY,aAAa,UAAU,IAAI;AACxD,mBAAiB,YAAY,cAAc,UAAU,UAAU;AAC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AqB,SAAS;AACnC,SAAK,sBACH,SAAS,wBAAwB,SAC7B,SACA,wBAAwB,QAAQ,mBAAmB;AAAA,EAC3D;AACF;AAGO,IAAM,mBAAN,cAA+B,UAAU;AAAA,EAC5B,OAAe;AAAA,EACxB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAET,YACE,SACA,SAUA;AACA,UAAM,SAAS,sBAAsB,OAAO;AAC5C,SAAK,cAAc,SAAS;AAC5B,SAAK,UAAU,SAAS;AACxB,SAAK,YAAY,SAAS;AAC1B,SAAK,SAAS,SAAS;AACvB,SAAK,cAAc,SAAS;AAC5B,SAAK,UAAU,SAAS;AACxB,SAAK,MAAM,SAAS;AACpB,SAAK,SAAS,SAAS;AAAA,EACzB;AACF;AAEA,SAAS,sBACP,cAC6B;AAC7B,MAAI,OAAO,iBAAiB,UAAU;AACpC,WAAO,OAAO,SAAS,YAAY,IAAI,eAAe;AAAA,EACxD;AACA,MAAI,OAAO,iBAAiB,UAAU;AACpC,WAAO,wBAAwB,cAAc,GAAG;AAAA,EAClD;AACA,SAAO;AACT;AAUO,SAAS,wBAAwB,OAAuC;AAC7E,MAAI,EAAE,iBAAiB,QAAQ;AAC7B,WAAO,EAAE,MAAM,gBAAgB,SAAS,OAAO,KAAK,EAAE;AAAA,EACxD;AACA,SAAO;AAAA,IACL,MAAM,MAAM;AAAA,IACZ,SAAS,MAAM;AAAA,IACf,GAAI,iBAAiB,YAAY,EAAE,MAAM,MAAM,KAAK,IAAI,CAAC;AAAA,IACzD,GAAI,iBAAiB,sBAAsB,MAAM,eAAe,SAC5D,EAAE,YAAY,MAAM,WAAW,IAC/B,CAAC;AAAA,EACP;AACF;","names":[]}
|
|
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/** 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_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\nexport type ArcaInputErrorOptions = ErrorOptions & {\n code: ArcaInputErrorCode;\n field?: string;\n expected?: string;\n};\n\n/** Thrown when caller-provided input data is missing or invalid. */\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\n constructor(message: string, options: ArcaInputErrorOptions) {\n super(message, options.code, options);\n this.field = options.field;\n this.expected = options.expected;\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 stable reason. */\n reason?: ArcaAuthenticationReason;\n providerCode?: string | number;\n faultCode?: string;\n field?: string;\n expected?: string;\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, { field: error.field, expected: error.expected });\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 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,IAAM,+BAA+B;AACrC,IAAM,6BAA6B;AACnC,IAAM,+BAA+B,IAAI;AAAA,EACvC,IAAI,0BAA0B;AAAA,EAC9B;AACF;AACA,IAAM,qCAAqC,IAAI;AAAA,EAC7C,IAAI,0BAA0B;AAAA,EAC9B;AACF;AACA,IAAM,qCAAqC,IAAI;AAAA,EAC7C,IAAI,0BAA0B;AAAA,EAC9B;AACF;AAkBO,SAAS,wBACd,OACA,qBAAqB,+BACb;AACR,QAAM,YAAY,uBAAuB,kBAAkB;AAE3D,SAAO,MACJ;AAAA,IACC;AAAA,IACA,CAAC,QAAQ,YAAoB,IAAI,OAAO,gBAAgB,OAAO;AAAA,EACjE,EACC;AAAA,IACC;AAAA,IACA,CAAC,QAAQ,YAAoB,IAAI,OAAO,gBAAgB,OAAO;AAAA,EACjE,EACC;AAAA,IACC;AAAA,IACA,CAAC,QAAQ,YAAoB,IAAI,OAAO;AAAA,EAC1C,EACC,MAAM,GAAG,SAAS;AACvB;AAGO,SAAS,6BACd,cACA,qBAAqB,+BACG;AACxB,SAAO;AAAA,IACL,oBAAoB,aAAa;AAAA,IACjC,qBAAqB;AAAA,MACnB;AAAA,MACA;AAAA,IACF;AAAA,EACF;AACF;AAGO,SAAS,0BAA0B,OAAqC;AAC7E,MAAI,EAAE,SAAS,OAAO,UAAU,WAAW;AACzC,WAAO,CAAC;AAAA,EACV;AAEA,QAAM,YAAY;AAClB,QAAM,aAAkC,CAAC;AAEzC,mBAAiB,YAAY,aAAa,UAAU,IAAI;AACxD,mBAAiB,YAAY,aAAa,UAAU,IAAI;AACxD,mBAAiB,YAAY,cAAc,UAAU,UAAU;AAC/D,mBAAiB,YAAY,eAA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M;AAAA,MACd,cAAc,MAAM;AAAA,IACtB,CAAC;AAAA,EACH,WAAW,iBAAiB,oBAAoB;AAC9C,WAAO,OAAO,QAAQ;AAAA,MACpB,YAAY,MAAM;AAAA,MAClB,aAAa,MAAM;AAAA,IACrB,CAAC;AAAA,EACH,WAAW,iBAAiB,oBAAoB;AAC9C,WAAO,OAAO,QAAQ,EAAE,WAAW,MAAM,UAAU,CAAC;AAAA,EACtD,WAAW,iBAAiB,8BAA8B;AACxD,WAAO,OAAO,QAAQ;AAAA,MACpB,SAAS,MAAM;AAAA,MACf,WAAW,MAAM;AAAA,MACjB,YAAY,MAAM;AAAA,MAClB,aAAa,MAAM;AAAA,IACrB,CAAC;AAAA,EACH,WAAW,iBAAiB,kBAAkB;AAC5C,WAAO,OAAO,QAAQ;AAAA,MACpB,SAAS,MAAM;AAAA,MACf,WAAW,MAAM;AAAA,MACjB,aACE,MAAM,gBAAgB,SAAY,SAAY,OAAO,MAAM,WAAW;AAAA,MACxE,QAAQ,MAAM;AAAA,MACd,aAAa,MAAM;AAAA,IACrB,CAAC;AAAA,EACH;AACA,aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,MAAM,GAAG;AACjD,QAAI,UAAU,QAAW;AACvB,MAAC,SAAqC,GAAG,IAAI;AAAA,IAC/C;AAAA,EACF;AACA,SAAO;AACT;","names":[]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
ArcaSoapFaultError
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-EZ4HA3LC.mjs";
|
|
4
4
|
|
|
5
5
|
// src/services/padron.ts
|
|
6
6
|
function createPadronService(options) {
|
|
@@ -25,13 +25,18 @@ function createPadronService(options) {
|
|
|
25
25
|
const idPersona = record.idPersona ?? datosGenerales?.idPersona;
|
|
26
26
|
const tipoPersona = record.tipoPersona ?? datosGenerales?.tipoPersona;
|
|
27
27
|
const taxes = extractPadronTaxes(record);
|
|
28
|
-
const
|
|
28
|
+
const errors = constanciaErrors(record);
|
|
29
|
+
const condition = errors.length > 0 ? void 0 : deriveReceiverCondition(taxes);
|
|
30
|
+
const address = extractPadronAddress(datosGenerales?.domicilioFiscal);
|
|
29
31
|
return {
|
|
30
32
|
taxId: String(idPersona ?? taxId),
|
|
31
33
|
...tipoPersona === void 0 ? {} : { personType: String(tipoPersona) },
|
|
32
34
|
...datosGenerales ? { name: extractPadronName(datosGenerales) } : {},
|
|
35
|
+
...address === void 0 ? {} : { address },
|
|
33
36
|
...condition === void 0 ? {} : { condition },
|
|
34
37
|
taxes,
|
|
38
|
+
activities: extractPadronActivities(record),
|
|
39
|
+
errors,
|
|
35
40
|
raw: record
|
|
36
41
|
};
|
|
37
42
|
},
|
|
@@ -77,9 +82,6 @@ function constanciaErrors(record) {
|
|
|
77
82
|
(message) => typeof message === "string" && message.trim() !== ""
|
|
78
83
|
);
|
|
79
84
|
}
|
|
80
|
-
function hasConstanciaError(record) {
|
|
81
|
-
return constanciaErrors(record).length > 0;
|
|
82
|
-
}
|
|
83
85
|
function isPadronNotFound(record) {
|
|
84
86
|
return constanciaErrors(record).some(
|
|
85
87
|
(message) => NOT_FOUND_PHRASES.some((phrase) => plainText(message).includes(phrase))
|
|
@@ -112,6 +114,64 @@ function extractPadronTaxes(record) {
|
|
|
112
114
|
}
|
|
113
115
|
return taxes;
|
|
114
116
|
}
|
|
117
|
+
function rowsOf(value) {
|
|
118
|
+
return (Array.isArray(value) ? value : value ? [value] : []).filter(
|
|
119
|
+
(row) => row !== null && typeof row === "object"
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
function extractPadronActivities(record) {
|
|
123
|
+
const activities = [];
|
|
124
|
+
const seen = /* @__PURE__ */ new Set();
|
|
125
|
+
for (const [regime, field, key] of [
|
|
126
|
+
["general", "datosRegimenGeneral", "actividad"],
|
|
127
|
+
["monotributo", "datosMonotributo", "actividad"],
|
|
128
|
+
["monotributo", "datosMonotributo", "actividadMonotributista"]
|
|
129
|
+
]) {
|
|
130
|
+
const bucket = record[field];
|
|
131
|
+
for (const row of rowsOf(bucket?.[key])) {
|
|
132
|
+
const activity = toPadronActivity(row, regime);
|
|
133
|
+
if (activity && !seen.has(`${regime}:${activity.id}`)) {
|
|
134
|
+
seen.add(`${regime}:${activity.id}`);
|
|
135
|
+
activities.push(activity);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return activities;
|
|
140
|
+
}
|
|
141
|
+
function toPadronActivity(row, regime) {
|
|
142
|
+
const digits = String(row.idActividad ?? "").replace(/\D/g, "");
|
|
143
|
+
if (digits === "" || Number(digits) === 0) {
|
|
144
|
+
return void 0;
|
|
145
|
+
}
|
|
146
|
+
const order = Number(row.orden);
|
|
147
|
+
const period = String(row.periodo ?? "");
|
|
148
|
+
return {
|
|
149
|
+
id: digits.padStart(6, "0"),
|
|
150
|
+
...typeof row.descripcionActividad === "string" ? { description: row.descripcionActividad } : {},
|
|
151
|
+
...row.orden !== void 0 && Number.isSafeInteger(order) ? { order } : {},
|
|
152
|
+
.../^\d{6}$/.test(period) ? { since: `${period.slice(0, 4)}-${period.slice(4)}` } : {},
|
|
153
|
+
regime
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
function extractPadronAddress(value) {
|
|
157
|
+
if (value === null || typeof value !== "object") {
|
|
158
|
+
return void 0;
|
|
159
|
+
}
|
|
160
|
+
const raw = value;
|
|
161
|
+
const provinceId = raw.idProvincia === void 0 || raw.idProvincia === null ? Number.NaN : Number(raw.idProvincia);
|
|
162
|
+
const address = {
|
|
163
|
+
...optionalText("street", raw.direccion),
|
|
164
|
+
...optionalText("city", raw.localidad),
|
|
165
|
+
...optionalText("postalCode", raw.codPostal),
|
|
166
|
+
...Number.isSafeInteger(provinceId) && String(raw.idProvincia).trim() !== "" ? { provinceId } : {},
|
|
167
|
+
...optionalText("province", raw.descripcionProvincia)
|
|
168
|
+
};
|
|
169
|
+
return Object.keys(address).length === 0 ? void 0 : address;
|
|
170
|
+
}
|
|
171
|
+
function optionalText(key, value) {
|
|
172
|
+
const text = typeof value === "string" ? value.trim() : typeof value === "number" ? String(value) : "";
|
|
173
|
+
return text === "" ? {} : { [key]: text };
|
|
174
|
+
}
|
|
115
175
|
function deriveReceiverCondition(taxes) {
|
|
116
176
|
const conditions = /* @__PURE__ */ new Set();
|
|
117
177
|
for (const tax of taxes) {
|
|
@@ -180,4 +240,4 @@ async function executePadronOperation(options, service, operation, body) {
|
|
|
180
240
|
export {
|
|
181
241
|
createPadronService
|
|
182
242
|
};
|
|
183
|
-
//# sourceMappingURL=chunk-
|
|
243
|
+
//# sourceMappingURL=chunk-MRBFLBWX.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/services/padron.ts"],"sourcesContent":["import type { ReceiverCondition } from \"../constants\";\nimport { ArcaSoapFaultError } from \"../errors\";\nimport type {\n ArcaClientConfig,\n ArcaPadronServiceName,\n} from \"../internal/types\";\nimport type { SoapTransport } from \"../soap\";\nimport type { WsaaAuthModule } from \"../wsaa\";\n\n/** One tax registration reported by the constancia de inscripción. */\nexport type PadronTax = {\n id: number;\n description?: string;\n /** ARCA's state code; `AC` is active. Absent when ARCA omits it. */\n state?: string;\n regime: \"general\" | \"monotributo\";\n};\n\n/** The domicilio fiscal. A field ARCA omits is absent. */\nexport type PadronAddress = {\n street?: string;\n city?: string;\n postalCode?: string;\n /** ARCA's province code, the one invoices and IIBB registrations use. */\n provinceId?: number;\n province?: string;\n};\n\n/** One economic activity registered under a regime. */\nexport type PadronActivity = {\n /** The six-digit NAES code, zero-padded, such as `011211`. */\n id: string;\n description?: string;\n /** ARCA's ordering; `1` is the main activity. */\n order?: number;\n /** The period the activity starts, as `YYYY-MM`. */\n since?: string;\n regime: \"general\" | \"monotributo\";\n};\n\n/** Result of a taxpayer lookup via Padron A5. */\nexport type PadronTaxpayerResult = {\n taxId: string;\n personType?: string;\n name?: string;\n address?: PadronAddress;\n /**\n * The receiver condition to invoice this taxpayer under, derived from its\n * active IVA registrations: 30 is responsable inscripto, 20 monotributo, 32\n * exento and 34 no alcanzado. A taxpayer with none of them is a consumidor\n * final. Absent when the registrations contradict each other or when the\n * constancia reports an error, because then they may be missing.\n */\n condition?: ReceiverCondition;\n taxes: PadronTax[];\n activities: PadronActivity[];\n /**\n * The constancia's own errors, such as an unresolved domicilio. Empty when\n * there are none. A taxpayer with errors has no `condition`.\n */\n errors: string[];\n raw: Record<string, unknown>;\n};\n\n/** Result of a tax ID lookup by document number via Padron A13. */\nexport type PadronTaxIdLookupResult = {\n taxIds: string[];\n raw: Record<string, unknown>;\n};\n\n/** Padron taxpayer registry service. */\nexport type PadronService = {\n /** Looks up taxpayer details by CUIT. Returns `null` if the taxpayer does not exist. */\n getTaxpayerDetails(\n taxId: number | string\n ): Promise<PadronTaxpayerResult | null>;\n /** Looks up CUITs associated with a document number. Returns `null` if not found. */\n getTaxIdByDocument(\n documentNumber: number | string\n ): Promise<PadronTaxIdLookupResult | null>;\n};\n\nexport type CreatePadronServiceOptions = {\n config: ArcaClientConfig;\n auth: WsaaAuthModule;\n soap: SoapTransport;\n};\n\n/** Creates a Padron service instance wired with authentication and SOAP transport. */\nexport function createPadronService(\n options: CreatePadronServiceOptions\n): PadronService {\n return {\n async getTaxpayerDetails(taxId) {\n const raw = await executePadronOperation(\n options,\n \"padron-a5\",\n \"getPersona_v2\",\n {\n idPersona: Number.parseInt(String(taxId), 10),\n }\n );\n if (!raw) {\n return null;\n }\n const record = raw as Record<string, unknown>;\n if (isPadronNotFound(record)) {\n return null;\n }\n const datosGenerales = record.datosGenerales as\n | Record<string, unknown>\n | undefined;\n const idPersona = record.idPersona ?? datosGenerales?.idPersona;\n const tipoPersona = record.tipoPersona ?? datosGenerales?.tipoPersona;\n const taxes = extractPadronTaxes(record);\n const errors = constanciaErrors(record);\n // A constancia with an unresolved error may be missing registrations, so\n // their absence proves nothing about the receiver's condition.\n const condition =\n errors.length > 0 ? undefined : deriveReceiverCondition(taxes);\n const address = extractPadronAddress(datosGenerales?.domicilioFiscal);\n return {\n taxId: String(idPersona ?? taxId),\n ...(tipoPersona === undefined\n ? {}\n : { personType: String(tipoPersona) }),\n ...(datosGenerales ? { name: extractPadronName(datosGenerales) } : {}),\n ...(address === undefined ? {} : { address }),\n ...(condition === undefined ? {} : { condition }),\n taxes,\n activities: extractPadronActivities(record),\n errors,\n raw: record,\n };\n },\n async getTaxIdByDocument(documentNumber) {\n const raw = await executePadronOperation(\n options,\n \"padron-a13\",\n \"getIdPersonaListByDocumento\",\n {\n documento: String(documentNumber),\n }\n );\n if (!raw) {\n return null;\n }\n const record = raw as Record<string, unknown>;\n const idPersona = record.idPersona;\n const taxIds = Array.isArray(idPersona)\n ? idPersona.map(String)\n : idPersona === undefined\n ? []\n : [String(idPersona)];\n return {\n taxIds,\n raw: record,\n };\n },\n };\n}\n\nconst IVA_TAX_CONDITIONS: Readonly<Record<number, ReceiverCondition>> = {\n 20: \"monotributo\",\n 30: \"responsable_inscripto\",\n 32: \"exento\",\n 34: \"no_alcanzado\",\n};\n\n// The constancia answers a missing CUIT inside errorConstancia, not as a fault.\nconst NOT_FOUND_PHRASES = [\n \"la clave solicitada no existe\",\n \"no existe persona con ese id\",\n \"no existe persona con esa clave\",\n \"persona no encontrada\",\n \"no se encontro informacion para la clave\",\n];\n\nfunction constanciaErrors(record: Record<string, unknown>): string[] {\n const errorConstancia = record.errorConstancia as\n | { error?: unknown }\n | undefined;\n const errors = errorConstancia?.error;\n return (Array.isArray(errors) ? errors : [errors]).filter(\n (message): message is string =>\n typeof message === \"string\" && message.trim() !== \"\"\n );\n}\n\nfunction isPadronNotFound(record: Record<string, unknown>): boolean {\n return constanciaErrors(record).some((message) =>\n NOT_FOUND_PHRASES.some((phrase) => plainText(message).includes(phrase))\n );\n}\n\nfunction plainText(value: string): string {\n return value\n .normalize(\"NFD\")\n .replace(/\\p{Diacritic}/gu, \"\")\n .toLowerCase();\n}\n\nfunction extractPadronTaxes(record: Record<string, unknown>): PadronTax[] {\n const taxes: PadronTax[] = [];\n for (const [regime, field] of [\n [\"general\", \"datosRegimenGeneral\"],\n [\"monotributo\", \"datosMonotributo\"],\n ] as const) {\n const bucket = record[field] as { impuesto?: unknown } | undefined;\n const rows = bucket?.impuesto;\n for (const row of Array.isArray(rows) ? rows : rows ? [rows] : []) {\n const tax = row as Record<string, unknown>;\n const id = Number(tax.idImpuesto);\n if (!Number.isSafeInteger(id)) {\n continue;\n }\n taxes.push({\n id,\n ...(typeof tax.descripcionImpuesto === \"string\"\n ? { description: tax.descripcionImpuesto }\n : {}),\n ...(typeof tax.estadoImpuesto === \"string\"\n ? { state: tax.estadoImpuesto.trim().toUpperCase() }\n : {}),\n regime,\n });\n }\n }\n return taxes;\n}\n\nfunction rowsOf(value: unknown): Record<string, unknown>[] {\n return (Array.isArray(value) ? value : value ? [value] : []).filter(\n (row): row is Record<string, unknown> =>\n row !== null && typeof row === \"object\"\n );\n}\n\nfunction extractPadronActivities(\n record: Record<string, unknown>\n): PadronActivity[] {\n const activities: PadronActivity[] = [];\n const seen = new Set<string>();\n for (const [regime, field, key] of [\n [\"general\", \"datosRegimenGeneral\", \"actividad\"],\n [\"monotributo\", \"datosMonotributo\", \"actividad\"],\n [\"monotributo\", \"datosMonotributo\", \"actividadMonotributista\"],\n ] as const) {\n const bucket = record[field] as Record<string, unknown> | undefined;\n for (const row of rowsOf(bucket?.[key])) {\n const activity = toPadronActivity(row, regime);\n if (activity && !seen.has(`${regime}:${activity.id}`)) {\n seen.add(`${regime}:${activity.id}`);\n activities.push(activity);\n }\n }\n }\n return activities;\n}\n\n// ARCA answers the NAES code as a number, which drops its leading zero.\nfunction toPadronActivity(\n row: Record<string, unknown>,\n regime: PadronActivity[\"regime\"]\n): PadronActivity | undefined {\n const digits = String(row.idActividad ?? \"\").replace(/\\D/g, \"\");\n if (digits === \"\" || Number(digits) === 0) {\n return undefined;\n }\n const order = Number(row.orden);\n const period = String(row.periodo ?? \"\");\n return {\n id: digits.padStart(6, \"0\"),\n ...(typeof row.descripcionActividad === \"string\"\n ? { description: row.descripcionActividad }\n : {}),\n ...(row.orden !== undefined && Number.isSafeInteger(order)\n ? { order }\n : {}),\n ...(/^\\d{6}$/.test(period)\n ? { since: `${period.slice(0, 4)}-${period.slice(4)}` }\n : {}),\n regime,\n };\n}\n\nfunction extractPadronAddress(value: unknown): PadronAddress | undefined {\n if (value === null || typeof value !== \"object\") {\n return undefined;\n }\n const raw = value as Record<string, unknown>;\n const provinceId =\n raw.idProvincia === undefined || raw.idProvincia === null\n ? Number.NaN\n : Number(raw.idProvincia);\n const address: PadronAddress = {\n ...optionalText(\"street\", raw.direccion),\n ...optionalText(\"city\", raw.localidad),\n ...optionalText(\"postalCode\", raw.codPostal),\n ...(Number.isSafeInteger(provinceId) &&\n String(raw.idProvincia).trim() !== \"\"\n ? { provinceId }\n : {}),\n ...optionalText(\"province\", raw.descripcionProvincia),\n };\n return Object.keys(address).length === 0 ? undefined : address;\n}\n\nfunction optionalText<K extends string>(\n key: K,\n value: unknown\n): Partial<Record<K, string>> {\n const text =\n typeof value === \"string\"\n ? value.trim()\n : typeof value === \"number\"\n ? String(value)\n : \"\";\n return text === \"\" ? {} : ({ [key]: text } as Record<K, string>);\n}\n\n/** One active IVA registration decides; none is a consumidor final; two is nobody's call. */\nfunction deriveReceiverCondition(\n taxes: readonly PadronTax[]\n): ReceiverCondition | undefined {\n const conditions = new Set<ReceiverCondition>();\n for (const tax of taxes) {\n const condition = IVA_TAX_CONDITIONS[tax.id];\n if (condition && (tax.state === undefined || tax.state === \"AC\")) {\n conditions.add(condition);\n }\n }\n if (conditions.size === 0) {\n return \"consumidor_final\";\n }\n return conditions.size === 1 ? [...conditions][0] : undefined;\n}\n\nfunction extractPadronName(\n datosGenerales: Record<string, unknown>\n): string | undefined {\n if (typeof datosGenerales.razonSocial === \"string\") {\n return datosGenerales.razonSocial;\n }\n const nombre = datosGenerales.nombre;\n const apellido = datosGenerales.apellido;\n if (typeof apellido === \"string\" && typeof nombre === \"string\") {\n return `${apellido} ${nombre}`.trim();\n }\n if (typeof apellido === \"string\") {\n return apellido;\n }\n if (typeof nombre === \"string\") {\n return nombre;\n }\n return undefined;\n}\n\nasync function executePadronOperation(\n options: CreatePadronServiceOptions,\n service: ArcaPadronServiceName,\n operation: string,\n body: Record<string, unknown>\n) {\n const auth = await options.auth.login(\n service === \"padron-a5\"\n ? \"ws_sr_constancia_inscripcion\"\n : \"ws_sr_padron_a13\"\n );\n\n try {\n const response = await options.soap.execute<\n Record<string, unknown>,\n Record<string, unknown>\n >({\n service,\n operation,\n bodyElementNamespaceMode: \"prefix\",\n body: {\n token: auth.token,\n sign: auth.sign,\n cuitRepresentada: Number.parseInt(options.config.taxId, 10),\n ...body,\n },\n });\n\n const operationResponse = response.result as Record<string, unknown>;\n\n if (operation === \"getPersona_v2\") {\n return operationResponse.personaReturn ?? null;\n }\n\n if (operation === \"getIdPersonaListByDocumento\") {\n return operationResponse.idPersonaListReturn ?? null;\n }\n\n return operationResponse.return ?? null;\n } catch (error) {\n if (\n error instanceof ArcaSoapFaultError &&\n // Public Padron A5/A13 WSDLs expose only a generic validation fault, so\n // there is no documented not-found-specific fault code to match here.\n // Keep the current message fallback, but treat it as fragile.\n error.message.toLowerCase().includes(\"no existe\")\n ) {\n return null;\n }\n\n throw error;\n }\n}\n"],"mappings":";;;;;AAyFO,SAAS,oBACd,SACe;AACf,SAAO;AAAA,IACL,MAAM,mBAAmB,OAAO;AAC9B,YAAM,MAAM,MAAM;AAAA,QAChB;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,UACE,WAAW,OAAO,SAAS,OAAO,KAAK,GAAG,EAAE;AAAA,QAC9C;AAAA,MACF;AACA,UAAI,CAAC,KAAK;AACR,eAAO;AAAA,MACT;AACA,YAAM,SAAS;AACf,UAAI,iBAAiB,MAAM,GAAG;AAC5B,eAAO;AAAA,MACT;AACA,YAAM,iBAAiB,OAAO;AAG9B,YAAM,YAAY,OAAO,aAAa,gBAA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executeWithAuthenticationRecovery
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-WPHD2GQJ.mjs";
|
|
7
7
|
import {
|
|
8
8
|
ArcaInputError,
|
|
9
9
|
ArcaInvalidSoapResponseError,
|
|
10
10
|
ArcaServiceError,
|
|
11
11
|
ArcaSoapFaultError,
|
|
12
12
|
ArcaTransportError
|
|
13
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-EZ4HA3LC.mjs";
|
|
14
|
+
|
|
15
|
+
// src/internal/dates.ts
|
|
16
|
+
function toIsoDate(value) {
|
|
17
|
+
if (typeof value !== "string" && typeof value !== "number") {
|
|
18
|
+
return void 0;
|
|
19
|
+
}
|
|
20
|
+
const text = String(value).trim();
|
|
21
|
+
if (/^\d{4}-\d{2}-\d{2}$/.test(text)) {
|
|
22
|
+
return text;
|
|
23
|
+
}
|
|
24
|
+
if (/^\d{8}$/.test(text)) {
|
|
25
|
+
return `${text.slice(0, 4)}-${text.slice(4, 6)}-${text.slice(6, 8)}`;
|
|
26
|
+
}
|
|
27
|
+
return void 0;
|
|
28
|
+
}
|
|
14
29
|
|
|
15
30
|
// src/internal/decimal.ts
|
|
16
31
|
var AMOUNT_SCALE = 100;
|
|
@@ -511,10 +526,6 @@ function createWsfeService(options) {
|
|
|
511
526
|
const raw = result.ResultGet ?? {};
|
|
512
527
|
return mapWsfeQuotation(raw);
|
|
513
528
|
},
|
|
514
|
-
async getVoucherInfo(input) {
|
|
515
|
-
const lookup = await lookupVoucher(input);
|
|
516
|
-
return lookup.kind === "found" ? lookup.voucher : null;
|
|
517
|
-
},
|
|
518
529
|
lookupVoucher
|
|
519
530
|
};
|
|
520
531
|
}
|
|
@@ -944,11 +955,12 @@ function assertValidCalendarDate(yearInput, monthInput, dayInput, fieldName) {
|
|
|
944
955
|
}
|
|
945
956
|
function mapWsfeSalesPoint(raw) {
|
|
946
957
|
const record = raw;
|
|
958
|
+
const deletedAt = toIsoDate(record.FchBaja);
|
|
947
959
|
return {
|
|
948
960
|
number: Number(record.Nro ?? 0),
|
|
949
961
|
...record.EmisionTipo === void 0 ? {} : { emissionType: String(record.EmisionTipo) },
|
|
950
|
-
|
|
951
|
-
...
|
|
962
|
+
blocked: String(record.Bloqueado ?? "N").trim().toUpperCase() === "S",
|
|
963
|
+
...deletedAt === void 0 ? {} : { deletedAt }
|
|
952
964
|
};
|
|
953
965
|
}
|
|
954
966
|
function mapWsfeCatalogEntry(raw) {
|
|
@@ -1438,6 +1450,7 @@ function getWsfeResultEntries(result, key) {
|
|
|
1438
1450
|
}
|
|
1439
1451
|
|
|
1440
1452
|
export {
|
|
1453
|
+
toIsoDate,
|
|
1441
1454
|
normalizeArcaAmountToMinorUnits,
|
|
1442
1455
|
serializeArcaExchangeRate,
|
|
1443
1456
|
assertArcaMinorUnits,
|
|
@@ -1448,4 +1461,4 @@ export {
|
|
|
1448
1461
|
normalizeWsfeVoucherInput,
|
|
1449
1462
|
normalizeWsfeDateInput
|
|
1450
1463
|
};
|
|
1451
|
-
//# sourceMappingURL=chunk-
|
|
1464
|
+
//# sourceMappingURL=chunk-OORNZFI5.mjs.map
|