facturas 0.6.1 → 0.7.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 +9 -2
- package/dist/chunk-C55KOV5N.mjs +1586 -0
- package/dist/chunk-C55KOV5N.mjs.map +1 -0
- package/dist/chunk-EDY3PNKJ.mjs +106 -0
- package/dist/chunk-EDY3PNKJ.mjs.map +1 -0
- package/dist/chunk-IOKZX6CA.mjs +195 -0
- package/dist/chunk-IOKZX6CA.mjs.map +1 -0
- package/dist/chunk-MBWOFO67.mjs +215 -0
- package/dist/chunk-MBWOFO67.mjs.map +1 -0
- package/dist/chunk-PKE4Z4GE.mjs +702 -0
- package/dist/chunk-PKE4Z4GE.mjs.map +1 -0
- package/dist/chunk-VVY2LZIZ.mjs +61 -0
- package/dist/chunk-VVY2LZIZ.mjs.map +1 -0
- package/dist/constants.d.ts +15 -2
- package/dist/constants.mjs +13 -42
- package/dist/constants.mjs.map +1 -1
- package/dist/errors.d.ts +2 -92
- package/dist/errors.mjs +14 -92
- package/dist/errors.mjs.map +1 -1
- package/dist/fiscal-evidence-BQuBbJ3h.d.ts +189 -0
- package/dist/{index-3fdgJ3c2.d.ts → index-CVpygFb0.d.ts} +1 -1
- package/dist/index.d.ts +15 -8
- package/dist/index.mjs +66 -1743
- package/dist/index.mjs.map +1 -1
- package/dist/padron.d.ts +2 -2
- package/dist/padron.mjs +4 -117
- package/dist/padron.mjs.map +1 -1
- package/dist/{types-Cup-oevW.d.ts → types-BXq0da71.d.ts} +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/wsfe.d.ts +48 -7
- package/dist/wsfe.mjs +10 -1028
- package/dist/wsfe.mjs.map +1 -1
- package/dist/wsmtxca.d.ts +3 -3
- package/dist/wsmtxca.mjs +5 -654
- package/dist/wsmtxca.mjs.map +1 -1
- package/package.json +2 -2
- package/dist/fiscal-evidence-DbbFH74x.d.ts +0 -69
package/dist/index.mjs
CHANGED
|
@@ -1,94 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
contentType;
|
|
28
|
-
responseBody;
|
|
29
|
-
constructor(message, options) {
|
|
30
|
-
super(message, "ARCA_TRANSPORT_ERROR", options);
|
|
31
|
-
this.statusCode = options?.statusCode;
|
|
32
|
-
this.contentType = options?.contentType;
|
|
33
|
-
this.responseBody = options?.responseBody;
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
var ArcaSoapFaultError = class extends ArcaError {
|
|
37
|
-
name = "ArcaSoapFaultError";
|
|
38
|
-
faultCode;
|
|
39
|
-
detail;
|
|
40
|
-
constructor(message, options) {
|
|
41
|
-
super(message, "ARCA_SOAP_FAULT", options);
|
|
42
|
-
this.faultCode = options?.faultCode;
|
|
43
|
-
this.detail = options?.detail;
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
var ArcaInvalidSoapResponseError = class extends ArcaError {
|
|
47
|
-
name = "ArcaInvalidSoapResponseError";
|
|
48
|
-
service;
|
|
49
|
-
operation;
|
|
50
|
-
endpointUrl;
|
|
51
|
-
statusCode;
|
|
52
|
-
contentType;
|
|
53
|
-
responseBodyLength;
|
|
54
|
-
responseBodyPreview;
|
|
55
|
-
parsedDetail;
|
|
56
|
-
constructor(message, options) {
|
|
57
|
-
super(message, "ARCA_INVALID_SOAP_RESPONSE", options);
|
|
58
|
-
this.service = options?.service;
|
|
59
|
-
this.operation = options?.operation;
|
|
60
|
-
this.endpointUrl = options?.endpointUrl;
|
|
61
|
-
this.statusCode = options?.statusCode;
|
|
62
|
-
this.contentType = options?.contentType;
|
|
63
|
-
this.responseBodyLength = options?.responseBodyLength;
|
|
64
|
-
this.responseBodyPreview = options?.responseBodyPreview;
|
|
65
|
-
this.parsedDetail = options?.parsedDetail;
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
var ArcaServiceError = class extends ArcaError {
|
|
69
|
-
name = "ArcaServiceError";
|
|
70
|
-
serviceCode;
|
|
71
|
-
service;
|
|
72
|
-
operation;
|
|
73
|
-
result;
|
|
74
|
-
resultLevel;
|
|
75
|
-
results;
|
|
76
|
-
cae;
|
|
77
|
-
issues;
|
|
78
|
-
detail;
|
|
79
|
-
constructor(message, options) {
|
|
80
|
-
super(message, "ARCA_SERVICE_ERROR", options);
|
|
81
|
-
this.serviceCode = options?.serviceCode;
|
|
82
|
-
this.service = options?.service;
|
|
83
|
-
this.operation = options?.operation;
|
|
84
|
-
this.result = options?.result;
|
|
85
|
-
this.resultLevel = options?.resultLevel;
|
|
86
|
-
this.results = options?.results;
|
|
87
|
-
this.cae = options?.cae;
|
|
88
|
-
this.issues = options?.issues;
|
|
89
|
-
this.detail = options?.detail;
|
|
90
|
-
}
|
|
91
|
-
};
|
|
1
|
+
import {
|
|
2
|
+
createPadronService
|
|
3
|
+
} from "./chunk-EDY3PNKJ.mjs";
|
|
4
|
+
import {
|
|
5
|
+
buildFacturaB,
|
|
6
|
+
buildFacturaC,
|
|
7
|
+
createWsfeService
|
|
8
|
+
} from "./chunk-C55KOV5N.mjs";
|
|
9
|
+
import "./chunk-VVY2LZIZ.mjs";
|
|
10
|
+
import {
|
|
11
|
+
createWsmtxcaService
|
|
12
|
+
} from "./chunk-PKE4Z4GE.mjs";
|
|
13
|
+
import "./chunk-IOKZX6CA.mjs";
|
|
14
|
+
import {
|
|
15
|
+
ArcaAuthenticationError,
|
|
16
|
+
ArcaConfigurationError,
|
|
17
|
+
ArcaError,
|
|
18
|
+
ArcaInputError,
|
|
19
|
+
ArcaInvalidSoapResponseError,
|
|
20
|
+
ArcaServiceError,
|
|
21
|
+
ArcaSoapFaultError,
|
|
22
|
+
ArcaTransportError,
|
|
23
|
+
createResponseBodyDiagnostic,
|
|
24
|
+
createSafeErrorDiagnostic,
|
|
25
|
+
isArcaAuthenticationError
|
|
26
|
+
} from "./chunk-MBWOFO67.mjs";
|
|
92
27
|
|
|
93
28
|
// src/config.ts
|
|
94
29
|
var ARCA_ENVIRONMENTS = ["production", "test"];
|
|
@@ -352,1616 +287,6 @@ function defaultArcaLog(level, message, ...args) {
|
|
|
352
287
|
method(message, ...args);
|
|
353
288
|
}
|
|
354
289
|
|
|
355
|
-
// src/services/padron.ts
|
|
356
|
-
function createPadronService(options) {
|
|
357
|
-
return {
|
|
358
|
-
async getTaxpayerDetails(taxId) {
|
|
359
|
-
const raw = await executePadronOperation(
|
|
360
|
-
options,
|
|
361
|
-
"padron-a5",
|
|
362
|
-
"getPersona_v2",
|
|
363
|
-
{
|
|
364
|
-
idPersona: Number.parseInt(String(taxId), 10)
|
|
365
|
-
}
|
|
366
|
-
);
|
|
367
|
-
if (!raw) {
|
|
368
|
-
return null;
|
|
369
|
-
}
|
|
370
|
-
const record = raw;
|
|
371
|
-
const datosGenerales = record.datosGenerales;
|
|
372
|
-
return {
|
|
373
|
-
taxId: String(record.idPersona ?? ""),
|
|
374
|
-
...record.tipoPersona === void 0 ? {} : { personType: String(record.tipoPersona) },
|
|
375
|
-
...datosGenerales ? { name: extractPadronName(datosGenerales) } : {},
|
|
376
|
-
raw: record
|
|
377
|
-
};
|
|
378
|
-
},
|
|
379
|
-
async getTaxIdByDocument(documentNumber) {
|
|
380
|
-
const raw = await executePadronOperation(
|
|
381
|
-
options,
|
|
382
|
-
"padron-a13",
|
|
383
|
-
"getIdPersonaListByDocumento",
|
|
384
|
-
{
|
|
385
|
-
documento: String(documentNumber)
|
|
386
|
-
}
|
|
387
|
-
);
|
|
388
|
-
if (!raw) {
|
|
389
|
-
return null;
|
|
390
|
-
}
|
|
391
|
-
const record = raw;
|
|
392
|
-
const idPersona = record.idPersona;
|
|
393
|
-
const taxIds = Array.isArray(idPersona) ? idPersona.map(String) : idPersona === void 0 ? [] : [String(idPersona)];
|
|
394
|
-
return {
|
|
395
|
-
taxIds,
|
|
396
|
-
raw: record
|
|
397
|
-
};
|
|
398
|
-
}
|
|
399
|
-
};
|
|
400
|
-
}
|
|
401
|
-
function extractPadronName(datosGenerales) {
|
|
402
|
-
if (typeof datosGenerales.razonSocial === "string") {
|
|
403
|
-
return datosGenerales.razonSocial;
|
|
404
|
-
}
|
|
405
|
-
const nombre = datosGenerales.nombre;
|
|
406
|
-
const apellido = datosGenerales.apellido;
|
|
407
|
-
if (typeof apellido === "string" && typeof nombre === "string") {
|
|
408
|
-
return `${apellido} ${nombre}`.trim();
|
|
409
|
-
}
|
|
410
|
-
if (typeof apellido === "string") {
|
|
411
|
-
return apellido;
|
|
412
|
-
}
|
|
413
|
-
if (typeof nombre === "string") {
|
|
414
|
-
return nombre;
|
|
415
|
-
}
|
|
416
|
-
return void 0;
|
|
417
|
-
}
|
|
418
|
-
async function executePadronOperation(options, service, operation, body) {
|
|
419
|
-
const auth = await options.auth.login(
|
|
420
|
-
service === "padron-a5" ? "ws_sr_constancia_inscripcion" : "ws_sr_padron_a13"
|
|
421
|
-
);
|
|
422
|
-
try {
|
|
423
|
-
const response = await options.soap.execute({
|
|
424
|
-
service,
|
|
425
|
-
operation,
|
|
426
|
-
bodyElementNamespaceMode: "prefix",
|
|
427
|
-
body: {
|
|
428
|
-
token: auth.token,
|
|
429
|
-
sign: auth.sign,
|
|
430
|
-
cuitRepresentada: Number.parseInt(options.config.taxId, 10),
|
|
431
|
-
...body
|
|
432
|
-
}
|
|
433
|
-
});
|
|
434
|
-
const operationResponse = response.result;
|
|
435
|
-
if (operation === "getPersona_v2") {
|
|
436
|
-
return operationResponse.personaReturn ?? null;
|
|
437
|
-
}
|
|
438
|
-
if (operation === "getIdPersonaListByDocumento") {
|
|
439
|
-
return operationResponse.idPersonaListReturn ?? null;
|
|
440
|
-
}
|
|
441
|
-
return operationResponse.return ?? null;
|
|
442
|
-
} catch (error) {
|
|
443
|
-
if (error instanceof ArcaSoapFaultError && // Public Padron A5/A13 WSDLs expose only a generic validation fault, so
|
|
444
|
-
// there is no documented not-found-specific fault code to match here.
|
|
445
|
-
// Keep the current message fallback, but treat it as fragile.
|
|
446
|
-
error.message.toLowerCase().includes("no existe")) {
|
|
447
|
-
return null;
|
|
448
|
-
}
|
|
449
|
-
throw error;
|
|
450
|
-
}
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
// src/services/wsfe.ts
|
|
454
|
-
function createWsfeService(options) {
|
|
455
|
-
async function executeWsfeAuthenticatedRawOperation(operation, input, body = {}, retries) {
|
|
456
|
-
const auth = await options.auth.login("wsfe", {
|
|
457
|
-
representedTaxId: input.representedTaxId,
|
|
458
|
-
forceRefresh: input.forceRefresh
|
|
459
|
-
});
|
|
460
|
-
const response = await options.soap.execute({
|
|
461
|
-
service: "wsfe",
|
|
462
|
-
operation,
|
|
463
|
-
...retries === void 0 ? {} : { retries },
|
|
464
|
-
body: {
|
|
465
|
-
Auth: createWsfeAuth(
|
|
466
|
-
input.representedTaxId ?? options.config.taxId,
|
|
467
|
-
auth.token,
|
|
468
|
-
auth.sign
|
|
469
|
-
),
|
|
470
|
-
...body
|
|
471
|
-
}
|
|
472
|
-
});
|
|
473
|
-
return unwrapWsfeOperationEnvelope(operation, response.result);
|
|
474
|
-
}
|
|
475
|
-
async function executeWsfeAuthenticatedOperation(operation, input, body = {}) {
|
|
476
|
-
const result = await executeWsfeAuthenticatedRawOperation(
|
|
477
|
-
operation,
|
|
478
|
-
input,
|
|
479
|
-
body
|
|
480
|
-
);
|
|
481
|
-
throwForWsfeOperationErrors(operation, result);
|
|
482
|
-
return result;
|
|
483
|
-
}
|
|
484
|
-
async function executeWsfeOperation(operation, body = {}) {
|
|
485
|
-
const response = await options.soap.execute({
|
|
486
|
-
service: "wsfe",
|
|
487
|
-
operation,
|
|
488
|
-
body
|
|
489
|
-
});
|
|
490
|
-
const result = unwrapWsfeOperationEnvelope(operation, response.result);
|
|
491
|
-
throwForWsfeOperationErrors(operation, result);
|
|
492
|
-
return result;
|
|
493
|
-
}
|
|
494
|
-
async function getNextVoucherNumber({
|
|
495
|
-
representedTaxId,
|
|
496
|
-
salesPoint,
|
|
497
|
-
voucherType,
|
|
498
|
-
forceRefresh
|
|
499
|
-
}) {
|
|
500
|
-
const result = await executeWsfeAuthenticatedOperation(
|
|
501
|
-
"FECompUltimoAutorizado",
|
|
502
|
-
{
|
|
503
|
-
representedTaxId,
|
|
504
|
-
forceRefresh
|
|
505
|
-
},
|
|
506
|
-
{
|
|
507
|
-
PtoVta: salesPoint,
|
|
508
|
-
CbteTipo: voucherType
|
|
509
|
-
}
|
|
510
|
-
);
|
|
511
|
-
return Number(result.CbteNro ?? 0) + 1;
|
|
512
|
-
}
|
|
513
|
-
async function getWsfeCatalog(operation, resultKey, input) {
|
|
514
|
-
const result = await executeWsfeAuthenticatedOperation(operation, {
|
|
515
|
-
representedTaxId: input.representedTaxId,
|
|
516
|
-
forceRefresh: input.forceRefresh
|
|
517
|
-
});
|
|
518
|
-
return getWsfeResultEntries(result, resultKey).map(mapWsfeCatalogEntry);
|
|
519
|
-
}
|
|
520
|
-
function authorizeVoucher({
|
|
521
|
-
representedTaxId,
|
|
522
|
-
data,
|
|
523
|
-
voucherNumber,
|
|
524
|
-
forceRefresh
|
|
525
|
-
}) {
|
|
526
|
-
const normalizedInput = normalizeWsfeVoucherInput(data);
|
|
527
|
-
return authorizeNormalizedVoucher({
|
|
528
|
-
representedTaxId,
|
|
529
|
-
data: normalizedInput,
|
|
530
|
-
voucherNumber,
|
|
531
|
-
forceRefresh
|
|
532
|
-
});
|
|
533
|
-
}
|
|
534
|
-
function authorizeVoucherOutcome({
|
|
535
|
-
representedTaxId,
|
|
536
|
-
data,
|
|
537
|
-
voucherNumber,
|
|
538
|
-
forceRefresh
|
|
539
|
-
}) {
|
|
540
|
-
const normalizedInput = normalizeWsfeVoucherInput(data);
|
|
541
|
-
return executeWsfeAuthorization({
|
|
542
|
-
representedTaxId,
|
|
543
|
-
data: normalizedInput,
|
|
544
|
-
voucherNumber,
|
|
545
|
-
forceRefresh
|
|
546
|
-
}).then(({ outcome }) => outcome);
|
|
547
|
-
}
|
|
548
|
-
async function authorizeNormalizedVoucher({
|
|
549
|
-
representedTaxId,
|
|
550
|
-
data: normalizedInput,
|
|
551
|
-
voucherNumber,
|
|
552
|
-
forceRefresh
|
|
553
|
-
}) {
|
|
554
|
-
const execution = await executeWsfeAuthorization({
|
|
555
|
-
representedTaxId,
|
|
556
|
-
data: normalizedInput,
|
|
557
|
-
voucherNumber,
|
|
558
|
-
forceRefresh
|
|
559
|
-
});
|
|
560
|
-
if (execution.error) {
|
|
561
|
-
throw execution.error;
|
|
562
|
-
}
|
|
563
|
-
if (execution.outcome.kind !== "authorized") {
|
|
564
|
-
throw createWsfeOutcomeError(execution.outcome);
|
|
565
|
-
}
|
|
566
|
-
const { cae, caeExpiry, raw } = execution.outcome;
|
|
567
|
-
if (!(caeExpiry && raw)) {
|
|
568
|
-
throw new ArcaServiceError("WSFE did not return CAE authorization data", {
|
|
569
|
-
service: "wsfe",
|
|
570
|
-
operation: "FECAESolicitar",
|
|
571
|
-
result: execution.outcome.result,
|
|
572
|
-
resultLevel: execution.outcome.resultLevel,
|
|
573
|
-
results: execution.outcome.results,
|
|
574
|
-
cae,
|
|
575
|
-
issues: [
|
|
576
|
-
...execution.outcome.errors,
|
|
577
|
-
...execution.outcome.observations
|
|
578
|
-
],
|
|
579
|
-
detail: raw
|
|
580
|
-
});
|
|
581
|
-
}
|
|
582
|
-
return {
|
|
583
|
-
cae,
|
|
584
|
-
caeExpiry,
|
|
585
|
-
voucherNumber,
|
|
586
|
-
raw
|
|
587
|
-
};
|
|
588
|
-
}
|
|
589
|
-
async function executeWsfeAuthorization({
|
|
590
|
-
representedTaxId,
|
|
591
|
-
data: normalizedInput,
|
|
592
|
-
voucherNumber,
|
|
593
|
-
forceRefresh
|
|
594
|
-
}) {
|
|
595
|
-
const requestData = mapWsfeVoucherInput(normalizedInput, voucherNumber);
|
|
596
|
-
try {
|
|
597
|
-
const result = await executeWsfeAuthenticatedRawOperation(
|
|
598
|
-
"FECAESolicitar",
|
|
599
|
-
{ representedTaxId, forceRefresh },
|
|
600
|
-
{
|
|
601
|
-
FeCAEReq: {
|
|
602
|
-
FeCabReq: {
|
|
603
|
-
CantReg: 1,
|
|
604
|
-
PtoVta: normalizedInput.salesPoint,
|
|
605
|
-
CbteTipo: normalizedInput.voucherType
|
|
606
|
-
},
|
|
607
|
-
FeDetReq: {
|
|
608
|
-
FECAEDetRequest: requestData
|
|
609
|
-
}
|
|
610
|
-
}
|
|
611
|
-
},
|
|
612
|
-
0
|
|
613
|
-
);
|
|
614
|
-
return {
|
|
615
|
-
outcome: classifyWsfeAuthorization(result, voucherNumber)
|
|
616
|
-
};
|
|
617
|
-
} catch (error) {
|
|
618
|
-
return {
|
|
619
|
-
outcome: createWsfeIndeterminateOutcome(error),
|
|
620
|
-
error
|
|
621
|
-
};
|
|
622
|
-
}
|
|
623
|
-
}
|
|
624
|
-
async function lookupVoucher({
|
|
625
|
-
representedTaxId,
|
|
626
|
-
number,
|
|
627
|
-
salesPoint,
|
|
628
|
-
voucherType,
|
|
629
|
-
forceRefresh
|
|
630
|
-
}) {
|
|
631
|
-
const operation = "FECompConsultar";
|
|
632
|
-
const result = await executeWsfeAuthenticatedRawOperation(
|
|
633
|
-
operation,
|
|
634
|
-
{ representedTaxId, forceRefresh },
|
|
635
|
-
{
|
|
636
|
-
FeCompConsReq: {
|
|
637
|
-
CbteNro: number,
|
|
638
|
-
PtoVta: salesPoint,
|
|
639
|
-
CbteTipo: voucherType
|
|
640
|
-
}
|
|
641
|
-
}
|
|
642
|
-
);
|
|
643
|
-
const errors = extractWsfeGlobalIssues(result, operation);
|
|
644
|
-
if (errors.length > 0 && errors.every((issue) => issue.code === "602")) {
|
|
645
|
-
return {
|
|
646
|
-
kind: "not_found",
|
|
647
|
-
service: "wsfe",
|
|
648
|
-
operation,
|
|
649
|
-
errors,
|
|
650
|
-
observations: [],
|
|
651
|
-
raw: result
|
|
652
|
-
};
|
|
653
|
-
}
|
|
654
|
-
if (errors.length > 0) {
|
|
655
|
-
throw createWsfeServiceError(operation, result, errors);
|
|
656
|
-
}
|
|
657
|
-
const raw = toWsfeRecord(result.ResultGet);
|
|
658
|
-
if (!raw) {
|
|
659
|
-
throw new ArcaServiceError("WSFE did not return the consulted voucher", {
|
|
660
|
-
service: "wsfe",
|
|
661
|
-
operation,
|
|
662
|
-
detail: result
|
|
663
|
-
});
|
|
664
|
-
}
|
|
665
|
-
return {
|
|
666
|
-
kind: "found",
|
|
667
|
-
service: "wsfe",
|
|
668
|
-
operation,
|
|
669
|
-
voucher: mapWsfeVoucherInfo(raw),
|
|
670
|
-
observations: [],
|
|
671
|
-
raw: result
|
|
672
|
-
};
|
|
673
|
-
}
|
|
674
|
-
return {
|
|
675
|
-
authorizeVoucherOutcome,
|
|
676
|
-
authorizeVoucher,
|
|
677
|
-
async createNextVoucher({ representedTaxId, data, forceRefresh }) {
|
|
678
|
-
const normalizedInput = normalizeWsfeVoucherInput(data);
|
|
679
|
-
const voucherNumber = await getNextVoucherNumber({
|
|
680
|
-
representedTaxId,
|
|
681
|
-
salesPoint: normalizedInput.salesPoint,
|
|
682
|
-
voucherType: normalizedInput.voucherType,
|
|
683
|
-
forceRefresh
|
|
684
|
-
});
|
|
685
|
-
return authorizeNormalizedVoucher({
|
|
686
|
-
representedTaxId,
|
|
687
|
-
data: normalizedInput,
|
|
688
|
-
voucherNumber
|
|
689
|
-
});
|
|
690
|
-
},
|
|
691
|
-
getNextVoucherNumber,
|
|
692
|
-
getLastVoucher(input) {
|
|
693
|
-
return getNextVoucherNumber(input);
|
|
694
|
-
},
|
|
695
|
-
async getSalesPoints({ representedTaxId, forceRefresh }) {
|
|
696
|
-
const result = await executeWsfeAuthenticatedOperation(
|
|
697
|
-
"FEParamGetPtosVenta",
|
|
698
|
-
{
|
|
699
|
-
representedTaxId,
|
|
700
|
-
forceRefresh
|
|
701
|
-
}
|
|
702
|
-
);
|
|
703
|
-
const rawPoints = result.ResultGet?.PtoVenta;
|
|
704
|
-
if (!rawPoints) {
|
|
705
|
-
return [];
|
|
706
|
-
}
|
|
707
|
-
const entries = Array.isArray(rawPoints) ? rawPoints : [rawPoints];
|
|
708
|
-
return entries.map(mapWsfeSalesPoint);
|
|
709
|
-
},
|
|
710
|
-
getVoucherTypes(input) {
|
|
711
|
-
return getWsfeCatalog("FEParamGetTiposCbte", "CbteTipo", input);
|
|
712
|
-
},
|
|
713
|
-
getDocumentTypes(input) {
|
|
714
|
-
return getWsfeCatalog("FEParamGetTiposDoc", "DocTipo", input);
|
|
715
|
-
},
|
|
716
|
-
getConceptTypes(input) {
|
|
717
|
-
return getWsfeCatalog("FEParamGetTiposConcepto", "ConceptoTipo", input);
|
|
718
|
-
},
|
|
719
|
-
async getCurrencyTypes({ representedTaxId, forceRefresh }) {
|
|
720
|
-
const result = await executeWsfeAuthenticatedOperation(
|
|
721
|
-
"FEParamGetTiposMonedas",
|
|
722
|
-
{
|
|
723
|
-
representedTaxId,
|
|
724
|
-
forceRefresh
|
|
725
|
-
}
|
|
726
|
-
);
|
|
727
|
-
return getWsfeResultEntries(result, "Moneda").map(mapWsfeCurrencyType);
|
|
728
|
-
},
|
|
729
|
-
getVatRates(input) {
|
|
730
|
-
return getWsfeCatalog("FEParamGetTiposIva", "IvaTipo", input);
|
|
731
|
-
},
|
|
732
|
-
getTaxTypes(input) {
|
|
733
|
-
return getWsfeCatalog("FEParamGetTiposTributos", "TributoTipo", input);
|
|
734
|
-
},
|
|
735
|
-
getOptionalTypes(input) {
|
|
736
|
-
return getWsfeCatalog("FEParamGetTiposOpcional", "OpcionalTipo", input);
|
|
737
|
-
},
|
|
738
|
-
async getActivities({ representedTaxId, forceRefresh }) {
|
|
739
|
-
const result = await executeWsfeAuthenticatedOperation(
|
|
740
|
-
"FEParamGetActividades",
|
|
741
|
-
{
|
|
742
|
-
representedTaxId,
|
|
743
|
-
forceRefresh
|
|
744
|
-
}
|
|
745
|
-
);
|
|
746
|
-
return getWsfeResultEntries(result, "ActividadesTipo").map(
|
|
747
|
-
mapWsfeActivityType
|
|
748
|
-
);
|
|
749
|
-
},
|
|
750
|
-
async getReceiverVatConditions({
|
|
751
|
-
representedTaxId,
|
|
752
|
-
voucherClass,
|
|
753
|
-
forceRefresh
|
|
754
|
-
}) {
|
|
755
|
-
const result = await executeWsfeAuthenticatedOperation(
|
|
756
|
-
"FEParamGetCondicionIvaReceptor",
|
|
757
|
-
{
|
|
758
|
-
representedTaxId,
|
|
759
|
-
forceRefresh
|
|
760
|
-
},
|
|
761
|
-
{
|
|
762
|
-
...voucherClass === void 0 ? {} : { ClaseCmp: voucherClass }
|
|
763
|
-
}
|
|
764
|
-
);
|
|
765
|
-
return getWsfeResultEntries(result, "CondicionIvaReceptor").map(
|
|
766
|
-
mapWsfeReceiverVatCondition
|
|
767
|
-
);
|
|
768
|
-
},
|
|
769
|
-
async getServerStatus() {
|
|
770
|
-
const result = await executeWsfeOperation("FEDummy");
|
|
771
|
-
return mapWsfeServerStatus(result);
|
|
772
|
-
},
|
|
773
|
-
async getQuotation({ currencyId, representedTaxId, forceRefresh }) {
|
|
774
|
-
const result = await executeWsfeAuthenticatedOperation(
|
|
775
|
-
"FEParamGetCotizacion",
|
|
776
|
-
{
|
|
777
|
-
representedTaxId,
|
|
778
|
-
forceRefresh
|
|
779
|
-
},
|
|
780
|
-
{
|
|
781
|
-
MonId: currencyId
|
|
782
|
-
}
|
|
783
|
-
);
|
|
784
|
-
const raw = result.ResultGet ?? {};
|
|
785
|
-
return mapWsfeQuotation(raw);
|
|
786
|
-
},
|
|
787
|
-
async getVoucherInfo(input) {
|
|
788
|
-
const lookup = await lookupVoucher(input);
|
|
789
|
-
return lookup.kind === "found" ? lookup.voucher : null;
|
|
790
|
-
},
|
|
791
|
-
lookupVoucher
|
|
792
|
-
};
|
|
793
|
-
}
|
|
794
|
-
function mapWsfeVoucherInput(input, voucherNumber) {
|
|
795
|
-
const data = {
|
|
796
|
-
Concepto: input.concept,
|
|
797
|
-
DocTipo: input.documentType,
|
|
798
|
-
DocNro: input.documentNumber,
|
|
799
|
-
CbteDesde: voucherNumber,
|
|
800
|
-
CbteHasta: voucherNumber,
|
|
801
|
-
CbteFch: input.voucherDate,
|
|
802
|
-
ImpTotal: input.totalAmount,
|
|
803
|
-
ImpTotConc: input.nonTaxableAmount,
|
|
804
|
-
ImpNeto: input.netAmount,
|
|
805
|
-
ImpOpEx: input.exemptAmount,
|
|
806
|
-
ImpTrib: input.taxAmount,
|
|
807
|
-
ImpIVA: input.vatAmount,
|
|
808
|
-
MonId: input.currencyId,
|
|
809
|
-
PtoVta: input.salesPoint,
|
|
810
|
-
CbteTipo: input.voucherType
|
|
811
|
-
};
|
|
812
|
-
if (input.exchangeRate !== void 0) {
|
|
813
|
-
data.MonCotiz = input.exchangeRate;
|
|
814
|
-
}
|
|
815
|
-
if (input.receiverVatConditionId !== void 0) {
|
|
816
|
-
data.CondicionIVAReceptorId = input.receiverVatConditionId;
|
|
817
|
-
}
|
|
818
|
-
if (input.currencyId !== "PES" && input.sameCurrencyForeignCancellation !== void 0) {
|
|
819
|
-
data.CanMisMonExt = input.sameCurrencyForeignCancellation;
|
|
820
|
-
}
|
|
821
|
-
if (input.serviceStartDate !== void 0) {
|
|
822
|
-
data.FchServDesde = input.serviceStartDate;
|
|
823
|
-
}
|
|
824
|
-
if (input.serviceEndDate !== void 0) {
|
|
825
|
-
data.FchServHasta = input.serviceEndDate;
|
|
826
|
-
}
|
|
827
|
-
if (input.paymentDueDate !== void 0) {
|
|
828
|
-
data.FchVtoPago = input.paymentDueDate;
|
|
829
|
-
}
|
|
830
|
-
if (input.associatedVouchers) {
|
|
831
|
-
data.CbtesAsoc = {
|
|
832
|
-
CbteAsoc: input.associatedVouchers.map((v) => ({
|
|
833
|
-
Tipo: v.type,
|
|
834
|
-
PtoVta: v.salesPoint,
|
|
835
|
-
Nro: v.number,
|
|
836
|
-
...v.taxId === void 0 ? {} : { Cuit: v.taxId },
|
|
837
|
-
...v.voucherDate === void 0 ? {} : { CbteFch: v.voucherDate }
|
|
838
|
-
}))
|
|
839
|
-
};
|
|
840
|
-
}
|
|
841
|
-
if (input.associatedPeriod) {
|
|
842
|
-
data.PeriodoAsoc = {
|
|
843
|
-
FchDesde: input.associatedPeriod.startDate,
|
|
844
|
-
FchHasta: input.associatedPeriod.endDate
|
|
845
|
-
};
|
|
846
|
-
}
|
|
847
|
-
if (input.taxes) {
|
|
848
|
-
data.Tributos = {
|
|
849
|
-
Tributo: input.taxes.map((t) => ({
|
|
850
|
-
Id: t.id,
|
|
851
|
-
...t.description === void 0 ? {} : { Desc: t.description },
|
|
852
|
-
BaseImp: t.baseAmount,
|
|
853
|
-
Alic: t.rate,
|
|
854
|
-
Importe: t.amount
|
|
855
|
-
}))
|
|
856
|
-
};
|
|
857
|
-
}
|
|
858
|
-
if (input.vatRates) {
|
|
859
|
-
data.Iva = {
|
|
860
|
-
AlicIva: input.vatRates.map((v) => ({
|
|
861
|
-
Id: v.id,
|
|
862
|
-
BaseImp: v.baseAmount,
|
|
863
|
-
Importe: v.amount
|
|
864
|
-
}))
|
|
865
|
-
};
|
|
866
|
-
}
|
|
867
|
-
if (input.optionalFields) {
|
|
868
|
-
data.Opcionales = {
|
|
869
|
-
Opcional: input.optionalFields.map((o) => ({
|
|
870
|
-
Id: o.id,
|
|
871
|
-
Valor: o.value
|
|
872
|
-
}))
|
|
873
|
-
};
|
|
874
|
-
}
|
|
875
|
-
if (input.buyers) {
|
|
876
|
-
data.Compradores = {
|
|
877
|
-
Comprador: input.buyers.map((b) => ({
|
|
878
|
-
DocTipo: b.documentType,
|
|
879
|
-
DocNro: b.documentNumber,
|
|
880
|
-
Porcentaje: b.percentage
|
|
881
|
-
}))
|
|
882
|
-
};
|
|
883
|
-
}
|
|
884
|
-
if (input.activities) {
|
|
885
|
-
data.Actividades = {
|
|
886
|
-
Actividad: input.activities.map((a) => ({
|
|
887
|
-
Id: a.id
|
|
888
|
-
}))
|
|
889
|
-
};
|
|
890
|
-
}
|
|
891
|
-
return data;
|
|
892
|
-
}
|
|
893
|
-
function normalizeWsfeVoucherInput(input) {
|
|
894
|
-
const {
|
|
895
|
-
voucherDate,
|
|
896
|
-
exchangeRate,
|
|
897
|
-
serviceStartDate,
|
|
898
|
-
serviceEndDate,
|
|
899
|
-
paymentDueDate,
|
|
900
|
-
associatedVouchers,
|
|
901
|
-
associatedPeriod,
|
|
902
|
-
...rest
|
|
903
|
-
} = input;
|
|
904
|
-
const normalizedExchangeRate = normalizeWsfeExchangeRate(input, exchangeRate);
|
|
905
|
-
return {
|
|
906
|
-
...rest,
|
|
907
|
-
voucherDate: normalizeWsfeDateInput(voucherDate, "voucherDate"),
|
|
908
|
-
...normalizedExchangeRate === void 0 ? {} : { exchangeRate: normalizedExchangeRate },
|
|
909
|
-
...serviceStartDate === void 0 ? {} : {
|
|
910
|
-
serviceStartDate: normalizeWsfeDateInput(
|
|
911
|
-
serviceStartDate,
|
|
912
|
-
"serviceStartDate"
|
|
913
|
-
)
|
|
914
|
-
},
|
|
915
|
-
...serviceEndDate === void 0 ? {} : {
|
|
916
|
-
serviceEndDate: normalizeWsfeDateInput(
|
|
917
|
-
serviceEndDate,
|
|
918
|
-
"serviceEndDate"
|
|
919
|
-
)
|
|
920
|
-
},
|
|
921
|
-
...paymentDueDate === void 0 ? {} : {
|
|
922
|
-
paymentDueDate: normalizeWsfeDateInput(
|
|
923
|
-
paymentDueDate,
|
|
924
|
-
"paymentDueDate"
|
|
925
|
-
)
|
|
926
|
-
},
|
|
927
|
-
...associatedVouchers === void 0 ? {} : {
|
|
928
|
-
associatedVouchers: associatedVouchers.map((voucher, index) => {
|
|
929
|
-
const { voucherDate: associatedVoucherDate, ...associatedRest } = voucher;
|
|
930
|
-
return {
|
|
931
|
-
...associatedRest,
|
|
932
|
-
...associatedVoucherDate === void 0 ? {} : {
|
|
933
|
-
voucherDate: normalizeWsfeDateInput(
|
|
934
|
-
associatedVoucherDate,
|
|
935
|
-
`associatedVouchers[${index}].voucherDate`
|
|
936
|
-
)
|
|
937
|
-
}
|
|
938
|
-
};
|
|
939
|
-
})
|
|
940
|
-
},
|
|
941
|
-
...associatedPeriod === void 0 ? {} : {
|
|
942
|
-
associatedPeriod: {
|
|
943
|
-
startDate: normalizeWsfeDateInput(
|
|
944
|
-
associatedPeriod.startDate,
|
|
945
|
-
"associatedPeriod.startDate"
|
|
946
|
-
),
|
|
947
|
-
endDate: normalizeWsfeDateInput(
|
|
948
|
-
associatedPeriod.endDate,
|
|
949
|
-
"associatedPeriod.endDate"
|
|
950
|
-
)
|
|
951
|
-
}
|
|
952
|
-
}
|
|
953
|
-
};
|
|
954
|
-
}
|
|
955
|
-
function normalizeWsfeExchangeRate(input, exchangeRate) {
|
|
956
|
-
if (input.currencyId === "PES") {
|
|
957
|
-
if (exchangeRate !== void 0 && exchangeRate !== 1) {
|
|
958
|
-
throw new ArcaInputError(
|
|
959
|
-
"exchangeRate must be 1 when currencyId is PES."
|
|
960
|
-
);
|
|
961
|
-
}
|
|
962
|
-
return 1;
|
|
963
|
-
}
|
|
964
|
-
if (exchangeRate === void 0) {
|
|
965
|
-
if (input.sameCurrencyForeignCancellation === "S") {
|
|
966
|
-
return void 0;
|
|
967
|
-
}
|
|
968
|
-
throw new ArcaInputError(
|
|
969
|
-
"exchangeRate is required unless sameCurrencyForeignCancellation is S for a foreign-currency voucher."
|
|
970
|
-
);
|
|
971
|
-
}
|
|
972
|
-
if (!(Number.isFinite(exchangeRate) && exchangeRate > 0)) {
|
|
973
|
-
throw new ArcaInputError(
|
|
974
|
-
"exchangeRate must be a positive finite number for a foreign-currency voucher."
|
|
975
|
-
);
|
|
976
|
-
}
|
|
977
|
-
return exchangeRate;
|
|
978
|
-
}
|
|
979
|
-
function normalizeWsfeDateInput(value, fieldName) {
|
|
980
|
-
if (typeof value !== "string") {
|
|
981
|
-
throw new ArcaInputError(
|
|
982
|
-
`Invalid WSFE ${fieldName}: expected a YYYY-MM-DD or YYYYMMDD string`,
|
|
983
|
-
{
|
|
984
|
-
detail: { field: fieldName, value }
|
|
985
|
-
}
|
|
986
|
-
);
|
|
987
|
-
}
|
|
988
|
-
const normalizedValue = value.trim();
|
|
989
|
-
const afipMatch = normalizedValue.match(/^(\d{4})(\d{2})(\d{2})$/);
|
|
990
|
-
if (afipMatch) {
|
|
991
|
-
const [, year, month, day] = afipMatch;
|
|
992
|
-
assertValidCalendarDate(year, month, day, fieldName, normalizedValue);
|
|
993
|
-
return normalizedValue;
|
|
994
|
-
}
|
|
995
|
-
const isoMatch = normalizedValue.match(/^(\d{4})-(\d{2})-(\d{2})$/);
|
|
996
|
-
if (isoMatch) {
|
|
997
|
-
const [, year, month, day] = isoMatch;
|
|
998
|
-
assertValidCalendarDate(year, month, day, fieldName, normalizedValue);
|
|
999
|
-
return `${year}${month}${day}`;
|
|
1000
|
-
}
|
|
1001
|
-
throw new ArcaInputError(
|
|
1002
|
-
`Invalid WSFE ${fieldName}: expected a YYYY-MM-DD or YYYYMMDD string`,
|
|
1003
|
-
{
|
|
1004
|
-
detail: { field: fieldName, value: normalizedValue }
|
|
1005
|
-
}
|
|
1006
|
-
);
|
|
1007
|
-
}
|
|
1008
|
-
function assertValidCalendarDate(yearInput, monthInput, dayInput, fieldName, value) {
|
|
1009
|
-
const year = Number(yearInput);
|
|
1010
|
-
const month = Number(monthInput);
|
|
1011
|
-
const day = Number(dayInput);
|
|
1012
|
-
const candidate = new Date(Date.UTC(year, month - 1, day));
|
|
1013
|
-
if (candidate.getUTCFullYear() !== year || candidate.getUTCMonth() !== month - 1 || candidate.getUTCDate() !== day) {
|
|
1014
|
-
throw new ArcaInputError(
|
|
1015
|
-
`Invalid WSFE ${fieldName}: received a non-existent calendar date`,
|
|
1016
|
-
{
|
|
1017
|
-
detail: { field: fieldName, value }
|
|
1018
|
-
}
|
|
1019
|
-
);
|
|
1020
|
-
}
|
|
1021
|
-
}
|
|
1022
|
-
function mapWsfeSalesPoint(raw) {
|
|
1023
|
-
const record = raw;
|
|
1024
|
-
return {
|
|
1025
|
-
number: Number(record.Nro ?? 0),
|
|
1026
|
-
...record.EmisionTipo === void 0 ? {} : { emissionType: String(record.EmisionTipo) },
|
|
1027
|
-
...record.Bloqueado === void 0 ? {} : { blocked: String(record.Bloqueado) },
|
|
1028
|
-
...record.FchBaja === void 0 ? {} : { deletedSince: String(record.FchBaja) }
|
|
1029
|
-
};
|
|
1030
|
-
}
|
|
1031
|
-
function mapWsfeCatalogEntry(raw) {
|
|
1032
|
-
const record = raw;
|
|
1033
|
-
return {
|
|
1034
|
-
id: Number(record.Id ?? 0),
|
|
1035
|
-
description: String(record.Desc ?? "")
|
|
1036
|
-
};
|
|
1037
|
-
}
|
|
1038
|
-
function mapWsfeActivityType(raw) {
|
|
1039
|
-
const record = raw;
|
|
1040
|
-
return {
|
|
1041
|
-
id: Number(record.Id ?? 0),
|
|
1042
|
-
description: String(record.Desc ?? ""),
|
|
1043
|
-
order: Number(record.Orden ?? 0)
|
|
1044
|
-
};
|
|
1045
|
-
}
|
|
1046
|
-
function mapWsfeReceiverVatCondition(raw) {
|
|
1047
|
-
const record = raw;
|
|
1048
|
-
return {
|
|
1049
|
-
id: Number(record.Id ?? 0),
|
|
1050
|
-
description: String(record.Desc ?? ""),
|
|
1051
|
-
voucherClass: String(record.Cmp_Clase ?? "")
|
|
1052
|
-
};
|
|
1053
|
-
}
|
|
1054
|
-
function mapWsfeCurrencyType(raw) {
|
|
1055
|
-
const record = raw;
|
|
1056
|
-
return {
|
|
1057
|
-
id: String(record.Id ?? ""),
|
|
1058
|
-
description: String(record.Desc ?? ""),
|
|
1059
|
-
validFrom: String(record.FchDesde ?? ""),
|
|
1060
|
-
validTo: String(record.FchHasta ?? "")
|
|
1061
|
-
};
|
|
1062
|
-
}
|
|
1063
|
-
function mapWsfeServerStatus(raw) {
|
|
1064
|
-
return {
|
|
1065
|
-
appServer: String(raw.AppServer ?? ""),
|
|
1066
|
-
dbServer: String(raw.DbServer ?? ""),
|
|
1067
|
-
authServer: String(raw.AuthServer ?? "")
|
|
1068
|
-
};
|
|
1069
|
-
}
|
|
1070
|
-
function mapWsfeQuotation(raw) {
|
|
1071
|
-
return {
|
|
1072
|
-
currencyId: String(raw.MonId ?? ""),
|
|
1073
|
-
rate: Number(raw.MonCotiz ?? 0),
|
|
1074
|
-
date: String(raw.FchCotiz ?? "")
|
|
1075
|
-
};
|
|
1076
|
-
}
|
|
1077
|
-
function mapWsfeVoucherInfo(raw) {
|
|
1078
|
-
const voucher = {
|
|
1079
|
-
voucherNumber: Number(raw.CbteDesde ?? raw.CbteHasta ?? 0),
|
|
1080
|
-
raw
|
|
1081
|
-
};
|
|
1082
|
-
assignWsfeValue(voucher, "voucherDate", normalizeWsfeString(raw.CbteFch));
|
|
1083
|
-
assignWsfeValue(voucher, "salesPoint", normalizeWsfeNumber(raw.PtoVta));
|
|
1084
|
-
assignWsfeValue(voucher, "voucherType", normalizeWsfeNumber(raw.CbteTipo));
|
|
1085
|
-
assignWsfeValue(voucher, "concept", normalizeWsfeNumber(raw.Concepto));
|
|
1086
|
-
assignWsfeValue(voucher, "documentType", normalizeWsfeNumber(raw.DocTipo));
|
|
1087
|
-
assignWsfeValue(voucher, "documentNumber", normalizeWsfeString(raw.DocNro));
|
|
1088
|
-
assignWsfeValue(
|
|
1089
|
-
voucher,
|
|
1090
|
-
"receiverVatConditionId",
|
|
1091
|
-
normalizeWsfeNumber(raw.CondicionIVAReceptorId)
|
|
1092
|
-
);
|
|
1093
|
-
assignWsfeValue(voucher, "totalAmount", normalizeWsfeNumber(raw.ImpTotal));
|
|
1094
|
-
assignWsfeValue(
|
|
1095
|
-
voucher,
|
|
1096
|
-
"nonTaxableAmount",
|
|
1097
|
-
normalizeWsfeNumber(raw.ImpTotConc)
|
|
1098
|
-
);
|
|
1099
|
-
assignWsfeValue(voucher, "netAmount", normalizeWsfeNumber(raw.ImpNeto));
|
|
1100
|
-
assignWsfeValue(voucher, "exemptAmount", normalizeWsfeNumber(raw.ImpOpEx));
|
|
1101
|
-
assignWsfeValue(voucher, "taxAmount", normalizeWsfeNumber(raw.ImpTrib));
|
|
1102
|
-
assignWsfeValue(voucher, "vatAmount", normalizeWsfeNumber(raw.ImpIVA));
|
|
1103
|
-
assignWsfeValue(voucher, "currencyId", normalizeWsfeString(raw.MonId));
|
|
1104
|
-
assignWsfeValue(voucher, "exchangeRate", normalizeWsfeNumber(raw.MonCotiz));
|
|
1105
|
-
assignWsfeValue(voucher, "result", normalizeWsfeString(raw.Resultado));
|
|
1106
|
-
assignWsfeValue(
|
|
1107
|
-
voucher,
|
|
1108
|
-
"cae",
|
|
1109
|
-
normalizeWsfeString(raw.CodAutorizacion ?? raw.CAE)
|
|
1110
|
-
);
|
|
1111
|
-
assignWsfeValue(
|
|
1112
|
-
voucher,
|
|
1113
|
-
"caeExpiry",
|
|
1114
|
-
normalizeWsfeString(raw.FchVto ?? raw.CAEFchVto)
|
|
1115
|
-
);
|
|
1116
|
-
return voucher;
|
|
1117
|
-
}
|
|
1118
|
-
function createWsfeAuth(representedTaxId, token, sign) {
|
|
1119
|
-
return {
|
|
1120
|
-
Token: token,
|
|
1121
|
-
Sign: sign,
|
|
1122
|
-
Cuit: Number.parseInt(String(representedTaxId), 10)
|
|
1123
|
-
};
|
|
1124
|
-
}
|
|
1125
|
-
function unwrapWsfeOperationEnvelope(operation, response) {
|
|
1126
|
-
const operationResponse = response[`${operation}Response`];
|
|
1127
|
-
const result = operationResponse?.[`${operation}Result`] ?? response[`${operation}Result`] ?? response;
|
|
1128
|
-
return result;
|
|
1129
|
-
}
|
|
1130
|
-
function throwForWsfeOperationErrors(operation, result) {
|
|
1131
|
-
const errors = extractWsfeGlobalIssues(result, operation);
|
|
1132
|
-
if (errors.length > 0) {
|
|
1133
|
-
throw createWsfeServiceError(operation, result, errors);
|
|
1134
|
-
}
|
|
1135
|
-
}
|
|
1136
|
-
function normalizeWsfeDetailResponse(result) {
|
|
1137
|
-
const detailResponse = result.FeDetResp;
|
|
1138
|
-
const rawDetail = detailResponse?.FECAEDetResponse;
|
|
1139
|
-
if (Array.isArray(rawDetail)) {
|
|
1140
|
-
return rawDetail[0] ?? {};
|
|
1141
|
-
}
|
|
1142
|
-
return rawDetail ?? {};
|
|
1143
|
-
}
|
|
1144
|
-
function classifyWsfeAuthorization(result, voucherNumber) {
|
|
1145
|
-
const operation = "FECAESolicitar";
|
|
1146
|
-
const header = toWsfeRecord(result.FeCabResp) ?? {};
|
|
1147
|
-
const detail = normalizeWsfeDetailResponse(result);
|
|
1148
|
-
const headerResult = normalizeWsfeResult(header.Resultado);
|
|
1149
|
-
const detailResult = normalizeWsfeResult(detail.Resultado);
|
|
1150
|
-
const resultCode = detailResult ?? headerResult;
|
|
1151
|
-
const resultLevel = getWsfeResultLevel(headerResult, detailResult);
|
|
1152
|
-
const cae = normalizeWsfeString(detail.CAE);
|
|
1153
|
-
const caeExpiry = normalizeWsfeString(detail.CAEFchVto);
|
|
1154
|
-
const errors = extractWsfeGlobalIssues(result, operation, "header");
|
|
1155
|
-
const observations = extractWsfeObservations(
|
|
1156
|
-
detail,
|
|
1157
|
-
detailResult === "R" ? "business" : "observation"
|
|
1158
|
-
);
|
|
1159
|
-
const hasInfrastructureError = errors.some(
|
|
1160
|
-
(issue) => issue.category === "infrastructure"
|
|
1161
|
-
);
|
|
1162
|
-
const base = {
|
|
1163
|
-
service: "wsfe",
|
|
1164
|
-
operation,
|
|
1165
|
-
results: createWsfeResults(headerResult, detailResult),
|
|
1166
|
-
errors,
|
|
1167
|
-
observations,
|
|
1168
|
-
raw: result
|
|
1169
|
-
};
|
|
1170
|
-
const context = {
|
|
1171
|
-
base,
|
|
1172
|
-
headerResult,
|
|
1173
|
-
detailResult,
|
|
1174
|
-
resultCode,
|
|
1175
|
-
resultLevel,
|
|
1176
|
-
cae,
|
|
1177
|
-
caeExpiry
|
|
1178
|
-
};
|
|
1179
|
-
if (hasContradictoryWsfeResults(context)) {
|
|
1180
|
-
return createWsfeStructuredIndeterminate(context, "contradictory_response");
|
|
1181
|
-
}
|
|
1182
|
-
if (hasInfrastructureError) {
|
|
1183
|
-
return createWsfeStructuredIndeterminate(context, "incomplete_response");
|
|
1184
|
-
}
|
|
1185
|
-
if (isAuthorizedWsfeContext(context)) {
|
|
1186
|
-
return {
|
|
1187
|
-
...base,
|
|
1188
|
-
kind: "authorized",
|
|
1189
|
-
result: "A",
|
|
1190
|
-
resultLevel: "detail",
|
|
1191
|
-
cae: context.cae,
|
|
1192
|
-
caeExpiry: context.caeExpiry,
|
|
1193
|
-
voucherNumber
|
|
1194
|
-
};
|
|
1195
|
-
}
|
|
1196
|
-
if (isRejectedWsfeDetailContext(context)) {
|
|
1197
|
-
return {
|
|
1198
|
-
...base,
|
|
1199
|
-
kind: "rejected",
|
|
1200
|
-
result: "R",
|
|
1201
|
-
resultLevel: "detail"
|
|
1202
|
-
};
|
|
1203
|
-
}
|
|
1204
|
-
if (isRejectedWsfeHeaderContext(context)) {
|
|
1205
|
-
return {
|
|
1206
|
-
...base,
|
|
1207
|
-
kind: "rejected",
|
|
1208
|
-
result: "R",
|
|
1209
|
-
resultLevel: "header"
|
|
1210
|
-
};
|
|
1211
|
-
}
|
|
1212
|
-
return createWsfeStructuredIndeterminate(
|
|
1213
|
-
context,
|
|
1214
|
-
hasWsfeCaeContradiction(context) ? "contradictory_response" : "incomplete_response"
|
|
1215
|
-
);
|
|
1216
|
-
}
|
|
1217
|
-
function getWsfeResultLevel(headerResult, detailResult) {
|
|
1218
|
-
if (detailResult) {
|
|
1219
|
-
return "detail";
|
|
1220
|
-
}
|
|
1221
|
-
return headerResult ? "header" : void 0;
|
|
1222
|
-
}
|
|
1223
|
-
function hasContradictoryWsfeResults(context) {
|
|
1224
|
-
return Boolean(
|
|
1225
|
-
context.headerResult && context.detailResult && context.headerResult !== context.detailResult
|
|
1226
|
-
);
|
|
1227
|
-
}
|
|
1228
|
-
function isAuthorizedWsfeContext(context) {
|
|
1229
|
-
return Boolean(
|
|
1230
|
-
context.detailResult === "A" && context.headerResult !== "R" && context.base.errors.length === 0 && context.cae && context.caeExpiry
|
|
1231
|
-
);
|
|
1232
|
-
}
|
|
1233
|
-
function isRejectedWsfeDetailContext(context) {
|
|
1234
|
-
return context.detailResult === "R" && context.headerResult !== "A" && !context.cae;
|
|
1235
|
-
}
|
|
1236
|
-
function isRejectedWsfeHeaderContext(context) {
|
|
1237
|
-
return context.headerResult === "R" && context.detailResult === void 0 && !context.cae && context.base.errors.length > 0 && context.base.errors.every((issue) => issue.category === "business");
|
|
1238
|
-
}
|
|
1239
|
-
function hasWsfeCaeContradiction(context) {
|
|
1240
|
-
return (context.resultCode === "A" || context.resultCode === "R") && Boolean(context.cae);
|
|
1241
|
-
}
|
|
1242
|
-
function createWsfeStructuredIndeterminate(context, reason) {
|
|
1243
|
-
const outcome = {
|
|
1244
|
-
...context.base,
|
|
1245
|
-
kind: "indeterminate",
|
|
1246
|
-
reason
|
|
1247
|
-
};
|
|
1248
|
-
assignWsfeValue(outcome, "result", context.resultCode);
|
|
1249
|
-
assignWsfeValue(outcome, "resultLevel", context.resultLevel);
|
|
1250
|
-
assignWsfeValue(outcome, "cae", context.cae);
|
|
1251
|
-
assignWsfeValue(outcome, "caeExpiry", context.caeExpiry);
|
|
1252
|
-
return outcome;
|
|
1253
|
-
}
|
|
1254
|
-
function createWsfeResults(headerResult, detailResult) {
|
|
1255
|
-
const results = {};
|
|
1256
|
-
assignWsfeValue(results, "header", headerResult);
|
|
1257
|
-
assignWsfeValue(results, "detail", detailResult);
|
|
1258
|
-
return results;
|
|
1259
|
-
}
|
|
1260
|
-
function createWsfeIndeterminateOutcome(error) {
|
|
1261
|
-
return {
|
|
1262
|
-
kind: "indeterminate",
|
|
1263
|
-
service: "wsfe",
|
|
1264
|
-
operation: "FECAESolicitar",
|
|
1265
|
-
results: {},
|
|
1266
|
-
reason: getArcaIndeterminateReason(error),
|
|
1267
|
-
errors: [],
|
|
1268
|
-
observations: []
|
|
1269
|
-
};
|
|
1270
|
-
}
|
|
1271
|
-
function getArcaIndeterminateReason(error) {
|
|
1272
|
-
if (error instanceof ArcaTransportError) {
|
|
1273
|
-
return "transport_error";
|
|
1274
|
-
}
|
|
1275
|
-
if (error instanceof ArcaSoapFaultError) {
|
|
1276
|
-
return "soap_fault";
|
|
1277
|
-
}
|
|
1278
|
-
if (error instanceof ArcaInvalidSoapResponseError) {
|
|
1279
|
-
return "invalid_response";
|
|
1280
|
-
}
|
|
1281
|
-
return "unexpected_error";
|
|
1282
|
-
}
|
|
1283
|
-
function createWsfeOutcomeError(outcome) {
|
|
1284
|
-
const issues = [...outcome.errors, ...outcome.observations];
|
|
1285
|
-
const firstIssue = issues[0];
|
|
1286
|
-
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";
|
|
1287
|
-
return new ArcaServiceError(message, {
|
|
1288
|
-
service: "wsfe",
|
|
1289
|
-
operation: outcome.operation,
|
|
1290
|
-
...firstIssue?.code === void 0 ? {} : { serviceCode: firstIssue.code },
|
|
1291
|
-
...outcome.result === void 0 ? {} : { result: outcome.result },
|
|
1292
|
-
...outcome.resultLevel === void 0 ? {} : { resultLevel: outcome.resultLevel },
|
|
1293
|
-
results: outcome.results,
|
|
1294
|
-
...outcome.kind === "indeterminate" && outcome.cae ? { cae: outcome.cae } : {},
|
|
1295
|
-
issues,
|
|
1296
|
-
detail: outcome.raw
|
|
1297
|
-
});
|
|
1298
|
-
}
|
|
1299
|
-
function createWsfeServiceError(operation, result, issues) {
|
|
1300
|
-
const firstIssue = issues[0];
|
|
1301
|
-
return new ArcaServiceError(
|
|
1302
|
-
firstIssue ? formatWsfeIssue(firstIssue) : "WSFE returned a service error",
|
|
1303
|
-
{
|
|
1304
|
-
service: "wsfe",
|
|
1305
|
-
operation,
|
|
1306
|
-
...firstIssue?.code === void 0 ? {} : { serviceCode: firstIssue.code },
|
|
1307
|
-
issues,
|
|
1308
|
-
detail: result
|
|
1309
|
-
}
|
|
1310
|
-
);
|
|
1311
|
-
}
|
|
1312
|
-
function extractWsfeGlobalIssues(result, operation, resultLevel) {
|
|
1313
|
-
const errorsContainer = toWsfeRecord(result.Errors);
|
|
1314
|
-
return normalizeWsfeIssueEntries(errorsContainer?.Err).map((entry) => ({
|
|
1315
|
-
service: "wsfe",
|
|
1316
|
-
operation,
|
|
1317
|
-
source: "error",
|
|
1318
|
-
category: operation === "FECAESolicitar" && WSFE_AUTHORIZATION_INFRASTRUCTURE_CODES.has(entry.code ?? "") ? "infrastructure" : operation === "FECAESolicitar" ? "business" : "unknown",
|
|
1319
|
-
...entry.code === void 0 ? {} : { code: entry.code },
|
|
1320
|
-
message: entry.message,
|
|
1321
|
-
...resultLevel === void 0 ? {} : { resultLevel }
|
|
1322
|
-
}));
|
|
1323
|
-
}
|
|
1324
|
-
function extractWsfeObservations(detail, category) {
|
|
1325
|
-
const observationsContainer = toWsfeRecord(detail.Observaciones);
|
|
1326
|
-
return normalizeWsfeIssueEntries(observationsContainer?.Obs).map((entry) => ({
|
|
1327
|
-
service: "wsfe",
|
|
1328
|
-
operation: "FECAESolicitar",
|
|
1329
|
-
source: "observation",
|
|
1330
|
-
category,
|
|
1331
|
-
...entry.code === void 0 ? {} : { code: entry.code },
|
|
1332
|
-
message: entry.message,
|
|
1333
|
-
resultLevel: "detail"
|
|
1334
|
-
}));
|
|
1335
|
-
}
|
|
1336
|
-
function normalizeWsfeIssueEntries(rawErrors) {
|
|
1337
|
-
const entries = Array.isArray(rawErrors) ? rawErrors : rawErrors ? [rawErrors] : [];
|
|
1338
|
-
return entries.map((entry) => entry).map((entry) => {
|
|
1339
|
-
const code = entry.Code ?? entry.code;
|
|
1340
|
-
const message = entry.Msg ?? entry.msg ?? "Unknown WSFE error";
|
|
1341
|
-
return {
|
|
1342
|
-
...code === void 0 ? {} : { code: String(code) },
|
|
1343
|
-
message: String(message)
|
|
1344
|
-
};
|
|
1345
|
-
});
|
|
1346
|
-
}
|
|
1347
|
-
function formatWsfeIssue(issue) {
|
|
1348
|
-
return issue.code ? `(${issue.code}) ${issue.message}` : issue.message;
|
|
1349
|
-
}
|
|
1350
|
-
function normalizeWsfeResult(value) {
|
|
1351
|
-
if (typeof value !== "string") {
|
|
1352
|
-
return void 0;
|
|
1353
|
-
}
|
|
1354
|
-
const normalized = value.trim().toUpperCase();
|
|
1355
|
-
return normalized || void 0;
|
|
1356
|
-
}
|
|
1357
|
-
function normalizeWsfeString(value) {
|
|
1358
|
-
if (value === void 0 || value === null) {
|
|
1359
|
-
return void 0;
|
|
1360
|
-
}
|
|
1361
|
-
const normalized = String(value).trim();
|
|
1362
|
-
return normalized || void 0;
|
|
1363
|
-
}
|
|
1364
|
-
function normalizeWsfeNumber(value) {
|
|
1365
|
-
if (value === void 0 || value === null || value === "") {
|
|
1366
|
-
return void 0;
|
|
1367
|
-
}
|
|
1368
|
-
const normalized = Number(value);
|
|
1369
|
-
return Number.isFinite(normalized) ? normalized : void 0;
|
|
1370
|
-
}
|
|
1371
|
-
function assignWsfeValue(target, key, value) {
|
|
1372
|
-
if (value !== void 0) {
|
|
1373
|
-
target[key] = value;
|
|
1374
|
-
}
|
|
1375
|
-
}
|
|
1376
|
-
function toWsfeRecord(value) {
|
|
1377
|
-
return value && typeof value === "object" && !Array.isArray(value) ? value : void 0;
|
|
1378
|
-
}
|
|
1379
|
-
var WSFE_AUTHORIZATION_INFRASTRUCTURE_CODES = /* @__PURE__ */ new Set([
|
|
1380
|
-
"500",
|
|
1381
|
-
"501",
|
|
1382
|
-
"502",
|
|
1383
|
-
"600",
|
|
1384
|
-
"601"
|
|
1385
|
-
]);
|
|
1386
|
-
function getWsfeResultEntries(result, key) {
|
|
1387
|
-
const rawEntries = result.ResultGet?.[key];
|
|
1388
|
-
if (!rawEntries) {
|
|
1389
|
-
return [];
|
|
1390
|
-
}
|
|
1391
|
-
return (Array.isArray(rawEntries) ? rawEntries : [rawEntries]).map(
|
|
1392
|
-
(entry) => entry
|
|
1393
|
-
);
|
|
1394
|
-
}
|
|
1395
|
-
|
|
1396
|
-
// src/services/wsmtxca.ts
|
|
1397
|
-
function createWsmtxcaService(options) {
|
|
1398
|
-
async function executeWsmtxcaAuthenticatedOperation(operation, input, body = {}, retries) {
|
|
1399
|
-
const auth = await options.auth.login("wsmtxca", {
|
|
1400
|
-
representedTaxId: input.representedTaxId,
|
|
1401
|
-
forceRefresh: input.forceRefresh
|
|
1402
|
-
});
|
|
1403
|
-
const response = await options.soap.execute({
|
|
1404
|
-
service: "wsmtxca",
|
|
1405
|
-
operation,
|
|
1406
|
-
...retries === void 0 ? {} : { retries },
|
|
1407
|
-
bodyElementName: `${operation}Request`,
|
|
1408
|
-
bodyElementNamespaceMode: "prefix",
|
|
1409
|
-
body: {
|
|
1410
|
-
...body,
|
|
1411
|
-
authRequest: createWsmtxcaAuth(
|
|
1412
|
-
input.representedTaxId ?? options.config.taxId,
|
|
1413
|
-
auth.token,
|
|
1414
|
-
auth.sign
|
|
1415
|
-
)
|
|
1416
|
-
}
|
|
1417
|
-
});
|
|
1418
|
-
return unwrapWsmtxcaOperationResponse(response.result, operation);
|
|
1419
|
-
}
|
|
1420
|
-
async function executeWsmtxcaAuthorization({
|
|
1421
|
-
representedTaxId,
|
|
1422
|
-
data,
|
|
1423
|
-
forceRefresh
|
|
1424
|
-
}) {
|
|
1425
|
-
if (Object.hasOwn(data, "authRequest")) {
|
|
1426
|
-
throw new ArcaInputError(
|
|
1427
|
-
'WSMTXCA authorization data cannot include the reserved top-level field "authRequest".'
|
|
1428
|
-
);
|
|
1429
|
-
}
|
|
1430
|
-
try {
|
|
1431
|
-
const raw = await executeWsmtxcaAuthenticatedOperation(
|
|
1432
|
-
"autorizarComprobante",
|
|
1433
|
-
{ representedTaxId, forceRefresh },
|
|
1434
|
-
data,
|
|
1435
|
-
0
|
|
1436
|
-
);
|
|
1437
|
-
return { outcome: classifyWsmtxcaAuthorization(raw) };
|
|
1438
|
-
} catch (error) {
|
|
1439
|
-
return {
|
|
1440
|
-
outcome: createWsmtxcaIndeterminateOutcome(error),
|
|
1441
|
-
error
|
|
1442
|
-
};
|
|
1443
|
-
}
|
|
1444
|
-
}
|
|
1445
|
-
async function authorizeVoucherOutcome(input) {
|
|
1446
|
-
return (await executeWsmtxcaAuthorization(input)).outcome;
|
|
1447
|
-
}
|
|
1448
|
-
async function authorizeVoucher(input) {
|
|
1449
|
-
const execution = await executeWsmtxcaAuthorization(input);
|
|
1450
|
-
if (execution.error) {
|
|
1451
|
-
throw execution.error;
|
|
1452
|
-
}
|
|
1453
|
-
if (execution.outcome.kind !== "authorized") {
|
|
1454
|
-
throw createWsmtxcaOutcomeError(execution.outcome);
|
|
1455
|
-
}
|
|
1456
|
-
const { outcome } = execution;
|
|
1457
|
-
return {
|
|
1458
|
-
cae: outcome.cae,
|
|
1459
|
-
...outcome.caeExpiry === void 0 ? {} : { caeExpiry: outcome.caeExpiry },
|
|
1460
|
-
voucherNumber: outcome.voucherNumber,
|
|
1461
|
-
messages: formatWsmtxcaIssues([
|
|
1462
|
-
...outcome.errors,
|
|
1463
|
-
...outcome.observations
|
|
1464
|
-
]),
|
|
1465
|
-
raw: outcome.raw ?? {}
|
|
1466
|
-
};
|
|
1467
|
-
}
|
|
1468
|
-
async function getLastAuthorizedVoucher({
|
|
1469
|
-
representedTaxId,
|
|
1470
|
-
voucherType,
|
|
1471
|
-
salesPoint,
|
|
1472
|
-
forceRefresh
|
|
1473
|
-
}) {
|
|
1474
|
-
const operation = "consultarUltimoComprobanteAutorizado";
|
|
1475
|
-
const raw = await executeWsmtxcaAuthenticatedOperation(
|
|
1476
|
-
operation,
|
|
1477
|
-
{ representedTaxId, forceRefresh },
|
|
1478
|
-
{
|
|
1479
|
-
consultaUltimoComprobanteAutorizadoRequest: {
|
|
1480
|
-
codigoTipoComprobante: voucherType,
|
|
1481
|
-
numeroPuntoVenta: salesPoint
|
|
1482
|
-
}
|
|
1483
|
-
}
|
|
1484
|
-
);
|
|
1485
|
-
const errors = extractWsmtxcaIssues(raw, operation, "error");
|
|
1486
|
-
if (errors.length > 0 && errors.every((issue) => issue.code === "1502")) {
|
|
1487
|
-
return { voucherNumber: 0, raw };
|
|
1488
|
-
}
|
|
1489
|
-
if (errors.length > 0) {
|
|
1490
|
-
throw createWsmtxcaServiceError(operation, raw, errors);
|
|
1491
|
-
}
|
|
1492
|
-
return {
|
|
1493
|
-
voucherNumber: parseWsmtxcaVoucherNumber(
|
|
1494
|
-
raw.numeroComprobante ?? raw.cbteNro ?? raw.nroComprobante,
|
|
1495
|
-
"WSMTXCA did not return the last authorized voucher number",
|
|
1496
|
-
raw,
|
|
1497
|
-
true
|
|
1498
|
-
),
|
|
1499
|
-
raw
|
|
1500
|
-
};
|
|
1501
|
-
}
|
|
1502
|
-
async function getSalesPoints({
|
|
1503
|
-
representedTaxId,
|
|
1504
|
-
forceRefresh
|
|
1505
|
-
}) {
|
|
1506
|
-
const raw = await executeWsmtxcaAuthenticatedOperation(
|
|
1507
|
-
"consultarPuntosVenta",
|
|
1508
|
-
{ representedTaxId, forceRefresh }
|
|
1509
|
-
);
|
|
1510
|
-
const rawSalesPoints = toRecord(raw.arrayPuntosVenta)?.puntoVenta;
|
|
1511
|
-
const entries = Array.isArray(rawSalesPoints) ? rawSalesPoints : rawSalesPoints ? [rawSalesPoints] : [];
|
|
1512
|
-
const salesPoints = entries.flatMap((entry) => {
|
|
1513
|
-
const record = toRecord(entry);
|
|
1514
|
-
const number = parseOptionalPositiveInteger(record?.numeroPuntoVenta);
|
|
1515
|
-
if (number === void 0) {
|
|
1516
|
-
return [];
|
|
1517
|
-
}
|
|
1518
|
-
const deletedAt = normalizeWsmtxcaResponseDate(record?.fechaBaja);
|
|
1519
|
-
return [
|
|
1520
|
-
{
|
|
1521
|
-
number,
|
|
1522
|
-
blocked: String(record?.bloqueado ?? "N").toUpperCase() === "S",
|
|
1523
|
-
...deletedAt === void 0 ? {} : { deletedAt }
|
|
1524
|
-
}
|
|
1525
|
-
];
|
|
1526
|
-
});
|
|
1527
|
-
return { salesPoints, raw };
|
|
1528
|
-
}
|
|
1529
|
-
async function lookupVoucher({
|
|
1530
|
-
representedTaxId,
|
|
1531
|
-
voucherType,
|
|
1532
|
-
salesPoint,
|
|
1533
|
-
voucherNumber,
|
|
1534
|
-
forceRefresh
|
|
1535
|
-
}) {
|
|
1536
|
-
const operation = "consultarComprobante";
|
|
1537
|
-
const raw = await executeWsmtxcaAuthenticatedOperation(
|
|
1538
|
-
operation,
|
|
1539
|
-
{ representedTaxId, forceRefresh },
|
|
1540
|
-
{
|
|
1541
|
-
consultaComprobanteRequest: {
|
|
1542
|
-
codigoTipoComprobante: voucherType,
|
|
1543
|
-
numeroPuntoVenta: salesPoint,
|
|
1544
|
-
numeroComprobante: voucherNumber
|
|
1545
|
-
}
|
|
1546
|
-
}
|
|
1547
|
-
);
|
|
1548
|
-
const errors = extractWsmtxcaIssues(raw, operation, "error");
|
|
1549
|
-
const observations = extractWsmtxcaIssues(raw, operation, "observation");
|
|
1550
|
-
if (errors.length > 0 && errors.every((issue) => issue.code === "1503")) {
|
|
1551
|
-
return {
|
|
1552
|
-
kind: "not_found",
|
|
1553
|
-
service: "wsmtxca",
|
|
1554
|
-
operation,
|
|
1555
|
-
errors,
|
|
1556
|
-
observations,
|
|
1557
|
-
raw
|
|
1558
|
-
};
|
|
1559
|
-
}
|
|
1560
|
-
if (errors.length > 0) {
|
|
1561
|
-
throw createWsmtxcaServiceError(operation, raw, errors);
|
|
1562
|
-
}
|
|
1563
|
-
const voucher = extractWsmtxcaVoucherPayload(raw);
|
|
1564
|
-
if (voucher === raw && !toRecord(raw.comprobante)) {
|
|
1565
|
-
throw new ArcaServiceError(
|
|
1566
|
-
"WSMTXCA did not return the voucher issue date",
|
|
1567
|
-
{
|
|
1568
|
-
service: "wsmtxca",
|
|
1569
|
-
operation,
|
|
1570
|
-
issues: observations,
|
|
1571
|
-
detail: raw
|
|
1572
|
-
}
|
|
1573
|
-
);
|
|
1574
|
-
}
|
|
1575
|
-
return {
|
|
1576
|
-
kind: "found",
|
|
1577
|
-
service: "wsmtxca",
|
|
1578
|
-
operation,
|
|
1579
|
-
voucher: mapWsmtxcaVoucherInfo(voucher),
|
|
1580
|
-
observations,
|
|
1581
|
-
raw
|
|
1582
|
-
};
|
|
1583
|
-
}
|
|
1584
|
-
async function getVoucher(input) {
|
|
1585
|
-
const lookup = await lookupVoucher(input);
|
|
1586
|
-
if (lookup.kind === "not_found") {
|
|
1587
|
-
throw createWsmtxcaServiceError(
|
|
1588
|
-
lookup.operation,
|
|
1589
|
-
lookup.raw,
|
|
1590
|
-
lookup.errors
|
|
1591
|
-
);
|
|
1592
|
-
}
|
|
1593
|
-
const invoiceDate = lookup.voucher.invoiceDate;
|
|
1594
|
-
if (!invoiceDate) {
|
|
1595
|
-
throw new ArcaServiceError(
|
|
1596
|
-
formatWsmtxcaIssues(lookup.observations)[0] ?? "WSMTXCA did not return the voucher issue date",
|
|
1597
|
-
{
|
|
1598
|
-
service: "wsmtxca",
|
|
1599
|
-
operation: lookup.operation,
|
|
1600
|
-
issues: lookup.observations,
|
|
1601
|
-
detail: lookup.raw
|
|
1602
|
-
}
|
|
1603
|
-
);
|
|
1604
|
-
}
|
|
1605
|
-
return {
|
|
1606
|
-
invoiceDate,
|
|
1607
|
-
voucher: lookup.voucher.raw,
|
|
1608
|
-
messages: formatWsmtxcaIssues(lookup.observations),
|
|
1609
|
-
raw: lookup.raw
|
|
1610
|
-
};
|
|
1611
|
-
}
|
|
1612
|
-
return {
|
|
1613
|
-
authorizeVoucherOutcome,
|
|
1614
|
-
authorizeVoucher,
|
|
1615
|
-
getLastAuthorizedVoucher,
|
|
1616
|
-
getSalesPoints,
|
|
1617
|
-
lookupVoucher,
|
|
1618
|
-
getVoucher
|
|
1619
|
-
};
|
|
1620
|
-
}
|
|
1621
|
-
function createWsmtxcaAuth(representedTaxId, token, sign) {
|
|
1622
|
-
return {
|
|
1623
|
-
token,
|
|
1624
|
-
sign,
|
|
1625
|
-
cuitRepresentada: Number.parseInt(String(representedTaxId), 10)
|
|
1626
|
-
};
|
|
1627
|
-
}
|
|
1628
|
-
function toRecord(value) {
|
|
1629
|
-
return value && typeof value === "object" && !Array.isArray(value) ? value : void 0;
|
|
1630
|
-
}
|
|
1631
|
-
function unwrapWsmtxcaOperationResponse(response, operation) {
|
|
1632
|
-
const responseRecord = toRecord(response) ?? {};
|
|
1633
|
-
if (operation === "autorizarComprobante") {
|
|
1634
|
-
return toRecord(responseRecord.autorizarComprobanteResponse) ?? toRecord(responseRecord.autorizarComprobanteResult) ?? toRecord(responseRecord.comprobanteCAEResponse) ?? toRecord(responseRecord.comprobanteCAEReponse) ?? responseRecord;
|
|
1635
|
-
}
|
|
1636
|
-
if (operation === "consultarComprobante") {
|
|
1637
|
-
return toRecord(responseRecord.consultarComprobanteResponse) ?? toRecord(responseRecord.consultaComprobanteResponse) ?? toRecord(responseRecord.consultarComprobanteResult) ?? responseRecord;
|
|
1638
|
-
}
|
|
1639
|
-
if (operation === "consultarPuntosVenta") {
|
|
1640
|
-
return toRecord(responseRecord.consultarPuntosVentaResponse) ?? toRecord(responseRecord.consultarPuntosVentaResult) ?? responseRecord;
|
|
1641
|
-
}
|
|
1642
|
-
return toRecord(responseRecord.consultarUltimoComprobanteAutorizadoResponse) ?? toRecord(responseRecord.consultaUltimoComprobanteAutorizadoResponse) ?? toRecord(responseRecord.consultarUltimoComprobanteAutorizadoResult) ?? responseRecord;
|
|
1643
|
-
}
|
|
1644
|
-
function extractWsmtxcaAuthorizationPayload(raw) {
|
|
1645
|
-
return toRecord(raw.comprobanteResponse) ?? toRecord(raw.comprobanteCAEResponse) ?? toRecord(raw.comprobanteCAEReponse) ?? raw;
|
|
1646
|
-
}
|
|
1647
|
-
function extractWsmtxcaVoucherPayload(raw) {
|
|
1648
|
-
return toRecord(raw.comprobanteResponse) ?? toRecord(raw.comprobante) ?? toRecord(raw.cmp) ?? raw;
|
|
1649
|
-
}
|
|
1650
|
-
function classifyWsmtxcaAuthorization(raw) {
|
|
1651
|
-
const operation = "autorizarComprobante";
|
|
1652
|
-
const payload = extractWsmtxcaAuthorizationPayload(raw);
|
|
1653
|
-
const result = normalizeWsmtxcaResult(raw.resultado ?? payload.resultado);
|
|
1654
|
-
const cae = normalizeWsmtxcaString(
|
|
1655
|
-
payload.CAE ?? payload.codigoAutorizacion ?? raw.codigoAutorizacion
|
|
1656
|
-
);
|
|
1657
|
-
const caeExpiry = normalizeWsmtxcaResponseDate(
|
|
1658
|
-
payload.fechaVencimientoCAE ?? payload.fechaVencimiento ?? raw.fechaVencimiento
|
|
1659
|
-
);
|
|
1660
|
-
const voucherNumber = parseOptionalPositiveInteger(
|
|
1661
|
-
payload.numeroComprobante ?? raw.numeroComprobante
|
|
1662
|
-
);
|
|
1663
|
-
const errors = extractWsmtxcaIssues(raw, operation, "error");
|
|
1664
|
-
const observations = extractWsmtxcaIssues(raw, operation, "observation");
|
|
1665
|
-
const base = {
|
|
1666
|
-
service: "wsmtxca",
|
|
1667
|
-
operation,
|
|
1668
|
-
results: createWsmtxcaResults(result),
|
|
1669
|
-
errors,
|
|
1670
|
-
observations,
|
|
1671
|
-
raw
|
|
1672
|
-
};
|
|
1673
|
-
if ((result === "A" || result === "O") && cae && voucherNumber !== void 0 && errors.length === 0) {
|
|
1674
|
-
return {
|
|
1675
|
-
...base,
|
|
1676
|
-
kind: "authorized",
|
|
1677
|
-
result,
|
|
1678
|
-
resultLevel: "operation",
|
|
1679
|
-
cae,
|
|
1680
|
-
...caeExpiry === void 0 ? {} : { caeExpiry },
|
|
1681
|
-
voucherNumber
|
|
1682
|
-
};
|
|
1683
|
-
}
|
|
1684
|
-
if (result === "R" && !cae && errors.length > 0) {
|
|
1685
|
-
return {
|
|
1686
|
-
...base,
|
|
1687
|
-
kind: "rejected",
|
|
1688
|
-
result: "R",
|
|
1689
|
-
resultLevel: "operation"
|
|
1690
|
-
};
|
|
1691
|
-
}
|
|
1692
|
-
const outcome = {
|
|
1693
|
-
...base,
|
|
1694
|
-
kind: "indeterminate",
|
|
1695
|
-
reason: result === "R" && Boolean(cae) || (result === "A" || result === "O") && Boolean(errors.length) ? "contradictory_response" : "incomplete_response",
|
|
1696
|
-
...result === void 0 ? {} : { result },
|
|
1697
|
-
...result === void 0 ? {} : { resultLevel: "operation" }
|
|
1698
|
-
};
|
|
1699
|
-
assignWsmtxcaValue(outcome, "cae", cae);
|
|
1700
|
-
assignWsmtxcaValue(outcome, "caeExpiry", caeExpiry);
|
|
1701
|
-
assignWsmtxcaValue(outcome, "voucherNumber", voucherNumber);
|
|
1702
|
-
return outcome;
|
|
1703
|
-
}
|
|
1704
|
-
function createWsmtxcaIndeterminateOutcome(error) {
|
|
1705
|
-
return {
|
|
1706
|
-
kind: "indeterminate",
|
|
1707
|
-
service: "wsmtxca",
|
|
1708
|
-
operation: "autorizarComprobante",
|
|
1709
|
-
results: {},
|
|
1710
|
-
reason: getWsmtxcaIndeterminateReason(error),
|
|
1711
|
-
errors: [],
|
|
1712
|
-
observations: []
|
|
1713
|
-
};
|
|
1714
|
-
}
|
|
1715
|
-
function getWsmtxcaIndeterminateReason(error) {
|
|
1716
|
-
if (error instanceof ArcaTransportError) {
|
|
1717
|
-
return "transport_error";
|
|
1718
|
-
}
|
|
1719
|
-
if (error instanceof ArcaSoapFaultError) {
|
|
1720
|
-
return "soap_fault";
|
|
1721
|
-
}
|
|
1722
|
-
if (error instanceof ArcaInvalidSoapResponseError) {
|
|
1723
|
-
return "invalid_response";
|
|
1724
|
-
}
|
|
1725
|
-
return "unexpected_error";
|
|
1726
|
-
}
|
|
1727
|
-
function createWsmtxcaOutcomeError(outcome) {
|
|
1728
|
-
const issues = [...outcome.errors, ...outcome.observations];
|
|
1729
|
-
const messages = formatWsmtxcaIssues(issues);
|
|
1730
|
-
const firstIssue = issues[0];
|
|
1731
|
-
return new ArcaServiceError(
|
|
1732
|
-
messages.join(" | ") || (outcome.kind === "rejected" ? "WSMTXCA rejected the voucher authorization" : "WSMTXCA did not return conclusive voucher authorization data"),
|
|
1733
|
-
{
|
|
1734
|
-
service: "wsmtxca",
|
|
1735
|
-
operation: outcome.operation,
|
|
1736
|
-
...firstIssue?.code === void 0 ? {} : { serviceCode: firstIssue.code },
|
|
1737
|
-
...outcome.result === void 0 ? {} : { result: outcome.result },
|
|
1738
|
-
...outcome.resultLevel === void 0 ? {} : { resultLevel: outcome.resultLevel },
|
|
1739
|
-
results: outcome.results,
|
|
1740
|
-
...outcome.kind === "indeterminate" && outcome.cae ? { cae: outcome.cae } : {},
|
|
1741
|
-
issues,
|
|
1742
|
-
detail: outcome.raw
|
|
1743
|
-
}
|
|
1744
|
-
);
|
|
1745
|
-
}
|
|
1746
|
-
function createWsmtxcaResults(operationResult) {
|
|
1747
|
-
const results = {};
|
|
1748
|
-
assignWsmtxcaValue(results, "operation", operationResult);
|
|
1749
|
-
return results;
|
|
1750
|
-
}
|
|
1751
|
-
function createWsmtxcaServiceError(operation, raw, issues) {
|
|
1752
|
-
const firstIssue = issues[0];
|
|
1753
|
-
return new ArcaServiceError(
|
|
1754
|
-
formatWsmtxcaIssues(issues).join(" | ") || "WSMTXCA returned a service error",
|
|
1755
|
-
{
|
|
1756
|
-
service: "wsmtxca",
|
|
1757
|
-
operation,
|
|
1758
|
-
...firstIssue?.code === void 0 ? {} : { serviceCode: firstIssue.code },
|
|
1759
|
-
issues,
|
|
1760
|
-
detail: raw
|
|
1761
|
-
}
|
|
1762
|
-
);
|
|
1763
|
-
}
|
|
1764
|
-
function extractWsmtxcaIssues(raw, operation, source) {
|
|
1765
|
-
const container = toRecord(
|
|
1766
|
-
source === "error" ? raw.arrayErrores : raw.arrayObservaciones
|
|
1767
|
-
);
|
|
1768
|
-
return normalizeWsmtxcaIssueEntries(container?.codigoDescripcion).map(
|
|
1769
|
-
(entry) => ({
|
|
1770
|
-
service: "wsmtxca",
|
|
1771
|
-
operation,
|
|
1772
|
-
source,
|
|
1773
|
-
category: source === "observation" ? "observation" : operation === "autorizarComprobante" ? "business" : "unknown",
|
|
1774
|
-
...entry.code === void 0 ? {} : { code: entry.code },
|
|
1775
|
-
message: entry.message,
|
|
1776
|
-
...operation === "autorizarComprobante" ? { resultLevel: "operation" } : {}
|
|
1777
|
-
})
|
|
1778
|
-
);
|
|
1779
|
-
}
|
|
1780
|
-
function normalizeWsmtxcaIssueEntries(value) {
|
|
1781
|
-
const entries = Array.isArray(value) ? value : value ? [value] : [];
|
|
1782
|
-
return entries.map((entry) => {
|
|
1783
|
-
const record = toRecord(entry) ?? {};
|
|
1784
|
-
const code = record.codigo;
|
|
1785
|
-
const description = record.descripcion;
|
|
1786
|
-
return {
|
|
1787
|
-
...code === void 0 || code === null ? {} : { code: String(code) },
|
|
1788
|
-
message: description === void 0 || description === null ? "Unknown WSMTXCA issue" : String(description)
|
|
1789
|
-
};
|
|
1790
|
-
});
|
|
1791
|
-
}
|
|
1792
|
-
function formatWsmtxcaIssues(issues) {
|
|
1793
|
-
return issues.map((issue) => {
|
|
1794
|
-
const prefix = issue.source === "error" ? "Error" : "Obs";
|
|
1795
|
-
return `${prefix}${issue.code ? ` ${issue.code}` : ""}: ${issue.message}`;
|
|
1796
|
-
});
|
|
1797
|
-
}
|
|
1798
|
-
function mapWsmtxcaVoucherInfo(raw) {
|
|
1799
|
-
const voucher = { raw };
|
|
1800
|
-
const invoiceDate = normalizeWsmtxcaResponseDate(
|
|
1801
|
-
raw.fechaEmision ?? raw.fecha ?? raw.CbteFch
|
|
1802
|
-
);
|
|
1803
|
-
const cae = normalizeWsmtxcaString(raw.codigoAutorizacion ?? raw.CAE);
|
|
1804
|
-
const caeExpiry = normalizeWsmtxcaResponseDate(
|
|
1805
|
-
raw.fechaVencimiento ?? raw.fechaVencimientoCAE
|
|
1806
|
-
);
|
|
1807
|
-
const vatAmount = sumWsmtxcaVatAmounts(raw.arraySubtotalesIVA);
|
|
1808
|
-
assignWsmtxcaValue(
|
|
1809
|
-
voucher,
|
|
1810
|
-
"voucherNumber",
|
|
1811
|
-
parseOptionalPositiveInteger(raw.numeroComprobante)
|
|
1812
|
-
);
|
|
1813
|
-
assignWsmtxcaValue(voucher, "invoiceDate", invoiceDate);
|
|
1814
|
-
assignWsmtxcaValue(
|
|
1815
|
-
voucher,
|
|
1816
|
-
"salesPoint",
|
|
1817
|
-
parseOptionalPositiveInteger(raw.numeroPuntoVenta)
|
|
1818
|
-
);
|
|
1819
|
-
assignWsmtxcaValue(
|
|
1820
|
-
voucher,
|
|
1821
|
-
"voucherType",
|
|
1822
|
-
parseOptionalPositiveInteger(raw.codigoTipoComprobante)
|
|
1823
|
-
);
|
|
1824
|
-
assignWsmtxcaValue(
|
|
1825
|
-
voucher,
|
|
1826
|
-
"concept",
|
|
1827
|
-
parseOptionalNumber(raw.codigoConcepto)
|
|
1828
|
-
);
|
|
1829
|
-
assignWsmtxcaValue(
|
|
1830
|
-
voucher,
|
|
1831
|
-
"documentType",
|
|
1832
|
-
parseOptionalNumber(raw.codigoTipoDocumento)
|
|
1833
|
-
);
|
|
1834
|
-
assignWsmtxcaValue(
|
|
1835
|
-
voucher,
|
|
1836
|
-
"documentNumber",
|
|
1837
|
-
normalizeWsmtxcaString(raw.numeroDocumento)
|
|
1838
|
-
);
|
|
1839
|
-
assignWsmtxcaValue(
|
|
1840
|
-
voucher,
|
|
1841
|
-
"receiverVatConditionId",
|
|
1842
|
-
parseOptionalNumber(raw.condicionIVAReceptor)
|
|
1843
|
-
);
|
|
1844
|
-
assignWsmtxcaValue(
|
|
1845
|
-
voucher,
|
|
1846
|
-
"totalAmount",
|
|
1847
|
-
parseOptionalNumber(raw.importeTotal)
|
|
1848
|
-
);
|
|
1849
|
-
assignWsmtxcaValue(
|
|
1850
|
-
voucher,
|
|
1851
|
-
"subtotalAmount",
|
|
1852
|
-
parseOptionalNumber(raw.importeSubtotal)
|
|
1853
|
-
);
|
|
1854
|
-
assignWsmtxcaValue(
|
|
1855
|
-
voucher,
|
|
1856
|
-
"taxableAmount",
|
|
1857
|
-
parseOptionalNumber(raw.importeGravado)
|
|
1858
|
-
);
|
|
1859
|
-
assignWsmtxcaValue(
|
|
1860
|
-
voucher,
|
|
1861
|
-
"nonTaxableAmount",
|
|
1862
|
-
parseOptionalNumber(raw.importeNoGravado)
|
|
1863
|
-
);
|
|
1864
|
-
assignWsmtxcaValue(
|
|
1865
|
-
voucher,
|
|
1866
|
-
"exemptAmount",
|
|
1867
|
-
parseOptionalNumber(raw.importeExento)
|
|
1868
|
-
);
|
|
1869
|
-
assignWsmtxcaValue(
|
|
1870
|
-
voucher,
|
|
1871
|
-
"taxAmount",
|
|
1872
|
-
parseOptionalNumber(raw.importeOtrosTributos)
|
|
1873
|
-
);
|
|
1874
|
-
assignWsmtxcaValue(voucher, "vatAmount", vatAmount);
|
|
1875
|
-
assignWsmtxcaValue(
|
|
1876
|
-
voucher,
|
|
1877
|
-
"currencyId",
|
|
1878
|
-
normalizeWsmtxcaString(raw.codigoMoneda)
|
|
1879
|
-
);
|
|
1880
|
-
assignWsmtxcaValue(
|
|
1881
|
-
voucher,
|
|
1882
|
-
"exchangeRate",
|
|
1883
|
-
parseOptionalNumber(raw.cotizacionMoneda)
|
|
1884
|
-
);
|
|
1885
|
-
assignWsmtxcaValue(voucher, "cae", cae);
|
|
1886
|
-
assignWsmtxcaValue(voucher, "caeExpiry", caeExpiry);
|
|
1887
|
-
return voucher;
|
|
1888
|
-
}
|
|
1889
|
-
function sumWsmtxcaVatAmounts(value) {
|
|
1890
|
-
const subtotals = toRecord(value)?.subtotalIVA;
|
|
1891
|
-
const entries = Array.isArray(subtotals) ? subtotals : subtotals ? [subtotals] : [];
|
|
1892
|
-
const amounts = entries.map((entry) => parseOptionalNumber(toRecord(entry)?.importe)).filter((amount) => amount !== void 0);
|
|
1893
|
-
return amounts.length > 0 ? amounts.reduce((total, amount) => total + amount, 0) : void 0;
|
|
1894
|
-
}
|
|
1895
|
-
function parseWsmtxcaVoucherNumber(value, message, detail, allowZero = false) {
|
|
1896
|
-
const parsed = Number.parseInt(String(value ?? ""), 10);
|
|
1897
|
-
if (!Number.isFinite(parsed) || (allowZero ? parsed < 0 : parsed <= 0)) {
|
|
1898
|
-
throw new ArcaServiceError(message, {
|
|
1899
|
-
service: "wsmtxca",
|
|
1900
|
-
detail
|
|
1901
|
-
});
|
|
1902
|
-
}
|
|
1903
|
-
return parsed;
|
|
1904
|
-
}
|
|
1905
|
-
function parseOptionalPositiveInteger(value) {
|
|
1906
|
-
const parsed = Number.parseInt(String(value ?? ""), 10);
|
|
1907
|
-
return Number.isFinite(parsed) && parsed > 0 ? parsed : void 0;
|
|
1908
|
-
}
|
|
1909
|
-
function parseOptionalNumber(value) {
|
|
1910
|
-
if (value === void 0 || value === null || value === "") {
|
|
1911
|
-
return void 0;
|
|
1912
|
-
}
|
|
1913
|
-
const parsed = Number(value);
|
|
1914
|
-
return Number.isFinite(parsed) ? parsed : void 0;
|
|
1915
|
-
}
|
|
1916
|
-
function normalizeWsmtxcaResult(value) {
|
|
1917
|
-
if (typeof value !== "string") {
|
|
1918
|
-
return void 0;
|
|
1919
|
-
}
|
|
1920
|
-
const normalized = value.trim().toUpperCase();
|
|
1921
|
-
return normalized || void 0;
|
|
1922
|
-
}
|
|
1923
|
-
function normalizeWsmtxcaString(value) {
|
|
1924
|
-
if (value === void 0 || value === null) {
|
|
1925
|
-
return void 0;
|
|
1926
|
-
}
|
|
1927
|
-
const normalized = String(value).trim();
|
|
1928
|
-
return normalized || void 0;
|
|
1929
|
-
}
|
|
1930
|
-
function assignWsmtxcaValue(target, key, value) {
|
|
1931
|
-
if (value !== void 0) {
|
|
1932
|
-
target[key] = value;
|
|
1933
|
-
}
|
|
1934
|
-
}
|
|
1935
|
-
function normalizeWsmtxcaResponseDate(value) {
|
|
1936
|
-
if (typeof value === "number" && Number.isInteger(value)) {
|
|
1937
|
-
return formatCompactDateToIso(value);
|
|
1938
|
-
}
|
|
1939
|
-
if (typeof value !== "string") {
|
|
1940
|
-
return void 0;
|
|
1941
|
-
}
|
|
1942
|
-
const trimmed = value.trim();
|
|
1943
|
-
if (!trimmed) {
|
|
1944
|
-
return void 0;
|
|
1945
|
-
}
|
|
1946
|
-
if (/^\d{8}$/.test(trimmed)) {
|
|
1947
|
-
return formatCompactDateToIso(Number.parseInt(trimmed, 10));
|
|
1948
|
-
}
|
|
1949
|
-
if (/^\d{4}-\d{2}-\d{2}/.test(trimmed)) {
|
|
1950
|
-
return trimmed.slice(0, 10);
|
|
1951
|
-
}
|
|
1952
|
-
return void 0;
|
|
1953
|
-
}
|
|
1954
|
-
function formatCompactDateToIso(dateValue) {
|
|
1955
|
-
if (!dateValue) {
|
|
1956
|
-
return void 0;
|
|
1957
|
-
}
|
|
1958
|
-
const raw = String(dateValue);
|
|
1959
|
-
if (raw.length !== 8) {
|
|
1960
|
-
return void 0;
|
|
1961
|
-
}
|
|
1962
|
-
return `${raw.slice(0, 4)}-${raw.slice(4, 6)}-${raw.slice(6, 8)}`;
|
|
1963
|
-
}
|
|
1964
|
-
|
|
1965
290
|
// src/internal/http.ts
|
|
1966
291
|
import https from "https";
|
|
1967
292
|
var defaultAgent = new https.Agent({
|
|
@@ -2006,7 +331,7 @@ async function postXmlWithMetadata({
|
|
|
2006
331
|
url,
|
|
2007
332
|
attempt,
|
|
2008
333
|
attempts: totalAttempts,
|
|
2009
|
-
error
|
|
334
|
+
...createSafeErrorDiagnostic(error)
|
|
2010
335
|
});
|
|
2011
336
|
throw error;
|
|
2012
337
|
}
|
|
@@ -2019,7 +344,7 @@ async function postXmlWithMetadata({
|
|
|
2019
344
|
url,
|
|
2020
345
|
attempt: nextAttempt,
|
|
2021
346
|
attempts: totalAttempts,
|
|
2022
|
-
error
|
|
347
|
+
...createSafeErrorDiagnostic(error)
|
|
2023
348
|
}
|
|
2024
349
|
);
|
|
2025
350
|
await delay(retryDelay);
|
|
@@ -2078,21 +403,18 @@ async function postXmlOnce({
|
|
|
2078
403
|
});
|
|
2079
404
|
response.on("error", (error) => {
|
|
2080
405
|
settleReject(
|
|
2081
|
-
new ArcaTransportError(
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
responseBody: getResponseBody()
|
|
2087
|
-
}
|
|
2088
|
-
)
|
|
406
|
+
new ArcaTransportError("ARCA HTTP response stream failed", {
|
|
407
|
+
cause: error,
|
|
408
|
+
statusCode: response.statusCode,
|
|
409
|
+
...createResponseBodyDiagnostic(getResponseBody())
|
|
410
|
+
})
|
|
2089
411
|
);
|
|
2090
412
|
});
|
|
2091
413
|
response.on("aborted", () => {
|
|
2092
414
|
settleReject(
|
|
2093
415
|
new ArcaTransportError("ARCA HTTP response was aborted", {
|
|
2094
416
|
statusCode: response.statusCode,
|
|
2095
|
-
|
|
417
|
+
...createResponseBodyDiagnostic(getResponseBody())
|
|
2096
418
|
})
|
|
2097
419
|
);
|
|
2098
420
|
});
|
|
@@ -2124,7 +446,7 @@ async function postXmlOnce({
|
|
|
2124
446
|
{
|
|
2125
447
|
statusCode,
|
|
2126
448
|
contentType: responseContentType,
|
|
2127
|
-
responseBody
|
|
449
|
+
...createResponseBodyDiagnostic(responseBody)
|
|
2128
450
|
}
|
|
2129
451
|
)
|
|
2130
452
|
);
|
|
@@ -2132,13 +454,20 @@ async function postXmlOnce({
|
|
|
2132
454
|
}
|
|
2133
455
|
);
|
|
2134
456
|
request.setTimeout(timeout, () => {
|
|
2135
|
-
|
|
2136
|
-
|
|
457
|
+
const timeoutCause = new Error(
|
|
458
|
+
`ARCA HTTP request timed out after ${timeout}ms`
|
|
2137
459
|
);
|
|
460
|
+
settleReject(
|
|
461
|
+
new ArcaTransportError(
|
|
462
|
+
`ARCA HTTP request timed out after ${timeout}ms`,
|
|
463
|
+
{ cause: timeoutCause }
|
|
464
|
+
)
|
|
465
|
+
);
|
|
466
|
+
request.destroy(timeoutCause);
|
|
2138
467
|
});
|
|
2139
468
|
request.on("error", (error) => {
|
|
2140
469
|
settleReject(
|
|
2141
|
-
new ArcaTransportError(
|
|
470
|
+
new ArcaTransportError("ARCA HTTP request failed", {
|
|
2142
471
|
cause: error
|
|
2143
472
|
})
|
|
2144
473
|
);
|
|
@@ -2206,7 +535,6 @@ function parseSoapBody(xml, context = {}) {
|
|
|
2206
535
|
throw createInvalidSoapResponseError(
|
|
2207
536
|
"Invalid SOAP response: XML parse failed",
|
|
2208
537
|
context,
|
|
2209
|
-
void 0,
|
|
2210
538
|
error instanceof Error ? error : void 0
|
|
2211
539
|
);
|
|
2212
540
|
}
|
|
@@ -2215,8 +543,7 @@ function parseSoapBody(xml, context = {}) {
|
|
|
2215
543
|
if (!body) {
|
|
2216
544
|
throw createInvalidSoapResponseError(
|
|
2217
545
|
"Invalid SOAP response: missing body",
|
|
2218
|
-
context
|
|
2219
|
-
parsed
|
|
546
|
+
context
|
|
2220
547
|
);
|
|
2221
548
|
}
|
|
2222
549
|
const fault = body.Fault;
|
|
@@ -2230,13 +557,12 @@ function getSingleBodyEntry(body, context = {}) {
|
|
|
2230
557
|
if (entries.length !== 1) {
|
|
2231
558
|
throw createInvalidSoapResponseError(
|
|
2232
559
|
`Invalid SOAP response: expected a single body entry, got ${entries.length}`,
|
|
2233
|
-
context
|
|
2234
|
-
body
|
|
560
|
+
context
|
|
2235
561
|
);
|
|
2236
562
|
}
|
|
2237
563
|
return entries[0];
|
|
2238
564
|
}
|
|
2239
|
-
function createInvalidSoapResponseError(message, context,
|
|
565
|
+
function createInvalidSoapResponseError(message, context, cause) {
|
|
2240
566
|
const responseBody = context.responseBody ?? "";
|
|
2241
567
|
return new ArcaInvalidSoapResponseError(message, {
|
|
2242
568
|
cause,
|
|
@@ -2245,20 +571,12 @@ function createInvalidSoapResponseError(message, context, parsedDetail, cause) {
|
|
|
2245
571
|
endpointUrl: context.endpointUrl,
|
|
2246
572
|
statusCode: context.statusCode,
|
|
2247
573
|
contentType: context.contentType,
|
|
2248
|
-
|
|
2249
|
-
responseBodyPreview: sanitizeSoapResponsePreview(
|
|
574
|
+
...createResponseBodyDiagnostic(
|
|
2250
575
|
responseBody,
|
|
2251
576
|
context.responseBodyPreviewLength
|
|
2252
|
-
)
|
|
2253
|
-
parsedDetail
|
|
577
|
+
)
|
|
2254
578
|
});
|
|
2255
579
|
}
|
|
2256
|
-
function sanitizeSoapResponsePreview(responseBody, maxLength = 4096) {
|
|
2257
|
-
return responseBody.replace(
|
|
2258
|
-
/<((?:[A-Za-z_][\w.-]*:)?(?:Token|Sign))\b([^>]*)>[\s\S]*?<\/\1>/gi,
|
|
2259
|
-
(_match, tagName, attributes) => `<${tagName}${attributes}>[REDACTED]</${tagName}>`
|
|
2260
|
-
).slice(0, maxLength);
|
|
2261
|
-
}
|
|
2262
580
|
function parseXmlDocument(xml) {
|
|
2263
581
|
return xmlParser.parse(xml);
|
|
2264
582
|
}
|
|
@@ -2276,8 +594,7 @@ function createSoapFaultError(fault) {
|
|
|
2276
594
|
const faultCode = typeof fault.faultcode === "string" ? fault.faultcode : getNestedString(fault, ["Code", "Value"]);
|
|
2277
595
|
const message = typeof fault.faultstring === "string" ? fault.faultstring : getNestedString(fault, ["Reason", "Text"]) ?? "ARCA SOAP fault response";
|
|
2278
596
|
return new ArcaSoapFaultError(message, {
|
|
2279
|
-
faultCode: faultCode ?? void 0
|
|
2280
|
-
detail: fault
|
|
597
|
+
faultCode: faultCode ?? void 0
|
|
2281
598
|
});
|
|
2282
599
|
}
|
|
2283
600
|
function getNestedString(value, path) {
|
|
@@ -2360,8 +677,7 @@ function createSoapTransport(options) {
|
|
|
2360
677
|
service: request.service,
|
|
2361
678
|
operation: request.operation,
|
|
2362
679
|
url,
|
|
2363
|
-
|
|
2364
|
-
error
|
|
680
|
+
...createSafeErrorDiagnostic(error)
|
|
2365
681
|
});
|
|
2366
682
|
}
|
|
2367
683
|
if (error instanceof ArcaInvalidSoapResponseError) {
|
|
@@ -2369,10 +685,7 @@ function createSoapTransport(options) {
|
|
|
2369
685
|
service: request.service,
|
|
2370
686
|
operation: request.operation,
|
|
2371
687
|
url,
|
|
2372
|
-
|
|
2373
|
-
contentType: error.contentType,
|
|
2374
|
-
responseBodyLength: error.responseBodyLength,
|
|
2375
|
-
error
|
|
688
|
+
...createSafeErrorDiagnostic(error)
|
|
2376
689
|
});
|
|
2377
690
|
}
|
|
2378
691
|
throw error;
|
|
@@ -2525,8 +838,7 @@ function createWsaaAuthModule(options) {
|
|
|
2525
838
|
service,
|
|
2526
839
|
operation: "loginCms",
|
|
2527
840
|
url: ARCA_WSAA_CONFIG.endpoint[options.config.environment],
|
|
2528
|
-
|
|
2529
|
-
error
|
|
841
|
+
...createSafeErrorDiagnostic(error)
|
|
2530
842
|
});
|
|
2531
843
|
}
|
|
2532
844
|
throw error;
|
|
@@ -2815,8 +1127,15 @@ function createArcaClient(config) {
|
|
|
2815
1127
|
const logger = createArcaLogger(normalizedConfig.logger);
|
|
2816
1128
|
const auth = createWsaaAuthModule({ config: normalizedConfig, logger });
|
|
2817
1129
|
const soap = createSoapTransport({ config: normalizedConfig, logger });
|
|
1130
|
+
const publicConfig = Object.freeze({
|
|
1131
|
+
taxId: normalizedConfig.taxId,
|
|
1132
|
+
environment: normalizedConfig.environment,
|
|
1133
|
+
timeout: normalizedConfig.timeout,
|
|
1134
|
+
retries: normalizedConfig.retries,
|
|
1135
|
+
retryDelay: normalizedConfig.retryDelay
|
|
1136
|
+
});
|
|
2818
1137
|
return {
|
|
2819
|
-
config:
|
|
1138
|
+
config: publicConfig,
|
|
2820
1139
|
wsfe: createWsfeService({ config: normalizedConfig, auth, soap }),
|
|
2821
1140
|
wsmtxca: createWsmtxcaService({ config: normalizedConfig, auth, soap }),
|
|
2822
1141
|
padron: createPadronService({ config: normalizedConfig, auth, soap })
|
|
@@ -2825,6 +1144,7 @@ function createArcaClient(config) {
|
|
|
2825
1144
|
export {
|
|
2826
1145
|
ARCA_ENVIRONMENTS,
|
|
2827
1146
|
ARCA_ENV_VARIABLES,
|
|
1147
|
+
ArcaAuthenticationError,
|
|
2828
1148
|
ArcaConfigurationError,
|
|
2829
1149
|
ArcaError,
|
|
2830
1150
|
ArcaInputError,
|
|
@@ -2833,12 +1153,15 @@ export {
|
|
|
2833
1153
|
ArcaSoapFaultError,
|
|
2834
1154
|
ArcaTransportError,
|
|
2835
1155
|
assertArcaClientConfig,
|
|
1156
|
+
buildFacturaB,
|
|
1157
|
+
buildFacturaC,
|
|
2836
1158
|
createArcaClient,
|
|
2837
1159
|
createArcaClientConfigFromEnv,
|
|
2838
1160
|
createMemoryWsaaSessionStore,
|
|
2839
1161
|
createPadronService,
|
|
2840
1162
|
createWsfeService,
|
|
2841
1163
|
createWsmtxcaService,
|
|
1164
|
+
isArcaAuthenticationError,
|
|
2842
1165
|
resolveArcaEnvironment
|
|
2843
1166
|
};
|
|
2844
1167
|
//# sourceMappingURL=index.mjs.map
|