ksef-client-ts 0.8.0 → 0.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -376,6 +376,25 @@ var init_ksef_validation_error = __esm({
376
376
  }
377
377
  });
378
378
 
379
+ // src/errors/ksef-metadata-pagination-error.ts
380
+ var KSeFMetadataPaginationError;
381
+ var init_ksef_metadata_pagination_error = __esm({
382
+ "src/errors/ksef-metadata-pagination-error.ts"() {
383
+ "use strict";
384
+ init_esm_shims();
385
+ init_ksef_error();
386
+ KSeFMetadataPaginationError = class extends KSeFError {
387
+ /** The boundary date value that failed to advance. */
388
+ boundaryValue;
389
+ constructor(message, boundaryValue) {
390
+ super(message);
391
+ this.name = "KSeFMetadataPaginationError";
392
+ this.boundaryValue = boundaryValue;
393
+ }
394
+ };
395
+ }
396
+ });
397
+
379
398
  // src/errors/error-codes.ts
380
399
  function hasErrorCode(body, code) {
381
400
  return !!body?.exception?.exceptionDetailList?.some((d) => d.exceptionCode === code);
@@ -387,7 +406,9 @@ var init_error_codes = __esm({
387
406
  init_esm_shims();
388
407
  KSeFErrorCode = {
389
408
  BatchTimeout: 21208,
390
- DuplicateInvoice: 440
409
+ DuplicateInvoice: 440,
410
+ /** The supplied public key identifier is unknown or points to a revoked key (KSeF API v2.5.0). */
411
+ UnknownPublicKeyId: 21470
391
412
  };
392
413
  }
393
414
  });
@@ -417,6 +438,38 @@ var init_ksef_batch_timeout_error = __esm({
417
438
  }
418
439
  });
419
440
 
441
+ // src/errors/ksef-unknown-public-key-error.ts
442
+ function messageOf(description) {
443
+ return description?.trim() || "The supplied public key identifier is unknown or revoked (KSeF 21470).";
444
+ }
445
+ var KSeFUnknownPublicKeyError;
446
+ var init_ksef_unknown_public_key_error = __esm({
447
+ "src/errors/ksef-unknown-public-key-error.ts"() {
448
+ "use strict";
449
+ init_esm_shims();
450
+ init_ksef_api_error();
451
+ init_error_codes();
452
+ KSeFUnknownPublicKeyError = class _KSeFUnknownPublicKeyError extends KSeFApiError {
453
+ statusCode = 400;
454
+ errorCode = KSeFErrorCode.UnknownPublicKeyId;
455
+ constructor(message, errorResponse) {
456
+ super(message, 400, errorResponse);
457
+ this.name = "KSeFUnknownPublicKeyError";
458
+ }
459
+ static fromLegacy(body) {
460
+ const detail = body?.exception?.exceptionDetailList?.find(
461
+ (d) => d.exceptionCode === KSeFErrorCode.UnknownPublicKeyId
462
+ );
463
+ return new _KSeFUnknownPublicKeyError(messageOf(detail?.exceptionDescription), body);
464
+ }
465
+ static fromProblem(problem) {
466
+ const detail = problem.errors?.find((e) => e.code === KSeFErrorCode.UnknownPublicKeyId);
467
+ return new _KSeFUnknownPublicKeyError(messageOf(detail?.description || problem.detail));
468
+ }
469
+ };
470
+ }
471
+ });
472
+
420
473
  // src/errors/ksef-circuit-open-error.ts
421
474
  var KSeFCircuitOpenError;
