facturas 0.7.1 → 0.9.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 +799 -27
  2. package/dist/{chunk-IOKZX6CA.mjs → chunk-4QVFXT35.mjs} +2 -2
  3. package/dist/chunk-76WU5BVI.mjs +109 -0
  4. package/dist/chunk-76WU5BVI.mjs.map +1 -0
  5. package/dist/{chunk-EDY3PNKJ.mjs → chunk-7LEKQ4P7.mjs} +2 -2
  6. package/dist/{chunk-OHHXHYLV.mjs → chunk-RCM4NAAG.mjs} +244 -48
  7. package/dist/chunk-RCM4NAAG.mjs.map +1 -0
  8. package/dist/{chunk-A3C3Y5PI.mjs → chunk-XNBD5NVL.mjs} +32 -31
  9. package/dist/chunk-XNBD5NVL.mjs.map +1 -0
  10. package/dist/{chunk-MBWOFO67.mjs → chunk-ZOSNASXB.mjs} +14 -2
  11. package/dist/chunk-ZOSNASXB.mjs.map +1 -0
  12. package/dist/constants.d.ts +49 -1
  13. package/dist/constants.mjs +9 -1
  14. package/dist/errors.d.ts +2 -2
  15. package/dist/errors.mjs +5 -3
  16. package/dist/{fiscal-evidence-BQuBbJ3h.d.ts → fiscal-evidence-DBzakqBE.d.ts} +11 -3
  17. package/dist/{index-CVpygFb0.d.ts → index-CVGQyyYM.d.ts} +1 -1
  18. package/dist/index.d.ts +238 -9
  19. package/dist/index.mjs +1343 -30
  20. package/dist/index.mjs.map +1 -1
  21. package/dist/padron.d.ts +2 -2
  22. package/dist/padron.mjs +2 -2
  23. package/dist/{types-BXq0da71.d.ts → types-BiznC1-X.d.ts} +12 -1
  24. package/dist/types.d.ts +1 -1
  25. package/dist/wsfe-DF0jAE2k.d.ts +325 -0
  26. package/dist/wsfe.d.ts +4 -309
  27. package/dist/wsfe.mjs +4 -4
  28. package/dist/wsmtxca.d.ts +14 -5
  29. package/dist/wsmtxca.mjs +3 -3
  30. package/package.json +1 -1
  31. package/dist/chunk-A3C3Y5PI.mjs.map +0 -1
  32. package/dist/chunk-MBWOFO67.mjs.map +0 -1
  33. package/dist/chunk-OHHXHYLV.mjs.map +0 -1
  34. package/dist/chunk-VVY2LZIZ.mjs +0 -61
  35. package/dist/chunk-VVY2LZIZ.mjs.map +0 -1
  36. /package/dist/{chunk-IOKZX6CA.mjs.map → chunk-4QVFXT35.mjs.map} +0 -0
  37. /package/dist/{chunk-EDY3PNKJ.mjs.map → chunk-7LEKQ4P7.mjs.map} +0 -0
@@ -60,5 +60,53 @@ declare const ARCA_CURRENCIES: {
60
60
  readonly PES: "PES";
61
61
  readonly DOL: "DOL";
62
62
  };
