ksef-client-ts 0.8.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -412,7 +412,9 @@ var init_error_codes = __esm({
412
412
  init_cjs_shims();
413
413
  KSeFErrorCode = {
414
414
  BatchTimeout: 21208,
415
- DuplicateInvoice: 440
415
+ DuplicateInvoice: 440,
416
+ /** The supplied public key identifier is unknown or points to a revoked key (KSeF API v2.5.0). */
417
+ UnknownPublicKeyId: 21470
416
418
  };
417
419
  }
418
420
  });
@@ -442,6 +444,38 @@ var init_ksef_batch_timeout_error = __esm({
442
444
  }
443
445
  });
444
446
 
447
+ // src/errors/ksef-unknown-public-key-error.ts
448
+ function messageOf(description) {
449
+ return description?.trim() || "The supplied public key identifier is unknown or revoked (KSeF 21470).";
450
+ }
451
+ var KSeFUnknownPublicKeyError;
452
+ var init_ksef_unknown_public_key_error = __esm({
453
+ "src/errors/ksef-unknown-public-key-error.ts"() {
454
+ "use strict";
455
+ init_cjs_shims();
456
+ init_ksef_api_error();
457
+ init_error_codes();
458
+ KSeFUnknownPublicKeyError = class _KSeFUnknownPublicKeyError extends KSeFApiError {
459
+ statusCode = 400;
460
+ errorCode = KSeFErrorCode.UnknownPublicKeyId;
461
+ constructor(message, errorResponse) {
462
+ super(message, 400, errorResponse);
463
+ this.name = "KSeFUnknownPublicKeyError";
464
+ }
465
+ static fromLegacy(body) {
466
+ const detail = body?.exception?.exceptionDetailList?.find(
467
+ (d) => d.exceptionCode === KSeFErrorCode.UnknownPublicKeyId
468
+ );
469
+ return new _KSeFUnknownPublicKeyError(messageOf(detail?.exceptionDescription), body);
470
+ }
471
+ static fromProblem(problem) {
472
+ const detail = problem.errors?.find((e) => e.code === KSeFErrorCode.UnknownPublicKeyId);
473
+ return new _KSeFUnknownPublicKeyError(messageOf(detail?.description || problem.detail));
474
+ }
475
+ };
476
+ }
477
+ });
478
+
445
479
  // src/errors/ksef-circuit-open-error.ts
446
480
  var KSeFCircuitOpenError;
