facturas 0.20.5 → 0.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -2
- package/dist/{chunk-C2KX652X.mjs → chunk-5CGIRDZY.mjs} +5 -2
- package/dist/chunk-5CGIRDZY.mjs.map +1 -0
- package/dist/{chunk-VEKUMXHW.mjs → chunk-67ISWKGE.mjs} +5 -4
- package/dist/{chunk-B2M64SIK.mjs → chunk-7MNVZSW6.mjs} +13 -4
- package/dist/chunk-7MNVZSW6.mjs.map +1 -0
- package/dist/{chunk-UOIZQMA6.mjs → chunk-FSJHE4VS.mjs} +3 -3
- package/dist/{chunk-EXJMG54W.mjs → chunk-GQGYO2Z2.mjs} +4 -4
- package/dist/{chunk-YPQJRSTA.mjs → chunk-HLSFMWRT.mjs} +2 -2
- package/dist/{chunk-NT2A6YMO.mjs → chunk-Q7IURW54.mjs} +12 -1
- package/dist/chunk-Q7IURW54.mjs.map +1 -0
- package/dist/{chunk-KBEV7QTU.mjs → chunk-R4MOVPYT.mjs} +2848 -297
- package/dist/chunk-R4MOVPYT.mjs.map +1 -0
- package/dist/cli.d.ts +4 -4
- package/dist/cli.mjs +11 -11
- package/dist/cli.mjs.map +1 -1
- package/dist/{client-BgWH_jKT.d.ts → client-ghHzZdu8.d.ts} +613 -73
- package/dist/constants.d.ts +3 -0
- package/dist/constants.mjs +1 -1
- package/dist/errors.d.ts +2 -2
- package/dist/errors.mjs +3 -1
- package/dist/{fiscal-evidence-Bg4o9nxt.d.ts → fiscal-evidence-DjG8zB3o.d.ts} +21 -5
- package/dist/{index-DAC3edtw.d.ts → index-BSTxy3nN.d.ts} +1 -1
- package/dist/index.d.ts +5 -5
- package/dist/index.mjs +35 -16
- package/dist/index.mjs.map +1 -1
- package/dist/padron.d.ts +2 -2
- package/dist/padron.mjs +3 -3
- package/dist/{types-Su7QwloQ.d.ts → types-CbvsjIhf.d.ts} +14 -5
- package/dist/types.d.ts +1 -1
- package/dist/wsfe.d.ts +3 -3
- package/dist/wsfe.mjs +4 -4
- package/dist/wsmtxca.d.ts +3 -3
- package/dist/wsmtxca.mjs +4 -4
- package/package.json +1 -1
- package/dist/chunk-B2M64SIK.mjs.map +0 -1
- package/dist/chunk-C2KX652X.mjs.map +0 -1
- package/dist/chunk-KBEV7QTU.mjs.map +0 -1
- package/dist/chunk-NT2A6YMO.mjs.map +0 -1
- /package/dist/{chunk-VEKUMXHW.mjs.map → chunk-67ISWKGE.mjs.map} +0 -0
- /package/dist/{chunk-UOIZQMA6.mjs.map → chunk-FSJHE4VS.mjs.map} +0 -0
- /package/dist/{chunk-EXJMG54W.mjs.map → chunk-GQGYO2Z2.mjs.map} +0 -0
- /package/dist/{chunk-YPQJRSTA.mjs.map → chunk-HLSFMWRT.mjs.map} +0 -0
package/dist/constants.d.ts
CHANGED
|
@@ -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: {
|
package/dist/constants.mjs
CHANGED
package/dist/errors.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import './types-
|
|
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
|
|
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';
|
package/dist/errors.mjs
CHANGED
|
@@ -4,18 +4,20 @@ import {
|
|
|
4
4
|
ArcaError,
|
|
5
5
|
ArcaInputError,
|
|
6
6
|
ArcaInvalidSoapResponseError,
|
|
7
|
+
ArcaLockTimeoutError,
|
|
7
8
|
ArcaServiceError,
|
|
8
9
|
ArcaSoapFaultError,
|
|
9
10
|
ArcaTransportError,
|
|
10
11
|
isArcaAuthenticationError,
|
|
11
12
|
toArcaSafeErrorMetadata
|
|
12
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-Q7IURW54.mjs";
|
|
13
14
|
export {
|
|
14
15
|
ArcaAuthenticationError,
|
|
15
16
|
ArcaConfigurationError,
|
|
16
17
|
ArcaError,
|
|
17
18
|
ArcaInputError,
|
|
18
19
|
ArcaInvalidSoapResponseError,
|
|
20
|
+
ArcaLockTimeoutError,
|
|
19
21
|
ArcaServiceError,
|
|
20
22
|
ArcaSoapFaultError,
|
|
21
23
|
ArcaTransportError,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { b as ArcaServiceName } from './types-
|
|
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 {
|
|
@@ -11,6 +11,22 @@ declare class ArcaConfigurationError extends ArcaError {
|
|
|
11
11
|
readonly name: string;
|
|
12
12
|
constructor(message: string, options?: ErrorOptions);
|
|
13
13
|
}
|
|
14
|
+
/** Why a store lock was never taken: it stayed held, or the caller gave up. */
|
|
15
|
+
type ArcaLockTimeoutReason = "held" | "aborted";
|
|
16
|
+
/**
|
|
17
|
+
* Thrown when a call gave up waiting for a store lock. Nothing was sent to
|
|
18
|
+
* ARCA, and a call that waited for the sequence lock reserved nothing either,
|
|
19
|
+
* so the same call can be repeated. `held` means another holder kept the lock
|
|
20
|
+
* past the wait, `aborted` that the caller's `abortSignal` fired first.
|
|
21
|
+
*/
|
|
22
|
+
declare class ArcaLockTimeoutError extends ArcaError {
|
|
23
|
+
readonly code: "ARCA_LOCK_TIMEOUT";
|
|
24
|
+
readonly name: string;
|
|
25
|
+
readonly reason: ArcaLockTimeoutReason;
|
|
26
|
+
constructor(message: string, options: ErrorOptions & {
|
|
27
|
+
reason: ArcaLockTimeoutReason;
|
|
28
|
+
});
|
|
29
|
+
}
|
|
14
30
|
/** Stable routing codes for caller-provided input failures. */
|
|
15
31
|
type ArcaInputErrorCode = "ARCA_INPUT_IDEMPOTENCY_MISMATCH" | "ARCA_INPUT_RESERVATION_NOT_FOUND" | "ARCA_INPUT_INVALID_DATE" | "ARCA_INPUT_DATE_OUTSIDE_WINDOW" | "ARCA_INPUT_INVALID_AMOUNT" | "ARCA_INPUT_AMOUNT_PRECISION" | "ARCA_INPUT_AMOUNT_MISMATCH" | "ARCA_INPUT_INVALID_EXCHANGE_RATE" | "ARCA_INPUT_INVALID_VALUE" | "ARCA_INPUT_MISSING_FIELD" | "ARCA_INPUT_RESERVED_FIELD";
|
|
16
32
|
/** The first and last day ARCA accepts, both `YYYY-MM-DD` and inclusive. */
|
|
@@ -135,8 +151,8 @@ type ArcaSafeErrorMetadata = {
|
|
|
135
151
|
contentType?: string;
|
|
136
152
|
service?: ArcaServiceName;
|
|
137
153
|
operation?: string;
|
|
138
|
-
/** ArcaAuthenticationError's stable reason. */
|
|
139
|
-
reason?: ArcaAuthenticationReason;
|
|
154
|
+
/** ArcaAuthenticationError's or ArcaLockTimeoutError's stable reason. */
|
|
155
|
+
reason?: ArcaAuthenticationReason | ArcaLockTimeoutReason;
|
|
140
156
|
providerCode?: string | number;
|
|
141
157
|
faultCode?: string;
|
|
142
158
|
field?: string;
|
|
@@ -150,7 +166,7 @@ type ArcaSafeErrorMetadata = {
|
|
|
150
166
|
declare function toArcaSafeErrorMetadata(error: unknown): ArcaSafeErrorMetadata;
|
|
151
167
|
|
|
152
168
|
/** The ARCA service a call targets. It is chosen explicitly, never switched. */
|
|
153
|
-
type IssuanceService = "wsfe" | "wsmtxca";
|
|
169
|
+
type IssuanceService = "wsfe" | "wsmtxca" | "wsfex";
|
|
154
170
|
/** Location of a structured authorization result in the service response. */
|
|
155
171
|
type ArcaFiscalResultLevel = "header" | "detail" | "operation";
|
|
156
172
|
/** Every structured result field exposed by one provider response. */
|
|
@@ -224,4 +240,4 @@ type ArcaVoucherLookupResult<TVoucher, TService extends IssuanceService = Issuan
|
|
|
224
240
|
raw: Record<string, unknown>;
|
|
225
241
|
};
|
|
226
242
|
|
|
227
|
-
export { ArcaAuthenticationError as A, type IssuanceService as I, type VoucherDateWindow as V, type ArcaAuthenticationErrorOptions as a, type ArcaAuthenticationEvidence as b, type ArcaAuthenticationReason as c, type ArcaAuthorizationIndeterminateReason as d, type ArcaAuthorizationOutcome as e, ArcaConfigurationError as f, ArcaError as g, type ArcaFiscalIssue as h, type ArcaFiscalResultLevel as i, type ArcaFiscalResults as j, ArcaInputError as k, type ArcaInputErrorCode as l, type ArcaInputErrorOptions as m, ArcaInvalidSoapResponseError as n, type ArcaSafeErrorMetadata as
|
|
243
|
+
export { ArcaAuthenticationError as A, type IssuanceService as I, type VoucherDateWindow as V, type ArcaAuthenticationErrorOptions as a, type ArcaAuthenticationEvidence as b, type ArcaAuthenticationReason as c, type ArcaAuthorizationIndeterminateReason as d, type ArcaAuthorizationOutcome as e, ArcaConfigurationError as f, ArcaError as g, type ArcaFiscalIssue as h, type ArcaFiscalResultLevel as i, type ArcaFiscalResults as j, ArcaInputError as k, type ArcaInputErrorCode as l, type ArcaInputErrorOptions as m, ArcaInvalidSoapResponseError as n, ArcaLockTimeoutError as o, type ArcaLockTimeoutReason as p, type ArcaSafeErrorMetadata as q, ArcaServiceError as r, ArcaSoapFaultError as s, ArcaTransportError as t, type ArcaVoucherLookupResult as u, isArcaAuthenticationError as v, toArcaSafeErrorMetadata as w };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { c as ArcaSoapExecutionOptions, d as ArcaSoapResponse, e as ArcaWsaaServiceId, f as ArcaAuthOptions, g as ArcaAuthCredentials } from './types-
|
|
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,
|
|
2
|
-
import { h as ArcaEnvironment, a as ArcaClientConfig, i as ArcaStore, j as ArcaWsaaSessionStore } from './types-
|
|
3
|
-
export { g as ArcaAuthCredentials, f as ArcaAuthOptions, A as ArcaClientConfig, k as
|
|
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
|
|
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-
|
|
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
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
ARCA_ENV_VARIABLES,
|
|
4
4
|
ARCA_LEASE_MS,
|
|
5
5
|
ARCA_QR_URL,
|
|
6
|
+
abortable,
|
|
6
7
|
arcaQrPayload,
|
|
7
8
|
arcaQrUrl,
|
|
8
9
|
assertArcaClientConfig,
|
|
@@ -10,42 +11,45 @@ import {
|
|
|
10
11
|
createArcaClientConfigFromEnv,
|
|
11
12
|
createFileStore,
|
|
12
13
|
createMemoryWsaaSessionStore,
|
|
14
|
+
createWsfexService,
|
|
13
15
|
describeVoucherType,
|
|
14
16
|
matchWsfeVoucherIdentity,
|
|
15
17
|
storeCall,
|
|
18
|
+
throwIfAborted,
|
|
16
19
|
voucherDateWindow,
|
|
17
20
|
withLease
|
|
18
|
-
} from "./chunk-
|
|
21
|
+
} from "./chunk-R4MOVPYT.mjs";
|
|
19
22
|
import {
|
|
20
23
|
ARCA_FINAL_CONSUMER_IDENTIFICATION_THRESHOLD_MINOR_UNITS,
|
|
21
24
|
ARCA_INVOICE_CLASS_BY_ISSUER,
|
|
22
25
|
ARCA_ISSUER_CONDITION_IDS,
|
|
23
26
|
ARCA_RECEIVER_CONDITION_IDS,
|
|
24
27
|
ARCA_WSMTXCA_GENERIC_CODES
|
|
25
|
-
} from "./chunk-
|
|
28
|
+
} from "./chunk-5CGIRDZY.mjs";
|
|
26
29
|
import {
|
|
27
30
|
createPadronService
|
|
28
|
-
} from "./chunk-
|
|
31
|
+
} from "./chunk-FSJHE4VS.mjs";
|
|
29
32
|
import {
|
|
30
33
|
createWsfeService
|
|
31
|
-
} from "./chunk-
|
|
34
|
+
} from "./chunk-67ISWKGE.mjs";
|
|
32
35
|
import {
|
|
33
36
|
createWsmtxcaService
|
|
34
|
-
} from "./chunk-
|
|
35
|
-
import "./chunk-
|
|
36
|
-
import "./chunk-
|
|
37
|
+
} from "./chunk-GQGYO2Z2.mjs";
|
|
38
|
+
import "./chunk-HLSFMWRT.mjs";
|
|
39
|
+
import "./chunk-7MNVZSW6.mjs";
|
|
37
40
|
import {
|
|
38
41
|
ArcaAuthenticationError,
|
|
39
42
|
ArcaConfigurationError,
|
|
40
43
|
ArcaError,
|
|
41
44
|
ArcaInputError,
|
|
42
45
|
ArcaInvalidSoapResponseError,
|
|
46
|
+
ArcaLockTimeoutError,
|
|
43
47
|
ArcaServiceError,
|
|
44
48
|
ArcaSoapFaultError,
|
|
45
49
|
ArcaTransportError,
|
|
46
50
|
isArcaAuthenticationError,
|
|
47
51
|
toArcaSafeErrorMetadata
|
|
48
|
-
} from "./chunk-
|
|
52
|
+
} from "./chunk-Q7IURW54.mjs";
|
|
49
53
|
|
|
50
54
|
// src/store/memory.ts
|
|
51
55
|
function createMemoryStore() {
|
|
@@ -68,7 +72,8 @@ function createMemoryStore() {
|
|
|
68
72
|
values.delete(key);
|
|
69
73
|
return Promise.resolve();
|
|
70
74
|
},
|
|
71
|
-
async withLock(key, fn) {
|
|
75
|
+
async withLock(key, fn, { signal } = {}) {
|
|
76
|
+
throwIfAborted(signal);
|
|
72
77
|
const previous = locks.get(key) ?? Promise.resolve();
|
|
73
78
|
let release = () => void 0;
|
|
74
79
|
const current = new Promise((resolve) => {
|
|
@@ -76,7 +81,19 @@ function createMemoryStore() {
|
|
|
76
81
|
});
|
|
77
82
|
const queued = previous.catch(() => void 0).then(() => current);
|
|
78
83
|
locks.set(key, queued);
|
|
79
|
-
await
|
|
84
|
+
await abortable(
|
|
85
|
+
previous.catch(() => void 0),
|
|
86
|
+
signal
|
|
87
|
+
).catch(() => void 0);
|
|
88
|
+
if (signal?.aborted) {
|
|
89
|
+
release();
|
|
90
|
+
queued.then(() => {
|
|
91
|
+
if (locks.get(key) === queued) {
|
|
92
|
+
locks.delete(key);
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
throwIfAborted(signal);
|
|
96
|
+
}
|
|
80
97
|
try {
|
|
81
98
|
return await fn();
|
|
82
99
|
} finally {
|
|
@@ -122,9 +139,8 @@ function createPostgresStore({
|
|
|
122
139
|
async delete(key) {
|
|
123
140
|
await run(`DELETE FROM ${name} WHERE key = $1`, [key]);
|
|
124
141
|
},
|
|
125
|
-
withLock(key, fn) {
|
|
142
|
+
withLock(key, fn, options) {
|
|
126
143
|
return withLease(
|
|
127
|
-
key,
|
|
128
144
|
{
|
|
129
145
|
async acquire(owner) {
|
|
130
146
|
const taken = await run(
|
|
@@ -153,7 +169,8 @@ function createPostgresStore({
|
|
|
153
169
|
]);
|
|
154
170
|
}
|
|
155
171
|
},
|
|
156
|
-
fn
|
|
172
|
+
fn,
|
|
173
|
+
options
|
|
157
174
|
);
|
|
158
175
|
}
|
|
159
176
|
};
|
|
@@ -200,8 +217,7 @@ function createRedisStore(client, options = {}) {
|
|
|
200
217
|
delete: (key) => storeCall(async () => {
|
|
201
218
|
await client.del?.(key);
|
|
202
219
|
}),
|
|
203
|
-
withLock: (key, fn) => withLease(
|
|
204
|
-
key,
|
|
220
|
+
withLock: (key, fn, options2) => withLease(
|
|
205
221
|
{
|
|
206
222
|
acquire: (owner) => lease(key, owner, "nx"),
|
|
207
223
|
renew: async (owner) => {
|
|
@@ -217,7 +233,8 @@ function createRedisStore(client, options = {}) {
|
|
|
217
233
|
});
|
|
218
234
|
}
|
|
219
235
|
},
|
|
220
|
-
fn
|
|
236
|
+
fn,
|
|
237
|
+
options2
|
|
221
238
|
)
|
|
222
239
|
} : {}
|
|
223
240
|
};
|
|
@@ -236,6 +253,7 @@ export {
|
|
|
236
253
|
ArcaError,
|
|
237
254
|
ArcaInputError,
|
|
238
255
|
ArcaInvalidSoapResponseError,
|
|
256
|
+
ArcaLockTimeoutError,
|
|
239
257
|
ArcaServiceError,
|
|
240
258
|
ArcaSoapFaultError,
|
|
241
259
|
ArcaTransportError,
|
|
@@ -251,6 +269,7 @@ export {
|
|
|
251
269
|
createPostgresStore,
|
|
252
270
|
createRedisStore,
|
|
253
271
|
createWsfeService,
|
|
272
|
+
createWsfexService,
|
|
254
273
|
createWsmtxcaService,
|
|
255
274
|
describeVoucherType,
|
|
256
275
|
isArcaAuthenticationError,
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/store/memory.ts","../src/store/postgres.ts","../src/store/redis.ts"],"sourcesContent":["import 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) {\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 await previous.catch(() => undefined);\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) {\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 );\n },\n };\n}\n","import { ArcaConfigurationError } from \"../errors\";\nimport { ARCA_LEASE_MS, withLease } from \"./lock\";\nimport { 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>(key: string, fn: () => Promise<T>) =>\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 ),\n }\n : {}),\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGO,SAAS,oBAA+B;AAC7C,QAAM,SAAS,oBAAI,IAAoB;AACvC,QAAM,QAAQ,oBAAI,IAA2B;AAC7C,SAAO;AAAA,IACL,KAAK,CAAC,QAAQ,QAAQ,QAAQ,OAAO,IAAI,GAAG,KAAK,IAAI;AAAA,IACrD,IAAI,KAAK,OAAO;AACd,aAAO,IAAI,KAAK,KAAK;AACrB,aAAO,QAAQ,QAAQ;AAAA,IACzB;AAAA,IACA,IAAI,KAAK,OAAO;AACd,UAAI,OAAO,IAAI,GAAG,GAAG;AACnB,eAAO,QAAQ,QAAQ,KAAK;AAAA,MAC9B;AACA,aAAO,IAAI,KAAK,KAAK;AACrB,aAAO,QAAQ,QAAQ,IAAI;AAAA,IAC7B;AAAA,IACA,OAAO,KAAK;AACV,aAAO,OAAO,GAAG;AACjB,aAAO,QAAQ,QAAQ;AAAA,IACzB;AAAA,IACA,MAAM,SAAS,KAAK,IAAI;AACtB,YAAM,WAAW,MAAM,IAAI,GAAG,KAAK,QAAQ,QAAQ;AACnD,UAAI,UAAsB,MAAM;AAChC,YAAM,UAAU,IAAI,QAAc,CAAC,YAAY;AAC7C,kBAAU;AAAA,MACZ,CAAC;AACD,YAAM,SAAS,SAAS,MAAM,MAAM,MAAS,EAAE,KAAK,MAAM,OAAO;AACjE,YAAM,IAAI,KAAK,MAAM;AACrB,YAAM,SAAS,MAAM,MAAM,MAAS;AACpC,U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OAAO;AAAA,EAChB;AACF,SAAO;AAAA,IACL,KAAK,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,CAAI,KAAa,OACzB;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,MACF;AAAA,IACJ,IACA,CAAC;AAAA,EACP;AACF;","names":[]}
|
|
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,oBA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vC,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,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-
|
|
3
|
-
import { W as WsaaAuthModule, S as SoapTransport } from './index-
|
|
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,8 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createPadronService
|
|
3
|
-
} from "./chunk-
|
|
4
|
-
import "./chunk-
|
|
5
|
-
import "./chunk-
|
|
3
|
+
} from "./chunk-FSJHE4VS.mjs";
|
|
4
|
+
import "./chunk-7MNVZSW6.mjs";
|
|
5
|
+
import "./chunk-Q7IURW54.mjs";
|
|
6
6
|
export {
|
|
7
7
|
createPadronService
|
|
8
8
|
};
|
|
@@ -1,22 +1,31 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/** What a caller may pass to `withLock`: a signal that stops the wait. */
|
|
2
|
+
type ArcaLockOptions = {
|
|
3
|
+
signal?: AbortSignal;
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* Durable values. add must atomically create only when the key is absent.
|
|
7
|
+
* withLock runs `fn` exclusively across processes. `options.signal` only stops
|
|
8
|
+
* the wait: an abort before the lock is taken throws `ArcaLockTimeoutError`
|
|
9
|
+
* with `reason: "aborted"` and never runs `fn`.
|
|
10
|
+
*/
|
|
2
11
|
type ArcaStore = {
|
|
3
12
|
get(key: string): Promise<string | null>;
|
|
4
13
|
set(key: string, value: string): Promise<void>;
|
|
5
14
|
add(key: string, value: string): Promise<boolean>;
|
|
6
15
|
delete?(key: string): Promise<void>;
|
|
7
|
-
withLock?<T>(key: string, fn: () => Promise<T
|
|
16
|
+
withLock?<T>(key: string, fn: () => Promise<T>, options?: ArcaLockOptions): Promise<T>;
|
|
8
17
|
};
|
|
9
18
|
|
|
10
19
|
/** Target environment for ARCA services. */
|
|
11
20
|
type ArcaEnvironment = "production" | "test";
|
|
12
21
|
/** All ARCA service identifiers, including WSAA. */
|
|
13
|
-
type ArcaServiceName = "wsaa" | "wsfe" | "wsmtxca" | "padron-a5" | "padron-a13";
|
|
22
|
+
type ArcaServiceName = "wsaa" | "wsfe" | "wsfex" | "wsmtxca" | "padron-a5" | "padron-a13";
|
|
14
23
|
/** ARCA service identifiers excluding the WSAA authentication service. */
|
|
15
24
|
type ArcaServiceTarget = Exclude<ArcaServiceName, "wsaa">;
|
|
16
25
|
/** Padron-specific service identifiers. */
|
|
17
26
|
type ArcaPadronServiceName = Extract<ArcaServiceTarget, "padron-a5" | "padron-a13">;
|
|
18
27
|
/** WSAA service identifiers used for authentication scoping. */
|
|
19
|
-
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";
|
|
20
29
|
type ArcaLogLevel = "debug" | "info" | "warn" | "error";
|
|
21
30
|
type ArcaLoggerConfig = {
|
|
22
31
|
disabled?: boolean;
|
|
@@ -78,4 +87,4 @@ type ArcaSoapExecutionOptions<TBody> = {
|
|
|
78
87
|
};
|
|
79
88
|
type ArcaClientOptions = Omit<ArcaClientConfig, "taxId" | "certificatePem" | "privateKeyPem" | "environment"> & Partial<Pick<ArcaClientConfig, "taxId" | "certificatePem" | "privateKeyPem" | "environment">>;
|
|
80
89
|
|
|
81
|
-
export type { ArcaClientOptions as A, ArcaClientConfig as a, ArcaServiceName as b, ArcaSoapExecutionOptions as c, ArcaSoapResponse as d, ArcaWsaaServiceId as e, ArcaAuthOptions as f, ArcaAuthCredentials as g, ArcaEnvironment as h, ArcaStore as i, ArcaWsaaSessionStore as j,
|
|
90
|
+
export type { ArcaClientOptions as A, ArcaClientConfig as a, ArcaServiceName as b, ArcaSoapExecutionOptions as c, ArcaSoapResponse as d, ArcaWsaaServiceId as e, ArcaAuthOptions as f, ArcaAuthCredentials as g, ArcaEnvironment as h, ArcaStore as i, ArcaWsaaSessionStore as j, ArcaLockOptions as k, ArcaLogLevel as l, ArcaLoggerConfig as m, ArcaPadronServiceName as n, ArcaRepresentedTaxId as o, ArcaServiceTarget as p, ArcaWsaaSessionKey as q };
|
package/dist/types.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { g as ArcaAuthCredentials, f as ArcaAuthOptions, A as ArcaClientConfig, h as ArcaEnvironment,
|
|
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-
|
|
2
|
-
import { W as WsaaAuthModule, S as SoapTransport } from './index-
|
|
3
|
-
import { e as ArcaAuthorizationOutcome,
|
|
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,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createWsfeService
|
|
3
|
-
} from "./chunk-
|
|
4
|
-
import "./chunk-
|
|
5
|
-
import "./chunk-
|
|
6
|
-
import "./chunk-
|
|
3
|
+
} from "./chunk-67ISWKGE.mjs";
|
|
4
|
+
import "./chunk-HLSFMWRT.mjs";
|
|
5
|
+
import "./chunk-7MNVZSW6.mjs";
|
|
6
|
+
import "./chunk-Q7IURW54.mjs";
|
|
7
7
|
export {
|
|
8
8
|
createWsfeService
|
|
9
9
|
};
|
package/dist/wsmtxca.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { W as WsaaAuthModule, S as SoapTransport } from './index-
|
|
3
|
-
import { e as ArcaAuthorizationOutcome,
|
|
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,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createWsmtxcaService
|
|
3
|
-
} from "./chunk-
|
|
4
|
-
import "./chunk-
|
|
5
|
-
import "./chunk-
|
|
6
|
-
import "./chunk-
|
|
3
|
+
} from "./chunk-GQGYO2Z2.mjs";
|
|
4
|
+
import "./chunk-HLSFMWRT.mjs";
|
|
5
|
+
import "./chunk-7MNVZSW6.mjs";
|
|
6
|
+
import "./chunk-Q7IURW54.mjs";
|
|
7
7
|
export {
|
|
8
8
|
createWsmtxcaService
|
|
9
9
|
};
|
package/package.json
CHANGED
|
@@ -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}: ${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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,IAAI,eAAe;AAAA,EACxD;AACA,MAAI,OAAO,iBAAiB,UAAU;AACpC,UAAM,aAAa,aAAa,KAAK;AACrC,WAAO,cAAc;AAAA,EACvB;AACA,SAAO;AACT;AAEA,SAAS,4BACP,SACA,WACA,QACQ;AACR,QAAM,eAAyD;AAAA,IAC7D,eAAe;AAAA,IACf,uBAAuB;AAAA,IACvB,sBAAsB;AAAA,IACtB,yBAAyB;AAAA,EAC3B;AACA,SAAO,oCAAoC,OAAO,IAAI,SAAS,KAAK,aAAa,MAAM,CAAC;AAC1F;","names":[]}
|
|
@@ -1 +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,e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