facturas 0.8.0 → 0.10.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/dist/index.d.ts CHANGED
@@ -1,16 +1,16 @@
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
5
  import { VoucherClass, ReceiverCondition } from './constants.js';
6
6
  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';
7
- import { A as ArcaAuthorizationOutcome, a as ArcaFiscalIssue, b as ArcaSafeErrorMetadata } from './errors-B0uouRzR.js';
8
- 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 './errors-B0uouRzR.js';
9
- import { S as SupportedVatRate, W as WsfeVoucherInput, a as WsfeVoucherInfo, b as WsfeDateInput, c as WsfeService } from './wsfe-CG_erq7V.js';
10
- 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-CG_erq7V.js';
7
+ import { A as ArcaAuthorizationOutcome, a as ArcaFiscalIssue, b as ArcaSafeErrorMetadata } from './fiscal-evidence-DBzakqBE.js';
8
+ 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';
9
+ import { S as SupportedVatRate, W as WsfeVoucherInput, a as WsfeVoucherInfo, b as WsfeDateInput, c as WsfeService } from './wsfe-DDY9E1GJ.js';
10
+ 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 WsfeAuthorizeVoucherInput, k as WsfeBuilderCurrencyInput, l as WsfeBuilderVatRate, m as WsfeBuyer, n as WsfeCatalogEntry, o as WsfeCurrencyType, p as WsfeOptionalField, q as WsfeQuotation, r as WsfeReceiverVatCondition, s as WsfeSalesPoint, t as WsfeServerStatus, u as WsfeTax, v as WsfeVatRate, w as WsfeVoucherLookupResult, x as buildFacturaB, y as buildFacturaC, z as createWsfeService } from './wsfe-DDY9E1GJ.js';
11
11
  import { WsmtxcaService } from './wsmtxca.js';
12
- export { CreateWsmtxcaServiceOptions, WsmtxcaAuthorizationOutcome, WsmtxcaAuthorizationResult, WsmtxcaAuthorizeVoucherInput, WsmtxcaLastAuthorizedVoucherResult, WsmtxcaSalesPoint, WsmtxcaSalesPointsResult, WsmtxcaVoucherInfo, WsmtxcaVoucherLookupOutcome, WsmtxcaVoucherLookupResult, createWsmtxcaService } from './wsmtxca.js';
13
- import './index-CVpygFb0.js';
12
+ export { CreateWsmtxcaServiceOptions, WsmtxcaAuthorizationOutcome, WsmtxcaAuthorizeVoucherInput, WsmtxcaLastAuthorizedVoucherResult, WsmtxcaSalesPoint, WsmtxcaSalesPointsResult, WsmtxcaVoucherInfo, WsmtxcaVoucherLookupOutcome, WsmtxcaVoucherLookupResult, createWsmtxcaService } from './wsmtxca.js';
13
+ import './index-CVGQyyYM.js';
14
14
 
15
15
  type VatRate = SupportedVatRate | "exempt" | "untaxed";
