facturas 0.21.0 → 0.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/README.md +4 -2
  2. package/dist/{chunk-C2KX652X.mjs → chunk-5CGIRDZY.mjs} +5 -2
  3. package/dist/chunk-5CGIRDZY.mjs.map +1 -0
  4. package/dist/{chunk-FQD2PZXE.mjs → chunk-67ISWKGE.mjs} +3 -2
  5. package/dist/{chunk-4PSLYA2B.mjs → chunk-7MNVZSW6.mjs} +12 -3
  6. package/dist/chunk-7MNVZSW6.mjs.map +1 -0
  7. package/dist/{chunk-QHNI4ZIA.mjs → chunk-FSJHE4VS.mjs} +2 -2
  8. package/dist/{chunk-HSGTCGUX.mjs → chunk-GQGYO2Z2.mjs} +2 -2
  9. package/dist/{chunk-WEEV76IC.mjs → chunk-R4MOVPYT.mjs} +2815 -299
  10. package/dist/chunk-R4MOVPYT.mjs.map +1 -0
  11. package/dist/cli.d.ts +4 -4
  12. package/dist/cli.mjs +9 -9
  13. package/dist/cli.mjs.map +1 -1
  14. package/dist/{client-CP1PQD_j.d.ts → client-ghHzZdu8.d.ts} +613 -73
  15. package/dist/constants.d.ts +3 -0
  16. package/dist/constants.mjs +1 -1
  17. package/dist/errors.d.ts +2 -2
  18. package/dist/{fiscal-evidence-Cp-ntg5p.d.ts → fiscal-evidence-DjG8zB3o.d.ts} +2 -2
  19. package/dist/{index-abxokwjJ.d.ts → index-BSTxy3nN.d.ts} +1 -1
  20. package/dist/index.d.ts +5 -5
  21. package/dist/index.mjs +10 -10
  22. package/dist/index.mjs.map +1 -1
  23. package/dist/padron.d.ts +2 -2
  24. package/dist/padron.mjs +2 -2
  25. package/dist/{types-DhrPnj3r.d.ts → types-CbvsjIhf.d.ts} +2 -2
  26. package/dist/types.d.ts +1 -1
  27. package/dist/wsfe.d.ts +3 -3
  28. package/dist/wsfe.mjs +2 -2
  29. package/dist/wsmtxca.d.ts +3 -3
  30. package/dist/wsmtxca.mjs +2 -2
  31. package/package.json +1 -1
  32. package/dist/chunk-4PSLYA2B.mjs.map +0 -1
  33. package/dist/chunk-C2KX652X.mjs.map +0 -1
  34. package/dist/chunk-WEEV76IC.mjs.map +0 -1
  35. /package/dist/{chunk-FQD2PZXE.mjs.map → chunk-67ISWKGE.mjs.map} +0 -0
  36. /package/dist/{chunk-QHNI4ZIA.mjs.map → chunk-FSJHE4VS.mjs.map} +0 -0
  37. /package/dist/{chunk-HSGTCGUX.mjs.map → chunk-GQGYO2Z2.mjs.map} +0 -0
@@ -9,6 +9,9 @@ declare const ARCA_VOUCHER_TYPES: {
9
9
  readonly FACTURA_C: 11;
10
10
  readonly NOTA_DEBITO_C: 12;
11
11
  readonly NOTA_CREDITO_C: 13;
12
+ readonly FACTURA_E: 19;
13
+ readonly NOTA_DEBITO_E: 20;
14
+ readonly NOTA_CREDITO_E: 21;
12
15
  };
13
16
  /** Common document types accepted by ARCA services. */
