ksef-client-ts 0.7.0 → 0.7.2-alpha.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 +2 -1
- package/dist/cli.js +1717 -333
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +733 -85
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +77 -2
- package/dist/index.d.ts +77 -2
- package/dist/index.js +711 -75
- package/dist/index.js.map +1 -1
- package/docs/schemas/FA/bazowe/ElementarneTypyDanych_v10-0E.xsd +1 -0
- package/docs/schemas/FA/bazowe/KodyKrajow_v10-0E.xsd +1283 -0
- package/docs/schemas/FA/bazowe/StrukturyDanych_v10-0E.xsd +1 -0
- package/docs/schemas/FA/schemat_FA(2)_v1-0E.xsd +3661 -0
- package/docs/schemas/FA/schemat_FA(3)_v1-0E.xsd +3950 -0
- package/docs/schemas/PEF/Schemat_PEF(3)_v2-1.xsd +977 -0
- package/docs/schemas/PEF/Schemat_PEF_KOR(3)_v2-1.xsd +926 -0
- package/docs/schemas/PEF/bazowe/20241206_PEFPL-CommonAggregateComponents-2.1-v1.4.34.xsd +428 -0
- package/docs/schemas/PEF/bazowe/20241206_PEFPL-CommonBasicComponents-2.1-v1.4.34.xsd +65 -0
- package/docs/schemas/PEF/bazowe/CCTS_CCT_SchemaModule-2.1.xsd +731 -0
- package/docs/schemas/PEF/bazowe/UBL-CommonAggregateComponents-2.1.xsd +39799 -0
- package/docs/schemas/PEF/bazowe/UBL-CommonBasicComponents-2.1.xsd +5389 -0
- package/docs/schemas/PEF/bazowe/UBL-CommonExtensionComponents-2.1.xsd +223 -0
- package/docs/schemas/PEF/bazowe/UBL-CommonSignatureComponents-2.1.xsd +101 -0
- package/docs/schemas/PEF/bazowe/UBL-ExtensionContentDataType-2.1.xsd +89 -0
- package/docs/schemas/PEF/bazowe/UBL-QualifiedDataTypes-2.1.xsd +69 -0
- package/docs/schemas/PEF/bazowe/UBL-SignatureAggregateComponents-2.1.xsd +138 -0
- package/docs/schemas/PEF/bazowe/UBL-SignatureBasicComponents-2.1.xsd +78 -0
- package/docs/schemas/PEF/bazowe/UBL-UnqualifiedDataTypes-2.1.xsd +553 -0
- package/docs/schemas/PEF/bazowe/UBL-XAdESv132-2.1.xsd +476 -0
- package/docs/schemas/PEF/bazowe/UBL-XAdESv141-2.1.xsd +25 -0
- package/docs/schemas/PEF/bazowe/UBL-xmldsig-core-schema-2.1.xsd +323 -0
- package/docs/schemas/PEF/bazowe/commontypes.xsd +735 -0
- package/docs/schemas/PEF/bazowe/isotypes.xsd +3158 -0
- package/docs/schemas/RR/schemat_FA_RR(1)_v1-1E.xsd +2188 -0
- package/docs/schemas/RR/schemat_RR(1)_v1-0E.xsd +2188 -0
- package/docs/schemas/RR/schemat_RR(1)_v1-1E.xsd +2188 -0
- package/package.json +12 -2
package/dist/index.cjs
CHANGED
|
@@ -30,11 +30,22 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
30
30
|
));
|
|
31
31
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
32
32
|
|
|
33
|
+
// node_modules/tsup/assets/cjs_shims.js
|
|
34
|
+
var getImportMetaUrl, importMetaUrl;
|
|
35
|
+
var init_cjs_shims = __esm({
|
|
36
|
+
"node_modules/tsup/assets/cjs_shims.js"() {
|
|
37
|
+
"use strict";
|
|
38
|
+
getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${__filename}`).href : document.currentScript && document.currentScript.tagName.toUpperCase() === "SCRIPT" ? document.currentScript.src : new URL("main.js", document.baseURI).href;
|
|
39
|
+
importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
|
|
33
43
|
// src/config/environments.ts
|
|
34
44
|
var Environment;
|
|
35
45
|
var init_environments = __esm({
|
|
36
46
|
"src/config/environments.ts"() {
|
|
37
47
|
"use strict";
|
|
48
|
+
init_cjs_shims();
|
|
38
49
|
Environment = {
|
|
39
50
|
TEST: {
|
|
40
51
|
apiUrl: "https://api-test.ksef.mf.gov.pl",
|
|
@@ -73,6 +84,7 @@ var DEFAULT_API_VERSION, DEFAULT_TIMEOUT;
|
|
|
73
84
|
var init_options = __esm({
|
|
74
85
|
"src/config/options.ts"() {
|
|
75
86
|
"use strict";
|
|
87
|
+
init_cjs_shims();
|
|
76
88
|
init_environments();
|
|
77
89
|
DEFAULT_API_VERSION = "v2";
|
|
78
90
|
DEFAULT_TIMEOUT = 3e4;
|
|
@@ -83,6 +95,7 @@ var init_options = __esm({
|
|
|
83
95
|
var init_config = __esm({
|
|
84
96
|
"src/config/index.ts"() {
|
|
85
97
|
"use strict";
|
|
98
|
+
init_cjs_shims();
|
|
86
99
|
init_environments();
|
|
87
100
|
init_options();
|
|
88
101
|
}
|
|
@@ -93,6 +106,7 @@ var KSeFError;
|
|
|
93
106
|
var init_ksef_error = __esm({
|
|
94
107
|
"src/errors/ksef-error.ts"() {
|
|
95
108
|
"use strict";
|
|
109
|
+
init_cjs_shims();
|
|
96
110
|
KSeFError = class extends Error {
|
|
97
111
|
constructor(message) {
|
|
98
112
|
super(message);
|
|
@@ -107,6 +121,7 @@ var KSeFApiError;
|
|
|
107
121
|
var init_ksef_api_error = __esm({
|
|
108
122
|
"src/errors/ksef-api-error.ts"() {
|
|
109
123
|
"use strict";
|
|
124
|
+
init_cjs_shims();
|
|
110
125
|
init_ksef_error();
|
|
111
126
|
KSeFApiError = class _KSeFApiError extends KSeFError {
|
|
112
127
|
statusCode;
|
|
@@ -134,6 +149,7 @@ var KSeFRateLimitError;
|
|
|
134
149
|
var init_ksef_rate_limit_error = __esm({
|
|
135
150
|
"src/errors/ksef-rate-limit-error.ts"() {
|
|
136
151
|
"use strict";
|
|
152
|
+
init_cjs_shims();
|
|
137
153
|
init_ksef_api_error();
|
|
138
154
|
KSeFRateLimitError = class _KSeFRateLimitError extends KSeFApiError {
|
|
139
155
|
statusCode = 429;
|
|
@@ -184,6 +200,7 @@ var KSeFUnauthorizedError;
|
|
|
184
200
|
var init_ksef_unauthorized_error = __esm({
|
|
185
201
|
"src/errors/ksef-unauthorized-error.ts"() {
|
|
186
202
|
"use strict";
|
|
203
|
+
init_cjs_shims();
|
|
187
204
|
init_ksef_api_error();
|
|
188
205
|
KSeFUnauthorizedError = class extends KSeFApiError {
|
|
189
206
|
statusCode = 401;
|
|
@@ -216,6 +233,7 @@ var KSeFForbiddenError;
|
|
|
216
233
|
var init_ksef_forbidden_error = __esm({
|
|
217
234
|
"src/errors/ksef-forbidden-error.ts"() {
|
|
218
235
|
"use strict";
|
|
236
|
+
init_cjs_shims();
|
|
219
237
|
init_ksef_api_error();
|
|
220
238
|
KSeFForbiddenError = class extends KSeFApiError {
|
|
221
239
|
statusCode = 403;
|
|
@@ -254,6 +272,7 @@ var KSeFGoneError;
|
|
|
254
272
|
var init_ksef_gone_error = __esm({
|
|
255
273
|
"src/errors/ksef-gone-error.ts"() {
|
|
256
274
|
"use strict";
|
|
275
|
+
init_cjs_shims();
|
|
257
276
|
init_ksef_api_error();
|
|
258
277
|
KSeFGoneError = class extends KSeFApiError {
|
|
259
278
|
statusCode = 410;
|
|
@@ -286,6 +305,7 @@ var KSeFBadRequestError;
|
|
|
286
305
|
var init_ksef_bad_request_error = __esm({
|
|
287
306
|
"src/errors/ksef-bad-request-error.ts"() {
|
|
288
307
|
"use strict";
|
|
308
|
+
init_cjs_shims();
|
|
289
309
|
init_ksef_api_error();
|
|
290
310
|
KSeFBadRequestError = class extends KSeFApiError {
|
|
291
311
|
statusCode = 400;
|
|
@@ -321,6 +341,7 @@ var KSeFAuthStatusError;
|
|
|
321
341
|
var init_ksef_auth_status_error = __esm({
|
|
322
342
|
"src/errors/ksef-auth-status-error.ts"() {
|
|
323
343
|
"use strict";
|
|
344
|
+
init_cjs_shims();
|
|
324
345
|
init_ksef_error();
|
|
325
346
|
KSeFAuthStatusError = class extends KSeFError {
|
|
326
347
|
referenceNumber;
|
|
@@ -340,6 +361,7 @@ var KSeFSessionExpiredError;
|
|
|
340
361
|
var init_ksef_session_expired_error = __esm({
|
|
341
362
|
"src/errors/ksef-session-expired-error.ts"() {
|
|
342
363
|
"use strict";
|
|
364
|
+
init_cjs_shims();
|
|
343
365
|
init_ksef_error();
|
|
344
366
|
KSeFSessionExpiredError = class extends KSeFError {
|
|
345
367
|
constructor(message = "KSeF session has expired") {
|
|
@@ -359,6 +381,7 @@ var KSeFValidationError;
|
|
|
359
381
|
var init_ksef_validation_error = __esm({
|
|
360
382
|
"src/errors/ksef-validation-error.ts"() {
|
|
361
383
|
"use strict";
|
|
384
|
+
init_cjs_shims();
|
|
362
385
|
init_ksef_error();
|
|
363
386
|
KSeFValidationError = class _KSeFValidationError extends KSeFError {
|
|
364
387
|
details;
|
|
@@ -386,6 +409,7 @@ var KSeFErrorCode;
|
|
|
386
409
|
var init_error_codes = __esm({
|
|
387
410
|
"src/errors/error-codes.ts"() {
|
|
388
411
|
"use strict";
|
|
412
|
+
init_cjs_shims();
|
|
389
413
|
KSeFErrorCode = {
|
|
390
414
|
BatchTimeout: 21208,
|
|
391
415
|
DuplicateInvoice: 440
|
|
@@ -398,6 +422,7 @@ var KSeFBatchTimeoutError;
|
|
|
398
422
|
var init_ksef_batch_timeout_error = __esm({
|
|
399
423
|
"src/errors/ksef-batch-timeout-error.ts"() {
|
|
400
424
|
"use strict";
|
|
425
|
+
init_cjs_shims();
|
|
401
426
|
init_ksef_api_error();
|
|
402
427
|
init_error_codes();
|
|
403
428
|
KSeFBatchTimeoutError = class _KSeFBatchTimeoutError extends KSeFApiError {
|
|
@@ -417,6 +442,52 @@ var init_ksef_batch_timeout_error = __esm({
|
|
|
417
442
|
}
|
|
418
443
|
});
|
|
419
444
|
|
|
445
|
+
// src/errors/ksef-circuit-open-error.ts
|
|
446
|
+
var KSeFCircuitOpenError;
|
|
447
|
+
var init_ksef_circuit_open_error = __esm({
|
|
448
|
+
"src/errors/ksef-circuit-open-error.ts"() {
|
|
449
|
+
"use strict";
|
|
450
|
+
init_cjs_shims();
|
|
451
|
+
init_ksef_error();
|
|
452
|
+
KSeFCircuitOpenError = class extends KSeFError {
|
|
453
|
+
endpoint;
|
|
454
|
+
openedAt;
|
|
455
|
+
retryAfterMs;
|
|
456
|
+
constructor(endpoint, openedAt, retryAfterMs) {
|
|
457
|
+
super(
|
|
458
|
+
`Circuit breaker is open for '${endpoint}'. Retry after ${Math.round(retryAfterMs)}ms.`
|
|
459
|
+
);
|
|
460
|
+
this.name = "KSeFCircuitOpenError";
|
|
461
|
+
this.endpoint = endpoint;
|
|
462
|
+
this.openedAt = openedAt;
|
|
463
|
+
this.retryAfterMs = retryAfterMs;
|
|
464
|
+
}
|
|
465
|
+
};
|
|
466
|
+
}
|
|
467
|
+
});
|
|
468
|
+
|
|
469
|
+
// src/errors/ksef-xsd-validation-error.ts
|
|
470
|
+
var KSeFXsdValidationError;
|
|
471
|
+
var init_ksef_xsd_validation_error = __esm({
|
|
472
|
+
"src/errors/ksef-xsd-validation-error.ts"() {
|
|
473
|
+
"use strict";
|
|
474
|
+
init_cjs_shims();
|
|
475
|
+
init_ksef_error();
|
|
476
|
+
KSeFXsdValidationError = class extends KSeFError {
|
|
477
|
+
schemaFile;
|
|
478
|
+
errors;
|
|
479
|
+
constructor(schemaFile, errors) {
|
|
480
|
+
const preview = errors.slice(0, 3).join("; ");
|
|
481
|
+
const extra = errors.length > 3 ? ` (+${errors.length - 3} more)` : "";
|
|
482
|
+
super(`XSD validation failed against ${schemaFile}: ${preview}${extra}`);
|
|
483
|
+
this.name = "KSeFXsdValidationError";
|
|
484
|
+
this.schemaFile = schemaFile;
|
|
485
|
+
this.errors = errors;
|
|
486
|
+
}
|
|
487
|
+
};
|
|
488
|
+
}
|
|
489
|
+
});
|
|
490
|
+
|
|
420
491
|
// src/errors/assert-never.ts
|
|
421
492
|
function assertNever(value) {
|
|
422
493
|
throw new Error(`Unexpected value: ${String(value)}`);
|
|
@@ -424,6 +495,7 @@ function assertNever(value) {
|
|
|
424
495
|
var init_assert_never = __esm({
|
|
425
496
|
"src/errors/assert-never.ts"() {
|
|
426
497
|
"use strict";
|
|
498
|
+
init_cjs_shims();
|
|
427
499
|
}
|
|
428
500
|
});
|
|
429
501
|
|
|
@@ -431,6 +503,7 @@ var init_assert_never = __esm({
|
|
|
431
503
|
var init_errors = __esm({
|
|
432
504
|
"src/errors/index.ts"() {
|
|
433
505
|
"use strict";
|
|
506
|
+
init_cjs_shims();
|
|
434
507
|
init_ksef_error();
|
|
435
508
|
init_ksef_api_error();
|
|
436
509
|
init_ksef_rate_limit_error();
|
|
@@ -442,6 +515,8 @@ var init_errors = __esm({
|
|
|
442
515
|
init_ksef_session_expired_error();
|
|
443
516
|
init_ksef_validation_error();
|
|
444
517
|
init_ksef_batch_timeout_error();
|
|
518
|
+
init_ksef_circuit_open_error();
|
|
519
|
+
init_ksef_xsd_validation_error();
|
|
445
520
|
init_error_codes();
|
|
446
521
|
init_assert_never();
|
|
447
522
|
}
|
|
@@ -452,6 +527,7 @@ var RouteBuilder;
|
|
|
452
527
|
var init_route_builder = __esm({
|
|
453
528
|
"src/http/route-builder.ts"() {
|
|
454
529
|
"use strict";
|
|
530
|
+
init_cjs_shims();
|
|
455
531
|
RouteBuilder = class {
|
|
456
532
|
apiVersion;
|
|
457
533
|
constructor(apiVersion) {
|
|
@@ -470,6 +546,7 @@ var RestRequest;
|
|
|
470
546
|
var init_rest_request = __esm({
|
|
471
547
|
"src/http/rest-request.ts"() {
|
|
472
548
|
"use strict";
|
|
549
|
+
init_cjs_shims();
|
|
473
550
|
RestRequest = class _RestRequest {
|
|
474
551
|
method;
|
|
475
552
|
path;
|
|
@@ -478,21 +555,21 @@ var init_rest_request = __esm({
|
|
|
478
555
|
_query = [];
|
|
479
556
|
_presigned = false;
|
|
480
557
|
_skipAuthRetry = false;
|
|
481
|
-
constructor(method,
|
|
558
|
+
constructor(method, path3) {
|
|
482
559
|
this.method = method;
|
|
483
|
-
this.path =
|
|
560
|
+
this.path = path3;
|
|
484
561
|
}
|
|
485
|
-
static get(
|
|
486
|
-
return new _RestRequest("GET",
|
|
562
|
+
static get(path3) {
|
|
563
|
+
return new _RestRequest("GET", path3);
|
|
487
564
|
}
|
|
488
|
-
static post(
|
|
489
|
-
return new _RestRequest("POST",
|
|
565
|
+
static post(path3) {
|
|
566
|
+
return new _RestRequest("POST", path3);
|
|
490
567
|
}
|
|
491
|
-
static put(
|
|
492
|
-
return new _RestRequest("PUT",
|
|
568
|
+
static put(path3) {
|
|
569
|
+
return new _RestRequest("PUT", path3);
|
|
493
570
|
}
|
|
494
|
-
static delete(
|
|
495
|
-
return new _RestRequest("DELETE",
|
|
571
|
+
static delete(path3) {
|
|
572
|
+
return new _RestRequest("DELETE", path3);
|
|
496
573
|
}
|
|
497
574
|
body(data) {
|
|
498
575
|
this._body = data;
|
|
@@ -546,6 +623,7 @@ var defaultTransport;
|
|
|
546
623
|
var init_transport = __esm({
|
|
547
624
|
"src/http/transport.ts"() {
|
|
548
625
|
"use strict";
|
|
626
|
+
init_cjs_shims();
|
|
549
627
|
defaultTransport = (url, init) => fetch(url, init);
|
|
550
628
|
}
|
|
551
629
|
});
|
|
@@ -595,6 +673,7 @@ var RETRYABLE_ERROR_CODES;
|
|
|
595
673
|
var init_retry_policy = __esm({
|
|
596
674
|
"src/http/retry-policy.ts"() {
|
|
597
675
|
"use strict";
|
|
676
|
+
init_cjs_shims();
|
|
598
677
|
RETRYABLE_ERROR_CODES = /* @__PURE__ */ new Set([
|
|
599
678
|
"ECONNRESET",
|
|
600
679
|
"ECONNREFUSED",
|
|
@@ -685,6 +764,7 @@ var BLOCKED_PARAMS;
|
|
|
685
764
|
var init_presigned_url_policy = __esm({
|
|
686
765
|
"src/http/presigned-url-policy.ts"() {
|
|
687
766
|
"use strict";
|
|
767
|
+
init_cjs_shims();
|
|
688
768
|
init_ksef_validation_error();
|
|
689
769
|
BLOCKED_PARAMS = ["redirect", "callback", "return_url", "next"];
|
|
690
770
|
}
|
|
@@ -716,6 +796,7 @@ var import_consola, RestClient;
|
|
|
716
796
|
var init_rest_client = __esm({
|
|
717
797
|
"src/http/rest-client.ts"() {
|
|
718
798
|
"use strict";
|
|
799
|
+
init_cjs_shims();
|
|
719
800
|
import_consola = require("consola");
|
|
720
801
|
init_ksef_api_error();
|
|
721
802
|
init_ksef_rate_limit_error();
|
|
@@ -735,6 +816,7 @@ var init_rest_client = __esm({
|
|
|
735
816
|
transport;
|
|
736
817
|
retryPolicy;
|
|
737
818
|
rateLimitPolicy;
|
|
819
|
+
circuitBreakerPolicy;
|
|
738
820
|
authManager;
|
|
739
821
|
presignedUrlPolicy;
|
|
740
822
|
constructor(options, config) {
|
|
@@ -743,6 +825,7 @@ var init_rest_client = __esm({
|
|
|
743
825
|
this.transport = config?.transport ?? defaultTransport;
|
|
744
826
|
this.retryPolicy = config?.retryPolicy ?? defaultRetryPolicy();
|
|
745
827
|
this.rateLimitPolicy = config?.rateLimitPolicy ?? null;
|
|
828
|
+
this.circuitBreakerPolicy = config?.circuitBreakerPolicy ?? null;
|
|
746
829
|
this.authManager = config?.authManager;
|
|
747
830
|
this.presignedUrlPolicy = config?.presignedUrlPolicy;
|
|
748
831
|
}
|
|
@@ -767,18 +850,32 @@ var init_rest_client = __esm({
|
|
|
767
850
|
if (request.isPresigned() && this.presignedUrlPolicy) {
|
|
768
851
|
validatePresignedUrl(url, this.presignedUrlPolicy);
|
|
769
852
|
}
|
|
853
|
+
let ownsProbeSlot = false;
|
|
854
|
+
if (this.circuitBreakerPolicy) {
|
|
855
|
+
const claimed = this.circuitBreakerPolicy.ensureClosed(request.path);
|
|
856
|
+
if (claimed) ownsProbeSlot = true;
|
|
857
|
+
}
|
|
770
858
|
if (this.rateLimitPolicy) {
|
|
771
|
-
|
|
859
|
+
try {
|
|
860
|
+
await this.rateLimitPolicy.acquire(request.path);
|
|
861
|
+
} catch (error) {
|
|
862
|
+
if (ownsProbeSlot) this.circuitBreakerPolicy?.releaseProbe(request.path);
|
|
863
|
+
throw error;
|
|
864
|
+
}
|
|
772
865
|
}
|
|
773
866
|
let lastError;
|
|
774
867
|
for (let attempt = 0; attempt <= this.retryPolicy.maxRetries; attempt++) {
|
|
868
|
+
if (this.circuitBreakerPolicy) {
|
|
869
|
+
const claimed = this.circuitBreakerPolicy.ensureClosed(request.path, ownsProbeSlot);
|
|
870
|
+
if (claimed) ownsProbeSlot = true;
|
|
871
|
+
}
|
|
775
872
|
try {
|
|
776
|
-
|
|
873
|
+
let response = await this.doRequest(request, url);
|
|
777
874
|
if (response.status === 401 && this.authManager && attempt === 0 && !request.isSkipAuthRetry()) {
|
|
778
875
|
const newToken = await this.authManager.onUnauthorized();
|
|
779
876
|
if (newToken) {
|
|
780
877
|
import_consola.consola.debug("Auth token refreshed, retrying request");
|
|
781
|
-
|
|
878
|
+
response = await this.doRequest(request, url, newToken);
|
|
782
879
|
}
|
|
783
880
|
}
|
|
784
881
|
if (isRetryableStatus(response.status, this.retryPolicy) && attempt < this.retryPolicy.maxRetries) {
|
|
@@ -788,10 +885,17 @@ var init_rest_client = __esm({
|
|
|
788
885
|
import_consola.consola.debug(`Retryable ${response.status}, attempt ${attempt + 1}/${this.retryPolicy.maxRetries}, waiting ${Math.round(delayMs)}ms`);
|
|
789
886
|
await sleep(delayMs);
|
|
790
887
|
if (is429 && this.rateLimitPolicy) {
|
|
791
|
-
|
|
888
|
+
try {
|
|
889
|
+
await this.rateLimitPolicy.acquire(request.path);
|
|
890
|
+
} catch (error) {
|
|
891
|
+
this.recordCircuitOutcome(request.path, 429);
|
|
892
|
+
ownsProbeSlot = false;
|
|
893
|
+
throw error;
|
|
894
|
+
}
|
|
792
895
|
}
|
|
793
896
|
continue;
|
|
794
897
|
}
|
|
898
|
+
this.recordCircuitOutcome(request.path, response.status);
|
|
795
899
|
return response;
|
|
796
900
|
} catch (error) {
|
|
797
901
|
lastError = error;
|
|
@@ -801,11 +905,22 @@ var init_rest_client = __esm({
|
|
|
801
905
|
await sleep(delayMs);
|
|
802
906
|
continue;
|
|
803
907
|
}
|
|
908
|
+
if (isRetryableError(error, this.retryPolicy) || ownsProbeSlot) {
|
|
909
|
+
this.circuitBreakerPolicy?.recordFailure(request.path);
|
|
910
|
+
}
|
|
804
911
|
throw error;
|
|
805
912
|
}
|
|
806
913
|
}
|
|
807
914
|
throw lastError;
|
|
808
915
|
}
|
|
916
|
+
recordCircuitOutcome(path3, status) {
|
|
917
|
+
if (!this.circuitBreakerPolicy) return;
|
|
918
|
+
if (status >= 500) {
|
|
919
|
+
this.circuitBreakerPolicy.recordFailure(path3);
|
|
920
|
+
return;
|
|
921
|
+
}
|
|
922
|
+
this.circuitBreakerPolicy.recordSuccess(path3);
|
|
923
|
+
}
|
|
809
924
|
async doRequest(request, url, overrideToken) {
|
|
810
925
|
const headers = {
|
|
811
926
|
...this.options.customHeaders,
|
|
@@ -841,9 +956,9 @@ var init_rest_client = __esm({
|
|
|
841
956
|
return response;
|
|
842
957
|
}
|
|
843
958
|
buildUrl(request) {
|
|
844
|
-
const
|
|
959
|
+
const path3 = this.routeBuilder.build(request.path);
|
|
845
960
|
const base = this.options.baseUrl;
|
|
846
|
-
const url = new URL(`${base}${
|
|
961
|
+
const url = new URL(`${base}${path3}`);
|
|
847
962
|
const query = request.getQuery();
|
|
848
963
|
for (const [key, value] of query) {
|
|
849
964
|
url.searchParams.append(key, value);
|
|
@@ -927,6 +1042,7 @@ var Routes;
|
|
|
927
1042
|
var init_routes = __esm({
|
|
928
1043
|
"src/http/routes.ts"() {
|
|
929
1044
|
"use strict";
|
|
1045
|
+
init_cjs_shims();
|
|
930
1046
|
Routes = {
|
|
931
1047
|
TestData: {
|
|
932
1048
|
createSubject: "testdata/subject",
|
|
@@ -1059,6 +1175,7 @@ var TokenBucket, RateLimitPolicy;
|
|
|
1059
1175
|
var init_rate_limit_policy = __esm({
|
|
1060
1176
|
"src/http/rate-limit-policy.ts"() {
|
|
1061
1177
|
"use strict";
|
|
1178
|
+
init_cjs_shims();
|
|
1062
1179
|
TokenBucket = class {
|
|
1063
1180
|
tokens;
|
|
1064
1181
|
maxTokens;
|
|
@@ -1119,11 +1236,151 @@ var init_rate_limit_policy = __esm({
|
|
|
1119
1236
|
}
|
|
1120
1237
|
});
|
|
1121
1238
|
|
|
1239
|
+
// src/http/circuit-breaker-policy.ts
|
|
1240
|
+
function defaultCircuitBreakerPolicy() {
|
|
1241
|
+
return new CircuitBreakerPolicy();
|
|
1242
|
+
}
|
|
1243
|
+
var import_consola2, GLOBAL_KEY, CircuitBreakerPolicy;
|
|
1244
|
+
var init_circuit_breaker_policy = __esm({
|
|
1245
|
+
"src/http/circuit-breaker-policy.ts"() {
|
|
1246
|
+
"use strict";
|
|
1247
|
+
init_cjs_shims();
|
|
1248
|
+
import_consola2 = require("consola");
|
|
1249
|
+
init_ksef_circuit_open_error();
|
|
1250
|
+
GLOBAL_KEY = "__global__";
|
|
1251
|
+
CircuitBreakerPolicy = class _CircuitBreakerPolicy {
|
|
1252
|
+
failureThreshold;
|
|
1253
|
+
openMs;
|
|
1254
|
+
scope;
|
|
1255
|
+
states = /* @__PURE__ */ new Map();
|
|
1256
|
+
constructor(config = {}) {
|
|
1257
|
+
const failureThreshold = config.failureThreshold ?? 5;
|
|
1258
|
+
const openMs = config.openMs ?? 3e4;
|
|
1259
|
+
if (!Number.isInteger(failureThreshold) || failureThreshold <= 0) {
|
|
1260
|
+
throw new RangeError("CircuitBreakerPolicy: failureThreshold must be a positive integer");
|
|
1261
|
+
}
|
|
1262
|
+
if (!Number.isFinite(openMs) || openMs <= 0) {
|
|
1263
|
+
throw new RangeError("CircuitBreakerPolicy: openMs must be > 0");
|
|
1264
|
+
}
|
|
1265
|
+
const scope = config.scope ?? "global";
|
|
1266
|
+
if (scope !== "global" && scope !== "endpoint") {
|
|
1267
|
+
throw new RangeError(
|
|
1268
|
+
"CircuitBreakerPolicy: scope must be 'global' or 'endpoint'"
|
|
1269
|
+
);
|
|
1270
|
+
}
|
|
1271
|
+
this.failureThreshold = failureThreshold;
|
|
1272
|
+
this.openMs = openMs;
|
|
1273
|
+
this.scope = scope;
|
|
1274
|
+
}
|
|
1275
|
+
// Returns true iff this call just claimed the single probe slot for the
|
|
1276
|
+
// caller. The caller MUST pass `alreadyOwnsProbe=true` on subsequent
|
|
1277
|
+
// re-checks for the same logical request (e.g. a retry loop) so the probe
|
|
1278
|
+
// owner cannot deadlock itself on its own in-flight slot.
|
|
1279
|
+
ensureClosed(endpoint, alreadyOwnsProbe = false) {
|
|
1280
|
+
const key = this.keyFor(endpoint);
|
|
1281
|
+
const state = this.states.get(key);
|
|
1282
|
+
if (!state || state.openedAt === null) return false;
|
|
1283
|
+
const now = performance.now();
|
|
1284
|
+
const elapsed = now - state.openedAt;
|
|
1285
|
+
if (elapsed >= this.openMs) {
|
|
1286
|
+
if (alreadyOwnsProbe) return false;
|
|
1287
|
+
if (state.probeInFlight) {
|
|
1288
|
+
throw new KSeFCircuitOpenError(endpoint, state.openedAt, 0);
|
|
1289
|
+
}
|
|
1290
|
+
state.probeInFlight = true;
|
|
1291
|
+
import_consola2.consola.debug(`Circuit breaker: probe after cooldown for '${key}'`);
|
|
1292
|
+
return true;
|
|
1293
|
+
}
|
|
1294
|
+
const retryAfterMs = Math.max(0, this.openMs - elapsed);
|
|
1295
|
+
throw new KSeFCircuitOpenError(endpoint, state.openedAt, retryAfterMs);
|
|
1296
|
+
}
|
|
1297
|
+
recordSuccess(endpoint) {
|
|
1298
|
+
const key = this.keyFor(endpoint);
|
|
1299
|
+
const state = this.states.get(key);
|
|
1300
|
+
if (!state) return;
|
|
1301
|
+
if (state.openedAt !== null || state.failures > 0) {
|
|
1302
|
+
import_consola2.consola.debug(`Circuit breaker: reset for '${key}'`);
|
|
1303
|
+
}
|
|
1304
|
+
this.states.delete(key);
|
|
1305
|
+
}
|
|
1306
|
+
// Release a claimed probe slot WITHOUT observing an outcome. Use this when
|
|
1307
|
+
// the probe attempt was aborted before reaching upstream (e.g. rate-limit
|
|
1308
|
+
// acquire rejected, client cancellation). We have no new information about
|
|
1309
|
+
// upstream health, so the breaker must stay OPEN — but we do restart the
|
|
1310
|
+
// cooldown clock so the next probe attempt waits a fresh `openMs`,
|
|
1311
|
+
// preventing a tight loop of aborted probes from spamming the limiter.
|
|
1312
|
+
releaseProbe(endpoint) {
|
|
1313
|
+
const key = this.keyFor(endpoint);
|
|
1314
|
+
const state = this.states.get(key);
|
|
1315
|
+
if (!state || !state.probeInFlight) return;
|
|
1316
|
+
state.probeInFlight = false;
|
|
1317
|
+
if (state.openedAt !== null) {
|
|
1318
|
+
state.openedAt = performance.now();
|
|
1319
|
+
}
|
|
1320
|
+
import_consola2.consola.debug(`Circuit breaker: probe aborted (not observed) for '${key}', cooldown restarted`);
|
|
1321
|
+
}
|
|
1322
|
+
recordFailure(endpoint) {
|
|
1323
|
+
const key = this.keyFor(endpoint);
|
|
1324
|
+
const now = performance.now();
|
|
1325
|
+
let state = this.states.get(key);
|
|
1326
|
+
if (!state) {
|
|
1327
|
+
state = { failures: 0, openedAt: null, lastFailureAt: null, probeInFlight: false };
|
|
1328
|
+
this.states.set(key, state);
|
|
1329
|
+
}
|
|
1330
|
+
if (state.openedAt !== null && state.probeInFlight) {
|
|
1331
|
+
state.openedAt = now;
|
|
1332
|
+
state.failures = this.failureThreshold;
|
|
1333
|
+
state.lastFailureAt = now;
|
|
1334
|
+
state.probeInFlight = false;
|
|
1335
|
+
import_consola2.consola.debug(`Circuit breaker: probe failed, re-opened for '${key}'`);
|
|
1336
|
+
this.maybeSweepStaleClosed(now, key);
|
|
1337
|
+
return;
|
|
1338
|
+
}
|
|
1339
|
+
const slidingStale = state.lastFailureAt !== null && now - state.lastFailureAt > this.openMs;
|
|
1340
|
+
state.failures = slidingStale ? 1 : state.failures + 1;
|
|
1341
|
+
state.lastFailureAt = now;
|
|
1342
|
+
if (state.openedAt === null && state.failures >= this.failureThreshold) {
|
|
1343
|
+
state.openedAt = now;
|
|
1344
|
+
import_consola2.consola.debug(
|
|
1345
|
+
`Circuit breaker: opened for '${key}' after ${state.failures} failures (cooldown ${this.openMs}ms)`
|
|
1346
|
+
);
|
|
1347
|
+
}
|
|
1348
|
+
this.maybeSweepStaleClosed(now, key);
|
|
1349
|
+
}
|
|
1350
|
+
keyFor(endpoint) {
|
|
1351
|
+
return this.scope === "global" ? GLOBAL_KEY : endpoint;
|
|
1352
|
+
}
|
|
1353
|
+
// Prevent unbounded map growth under `scope: 'endpoint'` when callers hit
|
|
1354
|
+
// many distinct parameterized paths (e.g. `auth/sessions/{ref}`) that each
|
|
1355
|
+
// fail once and are never revisited. Global scope is always a single entry.
|
|
1356
|
+
//
|
|
1357
|
+
// Runs amortized O(n) — gated on a size threshold so small workloads pay
|
|
1358
|
+
// nothing. Only evicts states that are genuinely settled: closed, no probe
|
|
1359
|
+
// in flight, and with the last failure older than two cooldowns.
|
|
1360
|
+
maybeSweepStaleClosed(now, keepKey) {
|
|
1361
|
+
if (this.scope !== "endpoint") return;
|
|
1362
|
+
if (this.states.size <= _CircuitBreakerPolicy.sweepThreshold) return;
|
|
1363
|
+
const staleBefore = now - 2 * this.openMs;
|
|
1364
|
+
for (const [key, state] of this.states) {
|
|
1365
|
+
if (key === keepKey) continue;
|
|
1366
|
+
if (state.openedAt !== null) continue;
|
|
1367
|
+
if (state.probeInFlight) continue;
|
|
1368
|
+
if (state.lastFailureAt !== null && state.lastFailureAt < staleBefore) {
|
|
1369
|
+
this.states.delete(key);
|
|
1370
|
+
}
|
|
1371
|
+
}
|
|
1372
|
+
}
|
|
1373
|
+
static sweepThreshold = 64;
|
|
1374
|
+
};
|
|
1375
|
+
}
|
|
1376
|
+
});
|
|
1377
|
+
|
|
1122
1378
|
// src/http/auth-manager.ts
|
|
1123
1379
|
var DefaultAuthManager;
|
|
1124
1380
|
var init_auth_manager = __esm({
|
|
1125
1381
|
"src/http/auth-manager.ts"() {
|
|
1126
1382
|
"use strict";
|
|
1383
|
+
init_cjs_shims();
|
|
1127
1384
|
DefaultAuthManager = class {
|
|
1128
1385
|
token;
|
|
1129
1386
|
refreshToken;
|
|
@@ -1164,6 +1421,7 @@ var KSEF_FEATURE_HEADER, UpoVersion, ENFORCE_XADES_COMPLIANCE;
|
|
|
1164
1421
|
var init_ksef_feature = __esm({
|
|
1165
1422
|
"src/http/ksef-feature.ts"() {
|
|
1166
1423
|
"use strict";
|
|
1424
|
+
init_cjs_shims();
|
|
1167
1425
|
KSEF_FEATURE_HEADER = "X-KSeF-Feature";
|
|
1168
1426
|
UpoVersion = {
|
|
1169
1427
|
/** UPO v4-2 format (default before 2026-01-05). */
|
|
@@ -1263,6 +1521,7 @@ var NIP_PATTERN_CORE, VAT_UE_PATTERN_CORE, Nip, VatUe, NipVatUe, InternalId, Pep
|
|
|
1263
1521
|
var init_patterns = __esm({
|
|
1264
1522
|
"src/validation/patterns.ts"() {
|
|
1265
1523
|
"use strict";
|
|
1524
|
+
init_cjs_shims();
|
|
1266
1525
|
NIP_PATTERN_CORE = "[1-9]((\\d[1-9])|([1-9]\\d))\\d{7}";
|
|
1267
1526
|
VAT_UE_PATTERN_CORE = "(ATU\\d{8}|BE[01]{1}\\d{9}|BG\\d{9,10}|CY\\d{8}[A-Z]|CZ\\d{8,10}|DE\\d{9}|DK\\d{8}|EE\\d{9}|EL\\d{9}|ES([A-Z]\\d{8}|\\d{8}[A-Z]|[A-Z]\\d{7}[A-Z])|FI\\d{8}|FR[A-Z0-9]{2}\\d{9}|HR\\d{11}|HU\\d{8}|IE(\\d{7}[A-Z]{2}|\\d[A-Z0-9+*]\\d{5}[A-Z])|IT\\d{11}|LT(\\d{9}|\\d{12})|LU\\d{8}|LV\\d{11}|MT\\d{8}|NL[A-Z0-9+*]{12}|PT\\d{9}|RO\\d{2,10}|SE\\d{12}|SI\\d{8}|SK\\d{10}|XI((\\d{9}|\\d{12})|(GD|HA)\\d{3}))";
|
|
1268
1527
|
Nip = new RegExp(`^${NIP_PATTERN_CORE}$`);
|
|
@@ -1379,6 +1638,7 @@ var import_xmldom;
|
|
|
1379
1638
|
var init_xml_to_object = __esm({
|
|
1380
1639
|
"src/validation/xml-to-object.ts"() {
|
|
1381
1640
|
"use strict";
|
|
1641
|
+
init_cjs_shims();
|
|
1382
1642
|
import_xmldom = require("@xmldom/xmldom");
|
|
1383
1643
|
}
|
|
1384
1644
|
});
|
|
@@ -1392,6 +1652,7 @@ var import_zod, TKodFormularza, TDataCzas, TZnakowy, TNaglowek, TKodyKrajowUE, T
|
|
|
1392
1652
|
var init_fa3 = __esm({
|
|
1393
1653
|
"src/validation/schemas/fa3.ts"() {
|
|
1394
1654
|
"use strict";
|
|
1655
|
+
init_cjs_shims();
|
|
1395
1656
|
import_zod = require("zod");
|
|
1396
1657
|
TKodFormularza = import_zod.z.literal("FA");
|
|
1397
1658
|
TDataCzas = import_zod.z.string();
|
|
@@ -1802,6 +2063,7 @@ var import_zod2, TKodFormularza2, TDataCzas2, TZnakowy3, TNaglowek2, TKodyKrajow
|
|
|
1802
2063
|
var init_fa2 = __esm({
|
|
1803
2064
|
"src/validation/schemas/fa2.ts"() {
|
|
1804
2065
|
"use strict";
|
|
2066
|
+
init_cjs_shims();
|
|
1805
2067
|
import_zod2 = require("zod");
|
|
1806
2068
|
TKodFormularza2 = import_zod2.z.literal("FA");
|
|
1807
2069
|
TDataCzas2 = import_zod2.z.string();
|
|
@@ -2196,6 +2458,7 @@ var import_zod3, TKodFormularza3, TDataCzas3, TZnakowy4, TNaglowek3, TNrNIP3, TZ
|
|
|
2196
2458
|
var init_rr1_v11e = __esm({
|
|
2197
2459
|
"src/validation/schemas/rr1-v11e.ts"() {
|
|
2198
2460
|
"use strict";
|
|
2461
|
+
init_cjs_shims();
|
|
2199
2462
|
import_zod3 = require("zod");
|
|
2200
2463
|
TKodFormularza3 = import_zod3.z.literal("FA_RR");
|
|
2201
2464
|
TDataCzas3 = import_zod3.z.string();
|
|
@@ -2401,6 +2664,7 @@ var import_zod4, TKodFormularza4, TDataCzas4, TZnakowy5, TNaglowek4, TNrNIP4, TZ
|
|
|
2401
2664
|
var init_rr1_v10e = __esm({
|
|
2402
2665
|
"src/validation/schemas/rr1-v10e.ts"() {
|
|
2403
2666
|
"use strict";
|
|
2667
|
+
init_cjs_shims();
|
|
2404
2668
|
import_zod4 = require("zod");
|
|
2405
2669
|
TKodFormularza4 = import_zod4.z.literal("FA_RR");
|
|
2406
2670
|
TDataCzas4 = import_zod4.z.string();
|
|
@@ -2606,6 +2870,7 @@ var import_zod5, InvoiceType, PEF3Schema;
|
|
|
2606
2870
|
var init_pef3 = __esm({
|
|
2607
2871
|
"src/validation/schemas/pef3.ts"() {
|
|
2608
2872
|
"use strict";
|
|
2873
|
+
init_cjs_shims();
|
|
2609
2874
|
import_zod5 = require("zod");
|
|
2610
2875
|
InvoiceType = import_zod5.z.object({
|
|
2611
2876
|
"UBLExtensions": import_zod5.z.any().optional(),
|
|
@@ -2676,6 +2941,7 @@ var import_zod6, CreditNoteType, PEF_KOR3Schema;
|
|
|
2676
2941
|
var init_pef_kor3 = __esm({
|
|
2677
2942
|
"src/validation/schemas/pef-kor3.ts"() {
|
|
2678
2943
|
"use strict";
|
|
2944
|
+
init_cjs_shims();
|
|
2679
2945
|
import_zod6 = require("zod");
|
|
2680
2946
|
CreditNoteType = import_zod6.z.object({
|
|
2681
2947
|
"UBLExtensions": import_zod6.z.any().optional(),
|
|
@@ -2739,6 +3005,7 @@ var NAMESPACE_MAP;
|
|
|
2739
3005
|
var init_schemas = __esm({
|
|
2740
3006
|
"src/validation/schemas/index.ts"() {
|
|
2741
3007
|
"use strict";
|
|
3008
|
+
init_cjs_shims();
|
|
2742
3009
|
init_fa3();
|
|
2743
3010
|
init_fa2();
|
|
2744
3011
|
init_rr1_v11e();
|
|
@@ -2795,6 +3062,7 @@ var ROOT_ELEMENT_MAP, schemaCache, SchemaRegistry;
|
|
|
2795
3062
|
var init_schema_registry = __esm({
|
|
2796
3063
|
"src/validation/schema-registry.ts"() {
|
|
2797
3064
|
"use strict";
|
|
3065
|
+
init_cjs_shims();
|
|
2798
3066
|
init_schemas();
|
|
2799
3067
|
ROOT_ELEMENT_MAP = {
|
|
2800
3068
|
Invoice: "PEF3",
|
|
@@ -2920,6 +3188,7 @@ var DISCOURAGED_UNICODE_RANGES, PI_TARGET_RE;
|
|
|
2920
3188
|
var init_char_validity = __esm({
|
|
2921
3189
|
"src/validation/char-validity.ts"() {
|
|
2922
3190
|
"use strict";
|
|
3191
|
+
init_cjs_shims();
|
|
2923
3192
|
DISCOURAGED_UNICODE_RANGES = [
|
|
2924
3193
|
[127, 132],
|
|
2925
3194
|
[134, 159],
|
|
@@ -3002,11 +3271,11 @@ async function validateSchema(xml, options, _parsed) {
|
|
|
3002
3271
|
const prefix = rootElement ? `/${rootElement}/` : "/";
|
|
3003
3272
|
const validationErrors = result.error.issues.map((issue) => {
|
|
3004
3273
|
const zodPath = issue.path.join("/");
|
|
3005
|
-
const
|
|
3274
|
+
const path3 = zodPath ? `${prefix}${zodPath}` : rootElement ? `/${rootElement}` : void 0;
|
|
3006
3275
|
return {
|
|
3007
3276
|
code: mapZodErrorCode(issue),
|
|
3008
3277
|
message: issue.message,
|
|
3009
|
-
path:
|
|
3278
|
+
path: path3
|
|
3010
3279
|
};
|
|
3011
3280
|
});
|
|
3012
3281
|
return { valid: false, schemaType, errors: validationErrors };
|
|
@@ -3046,9 +3315,9 @@ function validateBusinessRules(xml, _parsed) {
|
|
|
3046
3315
|
collectDateErrors(object, rootElement, errors);
|
|
3047
3316
|
return { valid: errors.length === 0, schemaType, errors };
|
|
3048
3317
|
}
|
|
3049
|
-
function collectNipPeselErrors(obj,
|
|
3318
|
+
function collectNipPeselErrors(obj, path3, errors) {
|
|
3050
3319
|
for (const [key, value] of Object.entries(obj)) {
|
|
3051
|
-
const currentPath =
|
|
3320
|
+
const currentPath = path3 ? `${path3}/${key}` : key;
|
|
3052
3321
|
if (key === "NIP" && typeof value === "string") {
|
|
3053
3322
|
if (!isValidNip(value)) {
|
|
3054
3323
|
errors.push({
|
|
@@ -3127,6 +3396,7 @@ function batchValidationDetails(batch) {
|
|
|
3127
3396
|
var init_invoice_validator = __esm({
|
|
3128
3397
|
"src/validation/invoice-validator.ts"() {
|
|
3129
3398
|
"use strict";
|
|
3399
|
+
init_cjs_shims();
|
|
3130
3400
|
init_xml_to_object();
|
|
3131
3401
|
init_schema_registry();
|
|
3132
3402
|
init_char_validity();
|
|
@@ -3139,6 +3409,7 @@ var SystemCode, FORM_CODES, DEFAULT_FORM_CODE, INVOICE_TYPES_BY_SYSTEM_CODE, FOR
|
|
|
3139
3409
|
var init_types = __esm({
|
|
3140
3410
|
"src/models/document-structures/types.ts"() {
|
|
3141
3411
|
"use strict";
|
|
3412
|
+
init_cjs_shims();
|
|
3142
3413
|
SystemCode = {
|
|
3143
3414
|
FA_2: "FA (2)",
|
|
3144
3415
|
FA_3: "FA (3)",
|
|
@@ -3191,6 +3462,7 @@ var SYSTEM_CODE_TO_FORM_CODE, ALL_FORM_CODES, BATCH_DISALLOWED_SYSTEM_CODES;
|
|
|
3191
3462
|
var init_helpers = __esm({
|
|
3192
3463
|
"src/models/document-structures/helpers.ts"() {
|
|
3193
3464
|
"use strict";
|
|
3465
|
+
init_cjs_shims();
|
|
3194
3466
|
init_types();
|
|
3195
3467
|
SYSTEM_CODE_TO_FORM_CODE = {
|
|
3196
3468
|
[SystemCode.FA_2]: FORM_CODES.FA_2,
|
|
@@ -3211,6 +3483,7 @@ var init_helpers = __esm({
|
|
|
3211
3483
|
var init_document_structures = __esm({
|
|
3212
3484
|
"src/models/document-structures/index.ts"() {
|
|
3213
3485
|
"use strict";
|
|
3486
|
+
init_cjs_shims();
|
|
3214
3487
|
init_types();
|
|
3215
3488
|
init_helpers();
|
|
3216
3489
|
}
|
|
@@ -3221,6 +3494,7 @@ var AuthService;
|
|
|
3221
3494
|
var init_auth = __esm({
|
|
3222
3495
|
"src/services/auth.ts"() {
|
|
3223
3496
|
"use strict";
|
|
3497
|
+
init_cjs_shims();
|
|
3224
3498
|
init_ksef_feature();
|
|
3225
3499
|
init_rest_request();
|
|
3226
3500
|
init_routes();
|
|
@@ -3271,6 +3545,7 @@ var ActiveSessionsService;
|
|
|
3271
3545
|
var init_active_sessions = __esm({
|
|
3272
3546
|
"src/services/active-sessions.ts"() {
|
|
3273
3547
|
"use strict";
|
|
3548
|
+
init_cjs_shims();
|
|
3274
3549
|
init_rest_request();
|
|
3275
3550
|
init_routes();
|
|
3276
3551
|
ActiveSessionsService = class {
|
|
@@ -3302,6 +3577,7 @@ var OnlineSessionService;
|
|
|
3302
3577
|
var init_online_session = __esm({
|
|
3303
3578
|
"src/services/online-session.ts"() {
|
|
3304
3579
|
"use strict";
|
|
3580
|
+
init_cjs_shims();
|
|
3305
3581
|
init_ksef_feature();
|
|
3306
3582
|
init_rest_request();
|
|
3307
3583
|
init_routes();
|
|
@@ -3354,6 +3630,7 @@ async function runWithConcurrency(tasks, parallelism) {
|
|
|
3354
3630
|
var init_concurrency = __esm({
|
|
3355
3631
|
"src/utils/concurrency.ts"() {
|
|
3356
3632
|
"use strict";
|
|
3633
|
+
init_cjs_shims();
|
|
3357
3634
|
}
|
|
3358
3635
|
});
|
|
3359
3636
|
|
|
@@ -3362,6 +3639,7 @@ var BatchSessionService;
|
|
|
3362
3639
|
var init_batch_session = __esm({
|
|
3363
3640
|
"src/services/batch-session.ts"() {
|
|
3364
3641
|
"use strict";
|
|
3642
|
+
init_cjs_shims();
|
|
3365
3643
|
init_ksef_feature();
|
|
3366
3644
|
init_rest_request();
|
|
3367
3645
|
init_routes();
|
|
@@ -3466,6 +3744,7 @@ var SessionStatusService;
|
|
|
3466
3744
|
var init_session_status = __esm({
|
|
3467
3745
|
"src/services/session-status.ts"() {
|
|
3468
3746
|
"use strict";
|
|
3747
|
+
init_cjs_shims();
|
|
3469
3748
|
init_rest_request();
|
|
3470
3749
|
init_routes();
|
|
3471
3750
|
SessionStatusService = class {
|
|
@@ -3552,6 +3831,7 @@ var InvoiceDownloadService;
|
|
|
3552
3831
|
var init_invoice_download = __esm({
|
|
3553
3832
|
"src/services/invoice-download.ts"() {
|
|
3554
3833
|
"use strict";
|
|
3834
|
+
init_cjs_shims();
|
|
3555
3835
|
init_rest_request();
|
|
3556
3836
|
init_routes();
|
|
3557
3837
|
InvoiceDownloadService = class {
|
|
@@ -3594,6 +3874,7 @@ var PermissionsService;
|
|
|
3594
3874
|
var init_permissions = __esm({
|
|
3595
3875
|
"src/services/permissions.ts"() {
|
|
3596
3876
|
"use strict";
|
|
3877
|
+
init_cjs_shims();
|
|
3597
3878
|
init_ksef_validation_error();
|
|
3598
3879
|
init_rest_request();
|
|
3599
3880
|
init_routes();
|
|
@@ -3786,6 +4067,7 @@ function parseKSeFTokenContext(token) {
|
|
|
3786
4067
|
var init_jwt = __esm({
|
|
3787
4068
|
"src/utils/jwt.ts"() {
|
|
3788
4069
|
"use strict";
|
|
4070
|
+
init_cjs_shims();
|
|
3789
4071
|
}
|
|
3790
4072
|
});
|
|
3791
4073
|
|
|
@@ -3797,6 +4079,7 @@ var TOKEN_AUTHOR_IDENTIFIER_TYPES, TokenService;
|
|
|
3797
4079
|
var init_tokens = __esm({
|
|
3798
4080
|
"src/services/tokens.ts"() {
|
|
3799
4081
|
"use strict";
|
|
4082
|
+
init_cjs_shims();
|
|
3800
4083
|
init_rest_request();
|
|
3801
4084
|
init_routes();
|
|
3802
4085
|
init_jwt();
|
|
@@ -3917,6 +4200,7 @@ var CertificateApiService;
|
|
|
3917
4200
|
var init_certificates = __esm({
|
|
3918
4201
|
"src/services/certificates.ts"() {
|
|
3919
4202
|
"use strict";
|
|
4203
|
+
init_cjs_shims();
|
|
3920
4204
|
init_rest_request();
|
|
3921
4205
|
init_routes();
|
|
3922
4206
|
CertificateApiService = class {
|
|
@@ -3969,6 +4253,7 @@ var LighthouseService;
|
|
|
3969
4253
|
var init_lighthouse = __esm({
|
|
3970
4254
|
"src/services/lighthouse.ts"() {
|
|
3971
4255
|
"use strict";
|
|
4256
|
+
init_cjs_shims();
|
|
3972
4257
|
init_errors();
|
|
3973
4258
|
LighthouseService = class {
|
|
3974
4259
|
lighthouseUrl;
|
|
@@ -3977,20 +4262,20 @@ var init_lighthouse = __esm({
|
|
|
3977
4262
|
this.lighthouseUrl = options.lighthouseUrl;
|
|
3978
4263
|
this.timeout = options.timeout;
|
|
3979
4264
|
}
|
|
3980
|
-
async fetchJson(
|
|
4265
|
+
async fetchJson(path3) {
|
|
3981
4266
|
if (!this.lighthouseUrl) {
|
|
3982
4267
|
throw new KSeFError(
|
|
3983
4268
|
"Lighthouse API is not available for the DEMO environment. Use TEST or PROD instead."
|
|
3984
4269
|
);
|
|
3985
4270
|
}
|
|
3986
|
-
const response = await fetch(`${this.lighthouseUrl}${
|
|
4271
|
+
const response = await fetch(`${this.lighthouseUrl}${path3}`, {
|
|
3987
4272
|
headers: { Accept: "application/json" },
|
|
3988
4273
|
signal: AbortSignal.timeout(this.timeout)
|
|
3989
4274
|
});
|
|
3990
4275
|
if (!response.ok) {
|
|
3991
4276
|
const body = await response.text();
|
|
3992
4277
|
throw new KSeFError(
|
|
3993
|
-
`Lighthouse ${
|
|
4278
|
+
`Lighthouse ${path3} failed: HTTP ${response.status} \u2014 ${body}`
|
|
3994
4279
|
);
|
|
3995
4280
|
}
|
|
3996
4281
|
return await response.json();
|
|
@@ -4011,6 +4296,7 @@ var LimitsService;
|
|
|
4011
4296
|
var init_limits = __esm({
|
|
4012
4297
|
"src/services/limits.ts"() {
|
|
4013
4298
|
"use strict";
|
|
4299
|
+
init_cjs_shims();
|
|
4014
4300
|
init_rest_request();
|
|
4015
4301
|
init_routes();
|
|
4016
4302
|
LimitsService = class {
|
|
@@ -4042,6 +4328,7 @@ var PeppolService;
|
|
|
4042
4328
|
var init_peppol = __esm({
|
|
4043
4329
|
"src/services/peppol.ts"() {
|
|
4044
4330
|
"use strict";
|
|
4331
|
+
init_cjs_shims();
|
|
4045
4332
|
init_rest_request();
|
|
4046
4333
|
init_routes();
|
|
4047
4334
|
PeppolService = class {
|
|
@@ -4065,6 +4352,7 @@ var TestDataService;
|
|
|
4065
4352
|
var init_test_data = __esm({
|
|
4066
4353
|
"src/services/test-data.ts"() {
|
|
4067
4354
|
"use strict";
|
|
4355
|
+
init_cjs_shims();
|
|
4068
4356
|
init_rest_request();
|
|
4069
4357
|
init_routes();
|
|
4070
4358
|
init_ksef_error();
|
|
@@ -4184,6 +4472,7 @@ var CertificateFetcher;
|
|
|
4184
4472
|
var init_certificate_fetcher = __esm({
|
|
4185
4473
|
"src/crypto/certificate-fetcher.ts"() {
|
|
4186
4474
|
"use strict";
|
|
4475
|
+
init_cjs_shims();
|
|
4187
4476
|
init_rest_request();
|
|
4188
4477
|
init_routes();
|
|
4189
4478
|
CertificateFetcher = class {
|
|
@@ -4277,7 +4566,8 @@ var crypto2, x509, CryptographyService;
|
|
|
4277
4566
|
var init_cryptography_service = __esm({
|
|
4278
4567
|
"src/crypto/cryptography-service.ts"() {
|
|
4279
4568
|
"use strict";
|
|
4280
|
-
|
|
4569
|
+
init_cjs_shims();
|
|
4570
|
+
crypto2 = __toESM(require("node:crypto"), 1);
|
|
4281
4571
|
x509 = __toESM(require("@peculiar/x509"), 1);
|
|
4282
4572
|
CryptographyService = class {
|
|
4283
4573
|
fetcher;
|
|
@@ -4336,7 +4626,7 @@ var init_cryptography_service = __esm({
|
|
|
4336
4626
|
const certPem = this.fetcher.getSymmetricKeyEncryptionPem();
|
|
4337
4627
|
const encryptedKey = crypto2.publicEncrypt(
|
|
4338
4628
|
{
|
|
4339
|
-
key: certPem,
|
|
4629
|
+
key: this.extractSpkiPem(certPem),
|
|
4340
4630
|
oaepHash: "sha256",
|
|
4341
4631
|
padding: crypto2.constants.RSA_PKCS1_OAEP_PADDING
|
|
4342
4632
|
},
|
|
@@ -4466,12 +4756,22 @@ var init_cryptography_service = __esm({
|
|
|
4466
4756
|
// ---------------------------------------------------------------------------
|
|
4467
4757
|
// Private helpers
|
|
4468
4758
|
// ---------------------------------------------------------------------------
|
|
4759
|
+
/**
|
|
4760
|
+
* Extract a public-key SPKI PEM (`-----BEGIN PUBLIC KEY-----`) from a full
|
|
4761
|
+
* CERTIFICATE PEM. Node's `publicEncrypt` accepts either form, but Deno's
|
|
4762
|
+
* Node compatibility layer only accepts SPKI PEM, so we normalize upfront
|
|
4763
|
+
* to keep the library portable across runtimes.
|
|
4764
|
+
*/
|
|
4765
|
+
extractSpkiPem(certPem) {
|
|
4766
|
+
const publicKey = new crypto2.X509Certificate(certPem).publicKey;
|
|
4767
|
+
return publicKey.export({ type: "spki", format: "pem" });
|
|
4768
|
+
}
|
|
4469
4769
|
/** RSA-OAEP SHA-256 encryption. */
|
|
4470
4770
|
encryptRsaOaep(certPem, plaintext) {
|
|
4471
4771
|
return new Uint8Array(
|
|
4472
4772
|
crypto2.publicEncrypt(
|
|
4473
4773
|
{
|
|
4474
|
-
key: certPem,
|
|
4774
|
+
key: this.extractSpkiPem(certPem),
|
|
4475
4775
|
oaepHash: "sha256",
|
|
4476
4776
|
padding: crypto2.constants.RSA_PKCS1_OAEP_PADDING
|
|
4477
4777
|
},
|
|
@@ -4513,6 +4813,40 @@ var signature_service_exports = {};
|
|
|
4513
4813
|
__export(signature_service_exports, {
|
|
4514
4814
|
SignatureService: () => SignatureService
|
|
4515
4815
|
});
|
|
4816
|
+
function pickRsaAlgo() {
|
|
4817
|
+
return {
|
|
4818
|
+
nodeHashName: "sha256",
|
|
4819
|
+
signatureUri: RSA_SHA256_SIGNATURE_URI,
|
|
4820
|
+
digestUri: DIGEST_URI.sha256
|
|
4821
|
+
};
|
|
4822
|
+
}
|
|
4823
|
+
function pickEcdsaAlgo(privateKey) {
|
|
4824
|
+
const curve = privateKey.asymmetricKeyDetails?.namedCurve;
|
|
4825
|
+
switch (curve) {
|
|
4826
|
+
case "prime256v1":
|
|
4827
|
+
return {
|
|
4828
|
+
nodeHashName: "sha256",
|
|
4829
|
+
signatureUri: ECDSA_SIGNATURE_URI.sha256,
|
|
4830
|
+
digestUri: DIGEST_URI.sha256
|
|
4831
|
+
};
|
|
4832
|
+
case "secp384r1":
|
|
4833
|
+
return {
|
|
4834
|
+
nodeHashName: "sha384",
|
|
4835
|
+
signatureUri: ECDSA_SIGNATURE_URI.sha384,
|
|
4836
|
+
digestUri: DIGEST_URI.sha384
|
|
4837
|
+
};
|
|
4838
|
+
case "secp521r1":
|
|
4839
|
+
return {
|
|
4840
|
+
nodeHashName: "sha512",
|
|
4841
|
+
signatureUri: ECDSA_SIGNATURE_URI.sha512,
|
|
4842
|
+
digestUri: DIGEST_URI.sha512
|
|
4843
|
+
};
|
|
4844
|
+
default:
|
|
4845
|
+
throw new KSeFError(
|
|
4846
|
+
`Unsupported ECDSA curve: ${curve ?? "unknown"}. Supported: P-256 (prime256v1), P-384 (secp384r1), P-521 (secp521r1).`
|
|
4847
|
+
);
|
|
4848
|
+
}
|
|
4849
|
+
}
|
|
4516
4850
|
function extractDerFromPem(pem) {
|
|
4517
4851
|
const base64 = pem.replace(/-----BEGIN [A-Z\s]+-----/g, "").replace(/-----END [A-Z\s]+-----/g, "").replace(/\s+/g, "");
|
|
4518
4852
|
return Buffer.from(base64, "base64");
|
|
@@ -4527,12 +4861,12 @@ function canonicalize(elem) {
|
|
|
4527
4861
|
const c14n = new import_xml_crypto.ExclusiveCanonicalization();
|
|
4528
4862
|
return c14n.process(elem, {});
|
|
4529
4863
|
}
|
|
4530
|
-
function computeRootDigest(doc) {
|
|
4864
|
+
function computeRootDigest(doc, hashName) {
|
|
4531
4865
|
const root = doc.documentElement;
|
|
4532
4866
|
const canonical = canonicalize(root);
|
|
4533
|
-
return crypto3.createHash(
|
|
4867
|
+
return crypto3.createHash(hashName).update(canonical, "utf-8").digest("base64");
|
|
4534
4868
|
}
|
|
4535
|
-
function computeSignedPropertiesDigest(qualifyingPropertiesXml) {
|
|
4869
|
+
function computeSignedPropertiesDigest(qualifyingPropertiesXml, hashName) {
|
|
4536
4870
|
const parser2 = new import_xmldom2.DOMParser();
|
|
4537
4871
|
const qpDoc = parser2.parseFromString(qualifyingPropertiesXml, "text/xml");
|
|
4538
4872
|
const signedProps = findElementByLocalName(qpDoc.documentElement, "SignedProperties");
|
|
@@ -4540,9 +4874,9 @@ function computeSignedPropertiesDigest(qualifyingPropertiesXml) {
|
|
|
4540
4874
|
throw new Error("SignedProperties element not found in QualifyingProperties");
|
|
4541
4875
|
}
|
|
4542
4876
|
const canonical = canonicalize(signedProps);
|
|
4543
|
-
return crypto3.createHash(
|
|
4877
|
+
return crypto3.createHash(hashName).update(canonical, "utf-8").digest("base64");
|
|
4544
4878
|
}
|
|
4545
|
-
function buildSignedInfo(signatureAlgorithm, rootDigest, signedPropertiesDigest) {
|
|
4879
|
+
function buildSignedInfo(signatureAlgorithm, digestAlgorithm, rootDigest, signedPropertiesDigest) {
|
|
4546
4880
|
return [
|
|
4547
4881
|
`<ds:SignedInfo xmlns:ds="${DS_NS}">`,
|
|
4548
4882
|
`<ds:CanonicalizationMethod Algorithm="${EXC_C14N_ALGORITHM}"/>`,
|
|
@@ -4553,7 +4887,7 @@ function buildSignedInfo(signatureAlgorithm, rootDigest, signedPropertiesDigest)
|
|
|
4553
4887
|
`<ds:Transform Algorithm="${ENVELOPED_SIGNATURE_TRANSFORM}"/>`,
|
|
4554
4888
|
`<ds:Transform Algorithm="${EXC_C14N_ALGORITHM}"/>`,
|
|
4555
4889
|
`</ds:Transforms>`,
|
|
4556
|
-
`<ds:DigestMethod Algorithm="${
|
|
4890
|
+
`<ds:DigestMethod Algorithm="${digestAlgorithm}"/>`,
|
|
4557
4891
|
`<ds:DigestValue>${rootDigest}</ds:DigestValue>`,
|
|
4558
4892
|
`</ds:Reference>`,
|
|
4559
4893
|
// Reference 2: SignedProperties
|
|
@@ -4561,22 +4895,22 @@ function buildSignedInfo(signatureAlgorithm, rootDigest, signedPropertiesDigest)
|
|
|
4561
4895
|
`<ds:Transforms>`,
|
|
4562
4896
|
`<ds:Transform Algorithm="${EXC_C14N_ALGORITHM}"/>`,
|
|
4563
4897
|
`</ds:Transforms>`,
|
|
4564
|
-
`<ds:DigestMethod Algorithm="${
|
|
4898
|
+
`<ds:DigestMethod Algorithm="${digestAlgorithm}"/>`,
|
|
4565
4899
|
`<ds:DigestValue>${signedPropertiesDigest}</ds:DigestValue>`,
|
|
4566
4900
|
`</ds:Reference>`,
|
|
4567
4901
|
`</ds:SignedInfo>`
|
|
4568
4902
|
].join("");
|
|
4569
4903
|
}
|
|
4570
|
-
function computeSignatureValue(canonicalSignedInfo, privateKey, isEc) {
|
|
4904
|
+
function computeSignatureValue(canonicalSignedInfo, privateKey, isEc, hashName) {
|
|
4571
4905
|
const data = Buffer.from(canonicalSignedInfo, "utf-8");
|
|
4572
4906
|
let signature;
|
|
4573
4907
|
if (isEc) {
|
|
4574
|
-
signature = crypto3.sign(
|
|
4908
|
+
signature = crypto3.sign(hashName, data, {
|
|
4575
4909
|
key: privateKey,
|
|
4576
4910
|
dsaEncoding: "ieee-p1363"
|
|
4577
4911
|
});
|
|
4578
4912
|
} else {
|
|
4579
|
-
signature = crypto3.sign(
|
|
4913
|
+
signature = crypto3.sign(hashName, data, privateKey);
|
|
4580
4914
|
}
|
|
4581
4915
|
return signature.toString("base64");
|
|
4582
4916
|
}
|
|
@@ -4597,7 +4931,7 @@ function buildSignatureElement(signedInfoXml, signatureValue, certBase64, qualif
|
|
|
4597
4931
|
`</ds:Signature>`
|
|
4598
4932
|
].join("");
|
|
4599
4933
|
}
|
|
4600
|
-
function buildQualifyingProperties(signatureId, signedPropertiesId, certDigest, issuerName, serialNumber, signingTime) {
|
|
4934
|
+
function buildQualifyingProperties(signatureId, signedPropertiesId, certDigest, issuerName, serialNumber, signingTime, digestAlgorithm) {
|
|
4601
4935
|
return [
|
|
4602
4936
|
`<xades:QualifyingProperties`,
|
|
4603
4937
|
` Target="#${signatureId}"`,
|
|
@@ -4609,7 +4943,7 @@ function buildQualifyingProperties(signatureId, signedPropertiesId, certDigest,
|
|
|
4609
4943
|
`<xades:SigningCertificate>`,
|
|
4610
4944
|
`<xades:Cert>`,
|
|
4611
4945
|
`<xades:CertDigest>`,
|
|
4612
|
-
`<DigestMethod Algorithm="${
|
|
4946
|
+
`<DigestMethod Algorithm="${digestAlgorithm}"/>`,
|
|
4613
4947
|
`<DigestValue>${certDigest}</DigestValue>`,
|
|
4614
4948
|
`</xades:CertDigest>`,
|
|
4615
4949
|
`<xades:IssuerSerial>`,
|
|
@@ -4645,21 +4979,31 @@ function wrapBase64(base64) {
|
|
|
4645
4979
|
}
|
|
4646
4980
|
return lines.join("\n");
|
|
4647
4981
|
}
|
|
4648
|
-
var crypto3, import_xml_crypto, import_xmldom2, XADES_NS, DS_NS, SIGNED_PROPERTIES_TYPE,
|
|
4982
|
+
var crypto3, import_xml_crypto, import_xmldom2, XADES_NS, DS_NS, SIGNED_PROPERTIES_TYPE, EXC_C14N_ALGORITHM, ENVELOPED_SIGNATURE_TRANSFORM, DIGEST_URI, ECDSA_SIGNATURE_URI, RSA_SHA256_SIGNATURE_URI, CLOCK_SKEW_BUFFER_MS, SIGNATURE_ID, SIGNED_PROPERTIES_ID, SignatureService;
|
|
4649
4983
|
var init_signature_service = __esm({
|
|
4650
4984
|
"src/crypto/signature-service.ts"() {
|
|
4651
4985
|
"use strict";
|
|
4652
|
-
|
|
4986
|
+
init_cjs_shims();
|
|
4987
|
+
crypto3 = __toESM(require("node:crypto"), 1);
|
|
4653
4988
|
import_xml_crypto = require("xml-crypto");
|
|
4654
4989
|
import_xmldom2 = require("@xmldom/xmldom");
|
|
4990
|
+
init_ksef_error();
|
|
4655
4991
|
XADES_NS = "http://uri.etsi.org/01903/v1.3.2#";
|
|
4656
4992
|
DS_NS = "http://www.w3.org/2000/09/xmldsig#";
|
|
4657
4993
|
SIGNED_PROPERTIES_TYPE = "http://uri.etsi.org/01903#SignedProperties";
|
|
4658
|
-
SHA256_DIGEST_METHOD = "http://www.w3.org/2001/04/xmlenc#sha256";
|
|
4659
4994
|
EXC_C14N_ALGORITHM = "http://www.w3.org/2001/10/xml-exc-c14n#";
|
|
4660
4995
|
ENVELOPED_SIGNATURE_TRANSFORM = "http://www.w3.org/2000/09/xmldsig#enveloped-signature";
|
|
4661
|
-
|
|
4662
|
-
|
|
4996
|
+
DIGEST_URI = {
|
|
4997
|
+
sha256: "http://www.w3.org/2001/04/xmlenc#sha256",
|
|
4998
|
+
sha384: "http://www.w3.org/2001/04/xmldsig-more#sha384",
|
|
4999
|
+
sha512: "http://www.w3.org/2001/04/xmlenc#sha512"
|
|
5000
|
+
};
|
|
5001
|
+
ECDSA_SIGNATURE_URI = {
|
|
5002
|
+
sha256: "http://www.w3.org/2001/04/xmldsig-more#ecdsa-sha256",
|
|
5003
|
+
sha384: "http://www.w3.org/2001/04/xmldsig-more#ecdsa-sha384",
|
|
5004
|
+
sha512: "http://www.w3.org/2001/04/xmldsig-more#ecdsa-sha512"
|
|
5005
|
+
};
|
|
5006
|
+
RSA_SHA256_SIGNATURE_URI = "http://www.w3.org/2001/04/xmldsig-more#rsa-sha256";
|
|
4663
5007
|
CLOCK_SKEW_BUFFER_MS = -6e4;
|
|
4664
5008
|
SIGNATURE_ID = "Signature";
|
|
4665
5009
|
SIGNED_PROPERTIES_ID = "SignedProperties";
|
|
@@ -4679,15 +5023,21 @@ var init_signature_service = __esm({
|
|
|
4679
5023
|
}
|
|
4680
5024
|
const certDer = extractDerFromPem(certPem);
|
|
4681
5025
|
const certBase64 = certDer.toString("base64");
|
|
4682
|
-
const certDigest = crypto3.createHash("sha256").update(certDer).digest("base64");
|
|
4683
5026
|
const x5093 = new crypto3.X509Certificate(certPem);
|
|
4684
5027
|
const issuerName = normalizeIssuerDn(x5093.issuer);
|
|
4685
5028
|
const serialNumber = hexSerialToDecimal(x5093.serialNumber);
|
|
4686
5029
|
const privateKey = crypto3.createPrivateKey(
|
|
4687
5030
|
passphrase ? { key: privateKeyPem, format: "pem", passphrase } : privateKeyPem
|
|
4688
5031
|
);
|
|
4689
|
-
const
|
|
4690
|
-
|
|
5032
|
+
const keyType = privateKey.asymmetricKeyType;
|
|
5033
|
+
if (keyType !== "ec" && keyType !== "rsa") {
|
|
5034
|
+
throw new KSeFError(
|
|
5035
|
+
`Unsupported private key type: ${keyType ?? "unknown"}. Supported: RSA and ECDSA.`
|
|
5036
|
+
);
|
|
5037
|
+
}
|
|
5038
|
+
const isEc = keyType === "ec";
|
|
5039
|
+
const algo = isEc ? pickEcdsaAlgo(privateKey) : pickRsaAlgo();
|
|
5040
|
+
const certDigest = crypto3.createHash(algo.nodeHashName).update(certDer).digest("base64");
|
|
4691
5041
|
const signingTime = new Date(Date.now() + CLOCK_SKEW_BUFFER_MS).toISOString();
|
|
4692
5042
|
const parser2 = new import_xmldom2.DOMParser();
|
|
4693
5043
|
const doc = parser2.parseFromString(xml, "text/xml");
|
|
@@ -4701,12 +5051,17 @@ var init_signature_service = __esm({
|
|
|
4701
5051
|
certDigest,
|
|
4702
5052
|
issuerName,
|
|
4703
5053
|
serialNumber,
|
|
4704
|
-
signingTime
|
|
5054
|
+
signingTime,
|
|
5055
|
+
algo.digestUri
|
|
5056
|
+
);
|
|
5057
|
+
const rootDigest = computeRootDigest(doc, algo.nodeHashName);
|
|
5058
|
+
const signedPropertiesDigest = computeSignedPropertiesDigest(
|
|
5059
|
+
qualifyingPropertiesXml,
|
|
5060
|
+
algo.nodeHashName
|
|
4705
5061
|
);
|
|
4706
|
-
const rootDigest = computeRootDigest(doc);
|
|
4707
|
-
const signedPropertiesDigest = computeSignedPropertiesDigest(qualifyingPropertiesXml);
|
|
4708
5062
|
const signedInfoXml = buildSignedInfo(
|
|
4709
|
-
|
|
5063
|
+
algo.signatureUri,
|
|
5064
|
+
algo.digestUri,
|
|
4710
5065
|
rootDigest,
|
|
4711
5066
|
signedPropertiesDigest
|
|
4712
5067
|
);
|
|
@@ -4715,7 +5070,8 @@ var init_signature_service = __esm({
|
|
|
4715
5070
|
const signatureValue = computeSignatureValue(
|
|
4716
5071
|
canonicalSignedInfo,
|
|
4717
5072
|
privateKey,
|
|
4718
|
-
isEc
|
|
5073
|
+
isEc,
|
|
5074
|
+
algo.nodeHashName
|
|
4719
5075
|
);
|
|
4720
5076
|
const signatureXml = buildSignatureElement(
|
|
4721
5077
|
signedInfoXml,
|
|
@@ -4741,6 +5097,7 @@ var import_node_forge, Pkcs12Loader;
|
|
|
4741
5097
|
var init_pkcs12_loader = __esm({
|
|
4742
5098
|
"src/crypto/pkcs12-loader.ts"() {
|
|
4743
5099
|
"use strict";
|
|
5100
|
+
init_cjs_shims();
|
|
4744
5101
|
import_node_forge = __toESM(require("node-forge"), 1);
|
|
4745
5102
|
Pkcs12Loader = class {
|
|
4746
5103
|
static load(p12, password) {
|
|
@@ -4810,6 +5167,7 @@ var AUTH_TOKEN_REQUEST_NS;
|
|
|
4810
5167
|
var init_auth_xml_builder = __esm({
|
|
4811
5168
|
"src/crypto/auth-xml-builder.ts"() {
|
|
4812
5169
|
"use strict";
|
|
5170
|
+
init_cjs_shims();
|
|
4813
5171
|
AUTH_TOKEN_REQUEST_NS = "http://ksef.mf.gov.pl/auth/token/2.0";
|
|
4814
5172
|
}
|
|
4815
5173
|
});
|
|
@@ -4819,7 +5177,8 @@ var import_node_crypto, VerificationLinkService;
|
|
|
4819
5177
|
var init_verification_link_service = __esm({
|
|
4820
5178
|
"src/qr/verification-link-service.ts"() {
|
|
4821
5179
|
"use strict";
|
|
4822
|
-
|
|
5180
|
+
init_cjs_shims();
|
|
5181
|
+
import_node_crypto = __toESM(require("node:crypto"), 1);
|
|
4823
5182
|
VerificationLinkService = class {
|
|
4824
5183
|
constructor(baseQrUrl) {
|
|
4825
5184
|
this.baseQrUrl = baseQrUrl;
|
|
@@ -4841,11 +5200,11 @@ var init_verification_link_service = __esm({
|
|
|
4841
5200
|
* Build certificate verification URL (Code II).
|
|
4842
5201
|
* Format: {baseQrUrl}/certificate/{contextType}/{contextId}/{sellerNip}/{certSerial}/{hash_base64url}/{signature_base64url}
|
|
4843
5202
|
*/
|
|
4844
|
-
buildCertificateVerificationUrl(contextType, contextId, sellerNip, certSerial, invoiceHashBase64, privateKeyPem) {
|
|
5203
|
+
buildCertificateVerificationUrl(contextType, contextId, sellerNip, certSerial, invoiceHashBase64, privateKeyPem, privateKeyPassword) {
|
|
4845
5204
|
const hashBase64Url = this.base64ToBase64Url(invoiceHashBase64);
|
|
4846
5205
|
const pathWithoutSignature = `${this.baseQrUrl}/certificate/${contextType}/${contextId}/${sellerNip}/${certSerial}/${hashBase64Url}`;
|
|
4847
5206
|
const dataToSign = pathWithoutSignature.replace(/^https?:\/\//, "");
|
|
4848
|
-
const key = import_node_crypto.default.createPrivateKey(privateKeyPem);
|
|
5207
|
+
const key = privateKeyPassword !== void 0 ? import_node_crypto.default.createPrivateKey({ key: privateKeyPem, format: "pem", passphrase: privateKeyPassword }) : import_node_crypto.default.createPrivateKey(privateKeyPem);
|
|
4849
5208
|
let signature;
|
|
4850
5209
|
if (key.asymmetricKeyType === "rsa") {
|
|
4851
5210
|
signature = import_node_crypto.default.sign("sha256", Buffer.from(dataToSign), {
|
|
@@ -4959,6 +5318,7 @@ var import_yazl, import_yauzl, DEFAULT_UNZIP_OPTIONS;
|
|
|
4959
5318
|
var init_zip = __esm({
|
|
4960
5319
|
"src/utils/zip.ts"() {
|
|
4961
5320
|
"use strict";
|
|
5321
|
+
init_cjs_shims();
|
|
4962
5322
|
import_yazl = require("yazl");
|
|
4963
5323
|
import_yauzl = require("yauzl");
|
|
4964
5324
|
DEFAULT_UNZIP_OPTIONS = {
|
|
@@ -5032,6 +5392,7 @@ var holidayCache;
|
|
|
5032
5392
|
var init_holidays = __esm({
|
|
5033
5393
|
"src/offline/holidays.ts"() {
|
|
5034
5394
|
"use strict";
|
|
5395
|
+
init_cjs_shims();
|
|
5035
5396
|
holidayCache = /* @__PURE__ */ new Map();
|
|
5036
5397
|
}
|
|
5037
5398
|
});
|
|
@@ -5131,6 +5492,7 @@ var FAR_FUTURE;
|
|
|
5131
5492
|
var init_deadline = __esm({
|
|
5132
5493
|
"src/offline/deadline.ts"() {
|
|
5133
5494
|
"use strict";
|
|
5495
|
+
init_cjs_shims();
|
|
5134
5496
|
init_holidays();
|
|
5135
5497
|
FAR_FUTURE = /* @__PURE__ */ new Date("9999-12-31T23:59:59Z");
|
|
5136
5498
|
}
|
|
@@ -5141,7 +5503,8 @@ var import_node_crypto3, OfflineInvoiceWorkflow;
|
|
|
5141
5503
|
var init_offline_invoice_workflow = __esm({
|
|
5142
5504
|
"src/workflows/offline-invoice-workflow.ts"() {
|
|
5143
5505
|
"use strict";
|
|
5144
|
-
|
|
5506
|
+
init_cjs_shims();
|
|
5507
|
+
import_node_crypto3 = __toESM(require("node:crypto"), 1);
|
|
5145
5508
|
init_ksef_api_error();
|
|
5146
5509
|
init_deadline();
|
|
5147
5510
|
init_document_structures();
|
|
@@ -5175,7 +5538,8 @@ var init_offline_invoice_workflow = __esm({
|
|
|
5175
5538
|
input.sellerNip,
|
|
5176
5539
|
options.certificate.certificateSerial,
|
|
5177
5540
|
invoiceHashBase64,
|
|
5178
|
-
options.certificate.privateKeyPem
|
|
5541
|
+
options.certificate.privateKeyPem,
|
|
5542
|
+
options.certificate.password
|
|
5179
5543
|
);
|
|
5180
5544
|
}
|
|
5181
5545
|
const submitBy = options?.customDeadline ? typeof options.customDeadline === "string" ? options.customDeadline : options.customDeadline.toISOString() : calculateOfflineDeadline(mode, input.invoiceDate, options?.maintenanceWindow).toISOString();
|
|
@@ -5365,7 +5729,8 @@ var init_offline_invoice_workflow = __esm({
|
|
|
5365
5729
|
original.sellerNip,
|
|
5366
5730
|
options.certificate.certificateSerial,
|
|
5367
5731
|
correctedHashBase64,
|
|
5368
|
-
options.certificate.privateKeyPem
|
|
5732
|
+
options.certificate.privateKeyPem,
|
|
5733
|
+
options.certificate.password
|
|
5369
5734
|
);
|
|
5370
5735
|
}
|
|
5371
5736
|
const correctionMetadata = {
|
|
@@ -5451,6 +5816,11 @@ function buildRestClientConfig(options, authManager) {
|
|
|
5451
5816
|
endpointLimits: options.rateLimit.endpointLimits
|
|
5452
5817
|
});
|
|
5453
5818
|
}
|
|
5819
|
+
if (options?.circuitBreaker === null) {
|
|
5820
|
+
config.circuitBreakerPolicy = null;
|
|
5821
|
+
} else if (options?.circuitBreaker) {
|
|
5822
|
+
config.circuitBreakerPolicy = new CircuitBreakerPolicy(options.circuitBreaker);
|
|
5823
|
+
}
|
|
5454
5824
|
if (options?.presignedUrlHosts) {
|
|
5455
5825
|
const base = defaultPresignedUrlPolicy();
|
|
5456
5826
|
config.presignedUrlPolicy = {
|
|
@@ -5464,10 +5834,12 @@ var KSeFClient;
|
|
|
5464
5834
|
var init_client = __esm({
|
|
5465
5835
|
"src/client.ts"() {
|
|
5466
5836
|
"use strict";
|
|
5837
|
+
init_cjs_shims();
|
|
5467
5838
|
init_config();
|
|
5468
5839
|
init_rest_client();
|
|
5469
5840
|
init_retry_policy();
|
|
5470
5841
|
init_rate_limit_policy();
|
|
5842
|
+
init_circuit_breaker_policy();
|
|
5471
5843
|
init_presigned_url_policy();
|
|
5472
5844
|
init_auth_manager();
|
|
5473
5845
|
init_auth();
|
|
@@ -5621,6 +5993,7 @@ __export(index_exports, {
|
|
|
5621
5993
|
CertificateFingerprint: () => CertificateFingerprint,
|
|
5622
5994
|
CertificateName: () => CertificateName,
|
|
5623
5995
|
CertificateService: () => CertificateService,
|
|
5996
|
+
CircuitBreakerPolicy: () => CircuitBreakerPolicy,
|
|
5624
5997
|
CryptographyService: () => CryptographyService,
|
|
5625
5998
|
DEFAULT_FORM_CODE: () => DEFAULT_FORM_CODE,
|
|
5626
5999
|
DISCOURAGED_UNICODE_RANGES: () => DISCOURAGED_UNICODE_RANGES,
|
|
@@ -5630,6 +6003,7 @@ __export(index_exports, {
|
|
|
5630
6003
|
EntityPermissionGrantBuilder: () => EntityPermissionGrantBuilder,
|
|
5631
6004
|
Environment: () => Environment,
|
|
5632
6005
|
FAKTURA_NAMESPACE: () => FAKTURA_NAMESPACE,
|
|
6006
|
+
FA_XSD_PATHS: () => FA_XSD_PATHS,
|
|
5633
6007
|
FORM_CODES: () => FORM_CODES,
|
|
5634
6008
|
FORM_CODE_KEYS: () => FORM_CODE_KEYS,
|
|
5635
6009
|
FileHwmStore: () => FileHwmStore,
|
|
@@ -5648,6 +6022,7 @@ __export(index_exports, {
|
|
|
5648
6022
|
KSeFAuthStatusError: () => KSeFAuthStatusError,
|
|
5649
6023
|
KSeFBadRequestError: () => KSeFBadRequestError,
|
|
5650
6024
|
KSeFBatchTimeoutError: () => KSeFBatchTimeoutError,
|
|
6025
|
+
KSeFCircuitOpenError: () => KSeFCircuitOpenError,
|
|
5651
6026
|
KSeFClient: () => KSeFClient,
|
|
5652
6027
|
KSeFError: () => KSeFError,
|
|
5653
6028
|
KSeFErrorCode: () => KSeFErrorCode,
|
|
@@ -5657,6 +6032,7 @@ __export(index_exports, {
|
|
|
5657
6032
|
KSeFSessionExpiredError: () => KSeFSessionExpiredError,
|
|
5658
6033
|
KSeFUnauthorizedError: () => KSeFUnauthorizedError,
|
|
5659
6034
|
KSeFValidationError: () => KSeFValidationError,
|
|
6035
|
+
KSeFXsdValidationError: () => KSeFXsdValidationError,
|
|
5660
6036
|
KsefNumber: () => KsefNumber,
|
|
5661
6037
|
KsefNumberV35: () => KsefNumberV35,
|
|
5662
6038
|
KsefNumberV36: () => KsefNumberV36,
|
|
@@ -5668,6 +6044,7 @@ __export(index_exports, {
|
|
|
5668
6044
|
OfflineInvoiceWorkflow: () => OfflineInvoiceWorkflow,
|
|
5669
6045
|
OnlineSessionService: () => OnlineSessionService,
|
|
5670
6046
|
PEF_NAMESPACE: () => PEF_NAMESPACE,
|
|
6047
|
+
PEF_XSD_PATHS: () => PEF_XSD_PATHS,
|
|
5671
6048
|
PERMISSION_DESCRIPTION_MAX_LENGTH: () => PERMISSION_DESCRIPTION_MAX_LENGTH,
|
|
5672
6049
|
PERMISSION_DESCRIPTION_MIN_LENGTH: () => PERMISSION_DESCRIPTION_MIN_LENGTH,
|
|
5673
6050
|
PeppolId: () => PeppolId,
|
|
@@ -5715,6 +6092,7 @@ __export(index_exports, {
|
|
|
5715
6092
|
createZip: () => createZip,
|
|
5716
6093
|
decodeJwtPayload: () => decodeJwtPayload,
|
|
5717
6094
|
deduplicateByKsefNumber: () => deduplicateByKsefNumber,
|
|
6095
|
+
defaultCircuitBreakerPolicy: () => defaultCircuitBreakerPolicy,
|
|
5718
6096
|
defaultPresignedUrlPolicy: () => defaultPresignedUrlPolicy,
|
|
5719
6097
|
defaultRateLimitPolicy: () => defaultRateLimitPolicy,
|
|
5720
6098
|
defaultRetryPolicy: () => defaultRetryPolicy,
|
|
@@ -5751,6 +6129,7 @@ __export(index_exports, {
|
|
|
5751
6129
|
isValidReferenceNumber: () => isValidReferenceNumber,
|
|
5752
6130
|
isValidSha256Base64: () => isValidSha256Base64,
|
|
5753
6131
|
isValidVatUe: () => isValidVatUe,
|
|
6132
|
+
libxmljsAvailable: () => libxmljsAvailable,
|
|
5754
6133
|
nextBusinessDay: () => nextBusinessDay,
|
|
5755
6134
|
openOnlineSession: () => openOnlineSession,
|
|
5756
6135
|
openSendAndClose: () => openSendAndClose,
|
|
@@ -5762,6 +6141,7 @@ __export(index_exports, {
|
|
|
5762
6141
|
parseXml: () => parseXml,
|
|
5763
6142
|
pollUntil: () => pollUntil,
|
|
5764
6143
|
resolveOptions: () => resolveOptions,
|
|
6144
|
+
resolveXsdFor: () => resolveXsdFor,
|
|
5765
6145
|
resumeOnlineSession: () => resumeOnlineSession,
|
|
5766
6146
|
runWithConcurrency: () => runWithConcurrency,
|
|
5767
6147
|
serializeInvoiceXml: () => serializeInvoiceXml,
|
|
@@ -5776,6 +6156,7 @@ __export(index_exports, {
|
|
|
5776
6156
|
uploadBatchStream: () => uploadBatchStream,
|
|
5777
6157
|
uploadBatchStreamParsed: () => uploadBatchStreamParsed,
|
|
5778
6158
|
validate: () => validate,
|
|
6159
|
+
validateAgainstXsd: () => validateAgainstXsd,
|
|
5779
6160
|
validateBatch: () => validateBatch,
|
|
5780
6161
|
validateBusinessRules: () => validateBusinessRules,
|
|
5781
6162
|
validateCharValidity: () => validateCharValidity,
|
|
@@ -5787,10 +6168,12 @@ __export(index_exports, {
|
|
|
5787
6168
|
xmlToObject: () => xmlToObject
|
|
5788
6169
|
});
|
|
5789
6170
|
module.exports = __toCommonJS(index_exports);
|
|
6171
|
+
init_cjs_shims();
|
|
5790
6172
|
init_config();
|
|
5791
6173
|
init_errors();
|
|
5792
6174
|
|
|
5793
6175
|
// src/http/index.ts
|
|
6176
|
+
init_cjs_shims();
|
|
5794
6177
|
init_route_builder();
|
|
5795
6178
|
init_rest_request();
|
|
5796
6179
|
init_rest_client();
|
|
@@ -5798,14 +6181,17 @@ init_routes();
|
|
|
5798
6181
|
init_transport();
|
|
5799
6182
|
init_retry_policy();
|
|
5800
6183
|
init_rate_limit_policy();
|
|
6184
|
+
init_circuit_breaker_policy();
|
|
5801
6185
|
init_auth_manager();
|
|
5802
6186
|
init_presigned_url_policy();
|
|
5803
6187
|
init_ksef_feature();
|
|
5804
6188
|
|
|
5805
6189
|
// src/validation/index.ts
|
|
6190
|
+
init_cjs_shims();
|
|
5806
6191
|
init_patterns();
|
|
5807
6192
|
|
|
5808
6193
|
// src/validation/constraints.ts
|
|
6194
|
+
init_cjs_shims();
|
|
5809
6195
|
var REQUIRED_CHALLENGE_LENGTH = 36;
|
|
5810
6196
|
var CERTIFICATE_NAME_MIN_LENGTH = 5;
|
|
5811
6197
|
var CERTIFICATE_NAME_MAX_LENGTH = 100;
|
|
@@ -5820,10 +6206,218 @@ init_schema_registry();
|
|
|
5820
6206
|
init_invoice_validator();
|
|
5821
6207
|
init_char_validity();
|
|
5822
6208
|
|
|
6209
|
+
// src/validation/xsd-validator.ts
|
|
6210
|
+
init_cjs_shims();
|
|
6211
|
+
var import_node_module = require("node:module");
|
|
6212
|
+
var fs = __toESM(require("node:fs"), 1);
|
|
6213
|
+
var path = __toESM(require("node:path"), 1);
|
|
6214
|
+
var import_node_url = require("node:url");
|
|
6215
|
+
var cachedPkgRoot = null;
|
|
6216
|
+
function locatePackageRoot() {
|
|
6217
|
+
if (cachedPkgRoot !== null) return cachedPkgRoot;
|
|
6218
|
+
let dir = path.dirname((0, import_node_url.fileURLToPath)(importMetaUrl));
|
|
6219
|
+
const root = path.parse(dir).root;
|
|
6220
|
+
while (dir !== root) {
|
|
6221
|
+
const candidate = path.join(dir, "docs", "schemas");
|
|
6222
|
+
if (fs.existsSync(candidate)) {
|
|
6223
|
+
cachedPkgRoot = dir;
|
|
6224
|
+
return dir;
|
|
6225
|
+
}
|
|
6226
|
+
dir = path.dirname(dir);
|
|
6227
|
+
}
|
|
6228
|
+
throw new Error("Could not locate ksef-client-ts package root (docs/schemas not found).");
|
|
6229
|
+
}
|
|
6230
|
+
var XSD_RELATIVE = {
|
|
6231
|
+
FA2: ["FA", "schemat_FA(2)_v1-0E.xsd"],
|
|
6232
|
+
FA3: ["FA", "schemat_FA(3)_v1-0E.xsd"],
|
|
6233
|
+
PEF: ["PEF", "Schemat_PEF(3)_v2-1.xsd"],
|
|
6234
|
+
PEF_KOR: ["PEF", "Schemat_PEF_KOR(3)_v2-1.xsd"]
|
|
6235
|
+
};
|
|
6236
|
+
var FA_XSD_PATHS = {
|
|
6237
|
+
get FA2() {
|
|
6238
|
+
return resolveXsdFor("FA2");
|
|
6239
|
+
},
|
|
6240
|
+
get FA3() {
|
|
6241
|
+
return resolveXsdFor("FA3");
|
|
6242
|
+
}
|
|
6243
|
+
};
|
|
6244
|
+
var PEF_XSD_PATHS = {
|
|
6245
|
+
get PEF() {
|
|
6246
|
+
return resolveXsdFor("PEF");
|
|
6247
|
+
},
|
|
6248
|
+
get PEF_KOR() {
|
|
6249
|
+
return resolveXsdFor("PEF_KOR");
|
|
6250
|
+
}
|
|
6251
|
+
};
|
|
6252
|
+
function resolveXsdFor(schema) {
|
|
6253
|
+
const rel = XSD_RELATIVE[schema];
|
|
6254
|
+
if (!rel) throw new Error(`Unknown invoice schema: ${String(schema)}`);
|
|
6255
|
+
return path.join(locatePackageRoot(), "docs", "schemas", ...rel);
|
|
6256
|
+
}
|
|
6257
|
+
var requireModule = (0, import_node_module.createRequire)(importMetaUrl);
|
|
6258
|
+
var libxmljs = null;
|
|
6259
|
+
var libxmljsLoadError = null;
|
|
6260
|
+
try {
|
|
6261
|
+
libxmljs = requireModule("libxmljs2");
|
|
6262
|
+
} catch (err) {
|
|
6263
|
+
const code = err?.code;
|
|
6264
|
+
if (code === "MODULE_NOT_FOUND" || code === "ERR_MODULE_NOT_FOUND") {
|
|
6265
|
+
libxmljs = null;
|
|
6266
|
+
} else {
|
|
6267
|
+
libxmljs = null;
|
|
6268
|
+
libxmljsLoadError = err instanceof Error ? err : new Error(String(err));
|
|
6269
|
+
}
|
|
6270
|
+
}
|
|
6271
|
+
var libxmljsAvailable = libxmljs !== null;
|
|
6272
|
+
var MISSING_LIBXMLJS_MESSAGE_PREFIX = "libxmljs2 is not installed";
|
|
6273
|
+
var EXTERNAL_STRUKTURY_DANYCH_URL = /schemaLocation="http:\/\/crd\.gov\.pl\/xml\/schematy\/dziedzinowe\/mf\/2022\/01\/05\/eD\/DefinicjeTypy\/StrukturyDanych_v10-0E\.xsd"/;
|
|
6274
|
+
function rewriteSchemaLocations(xsdContent) {
|
|
6275
|
+
if (!EXTERNAL_STRUKTURY_DANYCH_URL.test(xsdContent)) {
|
|
6276
|
+
return xsdContent;
|
|
6277
|
+
}
|
|
6278
|
+
const bazoweStrukturyPath = path.join(
|
|
6279
|
+
locatePackageRoot(),
|
|
6280
|
+
"docs",
|
|
6281
|
+
"schemas",
|
|
6282
|
+
"FA",
|
|
6283
|
+
"bazowe",
|
|
6284
|
+
"StrukturyDanych_v10-0E.xsd"
|
|
6285
|
+
);
|
|
6286
|
+
const bazoweStrukturyUrl = (0, import_node_url.pathToFileURL)(bazoweStrukturyPath).href;
|
|
6287
|
+
const rewritten = xsdContent.replace(
|
|
6288
|
+
EXTERNAL_STRUKTURY_DANYCH_URL,
|
|
6289
|
+
`schemaLocation="${bazoweStrukturyUrl}"`
|
|
6290
|
+
);
|
|
6291
|
+
if (rewritten === xsdContent) {
|
|
6292
|
+
throw new Error(
|
|
6293
|
+
"FA XSD schemaLocation rewrite produced no replacement despite URL being present; regex likely out of sync with docs/schemas/FA/. Re-check after `yarn sync-schemas`."
|
|
6294
|
+
);
|
|
6295
|
+
}
|
|
6296
|
+
return rewritten;
|
|
6297
|
+
}
|
|
6298
|
+
function validateAgainstXsd(xml, xsdPath) {
|
|
6299
|
+
if (!libxmljs) {
|
|
6300
|
+
const loadSuffix = libxmljsLoadError ? ` (load failed: ${libxmljsLoadError.message})` : "";
|
|
6301
|
+
throw new Error(
|
|
6302
|
+
`${MISSING_LIBXMLJS_MESSAGE_PREFIX}${loadSuffix}; cannot run XSD validation. Install it as an optional peer dependency (e.g. \`yarn add -O libxmljs2\` or \`npm i -O libxmljs2\`).`
|
|
6303
|
+
);
|
|
6304
|
+
}
|
|
6305
|
+
const xsdDir = path.dirname(xsdPath);
|
|
6306
|
+
const rawXsd = fs.readFileSync(xsdPath, "utf8");
|
|
6307
|
+
const rewrittenXsd = rewriteSchemaLocations(rawXsd);
|
|
6308
|
+
const baseUrl = (0, import_node_url.pathToFileURL)(xsdDir + path.sep).href;
|
|
6309
|
+
let schemaDoc;
|
|
6310
|
+
try {
|
|
6311
|
+
schemaDoc = libxmljs.parseXml(rewrittenXsd, { baseUrl });
|
|
6312
|
+
} catch (err) {
|
|
6313
|
+
return { valid: false, errors: [`XSD parse failed: ${err.message}`] };
|
|
6314
|
+
}
|
|
6315
|
+
let xmlDoc;
|
|
6316
|
+
try {
|
|
6317
|
+
xmlDoc = libxmljs.parseXml(xml);
|
|
6318
|
+
} catch (err) {
|
|
6319
|
+
return { valid: false, errors: [`XML parse failed: ${err.message}`] };
|
|
6320
|
+
}
|
|
6321
|
+
const valid = xmlDoc.validate(schemaDoc);
|
|
6322
|
+
const errors = valid ? [] : xmlDoc.validationErrors.map((err) => err.message.trim());
|
|
6323
|
+
return { valid, errors };
|
|
6324
|
+
}
|
|
6325
|
+
|
|
6326
|
+
// src/models/index.ts
|
|
6327
|
+
init_cjs_shims();
|
|
6328
|
+
|
|
6329
|
+
// src/models/common.ts
|
|
6330
|
+
init_cjs_shims();
|
|
6331
|
+
|
|
6332
|
+
// src/models/auth/index.ts
|
|
6333
|
+
init_cjs_shims();
|
|
6334
|
+
|
|
6335
|
+
// src/models/auth/types.ts
|
|
6336
|
+
init_cjs_shims();
|
|
6337
|
+
|
|
6338
|
+
// src/models/auth/active-sessions-types.ts
|
|
6339
|
+
init_cjs_shims();
|
|
6340
|
+
|
|
6341
|
+
// src/models/sessions/index.ts
|
|
6342
|
+
init_cjs_shims();
|
|
6343
|
+
|
|
6344
|
+
// src/models/sessions/online-types.ts
|
|
6345
|
+
init_cjs_shims();
|
|
6346
|
+
|
|
6347
|
+
// src/models/sessions/batch-types.ts
|
|
6348
|
+
init_cjs_shims();
|
|
6349
|
+
|
|
6350
|
+
// src/models/sessions/status-types.ts
|
|
6351
|
+
init_cjs_shims();
|
|
6352
|
+
|
|
6353
|
+
// src/models/sessions/session-state.ts
|
|
6354
|
+
init_cjs_shims();
|
|
6355
|
+
|
|
6356
|
+
// src/models/invoices/index.ts
|
|
6357
|
+
init_cjs_shims();
|
|
6358
|
+
|
|
6359
|
+
// src/models/invoices/types.ts
|
|
6360
|
+
init_cjs_shims();
|
|
6361
|
+
|
|
6362
|
+
// src/models/permissions/index.ts
|
|
6363
|
+
init_cjs_shims();
|
|
6364
|
+
|
|
6365
|
+
// src/models/permissions/types.ts
|
|
6366
|
+
init_cjs_shims();
|
|
6367
|
+
|
|
6368
|
+
// src/models/tokens/index.ts
|
|
6369
|
+
init_cjs_shims();
|
|
6370
|
+
|
|
6371
|
+
// src/models/tokens/types.ts
|
|
6372
|
+
init_cjs_shims();
|
|
6373
|
+
|
|
6374
|
+
// src/models/certificates/index.ts
|
|
6375
|
+
init_cjs_shims();
|
|
6376
|
+
|
|
6377
|
+
// src/models/certificates/types.ts
|
|
6378
|
+
init_cjs_shims();
|
|
6379
|
+
|
|
6380
|
+
// src/models/lighthouse/index.ts
|
|
6381
|
+
init_cjs_shims();
|
|
6382
|
+
|
|
6383
|
+
// src/models/lighthouse/types.ts
|
|
6384
|
+
init_cjs_shims();
|
|
6385
|
+
|
|
6386
|
+
// src/models/limits/index.ts
|
|
6387
|
+
init_cjs_shims();
|
|
6388
|
+
|
|
6389
|
+
// src/models/limits/types.ts
|
|
6390
|
+
init_cjs_shims();
|
|
6391
|
+
|
|
6392
|
+
// src/models/peppol/index.ts
|
|
6393
|
+
init_cjs_shims();
|
|
6394
|
+
|
|
6395
|
+
// src/models/peppol/types.ts
|
|
6396
|
+
init_cjs_shims();
|
|
6397
|
+
|
|
6398
|
+
// src/models/test-data/index.ts
|
|
6399
|
+
init_cjs_shims();
|
|
6400
|
+
|
|
6401
|
+
// src/models/test-data/types.ts
|
|
6402
|
+
init_cjs_shims();
|
|
6403
|
+
|
|
6404
|
+
// src/models/crypto/index.ts
|
|
6405
|
+
init_cjs_shims();
|
|
6406
|
+
|
|
6407
|
+
// src/models/crypto/types.ts
|
|
6408
|
+
init_cjs_shims();
|
|
6409
|
+
|
|
6410
|
+
// src/models/qrcode/index.ts
|
|
6411
|
+
init_cjs_shims();
|
|
6412
|
+
|
|
6413
|
+
// src/models/qrcode/types.ts
|
|
6414
|
+
init_cjs_shims();
|
|
6415
|
+
|
|
5823
6416
|
// src/models/index.ts
|
|
5824
6417
|
init_document_structures();
|
|
5825
6418
|
|
|
5826
6419
|
// src/services/index.ts
|
|
6420
|
+
init_cjs_shims();
|
|
5827
6421
|
init_auth();
|
|
5828
6422
|
init_active_sessions();
|
|
5829
6423
|
init_online_session();
|
|
@@ -5838,7 +6432,11 @@ init_limits();
|
|
|
5838
6432
|
init_peppol();
|
|
5839
6433
|
init_test_data();
|
|
5840
6434
|
|
|
6435
|
+
// src/builders/index.ts
|
|
6436
|
+
init_cjs_shims();
|
|
6437
|
+
|
|
5841
6438
|
// src/builders/auth-token-request.ts
|
|
6439
|
+
init_cjs_shims();
|
|
5842
6440
|
init_ksef_validation_error();
|
|
5843
6441
|
var AuthTokenRequestBuilder = class {
|
|
5844
6442
|
challenge;
|
|
@@ -5893,6 +6491,7 @@ var AuthTokenRequestBuilder = class {
|
|
|
5893
6491
|
};
|
|
5894
6492
|
|
|
5895
6493
|
// src/builders/auth-ksef-token-request.ts
|
|
6494
|
+
init_cjs_shims();
|
|
5896
6495
|
init_ksef_validation_error();
|
|
5897
6496
|
var AuthKsefTokenRequestBuilder = class {
|
|
5898
6497
|
challenge;
|
|
@@ -5947,6 +6546,7 @@ var AuthKsefTokenRequestBuilder = class {
|
|
|
5947
6546
|
};
|
|
5948
6547
|
|
|
5949
6548
|
// src/builders/invoice-query-filter.ts
|
|
6549
|
+
init_cjs_shims();
|
|
5950
6550
|
init_ksef_validation_error();
|
|
5951
6551
|
var InvoiceQueryFilterBuilder = class {
|
|
5952
6552
|
subjectType;
|
|
@@ -6043,7 +6643,11 @@ var InvoiceQueryFilterBuilder = class {
|
|
|
6043
6643
|
}
|
|
6044
6644
|
};
|
|
6045
6645
|
|
|
6646
|
+
// src/builders/permissions/index.ts
|
|
6647
|
+
init_cjs_shims();
|
|
6648
|
+
|
|
6046
6649
|
// src/builders/permissions/person-permission.ts
|
|
6650
|
+
init_cjs_shims();
|
|
6047
6651
|
init_ksef_validation_error();
|
|
6048
6652
|
var PersonPermissionGrantBuilder = class {
|
|
6049
6653
|
subjectIdentifier;
|
|
@@ -6093,6 +6697,7 @@ var PersonPermissionGrantBuilder = class {
|
|
|
6093
6697
|
};
|
|
6094
6698
|
|
|
6095
6699
|
// src/builders/permissions/entity-permission.ts
|
|
6700
|
+
init_cjs_shims();
|
|
6096
6701
|
init_ksef_validation_error();
|
|
6097
6702
|
var EntityPermissionGrantBuilder = class {
|
|
6098
6703
|
nip;
|
|
@@ -6142,6 +6747,7 @@ var EntityPermissionGrantBuilder = class {
|
|
|
6142
6747
|
};
|
|
6143
6748
|
|
|
6144
6749
|
// src/builders/permissions/authorization-permission.ts
|
|
6750
|
+
init_cjs_shims();
|
|
6145
6751
|
init_ksef_validation_error();
|
|
6146
6752
|
var AuthorizationPermissionGrantBuilder = class {
|
|
6147
6753
|
_subjectIdentifier;
|
|
@@ -6187,7 +6793,8 @@ var AuthorizationPermissionGrantBuilder = class {
|
|
|
6187
6793
|
};
|
|
6188
6794
|
|
|
6189
6795
|
// src/builders/batch-file.ts
|
|
6190
|
-
|
|
6796
|
+
init_cjs_shims();
|
|
6797
|
+
var crypto = __toESM(require("node:crypto"), 1);
|
|
6191
6798
|
init_ksef_validation_error();
|
|
6192
6799
|
var BATCH_MAX_PART_SIZE = 1e8;
|
|
6193
6800
|
var BATCH_MAX_TOTAL_SIZE = 5e9;
|
|
@@ -6357,12 +6964,14 @@ function sha256Base64(data) {
|
|
|
6357
6964
|
}
|
|
6358
6965
|
|
|
6359
6966
|
// src/crypto/index.ts
|
|
6967
|
+
init_cjs_shims();
|
|
6360
6968
|
init_certificate_fetcher();
|
|
6361
6969
|
init_cryptography_service();
|
|
6362
6970
|
init_signature_service();
|
|
6363
6971
|
|
|
6364
6972
|
// src/crypto/certificate-service.ts
|
|
6365
|
-
|
|
6973
|
+
init_cjs_shims();
|
|
6974
|
+
var crypto4 = __toESM(require("node:crypto"), 1);
|
|
6366
6975
|
var x5092 = __toESM(require("@peculiar/x509"), 1);
|
|
6367
6976
|
var CertificateService = class {
|
|
6368
6977
|
static getSha256Fingerprint(certPem) {
|
|
@@ -6447,9 +7056,11 @@ init_pkcs12_loader();
|
|
|
6447
7056
|
init_auth_xml_builder();
|
|
6448
7057
|
|
|
6449
7058
|
// src/qr/index.ts
|
|
7059
|
+
init_cjs_shims();
|
|
6450
7060
|
init_verification_link_service();
|
|
6451
7061
|
|
|
6452
7062
|
// src/qr/qrcode-service.ts
|
|
7063
|
+
init_cjs_shims();
|
|
6453
7064
|
var QRCode = __toESM(require("qrcode"), 1);
|
|
6454
7065
|
var QrCodeService = class _QrCodeService {
|
|
6455
7066
|
static async generateQrCode(url, options) {
|
|
@@ -6509,11 +7120,13 @@ function escapeXml2(str) {
|
|
|
6509
7120
|
}
|
|
6510
7121
|
|
|
6511
7122
|
// src/utils/index.ts
|
|
7123
|
+
init_cjs_shims();
|
|
6512
7124
|
init_zip();
|
|
6513
7125
|
init_jwt();
|
|
6514
7126
|
|
|
6515
7127
|
// src/utils/hash.ts
|
|
6516
|
-
|
|
7128
|
+
init_cjs_shims();
|
|
7129
|
+
var import_node_crypto2 = __toESM(require("node:crypto"), 1);
|
|
6517
7130
|
function sha256Base642(data) {
|
|
6518
7131
|
return import_node_crypto2.default.createHash("sha256").update(data).digest("base64");
|
|
6519
7132
|
}
|
|
@@ -6524,7 +7137,11 @@ function verifyHash(data, expectedHash) {
|
|
|
6524
7137
|
// src/utils/index.ts
|
|
6525
7138
|
init_concurrency();
|
|
6526
7139
|
|
|
7140
|
+
// src/workflows/index.ts
|
|
7141
|
+
init_cjs_shims();
|
|
7142
|
+
|
|
6527
7143
|
// src/workflows/polling.ts
|
|
7144
|
+
init_cjs_shims();
|
|
6528
7145
|
async function pollUntil(action, condition, options) {
|
|
6529
7146
|
const intervalMs = options?.intervalMs ?? 2e3;
|
|
6530
7147
|
const maxAttempts = options?.maxAttempts ?? 60;
|
|
@@ -6542,13 +7159,18 @@ async function pollUntil(action, condition, options) {
|
|
|
6542
7159
|
}
|
|
6543
7160
|
|
|
6544
7161
|
// src/workflows/online-session-workflow.ts
|
|
7162
|
+
init_cjs_shims();
|
|
6545
7163
|
init_ksef_session_expired_error();
|
|
6546
7164
|
init_auth_manager();
|
|
6547
7165
|
init_online_session();
|
|
6548
7166
|
init_session_status();
|
|
6549
7167
|
init_document_structures();
|
|
6550
7168
|
|
|
7169
|
+
// src/xml/index.ts
|
|
7170
|
+
init_cjs_shims();
|
|
7171
|
+
|
|
6551
7172
|
// src/xml/upo-parser.ts
|
|
7173
|
+
init_cjs_shims();
|
|
6552
7174
|
var import_fast_xml_parser = require("fast-xml-parser");
|
|
6553
7175
|
init_ksef_validation_error();
|
|
6554
7176
|
function isRecord(value) {
|
|
@@ -6667,6 +7289,7 @@ function parseUpoXml(xml) {
|
|
|
6667
7289
|
}
|
|
6668
7290
|
|
|
6669
7291
|
// src/xml/invoice-field-extractor.ts
|
|
7292
|
+
init_cjs_shims();
|
|
6670
7293
|
var import_fast_xml_parser2 = require("fast-xml-parser");
|
|
6671
7294
|
var invoiceParser = new import_fast_xml_parser2.XMLParser({
|
|
6672
7295
|
ignoreAttributes: false,
|
|
@@ -6707,6 +7330,7 @@ function nonEmptyString(value) {
|
|
|
6707
7330
|
}
|
|
6708
7331
|
|
|
6709
7332
|
// src/xml/xml-engine.ts
|
|
7333
|
+
init_cjs_shims();
|
|
6710
7334
|
var import_fast_xml_parser3 = require("fast-xml-parser");
|
|
6711
7335
|
var XML_DECLARATION = '<?xml version="1.0" encoding="UTF-8"?>\n';
|
|
6712
7336
|
var parser = new import_fast_xml_parser3.XMLParser({
|
|
@@ -6749,17 +7373,18 @@ function prependDeclaration(xml) {
|
|
|
6749
7373
|
function parseXml(xml) {
|
|
6750
7374
|
return parser.parse(xml);
|
|
6751
7375
|
}
|
|
6752
|
-
function buildXml(
|
|
6753
|
-
return prependDeclaration(builder.build(
|
|
7376
|
+
function buildXml(document2) {
|
|
7377
|
+
return prependDeclaration(builder.build(document2));
|
|
6754
7378
|
}
|
|
6755
|
-
function buildXmlFromObject(
|
|
6756
|
-
return prependDeclaration(createObjectBuilder(options?.pretty).build(
|
|
7379
|
+
function buildXmlFromObject(document2, options) {
|
|
7380
|
+
return prependDeclaration(createObjectBuilder(options?.pretty).build(document2));
|
|
6757
7381
|
}
|
|
6758
7382
|
function stripBom(input) {
|
|
6759
7383
|
return input.charCodeAt(0) === 65279 ? input.slice(1) : input;
|
|
6760
7384
|
}
|
|
6761
7385
|
|
|
6762
7386
|
// src/xml/order-map.ts
|
|
7387
|
+
init_cjs_shims();
|
|
6763
7388
|
var ORDER_MAP = {
|
|
6764
7389
|
Faktura: ["Naglowek", "Podmiot1", "Podmiot2", "Podmiot3", "Fa", "Stopka"],
|
|
6765
7390
|
Naglowek: ["KodFormularza", "WariantFormularza", "DataWytworzeniaFa", "SystemInfo"],
|
|
@@ -6958,6 +7583,7 @@ function orderXmlObject(value, contextKey) {
|
|
|
6958
7583
|
}
|
|
6959
7584
|
|
|
6960
7585
|
// src/xml/faktura-builder.ts
|
|
7586
|
+
init_cjs_shims();
|
|
6961
7587
|
var FAKTURA_NAMESPACE = {
|
|
6962
7588
|
FA2: "http://crd.gov.pl/wzor/2023/06/29/12648/",
|
|
6963
7589
|
FA3: "http://crd.gov.pl/wzor/2025/06/25/13775/"
|
|
@@ -7027,14 +7653,14 @@ function buildFakturaXml(faktura, options = {}) {
|
|
|
7027
7653
|
const etdNamespace = options.etdNamespace ?? ETD_NAMESPACE[schema];
|
|
7028
7654
|
const normalized = normalizeTopLevel(faktura);
|
|
7029
7655
|
const ordered = orderXmlObject(normalized, "Faktura");
|
|
7030
|
-
const
|
|
7656
|
+
const document2 = {
|
|
7031
7657
|
Faktura: {
|
|
7032
7658
|
...ordered,
|
|
7033
7659
|
"@_xmlns": fakturaNamespace,
|
|
7034
7660
|
"@_xmlns:etd": etdNamespace
|
|
7035
7661
|
}
|
|
7036
7662
|
};
|
|
7037
|
-
return buildXmlFromObject(
|
|
7663
|
+
return buildXmlFromObject(document2, { pretty: options.pretty });
|
|
7038
7664
|
}
|
|
7039
7665
|
function isFakturaInput(input) {
|
|
7040
7666
|
if (!isObject2(input)) return false;
|
|
@@ -7045,6 +7671,7 @@ function isFakturaInput(input) {
|
|
|
7045
7671
|
}
|
|
7046
7672
|
|
|
7047
7673
|
// src/xml/pef-builder.ts
|
|
7674
|
+
init_cjs_shims();
|
|
7048
7675
|
init_ksef_validation_error();
|
|
7049
7676
|
var PEF_NAMESPACE = {
|
|
7050
7677
|
PEF: "urn:oasis:names:specification:ubl:schema:xsd:Invoice-2",
|
|
@@ -7109,7 +7736,7 @@ function buildPefXml(input, options = {}) {
|
|
|
7109
7736
|
"@_xmlns:cbc-pl": UBL_CBC_PL_NS,
|
|
7110
7737
|
"@_xmlns:cac-pl": UBL_CAC_PL_NS
|
|
7111
7738
|
};
|
|
7112
|
-
const
|
|
7739
|
+
const document2 = "Invoice" in input ? {
|
|
7113
7740
|
Invoice: {
|
|
7114
7741
|
...input.Invoice,
|
|
7115
7742
|
"@_xmlns": PEF_NAMESPACE.PEF,
|
|
@@ -7122,10 +7749,11 @@ function buildPefXml(input, options = {}) {
|
|
|
7122
7749
|
...commonNamespaces
|
|
7123
7750
|
}
|
|
7124
7751
|
};
|
|
7125
|
-
return buildXmlFromObject(
|
|
7752
|
+
return buildXmlFromObject(document2, { pretty: options.pretty });
|
|
7126
7753
|
}
|
|
7127
7754
|
|
|
7128
7755
|
// src/xml/invoice-serializer.ts
|
|
7756
|
+
init_cjs_shims();
|
|
7129
7757
|
init_ksef_validation_error();
|
|
7130
7758
|
var FAKTURA_SCHEMAS = /* @__PURE__ */ new Set(["FA2", "FA3"]);
|
|
7131
7759
|
var PEF_SCHEMAS = /* @__PURE__ */ new Set(["PEF", "PEF_KOR"]);
|
|
@@ -7220,8 +7848,8 @@ function serializeInvoiceXml(input, options) {
|
|
|
7220
7848
|
"Unsupported invoice input type: expected Buffer, string, XmlDocument, FakturaInput, or PefUblDocumentInput."
|
|
7221
7849
|
);
|
|
7222
7850
|
}
|
|
7223
|
-
function buildRawXmlString(
|
|
7224
|
-
return buildXmlFromObject(
|
|
7851
|
+
function buildRawXmlString(document2, options) {
|
|
7852
|
+
return buildXmlFromObject(document2, options);
|
|
7225
7853
|
}
|
|
7226
7854
|
|
|
7227
7855
|
// src/workflows/online-session-workflow.ts
|
|
@@ -7361,6 +7989,7 @@ async function openSendAndClose(client, invoices, options) {
|
|
|
7361
7989
|
}
|
|
7362
7990
|
|
|
7363
7991
|
// src/workflows/batch-session-workflow.ts
|
|
7992
|
+
init_cjs_shims();
|
|
7364
7993
|
init_document_structures();
|
|
7365
7994
|
async function uploadBatch(client, zipData, options) {
|
|
7366
7995
|
if (options?.parallelism !== void 0 && (!Number.isInteger(options.parallelism) || options.parallelism < 1)) {
|
|
@@ -7499,6 +8128,7 @@ async function uploadBatchParsed(client, zipData, options) {
|
|
|
7499
8128
|
}
|
|
7500
8129
|
|
|
7501
8130
|
// src/workflows/invoice-export-workflow.ts
|
|
8131
|
+
init_cjs_shims();
|
|
7502
8132
|
init_zip();
|
|
7503
8133
|
async function doExport(client, filters, options) {
|
|
7504
8134
|
await client.crypto.init();
|
|
@@ -7571,7 +8201,11 @@ async function exportAndDownload(client, filters, options) {
|
|
|
7571
8201
|
};
|
|
7572
8202
|
}
|
|
7573
8203
|
|
|
8204
|
+
// src/workflows/incremental-export-workflow.ts
|
|
8205
|
+
init_cjs_shims();
|
|
8206
|
+
|
|
7574
8207
|
// src/workflows/hwm-coordinator.ts
|
|
8208
|
+
init_cjs_shims();
|
|
7575
8209
|
function updateContinuationPoint(points, subjectType, pkg) {
|
|
7576
8210
|
if (pkg.isTruncated && pkg.lastPermanentStorageDate) {
|
|
7577
8211
|
points[subjectType] = pkg.lastPermanentStorageDate;
|
|
@@ -7669,7 +8303,8 @@ function buildDefaultFilters(subjectType, from, to) {
|
|
|
7669
8303
|
}
|
|
7670
8304
|
|
|
7671
8305
|
// src/workflows/hwm-storage.ts
|
|
7672
|
-
|
|
8306
|
+
init_cjs_shims();
|
|
8307
|
+
var fs2 = __toESM(require("node:fs/promises"), 1);
|
|
7673
8308
|
var InMemoryHwmStore = class {
|
|
7674
8309
|
points = {};
|
|
7675
8310
|
async load() {
|
|
@@ -7685,7 +8320,7 @@ var FileHwmStore = class {
|
|
|
7685
8320
|
}
|
|
7686
8321
|
async load() {
|
|
7687
8322
|
try {
|
|
7688
|
-
const data = await
|
|
8323
|
+
const data = await fs2.readFile(this.filePath, "utf-8");
|
|
7689
8324
|
return JSON.parse(data);
|
|
7690
8325
|
} catch (err) {
|
|
7691
8326
|
if (err.code === "ENOENT") {
|
|
@@ -7695,11 +8330,12 @@ var FileHwmStore = class {
|
|
|
7695
8330
|
}
|
|
7696
8331
|
}
|
|
7697
8332
|
async save(points) {
|
|
7698
|
-
await
|
|
8333
|
+
await fs2.writeFile(this.filePath, JSON.stringify(points, null, 2), "utf-8");
|
|
7699
8334
|
}
|
|
7700
8335
|
};
|
|
7701
8336
|
|
|
7702
8337
|
// src/workflows/auth-workflow.ts
|
|
8338
|
+
init_cjs_shims();
|
|
7703
8339
|
init_auth_xml_builder();
|
|
7704
8340
|
async function authenticateWithToken(client, options) {
|
|
7705
8341
|
const challenge = await client.auth.getChallenge();
|
|
@@ -7796,10 +8432,12 @@ async function authenticateWithPkcs12(client, options) {
|
|
|
7796
8432
|
}
|
|
7797
8433
|
|
|
7798
8434
|
// src/offline/index.ts
|
|
8435
|
+
init_cjs_shims();
|
|
7799
8436
|
init_deadline();
|
|
7800
8437
|
init_holidays();
|
|
7801
8438
|
|
|
7802
8439
|
// src/offline/storage.ts
|
|
8440
|
+
init_cjs_shims();
|
|
7803
8441
|
function matchesFilter(invoice, filter) {
|
|
7804
8442
|
if (filter.status !== void 0) {
|
|
7805
8443
|
const statuses = Array.isArray(filter.status) ? filter.status : [filter.status];
|
|
@@ -7838,12 +8476,13 @@ var InMemoryOfflineInvoiceStorage = class {
|
|
|
7838
8476
|
};
|
|
7839
8477
|
|
|
7840
8478
|
// src/offline/file-storage.ts
|
|
7841
|
-
|
|
7842
|
-
var
|
|
7843
|
-
var
|
|
8479
|
+
init_cjs_shims();
|
|
8480
|
+
var fs3 = __toESM(require("node:fs/promises"), 1);
|
|
8481
|
+
var path2 = __toESM(require("node:path"), 1);
|
|
8482
|
+
var os = __toESM(require("node:os"), 1);
|
|
7844
8483
|
function resolveDir(dir) {
|
|
7845
8484
|
if (dir === "~" || dir.startsWith("~/")) {
|
|
7846
|
-
return
|
|
8485
|
+
return path2.join(os.homedir(), dir.slice(1));
|
|
7847
8486
|
}
|
|
7848
8487
|
return dir;
|
|
7849
8488
|
}
|
|
@@ -7859,23 +8498,23 @@ var FileOfflineInvoiceStorage = class {
|
|
|
7859
8498
|
this.dir = resolveDir(directory ?? "~/.ksef/offline");
|
|
7860
8499
|
}
|
|
7861
8500
|
async ensureDir() {
|
|
7862
|
-
await
|
|
8501
|
+
await fs3.mkdir(this.dir, { recursive: true });
|
|
7863
8502
|
}
|
|
7864
8503
|
filePath(id) {
|
|
7865
8504
|
validateId(id);
|
|
7866
|
-
return
|
|
8505
|
+
return path2.join(this.dir, `${id}.json`);
|
|
7867
8506
|
}
|
|
7868
8507
|
async save(invoice) {
|
|
7869
8508
|
await this.ensureDir();
|
|
7870
8509
|
const file = this.filePath(invoice.id);
|
|
7871
8510
|
const tmp = `${file}.tmp`;
|
|
7872
|
-
await
|
|
7873
|
-
await
|
|
8511
|
+
await fs3.writeFile(tmp, JSON.stringify(invoice, null, 2));
|
|
8512
|
+
await fs3.rename(tmp, file);
|
|
7874
8513
|
}
|
|
7875
8514
|
async get(id) {
|
|
7876
8515
|
const file = this.filePath(id);
|
|
7877
8516
|
try {
|
|
7878
|
-
return JSON.parse(await
|
|
8517
|
+
return JSON.parse(await fs3.readFile(file, "utf-8"));
|
|
7879
8518
|
} catch (err) {
|
|
7880
8519
|
if (err instanceof Error && "code" in err && err.code === "ENOENT") {
|
|
7881
8520
|
return null;
|
|
@@ -7887,7 +8526,7 @@ var FileOfflineInvoiceStorage = class {
|
|
|
7887
8526
|
async list(filter) {
|
|
7888
8527
|
let files;
|
|
7889
8528
|
try {
|
|
7890
|
-
files = (await
|
|
8529
|
+
files = (await fs3.readdir(this.dir)).filter((f) => f.endsWith(".json"));
|
|
7891
8530
|
} catch {
|
|
7892
8531
|
return [];
|
|
7893
8532
|
}
|
|
@@ -7895,7 +8534,7 @@ var FileOfflineInvoiceStorage = class {
|
|
|
7895
8534
|
for (const file of files) {
|
|
7896
8535
|
try {
|
|
7897
8536
|
const data = JSON.parse(
|
|
7898
|
-
await
|
|
8537
|
+
await fs3.readFile(path2.join(this.dir, file), "utf-8")
|
|
7899
8538
|
);
|
|
7900
8539
|
if (!filter || matchesFilter(data, filter)) {
|
|
7901
8540
|
results.push(data);
|
|
@@ -7921,7 +8560,7 @@ var FileOfflineInvoiceStorage = class {
|
|
|
7921
8560
|
async delete(id) {
|
|
7922
8561
|
const file = this.filePath(id);
|
|
7923
8562
|
try {
|
|
7924
|
-
await
|
|
8563
|
+
await fs3.unlink(file);
|
|
7925
8564
|
} catch (e) {
|
|
7926
8565
|
if (e instanceof Error && "code" in e && e.code !== "ENOENT") throw e;
|
|
7927
8566
|
}
|
|
@@ -7951,6 +8590,7 @@ init_client();
|
|
|
7951
8590
|
CertificateFingerprint,
|
|
7952
8591
|
CertificateName,
|
|
7953
8592
|
CertificateService,
|
|
8593
|
+
CircuitBreakerPolicy,
|
|
7954
8594
|
CryptographyService,
|
|
7955
8595
|
DEFAULT_FORM_CODE,
|
|
7956
8596
|
DISCOURAGED_UNICODE_RANGES,
|
|
@@ -7960,6 +8600,7 @@ init_client();
|
|
|
7960
8600
|
EntityPermissionGrantBuilder,
|
|
7961
8601
|
Environment,
|
|
7962
8602
|
FAKTURA_NAMESPACE,
|
|
8603
|
+
FA_XSD_PATHS,
|
|
7963
8604
|
FORM_CODES,
|
|
7964
8605
|
FORM_CODE_KEYS,
|
|
7965
8606
|
FileHwmStore,
|
|
@@ -7978,6 +8619,7 @@ init_client();
|
|
|
7978
8619
|
KSeFAuthStatusError,
|
|
7979
8620
|
KSeFBadRequestError,
|
|
7980
8621
|
KSeFBatchTimeoutError,
|
|
8622
|
+
KSeFCircuitOpenError,
|
|
7981
8623
|
KSeFClient,
|
|
7982
8624
|
KSeFError,
|
|
7983
8625
|
KSeFErrorCode,
|
|
@@ -7987,6 +8629,7 @@ init_client();
|
|
|
7987
8629
|
KSeFSessionExpiredError,
|
|
7988
8630
|
KSeFUnauthorizedError,
|
|
7989
8631
|
KSeFValidationError,
|
|
8632
|
+
KSeFXsdValidationError,
|
|
7990
8633
|
KsefNumber,
|
|
7991
8634
|
KsefNumberV35,
|
|
7992
8635
|
KsefNumberV36,
|
|
@@ -7998,6 +8641,7 @@ init_client();
|
|
|
7998
8641
|
OfflineInvoiceWorkflow,
|
|
7999
8642
|
OnlineSessionService,
|
|
8000
8643
|
PEF_NAMESPACE,
|
|
8644
|
+
PEF_XSD_PATHS,
|
|
8001
8645
|
PERMISSION_DESCRIPTION_MAX_LENGTH,
|
|
8002
8646
|
PERMISSION_DESCRIPTION_MIN_LENGTH,
|
|
8003
8647
|
PeppolId,
|
|
@@ -8045,6 +8689,7 @@ init_client();
|
|
|
8045
8689
|
createZip,
|
|
8046
8690
|
decodeJwtPayload,
|
|
8047
8691
|
deduplicateByKsefNumber,
|
|
8692
|
+
defaultCircuitBreakerPolicy,
|
|
8048
8693
|
defaultPresignedUrlPolicy,
|
|
8049
8694
|
defaultRateLimitPolicy,
|
|
8050
8695
|
defaultRetryPolicy,
|
|
@@ -8081,6 +8726,7 @@ init_client();
|
|
|
8081
8726
|
isValidReferenceNumber,
|
|
8082
8727
|
isValidSha256Base64,
|
|
8083
8728
|
isValidVatUe,
|
|
8729
|
+
libxmljsAvailable,
|
|
8084
8730
|
nextBusinessDay,
|
|
8085
8731
|
openOnlineSession,
|
|
8086
8732
|
openSendAndClose,
|
|
@@ -8092,6 +8738,7 @@ init_client();
|
|
|
8092
8738
|
parseXml,
|
|
8093
8739
|
pollUntil,
|
|
8094
8740
|
resolveOptions,
|
|
8741
|
+
resolveXsdFor,
|
|
8095
8742
|
resumeOnlineSession,
|
|
8096
8743
|
runWithConcurrency,
|
|
8097
8744
|
serializeInvoiceXml,
|
|
@@ -8106,6 +8753,7 @@ init_client();
|
|
|
8106
8753
|
uploadBatchStream,
|
|
8107
8754
|
uploadBatchStreamParsed,
|
|
8108
8755
|
validate,
|
|
8756
|
+
validateAgainstXsd,
|
|
8109
8757
|
validateBatch,
|
|
8110
8758
|
validateBusinessRules,
|
|
8111
8759
|
validateCharValidity,
|