447
481
  var init_ksef_circuit_open_error = __esm({
@@ -515,6 +549,7 @@ var init_errors = __esm({
515
549
  init_ksef_session_expired_error();
516
550
  init_ksef_validation_error();
517
551
  init_ksef_batch_timeout_error();
552
+ init_ksef_unknown_public_key_error();
518
553
  init_ksef_circuit_open_error();
519
554
  init_ksef_xsd_validation_error();
520
555
  init_error_codes();
@@ -805,6 +840,7 @@ var init_rest_client = __esm({
805
840
  init_ksef_gone_error();
806
841
  init_ksef_bad_request_error();
807
842
  init_ksef_batch_timeout_error();
843
+ init_ksef_unknown_public_key_error();
808
844
  init_error_codes();
809
845
  init_route_builder();
810
846
  init_transport();
@@ -819,6 +855,7 @@ var init_rest_client = __esm({
819
855
  circuitBreakerPolicy;
820
856
  authManager;
821
857
  presignedUrlPolicy;
858
+ onSystemWarning;
822
859
  constructor(options, config) {
823
860
  this.options = options;
824
861
  this.routeBuilder = new RouteBuilder(options.apiVersion);
@@ -828,23 +865,41 @@ var init_rest_client = __esm({
828
865
  this.circuitBreakerPolicy = config?.circuitBreakerPolicy ?? null;
829
866
  this.authManager = config?.authManager;
830
867
  this.presignedUrlPolicy = config?.presignedUrlPolicy;
868
+ this.onSystemWarning = config?.onSystemWarning;
831
869
  }
832
870
  async execute(request) {
833
871
  const response = await this.sendRequest(request);
834
872
  await this.ensureSuccess(response);
873
+ this.handleSystemWarning(response);
835
874
  const body = await response.json();
836
875
  return { body, headers: response.headers, statusCode: response.status };
837
876
  }
838
877
  async executeVoid(request) {
839
878
  const response = await this.sendRequest(request);
840
879
  await this.ensureSuccess(response);
880
+ this.handleSystemWarning(response);
841
881
  }
842
882
  async executeRaw(request) {
843
883
  const response = await this.sendRequest(request);
844
884
  await this.ensureSuccess(response);
885
+ this.handleSystemWarning(response);
845
886
  const body = await response.arrayBuffer();
846
887
  return { body, headers: response.headers, statusCode: response.status };
847
888
  }
889
+ /** Surface the optional `X-System-Warning` response header (KSeF API v2.6.0). */
890
+ handleSystemWarning(response) {
891
+ const warning = response.headers.get("x-system-warning");
892
+ if (!warning) return;
893
+ if (this.onSystemWarning) {
894
+ try {
895
+ this.onSystemWarning(warning);
896
+ } catch (error) {
897
+ import_consola.consola.warn("onSystemWarning callback threw an exception (ignored):", error);
898
+ }
899
+ } else {
900
+ import_consola.consola.warn(`KSeF system warning: ${warning}`);
901
+ }
902
+ }
848
903
  async sendRequest(request) {
849
904
  const url = this.buildUrl(request);
850
905
  if (request.isPresigned() && this.presignedUrlPolicy) {
@@ -986,9 +1041,15 @@ var init_rest_client = __esm({
986
1041
  if (response.status === 400) {
987
1042
  const problem = tryParseProblem(isBadRequestProblem);
988
1043
  if (problem) {
1044
+ if (problem.errors?.some((e) => e.code === KSeFErrorCode.UnknownPublicKeyId)) {
1045
+ throw KSeFUnknownPublicKeyError.fromProblem(problem);
1046
+ }
989
1047
  throw new KSeFBadRequestError(problem);
990
1048
  }
991
1049
  const legacy = parseJson();
1050
+ if (hasErrorCode(legacy, KSeFErrorCode.UnknownPublicKeyId)) {
1051
+ throw KSeFUnknownPublicKeyError.fromLegacy(legacy);
1052
+ }
992
1053
  if (hasErrorCode(legacy, KSeFErrorCode.BatchTimeout)) {
993
1054
  throw KSeFBatchTimeoutError.fromResponse(400, legacy);
994
1055
  }
@@ -2449,14 +2510,14 @@ var init_fa2 = __esm({
2449
2510
  }
2450
2511
  });
2451
2512
 
2452
- // src/validation/schemas/rr1-v11e.ts
2453
- var rr1_v11e_exports = {};
2454
- __export(rr1_v11e_exports, {
2455
- RR1_V11ESchema: () => RR1_V11ESchema
2513
+ // src/validation/schemas/fa-rr1.ts
2514
+ var fa_rr1_exports = {};
2515
+ __export(fa_rr1_exports, {
2516
+ FA_RR1Schema: () => FA_RR1Schema
2456
2517
  });
2457
- var import_zod3, 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;
2458
- var init_rr1_v11e = __esm({
2459
- "src/validation/schemas/rr1-v11e.ts"() {
2518
+ var import_zod3, 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;
2519
+ var init_fa_rr1 = __esm({
2520
+ "src/validation/schemas/fa-rr1.ts"() {
2460
2521
  "use strict";
2461
2522
  init_cjs_shims();
2462
2523
  import_zod3 = require("zod");
@@ -2526,7 +2587,7 @@ var init_rr1_v11e = __esm({
2526
2587
  TTekstowy3 = import_zod3.z.string().min(1).max(3500);
2527
2588
  TNrKRS3 = import_zod3.z.string().regex(/^\d{10}$/);
2528
2589
  TNrREGON3 = import_zod3.z.union([import_zod3.z.string().regex(/^\d{9}$/), import_zod3.z.string().regex(/^\d{14}$/)]);
2529
- RR1_V11ESchema = import_zod3.z.object({
2590
+ FA_RR1Schema = import_zod3.z.object({
2530
2591
  "Naglowek": TNaglowek3,
2531
2592
  "Podmiot1": import_zod3.z.object({
2532
2593
  "DaneIdentyfikacyjne": TPodmiot13,
@@ -2655,224 +2716,89 @@ var init_rr1_v11e = __esm({
2655
2716
  }
2656
2717
  });
2657
2718
 
2658
- // src/validation/schemas/rr1-v10e.ts
2659
- var rr1_v10e_exports = {};
2660
- __export(rr1_v10e_exports, {
2661
- RR1_V10ESchema: () => RR1_V10ESchema
2719
+ // src/validation/schemas/pef3.ts
2720
+ var pef3_exports = {};
2721
+ __export(pef3_exports, {
2722
+ PEF3Schema: () => PEF3Schema
2662
2723
  });
2663
- var import_zod4, 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;
2664
- var init_rr1_v10e = __esm({
2665
- "src/validation/schemas/rr1-v10e.ts"() {
2724
+ var import_zod4, InvoiceType, PEF3Schema;
2725
+ var init_pef3 = __esm({
2726
+ "src/validation/schemas/pef3.ts"() {
2666
2727
  "use strict";
2667
2728
  init_cjs_shims();
2668
2729
  import_zod4 = require("zod");
2669
- TKodFormularza4 = import_zod4.z.literal("FA_RR");
2670
- TDataCzas4 = import_zod4.z.string();
2671
- TZnakowy5 = import_zod4.z.string().min(1).max(256);
2672
- TNaglowek4 = import_zod4.z.object({
2673
- "KodFormularza": import_zod4.z.object({ "#text": TKodFormularza4, "@kodSystemowy": import_zod4.z.literal("FA_RR(1)"), "@wersjaSchemy": import_zod4.z.literal("1-0E") }).strict(),
2674
- "WariantFormularza": import_zod4.z.literal("1"),
2675
- "DataWytworzeniaFa": import_zod4.z.string(),
2676
- "SystemInfo": TZnakowy5.optional()
2677
- }).strict();
2678
- TNrNIP4 = import_zod4.z.string().regex(/^[1-9]((\d[1-9])|([1-9]\d))\d{7}$/);
2679
- TZnakowy5124 = import_zod4.z.string().min(1).max(512);
2680
- TPodmiot14 = import_zod4.z.object({
2681
- "NIP": TNrNIP4,
2682
- "Nazwa": TZnakowy5124
2683
- }).strict();
2684
- TKodKraju4 = import_zod4.z.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"]);
2685
- TGLN4 = import_zod4.z.string().min(1).max(13);
2686
- TAdres4 = import_zod4.z.object({
2687
- "KodKraju": TKodKraju4,
2688
- "AdresL1": TZnakowy5124,
2689
- "AdresL2": TZnakowy5124.optional(),
2690
- "GLN": TGLN4.optional()
2691
- }).strict();
2692
- TAdresEmail4 = import_zod4.z.string().min(3).max(255).regex(/^(.)+@(.)+$/);
2693
- TNumerTelefonu4 = import_zod4.z.string().min(1).max(16);
2694
- TStatusInfoPodatnika4 = import_zod4.z.enum(["1", "2", "3", "4"]);
2695
- TZnakowy204 = import_zod4.z.string().min(1).max(20);
2696
- TNIPIdWew4 = import_zod4.z.string().min(1).max(20).regex(/^[1-9]((\d[1-9])|([1-9]\d))\d{7}-\d{5}$/);
2697
- TWybor14 = import_zod4.z.literal("1");
2698
- TPodmiot34 = import_zod4.z.object({
2699
- "NIP": TNrNIP4.optional(),
2700
- "IDWew": TNIPIdWew4.optional(),
2701
- "BrakID": TWybor14.optional(),
2702
- "Nazwa": TZnakowy5124
2703
- }).strict();
2704
- TRolaPodmiotu34 = import_zod4.z.enum(["1", "2", "3", "5", "6", "7", "8", "9", "10", "11"]);
2705
- TKodWaluty4 = import_zod4.z.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"]);
2706
- TData4 = import_zod4.z.string();
2707
- TDataT4 = import_zod4.z.string();
2708
- TKwotowy5 = import_zod4.z.string().regex(/^-?([1-9]\d{0,15}|0)(\.\d{1,2})?$/);
2709
- TRodzajFaktury4 = import_zod4.z.enum(["VAT_RR", "KOR_VAT_RR"]);
2710
- TTypKorekty4 = import_zod4.z.enum(["1", "2", "3", "4"]);
2711
- TNumerKSeF4 = import_zod4.z.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})$/);
2712
- TNaturalny4 = import_zod4.z.string();
2713
- TKluczWartosc4 = import_zod4.z.object({
2714
- "NrWiersza": TNaturalny4.optional(),
2715
- "Klucz": TZnakowy5,
2716
- "Wartosc": TZnakowy5
2717
- }).strict();
2718
- TZnakowy504 = import_zod4.z.string().min(1).max(50);
2719
- TIlosci4 = import_zod4.z.string().regex(/^-?([1-9]\d{0,15}|0)(\.\d{1,6})?$/);
2720
- TKwotowy24 = import_zod4.z.string().regex(/^-?([1-9]\d{0,13}|0)(\.\d{1,8})?$/);
2721
- TProcentowy4 = import_zod4.z.coerce.number().min(0).max(100);
2722
- TStawkaPodatku4 = import_zod4.z.enum(["6.5", "7"]);
2723
- TFormaPlatnosci4 = import_zod4.z.literal("1");
2724
- TNrRB4 = import_zod4.z.string().min(10).max(34);
2725
- SWIFT_Type4 = import_zod4.z.string().regex(/^[A-Z]{6}[A-Z0-9]{2}([A-Z0-9]{3}){0,1}$/);
2726
- TRachunekBankowy4 = import_zod4.z.object({
2727
- "NrRB": TNrRB4,
2728
- "SWIFT": SWIFT_Type4.optional(),
2729
- "NazwaBanku": TZnakowy5.optional(),
2730
- "OpisRachunku": TZnakowy5.optional()
2731
- }).strict();
2732
- TTekstowy4 = import_zod4.z.string().min(1).max(3500);
2733
- TNrKRS4 = import_zod4.z.string().regex(/^\d{10}$/);
2734
- TNrREGON4 = import_zod4.z.union([import_zod4.z.string().regex(/^\d{9}$/), import_zod4.z.string().regex(/^\d{14}$/)]);
2735
- RR1_V10ESchema = import_zod4.z.object({
2736
- "Naglowek": TNaglowek4,
2737
- "Podmiot1": import_zod4.z.object({
2738
- "DaneIdentyfikacyjne": TPodmiot14,
2739
- "Adres": TAdres4,
2740
- "AdresKoresp": TAdres4.optional(),
2741
- "DaneKontaktowe": import_zod4.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod4.z.array(import_zod4.z.object({
2742
- "Email": TAdresEmail4.optional(),
2743
- "Telefon": TNumerTelefonu4.optional()
2744
- }).strict()).min(0).max(3)).optional(),
2745
- "NrKontrahenta": TZnakowy5.optional()
2746
- }).strict(),
2747
- "Podmiot2": import_zod4.z.object({
2748
- "DaneIdentyfikacyjne": TPodmiot14,
2749
- "Adres": TAdres4,
2750
- "AdresKoresp": TAdres4.optional(),
2751
- "DaneKontaktowe": import_zod4.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod4.z.array(import_zod4.z.object({
2752
- "Email": TAdresEmail4.optional(),
2753
- "Telefon": TNumerTelefonu4.optional()
2754
- }).strict()).min(0).max(3)).optional(),
2755
- "StatusInfoPodatnika": TStatusInfoPodatnika4.optional()
2756
- }).strict(),
2757
- "Podmiot3": import_zod4.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod4.z.array(import_zod4.z.object({
2758
- "DaneIdentyfikacyjne": TPodmiot34,
2759
- "Adres": TAdres4.optional(),
2760
- "AdresKoresp": TAdres4.optional(),
2761
- "DaneKontaktowe": import_zod4.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod4.z.array(import_zod4.z.object({
2762
- "Email": TAdresEmail4.optional(),
2763
- "Telefon": TNumerTelefonu4.optional()
2764
- }).strict()).min(0).max(3)).optional(),
2765
- "Rola": TRolaPodmiotu34.optional(),
2766
- "RolaInna": TWybor14.optional(),
2767
- "OpisRoli": TZnakowy5.optional()
2768
- }).strict()).min(0).max(100)).optional(),
2769
- "FakturaRR": import_zod4.z.object({
2770
- "KodWaluty": TKodWaluty4,
2771
- "P_1M": TZnakowy5.optional(),
2772
- "P_4A": TDataT4.optional(),
2773
- "P_4B": TDataT4,
2774
- "P_4C": TZnakowy5,
2775
- "P_11_1": TKwotowy5,
2776
- "P_11_1W": TKwotowy5.optional(),
2777
- "P_11_2": TKwotowy5,
2778
- "P_11_2W": TKwotowy5.optional(),
2779
- "P_12_1": TKwotowy5,
2780
- "P_12_1W": TKwotowy5.optional(),
2781
- "P_12_2": TZnakowy5,
2782
- "RodzajFaktury": TRodzajFaktury4,
2783
- "PrzyczynaKorekty": TZnakowy5.optional(),
2784
- "TypKorekty": TTypKorekty4.optional(),
2785
- "DaneFaKorygowanej": import_zod4.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod4.z.array(import_zod4.z.object({
2786
- "DataWystFaKorygowanej": TDataT4,
2787
- "NrFaKorygowanej": TZnakowy5,
2788
- "NrKSeF": TWybor14.optional(),
2789
- "NrKSeFFaKorygowanej": TNumerKSeF4.optional(),
2790
- "NrKSeFN": TWybor14.optional()
2791
- }).strict()).min(1).max(5e4)).optional(),
2792
- "NrFaKorygowany": TZnakowy5.optional(),
2793
- "Podmiot1K": import_zod4.z.object({
2794
- "DaneIdentyfikacyjne": TPodmiot14,
2795
- "Adres": TAdres4
2796
- }).strict().optional(),
2797
- "Podmiot2K": import_zod4.z.object({
2798
- "DaneIdentyfikacyjne": TPodmiot14,
2799
- "Adres": TAdres4
2800
- }).strict().optional(),
2801
- "DokumentZaplaty": import_zod4.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod4.z.array(import_zod4.z.object({
2802
- "NrDokumentu": TZnakowy5,
2803
- "DataDokumentu": TData4.optional()
2804
- }).strict()).min(0).max(50)).optional(),
2805
- "DodatkowyOpis": import_zod4.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod4.z.array(TKluczWartosc4).min(0).max(1e4)).optional(),
2806
- "FakturaRRWiersz": import_zod4.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod4.z.array(import_zod4.z.object({
2807
- "NrWierszaFa": TNaturalny4,
2808
- "UU_ID": TZnakowy504.optional(),
2809
- "P_4AA": TDataT4.optional(),
2810
- "P_5": TZnakowy5,
2811
- "GTIN": TZnakowy204.optional(),
2812
- "PKWiU": TZnakowy504.optional(),
2813
- "CN": TZnakowy504.optional(),
2814
- "P_6A": TZnakowy5,
2815
- "P_6B": TIlosci4,
2816
- "P_6C": TZnakowy5,
2817
- "P_7": TKwotowy24,
2818
- "P_8": TKwotowy5,
2819
- "P_9": TStawkaPodatku4,
2820
- "P_10": TKwotowy5,
2821
- "P_11": TKwotowy5,
2822
- "StanPrzed": TWybor14.optional(),
2823
- "KursWaluty": TIlosci4.optional()
2824
- }).strict()).min(0).max(1e4)).optional(),
2825
- "Rozliczenie": import_zod4.z.object({
2826
- "Obciazenia": import_zod4.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod4.z.array(import_zod4.z.object({
2827
- "Kwota": TKwotowy5,
2828
- "Powod": TZnakowy5
2829
- }).strict()).min(0).max(100)).optional(),
2830
- "SumaObciazen": TKwotowy5.optional(),
2831
- "Odliczenia": import_zod4.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod4.z.array(import_zod4.z.object({
2832
- "Kwota": TKwotowy5,
2833
- "Powod": TZnakowy5
2834
- }).strict()).min(0).max(100)).optional(),
2835
- "SumaOdliczen": TKwotowy5.optional(),
2836
- "DoZaplaty": TKwotowy5.optional(),
2837
- "DoRozliczenia": TKwotowy5.optional()
2838
- }).strict().optional(),
2839
- "Platnosc": import_zod4.z.object({
2840
- "FormaPlatnosci": TFormaPlatnosci4.optional(),
2841
- "PlatnoscInna": TWybor14.optional(),
2842
- "OpisPlatnosci": TZnakowy5.optional(),
2843
- "RachunekBankowy1": import_zod4.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod4.z.array(TRachunekBankowy4).min(0).max(3)).optional(),
2844
- "RachunekBankowy2": import_zod4.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod4.z.array(TRachunekBankowy4).min(0).max(3)).optional(),
2845
- "IPKSeF": import_zod4.z.string().min(1).max(13).regex(/^[0-9]{3}[a-zA-Z0-9]{10}$/).optional(),
2846
- "LinkDoPlatnosci": import_zod4.z.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()
2847
- }).strict().optional()
2848
- }).strict(),
2849
- "Stopka": import_zod4.z.object({
2850
- "Informacje": import_zod4.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod4.z.array(import_zod4.z.object({
2851
- "StopkaFaktury": TTekstowy4.optional()
2852
- }).strict()).min(0).max(3)).optional(),
2853
- "Rejestry": import_zod4.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod4.z.array(import_zod4.z.object({
2854
- "PelnaNazwa": TZnakowy5.optional(),
2855
- "KRS": TNrKRS4.optional(),
2856
- "REGON": TNrREGON4.optional(),
2857
- "BDO": import_zod4.z.string().min(1).max(9).optional()
2858
- }).strict()).min(0).max(100)).optional()
2859
- }).strict().optional()
2730
+ InvoiceType = import_zod4.z.object({
2731
+ "UBLExtensions": import_zod4.z.any().optional(),
2732
+ "UBLVersionID": import_zod4.z.any().optional(),
2733
+ "CustomizationID": import_zod4.z.any().optional(),
2734
+ "ProfileID": import_zod4.z.any().optional(),
2735
+ "ProfileExecutionID": import_zod4.z.any().optional(),
2736
+ "ID": import_zod4.z.any(),
2737
+ "CopyIndicator": import_zod4.z.any().optional(),
2738
+ "UUID": import_zod4.z.any().optional(),
2739
+ "IssueDate": import_zod4.z.any(),
2740
+ "IssueTime": import_zod4.z.any().optional(),
2741
+ "DueDate": import_zod4.z.any().optional(),
2742
+ "InvoiceTypeCode": import_zod4.z.any().optional(),
2743
+ "Note": import_zod4.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod4.z.array(import_zod4.z.any()).min(0)).optional(),
2744
+ "TaxPointDate": import_zod4.z.any().optional(),
2745
+ "DocumentCurrencyCode": import_zod4.z.any().optional(),
2746
+ "TaxCurrencyCode": import_zod4.z.any().optional(),
2747
+ "PricingCurrencyCode": import_zod4.z.any().optional(),
2748
+ "PaymentCurrencyCode": import_zod4.z.any().optional(),
2749
+ "PaymentAlternativeCurrencyCode": import_zod4.z.any().optional(),
2750
+ "AccountingCostCode": import_zod4.z.any().optional(),
2751
+ "AccountingCost": import_zod4.z.any().optional(),
2752
+ "LineCountNumeric": import_zod4.z.any().optional(),
2753
+ "BuyerReference": import_zod4.z.any().optional(),
2754
+ "InvoicePeriod": import_zod4.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod4.z.array(import_zod4.z.any()).min(0)).optional(),
2755
+ "OrderReference": import_zod4.z.any().optional(),
2756
+ "BillingReference": import_zod4.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod4.z.array(import_zod4.z.any()).min(0)).optional(),
2757
+ "DespatchDocumentReference": import_zod4.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod4.z.array(import_zod4.z.any()).min(0)).optional(),
2758
+ "ReceiptDocumentReference": import_zod4.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod4.z.array(import_zod4.z.any()).min(0)).optional(),
2759
+ "StatementDocumentReference": import_zod4.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod4.z.array(import_zod4.z.any()).min(0)).optional(),
2760
+ "OriginatorDocumentReference": import_zod4.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod4.z.array(import_zod4.z.any()).min(0)).optional(),
2761
+ "ContractDocumentReference": import_zod4.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod4.z.array(import_zod4.z.any()).min(0)).optional(),
2762
+ "AdditionalDocumentReference": import_zod4.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod4.z.array(import_zod4.z.any()).min(0)).optional(),
2763
+ "ProjectReference": import_zod4.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod4.z.array(import_zod4.z.any()).min(0)).optional(),
2764
+ "Signature": import_zod4.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod4.z.array(import_zod4.z.any()).min(0)).optional(),
2765
+ "AccountingSupplierParty": import_zod4.z.any(),
2766
+ "AccountingCustomerParty": import_zod4.z.any(),
2767
+ "PayeeParty": import_zod4.z.any().optional(),
2768
+ "BuyerCustomerParty": import_zod4.z.any().optional(),
2769
+ "SellerSupplierParty": import_zod4.z.any().optional(),
2770
+ "TaxRepresentativeParty": import_zod4.z.any().optional(),
2771
+ "Delivery": import_zod4.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod4.z.array(import_zod4.z.any()).min(0)).optional(),
2772
+ "DeliveryTerms": import_zod4.z.any().optional(),
2773
+ "PaymentMeans": import_zod4.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod4.z.array(import_zod4.z.any()).min(0)).optional(),
2774
+ "PaymentTerms": import_zod4.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod4.z.array(import_zod4.z.any()).min(0)).optional(),
2775
+ "PrepaidPayment": import_zod4.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod4.z.array(import_zod4.z.any()).min(0)).optional(),
2776
+ "AllowanceCharge": import_zod4.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod4.z.array(import_zod4.z.any()).min(0)).optional(),
2777
+ "TaxExchangeRate": import_zod4.z.any().optional(),
2778
+ "PricingExchangeRate": import_zod4.z.any().optional(),
2779
+ "PaymentExchangeRate": import_zod4.z.any().optional(),
2780
+ "PaymentAlternativeExchangeRate": import_zod4.z.any().optional(),
2781
+ "TaxTotal": import_zod4.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod4.z.array(import_zod4.z.any()).min(0)).optional(),
2782
+ "WithholdingTaxTotal": import_zod4.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod4.z.array(import_zod4.z.any()).min(0)).optional(),
2783
+ "LegalMonetaryTotal": import_zod4.z.any(),
2784
+ "InvoiceLine": import_zod4.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod4.z.array(import_zod4.z.any()).min(1))
2860
2785
  }).strict();
2786
+ PEF3Schema = InvoiceType;
2861
2787
  }
2862
2788
  });