14
17
  declare const ARCA_DOCUMENT_TYPES: {
@@ -11,7 +11,7 @@ import {
11
11
  ARCA_VOUCHER_TYPES,
12
12
  ARCA_WSMTXCA_GENERIC_CODES,
13
13
  ISO_CURRENCIES
14
- } from "./chunk-C2KX652X.mjs";
14
+ } from "./chunk-5CGIRDZY.mjs";
15
15
  export {
16
16
  ARCA_CONCEPT_TYPES,
17
17
  ARCA_CURRENCY_IDS,
package/dist/errors.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import './types-DhrPnj3r.js';
2
- export { A as ArcaAuthenticationError, a as ArcaAuthenticationErrorOptions, c as ArcaAuthenticationReason, f as ArcaConfigurationError, g as ArcaError, k as ArcaInputError, l as ArcaInputErrorCode, m as ArcaInputErrorOptions, n as ArcaInvalidSoapResponseError, o as ArcaLockTimeoutError, p as ArcaLockTimeoutReason, q as ArcaSafeErrorMetadata, r as ArcaServiceError, s as ArcaSoapFaultError, t as ArcaTransportError, V as VoucherDateWindow, v as isArcaAuthenticationError, w as toArcaSafeErrorMetadata } from './fiscal-evidence-Cp-ntg5p.js';
1
+ import './types-CbvsjIhf.js';
2
+ export { A as ArcaAuthenticationError, a as ArcaAuthenticationErrorOptions, c as ArcaAuthenticationReason, f as ArcaConfigurationError, g as ArcaError, k as ArcaInputError, l as ArcaInputErrorCode, m as ArcaInputErrorOptions, n as ArcaInvalidSoapResponseError, o as ArcaLockTimeoutError, p as ArcaLockTimeoutReason, q as ArcaSafeErrorMetadata, r as ArcaServiceError, s as ArcaSoapFaultError, t as ArcaTransportError, V as VoucherDateWindow, v as isArcaAuthenticationError, w as toArcaSafeErrorMetadata } from './fiscal-evidence-DjG8zB3o.js';
@@ -1,4 +1,4 @@
1
- import { b as ArcaServiceName } from './types-DhrPnj3r.js';
1
+ import { b as ArcaServiceName } from './types-CbvsjIhf.js';
2
2
 
3
3
  /** Base error class for all ARCA-related errors. */
4
4
  declare class ArcaError extends Error {
@@ -166,7 +166,7 @@ type ArcaSafeErrorMetadata = {
166
166
  declare function toArcaSafeErrorMetadata(error: unknown): ArcaSafeErrorMetadata;
167
167
 
168
168
  /** The ARCA service a call targets. It is chosen explicitly, never switched. */
169
- type IssuanceService = "wsfe" | "wsmtxca";
169
+ type IssuanceService = "wsfe" | "wsmtxca" | "wsfex";
170
170
  /** Location of a structured authorization result in the service response. */
171
171
  type ArcaFiscalResultLevel = "header" | "detail" | "operation";
172
172
  /** Every structured result field exposed by one provider response. */
@@ -1,4 +1,4 @@
1
- import { c as ArcaSoapExecutionOptions, d as ArcaSoapResponse, e as ArcaWsaaServiceId, f as ArcaAuthOptions, g as ArcaAuthCredentials } from './types-DhrPnj3r.js';
1
+ import { c as ArcaSoapExecutionOptions, d as ArcaSoapResponse, e as ArcaWsaaServiceId, f as ArcaAuthOptions, g as ArcaAuthCredentials } from './types-CbvsjIhf.js';
2
2
 
3
3
  type SoapTransport = {
4
4
  execute<TBody, TResult>(request: ArcaSoapExecutionOptions<TBody>): Promise<ArcaSoapResponse<TResult>>;
package/dist/index.d.ts CHANGED
@@ -1,12 +1,12 @@
1
- export { a as ARCA_QR_URL, b as AmountItem, A as ArcaClient, c as ArcaClientConfigView, d as ArcaQrInput, e as ArcaQrPayload, C as CreditNoteInput, D as DebitNoteInput, F as FceOptions, f as FiscalHeader, I as InvoiceFamily, g as IssuanceFields, h as IssueAmounts, i as IssueCommon, j as IssueInput, k as IssueOptions, l as IssueOutcome, m as IssuePreview, n as IssueRequest, o as IssuedVoucher, p as ItemLine, N as NotePreview, P as PeriodNoteInput, q as PreviewOptions, R as Receiver, r as RecoveryOptions, T as Tribute, V as VatItem, s as VatRate, t as VoucherAmounts, u as VoucherCoordinates, v as VoucherDateWindowInput, w as VoucherSummary, x as VoucherTypeInfo, y as VouchersService, W as WsfeIdentityMatch, z as WsmtxcaIssueRequest, B as WsmtxcaLine, E as arcaQrPayload, G as arcaQrUrl, H as createArcaClient, J as describeVoucherType, K as matchWsfeVoucherIdentity, L as voucherDateWindow } from './client-CP1PQD_j.js';
2
- import { h as ArcaEnvironment, a as ArcaClientConfig, i as ArcaStore, j as ArcaWsaaSessionStore } from './types-DhrPnj3r.js';
3
- export { g as ArcaAuthCredentials, f as ArcaAuthOptions, A as ArcaClientConfig, k as ArcaLockOptions, l as ArcaLogLevel, m as ArcaLoggerConfig, n as ArcaPadronServiceName, o as ArcaRepresentedTaxId, b as ArcaServiceName, p as ArcaServiceTarget, e as ArcaWsaaServiceId, q as ArcaWsaaSessionKey } from './types-DhrPnj3r.js';
1
+ export { a as ARCA_QR_URL, b as AmountItem, A as ArcaClient, c as ArcaClientConfigView, d as ArcaQrInput, e as ArcaQrPayload, C as CreateWsfexServiceOptions, f as CreditNoteInput, D as DebitNoteInput, E as ExportCreditNoteInput, g as ExportDebitNoteInput, h as ExportHeader, i as ExportIssueInput, j as ExportIssueOutcome, k as ExportIssueRequest, l as ExportIssuedVoucher, m as ExportItem, n as ExportOfGoods, o as ExportOfServices, p as ExportPreview, q as ExportReceiver, r as ExportVoucherSummary, s as ExportVoucherType, F as FceOptions, t as FiscalHeader, I as InvoiceFamily, u as IssuanceFields, v as IssueAmounts, w as IssueCommon, x as IssueInput, y as IssueOptions, z as IssueOutcome, B as IssuePreview, G as IssueRequest, H as IssuedVoucher, J as ItemLine, N as NotePreview, P as PeriodNoteInput, K as PreviewOptions, R as Receiver, L as RecoveryOptions, T as Tribute, V as VatItem, M as VatRate, O as VoucherAmounts, Q as VoucherCoordinates, S as VoucherDateWindowInput, U as VoucherSummary, W as VoucherTypeInfo, X as VouchersService, Y as WsfeIdentityMatch, Z as WsfexAssociatedVoucher, _ as WsfexAuthorizationOutcome, $ as WsfexCatalogEntry, a0 as WsfexCountryTaxId, a1 as WsfexExchangeRate, a2 as WsfexExportType, a3 as WsfexIssueInput, a4 as WsfexItem, a5 as WsfexLanguage, a6 as WsfexPermit, a7 as WsfexSalesPoint, a8 as WsfexService, a9 as WsfexVoucherInfo, aa as WsfexVoucherInput, ab as WsfexVoucherLookupResult, ac as WsfexVoucherType, ad as WsmtxcaIssueRequest, ae as WsmtxcaLine, af as arcaQrPayload, ag as arcaQrUrl, ah as createArcaClient, ai as createWsfexService, aj as describeVoucherType, ak as matchWsfeVoucherIdentity, al as voucherDateWindow } from './client-ghHzZdu8.js';
2
+ import { h as ArcaEnvironment, a as ArcaClientConfig, i as ArcaStore, j as ArcaWsaaSessionStore } from './types-CbvsjIhf.js';
3
+ export { g as ArcaAuthCredentials, f as ArcaAuthOptions, A as ArcaClientConfig, k as ArcaLockOptions, l as ArcaLogLevel, m as ArcaLoggerConfig, n as ArcaPadronServiceName, o as ArcaRepresentedTaxId, b as ArcaServiceName, p as ArcaServiceTarget, e as ArcaWsaaServiceId, q as ArcaWsaaSessionKey } from './types-CbvsjIhf.js';
4
4
  export { ARCA_FINAL_CONSUMER_IDENTIFICATION_THRESHOLD_MINOR_UNITS, ARCA_INVOICE_CLASS_BY_ISSUER, ARCA_ISSUER_CONDITION_IDS, ARCA_RECEIVER_CONDITION_IDS, ARCA_WSMTXCA_GENERIC_CODES, IssuerCondition, IssuerConditionId, ReceiverCondition, VoucherClass } from './constants.js';
5
- export { A as ArcaAuthenticationError, a as ArcaAuthenticationErrorOptions, b as ArcaAuthenticationEvidence, c as ArcaAuthenticationReason, d as ArcaAuthorizationIndeterminateReason, e as ArcaAuthorizationOutcome, f as ArcaConfigurationError, g as ArcaError, h as ArcaFiscalIssue, i as ArcaFiscalResultLevel, j as ArcaFiscalResults, k as ArcaInputError, l as ArcaInputErrorCode, m as ArcaInputErrorOptions, n as ArcaInvalidSoapResponseError, o as ArcaLockTimeoutError, p as ArcaLockTimeoutReason, q as ArcaSafeErrorMetadata, r as ArcaServiceError, s as ArcaSoapFaultError, t as ArcaTransportError, u as ArcaVoucherLookupResult, I as IssuanceService, V as VoucherDateWindow, v as isArcaAuthenticationError, w as toArcaSafeErrorMetadata } from './fiscal-evidence-Cp-ntg5p.js';
5
+ export { A as ArcaAuthenticationError, a as ArcaAuthenticationErrorOptions, b as ArcaAuthenticationEvidence, c as ArcaAuthenticationReason, d as ArcaAuthorizationIndeterminateReason, e as ArcaAuthorizationOutcome, f as ArcaConfigurationError, g as ArcaError, h as ArcaFiscalIssue, i as ArcaFiscalResultLevel, j as ArcaFiscalResults, k as ArcaInputError, l as ArcaInputErrorCode, m as ArcaInputErrorOptions, n as ArcaInvalidSoapResponseError, o as ArcaLockTimeoutError, p as ArcaLockTimeoutReason, q as ArcaSafeErrorMetadata, r as ArcaServiceError, s as ArcaSoapFaultError, t as ArcaTransportError, u as ArcaVoucherLookupResult, I as IssuanceService, V as VoucherDateWindow, v as isArcaAuthenticationError, w as toArcaSafeErrorMetadata } from './fiscal-evidence-DjG8zB3o.js';
6
6
  export { CreatePadronServiceOptions, PadronActivity, PadronAddress, PadronService, PadronTax, PadronTaxIdLookupResult, PadronTaxpayerResult, createPadronService } from './padron.js';
7
7
  export { CreateWsfeServiceOptions, WsfeActivity, WsfeActivityType, WsfeAssociatedPeriod, WsfeAssociatedVoucher, WsfeAuthorizationOutcome, WsfeBuyer, WsfeCatalogEntry, WsfeCurrencyType, WsfeDateInput, WsfeIssueInput, WsfeOptionalField, WsfeQuotation, WsfeReceiverVatCondition, WsfeSalesPoint, WsfeServerStatus, WsfeService, WsfeTax, WsfeVatRate, WsfeVoucherInfo, WsfeVoucherInput, WsfeVoucherLookupResult, createWsfeService } from './wsfe.js';
8
8
  export { CreateWsmtxcaServiceOptions, WsmtxcaAuthorizationOutcome, WsmtxcaIssueInput, WsmtxcaLastAuthorizedVoucherResult, WsmtxcaSalesPoint, WsmtxcaSalesPointsResult, WsmtxcaService, WsmtxcaVoucherInfo, WsmtxcaVoucherLookupOutcome, createWsmtxcaService } from './wsmtxca.js';
9
- import './index-abxokwjJ.js';
9
+ import './index-BSTxy3nN.js';
10
10
 
11
11
  /** Valid ARCA environment names. */
12
12
  declare const ARCA_ENVIRONMENTS: readonly ["production", "test"];
package/dist/index.mjs CHANGED
@@ -11,31 +11,32 @@ import {
11
11
  createArcaClientConfigFromEnv,
12
12
  createFileStore,
13
13
  createMemoryWsaaSessionStore,
14
+ createWsfexService,
14
15
  describeVoucherType,
15
16
  matchWsfeVoucherIdentity,
16
17
  storeCall,
17
18
  throwIfAborted,
18
19
  voucherDateWindow,
19
20
  withLease
20
- } from "./chunk-WEEV76IC.mjs";
21
+ } from "./chunk-R4MOVPYT.mjs";
21
22
  import {
22
23
  ARCA_FINAL_CONSUMER_IDENTIFICATION_THRESHOLD_MINOR_UNITS,
23
24
  ARCA_INVOICE_CLASS_BY_ISSUER,
24
25
  ARCA_ISSUER_CONDITION_IDS,
25
26
  ARCA_RECEIVER_CONDITION_IDS,
26
27
  ARCA_WSMTXCA_GENERIC_CODES
27
- } from "./chunk-C2KX652X.mjs";
28
+ } from "./chunk-5CGIRDZY.mjs";
28
29
  import {
29
30
  createPadronService
30
- } from "./chunk-QHNI4ZIA.mjs";
31
+ } from "./chunk-FSJHE4VS.mjs";
31
32
  import {
32
33
  createWsfeService
33
- } from "./chunk-FQD2PZXE.mjs";
34
+ } from "./chunk-67ISWKGE.mjs";
34
35
  import {
35
36
  createWsmtxcaService
36
- } from "./chunk-HSGTCGUX.mjs";
37
+ } from "./chunk-GQGYO2Z2.mjs";
37
38
  import "./chunk-HLSFMWRT.mjs";
