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.
Files changed (37) hide show
  1. package/README.md +2 -1
  2. package/dist/cli.js +1717 -333
  3. package/dist/cli.js.map +1 -1
  4. package/dist/index.cjs +733 -85
  5. package/dist/index.cjs.map +1 -1
  6. package/dist/index.d.cts +77 -2
  7. package/dist/index.d.ts +77 -2
  8. package/dist/index.js +711 -75
  9. package/dist/index.js.map +1 -1
  10. package/docs/schemas/FA/bazowe/ElementarneTypyDanych_v10-0E.xsd +1 -0
  11. package/docs/schemas/FA/bazowe/KodyKrajow_v10-0E.xsd +1283 -0
  12. package/docs/schemas/FA/bazowe/StrukturyDanych_v10-0E.xsd +1 -0
  13. package/docs/schemas/FA/schemat_FA(2)_v1-0E.xsd +3661 -0
  14. package/docs/schemas/FA/schemat_FA(3)_v1-0E.xsd +3950 -0
  15. package/docs/schemas/PEF/Schemat_PEF(3)_v2-1.xsd +977 -0
  16. package/docs/schemas/PEF/Schemat_PEF_KOR(3)_v2-1.xsd +926 -0
  17. package/docs/schemas/PEF/bazowe/20241206_PEFPL-CommonAggregateComponents-2.1-v1.4.34.xsd +428 -0
  18. package/docs/schemas/PEF/bazowe/20241206_PEFPL-CommonBasicComponents-2.1-v1.4.34.xsd +65 -0
  19. package/docs/schemas/PEF/bazowe/CCTS_CCT_SchemaModule-2.1.xsd +731 -0
  20. package/docs/schemas/PEF/bazowe/UBL-CommonAggregateComponents-2.1.xsd +39799 -0
  21. package/docs/schemas/PEF/bazowe/UBL-CommonBasicComponents-2.1.xsd +5389 -0
  22. package/docs/schemas/PEF/bazowe/UBL-CommonExtensionComponents-2.1.xsd +223 -0
  23. package/docs/schemas/PEF/bazowe/UBL-CommonSignatureComponents-2.1.xsd +101 -0
  24. package/docs/schemas/PEF/bazowe/UBL-ExtensionContentDataType-2.1.xsd +89 -0
  25. package/docs/schemas/PEF/bazowe/UBL-QualifiedDataTypes-2.1.xsd +69 -0
  26. package/docs/schemas/PEF/bazowe/UBL-SignatureAggregateComponents-2.1.xsd +138 -0
  27. package/docs/schemas/PEF/bazowe/UBL-SignatureBasicComponents-2.1.xsd +78 -0
  28. package/docs/schemas/PEF/bazowe/UBL-UnqualifiedDataTypes-2.1.xsd +553 -0
  29. package/docs/schemas/PEF/bazowe/UBL-XAdESv132-2.1.xsd +476 -0
  30. package/docs/schemas/PEF/bazowe/UBL-XAdESv141-2.1.xsd +25 -0
  31. package/docs/schemas/PEF/bazowe/UBL-xmldsig-core-schema-2.1.xsd +323 -0
  32. package/docs/schemas/PEF/bazowe/commontypes.xsd +735 -0
  33. package/docs/schemas/PEF/bazowe/isotypes.xsd +3158 -0
  34. package/docs/schemas/RR/schemat_FA_RR(1)_v1-1E.xsd +2188 -0
  35. package/docs/schemas/RR/schemat_RR(1)_v1-0E.xsd +2188 -0
  36. package/docs/schemas/RR/schemat_RR(1)_v1-1E.xsd +2188 -0
  37. package/package.json +12 -2
package/dist/index.js CHANGED
@@ -8,11 +8,19 @@ var __export = (target, all) => {
8
8
  __defProp(target, name, { get: all[name], enumerable: true });
9
9
  };
10
10
 
11
+ // node_modules/tsup/assets/esm_shims.js
12
+ var init_esm_shims = __esm({
13
+ "node_modules/tsup/assets/esm_shims.js"() {
14
+ "use strict";
15
+ }
16
+ });
17
+
11
18
  // src/config/environments.ts
12
19
  var Environment;
