facturas 0.20.3 → 0.20.5

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.
@@ -1,6 +1,5 @@
1
1
  import {
2
2
  ArcaAuthenticationError,
3
- ArcaInvalidSoapResponseError,
4
3
  ArcaServiceError,
5
4
  ArcaSoapFaultError,
6
5
  isArcaAuthenticationError
@@ -171,22 +170,10 @@ function formatAuthenticationMessage(service, operation, reason) {
171
170
  return `ARCA rejected authentication for ${service}.${operation}: ${descriptions[reason]}.`;
172
171
  }
173
172
 
174
- // src/internal/voucher-number.ts
175
- function parseLastAuthorizedNumber(value, { service, operation }) {
176
- if ((typeof value === "string" || typeof value === "number") && /^\d+$/.test(String(value).trim()) && Number(value) <= 99999999) {
177
- return Number(value);
178
- }
179
- throw new ArcaInvalidSoapResponseError(
180
- `Invalid ${service.toUpperCase()} last authorized number`,
181
- { service, operation }
182
- );
183
- }
184
-
185
173
  export {
186
174
  classifyArcaAuthenticationError,
187
175
  classifyArcaAuthenticationIssues,
188
176
  createArcaAuthenticationEvidence,
189
- executeWithAuthenticationRecovery,
190
- parseLastAuthorizedNumber
177
+ executeWithAuthenticationRecovery
191
178
  };
192
- //# sourceMappingURL=chunk-XTKZ5FDN.mjs.map
179
+ //# sourceMappingURL=chunk-B2M64SIK.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/internal/authentication.ts"],"sourcesContent":["import {\n ArcaAuthenticationError,\n type ArcaAuthenticationReason,\n ArcaServiceError,\n ArcaSoapFaultError,\n isArcaAuthenticationError,\n} from \"../errors\";\nimport type {\n ArcaAuthenticationEvidence,\n ArcaFiscalIssue,\n} from \"../services/fiscal-evidence\";\nimport type { ArcaServiceName } from \"./types\";\n\ntype AuthenticationContext = {\n service: ArcaServiceName;\n operation: string;\n};\n\ntype AuthenticationCandidate = AuthenticationContext & {\n providerCode?: string | number;\n message?: string;\n cause?: unknown;\n};\n\ntype AuthenticationRecoveryOptions<T> = AuthenticationContext & {\n forceRefresh?: boolean;\n allowRetry?: boolean;\n execute(forceRefresh?: boolean): Promise<T>;\n};\n\nconst WSFE_AUTHENTICATION_CODES: Readonly<\n Record<string, ArcaAuthenticationReason>\n> = {\n \"600\": \"invalid_token\",\n \"601\": \"missing_relationship\",\n};\n\n/** Classifies one safe provider code/message pair without inspecting object graphs. */\nexport function classifyArcaAuthenticationCandidate(\n candidate: AuthenticationCandidate\n): ArcaAuthenticationError | undefined {\n const providerCode = normalizeProviderCode(candidate.providerCode);\n const reason =\n getStructuredAuthenticationReason(candidate.service, providerCode) ??\n getTextAuthenticationReason(candidate.message);\n\n if (!reason) {\n return undefined;\n }\n\n return new ArcaAuthenticationError(\n formatAuthenticationMessage(candidate.service, candidate.operation, reason),\n {\n reason,\n service: candidate.service,\n operation: candidate.operation,\n ...(providerCode === undefined ? {} : { providerCode }),\n ...(candidate.cause === undefined ? {} : { cause: candidate.cause }),\n }\n );\n}\n\n/** Classifies supported public ARCA errors while ignoring arbitrary errors and causes. */\nexport function classifyArcaAuthenticationError(\n error: unknown,\n context: AuthenticationContext\n): ArcaAuthenticationError | undefined {\n if (isArcaAuthenticationError(error)) {\n return error;\n }\n\n if (error instanceof ArcaSoapFaultError) {\n return classifyArcaAuthenticationCandidate({\n ...context,\n providerCode: error.faultCode,\n message: error.message,\n cause: error,\n });\n }\n\n if (error instanceof ArcaServiceError) {\n const issueError = classifyArcaAuthenticationIssues(\n error.issues ?? [],\n context\n );\n if (issueError) {\n return new ArcaAuthenticationError(issueError.message, {\n reason: issueError.reason,\n service: issueError.service,\n operation: issueError.operation,\n ...(issueError.providerCode === undefined\n ? {}\n : { providerCode: issueError.providerCode }),\n cause: error,\n });\n }\n\n return classifyArcaAuthenticationCandidate({\n ...context,\n providerCode: error.serviceCode,\n message: error.message,\n cause: error,\n });\n }\n\n return undefined;\n}\n\n/** Classifies structured service issues in provider order. */\nexport function classifyArcaAuthenticationIssues(\n issues: readonly ArcaFiscalIssue[],\n context: AuthenticationContext\n): ArcaAuthenticationError | undefined {\n for (const issue of issues) {\n const authenticationError = classifyArcaAuthenticationCandidate({\n ...context,\n providerCode: issue.code,\n message: issue.message,\n });\n if (authenticationError) {\n return authenticationError;\n }\n }\n return undefined;\n}\n\n/** Converts the public error to safe serializable exact-attempt evidence. */\nexport function createArcaAuthenticationEvidence(\n error: ArcaAuthenticationError\n): ArcaAuthenticationEvidence {\n return {\n code: \"ARCA_AUTHENTICATION_ERROR\",\n reason: error.reason,\n ...(error.providerCode === undefined\n ? {}\n : { providerCode: error.providerCode }),\n };\n}\n\n/** Recreates the throwable contract from safe exact-attempt evidence. */\nexport function createArcaAuthenticationErrorFromEvidence(\n evidence: ArcaAuthenticationEvidence,\n context: AuthenticationContext\n): ArcaAuthenticationError {\n return new ArcaAuthenticationError(\n formatAuthenticationMessage(\n context.service,\n context.operation,\n evidence.reason\n ),\n {\n reason: evidence.reason,\n service: context.service,\n operation: context.operation,\n ...(evidence.providerCode === undefined\n ? {}\n : { providerCode: evidence.providerCode }),\n }\n );\n}\n\n/** Runs one convenience operation and permits one proven-safe forced refresh. */\nexport async function executeWithAuthenticationRecovery<T>(\n options: AuthenticationRecoveryOptions<T>\n): Promise<T> {\n const executeAttempt = async (forceRefresh?: boolean): Promise<T> => {\n try {\n return await options.execute(forceRefresh);\n } catch (error) {\n throw classifyArcaAuthenticationError(error, options) ?? error;\n }\n };\n\n try {\n return await executeAttempt(options.forceRefresh);\n } catch (error) {\n const allowRetry =\n options.allowRetry !== false && options.forceRefresh !== true;\n if (!(allowRetry && isArcaAuthenticationError(error))) {\n throw error;\n }\n return executeAttempt(true);\n }\n}\n\nfunction getStructuredAuthenticationReason(\n service: ArcaServiceName,\n providerCode: string | number | undefined\n): ArcaAuthenticationReason | undefined {\n if (service !== \"wsfe\" || providerCode === undefined) {\n return undefined;\n }\n return WSFE_AUTHENTICATION_CODES[String(providerCode).trim()];\n}\n\nfunction getTextAuthenticationReason(\n message: string | undefined\n): ArcaAuthenticationReason | undefined {\n if (!message) {\n return undefined;\n }\n const normalized = normalizeAuthenticationText(message);\n\n if (\n includesWholePhrase(\n normalized,\n \"no aparecio cuit en lista de relaciones\"\n ) ||\n includesWholePhrase(normalized, \"cuit representada no incluida en token\")\n ) {\n return \"missing_relationship\";\n }\n if (includesWholePhrase(normalized, \"computador no autorizado\")) {\n return \"unauthorized_computer\";\n }\n if (\n includesWholePhrase(normalized, \"validaciondetoken\") ||\n includesWholePhrase(normalized, \"token vencido\") ||\n includesWholePhrase(normalized, \"no se corresponden token y firma\")\n ) {\n return \"invalid_token\";\n }\n if (\n includesWholePhrase(normalized, \"no autorizado a acceder al servicio\") ||\n includesWholePhrase(normalized, \"no autorizado a acceder a los servicios\")\n ) {\n return \"authentication_rejected\";\n }\n return undefined;\n}\n\nfunction normalizeAuthenticationText(value: string): string {\n return value\n .normalize(\"NFD\")\n .replace(/\\p{Diacritic}/gu, \"\")\n .toLowerCase()\n .replace(/\\s+/g, \" \")\n .trim();\n}\n\nfunction includesWholePhrase(value: string, phrase: string): boolean {\n let searchFrom = 0;\n while (searchFrom <= value.length - phrase.length) {\n const index = value.indexOf(phrase, searchFrom);\n if (index < 0) {\n return false;\n }\n const before = value[index - 1];\n const after = value[index + phrase.length];\n if (!(isWordCharacter(before) || isWordCharacter(after))) {\n return true;\n }\n searchFrom = index + phrase.length;\n }\n return false;\n}\n\nfunction isWordCharacter(value: string | undefined): boolean {\n return value !== undefined && /[a-z0-9]/.test(value);\n}\n\nfunction normalizeProviderCode(\n providerCode: string | number | undefined\n): string | number | undefined {\n if (typeof providerCode === \"number\") {\n return Number.isFinite(providerCode) ? providerCode : undefined;\n }\n if (typeof providerCode === \"string\") {\n const normalized = providerCode.trim();\n return normalized || undefined;\n }\n return undefined;\n}\n\nfunction formatAuthenticationMessage(\n service: ArcaServiceName,\n operation: string,\n reason: ArcaAuthenticationReason\n): string {\n const descriptions: Record<ArcaAuthenticationReason, string> = {\n invalid_token: \"the token or signature was rejected\",\n unauthorized_computer: \"the certificate or computer is not authorized\",\n missing_relationship: \"the represented taxpayer relationship is missing\",\n authentication_rejected: \"the service denied authenticated access\",\n };\n return `ARCA rejected authentication for ${service}.${operation}: ${descriptions[reason]}.`;\n}\n"],"mappings":";;;;;;;;AA8BA,IAAM,4BAEF;AAAA,EACF,OAAO;AAAA,EACP,OAAO;AACT;AAGO,SAAS,oCACd,WACqC;AACrC,QAAM,eAAe,sBAAsB,UAAU,YAAY;AACjE,QAAM,SACJ,kCAAkC,UAAU,SAAS,YAAY,KACjE,4BAA4B,UAAU,OAAO;AAE/C,MAAI,CAAC,QAAQ;AACX,WAAO;AAAA,EACT;AAEA,SAAO,IAAI;AAAA,IACT,4BAA4B,UAAU,SAAS,UAAU,WAAW,MAAM;AAAA,IAC1E;AAAA,MACE;AAAA,MACA,SAAS,UAAU;AAAA,MACnB,WAAW,UAAU;AAAA,MACrB,GAAI,iBAAiB,SAAY,CAAC,IAAI,EAAE,aAAa;AAAA,MACrD,GAAI,UAAU,UAAU,SAAY,CAAC,IAAI,EAAE,OAAO,UAAU,MAAM;AAAA,IACpE;AAAA,EACF;AACF;AAGO,SAAS,gCACd,OACA,SACqC;AACrC,MAAI,0BAA0B,KAAK,GAAG;AACpC,WAAO;AAAA,EACT;AAEA,MAAI,iBAAiB,oBAAoB;AACvC,WAAO,oCAAoC;AAAA,MACzC,GAAG;AAAA,MACH,cAAc,MAAM;AAAA,MACpB,SAAS,MAAM;AAAA,MACf,OAAO;AAAA,IACT,CAAC;AAAA,EACH;AAEA,MAAI,iBAAiB,kBAAkB;AACrC,UAAM,aAAa;AAAA,MACjB,MAAM,UAAU,CAAC;AAAA,MACjB;AAAA,IACF;AACA,QAAI,YAAY;AACd,aAAO,IAAI,wBAAwB,WAAW,SAAS;AAAA,QACrD,QAAQ,WAAW;AAAA,QACnB,SAAS,WAAW;AAAA,QACpB,WAAW,WAAW;AAAA,QACtB,GAAI,WAAW,iBAAiB,SAC5B,CAAC,IACD,EAAE,cAAc,WAAW,aA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M,aAAa,aAAa,KAAK;AACrC,WAAO,cAAc;AAAA,EACvB;AACA,SAAO;AACT;AAEA,SAAS,4BACP,SACA,WACA,QACQ;AACR,QAAM,eAAyD;AAAA,IAC7D,eAAe;AAAA,IACf,uBAAuB;AAAA,IACvB,sBAAsB;AAAA,IACtB,yBAAyB;AAAA,EAC3B;AACA,SAAO,oCAAoC,OAAO,IAAI,SAAS,KAAK,aAAa,MAAM,CAAC;AAC1F;","names":[]}
@@ -1,10 +1,14 @@
1
+ import {
2
+ parseLastAuthorizedNumber,
3
+ parseOptionalResponseInteger,
4
+ parseResponseInteger
5
+ } from "./chunk-YPQJRSTA.mjs";
1
6
  import {
2
7
  classifyArcaAuthenticationError,
3
8
  classifyArcaAuthenticationIssues,
4
9
  createArcaAuthenticationEvidence,
5
- executeWithAuthenticationRecovery,
6
- parseLastAuthorizedNumber
7
- } from "./chunk-XTKZ5FDN.mjs";
10
+ executeWithAuthenticationRecovery
11
+ } from "./chunk-B2M64SIK.mjs";
8
12
  import {
9
13
  ArcaInputError,
10
14
  ArcaInvalidSoapResponseError,
@@ -152,21 +156,22 @@ function createWsmtxcaService(options) {
152
156
  });