422
475
  var init_ksef_circuit_open_error = __esm({
@@ -489,7 +542,9 @@ var init_errors = __esm({
489
542
  init_ksef_auth_status_error();
490
543
  init_ksef_session_expired_error();
491
544
  init_ksef_validation_error();
545
+ init_ksef_metadata_pagination_error();
492
546
  init_ksef_batch_timeout_error();
547
+ init_ksef_unknown_public_key_error();
493
548
  init_ksef_circuit_open_error();
494
549
  init_ksef_xsd_validation_error();
495
550
  init_error_codes();
@@ -780,6 +835,7 @@ var init_rest_client = __esm({
780
835
  init_ksef_gone_error();
781
836
  init_ksef_bad_request_error();
782
837
  init_ksef_batch_timeout_error();
838
+ init_ksef_unknown_public_key_error();
783
839
  init_error_codes();
784
840
  init_route_builder();
785
841
  init_transport();
@@ -794,6 +850,7 @@ var init_rest_client = __esm({
794
850
  circuitBreakerPolicy;
795
851
  authManager;
796
852
  presignedUrlPolicy;
853
+ onSystemWarning;
797
854
  constructor(options, config) {
798
855
  this.options = options;
799
856
  this.routeBuilder = new RouteBuilder(options.apiVersion);
@@ -803,23 +860,41 @@ var init_rest_client = __esm({
803
860
  this.circuitBreakerPolicy = config?.circuitBreakerPolicy ?? null;
804
861
  this.authManager = config?.authManager;
805
862
  this.presignedUrlPolicy = config?.presignedUrlPolicy;
863
+ this.onSystemWarning = config?.onSystemWarning;
806
864
  }
807
865
  async execute(request) {
808
866
  const response = await this.sendRequest(request);
809
867
  await this.ensureSuccess(response);
868
+ this.handleSystemWarning(response);
810
869
  const body = await response.json();
811
870
  return { body, headers: response.headers, statusCode: response.status };
812
871
  }
813
872
  async executeVoid(request) {
814
873
  const response = await this.sendRequest(request);
815
874
  await this.ensureSuccess(response);
875
+ this.handleSystemWarning(response);
816
876
  }
817
877
  async executeRaw(request) {
818
878
  const response = await this.sendRequest(request);
819
879
  await this.ensureSuccess(response);
880
+ this.handleSystemWarning(response);
820
881
  const body = await response.arrayBuffer();
821
882
  return { body, headers: response.headers, statusCode: response.status };
822
883
  }
884
+ /** Surface the optional `X-System-Warning` response header (KSeF API v2.6.0). */
885
+ handleSystemWarning(response) {
886
+ const warning = response.headers.get("x-system-warning");
887
+ if (!warning) return;
888
+ if (this.onSystemWarning) {
889
+ try {
890
+ this.onSystemWarning(warning);
891
+ } catch (error) {
892
+ consola.warn("onSystemWarning callback threw an exception (ignored):", error);
893
+ }
894
+ } else {
895
+ consola.warn(`KSeF system warning: ${warning}`);
896
+ }
897
+ }
823
898
  async sendRequest(request) {
824
899
  const url = this.buildUrl(request);
825
900
  if (request.isPresigned() && this.presignedUrlPolicy) {
@@ -961,9 +1036,15 @@ var init_rest_client = __esm({
961
1036
  if (response.status === 400) {
962
1037
  const problem = tryParseProblem(isBadRequestProblem);
963
1038
  if (problem) {
1039
+ if (problem.errors?.some((e) => e.code === KSeFErrorCode.UnknownPublicKeyId)) {
1040
+ throw KSeFUnknownPublicKeyError.fromProblem(problem);
1041
+ }
964
1042
  throw new KSeFBadRequestError(problem);
965
1043
  }
966
1044
  const legacy = parseJson();
1045
+ if (hasErrorCode(legacy, KSeFErrorCode.UnknownPublicKeyId)) {
1046
+ throw KSeFUnknownPublicKeyError.fromLegacy(legacy);
1047
+ }
967
1048
  if (hasErrorCode(legacy, KSeFErrorCode.BatchTimeout)) {
968
1049
  throw KSeFBatchTimeoutError.fromResponse(400, legacy);
969
1050
  }
@@ -1483,6 +1564,9 @@ function isValidCertificateName(value) {
1483
1564
  function isValidCertificateFingerprint(value) {
1484
1565
  return CertificateFingerprint.test(value);
1485
1566
  }
1567
+ function isValidCertificateSerialNumber(value) {
1568
+ return CertificateSerialNumber.test(value);
1569
+ }
1486
1570
  function isValidBase64(value) {
1487
1571
  return Base64String.test(value);
1488
1572
  }
@@ -1492,7 +1576,7 @@ function isValidIp4Address(value) {
1492
1576
  function isValidSha256Base64(value) {
1493
1577
  return Sha256Base64.test(value);
1494
1578
  }
1495
- var NIP_PATTERN_CORE, VAT_UE_PATTERN_CORE, Nip, VatUe, NipVatUe, InternalId, PeppolId, ReferenceNumber, KsefNumber, KsefNumberV35, KsefNumberV36, CertificateName, Pesel, CertificateFingerprint, Base64String, Ip4Address, Ip4Range, Ip4Mask, Sha256Base64, NIP_WEIGHTS, PESEL_WEIGHTS, CRC8_POLY;
1579
+ var NIP_PATTERN_CORE, VAT_UE_PATTERN_CORE, Nip, VatUe, NipVatUe, InternalId, PeppolId, ReferenceNumber, KsefNumber, KsefNumberV35, KsefNumberV36, CertificateName, Pesel, CertificateFingerprint, CertificateSerialNumber, Base64String, Ip4Address, Ip4Range, Ip4Mask, Sha256Base64, NIP_WEIGHTS, PESEL_WEIGHTS, CRC8_POLY;
1496
1580
  var init_patterns = __esm({
1497
1581
  "src/validation/patterns.ts"() {
1498
1582
  "use strict";
@@ -1511,6 +1595,7 @@ var init_patterns = __esm({
1511
1595
  CertificateName = /^[a-zA-Z0-9_\- ąćęłńóśźżĄĆĘŁŃÓŚŹŻ]+$/;
1512
1596
  Pesel = /^\d{2}(?:0[1-9]|1[0-2]|2[1-9]|3[0-2]|4[1-9]|5[0-2]|6[1-9]|7[0-2]|8[1-9]|9[0-2])\d{7}$/;
1513
1597
  CertificateFingerprint = /^[0-9A-F]{64}$/;
1598
+ CertificateSerialNumber = /^[0-9A-F]{16}$/;
1514
1599
  Base64String = /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/;
1515
1600
  Ip4Address = /^((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)\.?\b){4}$/;
1516
1601
  Ip4Range = /^((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)\.?\b){4}-((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)\.?\b){4}$/;
@@ -2423,15 +2508,15 @@ var init_fa2 = __esm({
2423
2508
  }
2424
2509
  });
2425
2510
 
2426
- // src/validation/schemas/rr1-v11e.ts
2427
- var rr1_v11e_exports = {};
2428
- __export(rr1_v11e_exports, {
2429
- RR1_V11ESchema: () => RR1_V11ESchema
2511
+ // src/validation/schemas/fa-rr1.ts
2512
+ var fa_rr1_exports = {};
2513
+ __export(fa_rr1_exports, {
2514
+ FA_RR1Schema: () => FA_RR1Schema
2430
2515
  });
2431
2516
  import { z as z3 } from "zod";
2432
- var TKodFormularza3, TDataCzas3, TZnakowy4, TNaglowek3, TNrNIP3, TZnakowy5123, TPodmiot13, TKodKraju3, TGLN3, TAdres3, TAdresEmail3, TNumerTelefonu3, TStatusInfoPodatnika3, TZnakowy203, TNIPIdWew3, TWybor13, TPodmiot33, TRolaPodmiotu33, TKodWaluty3, TData3, TDataT3, TKwotowy4, TRodzajFaktury3, TTypKorekty3, TNumerKSeF3, TNaturalny3, TKluczWartosc3, TZnakowy503, TIlosci3, TKwotowy23, TProcentowy3, TStawkaPodatku3, TFormaPlatnosci3, TNrRB3, SWIFT_Type3, TRachunekBankowy3, TTekstowy3, TNrKRS3, TNrREGON3, RR1_V11ESchema;
2433
- var init_rr1_v11e = __esm({
2434
- "src/validation/schemas/rr1-v11e.ts"() {
2517
+ var TKodFormularza3, TDataCzas3, TZnakowy4, TNaglowek3, TNrNIP3, TZnakowy5123, TPodmiot13, TKodKraju3, TGLN3, TAdres3, TAdresEmail3, TNumerTelefonu3, TStatusInfoPodatnika3, TZnakowy203, TNIPIdWew3, TWybor13, TPodmiot33, TRolaPodmiotu33, TKodWaluty3, TData3, TDataT3, TKwotowy4, TRodzajFaktury3, TTypKorekty3, TNumerKSeF3, TNaturalny3, TKluczWartosc3, TZnakowy503, TIlosci3, TKwotowy23, TProcentowy3, TStawkaPodatku3, TFormaPlatnosci3, TNrRB3, SWIFT_Type3, TRachunekBankowy3, TTekstowy3, TNrKRS3, TNrREGON3, FA_RR1Schema;
2518
+ var init_fa_rr1 = __esm({
2519
+ "src/validation/schemas/fa-rr1.ts"() {
2435
2520
  "use strict";
2436
2521
  init_esm_shims();
2437
2522
  TKodFormularza3 = z3.literal("FA_RR");
@@ -2500,7 +2585,7 @@ var init_rr1_v11e = __esm({
2500
2585
  TTekstowy3 = z3.string().min(1).max(3500);
2501
2586
  TNrKRS3 = z3.string().regex(/^\d{10}$/);
2502
2587
  TNrREGON3 = z3.union([z3.string().regex(/^\d{9}$/), z3.string().regex(/^\d{14}$/)]);
2503
- RR1_V11ESchema = z3.object({
2588
+ FA_RR1Schema = z3.object({
2504
2589
  "Naglowek": TNaglowek3,
2505
2590
  "Podmiot1": z3.object({
2506
2591
  "DaneIdentyfikacyjne": TPodmiot13,
@@ -2629,224 +2714,89 @@ var init_rr1_v11e = __esm({
2629
2714
  }
2630
2715
  });
2631
2716
 
2632
- // src/validation/schemas/rr1-v10e.ts
2633
- var rr1_v10e_exports = {};
2634
- __export(rr1_v10e_exports, {
2635
- RR1_V10ESchema: () => RR1_V10ESchema
2717
+ // src/validation/schemas/pef3.ts
2718
+ var pef3_exports = {};
2719
+ __export(pef3_exports, {
2720
+ PEF3Schema: () => PEF3Schema
2636
2721
  });
2637
2722
  import { z as z4 } from "zod";
2638
- var TKodFormularza4, TDataCzas4, TZnakowy5, TNaglowek4, TNrNIP4, TZnakowy5124, TPodmiot14, TKodKraju4, TGLN4, TAdres4, TAdresEmail4, TNumerTelefonu4, TStatusInfoPodatnika4, TZnakowy204, TNIPIdWew4, TWybor14, TPodmiot34, TRolaPodmiotu34, TKodWaluty4, TData4, TDataT4, TKwotowy5, TRodzajFaktury4, TTypKorekty4, TNumerKSeF4, TNaturalny4, TKluczWartosc4, TZnakowy504, TIlosci4, TKwotowy24, TProcentowy4, TStawkaPodatku4, TFormaPlatnosci4, TNrRB4, SWIFT_Type4, TRachunekBankowy4, TTekstowy4, TNrKRS4, TNrREGON4, RR1_V10ESchema;
2639
- var init_rr1_v10e = __esm({
2640
- "src/validation/schemas/rr1-v10e.ts"() {
2723
+ var InvoiceType, PEF3Schema;
2724
+ var init_pef3 = __esm({
2725
+ "src/validation/schemas/pef3.ts"() {
2641
2726
  "use strict";
2642
2727
  init_esm_shims();
2643
- TKodFormularza4 = z4.literal("FA_RR");
2644
- TDataCzas4 = z4.string();
2645
- TZnakowy5 = z4.string().min(1).max(256);
2646
- TNaglowek4 = z4.object({
2647
- "KodFormularza": z4.object({ "#text": TKodFormularza4, "@kodSystemowy": z4.literal("FA_RR(1)"), "@wersjaSchemy": z4.literal("1-0E") }).strict(),
2648
- "WariantFormularza": z4.literal("1"),
2649
- "DataWytworzeniaFa": z4.string(),
2650
- "SystemInfo": TZnakowy5.optional()
2651
- }).strict();
2652
- TNrNIP4 = z4.string().regex(/^[1-9]((\d[1-9])|([1-9]\d))\d{7}$/);
2653
- TZnakowy5124 = z4.string().min(1).max(512);
2654
- TPodmiot14 = z4.object({
2655
- "NIP": TNrNIP4,
2656
- "Nazwa": TZnakowy5124
2657
- }).strict();
2658
- TKodKraju4 = z4.enum(["AF", "AX", "AL", "DZ", "AD", "AO", "AI", "AQ", "AG", "AN", "SA", "AR", "AM", "AW", "AU", "AT", "AZ", "BS", "BH", "BD", "BB", "BE", "BZ", "BJ", "BM", "BT", "BY", "BO", "BQ", "BA", "BW", "BR", "BN", "IO", "BG", "BF", "BI", "XC", "CL", "CN", "HR", "CW", "CY", "TD", "ME", "DK", "DM", "DO", "DJ", "EG", "EC", "ER", "EE", "ET", "FK", "FJ", "PH", "FI", "FR", "TF", "GA", "GM", "GH", "GI", "GR", "GD", "GL", "GE", "GU", "GG", "GY", "GF", "GP", "GT", "GN", "GQ", "GW", "HT", "ES", "HN", "HK", "IN", "ID", "IQ", "IR", "IE", "IS", "IL", "JM", "JP", "YE", "JE", "JO", "KY", "KH", "CM", "CA", "QA", "KZ", "KE", "KG", "KI", "CO", "KM", "CG", "CD", "KP", "XK", "CR", "CU", "KW", "LA", "LS", "LB", "LR", "LY", "LI", "LT", "LV", "LU", "MK", "MG", "YT", "MO", "MW", "MV", "MY", "ML", "MT", "MP", "MA", "MQ", "MR", "MU", "MX", "XL", "FM", "UM", "MD", "MC", "MN", "MS", "MZ", "MM", "NA", "NR", "NP", "NL", "DE", "NE", "NG", "NI", "NU", "NF", "NO", "NC", "NZ", "PS", "OM", "PK", "PW", "PA", "PG", "PY", "PE", "PN", "PF", "PL", "GS", "PT", "PR", "CF", "CZ", "KR", "ZA", "RE", "RU", "RO", "RW", "EH", "BL", "KN", "LC", "MF", "VC", "SV", "WS", "AS", "SM", "SN", "RS", "SC", "SL", "SG", "SK", "SI", "SO", "LK", "PM", "US", "SZ", "SD", "SS", "SR", "SJ", "SH", "SY", "CH", "SE", "TJ", "TH", "TW", "TZ", "TG", "TK", "TO", "TT", "TN", "TR", "TM", "TV", "UG", "UA", "UY", "UZ", "VU", "WF", "VA", "HU", "VE", "GB", "VN", "IT", "TL", "CI", "BV", "CX", "IM", "SX", "CK", "VI", "VG", "HM", "CC", "MH", "FO", "SB", "ST", "TC", "ZM", "CV", "ZW", "AE", "XI"]);
2659
- TGLN4 = z4.string().min(1).max(13);
2660
- TAdres4 = z4.object({
2661
- "KodKraju": TKodKraju4,
2662
- "AdresL1": TZnakowy5124,
2663
- "AdresL2": TZnakowy5124.optional(),
2664
- "GLN": TGLN4.optional()
2665
- }).strict();
2666
- TAdresEmail4 = z4.string().min(3).max(255).regex(/^(.)+@(.)+$/);
2667
- TNumerTelefonu4 = z4.string().min(1).max(16);
2668
- TStatusInfoPodatnika4 = z4.enum(["1", "2", "3", "4"]);
2669
- TZnakowy204 = z4.string().min(1).max(20);
2670
- TNIPIdWew4 = z4.string().min(1).max(20).regex(/^[1-9]((\d[1-9])|([1-9]\d))\d{7}-\d{5}$/);
2671
- TWybor14 = z4.literal("1");
2672
- TPodmiot34 = z4.object({
2673
- "NIP": TNrNIP4.optional(),
2674
- "IDWew": TNIPIdWew4.optional(),
2675
- "BrakID": TWybor14.optional(),
2676
- "Nazwa": TZnakowy5124
2677
- }).strict();
2678
- TRolaPodmiotu34 = z4.enum(["1", "2", "3", "5", "6", "7", "8", "9", "10", "11"]);
2679
- TKodWaluty4 = z4.enum(["AED", "AFN", "ALL", "AMD", "ANG", "AOA", "ARS", "AUD", "AWG", "AZN", "BAM", "BBD", "BDT", "BGN", "BHD", "BIF", "BMD", "BND", "BOB", "BOV", "BRL", "BSD", "BTN", "BWP", "BYN", "BZD", "CAD", "CDF", "CHE", "CHF", "CHW", "CLF", "CLP", "CNY", "COP", "COU", "CRC", "CUC", "CUP", "CVE", "CZK", "DJF", "DKK", "DOP", "DZD", "EGP", "ERN", "ETB", "EUR", "FJD", "FKP", "GBP", "GEL", "GGP", "GHS", "GIP", "GMD", "GNF", "GTQ", "GYD", "HKD", "HNL", "HRK", "HTG", "HUF", "IDR", "ILS", "IMP", "INR", "IQD", "IRR", "ISK", "JEP", "JMD", "JOD", "JPY", "KES", "KGS", "KHR", "KMF", "KPW", "KRW", "KWD", "KYD", "KZT", "LAK", "LBP", "LKR", "LRD", "LSL", "LYD", "MAD", "MDL", "MGA", "MKD", "MMK", "MNT", "MOP", "MRU", "MUR", "MVR", "MWK", "MXN", "MXV", "MYR", "MZN", "NAD", "NGN", "NIO", "NOK", "NPR", "NZD", "OMR", "PAB", "PEN", "PGK", "PHP", "PKR", "PLN", "PYG", "QAR", "RON", "RSD", "RUB", "RWF", "SAR", "SBD", "SCR", "SDG", "SEK", "SGD", "SHP", "SLL", "SOS", "SRD", "SSP", "STN", "SVC", "SYP", "SZL", "THB", "TJS", "TMT", "TND", "TOP", "TRY", "TTD", "TWD", "TZS", "UAH", "UGX", "USD", "USN", "UYI", "UYU", "UYW", "UZS", "VES", "VND", "VUV", "WST", "XAF", "XAG", "XAU", "XBA", "XBB", "XBC", "XBD", "XCD", "XCG", "XDR", "XOF", "XPD", "XPF", "XPT", "XSU", "XUA", "XXX", "YER", "ZAR", "ZMW", "ZWL"]);
2680
- TData4 = z4.string();
2681
- TDataT4 = z4.string();
2682
- TKwotowy5 = z4.string().regex(/^-?([1-9]\d{0,15}|0)(\.\d{1,2})?$/);
2683
- TRodzajFaktury4 = z4.enum(["VAT_RR", "KOR_VAT_RR"]);
2684
- TTypKorekty4 = z4.enum(["1", "2", "3", "4"]);
2685
- TNumerKSeF4 = z4.string().regex(/^([1-9]((\d[1-9])|([1-9]\d))\d{7}|M\d{9}|[A-Z]{3}\d{7})-(20[2-9][0-9]|2[1-9][0-9]{2}|[3-9][0-9]{3})(0[1-9]|1[0-2])(0[1-9]|[1-2][0-9]|3[0-1])-([0-9A-F]{6})-?([0-9A-F]{6})-([0-9A-F]{2})$/);
2686
- TNaturalny4 = z4.string();
2687
- TKluczWartosc4 = z4.object({
2688
- "NrWiersza": TNaturalny4.optional(),
2689
- "Klucz": TZnakowy5,
2690
- "Wartosc": TZnakowy5
2691
- }).strict();
2692
- TZnakowy504 = z4.string().min(1).max(50);
2693
- TIlosci4 = z4.string().regex(/^-?([1-9]\d{0,15}|0)(\.\d{1,6})?$/);
2694
- TKwotowy24 = z4.string().regex(/^-?([1-9]\d{0,13}|0)(\.\d{1,8})?$/);
2695
- TProcentowy4 = z4.coerce.number().min(0).max(100);
2696
- TStawkaPodatku4 = z4.enum(["6.5", "7"]);
2697
- TFormaPlatnosci4 = z4.literal("1");
2698
- TNrRB4 = z4.string().min(10).max(34);
2699
- SWIFT_Type4 = z4.string().regex(/^[A-Z]{6}[A-Z0-9]{2}([A-Z0-9]{3}){0,1}$/);
2700
- TRachunekBankowy4 = z4.object({
2701
- "NrRB": TNrRB4,
2702
- "SWIFT": SWIFT_Type4.optional(),
2703
- "NazwaBanku": TZnakowy5.optional(),
2704
- "OpisRachunku": TZnakowy5.optional()
2705
- }).strict();
2706
- TTekstowy4 = z4.string().min(1).max(3500);
2707
- TNrKRS4 = z4.string().regex(/^\d{10}$/);
2708
- TNrREGON4 = z4.union([z4.string().regex(/^\d{9}$/), z4.string().regex(/^\d{14}$/)]);
2709
- RR1_V10ESchema = z4.object({
2710
- "Naglowek": TNaglowek4,
2711
- "Podmiot1": z4.object({
2712
- "DaneIdentyfikacyjne": TPodmiot14,
2713
- "Adres": TAdres4,
2714
- "AdresKoresp": TAdres4.optional(),
2715
- "DaneKontaktowe": z4.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], z4.array(z4.object({
2716
- "Email": TAdresEmail4.optional(),
2717
- "Telefon": TNumerTelefonu4.optional()
2718
- }).strict()).min(0).max(3)).optional(),
2719
- "NrKontrahenta": TZnakowy5.optional()
2720
- }).strict(),
2721
- "Podmiot2": z4.object({
2722
- "DaneIdentyfikacyjne": TPodmiot14,
2723
- "Adres": TAdres4,
2724
- "AdresKoresp": TAdres4.optional(),
2725
- "DaneKontaktowe": z4.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], z4.array(z4.object({
2726
- "Email": TAdresEmail4.optional(),
2727
- "Telefon": TNumerTelefonu4.optional()
2728
- }).strict()).min(0).max(3)).optional(),
2729
- "StatusInfoPodatnika": TStatusInfoPodatnika4.optional()
2730
- }).strict(),
2731
- "Podmiot3": z4.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], z4.array(z4.object({
2732
- "DaneIdentyfikacyjne": TPodmiot34,
2733
- "Adres": TAdres4.optional(),
2734
- "AdresKoresp": TAdres4.optional(),
2735
- "DaneKontaktowe": z4.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], z4.array(z4.object({
2736
- "Email": TAdresEmail4.optional(),
2737
- "Telefon": TNumerTelefonu4.optional()
2738
- }).strict()).min(0).max(3)).optional(),
2739
- "Rola": TRolaPodmiotu34.optional(),
2740
- "RolaInna": TWybor14.optional(),
2741
- "OpisRoli": TZnakowy5.optional()
2742
- }).strict()).min(0).max(100)).optional(),
2743
- "FakturaRR": z4.object({
2744
- "KodWaluty": TKodWaluty4,
2745
- "P_1M": TZnakowy5.optional(),
2746
- "P_4A": TDataT4.optional(),
2747
- "P_4B": TDataT4,
2748
- "P_4C": TZnakowy5,
2749
- "P_11_1": TKwotowy5,
2750
- "P_11_1W": TKwotowy5.optional(),
2751
- "P_11_2": TKwotowy5,
2752
- "P_11_2W": TKwotowy5.optional(),
2753
- "P_12_1": TKwotowy5,
2754
- "P_12_1W": TKwotowy5.optional(),
2755
- "P_12_2": TZnakowy5,
2756
- "RodzajFaktury": TRodzajFaktury4,
2757
- "PrzyczynaKorekty": TZnakowy5.optional(),
2758
- "TypKorekty": TTypKorekty4.optional(),
2759
- "DaneFaKorygowanej": z4.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], z4.array(z4.object({
2760
- "DataWystFaKorygowanej": TDataT4,
2761
- "NrFaKorygowanej": TZnakowy5,
2762
- "NrKSeF": TWybor14.optional(),
2763
- "NrKSeFFaKorygowanej": TNumerKSeF4.optional(),
2764
- "NrKSeFN": TWybor14.optional()
2765
- }).strict()).min(1).max(5e4)).optional(),
2766
- "NrFaKorygowany": TZnakowy5.optional(),
2767
- "Podmiot1K": z4.object({
2768
- "DaneIdentyfikacyjne": TPodmiot14,
2769
- "Adres": TAdres4
2770
- }).strict().optional(),
2771
- "Podmiot2K": z4.object({
2772
- "DaneIdentyfikacyjne": TPodmiot14,
2773
- "Adres": TAdres4
2774
- }).strict().optional(),
2775
- "DokumentZaplaty": z4.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], z4.array(z4.object({
2776
- "NrDokumentu": TZnakowy5,
2777
- "DataDokumentu": TData4.optional()
2778
- }).strict()).min(0).max(50)).optional(),
2779
- "DodatkowyOpis": z4.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], z4.array(TKluczWartosc4).min(0).max(1e4)).optional(),
2780
- "FakturaRRWiersz": z4.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], z4.array(z4.object({
2781
- "NrWierszaFa": TNaturalny4,
2782
- "UU_ID": TZnakowy504.optional(),
2783
- "P_4AA": TDataT4.optional(),
2784
- "P_5": TZnakowy5,
2785
- "GTIN": TZnakowy204.optional(),
2786
- "PKWiU": TZnakowy504.optional(),
2787
- "CN": TZnakowy504.optional(),
2788
- "P_6A": TZnakowy5,
2789
- "P_6B": TIlosci4,
2790
- "P_6C": TZnakowy5,
2791
- "P_7": TKwotowy24,
2792
- "P_8": TKwotowy5,
2793
- "P_9": TStawkaPodatku4,
2794
- "P_10": TKwotowy5,
2795
- "P_11": TKwotowy5,
2796
- "StanPrzed": TWybor14.optional(),
2797
- "KursWaluty": TIlosci4.optional()
2798
- }).strict()).min(0).max(1e4)).optional(),
2799
- "Rozliczenie": z4.object({
2800
- "Obciazenia": z4.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], z4.array(z4.object({
2801
- "Kwota": TKwotowy5,
2802
- "Powod": TZnakowy5
2803
- }).strict()).min(0).max(100)).optional(),
2804
- "SumaObciazen": TKwotowy5.optional(),
2805
- "Odliczenia": z4.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], z4.array(z4.object({
2806
- "Kwota": TKwotowy5,
2807
- "Powod": TZnakowy5
2808
- }).strict()).min(0).max(100)).optional(),
2809
- "SumaOdliczen": TKwotowy5.optional(),
2810
- "DoZaplaty": TKwotowy5.optional(),
2811
- "DoRozliczenia": TKwotowy5.optional()
2812
- }).strict().optional(),
2813
- "Platnosc": z4.object({
2814
- "FormaPlatnosci": TFormaPlatnosci4.optional(),
2815
- "PlatnoscInna": TWybor14.optional(),
2816
- "OpisPlatnosci": TZnakowy5.optional(),
2817
- "RachunekBankowy1": z4.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], z4.array(TRachunekBankowy4).min(0).max(3)).optional(),
2818
- "RachunekBankowy2": z4.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], z4.array(TRachunekBankowy4).min(0).max(3)).optional(),
2819
- "IPKSeF": z4.string().min(1).max(13).regex(/^[0-9]{3}[a-zA-Z0-9]{10}$/).optional(),
2820
- "LinkDoPlatnosci": z4.string().min(1).max(512).regex(/^(https?):\/\/([a-zA-Z0-9][a-zA-Z0-9-]*\.)+[a-zA-Z]{2,}(:[0-9]{1,5})?(\/[^\s?#]*)?\?([^#\s]*&)?IPKSeF=[0-9]{3}[a-zA-Z0-9]{10}(&[^#\s]*)?(#.*)?$/).optional()
2821
- }).strict().optional()
2822
- }).strict(),
2823
- "Stopka": z4.object({
2824
- "Informacje": z4.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], z4.array(z4.object({
2825
- "StopkaFaktury": TTekstowy4.optional()
2826
- }).strict()).min(0).max(3)).optional(),
2827
- "Rejestry": z4.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], z4.array(z4.object({
2828
- "PelnaNazwa": TZnakowy5.optional(),
2829
- "KRS": TNrKRS4.optional(),
2830
- "REGON": TNrREGON4.optional(),
2831
- "BDO": z4.string().min(1).max(9).optional()
2832
- }).strict()).min(0).max(100)).optional()
2833
- }).strict().optional()
2728
+ InvoiceType = z4.object({
2729
+ "UBLExtensions": z4.any().optional(),
2730
+ "UBLVersionID": z4.any().optional(),
2731
+ "CustomizationID": z4.any().optional(),
2732
+ "ProfileID": z4.any().optional(),
2733
+ "ProfileExecutionID": z4.any().optional(),
2734
+ "ID": z4.any(),
2735
+ "CopyIndicator": z4.any().optional(),
2736
+ "UUID": z4.any().optional(),
2737
+ "IssueDate": z4.any(),
2738
+ "IssueTime": z4.any().optional(),
2739
+ "DueDate": z4.any().optional(),
2740
+ "InvoiceTypeCode": z4.any().optional(),
2741
+ "Note": z4.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], z4.array(z4.any()).min(0)).optional(),
2742
+ "TaxPointDate": z4.any().optional(),
2743
+ "DocumentCurrencyCode": z4.any().optional(),
2744
+ "TaxCurrencyCode": z4.any().optional(),
2745
+ "PricingCurrencyCode": z4.any().optional(),
2746
+ "PaymentCurrencyCode": z4.any().optional(),
2747
+ "PaymentAlternativeCurrencyCode": z4.any().optional(),
2748
+ "AccountingCostCode": z4.any().optional(),
2749
+ "AccountingCost": z4.any().optional(),
2750
+ "LineCountNumeric": z4.any().optional(),
2751
+ "BuyerReference": z4.any().optional(),
2752
+ "InvoicePeriod": z4.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], z4.array(z4.any()).min(0)).optional(),
2753
+ "OrderReference": z4.any().optional(),
2754
+ "BillingReference": z4.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], z4.array(z4.any()).min(0)).optional(),
2755
+ "DespatchDocumentReference": z4.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], z4.array(z4.any()).min(0)).optional(),
2756
+ "ReceiptDocumentReference": z4.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], z4.array(z4.any()).min(0)).optional(),
2757
+ "StatementDocumentReference": z4.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], z4.array(z4.any()).min(0)).optional(),
2758
+ "OriginatorDocumentReference": z4.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], z4.array(z4.any()).min(0)).optional(),
2759
+ "ContractDocumentReference": z4.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], z4.array(z4.any()).min(0)).optional(),
2760
+ "AdditionalDocumentReference": z4.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], z4.array(z4.any()).min(0)).optional(),
2761
+ "ProjectReference": z4.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], z4.array(z4.any()).min(0)).optional(),
2762
+ "Signature": z4.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], z4.array(z4.any()).min(0)).optional(),
2763
+ "AccountingSupplierParty": z4.any(),
2764
+ "AccountingCustomerParty": z4.any(),
2765
+ "PayeeParty": z4.any().optional(),
2766
+ "BuyerCustomerParty": z4.any().optional(),
2767
+ "SellerSupplierParty": z4.any().optional(),
2768
+ "TaxRepresentativeParty": z4.any().optional(),
2769
+ "Delivery": z4.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], z4.array(z4.any()).min(0)).optional(),
2770
+ "DeliveryTerms": z4.any().optional(),
2771
+ "PaymentMeans": z4.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], z4.array(z4.any()).min(0)).optional(),
2772
+ "PaymentTerms": z4.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], z4.array(z4.any()).min(0)).optional(),
2773
+ "PrepaidPayment": z4.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], z4.array(z4.any()).min(0)).optional(),
2774
+ "AllowanceCharge": z4.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], z4.array(z4.any()).min(0)).optional(),
2775
+ "TaxExchangeRate": z4.any().optional(),
2776
+ "PricingExchangeRate": z4.any().optional(),
2777
+ "PaymentExchangeRate": z4.any().optional(),
2778
+ "PaymentAlternativeExchangeRate": z4.any().optional(),
2779
+ "TaxTotal": z4.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], z4.array(z4.any()).min(0)).optional(),
2780
+ "WithholdingTaxTotal": z4.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], z4.array(z4.any()).min(0)).optional(),
2781
+ "LegalMonetaryTotal": z4.any(),
2782
+ "InvoiceLine": z4.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], z4.array(z4.any()).min(1))
2834
2783
  }).strict();
