facturas 0.12.2 → 0.12.4
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/dist/{chunk-D5ZWXTCV.mjs → chunk-3EJINDBP.mjs} +4 -4
- package/dist/{chunk-D5ZWXTCV.mjs.map → chunk-3EJINDBP.mjs.map} +1 -1
- package/dist/{chunk-BP72XNPS.mjs → chunk-7V5S3ISG.mjs} +135 -40
- package/dist/chunk-7V5S3ISG.mjs.map +1 -0
- package/dist/{chunk-ZOSNASXB.mjs → chunk-BYEP3ABS.mjs} +1 -1
- package/dist/chunk-BYEP3ABS.mjs.map +1 -0
- package/dist/{chunk-UDX6HLAU.mjs → chunk-PHXH34L6.mjs} +2 -2
- package/dist/{chunk-7LEKQ4P7.mjs → chunk-WVKVJTFG.mjs} +2 -2
- package/dist/{chunk-QHYJ424J.mjs → chunk-YYDSBHMO.mjs} +3 -3
- package/dist/{chunk-VGNLXU4T.mjs → chunk-ZZDL6I56.mjs} +3 -3
- package/dist/cli.d.ts +3 -3
- package/dist/cli.mjs +6 -6
- package/dist/{client-DbK78fyQ.d.ts → client-tzfxAy7w.d.ts} +47 -42
- package/dist/{decimal-xie0oMOQ.d.ts → decimal-CgWMOiAC.d.ts} +1 -1
- package/dist/errors.d.ts +1 -1
- package/dist/errors.mjs +1 -1
- package/dist/{fiscal-evidence-Dpj-Iao8.d.ts → fiscal-evidence-DXl_U1uz.d.ts} +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.mjs +7 -7
- package/dist/padron.mjs +2 -2
- package/dist/wsfe.d.ts +3 -3
- package/dist/wsfe.mjs +4 -4
- package/dist/wsmtxca.d.ts +1 -1
- package/dist/wsmtxca.mjs +3 -3
- package/package.json +1 -1
- package/dist/chunk-BP72XNPS.mjs.map +0 -1
- package/dist/chunk-ZOSNASXB.mjs.map +0 -1
- /package/dist/{chunk-UDX6HLAU.mjs.map → chunk-PHXH34L6.mjs.map} +0 -0
- /package/dist/{chunk-7LEKQ4P7.mjs.map → chunk-WVKVJTFG.mjs.map} +0 -0
- /package/dist/{chunk-QHYJ424J.mjs.map → chunk-YYDSBHMO.mjs.map} +0 -0
- /package/dist/{chunk-VGNLXU4T.mjs.map → chunk-ZZDL6I56.mjs.map} +0 -0
|
@@ -3,14 +3,14 @@ import {
|
|
|
3
3
|
classifyArcaAuthenticationIssues,
|
|
4
4
|
createArcaAuthenticationEvidence,
|
|
5
5
|
executeWithAuthenticationRecovery
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-PHXH34L6.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-BYEP3ABS.mjs";
|
|
14
14
|
|
|
15
15
|
// src/services/wsmtxca.ts
|
|
16
16
|
function createWsmtxcaService(options) {
|
|
@@ -560,7 +560,7 @@ function mapWsmtxcaVoucherInfo(raw) {
|
|
|
560
560
|
assignWsmtxcaValue(
|
|
561
561
|
voucher,
|
|
562
562
|
"taxAmount",
|
|
563
|
-
parseOptionalNumber(raw.importeOtrosTributos)
|
|
563
|
+
parseOptionalNumber(raw.importeOtrosTributos) ?? (raw.arrayOtrosTributos === void 0 ? 0 : void 0)
|
|
564
564
|
);
|
|
565
565
|
assignWsmtxcaValue(voucher, "vatAmount", vatAmount);
|
|
566
566
|
assignWsmtxcaValue(
|
|
@@ -655,4 +655,4 @@ function formatCompactDateToIso(dateValue) {
|
|
|
655
655
|
export {
|
|
656
656
|
createWsmtxcaService
|
|
657
657
|
};
|
|
658
|
-
//# sourceMappingURL=chunk-
|
|
658
|
+
//# sourceMappingURL=chunk-3EJINDBP.mjs.map
|
|
@@ -1 +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 data for one WSMTXCA voucher authorization. */\nexport type WsmtxcaAuthorizeVoucherInput = {\n representedTaxId?: ArcaRepresentedTaxId;\n data: Record<string, unknown>;\n forceRefresh?: boolean;\n /** Aborts login, submission and consultation with the caller's deadline. */\n signal?: 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/** Result of looking up a specific WSMTXCA voucher. */\nexport type WsmtxcaVoucherLookupResult = {\n invoiceDate: string;\n voucher: Record<string, unknown>;\n messages: string[];\n raw: Record<string, unknown>;\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(\n input: WsmtxcaAuthorizeVoucherInput\n ): 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 signal?: 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 signal?: AbortSignal;\n }): Promise<WsmtxcaVoucherLookupOutcome>;\n /** Retrieves details for a specific voucher. */\n getVoucher(input: {\n representedTaxId?: ArcaRepresentedTaxId;\n voucherType: number;\n salesPoint: number;\n voucherNumber: number;\n forceRefresh?: boolean;\n }): Promise<WsmtxcaVoucherLookupResult>;\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 signal?: 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 signal: input.signal,\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.signal,\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 signal,\n }: WsmtxcaAuthorizeVoucherInput): 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, signal },\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: WsmtxcaAuthorizeVoucherInput\n ): Promise<WsmtxcaAuthorizationOutcome> {\n return (await executeWsmtxcaAuthorization(input)).outcome;\n }\n\n function getLastAuthorizedVoucher({\n representedTaxId,\n voucherType,\n salesPoint,\n forceRefresh,\n signal,\n }: {\n representedTaxId?: ArcaRepresentedTaxId;\n voucherType: number;\n salesPoint: number;\n forceRefresh?: boolean;\n signal?: 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 signal,\n }),\n });\n }\n\n async function getLastAuthorizedVoucherOnce({\n representedTaxId,\n voucherType,\n salesPoint,\n forceRefresh,\n signal,\n }: {\n representedTaxId?: ArcaRepresentedTaxId;\n voucherType: number;\n salesPoint: number;\n forceRefresh?: boolean;\n signal?: AbortSignal;\n }): Promise<WsmtxcaLastAuthorizedVoucherResult> {\n const operation = \"consultarUltimoComprobanteAutorizado\";\n const raw = await executeWsmtxcaAuthenticatedOperation(\n operation,\n { representedTaxId, forceRefresh, signal },\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 signal,\n }: {\n representedTaxId?: ArcaRepresentedTaxId;\n voucherType: number;\n salesPoint: number;\n voucherNumber: number;\n forceRefresh?: boolean;\n signal?: 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 signal,\n }),\n });\n }\n\n async function lookupVoucherOnce({\n representedTaxId,\n voucherType,\n salesPoint,\n voucherNumber,\n forceRefresh,\n signal,\n }: {\n representedTaxId?: ArcaRepresentedTaxId;\n voucherType: number;\n salesPoint: number;\n voucherNumber: number;\n forceRefresh?: boolean;\n signal?: AbortSignal;\n }): Promise<WsmtxcaVoucherLookupOutcome> {\n const operation = \"consultarComprobante\";\n const raw = await executeWsmtxcaAuthenticatedOperation(\n operation,\n { representedTaxId, forceRefresh, signal },\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 async function getVoucher(input: {\n representedTaxId?: ArcaRepresentedTaxId;\n voucherType: number;\n salesPoint: number;\n voucherNumber: number;\n forceRefresh?: boolean;\n }): Promise<WsmtxcaVoucherLookupResult> {\n const lookup = await lookupVoucher(input);\n if (lookup.kind === \"not_found\") {\n throw createWsmtxcaServiceError(lookup.operation, lookup.errors);\n }\n\n const invoiceDate = lookup.voucher.invoiceDate;\n if (!invoiceDate) {\n throw new ArcaServiceError(\n formatWsmtxcaIssues(lookup.observations)[0] ??\n \"WSMTXCA did not return the voucher issue date\",\n {\n service: \"wsmtxca\",\n operation: lookup.operation,\n issues: lookup.observations,\n }\n );\n }\n\n return {\n invoiceDate,\n voucher: lookup.voucher.raw,\n messages: formatWsmtxcaIssues(lookup.observations),\n raw: lookup.raw,\n };\n }\n\n return {\n issue,\n getLastAuthorizedVoucher,\n getSalesPoints,\n lookupVoucher,\n getVoucher,\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 assignWsmtxcaValue(\n voucher,\n \"taxAmount\",\n parseOptionalNumber(raw.importeOtrosTributos)\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":";;;;;;;;;;;;;;;AA4IO,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,QAAQ,MAAM;AAAA,IAChB,CAAC;AACD,UAAM,WAAW,MAAM,QA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M,GAAG,EAAE;AAAA,EAC5B;AAEA,SAAO;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"]}
|
|
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 data for one WSMTXCA voucher authorization. */\nexport type WsmtxcaAuthorizeVoucherInput = {\n representedTaxId?: ArcaRepresentedTaxId;\n data: Record<string, unknown>;\n forceRefresh?: boolean;\n /** Aborts login, submission and consultation with the caller's deadline. */\n signal?: 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/** Result of looking up a specific WSMTXCA voucher. */\nexport type WsmtxcaVoucherLookupResult = {\n invoiceDate: string;\n voucher: Record<string, unknown>;\n messages: string[];\n raw: Record<string, unknown>;\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(\n input: WsmtxcaAuthorizeVoucherInput\n ): 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 signal?: 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 signal?: AbortSignal;\n }): Promise<WsmtxcaVoucherLookupOutcome>;\n /** Retrieves details for a specific voucher. */\n getVoucher(input: {\n representedTaxId?: ArcaRepresentedTaxId;\n voucherType: number;\n salesPoint: number;\n voucherNumber: number;\n forceRefresh?: boolean;\n }): Promise<WsmtxcaVoucherLookupResult>;\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 signal?: 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 signal: input.signal,\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.signal,\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 signal,\n }: WsmtxcaAuthorizeVoucherInput): 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, signal },\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: WsmtxcaAuthorizeVoucherInput\n ): Promise<WsmtxcaAuthorizationOutcome> {\n return (await executeWsmtxcaAuthorization(input)).outcome;\n }\n\n function getLastAuthorizedVoucher({\n representedTaxId,\n voucherType,\n salesPoint,\n forceRefresh,\n signal,\n }: {\n representedTaxId?: ArcaRepresentedTaxId;\n voucherType: number;\n salesPoint: number;\n forceRefresh?: boolean;\n signal?: 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 signal,\n }),\n });\n }\n\n async function getLastAuthorizedVoucherOnce({\n representedTaxId,\n voucherType,\n salesPoint,\n forceRefresh,\n signal,\n }: {\n representedTaxId?: ArcaRepresentedTaxId;\n voucherType: number;\n salesPoint: number;\n forceRefresh?: boolean;\n signal?: AbortSignal;\n }): Promise<WsmtxcaLastAuthorizedVoucherResult> {\n const operation = \"consultarUltimoComprobanteAutorizado\";\n const raw = await executeWsmtxcaAuthenticatedOperation(\n operation,\n { representedTaxId, forceRefresh, signal },\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 signal,\n }: {\n representedTaxId?: ArcaRepresentedTaxId;\n voucherType: number;\n salesPoint: number;\n voucherNumber: number;\n forceRefresh?: boolean;\n signal?: 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 signal,\n }),\n });\n }\n\n async function lookupVoucherOnce({\n representedTaxId,\n voucherType,\n salesPoint,\n voucherNumber,\n forceRefresh,\n signal,\n }: {\n representedTaxId?: ArcaRepresentedTaxId;\n voucherType: number;\n salesPoint: number;\n voucherNumber: number;\n forceRefresh?: boolean;\n signal?: AbortSignal;\n }): Promise<WsmtxcaVoucherLookupOutcome> {\n const operation = \"consultarComprobante\";\n const raw = await executeWsmtxcaAuthenticatedOperation(\n operation,\n { representedTaxId, forceRefresh, signal },\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 async function getVoucher(input: {\n representedTaxId?: ArcaRepresentedTaxId;\n voucherType: number;\n salesPoint: number;\n voucherNumber: number;\n forceRefresh?: boolean;\n }): Promise<WsmtxcaVoucherLookupResult> {\n const lookup = await lookupVoucher(input);\n if (lookup.kind === \"not_found\") {\n throw createWsmtxcaServiceError(lookup.operation, lookup.errors);\n }\n\n const invoiceDate = lookup.voucher.invoiceDate;\n if (!invoiceDate) {\n throw new ArcaServiceError(\n formatWsmtxcaIssues(lookup.observations)[0] ??\n \"WSMTXCA did not return the voucher issue date\",\n {\n service: \"wsmtxca\",\n operation: lookup.operation,\n issues: lookup.observations,\n }\n );\n }\n\n return {\n invoiceDate,\n voucher: lookup.voucher.raw,\n messages: formatWsmtxcaIssues(lookup.observations),\n raw: lookup.raw,\n };\n }\n\n return {\n issue,\n getLastAuthorizedVoucher,\n getSalesPoints,\n lookupVoucher,\n getVoucher,\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":";;;;;;;;;;;;;;;AA4IO,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,QAAQ,MAAM;AAAA,IAChB,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,OAAO;AAAA,QAC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Ac;AACvB;AAEA,SAAS,mBACP,QACA,KACA,OACA;AACA,MAAI,UAAU,QAAW;AACvB,WAAO,GAAG,IAAI;AAAA,EAChB;AACF;AAEA,SAAS,6BAA6B,OAAoC;AACxE,MAAI,OAAO,UAAU,YAAY,OAAO,UAAU,KAAK,GAAG;AACxD,WAAO,uBAAuB,KAAK;AAAA,EACrC;AAEA,MAAI,OAAO,UAAU,UAAU;AAC7B,WAAO;AAAA,EACT;AAEA,QAAM,UAAU,MAAM,KAAK;AAC3B,MAAI,CAAC,SAAS;AACZ,WAAO;AAAA,EACT;AAEA,MAAI,UAAU,KAAK,OAAO,GAAG;AAC3B,WAAO,uBAAuB,OAAO,SAAS,SAAS,EAAE,CAAC;AAAA,EAC5D;AAEA,MAAI,qBAAqB,KAAK,OAAO,GAAG;AACtC,WAAO,QAAQ,MAAM,GAAG,EAAE;AAAA,EAC5B;AAEA,SAAO;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"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createPadronService
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-WVKVJTFG.mjs";
|
|
4
4
|
import {
|
|
5
5
|
arcaMinorUnitsToNumber,
|
|
6
6
|
assertArcaMinorUnits,
|
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
normalizeWsfeDateInput,
|
|
12
12
|
normalizeWsfeVoucherInput,
|
|
13
13
|
serializeArcaExchangeRate
|
|
14
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-YYDSBHMO.mjs";
|
|
15
15
|
import {
|
|
16
16
|
ARCA_CURRENCY_IDS,
|
|
17
17
|
ARCA_DOCUMENT_TYPES,
|
|
@@ -23,7 +23,7 @@ import {
|
|
|
23
23
|
} from "./chunk-GX5ERXT6.mjs";
|
|
24
24
|
import {
|
|
25
25
|
createWsmtxcaService
|
|
26
|
-
} from "./chunk-
|
|
26
|
+
} from "./chunk-3EJINDBP.mjs";
|
|
27
27
|
import {
|
|
28
28
|
ArcaConfigurationError,
|
|
29
29
|
ArcaError,
|
|
@@ -35,7 +35,7 @@ import {
|
|
|
35
35
|
createResponseBodyDiagnostic,
|
|
36
36
|
createSafeErrorDiagnostic,
|
|
37
37
|
toArcaSafeErrorMetadata
|
|
38
|
-
} from "./chunk-
|
|
38
|
+
} from "./chunk-BYEP3ABS.mjs";
|
|
39
39
|
|
|
40
40
|
// src/config.ts
|
|
41
41
|
var ARCA_ENVIRONMENTS = ["production", "test"];
|
|
@@ -1882,6 +1882,10 @@ function wsmtxcaRequest(data, number) {
|
|
|
1882
1882
|
"Item totals must equal the voucher total excluding tributes"
|
|
1883
1883
|
);
|
|
1884
1884
|
}
|
|
1885
|
+
const tributes = data.taxes?.length ? data.taxes : void 0;
|
|
1886
|
+
if (tributes === void 0 && normalizeArcaAmountToMinorUnits(data.taxAmount, "taxes") !== 0n) {
|
|
1887
|
+
invalid("taxes", "Tribute amount requires tribute details");
|
|
1888
|
+
}
|
|
1885
1889
|
return {
|
|
1886
1890
|
comprobanteCAERequest: {
|
|
1887
1891
|
codigoTipoComprobante: data.voucherType,
|
|
@@ -1897,7 +1901,7 @@ function wsmtxcaRequest(data, number) {
|
|
|
1897
1901
|
importeSubtotal: Number(
|
|
1898
1902
|
normalizeArcaAmountToMinorUnits(data.netAmount, "net") + normalizeArcaAmountToMinorUnits(data.nonTaxableAmount, "untaxed") + normalizeArcaAmountToMinorUnits(data.exemptAmount, "exempt")
|
|
1899
1903
|
) / 100,
|
|
1900
|
-
importeOtrosTributos: data.taxAmount,
|
|
1904
|
+
...tributes === void 0 ? {} : { importeOtrosTributos: data.taxAmount },
|
|
1901
1905
|
importeTotal: data.totalAmount,
|
|
1902
1906
|
codigoMoneda: data.currencyId,
|
|
1903
1907
|
cotizacionMoneda: data.exchangeRate,
|
|
@@ -1928,14 +1932,16 @@ function wsmtxcaRequest(data, number) {
|
|
|
1928
1932
|
porcentaje: b.percentage
|
|
1929
1933
|
}))
|
|
1930
1934
|
} : void 0,
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1935
|
+
...tributes ? {
|
|
1936
|
+
arrayOtrosTributos: {
|
|
1937
|
+
otroTributo: tributes.map((t) => ({
|
|
1938
|
+
codigo: t.id,
|
|
1939
|
+
descripcion: t.description,
|
|
1940
|
+
baseImponible: t.baseAmount,
|
|
1941
|
+
importe: t.amount
|
|
1942
|
+
}))
|
|
1943
|
+
}
|
|
1944
|
+
} : {},
|
|
1939
1945
|
arrayItems: { item: items },
|
|
1940
1946
|
arraySubtotalesIVA: data.vatRates?.length ? {
|
|
1941
1947
|
subtotalIVA: data.vatRates.map((v) => ({
|
|
@@ -3652,10 +3658,11 @@ async function previewNote(wsfe, input, inputOptions, context, kind) {
|
|
|
3652
3658
|
["representedTaxId", "service", "forceRefresh"],
|
|
3653
3659
|
"options"
|
|
3654
3660
|
);
|
|
3655
|
-
|
|
3656
|
-
|
|
3657
|
-
options
|
|
3658
|
-
|
|
3661
|
+
const prepared = await prepareNote(wsfe, input, options, context, kind);
|
|
3662
|
+
return {
|
|
3663
|
+
...toPreview(prepared, options),
|
|
3664
|
+
...prepared.original === void 0 ? {} : { original: prepared.original }
|
|
3665
|
+
};
|
|
3659
3666
|
}
|
|
3660
3667
|
async function prepareNote(wsfe, input, options, context, kind) {
|
|
3661
3668
|
validateOptions(options);
|
|
@@ -3708,7 +3715,7 @@ async function prepareNote(wsfe, input, options, context, kind) {
|
|
|
3708
3715
|
}
|
|
3709
3716
|
}
|
|
3710
3717
|
validatePrepared(prepared, options);
|
|
3711
|
-
return prepared;
|
|
3718
|
+
return { ...prepared, original: toVoucherSummary(original.voucher) };
|
|
3712
3719
|
}
|
|
3713
3720
|
function preparePeriodNote(input, options, kind) {
|
|
3714
3721
|
const { associatedPeriod, ...invoice } = input;
|
|
@@ -3763,7 +3770,7 @@ async function recoverOperation(select, key, inputOptions, context) {
|
|
|
3763
3770
|
);
|
|
3764
3771
|
if (json === null) {
|
|
3765
3772
|
throw new ArcaInputError("No reservation exists for this idempotency key", {
|
|
3766
|
-
code: "
|
|
3773
|
+
code: "ARCA_INPUT_RESERVATION_NOT_FOUND",
|
|
3767
3774
|
field: "idempotencyKey"
|
|
3768
3775
|
});
|
|
3769
3776
|
}
|
|
@@ -4082,10 +4089,12 @@ function createArcaClient(config = {}) {
|
|
|
4082
4089
|
// src/store/file.ts
|
|
4083
4090
|
import { createHash as createHash3, randomUUID as randomUUID2 } from "crypto";
|
|
4084
4091
|
import {
|
|
4092
|
+
link,
|
|
4085
4093
|
mkdir,
|
|
4094
|
+
open,
|
|
4086
4095
|
readFile,
|
|
4087
4096
|
rename,
|
|
4088
|
-
|
|
4097
|
+
rmdir,
|
|
4089
4098
|
stat,
|
|
4090
4099
|
unlink,
|
|
4091
4100
|
writeFile
|
|
@@ -4188,35 +4197,28 @@ function fileLease(directory, ensure) {
|
|
|
4188
4197
|
owner,
|
|
4189
4198
|
expiresAt: new Date(Date.now() + ARCA_LEASE_MS).toISOString()
|
|
4190
4199
|
});
|
|
4191
|
-
const read = async () => {
|
|
4192
|
-
try {
|
|
4193
|
-
return JSON.parse(await readFile(holder, "utf8"));
|
|
4194
|
-
} catch {
|
|
4195
|
-
return null;
|
|
4196
|
-
}
|
|
4197
|
-
};
|
|
4198
4200
|
return {
|
|
4199
4201
|
acquire: (owner) => storeCall(async () => {
|
|
4200
4202
|
await ensure();
|
|
4201
4203
|
if (!await createDirectory(directory)) {
|
|
4202
|
-
|
|
4204
|
+
const current = await readHolder(holder);
|
|
4205
|
+
if (await stillHeld(directory, current?.value ?? null)) {
|
|
4203
4206
|
return false;
|
|
4204
4207
|
}
|
|
4205
|
-
|
|
4206
|
-
|
|
4207
|
-
|
|
4208
|
+
if (current) {
|
|
4209
|
+
await retireHolder(directory, holder, current.raw);
|
|
4210
|
+
} else {
|
|
4211
|
+
await removeEmptyDirectory(directory);
|
|
4208
4212
|
}
|
|
4213
|
+
return false;
|
|
4209
4214
|
}
|
|
4210
4215
|
return await writeHolder(holder, claim(owner));
|
|
4211
4216
|
}),
|
|
4212
|
-
renew: (owner) => storeCall(
|
|
4213
|
-
if ((await read())?.owner === owner) {
|
|
4214
|
-
await writeFile(holder, claim(owner), { mode: 384 });
|
|
4215
|
-
}
|
|
4216
|
-
}),
|
|
4217
|
+
renew: (owner) => storeCall(() => renewHolder(holder, owner, claim(owner))),
|
|
4217
4218
|
release: (owner) => storeCall(async () => {
|
|
4218
|
-
|
|
4219
|
-
|
|
4219
|
+
const current = await readHolder(holder);
|
|
4220
|
+
if (current?.value?.owner === owner) {
|
|
4221
|
+
await retireHolder(directory, holder, current.raw);
|
|
4220
4222
|
}
|
|
4221
4223
|
})
|
|
4222
4224
|
};
|
|
@@ -4237,12 +4239,105 @@ async function writeHolder(holder, value) {
|
|
|
4237
4239
|
await writeFile(holder, value, { mode: 384, flag: "wx" });
|
|
4238
4240
|
return true;
|
|
4239
4241
|
} catch (error) {
|
|
4240
|
-
if (error.code === "EEXIST") {
|
|
4242
|
+
if (error.code === "EEXIST" || error.code === "ENOENT") {
|
|
4241
4243
|
return false;
|
|
4242
4244
|
}
|
|
4243
4245
|
throw error;
|
|
4244
4246
|
}
|
|
4245
4247
|
}
|
|
4248
|
+
async function readHolder(holder) {
|
|
4249
|
+
let raw;
|
|
4250
|
+
try {
|
|
4251
|
+
raw = await readFile(holder, "utf8");
|
|
4252
|
+
} catch (error) {
|
|
4253
|
+
if (error.code === "ENOENT") {
|
|
4254
|
+
return null;
|
|
4255
|
+
}
|
|
4256
|
+
throw error;
|
|
4257
|
+
}
|
|
4258
|
+
try {
|
|
4259
|
+
return { raw, value: JSON.parse(raw) };
|
|
4260
|
+
} catch {
|
|
4261
|
+
return { raw, value: null };
|
|
4262
|
+
}
|
|
4263
|
+
}
|
|
4264
|
+
async function renewHolder(holder, owner, value) {
|
|
4265
|
+
let file;
|
|
4266
|
+
try {
|
|
4267
|
+
file = await open(holder, "r+");
|
|
4268
|
+
} catch (error) {
|
|
4269
|
+
if (error.code === "ENOENT") {
|
|
4270
|
+
return;
|
|
4271
|
+
}
|
|
4272
|
+
throw error;
|
|
4273
|
+
}
|
|
4274
|
+
try {
|
|
4275
|
+
let current = null;
|
|
4276
|
+
try {
|
|
4277
|
+
current = JSON.parse(await file.readFile("utf8"));
|
|
4278
|
+
} catch {
|
|
4279
|
+
}
|
|
4280
|
+
if (current?.owner === owner) {
|
|
4281
|
+
await file.truncate(0);
|
|
4282
|
+
await file.write(value, 0, "utf8");
|
|
4283
|
+
}
|
|
4284
|
+
} finally {
|
|
4285
|
+
await file.close();
|
|
4286
|
+
}
|
|
4287
|
+
}
|
|
4288
|
+
async function retireHolder(directory, holder, expected) {
|
|
4289
|
+
const retired = `${directory}.${randomUUID2()}.stale`;
|
|
4290
|
+
try {
|
|
4291
|
+
await rename(holder, retired);
|
|
4292
|
+
} catch (error) {
|
|
4293
|
+
if (error.code === "ENOENT") {
|
|
4294
|
+
return;
|
|
4295
|
+
}
|
|
4296
|
+
throw error;
|
|
4297
|
+
}
|
|
4298
|
+
let removed = false;
|
|
4299
|
+
try {
|
|
4300
|
+
if (await readFile(retired, "utf8") !== expected) {
|
|
4301
|
+
return;
|
|
4302
|
+
}
|
|
4303
|
+
try {
|
|
4304
|
+
await rmdir(directory);
|
|
4305
|
+
removed = true;
|
|
4306
|
+
} catch (error) {
|
|
4307
|
+
if (!isDirectoryContention(error)) {
|
|
4308
|
+
throw error;
|
|
4309
|
+
}
|
|
4310
|
+
}
|
|
4311
|
+
} finally {
|
|
4312
|
+
if (!removed) {
|
|
4313
|
+
await restoreHolder(retired, holder);
|
|
4314
|
+
}
|
|
4315
|
+
await unlink(retired).catch(() => void 0);
|
|
4316
|
+
}
|
|
4317
|
+
}
|
|
4318
|
+
async function restoreHolder(retired, holder) {
|
|
4319
|
+
try {
|
|
4320
|
+
await link(retired, holder);
|
|
4321
|
+
} catch (error) {
|
|
4322
|
+
const code = error.code;
|
|
4323
|
+
if (code !== "EEXIST" && code !== "ENOENT") {
|
|
4324
|
+
throw error;
|
|
4325
|
+
}
|
|
4326
|
+
}
|
|
4327
|
+
}
|
|
4328
|
+
async function removeEmptyDirectory(directory) {
|
|
4329
|
+
try {
|
|
4330
|
+
await rmdir(directory);
|
|
4331
|
+
} catch (error) {
|
|
4332
|
+
if (!isDirectoryContention(error)) {
|
|
4333
|
+
throw error;
|
|
4334
|
+
}
|
|
4335
|
+
}
|
|
4336
|
+
}
|
|
4337
|
+
function isDirectoryContention(error) {
|
|
4338
|
+
const code = error.code;
|
|
4339
|
+
return code === "ENOENT" || code === "ENOTEMPTY" || code === "EEXIST";
|
|
4340
|
+
}
|
|
4246
4341
|
async function stillHeld(directory, holder) {
|
|
4247
4342
|
if (holder) {
|
|
4248
4343
|
return Date.parse(holder.expiresAt) > Date.now();
|
|
@@ -4272,4 +4367,4 @@ export {
|
|
|
4272
4367
|
withLease,
|
|
4273
4368
|
createFileStore
|
|
4274
4369
|
};
|
|
4275
|
-
//# sourceMappingURL=chunk-
|
|
4370
|
+
//# sourceMappingURL=chunk-7V5S3ISG.mjs.map
|