2863
2789
 
2864
- // src/validation/schemas/pef3.ts
2865
- var pef3_exports = {};
2866
- __export(pef3_exports, {
2867
- PEF3Schema: () => PEF3Schema
2790
+ // src/validation/schemas/pef-kor3.ts
2791
+ var pef_kor3_exports = {};
2792
+ __export(pef_kor3_exports, {
2793
+ PEF_KOR3Schema: () => PEF_KOR3Schema
2868
2794
  });
2869
- var import_zod5, InvoiceType, PEF3Schema;
2870
- var init_pef3 = __esm({
2871
- "src/validation/schemas/pef3.ts"() {
2795
+ var import_zod5, CreditNoteType, PEF_KOR3Schema;
2796
+ var init_pef_kor3 = __esm({
2797
+ "src/validation/schemas/pef-kor3.ts"() {
2872
2798
  "use strict";
2873
2799
  init_cjs_shims();
2874
2800
  import_zod5 = require("zod");
2875
- InvoiceType = import_zod5.z.object({
2801
+ CreditNoteType = import_zod5.z.object({
2876
2802
  "UBLExtensions": import_zod5.z.any().optional(),
2877
2803
  "UBLVersionID": import_zod5.z.any().optional(),
2878
2804
  "CustomizationID": import_zod5.z.any().optional(),
@@ -2883,10 +2809,9 @@ var init_pef3 = __esm({
2883
2809
  "UUID": import_zod5.z.any().optional(),
2884
2810
  "IssueDate": import_zod5.z.any(),
2885
2811
  "IssueTime": import_zod5.z.any().optional(),
2886
- "DueDate": import_zod5.z.any().optional(),
2887
- "InvoiceTypeCode": import_zod5.z.any().optional(),
2888
- "Note": import_zod5.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod5.z.array(import_zod5.z.any()).min(0)).optional(),
2889
2812
  "TaxPointDate": import_zod5.z.any().optional(),
2813
+ "CreditNoteTypeCode": import_zod5.z.any().optional(),
2814
+ "Note": import_zod5.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod5.z.array(import_zod5.z.any()).min(0)).optional(),
2890
2815
  "DocumentCurrencyCode": import_zod5.z.any().optional(),
2891
2816
  "TaxCurrencyCode": import_zod5.z.any().optional(),
2892
2817
  "PricingCurrencyCode": import_zod5.z.any().optional(),
@@ -2897,15 +2822,15 @@ var init_pef3 = __esm({
2897
2822
  "LineCountNumeric": import_zod5.z.any().optional(),
2898
2823
  "BuyerReference": import_zod5.z.any().optional(),
2899
2824
  "InvoicePeriod": import_zod5.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod5.z.array(import_zod5.z.any()).min(0)).optional(),
2825
+ "DiscrepancyResponse": import_zod5.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod5.z.array(import_zod5.z.any()).min(0)).optional(),
2900
2826
  "OrderReference": import_zod5.z.any().optional(),
2901
2827
  "BillingReference": import_zod5.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod5.z.array(import_zod5.z.any()).min(0)).optional(),
2902
2828
  "DespatchDocumentReference": import_zod5.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod5.z.array(import_zod5.z.any()).min(0)).optional(),
2903
2829
  "ReceiptDocumentReference": import_zod5.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod5.z.array(import_zod5.z.any()).min(0)).optional(),
2904
- "StatementDocumentReference": import_zod5.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod5.z.array(import_zod5.z.any()).min(0)).optional(),
2905
- "OriginatorDocumentReference": import_zod5.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod5.z.array(import_zod5.z.any()).min(0)).optional(),
2906
2830
  "ContractDocumentReference": import_zod5.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod5.z.array(import_zod5.z.any()).min(0)).optional(),
2907
2831
  "AdditionalDocumentReference": import_zod5.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod5.z.array(import_zod5.z.any()).min(0)).optional(),
2908
- "ProjectReference": import_zod5.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod5.z.array(import_zod5.z.any()).min(0)).optional(),
2832
+ "StatementDocumentReference": import_zod5.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod5.z.array(import_zod5.z.any()).min(0)).optional(),
2833
+ "OriginatorDocumentReference": import_zod5.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod5.z.array(import_zod5.z.any()).min(0)).optional(),
2909
2834
  "Signature": import_zod5.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod5.z.array(import_zod5.z.any()).min(0)).optional(),
2910
2835
  "AccountingSupplierParty": import_zod5.z.any(),
2911
2836
  "AccountingCustomerParty": import_zod5.z.any(),
@@ -2914,87 +2839,17 @@ var init_pef3 = __esm({
2914
2839
  "SellerSupplierParty": import_zod5.z.any().optional(),
2915
2840
  "TaxRepresentativeParty": import_zod5.z.any().optional(),
2916
2841
  "Delivery": import_zod5.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod5.z.array(import_zod5.z.any()).min(0)).optional(),
2917
- "DeliveryTerms": import_zod5.z.any().optional(),
2842
+ "DeliveryTerms": import_zod5.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod5.z.array(import_zod5.z.any()).min(0)).optional(),
2918
2843
  "PaymentMeans": import_zod5.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod5.z.array(import_zod5.z.any()).min(0)).optional(),