63
+ /** Legal assertions supported by the invoice facade; never inferred from Padrón. */
64
+ type IssuerCondition = "responsable_inscripto" | "monotributo" | "exento" | "no_alcanzado";
65
+ type ReceiverCondition = IssuerCondition | "consumidor_final";
66
+ type VoucherClass = "A" | "B" | "C";
67
+ declare const ARCA_RECEIVER_CONDITION_IDS: {
68
+ readonly responsable_inscripto: 1;
69
+ readonly monotributo: 6;
70
+ readonly exento: 4;
71
+ readonly consumidor_final: 5;
72
+ readonly no_alcanzado: 15;
73
+ };
74
+ declare const ARCA_ISSUER_CONDITION_IDS: {
75
+ readonly responsable_inscripto: 1;
76
+ readonly monotributo: 6;
77
+ readonly exento: 4;
78
+ readonly no_alcanzado: 15;
79
+ };
80
+ declare const ARCA_FINAL_CONSUMER_IDENTIFICATION_THRESHOLD_MINOR_UNITS = 1000000000n;
81
+ declare const ARCA_INVOICE_CLASS_BY_ISSUER: {
82
+ readonly responsable_inscripto: {
83
+ readonly responsable_inscripto: "A";
84
+ readonly monotributo: "A";
85
+ readonly exento: "B";
86
+ readonly consumidor_final: "B";
87
+ readonly no_alcanzado: "B";
88
+ };
89
+ readonly monotributo: {
90
+ readonly responsable_inscripto: "C";
91
+ readonly monotributo: "C";
92
+ readonly exento: "C";
93
+ readonly consumidor_final: "C";
94
+ readonly no_alcanzado: "C";
95
+ };
96
+ readonly exento: {
97
+ readonly responsable_inscripto: "C";
98
+ readonly monotributo: "C";
99
+ readonly exento: "C";
100
+ readonly consumidor_final: "C";
101
+ readonly no_alcanzado: "C";
102
+ };
103
+ readonly no_alcanzado: {
104
+ readonly responsable_inscripto: "C";
105
+ readonly monotributo: "C";
106
+ readonly exento: "C";
107
+ readonly consumidor_final: "C";
108
+ readonly no_alcanzado: "C";
109
+ };
110
+ };
63
111
 