13
20
  var init_environments = __esm({
14
21
  "src/config/environments.ts"() {
15
22
  "use strict";
23
+ init_esm_shims();
16
24
  Environment = {
17
25
  TEST: {
18
26
  apiUrl: "https://api-test.ksef.mf.gov.pl",
@@ -51,6 +59,7 @@ var DEFAULT_API_VERSION, DEFAULT_TIMEOUT;
51
59
  var init_options = __esm({
52
60
  "src/config/options.ts"() {
53
61
  "use strict";
62
+ init_esm_shims();
54
63
  init_environments();
55
64
  DEFAULT_API_VERSION = "v2";
56
65
  DEFAULT_TIMEOUT = 3e4;
@@ -61,6 +70,7 @@ var init_options = __esm({
61
70
  var init_config = __esm({
62
71
  "src/config/index.ts"() {
63
72
  "use strict";
73
+ init_esm_shims();
64
74
  init_environments();
65
75
  init_options();
66
76
  }
@@ -71,6 +81,7 @@ var KSeFError;
71
81
  var init_ksef_error = __esm({
72
82
  "src/errors/ksef-error.ts"() {
73
83
  "use strict";
84
+ init_esm_shims();
74
85
  KSeFError = class extends Error {
75
86
  constructor(message) {
76
87
  super(message);
@@ -85,6 +96,7 @@ var KSeFApiError;
85
96
  var init_ksef_api_error = __esm({
86
97
  "src/errors/ksef-api-error.ts"() {
87
98
  "use strict";
99
+ init_esm_shims();
88
100
  init_ksef_error();
89
101
  KSeFApiError = class _KSeFApiError extends KSeFError {
90
102
  statusCode;
@@ -112,6 +124,7 @@ var KSeFRateLimitError;
112
124
  var init_ksef_rate_limit_error = __esm({
113
125
  "src/errors/ksef-rate-limit-error.ts"() {
114
126
  "use strict";
127
+ init_esm_shims();
115
128
  init_ksef_api_error();
116
129
  KSeFRateLimitError = class _KSeFRateLimitError extends KSeFApiError {
117
130
  statusCode = 429;
@@ -162,6 +175,7 @@ var KSeFUnauthorizedError;
162
175
  var init_ksef_unauthorized_error = __esm({
163
176
  "src/errors/ksef-unauthorized-error.ts"() {
164
177
  "use strict";
178
+ init_esm_shims();
165
179
  init_ksef_api_error();
166
180
  KSeFUnauthorizedError = class extends KSeFApiError {
167
181
  statusCode = 401;
@@ -194,6 +208,7 @@ var KSeFForbiddenError;
194
208
  var init_ksef_forbidden_error = __esm({
195
209
  "src/errors/ksef-forbidden-error.ts"() {
196
210
  "use strict";
211
+ init_esm_shims();
197
212
  init_ksef_api_error();
198
213
  KSeFForbiddenError = class extends KSeFApiError {
199
214
  statusCode = 403;
@@ -232,6 +247,7 @@ var KSeFGoneError;
232
247
  var init_ksef_gone_error = __esm({
233
248
  "src/errors/ksef-gone-error.ts"() {
234
249
  "use strict";
250
+ init_esm_shims();
235
251
  init_ksef_api_error();
236
252
  KSeFGoneError = class extends KSeFApiError {
237
253
  statusCode = 410;
@@ -264,6 +280,7 @@ var KSeFBadRequestError;
264
280
  var init_ksef_bad_request_error = __esm({
265
281
  "src/errors/ksef-bad-request-error.ts"() {
266
282
  "use strict";
283
+ init_esm_shims();
267
284
  init_ksef_api_error();
268
285
  KSeFBadRequestError = class extends KSeFApiError {
269
286
  statusCode = 400;
@@ -299,6 +316,7 @@ var KSeFAuthStatusError;
299
316
  var init_ksef_auth_status_error = __esm({
300
317
  "src/errors/ksef-auth-status-error.ts"() {
301
318
  "use strict";
319
+ init_esm_shims();
302
320
  init_ksef_error();
303
321
  KSeFAuthStatusError = class extends KSeFError {
304
322
  referenceNumber;
@@ -318,6 +336,7 @@ var KSeFSessionExpiredError;
318
336
  var init_ksef_session_expired_error = __esm({
319
337
  "src/errors/ksef-session-expired-error.ts"() {
320
338
  "use strict";
339
+ init_esm_shims();
321
340
  init_ksef_error();
322
341
  KSeFSessionExpiredError = class extends KSeFError {
323
342
  constructor(message = "KSeF session has expired") {
@@ -337,6 +356,7 @@ var KSeFValidationError;
337
356
  var init_ksef_validation_error = __esm({
338
357
  "src/errors/ksef-validation-error.ts"() {
339
358
  "use strict";
359
+ init_esm_shims();
340
360
  init_ksef_error();
341
361
  KSeFValidationError = class _KSeFValidationError extends KSeFError {
342
362
  details;
@@ -364,6 +384,7 @@ var KSeFErrorCode;
364
384
  var init_error_codes = __esm({
365
385
  "src/errors/error-codes.ts"() {
366
386
  "use strict";
387
+ init_esm_shims();
367
388
  KSeFErrorCode = {
368
389
  BatchTimeout: 21208,
369
390
  DuplicateInvoice: 440
@@ -376,6 +397,7 @@ var KSeFBatchTimeoutError;
376
397
  var init_ksef_batch_timeout_error = __esm({
377
398
  "src/errors/ksef-batch-timeout-error.ts"() {
378
399
  "use strict";
400
+ init_esm_shims();
379
401
  init_ksef_api_error();
380
402
  init_error_codes();
381
403
  KSeFBatchTimeoutError = class _KSeFBatchTimeoutError extends KSeFApiError {
@@ -395,6 +417,52 @@ var init_ksef_batch_timeout_error = __esm({
395
417
  }
396
418
  });
397
419
 
420
+ // src/errors/ksef-circuit-open-error.ts
421
+ var KSeFCircuitOpenError;
422
+ var init_ksef_circuit_open_error = __esm({
423
+ "src/errors/ksef-circuit-open-error.ts"() {
424
+ "use strict";
425
+ init_esm_shims();
426
+ init_ksef_error();
427
+ KSeFCircuitOpenError = class extends KSeFError {
428
+ endpoint;
429
+ openedAt;
430
+ retryAfterMs;
431
+ constructor(endpoint, openedAt, retryAfterMs) {
432
+ super(
433
+ `Circuit breaker is open for '${endpoint}'. Retry after ${Math.round(retryAfterMs)}ms.`
434
+ );
435
+ this.name = "KSeFCircuitOpenError";
436
+ this.endpoint = endpoint;
437
+ this.openedAt = openedAt;
438
+ this.retryAfterMs = retryAfterMs;
439
+ }
440
+ };
441
+ }
442
+ });
443
+
444
+ // src/errors/ksef-xsd-validation-error.ts
445
+ var KSeFXsdValidationError;
446
+ var init_ksef_xsd_validation_error = __esm({
447
+ "src/errors/ksef-xsd-validation-error.ts"() {
448
+ "use strict";
449
+ init_esm_shims();
450
+ init_ksef_error();
451
+ KSeFXsdValidationError = class extends KSeFError {
452
+ schemaFile;
453
+ errors;
454
+ constructor(schemaFile, errors) {
455
+ const preview = errors.slice(0, 3).join("; ");
456
+ const extra = errors.length > 3 ? ` (+${errors.length - 3} more)` : "";
457
+ super(`XSD validation failed against ${schemaFile}: ${preview}${extra}`);
458
+ this.name = "KSeFXsdValidationError";
459
+ this.schemaFile = schemaFile;
460
+ this.errors = errors;
461
+ }
462
+ };
463
+ }
464
+ });
465
+
398
466
  // src/errors/assert-never.ts
399
467
  function assertNever(value) {
400
468
  throw new Error(`Unexpected value: ${String(value)}`);
@@ -402,6 +470,7 @@ function assertNever(value) {
402
470
  var init_assert_never = __esm({
403
471
  "src/errors/assert-never.ts"() {
404
472
  "use strict";
473
+ init_esm_shims();
405
474
  }
406
475
  });
407
476
 
@@ -409,6 +478,7 @@ var init_assert_never = __esm({
409
478
  var init_errors = __esm({
410
479
  "src/errors/index.ts"() {
411
480
  "use strict";
481
+ init_esm_shims();
412
482
  init_ksef_error();
413
483
  init_ksef_api_error();
414
484
  init_ksef_rate_limit_error();
@@ -420,6 +490,8 @@ var init_errors = __esm({
420
490
  init_ksef_session_expired_error();
421
491
  init_ksef_validation_error();
422
492
  init_ksef_batch_timeout_error();
493
+ init_ksef_circuit_open_error();
494
+ init_ksef_xsd_validation_error();
423
495
  init_error_codes();
424
496
  init_assert_never();
425
497
  }
@@ -430,6 +502,7 @@ var RouteBuilder;
430
502
  var init_route_builder = __esm({
431
503
  "src/http/route-builder.ts"() {
432
504
  "use strict";
505
+ init_esm_shims();
433
506
  RouteBuilder = class {
434
507
  apiVersion;
435
508
  constructor(apiVersion) {
@@ -448,6 +521,7 @@ var RestRequest;
448
521
  var init_rest_request = __esm({
449
522
  "src/http/rest-request.ts"() {
450
523
  "use strict";
524
+ init_esm_shims();
451
525
  RestRequest = class _RestRequest {
452
526
  method;
453
527
  path;
@@ -456,21 +530,21 @@ var init_rest_request = __esm({
456
530
  _query = [];
457
531
  _presigned = false;
458
532
  _skipAuthRetry = false;
459
- constructor(method, path2) {
533
+ constructor(method, path3) {
460
534
  this.method = method;
461
- this.path = path2;
535
+ this.path = path3;
462
536
  }
463
- static get(path2) {
464
- return new _RestRequest("GET", path2);
537
+ static get(path3) {
538
+ return new _RestRequest("GET", path3);
465
539
  }
466
- static post(path2) {
467
- return new _RestRequest("POST", path2);
540
+ static post(path3) {
541
+ return new _RestRequest("POST", path3);
468
542
  }
469
- static put(path2) {
470
- return new _RestRequest("PUT", path2);
543
+ static put(path3) {
544
+ return new _RestRequest("PUT", path3);
471
545
  }
472
- static delete(path2) {
473
- return new _RestRequest("DELETE", path2);
546
+ static delete(path3) {
547
+ return new _RestRequest("DELETE", path3);
474
548
  }
475
549
  body(data) {
476
550
  this._body = data;
@@ -524,6 +598,7 @@ var defaultTransport;
524
598
  var init_transport = __esm({
525
599
  "src/http/transport.ts"() {
526
600
  "use strict";
601
+ init_esm_shims();
527
602
  defaultTransport = (url, init) => fetch(url, init);
528
603
  }
529
604
  });
@@ -573,6 +648,7 @@ var RETRYABLE_ERROR_CODES;
573
648
  var init_retry_policy = __esm({
574
649
  "src/http/retry-policy.ts"() {
575
650
  "use strict";
651
+ init_esm_shims();
576
652
  RETRYABLE_ERROR_CODES = /* @__PURE__ */ new Set([
577
653
  "ECONNRESET",
578
654
  "ECONNREFUSED",
@@ -663,6 +739,7 @@ var BLOCKED_PARAMS;
663
739
  var init_presigned_url_policy = __esm({
664
740
  "src/http/presigned-url-policy.ts"() {
665
741
  "use strict";
742
+ init_esm_shims();
666
743
  init_ksef_validation_error();
667
744
  BLOCKED_PARAMS = ["redirect", "callback", "return_url", "next"];
668
745
  }
@@ -695,6 +772,7 @@ var RestClient;
695
772
  var init_rest_client = __esm({
696
773
  "src/http/rest-client.ts"() {
697
774
  "use strict";
775
+ init_esm_shims();
698
776
  init_ksef_api_error();
699
777
  init_ksef_rate_limit_error();
700
778
  init_ksef_unauthorized_error();
@@ -713,6 +791,7 @@ var init_rest_client = __esm({
713
791
  transport;
714
792
  retryPolicy;
715
793
  rateLimitPolicy;
794
+ circuitBreakerPolicy;
716
795
  authManager;
717
796
  presignedUrlPolicy;
718
797
  constructor(options, config) {
@@ -721,6 +800,7 @@ var init_rest_client = __esm({
721
800
  this.transport = config?.transport ?? defaultTransport;
722
801
  this.retryPolicy = config?.retryPolicy ?? defaultRetryPolicy();
723
802
  this.rateLimitPolicy = config?.rateLimitPolicy ?? null;
803
+ this.circuitBreakerPolicy = config?.circuitBreakerPolicy ?? null;
724
804
  this.authManager = config?.authManager;
725
805
  this.presignedUrlPolicy = config?.presignedUrlPolicy;
726
806
  }
@@ -745,18 +825,32 @@ var init_rest_client = __esm({
745
825
  if (request.isPresigned() && this.presignedUrlPolicy) {
746
826
  validatePresignedUrl(url, this.presignedUrlPolicy);
747
827
  }
828
+ let ownsProbeSlot = false;
829
+ if (this.circuitBreakerPolicy) {
830
+ const claimed = this.circuitBreakerPolicy.ensureClosed(request.path);
831
+ if (claimed) ownsProbeSlot = true;
832
+ }
748
833
  if (this.rateLimitPolicy) {
749
- await this.rateLimitPolicy.acquire(request.path);
834
+ try {
835
+ await this.rateLimitPolicy.acquire(request.path);
836
+ } catch (error) {
837
+ if (ownsProbeSlot) this.circuitBreakerPolicy?.releaseProbe(request.path);
838
+ throw error;
839
+ }
750
840
  }
751
841
  let lastError;
752
842
  for (let attempt = 0; attempt <= this.retryPolicy.maxRetries; attempt++) {
843
+ if (this.circuitBreakerPolicy) {
844
+ const claimed = this.circuitBreakerPolicy.ensureClosed(request.path, ownsProbeSlot);
845
+ if (claimed) ownsProbeSlot = true;
846
+ }
753
847
  try {
754
- const response = await this.doRequest(request, url);
848
+ let response = await this.doRequest(request, url);
755
849
  if (response.status === 401 && this.authManager && attempt === 0 && !request.isSkipAuthRetry()) {
756
850
  const newToken = await this.authManager.onUnauthorized();
757
851
  if (newToken) {
758
852
  consola.debug("Auth token refreshed, retrying request");
759
- return this.doRequest(request, url, newToken);
853
+ response = await this.doRequest(request, url, newToken);
760
854
  }
761
855
  }
762
856
  if (isRetryableStatus(response.status, this.retryPolicy) && attempt < this.retryPolicy.maxRetries) {
@@ -766,10 +860,17 @@ var init_rest_client = __esm({
766
860
  consola.debug(`Retryable ${response.status}, attempt ${attempt + 1}/${this.retryPolicy.maxRetries}, waiting ${Math.round(delayMs)}ms`);
767
861
  await sleep(delayMs);
768
862
  if (is429 && this.rateLimitPolicy) {
769
- await this.rateLimitPolicy.acquire(request.path);
863
+ try {
864
+ await this.rateLimitPolicy.acquire(request.path);
865
+ } catch (error) {
866
+ this.recordCircuitOutcome(request.path, 429);
867
+ ownsProbeSlot = false;
868
+ throw error;
869
+ }
770
870
  }
771
871
  continue;
772
872
  }
873
+ this.recordCircuitOutcome(request.path, response.status);
773
874
  return response;
774
875
  } catch (error) {
775
876
  lastError = error;
@@ -779,11 +880,22 @@ var init_rest_client = __esm({
779
880
  await sleep(delayMs);
780
881
  continue;
781
882
  }
883
+ if (isRetryableError(error, this.retryPolicy) || ownsProbeSlot) {
884
+ this.circuitBreakerPolicy?.recordFailure(request.path);
885
+ }
782
886
  throw error;
783
887
  }
784
888
  }
785
889
  throw lastError;
786
890
  }
891
+ recordCircuitOutcome(path3, status) {
892
+ if (!this.circuitBreakerPolicy) return;
893
+ if (status >= 500) {
894
+ this.circuitBreakerPolicy.recordFailure(path3);
895
+ return;
896
+ }
897
+ this.circuitBreakerPolicy.recordSuccess(path3);
898
+ }
787
899
  async doRequest(request, url, overrideToken) {
788
900
  const headers = {
789
901
  ...this.options.customHeaders,
@@ -819,9 +931,9 @@ var init_rest_client = __esm({
819
931
  return response;
820
932
  }
821
933
  buildUrl(request) {
822
- const path2 = this.routeBuilder.build(request.path);
934
+ const path3 = this.routeBuilder.build(request.path);
823
935
  const base = this.options.baseUrl;
824
- const url = new URL(`${base}${path2}`);
936
+ const url = new URL(`${base}${path3}`);
825
937
  const query = request.getQuery();
826
938
  for (const [key, value] of query) {
827
939
  url.searchParams.append(key, value);
@@ -905,6 +1017,7 @@ var Routes;
905
1017
  var init_routes = __esm({
906
1018
  "src/http/routes.ts"() {
907
1019
  "use strict";
1020
+ init_esm_shims();
908
1021
  Routes = {
909
1022
  TestData: {
910
1023
  createSubject: "testdata/subject",
@@ -1037,6 +1150,7 @@ var TokenBucket, RateLimitPolicy;
1037
1150
  var init_rate_limit_policy = __esm({
1038
1151
  "src/http/rate-limit-policy.ts"() {
1039
1152
  "use strict";
1153
+ init_esm_shims();
1040
1154
  TokenBucket = class {
1041
1155
  tokens;
1042
1156
  maxTokens;
@@ -1097,11 +1211,151 @@ var init_rate_limit_policy = __esm({
1097
1211
  }
1098
1212
  });
1099
1213
 
1214
+ // src/http/circuit-breaker-policy.ts
1215
+ import { consola as consola2 } from "consola";
1216
+ function defaultCircuitBreakerPolicy() {
1217
+ return new CircuitBreakerPolicy();
1218
+ }
1219
+ var GLOBAL_KEY, CircuitBreakerPolicy;
1220
+ var init_circuit_breaker_policy = __esm({
1221
+ "src/http/circuit-breaker-policy.ts"() {
1222
+ "use strict";
1223
+ init_esm_shims();
1224
+ init_ksef_circuit_open_error();
1225
+ GLOBAL_KEY = "__global__";
1226
+ CircuitBreakerPolicy = class _CircuitBreakerPolicy {
1227
+ failureThreshold;
1228
+ openMs;
1229
+ scope;
1230
+ states = /* @__PURE__ */ new Map();
1231
+ constructor(config = {}) {
1232
+ const failureThreshold = config.failureThreshold ?? 5;
1233
+ const openMs = config.openMs ?? 3e4;
1234
+ if (!Number.isInteger(failureThreshold) || failureThreshold <= 0) {
1235
+ throw new RangeError("CircuitBreakerPolicy: failureThreshold must be a positive integer");
1236
+ }
1237
+ if (!Number.isFinite(openMs) || openMs <= 0) {
1238
+ throw new RangeError("CircuitBreakerPolicy: openMs must be > 0");
1239
+ }
1240
+ const scope = config.scope ?? "global";
1241
+ if (scope !== "global" && scope !== "endpoint") {
1242
+ throw new RangeError(
1243
+ "CircuitBreakerPolicy: scope must be 'global' or 'endpoint'"
1244
+ );
1245
+ }
1246
+ this.failureThreshold = failureThreshold;
1247
+ this.openMs = openMs;
1248
+ this.scope = scope;
1249
+ }
1250
+ // Returns true iff this call just claimed the single probe slot for the
1251
+ // caller. The caller MUST pass `alreadyOwnsProbe=true` on subsequent
1252
+ // re-checks for the same logical request (e.g. a retry loop) so the probe
1253
+ // owner cannot deadlock itself on its own in-flight slot.
1254
+ ensureClosed(endpoint, alreadyOwnsProbe = false) {
1255
+ const key = this.keyFor(endpoint);
1256
+ const state = this.states.get(key);
1257
+ if (!state || state.openedAt === null) return false;
1258
+ const now = performance.now();
1259
+ const elapsed = now - state.openedAt;
1260
+ if (elapsed >= this.openMs) {
1261
+ if (alreadyOwnsProbe) return false;
1262
+ if (state.probeInFlight) {
1263
+ throw new KSeFCircuitOpenError(endpoint, state.openedAt, 0);
1264
+ }
1265
+ state.probeInFlight = true;
1266
+ consola2.debug(`Circuit breaker: probe after cooldown for '${key}'`);
1267
+ return true;
1268
+ }
1269
+ const retryAfterMs = Math.max(0, this.openMs - elapsed);
1270
+ throw new KSeFCircuitOpenError(endpoint, state.openedAt, retryAfterMs);
1271
+ }
1272
+ recordSuccess(endpoint) {
1273
+ const key = this.keyFor(endpoint);
1274
+ const state = this.states.get(key);
1275
+ if (!state) return;
1276
+ if (state.openedAt !== null || state.failures > 0) {
1277
+ consola2.debug(`Circuit breaker: reset for '${key}'`);
1278
+ }
1279
+ this.states.delete(key);
1280
+ }
1281
+ // Release a claimed probe slot WITHOUT observing an outcome. Use this when
1282
+ // the probe attempt was aborted before reaching upstream (e.g. rate-limit
1283
+ // acquire rejected, client cancellation). We have no new information about
1284
+ // upstream health, so the breaker must stay OPEN — but we do restart the
1285
+ // cooldown clock so the next probe attempt waits a fresh `openMs`,
1286
+ // preventing a tight loop of aborted probes from spamming the limiter.
1287
+ releaseProbe(endpoint) {
1288
+ const key = this.keyFor(endpoint);
1289
+ const state = this.states.get(key);
1290
+ if (!state || !state.probeInFlight) return;
1291
+ state.probeInFlight = false;
1292
+ if (state.openedAt !== null) {
1293
+ state.openedAt = performance.now();
1294
+ }
1295
+ consola2.debug(`Circuit breaker: probe aborted (not observed) for '${key}', cooldown restarted`);
1296
+ }
1297
+ recordFailure(endpoint) {
1298
+ const key = this.keyFor(endpoint);
1299
+ const now = performance.now();
1300
+ let state = this.states.get(key);
1301
+ if (!state) {
1302
+ state = { failures: 0, openedAt: null, lastFailureAt: null, probeInFlight: false };
1303
+ this.states.set(key, state);
1304
+ }
1305
+ if (state.openedAt !== null && state.probeInFlight) {
1306
+ state.openedAt = now;
1307
+ state.failures = this.failureThreshold;
1308
+ state.lastFailureAt = now;
1309
+ state.probeInFlight = false;
1310
+ consola2.debug(`Circuit breaker: probe failed, re-opened for '${key}'`);
1311
+ this.maybeSweepStaleClosed(now, key);
1312
+ return;
1313
+ }
1314
+ const slidingStale = state.lastFailureAt !== null && now - state.lastFailureAt > this.openMs;
1315
+ state.failures = slidingStale ? 1 : state.failures + 1;
1316
+ state.lastFailureAt = now;
1317
+ if (state.openedAt === null && state.failures >= this.failureThreshold) {
1318
+ state.openedAt = now;
1319
+ consola2.debug(
1320
+ `Circuit breaker: opened for '${key}' after ${state.failures} failures (cooldown ${this.openMs}ms)`
1321
+ );
1322
+ }
1323
+ this.maybeSweepStaleClosed(now, key);
1324
+ }
1325
+ keyFor(endpoint) {
1326
+ return this.scope === "global" ? GLOBAL_KEY : endpoint;
1327
+ }
1328
+ // Prevent unbounded map growth under `scope: 'endpoint'` when callers hit
1329
+ // many distinct parameterized paths (e.g. `auth/sessions/{ref}`) that each
1330
+ // fail once and are never revisited. Global scope is always a single entry.
1331
+ //
1332
+ // Runs amortized O(n) — gated on a size threshold so small workloads pay
1333
+ // nothing. Only evicts states that are genuinely settled: closed, no probe
1334
+ // in flight, and with the last failure older than two cooldowns.
1335
+ maybeSweepStaleClosed(now, keepKey) {
1336
+ if (this.scope !== "endpoint") return;
1337
+ if (this.states.size <= _CircuitBreakerPolicy.sweepThreshold) return;
1338
+ const staleBefore = now - 2 * this.openMs;
1339
+ for (const [key, state] of this.states) {
1340
+ if (key === keepKey) continue;
1341
+ if (state.openedAt !== null) continue;
1342
+ if (state.probeInFlight) continue;
1343
+ if (state.lastFailureAt !== null && state.lastFailureAt < staleBefore) {
1344
+ this.states.delete(key);
1345
+ }
1346
+ }
1347
+ }
1348
+ static sweepThreshold = 64;
1349
+ };
1350
+ }
1351
+ });
1352
+
1100
1353
  // src/http/auth-manager.ts
1101
1354
  var DefaultAuthManager;
1102
1355
  var init_auth_manager = __esm({
1103
1356
  "src/http/auth-manager.ts"() {
1104
1357
  "use strict";
1358
+ init_esm_shims();
1105
1359
  DefaultAuthManager = class {
1106
1360
  token;
1107
1361
  refreshToken;
@@ -1142,6 +1396,7 @@ var KSEF_FEATURE_HEADER, UpoVersion, ENFORCE_XADES_COMPLIANCE;
1142
1396
  var init_ksef_feature = __esm({
1143
1397
  "src/http/ksef-feature.ts"() {
1144
1398
  "use strict";
1399
+ init_esm_shims();
1145
1400
  KSEF_FEATURE_HEADER = "X-KSeF-Feature";
1146
1401
  UpoVersion = {
1147
1402
  /** UPO v4-2 format (default before 2026-01-05). */
@@ -1241,6 +1496,7 @@ var NIP_PATTERN_CORE, VAT_UE_PATTERN_CORE, Nip, VatUe, NipVatUe, InternalId, Pep
1241
1496
  var init_patterns = __esm({
1242
1497
  "src/validation/patterns.ts"() {
1243
1498
  "use strict";
1499
+ init_esm_shims();
1244
1500
  NIP_PATTERN_CORE = "[1-9]((\\d[1-9])|([1-9]\\d))\\d{7}";
1245
1501
  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}))";
1246
1502
  Nip = new RegExp(`^${NIP_PATTERN_CORE}$`);
@@ -1357,6 +1613,7 @@ function getTextContent(el) {
1357
1613
  var init_xml_to_object = __esm({
1358
1614
  "src/validation/xml-to-object.ts"() {
1359
1615
  "use strict";
1616
+ init_esm_shims();
1360
1617
  }
1361
1618
  });
1362
1619
 
@@ -1370,6 +1627,7 @@ var TKodFormularza, TDataCzas, TZnakowy, TNaglowek, TKodyKrajowUE, TNrNIP, TZnak
1370
1627
  var init_fa3 = __esm({
1371
1628
  "src/validation/schemas/fa3.ts"() {
1372
1629
  "use strict";
1630
+ init_esm_shims();
1373
1631
  TKodFormularza = z.literal("FA");
1374
1632
  TDataCzas = z.string();
1375
1633
  TZnakowy = z.string().min(1).max(256);
@@ -1780,6 +2038,7 @@ var TKodFormularza2, TDataCzas2, TZnakowy3, TNaglowek2, TKodyKrajowUE2, TNrNIP2,
1780
2038
  var init_fa2 = __esm({
1781
2039
  "src/validation/schemas/fa2.ts"() {
1782
2040
  "use strict";
2041
+ init_esm_shims();
1783
2042
  TKodFormularza2 = z2.literal("FA");
1784
2043
  TDataCzas2 = z2.string();
1785
2044
  TZnakowy3 = z2.string().min(1).max(256);
@@ -2174,6 +2433,7 @@ var TKodFormularza3, TDataCzas3, TZnakowy4, TNaglowek3, TNrNIP3, TZnakowy5123, T
2174
2433
  var init_rr1_v11e = __esm({
2175
2434
  "src/validation/schemas/rr1-v11e.ts"() {
2176
2435
  "use strict";
2436
+ init_esm_shims();
2177
2437
  TKodFormularza3 = z3.literal("FA_RR");
2178
2438
  TDataCzas3 = z3.string();
2179
2439
  TZnakowy4 = z3.string().min(1).max(256);
@@ -2379,6 +2639,7 @@ var TKodFormularza4, TDataCzas4, TZnakowy5, TNaglowek4, TNrNIP4, TZnakowy5124, T
2379
2639
  var init_rr1_v10e = __esm({
2380
2640
  "src/validation/schemas/rr1-v10e.ts"() {
2381
2641
  "use strict";
2642
+ init_esm_shims();
2382
2643
  TKodFormularza4 = z4.literal("FA_RR");
2383
2644
  TDataCzas4 = z4.string();
2384
2645
  TZnakowy5 = z4.string().min(1).max(256);
@@ -2584,6 +2845,7 @@ var InvoiceType, PEF3Schema;
2584
2845
  var init_pef3 = __esm({
2585
2846
  "src/validation/schemas/pef3.ts"() {
2586
2847
  "use strict";
2848
+ init_esm_shims();
2587
2849
  InvoiceType = z5.object({
2588
2850
  "UBLExtensions": z5.any().optional(),
2589
2851
  "UBLVersionID": z5.any().optional(),
@@ -2654,6 +2916,7 @@ var CreditNoteType, PEF_KOR3Schema;
2654
2916
  var init_pef_kor3 = __esm({
2655
2917
  "src/validation/schemas/pef-kor3.ts"() {
2656
2918
  "use strict";
2919
+ init_esm_shims();
2657
2920
  CreditNoteType = z6.object({
2658
2921
  "UBLExtensions": z6.any().optional(),
2659
2922
  "UBLVersionID": z6.any().optional(),
@@ -2716,6 +2979,7 @@ var NAMESPACE_MAP;
2716
2979
  var init_schemas = __esm({
2717
2980
  "src/validation/schemas/index.ts"() {
2718
2981
  "use strict";
2982
+ init_esm_shims();
2719
2983
  init_fa3();
2720
2984
  init_fa2();
2721
2985
  init_rr1_v11e();
@@ -2772,6 +3036,7 @@ var ROOT_ELEMENT_MAP, schemaCache, SchemaRegistry;
2772
3036
  var init_schema_registry = __esm({
2773
3037
  "src/validation/schema-registry.ts"() {
2774
3038
  "use strict";
3039
+ init_esm_shims();
2775
3040
  init_schemas();
2776
3041
  ROOT_ELEMENT_MAP = {
2777
3042
  Invoice: "PEF3",
@@ -2897,6 +3162,7 @@ var DISCOURAGED_UNICODE_RANGES, PI_TARGET_RE;
2897
3162
  var init_char_validity = __esm({
2898
3163
  "src/validation/char-validity.ts"() {
2899
3164
  "use strict";
3165
+ init_esm_shims();
2900
3166
  DISCOURAGED_UNICODE_RANGES = [
2901
3167
  [127, 132],
2902
3168
  [134, 159],
@@ -2979,11 +3245,11 @@ async function validateSchema(xml, options, _parsed) {
2979
3245
  const prefix = rootElement ? `/${rootElement}/` : "/";
2980
3246
  const validationErrors = result.error.issues.map((issue) => {
2981
3247
  const zodPath = issue.path.join("/");
2982
- const path2 = zodPath ? `${prefix}${zodPath}` : rootElement ? `/${rootElement}` : void 0;
3248
+ const path3 = zodPath ? `${prefix}${zodPath}` : rootElement ? `/${rootElement}` : void 0;
2983
3249
  return {
2984
3250
  code: mapZodErrorCode(issue),
2985
3251
  message: issue.message,
2986
- path: path2
3252
+ path: path3
2987
3253
  };
2988
3254
  });
2989
3255
  return { valid: false, schemaType, errors: validationErrors };
@@ -3023,9 +3289,9 @@ function validateBusinessRules(xml, _parsed) {
3023
3289
  collectDateErrors(object, rootElement, errors);
3024
3290
  return { valid: errors.length === 0, schemaType, errors };
3025
3291
  }
3026
- function collectNipPeselErrors(obj, path2, errors) {
3292
+ function collectNipPeselErrors(obj, path3, errors) {
3027
3293
  for (const [key, value] of Object.entries(obj)) {
3028
- const currentPath = path2 ? `${path2}/${key}` : key;
3294
+ const currentPath = path3 ? `${path3}/${key}` : key;
3029
3295
  if (key === "NIP" && typeof value === "string") {
3030
3296
  if (!isValidNip(value)) {
3031
3297
  errors.push({
@@ -3104,6 +3370,7 @@ function batchValidationDetails(batch) {
3104
3370
  var init_invoice_validator = __esm({
3105
3371
  "src/validation/invoice-validator.ts"() {
3106
3372
  "use strict";
3373
+ init_esm_shims();
3107
3374
  init_xml_to_object();
3108
3375
  init_schema_registry();
3109
3376
  init_char_validity();
@@ -3116,6 +3383,7 @@ var SystemCode, FORM_CODES, DEFAULT_FORM_CODE, INVOICE_TYPES_BY_SYSTEM_CODE, FOR
3116
3383
  var init_types = __esm({
3117
3384
  "src/models/document-structures/types.ts"() {
3118
3385
  "use strict";
3386
+ init_esm_shims();
3119
3387
  SystemCode = {
3120
3388
  FA_2: "FA (2)",
3121
3389
  FA_3: "FA (3)",
@@ -3168,6 +3436,7 @@ var SYSTEM_CODE_TO_FORM_CODE, ALL_FORM_CODES, BATCH_DISALLOWED_SYSTEM_CODES;
3168
3436
  var init_helpers = __esm({
3169
3437
  "src/models/document-structures/helpers.ts"() {
3170
3438
  "use strict";
3439
+ init_esm_shims();
3171
3440
  init_types();
3172
3441
  SYSTEM_CODE_TO_FORM_CODE = {
3173
3442
  [SystemCode.FA_2]: FORM_CODES.FA_2,
@@ -3188,6 +3457,7 @@ var init_helpers = __esm({
3188
3457
  var init_document_structures = __esm({
3189
3458
  "src/models/document-structures/index.ts"() {
3190
3459
  "use strict";
3460
+ init_esm_shims();
3191
3461
  init_types();
3192
3462
  init_helpers();
3193
3463
  }
@@ -3198,6 +3468,7 @@ var AuthService;
3198
3468
  var init_auth = __esm({
3199
3469
  "src/services/auth.ts"() {
3200
3470
  "use strict";
3471
+ init_esm_shims();
3201
3472
  init_ksef_feature();
3202
3473
  init_rest_request();
3203
3474
  init_routes();
@@ -3248,6 +3519,7 @@ var ActiveSessionsService;
3248
3519
  var init_active_sessions = __esm({
3249
3520
  "src/services/active-sessions.ts"() {
3250
3521
  "use strict";
3522
+ init_esm_shims();
3251
3523
  init_rest_request();
3252
3524
  init_routes();
3253
3525
  ActiveSessionsService = class {
@@ -3279,6 +3551,7 @@ var OnlineSessionService;
3279
3551
  var init_online_session = __esm({
3280
3552
  "src/services/online-session.ts"() {
3281
3553
  "use strict";
3554
+ init_esm_shims();
3282
3555
  init_ksef_feature();
3283
3556
  init_rest_request();
3284
3557
  init_routes();
@@ -3331,6 +3604,7 @@ async function runWithConcurrency(tasks, parallelism) {
3331
3604
  var init_concurrency = __esm({
3332
3605
  "src/utils/concurrency.ts"() {
3333
3606
  "use strict";
3607
+ init_esm_shims();
3334
3608
  }
3335
3609
  });
3336
3610
 
@@ -3339,6 +3613,7 @@ var BatchSessionService;
3339
3613
  var init_batch_session = __esm({
3340
3614
  "src/services/batch-session.ts"() {
3341
3615
  "use strict";
3616
+ init_esm_shims();
3342
3617
  init_ksef_feature();
3343
3618
  init_rest_request();
3344
3619
  init_routes();
@@ -3443,6 +3718,7 @@ var SessionStatusService;
3443
3718
  var init_session_status = __esm({
3444
3719
  "src/services/session-status.ts"() {
3445
3720
  "use strict";
3721
+ init_esm_shims();
3446
3722
  init_rest_request();
3447
3723
  init_routes();
3448
3724
  SessionStatusService = class {
@@ -3529,6 +3805,7 @@ var InvoiceDownloadService;
3529
3805
  var init_invoice_download = __esm({
3530
3806
  "src/services/invoice-download.ts"() {
3531
3807
  "use strict";
3808
+ init_esm_shims();
3532
3809
  init_rest_request();
3533
3810
  init_routes();
3534
3811
  InvoiceDownloadService = class {
@@ -3571,6 +3848,7 @@ var PermissionsService;
3571
3848
  var init_permissions = __esm({
3572
3849
  "src/services/permissions.ts"() {
3573
3850
  "use strict";
3851
+ init_esm_shims();
3574
3852
  init_ksef_validation_error();
3575
3853
  init_rest_request();
3576
3854
  init_routes();
@@ -3763,6 +4041,7 @@ function parseKSeFTokenContext(token) {
3763
4041
  var init_jwt = __esm({
3764
4042
  "src/utils/jwt.ts"() {
3765
4043
  "use strict";
4044
+ init_esm_shims();
3766
4045
  }
3767
4046
  });
3768
4047
 
@@ -3774,6 +4053,7 @@ var TOKEN_AUTHOR_IDENTIFIER_TYPES, TokenService;
3774
4053
  var init_tokens = __esm({
3775
4054
  "src/services/tokens.ts"() {
3776
4055
  "use strict";
4056
+ init_esm_shims();
3777
4057
  init_rest_request();
3778
4058
  init_routes();
3779
4059
  init_jwt();
@@ -3894,6 +4174,7 @@ var CertificateApiService;
3894
4174
  var init_certificates = __esm({
3895
4175
  "src/services/certificates.ts"() {
3896
4176
  "use strict";
4177
+ init_esm_shims();
3897
4178
  init_rest_request();
3898
4179
  init_routes();
3899
4180
  CertificateApiService = class {
@@ -3946,6 +4227,7 @@ var LighthouseService;
3946
4227
  var init_lighthouse = __esm({
3947
4228
  "src/services/lighthouse.ts"() {
3948
4229
  "use strict";
4230
+ init_esm_shims();
3949
4231
  init_errors();
3950
4232
  LighthouseService = class {
3951
4233
  lighthouseUrl;
@@ -3954,20 +4236,20 @@ var init_lighthouse = __esm({
3954
4236
  this.lighthouseUrl = options.lighthouseUrl;
3955
4237
  this.timeout = options.timeout;
3956
4238
  }
3957
- async fetchJson(path2) {
4239
+ async fetchJson(path3) {
3958
4240
  if (!this.lighthouseUrl) {
3959
4241
  throw new KSeFError(
3960
4242
  "Lighthouse API is not available for the DEMO environment. Use TEST or PROD instead."
3961
4243
  );
3962
4244
  }
3963
- const response = await fetch(`${this.lighthouseUrl}${path2}`, {
4245
+ const response = await fetch(`${this.lighthouseUrl}${path3}`, {
3964
4246
  headers: { Accept: "application/json" },
3965
4247
  signal: AbortSignal.timeout(this.timeout)
3966
4248
  });
3967
4249
  if (!response.ok) {
3968
4250
  const body = await response.text();
3969
4251
  throw new KSeFError(
3970
- `Lighthouse ${path2} failed: HTTP ${response.status} \u2014 ${body}`
4252
+ `Lighthouse ${path3} failed: HTTP ${response.status} \u2014 ${body}`
3971
4253
  );
3972
4254
  }
3973
4255
  return await response.json();
@@ -3988,6 +4270,7 @@ var LimitsService;
3988
4270
  var init_limits = __esm({
3989
4271
  "src/services/limits.ts"() {
3990
4272
  "use strict";
4273
+ init_esm_shims();
3991
4274
  init_rest_request();
3992
4275
  init_routes();
3993
4276
  LimitsService = class {
@@ -4019,6 +4302,7 @@ var PeppolService;
4019
4302
  var init_peppol = __esm({
4020
4303
  "src/services/peppol.ts"() {
4021
4304
  "use strict";
4305
+ init_esm_shims();
4022
4306
  init_rest_request();
4023
4307
  init_routes();
4024
4308
  PeppolService = class {
@@ -4042,6 +4326,7 @@ var TestDataService;
4042
4326
  var init_test_data = __esm({
4043
4327
  "src/services/test-data.ts"() {
4044
4328
  "use strict";
4329
+ init_esm_shims();
4045
4330
  init_rest_request();
4046
4331
  init_routes();
4047
4332
  init_ksef_error();
@@ -4161,6 +4446,7 @@ var CertificateFetcher;
4161
4446
  var init_certificate_fetcher = __esm({
4162
4447
  "src/crypto/certificate-fetcher.ts"() {
4163
4448
  "use strict";
4449
+ init_esm_shims();
4164
4450
  init_rest_request();
4165
4451
  init_routes();
4166
4452
  CertificateFetcher = class {
@@ -4225,7 +4511,7 @@ ${lines.join("\n")}
4225
4511
  });
4226
4512
 
4227
4513
  // src/crypto/cryptography-service.ts
4228
- import * as crypto2 from "crypto";
4514
+ import * as crypto2 from "node:crypto";
4229
4515
  import * as x509 from "@peculiar/x509";
4230
4516
  function setCryptoProvider() {
4231
4517
  x509.cryptoProvider.set(crypto2.webcrypto);
@@ -4256,6 +4542,7 @@ var CryptographyService;
4256
4542
  var init_cryptography_service = __esm({
4257
4543
  "src/crypto/cryptography-service.ts"() {
4258
4544
  "use strict";
4545
+ init_esm_shims();
4259
4546
  CryptographyService = class {
4260
4547
  fetcher;
4261
4548
  constructor(fetcher) {
@@ -4313,7 +4600,7 @@ var init_cryptography_service = __esm({
4313
4600
  const certPem = this.fetcher.getSymmetricKeyEncryptionPem();
4314
4601
  const encryptedKey = crypto2.publicEncrypt(
4315
4602
  {
4316
- key: certPem,
4603
+ key: this.extractSpkiPem(certPem),
4317
4604
  oaepHash: "sha256",
4318
4605
  padding: crypto2.constants.RSA_PKCS1_OAEP_PADDING
4319
4606
  },
@@ -4443,12 +4730,22 @@ var init_cryptography_service = __esm({
4443
4730
  // ---------------------------------------------------------------------------
4444
4731
  // Private helpers
4445
4732
  // ---------------------------------------------------------------------------
4733
+ /**
4734
+ * Extract a public-key SPKI PEM (`-----BEGIN PUBLIC KEY-----`) from a full
4735
+ * CERTIFICATE PEM. Node's `publicEncrypt` accepts either form, but Deno's
4736
+ * Node compatibility layer only accepts SPKI PEM, so we normalize upfront
4737
+ * to keep the library portable across runtimes.
4738
+ */
4739
+ extractSpkiPem(certPem) {
4740
+ const publicKey = new crypto2.X509Certificate(certPem).publicKey;
4741
+ return publicKey.export({ type: "spki", format: "pem" });
4742
+ }
4446
4743
  /** RSA-OAEP SHA-256 encryption. */
4447
4744
  encryptRsaOaep(certPem, plaintext) {
4448
4745
  return new Uint8Array(
4449
4746
  crypto2.publicEncrypt(
4450
4747
  {
4451
- key: certPem,
4748
+ key: this.extractSpkiPem(certPem),
4452
4749
  oaepHash: "sha256",
4453
4750
  padding: crypto2.constants.RSA_PKCS1_OAEP_PADDING
4454
4751
  },
@@ -4490,9 +4787,43 @@ var signature_service_exports = {};
4490
4787
  __export(signature_service_exports, {
4491
4788
  SignatureService: () => SignatureService
4492
4789
  });
4493
- import * as crypto3 from "crypto";
4790
+ import * as crypto3 from "node:crypto";
4494
4791
  import { ExclusiveCanonicalization } from "xml-crypto";
4495
4792
  import { DOMParser as DOMParser2, XMLSerializer } from "@xmldom/xmldom";
4793
+ function pickRsaAlgo() {
4794
+ return {
4795
+ nodeHashName: "sha256",
4796
+ signatureUri: RSA_SHA256_SIGNATURE_URI,
4797
+ digestUri: DIGEST_URI.sha256
4798
+ };
4799
+ }
4800
+ function pickEcdsaAlgo(privateKey) {
4801
+ const curve = privateKey.asymmetricKeyDetails?.namedCurve;
4802
+ switch (curve) {
4803
+ case "prime256v1":
4804
+ return {
4805
+ nodeHashName: "sha256",
4806
+ signatureUri: ECDSA_SIGNATURE_URI.sha256,
4807
+ digestUri: DIGEST_URI.sha256
4808
+ };
4809
+ case "secp384r1":
4810
+ return {
4811
+ nodeHashName: "sha384",
4812
+ signatureUri: ECDSA_SIGNATURE_URI.sha384,
4813
+ digestUri: DIGEST_URI.sha384
4814
+ };
4815
+ case "secp521r1":
4816
+ return {
4817
+ nodeHashName: "sha512",
4818
+ signatureUri: ECDSA_SIGNATURE_URI.sha512,
4819
+ digestUri: DIGEST_URI.sha512
4820
+ };
4821
+ default:
4822
+ throw new KSeFError(
4823
+ `Unsupported ECDSA curve: ${curve ?? "unknown"}. Supported: P-256 (prime256v1), P-384 (secp384r1), P-521 (secp521r1).`
4824
+ );
4825
+ }
4826
+ }
4496
4827
  function extractDerFromPem(pem) {
4497
4828
  const base64 = pem.replace(/-----BEGIN [A-Z\s]+-----/g, "").replace(/-----END [A-Z\s]+-----/g, "").replace(/\s+/g, "");
4498
4829
  return Buffer.from(base64, "base64");
@@ -4507,12 +4838,12 @@ function canonicalize(elem) {
4507
4838
  const c14n = new ExclusiveCanonicalization();
4508
4839
  return c14n.process(elem, {});
4509
4840
  }
4510
- function computeRootDigest(doc) {
4841
+ function computeRootDigest(doc, hashName) {
4511
4842
  const root = doc.documentElement;
4512
4843
  const canonical = canonicalize(root);
4513
- return crypto3.createHash("sha256").update(canonical, "utf-8").digest("base64");
4844
+ return crypto3.createHash(hashName).update(canonical, "utf-8").digest("base64");
4514
4845
  }
4515
- function computeSignedPropertiesDigest(qualifyingPropertiesXml) {
4846
+ function computeSignedPropertiesDigest(qualifyingPropertiesXml, hashName) {
4516
4847
  const parser2 = new DOMParser2();
4517
4848
  const qpDoc = parser2.parseFromString(qualifyingPropertiesXml, "text/xml");
4518
4849
  const signedProps = findElementByLocalName(qpDoc.documentElement, "SignedProperties");
@@ -4520,9 +4851,9 @@ function computeSignedPropertiesDigest(qualifyingPropertiesXml) {
4520
4851
  throw new Error("SignedProperties element not found in QualifyingProperties");
4521
4852
  }
4522
4853
  const canonical = canonicalize(signedProps);
4523
- return crypto3.createHash("sha256").update(canonical, "utf-8").digest("base64");
4854
+ return crypto3.createHash(hashName).update(canonical, "utf-8").digest("base64");
4524
4855
  }
4525
- function buildSignedInfo(signatureAlgorithm, rootDigest, signedPropertiesDigest) {
4856
+ function buildSignedInfo(signatureAlgorithm, digestAlgorithm, rootDigest, signedPropertiesDigest) {
4526
4857
  return [
4527
4858
  `<ds:SignedInfo xmlns:ds="${DS_NS}">`,
4528
4859
  `<ds:CanonicalizationMethod Algorithm="${EXC_C14N_ALGORITHM}"/>`,
@@ -4533,7 +4864,7 @@ function buildSignedInfo(signatureAlgorithm, rootDigest, signedPropertiesDigest)
4533
4864
  `<ds:Transform Algorithm="${ENVELOPED_SIGNATURE_TRANSFORM}"/>`,
4534
4865
  `<ds:Transform Algorithm="${EXC_C14N_ALGORITHM}"/>`,
4535
4866
  `</ds:Transforms>`,
4536
- `<ds:DigestMethod Algorithm="${SHA256_DIGEST_METHOD}"/>`,
4867
+ `<ds:DigestMethod Algorithm="${digestAlgorithm}"/>`,
4537
4868
  `<ds:DigestValue>${rootDigest}</ds:DigestValue>`,
4538
4869
  `</ds:Reference>`,
4539
4870
  // Reference 2: SignedProperties
@@ -4541,22 +4872,22 @@ function buildSignedInfo(signatureAlgorithm, rootDigest, signedPropertiesDigest)
4541
4872
  `<ds:Transforms>`,
4542
4873
  `<ds:Transform Algorithm="${EXC_C14N_ALGORITHM}"/>`,
4543
4874
  `</ds:Transforms>`,
4544
- `<ds:DigestMethod Algorithm="${SHA256_DIGEST_METHOD}"/>`,
4875
+ `<ds:DigestMethod Algorithm="${digestAlgorithm}"/>`,
4545
4876
  `<ds:DigestValue>${signedPropertiesDigest}</ds:DigestValue>`,
4546
4877
  `</ds:Reference>`,
4547
4878
  `</ds:SignedInfo>`
4548
4879
  ].join("");
4549
4880
  }
4550
- function computeSignatureValue(canonicalSignedInfo, privateKey, isEc) {
4881
+ function computeSignatureValue(canonicalSignedInfo, privateKey, isEc, hashName) {
4551
4882
  const data = Buffer.from(canonicalSignedInfo, "utf-8");
4552
4883
  let signature;
4553
4884
  if (isEc) {
4554
- signature = crypto3.sign("sha256", data, {
4885
+ signature = crypto3.sign(hashName, data, {
4555
4886
  key: privateKey,
4556
4887
  dsaEncoding: "ieee-p1363"
4557
4888
  });
4558
4889
  } else {
4559
- signature = crypto3.sign("sha256", data, privateKey);
4890
+ signature = crypto3.sign(hashName, data, privateKey);
4560
4891
  }
4561
4892
  return signature.toString("base64");
4562
4893
  }
@@ -4577,7 +4908,7 @@ function buildSignatureElement(signedInfoXml, signatureValue, certBase64, qualif
4577
4908
  `</ds:Signature>`
4578
4909
  ].join("");
4579
4910
  }
4580
- function buildQualifyingProperties(signatureId, signedPropertiesId, certDigest, issuerName, serialNumber, signingTime) {
4911
+ function buildQualifyingProperties(signatureId, signedPropertiesId, certDigest, issuerName, serialNumber, signingTime, digestAlgorithm) {
4581
4912
  return [
4582
4913
  `<xades:QualifyingProperties`,
4583
4914
  ` Target="#${signatureId}"`,
@@ -4589,7 +4920,7 @@ function buildQualifyingProperties(signatureId, signedPropertiesId, certDigest,
4589
4920
  `<xades:SigningCertificate>`,
4590
4921
  `<xades:Cert>`,
4591
4922
  `<xades:CertDigest>`,
4592
- `<DigestMethod Algorithm="${SHA256_DIGEST_METHOD}"/>`,
4923
+ `<DigestMethod Algorithm="${digestAlgorithm}"/>`,
4593
4924
  `<DigestValue>${certDigest}</DigestValue>`,
4594
4925
  `</xades:CertDigest>`,
4595
4926
  `<xades:IssuerSerial>`,
@@ -4625,18 +4956,28 @@ function wrapBase64(base64) {
4625
4956
  }
4626
4957
  return lines.join("\n");
4627
4958
  }
4628
- var XADES_NS, DS_NS, SIGNED_PROPERTIES_TYPE, SHA256_DIGEST_METHOD, EXC_C14N_ALGORITHM, ENVELOPED_SIGNATURE_TRANSFORM, RSA_SHA256_SIGNATURE, ECDSA_SHA256_SIGNATURE, CLOCK_SKEW_BUFFER_MS, SIGNATURE_ID, SIGNED_PROPERTIES_ID, SignatureService;
4959
+ var 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;
4629
4960
  var init_signature_service = __esm({
4630
4961
  "src/crypto/signature-service.ts"() {
4631
4962
  "use strict";
4963
+ init_esm_shims();
4964
+ init_ksef_error();
4632
4965
  XADES_NS = "http://uri.etsi.org/01903/v1.3.2#";
4633
4966
  DS_NS = "http://www.w3.org/2000/09/xmldsig#";
4634
4967
  SIGNED_PROPERTIES_TYPE = "http://uri.etsi.org/01903#SignedProperties";
4635
- SHA256_DIGEST_METHOD = "http://www.w3.org/2001/04/xmlenc#sha256";
4636
4968
  EXC_C14N_ALGORITHM = "http://www.w3.org/2001/10/xml-exc-c14n#";
4637
4969
  ENVELOPED_SIGNATURE_TRANSFORM = "http://www.w3.org/2000/09/xmldsig#enveloped-signature";
4638
- RSA_SHA256_SIGNATURE = "http://www.w3.org/2001/04/xmldsig-more#rsa-sha256";
4639
- ECDSA_SHA256_SIGNATURE = "http://www.w3.org/2001/04/xmldsig-more#ecdsa-sha256";
4970
+ DIGEST_URI = {
4971
+ sha256: "http://www.w3.org/2001/04/xmlenc#sha256",
4972
+ sha384: "http://www.w3.org/2001/04/xmldsig-more#sha384",
4973
+ sha512: "http://www.w3.org/2001/04/xmlenc#sha512"
4974
+ };
4975
+ ECDSA_SIGNATURE_URI = {
4976
+ sha256: "http://www.w3.org/2001/04/xmldsig-more#ecdsa-sha256",
4977
+ sha384: "http://www.w3.org/2001/04/xmldsig-more#ecdsa-sha384",
4978
+ sha512: "http://www.w3.org/2001/04/xmldsig-more#ecdsa-sha512"
4979
+ };
4980
+ RSA_SHA256_SIGNATURE_URI = "http://www.w3.org/2001/04/xmldsig-more#rsa-sha256";
4640
4981
  CLOCK_SKEW_BUFFER_MS = -6e4;
4641
4982
  SIGNATURE_ID = "Signature";
4642
4983
  SIGNED_PROPERTIES_ID = "SignedProperties";
@@ -4656,15 +4997,21 @@ var init_signature_service = __esm({
4656
4997
  }
4657
4998
  const certDer = extractDerFromPem(certPem);
4658
4999
  const certBase64 = certDer.toString("base64");
4659
- const certDigest = crypto3.createHash("sha256").update(certDer).digest("base64");
4660
5000
  const x5093 = new crypto3.X509Certificate(certPem);
4661
5001
  const issuerName = normalizeIssuerDn(x5093.issuer);
4662
5002
  const serialNumber = hexSerialToDecimal(x5093.serialNumber);
4663
5003
  const privateKey = crypto3.createPrivateKey(
4664
5004
  passphrase ? { key: privateKeyPem, format: "pem", passphrase } : privateKeyPem
4665
5005
  );
4666
- const isEc = privateKey.asymmetricKeyType === "ec";
4667
- const signatureAlgorithm = isEc ? ECDSA_SHA256_SIGNATURE : RSA_SHA256_SIGNATURE;
5006
+ const keyType = privateKey.asymmetricKeyType;
5007
+ if (keyType !== "ec" && keyType !== "rsa") {
5008
+ throw new KSeFError(
5009
+ `Unsupported private key type: ${keyType ?? "unknown"}. Supported: RSA and ECDSA.`
5010
+ );
5011
+ }
5012
+ const isEc = keyType === "ec";
5013
+ const algo = isEc ? pickEcdsaAlgo(privateKey) : pickRsaAlgo();
5014
+ const certDigest = crypto3.createHash(algo.nodeHashName).update(certDer).digest("base64");
4668
5015
  const signingTime = new Date(Date.now() + CLOCK_SKEW_BUFFER_MS).toISOString();
4669
5016
  const parser2 = new DOMParser2();
4670
5017
  const doc = parser2.parseFromString(xml, "text/xml");
@@ -4678,12 +5025,17 @@ var init_signature_service = __esm({
4678
5025
  certDigest,
4679
5026
  issuerName,
4680
5027
  serialNumber,
4681
- signingTime
5028
+ signingTime,
5029
+ algo.digestUri
5030
+ );
5031
+ const rootDigest = computeRootDigest(doc, algo.nodeHashName);
5032
+ const signedPropertiesDigest = computeSignedPropertiesDigest(
5033
+ qualifyingPropertiesXml,
5034
+ algo.nodeHashName
4682
5035
  );
4683
- const rootDigest = computeRootDigest(doc);
4684
- const signedPropertiesDigest = computeSignedPropertiesDigest(qualifyingPropertiesXml);
4685
5036
  const signedInfoXml = buildSignedInfo(
4686
- signatureAlgorithm,
5037
+ algo.signatureUri,
5038
+ algo.digestUri,
4687
5039
  rootDigest,
4688
5040
  signedPropertiesDigest
4689
5041
  );
@@ -4692,7 +5044,8 @@ var init_signature_service = __esm({
4692
5044
  const signatureValue = computeSignatureValue(
4693
5045
  canonicalSignedInfo,
4694
5046
  privateKey,
4695
- isEc
5047
+ isEc,
5048
+ algo.nodeHashName
4696
5049
  );
4697
5050
  const signatureXml = buildSignatureElement(
4698
5051
  signedInfoXml,
@@ -4719,6 +5072,7 @@ var Pkcs12Loader;
4719
5072
  var init_pkcs12_loader = __esm({
4720
5073
  "src/crypto/pkcs12-loader.ts"() {
4721
5074
  "use strict";
5075
+ init_esm_shims();
4722
5076
  Pkcs12Loader = class {
4723
5077
  static load(p12, password) {
4724
5078
  const { pki, pkcs12, asn1 } = forge;
@@ -4787,16 +5141,18 @@ var AUTH_TOKEN_REQUEST_NS;
4787
5141
  var init_auth_xml_builder = __esm({
4788
5142
  "src/crypto/auth-xml-builder.ts"() {
4789
5143
  "use strict";
5144
+ init_esm_shims();
4790
5145
  AUTH_TOKEN_REQUEST_NS = "http://ksef.mf.gov.pl/auth/token/2.0";
4791
5146
  }
4792
5147
  });
4793
5148
 
4794
5149
  // src/qr/verification-link-service.ts
4795
- import crypto5 from "crypto";
5150
+ import crypto5 from "node:crypto";
4796
5151
  var VerificationLinkService;
4797
5152
  var init_verification_link_service = __esm({
4798
5153
  "src/qr/verification-link-service.ts"() {
4799
5154
  "use strict";
5155
+ init_esm_shims();
4800
5156
  VerificationLinkService = class {
4801
5157
  constructor(baseQrUrl) {
4802
5158
  this.baseQrUrl = baseQrUrl;
@@ -4818,11 +5174,11 @@ var init_verification_link_service = __esm({
4818
5174
  * Build certificate verification URL (Code II).
4819
5175
  * Format: {baseQrUrl}/certificate/{contextType}/{contextId}/{sellerNip}/{certSerial}/{hash_base64url}/{signature_base64url}
4820
5176
  */
4821
- buildCertificateVerificationUrl(contextType, contextId, sellerNip, certSerial, invoiceHashBase64, privateKeyPem) {
5177
+ buildCertificateVerificationUrl(contextType, contextId, sellerNip, certSerial, invoiceHashBase64, privateKeyPem, privateKeyPassword) {
4822
5178
  const hashBase64Url = this.base64ToBase64Url(invoiceHashBase64);
4823
5179
  const pathWithoutSignature = `${this.baseQrUrl}/certificate/${contextType}/${contextId}/${sellerNip}/${certSerial}/${hashBase64Url}`;
4824
5180
  const dataToSign = pathWithoutSignature.replace(/^https?:\/\//, "");
4825
- const key = crypto5.createPrivateKey(privateKeyPem);
5181
+ const key = privateKeyPassword !== void 0 ? crypto5.createPrivateKey({ key: privateKeyPem, format: "pem", passphrase: privateKeyPassword }) : crypto5.createPrivateKey(privateKeyPem);
4826
5182
  let signature;
4827
5183
  if (key.asymmetricKeyType === "rsa") {
4828
5184
  signature = crypto5.sign("sha256", Buffer.from(dataToSign), {
@@ -4938,6 +5294,7 @@ var DEFAULT_UNZIP_OPTIONS;
4938
5294
  var init_zip = __esm({
4939
5295
  "src/utils/zip.ts"() {
4940
5296
  "use strict";
5297
+ init_esm_shims();
4941
5298
  DEFAULT_UNZIP_OPTIONS = {
4942
5299
  maxFiles: 1e4,
4943
5300
  maxTotalUncompressedSize: 2e9,
@@ -5009,6 +5366,7 @@ var holidayCache;
5009
5366
  var init_holidays = __esm({
5010
5367
  "src/offline/holidays.ts"() {
5011
5368
  "use strict";
5369
+ init_esm_shims();
5012
5370
  holidayCache = /* @__PURE__ */ new Map();
5013
5371
  }
5014
5372
  });
@@ -5108,17 +5466,19 @@ var FAR_FUTURE;
5108
5466
  var init_deadline = __esm({
5109
5467
  "src/offline/deadline.ts"() {
5110
5468
  "use strict";
5469
+ init_esm_shims();
5111
5470
  init_holidays();
5112
5471
  FAR_FUTURE = /* @__PURE__ */ new Date("9999-12-31T23:59:59Z");
5113
5472
  }
5114
5473
  });
5115
5474
 
5116
5475
  // src/workflows/offline-invoice-workflow.ts
5117
- import crypto7 from "crypto";
5476
+ import crypto7 from "node:crypto";
5118
5477
  var OfflineInvoiceWorkflow;
5119
5478
  var init_offline_invoice_workflow = __esm({
5120
5479
  "src/workflows/offline-invoice-workflow.ts"() {
5121
5480
  "use strict";
5481
+ init_esm_shims();
5122
5482
  init_ksef_api_error();
5123
5483
  init_deadline();
5124
5484
  init_document_structures();
@@ -5152,7 +5512,8 @@ var init_offline_invoice_workflow = __esm({
5152
5512
  input.sellerNip,
5153
5513
  options.certificate.certificateSerial,
5154
5514
  invoiceHashBase64,
5155
- options.certificate.privateKeyPem
5515
+ options.certificate.privateKeyPem,
5516
+ options.certificate.password
5156
5517
  );
5157
5518
  }
5158
5519
  const submitBy = options?.customDeadline ? typeof options.customDeadline === "string" ? options.customDeadline : options.customDeadline.toISOString() : calculateOfflineDeadline(mode, input.invoiceDate, options?.maintenanceWindow).toISOString();
@@ -5342,7 +5703,8 @@ var init_offline_invoice_workflow = __esm({
5342
5703
  original.sellerNip,
5343
5704
  options.certificate.certificateSerial,
5344
5705
  correctedHashBase64,
5345
- options.certificate.privateKeyPem
5706
+ options.certificate.privateKeyPem,
5707
+ options.certificate.password
5346
5708
  );
5347
5709
  }
5348
5710
  const correctionMetadata = {
@@ -5428,6 +5790,11 @@ function buildRestClientConfig(options, authManager) {
5428
5790
  endpointLimits: options.rateLimit.endpointLimits
5429
5791
  });
5430
5792
  }
5793
+ if (options?.circuitBreaker === null) {
5794
+ config.circuitBreakerPolicy = null;
5795
+ } else if (options?.circuitBreaker) {
5796
+ config.circuitBreakerPolicy = new CircuitBreakerPolicy(options.circuitBreaker);
5797
+ }
5431
5798
  if (options?.presignedUrlHosts) {
5432
5799
  const base = defaultPresignedUrlPolicy();
5433
5800
  config.presignedUrlPolicy = {
@@ -5441,10 +5808,12 @@ var KSeFClient;
5441
5808
  var init_client = __esm({
5442
5809
  "src/client.ts"() {
5443
5810
  "use strict";
5811
+ init_esm_shims();
5444
5812
  init_config();
5445
5813
  init_rest_client();
5446
5814
  init_retry_policy();
5447
5815
  init_rate_limit_policy();
5816
+ init_circuit_breaker_policy();
5448
5817
  init_presigned_url_policy();
5449
5818
  init_auth_manager();
5450
5819
  init_auth();
@@ -5578,10 +5947,12 @@ var init_client = __esm({
5578
5947
  });
5579
5948
 
5580
5949
  // src/index.ts
5950
+ init_esm_shims();
5581
5951
  init_config();
5582
5952
  init_errors();
5583
5953
 
5584
5954
  // src/http/index.ts
5955
+ init_esm_shims();
5585
5956
  init_route_builder();
5586
5957
  init_rest_request();
5587
5958
  init_rest_client();
@@ -5589,14 +5960,17 @@ init_routes();
5589
5960
  init_transport();
5590
5961
  init_retry_policy();
5591
5962
  init_rate_limit_policy();
5963
+ init_circuit_breaker_policy();
5592
5964
  init_auth_manager();
5593
5965
  init_presigned_url_policy();
5594
5966
  init_ksef_feature();
5595
5967
 
5596
5968
  // src/validation/index.ts
5969
+ init_esm_shims();
5597
5970
  init_patterns();
5598
5971
 
5599
5972
  // src/validation/constraints.ts
5973
+ init_esm_shims();
5600
5974
  var REQUIRED_CHALLENGE_LENGTH = 36;
5601
5975
  var CERTIFICATE_NAME_MIN_LENGTH = 5;
5602
5976
  var CERTIFICATE_NAME_MAX_LENGTH = 100;
@@ -5611,10 +5985,218 @@ init_schema_registry();
5611
5985
  init_invoice_validator();
5612
5986
  init_char_validity();
5613
5987
 
5988
+ // src/validation/xsd-validator.ts
5989
+ init_esm_shims();
5990
+ import { createRequire } from "node:module";
5991
+ import * as fs from "node:fs";
5992
+ import * as path from "node:path";
5993
+ import { fileURLToPath, pathToFileURL } from "node:url";
5994
+ var cachedPkgRoot = null;
5995
+ function locatePackageRoot() {
5996
+ if (cachedPkgRoot !== null) return cachedPkgRoot;
5997
+ let dir = path.dirname(fileURLToPath(import.meta.url));
5998
+ const root = path.parse(dir).root;
5999
+ while (dir !== root) {
6000
+ const candidate = path.join(dir, "docs", "schemas");
6001
+ if (fs.existsSync(candidate)) {
6002
+ cachedPkgRoot = dir;
6003
+ return dir;
6004
+ }
6005
+ dir = path.dirname(dir);
6006
+ }
6007
+ throw new Error("Could not locate ksef-client-ts package root (docs/schemas not found).");
6008
+ }
6009
+ var XSD_RELATIVE = {
6010
+ FA2: ["FA", "schemat_FA(2)_v1-0E.xsd"],
6011
+ FA3: ["FA", "schemat_FA(3)_v1-0E.xsd"],
6012
+ PEF: ["PEF", "Schemat_PEF(3)_v2-1.xsd"],
6013
+ PEF_KOR: ["PEF", "Schemat_PEF_KOR(3)_v2-1.xsd"]
6014
+ };
6015
+ var FA_XSD_PATHS = {
6016
+ get FA2() {
6017
+ return resolveXsdFor("FA2");
6018
+ },
6019
+ get FA3() {
6020
+ return resolveXsdFor("FA3");
6021
+ }
6022
+ };
6023
+ var PEF_XSD_PATHS = {
6024
+ get PEF() {
6025
+ return resolveXsdFor("PEF");
6026
+ },
6027
+ get PEF_KOR() {
6028
+ return resolveXsdFor("PEF_KOR");
6029
+ }
6030
+ };
6031
+ function resolveXsdFor(schema) {
6032
+ const rel = XSD_RELATIVE[schema];
6033
+ if (!rel) throw new Error(`Unknown invoice schema: ${String(schema)}`);
6034
+ return path.join(locatePackageRoot(), "docs", "schemas", ...rel);
6035
+ }
6036
+ var requireModule = createRequire(import.meta.url);
6037
+ var libxmljs = null;
6038
+ var libxmljsLoadError = null;
6039
+ try {
6040
+ libxmljs = requireModule("libxmljs2");
6041
+ } catch (err) {
6042
+ const code = err?.code;
6043
+ if (code === "MODULE_NOT_FOUND" || code === "ERR_MODULE_NOT_FOUND") {
6044
+ libxmljs = null;
6045
+ } else {
6046
+ libxmljs = null;
6047
+ libxmljsLoadError = err instanceof Error ? err : new Error(String(err));
6048
+ }
6049
+ }
6050
+ var libxmljsAvailable = libxmljs !== null;
6051
+ var MISSING_LIBXMLJS_MESSAGE_PREFIX = "libxmljs2 is not installed";
6052
+ var EXTERNAL_STRUKTURY_DANYCH_URL = /schemaLocation="http:\/\/crd\.gov\.pl\/xml\/schematy\/dziedzinowe\/mf\/2022\/01\/05\/eD\/DefinicjeTypy\/StrukturyDanych_v10-0E\.xsd"/;
6053
+ function rewriteSchemaLocations(xsdContent) {
6054
+ if (!EXTERNAL_STRUKTURY_DANYCH_URL.test(xsdContent)) {
6055
+ return xsdContent;
6056
+ }
6057
+ const bazoweStrukturyPath = path.join(
6058
+ locatePackageRoot(),
6059
+ "docs",
6060
+ "schemas",
6061
+ "FA",
6062
+ "bazowe",
6063
+ "StrukturyDanych_v10-0E.xsd"
6064
+ );
6065
+ const bazoweStrukturyUrl = pathToFileURL(bazoweStrukturyPath).href;
6066
+ const rewritten = xsdContent.replace(
6067
+ EXTERNAL_STRUKTURY_DANYCH_URL,
6068
+ `schemaLocation="${bazoweStrukturyUrl}"`
6069
+ );
6070
+ if (rewritten === xsdContent) {
6071
+ throw new Error(
6072
+ "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`."
6073
+ );
6074
+ }
6075
+ return rewritten;
6076
+ }
6077
+ function validateAgainstXsd(xml, xsdPath) {
6078
+ if (!libxmljs) {
6079
+ const loadSuffix = libxmljsLoadError ? ` (load failed: ${libxmljsLoadError.message})` : "";
6080
+ throw new Error(
6081
+ `${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\`).`
6082
+ );
6083
+ }
6084
+ const xsdDir = path.dirname(xsdPath);
6085
+ const rawXsd = fs.readFileSync(xsdPath, "utf8");
6086
+ const rewrittenXsd = rewriteSchemaLocations(rawXsd);
6087
+ const baseUrl = pathToFileURL(xsdDir + path.sep).href;
6088
+ let schemaDoc;
6089
+ try {
6090
+ schemaDoc = libxmljs.parseXml(rewrittenXsd, { baseUrl });
6091
+ } catch (err) {
6092
+ return { valid: false, errors: [`XSD parse failed: ${err.message}`] };
6093
+ }
6094
+ let xmlDoc;
6095
+ try {
6096
+ xmlDoc = libxmljs.parseXml(xml);
6097
+ } catch (err) {
6098
+ return { valid: false, errors: [`XML parse failed: ${err.message}`] };
6099
+ }
6100
+ const valid = xmlDoc.validate(schemaDoc);
6101
+ const errors = valid ? [] : xmlDoc.validationErrors.map((err) => err.message.trim());
6102
+ return { valid, errors };
6103
+ }
6104
+
6105
+ // src/models/index.ts
6106
+ init_esm_shims();
6107
+
6108
+ // src/models/common.ts
6109
+ init_esm_shims();
6110
+
6111
+ // src/models/auth/index.ts
6112
+ init_esm_shims();
6113
+
6114
+ // src/models/auth/types.ts
6115
+ init_esm_shims();
6116
+
6117
+ // src/models/auth/active-sessions-types.ts
6118
+ init_esm_shims();
6119
+
6120
+ // src/models/sessions/index.ts
6121
+ init_esm_shims();
6122
+
6123
+ // src/models/sessions/online-types.ts
6124
+ init_esm_shims();
6125
+
6126
+ // src/models/sessions/batch-types.ts
6127
+ init_esm_shims();
6128
+
6129
+ // src/models/sessions/status-types.ts
6130
+ init_esm_shims();
6131
+
6132
+ // src/models/sessions/session-state.ts
6133
+ init_esm_shims();
6134
+
6135
+ // src/models/invoices/index.ts
6136
+ init_esm_shims();
6137
+
6138
+ // src/models/invoices/types.ts
6139
+ init_esm_shims();
6140
+
6141
+ // src/models/permissions/index.ts
6142
+ init_esm_shims();
6143
+
6144
+ // src/models/permissions/types.ts
6145
+ init_esm_shims();
6146
+
6147
+ // src/models/tokens/index.ts
6148
+ init_esm_shims();
6149
+
6150
+ // src/models/tokens/types.ts
6151
+ init_esm_shims();
6152
+
6153
+ // src/models/certificates/index.ts
6154
+ init_esm_shims();
6155
+
6156
+ // src/models/certificates/types.ts
6157
+ init_esm_shims();
6158
+
6159
+ // src/models/lighthouse/index.ts
6160
+ init_esm_shims();
6161
+
6162
+ // src/models/lighthouse/types.ts
6163
+ init_esm_shims();
6164
+
6165
+ // src/models/limits/index.ts
6166
+ init_esm_shims();
6167
+
6168
+ // src/models/limits/types.ts
6169
+ init_esm_shims();
6170
+
6171
+ // src/models/peppol/index.ts
6172
+ init_esm_shims();
6173
+
6174
+ // src/models/peppol/types.ts
6175
+ init_esm_shims();
6176
+
6177
+ // src/models/test-data/index.ts
6178
+ init_esm_shims();
6179
+
6180
+ // src/models/test-data/types.ts
6181
+ init_esm_shims();
6182
+
6183
+ // src/models/crypto/index.ts
6184
+ init_esm_shims();
6185
+
6186
+ // src/models/crypto/types.ts
6187
+ init_esm_shims();
6188
+
6189
+ // src/models/qrcode/index.ts
6190
+ init_esm_shims();
6191
+
6192
+ // src/models/qrcode/types.ts
6193
+ init_esm_shims();
6194
+
5614
6195
  // src/models/index.ts
5615
6196
  init_document_structures();
5616
6197
 
5617
6198
  // src/services/index.ts
6199
+ init_esm_shims();
5618
6200
  init_auth();
5619
6201
  init_active_sessions();
5620
6202
  init_online_session();
@@ -5629,7 +6211,11 @@ init_limits();
5629
6211
  init_peppol();
5630
6212
  init_test_data();
5631
6213
 
6214
+ // src/builders/index.ts
6215
+ init_esm_shims();
6216
+
5632
6217
  // src/builders/auth-token-request.ts
6218
+ init_esm_shims();
5633
6219
  init_ksef_validation_error();
5634
6220
  var AuthTokenRequestBuilder = class {
5635
6221
  challenge;
@@ -5684,6 +6270,7 @@ var AuthTokenRequestBuilder = class {
5684
6270
  };
5685
6271
 
5686
6272
  // src/builders/auth-ksef-token-request.ts
6273
+ init_esm_shims();
5687
6274
  init_ksef_validation_error();
5688
6275
  var AuthKsefTokenRequestBuilder = class {
5689
6276
  challenge;
@@ -5738,6 +6325,7 @@ var AuthKsefTokenRequestBuilder = class {
5738
6325
  };
5739
6326
 
5740
6327
  // src/builders/invoice-query-filter.ts
6328
+ init_esm_shims();
5741
6329
  init_ksef_validation_error();
5742
6330
  var InvoiceQueryFilterBuilder = class {
5743
6331
  subjectType;
@@ -5834,7 +6422,11 @@ var InvoiceQueryFilterBuilder = class {
5834
6422
  }
5835
6423
  };
5836
6424
 
6425
+ // src/builders/permissions/index.ts
6426
+ init_esm_shims();
6427
+
5837
6428
  // src/builders/permissions/person-permission.ts
6429
+ init_esm_shims();
5838
6430
  init_ksef_validation_error();
5839
6431
  var PersonPermissionGrantBuilder = class {
5840
6432
  subjectIdentifier;
@@ -5884,6 +6476,7 @@ var PersonPermissionGrantBuilder = class {
5884
6476
  };
5885
6477
 
5886
6478
  // src/builders/permissions/entity-permission.ts
6479
+ init_esm_shims();
5887
6480
  init_ksef_validation_error();
5888
6481
  var EntityPermissionGrantBuilder = class {
5889
6482
  nip;
@@ -5933,6 +6526,7 @@ var EntityPermissionGrantBuilder = class {
5933
6526
  };
5934
6527
 
5935
6528
  // src/builders/permissions/authorization-permission.ts
6529
+ init_esm_shims();
5936
6530
  init_ksef_validation_error();
5937
6531
  var AuthorizationPermissionGrantBuilder = class {
5938
6532
  _subjectIdentifier;
@@ -5978,8 +6572,9 @@ var AuthorizationPermissionGrantBuilder = class {
5978
6572
  };
5979
6573
 
5980
6574
  // src/builders/batch-file.ts
6575
+ init_esm_shims();
5981
6576
  init_ksef_validation_error();
5982
- import * as crypto from "crypto";
6577
+ import * as crypto from "node:crypto";
5983
6578
  var BATCH_MAX_PART_SIZE = 1e8;
5984
6579
  var BATCH_MAX_TOTAL_SIZE = 5e9;
5985
6580
  var BATCH_MAX_PARTS = 50;
@@ -6148,12 +6743,14 @@ function sha256Base64(data) {
6148
6743
  }
6149
6744
 
6150
6745
  // src/crypto/index.ts
6746
+ init_esm_shims();
6151
6747
  init_certificate_fetcher();
6152
6748
  init_cryptography_service();
6153
6749
  init_signature_service();
6154
6750
 
6155
6751
  // src/crypto/certificate-service.ts
6156
- import * as crypto4 from "crypto";
6752
+ init_esm_shims();
6753
+ import * as crypto4 from "node:crypto";
6157
6754
  import * as x5092 from "@peculiar/x509";
6158
6755
  var CertificateService = class {
6159
6756
  static getSha256Fingerprint(certPem) {
@@ -6238,9 +6835,11 @@ init_pkcs12_loader();
6238
6835
  init_auth_xml_builder();
6239
6836
 
6240
6837
  // src/qr/index.ts
6838
+ init_esm_shims();
6241
6839
  init_verification_link_service();
6242
6840
 
6243
6841
  // src/qr/qrcode-service.ts
6842
+ init_esm_shims();
6244
6843
  import * as QRCode from "qrcode";
6245
6844
  var QrCodeService = class _QrCodeService {
6246
6845
  static async generateQrCode(url, options) {
@@ -6300,11 +6899,13 @@ function escapeXml2(str) {
6300
6899
  }
6301
6900
 
6302
6901
  // src/utils/index.ts
6902
+ init_esm_shims();
6303
6903
  init_zip();
6304
6904
  init_jwt();
6305
6905
 
6306
6906
  // src/utils/hash.ts
6307
- import crypto6 from "crypto";
6907
+ init_esm_shims();
6908
+ import crypto6 from "node:crypto";
6308
6909
  function sha256Base642(data) {
6309
6910
  return crypto6.createHash("sha256").update(data).digest("base64");
6310
6911
  }
@@ -6315,7 +6916,11 @@ function verifyHash(data, expectedHash) {
6315
6916
  // src/utils/index.ts
6316
6917
  init_concurrency();
6317
6918
 
6919
+ // src/workflows/index.ts
6920
+ init_esm_shims();
6921
+
6318
6922
  // src/workflows/polling.ts
6923
+ init_esm_shims();
6319
6924
  async function pollUntil(action, condition, options) {
6320
6925
  const intervalMs = options?.intervalMs ?? 2e3;
6321
6926
  const maxAttempts = options?.maxAttempts ?? 60;
@@ -6333,13 +6938,18 @@ async function pollUntil(action, condition, options) {
6333
6938
  }
6334
6939
 
6335
6940
  // src/workflows/online-session-workflow.ts
6941
+ init_esm_shims();
6336
6942
  init_ksef_session_expired_error();
6337
6943
  init_auth_manager();
6338
6944
  init_online_session();
6339
6945
  init_session_status();
6340
6946
  init_document_structures();
6341
6947
 
6948
+ // src/xml/index.ts
6949
+ init_esm_shims();
6950
+
6342
6951
  // src/xml/upo-parser.ts
6952
+ init_esm_shims();
6343
6953
  init_ksef_validation_error();
6344
6954
  import { XMLParser } from "fast-xml-parser";
6345
6955
  function isRecord(value) {
@@ -6458,6 +7068,7 @@ function parseUpoXml(xml) {
6458
7068
  }
6459
7069
 
6460
7070
  // src/xml/invoice-field-extractor.ts
7071
+ init_esm_shims();
6461
7072
  import { XMLParser as XMLParser2 } from "fast-xml-parser";
6462
7073
  var invoiceParser = new XMLParser2({
6463
7074
  ignoreAttributes: false,
@@ -6498,6 +7109,7 @@ function nonEmptyString(value) {
6498
7109
  }
6499
7110
 
6500
7111
  // src/xml/xml-engine.ts
7112
+ init_esm_shims();
6501
7113
  import { XMLBuilder, XMLParser as XMLParser3 } from "fast-xml-parser";
6502
7114
  var XML_DECLARATION = '<?xml version="1.0" encoding="UTF-8"?>\n';
6503
7115
  var parser = new XMLParser3({
@@ -6551,6 +7163,7 @@ function stripBom(input) {
6551
7163
  }
6552
7164
 
6553
7165
  // src/xml/order-map.ts
7166
+ init_esm_shims();
6554
7167
  var ORDER_MAP = {
6555
7168
  Faktura: ["Naglowek", "Podmiot1", "Podmiot2", "Podmiot3", "Fa", "Stopka"],
6556
7169
  Naglowek: ["KodFormularza", "WariantFormularza", "DataWytworzeniaFa", "SystemInfo"],
@@ -6749,6 +7362,7 @@ function orderXmlObject(value, contextKey) {
6749
7362
  }
6750
7363
 
6751
7364
  // src/xml/faktura-builder.ts
7365
+ init_esm_shims();
6752
7366
  var FAKTURA_NAMESPACE = {
6753
7367
  FA2: "http://crd.gov.pl/wzor/2023/06/29/12648/",
6754
7368
  FA3: "http://crd.gov.pl/wzor/2025/06/25/13775/"
@@ -6836,6 +7450,7 @@ function isFakturaInput(input) {
6836
7450
  }
6837
7451
 
6838
7452
  // src/xml/pef-builder.ts
7453
+ init_esm_shims();
6839
7454
  init_ksef_validation_error();
6840
7455
  var PEF_NAMESPACE = {
6841
7456
  PEF: "urn:oasis:names:specification:ubl:schema:xsd:Invoice-2",
@@ -6917,6 +7532,7 @@ function buildPefXml(input, options = {}) {
6917
7532
  }
6918
7533
 
6919
7534
  // src/xml/invoice-serializer.ts
7535
+ init_esm_shims();
6920
7536
  init_ksef_validation_error();
6921
7537
  var FAKTURA_SCHEMAS = /* @__PURE__ */ new Set(["FA2", "FA3"]);
6922
7538
  var PEF_SCHEMAS = /* @__PURE__ */ new Set(["PEF", "PEF_KOR"]);
@@ -7152,6 +7768,7 @@ async function openSendAndClose(client, invoices, options) {
7152
7768
  }
7153
7769
 
7154
7770
  // src/workflows/batch-session-workflow.ts
7771
+ init_esm_shims();
7155
7772
  init_document_structures();
7156
7773
  async function uploadBatch(client, zipData, options) {
7157
7774
  if (options?.parallelism !== void 0 && (!Number.isInteger(options.parallelism) || options.parallelism < 1)) {
@@ -7290,6 +7907,7 @@ async function uploadBatchParsed(client, zipData, options) {
7290
7907
  }
7291
7908
 
7292
7909
  // src/workflows/invoice-export-workflow.ts
7910
+ init_esm_shims();
7293
7911
  init_zip();
7294
7912
  async function doExport(client, filters, options) {
7295
7913
  await client.crypto.init();
@@ -7362,7 +7980,11 @@ async function exportAndDownload(client, filters, options) {
7362
7980
  };
7363
7981
  }
7364
7982
 
7983
+ // src/workflows/incremental-export-workflow.ts
7984
+ init_esm_shims();
7985
+
7365
7986
  // src/workflows/hwm-coordinator.ts
7987
+ init_esm_shims();
7366
7988
  function updateContinuationPoint(points, subjectType, pkg) {
7367
7989
  if (pkg.isTruncated && pkg.lastPermanentStorageDate) {
7368
7990
  points[subjectType] = pkg.lastPermanentStorageDate;
@@ -7460,7 +8082,8 @@ function buildDefaultFilters(subjectType, from, to) {
7460
8082
  }
7461
8083
 
7462
8084
  // src/workflows/hwm-storage.ts
7463
- import * as fs from "fs/promises";
8085
+ init_esm_shims();
8086
+ import * as fs2 from "node:fs/promises";
7464
8087
  var InMemoryHwmStore = class {
7465
8088
  points = {};
7466
8089
  async load() {
@@ -7476,7 +8099,7 @@ var FileHwmStore = class {
7476
8099
  }
7477
8100
  async load() {
7478
8101
  try {
7479
- const data = await fs.readFile(this.filePath, "utf-8");
8102
+ const data = await fs2.readFile(this.filePath, "utf-8");
7480
8103
  return JSON.parse(data);
7481
8104
  } catch (err) {
7482
8105
  if (err.code === "ENOENT") {
@@ -7486,11 +8109,12 @@ var FileHwmStore = class {
7486
8109
  }
7487
8110
  }
7488
8111
  async save(points) {
7489
- await fs.writeFile(this.filePath, JSON.stringify(points, null, 2), "utf-8");
8112
+ await fs2.writeFile(this.filePath, JSON.stringify(points, null, 2), "utf-8");
7490
8113
  }
7491
8114
  };
7492
8115
 
7493
8116
  // src/workflows/auth-workflow.ts
8117
+ init_esm_shims();
7494
8118
  init_auth_xml_builder();
7495
8119
  async function authenticateWithToken(client, options) {
7496
8120
  const challenge = await client.auth.getChallenge();
@@ -7587,10 +8211,12 @@ async function authenticateWithPkcs12(client, options) {
7587
8211
  }
7588
8212
 
7589
8213
  // src/offline/index.ts
8214
+ init_esm_shims();
7590
8215
  init_deadline();
7591
8216
  init_holidays();
7592
8217
 
7593
8218
  // src/offline/storage.ts
8219
+ init_esm_shims();
7594
8220
  function matchesFilter(invoice, filter) {
7595
8221
  if (filter.status !== void 0) {
7596
8222
  const statuses = Array.isArray(filter.status) ? filter.status : [filter.status];
@@ -7629,12 +8255,13 @@ var InMemoryOfflineInvoiceStorage = class {
7629
8255
  };
7630
8256
 
7631
8257
  // src/offline/file-storage.ts
7632
- import * as fs2 from "fs/promises";
7633
- import * as path from "path";
7634
- import * as os from "os";
8258
+ init_esm_shims();
8259
+ import * as fs3 from "node:fs/promises";
8260
+ import * as path2 from "node:path";
8261
+ import * as os from "node:os";
7635
8262
  function resolveDir(dir) {
7636
8263
  if (dir === "~" || dir.startsWith("~/")) {
7637
- return path.join(os.homedir(), dir.slice(1));
8264
+ return path2.join(os.homedir(), dir.slice(1));
7638
8265
  }
7639
8266
  return dir;
7640
8267
  }
@@ -7650,23 +8277,23 @@ var FileOfflineInvoiceStorage = class {
7650
8277
  this.dir = resolveDir(directory ?? "~/.ksef/offline");
7651
8278
  }
7652
8279
  async ensureDir() {
7653
- await fs2.mkdir(this.dir, { recursive: true });
8280
+ await fs3.mkdir(this.dir, { recursive: true });
7654
8281
  }
7655
8282
  filePath(id) {
7656
8283
  validateId(id);
7657
- return path.join(this.dir, `${id}.json`);
8284
+ return path2.join(this.dir, `${id}.json`);
7658
8285
  }
7659
8286
  async save(invoice) {
7660
8287
  await this.ensureDir();
7661
8288
  const file = this.filePath(invoice.id);
7662
8289
  const tmp = `${file}.tmp`;
7663
- await fs2.writeFile(tmp, JSON.stringify(invoice, null, 2));
7664
- await fs2.rename(tmp, file);
8290
+ await fs3.writeFile(tmp, JSON.stringify(invoice, null, 2));
8291
+ await fs3.rename(tmp, file);
7665
8292
  }
7666
8293
  async get(id) {
7667
8294
  const file = this.filePath(id);
7668
8295
  try {
7669
- return JSON.parse(await fs2.readFile(file, "utf-8"));
8296
+ return JSON.parse(await fs3.readFile(file, "utf-8"));
7670
8297
  } catch (err) {
7671
8298
  if (err instanceof Error && "code" in err && err.code === "ENOENT") {
7672
8299
  return null;
@@ -7678,7 +8305,7 @@ var FileOfflineInvoiceStorage = class {
7678
8305
  async list(filter) {
7679
8306
  let files;
7680
8307
  try {
7681
- files = (await fs2.readdir(this.dir)).filter((f) => f.endsWith(".json"));
8308
+ files = (await fs3.readdir(this.dir)).filter((f) => f.endsWith(".json"));
7682
8309
  } catch {
7683
8310
  return [];
7684
8311
  }
@@ -7686,7 +8313,7 @@ var FileOfflineInvoiceStorage = class {
7686
8313
  for (const file of files) {
7687
8314
  try {
7688
8315
  const data = JSON.parse(
7689
- await fs2.readFile(path.join(this.dir, file), "utf-8")
8316
+ await fs3.readFile(path2.join(this.dir, file), "utf-8")
7690
8317
  );
7691
8318
  if (!filter || matchesFilter(data, filter)) {
7692
8319
  results.push(data);
@@ -7712,7 +8339,7 @@ var FileOfflineInvoiceStorage = class {
7712
8339
  async delete(id) {
7713
8340
  const file = this.filePath(id);
7714
8341
  try {
7715
- await fs2.unlink(file);
8342
+ await fs3.unlink(file);
7716
8343
  } catch (e) {
7717
8344
  if (e instanceof Error && "code" in e && e.code !== "ENOENT") throw e;
7718
8345
  }
@@ -7741,6 +8368,7 @@ export {
7741
8368
  CertificateFingerprint,
7742
8369
  CertificateName,
7743
8370
  CertificateService,
8371
+ CircuitBreakerPolicy,
7744
8372
  CryptographyService,
7745
8373
  DEFAULT_FORM_CODE,
7746
8374
  DISCOURAGED_UNICODE_RANGES,
@@ -7750,6 +8378,7 @@ export {
7750
8378
  EntityPermissionGrantBuilder,
7751
8379
  Environment,
7752
8380
  FAKTURA_NAMESPACE,
8381
+ FA_XSD_PATHS,
7753
8382
  FORM_CODES,
7754
8383
  FORM_CODE_KEYS,
7755
8384
  FileHwmStore,
@@ -7768,6 +8397,7 @@ export {
7768
8397
  KSeFAuthStatusError,
7769
8398
  KSeFBadRequestError,
7770
8399
  KSeFBatchTimeoutError,
8400
+ KSeFCircuitOpenError,
7771
8401
  KSeFClient,
7772
8402
  KSeFError,
7773
8403
  KSeFErrorCode,
@@ -7777,6 +8407,7 @@ export {
7777
8407
  KSeFSessionExpiredError,
7778
8408
  KSeFUnauthorizedError,
7779
8409
  KSeFValidationError,
8410
+ KSeFXsdValidationError,
7780
8411
  KsefNumber,
7781
8412
  KsefNumberV35,
7782
8413
  KsefNumberV36,
@@ -7788,6 +8419,7 @@ export {
7788
8419
  OfflineInvoiceWorkflow,
7789
8420
  OnlineSessionService,
7790
8421
  PEF_NAMESPACE,
8422
+ PEF_XSD_PATHS,
7791
8423
  PERMISSION_DESCRIPTION_MAX_LENGTH,
7792
8424
  PERMISSION_DESCRIPTION_MIN_LENGTH,
7793
8425
  PeppolId,
@@ -7835,6 +8467,7 @@ export {
7835
8467
  createZip,
7836
8468
  decodeJwtPayload,
7837
8469
  deduplicateByKsefNumber,
8470
+ defaultCircuitBreakerPolicy,
7838
8471
  defaultPresignedUrlPolicy,
7839
8472
  defaultRateLimitPolicy,
7840
8473
  defaultRetryPolicy,
@@ -7871,6 +8504,7 @@ export {
7871
8504
  isValidReferenceNumber,
7872
8505
  isValidSha256Base64,
7873
8506
  isValidVatUe,
8507
+ libxmljsAvailable,
7874
8508
  nextBusinessDay,
7875
8509
  openOnlineSession,
7876
8510
  openSendAndClose,
@@ -7882,6 +8516,7 @@ export {
7882
8516
  parseXml,
7883
8517
  pollUntil,
7884
8518
  resolveOptions,
8519
+ resolveXsdFor,
7885
8520
  resumeOnlineSession,
7886
8521
  runWithConcurrency,
7887
8522
  serializeInvoiceXml,
@@ -7896,6 +8531,7 @@ export {
7896
8531
  uploadBatchStream,
7897
8532
  uploadBatchStreamParsed,
7898
8533
  validate,
8534
+ validateAgainstXsd,
7899
8535
  validateBatch,
7900
8536
  validateBusinessRules,
7901
8537
  validateCharValidity,