16
16
  type VatItem = {
@@ -79,13 +79,14 @@ type WsfeIdentityMatch = {
79
79
  reason: string;
80
80
  };
81
81
  /**
82
- * Compares the invoice subset supported by vouchers.issue(). This proves
83
- * consistency, not authorship; callers must serialize writers per taxpayer,
84
- * sales point and voucher type. Unsupported exact-API extensions are incomplete.
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
85
  */
86
86
  declare function matchWsfeVoucherIdentity(sent: WsfeVoucherInput, number: number, found: WsfeVoucherInfo): WsfeIdentityMatch;
87
87
 
88
88
  type IssueOptions = {
89
+ idempotencyKey?: string;
89
90
  representedTaxId?: number | string;
90
91
  forceRefresh?: boolean;
91
92
  include?: {
@@ -100,6 +101,16 @@ type IssuedVoucher = VoucherCoordinates & {
100
101
  caeExpiry: string;
101
102
  amounts: IssueAmounts;
102
103
  };
104
+ /**
105
+ * What issue() would send, derived with zero I/O. The voucher number is absent
106
+ * because it is only known when the number is reserved at issuance.
107
+ */
108
+ type IssuePreview = {
109
+ voucherClass: VoucherClass;
110
+ voucherType: number;
111
+ amounts: IssueAmounts;
112
+ request: WsfeVoucherInput;
113
+ };
103
114
  type WithRaw<T, O extends IssueOptions> = T & (true extends NonNullable<O["include"]>["raw"] ? {
104
115
  raw?: Record<string, unknown>;
105
116
  } : unknown);
@@ -115,7 +126,7 @@ type WithSent<O extends IssueOptions> = O extends {
115
126
  type Evidence<K extends ArcaAuthorizationOutcome<"wsfe">["kind"], O extends IssueOptions> = WithRaw<Omit<Extract<ArcaAuthorizationOutcome<"wsfe">, {
116
127
  kind: K;
117
128
  }>, "raw">, O>;
118
- /** Fiscal outcomes are returned, never thrown or automatically resubmitted. */
129
+ /** Fiscal outcomes are returned. Keyed replays authorize only after not_found. */
119
130
  type IssueOutcome<O extends IssueOptions = {
120
131
  include?: never;
121
132
  }> = ({
@@ -185,21 +196,61 @@ type IssueInput = IssueCommon & ({
185
196
  items: readonly AmountItem[];
186
197
  });
187
198
 
199
+ /**
200
+ * The credited lines and, at most, the note's own sales point and date.
201
+ * Class, receiver, currency, concept and service dates come from the original.
202
+ *
203
+ * The mode is explicit: `items` credits the chosen lines, `all: true` credits
204
+ * the whole original. A forgotten field never credits the whole invoice.
205
+ */
206
+ type CreditNoteInput = {
207
+ /** The authorized invoice the note corrects. */
208
+ for: VoucherCoordinates;
209
+ salesPoint?: number;
210
+ date?: WsfeDateInput;
211
+ } & ({
212
+ items: IssueInput["items"];
213
+ total?: number;
214
+ all?: never;
215
+ } | {
216
+ all: true;
217
+ items?: never;
218
+ total?: never;
219
+ });
220
+
188
221
  type VouchersService = {
189
222
  /**
190
- * Single-writer contract: serialize calls per (representedTaxId, salesPoint,
191
- * voucherType), including concurrent promises in one process. The SDK does not
192
- * coordinate writers; uncoordinated calls collide on ARCA 10016. Servers and
193
- * queues must persist attempts and use wsfe.authorizeVoucherOutcome() directly.
194
- * See the "does not serialize concurrent calls" test in services/vouchers.test.ts.
223
+ * Issues a credit note against an authorized A, B or C invoice. The note
224
+ * credits the chosen `items`, or the whole original with `all: true`.
195
225
  *
196
- * One next-number read, one authorization attempt (zero transport retries), and
197
- * at most one identity-matched lookup after indeterminate. Never resubmits.
226
+ * Everything except the credited lines, the note's sales point and its date
227
+ * comes from the original: class, receiver, currency, concept and service
228
+ * dates. ARCA has no cancellation; both modes write a real fiscal document.
229
+ */
230
+ issueCreditNote<O extends IssueOptions = {
231
+ include?: never;
232
+ }>(input: CreditNoteInput, options?: O): Promise<IssueOutcome<O>>;
233
+ /**
234
+ * Configure a store and pass idempotencyKey to recover retries after a crash.
235
+ *
236
+ * Without a key: one next-number read, one authorization and at most one lookup.
237
+ * Keyed replay consults the reserved number; only not_found permits a write.
198
238
  * Local validation and next-number read failures throw before authorization.
199
239
  */
200
240
  issue<O extends IssueOptions = {
201
241
  include?: never;
202
242
  }>(input: IssueInput, options?: O): Promise<IssueOutcome<O>>;
243
+ /**
244
+ * Derives what issue() would send for the same input, with no I/O at all:
245
+ * no store, no WSAA, no SOAP and no next-number read.
246
+ *
247
+ * It throws every input error issue() throws before its first call, so a
248
+ * caller that previews and then issues sees no new local error.
249
+ */
250
+ preview(input: IssueInput, options?: PreviewOptions): IssuePreview;
251
+ };
252
+ type PreviewOptions = {
253
+ representedTaxId?: number | string;
203
254
  };
204
255
 
205
256
  /** Immutable, credential-free operational view of an ARCA client configuration. */
@@ -213,19 +264,24 @@ type ArcaClientConfigView = Readonly<{
213
264
  /** Fully wired ARCA client with access to all service modules. */
214
265
  type ArcaClient = {
215
266
  readonly config: ArcaClientConfigView;
267
+ /** Issues an invoice from business input. Idempotent with a store and key. */
268
+ issue: VouchersService["issue"];
269
+ /** Derives what issue() would send for the same input, with no I/O. */
270
+ preview: VouchersService["preview"];
271
+ /** Issues a credit note against an authorized invoice, partial or full. */
272
+ issueCreditNote: VouchersService["issueCreditNote"];
216
273
  wsfe: WsfeService;
217
- vouchers: VouchersService;
218
274
  wsmtxca: WsmtxcaService;
219
275
  padron: PadronService;
220
276
  };
221
277
  /**
222
278
  * Creates an ARCA client from the given configuration.
223
279
  * Validates the config, wires WSAA authentication and SOAP transport,
224
- * and returns an object with `.vouchers`, `.wsfe`, `.wsmtxca`, and `.padron` service modules.
280
+ * and returns an object with `issue()`, `preview()`, `issueCreditNote()` and the `.wsfe`, `.wsmtxca`, and `.padron` service modules.
225
281
  *
226
282
  * @throws {ArcaConfigurationError} When the config is missing or invalid.
227
283
  */
228
- declare function createArcaClient(config: ArcaClientConfig): ArcaClient;
284
+ declare function createArcaClient(config?: ArcaClientOptions): ArcaClient;
229
285
 
230
286
  /** Valid ARCA environment names. */
231
287
  declare const ARCA_ENVIRONMENTS: readonly ["production", "test"];
@@ -259,6 +315,35 @@ declare function createArcaClientConfigFromEnv(options?: CreateArcaClientConfigF
259
315
  */
260
316
  declare function assertArcaClientConfig(config: ArcaClientConfig): void;
261
317
 
318
+ /** Persistent store for a single server with a private durable volume. */
319
+ declare function createFileStore(directory: string): ArcaStore;
320
+
321
+ /** In-process store for tests; reservations do not survive a restart. */
322
+ declare function createMemoryStore(): ArcaStore;
323
+
324
+ type Row = {
325
+ key?: string;
326
+ value?: string;
327
+ };
328
+ /** Uses the caller's SQL client; provision the table before use. */
329
+ declare function createPostgresStore({ query, table, }: {
330
+ query: (text: string, params: string[]) => Promise<Row[] | {
331
+ rows: Row[];
332
+ }>;
333
+ table?: string;
334
+ }): ArcaStore;
335
+
336
+ type RedisClient = {
337
+ get(key: string): Promise<unknown>;
338
+ set(key: string, value: string): Promise<unknown>;
339
+ call?(...args: string[]): Promise<unknown>;
340
+ del?(key: string): Promise<unknown>;
341
+ };
342
+ /** Uses ioredis or Upstash without importing either driver. */
343
+ declare function createRedisStore(client: RedisClient, options?: {
344
+ flavor?: "ioredis" | "upstash";
345
+ }): ArcaStore;
346
+
262
347
  declare function createMemoryWsaaSessionStore(): ArcaWsaaSessionStore;
263
348
 
264
- export { ARCA_ENVIRONMENTS, ARCA_ENV_VARIABLES, type AmountItem, ArcaAuthorizationOutcome, type ArcaClient, ArcaClientConfig, type ArcaClientConfigView, ArcaEnvironment, ArcaFiscalIssue, ArcaSafeErrorMetadata, 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, createMemoryWsaaSessionStore, matchWsfeVoucherIdentity, resolveArcaEnvironment };
349
+ export { ARCA_ENVIRONMENTS, ARCA_ENV_VARIABLES, type AmountItem, ArcaAuthorizationOutcome, type ArcaClient, ArcaClientOptions as ArcaClientConfig, type ArcaClientConfigView, ArcaEnvironment, ArcaFiscalIssue, ArcaSafeErrorMetadata, ArcaStore, ArcaWsaaSessionStore, type CreateArcaClientConfigFromEnvOptions, type CreditNoteInput, type IssueAmounts, type IssueCommon, type IssueInput, type IssueOptions, type IssueOutcome, type IssuePreview, 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 };