64
- export { ARCA_CONCEPT_TYPES, ARCA_CURRENCIES, ARCA_CURRENCY_IDS, ARCA_DOCUMENT_TYPES, ARCA_RECEIVER_VAT_CONDITIONS, ARCA_VAT_RATES, ARCA_VOUCHER_TYPES, ISO_CURRENCIES };
112
+ export { ARCA_CONCEPT_TYPES, ARCA_CURRENCIES, ARCA_CURRENCY_IDS, ARCA_DOCUMENT_TYPES, ARCA_FINAL_CONSUMER_IDENTIFICATION_THRESHOLD_MINOR_UNITS, ARCA_INVOICE_CLASS_BY_ISSUER, ARCA_ISSUER_CONDITION_IDS, ARCA_RECEIVER_CONDITION_IDS, ARCA_RECEIVER_VAT_CONDITIONS, ARCA_VAT_RATES, ARCA_VOUCHER_TYPES, ISO_CURRENCIES, type IssuerCondition, type ReceiverCondition, type VoucherClass };
@@ -3,16 +3,24 @@ import {
3
3
  ARCA_CURRENCIES,
4
4
  ARCA_CURRENCY_IDS,
5
5
  ARCA_DOCUMENT_TYPES,
6
+ ARCA_FINAL_CONSUMER_IDENTIFICATION_THRESHOLD_MINOR_UNITS,
7
+ ARCA_INVOICE_CLASS_BY_ISSUER,
8
+ ARCA_ISSUER_CONDITION_IDS,
9
+ ARCA_RECEIVER_CONDITION_IDS,
6
10
  ARCA_RECEIVER_VAT_CONDITIONS,
7
11
  ARCA_VAT_RATES,
8
12
  ARCA_VOUCHER_TYPES,
9
13
  ISO_CURRENCIES
10
- } from "./chunk-VVY2LZIZ.mjs";
14
+ } from "./chunk-76WU5BVI.mjs";
11
15
  export {
12
16
  ARCA_CONCEPT_TYPES,
13
17
  ARCA_CURRENCIES,
14
18
  ARCA_CURRENCY_IDS,
15
19
  ARCA_DOCUMENT_TYPES,
20
+ ARCA_FINAL_CONSUMER_IDENTIFICATION_THRESHOLD_MINOR_UNITS,
21
+ ARCA_INVOICE_CLASS_BY_ISSUER,
22
+ ARCA_ISSUER_CONDITION_IDS,
23
+ ARCA_RECEIVER_CONDITION_IDS,
16
24
  ARCA_RECEIVER_VAT_CONDITIONS,
17
25
  ARCA_VAT_RATES,
18
26
  ARCA_VOUCHER_TYPES,
package/dist/errors.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import './types-BXq0da71.js';
2
- export { A as ArcaAuthenticationError, a as ArcaAuthenticationErrorOptions, c as ArcaAuthenticationReason, f as ArcaConfigurationError, g as ArcaError, l as ArcaInputError, m as ArcaInputErrorCode, n as ArcaInputErrorOptions, o as ArcaInvalidSoapResponseError, p as ArcaServiceError, q as ArcaSoapFaultError, r as ArcaTransportError, t as isArcaAuthenticationError } from './fiscal-evidence-BQuBbJ3h.js';
1
+ import './types-BiznC1-X.js';
2
+ export { c as ArcaAuthenticationError, d as ArcaAuthenticationErrorOptions, f as ArcaAuthenticationReason, h as ArcaConfigurationError, i as ArcaError, m as ArcaInputError, n as ArcaInputErrorCode, o as ArcaInputErrorOptions, p as ArcaInvalidSoapResponseError, b as ArcaSafeErrorMetadata, q as ArcaServiceError, r as ArcaSoapFaultError, s as ArcaTransportError, u as isArcaAuthenticationError, v as toArcaSafeErrorMetadata } from './fiscal-evidence-DBzakqBE.js';
package/dist/errors.mjs CHANGED
@@ -7,8 +7,9 @@ import {
7
7
  ArcaServiceError,
8
8
  ArcaSoapFaultError,
9
9
  ArcaTransportError,
10
- isArcaAuthenticationError
11
- } from "./chunk-MBWOFO67.mjs";
10
+ isArcaAuthenticationError,
11
+ toArcaSafeErrorMetadata
12
+ } from "./chunk-ZOSNASXB.mjs";
12
13
  export {
13
14
  ArcaAuthenticationError,
14
15
  ArcaConfigurationError,
@@ -18,6 +19,7 @@ export {
18
19
  ArcaServiceError,
19
20
  ArcaSoapFaultError,
20
21
  ArcaTransportError,
21
- isArcaAuthenticationError
22
+ isArcaAuthenticationError,
23
+ toArcaSafeErrorMetadata
22
24
  };
23
25
  //# sourceMappingURL=errors.mjs.map
@@ -1,4 +1,4 @@
1
- import { A as ArcaServiceName } from './types-BXq0da71.js';
1
+ import { A as ArcaServiceName } from './types-BiznC1-X.js';
2
2
 
3
3
  /** Base error class for all ARCA-related errors. */
4
4
  declare class ArcaError extends Error {
@@ -12,7 +12,7 @@ declare class ArcaConfigurationError extends ArcaError {
12
12
  constructor(message: string, options?: ErrorOptions);
13
13
  }
14
14
  /** Stable routing codes for caller-provided input failures. */
15
- type ArcaInputErrorCode = "ARCA_INPUT_INVALID_DATE" | "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";
15
+ type ArcaInputErrorCode = "ARCA_INPUT_IDEMPOTENCY_MISMATCH" | "ARCA_INPUT_INVALID_DATE" | "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
16
  type ArcaInputErrorOptions = ErrorOptions & {
17
17
  code: ArcaInputErrorCode;
18
18
  field?: string;
@@ -110,6 +110,14 @@ declare class ArcaServiceError extends ArcaError {
110
110
  issues?: readonly ArcaFiscalIssue[];
111
111
  });
112
112
  }
113
+ /** Narrow error evidence: never includes a cause, raw response or stack. */
114
+ type ArcaSafeErrorMetadata = {
115
+ name: string;
116
+ message: string;
117
+ code?: string;
118
+ statusCode?: number;
119
+ };
120
+ declare function toArcaSafeErrorMetadata(error: unknown): ArcaSafeErrorMetadata;
113
121
 
114
122
  /** ARCA services that authorize fiscal vouchers. */
115
123
  type ArcaFiscalService = "wsfe" | "wsmtxca";
@@ -186,4 +194,4 @@ type ArcaVoucherLookupResult<TVoucher, TService extends ArcaFiscalService = Arca
186
194
  raw: Record<string, unknown>;
187
195
  };