153
157
  throwForWsmtxcaOperationErrors(operation, raw);
154
158
  const rawSalesPoints = toRecord(raw.arrayPuntosVenta)?.puntoVenta;
155
- const entries = Array.isArray(rawSalesPoints) ? rawSalesPoints : rawSalesPoints ? [rawSalesPoints] : [];
156
- const salesPoints = entries.flatMap((entry) => {
159
+ const entries = Array.isArray(rawSalesPoints) ? rawSalesPoints : rawSalesPoints === void 0 ? [] : [rawSalesPoints];
160
+ const salesPoints = entries.map((entry) => {
157
161
  const record = toRecord(entry);
158
- const number = parseOptionalPositiveInteger(record?.numeroPuntoVenta);
159
- if (number === void 0) {
160
- return [];
161
- }
162
+ const number = parseResponseInteger(record?.numeroPuntoVenta, {
163
+ service: "wsmtxca",
164
+ operation,
165
+ field: "numeroPuntoVenta",
166
+ min: 1,
167
+ max: 99999
168
+ });
162
169
  const deletedAt = normalizeWsmtxcaResponseDate(record?.fechaBaja);
163
- return [
164
- {
165
- number,
166
- blocked: String(record?.bloqueado ?? "N").toUpperCase() === "S",
167
- ...deletedAt === void 0 ? {} : { deletedAt }
168
- }
169
- ];
170
+ return {
171
+ number,
172
+ blocked: String(record?.bloqueado ?? "N").toUpperCase() === "S",
173
+ ...deletedAt === void 0 ? {} : { deletedAt }
174
+ };
170
175
  });
171
176
  return { salesPoints, raw };
172
177
  }
@@ -293,9 +298,6 @@ function classifyWsmtxcaAuthorization(raw) {
293
298
  const caeExpiry = normalizeWsmtxcaResponseDate(
294
299
  payload.fechaVencimientoCAE ?? payload.fechaVencimiento ?? raw.fechaVencimiento
295
300
  );
296
- const voucherNumber = parseOptionalPositiveInteger(
297
- payload.numeroComprobante ?? raw.numeroComprobante
298
- );
299
301
  const errors = extractWsmtxcaIssues(raw, operation, "error");
300
302
  const observations = extractWsmtxcaIssues(raw, operation, "observation");
301
303
  const base = {
@@ -306,6 +308,24 @@ function classifyWsmtxcaAuthorization(raw) {
306
308
  observations,
307
309
  raw
308
310
  };
311
+ const parsedNumber = parseWsmtxcaAuthorizationNumber(payload, raw);
312
+ if (parsedNumber.invalid) {
313
+ const outcome2 = {
314
+ ...base,
315
+ kind: "indeterminate",
316
+ reason: "invalid_response"
317
+ };
318
+ assignWsmtxcaValue(outcome2, "result", result);
319
+ assignWsmtxcaValue(
320
+ outcome2,
321
+ "resultLevel",
322
+ result === void 0 ? void 0 : "operation"
323
+ );
324
+ assignWsmtxcaValue(outcome2, "cae", cae);
325
+ assignWsmtxcaValue(outcome2, "caeExpiry", caeExpiry);
326
+ return outcome2;
327
+ }
328
+ const voucherNumber = parsedNumber.voucherNumber;
309
329
  const authenticationOutcome = createWsmtxcaAuthenticationOutcome({
310
330
  base,
311
331
  result,
@@ -338,14 +358,35 @@ function classifyWsmtxcaAuthorization(raw) {
338
358
  ...base,
339
359
  kind: "indeterminate",
340
360
  reason: result === "R" && Boolean(cae) || (result === "A" || result === "O") && Boolean(errors.length) ? "contradictory_response" : "incomplete_response",
341
- ...result === void 0 ? {} : { result },
342
- ...result === void 0 ? {} : { resultLevel: "operation" }
361
+ ...result === void 0 ? {} : { result, resultLevel: "operation" }
343
362
  };
344
363
  assignWsmtxcaValue(outcome, "cae", cae);
345
364
  assignWsmtxcaValue(outcome, "caeExpiry", caeExpiry);
346
365
  assignWsmtxcaValue(outcome, "voucherNumber", voucherNumber);
347
366
  return outcome;
348
367
  }
368
+ function parseWsmtxcaAuthorizationNumber(payload, raw) {
369
+ try {
370
+ return {
371
+ invalid: false,
372
+ voucherNumber: parseOptionalResponseInteger(
373
+ payload.numeroComprobante === void 0 ? raw.numeroComprobante : payload.numeroComprobante,
374
+ {
375
+ service: "wsmtxca",
376
+ operation: "autorizarComprobante",
377
+ field: "numeroComprobante",
378
+ min: 1,
379
+ max: 99999999
380
+ }
381
+ )
382
+ };
383
+ } catch (error) {
384
+ if (!(error instanceof ArcaInvalidSoapResponseError)) {
385
+ throw error;
386
+ }
387
+ return { invalid: true };
388
+ }
389
+ }
349
390
  function createWsmtxcaAuthenticationOutcome({
350
391
  base,
351
392
  result,
@@ -475,18 +516,36 @@ function mapWsmtxcaVoucherInfo(raw) {
475
516
  assignWsmtxcaValue(
476
517
  voucher,
477
518
  "voucherNumber",
478
- parseOptionalPositiveInteger(raw.numeroComprobante)
519
+ parseOptionalResponseInteger(raw.numeroComprobante, {
520
+ service: "wsmtxca",
521
+ operation: "consultarComprobante",
522
+ field: "numeroComprobante",
523
+ min: 1,
524
+ max: 99999999
525
+ })
479
526
  );
480
527
  assignWsmtxcaValue(voucher, "invoiceDate", invoiceDate);
481
528
  assignWsmtxcaValue(
482
529
  voucher,
483
530
  "salesPoint",
484
- parseOptionalPositiveInteger(raw.numeroPuntoVenta)
531
+ parseOptionalResponseInteger(raw.numeroPuntoVenta, {
532
+ service: "wsmtxca",
533
+ operation: "consultarComprobante",
534
+ field: "numeroPuntoVenta",
535
+ min: 1,
536
+ max: 99999
537
+ })
485
538
  );
486
539
  assignWsmtxcaValue(
487
540
  voucher,
488
541
  "voucherType",
489
- parseOptionalPositiveInteger(raw.codigoTipoComprobante)
542
+ parseOptionalResponseInteger(raw.codigoTipoComprobante, {
543
+ service: "wsmtxca",
544
+ operation: "consultarComprobante",
545
+ field: "codigoTipoComprobante",
546
+ min: 1,
547
+ max: 999
548
+ })
490
549
  );
491
550
  assignWsmtxcaValue(
492
551
  voucher,
@@ -559,10 +618,6 @@ function sumWsmtxcaVatAmounts(value) {
559
618
  const amounts = entries.map((entry) => parseOptionalNumber(toRecord(entry)?.importe)).filter((amount) => amount !== void 0);
560
619
  return amounts.length > 0 ? amounts.reduce((total, amount) => total + amount, 0) : void 0;
561
620
  }
562
- function parseOptionalPositiveInteger(value) {
563
- const parsed = Number.parseInt(String(value ?? ""), 10);
564
- return Number.isFinite(parsed) && parsed > 0 ? parsed : void 0;
565
- }
566
621
  function parseOptionalNumber(value) {
567
622
  if (value === void 0 || value === null || value === "") {
568
623
  return void 0;
@@ -622,4 +677,4 @@ function formatCompactDateToIso(dateValue) {
622
677
  export {
623
678
  createWsmtxcaService
624
679
  };
625
- //# sourceMappingURL=chunk-VF3XJXBG.mjs.map
680
+ //# sourceMappingURL=chunk-EXJMG54W.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 {\n parseOptionalResponseInteger,\n parseResponseInteger,\n} from \"../internal/response-integer\";\nimport type { ArcaClientConfig, ArcaRepresentedTaxId } from \"../internal/types\";\nimport { parseLastAuthorizedNumber } from \"../internal/voucher-number\";\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: parseLastAuthorizedNumber(\n raw.numeroComprobante ?? raw.cbteNro ?? raw.nroComprobante,\n { service: \"wsmtxca\", operation }\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 === undefined\n ? []\n : [rawSalesPoints];\n const salesPoints = entries.map((entry) => {\n const record = toRecord(entry);\n const number = parseResponseInteger(record?.numeroPuntoVenta, {\n service: \"wsmtxca\",\n operation,\n field: \"numeroPuntoVenta\",\n min: 1,\n max: 99_999,\n });\n const deletedAt = normalizeWsmtxcaResponseDate(record?.fechaBaja);\n return {\n number,\n blocked: String(record?.bloqueado ?? \"N\").toUpperCase() === \"S\",\n ...(deletedAt === undefined ? {} : { deletedAt }),\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 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 parsedNumber = parseWsmtxcaAuthorizationNumber(payload, raw);\n if (parsedNumber.invalid) {\n // El envío ya ocurrió. Conservá el CAE y la evidencia para conciliar.\n const outcome: WsmtxcaAuthorizationOutcome = {\n ...base,\n kind: \"indeterminate\",\n reason: \"invalid_response\",\n };\n assignWsmtxcaValue(outcome, \"result\", result);\n assignWsmtxcaValue(\n outcome,\n \"resultLevel\",\n result === undefined ? undefined : \"operation\"\n );\n assignWsmtxcaValue(outcome, \"cae\", cae);\n assignWsmtxcaValue(outcome, \"caeExpiry\", caeExpiry);\n return outcome;\n }\n const voucherNumber = parsedNumber.voucherNumber;\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, resultLevel: \"operation\" }),\n };\n assignWsmtxcaValue(outcome, \"cae\", cae);\n assignWsmtxcaValue(outcome, \"caeExpiry\", caeExpiry);\n assignWsmtxcaValue(outcome, \"voucherNumber\", voucherNumber);\n return outcome;\n}\n\nfunction parseWsmtxcaAuthorizationNumber(\n payload: Record<string, unknown>,\n raw: Record<string, unknown>\n): { invalid: true } | { invalid: false; voucherNumber?: number } {\n try {\n return {\n invalid: false,\n voucherNumber: parseOptionalResponseInteger(\n payload.numeroComprobante === undefined\n ? raw.numeroComprobante\n : payload.numeroComprobante,\n {\n service: \"wsmtxca\",\n operation: \"autorizarComprobante\",\n field: \"numeroComprobante\",\n min: 1,\n max: 99_999_999,\n }\n ),\n };\n } catch (error) {\n if (!(error instanceof ArcaInvalidSoapResponseError)) {\n throw error;\n }\n return { invalid: true };\n }\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 parseOptionalResponseInteger(raw.numeroComprobante, {\n service: \"wsmtxca\",\n operation: \"consultarComprobante\",\n field: \"numeroComprobante\",\n min: 1,\n max: 99_999_999,\n })\n );\n assignWsmtxcaValue(voucher, \"invoiceDate\", invoiceDate);\n assignWsmtxcaValue(\n voucher,\n \"salesPoint\",\n parseOptionalResponseInteger(raw.numeroPuntoVenta, {\n service: \"wsmtxca\",\n operation: \"consultarComprobante\",\n field: \"numeroPuntoVenta\",\n min: 1,\n max: 99_999,\n })\n );\n assignWsmtxcaValue(\n voucher,\n \"voucherType\",\n parseOptionalResponseInteger(raw.codigoTipoComprobante, {\n service: \"wsmtxca\",\n operation: \"consultarComprobante\",\n field: \"codigoTipoComprobante\",\n min: 1,\n max: 999,\n })\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 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":";;;;;;;;;;;;;;;;;;;;AA+HO,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;A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