2784
+ PEF3Schema = InvoiceType;
2835
2785
  }
2836
2786
  });
2837
2787
 
2838
- // src/validation/schemas/pef3.ts
2839
- var pef3_exports = {};
2840
- __export(pef3_exports, {
2841
- PEF3Schema: () => PEF3Schema
2788
+ // src/validation/schemas/pef-kor3.ts
2789
+ var pef_kor3_exports = {};
2790
+ __export(pef_kor3_exports, {
2791
+ PEF_KOR3Schema: () => PEF_KOR3Schema
2842
2792
  });
2843
2793
  import { z as z5 } from "zod";
2844
- var InvoiceType, PEF3Schema;
2845
- var init_pef3 = __esm({
2846
- "src/validation/schemas/pef3.ts"() {
2794
+ var CreditNoteType, PEF_KOR3Schema;
2795
+ var init_pef_kor3 = __esm({
2796
+ "src/validation/schemas/pef-kor3.ts"() {
2847
2797
  "use strict";
2848
2798
  init_esm_shims();
2849
- InvoiceType = z5.object({
2799
+ CreditNoteType = z5.object({
2850
2800
  "UBLExtensions": z5.any().optional(),
2851
2801
  "UBLVersionID": z5.any().optional(),
2852
2802
  "CustomizationID": z5.any().optional(),
@@ -2857,10 +2807,9 @@ var init_pef3 = __esm({
2857
2807
  "UUID": z5.any().optional(),
2858
2808
  "IssueDate": z5.any(),
2859
2809
  "IssueTime": z5.any().optional(),
2860
- "DueDate": z5.any().optional(),
2861
- "InvoiceTypeCode": z5.any().optional(),
2862
- "Note": z5.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], z5.array(z5.any()).min(0)).optional(),
2863
2810
  "TaxPointDate": z5.any().optional(),
2811
+ "CreditNoteTypeCode": z5.any().optional(),
2812
+ "Note": z5.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], z5.array(z5.any()).min(0)).optional(),
2864
2813
  "DocumentCurrencyCode": z5.any().optional(),
2865
2814
  "TaxCurrencyCode": z5.any().optional(),
2866
2815
  "PricingCurrencyCode": z5.any().optional(),
@@ -2871,15 +2820,15 @@ var init_pef3 = __esm({
2871
2820
  "LineCountNumeric": z5.any().optional(),
2872
2821
  "BuyerReference": z5.any().optional(),
2873
2822
  "InvoicePeriod": z5.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], z5.array(z5.any()).min(0)).optional(),
2823
+ "DiscrepancyResponse": z5.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], z5.array(z5.any()).min(0)).optional(),
2874
2824
  "OrderReference": z5.any().optional(),
2875
2825
  "BillingReference": z5.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], z5.array(z5.any()).min(0)).optional(),
2876
2826
  "DespatchDocumentReference": z5.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], z5.array(z5.any()).min(0)).optional(),
2877
2827
  "ReceiptDocumentReference": z5.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], z5.array(z5.any()).min(0)).optional(),
2878
- "StatementDocumentReference": z5.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], z5.array(z5.any()).min(0)).optional(),
2879
- "OriginatorDocumentReference": z5.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], z5.array(z5.any()).min(0)).optional(),
2880
2828
  "ContractDocumentReference": z5.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], z5.array(z5.any()).min(0)).optional(),