188
196
 
189
- export { ArcaAuthenticationError as A, 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, type ArcaFiscalService as k, ArcaInputError as l, type ArcaInputErrorCode as m, type ArcaInputErrorOptions as n, ArcaInvalidSoapResponseError as o, ArcaServiceError as p, ArcaSoapFaultError as q, ArcaTransportError as r, type ArcaVoucherLookupResult as s, isArcaAuthenticationError as t };
197
+ export { type ArcaAuthorizationOutcome as A, type ArcaFiscalIssue as a, type ArcaSafeErrorMetadata as b, ArcaAuthenticationError as c, type ArcaAuthenticationErrorOptions as d, type ArcaAuthenticationEvidence as e, type ArcaAuthenticationReason as f, type ArcaAuthorizationIndeterminateReason as g, ArcaConfigurationError as h, ArcaError as i, type ArcaFiscalResultLevel as j, type ArcaFiscalResults as k, type ArcaFiscalService as l, ArcaInputError as m, type ArcaInputErrorCode as n, type ArcaInputErrorOptions as o, ArcaInvalidSoapResponseError as p, ArcaServiceError as q, ArcaSoapFaultError as r, ArcaTransportError as s, type ArcaVoucherLookupResult as t, isArcaAuthenticationError as u, toArcaSafeErrorMetadata as v };
@@ -1,4 +1,4 @@
1
- import { a as ArcaSoapExecutionOptions, b as ArcaSoapResponse, c as ArcaWsaaServiceId, d as ArcaAuthOptions, e as ArcaAuthCredentials } from './types-BXq0da71.js';
1
+ import { a as ArcaSoapExecutionOptions, b as ArcaSoapResponse, c as ArcaWsaaServiceId, d as ArcaAuthOptions, e as ArcaAuthCredentials } from './types-BiznC1-X.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,13 +1,209 @@
1
- import { f as ArcaEnvironment, g as ArcaClientConfig, h as ArcaWsaaSessionStore } from './types-BXq0da71.js';
2
- export { e as ArcaAuthCredentials, d as ArcaAuthOptions, i as ArcaLogLevel, j as ArcaLoggerConfig, k as ArcaPadronServiceName, l as ArcaRepresentedTaxId, A as ArcaServiceName, m as ArcaServiceTarget, c as ArcaWsaaServiceId, n as ArcaWsaaSessionKey } from './types-BXq0da71.js';
1
+ import { f as ArcaEnvironment, g as ArcaClientOptions, h as ArcaClientConfig, i as ArcaStore, j as ArcaWsaaSessionStore } from './types-BiznC1-X.js';
2
+ export { e as ArcaAuthCredentials, d as ArcaAuthOptions, k as ArcaLogLevel, l as ArcaLoggerConfig, m as ArcaPadronServiceName, n as ArcaRepresentedTaxId, A as ArcaServiceName, o as ArcaServiceTarget, c as ArcaWsaaServiceId, p as ArcaWsaaSessionKey } from './types-BiznC1-X.js';
3
3
  import { PadronService } from './padron.js';
4
4
  export { CreatePadronServiceOptions, PadronTaxIdLookupResult, PadronTaxpayerResult, createPadronService } from './padron.js';