2919
2844
  "PaymentTerms": import_zod5.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod5.z.array(import_zod5.z.any()).min(0)).optional(),
2920
- "PrepaidPayment": import_zod5.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod5.z.array(import_zod5.z.any()).min(0)).optional(),
2921
- "AllowanceCharge": import_zod5.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod5.z.array(import_zod5.z.any()).min(0)).optional(),
2922
2845
  "TaxExchangeRate": import_zod5.z.any().optional(),
2923
2846
  "PricingExchangeRate": import_zod5.z.any().optional(),
2924
2847
  "PaymentExchangeRate": import_zod5.z.any().optional(),
2925
2848
  "PaymentAlternativeExchangeRate": import_zod5.z.any().optional(),
2849
+ "AllowanceCharge": import_zod5.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod5.z.array(import_zod5.z.any()).min(0)).optional(),
2926
2850
  "TaxTotal": import_zod5.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod5.z.array(import_zod5.z.any()).min(0)).optional(),
2927
- "WithholdingTaxTotal": import_zod5.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod5.z.array(import_zod5.z.any()).min(0)).optional(),
2928
2851
  "LegalMonetaryTotal": import_zod5.z.any(),
2929
- "InvoiceLine": import_zod5.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod5.z.array(import_zod5.z.any()).min(1))
2930
- }).strict();
2931
- PEF3Schema = InvoiceType;
2932
- }
2933
- });
2934
-
2935
- // src/validation/schemas/pef-kor3.ts
2936
- var pef_kor3_exports = {};
2937
- __export(pef_kor3_exports, {
2938
- PEF_KOR3Schema: () => PEF_KOR3Schema
2939
- });
2940
- var import_zod6, CreditNoteType, PEF_KOR3Schema;
2941
- var init_pef_kor3 = __esm({
2942
- "src/validation/schemas/pef-kor3.ts"() {
2943
- "use strict";
2944
- init_cjs_shims();
2945
- import_zod6 = require("zod");
2946
- CreditNoteType = import_zod6.z.object({
2947
- "UBLExtensions": import_zod6.z.any().optional(),
2948
- "UBLVersionID": import_zod6.z.any().optional(),
2949
- "CustomizationID": import_zod6.z.any().optional(),
2950
- "ProfileID": import_zod6.z.any().optional(),
2951
- "ProfileExecutionID": import_zod6.z.any().optional(),
2952
- "ID": import_zod6.z.any(),
2953
- "CopyIndicator": import_zod6.z.any().optional(),
2954
- "UUID": import_zod6.z.any().optional(),
2955
- "IssueDate": import_zod6.z.any(),
2956
- "IssueTime": import_zod6.z.any().optional(),
2957
- "TaxPointDate": import_zod6.z.any().optional(),
2958
- "CreditNoteTypeCode": import_zod6.z.any().optional(),
2959
- "Note": import_zod6.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod6.z.array(import_zod6.z.any()).min(0)).optional(),
2960
- "DocumentCurrencyCode": import_zod6.z.any().optional(),
2961
- "TaxCurrencyCode": import_zod6.z.any().optional(),
2962
- "PricingCurrencyCode": import_zod6.z.any().optional(),
2963
- "PaymentCurrencyCode": import_zod6.z.any().optional(),
2964
- "PaymentAlternativeCurrencyCode": import_zod6.z.any().optional(),
2965
- "AccountingCostCode": import_zod6.z.any().optional(),
2966
- "AccountingCost": import_zod6.z.any().optional(),
2967
- "LineCountNumeric": import_zod6.z.any().optional(),
2968
- "BuyerReference": import_zod6.z.any().optional(),
2969
- "InvoicePeriod": import_zod6.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod6.z.array(import_zod6.z.any()).min(0)).optional(),
2970
- "DiscrepancyResponse": import_zod6.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod6.z.array(import_zod6.z.any()).min(0)).optional(),
2971
- "OrderReference": import_zod6.z.any().optional(),
2972
- "BillingReference": import_zod6.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod6.z.array(import_zod6.z.any()).min(0)).optional(),
2973
- "DespatchDocumentReference": import_zod6.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod6.z.array(import_zod6.z.any()).min(0)).optional(),
2974
- "ReceiptDocumentReference": import_zod6.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod6.z.array(import_zod6.z.any()).min(0)).optional(),
2975
- "ContractDocumentReference": import_zod6.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod6.z.array(import_zod6.z.any()).min(0)).optional(),
2976
- "AdditionalDocumentReference": import_zod6.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod6.z.array(import_zod6.z.any()).min(0)).optional(),
2977
- "StatementDocumentReference": import_zod6.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod6.z.array(import_zod6.z.any()).min(0)).optional(),
2978
- "OriginatorDocumentReference": import_zod6.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod6.z.array(import_zod6.z.any()).min(0)).optional(),
2979
- "Signature": import_zod6.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod6.z.array(import_zod6.z.any()).min(0)).optional(),
2980
- "AccountingSupplierParty": import_zod6.z.any(),
2981
- "AccountingCustomerParty": import_zod6.z.any(),
2982
- "PayeeParty": import_zod6.z.any().optional(),
2983
- "BuyerCustomerParty": import_zod6.z.any().optional(),
2984
- "SellerSupplierParty": import_zod6.z.any().optional(),
2985
- "TaxRepresentativeParty": import_zod6.z.any().optional(),
2986
- "Delivery": import_zod6.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod6.z.array(import_zod6.z.any()).min(0)).optional(),
2987
- "DeliveryTerms": import_zod6.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod6.z.array(import_zod6.z.any()).min(0)).optional(),
2988
- "PaymentMeans": import_zod6.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod6.z.array(import_zod6.z.any()).min(0)).optional(),
2989
- "PaymentTerms": import_zod6.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod6.z.array(import_zod6.z.any()).min(0)).optional(),
2990
- "TaxExchangeRate": import_zod6.z.any().optional(),
2991
- "PricingExchangeRate": import_zod6.z.any().optional(),
2992
- "PaymentExchangeRate": import_zod6.z.any().optional(),
2993
- "PaymentAlternativeExchangeRate": import_zod6.z.any().optional(),
2994
- "AllowanceCharge": import_zod6.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod6.z.array(import_zod6.z.any()).min(0)).optional(),
2995
- "TaxTotal": import_zod6.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod6.z.array(import_zod6.z.any()).min(0)).optional(),
2996
- "LegalMonetaryTotal": import_zod6.z.any(),
2997
- "CreditNoteLine": import_zod6.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod6.z.array(import_zod6.z.any()).min(1))
2852
+ "CreditNoteLine": import_zod5.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod5.z.array(import_zod5.z.any()).min(1))
2998
2853
  }).strict();
2999
2854
  PEF_KOR3Schema = CreditNoteType;
3000
2855
  }