2881
2829
  "AdditionalDocumentReference": z5.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], z5.array(z5.any()).min(0)).optional(),
2882
- "ProjectReference": z5.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], z5.array(z5.any()).min(0)).optional(),
2830
+ "StatementDocumentReference": z5.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], z5.array(z5.any()).min(0)).optional(),
2831
+ "OriginatorDocumentReference": z5.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], z5.array(z5.any()).min(0)).optional(),
2883
2832
  "Signature": z5.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], z5.array(z5.any()).min(0)).optional(),
2884
2833
  "AccountingSupplierParty": z5.any(),
2885
2834
  "AccountingCustomerParty": z5.any(),
@@ -2888,87 +2837,17 @@ var init_pef3 = __esm({
2888
2837
  "SellerSupplierParty": z5.any().optional(),
2889
2838
  "TaxRepresentativeParty": z5.any().optional(),
2890
2839
  "Delivery": z5.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], z5.array(z5.any()).min(0)).optional(),
2891
- "DeliveryTerms": z5.any().optional(),
2840
+ "DeliveryTerms": z5.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], z5.array(z5.any()).min(0)).optional(),
2892
2841
  "PaymentMeans": z5.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], z5.array(z5.any()).min(0)).optional(),
2893
2842
  "PaymentTerms": z5.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], z5.array(z5.any()).min(0)).optional(),
2894
- "PrepaidPayment": z5.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], z5.array(z5.any()).min(0)).optional(),
2895
- "AllowanceCharge": z5.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], z5.array(z5.any()).min(0)).optional(),
2896
2843
  "TaxExchangeRate": z5.any().optional(),
2897
2844
  "PricingExchangeRate": z5.any().optional(),
2898
2845
  "PaymentExchangeRate": z5.any().optional(),
2899
2846
  "PaymentAlternativeExchangeRate": z5.any().optional(),
2847
+ "AllowanceCharge": z5.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], z5.array(z5.any()).min(0)).optional(),
2900
2848
  "TaxTotal": z5.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], z5.array(z5.any()).min(0)).optional(),
2901
- "WithholdingTaxTotal": z5.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], z5.array(z5.any()).min(0)).optional(),
2902
2849
  "LegalMonetaryTotal": z5.any(),
2903
- "InvoiceLine": z5.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], z5.array(z5.any()).min(1))
2904
- }).strict();
2905
- PEF3Schema = InvoiceType;
2906
- }
2907
- });
2908
-
2909
- // src/validation/schemas/pef-kor3.ts
2910
- var pef_kor3_exports = {};
2911
- __export(pef_kor3_exports, {
2912
- PEF_KOR3Schema: () => PEF_KOR3Schema
2913
- });
2914
- import { z as z6 } from "zod";
2915
- var CreditNoteType, PEF_KOR3Schema;
2916
- var init_pef_kor3 = __esm({
2917
- "src/validation/schemas/pef-kor3.ts"() {
2918
- "use strict";
2919
- init_esm_shims();
2920
- CreditNoteType = z6.object({
2921
- "UBLExtensions": z6.any().optional(),
2922
- "UBLVersionID": z6.any().optional(),
2923
- "CustomizationID": z6.any().optional(),
2924
- "ProfileID": z6.any().optional(),
2925
- "ProfileExecutionID": z6.any().optional(),
2926
- "ID": z6.any(),
2927
- "CopyIndicator": z6.any().optional(),
2928
- "UUID": z6.any().optional(),
2929
- "IssueDate": z6.any(),
2930
- "IssueTime": z6.any().optional(),
2931
- "TaxPointDate": z6.any().optional(),
2932
- "CreditNoteTypeCode": z6.any().optional(),
2933
- "Note": z6.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], z6.array(z6.any()).min(0)).optional(),
2934
- "DocumentCurrencyCode": z6.any().optional(),
2935
- "TaxCurrencyCode": z6.any().optional(),
2936
- "PricingCurrencyCode": z6.any().optional(),
2937
- "PaymentCurrencyCode": z6.any().optional(),
2938
- "PaymentAlternativeCurrencyCode": z6.any().optional(),
2939
- "AccountingCostCode": z6.any().optional(),
2940
- "AccountingCost": z6.any().optional(),
2941
- "LineCountNumeric": z6.any().optional(),
2942
- "BuyerReference": z6.any().optional(),
2943
- "InvoicePeriod": z6.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], z6.array(z6.any()).min(0)).optional(),
2944
- "DiscrepancyResponse": z6.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], z6.array(z6.any()).min(0)).optional(),
2945
- "OrderReference": z6.any().optional(),
2946
- "BillingReference": z6.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], z6.array(z6.any()).min(0)).optional(),
2947
- "DespatchDocumentReference": z6.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], z6.array(z6.any()).min(0)).optional(),
2948
- "ReceiptDocumentReference": z6.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], z6.array(z6.any()).min(0)).optional(),
2949
- "ContractDocumentReference": z6.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], z6.array(z6.any()).min(0)).optional(),
2950
- "AdditionalDocumentReference": z6.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], z6.array(z6.any()).min(0)).optional(),
2951
- "StatementDocumentReference": z6.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], z6.array(z6.any()).min(0)).optional(),
2952
- "OriginatorDocumentReference": z6.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], z6.array(z6.any()).min(0)).optional(),
2953
- "Signature": z6.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], z6.array(z6.any()).min(0)).optional(),
2954
- "AccountingSupplierParty": z6.any(),
2955
- "AccountingCustomerParty": z6.any(),
2956
- "PayeeParty": z6.any().optional(),
2957
- "BuyerCustomerParty": z6.any().optional(),
2958
- "SellerSupplierParty": z6.any().optional(),
2959
- "TaxRepresentativeParty": z6.any().optional(),
2960
- "Delivery": z6.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], z6.array(z6.any()).min(0)).optional(),
2961
- "DeliveryTerms": z6.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], z6.array(z6.any()).min(0)).optional(),
2962
- "PaymentMeans": z6.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], z6.array(z6.any()).min(0)).optional(),
2963
- "PaymentTerms": z6.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], z6.array(z6.any()).min(0)).optional(),
2964
- "TaxExchangeRate": z6.any().optional(),
2965
- "PricingExchangeRate": z6.any().optional(),
2966
- "PaymentExchangeRate": z6.any().optional(),
2967
- "PaymentAlternativeExchangeRate": z6.any().optional(),
2968
- "AllowanceCharge": z6.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], z6.array(z6.any()).min(0)).optional(),
2969
- "TaxTotal": z6.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], z6.array(z6.any()).min(0)).optional(),
2970
- "LegalMonetaryTotal": z6.any(),
2971
- "CreditNoteLine": z6.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], z6.array(z6.any()).min(1))
2850
+ "CreditNoteLine": z5.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], z5.array(z5.any()).min(1))
2972
2851
  }).strict();
2973
2852
  PEF_KOR3Schema = CreditNoteType;
2974
2853
  }