5
- import { WsfeService } from './wsfe.js';
6
- export { BuildFacturaBInput, BuildFacturaCInput, CreateWsfeServiceOptions, WsfeActivity, WsfeActivityType, WsfeAssociatedPeriod, WsfeAssociatedVoucher, WsfeAuthorizationOutcome, WsfeAuthorizationResult, WsfeAuthorizeVoucherInput, WsfeBuilderCurrencyInput, WsfeBuilderVatRate, WsfeBuyer, WsfeCatalogEntry, WsfeCurrencyType, WsfeDateInput, WsfeOptionalField, WsfeQuotation, WsfeReceiverVatCondition, WsfeSalesPoint, WsfeServerStatus, WsfeTax, WsfeVatRate, WsfeVoucherInfo, WsfeVoucherInput, WsfeVoucherLookupResult, buildFacturaB, buildFacturaC, createWsfeService } from './wsfe.js';
5
+ import { S as SupportedVatRate, W as WsfeVoucherInput, a as WsfeVoucherInfo, b as WsfeDateInput, c as WsfeService } from './wsfe-DF0jAE2k.js';
6
+ export { B as BuildFacturaBInput, d as BuildFacturaCInput, C as CreateWsfeServiceOptions, e as WsfeActivity, f as WsfeActivityType, g as WsfeAssociatedPeriod, h as WsfeAssociatedVoucher, i as WsfeAuthorizationOutcome, j as WsfeAuthorizationResult, k as WsfeAuthorizeVoucherInput, l as WsfeBuilderCurrencyInput, m as WsfeBuilderVatRate, n as WsfeBuyer, o as WsfeCatalogEntry, p as WsfeCurrencyType, q as WsfeOptionalField, r as WsfeQuotation, s as WsfeReceiverVatCondition, t as WsfeSalesPoint, u as WsfeServerStatus, v as WsfeTax, w as WsfeVatRate, x as WsfeVoucherLookupResult, y as buildFacturaB, z as buildFacturaC, A as createWsfeService } from './wsfe-DF0jAE2k.js';
7
+ import { VoucherClass, ReceiverCondition } from './constants.js';
8
+ export { ARCA_FINAL_CONSUMER_IDENTIFICATION_THRESHOLD_MINOR_UNITS, ARCA_INVOICE_CLASS_BY_ISSUER, ARCA_ISSUER_CONDITION_IDS, ARCA_RECEIVER_CONDITION_IDS, IssuerCondition } from './constants.js';
9
+ import { A as ArcaAuthorizationOutcome, a as ArcaFiscalIssue, b as ArcaSafeErrorMetadata } from './fiscal-evidence-DBzakqBE.js';
10
+ export { c as ArcaAuthenticationError, d as ArcaAuthenticationErrorOptions, e as ArcaAuthenticationEvidence, f as ArcaAuthenticationReason, g as ArcaAuthorizationIndeterminateReason, h as ArcaConfigurationError, i as ArcaError, j as ArcaFiscalResultLevel, k as ArcaFiscalResults, l as ArcaFiscalService, m as ArcaInputError, n as ArcaInputErrorCode, o as ArcaInputErrorOptions, p as ArcaInvalidSoapResponseError, q as ArcaServiceError, r as ArcaSoapFaultError, s as ArcaTransportError, t as ArcaVoucherLookupResult, u as isArcaAuthenticationError, v as toArcaSafeErrorMetadata } from './fiscal-evidence-DBzakqBE.js';
7
11
  import { WsmtxcaService } from './wsmtxca.js';
8
12
  export { CreateWsmtxcaServiceOptions, WsmtxcaAuthorizationOutcome, WsmtxcaAuthorizationResult, WsmtxcaAuthorizeVoucherInput, WsmtxcaLastAuthorizedVoucherResult, WsmtxcaSalesPoint, WsmtxcaSalesPointsResult, WsmtxcaVoucherInfo, WsmtxcaVoucherLookupOutcome, WsmtxcaVoucherLookupResult, createWsmtxcaService } from './wsmtxca.js';
