facturas 0.9.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/README.md +95 -34
- package/dist/{chunk-XNBD5NVL.mjs → chunk-ALH5IPSY.mjs} +2 -57
- package/dist/chunk-ALH5IPSY.mjs.map +1 -0
- package/dist/{chunk-RCM4NAAG.mjs → chunk-QHHLHSBW.mjs} +9 -122
- package/dist/chunk-QHHLHSBW.mjs.map +1 -0
- package/dist/{chunk-4QVFXT35.mjs → chunk-UDX6HLAU.mjs} +1 -17
- package/dist/{chunk-4QVFXT35.mjs.map → chunk-UDX6HLAU.mjs.map} +1 -1
- package/dist/index.d.ts +62 -12
- package/dist/index.mjs +265 -87
- package/dist/index.mjs.map +1 -1
- package/dist/{wsfe-DF0jAE2k.d.ts → wsfe-DDY9E1GJ.d.ts} +1 -25
- package/dist/wsfe.d.ts +1 -1
- package/dist/wsfe.mjs +2 -2
- package/dist/wsmtxca.d.ts +1 -17
- package/dist/wsmtxca.mjs +2 -2
- package/package.json +1 -1
- package/dist/chunk-RCM4NAAG.mjs.map +0 -1
- package/dist/chunk-XNBD5NVL.mjs.map +0 -1
package/README.md
CHANGED
|
@@ -59,39 +59,102 @@ also checked as part of the input identity. A key without a store throws before
|
|
|
59
59
|
provider I/O. Different keys identify different business operations; a key does
|
|
60
60
|
not reserve the entire point-of-sale sequence against other writers.
|
|
61
61
|
|
|
62
|
-
|
|
62
|
+
### Check before you send
|
|
63
63
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
64
|
+
`preview()` derives exactly what `issue()` would send, with no I/O at all: no
|
|
65
|
+
store, no WSAA, no SOAP and no next-number read. It throws the same input
|
|
66
|
+
errors `issue()` throws before its first call, so an input that previews
|
|
67
|
+
cleanly raises no new local error at issuance.
|
|
68
68
|
|
|
69
69
|
```ts
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
issuer: "monotributo",
|
|
70
|
+
const input = {
|
|
71
|
+
issuer: "monotributo" as const,
|
|
73
72
|
salesPoint: 3,
|
|
74
|
-
to: { condition: "consumidor_final" },
|
|
75
|
-
items: [{ amount:
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
73
|
+
to: { condition: "consumidor_final" as const },
|
|
74
|
+
items: [{ amount: 150_000 }],
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
const previsualizacion = arca.preview(input);
|
|
78
|
+
if (previsualizacion.amounts.sentTotal !== venta.totalEnCentavos) {
|
|
79
|
+
throw new Error("The derived invoice does not match the sale total.");
|
|
80
80
|
}
|
|
81
|
+
const factura = await arca.issue(input, { idempotencyKey: venta.id });
|
|
81
82
|
```
|
|
82
83
|
|
|
83
|
-
`
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
84
|
+
`preview()` is synchronous and returns the derived `voucherClass`,
|
|
85
|
+
`voucherType`, the same `amounts` an authorized outcome reports, and `request`,
|
|
86
|
+
the exact `WsfeVoucherInput` that `issue()` would send. The voucher number is
|
|
87
|
+
absent because it is only known when the number is reserved at issuance.
|
|
88
|
+
Previewing a credit note needs the original and is not offered.
|
|
89
|
+
|
|
90
|
+
## Credit notes
|
|
91
|
+
|
|
92
|
+
ARCA has no cancellation. A correction is a credit note, and both modes of
|
|
93
|
+
`issueCreditNote()` write a real fiscal document that stays in ARCA's records.
|
|
90
94
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
+
A credit note names the invoice it corrects. The SDK does not offer associated
|
|
96
|
+
periods; use `wsfe.issue()` if you need one.
|
|
97
|
+
|
|
98
|
+
The common case is partial: a refund or a price correction that credits chosen
|
|
99
|
+
lines rather than the whole invoice.
|
|
100
|
+
|
|
101
|
+
```ts
|
|
102
|
+
const nota = await arca.issueCreditNote(
|
|
103
|
+
{
|
|
104
|
+
for: { salesPoint: 3, voucherType: 11, number: 41 },
|
|
105
|
+
items: [{ amount: 50_000 }], // ARS 500,00 of an ARS 1.500,00 invoice.
|
|
106
|
+
},
|
|
107
|
+
{ idempotencyKey: `nc:${devolucion.id}` },
|
|
108
|
+
);
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
`all: true` credits the whole original instead, mirroring its amounts and VAT
|
|
112
|
+
rates line by line:
|
|
113
|
+
|
|
114
|
+
```ts
|
|
115
|
+
const notaTotal = await arca.issueCreditNote(
|
|
116
|
+
{ for: { salesPoint: 3, voucherType: 11, number: 41 }, all: true },
|
|
117
|
+
{ idempotencyKey: `nc-total:${venta.id}` },
|
|
118
|
+
);
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
The mode is explicit and required: an input with neither `items` nor
|
|
122
|
+
`all: true`, or with both, is rejected before any I/O, so a forgotten field
|
|
123
|
+
cannot credit the whole invoice.
|
|
124
|
+
|
|
125
|
+
From the original the SDK takes the class and therefore the note type
|
|
126
|
+
(1 → 3, 6 → 8, 11 → 13), the receiver document type, number and VAT condition,
|
|
127
|
+
the currency and exchange rate, the concept and, for concepts 2 and 3, the
|
|
128
|
+
service dates with the due date raised to the note date. The caller provides
|
|
129
|
+
`for`, the mode (`items`, with an optional `total`, or `all: true`) and, at
|
|
130
|
+
most, the note's own `salesPoint`, which defaults to the original's, and
|
|
131
|
+
`date`, which defaults to today in Buenos Aires. There is no `issuer`, `to` or
|
|
132
|
+
`currency` field: a note to a different receiver or in a different currency is
|
|
133
|
+
a different document and belongs to the exact layer.
|
|
134
|
+
|
|
135
|
+
Item shapes follow the original's class. A class C note accepts `{ amount }`
|
|
136
|
+
items; class A and B notes accept `{ gross | net, vat }` items with the same
|
|
137
|
+
rates and reconciliation as `issue()`. The class is evidence from the original,
|
|
138
|
+
so a shape that contradicts it is rejected after the single lookup of the
|
|
139
|
+
original and before any write.
|
|
140
|
+
|
|
141
|
+
The note may not exceed the original's total. The SDK does not track earlier
|
|
142
|
+
notes against an original; preventing several notes from adding up beyond the
|
|
143
|
+
invoice is the application's job.
|
|
144
|
+
|
|
145
|
+
Only authorized invoices of type 1, 6 or 11 in ARS or USD can be corrected.
|
|
146
|
+
Originals with tributes, optional fields, buyers, activities or an associated
|
|
147
|
+
period, debit-note targets, and FCE all require the exact API.
|
|
148
|
+
|
|
149
|
+
`idempotencyKey` and `include` work exactly as for `issue()`; give the note its
|
|
150
|
+
own stable key, such as `nc:${devolucion.id}`. A keyed replay consults only the
|
|
151
|
+
reserved note and reports `amounts` from the stored request, so on that path
|
|
152
|
+
`computedTotal` equals `sentTotal` and `vatAdjustment` is `0`.
|
|
153
|
+
|
|
154
|
+
A production smoke test is an ARS 1 invoice followed by a full note. **Both
|
|
155
|
+
documents are real and remain in ARCA's records.** The note is a separate
|
|
156
|
+
operation; a failure leaves the invoice outstanding. Match `issuer` to your
|
|
157
|
+
actual tax condition.
|
|
95
158
|
|
|
96
159
|
## Stores
|
|
97
160
|
|
|
@@ -222,7 +285,8 @@ A first keyed call reserves that number before writing. A keyed replay looks
|
|
|
222
285
|
up the reservation: only `not_found` allows one authorization of the stored
|
|
223
286
|
number. A found voucher is never resubmitted. Indeterminate writes and keyed
|
|
224
287
|
10016 rejections can add one lookup; a 10016 without a complete match remains
|
|
225
|
-
rejected.
|
|
288
|
+
rejected. `issueCreditNote()` adds the original's lookup only when creating a new
|
|
289
|
+
reservation.
|
|
226
290
|
|
|
227
291
|
| Outcome | Meaning and caller action |
|
|
228
292
|
| --- | --- |
|
|
@@ -338,7 +402,8 @@ WSMTXCA remains supported and exported, but this package currently puts most edi
|
|
|
338
402
|
|
|
339
403
|
`client.issue()` derives the WSFE request, reserves the number and recovers
|
|
340
404
|
after a crash for you. When you need something it does not derive (tributes,
|
|
341
|
-
|
|
405
|
+
FCE, an associated period, a note in another currency or to another receiver)
|
|
406
|
+
or your application owns the
|
|
342
407
|
numbering, use the exact layer: `client.wsfe.issue(...)` sends one
|
|
343
408
|
FECAESolicitar for a caller-owned, durably reserved voucher number and tells
|
|
344
409
|
you whether that exact attempt was authorized, rejected, or left
|
|
@@ -376,12 +441,6 @@ forced credential refresh after an explicit typed authentication rejection.
|
|
|
376
441
|
Passing `forceRefresh: true` disables any further authentication recovery
|
|
377
442
|
attempt.
|
|
378
443
|
|
|
379
|
-
The deprecated `authorizeVoucher(...)` methods throw instead of returning
|
|
380
|
-
evidence, and the deprecated WSFE `createNextVoucher(...)` reads the next
|
|
381
|
-
number and authorizes it in one non-idempotent call. Both remain for one
|
|
382
|
-
release; applications use `client.issue()` or reserve a number and call
|
|
383
|
-
`wsfe.issue()`.
|
|
384
|
-
|
|
385
444
|
Exact lookup absence is operation-specific:
|
|
386
445
|
|
|
387
446
|
- WSFE `FECompConsultar` code 602 returns `not_found`.
|
|
@@ -462,7 +521,9 @@ remain decimal major-unit values and its `currencyId` remains an ARCA ID.
|
|
|
462
521
|
## Examples
|
|
463
522
|
|
|
464
523
|
- [Keyed invoice](./examples/issue-invoice.ts)
|
|
465
|
-
- [
|
|
524
|
+
- [Preview before issuing](./examples/preview.ts)
|
|
525
|
+
- [Partial credit note](./examples/nota-de-credito-parcial.ts)
|
|
526
|
+
- [Full credit note](./examples/nota-de-credito-total.ts)
|
|
466
527
|
|
|
467
528
|
Examples live in [examples/](./examples) and are intentionally complete, hardcoded, and readable so they can be adapted quickly by a developer or a coding agent.
|
|
468
529
|
Issuance examples use deterministic dates for compilation; replace them with an
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
classifyArcaAuthenticationError,
|
|
3
3
|
classifyArcaAuthenticationIssues,
|
|
4
|
-
createArcaAuthenticationErrorFromEvidence,
|
|
5
4
|
createArcaAuthenticationEvidence,
|
|
6
5
|
executeWithAuthenticationRecovery
|
|
7
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-UDX6HLAU.mjs";
|
|
8
7
|
import {
|
|
9
8
|
ArcaInputError,
|
|
10
9
|
ArcaInvalidSoapResponseError,
|
|
@@ -71,34 +70,6 @@ function createWsmtxcaService(options) {
|
|
|
71
70
|
async function issue(input) {
|
|
72
71
|
return (await executeWsmtxcaAuthorization(input)).outcome;
|
|
73
72
|
}
|
|
74
|
-
function authorizeVoucher(input) {
|
|
75
|
-
return executeWithAuthenticationRecovery({
|
|
76
|
-
service: "wsmtxca",
|
|
77
|
-
operation: "autorizarComprobante",
|
|
78
|
-
forceRefresh: input.forceRefresh,
|
|
79
|
-
execute: (forceRefresh) => authorizeVoucherOnce({ ...input, forceRefresh })
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
async function authorizeVoucherOnce(input) {
|
|
83
|
-
const execution = await executeWsmtxcaAuthorization(input);
|
|
84
|
-
if (execution.error) {
|
|
85
|
-
throw execution.error;
|
|
86
|
-
}
|
|
87
|
-
if (execution.outcome.kind !== "authorized") {
|
|
88
|
-
throw createWsmtxcaOutcomeError(execution.outcome);
|
|
89
|
-
}
|
|
90
|
-
const { outcome } = execution;
|
|
91
|
-
return {
|
|
92
|
-
cae: outcome.cae,
|
|
93
|
-
...outcome.caeExpiry === void 0 ? {} : { caeExpiry: outcome.caeExpiry },
|
|
94
|
-
voucherNumber: outcome.voucherNumber,
|
|
95
|
-
messages: formatWsmtxcaIssues([
|
|
96
|
-
...outcome.errors,
|
|
97
|
-
...outcome.observations
|
|
98
|
-
]),
|
|
99
|
-
raw: outcome.raw ?? {}
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
73
|
function getLastAuthorizedVoucher({
|
|
103
74
|
representedTaxId,
|
|
104
75
|
voucherType,
|
|
@@ -292,8 +263,6 @@ function createWsmtxcaService(options) {
|
|
|
292
263
|
}
|
|
293
264
|
return {
|
|
294
265
|
issue,
|
|
295
|
-
authorizeVoucherOutcome: issue,
|
|
296
|
-
authorizeVoucher,
|
|
297
266
|
getLastAuthorizedVoucher,
|
|
298
267
|
getSalesPoints,
|
|
299
268
|
lookupVoucher,
|
|
@@ -502,30 +471,6 @@ function normalizeWsmtxcaIssueEntries(value) {
|
|
|
502
471
|
};
|
|
503
472
|
});
|
|
504
473
|
}
|
|
505
|
-
function createWsmtxcaOutcomeError(outcome) {
|
|
506
|
-
if (outcome.kind === "indeterminate" && outcome.authentication) {
|
|
507
|
-
return createArcaAuthenticationErrorFromEvidence(outcome.authentication, {
|
|
508
|
-
service: "wsmtxca",
|
|
509
|
-
operation: outcome.operation
|
|
510
|
-
});
|
|
511
|
-
}
|
|
512
|
-
const issues = [...outcome.errors, ...outcome.observations];
|
|
513
|
-
const messages = formatWsmtxcaIssues(issues);
|
|
514
|
-
const firstIssue = issues[0];
|
|
515
|
-
return new ArcaServiceError(
|
|
516
|
-
messages.join(" | ") || (outcome.kind === "rejected" ? "WSMTXCA rejected the voucher authorization" : "WSMTXCA did not return conclusive voucher authorization data"),
|
|
517
|
-
{
|
|
518
|
-
service: "wsmtxca",
|
|
519
|
-
operation: outcome.operation,
|
|
520
|
-
...firstIssue?.code === void 0 ? {} : { serviceCode: firstIssue.code },
|
|
521
|
-
...outcome.result === void 0 ? {} : { result: outcome.result },
|
|
522
|
-
...outcome.resultLevel === void 0 ? {} : { resultLevel: outcome.resultLevel },
|
|
523
|
-
results: outcome.results,
|
|
524
|
-
...outcome.kind === "indeterminate" && outcome.cae ? { cae: outcome.cae } : {},
|
|
525
|
-
issues
|
|
526
|
-
}
|
|
527
|
-
);
|
|
528
|
-
}
|
|
529
474
|
function formatWsmtxcaIssues(issues) {
|
|
530
475
|
return issues.map((issue) => {
|
|
531
476
|
const prefix = issue.source === "error" ? "Error" : "Obs";
|
|
@@ -701,4 +646,4 @@ function formatCompactDateToIso(dateValue) {
|
|
|
701
646
|
export {
|
|
702
647
|
createWsmtxcaService
|
|
703
648
|
};
|
|
704
|
-
//# sourceMappingURL=chunk-
|
|
649
|
+
//# sourceMappingURL=chunk-ALH5IPSY.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/services/wsmtxca.ts"],"sourcesContent":["import {\n ArcaInputError,\n ArcaInvalidSoapResponseError,\n ArcaServiceError,\n ArcaSoapFaultError,\n ArcaTransportError,\n} from \"../errors\";\nimport {\n classifyArcaAuthenticationError,\n classifyArcaAuthenticationIssues,\n createArcaAuthenticationEvidence,\n executeWithAuthenticationRecovery,\n} from \"../internal/authentication\";\nimport type { ArcaClientConfig, ArcaRepresentedTaxId } from \"../internal/types\";\nimport type { SoapTransport } from \"../soap\";\nimport type { WsaaAuthModule } from \"../wsaa\";\nimport type {\n ArcaAuthorizationIndeterminateReason,\n ArcaAuthorizationOutcome,\n ArcaFiscalIssue,\n ArcaVoucherLookupResult,\n} from \"./fiscal-evidence\";\n\n/** Input data for one WSMTXCA voucher authorization. */\nexport type WsmtxcaAuthorizeVoucherInput = {\n representedTaxId?: ArcaRepresentedTaxId;\n data: Record<string, unknown>;\n forceRefresh?: boolean;\n};\n\n/** Structured evidence from one exact WSMTXCA authorization attempt. */\nexport type WsmtxcaAuthorizationOutcome = ArcaAuthorizationOutcome<\"wsmtxca\">;\n\n/** Result of querying the last authorized voucher number. */\nexport type WsmtxcaLastAuthorizedVoucherResult = {\n voucherNumber: number;\n raw: Record<string, unknown>;\n};\n\n/** A point of sale enabled for WSMTXCA. */\nexport type WsmtxcaSalesPoint = {\n number: number;\n blocked: boolean;\n deletedAt?: string;\n};\n\n/** Result of querying WSMTXCA points of sale. */\nexport type WsmtxcaSalesPointsResult = {\n salesPoints: WsmtxcaSalesPoint[];\n raw: Record<string, unknown>;\n};\n\n/** Typed provider fields used to match one exact WSMTXCA voucher. */\nexport type WsmtxcaVoucherInfo = {\n voucherNumber?: number;\n invoiceDate?: string;\n salesPoint?: number;\n voucherType?: number;\n concept?: number;\n documentType?: number;\n documentNumber?: string;\n receiverVatConditionId?: number;\n totalAmount?: number;\n subtotalAmount?: number;\n taxableAmount?: number;\n nonTaxableAmount?: number;\n exemptAmount?: number;\n taxAmount?: number;\n vatAmount?: number;\n currencyId?: string;\n exchangeRate?: number;\n cae?: string;\n caeExpiry?: string;\n raw: Record<string, unknown>;\n};\n\n/** Typed exact-voucher consultation result for WSMTXCA. */\nexport type WsmtxcaVoucherLookupOutcome = ArcaVoucherLookupResult<\n WsmtxcaVoucherInfo,\n \"wsmtxca\"\n>;\n\n/** Result of looking up a specific WSMTXCA voucher. */\nexport type WsmtxcaVoucherLookupResult = {\n invoiceDate: string;\n voucher: Record<string, unknown>;\n messages: string[];\n raw: Record<string, unknown>;\n};\n\n/** WSMTXCA electronic invoicing service (Factura de Crédito Electrónica). */\nexport type WsmtxcaService = {\n /**\n * Issues one exact voucher: a single autorizarComprobante without transport\n * retries, returning structured evidence instead of throwing.\n */\n issue(\n input: WsmtxcaAuthorizeVoucherInput\n ): Promise<WsmtxcaAuthorizationOutcome>;\n /** Returns the last authorized voucher number for the given sales point and type. */\n getLastAuthorizedVoucher(input: {\n representedTaxId?: ArcaRepresentedTaxId;\n voucherType: number;\n salesPoint: number;\n forceRefresh?: boolean;\n }): Promise<WsmtxcaLastAuthorizedVoucherResult>;\n /** Returns the points of sale enabled for WSMTXCA. */\n getSalesPoints(input: {\n representedTaxId?: ArcaRepresentedTaxId;\n forceRefresh?: boolean;\n }): Promise<WsmtxcaSalesPointsResult>;\n /** Consults one exact voucher and normalizes WSMTXCA error 1503 to `not_found`. */\n lookupVoucher(input: {\n representedTaxId?: ArcaRepresentedTaxId;\n voucherType: number;\n salesPoint: number;\n voucherNumber: number;\n forceRefresh?: boolean;\n }): Promise<WsmtxcaVoucherLookupOutcome>;\n /** Retrieves details for a specific voucher. */\n getVoucher(input: {\n representedTaxId?: ArcaRepresentedTaxId;\n voucherType: number;\n salesPoint: number;\n voucherNumber: number;\n forceRefresh?: boolean;\n }): Promise<WsmtxcaVoucherLookupResult>;\n};\n\nexport type CreateWsmtxcaServiceOptions = {\n config: ArcaClientConfig;\n auth: WsaaAuthModule;\n soap: SoapTransport;\n};\n\n/** Creates a WSMTXCA service instance wired with authentication and SOAP transport. */\nexport function createWsmtxcaService(\n options: CreateWsmtxcaServiceOptions\n): WsmtxcaService {\n async function executeWsmtxcaAuthenticatedOperation(\n operation: WsmtxcaOperation,\n input: {\n representedTaxId?: ArcaRepresentedTaxId;\n forceRefresh?: boolean;\n },\n body: Record<string, unknown> = {},\n retries?: number\n ) {\n const auth = await options.auth.login(\"wsmtxca\", {\n representedTaxId: input.representedTaxId,\n forceRefresh: input.forceRefresh,\n });\n const response = await options.soap.execute<\n Record<string, unknown>,\n Record<string, unknown>\n >({\n service: \"wsmtxca\",\n operation,\n ...(retries === undefined ? {} : { retries }),\n bodyElementName: `${operation}Request`,\n bodyElementNamespaceMode: \"prefix\",\n body: {\n // WSMTXCA request types use an XML sequence with authentication first.\n authRequest: createWsmtxcaAuth(\n input.representedTaxId ?? options.config.taxId,\n auth.token,\n auth.sign\n ),\n ...body,\n },\n });\n\n return unwrapWsmtxcaOperationResponse(response.result, operation);\n }\n\n async function executeWsmtxcaAuthorization({\n representedTaxId,\n data,\n forceRefresh,\n }: WsmtxcaAuthorizeVoucherInput): Promise<{\n outcome: WsmtxcaAuthorizationOutcome;\n error?: unknown;\n }> {\n if (Object.hasOwn(data, \"authRequest\")) {\n throw new ArcaInputError(\n 'WSMTXCA authorization data cannot include the reserved top-level field \"authRequest\".',\n {\n code: \"ARCA_INPUT_RESERVED_FIELD\",\n field: \"data.authRequest\",\n expected: \"omitted because facturas manages authentication fields\",\n }\n );\n }\n\n try {\n const raw = await executeWsmtxcaAuthenticatedOperation(\n \"autorizarComprobante\",\n { representedTaxId, forceRefresh },\n data,\n 0\n );\n return { outcome: classifyWsmtxcaAuthorization(raw) };\n } catch (error) {\n return {\n outcome: createWsmtxcaIndeterminateOutcome(error),\n error,\n };\n }\n }\n\n async function issue(\n input: WsmtxcaAuthorizeVoucherInput\n ): Promise<WsmtxcaAuthorizationOutcome> {\n return (await executeWsmtxcaAuthorization(input)).outcome;\n }\n\n function getLastAuthorizedVoucher({\n representedTaxId,\n voucherType,\n salesPoint,\n forceRefresh,\n }: {\n representedTaxId?: ArcaRepresentedTaxId;\n voucherType: number;\n salesPoint: number;\n forceRefresh?: boolean;\n }): Promise<WsmtxcaLastAuthorizedVoucherResult> {\n return executeWithAuthenticationRecovery({\n service: \"wsmtxca\",\n operation: \"consultarUltimoComprobanteAutorizado\",\n forceRefresh,\n execute: (attemptForceRefresh) =>\n getLastAuthorizedVoucherOnce({\n representedTaxId,\n voucherType,\n salesPoint,\n forceRefresh: attemptForceRefresh,\n }),\n });\n }\n\n async function getLastAuthorizedVoucherOnce({\n representedTaxId,\n voucherType,\n salesPoint,\n forceRefresh,\n }: {\n representedTaxId?: ArcaRepresentedTaxId;\n voucherType: number;\n salesPoint: number;\n forceRefresh?: boolean;\n }): Promise<WsmtxcaLastAuthorizedVoucherResult> {\n const operation = \"consultarUltimoComprobanteAutorizado\";\n const raw = await executeWsmtxcaAuthenticatedOperation(\n operation,\n { representedTaxId, forceRefresh },\n {\n consultaUltimoComprobanteAutorizadoRequest: {\n codigoTipoComprobante: voucherType,\n numeroPuntoVenta: salesPoint,\n },\n }\n );\n const errors = extractWsmtxcaIssues(raw, operation, \"error\");\n\n if (errors.length > 0 && errors.every((issue) => issue.code === \"1502\")) {\n return { voucherNumber: 0, raw };\n }\n if (errors.length > 0) {\n throw createWsmtxcaServiceError(operation, errors);\n }\n\n return {\n voucherNumber: parseWsmtxcaVoucherNumber(\n raw.numeroComprobante ?? raw.cbteNro ?? raw.nroComprobante,\n \"WSMTXCA did not return the last authorized voucher number\",\n true\n ),\n raw,\n };\n }\n\n function getSalesPoints({\n representedTaxId,\n forceRefresh,\n }: {\n representedTaxId?: ArcaRepresentedTaxId;\n forceRefresh?: boolean;\n }): Promise<WsmtxcaSalesPointsResult> {\n return executeWithAuthenticationRecovery({\n service: \"wsmtxca\",\n operation: \"consultarPuntosVenta\",\n forceRefresh,\n execute: (attemptForceRefresh) =>\n getSalesPointsOnce({\n representedTaxId,\n forceRefresh: attemptForceRefresh,\n }),\n });\n }\n\n async function getSalesPointsOnce({\n representedTaxId,\n forceRefresh,\n }: {\n representedTaxId?: ArcaRepresentedTaxId;\n forceRefresh?: boolean;\n }): Promise<WsmtxcaSalesPointsResult> {\n const operation = \"consultarPuntosVenta\";\n const raw = await executeWsmtxcaAuthenticatedOperation(operation, {\n representedTaxId,\n forceRefresh,\n });\n throwForWsmtxcaOperationErrors(operation, raw);\n const rawSalesPoints = toRecord(raw.arrayPuntosVenta)?.puntoVenta;\n const entries = Array.isArray(rawSalesPoints)\n ? rawSalesPoints\n : rawSalesPoints\n ? [rawSalesPoints]\n : [];\n const salesPoints = entries.flatMap((entry) => {\n const record = toRecord(entry);\n const number = parseOptionalPositiveInteger(record?.numeroPuntoVenta);\n if (number === undefined) {\n return [];\n }\n const deletedAt = normalizeWsmtxcaResponseDate(record?.fechaBaja);\n return [\n {\n number,\n blocked: String(record?.bloqueado ?? \"N\").toUpperCase() === \"S\",\n ...(deletedAt === undefined ? {} : { deletedAt }),\n },\n ];\n });\n\n return { salesPoints, raw };\n }\n\n function lookupVoucher({\n representedTaxId,\n voucherType,\n salesPoint,\n voucherNumber,\n forceRefresh,\n }: {\n representedTaxId?: ArcaRepresentedTaxId;\n voucherType: number;\n salesPoint: number;\n voucherNumber: number;\n forceRefresh?: boolean;\n }): Promise<WsmtxcaVoucherLookupOutcome> {\n return executeWithAuthenticationRecovery({\n service: \"wsmtxca\",\n operation: \"consultarComprobante\",\n forceRefresh,\n execute: (attemptForceRefresh) =>\n lookupVoucherOnce({\n representedTaxId,\n voucherType,\n salesPoint,\n voucherNumber,\n forceRefresh: attemptForceRefresh,\n }),\n });\n }\n\n async function lookupVoucherOnce({\n representedTaxId,\n voucherType,\n salesPoint,\n voucherNumber,\n forceRefresh,\n }: {\n representedTaxId?: ArcaRepresentedTaxId;\n voucherType: number;\n salesPoint: number;\n voucherNumber: number;\n forceRefresh?: boolean;\n }): Promise<WsmtxcaVoucherLookupOutcome> {\n const operation = \"consultarComprobante\";\n const raw = await executeWsmtxcaAuthenticatedOperation(\n operation,\n { representedTaxId, forceRefresh },\n {\n consultaComprobanteRequest: {\n codigoTipoComprobante: voucherType,\n numeroPuntoVenta: salesPoint,\n numeroComprobante: voucherNumber,\n },\n }\n );\n const errors = extractWsmtxcaIssues(raw, operation, \"error\");\n const observations = extractWsmtxcaIssues(raw, operation, \"observation\");\n\n if (errors.length > 0 && errors.every((issue) => issue.code === \"1503\")) {\n return {\n kind: \"not_found\",\n service: \"wsmtxca\",\n operation,\n errors,\n observations,\n raw,\n };\n }\n if (errors.length > 0) {\n throw createWsmtxcaServiceError(operation, errors);\n }\n\n const voucher = extractWsmtxcaVoucherPayload(raw);\n if (voucher === raw && !toRecord(raw.comprobante)) {\n throw new ArcaServiceError(\n \"WSMTXCA did not return the voucher issue date\",\n {\n service: \"wsmtxca\",\n operation,\n issues: observations,\n }\n );\n }\n\n return {\n kind: \"found\",\n service: \"wsmtxca\",\n operation,\n voucher: mapWsmtxcaVoucherInfo(voucher),\n observations,\n raw,\n };\n }\n\n async function getVoucher(input: {\n representedTaxId?: ArcaRepresentedTaxId;\n voucherType: number;\n salesPoint: number;\n voucherNumber: number;\n forceRefresh?: boolean;\n }): Promise<WsmtxcaVoucherLookupResult> {\n const lookup = await lookupVoucher(input);\n if (lookup.kind === \"not_found\") {\n throw createWsmtxcaServiceError(lookup.operation, lookup.errors);\n }\n\n const invoiceDate = lookup.voucher.invoiceDate;\n if (!invoiceDate) {\n throw new ArcaServiceError(\n formatWsmtxcaIssues(lookup.observations)[0] ??\n \"WSMTXCA did not return the voucher issue date\",\n {\n service: \"wsmtxca\",\n operation: lookup.operation,\n issues: lookup.observations,\n }\n );\n }\n\n return {\n invoiceDate,\n voucher: lookup.voucher.raw,\n messages: formatWsmtxcaIssues(lookup.observations),\n raw: lookup.raw,\n };\n }\n\n return {\n issue,\n getLastAuthorizedVoucher,\n getSalesPoints,\n lookupVoucher,\n getVoucher,\n };\n}\n\nfunction createWsmtxcaAuth(\n representedTaxId: number | string,\n token: string,\n sign: string\n) {\n return {\n token,\n sign,\n cuitRepresentada: Number.parseInt(String(representedTaxId), 10),\n };\n}\n\nfunction toRecord(value: unknown): Record<string, unknown> | undefined {\n return value && typeof value === \"object\" && !Array.isArray(value)\n ? (value as Record<string, unknown>)\n : undefined;\n}\n\ntype WsmtxcaOperation =\n | \"autorizarComprobante\"\n | \"consultarUltimoComprobanteAutorizado\"\n | \"consultarPuntosVenta\"\n | \"consultarComprobante\";\n\nfunction unwrapWsmtxcaOperationResponse(\n response: unknown,\n operation: WsmtxcaOperation\n) {\n const responseRecord = toRecord(response) ?? {};\n\n if (operation === \"autorizarComprobante\") {\n return (\n toRecord(responseRecord.autorizarComprobanteResponse) ??\n toRecord(responseRecord.autorizarComprobanteResult) ??\n toRecord(responseRecord.comprobanteCAEResponse) ??\n toRecord(responseRecord.comprobanteCAEReponse) ??\n responseRecord\n );\n }\n\n if (operation === \"consultarComprobante\") {\n return (\n toRecord(responseRecord.consultarComprobanteResponse) ??\n toRecord(responseRecord.consultaComprobanteResponse) ??\n toRecord(responseRecord.consultarComprobanteResult) ??\n responseRecord\n );\n }\n\n if (operation === \"consultarPuntosVenta\") {\n return (\n toRecord(responseRecord.consultarPuntosVentaResponse) ??\n toRecord(responseRecord.consultarPuntosVentaResult) ??\n responseRecord\n );\n }\n\n return (\n toRecord(responseRecord.consultarUltimoComprobanteAutorizadoResponse) ??\n toRecord(responseRecord.consultaUltimoComprobanteAutorizadoResponse) ??\n toRecord(responseRecord.consultarUltimoComprobanteAutorizadoResult) ??\n responseRecord\n );\n}\n\nfunction extractWsmtxcaAuthorizationPayload(raw: Record<string, unknown>) {\n return (\n toRecord(raw.comprobanteResponse) ??\n toRecord(raw.comprobanteCAEResponse) ??\n toRecord(raw.comprobanteCAEReponse) ??\n raw\n );\n}\n\nfunction extractWsmtxcaVoucherPayload(raw: Record<string, unknown>) {\n return (\n toRecord(raw.comprobanteResponse) ??\n toRecord(raw.comprobante) ??\n toRecord(raw.cmp) ??\n raw\n );\n}\n\nfunction classifyWsmtxcaAuthorization(\n raw: Record<string, unknown>\n): WsmtxcaAuthorizationOutcome {\n const operation = \"autorizarComprobante\";\n const payload = extractWsmtxcaAuthorizationPayload(raw);\n const result = normalizeWsmtxcaResult(raw.resultado ?? payload.resultado);\n const cae = normalizeWsmtxcaString(\n payload.CAE ?? payload.codigoAutorizacion ?? raw.codigoAutorizacion\n );\n const caeExpiry = normalizeWsmtxcaResponseDate(\n payload.fechaVencimientoCAE ??\n payload.fechaVencimiento ??\n raw.fechaVencimiento\n );\n const voucherNumber = parseOptionalPositiveInteger(\n payload.numeroComprobante ?? raw.numeroComprobante\n );\n const errors = extractWsmtxcaIssues(raw, operation, \"error\");\n const observations = extractWsmtxcaIssues(raw, operation, \"observation\");\n const base = {\n service: \"wsmtxca\" as const,\n operation,\n results: createWsmtxcaResults(result),\n errors,\n observations,\n raw,\n };\n\n const authenticationOutcome = createWsmtxcaAuthenticationOutcome({\n base,\n result,\n cae,\n voucherNumber,\n });\n if (authenticationOutcome) {\n return authenticationOutcome;\n }\n\n if (\n (result === \"A\" || result === \"O\") &&\n cae &&\n voucherNumber !== undefined &&\n errors.length === 0\n ) {\n return {\n ...base,\n kind: \"authorized\",\n result,\n resultLevel: \"operation\",\n cae,\n ...(caeExpiry === undefined ? {} : { caeExpiry }),\n voucherNumber,\n };\n }\n\n if (result === \"R\" && !cae && errors.length > 0) {\n return {\n ...base,\n kind: \"rejected\",\n result: \"R\",\n resultLevel: \"operation\",\n };\n }\n\n const outcome: WsmtxcaAuthorizationOutcome = {\n ...base,\n kind: \"indeterminate\",\n reason:\n (result === \"R\" && Boolean(cae)) ||\n ((result === \"A\" || result === \"O\") && Boolean(errors.length))\n ? \"contradictory_response\"\n : \"incomplete_response\",\n ...(result === undefined ? {} : { result }),\n ...(result === undefined ? {} : { resultLevel: \"operation\" }),\n };\n assignWsmtxcaValue(outcome, \"cae\", cae);\n assignWsmtxcaValue(outcome, \"caeExpiry\", caeExpiry);\n assignWsmtxcaValue(outcome, \"voucherNumber\", voucherNumber);\n return outcome;\n}\n\nfunction createWsmtxcaAuthenticationOutcome({\n base,\n result,\n cae,\n voucherNumber,\n}: {\n base: {\n service: \"wsmtxca\";\n operation: string;\n results: ReturnType<typeof createWsmtxcaResults>;\n errors: ArcaFiscalIssue[];\n observations: ArcaFiscalIssue[];\n raw: Record<string, unknown>;\n };\n result?: string;\n cae?: string;\n voucherNumber?: number;\n}): WsmtxcaAuthorizationOutcome | undefined {\n const authenticationError = classifyArcaAuthenticationIssues(base.errors, {\n service: base.service,\n operation: base.operation,\n });\n if (\n !authenticationError ||\n result === \"A\" ||\n result === \"O\" ||\n cae ||\n voucherNumber !== undefined\n ) {\n return undefined;\n }\n\n return {\n ...base,\n kind: \"indeterminate\",\n reason: \"authentication_rejected\",\n authentication: createArcaAuthenticationEvidence(authenticationError),\n ...(result === undefined ? {} : { result }),\n ...(result === undefined ? {} : { resultLevel: \"operation\" }),\n };\n}\n\nfunction createWsmtxcaIndeterminateOutcome(\n error: unknown\n): WsmtxcaAuthorizationOutcome {\n const authenticationError = classifyArcaAuthenticationError(error, {\n service: \"wsmtxca\",\n operation: \"autorizarComprobante\",\n });\n return {\n kind: \"indeterminate\",\n service: \"wsmtxca\",\n operation: \"autorizarComprobante\",\n results: {},\n reason: authenticationError\n ? \"authentication_rejected\"\n : getWsmtxcaIndeterminateReason(error),\n ...(authenticationError\n ? {\n authentication: createArcaAuthenticationEvidence(authenticationError),\n }\n : {}),\n errors: [],\n observations: [],\n };\n}\n\nfunction getWsmtxcaIndeterminateReason(\n error: unknown\n): ArcaAuthorizationIndeterminateReason {\n if (error instanceof ArcaTransportError) {\n return \"transport_error\";\n }\n if (error instanceof ArcaSoapFaultError) {\n return \"soap_fault\";\n }\n if (error instanceof ArcaInvalidSoapResponseError) {\n return \"invalid_response\";\n }\n return \"unexpected_error\";\n}\n\nfunction createWsmtxcaResults(operationResult?: string) {\n const results: { operation?: string } = {};\n assignWsmtxcaValue(results, \"operation\", operationResult);\n return results;\n}\n\nfunction createWsmtxcaServiceError(\n operation: string,\n issues: ArcaFiscalIssue[]\n) {\n const authenticationError = classifyArcaAuthenticationIssues(issues, {\n service: \"wsmtxca\",\n operation,\n });\n if (authenticationError) {\n return authenticationError;\n }\n\n const firstIssue = issues[0];\n return new ArcaServiceError(\n formatWsmtxcaIssues(issues).join(\" | \") ||\n \"WSMTXCA returned a service error\",\n {\n service: \"wsmtxca\",\n operation,\n ...(firstIssue?.code === undefined\n ? {}\n : { serviceCode: firstIssue.code }),\n issues,\n }\n );\n}\n\nfunction throwForWsmtxcaOperationErrors(\n operation: string,\n raw: Record<string, unknown>\n): void {\n const errors = extractWsmtxcaIssues(raw, operation, \"error\");\n if (errors.length > 0) {\n throw createWsmtxcaServiceError(operation, errors);\n }\n}\n\nfunction extractWsmtxcaIssues(\n raw: Record<string, unknown>,\n operation: string,\n source: \"error\" | \"observation\"\n): ArcaFiscalIssue[] {\n const container = toRecord(\n source === \"error\" ? raw.arrayErrores : raw.arrayObservaciones\n );\n return normalizeWsmtxcaIssueEntries(container?.codigoDescripcion).map(\n (entry) => ({\n service: \"wsmtxca\",\n operation,\n source,\n category:\n source === \"observation\"\n ? \"observation\"\n : operation === \"autorizarComprobante\"\n ? \"business\"\n : \"unknown\",\n ...(entry.code === undefined ? {} : { code: entry.code }),\n message: entry.message,\n ...(operation === \"autorizarComprobante\"\n ? { resultLevel: \"operation\" as const }\n : {}),\n })\n );\n}\n\nfunction normalizeWsmtxcaIssueEntries(value: unknown) {\n const entries = Array.isArray(value) ? value : value ? [value] : [];\n return entries.map((entry) => {\n const record = toRecord(entry) ?? {};\n const code = record.codigo;\n const description = record.descripcion;\n return {\n ...(code === undefined || code === null ? {} : { code: String(code) }),\n message:\n description === undefined || description === null\n ? \"Unknown WSMTXCA issue\"\n : String(description),\n };\n });\n}\n\nfunction formatWsmtxcaIssues(issues: ArcaFiscalIssue[]): string[] {\n return issues.map((issue) => {\n const prefix = issue.source === \"error\" ? \"Error\" : \"Obs\";\n return `${prefix}${issue.code ? ` ${issue.code}` : \"\"}: ${issue.message}`;\n });\n}\n\nfunction mapWsmtxcaVoucherInfo(\n raw: Record<string, unknown>\n): WsmtxcaVoucherInfo {\n const voucher: WsmtxcaVoucherInfo = { raw };\n const invoiceDate = normalizeWsmtxcaResponseDate(\n raw.fechaEmision ?? raw.fecha ?? raw.CbteFch\n );\n const cae = normalizeWsmtxcaString(raw.codigoAutorizacion ?? raw.CAE);\n const caeExpiry = normalizeWsmtxcaResponseDate(\n raw.fechaVencimiento ?? raw.fechaVencimientoCAE\n );\n const vatAmount = sumWsmtxcaVatAmounts(raw.arraySubtotalesIVA);\n\n assignWsmtxcaValue(\n voucher,\n \"voucherNumber\",\n parseOptionalPositiveInteger(raw.numeroComprobante)\n );\n assignWsmtxcaValue(voucher, \"invoiceDate\", invoiceDate);\n assignWsmtxcaValue(\n voucher,\n \"salesPoint\",\n parseOptionalPositiveInteger(raw.numeroPuntoVenta)\n );\n assignWsmtxcaValue(\n voucher,\n \"voucherType\",\n parseOptionalPositiveInteger(raw.codigoTipoComprobante)\n );\n assignWsmtxcaValue(\n voucher,\n \"concept\",\n parseOptionalNumber(raw.codigoConcepto)\n );\n assignWsmtxcaValue(\n voucher,\n \"documentType\",\n parseOptionalNumber(raw.codigoTipoDocumento)\n );\n assignWsmtxcaValue(\n voucher,\n \"documentNumber\",\n normalizeWsmtxcaString(raw.numeroDocumento)\n );\n assignWsmtxcaValue(\n voucher,\n \"receiverVatConditionId\",\n parseOptionalNumber(raw.condicionIVAReceptor)\n );\n assignWsmtxcaValue(\n voucher,\n \"totalAmount\",\n parseOptionalNumber(raw.importeTotal)\n );\n assignWsmtxcaValue(\n voucher,\n \"subtotalAmount\",\n parseOptionalNumber(raw.importeSubtotal)\n );\n assignWsmtxcaValue(\n voucher,\n \"taxableAmount\",\n parseOptionalNumber(raw.importeGravado)\n );\n assignWsmtxcaValue(\n voucher,\n \"nonTaxableAmount\",\n parseOptionalNumber(raw.importeNoGravado)\n );\n assignWsmtxcaValue(\n voucher,\n \"exemptAmount\",\n parseOptionalNumber(raw.importeExento)\n );\n assignWsmtxcaValue(\n voucher,\n \"taxAmount\",\n parseOptionalNumber(raw.importeOtrosTributos)\n );\n assignWsmtxcaValue(voucher, \"vatAmount\", vatAmount);\n assignWsmtxcaValue(\n voucher,\n \"currencyId\",\n normalizeWsmtxcaString(raw.codigoMoneda)\n );\n assignWsmtxcaValue(\n voucher,\n \"exchangeRate\",\n parseOptionalNumber(raw.cotizacionMoneda)\n );\n assignWsmtxcaValue(voucher, \"cae\", cae);\n assignWsmtxcaValue(voucher, \"caeExpiry\", caeExpiry);\n\n return voucher;\n}\n\nfunction sumWsmtxcaVatAmounts(value: unknown): number | undefined {\n const subtotals = toRecord(value)?.subtotalIVA;\n const entries = Array.isArray(subtotals)\n ? subtotals\n : subtotals\n ? [subtotals]\n : [];\n const amounts = entries\n .map((entry) => parseOptionalNumber(toRecord(entry)?.importe))\n .filter((amount): amount is number => amount !== undefined);\n return amounts.length > 0\n ? amounts.reduce((total, amount) => total + amount, 0)\n : undefined;\n}\n\nfunction parseWsmtxcaVoucherNumber(\n value: unknown,\n message: string,\n allowZero = false\n) {\n const parsed = Number.parseInt(String(value ?? \"\"), 10);\n if (!Number.isFinite(parsed) || (allowZero ? parsed < 0 : parsed <= 0)) {\n throw new ArcaServiceError(message, {\n service: \"wsmtxca\",\n });\n }\n return parsed;\n}\n\nfunction parseOptionalPositiveInteger(value: unknown): number | undefined {\n const parsed = Number.parseInt(String(value ?? \"\"), 10);\n return Number.isFinite(parsed) && parsed > 0 ? parsed : undefined;\n}\n\nfunction parseOptionalNumber(value: unknown): number | undefined {\n if (value === undefined || value === null || value === \"\") {\n return undefined;\n }\n const parsed = Number(value);\n return Number.isFinite(parsed) ? parsed : undefined;\n}\n\nfunction normalizeWsmtxcaResult(value: unknown): string | undefined {\n if (typeof value !== \"string\") {\n return undefined;\n }\n const normalized = value.trim().toUpperCase();\n return normalized || undefined;\n}\n\nfunction normalizeWsmtxcaString(value: unknown): string | undefined {\n if (value === undefined || value === null) {\n return undefined;\n }\n const normalized = String(value).trim();\n return normalized || undefined;\n}\n\nfunction assignWsmtxcaValue<TTarget, TKey extends keyof TTarget>(\n target: TTarget,\n key: TKey,\n value: TTarget[TKey] | undefined\n) {\n if (value !== undefined) {\n target[key] = value;\n }\n}\n\nfunction normalizeWsmtxcaResponseDate(value: unknown): string | undefined {\n if (typeof value === \"number\" && Number.isInteger(value)) {\n return formatCompactDateToIso(value);\n }\n\n if (typeof value !== \"string\") {\n return undefined;\n }\n\n const trimmed = value.trim();\n if (!trimmed) {\n return undefined;\n }\n\n if (/^\\d{8}$/.test(trimmed)) {\n return formatCompactDateToIso(Number.parseInt(trimmed, 10));\n }\n\n if (/^\\d{4}-\\d{2}-\\d{2}/.test(trimmed)) {\n return trimmed.slice(0, 10);\n }\n\n return undefined;\n}\n\nfunction formatCompactDateToIso(dateValue?: number | null): string | undefined {\n if (!dateValue) {\n return undefined;\n }\n\n const raw = String(dateValue);\n if (raw.length !== 8) {\n return undefined;\n }\n\n return `${raw.slice(0, 4)}-${raw.slice(4, 6)}-${raw.slice(6, 8)}`;\n}\n"],"mappings":";;;;;;;;;;;;;;;AAwIO,SAAS,qBACd,SACgB;AAChB,iBAAe,qCACb,WACA,OAIA,OAAgC,CAAC,GACjC,SACA;AACA,UAAM,OAAO,MAAM,QAAQ,KAAK,MAAM,WAAW;AAAA,MAC/C,kBAAkB,MAAM;AAAA,MACxB,cAAc,MAAM;AAAA,IACtB,CAAC;AACD,UAAM,WAAW,MAAM,QAAQ,KAAK,QAGlC;AAAA,MACA,SAAS;AAAA,MACT;AAAA,MACA,GAAI,YAAY,SAAY,CAAC,IAAI,EAAE,QAAQ;AAAA,MAC3C,iBAAiB,GAAG,SAAS;AAAA,MAC7B,0BAA0B;AAAA,MAC1B,MAAM;AAAA;AAAA,QAEJ,aAAa;AAAA,UACX,MAAM,oBAAoB,QAAQ,OAAO;AAAA,UACzC,KAAK;AAAA,UACL,KAAK;AAAA,QACP;AAAA,QACA,GAA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Error,
|
|
8
8
|
classifyArcaAuthenticationIssues,
|
|
9
|
-
createArcaAuthenticationErrorFromEvidence,
|
|
10
9
|
createArcaAuthenticationEvidence,
|
|
11
10
|
executeWithAuthenticationRecovery
|
|
12
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-UDX6HLAU.mjs";
|
|
13
12
|
import {
|
|
14
13
|
ArcaInputError,
|
|
15
14
|
ArcaInvalidSoapResponseError,
|
|
@@ -297,20 +296,6 @@ function createWsfeService(options) {
|
|
|
297
296
|
});
|
|
298
297
|
return getWsfeResultEntries(result, resultKey).map(mapWsfeCatalogEntry);
|
|
299
298
|
}
|
|
300
|
-
function authorizeVoucher({
|
|
301
|
-
representedTaxId,
|
|
302
|
-
data,
|
|
303
|
-
voucherNumber,
|
|
304
|
-
forceRefresh
|
|
305
|
-
}) {
|
|
306
|
-
const normalizedInput = normalizeWsfeVoucherInput(data);
|
|
307
|
-
return authorizeNormalizedVoucher({
|
|
308
|
-
representedTaxId,
|
|
309
|
-
data: normalizedInput,
|
|
310
|
-
voucherNumber,
|
|
311
|
-
forceRefresh
|
|
312
|
-
});
|
|
313
|
-
}
|
|
314
299
|
function issue({
|
|
315
300
|
representedTaxId,
|
|
316
301
|
data,
|
|
@@ -325,66 +310,6 @@ function createWsfeService(options) {
|
|
|
325
310
|
forceRefresh
|
|
326
311
|
}).then(({ outcome }) => outcome);
|
|
327
312
|
}
|
|
328
|
-
function authorizeNormalizedVoucher({
|
|
329
|
-
representedTaxId,
|
|
330
|
-
data: normalizedInput,
|
|
331
|
-
voucherNumber,
|
|
332
|
-
forceRefresh,
|
|
333
|
-
allowAuthenticationRecovery
|
|
334
|
-
}) {
|
|
335
|
-
return executeWithAuthenticationRecovery({
|
|
336
|
-
service: "wsfe",
|
|
337
|
-
operation: "FECAESolicitar",
|
|
338
|
-
forceRefresh,
|
|
339
|
-
allowRetry: allowAuthenticationRecovery,
|
|
340
|
-
execute: (attemptForceRefresh) => authorizeNormalizedVoucherOnce({
|
|
341
|
-
representedTaxId,
|
|
342
|
-
data: normalizedInput,
|
|
343
|
-
voucherNumber,
|
|
344
|
-
forceRefresh: attemptForceRefresh
|
|
345
|
-
})
|
|
346
|
-
});
|
|
347
|
-
}
|
|
348
|
-
async function authorizeNormalizedVoucherOnce({
|
|
349
|
-
representedTaxId,
|
|
350
|
-
data: normalizedInput,
|
|
351
|
-
voucherNumber,
|
|
352
|
-
forceRefresh
|
|
353
|
-
}) {
|
|
354
|
-
const execution = await executeWsfeAuthorization({
|
|
355
|
-
representedTaxId,
|
|
356
|
-
data: normalizedInput,
|
|
357
|
-
voucherNumber,
|
|
358
|
-
forceRefresh
|
|
359
|
-
});
|
|
360
|
-
if (execution.error) {
|
|
361
|
-
throw execution.error;
|
|
362
|
-
}
|
|
363
|
-
if (execution.outcome.kind !== "authorized") {
|
|
364
|
-
throw createWsfeOutcomeError(execution.outcome);
|
|
365
|
-
}
|
|
366
|
-
const { cae, caeExpiry, raw } = execution.outcome;
|
|
367
|
-
if (!(caeExpiry && raw)) {
|
|
368
|
-
throw new ArcaServiceError("WSFE did not return CAE authorization data", {
|
|
369
|
-
service: "wsfe",
|
|
370
|
-
operation: "FECAESolicitar",
|
|
371
|
-
result: execution.outcome.result,
|
|
372
|
-
resultLevel: execution.outcome.resultLevel,
|
|
373
|
-
results: execution.outcome.results,
|
|
374
|
-
cae,
|
|
375
|
-
issues: [
|
|
376
|
-
...execution.outcome.errors,
|
|
377
|
-
...execution.outcome.observations
|
|
378
|
-
]
|
|
379
|
-
});
|
|
380
|
-
}
|
|
381
|
-
return {
|
|
382
|
-
cae,
|
|
383
|
-
caeExpiry,
|
|
384
|
-
voucherNumber,
|
|
385
|
-
raw
|
|
386
|
-
};
|
|
387
|
-
}
|
|
388
313
|
async function executeWsfeAuthorization({
|
|
389
314
|
representedTaxId,
|
|
390
315
|
data: normalizedInput,
|
|
@@ -491,23 +416,6 @@ function createWsfeService(options) {
|
|
|
491
416
|
}
|
|
492
417
|
return {
|
|
493
418
|
issue,
|
|
494
|
-
authorizeVoucherOutcome: issue,
|
|
495
|
-
authorizeVoucher,
|
|
496
|
-
async createNextVoucher({ representedTaxId, data, forceRefresh }) {
|
|
497
|
-
const normalizedInput = normalizeWsfeVoucherInput(data);
|
|
498
|
-
const voucherNumber = await getNextVoucherNumber({
|
|
499
|
-
representedTaxId,
|
|
500
|
-
salesPoint: normalizedInput.salesPoint,
|
|
501
|
-
voucherType: normalizedInput.voucherType,
|
|
502
|
-
forceRefresh
|
|
503
|
-
});
|
|
504
|
-
return authorizeNormalizedVoucher({
|
|
505
|
-
representedTaxId,
|
|
506
|
-
data: normalizedInput,
|
|
507
|
-
voucherNumber,
|
|
508
|
-
allowAuthenticationRecovery: forceRefresh !== true
|
|
509
|
-
});
|
|
510
|
-
},
|
|
511
419
|
getNextVoucherNumber,
|
|
512
420
|
getLastVoucher(input) {
|
|
513
421
|
return getNextVoucherNumber(input);
|
|
@@ -1377,27 +1285,6 @@ function getArcaIndeterminateReason(error) {
|
|
|
1377
1285
|
}
|
|
1378
1286
|
return "unexpected_error";
|
|
1379
1287
|
}
|
|
1380
|
-
function createWsfeOutcomeError(outcome) {
|
|
1381
|
-
if (outcome.kind === "indeterminate" && outcome.authentication) {
|
|
1382
|
-
return createArcaAuthenticationErrorFromEvidence(outcome.authentication, {
|
|
1383
|
-
service: "wsfe",
|
|
1384
|
-
operation: outcome.operation
|
|
1385
|
-
});
|
|
1386
|
-
}
|
|
1387
|
-
const issues = [...outcome.errors, ...outcome.observations];
|
|
1388
|
-
const firstIssue = issues[0];
|
|
1389
|
-
const message = firstIssue ? formatWsfeIssue(firstIssue) : outcome.kind === "rejected" ? "WSFE rejected the voucher authorization" : outcome.result === "A" ? "WSFE did not return CAE authorization data" : "WSFE did not return conclusive voucher authorization data";
|
|
1390
|
-
return new ArcaServiceError(message, {
|
|
1391
|
-
service: "wsfe",
|
|
1392
|
-
operation: outcome.operation,
|
|
1393
|
-
...firstIssue?.code === void 0 ? {} : { serviceCode: firstIssue.code },
|
|
1394
|
-
...outcome.result === void 0 ? {} : { result: outcome.result },
|
|
1395
|
-
...outcome.resultLevel === void 0 ? {} : { resultLevel: outcome.resultLevel },
|
|
1396
|
-
results: outcome.results,
|
|
1397
|
-
...outcome.kind === "indeterminate" && outcome.cae ? { cae: outcome.cae } : {},
|
|
1398
|
-
issues
|
|
1399
|
-
});
|
|
1400
|
-
}
|
|
1401
1288
|
function createWsfeServiceError(operation, issues) {
|
|
1402
1289
|
const authenticationError = classifyArcaAuthenticationIssues(issues, {
|
|
1403
1290
|
service: "wsfe",
|
|
@@ -1514,9 +1401,9 @@ function calculateWsfeAmounts(input) {
|
|
|
1514
1401
|
if (!Array.isArray(input.items) || input.items.length === 0) {
|
|
1515
1402
|
invalidItem("items", "a non-empty array of items");
|
|
1516
1403
|
}
|
|
1517
|
-
const isVat = input.
|
|
1518
|
-
if (!(isVat ||
|
|
1519
|
-
invalidItem("
|
|
1404
|
+
const isVat = input.voucherClass === "A" || input.voucherClass === "B";
|
|
1405
|
+
if (!(isVat || input.voucherClass === "C")) {
|
|
1406
|
+
invalidItem("voucherClass", "A, B or C");
|
|
1520
1407
|
}
|
|
1521
1408
|
const totals = collectItems(input.items, isVat);
|
|
1522
1409
|
let net = totals.net;
|
|
@@ -1605,7 +1492,7 @@ function collectItems(items, isVat) {
|
|
|
1605
1492
|
}
|
|
1606
1493
|
function classCAmount(item, path) {
|
|
1607
1494
|
if ("vat" in item || "net" in item || "gross" in item) {
|
|
1608
|
-
invalidItem("items", "amount items for a
|
|
1495
|
+
invalidItem("items", "amount items for a class C voucher");
|
|
1609
1496
|
}
|
|
1610
1497
|
return assertArcaMinorUnits(item.amount, `${path}.amount`);
|
|
1611
1498
|
}
|
|
@@ -1613,7 +1500,7 @@ function vatItemAmount(item, path) {
|
|
|
1613
1500
|
if ("amount" in item || "net" in item === "gross" in item) {
|
|
1614
1501
|
invalidItem(
|
|
1615
1502
|
"items",
|
|
1616
|
-
"exactly one of net or gross, and vat, for
|
|
1503
|
+
"exactly one of net or gross, and vat, for a class A or B voucher"
|
|
1617
1504
|
);
|
|
1618
1505
|
}
|
|
1619
1506
|
const field = "net" in item ? "net" : "gross";
|
|
@@ -1667,7 +1554,7 @@ function buildFacturaB(input) {
|
|
|
1667
1554
|
);
|
|
1668
1555
|
}
|
|
1669
1556
|
const { data } = calculateWsfeAmounts({
|
|
1670
|
-
|
|
1557
|
+
voucherClass: "B",
|
|
1671
1558
|
items: [{ net: input.taxableAmount, vat: input.vatRate }]
|
|
1672
1559
|
});
|
|
1673
1560
|
for (const rate of data.vatRates ?? []) {
|
|
@@ -1683,7 +1570,7 @@ function buildFacturaB(input) {
|
|
|
1683
1570
|
function buildFacturaC(input) {
|
|
1684
1571
|
assertArcaMinorUnits(input.amount, "amount");
|
|
1685
1572
|
const { data } = calculateWsfeAmounts({
|
|
1686
|
-
|
|
1573
|
+
voucherClass: "C",
|
|
1687
1574
|
items: [{ amount: input.amount }]
|
|
1688
1575
|
});
|
|
1689
1576
|
return Object.freeze({
|
|
@@ -1795,4 +1682,4 @@ export {
|
|
|
1795
1682
|
buildFacturaB,
|
|
1796
1683
|
buildFacturaC
|
|
1797
1684
|
};
|
|
1798
|
-
//# sourceMappingURL=chunk-
|
|
1685
|
+
//# sourceMappingURL=chunk-QHHLHSBW.mjs.map
|