@@ -2982,15 +2861,13 @@ var init_schemas = __esm({
2982
2861
  init_esm_shims();
2983
2862
  init_fa3();
2984
2863
  init_fa2();
2985
- init_rr1_v11e();
2986
- init_rr1_v10e();
2864
+ init_fa_rr1();
2987
2865
  init_pef3();
2988
2866
  init_pef_kor3();
2989
2867
  NAMESPACE_MAP = {
2990
2868
  "http://crd.gov.pl/wzor/2025/06/25/13775/": "FA3",
2991
2869
  "http://crd.gov.pl/wzor/2023/06/29/12648/": "FA2",
2992
- "http://crd.gov.pl/wzor/2026/03/06/14189/": "RR1_V11E",
2993
- "http://crd.gov.pl/wzor/2026/02/17/14164/": "RR1_V10E",
2870
+ "http://crd.gov.pl/wzor/2026/03/06/14189/": "FA_RR1",
2994
2871
  "urn:oasis:names:specification:ubl:schema:xsd:Invoice-2": "PEF3",
2995
2872
  "urn:oasis:names:specification:ubl:schema:xsd:CreditNote-2": "PEF_KOR3"
2996
2873
  };
@@ -3009,11 +2886,8 @@ async function loadSchema(type) {
3009
2886
  case "FA2":
3010
2887
  mod = await Promise.resolve().then(() => (init_fa2(), fa2_exports));
3011
2888
  break;
3012
- case "RR1_V11E":
3013
- mod = await Promise.resolve().then(() => (init_rr1_v11e(), rr1_v11e_exports));
3014
- break;
3015
- case "RR1_V10E":
3016
- mod = await Promise.resolve().then(() => (init_rr1_v10e(), rr1_v10e_exports));
2889
+ case "FA_RR1":
2890
+ mod = await Promise.resolve().then(() => (init_fa_rr1(), fa_rr1_exports));
3017
2891
  break;
3018
2892
  case "PEF3":
3019
2893
  mod = await Promise.resolve().then(() => (init_pef3(), pef3_exports));
@@ -3054,7 +2928,7 @@ var init_schema_registry = __esm({
3054
2928
  * List all available schema types.
3055
2929
  */
3056
2930
  availableSchemas() {
3057
- return ["FA3", "FA2", "RR1_V11E", "RR1_V10E", "PEF3", "PEF_KOR3"];
2931
+ return ["FA3", "FA2", "FA_RR1", "PEF3", "PEF_KOR3"];
3058
2932
  },
3059
2933
  /**
3060
2934
  * Detect schema type from XML namespace URI and/or root element name.
@@ -4177,6 +4051,8 @@ var init_certificates = __esm({
4177
4051
  init_esm_shims();
4178
4052
  init_rest_request();
4179
4053
  init_routes();
4054
+ init_ksef_validation_error();
4055
+ init_patterns();
4180
4056
  CertificateApiService = class {
4181
4057
  restClient;
4182
4058
  constructor(restClient) {
@@ -4203,6 +4079,14 @@ var init_certificates = __esm({
4203
4079
  return response.body;
4204
4080
  }
4205
4081
  async retrieve(request) {
4082
+ for (const serial of request.certificateSerialNumbers ?? []) {
4083
+ if (!isValidCertificateSerialNumber(serial)) {
4084
+ throw KSeFValidationError.fromField(
4085
+ "certificateSerialNumbers",
4086
+ `Invalid certificate serial number "${serial}": must be exactly 16 uppercase hex characters (^[0-9A-F]{16}$)`
4087
+ );
4088
+ }
4089
+ }
4206
4090
  const req = RestRequest.post(Routes.Certificates.retrieve).body(request);
4207
4091
  const response = await this.restClient.execute(req);
4208
4092
  return response.body;
@@ -4451,8 +4335,8 @@ var init_certificate_fetcher = __esm({
4451
4335
  init_routes();
4452
4336
  CertificateFetcher = class {
4453
4337
  restClient;
4454
- symmetricKeyPem;
4455
- ksefTokenPem;
4338
+ symmetricKey;
4339
+ ksefToken;
4456
4340
  initialized = false;
4457
4341
  constructor(restClient) {
4458
4342
  this.restClient = restClient;
@@ -4465,17 +4349,38 @@ var init_certificate_fetcher = __esm({
4465
4349
  this.initialized = false;
4466
4350
  await this.fetchCertificates();
4467
4351
  }
4352
+ /**
4353
+ * Immutable snapshot ({@link SelectedCertificate}) of the selected
4354
+ * SymmetricKeyEncryption certificate. The stored object is replaced wholesale
4355
+ * by {@link refresh}, never mutated, so holding the returned reference yields a
4356
+ * consistent pem + publicKeyId pair even if a concurrent refresh swaps the cache.
4357
+ */
4358
+ getSymmetricKeyEncryption() {
4359
+ return { ...this.requireSelected(this.symmetricKey) };
4360
+ }
4361
+ /** Immutable snapshot of the selected KsefTokenEncryption certificate. See {@link getSymmetricKeyEncryption}. */
4362
+ getKsefTokenEncryption() {
4363
+ return { ...this.requireSelected(this.ksefToken) };
4364
+ }
4468
4365
  getSymmetricKeyEncryptionPem() {
4469
- if (!this.symmetricKeyPem) {
4470
- throw new Error("CertificateFetcher not initialized. Call init() first.");
4471
- }
4472
- return this.symmetricKeyPem;
4366
+ return this.requireSelected(this.symmetricKey).pem;
4473
4367
  }
4474
4368
  getKsefTokenEncryptionPem() {
4475
- if (!this.ksefTokenPem) {
4369
+ return this.requireSelected(this.ksefToken).pem;
4370
+ }
4371
+ /** Public key identifier of the selected SymmetricKeyEncryption certificate (KSeF API v2.5.0). */
4372
+ getSymmetricKeyPublicKeyId() {
4373
+ return this.requireSelected(this.symmetricKey).publicKeyId;
4374
+ }
4375
+ /** Public key identifier of the selected KsefTokenEncryption certificate (KSeF API v2.5.0). */
4376
+ getKsefTokenPublicKeyId() {
4377
+ return this.requireSelected(this.ksefToken).publicKeyId;
4378
+ }
4379
+ requireSelected(selected) {
4380
+ if (!selected) {
4476
4381
  throw new Error("CertificateFetcher not initialized. Call init() first.");
4477
4382
  }
4478
- return this.ksefTokenPem;
4383
+ return selected;
4479
4384
  }
4480
4385
  async fetchCertificates() {
4481
4386
  const request = RestRequest.get(Routes.Security.publicKeyCertificates);
@@ -4484,19 +4389,27 @@ var init_certificate_fetcher = __esm({
4484
4389
  if (!certs || certs.length === 0) {
4485
4390
  throw new Error("No public key certificates returned from KSeF API.");
4486
4391
  }
4487
- const symmetricCert = certs.find((c) => c.usage.includes("SymmetricKeyEncryption"));
4488
- if (!symmetricCert) {
4489
- throw new Error("No SymmetricKeyEncryption certificate found.");
4490
- }
4491
- this.symmetricKeyPem = this.derBase64ToPem(symmetricCert.certificate);
4492
- const tokenCerts = certs.filter((c) => c.usage.includes("KsefTokenEncryption")).sort((a, b) => a.validFrom.localeCompare(b.validFrom));
4493
- const tokenCert = tokenCerts[0];
4494
- if (!tokenCert) {
4495
- throw new Error("No KsefTokenEncryption certificate found.");
4496
- }
4497
- this.ksefTokenPem = this.derBase64ToPem(tokenCert.certificate);
4392
+ this.symmetricKey = this.select(certs, "SymmetricKeyEncryption");
4393
+ this.ksefToken = this.select(certs, "KsefTokenEncryption");
4498
4394
  this.initialized = true;
4499
4395
  }
4396
+ /**
4397
+ * Select the certificate to use for a given usage under key rotation:
4398
+ * filter to currently-valid certificates (validFrom ≤ now < validTo) and pick
4399
+ * the newest by validFrom. If none are currently valid, fall back to the newest
4400
+ * overall so the server can reject it with a clear error rather than sending nothing.
4401
+ */
4402
+ select(certs, usage) {
4403
+ const candidates = certs.filter((c) => c.usage.includes(usage));
4404
+ if (candidates.length === 0) {
4405
+ throw new Error(`No ${usage} certificate found.`);
4406
+ }
4407
+ const now = Date.now();
4408
+ const byNewestValidFrom = (a, b) => Date.parse(b.validFrom) - Date.parse(a.validFrom);
4409
+ const valid = candidates.filter((c) => Date.parse(c.validFrom) <= now && now < Date.parse(c.validTo)).sort(byNewestValidFrom);
4410
+ const chosen = valid[0] ?? [...candidates].sort(byNewestValidFrom)[0];
4411
+ return { pem: this.derBase64ToPem(chosen.certificate), publicKeyId: chosen.publicKeyId };
4412
+ }
4500
4413
  derBase64ToPem(base64Der) {
4501
4414
  const lines = [];
4502
4415
  for (let i = 0; i < base64Der.length; i += 64) {
@@ -4552,6 +4465,14 @@ var init_cryptography_service = __esm({
4552
4465
  async init() {
4553
4466
  await this.fetcher.init();
4554
4467
  }
4468
+ /** Re-fetch KSeF public certificates, discarding the cached selection (used for key-rotation recovery). */
4469
+ async refresh() {
4470
+ await this.fetcher.refresh();
4471
+ }
4472
+ /** Identifier of the KsefTokenEncryption public key used by {@link encryptKsefToken} (KSeF API v2.5.0). */
4473
+ getKsefTokenPublicKeyId() {
4474
+ return this.fetcher.getKsefTokenPublicKeyId();
4475
+ }
4555
4476
  // ---------------------------------------------------------------------------
4556
4477
  // AES-256-CBC
4557
4478
  // ---------------------------------------------------------------------------
@@ -4597,11 +4518,12 @@ var init_cryptography_service = __esm({
4597
4518
  async getEncryptionData() {
4598
4519
  const key = crypto2.randomBytes(32);
4599
4520
  const iv = crypto2.randomBytes(16);
4600
- const certPem = this.fetcher.getSymmetricKeyEncryptionPem();
4601
- const encryptedKey = await this.rsaOaepEncrypt(certPem, new Uint8Array(key));
4521
+ const cert = this.fetcher.getSymmetricKeyEncryption();
4522
+ const encryptedKey = await this.rsaOaepEncrypt(cert.pem, new Uint8Array(key));
4602
4523
  const encryptionInfo = {
4603
4524
  encryptedSymmetricKey: Buffer.from(encryptedKey).toString("base64"),
4604
- initializationVector: iv.toString("base64")
4525
+ initializationVector: iv.toString("base64"),
4526
+ publicKeyId: cert.publicKeyId
4605
4527
  };
4606
4528
  return {
4607
4529
  cipherKey: new Uint8Array(key),
@@ -4626,9 +4548,29 @@ var init_cryptography_service = __esm({
4626
4548
  * `[ephemeralSPKI | nonce(12) | ciphertext+tag]`.
4627
4549
  */
4628
4550
  async encryptKsefToken(token, challengeTimestamp) {
4551
+ return this.encryptKsefTokenWithCertPem(
4552
+ this.fetcher.getKsefTokenEncryptionPem(),
4553
+ token,
4554
+ challengeTimestamp
4555
+ );
4556
+ }
4557
+ /**
4558
+ * Encrypt a KSeF token and return it together with the public key id of the
4559
+ * exact certificate used.
4560
+ *
4561
+ * Both values come from a single certificate snapshot taken before any
4562
+ * `await`, so a concurrent {@link refresh} cannot tag the ciphertext with a
4563
+ * different key than it was encrypted under (KSeF API v2.5.0). Prefer this over
4564
+ * pairing {@link encryptKsefToken} with a separate {@link getKsefTokenPublicKeyId}.
4565
+ */
4566
+ async encryptKsefTokenWithKeyId(token, challengeTimestamp) {
4567
+ const cert = this.fetcher.getKsefTokenEncryption();
4568
+ const encryptedToken = await this.encryptKsefTokenWithCertPem(cert.pem, token, challengeTimestamp);
4569
+ return { encryptedToken, publicKeyId: cert.publicKeyId };
4570
+ }
4571
+ async encryptKsefTokenWithCertPem(certPem, token, challengeTimestamp) {
4629
4572
  const timestampMs = new Date(challengeTimestamp).getTime();
4630
4573
  const plaintext = Buffer.from(`${token}|${timestampMs}`, "utf-8");
4631
- const certPem = this.fetcher.getKsefTokenEncryptionPem();
4632
4574
  const cert = new crypto2.X509Certificate(certPem);
4633
4575
  const publicKey = cert.publicKey;
4634
4576
  if (publicKey.asymmetricKeyType === "rsa") {
@@ -5147,7 +5089,7 @@ var init_auth_xml_builder = __esm({
5147
5089
  "src/crypto/auth-xml-builder.ts"() {
5148
5090
  "use strict";
5149
5091
  init_esm_shims();
5150
- AUTH_TOKEN_REQUEST_NS = "http://ksef.mf.gov.pl/auth/token/2.0";
5092
+ AUTH_TOKEN_REQUEST_NS = "http://ksef.mf.gov.pl/auth/token/2.1";
5151
5093
  }
5152
5094
  });
5153
5095
 
@@ -5309,6 +5251,156 @@ var init_zip = __esm({
5309
5251
  }
5310
5252
  });
5311
5253
 
5254
+ // src/utils/targz.ts
5255
+ var targz_exports = {};
5256
+ __export(targz_exports, {
5257
+ createTarGz: () => createTarGz,
5258
+ extractTarGz: () => extractTarGz
5259
+ });
5260
+ import { createGzip, createGunzip } from "node:zlib";
5261
+ import { Readable } from "node:stream";
5262
+ import { extract, pack } from "tar-stream";
5263
+ async function createTarGz(entries) {
5264
+ const packer = pack();
5265
+ const gzip = packer.pipe(createGzip());
5266
+ const chunks = [];
5267
+ return new Promise((resolve, reject) => {
5268
+ let settled = false;
5269
+ const fail = (err) => {
5270
+ if (settled) return;
5271
+ settled = true;
5272
+ reject(err);
5273
+ };
5274
+ packer.on("error", fail);
5275
+ gzip.on("error", fail);
5276
+ gzip.on("data", (chunk) => chunks.push(chunk));
5277
+ gzip.on("end", () => {
5278
+ if (settled) return;
5279
+ settled = true;
5280
+ resolve(Buffer.concat(chunks));
5281
+ });
5282
+ try {
5283
+ for (const entry of entries) {
5284
+ const content = Buffer.from(entry.content);
5285
+ packer.entry({ name: entry.fileName, size: content.length }, content);
5286
+ }
5287
+ packer.finalize();
5288
+ } catch (err) {
5289
+ fail(err instanceof Error ? err : new Error(String(err)));
5290
+ }
5291
+ });
5292
+ }
5293
+ async function extractTarGz(buffer, options = {}) {
5294
+ const limits = { ...DEFAULT_LIMITS, ...options };
5295
+ const ratioCeiling = limits.maxCompressionRatio !== null && limits.maxCompressionRatio !== void 0 && buffer.length > 0 ? buffer.length * limits.maxCompressionRatio : null;
5296
+ return new Promise((resolve, reject) => {
5297
+ const source = Readable.from(buffer);
5298
+ const gunzip = createGunzip();
5299
+ const extractor = extract();
5300
+ const files = /* @__PURE__ */ new Map();
5301
+ let extractedFileCount = 0;
5302
+ let totalUncompressed = 0;
5303
+ let settled = false;
5304
+ const cleanup = () => {
5305
+ source.destroy();
5306
+ gunzip.destroy();
5307
+ extractor.destroy();
5308
+ };
5309
+ const fail = (err) => {
5310
+ if (settled) return;
5311
+ settled = true;
5312
+ cleanup();
5313
+ reject(err);
5314
+ };
5315
+ const succeed = () => {
5316
+ if (settled) return;
5317
+ settled = true;
5318
+ resolve(files);
5319
+ };
5320
+ gunzip.on("data", (chunk) => {
5321
+ totalUncompressed += chunk.length;
5322
+ if (limits.maxTotalUncompressedSize > 0 && totalUncompressed > limits.maxTotalUncompressedSize) {
5323
+ fail(new Error("tar.gz exceeds max_total_uncompressed_size"));
5324
+ return;
5325
+ }
5326
+ if (ratioCeiling !== null && totalUncompressed > ratioCeiling) {
5327
+ fail(new Error("tar.gz exceeds max_compression_ratio"));
5328
+ }
5329
+ });
5330
+ extractor.on("entry", (header, stream, next) => {
5331
+ if (settled) {
5332
+ stream.resume();
5333
+ return;
5334
+ }
5335
+ if (header.type !== "file") {
5336
+ stream.resume();
5337
+ stream.on("end", next);
5338
+ return;
5339
+ }
5340
+ if (limits.maxFiles > 0 && extractedFileCount >= limits.maxFiles) {
5341
+ fail(new Error("tar.gz contains too many files"));
5342
+ return;
5343
+ }
5344
+ const chunks = [];
5345
+ let entrySize = 0;
5346
+ stream.on("data", (chunk) => {
5347
+ if (settled) return;
5348
+ entrySize += chunk.length;
5349
+ if (limits.maxFileUncompressedSize > 0 && entrySize > limits.maxFileUncompressedSize) {
5350
+ fail(new Error("tar.gz entry exceeds max_file_uncompressed_size"));
5351
+ return;
5352
+ }
5353
+ chunks.push(chunk);
5354
+ });
5355
+ stream.on("error", fail);
5356
+ stream.on("end", () => {
5357
+ if (settled) return;
5358
+ extractedFileCount += 1;
5359
+ files.set(header.name, Buffer.concat(chunks));
5360
+ next();
5361
+ });
5362
+ });
5363
+ extractor.on("finish", succeed);
5364
+ extractor.on("error", fail);
5365
+ gunzip.on("error", fail);
5366
+ source.on("error", fail);
5367
+ source.pipe(gunzip).pipe(extractor);
5368
+ });
5369
+ }
5370
+ var DEFAULT_LIMITS;
5371
+ var init_targz = __esm({
5372
+ "src/utils/targz.ts"() {
5373
+ "use strict";
5374
+ init_esm_shims();
5375
+ DEFAULT_LIMITS = {
5376
+ maxFiles: 1e4,
5377
+ maxTotalUncompressedSize: 2e9,
5378
+ maxFileUncompressedSize: 5e8,
5379
+ maxCompressionRatio: 200
5380
+ };
5381
+ }
5382
+ });
5383
+
5384
+ // src/crypto/with-key-rotation-retry.ts
5385
+ async function withKeyRotationRetry(crypto8, op) {
5386
+ try {
5387
+ return await op();
5388
+ } catch (err) {
5389
+ if (err instanceof KSeFUnknownPublicKeyError) {
5390
+ await crypto8.refresh();
5391
+ return await op();
5392
+ }
5393
+ throw err;
5394
+ }
5395
+ }
5396
+ var init_with_key_rotation_retry = __esm({
5397
+ "src/crypto/with-key-rotation-retry.ts"() {
5398
+ "use strict";
5399
+ init_esm_shims();
5400
+ init_ksef_unknown_public_key_error();
5401
+ }
5402
+ });
5403
+
5312
5404
  // src/offline/holidays.ts
5313
5405
  function toDateKey(d) {
5314
5406
  return d.toISOString().slice(0, 10);
@@ -5486,6 +5578,7 @@ var init_offline_invoice_workflow = __esm({
5486
5578
  init_esm_shims();
5487
5579
  init_ksef_api_error();
5488
5580
  init_deadline();
5581
+ init_with_key_rotation_retry();
5489
5582
  init_document_structures();
5490
5583
  OfflineInvoiceWorkflow = class {
5491
5584
  constructor(qrService) {
@@ -5592,11 +5685,14 @@ var init_offline_invoice_workflow = __esm({
5592
5685
  }
5593
5686
  if (pending.length === 0) return result;
5594
5687
  await client.crypto.init();
5595
- const encData = await client.crypto.getEncryptionData();
5596
5688
  const formCode = options.formCode ?? DEFAULT_FORM_CODE;
5597
- const openResp = await client.onlineSession.openSession(
5598
- { formCode, encryption: encData.encryptionInfo }
5599
- );
5689
+ const { encData, openResp } = await withKeyRotationRetry(client.crypto, async () => {
5690
+ const encData2 = await client.crypto.getEncryptionData();
5691
+ const openResp2 = await client.onlineSession.openSession(
5692
+ { formCode, encryption: encData2.encryptionInfo }
5693
+ );
5694
+ return { encData: encData2, openResp: openResp2 };
5695
+ });
5600
5696
  const sessionRef = openResp.referenceNumber;
5601
5697
  try {
5602
5698
  for (const inv of pending) {
@@ -5681,11 +5777,14 @@ var init_offline_invoice_workflow = __esm({
5681
5777
  }
5682
5778
  const originalHash = crypto7.createHash("sha256").update(original.invoiceXml).digest("base64");
5683
5779
  await client.crypto.init();
5684
- const encData = await client.crypto.getEncryptionData();
5685
5780
  const formCode = options.formCode ?? DEFAULT_FORM_CODE;
5686
- const openResp = await client.onlineSession.openSession(
5687
- { formCode, encryption: encData.encryptionInfo }
5688
- );
5781
+ const { encData, openResp } = await withKeyRotationRetry(client.crypto, async () => {
5782
+ const encData2 = await client.crypto.getEncryptionData();
5783
+ const openResp2 = await client.onlineSession.openSession(
5784
+ { formCode, encryption: encData2.encryptionInfo }
5785
+ );
5786
+ return { encData: encData2, openResp: openResp2 };
5787
+ });
5689
5788
  const sessionRef = openResp.referenceNumber;
5690
5789
  try {
5691
5790
  const data = new TextEncoder().encode(correctedInvoiceXml);
@@ -5807,6 +5906,9 @@ function buildRestClientConfig(options, authManager) {
5807
5906
  allowedHosts: [...base.allowedHosts, ...options.presignedUrlHosts]
5808
5907
  };
5809
5908
  }
5909
+ if (options?.onSystemWarning) {
5910
+ config.onSystemWarning = options.onSystemWarning;
5911
+ }
5810
5912
  return config;
5811
5913
  }
5812
5914
  var KSeFClient;
@@ -5836,6 +5938,7 @@ var init_client = __esm({
5836
5938
  init_test_data();
5837
5939
  init_certificate_fetcher();
5838
5940
  init_cryptography_service();
5941
+ init_with_key_rotation_retry();
5839
5942
  init_verification_link_service();
5840
5943
  init_auth_xml_builder();
5841
5944
  init_offline_invoice_workflow();
@@ -5902,11 +6005,14 @@ var init_client = __esm({
5902
6005
  async loginWithToken(token, nip) {
5903
6006
  const challenge = await this.auth.getChallenge();
5904
6007
  await this.crypto.init();
5905
- const encryptedToken = await this.crypto.encryptKsefToken(token, challenge.timestamp);
5906
- const submitResult = await this.auth.submitKsefTokenAuthRequest({
5907
- challenge: challenge.challenge,
5908
- contextIdentifier: { type: "Nip", value: nip },
5909
- encryptedToken: Buffer.from(encryptedToken).toString("base64")
6008
+ const submitResult = await withKeyRotationRetry(this.crypto, async () => {
6009
+ const { encryptedToken, publicKeyId } = await this.crypto.encryptKsefTokenWithKeyId(token, challenge.timestamp);
6010
+ return this.auth.submitKsefTokenAuthRequest({
6011
+ challenge: challenge.challenge,
6012
+ contextIdentifier: { type: "Nip", value: nip },
6013
+ encryptedToken: Buffer.from(encryptedToken).toString("base64"),
6014
+ publicKeyId
6015
+ });
5910
6016
  });
5911
6017
  const authToken = submitResult.authenticationToken.token;
5912
6018
  await this.awaitAuthReady(submitResult.referenceNumber, authToken);
@@ -6284,6 +6390,7 @@ var AuthKsefTokenRequestBuilder = class {
6284
6390
  challenge;
6285
6391
  contextIdentifier;
6286
6392
  encryptedToken;
6393
+ publicKeyId;
6287
6394
  authorizationPolicy;
6288
6395
  withChallenge(challenge) {
6289
6396
  this.challenge = challenge;
@@ -6305,6 +6412,13 @@ var AuthKsefTokenRequestBuilder = class {
6305
6412
  this.encryptedToken = token;
6306
6413
  return this;
6307
6414
  }
6415
+ withPublicKeyId(publicKeyId) {
6416
+ if (!publicKeyId.trim()) {
6417
+ throw KSeFValidationError.fromField("publicKeyId", "Public key id is required");
6418
+ }
6419
+ this.publicKeyId = publicKeyId.trim();
6420
+ return this;
6421
+ }
6308
6422
  withAuthorizationPolicy(policy) {
6309
6423
  this.authorizationPolicy = policy;
6310
6424
  return this;
@@ -6323,6 +6437,7 @@ var AuthKsefTokenRequestBuilder = class {
6323
6437
  challenge: this.challenge,
6324
6438
  contextIdentifier: this.contextIdentifier,
6325
6439
  encryptedToken: this.encryptedToken,
6440
+ ...this.publicKeyId && { publicKeyId: this.publicKeyId },
6326
6441
  ...this.authorizationPolicy && { authorizationPolicy: this.authorizationPolicy }
6327
6442
  };
6328
6443
  }
@@ -6628,6 +6743,7 @@ var BatchFileBuilder = class {
6628
6743
  batchFile: {
6629
6744
  fileSize: zipBytes.length,
6630
6745
  fileHash: zipHash,
6746
+ ...options?.compressionType && { compressionType: options.compressionType },
6631
6747
  fileParts
6632
6748
  },
6633
6749
  encryptedParts
@@ -6730,6 +6846,7 @@ var BatchFileBuilder = class {
6730
6846
  batchFile: {
6731
6847
  fileSize: zipSize,
6732
6848
  fileHash: zipMeta.hashSHA,
6849
+ ...options?.compressionType && { compressionType: options.compressionType },
6733
6850
  fileParts
6734
6851
  },
6735
6852
  streamParts
@@ -6909,6 +7026,7 @@ function escapeXml2(str) {
6909
7026
  // src/utils/index.ts
6910
7027
  init_esm_shims();
6911
7028
  init_zip();
7029
+ init_targz();
6912
7030
  init_jwt();
6913
7031
 
6914
7032
  // src/utils/hash.ts
@@ -6952,6 +7070,7 @@ init_auth_manager();
6952
7070
  init_online_session();
6953
7071
  init_session_status();
6954
7072
  init_document_structures();
7073
+ init_with_key_rotation_retry();
6955
7074
 
6956
7075
  // src/xml/index.ts
6957
7076
  init_esm_shims();
@@ -7721,12 +7840,15 @@ function buildSessionHandle(params) {
7721
7840
  }
7722
7841
  async function openOnlineSession(client, options) {
7723
7842
  await client.crypto.init();
7724
- const encData = await client.crypto.getEncryptionData();
7725
7843
  const formCode = options?.formCode ?? DEFAULT_FORM_CODE;
7726
- const openResp = await client.onlineSession.openSession(
7727
- { formCode, encryption: encData.encryptionInfo },
7728
- options?.upoVersion
7729
- );
7844
+ const { encData, openResp } = await withKeyRotationRetry(client.crypto, async () => {
7845
+ const encData2 = await client.crypto.getEncryptionData();
7846
+ const openResp2 = await client.onlineSession.openSession(
7847
+ { formCode, encryption: encData2.encryptionInfo },
7848
+ options?.upoVersion
7849
+ );
7850
+ return { encData: encData2, openResp: openResp2 };
7851
+ });
7730
7852
  return buildSessionHandle({
7731
7853
  deps: {
7732
7854
  crypto: client.crypto,
@@ -7778,17 +7900,17 @@ async function openSendAndClose(client, invoices, options) {
7778
7900
  // src/workflows/batch-session-workflow.ts
7779
7901
  init_esm_shims();
7780
7902
  init_document_structures();
7903
+ init_with_key_rotation_retry();
7781
7904
  async function uploadBatch(client, zipData, options) {
7782
7905
  if (options?.parallelism !== void 0 && (!Number.isInteger(options.parallelism) || options.parallelism < 1)) {
7783
7906
  throw new Error("parallelism must be a positive integer");
7784
7907
  }
7785
7908
  await client.crypto.init();
7786
7909
  if (options?.validate) {
7787
- const { unzip: unzip2 } = await Promise.resolve().then(() => (init_zip(), zip_exports));
7788
7910
  const { validateBatch: validateBatch2, batchValidationDetails: batchValidationDetails2 } = await Promise.resolve().then(() => (init_invoice_validator(), invoice_validator_exports));
7789
7911
  const { KSeFValidationError: KSeFValidationError2 } = await Promise.resolve().then(() => (init_ksef_validation_error(), ksef_validation_error_exports));
7790
7912
  const zipBuf = Buffer.isBuffer(zipData) ? zipData : Buffer.from(zipData.buffer, zipData.byteOffset, zipData.byteLength);
7791
- const files = await unzip2(zipBuf);
7913
+ const files = options?.compressionType === "TarGz" ? await (await Promise.resolve().then(() => (init_targz(), targz_exports))).extractTarGz(zipBuf) : await (await Promise.resolve().then(() => (init_zip(), zip_exports))).unzip(zipBuf);
7792
7914
  const invoices = [...files.entries()].filter(([name]) => name.endsWith(".xml")).map(([name, data]) => ({ fileName: name, xml: data.toString("utf-8") }));
7793
7915
  if (invoices.length > 0) {
7794
7916
  const result2 = await validateBatch2(invoices);
@@ -7801,21 +7923,25 @@ async function uploadBatch(client, zipData, options) {
7801
7923
  }
7802
7924
  }
7803
7925
  }
7804
- const encData = await client.crypto.getEncryptionData();
7805
7926
  const formCode = options?.formCode ?? DEFAULT_FORM_CODE;
7806
- const encryptFn = (part) => client.crypto.encryptAES256(part, encData.cipherKey, encData.cipherIv);
7807
- const { batchFile, encryptedParts } = BatchFileBuilder.build(zipData, encryptFn, {
7808
- maxPartSize: options?.maxPartSize
7927
+ const { batchFile, encryptedParts, openResp } = await withKeyRotationRetry(client.crypto, async () => {
7928
+ const encData = await client.crypto.getEncryptionData();
7929
+ const encryptFn = (part) => client.crypto.encryptAES256(part, encData.cipherKey, encData.cipherIv);
7930
+ const { batchFile: batchFile2, encryptedParts: encryptedParts2 } = BatchFileBuilder.build(zipData, encryptFn, {
7931
+ maxPartSize: options?.maxPartSize,
7932
+ compressionType: options?.compressionType
7933
+ });
7934
+ const openResp2 = await client.batchSession.openSession(
7935
+ {
7936
+ formCode,
7937
+ encryption: encData.encryptionInfo,
7938
+ batchFile: batchFile2,
7939
+ offlineMode: options?.offlineMode
7940
+ },
7941
+ options?.upoVersion
7942
+ );
7943
+ return { batchFile: batchFile2, encryptedParts: encryptedParts2, openResp: openResp2 };
7809
7944
  });
7810
- const openResp = await client.batchSession.openSession(
7811
- {
7812
- formCode,
7813
- encryption: encData.encryptionInfo,
7814
- batchFile,
7815
- offlineMode: options?.offlineMode
7816
- },
7817
- options?.upoVersion
7818
- );
7819
7945
  const sendingParts = encryptedParts.map((part, i) => ({
7820
7946
  data: part.buffer.slice(part.byteOffset, part.byteOffset + part.byteLength),
7821
7947
  metadata: {
@@ -7849,26 +7975,29 @@ async function uploadBatchStream(client, zipStreamFactory, zipSize, options) {
7849
7975
  throw new Error("parallelism must be a positive integer");
7850
7976
  }
7851
7977
  await client.crypto.init();
7852
- const encData = await client.crypto.getEncryptionData();
7853
7978
  const formCode = options?.formCode ?? DEFAULT_FORM_CODE;
7854
- const encryptStreamFn = (stream) => client.crypto.encryptAES256Stream(stream, encData.cipherKey, encData.cipherIv);
7855
- const hashStreamFn = (stream) => client.crypto.getFileMetadataFromStream(stream);
7856
- const { batchFile, streamParts } = await BatchFileBuilder.buildFromStream(
7857
- zipStreamFactory,
7858
- zipSize,
7859
- encryptStreamFn,
7860
- hashStreamFn,
7861
- { maxPartSize: options?.maxPartSize }
7862
- );
7863
- const openResp = await client.batchSession.openSession(
7864
- {
7865
- formCode,
7866
- encryption: encData.encryptionInfo,
7867
- batchFile,
7868
- offlineMode: options?.offlineMode
7869
- },
7870
- options?.upoVersion
7871
- );
7979
+ const { streamParts, openResp } = await withKeyRotationRetry(client.crypto, async () => {
7980
+ const encData = await client.crypto.getEncryptionData();
7981
+ const encryptStreamFn = (stream) => client.crypto.encryptAES256Stream(stream, encData.cipherKey, encData.cipherIv);
7982
+ const hashStreamFn = (stream) => client.crypto.getFileMetadataFromStream(stream);
7983
+ const { batchFile, streamParts: streamParts2 } = await BatchFileBuilder.buildFromStream(
7984
+ zipStreamFactory,
7985
+ zipSize,
7986
+ encryptStreamFn,
7987
+ hashStreamFn,
7988
+ { maxPartSize: options?.maxPartSize, compressionType: options?.compressionType }
7989
+ );
7990
+ const openResp2 = await client.batchSession.openSession(
7991
+ {
7992
+ formCode,
7993
+ encryption: encData.encryptionInfo,
7994
+ batchFile,
7995
+ offlineMode: options?.offlineMode
7996
+ },
7997
+ options?.upoVersion
7998
+ );
7999
+ return { streamParts: streamParts2, openResp: openResp2 };
8000
+ });
7872
8001
  await client.batchSession.sendPartsWithStream(openResp, streamParts, options?.parallelism);
7873
8002
  await client.batchSession.closeSession(openResp.referenceNumber);
7874
8003
  const result = await pollUntil(
@@ -7917,13 +8046,19 @@ async function uploadBatchParsed(client, zipData, options) {
7917
8046
  // src/workflows/invoice-export-workflow.ts
7918
8047
  init_esm_shims();
7919
8048
  init_zip();
8049
+ init_targz();
8050
+ init_with_key_rotation_retry();
7920
8051
  async function doExport(client, filters, options) {
7921
8052
  await client.crypto.init();
7922
- const encData = await client.crypto.getEncryptionData();
7923
- const opResp = await client.invoices.exportInvoices({
7924
- encryption: encData.encryptionInfo,
7925
- filters,
7926
- onlyMetadata: options?.onlyMetadata
8053
+ const { encData, opResp } = await withKeyRotationRetry(client.crypto, async () => {
8054
+ const encData2 = await client.crypto.getEncryptionData();
8055
+ const opResp2 = await client.invoices.exportInvoices({
8056
+ encryption: encData2.encryptionInfo,
8057
+ filters,
8058
+ onlyMetadata: options?.onlyMetadata,
8059
+ ...options?.compressionType && { compressionType: options.compressionType }
8060
+ });
8061
+ return { encData: encData2, opResp: opResp2 };
7927
8062
  });
7928
8063
  const result = await pollUntil(
7929
8064
  () => client.invoices.getInvoiceExportStatus(opResp.referenceNumber),
@@ -7978,8 +8113,8 @@ async function exportAndDownload(client, filters, options) {
7978
8113
  decryptedParts.push(decrypted);
7979
8114
  }
7980
8115
  if (options?.extract) {
7981
- const zipBuffer = Buffer.concat(decryptedParts);
7982
- const files = await unzip(zipBuffer, options.unzipOptions);
8116
+ const archiveBuffer = Buffer.concat(decryptedParts);
8117
+ const files = options.compressionType === "TarGz" ? await extractTarGz(archiveBuffer, options.unzipOptions) : await unzip(archiveBuffer, options.unzipOptions);
7983
8118
  return { ...exportResult, files };
7984
8119
  }
7985
8120
  return {
@@ -8124,22 +8259,24 @@ var FileHwmStore = class {
8124
8259
  // src/workflows/auth-workflow.ts
8125
8260
  init_esm_shims();
8126
8261
  init_auth_xml_builder();
8127
- async function authenticateWithToken(client, options) {
8128
- const challenge = await client.auth.getChallenge();
8129
- await client.crypto.init();
8130
- const encryptedToken = await client.crypto.encryptKsefToken(options.token, challenge.timestamp);
8131
- const submitResult = await client.auth.submitKsefTokenAuthRequest({
8132
- challenge: challenge.challenge,
8133
- contextIdentifier: { type: "Nip", value: options.nip },
8134
- encryptedToken: Buffer.from(encryptedToken).toString("base64"),
8135
- authorizationPolicy: options.authorizationPolicy
8136
- });
8137
- const authToken = submitResult.authenticationToken.token;
8138
- await pollUntil(
8139
- () => client.auth.getAuthStatus(submitResult.referenceNumber, authToken),
8140
- (s) => s.status.code !== 100,
8141
- { ...options.pollOptions, description: `auth ${submitResult.referenceNumber}` }
8262
+ init_with_key_rotation_retry();
8263
+ init_ksef_auth_status_error();
8264
+ var AUTH_STATUS_SUCCESS = 200;
8265
+ var AUTH_STATUS_IN_PROGRESS = 100;
8266
+ async function awaitAuthentication(client, referenceNumber, authToken, pollOptions) {
8267
+ const final = await pollUntil(
8268
+ () => client.auth.getAuthStatus(referenceNumber, authToken),
8269
+ (s) => s.status.code !== AUTH_STATUS_IN_PROGRESS,
8270
+ { ...pollOptions, description: `auth ${referenceNumber}` }
8142
8271
  );
8272
+ if (final.status.code !== AUTH_STATUS_SUCCESS) {
8273
+ const details = final.status.details?.length ? ` (${final.status.details.join("; ")})` : "";
8274
+ throw new KSeFAuthStatusError(
8275
+ `Authentication failed with status ${final.status.code}: ${final.status.description}${details}`,
8276
+ referenceNumber,
8277
+ final.status.description
8278
+ );
8279
+ }
8143
8280
  const tokens = await client.auth.getAccessToken(authToken);
8144
8281
  client.authManager.setAccessToken(tokens.accessToken.token);
8145
8282
  client.authManager.setRefreshToken(tokens.refreshToken.token);
@@ -8150,6 +8287,22 @@ async function authenticateWithToken(client, options) {
8150
8287
  refreshTokenValidUntil: tokens.refreshToken.validUntil
8151
8288
  };
8152
8289
  }
8290
+ async function authenticateWithToken(client, options) {
8291
+ const challenge = await client.auth.getChallenge();
8292
+ await client.crypto.init();
8293
+ const submitResult = await withKeyRotationRetry(client.crypto, async () => {
8294
+ const { encryptedToken, publicKeyId } = await client.crypto.encryptKsefTokenWithKeyId(options.token, challenge.timestamp);
8295
+ return client.auth.submitKsefTokenAuthRequest({
8296
+ challenge: challenge.challenge,
8297
+ contextIdentifier: { type: "Nip", value: options.nip },
8298
+ encryptedToken: Buffer.from(encryptedToken).toString("base64"),
8299
+ publicKeyId,
8300
+ authorizationPolicy: options.authorizationPolicy
8301
+ });
8302
+ });
8303
+ const authToken = submitResult.authenticationToken.token;
8304
+ return awaitAuthentication(client, submitResult.referenceNumber, authToken, options.pollOptions);
8305
+ }
8153
8306
  async function authenticateWithCertificate(client, options) {
8154
8307
  const challenge = await client.auth.getChallenge();
8155
8308
  const { buildAuthTokenRequestXml: buildAuthTokenRequestXml2 } = await Promise.resolve().then(() => (init_client(), client_exports));
@@ -8162,20 +8315,7 @@ async function authenticateWithCertificate(client, options) {
8162
8315
  options.enforceXadesCompliance ?? false
8163
8316
  );
8164
8317
  const authToken = submitResult.authenticationToken.token;
8165
- await pollUntil(
8166
- () => client.auth.getAuthStatus(submitResult.referenceNumber, authToken),
8167
- (s) => s.status.code !== 100,
8168
- { ...options.pollOptions, description: `auth ${submitResult.referenceNumber}` }
8169
- );
8170
- const tokens = await client.auth.getAccessToken(authToken);
8171
- client.authManager.setAccessToken(tokens.accessToken.token);
8172
- client.authManager.setRefreshToken(tokens.refreshToken.token);
8173
- return {
8174
- accessToken: tokens.accessToken.token,
8175
- accessTokenValidUntil: tokens.accessToken.validUntil,
8176
- refreshToken: tokens.refreshToken.token,
8177
- refreshTokenValidUntil: tokens.refreshToken.validUntil
8178
- };
8318
+ return awaitAuthentication(client, submitResult.referenceNumber, authToken, options.pollOptions);
8179
8319
  }
8180
8320
  async function authenticateWithExternalSignature(client, options) {
8181
8321
  const challenge = await client.auth.getChallenge();
@@ -8190,20 +8330,7 @@ async function authenticateWithExternalSignature(client, options) {
8190
8330
  options.enforceXadesCompliance ?? false
8191
8331
  );
8192
8332
  const authToken = submitResult.authenticationToken.token;
8193
- await pollUntil(
8194
- () => client.auth.getAuthStatus(submitResult.referenceNumber, authToken),
8195
- (s) => s.status.code !== 100,
8196
- { ...options.pollOptions, description: `auth ${submitResult.referenceNumber}` }
8197
- );
8198
- const tokens = await client.auth.getAccessToken(authToken);
8199
- client.authManager.setAccessToken(tokens.accessToken.token);
8200
- client.authManager.setRefreshToken(tokens.refreshToken.token);
8201
- return {
8202
- accessToken: tokens.accessToken.token,
8203
- accessTokenValidUntil: tokens.accessToken.validUntil,
8204
- refreshToken: tokens.refreshToken.token,
8205
- refreshTokenValidUntil: tokens.refreshToken.validUntil
8206
- };
8333
+ return awaitAuthentication(client, submitResult.referenceNumber, authToken, options.pollOptions);
8207
8334
  }
8208
8335
  async function authenticateWithPkcs12(client, options) {
8209
8336
  const { Pkcs12Loader: Pkcs12Loader2 } = await Promise.resolve().then(() => (init_pkcs12_loader(), pkcs12_loader_exports));
@@ -8218,6 +8345,95 @@ async function authenticateWithPkcs12(client, options) {
8218
8345
  });
8219
8346
  }
8220
8347
 
8348
+ // src/workflows/metadata-query-paging.ts
8349
+ init_esm_shims();
8350
+ init_ksef_metadata_pagination_error();
8351
+ init_ksef_validation_error();
8352
+ var DEFAULT_PAGE_SIZE = 100;
8353
+ var DEFAULT_MAX_BOUNDARY_CROSSINGS = 1e3;
8354
+ function boundaryFieldFor(dateType) {
8355
+ switch (dateType) {
8356
+ case "Issue":
8357
+ return "issueDate";
8358
+ case "Invoicing":
8359
+ return "invoicingDate";
8360
+ case "PermanentStorage":
8361
+ return "permanentStorageDate";
8362
+ }
8363
+ }
8364
+ async function* queryAllInvoiceMetadata(client, filters, options = {}) {
8365
+ const sortOrder = options.sortOrder ?? "Asc";
8366
+ const pageSize = options.pageSize ?? DEFAULT_PAGE_SIZE;
8367
+ const maxBoundaryCrossings = options.maxBoundaryCrossings ?? DEFAULT_MAX_BOUNDARY_CROSSINGS;
8368
+ if (!Number.isInteger(pageSize) || pageSize <= 0) {
8369
+ throw new KSeFValidationError("`pageSize` must be a positive integer.");
8370
+ }
8371
+ if (!Number.isInteger(maxBoundaryCrossings) || maxBoundaryCrossings < 0) {
8372
+ throw new KSeFValidationError("`maxBoundaryCrossings` must be a non-negative integer.");
8373
+ }
8374
+ const boundaryField = boundaryFieldFor(filters.dateRange.dateType);
8375
+ let dateRange = { ...filters.dateRange };
8376
+ let boundaryCrossings = 0;
8377
+ let carryKeys = /* @__PURE__ */ new Set();
8378
+ let carryValue;
8379
+ for (; ; ) {
8380
+ let pageIndex = 0;
8381
+ let lastBoundaryValue;
8382
+ let isTruncated = false;
8383
+ let boundaryKeys = /* @__PURE__ */ new Set();
8384
+ for (; ; ) {
8385
+ const window = { ...filters, dateRange };
8386
+ const response = await client.invoices.queryInvoiceMetadata(
8387
+ window,
8388
+ pageIndex,
8389
+ pageSize,
8390
+ sortOrder
8391
+ );
8392
+ isTruncated = response.isTruncated;
8393
+ for (const invoice of response.invoices) {
8394
+ const boundaryValue = invoice[boundaryField];
8395
+ const key = invoice.ksefNumber.toLowerCase();
8396
+ if (boundaryValue === carryValue && carryKeys.has(key)) continue;
8397
+ if (boundaryValue !== lastBoundaryValue) {
8398
+ lastBoundaryValue = boundaryValue;
8399
+ boundaryKeys = /* @__PURE__ */ new Set();
8400
+ }
8401
+ boundaryKeys.add(key);
8402
+ yield invoice;
8403
+ }
8404
+ if (response.hasMore) {
8405
+ pageIndex += 1;
8406
+ continue;
8407
+ }
8408
+ break;
8409
+ }
8410
+ if (!isTruncated || lastBoundaryValue === void 0) return;
8411
+ const previousBoundary = sortOrder === "Asc" ? dateRange.from : dateRange.to;
8412
+ if (previousBoundary === lastBoundaryValue) {
8413
+ throw new KSeFMetadataPaginationError(
8414
+ `Metadata paging stalled: a truncated window did not advance past ${boundaryField}=${lastBoundaryValue}. The result set likely exceeds the server cap within a single ${boundaryField} value; narrow the query further.`,
8415
+ lastBoundaryValue
8416
+ );
8417
+ }
8418
+ if (++boundaryCrossings > maxBoundaryCrossings) {
8419
+ throw new KSeFMetadataPaginationError(
8420
+ `Metadata paging exceeded ${maxBoundaryCrossings} truncation boundaries; aborting to avoid an unbounded loop.`,
8421
+ lastBoundaryValue
8422
+ );
8423
+ }
8424
+ carryKeys = boundaryKeys;
8425
+ carryValue = lastBoundaryValue;
8426
+ dateRange = sortOrder === "Asc" ? { ...dateRange, from: lastBoundaryValue } : { ...dateRange, to: lastBoundaryValue };
8427
+ }
8428
+ }
8429
+ async function collectAllInvoiceMetadata(client, filters, options = {}) {
8430
+ const all = [];
8431
+ for await (const invoice of queryAllInvoiceMetadata(client, filters, options)) {
8432
+ all.push(invoice);
8433
+ }
8434
+ return all;
8435
+ }
8436
+
8221
8437
  // src/offline/index.ts
8222
8438
  init_esm_shims();
8223
8439
  init_deadline();
@@ -8375,6 +8591,7 @@ export {
8375
8591
  CertificateFetcher,
8376
8592
  CertificateFingerprint,
8377
8593
  CertificateName,
8594
+ CertificateSerialNumber,
8378
8595
  CertificateService,
8379
8596
  CircuitBreakerPolicy,
8380
8597
  CryptographyService,
@@ -8411,9 +8628,11 @@ export {
8411
8628
  KSeFErrorCode,
8412
8629
  KSeFForbiddenError,
8413
8630
  KSeFGoneError,
8631
+ KSeFMetadataPaginationError,
8414
8632
  KSeFRateLimitError,
8415
8633
  KSeFSessionExpiredError,
8416
8634
  KSeFUnauthorizedError,
8635
+ KSeFUnknownPublicKeyError,
8417
8636
  KSeFValidationError,
8418
8637
  KSeFXsdValidationError,
8419
8638
  KsefNumber,
@@ -8471,7 +8690,9 @@ export {
8471
8690
  buildXmlFromObject,
8472
8691
  calculateBackoff,
8473
8692
  calculateOfflineDeadline,
8693
+ collectAllInvoiceMetadata,
8474
8694
  comparePKey,
8695
+ createTarGz,
8475
8696
  createZip,
8476
8697
  decodeJwtPayload,
8477
8698
  deduplicateByKsefNumber,
@@ -8484,6 +8705,7 @@ export {
8484
8705
  exportInvoices,
8485
8706
  extendDeadlineForMaintenance,
8486
8707
  extractInvoiceFields,
8708
+ extractTarGz,
8487
8709
  getDefaultReason,
8488
8710
  getEffectiveStartDate,
8489
8711
  getFormCode,
@@ -8501,6 +8723,7 @@ export {
8501
8723
  isValidBase64,
8502
8724
  isValidCertificateFingerprint,
8503
8725
  isValidCertificateName,
8726
+ isValidCertificateSerialNumber,
8504
8727
  isValidInternalId,
8505
8728
  isValidIp4Address,
8506
8729
  isValidKsefNumber,
@@ -8524,6 +8747,7 @@ export {
8524
8747
  parseUpoXml,
8525
8748
  parseXml,
8526
8749
  pollUntil,
8750
+ queryAllInvoiceMetadata,
8527
8751
  resolveOptions,
8528
8752
  resolveXsdFor,
8529
8753
  resumeOnlineSession,