9
- 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 ArcaFiscalService, l as ArcaInputError, m as ArcaInputErrorCode, n as ArcaInputErrorOptions, o as ArcaInvalidSoapResponseError, p as ArcaServiceError, q as ArcaSoapFaultError, r as ArcaTransportError, s as ArcaVoucherLookupResult, t as isArcaAuthenticationError } from './fiscal-evidence-BQuBbJ3h.js';
10
- import './index-CVpygFb0.js';
13
+ import './index-CVGQyyYM.js';
14
+
15
+ type VatRate = SupportedVatRate | "exempt" | "untaxed";
16
+ type VatItem = {
17
+ net: number;
18
+ gross?: never;
19
+ amount?: never;
20
+ vat: VatRate;
21
+ } | {
22
+ gross: number;
23
+ net?: never;
24
+ amount?: never;
25
+ vat: VatRate;
26
+ };
27
+ type AmountItem = {
28
+ amount: number;
29
+ vat?: never;
30
+ net?: never;
31
+ gross?: never;
32
+ };
33
+ type IssueAmounts = {
34
+ computedTotal: number;
35
+ sentTotal: number;
36
+ vatAdjustment: number;
37
+ };
38
+
39
+ type VoucherCoordinates = {
40
+ salesPoint: number;
41
+ voucherType: number;
42
+ number: number;
43
+ };
44
+ /** Raw-free consultation evidence. Missing provider fields remain absent. */
45
+ type VoucherSummary = {
46
+ number: number;
47
+ salesPoint?: number;
48
+ voucherType?: number;
49
+ date?: string;
50
+ concept?: number;
51
+ documentType?: number;
52
+ documentNumber?: string;
53
+ receiverVatConditionId?: number;
54
+ currencyId?: string;
55
+ exchangeRate?: number;
56
+ totalAmount?: number;
57
+ netAmount?: number;
58
+ vatAmount?: number;
59
+ exemptAmount?: number;
60
+ nonTaxableAmount?: number;
61
+ taxAmount?: number;
62
+ vatRates?: {
63
+ id: number;
64
+ baseAmount: number;
65
+ amount: number;
66
+ }[];
67
+ serviceStartDate?: string;
68
+ serviceEndDate?: string;
69
+ paymentDueDate?: string;
70
+ result?: string;
71
+ cae?: string;
72
+ caeExpiry?: string;
73
+ };
74
+ type WsfeIdentityMatch = {
75
+ matches: true;
76
+ } | {
77
+ matches: false;
78
+ evidence: "conflict" | "incomplete";
79
+ reason: string;
80
+ };
81
+ /**
82
+ * Compares the invoice subset supported by issue(). This proves
83
+ * consistency, not authorship. Configure a store and pass idempotencyKey for retries.
84
+ * Unsupported exact-API extensions are incomplete.
85
+ */
86
+ declare function matchWsfeVoucherIdentity(sent: WsfeVoucherInput, number: number, found: WsfeVoucherInfo): WsfeIdentityMatch;
87
+
88
+ type IssueOptions = {
89
+ idempotencyKey?: string;
90
+ representedTaxId?: number | string;
91
+ forceRefresh?: boolean;
92
+ include?: {
93
+ raw?: boolean;
94
+ exactInput?: boolean;
95
+ };
96
+ };
97
+ type IssuedVoucher = VoucherCoordinates & {
98
+ voucherClass: VoucherClass;
99
+ date: string;
100
+ cae: string;
101
+ caeExpiry: string;
102
+ amounts: IssueAmounts;
103
+ };
104
+ type WithRaw<T, O extends IssueOptions> = T & (true extends NonNullable<O["include"]>["raw"] ? {
105
+ raw?: Record<string, unknown>;
106
+ } : unknown);
107
+ type WithSent<O extends IssueOptions> = O extends {
108
+ include: {
109
+ exactInput: true;
110
+ };
111
+ } ? {
112
+ sent: WsfeVoucherInput;
113
+ } : true extends NonNullable<O["include"]>["exactInput"] ? {
114
+ sent?: WsfeVoucherInput;
115
+ } : unknown;
116
+ type Evidence<K extends ArcaAuthorizationOutcome<"wsfe">["kind"], O extends IssueOptions> = WithRaw<Omit<Extract<ArcaAuthorizationOutcome<"wsfe">, {
117
+ kind: K;
118
+ }>, "raw">, O>;
119
+ /** Fiscal outcomes are returned. Keyed replays authorize only after not_found. */
120
+ type IssueOutcome<O extends IssueOptions = {
121
+ include?: never;
122
+ }> = ({
123
+ kind: "authorized";
124
+ recoveredByMatch: false;
125
+ voucher: IssuedVoucher;
126
+ authorization: Evidence<"authorized", O>;
127
+ } & WithSent<O>) | ({
128
+ kind: "authorized";
129
+ recoveredByMatch: true;
130
+ voucher: IssuedVoucher;
131
+ attempt: Evidence<"indeterminate", O>;
132
+ lookup: WithRaw<VoucherSummary, O>;
133
+ } & WithSent<O>) | {
134
+ kind: "rejected";
135
+ attempted: VoucherCoordinates;
136
+ issues: ArcaFiscalIssue[];
137
+ authorization: Evidence<"rejected", O>;
138
+ } | {
139
+ kind: "indeterminate";
140
+ attempted: VoucherCoordinates;
141
+ attempt: Evidence<"indeterminate", O>;
142
+ lookup: WithRaw<{
143
+ kind: "not_found";
144
+ }, O> | WithRaw<{
145
+ kind: "incomplete";
146
+ reason: string;
147
+ }, O> | {
148
+ kind: "failed";
149
+ error: ArcaSafeErrorMetadata;
150
+ };
151
+ } | {
152
+ kind: "conflict";
153
+ attempted: VoucherCoordinates;
154
+ attempt: Evidence<"indeterminate", O>;
155
+ found: WithRaw<VoucherSummary, O>;
156
+ reason: string;
157
+ };
158
+
159
+ type Receiver = {
160
+ condition: "consumidor_final";
161
+ cuit?: number | string;
162
+ dni?: number | string;
163
+ } | {
164
+ condition: Exclude<ReceiverCondition, "consumidor_final">;
165
+ cuit: number | string;
166
+ dni?: never;
167
+ };
168
+ type IssueCommon = {
169
+ salesPoint: number;
170
+ to: Receiver;
171
+ total?: number;
172
+ date?: WsfeDateInput;
173
+ currency?: "ARS" | "USD";
174
+ exchangeRate?: string;
175
+ service?: {
176
+ from: WsfeDateInput;
177
+ to: WsfeDateInput;
178
+ dueDate: WsfeDateInput;
179
+ };
180
+ };
181
+ type IssueInput = IssueCommon & ({
182
+ issuer: "responsable_inscripto";
183
+ items: readonly VatItem[];
184
+ } | {
185
+ issuer: "monotributo" | "exento" | "no_alcanzado";
186
+ items: readonly AmountItem[];
187
+ });
188
+
189
+ type VouchersService = {
190
+ /** Creates a full credit note associated to an authorized A, B or C invoice. */
191
+ cancel<O extends IssueOptions & {
192
+ date?: WsfeDateInput;
193
+ } = {
194
+ include?: never;
195
+ }>(target: VoucherCoordinates, options?: O): Promise<IssueOutcome<O>>;
196
+ /**
197
+ * Configure a store and pass idempotencyKey to recover retries after a crash.
198
+ *
199
+ * Without a key: one next-number read, one authorization and at most one lookup.
200
+ * Keyed replay consults the reserved number; only not_found permits a write.
201
+ * Local validation and next-number read failures throw before authorization.
202
+ */
203
+ issue<O extends IssueOptions = {
204
+ include?: never;
205
+ }>(input: IssueInput, options?: O): Promise<IssueOutcome<O>>;
206
+ };
11
207
 