@@ -3008,15 +2863,13 @@ var init_schemas = __esm({
3008
2863
  init_cjs_shims();
3009
2864
  init_fa3();
3010
2865
  init_fa2();
3011
- init_rr1_v11e();
3012
- init_rr1_v10e();
2866
+ init_fa_rr1();
3013
2867
  init_pef3();
3014
2868
  init_pef_kor3();
3015
2869
  NAMESPACE_MAP = {
3016
2870
  "http://crd.gov.pl/wzor/2025/06/25/13775/": "FA3",
3017
2871
  "http://crd.gov.pl/wzor/2023/06/29/12648/": "FA2",
3018
- "http://crd.gov.pl/wzor/2026/03/06/14189/": "RR1_V11E",
3019
- "http://crd.gov.pl/wzor/2026/02/17/14164/": "RR1_V10E",
2872
+ "http://crd.gov.pl/wzor/2026/03/06/14189/": "FA_RR1",
3020
2873
  "urn:oasis:names:specification:ubl:schema:xsd:Invoice-2": "PEF3",
3021
2874
  "urn:oasis:names:specification:ubl:schema:xsd:CreditNote-2": "PEF_KOR3"
3022
2875
  };
@@ -3035,11 +2888,8 @@ async function loadSchema(type) {
3035
2888
  case "FA2":
3036
2889
  mod = await Promise.resolve().then(() => (init_fa2(), fa2_exports));
3037
2890
  break;
3038
- case "RR1_V11E":
3039
- mod = await Promise.resolve().then(() => (init_rr1_v11e(), rr1_v11e_exports));
3040
- break;
3041
- case "RR1_V10E":
3042
- mod = await Promise.resolve().then(() => (init_rr1_v10e(), rr1_v10e_exports));
2891
+ case "FA_RR1":
2892
+ mod = await Promise.resolve().then(() => (init_fa_rr1(), fa_rr1_exports));
3043
2893
  break;
3044
2894
  case "PEF3":
3045
2895
  mod = await Promise.resolve().then(() => (init_pef3(), pef3_exports));
@@ -3080,7 +2930,7 @@ var init_schema_registry = __esm({
3080
2930
  * List all available schema types.
3081
2931
  */
3082
2932
  availableSchemas() {
3083
- return ["FA3", "FA2", "RR1_V11E", "RR1_V10E", "PEF3", "PEF_KOR3"];
2933
+ return ["FA3", "FA2", "FA_RR1", "PEF3", "PEF_KOR3"];
3084
2934
  },
3085
2935
  /**
3086
2936
  * Detect schema type from XML namespace URI and/or root element name.
@@ -4477,8 +4327,8 @@ var init_certificate_fetcher = __esm({
4477
4327
  init_routes();
4478
4328
  CertificateFetcher = class {
4479
4329
  restClient;
4480
- symmetricKeyPem;
4481
- ksefTokenPem;
4330
+ symmetricKey;
4331
+ ksefToken;
4482
4332
  initialized = false;
4483
4333
  constructor(restClient) {
4484
4334
  this.restClient = restClient;
@@ -4491,17 +4341,38 @@ var init_certificate_fetcher = __esm({
4491
4341
  this.initialized = false;
4492
4342
  await this.fetchCertificates();
4493
4343
  }
4344
+ /**
4345
+ * Immutable snapshot ({@link SelectedCertificate}) of the selected
4346
+ * SymmetricKeyEncryption certificate. The stored object is replaced wholesale
4347
+ * by {@link refresh}, never mutated, so holding the returned reference yields a
4348
+ * consistent pem + publicKeyId pair even if a concurrent refresh swaps the cache.
4349
+ */
4350
+ getSymmetricKeyEncryption() {
4351
+ return { ...this.requireSelected(this.symmetricKey) };
4352
+ }
4353
+ /** Immutable snapshot of the selected KsefTokenEncryption certificate. See {@link getSymmetricKeyEncryption}. */
4354
+ getKsefTokenEncryption() {
4355
+ return { ...this.requireSelected(this.ksefToken) };
4356
+ }
4494
4357
  getSymmetricKeyEncryptionPem() {
4495
- if (!this.symmetricKeyPem) {
4496
- throw new Error("CertificateFetcher not initialized. Call init() first.");
4497
- }
4498
- return this.symmetricKeyPem;
4358
+ return this.requireSelected(this.symmetricKey).pem;
4499
4359
  }
4500
4360
  getKsefTokenEncryptionPem() {
4501
- if (!this.ksefTokenPem) {
4361
+ return this.requireSelected(this.ksefToken).pem;
4362
+ }
4363
+ /** Public key identifier of the selected SymmetricKeyEncryption certificate (KSeF API v2.5.0). */
4364
+ getSymmetricKeyPublicKeyId() {
4365
+ return this.requireSelected(this.symmetricKey).publicKeyId;
4366
+ }
4367
+ /** Public key identifier of the selected KsefTokenEncryption certificate (KSeF API v2.5.0). */
4368
+ getKsefTokenPublicKeyId() {
4369
+ return this.requireSelected(this.ksefToken).publicKeyId;
4370
+ }
4371
+ requireSelected(selected) {
4372
+ if (!selected) {
4502
4373
  throw new Error("CertificateFetcher not initialized. Call init() first.");
4503
4374
  }
4504
- return this.ksefTokenPem;
4375
+ return selected;
4505
4376
  }
4506
4377
  async fetchCertificates() {
4507
4378
  const request = RestRequest.get(Routes.Security.publicKeyCertificates);
@@ -4510,19 +4381,27 @@ var init_certificate_fetcher = __esm({
4510
4381
  if (!certs || certs.length === 0) {
4511
4382
  throw new Error("No public key certificates returned from KSeF API.");
4512
4383
  }
4513
- const symmetricCert = certs.find((c) => c.usage.includes("SymmetricKeyEncryption"));
4514
- if (!symmetricCert) {
4515
- throw new Error("No SymmetricKeyEncryption certificate found.");
4516
- }
4517
- this.symmetricKeyPem = this.derBase64ToPem(symmetricCert.certificate);
4518
- const tokenCerts = certs.filter((c) => c.usage.includes("KsefTokenEncryption")).sort((a, b) => a.validFrom.localeCompare(b.validFrom));
4519
- const tokenCert = tokenCerts[0];
4520
- if (!tokenCert) {
4521
- throw new Error("No KsefTokenEncryption certificate found.");
4522
- }
4523
- this.ksefTokenPem = this.derBase64ToPem(tokenCert.certificate);
4384
+ this.symmetricKey = this.select(certs, "SymmetricKeyEncryption");
4385
+ this.ksefToken = this.select(certs, "KsefTokenEncryption");
4524
4386
  this.initialized = true;
4525
4387
  }
4388
+ /**
4389
+ * Select the certificate to use for a given usage under key rotation:
4390
+ * filter to currently-valid certificates (validFrom ≤ now < validTo) and pick
4391
+ * the newest by validFrom. If none are currently valid, fall back to the newest
4392
+ * overall so the server can reject it with a clear error rather than sending nothing.
4393
+ */
4394
+ select(certs, usage) {
4395
+ const candidates = certs.filter((c) => c.usage.includes(usage));
4396
+ if (candidates.length === 0) {
4397
+ throw new Error(`No ${usage} certificate found.`);
4398
+ }
4399
+ const now = Date.now();
4400
+ const byNewestValidFrom = (a, b) => Date.parse(b.validFrom) - Date.parse(a.validFrom);
4401
+ const valid = candidates.filter((c) => Date.parse(c.validFrom) <= now && now < Date.parse(c.validTo)).sort(byNewestValidFrom);
4402
+ const chosen = valid[0] ?? [...candidates].sort(byNewestValidFrom)[0];
4403
+ return { pem: this.derBase64ToPem(chosen.certificate), publicKeyId: chosen.publicKeyId };
4404
+ }
4526
4405
  derBase64ToPem(base64Der) {
4527
4406
  const lines = [];
4528
4407
  for (let i = 0; i < base64Der.length; i += 64) {
@@ -4578,6 +4457,14 @@ var init_cryptography_service = __esm({
4578
4457
  async init() {
4579
4458
  await this.fetcher.init();
4580
4459
  }
4460
+ /** Re-fetch KSeF public certificates, discarding the cached selection (used for key-rotation recovery). */
4461
+ async refresh() {
4462
+ await this.fetcher.refresh();
4463
+ }
4464
+ /** Identifier of the KsefTokenEncryption public key used by {@link encryptKsefToken} (KSeF API v2.5.0). */
4465
+ getKsefTokenPublicKeyId() {
4466
+ return this.fetcher.getKsefTokenPublicKeyId();
4467
+ }
4581
4468
  // ---------------------------------------------------------------------------
4582
4469
  // AES-256-CBC
4583
4470
  // ---------------------------------------------------------------------------
@@ -4623,11 +4510,12 @@ var init_cryptography_service = __esm({
4623
4510
  async getEncryptionData() {
4624
4511
  const key = crypto2.randomBytes(32);
4625
4512
  const iv = crypto2.randomBytes(16);
4626
- const certPem = this.fetcher.getSymmetricKeyEncryptionPem();
4627
- const encryptedKey = await this.rsaOaepEncrypt(certPem, new Uint8Array(key));
4513
+ const cert = this.fetcher.getSymmetricKeyEncryption();
4514
+ const encryptedKey = await this.rsaOaepEncrypt(cert.pem, new Uint8Array(key));
4628
4515
  const encryptionInfo = {
4629
4516
  encryptedSymmetricKey: Buffer.from(encryptedKey).toString("base64"),
4630
- initializationVector: iv.toString("base64")
4517
+ initializationVector: iv.toString("base64"),
4518
+ publicKeyId: cert.publicKeyId
4631
4519
  };
4632
4520
  return {
4633
4521
  cipherKey: new Uint8Array(key),
@@ -4652,9 +4540,29 @@ var init_cryptography_service = __esm({
4652
4540
  * `[ephemeralSPKI | nonce(12) | ciphertext+tag]`.
4653
4541
  */
4654
4542
  async encryptKsefToken(token, challengeTimestamp) {
4543
+ return this.encryptKsefTokenWithCertPem(
4544
+ this.fetcher.getKsefTokenEncryptionPem(),
4545
+ token,
4546
+ challengeTimestamp
4547
+ );
4548
+ }
4549
+ /**
4550
+ * Encrypt a KSeF token and return it together with the public key id of the
4551
+ * exact certificate used.
4552
+ *
4553
+ * Both values come from a single certificate snapshot taken before any
4554
+ * `await`, so a concurrent {@link refresh} cannot tag the ciphertext with a
4555
+ * different key than it was encrypted under (KSeF API v2.5.0). Prefer this over
4556
+ * pairing {@link encryptKsefToken} with a separate {@link getKsefTokenPublicKeyId}.
4557
+ */
4558
+ async encryptKsefTokenWithKeyId(token, challengeTimestamp) {
4559
+ const cert = this.fetcher.getKsefTokenEncryption();
4560
+ const encryptedToken = await this.encryptKsefTokenWithCertPem(cert.pem, token, challengeTimestamp);
4561
+ return { encryptedToken, publicKeyId: cert.publicKeyId };
4562
+ }
4563
+ async encryptKsefTokenWithCertPem(certPem, token, challengeTimestamp) {
4655
4564
  const timestampMs = new Date(challengeTimestamp).getTime();
4656
4565
  const plaintext = Buffer.from(`${token}|${timestampMs}`, "utf-8");
4657
- const certPem = this.fetcher.getKsefTokenEncryptionPem();
4658
4566
  const cert = new crypto2.X509Certificate(certPem);
4659
4567
  const publicKey = cert.publicKey;
4660
4568
  if (publicKey.asymmetricKeyType === "rsa") {
@@ -5173,7 +5081,7 @@ var init_auth_xml_builder = __esm({
5173
5081
  "src/crypto/auth-xml-builder.ts"() {
5174
5082
  "use strict";
5175
5083
  init_cjs_shims();
5176
- AUTH_TOKEN_REQUEST_NS = "http://ksef.mf.gov.pl/auth/token/2.0";
5084
+ AUTH_TOKEN_REQUEST_NS = "http://ksef.mf.gov.pl/auth/token/2.1";
5177
5085
  }
5178
5086
  });
5179
5087
 
@@ -5335,6 +5243,156 @@ var init_zip = __esm({
5335
5243
  }
5336
5244
  });
5337
5245
 
5246
+ // src/utils/targz.ts
5247
+ var targz_exports = {};
5248
+ __export(targz_exports, {
5249
+ createTarGz: () => createTarGz,
5250
+ extractTarGz: () => extractTarGz
5251
+ });
5252
+ async function createTarGz(entries) {
5253
+ const packer = (0, import_tar_stream.pack)();
5254
+ const gzip = packer.pipe((0, import_node_zlib.createGzip)());
5255
+ const chunks = [];
5256
+ return new Promise((resolve, reject) => {
5257
+ let settled = false;
5258
+ const fail = (err) => {
5259
+ if (settled) return;
5260
+ settled = true;
5261
+ reject(err);
5262
+ };
5263
+ packer.on("error", fail);
5264
+ gzip.on("error", fail);
5265
+ gzip.on("data", (chunk) => chunks.push(chunk));
5266
+ gzip.on("end", () => {
5267
+ if (settled) return;
5268
+ settled = true;
5269
+ resolve(Buffer.concat(chunks));
5270
+ });
5271
+ try {
5272
+ for (const entry of entries) {
5273
+ const content = Buffer.from(entry.content);
5274
+ packer.entry({ name: entry.fileName, size: content.length }, content);
5275
+ }
5276
+ packer.finalize();
5277
+ } catch (err) {
5278
+ fail(err instanceof Error ? err : new Error(String(err)));
5279
+ }
5280
+ });
5281
+ }
5282
+ async function extractTarGz(buffer, options = {}) {
5283
+ const limits = { ...DEFAULT_LIMITS, ...options };
5284
+ const ratioCeiling = limits.maxCompressionRatio !== null && limits.maxCompressionRatio !== void 0 && buffer.length > 0 ? buffer.length * limits.maxCompressionRatio : null;
5285
+ return new Promise((resolve, reject) => {
5286
+ const source = import_node_stream.Readable.from(buffer);
5287
+ const gunzip = (0, import_node_zlib.createGunzip)();
5288
+ const extractor = (0, import_tar_stream.extract)();
5289
+ const files = /* @__PURE__ */ new Map();
5290
+ let extractedFileCount = 0;
5291
+ let totalUncompressed = 0;
5292
+ let settled = false;
5293
+ const cleanup = () => {
5294
+ source.destroy();
5295
+ gunzip.destroy();
5296
+ extractor.destroy();
5297
+ };
5298
+ const fail = (err) => {
5299
+ if (settled) return;
5300
+ settled = true;
5301
+ cleanup();
5302
+ reject(err);
5303
+ };
5304
+ const succeed = () => {
5305
+ if (settled) return;
5306
+ settled = true;
5307
+ resolve(files);
5308
+ };
5309
+ gunzip.on("data", (chunk) => {
5310
+ totalUncompressed += chunk.length;
5311
+ if (limits.maxTotalUncompressedSize > 0 && totalUncompressed > limits.maxTotalUncompressedSize) {
5312
+ fail(new Error("tar.gz exceeds max_total_uncompressed_size"));
5313
+ return;
5314
+ }
5315
+ if (ratioCeiling !== null && totalUncompressed > ratioCeiling) {
5316
+ fail(new Error("tar.gz exceeds max_compression_ratio"));
5317
+ }
5318
+ });
5319
+ extractor.on("entry", (header, stream, next) => {
5320
+ if (settled) {
5321
+ stream.resume();
5322
+ return;
5323
+ }
5324
+ if (header.type !== "file") {
5325
+ stream.resume();
5326
+ stream.on("end", next);
5327
+ return;
5328
+ }
5329
+ if (limits.maxFiles > 0 && extractedFileCount >= limits.maxFiles) {
5330
+ fail(new Error("tar.gz contains too many files"));
5331
+ return;
5332
+ }
5333
+ const chunks = [];
5334
+ let entrySize = 0;
5335
+ stream.on("data", (chunk) => {
5336
+ if (settled) return;
5337
+ entrySize += chunk.length;
5338
+ if (limits.maxFileUncompressedSize > 0 && entrySize > limits.maxFileUncompressedSize) {
5339
+ fail(new Error("tar.gz entry exceeds max_file_uncompressed_size"));
5340
+ return;
5341
+ }
5342
+ chunks.push(chunk);
5343
+ });
5344
+ stream.on("error", fail);
5345
+ stream.on("end", () => {
5346
+ if (settled) return;
5347
+ extractedFileCount += 1;
5348
+ files.set(header.name, Buffer.concat(chunks));
5349
+ next();
5350
+ });
5351
+ });
5352
+ extractor.on("finish", succeed);
5353
+ extractor.on("error", fail);
5354
+ gunzip.on("error", fail);
5355
+ source.on("error", fail);
5356
+ source.pipe(gunzip).pipe(extractor);
5357
+ });
5358
+ }
5359
+ var import_node_zlib, import_node_stream, import_tar_stream, DEFAULT_LIMITS;
5360
+ var init_targz = __esm({
5361
+ "src/utils/targz.ts"() {
5362
+ "use strict";
5363
+ init_cjs_shims();
5364
+ import_node_zlib = require("node:zlib");
5365
+ import_node_stream = require("node:stream");
5366
+ import_tar_stream = require("tar-stream");
5367
+ DEFAULT_LIMITS = {
5368
+ maxFiles: 1e4,
5369
+ maxTotalUncompressedSize: 2e9,
5370
+ maxFileUncompressedSize: 5e8,
5371
+ maxCompressionRatio: 200
5372
+ };
5373
+ }
5374
+ });
5375
+
5376
+ // src/crypto/with-key-rotation-retry.ts
5377
+ async function withKeyRotationRetry(crypto8, op) {
5378
+ try {
5379
+ return await op();
5380
+ } catch (err) {
5381
+ if (err instanceof KSeFUnknownPublicKeyError) {
5382
+ await crypto8.refresh();
5383
+ return await op();
5384
+ }
5385
+ throw err;
5386
+ }
5387
+ }
5388
+ var init_with_key_rotation_retry = __esm({
5389
+ "src/crypto/with-key-rotation-retry.ts"() {
5390
+ "use strict";
5391
+ init_cjs_shims();
5392
+ init_ksef_unknown_public_key_error();
5393
+ }
5394
+ });
5395
+
5338
5396
  // src/offline/holidays.ts
5339
5397
  function toDateKey(d) {
5340
5398
  return d.toISOString().slice(0, 10);
@@ -5512,6 +5570,7 @@ var init_offline_invoice_workflow = __esm({
5512
5570
  import_node_crypto3 = __toESM(require("node:crypto"), 1);
5513
5571
  init_ksef_api_error();
5514
5572
  init_deadline();
5573
+ init_with_key_rotation_retry();
5515
5574
  init_document_structures();
5516
5575
  OfflineInvoiceWorkflow = class {
5517
5576
  constructor(qrService) {
@@ -5618,11 +5677,14 @@ var init_offline_invoice_workflow = __esm({
5618
5677
  }
5619
5678
  if (pending.length === 0) return result;
5620
5679
  await client.crypto.init();
5621
- const encData = await client.crypto.getEncryptionData();
5622
5680
  const formCode = options.formCode ?? DEFAULT_FORM_CODE;
5623
- const openResp = await client.onlineSession.openSession(
5624
- { formCode, encryption: encData.encryptionInfo }
5625
- );
5681
+ const { encData, openResp } = await withKeyRotationRetry(client.crypto, async () => {
5682
+ const encData2 = await client.crypto.getEncryptionData();
5683
+ const openResp2 = await client.onlineSession.openSession(
5684
+ { formCode, encryption: encData2.encryptionInfo }
5685
+ );
5686
+ return { encData: encData2, openResp: openResp2 };
5687
+ });
5626
5688
  const sessionRef = openResp.referenceNumber;
5627
5689
  try {
5628
5690
  for (const inv of pending) {
@@ -5707,11 +5769,14 @@ var init_offline_invoice_workflow = __esm({
5707
5769
  }
5708
5770
  const originalHash = import_node_crypto3.default.createHash("sha256").update(original.invoiceXml).digest("base64");
5709
5771
  await client.crypto.init();
5710
- const encData = await client.crypto.getEncryptionData();
5711
5772
  const formCode = options.formCode ?? DEFAULT_FORM_CODE;
5712
- const openResp = await client.onlineSession.openSession(
5713
- { formCode, encryption: encData.encryptionInfo }
5714
- );
5773
+ const { encData, openResp } = await withKeyRotationRetry(client.crypto, async () => {
5774
+ const encData2 = await client.crypto.getEncryptionData();
5775
+ const openResp2 = await client.onlineSession.openSession(
5776
+ { formCode, encryption: encData2.encryptionInfo }
5777
+ );
5778
+ return { encData: encData2, openResp: openResp2 };
5779
+ });
5715
5780
  const sessionRef = openResp.referenceNumber;
5716
5781
  try {
5717
5782
  const data = new TextEncoder().encode(correctedInvoiceXml);
@@ -5833,6 +5898,9 @@ function buildRestClientConfig(options, authManager) {
5833
5898
  allowedHosts: [...base.allowedHosts, ...options.presignedUrlHosts]
5834
5899
  };
5835
5900
  }
5901
+ if (options?.onSystemWarning) {
5902
+ config.onSystemWarning = options.onSystemWarning;
5903
+ }
5836
5904
  return config;
5837
5905
  }
5838
5906
  var KSeFClient;
@@ -5862,6 +5930,7 @@ var init_client = __esm({
5862
5930
  init_test_data();
5863
5931
  init_certificate_fetcher();
5864
5932
  init_cryptography_service();
5933
+ init_with_key_rotation_retry();
5865
5934
  init_verification_link_service();
5866
5935
  init_auth_xml_builder();
5867
5936
  init_offline_invoice_workflow();
@@ -5928,11 +5997,14 @@ var init_client = __esm({
5928
5997
  async loginWithToken(token, nip) {
5929
5998
  const challenge = await this.auth.getChallenge();
5930
5999
  await this.crypto.init();
5931
- const encryptedToken = await this.crypto.encryptKsefToken(token, challenge.timestamp);
5932
- const submitResult = await this.auth.submitKsefTokenAuthRequest({
5933
- challenge: challenge.challenge,
5934
- contextIdentifier: { type: "Nip", value: nip },
5935
- encryptedToken: Buffer.from(encryptedToken).toString("base64")
6000
+ const submitResult = await withKeyRotationRetry(this.crypto, async () => {
6001
+ const { encryptedToken, publicKeyId } = await this.crypto.encryptKsefTokenWithKeyId(token, challenge.timestamp);
6002
+ return this.auth.submitKsefTokenAuthRequest({
6003
+ challenge: challenge.challenge,
6004
+ contextIdentifier: { type: "Nip", value: nip },
6005
+ encryptedToken: Buffer.from(encryptedToken).toString("base64"),
6006
+ publicKeyId
6007
+ });
5936
6008
  });
5937
6009
  const authToken = submitResult.authenticationToken.token;
5938
6010
  await this.awaitAuthReady(submitResult.referenceNumber, authToken);
@@ -6036,6 +6108,7 @@ __export(index_exports, {
6036
6108
  KSeFRateLimitError: () => KSeFRateLimitError,
6037
6109
  KSeFSessionExpiredError: () => KSeFSessionExpiredError,
6038
6110
  KSeFUnauthorizedError: () => KSeFUnauthorizedError,
6111
+ KSeFUnknownPublicKeyError: () => KSeFUnknownPublicKeyError,
6039
6112
  KSeFValidationError: () => KSeFValidationError,
6040
6113
  KSeFXsdValidationError: () => KSeFXsdValidationError,
6041
6114
  KsefNumber: () => KsefNumber,
@@ -6094,6 +6167,7 @@ __export(index_exports, {
6094
6167
  calculateBackoff: () => calculateBackoff,
6095
6168
  calculateOfflineDeadline: () => calculateOfflineDeadline,
6096
6169
  comparePKey: () => comparePKey,
6170
+ createTarGz: () => createTarGz,
6097
6171
  createZip: () => createZip,
6098
6172
  decodeJwtPayload: () => decodeJwtPayload,
6099
6173
  deduplicateByKsefNumber: () => deduplicateByKsefNumber,
@@ -6106,6 +6180,7 @@ __export(index_exports, {
6106
6180
  exportInvoices: () => exportInvoices,
6107
6181
  extendDeadlineForMaintenance: () => extendDeadlineForMaintenance,
6108
6182
  extractInvoiceFields: () => extractInvoiceFields,
6183
+ extractTarGz: () => extractTarGz,
6109
6184
  getDefaultReason: () => getDefaultReason,
6110
6185
  getEffectiveStartDate: () => getEffectiveStartDate,
6111
6186
  getFormCode: () => getFormCode,
@@ -6506,6 +6581,7 @@ var AuthKsefTokenRequestBuilder = class {
6506
6581
  challenge;
6507
6582
  contextIdentifier;
6508
6583
  encryptedToken;
6584
+ publicKeyId;
6509
6585
  authorizationPolicy;
6510
6586
  withChallenge(challenge) {
6511
6587
  this.challenge = challenge;
@@ -6527,6 +6603,13 @@ var AuthKsefTokenRequestBuilder = class {
6527
6603
  this.encryptedToken = token;
6528
6604
  return this;
6529
6605
  }
6606
+ withPublicKeyId(publicKeyId) {
6607
+ if (!publicKeyId.trim()) {
6608
+ throw KSeFValidationError.fromField("publicKeyId", "Public key id is required");
6609
+ }
6610
+ this.publicKeyId = publicKeyId.trim();
6611
+ return this;
6612
+ }
6530
6613
  withAuthorizationPolicy(policy) {
6531
6614
  this.authorizationPolicy = policy;
6532
6615
  return this;
@@ -6545,6 +6628,7 @@ var AuthKsefTokenRequestBuilder = class {
6545
6628
  challenge: this.challenge,
6546
6629
  contextIdentifier: this.contextIdentifier,
6547
6630
  encryptedToken: this.encryptedToken,
6631
+ ...this.publicKeyId && { publicKeyId: this.publicKeyId },
6548
6632
  ...this.authorizationPolicy && { authorizationPolicy: this.authorizationPolicy }
6549
6633
  };
6550
6634
  }
@@ -6850,6 +6934,7 @@ var BatchFileBuilder = class {
6850
6934
  batchFile: {
6851
6935
  fileSize: zipBytes.length,
6852
6936
  fileHash: zipHash,
6937
+ ...options?.compressionType && { compressionType: options.compressionType },
6853
6938
  fileParts
6854
6939
  },
6855
6940
  encryptedParts
@@ -6952,6 +7037,7 @@ var BatchFileBuilder = class {
6952
7037
  batchFile: {
6953
7038
  fileSize: zipSize,
6954
7039
  fileHash: zipMeta.hashSHA,
7040
+ ...options?.compressionType && { compressionType: options.compressionType },
6955
7041
  fileParts
6956
7042
  },
6957
7043
  streamParts
@@ -7131,6 +7217,7 @@ function escapeXml2(str) {
7131
7217
  // src/utils/index.ts
7132
7218
  init_cjs_shims();
7133
7219
  init_zip();
7220
+ init_targz();
7134
7221
  init_jwt();
7135
7222
 
7136
7223
  // src/utils/hash.ts
@@ -7174,6 +7261,7 @@ init_auth_manager();
7174
7261
  init_online_session();
7175
7262
  init_session_status();
7176
7263
  init_document_structures();
7264
+ init_with_key_rotation_retry();
7177
7265
 
7178
7266
  // src/xml/index.ts
7179
7267
  init_cjs_shims();
@@ -7943,12 +8031,15 @@ function buildSessionHandle(params) {
7943
8031
  }
7944
8032
  async function openOnlineSession(client, options) {
7945
8033
  await client.crypto.init();
7946
- const encData = await client.crypto.getEncryptionData();
7947
8034
  const formCode = options?.formCode ?? DEFAULT_FORM_CODE;
7948
- const openResp = await client.onlineSession.openSession(
7949
- { formCode, encryption: encData.encryptionInfo },
7950
- options?.upoVersion
7951
- );
8035
+ const { encData, openResp } = await withKeyRotationRetry(client.crypto, async () => {
8036
+ const encData2 = await client.crypto.getEncryptionData();
8037
+ const openResp2 = await client.onlineSession.openSession(
8038
+ { formCode, encryption: encData2.encryptionInfo },
8039
+ options?.upoVersion
8040
+ );
8041
+ return { encData: encData2, openResp: openResp2 };
8042
+ });
7952
8043
  return buildSessionHandle({
7953
8044
  deps: {
7954
8045
  crypto: client.crypto,
@@ -8000,17 +8091,17 @@ async function openSendAndClose(client, invoices, options) {
8000
8091
  // src/workflows/batch-session-workflow.ts
8001
8092
  init_cjs_shims();
8002
8093
  init_document_structures();
8094
+ init_with_key_rotation_retry();
8003
8095
  async function uploadBatch(client, zipData, options) {
8004
8096
  if (options?.parallelism !== void 0 && (!Number.isInteger(options.parallelism) || options.parallelism < 1)) {
8005
8097
  throw new Error("parallelism must be a positive integer");
8006
8098
  }
8007
8099
  await client.crypto.init();
8008
8100
  if (options?.validate) {
8009
- const { unzip: unzip2 } = await Promise.resolve().then(() => (init_zip(), zip_exports));
8010
8101
  const { validateBatch: validateBatch2, batchValidationDetails: batchValidationDetails2 } = await Promise.resolve().then(() => (init_invoice_validator(), invoice_validator_exports));
8011
8102
  const { KSeFValidationError: KSeFValidationError2 } = await Promise.resolve().then(() => (init_ksef_validation_error(), ksef_validation_error_exports));
8012
8103
  const zipBuf = Buffer.isBuffer(zipData) ? zipData : Buffer.from(zipData.buffer, zipData.byteOffset, zipData.byteLength);
8013
- const files = await unzip2(zipBuf);
8104
+ 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);
8014
8105
  const invoices = [...files.entries()].filter(([name]) => name.endsWith(".xml")).map(([name, data]) => ({ fileName: name, xml: data.toString("utf-8") }));
8015
8106
  if (invoices.length > 0) {
8016
8107
  const result2 = await validateBatch2(invoices);
@@ -8023,21 +8114,25 @@ async function uploadBatch(client, zipData, options) {
8023
8114
  }
8024
8115
  }
8025
8116
  }
8026
- const encData = await client.crypto.getEncryptionData();
8027
8117
  const formCode = options?.formCode ?? DEFAULT_FORM_CODE;
8028
- const encryptFn = (part) => client.crypto.encryptAES256(part, encData.cipherKey, encData.cipherIv);
8029
- const { batchFile, encryptedParts } = BatchFileBuilder.build(zipData, encryptFn, {
8030
- maxPartSize: options?.maxPartSize
8118
+ const { batchFile, encryptedParts, openResp } = await withKeyRotationRetry(client.crypto, async () => {
8119
+ const encData = await client.crypto.getEncryptionData();
8120
+ const encryptFn = (part) => client.crypto.encryptAES256(part, encData.cipherKey, encData.cipherIv);
8121
+ const { batchFile: batchFile2, encryptedParts: encryptedParts2 } = BatchFileBuilder.build(zipData, encryptFn, {
8122
+ maxPartSize: options?.maxPartSize,
8123
+ compressionType: options?.compressionType
8124
+ });
8125
+ const openResp2 = await client.batchSession.openSession(
8126
+ {
8127
+ formCode,
8128
+ encryption: encData.encryptionInfo,
8129
+ batchFile: batchFile2,
8130
+ offlineMode: options?.offlineMode
8131
+ },
8132
+ options?.upoVersion
8133
+ );
8134
+ return { batchFile: batchFile2, encryptedParts: encryptedParts2, openResp: openResp2 };
8031
8135
  });
8032
- const openResp = await client.batchSession.openSession(
8033
- {
8034
- formCode,
8035
- encryption: encData.encryptionInfo,
8036
- batchFile,
8037
- offlineMode: options?.offlineMode
8038
- },
8039
- options?.upoVersion
8040
- );
8041
8136
  const sendingParts = encryptedParts.map((part, i) => ({
8042
8137
  data: part.buffer.slice(part.byteOffset, part.byteOffset + part.byteLength),
8043
8138
  metadata: {
@@ -8071,26 +8166,29 @@ async function uploadBatchStream(client, zipStreamFactory, zipSize, options) {
8071
8166
  throw new Error("parallelism must be a positive integer");
8072
8167
  }
8073
8168
  await client.crypto.init();
8074
- const encData = await client.crypto.getEncryptionData();
8075
8169
  const formCode = options?.formCode ?? DEFAULT_FORM_CODE;
8076
- const encryptStreamFn = (stream) => client.crypto.encryptAES256Stream(stream, encData.cipherKey, encData.cipherIv);
8077
- const hashStreamFn = (stream) => client.crypto.getFileMetadataFromStream(stream);
8078
- const { batchFile, streamParts } = await BatchFileBuilder.buildFromStream(
8079
- zipStreamFactory,
8080
- zipSize,
8081
- encryptStreamFn,
8082
- hashStreamFn,
8083
- { maxPartSize: options?.maxPartSize }
8084
- );
8085
- const openResp = await client.batchSession.openSession(
8086
- {
8087
- formCode,
8088
- encryption: encData.encryptionInfo,
8089
- batchFile,
8090
- offlineMode: options?.offlineMode
8091
- },
8092
- options?.upoVersion
8093
- );
8170
+ const { streamParts, openResp } = await withKeyRotationRetry(client.crypto, async () => {
8171
+ const encData = await client.crypto.getEncryptionData();
8172
+ const encryptStreamFn = (stream) => client.crypto.encryptAES256Stream(stream, encData.cipherKey, encData.cipherIv);
8173
+ const hashStreamFn = (stream) => client.crypto.getFileMetadataFromStream(stream);
8174
+ const { batchFile, streamParts: streamParts2 } = await BatchFileBuilder.buildFromStream(
8175
+ zipStreamFactory,
8176
+ zipSize,
8177
+ encryptStreamFn,
8178
+ hashStreamFn,
8179
+ { maxPartSize: options?.maxPartSize, compressionType: options?.compressionType }
8180
+ );
8181
+ const openResp2 = await client.batchSession.openSession(
8182
+ {
8183
+ formCode,
8184
+ encryption: encData.encryptionInfo,
8185
+ batchFile,
8186
+ offlineMode: options?.offlineMode
8187
+ },
8188
+ options?.upoVersion
8189
+ );
8190
+ return { streamParts: streamParts2, openResp: openResp2 };
8191
+ });
8094
8192
  await client.batchSession.sendPartsWithStream(openResp, streamParts, options?.parallelism);
8095
8193
  await client.batchSession.closeSession(openResp.referenceNumber);
8096
8194
  const result = await pollUntil(
@@ -8139,13 +8237,19 @@ async function uploadBatchParsed(client, zipData, options) {
8139
8237
  // src/workflows/invoice-export-workflow.ts
8140
8238
  init_cjs_shims();
8141
8239
  init_zip();
8240
+ init_targz();
8241
+ init_with_key_rotation_retry();
8142
8242
  async function doExport(client, filters, options) {
8143
8243
  await client.crypto.init();
8144
- const encData = await client.crypto.getEncryptionData();
8145
- const opResp = await client.invoices.exportInvoices({
8146
- encryption: encData.encryptionInfo,
8147
- filters,
8148
- onlyMetadata: options?.onlyMetadata
8244
+ const { encData, opResp } = await withKeyRotationRetry(client.crypto, async () => {
8245
+ const encData2 = await client.crypto.getEncryptionData();
8246
+ const opResp2 = await client.invoices.exportInvoices({
8247
+ encryption: encData2.encryptionInfo,
8248
+ filters,
8249
+ onlyMetadata: options?.onlyMetadata,
8250
+ ...options?.compressionType && { compressionType: options.compressionType }
8251
+ });
8252
+ return { encData: encData2, opResp: opResp2 };
8149
8253
  });
8150
8254
  const result = await pollUntil(
8151
8255
  () => client.invoices.getInvoiceExportStatus(opResp.referenceNumber),
@@ -8200,8 +8304,8 @@ async function exportAndDownload(client, filters, options) {
8200
8304
  decryptedParts.push(decrypted);
8201
8305
  }
8202
8306
  if (options?.extract) {
8203
- const zipBuffer = Buffer.concat(decryptedParts);
8204
- const files = await unzip(zipBuffer, options.unzipOptions);
8307
+ const archiveBuffer = Buffer.concat(decryptedParts);
8308
+ const files = options.compressionType === "TarGz" ? await extractTarGz(archiveBuffer, options.unzipOptions) : await unzip(archiveBuffer, options.unzipOptions);
8205
8309
  return { ...exportResult, files };
8206
8310
  }
8207
8311
  return {
@@ -8346,15 +8450,19 @@ var FileHwmStore = class {
8346
8450
  // src/workflows/auth-workflow.ts
8347
8451
  init_cjs_shims();
8348
8452
  init_auth_xml_builder();
8453
+ init_with_key_rotation_retry();
8349
8454
  async function authenticateWithToken(client, options) {
8350
8455
  const challenge = await client.auth.getChallenge();
8351
8456
  await client.crypto.init();
8352
- const encryptedToken = await client.crypto.encryptKsefToken(options.token, challenge.timestamp);
8353
- const submitResult = await client.auth.submitKsefTokenAuthRequest({
8354
- challenge: challenge.challenge,
8355
- contextIdentifier: { type: "Nip", value: options.nip },
8356
- encryptedToken: Buffer.from(encryptedToken).toString("base64"),
8357
- authorizationPolicy: options.authorizationPolicy
8457
+ const submitResult = await withKeyRotationRetry(client.crypto, async () => {
8458
+ const { encryptedToken, publicKeyId } = await client.crypto.encryptKsefTokenWithKeyId(options.token, challenge.timestamp);
8459
+ return client.auth.submitKsefTokenAuthRequest({
8460
+ challenge: challenge.challenge,
8461
+ contextIdentifier: { type: "Nip", value: options.nip },
8462
+ encryptedToken: Buffer.from(encryptedToken).toString("base64"),
8463
+ publicKeyId,
8464
+ authorizationPolicy: options.authorizationPolicy
8465
+ });
8358
8466
  });
8359
8467
  const authToken = submitResult.authenticationToken.token;
8360
8468
  await pollUntil(
@@ -8637,6 +8745,7 @@ init_client();
8637
8745
  KSeFRateLimitError,
8638
8746
  KSeFSessionExpiredError,
8639
8747
  KSeFUnauthorizedError,
8748
+ KSeFUnknownPublicKeyError,
8640
8749
  KSeFValidationError,
8641
8750
  KSeFXsdValidationError,
8642
8751
  KsefNumber,
@@ -8695,6 +8804,7 @@ init_client();
8695
8804
  calculateBackoff,
8696
8805
  calculateOfflineDeadline,
8697
8806
  comparePKey,
8807
+ createTarGz,
8698
8808
  createZip,
8699
8809
  decodeJwtPayload,
8700
8810
  deduplicateByKsefNumber,
@@ -8707,6 +8817,7 @@ init_client();
8707
8817
  exportInvoices,
8708
8818
  extendDeadlineForMaintenance,
8709
8819
  extractInvoiceFields,
8820
+ extractTarGz,
8710
8821
  getDefaultReason,
8711
8822
  getEffectiveStartDate,
8712
8823
  getFormCode,