38
- import "./chunk-4PSLYA2B.mjs";
39
+ import "./chunk-7MNVZSW6.mjs";
39
40
  import {
40
41
  ArcaAuthenticationError,
41
42
  ArcaConfigurationError,
@@ -72,7 +73,7 @@ function createMemoryStore() {
72
73
  return Promise.resolve();
73
74
  },
74
75
  async withLock(key, fn, { signal } = {}) {
75
- throwIfAborted(key, signal);
76
+ throwIfAborted(signal);
76
77
  const previous = locks.get(key) ?? Promise.resolve();
77
78
  let release = () => void 0;
78
79
  const current = new Promise((resolve) => {
@@ -91,7 +92,7 @@ function createMemoryStore() {
91
92
  locks.delete(key);
92
93
  }
93
94
  });
94
- throwIfAborted(key, signal);
95
+ throwIfAborted(signal);
95
96
  }
96
97
  try {
97
98
  return await fn();
@@ -140,7 +141,6 @@ function createPostgresStore({
140
141
  },
141
142
  withLock(key, fn, options) {
142
143
  return withLease(
143
- key,
144
144
  {
145
145
  async acquire(owner) {
146
146
  const taken = await run(
@@ -218,7 +218,6 @@ function createRedisStore(client, options = {}) {
218
218
  await client.del?.(key);
219
219
  }),
220
220
  withLock: (key, fn, options2) => withLease(
221
- key,
222
221
  {
223
222
  acquire: (owner) => lease(key, owner, "nx"),
224
223
  renew: async (owner) => {
@@ -270,6 +269,7 @@ export {
270
269
  createPostgresStore,
271
270
  createRedisStore,
272
271
  createWsfeService,
272
+ createWsfexService,
273
273
  createWsmtxcaService,
274
274
  describeVoucherType,
275
275
  isArcaAuthenticationError,
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/store/memory.ts","../src/store/postgres.ts","../src/store/redis.ts"],"sourcesContent":["import { abortable } from \"../internal/abort\";\nimport { throwIfAborted } from \"./lock\";\nimport type { ArcaStore } from \"./types\";\n\n/** In-process store for tests; reservations do not survive a restart. */\nexport function createMemoryStore(): ArcaStore {\n const values = new Map<string, string>();\n const locks = new Map<string, Promise<void>>();\n return {\n get: (key) => Promise.resolve(values.get(key) ?? null),\n set(key, value) {\n values.set(key, value);\n return Promise.resolve();\n },\n add(key, value) {\n if (values.has(key)) {\n return Promise.resolve(false);\n }\n values.set(key, value);\n return Promise.resolve(true);\n },\n delete(key) {\n values.delete(key);\n return Promise.resolve();\n },\n async withLock(key, fn, { signal } = {}) {\n throwIfAborted(key, signal);\n const previous = locks.get(key) ?? Promise.resolve();\n let release: () => void = () => undefined;\n const current = new Promise<void>((resolve) => {\n release = resolve;\n });\n const queued = previous.catch(() => undefined).then(() => current);\n locks.set(key, queued);\n // An abort ends the wait early; the check below reports it.\n await abortable(\n previous.catch(() => undefined),\n signal\n ).catch(() => undefined);\n if (signal?.aborted) {\n // Hand the turn on, but keep this call's place until the holder\n // before it finishes: a caller arriving now must still wait for it.\n release();\n queued.then(() => {\n if (locks.get(key) === queued) {\n locks.delete(key);\n }\n });\n throwIfAborted(key, signal);\n }\n try {\n return await fn();\n } finally {\n release();\n if (locks.get(key) === queued) {\n locks.delete(key);\n }\n }\n },\n };\n}\n","import { ArcaConfigurationError } from \"../errors\";\nimport { ARCA_LEASE_MS, withLease } from \"./lock\";\nimport { type ArcaStore, storeCall } from \"./types\";\n\ntype Row = { key?: string; value?: string };\n/** Uses the caller's SQL client; provision the table before use. */\nexport function createPostgresStore({\n query,\n table = \"arca_store\",\n}: {\n query: (text: string, params: string[]) => Promise<Row[] | { rows: Row[] }>;\n table?: string;\n}): ArcaStore {\n if (!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(table)) {\n throw new ArcaConfigurationError(\"Invalid ARCA store table identifier.\");\n }\n const name = `\"${table}\"`;\n const lease = Math.round(ARCA_LEASE_MS / 1000);\n const run = (text: string, params: string[]) =>\n storeCall(async () => {\n const result = await query(text, params);\n return Array.isArray(result) ? result : result.rows;\n });\n return {\n async get(key) {\n return (\n (await run(`SELECT value FROM ${name} WHERE key = $1`, [key]))[0]\n ?.value ?? null\n );\n },\n async set(key, value) {\n await run(\n `INSERT INTO ${name} (key, value) VALUES ($1, $2) ON CONFLICT (key) DO UPDATE SET value = EXCLUDED.value, updated_at = now()`,\n [key, value]\n );\n },\n async add(key, value) {\n return (\n (\n await run(\n `INSERT INTO ${name} (key, value) VALUES ($1, $2) ON CONFLICT DO NOTHING RETURNING key`,\n [key, value]\n )\n ).length > 0\n );\n },\n async delete(key) {\n await run(`DELETE FROM ${name} WHERE key = $1`, [key]);\n },\n withLock(key, fn, options) {\n // A lease row, not an advisory lock: it survives a transaction-mode\n // pooler, where a session-scoped lock would be taken on another backend.\n return withLease(\n key,\n {\n async acquire(owner) {\n const taken = await run(\n `INSERT INTO ${name} (key, value) VALUES ($1, $2) ON CONFLICT DO NOTHING RETURNING key`,\n [key, owner]\n );\n if (taken.length > 0) {\n return true;\n }\n const expired = await run(\n `UPDATE ${name} SET value = $2, updated_at = now() WHERE key = $1 AND updated_at < now() - interval '${lease} seconds' RETURNING key`,\n [key, owner]\n );\n return expired.length > 0;\n },\n async renew(owner) {\n await run(\n `UPDATE ${name} SET updated_at = now() WHERE key = $1 AND value = $2`,\n [key, owner]\n );\n },\n async release(owner) {\n await run(`DELETE FROM ${name} WHERE key = $1 AND value = $2`, [\n key,\n owner,\n ]);\n },\n },\n fn,\n options\n );\n },\n };\n}\n","import { ArcaConfigurationError } from \"../errors\";\nimport { ARCA_LEASE_MS, withLease } from \"./lock\";\nimport { type ArcaLockOptions, type ArcaStore, storeCall } from \"./types\";\n\ntype RedisClient = {\n get(key: string): Promise<unknown>;\n set(key: string, value: string): Promise<unknown>;\n call?(...args: string[]): Promise<unknown>;\n del?(key: string): Promise<unknown>;\n};\n/** Uses ioredis or Upstash without importing either driver. */\nexport function createRedisStore(\n client: RedisClient,\n options: { flavor?: \"ioredis\" | \"upstash\" } = {}\n): ArcaStore {\n const flavor =\n options.flavor ??\n (typeof client.call === \"function\" ? \"ioredis\" : \"upstash\");\n if (flavor === \"ioredis\" && !client.call) {\n throw new ArcaConfigurationError(\n \"ARCA Redis ioredis flavor requires client.call.\"\n );\n }\n // The public structural type accepts ioredis's overloaded set method.\n // Only the Upstash flavor invokes its options-object overload.\n const upstashSet = client.set as (\n key: string,\n value: string,\n options: { nx?: true; xx?: true; px?: number }\n ) => Promise<unknown>;\n const read = async (key: string) => {\n const value = await client.get(key);\n if (value === null || value === undefined) {\n return null;\n }\n // Upstash can deserialize stored JSON automatically.\n return typeof value === \"string\" ? value : JSON.stringify(value);\n };\n // A lease, so a crashed holder frees the key; a renewal keeps a live one.\n const lease = (key: string, owner: string, mode: \"nx\" | \"xx\") =>\n storeCall(\n async () =>\n (flavor === \"ioredis\"\n ? await client.call?.(\n \"SET\",\n key,\n owner,\n mode.toUpperCase(),\n \"PX\",\n String(ARCA_LEASE_MS)\n )\n : await upstashSet.call(client, key, owner, {\n [mode]: true,\n px: ARCA_LEASE_MS,\n })) === \"OK\"\n );\n return {\n get: (key) => storeCall(() => read(key)),\n set: (key, value) =>\n storeCall(async () => {\n await client.set(key, value);\n }),\n add: (key, value) =>\n storeCall(\n async () =>\n (flavor === \"ioredis\"\n ? await client.call?.(\"SET\", key, value, \"NX\")\n : await upstashSet.call(client, key, value, { nx: true })) === \"OK\"\n ),\n ...(client.del\n ? {\n delete: (key: string) =>\n storeCall(async () => {\n await client.del?.(key);\n }),\n withLock: <T>(\n key: string,\n fn: () => Promise<T>,\n options?: ArcaLockOptions\n ) =>\n withLease(\n key,\n {\n acquire: (owner) => lease(key, owner, \"nx\"),\n renew: async (owner) => {\n // Check and set: only the holder extends its own lease.\n if ((await storeCall(() => read(key))) === owner) {\n await lease(key, owner, \"xx\");\n }\n },\n release: async (owner) => {\n await storeCall(async () => {\n if ((await read(key)) === owner) {\n await client.del?.(key);\n }\n });\n },\n },\n fn,\n options\n ),\n }\n : {}),\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAKO,SAAS,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AAK,CAAC,QAAQ,UAAU,MAAM,KAAK,GAAG,CAAC;AAAA,IACvC,KAAK,CAAC,KAAK,UACT,UAAU,YAAY;AACpB,YAAM,OAAO,IAAI,KAAK,KAAK;AAAA,IAC7B,CAAC;AAAA,IACH,KAAK,CAAC,KAAK,UACT;AAAA,MACE,aACG,WAAW,YACR,MAAM,OAAO,OAAO,OAAO,KAAK,OAAO,IAAI,IAC3C,MAAM,WAAW,KAAK,QAAQ,KAAK,OAAO,EAAE,IAAI,KAAK,CAAC,OAAO;AAAA,IACrE;AAAA,IACF,GAAI,OAAO,MACP;AAAA,MACE,QAAQ,CAAC,QACP,UAAU,YAAY;AACpB,cAAM,OAAO,MAAM,GAAG;AAAA,MACxB,CAAC;AAAA,MACH,UAAU,CACR,KACA,IACAA,aAEA;AAAA,QACE;AAAA,QACA;AAAA,UACE,SAAS,CAAC,UAAU,MAAM,KAAK,OAAO,IAAI;AAAA,UAC1C,OAAO,OAAO,UAAU;AAEtB,gBAAK,MAAM,UAAU,MAAM,KAAK,GAAG,CAAC,MAAO,OAAO;AAChD,oBAAM,MAAM,KAAK,OAAO,IAAI;AAAA,YAC9B;AAAA,UACF;AAAA,UACA,SAAS,OAAO,UAAU;AACxB,kBAAM,UAAU,YAAY;AAC1B,kBAAK,MAAM,KAAK,GAAG,MAAO,OAAO;AAC/B,sBAAM,OAAO,MAAM,GAAG;AAAA,cACxB;AAAA,YACF,CAAC;AAAA,UACH;AAAA,QACF;AAAA,QACA;AAAA,QACAA;AAAA,MACF;AAAA,IACJ,IACA,CAAC;AAAA,EACP;AACF;","names":["options"]}
1
+ {"version":3,"sources":["../src/store/memory.ts","../src/store/postgres.ts","../src/store/redis.ts"],"sourcesContent":["import { abortable } from \"../internal/abort\";\nimport { throwIfAborted } from \"./lock\";\nimport type { ArcaStore } from \"./types\";\n\n/** In-process store for tests; reservations do not survive a restart. */\nexport function createMemoryStore(): ArcaStore {\n const values = new Map<string, string>();\n const locks = new Map<string, Promise<void>>();\n return {\n get: (key) => Promise.resolve(values.get(key) ?? null),\n set(key, value) {\n values.set(key, value);\n return Promise.resolve();\n },\n add(key, value) {\n if (values.has(key)) {\n return Promise.resolve(false);\n }\n values.set(key, value);\n return Promise.resolve(true);\n },\n delete(key) {\n values.delete(key);\n return Promise.resolve();\n },\n async withLock(key, fn, { signal } = {}) {\n throwIfAborted(signal);\n const previous = locks.get(key) ?? Promise.resolve();\n let release: () => void = () => undefined;\n const current = new Promise<void>((resolve) => {\n release = resolve;\n });\n const queued = previous.catch(() => undefined).then(() => current);\n locks.set(key, queued);\n // An abort ends the wait early; the check below reports it.\n await abortable(\n previous.catch(() => undefined),\n signal\n ).catch(() => undefined);\n if (signal?.aborted) {\n // Hand the turn on, but keep this call's place until the holder\n // before it finishes: a caller arriving now must still wait for it.\n release();\n queued.then(() => {\n if (locks.get(key) === queued) {\n locks.delete(key);\n }\n });\n throwIfAborted(signal);\n }\n try {\n return await fn();\n } finally {\n release();\n if (locks.get(key) === queued) {\n locks.delete(key);\n }\n }\n },\n };\n}\n","import { ArcaConfigurationError } from \"../errors\";\nimport { ARCA_LEASE_MS, withLease } from \"./lock\";\nimport { type ArcaStore, storeCall } from \"./types\";\n\ntype Row = { key?: string; value?: string };\n/** Uses the caller's SQL client; provision the table before use. */\nexport function createPostgresStore({\n query,\n table = \"arca_store\",\n}: {\n query: (text: string, params: string[]) => Promise<Row[] | { rows: Row[] }>;\n table?: string;\n}): ArcaStore {\n if (!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(table)) {\n throw new ArcaConfigurationError(\"Invalid ARCA store table identifier.\");\n }\n const name = `\"${table}\"`;\n const lease = Math.round(ARCA_LEASE_MS / 1000);\n const run = (text: string, params: string[]) =>\n storeCall(async () => {\n const result = await query(text, params);\n return Array.isArray(result) ? result : result.rows;\n });\n return {\n async get(key) {\n return (\n (await run(`SELECT value FROM ${name} WHERE key = $1`, [key]))[0]\n ?.value ?? null\n );\n },\n async set(key, value) {\n await run(\n `INSERT INTO ${name} (key, value) VALUES ($1, $2) ON CONFLICT (key) DO UPDATE SET value = EXCLUDED.value, updated_at = now()`,\n [key, value]\n );\n },\n async add(key, value) {\n return (\n (\n await run(\n `INSERT INTO ${name} (key, value) VALUES ($1, $2) ON CONFLICT DO NOTHING RETURNING key`,\n [key, value]\n )\n ).length > 0\n );\n },\n async delete(key) {\n await run(`DELETE FROM ${name} WHERE key = $1`, [key]);\n },\n withLock(key, fn, options) {\n // A lease row, not an advisory lock: it survives a transaction-mode\n // pooler, where a session-scoped lock would be taken on another backend.\n return withLease(\n {\n async acquire(owner) {\n const taken = await run(\n `INSERT INTO ${name} (key, value) VALUES ($1, $2) ON CONFLICT DO NOTHING RETURNING key`,\n [key, owner]\n );\n if (taken.length > 0) {\n return true;\n }\n const expired = await run(\n `UPDATE ${name} SET value = $2, updated_at = now() WHERE key = $1 AND updated_at < now() - interval '${lease} seconds' RETURNING key`,\n [key, owner]\n );\n return expired.length > 0;\n },\n async renew(owner) {\n await run(\n `UPDATE ${name} SET updated_at = now() WHERE key = $1 AND value = $2`,\n [key, owner]\n );\n },\n async release(owner) {\n await run(`DELETE FROM ${name} WHERE key = $1 AND value = $2`, [\n key,\n owner,\n ]);\n },\n },\n fn,\n options\n );\n },\n };\n}\n","import { ArcaConfigurationError } from \"../errors\";\nimport { ARCA_LEASE_MS, withLease } from \"./lock\";\nimport { type ArcaLockOptions, type ArcaStore, storeCall } from \"./types\";\n\ntype RedisClient = {\n get(key: string): Promise<unknown>;\n set(key: string, value: string): Promise<unknown>;\n call?(...args: string[]): Promise<unknown>;\n del?(key: string): Promise<unknown>;\n};\n/** Uses ioredis or Upstash without importing either driver. */\nexport function createRedisStore(\n client: RedisClient,\n options: { flavor?: \"ioredis\" | \"upstash\" } = {}\n): ArcaStore {\n const flavor =\n options.flavor ??\n (typeof client.call === \"function\" ? \"ioredis\" : \"upstash\");\n if (flavor === \"ioredis\" && !client.call) {\n throw new ArcaConfigurationError(\n \"ARCA Redis ioredis flavor requires client.call.\"\n );\n }\n // The public structural type accepts ioredis's overloaded set method.\n // Only the Upstash flavor invokes its options-object overload.\n const upstashSet = client.set as (\n key: string,\n value: string,\n options: { nx?: true; xx?: true; px?: number }\n ) => Promise<unknown>;\n const read = async (key: string) => {\n const value = await client.get(key);\n if (value === null || value === undefined) {\n return null;\n }\n // Upstash can deserialize stored JSON automatically.\n return typeof value === \"string\" ? value : JSON.stringify(value);\n };\n // A lease, so a crashed holder frees the key; a renewal keeps a live one.\n const lease = (key: string, owner: string, mode: \"nx\" | \"xx\") =>\n storeCall(\n async () =>\n (flavor === \"ioredis\"\n ? await client.call?.(\n \"SET\",\n key,\n owner,\n mode.toUpperCase(),\n \"PX\",\n String(ARCA_LEASE_MS)\n )\n : await upstashSet.call(client, key, owner, {\n [mode]: true,\n px: ARCA_LEASE_MS,\n })) === \"OK\"\n );\n return {\n get: (key) => storeCall(() => read(key)),\n set: (key, value) =>\n storeCall(async () => {\n await client.set(key, value);\n }),\n add: (key, value) =>\n storeCall(\n async () =>\n (flavor === \"ioredis\"\n ? await client.call?.(\"SET\", key, value, \"NX\")\n : await upstashSet.call(client, key, value, { nx: true })) === \"OK\"\n ),\n ...(client.del\n ? {\n delete: (key: string) =>\n storeCall(async () => {\n await client.del?.(key);\n }),\n withLock: <T>(\n key: string,\n fn: () => Promise<T>,\n options?: ArcaLockOptions\n ) =>\n withLease(\n {\n acquire: (owner) => lease(key, owner, \"nx\"),\n renew: async (owner) => {\n // Check and set: only the holder extends its own lease.\n if ((await storeCall(() => read(key))) === owner) {\n await lease(key, owner, \"xx\");\n }\n },\n release: async (owner) => {\n await storeCall(async () => {\n if ((await read(key)) === owner) {\n await client.del?.(key);\n }\n });\n },\n },\n fn,\n options\n ),\n }\n : {}),\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAKO,SAAS,oBAA+B;AAC7C,QAAM,SAAS,oBAAI,IAAoB;AACvC,QAAM,QAAQ,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U,YAAY;AACpB,YAAM,OAAO,IAAI,KAAK,KAAK;AAAA,IAC7B,CAAC;AAAA,IACH,KAAK,CAAC,KAAK,UACT;AAAA,MACE,aACG,WAAW,YACR,MAAM,OAAO,OAAO,OAAO,KAAK,OAAO,IAAI,IAC3C,MAAM,WAAW,KAAK,QAAQ,KAAK,OAAO,EAAE,IAAI,KAAK,CAAC,OAAO;AAAA,IACrE;AAAA,IACF,GAAI,OAAO,MACP;AAAA,MACE,QAAQ,CAAC,QACP,UAAU,YAAY;AACpB,cAAM,OAAO,MAAM,GAAG;AAAA,MACxB,CAAC;AAAA,MACH,UAAU,CACR,KACA,IACAA,aAEA;AAAA,QACE;AAAA,UACE,SAAS,CAAC,UAAU,MAAM,KAAK,OAAO,IAAI;AAAA,UAC1C,OAAO,OAAO,UAAU;AAEtB,gBAAK,MAAM,UAAU,MAAM,KAAK,GAAG,CAAC,MAAO,OAAO;AAChD,oBAAM,MAAM,KAAK,OAAO,IAAI;AAAA,YAC9B;AAAA,UACF;AAAA,UACA,SAAS,OAAO,UAAU;AACxB,kBAAM,UAAU,YAAY;AAC1B,kBAAK,MAAM,KAAK,GAAG,MAAO,OAAO;AAC/B,sBAAM,OAAO,MAAM,GAAG;AAAA,cACxB;AAAA,YACF,CAAC;AAAA,UACH;AAAA,QACF;AAAA,QACA;AAAA,QACAA;AAAA,MACF;AAAA,IACJ,IACA,CAAC;AAAA,EACP;AACF;","names":["options"]}
package/dist/padron.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { ReceiverCondition } from './constants.js';
2
- import { a as ArcaClientConfig } from './types-DhrPnj3r.js';
3
- import { W as WsaaAuthModule, S as SoapTransport } from './index-abxokwjJ.js';
2
+ import { a as ArcaClientConfig } from './types-CbvsjIhf.js';
3
+ import { W as WsaaAuthModule, S as SoapTransport } from './index-BSTxy3nN.js';
4
4
 
5
5
  /** One tax registration reported by the constancia de inscripción. */
6
6
  type PadronTax = {
package/dist/padron.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  createPadronService
3
- } from "./chunk-QHNI4ZIA.mjs";
4
- import "./chunk-4PSLYA2B.mjs";
3
+ } from "./chunk-FSJHE4VS.mjs";
4
+ import "./chunk-7MNVZSW6.mjs";
5
5
  import "./chunk-Q7IURW54.mjs";
6
6
  export {
7
7
  createPadronService
@@ -19,13 +19,13 @@ type ArcaStore = {
19
19
  /** Target environment for ARCA services. */
20
20
  type ArcaEnvironment = "production" | "test";
21
21
  /** All ARCA service identifiers, including WSAA. */
22
- type ArcaServiceName = "wsaa" | "wsfe" | "wsmtxca" | "padron-a5" | "padron-a13";
22
+ type ArcaServiceName = "wsaa" | "wsfe" | "wsfex" | "wsmtxca" | "padron-a5" | "padron-a13";
23
23
  /** ARCA service identifiers excluding the WSAA authentication service. */
24
24
  type ArcaServiceTarget = Exclude<ArcaServiceName, "wsaa">;
25
25
  /** Padron-specific service identifiers. */
26
26
  type ArcaPadronServiceName = Extract<ArcaServiceTarget, "padron-a5" | "padron-a13">;
27
27
  /** WSAA service identifiers used for authentication scoping. */
28
- type ArcaWsaaServiceId = "wsfe" | "wsmtxca" | "ws_sr_constancia_inscripcion" | "ws_sr_padron_a13";
28
+ type ArcaWsaaServiceId = "wsfe" | "wsfex" | "wsmtxca" | "ws_sr_constancia_inscripcion" | "ws_sr_padron_a13";
29
29
  type ArcaLogLevel = "debug" | "info" | "warn" | "error";
30
30
  type ArcaLoggerConfig = {
31
31
  disabled?: boolean;
package/dist/types.d.ts CHANGED
@@ -1 +1 @@
1
- export { g as ArcaAuthCredentials, f as ArcaAuthOptions, A as ArcaClientConfig, h as ArcaEnvironment, l as ArcaLogLevel, m as ArcaLoggerConfig, n as ArcaPadronServiceName, o as ArcaRepresentedTaxId, b as ArcaServiceName, p as ArcaServiceTarget, e as ArcaWsaaServiceId, q as ArcaWsaaSessionKey, j as ArcaWsaaSessionStore } from './types-DhrPnj3r.js';
1
+ export { g as ArcaAuthCredentials, f as ArcaAuthOptions, A as ArcaClientConfig, h as ArcaEnvironment, l as ArcaLogLevel, m as ArcaLoggerConfig, n as ArcaPadronServiceName, o as ArcaRepresentedTaxId, b as ArcaServiceName, p as ArcaServiceTarget, e as ArcaWsaaServiceId, q as ArcaWsaaSessionKey, j as ArcaWsaaSessionStore } from './types-CbvsjIhf.js';
package/dist/wsfe.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { a as ArcaClientConfig } from './types-DhrPnj3r.js';
2
- import { W as WsaaAuthModule, S as SoapTransport } from './index-abxokwjJ.js';
3
- import { e as ArcaAuthorizationOutcome, u as ArcaVoucherLookupResult } from './fiscal-evidence-Cp-ntg5p.js';
1
+ import { a as ArcaClientConfig } from './types-CbvsjIhf.js';
2
+ import { W as WsaaAuthModule, S as SoapTransport } from './index-BSTxy3nN.js';
3
+ import { e as ArcaAuthorizationOutcome, u as ArcaVoucherLookupResult } from './fiscal-evidence-DjG8zB3o.js';
4
4
 
5
5
  /** Accepted public date inputs for WSFE request fields. */
6
6
  type WsfeDateInput = `${number}${number}${number}${number}-${number}${number}-${number}${number}` | `${number}${number}${number}${number}${number}${number}${number}${number}`;
package/dist/wsfe.mjs CHANGED
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  createWsfeService
3
- } from "./chunk-FQD2PZXE.mjs";
3
+ } from "./chunk-67ISWKGE.mjs";
4
4
  import "./chunk-HLSFMWRT.mjs";
5
- import "./chunk-4PSLYA2B.mjs";
5
+ import "./chunk-7MNVZSW6.mjs";
6
6
  import "./chunk-Q7IURW54.mjs";
7
7
  export {
8
8
  createWsfeService
package/dist/wsmtxca.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { o as ArcaRepresentedTaxId, a as ArcaClientConfig } from './types-DhrPnj3r.js';
2
- import { W as WsaaAuthModule, S as SoapTransport } from './index-abxokwjJ.js';
3
- import { e as ArcaAuthorizationOutcome, u as ArcaVoucherLookupResult } from './fiscal-evidence-Cp-ntg5p.js';
1
+ import { o as ArcaRepresentedTaxId, a as ArcaClientConfig } from './types-CbvsjIhf.js';
2
+ import { W as WsaaAuthModule, S as SoapTransport } from './index-BSTxy3nN.js';
3
+ import { e as ArcaAuthorizationOutcome, u as ArcaVoucherLookupResult } from './fiscal-evidence-DjG8zB3o.js';
4
4
 
5
5
  /** Input for {@link WsmtxcaService.issue}: one WSMTXCA voucher request. */
6
6
  type WsmtxcaIssueInput = {
package/dist/wsmtxca.mjs CHANGED
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  createWsmtxcaService
3
- } from "./chunk-HSGTCGUX.mjs";
3
+ } from "./chunk-GQGYO2Z2.mjs";
4
4
  import "./chunk-HLSFMWRT.mjs";
5
- import "./chunk-4PSLYA2B.mjs";
5
+ import "./chunk-7MNVZSW6.mjs";
6
6
  import "./chunk-Q7IURW54.mjs";
7
7
  export {
8
8
  createWsmtxcaService
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "facturas",
3
- "version": "0.21.0",
3
+ "version": "0.22.0",
4
4
  "description": "SDK de TypeScript para facturación electrónica con ARCA / AFIP: facturas, notas de crédito y débito, y Padrón con una sola API.",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",
@@ -1 +0,0 @@
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}: 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D;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 +0,0 @@
1
- {"version":3,"sources":["../src/constants.ts"],"sourcesContent":["/** Common ARCA reference data for readable userland code and examples. */\nexport const ARCA_VOUCHER_TYPES = {\n FACTURA_A: 1,\n NOTA_DEBITO_A: 2,\n NOTA_CREDITO_A: 3,\n FACTURA_B: 6,\n NOTA_DEBITO_B: 7,\n NOTA_CREDITO_B: 8,\n FACTURA_C: 11,\n NOTA_DEBITO_C: 12,\n NOTA_CREDITO_C: 13,\n} as const;\n\n/** Common document types accepted by ARCA services. */\nexport const ARCA_DOCUMENT_TYPES = {\n CUIT: 80,\n DNI: 96,\n CONSUMIDOR_FINAL: 99,\n} as const;\n\n/**\n * ARCA's generic WSMTXCA item codes, keyed by the `matrixCode` to send.\n * RG 2904, Anexo VII: for concepts outside the issuer's main line of goods,\n * which carry their GTIN instead. Samples and promotional material use\n * `7790001001054` (Ventas varias).\n * https://www.afip.gob.ar/fe/documentos/codigosGenericosYEspecificos.xls\n */\nexport const ARCA_WSMTXCA_GENERIC_CODES = {\n \"7790001001030\": \"Descuentos y bonificaciones comerciales\",\n \"7790001001047\": \"Conceptos financieros\",\n \"7790001001054\": \"Ventas varias\",\n \"7790001001061\": \"Bienes de uso\",\n \"7790001001078\": \"Servicios prestados\",\n \"7790001001085\": \"Fletes\",\n \"7790001001092\": \"Alquileres\",\n \"7790001001115\": \"Depósito y servicios de logística\",\n \"7790001001122\": \"Repuestos y accesorios\",\n \"7790001001139\": \"Ajustes impositivos\",\n \"7790001001146\": \"Actividades comerciales no codificadas\",\n \"7790001001153\": \"Venta de material de rezago\",\n \"7790001001856\": \"Anticipos y señas\",\n} as const;\n\n/**\n * Common receiver IVA condition identifiers used by WSFE.\n * Allowed values depend on the voucher class and ARCA's live catalog.\n */\nexport const ARCA_RECEIVER_VAT_CONDITIONS = {\n RESPONSABLE_INSCRIPTO: 1,\n EXENTO: 4,\n CONSUMIDOR_FINAL: 5,\n MONOTRIBUTISTA: 6,\n IVA_NO_ALCANZADO: 15,\n} as const;\n\n/** Supported invoice concept types for WSFE requests. */\nexport const ARCA_CONCEPT_TYPES = {\n PRODUCTOS: 1,\n SERVICIOS: 2,\n PRODUCTOS_Y_SERVICIOS: 3,\n} as const;\n\n/** Common IVA rate identifiers used by WSFE. */\nexport const ARCA_VAT_RATES = {\n IVA_0: 3,\n IVA_10_5: 4,\n IVA_21: 5,\n IVA_27: 6,\n IVA_5: 8,\n IVA_2_5: 9,\n} as const;\n\n/** ISO currency codes accepted by the high-level WSFE builders. */\nexport const ISO_CURRENCIES = {\n ARS: \"ARS\",\n USD: \"USD\",\n} as const;\n\n/** ARCA currency identifiers keyed by their corresponding ISO currency. */\nexport const ARCA_CURRENCY_IDS = {\n ARS: \"PES\",\n USD: \"DOL\",\n} as const;\n\n/** Legal assertions supported by the invoice high-level API; never inferred from Padrón. */\nexport type IssuerCondition =\n | \"responsable_inscripto\"\n | \"monotributo\"\n | \"exento\"\n | \"no_alcanzado\";\nexport type ReceiverCondition = IssuerCondition | \"consumidor_final\";\nexport type VoucherClass = \"A\" | \"B\" | \"C\";\n\nexport const ARCA_RECEIVER_CONDITION_IDS = {\n responsable_inscripto: ARCA_RECEIVER_VAT_CONDITIONS.RESPONSABLE_INSCRIPTO,\n monotributo: ARCA_RECEIVER_VAT_CONDITIONS.MONOTRIBUTISTA,\n exento: ARCA_RECEIVER_VAT_CONDITIONS.EXENTO,\n consumidor_final: ARCA_RECEIVER_VAT_CONDITIONS.CONSUMIDOR_FINAL,\n no_alcanzado: ARCA_RECEIVER_VAT_CONDITIONS.IVA_NO_ALCANZADO,\n} as const satisfies Record<ReceiverCondition, number>;\n\nexport const ARCA_ISSUER_CONDITION_IDS = {\n responsable_inscripto: 1,\n monotributo: 6,\n exento: 4,\n no_alcanzado: 15,\n} as const satisfies Record<IssuerCondition, number>;\n\n/** The ARCA identifier of each issuer condition, accepted wherever a name is. */\nexport type IssuerConditionId =\n (typeof ARCA_ISSUER_CONDITION_IDS)[IssuerCondition];\n\n// RG 5866/2026, art. 1(f), effective 2026-07-01 (art. 4).\n// https://www.argentina.gob.ar/normativa/nacional/norma-427092/texto\nexport const ARCA_FINAL_CONSUMER_IDENTIFICATION_THRESHOLD_MINOR_UNITS =\n 1_000_000_000n;\n\n// WSFE v4.7, physical PDF p. 203, validations 10243/10246; issuer asserted first.\n// ARCA checks actual issuer eligibility independently at authorization.\nexport const ARCA_INVOICE_CLASS_BY_ISSUER = {\n responsable_inscripto: {\n responsable_inscripto: \"A\",\n monotributo: \"A\",\n exento: \"B\",\n consumidor_final: \"B\",\n no_alcanzado: \"B\",\n },\n monotributo: {\n responsable_inscripto: \"C\",\n monotributo: \"C\",\n exento: \"C\",\n consumidor_final: \"C\",\n no_alcanzado: \"C\",\n },\n exento: {\n responsable_inscripto: \"C\",\n monotributo: \"C\",\n exento: \"C\",\n consumidor_final: \"C\",\n no_alcanzado: \"C\",\n },\n no_alcanzado: {\n responsable_inscripto: \"C\",\n monotributo: \"C\",\n exento: \"C\",\n consumidor_final: \"C\",\n no_alcanzado: \"C\",\n },\n} as const satisfies Record<\n IssuerCondition,\n Record<ReceiverCondition, VoucherClass>\n>;\n"],"mappings":";AACO,IAAM,qBAAqB;AAAA,EAChC,WAAW;AAAA,EACX,eAAe;AAAA,EACf,gBAAgB;AAAA,EAChB,WAAW;AAAA,EACX,eAAe;AAAA,EACf,gBAAgB;AAAA,EAChB,WAAW;AAAA,EACX,eAAe;AAAA,EACf,gBAAgB;AAClB;AAGO,IAAM,sBAAsB;AAAA,EACjC,MAAM;AAAA,EACN,KAAK;AAAA,EACL,kBAAkB;AACpB;AASO,IAAM,6BAA6B;AAAA,EACxC,iBAAiB;AAAA,EACjB,iBAAiB;AAAA,EACjB,iBAAiB;AAAA,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