12
208
  /** Immutable, credential-free operational view of an ARCA client configuration. */
13
209
  type ArcaClientConfigView = Readonly<{
@@ -20,6 +216,10 @@ type ArcaClientConfigView = Readonly<{
20
216
  /** Fully wired ARCA client with access to all service modules. */
21
217
  type ArcaClient = {
22
218
  readonly config: ArcaClientConfigView;
219
+ /** Issues an invoice from business input. Idempotent with a store and key. */
220
+ issue: VouchersService["issue"];
221
+ /** Issues a full credit note against an authorized invoice. */
222
+ cancel: VouchersService["cancel"];
23
223
  wsfe: WsfeService;
24
224
  wsmtxca: WsmtxcaService;
25
225
  padron: PadronService;
@@ -27,11 +227,11 @@ type ArcaClient = {
27
227
  /**
28
228
  * Creates an ARCA client from the given configuration.
29
229
  * Validates the config, wires WSAA authentication and SOAP transport,
30
- * and returns an object with `.wsfe`, `.wsmtxca`, and `.padron` service modules.
230
+ * and returns an object with `issue()`, `cancel()` and the `.wsfe`, `.wsmtxca`, and `.padron` service modules.
31
231
  *
32
232
  * @throws {ArcaConfigurationError} When the config is missing or invalid.
33
233
  */
34
- declare function createArcaClient(config: ArcaClientConfig): ArcaClient;
234
+ declare function createArcaClient(config?: ArcaClientOptions): ArcaClient;
35
235
 
36
236
  /** Valid ARCA environment names. */
37
237
  declare const ARCA_ENVIRONMENTS: readonly ["production", "test"];
@@ -65,6 +265,35 @@ declare function createArcaClientConfigFromEnv(options?: CreateArcaClientConfigF
65
265
  */
66
266
  declare function assertArcaClientConfig(config: ArcaClientConfig): void;
67
267
 
268
+ /** Persistent store for a single server with a private durable volume. */
269
+ declare function createFileStore(directory: string): ArcaStore;
270
+
271
+ /** In-process store for tests; reservations do not survive a restart. */
272
+ declare function createMemoryStore(): ArcaStore;
273
+
274
+ type Row = {
275
+ key?: string;
276
+ value?: string;
277
+ };
278
+ /** Uses the caller's SQL client; provision the table before use. */
279
+ declare function createPostgresStore({ query, table, }: {
280
+ query: (text: string, params: string[]) => Promise<Row[] | {
281
+ rows: Row[];
282
+ }>;
283
+ table?: string;
284
+ }): ArcaStore;
285
+
286
+ type RedisClient = {
287
+ get(key: string): Promise<unknown>;
288
+ set(key: string, value: string): Promise<unknown>;
289
+ call?(...args: string[]): Promise<unknown>;
290
+ del?(key: string): Promise<unknown>;
291
+ };
292
+ /** Uses ioredis or Upstash without importing either driver. */
293
+ declare function createRedisStore(client: RedisClient, options?: {
294
+ flavor?: "ioredis" | "upstash";
295
+ }): ArcaStore;
296
+
68
297
  declare function createMemoryWsaaSessionStore(): ArcaWsaaSessionStore;
69
298
 
70
- export { ARCA_ENVIRONMENTS, ARCA_ENV_VARIABLES, type ArcaClient, ArcaClientConfig, type ArcaClientConfigView, ArcaEnvironment, ArcaWsaaSessionStore, type CreateArcaClientConfigFromEnvOptions, PadronService, WsfeService, WsmtxcaService, assertArcaClientConfig, createArcaClient, createArcaClientConfigFromEnv, createMemoryWsaaSessionStore, resolveArcaEnvironment };
299
+ export { ARCA_ENVIRONMENTS, ARCA_ENV_VARIABLES, type AmountItem, ArcaAuthorizationOutcome, type ArcaClient, ArcaClientOptions as ArcaClientConfig, type ArcaClientConfigView, ArcaEnvironment, ArcaFiscalIssue, ArcaSafeErrorMetadata, ArcaStore, ArcaWsaaSessionStore, type CreateArcaClientConfigFromEnvOptions, type IssueAmounts, type IssueCommon, type IssueInput, type IssueOptions, type IssueOutcome, type IssuedVoucher, PadronService, type Receiver, ReceiverCondition, type VatItem, type VatRate, VoucherClass, type VoucherCoordinates, type VoucherSummary, type VouchersService, WsfeDateInput, type WsfeIdentityMatch, WsfeService, WsfeVoucherInfo, WsfeVoucherInput, WsmtxcaService, assertArcaClientConfig, createArcaClient, createArcaClientConfigFromEnv, createFileStore, createMemoryStore, createMemoryWsaaSessionStore, createPostgresStore, createRedisStore, matchWsfeVoucherIdentity, resolveArcaEnvironment };