ksef-client-ts 0.5.1 → 0.6.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
@@ -247,6 +247,10 @@ var init_ksef_session_expired_error = __esm({
247
247
  });
248
248
 
249
249
  // src/errors/ksef-validation-error.ts
250
+ var ksef_validation_error_exports = {};
251
+ __export(ksef_validation_error_exports, {
252
+ KSeFValidationError: () => KSeFValidationError
253
+ });
250
254
  var KSeFValidationError;
251
255
  var init_ksef_validation_error = __esm({
252
256
  "src/errors/ksef-validation-error.ts"() {
@@ -316,21 +320,21 @@ var init_rest_request = __esm({
316
320
  _query = [];
317
321
  _presigned = false;
318
322
  _skipAuthRetry = false;
319
- constructor(method, path) {
323
+ constructor(method, path2) {
320
324
  this.method = method;
321
- this.path = path;
325
+ this.path = path2;
322
326
  }
323
- static get(path) {
324
- return new _RestRequest("GET", path);
327
+ static get(path2) {
328
+ return new _RestRequest("GET", path2);
325
329
  }
326
- static post(path) {
327
- return new _RestRequest("POST", path);
330
+ static post(path2) {
331
+ return new _RestRequest("POST", path2);
328
332
  }
329
- static put(path) {
330
- return new _RestRequest("PUT", path);
333
+ static put(path2) {
334
+ return new _RestRequest("PUT", path2);
331
335
  }
332
- static delete(path) {
333
- return new _RestRequest("DELETE", path);
336
+ static delete(path2) {
337
+ return new _RestRequest("DELETE", path2);
334
338
  }
335
339
  body(data) {
336
340
  this._body = data;
@@ -650,9 +654,9 @@ var init_rest_client = __esm({
650
654
  return response;
651
655
  }
652
656
  buildUrl(request) {
653
- const path = this.routeBuilder.build(request.path);
657
+ const path2 = this.routeBuilder.build(request.path);
654
658
  const base = this.options.baseUrl;
655
- const url = new URL(`${base}${path}`);
659
+ const url = new URL(`${base}${path2}`);
656
660
  const query = request.getQuery();
657
661
  for (const [key, value] of query) {
658
662
  url.searchParams.append(key, value);
@@ -948,6 +952,212 @@ var init_ksef_feature = __esm({
948
952
  }
949
953
  });
950
954
 
955
+ // src/validation/patterns.ts
956
+ function computeCrc8Hex(data) {
957
+ let crc = 0;
958
+ const bytes = new TextEncoder().encode(data);
959
+ for (const byte of bytes) {
960
+ crc ^= byte;
961
+ for (let i = 0; i < 8; i++) {
962
+ crc = (crc & 128) !== 0 ? (crc << 1 ^ CRC8_POLY) & 255 : crc << 1 & 255;
963
+ }
964
+ }
965
+ return crc.toString(16).toUpperCase().padStart(2, "0");
966
+ }
967
+ function isValidNip(value) {
968
+ if (!Nip.test(value)) return false;
969
+ let sum = 0;
970
+ for (let i = 0; i < 9; i++) {
971
+ sum += Number(value[i]) * NIP_WEIGHTS[i];
972
+ }
973
+ const checksum = sum % 11;
974
+ return checksum !== 10 && checksum === Number(value[9]);
975
+ }
976
+ function isValidVatUe(value) {
977
+ return VatUe.test(value);
978
+ }
979
+ function isValidNipVatUe(value) {
980
+ return NipVatUe.test(value);
981
+ }
982
+ function isValidInternalId(value) {
983
+ return InternalId.test(value);
984
+ }
985
+ function isValidPeppolId(value) {
986
+ return PeppolId.test(value);
987
+ }
988
+ function isValidReferenceNumber(value) {
989
+ return ReferenceNumber.test(value);
990
+ }
991
+ function isValidKsefNumber(value) {
992
+ if (!KsefNumber.test(value)) return false;
993
+ let normalized = value;
994
+ if (value.length === 36) {
995
+ const parts = value.split("-");
996
+ if (parts.length === 5) normalized = `${parts[0]}-${parts[1]}-${parts[2]}${parts[3]}-${parts[4]}`;
997
+ else return false;
998
+ }
999
+ if (normalized.length !== 35) return false;
1000
+ return computeCrc8Hex(normalized.slice(0, 32)) === normalized.slice(-2);
1001
+ }
1002
+ function isValidKsefNumberV35(value) {
1003
+ if (!KsefNumberV35.test(value)) return false;
1004
+ return computeCrc8Hex(value.slice(0, 32)) === value.slice(-2);
1005
+ }
1006
+ function isValidKsefNumberV36(value) {
1007
+ if (!KsefNumberV36.test(value)) return false;
1008
+ const parts = value.split("-");
1009
+ if (parts.length !== 5) return false;
1010
+ const normalized = `${parts[0]}-${parts[1]}-${parts[2]}${parts[3]}-${parts[4]}`;
1011
+ return computeCrc8Hex(normalized.slice(0, 32)) === normalized.slice(-2);
1012
+ }
1013
+ function isValidPesel(value) {
1014
+ if (!Pesel.test(value)) return false;
1015
+ let sum = 0;
1016
+ for (let i = 0; i < 10; i++) {
1017
+ sum += Number(value[i]) * PESEL_WEIGHTS[i];
1018
+ }
1019
+ const checksum = (10 - sum % 10) % 10;
1020
+ return checksum === Number(value[10]);
1021
+ }
1022
+ function isValidCertificateName(value) {
1023
+ return CertificateName.test(value);
1024
+ }
1025
+ function isValidCertificateFingerprint(value) {
1026
+ return CertificateFingerprint.test(value);
1027
+ }
1028
+ function isValidBase64(value) {
1029
+ return Base64String.test(value);
1030
+ }
1031
+ function isValidIp4Address(value) {
1032
+ return Ip4Address.test(value);
1033
+ }
1034
+ function isValidSha256Base64(value) {
1035
+ return Sha256Base64.test(value);
1036
+ }
1037
+ 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;
1038
+ var init_patterns = __esm({
1039
+ "src/validation/patterns.ts"() {
1040
+ "use strict";
1041
+ NIP_PATTERN_CORE = "[1-9]((\\d[1-9])|([1-9]\\d))\\d{7}";
1042
+ VAT_UE_PATTERN_CORE = "(ATU\\d{8}|BE[01]{1}\\d{9}|BG\\d{9,10}|CY\\d{8}[A-Z]|CZ\\d{8,10}|DE\\d{9}|DK\\d{8}|EE\\d{9}|EL\\d{9}|ES([A-Z]\\d{8}|\\d{8}[A-Z]|[A-Z]\\d{7}[A-Z])|FI\\d{8}|FR[A-Z0-9]{2}\\d{9}|HR\\d{11}|HU\\d{8}|IE(\\d{7}[A-Z]{2}|\\d[A-Z0-9+*]\\d{5}[A-Z])|IT\\d{11}|LT(\\d{9}|\\d{12})|LU\\d{8}|LV\\d{11}|MT\\d{8}|NL[A-Z0-9+*]{12}|PT\\d{9}|RO\\d{2,10}|SE\\d{12}|SI\\d{8}|SK\\d{10}|XI((\\d{9}|\\d{12})|(GD|HA)\\d{3}))";
1043
+ Nip = new RegExp(`^${NIP_PATTERN_CORE}$`);
1044
+ VatUe = new RegExp(`^${VAT_UE_PATTERN_CORE}$`);
1045
+ NipVatUe = new RegExp(`^${NIP_PATTERN_CORE}-${VAT_UE_PATTERN_CORE}$`);
1046
+ InternalId = /^[1-9]((\d[1-9])|([1-9]\d))\d{7}-\d{5}$/;
1047
+ PeppolId = /^P[A-Z]{2}[0-9]{6}$/;
1048
+ ReferenceNumber = /^(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-Z]{2})-([0-9A-F]{10})-([0-9A-F]{10})-([0-9A-F]{2})$/;
1049
+ KsefNumber = /^([1-9](\d[1-9]|[1-9]\d)\d{7})-(20[2-9][0-9]|2[1-9]\d{2}|[3-9]\d{3})(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])-([0-9A-F]{6})-?([0-9A-F]{6})-([0-9A-F]{2})$/;
1050
+ KsefNumberV35 = /^([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})$/;
1051
+ KsefNumberV36 = /^([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})$/;
1052
+ CertificateName = /^[a-zA-Z0-9_\- ąćęłńóśźżĄĆĘŁŃÓŚŹŻ]+$/;
1053
+ 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}$/;
1054
+ CertificateFingerprint = /^[0-9A-F]{64}$/;
1055
+ Base64String = /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/;
1056
+ Ip4Address = /^((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)\.?\b){4}$/;
1057
+ 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}$/;
1058
+ Ip4Mask = /^((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)\.?\b){4}\/(0|[1-9]|1[0-9]|2[0-9]|3[0-2])$/;
1059
+ Sha256Base64 = /^[A-Za-z0-9+/]{43}=$/;
1060
+ NIP_WEIGHTS = [6, 5, 7, 2, 3, 4, 5, 6, 7];
1061
+ PESEL_WEIGHTS = [1, 3, 7, 9, 1, 3, 7, 9, 1, 3];
1062
+ CRC8_POLY = 7;
1063
+ }
1064
+ });
1065
+
1066
+ // src/validation/xml-to-object.ts
1067
+ function xmlToObject(xml) {
1068
+ const errors = [];
1069
+ const doc = new import_xmldom.DOMParser({
1070
+ errorHandler: {
1071
+ warning: (_msg) => {
1072
+ },
1073
+ error: (msg) => errors.push(msg),
1074
+ fatalError: (msg) => errors.push(msg)
1075
+ }
1076
+ }).parseFromString(xml, "text/xml");
1077
+ if (errors.length > 0 || !doc || !doc.documentElement) {
1078
+ return { object: null, rootElement: null, namespace: null, errors };
1079
+ }
1080
+ const root = doc.documentElement;
1081
+ const rootName = getLocalName(root);
1082
+ const namespace = root.namespaceURI || null;
1083
+ const obj = elementToObject(root);
1084
+ return {
1085
+ object: typeof obj === "object" && obj !== null ? obj : { "#text": obj },
1086
+ rootElement: rootName,
1087
+ namespace,
1088
+ errors: []
1089
+ };
1090
+ }
1091
+ function getLocalName(node) {
1092
+ if (node.localName) return node.localName;
1093
+ const name = node.nodeName;
1094
+ const idx = name.indexOf(":");
1095
+ return idx === -1 ? name : name.substring(idx + 1);
1096
+ }
1097
+ function elementToObject(el) {
1098
+ const result = {};
1099
+ let hasChildElements = false;
1100
+ for (let i = 0; i < el.attributes.length; i++) {
1101
+ const a = el.attributes.item(i);
1102
+ if (!a) continue;
1103
+ const name = a.nodeName;
1104
+ if (name === "xmlns" || name.startsWith("xmlns:")) continue;
1105
+ const attrLocal = getLocalName(a);
1106
+ result[`@${attrLocal}`] = a.value;
1107
+ }
1108
+ const childCounts = /* @__PURE__ */ new Map();
1109
+ for (let i = 0; i < el.childNodes.length; i++) {
1110
+ const child = el.childNodes.item(i);
1111
+ if (!child || child.nodeType !== 1) continue;
1112
+ const name = getLocalName(child);
1113
+ childCounts.set(name, (childCounts.get(name) || 0) + 1);
1114
+ hasChildElements = true;
1115
+ }
1116
+ if (!hasChildElements) {
1117
+ const text = getTextContent(el);
1118
+ const hasAttrs = Object.keys(result).length > 0;
1119
+ if (hasAttrs) {
1120
+ result["#text"] = text;
1121
+ return result;
1122
+ }
1123
+ return text;
1124
+ }
1125
+ for (let i = 0; i < el.childNodes.length; i++) {
1126
+ const child = el.childNodes.item(i);
1127
+ if (!child || child.nodeType !== 1) continue;
1128
+ const name = getLocalName(child);
1129
+ const value = elementToObject(child);
1130
+ const count = childCounts.get(name) || 1;
1131
+ if (count > 1) {
1132
+ if (!Array.isArray(result[name])) {
1133
+ result[name] = [];
1134
+ }
1135
+ result[name].push(value);
1136
+ } else {
1137
+ result[name] = value;
1138
+ }
1139
+ }
1140
+ return result;
1141
+ }
1142
+ function getTextContent(el) {
1143
+ let text = "";
1144
+ for (let i = 0; i < el.childNodes.length; i++) {
1145
+ const child = el.childNodes.item(i);
1146
+ if (!child) continue;
1147
+ if (child.nodeType === 3 || child.nodeType === 4) {
1148
+ text += child.nodeValue || "";
1149
+ }
1150
+ }
1151
+ return text.trim();
1152
+ }
1153
+ var import_xmldom;
1154
+ var init_xml_to_object = __esm({
1155
+ "src/validation/xml-to-object.ts"() {
1156
+ "use strict";
1157
+ import_xmldom = require("@xmldom/xmldom");
1158
+ }
1159
+ });
1160
+
951
1161
  // src/validation/schemas/fa3.ts
952
1162
  var fa3_exports = {};
953
1163
  __export(fa3_exports, {
@@ -962,18 +1172,18 @@ var init_fa3 = __esm({
962
1172
  TDataCzas = import_zod.z.string();
963
1173
  TZnakowy = import_zod.z.string().min(1).max(256);
964
1174
  TNaglowek = import_zod.z.object({
965
- "KodFormularza": import_zod.z.object({ "#text": TKodFormularza, "@kodSystemowy": import_zod.z.literal("FA (3)"), "@wersjaSchemy": import_zod.z.literal("1-0E") }),
1175
+ "KodFormularza": import_zod.z.object({ "#text": TKodFormularza, "@kodSystemowy": import_zod.z.literal("FA (3)"), "@wersjaSchemy": import_zod.z.literal("1-0E") }).strict(),
966
1176
  "WariantFormularza": import_zod.z.literal("3"),
967
1177
  "DataWytworzeniaFa": import_zod.z.string(),
968
1178
  "SystemInfo": TZnakowy.optional()
969
- });
1179
+ }).strict();
970
1180
  TKodyKrajowUE = import_zod.z.enum(["AT", "BE", "BG", "CY", "CZ", "DK", "EE", "FI", "FR", "DE", "EL", "HR", "HU", "IE", "IT", "LV", "LT", "LU", "MT", "NL", "PL", "PT", "RO", "SK", "SI", "ES", "SE", "XI"]);
971
1181
  TNrNIP = import_zod.z.string().regex(/^[1-9]((\d[1-9])|([1-9]\d))\d{7}$/);
972
1182
  TZnakowy512 = import_zod.z.string().min(1).max(512);
973
1183
  TPodmiot1 = import_zod.z.object({
974
1184
  "NIP": TNrNIP,
975
1185
  "Nazwa": TZnakowy512
976
- });
1186
+ }).strict();
977
1187
  TKodKraju = import_zod.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"]);
978
1188
  TGLN = import_zod.z.string().min(1).max(13);
979
1189
  TAdres = import_zod.z.object({
@@ -981,7 +1191,7 @@ var init_fa3 = __esm({
981
1191
  "AdresL1": TZnakowy512,
982
1192
  "AdresL2": TZnakowy512.optional(),
983
1193
  "GLN": TGLN.optional()
984
- });
1194
+ }).strict();
985
1195
  TAdresEmail = import_zod.z.string().min(3).max(255).regex(/^(.)+@(.)+$/);
986
1196
  TNumerTelefonu = import_zod.z.string().min(1).max(16);
987
1197
  TStatusInfoPodatnika = import_zod.z.enum(["1", "2", "3", "4"]);
@@ -996,7 +1206,7 @@ var init_fa3 = __esm({
996
1206
  "NrID": import_zod.z.string().min(1).max(50).optional(),
997
1207
  "BrakID": TWybor1.optional(),
998
1208
  "Nazwa": TZnakowy512.optional()
999
- });
1209
+ }).strict();
1000
1210
  TZnakowy50 = import_zod.z.string().min(1).max(50);
1001
1211
  TZnakowy20 = import_zod.z.string().min(1).max(20);
1002
1212
  TNIPIdWew = import_zod.z.string().min(1).max(20).regex(/^[1-9]((\d[1-9])|([1-9]\d))\d{7}-\d{5}$/);
@@ -1009,7 +1219,7 @@ var init_fa3 = __esm({
1009
1219
  "NrID": import_zod.z.string().min(1).max(50).optional(),
1010
1220
  "BrakID": TWybor1.optional(),
1011
1221
  "Nazwa": TZnakowy512.optional()
1012
- });
1222
+ }).strict();
1013
1223
  TRolaPodmiotu3 = import_zod.z.enum(["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11"]);
1014
1224
  TProcentowy = import_zod.z.coerce.number().min(0).max(100);
1015
1225
  TRolaPodmiotuUpowaznionego = import_zod.z.enum(["1", "2", "3"]);
@@ -1027,7 +1237,7 @@ var init_fa3 = __esm({
1027
1237
  "NrWiersza": TNaturalny.optional(),
1028
1238
  "Klucz": TZnakowy,
1029
1239
  "Wartosc": TZnakowy
1030
- });
1240
+ }).strict();
1031
1241
  TKwotowy2 = import_zod.z.string().regex(/^-?([1-9]\d{0,13}|0)(\.\d{1,8})?$/);
1032
1242
  TStawkaPodatku = import_zod.z.enum(["23", "22", "8", "7", "5", "4", "3", "0 KR", "0 WDT", "0 EX", "zw", "oo", "np I", "np II"]);
1033
1243
  TGTU = import_zod.z.enum(["GTU_01", "GTU_02", "GTU_03", "GTU_04", "GTU_05", "GTU_06", "GTU_07", "GTU_08", "GTU_09", "GTU_10", "GTU_11", "GTU_12", "GTU_13"]);
@@ -1042,7 +1252,7 @@ var init_fa3 = __esm({
1042
1252
  "RachunekWlasnyBanku": TRachunekWlasnyBanku.optional(),
1043
1253
  "NazwaBanku": TZnakowy.optional(),
1044
1254
  "OpisRachunku": TZnakowy.optional()
1045
- });
1255
+ }).strict();
1046
1256
  TDataU = import_zod.z.string();
1047
1257
  TRodzajTransportu = import_zod.z.enum(["1", "2", "3", "4", "5", "7", "8"]);
1048
1258
  TLadunek = import_zod.z.enum(["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20"]);
@@ -1063,13 +1273,13 @@ var init_fa3 = __esm({
1063
1273
  "AdresL1": TZnakowy512,
1064
1274
  "AdresL2": TZnakowy512.optional(),
1065
1275
  "GLN": TGLN.optional()
1066
- }).optional(),
1276
+ }).strict().optional(),
1067
1277
  "DaneKontaktowe": import_zod.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod.z.array(import_zod.z.object({
1068
1278
  "Email": TAdresEmail.optional(),
1069
1279
  "Telefon": TNumerTelefonu.optional()
1070
- })).min(0).max(3)).optional(),
1280
+ }).strict()).min(0).max(3)).optional(),
1071
1281
  "StatusInfoPodatnika": TStatusInfoPodatnika.optional()
1072
- }),
1282
+ }).strict(),
1073
1283
  "Podmiot2": import_zod.z.object({
1074
1284
  "NrEORI": TZnakowy.optional(),
1075
1285
  "DaneIdentyfikacyjne": TPodmiot2,
@@ -1078,12 +1288,12 @@ var init_fa3 = __esm({
1078
1288
  "DaneKontaktowe": import_zod.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod.z.array(import_zod.z.object({
1079
1289
  "Email": TAdresEmail.optional(),
1080
1290
  "Telefon": TNumerTelefonu.optional()
1081
- })).min(0).max(3)).optional(),
1291
+ }).strict()).min(0).max(3)).optional(),
1082
1292
  "NrKlienta": TZnakowy.optional(),
1083
1293
  "IDNabywcy": import_zod.z.string().min(1).max(32).optional(),
1084
1294
  "JST": import_zod.z.enum(["1", "2"]),
1085
1295
  "GV": import_zod.z.enum(["1", "2"])
1086
- }),
1296
+ }).strict(),
1087
1297
  "Podmiot3": import_zod.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod.z.array(import_zod.z.object({
1088
1298
  "IDNabywcy": import_zod.z.string().min(1).max(32).optional(),
1089
1299
  "NrEORI": TZnakowy.optional(),
@@ -1093,13 +1303,13 @@ var init_fa3 = __esm({
1093
1303
  "DaneKontaktowe": import_zod.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod.z.array(import_zod.z.object({
1094
1304
  "Email": TAdresEmail.optional(),
1095
1305
  "Telefon": TNumerTelefonu.optional()
1096
- })).min(0).max(3)).optional(),
1306
+ }).strict()).min(0).max(3)).optional(),
1097
1307
  "Rola": TRolaPodmiotu3.optional(),
1098
1308
  "RolaInna": TWybor1.optional(),
1099
1309
  "OpisRoli": TZnakowy.optional(),
1100
1310
  "Udzial": TProcentowy.optional(),
1101
1311
  "NrKlienta": TZnakowy.optional()
1102
- })).min(0).max(100)).optional(),
1312
+ }).strict()).min(0).max(100)).optional(),
1103
1313
  "PodmiotUpowazniony": import_zod.z.object({
1104
1314
  "NrEORI": TZnakowy.optional(),
1105
1315
  "DaneIdentyfikacyjne": TPodmiot1,
@@ -1108,9 +1318,9 @@ var init_fa3 = __esm({
1108
1318
  "DaneKontaktowe": import_zod.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod.z.array(import_zod.z.object({
1109
1319
  "EmailPU": TAdresEmail.optional(),
1110
1320
  "TelefonPU": TNumerTelefonu.optional()
1111
- })).min(0).max(3)).optional(),
1321
+ }).strict()).min(0).max(3)).optional(),
1112
1322
  "RolaPU": TRolaPodmiotuUpowaznionego
1113
- }).optional(),
1323
+ }).strict().optional(),
1114
1324
  "Fa": import_zod.z.object({
1115
1325
  "KodWaluty": TKodWaluty,
1116
1326
  "P_1": TDataT,
@@ -1121,7 +1331,7 @@ var init_fa3 = __esm({
1121
1331
  "OkresFa": import_zod.z.object({
1122
1332
  "P_6_Od": TDataT,
1123
1333
  "P_6_Do": TDataT
1124
- }).optional(),
1334
+ }).strict().optional(),
1125
1335
  "P_13_1": TKwotowy.optional(),
1126
1336
  "P_14_1": TKwotowy.optional(),
1127
1337
  "P_14_1W": TKwotowy.optional(),
@@ -1151,7 +1361,7 @@ var init_fa3 = __esm({
1151
1361
  "P_17": TWybor1_2,
1152
1362
  "P_18": TWybor1_2,
1153
1363
  "P_18A": TWybor1_2,
1154
- "Zwolnienie": import_zod.z.union([import_zod.z.object({ "P_19": TWybor1, "P_19A": TZnakowy.optional(), "P_19B": TZnakowy.optional(), "P_19C": TZnakowy.optional() }), import_zod.z.object({ "P_19N": TWybor1 })]),
1364
+ "Zwolnienie": import_zod.z.union([import_zod.z.object({ "P_19": TWybor1, "P_19A": TZnakowy.optional(), "P_19B": TZnakowy.optional(), "P_19C": TZnakowy.optional() }).strict(), import_zod.z.object({ "P_19N": TWybor1 }).strict()]),
1155
1365
  "NoweSrodkiTransportu": import_zod.z.union([import_zod.z.object({ "P_22": TWybor1, "P_42_5": TWybor1_2, "NowySrodekTransportu": import_zod.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod.z.array(import_zod.z.object({
1156
1366
  "P_22A": TDataT,
1157
1367
  "P_NrWierszaNST": TNaturalny,
@@ -1170,10 +1380,10 @@ var init_fa3 = __esm({
1170
1380
  "P_22C1": TZnakowy.optional(),
1171
1381
  "P_22D": TZnakowy.optional(),
1172
1382
  "P_22D1": TZnakowy.optional()
1173
- })).min(1).max(1e4)) }), import_zod.z.object({ "P_22N": TWybor1 })]),
1383
+ }).strict()).min(1).max(1e4)) }).strict(), import_zod.z.object({ "P_22N": TWybor1 }).strict()]),
1174
1384
  "P_23": TWybor1_2,
1175
- "PMarzy": import_zod.z.union([import_zod.z.object({ "P_PMarzy": TWybor1, "P_PMarzy_2": TWybor1.optional(), "P_PMarzy_3_1": TWybor1.optional(), "P_PMarzy_3_2": TWybor1.optional(), "P_PMarzy_3_3": TWybor1.optional() }), import_zod.z.object({ "P_PMarzyN": TWybor1 })])
1176
- }),
1385
+ "PMarzy": import_zod.z.union([import_zod.z.object({ "P_PMarzy": TWybor1, "P_PMarzy_2": TWybor1.optional(), "P_PMarzy_3_1": TWybor1.optional(), "P_PMarzy_3_2": TWybor1.optional(), "P_PMarzy_3_3": TWybor1.optional() }).strict(), import_zod.z.object({ "P_PMarzyN": TWybor1 }).strict()])
1386
+ }).strict(),
1177
1387
  "RodzajFaktury": TRodzajFaktury,
1178
1388
  "PrzyczynaKorekty": TZnakowy.optional(),
1179
1389
  "TypKorekty": TTypKorekty.optional(),
@@ -1183,30 +1393,30 @@ var init_fa3 = __esm({
1183
1393
  "NrKSeF": TWybor1.optional(),
1184
1394
  "NrKSeFFaKorygowanej": TNumerKSeF.optional(),
1185
1395
  "NrKSeFN": TWybor1.optional()
1186
- })).min(1).max(5e4)).optional(),
1396
+ }).strict()).min(1).max(5e4)).optional(),
1187
1397
  "OkresFaKorygowanej": TZnakowy.optional(),
1188
1398
  "NrFaKorygowany": TZnakowy.optional(),
1189
1399
  "Podmiot1K": import_zod.z.object({
1190
1400
  "PrefiksPodatnika": TKodyKrajowUE.optional(),
1191
1401
  "DaneIdentyfikacyjne": TPodmiot1,
1192
1402
  "Adres": TAdres
1193
- }).optional(),
1403
+ }).strict().optional(),
1194
1404
  "Podmiot2K": import_zod.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod.z.array(import_zod.z.object({
1195
1405
  "DaneIdentyfikacyjne": TPodmiot2,
1196
1406
  "Adres": TAdres.optional(),
1197
1407
  "IDNabywcy": import_zod.z.string().min(1).max(32).optional()
1198
- })).min(0).max(101)).optional(),
1408
+ }).strict()).min(0).max(101)).optional(),
1199
1409
  "P_15ZK": TKwotowy.optional(),
1200
1410
  "KursWalutyZK": TIlosci.optional(),
1201
1411
  "ZaliczkaCzesciowa": import_zod.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod.z.array(import_zod.z.object({
1202
1412
  "P_6Z": TDataT,
1203
1413
  "P_15Z": TKwotowy,
1204
1414
  "KursWalutyZW": TIlosci.optional()
1205
- })).min(0).max(31)).optional(),
1415
+ }).strict()).min(0).max(31)).optional(),
1206
1416
  "FP": TWybor1.optional(),
1207
1417
  "TP": TWybor1.optional(),
1208
1418
  "DodatkowyOpis": import_zod.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod.z.array(TKluczWartosc).min(0).max(1e4)).optional(),
1209
- "FakturaZaliczkowa": import_zod.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod.z.array(import_zod.z.union([import_zod.z.object({ "NrKSeFZN": TWybor1, "NrFaZaliczkowej": TZnakowy }), import_zod.z.object({ "NrKSeFFaZaliczkowej": TNumerKSeF })])).min(0).max(100)).optional(),
1419
+ "FakturaZaliczkowa": import_zod.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod.z.array(import_zod.z.union([import_zod.z.object({ "NrKSeFZN": TWybor1, "NrFaZaliczkowej": TZnakowy }).strict(), import_zod.z.object({ "NrKSeFFaZaliczkowej": TNumerKSeF }).strict()])).min(0).max(100)).optional(),
1210
1420
  "ZwrotAkcyzy": TWybor1.optional(),
1211
1421
  "FaWiersz": import_zod.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod.z.array(import_zod.z.object({
1212
1422
  "NrWierszaFa": TNaturalny,
@@ -1234,21 +1444,21 @@ var init_fa3 = __esm({
1234
1444
  "Procedura": TOznaczenieProcedury.optional(),
1235
1445
  "KursWaluty": TIlosci.optional(),
1236
1446
  "StanPrzed": TWybor1.optional()
1237
- })).min(0).max(1e4)).optional(),
1447
+ }).strict()).min(0).max(1e4)).optional(),
1238
1448
  "Rozliczenie": import_zod.z.object({
1239
1449
  "Obciazenia": import_zod.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod.z.array(import_zod.z.object({
1240
1450
  "Kwota": TKwotowy,
1241
1451
  "Powod": TZnakowy
1242
- })).min(0).max(100)).optional(),
1452
+ }).strict()).min(0).max(100)).optional(),
1243
1453
  "SumaObciazen": TKwotowy.optional(),
1244
1454
  "Odliczenia": import_zod.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod.z.array(import_zod.z.object({
1245
1455
  "Kwota": TKwotowy,
1246
1456
  "Powod": TZnakowy
1247
- })).min(0).max(100)).optional(),
1457
+ }).strict()).min(0).max(100)).optional(),
1248
1458
  "SumaOdliczen": TKwotowy.optional(),
1249
1459
  "DoZaplaty": TKwotowy.optional(),
1250
1460
  "DoRozliczenia": TKwotowy.optional()
1251
- }).optional(),
1461
+ }).strict().optional(),
1252
1462
  "Platnosc": import_zod.z.object({
1253
1463
  "Zaplacono": TWybor1.optional(),
1254
1464
  "DataZaplaty": TData.optional(),
@@ -1259,15 +1469,15 @@ var init_fa3 = __esm({
1259
1469
  "FormaPlatnosci": TFormaPlatnosci.optional(),
1260
1470
  "PlatnoscInna": TWybor1.optional(),
1261
1471
  "OpisPlatnosci": TZnakowy.optional()
1262
- })).min(1).max(100)).optional(),
1472
+ }).strict()).min(1).max(100)).optional(),
1263
1473
  "TerminPlatnosci": import_zod.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod.z.array(import_zod.z.object({
1264
1474
  "Termin": TData.optional(),
1265
1475
  "TerminOpis": import_zod.z.object({
1266
1476
  "Ilosc": import_zod.z.coerce.number().int(),
1267
1477
  "Jednostka": TZnakowy50,
1268
1478
  "ZdarzeniePoczatkowe": TZnakowy
1269
- }).optional()
1270
- })).min(0).max(100)).optional(),
1479
+ }).strict().optional()
1480
+ }).strict()).min(0).max(100)).optional(),
1271
1481
  "FormaPlatnosci": TFormaPlatnosci.optional(),
1272
1482
  "PlatnoscInna": TWybor1.optional(),
1273
1483
  "OpisPlatnosci": TZnakowy.optional(),
@@ -1276,19 +1486,19 @@ var init_fa3 = __esm({
1276
1486
  "Skonto": import_zod.z.object({
1277
1487
  "WarunkiSkonta": TZnakowy,
1278
1488
  "WysokoscSkonta": TZnakowy
1279
- }).optional(),
1489
+ }).strict().optional(),
1280
1490
  "LinkDoPlatnosci": import_zod.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(),
1281
1491
  "IPKSeF": import_zod.z.string().min(1).max(13).regex(/^[0-9]{3}[a-zA-Z0-9]{10}$/).optional()
1282
- }).optional(),
1492
+ }).strict().optional(),
1283
1493
  "WarunkiTransakcji": import_zod.z.object({
1284
1494
  "Umowy": import_zod.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod.z.array(import_zod.z.object({
1285
1495
  "DataUmowy": TDataU.optional(),
1286
1496
  "NrUmowy": TZnakowy.optional()
1287
- })).min(0).max(100)).optional(),
1497
+ }).strict()).min(0).max(100)).optional(),
1288
1498
  "Zamowienia": import_zod.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod.z.array(import_zod.z.object({
1289
1499
  "DataZamowienia": TDataU.optional(),
1290
1500
  "NrZamowienia": TZnakowy.optional()
1291
- })).min(0).max(100)).optional(),
1501
+ }).strict()).min(0).max(100)).optional(),
1292
1502
  "NrPartiiTowaru": import_zod.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod.z.array(TZnakowy).min(0).max(1e3)).optional(),
1293
1503
  "WarunkiDostawy": TZnakowy.optional(),
1294
1504
  "KursUmowny": TIlosci.optional(),
@@ -1300,7 +1510,7 @@ var init_fa3 = __esm({
1300
1510
  "Przewoznik": import_zod.z.object({
1301
1511
  "DaneIdentyfikacyjne": TPodmiot2,
1302
1512
  "AdresPrzewoznika": TAdres
1303
- }).optional(),
1513
+ }).strict().optional(),
1304
1514
  "NrZleceniaTransportu": TZnakowy.optional(),
1305
1515
  "OpisLadunku": TLadunek.optional(),
1306
1516
  "LadunekInny": TWybor1.optional(),
@@ -1311,9 +1521,9 @@ var init_fa3 = __esm({
1311
1521
  "WysylkaZ": TAdres.optional(),
1312
1522
  "WysylkaPrzez": import_zod.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod.z.array(TAdres).min(0).max(20)).optional(),
1313
1523
  "WysylkaDo": TAdres.optional()
1314
- })).min(0).max(20)).optional(),
1524
+ }).strict()).min(0).max(20)).optional(),
1315
1525
  "PodmiotPosredniczacy": TWybor1.optional()
1316
- }).optional(),
1526
+ }).strict().optional(),
1317
1527
  "Zamowienie": import_zod.z.object({
1318
1528
  "WartoscZamowienia": TKwotowy,
1319
1529
  "ZamowienieWiersz": import_zod.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod.z.array(import_zod.z.object({
@@ -1337,24 +1547,24 @@ var init_fa3 = __esm({
1337
1547
  "ProceduraZ": TOznaczenieProceduryZ.optional(),
1338
1548
  "KwotaAkcyzyZ": TKwotowy.optional(),
1339
1549
  "StanPrzedZ": TWybor1.optional()
1340
- })).min(1).max(1e4))
1341
- }).optional()
1342
- }),
1550
+ }).strict()).min(1).max(1e4))
1551
+ }).strict().optional()
1552
+ }).strict(),
1343
1553
  "Stopka": import_zod.z.object({
1344
1554
  "Informacje": import_zod.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod.z.array(import_zod.z.object({
1345
1555
  "StopkaFaktury": TTekstowy.optional()
1346
- })).min(0).max(3)).optional(),
1556
+ }).strict()).min(0).max(3)).optional(),
1347
1557
  "Rejestry": import_zod.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod.z.array(import_zod.z.object({
1348
1558
  "PelnaNazwa": TZnakowy.optional(),
1349
1559
  "KRS": TNrKRS.optional(),
1350
1560
  "REGON": TNrREGON.optional(),
1351
1561
  "BDO": import_zod.z.string().min(1).max(9).optional()
1352
- })).min(0).max(100)).optional()
1353
- }).optional(),
1562
+ }).strict()).min(0).max(100)).optional()
1563
+ }).strict().optional(),
1354
1564
  "Zalacznik": import_zod.z.object({
1355
1565
  "BlokDanych": import_zod.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod.z.array(import_zod.z.any()).min(1).max(1e3))
1356
- }).optional()
1357
- });
1566
+ }).strict().optional()
1567
+ }).strict();
1358
1568
  }
1359
1569
  });
1360
1570
 
@@ -1372,18 +1582,18 @@ var init_fa2 = __esm({
1372
1582
  TDataCzas2 = import_zod2.z.string();
1373
1583
  TZnakowy3 = import_zod2.z.string().min(1).max(256);
1374
1584
  TNaglowek2 = import_zod2.z.object({
1375
- "KodFormularza": import_zod2.z.object({ "#text": TKodFormularza2, "@kodSystemowy": import_zod2.z.literal("FA (2)"), "@wersjaSchemy": import_zod2.z.literal("1-0E") }),
1585
+ "KodFormularza": import_zod2.z.object({ "#text": TKodFormularza2, "@kodSystemowy": import_zod2.z.literal("FA (2)"), "@wersjaSchemy": import_zod2.z.literal("1-0E") }).strict(),
1376
1586
  "WariantFormularza": import_zod2.z.literal("2"),
1377
1587
  "DataWytworzeniaFa": import_zod2.z.string(),
1378
1588
  "SystemInfo": TZnakowy3.optional()
1379
- });
1589
+ }).strict();
1380
1590
  TKodyKrajowUE2 = import_zod2.z.enum(["AT", "BE", "BG", "CY", "CZ", "DK", "EE", "FI", "FR", "DE", "EL", "HR", "HU", "IE", "IT", "LV", "LT", "LU", "MT", "NL", "PL", "PT", "RO", "SK", "SI", "ES", "SE", "XI"]);
1381
1591
  TNrNIP2 = import_zod2.z.string().regex(/^[1-9]((\d[1-9])|([1-9]\d))\d{7}$/);
1382
1592
  TZnakowy5122 = import_zod2.z.string().min(1).max(512);
1383
1593
  TPodmiot12 = import_zod2.z.object({
1384
1594
  "NIP": TNrNIP2,
1385
1595
  "Nazwa": TZnakowy5122
1386
- });
1596
+ }).strict();
1387
1597
  TKodKraju2 = import_zod2.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"]);
1388
1598
  TGLN2 = import_zod2.z.string().min(1).max(13);
1389
1599
  TAdres2 = import_zod2.z.object({
@@ -1391,7 +1601,7 @@ var init_fa2 = __esm({
1391
1601
  "AdresL1": TZnakowy5122,
1392
1602
  "AdresL2": TZnakowy5122.optional(),
1393
1603
  "GLN": TGLN2.optional()
1394
- });
1604
+ }).strict();
1395
1605
  TAdresEmail2 = import_zod2.z.string().min(3).max(255).regex(/^(.)+@(.)+$/);
1396
1606
  TNumerTelefonu2 = import_zod2.z.string().min(1).max(16);
1397
1607
  TStatusInfoPodatnika2 = import_zod2.z.enum(["1", "2", "3", "4"]);
@@ -1406,7 +1616,7 @@ var init_fa2 = __esm({
1406
1616
  "NrID": import_zod2.z.string().min(1).max(50).regex(/^[a-zA-Z0-9]{1,50}$/).optional(),
1407
1617
  "BrakID": TWybor12.optional(),
1408
1618
  "Nazwa": TZnakowy5122.optional()
1409
- });
1619
+ }).strict();
1410
1620
  TZnakowy502 = import_zod2.z.string().min(1).max(50);
1411
1621
  TZnakowy202 = import_zod2.z.string().min(1).max(20);
1412
1622
  TNIPIdWew2 = import_zod2.z.string().min(1).max(20).regex(/^[1-9]((\d[1-9])|([1-9]\d))\d{7}-\d{5}$/);
@@ -1419,7 +1629,7 @@ var init_fa2 = __esm({
1419
1629
  "NrID": import_zod2.z.string().min(1).max(50).regex(/^[a-zA-Z0-9]{1,50}$/).optional(),
1420
1630
  "BrakID": TWybor12.optional(),
1421
1631
  "Nazwa": TZnakowy5122.optional()
1422
- });
1632
+ }).strict();
1423
1633
  TRolaPodmiotu32 = import_zod2.z.enum(["1", "2", "3", "4", "5", "6", "7", "8", "9", "10"]);
1424
1634
  TProcentowy2 = import_zod2.z.coerce.number().min(0).max(100);
1425
1635
  TRolaPodmiotuUpowaznionego2 = import_zod2.z.enum(["1", "2", "3"]);
@@ -1437,7 +1647,7 @@ var init_fa2 = __esm({
1437
1647
  "NrWiersza": TNaturalny2.optional(),
1438
1648
  "Klucz": TZnakowy3,
1439
1649
  "Wartosc": TZnakowy3
1440
- });
1650
+ }).strict();
1441
1651
  TKwotowy22 = import_zod2.z.string().regex(/^-?([1-9]\d{0,13}|0)(\.\d{1,8})?$/);
1442
1652
  TStawkaPodatku2 = import_zod2.z.enum(["23", "22", "8", "7", "5", "4", "3", "0", "zw", "oo", "np"]);
1443
1653
  TGTU2 = import_zod2.z.enum(["GTU_01", "GTU_02", "GTU_03", "GTU_04", "GTU_05", "GTU_06", "GTU_07", "GTU_08", "GTU_09", "GTU_10", "GTU_11", "GTU_12", "GTU_13"]);
@@ -1452,7 +1662,7 @@ var init_fa2 = __esm({
1452
1662
  "RachunekWlasnyBanku": TRachunekWlasnyBanku2.optional(),
1453
1663
  "NazwaBanku": TZnakowy3.optional(),
1454
1664
  "OpisRachunku": TZnakowy3.optional()
1455
- });
1665
+ }).strict();
1456
1666
  TRodzajTransportu2 = import_zod2.z.enum(["1", "2", "3", "4", "5", "7", "8"]);
1457
1667
  TLadunek2 = import_zod2.z.enum(["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20"]);
1458
1668
  TOznaczenieProceduryZ2 = import_zod2.z.enum(["WSTO_EE", "IED", "TT_D", "B_SPV", "B_SPV_DOSTAWA", "B_MPV_PROWIZJA"]);
@@ -1471,13 +1681,13 @@ var init_fa2 = __esm({
1471
1681
  "AdresL1": TZnakowy5122,
1472
1682
  "AdresL2": TZnakowy5122.optional(),
1473
1683
  "GLN": TGLN2.optional()
1474
- }).optional(),
1684
+ }).strict().optional(),
1475
1685
  "DaneKontaktowe": import_zod2.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod2.z.array(import_zod2.z.object({
1476
1686
  "Email": TAdresEmail2.optional(),
1477
1687
  "Telefon": TNumerTelefonu2.optional()
1478
- })).min(0).max(3)).optional(),
1688
+ }).strict()).min(0).max(3)).optional(),
1479
1689
  "StatusInfoPodatnika": TStatusInfoPodatnika2.optional()
1480
- }),
1690
+ }).strict(),
1481
1691
  "Podmiot2": import_zod2.z.object({
1482
1692
  "NrEORI": TZnakowy3.optional(),
1483
1693
  "DaneIdentyfikacyjne": TPodmiot22,
@@ -1486,10 +1696,10 @@ var init_fa2 = __esm({
1486
1696
  "DaneKontaktowe": import_zod2.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod2.z.array(import_zod2.z.object({
1487
1697
  "Email": TAdresEmail2.optional(),
1488
1698
  "Telefon": TNumerTelefonu2.optional()
1489
- })).min(0).max(3)).optional(),
1699
+ }).strict()).min(0).max(3)).optional(),
1490
1700
  "NrKlienta": TZnakowy3.optional(),
1491
1701
  "IDNabywcy": import_zod2.z.string().min(1).max(32).optional()
1492
- }),
1702
+ }).strict(),
1493
1703
  "Podmiot3": import_zod2.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod2.z.array(import_zod2.z.object({
1494
1704
  "IDNabywcy": import_zod2.z.string().min(1).max(32).optional(),
1495
1705
  "NrEORI": TZnakowy3.optional(),
@@ -1499,13 +1709,13 @@ var init_fa2 = __esm({
1499
1709
  "DaneKontaktowe": import_zod2.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod2.z.array(import_zod2.z.object({
1500
1710
  "Email": TAdresEmail2.optional(),
1501
1711
  "Telefon": TNumerTelefonu2.optional()
1502
- })).min(0).max(3)).optional(),
1712
+ }).strict()).min(0).max(3)).optional(),
1503
1713
  "Rola": TRolaPodmiotu32.optional(),
1504
1714
  "RolaInna": TWybor12.optional(),
1505
1715
  "OpisRoli": TZnakowy3.optional(),
1506
1716
  "Udzial": TProcentowy2.optional(),
1507
1717
  "NrKlienta": TZnakowy3.optional()
1508
- })).min(0).max(100)).optional(),
1718
+ }).strict()).min(0).max(100)).optional(),
1509
1719
  "PodmiotUpowazniony": import_zod2.z.object({
1510
1720
  "NrEORI": TZnakowy3.optional(),
1511
1721
  "DaneIdentyfikacyjne": TPodmiot12,
@@ -1514,9 +1724,9 @@ var init_fa2 = __esm({
1514
1724
  "DaneKontaktowe": import_zod2.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod2.z.array(import_zod2.z.object({
1515
1725
  "EmailPU": TAdresEmail2.optional(),
1516
1726
  "TelefonPU": TNumerTelefonu2.optional()
1517
- })).min(0).max(3)).optional(),
1727
+ }).strict()).min(0).max(3)).optional(),
1518
1728
  "RolaPU": TRolaPodmiotuUpowaznionego2
1519
- }).optional(),
1729
+ }).strict().optional(),
1520
1730
  "Fa": import_zod2.z.object({
1521
1731
  "KodWaluty": TKodWaluty2,
1522
1732
  "P_1": TDataT2,
@@ -1527,7 +1737,7 @@ var init_fa2 = __esm({
1527
1737
  "OkresFa": import_zod2.z.object({
1528
1738
  "P_6_Od": TDataT2,
1529
1739
  "P_6_Do": TDataT2
1530
- }).optional(),
1740
+ }).strict().optional(),
1531
1741
  "P_13_1": TKwotowy3.optional(),
1532
1742
  "P_14_1": TKwotowy3.optional(),
1533
1743
  "P_14_1W": TKwotowy3.optional(),
@@ -1557,7 +1767,7 @@ var init_fa2 = __esm({
1557
1767
  "P_17": TWybor1_22,
1558
1768
  "P_18": TWybor1_22,
1559
1769
  "P_18A": TWybor1_22,
1560
- "Zwolnienie": import_zod2.z.union([import_zod2.z.object({ "P_19": TWybor12, "P_19A": TZnakowy3.optional(), "P_19B": TZnakowy3.optional(), "P_19C": TZnakowy3.optional() }), import_zod2.z.object({ "P_19N": TWybor12 })]),
1770
+ "Zwolnienie": import_zod2.z.union([import_zod2.z.object({ "P_19": TWybor12, "P_19A": TZnakowy3.optional(), "P_19B": TZnakowy3.optional(), "P_19C": TZnakowy3.optional() }).strict(), import_zod2.z.object({ "P_19N": TWybor12 }).strict()]),
1561
1771
  "NoweSrodkiTransportu": import_zod2.z.union([import_zod2.z.object({ "P_22": TWybor12, "P_42_5": TWybor1_22, "NowySrodekTransportu": import_zod2.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod2.z.array(import_zod2.z.object({
1562
1772
  "P_22A": TDataT2,
1563
1773
  "P_NrWierszaNST": TNaturalny2,
@@ -1576,10 +1786,10 @@ var init_fa2 = __esm({
1576
1786
  "P_22C1": TZnakowy3.optional(),
1577
1787
  "P_22D": TZnakowy3.optional(),
1578
1788
  "P_22D1": TZnakowy3.optional()
1579
- })).min(1).max(1e4)) }), import_zod2.z.object({ "P_22N": TWybor12 })]),
1789
+ }).strict()).min(1).max(1e4)) }).strict(), import_zod2.z.object({ "P_22N": TWybor12 }).strict()]),
1580
1790
  "P_23": TWybor1_22,
1581
- "PMarzy": import_zod2.z.union([import_zod2.z.object({ "P_PMarzy": TWybor12, "P_PMarzy_2": TWybor12.optional(), "P_PMarzy_3_1": TWybor12.optional(), "P_PMarzy_3_2": TWybor12.optional(), "P_PMarzy_3_3": TWybor12.optional() }), import_zod2.z.object({ "P_PMarzyN": TWybor12 })])
1582
- }),
1791
+ "PMarzy": import_zod2.z.union([import_zod2.z.object({ "P_PMarzy": TWybor12, "P_PMarzy_2": TWybor12.optional(), "P_PMarzy_3_1": TWybor12.optional(), "P_PMarzy_3_2": TWybor12.optional(), "P_PMarzy_3_3": TWybor12.optional() }).strict(), import_zod2.z.object({ "P_PMarzyN": TWybor12 }).strict()])
1792
+ }).strict(),
1583
1793
  "RodzajFaktury": TRodzajFaktury2,
1584
1794
  "PrzyczynaKorekty": TZnakowy3.optional(),
1585
1795
  "TypKorekty": TTypKorekty2.optional(),
@@ -1589,30 +1799,30 @@ var init_fa2 = __esm({
1589
1799
  "NrKSeF": TWybor12.optional(),
1590
1800
  "NrKSeFFaKorygowanej": TNumerKSeF2.optional(),
1591
1801
  "NrKSeFN": TWybor12.optional()
1592
- })).min(1)).optional(),
1802
+ }).strict()).min(1)).optional(),
1593
1803
  "OkresFaKorygowanej": TZnakowy3.optional(),
1594
1804
  "NrFaKorygowany": TZnakowy3.optional(),
1595
1805
  "Podmiot1K": import_zod2.z.object({
1596
1806
  "PrefiksPodatnika": TKodyKrajowUE2.optional(),
1597
1807
  "DaneIdentyfikacyjne": TPodmiot12,
1598
1808
  "Adres": TAdres2
1599
- }).optional(),
1809
+ }).strict().optional(),
1600
1810
  "Podmiot2K": import_zod2.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod2.z.array(import_zod2.z.object({
1601
1811
  "DaneIdentyfikacyjne": TPodmiot22,
1602
1812
  "Adres": TAdres2.optional(),
1603
1813
  "IDNabywcy": import_zod2.z.string().min(1).max(32).optional()
1604
- })).min(0).max(101)).optional(),
1814
+ }).strict()).min(0).max(101)).optional(),
1605
1815
  "P_15ZK": TKwotowy3.optional(),
1606
1816
  "KursWalutyZK": TIlosci2.optional(),
1607
1817
  "ZaliczkaCzesciowa": import_zod2.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod2.z.array(import_zod2.z.object({
1608
1818
  "P_6Z": TDataT2,
1609
1819
  "P_15Z": TKwotowy3,
1610
1820
  "KursWalutyZW": TIlosci2.optional()
1611
- })).min(0).max(31)).optional(),
1821
+ }).strict()).min(0).max(31)).optional(),
1612
1822
  "FP": TWybor12.optional(),
1613
1823
  "TP": TWybor12.optional(),
1614
1824
  "DodatkowyOpis": import_zod2.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod2.z.array(TKluczWartosc2).min(0).max(1e4)).optional(),
1615
- "FakturaZaliczkowa": import_zod2.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod2.z.array(import_zod2.z.union([import_zod2.z.object({ "NrKSeFZN": TWybor12, "NrFaZaliczkowej": TZnakowy3 }), import_zod2.z.object({ "NrKSeFFaZaliczkowej": TNumerKSeF2 })])).min(0).max(100)).optional(),
1825
+ "FakturaZaliczkowa": import_zod2.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod2.z.array(import_zod2.z.union([import_zod2.z.object({ "NrKSeFZN": TWybor12, "NrFaZaliczkowej": TZnakowy3 }).strict(), import_zod2.z.object({ "NrKSeFFaZaliczkowej": TNumerKSeF2 }).strict()])).min(0).max(100)).optional(),
1616
1826
  "ZwrotAkcyzy": TWybor12.optional(),
1617
1827
  "FaWiersz": import_zod2.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod2.z.array(import_zod2.z.object({
1618
1828
  "NrWierszaFa": TNaturalny2,
@@ -1640,21 +1850,21 @@ var init_fa2 = __esm({
1640
1850
  "Procedura": TOznaczenieProcedury2.optional(),
1641
1851
  "KursWaluty": TIlosci2.optional(),
1642
1852
  "StanPrzed": TWybor12.optional()
1643
- })).min(0).max(1e4)).optional(),
1853
+ }).strict()).min(0).max(1e4)).optional(),
1644
1854
  "Rozliczenie": import_zod2.z.object({
1645
1855
  "Obciazenia": import_zod2.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod2.z.array(import_zod2.z.object({
1646
1856
  "Kwota": TKwotowy3,
1647
1857
  "Powod": TZnakowy3
1648
- })).min(0).max(100)).optional(),
1858
+ }).strict()).min(0).max(100)).optional(),
1649
1859
  "SumaObciazen": TKwotowy3.optional(),
1650
1860
  "Odliczenia": import_zod2.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod2.z.array(import_zod2.z.object({
1651
1861
  "Kwota": TKwotowy3,
1652
1862
  "Powod": TZnakowy3
1653
- })).min(0).max(100)).optional(),
1863
+ }).strict()).min(0).max(100)).optional(),
1654
1864
  "SumaOdliczen": TKwotowy3.optional(),
1655
1865
  "DoZaplaty": TKwotowy3.optional(),
1656
1866
  "DoRozliczenia": TKwotowy3.optional()
1657
- }).optional(),
1867
+ }).strict().optional(),
1658
1868
  "Platnosc": import_zod2.z.object({
1659
1869
  "Zaplacono": TWybor12.optional(),
1660
1870
  "DataZaplaty": TData2.optional(),
@@ -1662,11 +1872,11 @@ var init_fa2 = __esm({
1662
1872
  "ZaplataCzesciowa": import_zod2.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod2.z.array(import_zod2.z.object({
1663
1873
  "KwotaZaplatyCzesciowej": TKwotowy3,
1664
1874
  "DataZaplatyCzesciowej": TData2
1665
- })).min(1).max(100)).optional(),
1875
+ }).strict()).min(1).max(100)).optional(),
1666
1876
  "TerminPlatnosci": import_zod2.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod2.z.array(import_zod2.z.object({
1667
1877
  "Termin": TData2,
1668
1878
  "TerminOpis": TZnakowy3.optional()
1669
- })).min(0).max(100)).optional(),
1879
+ }).strict()).min(0).max(100)).optional(),
1670
1880
  "FormaPlatnosci": TFormaPlatnosci2.optional(),
1671
1881
  "PlatnoscInna": TWybor12.optional(),
1672
1882
  "OpisPlatnosci": TZnakowy3.optional(),
@@ -1675,17 +1885,17 @@ var init_fa2 = __esm({
1675
1885
  "Skonto": import_zod2.z.object({
1676
1886
  "WarunkiSkonta": TZnakowy3,
1677
1887
  "WysokoscSkonta": TZnakowy3
1678
- }).optional()
1679
- }).optional(),
1888
+ }).strict().optional()
1889
+ }).strict().optional(),
1680
1890
  "WarunkiTransakcji": import_zod2.z.object({
1681
1891
  "Umowy": import_zod2.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod2.z.array(import_zod2.z.object({
1682
1892
  "DataUmowy": TData2.optional(),
1683
1893
  "NrUmowy": TZnakowy3.optional()
1684
- })).min(0).max(100)).optional(),
1894
+ }).strict()).min(0).max(100)).optional(),
1685
1895
  "Zamowienia": import_zod2.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod2.z.array(import_zod2.z.object({
1686
1896
  "DataZamowienia": TData2.optional(),
1687
1897
  "NrZamowienia": TZnakowy3.optional()
1688
- })).min(0).max(100)).optional(),
1898
+ }).strict()).min(0).max(100)).optional(),
1689
1899
  "NrPartiiTowaru": import_zod2.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod2.z.array(TZnakowy3).min(0).max(1e3)).optional(),
1690
1900
  "WarunkiDostawy": TZnakowy3.optional(),
1691
1901
  "KursUmowny": TIlosci2.optional(),
@@ -1697,7 +1907,7 @@ var init_fa2 = __esm({
1697
1907
  "Przewoznik": import_zod2.z.object({
1698
1908
  "DaneIdentyfikacyjne": TPodmiot22,
1699
1909
  "AdresPrzewoznika": TAdres2
1700
- }).optional(),
1910
+ }).strict().optional(),
1701
1911
  "NrZleceniaTransportu": TZnakowy3.optional(),
1702
1912
  "OpisLadunku": TLadunek2.optional(),
1703
1913
  "LadunekInny": TWybor12.optional(),
@@ -1708,9 +1918,9 @@ var init_fa2 = __esm({
1708
1918
  "WysylkaZ": TAdres2.optional(),
1709
1919
  "WysylkaPrzez": import_zod2.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod2.z.array(TAdres2).min(0).max(20)).optional(),
1710
1920
  "WysylkaDo": TAdres2.optional()
1711
- })).min(0).max(20)).optional(),
1921
+ }).strict()).min(0).max(20)).optional(),
1712
1922
  "PodmiotPosredniczacy": TWybor12.optional()
1713
- }).optional(),
1923
+ }).strict().optional(),
1714
1924
  "Zamowienie": import_zod2.z.object({
1715
1925
  "WartoscZamowienia": TKwotowy3,
1716
1926
  "ZamowienieWiersz": import_zod2.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod2.z.array(import_zod2.z.object({
@@ -1734,21 +1944,21 @@ var init_fa2 = __esm({
1734
1944
  "ProceduraZ": TOznaczenieProceduryZ2.optional(),
1735
1945
  "KwotaAkcyzyZ": TKwotowy3.optional(),
1736
1946
  "StanPrzedZ": TWybor12.optional()
1737
- })).min(1).max(1e4))
1738
- }).optional()
1739
- }),
1947
+ }).strict()).min(1).max(1e4))
1948
+ }).strict().optional()
1949
+ }).strict(),
1740
1950
  "Stopka": import_zod2.z.object({
1741
1951
  "Informacje": import_zod2.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod2.z.array(import_zod2.z.object({
1742
1952
  "StopkaFaktury": TTekstowy2.optional()
1743
- })).min(0).max(3)).optional(),
1953
+ }).strict()).min(0).max(3)).optional(),
1744
1954
  "Rejestry": import_zod2.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod2.z.array(import_zod2.z.object({
1745
1955
  "PelnaNazwa": TZnakowy3.optional(),
1746
1956
  "KRS": TNrKRS2.optional(),
1747
1957
  "REGON": TNrREGON2.optional(),
1748
1958
  "BDO": import_zod2.z.string().min(1).max(9).optional()
1749
- })).min(0).max(100)).optional()
1750
- }).optional()
1751
- });
1959
+ }).strict()).min(0).max(100)).optional()
1960
+ }).strict().optional()
1961
+ }).strict();
1752
1962
  }
1753
1963
  });
1754
1964
 
@@ -1766,17 +1976,17 @@ var init_rr1_v11e = __esm({
1766
1976
  TDataCzas3 = import_zod3.z.string();
1767
1977
  TZnakowy4 = import_zod3.z.string().min(1).max(256);
1768
1978
  TNaglowek3 = import_zod3.z.object({
1769
- "KodFormularza": import_zod3.z.object({ "#text": TKodFormularza3, "@kodSystemowy": import_zod3.z.literal("FA_RR (1)"), "@wersjaSchemy": import_zod3.z.literal("1-1E") }),
1979
+ "KodFormularza": import_zod3.z.object({ "#text": TKodFormularza3, "@kodSystemowy": import_zod3.z.literal("FA_RR (1)"), "@wersjaSchemy": import_zod3.z.literal("1-1E") }).strict(),
1770
1980
  "WariantFormularza": import_zod3.z.literal("1"),
1771
1981
  "DataWytworzeniaFa": import_zod3.z.string(),
1772
1982
  "SystemInfo": TZnakowy4.optional()
1773
- });
1983
+ }).strict();
1774
1984
  TNrNIP3 = import_zod3.z.string().regex(/^[1-9]((\d[1-9])|([1-9]\d))\d{7}$/);
1775
1985
  TZnakowy5123 = import_zod3.z.string().min(1).max(512);
1776
1986
  TPodmiot13 = import_zod3.z.object({
1777
1987
  "NIP": TNrNIP3,
1778
1988
  "Nazwa": TZnakowy5123
1779
- });
1989
+ }).strict();
1780
1990
  TKodKraju3 = import_zod3.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"]);
1781
1991
  TGLN3 = import_zod3.z.string().min(1).max(13);
1782
1992
  TAdres3 = import_zod3.z.object({
@@ -1784,7 +1994,7 @@ var init_rr1_v11e = __esm({
1784
1994
  "AdresL1": TZnakowy5123,
1785
1995
  "AdresL2": TZnakowy5123.optional(),
1786
1996
  "GLN": TGLN3.optional()
1787
- });
1997
+ }).strict();
1788
1998
  TAdresEmail3 = import_zod3.z.string().min(3).max(255).regex(/^(.)+@(.)+$/);
1789
1999
  TNumerTelefonu3 = import_zod3.z.string().min(1).max(16);
1790
2000
  TStatusInfoPodatnika3 = import_zod3.z.enum(["1", "2", "3", "4"]);
@@ -1796,7 +2006,7 @@ var init_rr1_v11e = __esm({
1796
2006
  "IDWew": TNIPIdWew3.optional(),
1797
2007
  "BrakID": TWybor13.optional(),
1798
2008
  "Nazwa": TZnakowy5123
1799
- });
2009
+ }).strict();
1800
2010
  TRolaPodmiotu33 = import_zod3.z.enum(["1", "2", "3", "5", "6", "7", "8", "9", "10", "11"]);
1801
2011
  TKodWaluty3 = import_zod3.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"]);
1802
2012
  TData3 = import_zod3.z.string();
@@ -1810,7 +2020,7 @@ var init_rr1_v11e = __esm({
1810
2020
  "NrWiersza": TNaturalny3.optional(),
1811
2021
  "Klucz": TZnakowy4,
1812
2022
  "Wartosc": TZnakowy4
1813
- });
2023
+ }).strict();
1814
2024
  TZnakowy503 = import_zod3.z.string().min(1).max(50);
1815
2025
  TIlosci3 = import_zod3.z.string().regex(/^-?([1-9]\d{0,15}|0)(\.\d{1,6})?$/);
1816
2026
  TKwotowy23 = import_zod3.z.string().regex(/^-?([1-9]\d{0,13}|0)(\.\d{1,8})?$/);
@@ -1824,7 +2034,7 @@ var init_rr1_v11e = __esm({
1824
2034
  "SWIFT": SWIFT_Type3.optional(),
1825
2035
  "NazwaBanku": TZnakowy4.optional(),
1826
2036
  "OpisRachunku": TZnakowy4.optional()
1827
- });
2037
+ }).strict();
1828
2038
  TTekstowy3 = import_zod3.z.string().min(1).max(3500);
1829
2039
  TNrKRS3 = import_zod3.z.string().regex(/^\d{10}$/);
1830
2040
  TNrREGON3 = import_zod3.z.union([import_zod3.z.string().regex(/^\d{9}$/), import_zod3.z.string().regex(/^\d{14}$/)]);
@@ -1837,9 +2047,9 @@ var init_rr1_v11e = __esm({
1837
2047
  "DaneKontaktowe": import_zod3.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod3.z.array(import_zod3.z.object({
1838
2048
  "Email": TAdresEmail3.optional(),
1839
2049
  "Telefon": TNumerTelefonu3.optional()
1840
- })).min(0).max(3)).optional(),
2050
+ }).strict()).min(0).max(3)).optional(),
1841
2051
  "NrKontrahenta": TZnakowy4.optional()
1842
- }),
2052
+ }).strict(),
1843
2053
  "Podmiot2": import_zod3.z.object({
1844
2054
  "DaneIdentyfikacyjne": TPodmiot13,
1845
2055
  "Adres": TAdres3,
@@ -1847,9 +2057,9 @@ var init_rr1_v11e = __esm({
1847
2057
  "DaneKontaktowe": import_zod3.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod3.z.array(import_zod3.z.object({
1848
2058
  "Email": TAdresEmail3.optional(),
1849
2059
  "Telefon": TNumerTelefonu3.optional()
1850
- })).min(0).max(3)).optional(),
2060
+ }).strict()).min(0).max(3)).optional(),
1851
2061
  "StatusInfoPodatnika": TStatusInfoPodatnika3.optional()
1852
- }),
2062
+ }).strict(),
1853
2063
  "Podmiot3": import_zod3.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod3.z.array(import_zod3.z.object({
1854
2064
  "DaneIdentyfikacyjne": TPodmiot33,
1855
2065
  "Adres": TAdres3.optional(),
@@ -1857,11 +2067,11 @@ var init_rr1_v11e = __esm({
1857
2067
  "DaneKontaktowe": import_zod3.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod3.z.array(import_zod3.z.object({
1858
2068
  "Email": TAdresEmail3.optional(),
1859
2069
  "Telefon": TNumerTelefonu3.optional()
1860
- })).min(0).max(3)).optional(),
2070
+ }).strict()).min(0).max(3)).optional(),
1861
2071
  "Rola": TRolaPodmiotu33.optional(),
1862
2072
  "RolaInna": TWybor13.optional(),
1863
2073
  "OpisRoli": TZnakowy4.optional()
1864
- })).min(0).max(100)).optional(),
2074
+ }).strict()).min(0).max(100)).optional(),
1865
2075
  "FakturaRR": import_zod3.z.object({
1866
2076
  "KodWaluty": TKodWaluty3,
1867
2077
  "P_1M": TZnakowy4.optional(),
@@ -1884,20 +2094,20 @@ var init_rr1_v11e = __esm({
1884
2094
  "NrKSeF": TWybor13.optional(),
1885
2095
  "NrKSeFFaKorygowanej": TNumerKSeF3.optional(),
1886
2096
  "NrKSeFN": TWybor13.optional()
1887
- })).min(1).max(5e4)).optional(),
2097
+ }).strict()).min(1).max(5e4)).optional(),
1888
2098
  "NrFaKorygowany": TZnakowy4.optional(),
1889
2099
  "Podmiot1K": import_zod3.z.object({
1890
2100
  "DaneIdentyfikacyjne": TPodmiot13,
1891
2101
  "Adres": TAdres3
1892
- }).optional(),
2102
+ }).strict().optional(),
1893
2103
  "Podmiot2K": import_zod3.z.object({
1894
2104
  "DaneIdentyfikacyjne": TPodmiot13,
1895
2105
  "Adres": TAdres3
1896
- }).optional(),
2106
+ }).strict().optional(),
1897
2107
  "DokumentZaplaty": import_zod3.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod3.z.array(import_zod3.z.object({
1898
2108
  "NrDokumentu": TZnakowy4,
1899
2109
  "DataDokumentu": TData3.optional()
1900
- })).min(0).max(50)).optional(),
2110
+ }).strict()).min(0).max(50)).optional(),
1901
2111
  "DodatkowyOpis": import_zod3.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod3.z.array(TKluczWartosc3).min(0).max(1e4)).optional(),
1902
2112
  "FakturaRRWiersz": import_zod3.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod3.z.array(import_zod3.z.object({
1903
2113
  "NrWierszaFa": TNaturalny3,
@@ -1917,21 +2127,21 @@ var init_rr1_v11e = __esm({
1917
2127
  "P_11": TKwotowy4,
1918
2128
  "StanPrzed": TWybor13.optional(),
1919
2129
  "KursWaluty": TIlosci3.optional()
1920
- })).min(0).max(1e4)).optional(),
2130
+ }).strict()).min(0).max(1e4)).optional(),
1921
2131
  "Rozliczenie": import_zod3.z.object({
1922
2132
  "Obciazenia": import_zod3.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod3.z.array(import_zod3.z.object({
1923
2133
  "Kwota": TKwotowy4,
1924
2134
  "Powod": TZnakowy4
1925
- })).min(0).max(100)).optional(),
2135
+ }).strict()).min(0).max(100)).optional(),
1926
2136
  "SumaObciazen": TKwotowy4.optional(),
1927
2137
  "Odliczenia": import_zod3.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod3.z.array(import_zod3.z.object({
1928
2138
  "Kwota": TKwotowy4,
1929
2139
  "Powod": TZnakowy4
1930
- })).min(0).max(100)).optional(),
2140
+ }).strict()).min(0).max(100)).optional(),
1931
2141
  "SumaOdliczen": TKwotowy4.optional(),
1932
2142
  "DoZaplaty": TKwotowy4.optional(),
1933
2143
  "DoRozliczenia": TKwotowy4.optional()
1934
- }).optional(),
2144
+ }).strict().optional(),
1935
2145
  "Platnosc": import_zod3.z.object({
1936
2146
  "FormaPlatnosci": TFormaPlatnosci3.optional(),
1937
2147
  "PlatnoscInna": TWybor13.optional(),
@@ -1940,20 +2150,20 @@ var init_rr1_v11e = __esm({
1940
2150
  "RachunekBankowy2": import_zod3.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod3.z.array(TRachunekBankowy3).min(0).max(3)).optional(),
1941
2151
  "IPKSeF": import_zod3.z.string().min(1).max(13).regex(/^[0-9]{3}[a-zA-Z0-9]{10}$/).optional(),
1942
2152
  "LinkDoPlatnosci": import_zod3.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()
1943
- }).optional()
1944
- }),
2153
+ }).strict().optional()
2154
+ }).strict(),
1945
2155
  "Stopka": import_zod3.z.object({
1946
2156
  "Informacje": import_zod3.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod3.z.array(import_zod3.z.object({
1947
2157
  "StopkaFaktury": TTekstowy3.optional()
1948
- })).min(0).max(3)).optional(),
2158
+ }).strict()).min(0).max(3)).optional(),
1949
2159
  "Rejestry": import_zod3.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod3.z.array(import_zod3.z.object({
1950
2160
  "PelnaNazwa": TZnakowy4.optional(),
1951
2161
  "KRS": TNrKRS3.optional(),
1952
2162
  "REGON": TNrREGON3.optional(),
1953
2163
  "BDO": import_zod3.z.string().min(1).max(9).optional()
1954
- })).min(0).max(100)).optional()
1955
- }).optional()
1956
- });
2164
+ }).strict()).min(0).max(100)).optional()
2165
+ }).strict().optional()
2166
+ }).strict();
1957
2167
  }
1958
2168
  });
1959
2169
 
@@ -1971,17 +2181,17 @@ var init_rr1_v10e = __esm({
1971
2181
  TDataCzas4 = import_zod4.z.string();
1972
2182
  TZnakowy5 = import_zod4.z.string().min(1).max(256);
1973
2183
  TNaglowek4 = import_zod4.z.object({
1974
- "KodFormularza": import_zod4.z.object({ "#text": TKodFormularza4, "@kodSystemowy": import_zod4.z.literal("FA_RR(1)"), "@wersjaSchemy": import_zod4.z.literal("1-0E") }),
2184
+ "KodFormularza": import_zod4.z.object({ "#text": TKodFormularza4, "@kodSystemowy": import_zod4.z.literal("FA_RR(1)"), "@wersjaSchemy": import_zod4.z.literal("1-0E") }).strict(),
1975
2185
  "WariantFormularza": import_zod4.z.literal("1"),
1976
2186
  "DataWytworzeniaFa": import_zod4.z.string(),
1977
2187
  "SystemInfo": TZnakowy5.optional()
1978
- });
2188
+ }).strict();
1979
2189
  TNrNIP4 = import_zod4.z.string().regex(/^[1-9]((\d[1-9])|([1-9]\d))\d{7}$/);
1980
2190
  TZnakowy5124 = import_zod4.z.string().min(1).max(512);
1981
2191
  TPodmiot14 = import_zod4.z.object({
1982
2192
  "NIP": TNrNIP4,
1983
2193
  "Nazwa": TZnakowy5124
1984
- });
2194
+ }).strict();
1985
2195
  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"]);
1986
2196
  TGLN4 = import_zod4.z.string().min(1).max(13);
1987
2197
  TAdres4 = import_zod4.z.object({
@@ -1989,7 +2199,7 @@ var init_rr1_v10e = __esm({
1989
2199
  "AdresL1": TZnakowy5124,
1990
2200
  "AdresL2": TZnakowy5124.optional(),
1991
2201
  "GLN": TGLN4.optional()
1992
- });
2202
+ }).strict();
1993
2203
  TAdresEmail4 = import_zod4.z.string().min(3).max(255).regex(/^(.)+@(.)+$/);
1994
2204
  TNumerTelefonu4 = import_zod4.z.string().min(1).max(16);
1995
2205
  TStatusInfoPodatnika4 = import_zod4.z.enum(["1", "2", "3", "4"]);
@@ -2001,7 +2211,7 @@ var init_rr1_v10e = __esm({
2001
2211
  "IDWew": TNIPIdWew4.optional(),
2002
2212
  "BrakID": TWybor14.optional(),
2003
2213
  "Nazwa": TZnakowy5124
2004
- });
2214
+ }).strict();
2005
2215
  TRolaPodmiotu34 = import_zod4.z.enum(["1", "2", "3", "5", "6", "7", "8", "9", "10", "11"]);
2006
2216
  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"]);
2007
2217
  TData4 = import_zod4.z.string();
@@ -2015,7 +2225,7 @@ var init_rr1_v10e = __esm({
2015
2225
  "NrWiersza": TNaturalny4.optional(),
2016
2226
  "Klucz": TZnakowy5,
2017
2227
  "Wartosc": TZnakowy5
2018
- });
2228
+ }).strict();
2019
2229
  TZnakowy504 = import_zod4.z.string().min(1).max(50);
2020
2230
  TIlosci4 = import_zod4.z.string().regex(/^-?([1-9]\d{0,15}|0)(\.\d{1,6})?$/);
2021
2231
  TKwotowy24 = import_zod4.z.string().regex(/^-?([1-9]\d{0,13}|0)(\.\d{1,8})?$/);
@@ -2029,7 +2239,7 @@ var init_rr1_v10e = __esm({
2029
2239
  "SWIFT": SWIFT_Type4.optional(),
2030
2240
  "NazwaBanku": TZnakowy5.optional(),
2031
2241
  "OpisRachunku": TZnakowy5.optional()
2032
- });
2242
+ }).strict();
2033
2243
  TTekstowy4 = import_zod4.z.string().min(1).max(3500);
2034
2244
  TNrKRS4 = import_zod4.z.string().regex(/^\d{10}$/);
2035
2245
  TNrREGON4 = import_zod4.z.union([import_zod4.z.string().regex(/^\d{9}$/), import_zod4.z.string().regex(/^\d{14}$/)]);
@@ -2042,9 +2252,9 @@ var init_rr1_v10e = __esm({
2042
2252
  "DaneKontaktowe": import_zod4.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod4.z.array(import_zod4.z.object({
2043
2253
  "Email": TAdresEmail4.optional(),
2044
2254
  "Telefon": TNumerTelefonu4.optional()
2045
- })).min(0).max(3)).optional(),
2255
+ }).strict()).min(0).max(3)).optional(),
2046
2256
  "NrKontrahenta": TZnakowy5.optional()
2047
- }),
2257
+ }).strict(),
2048
2258
  "Podmiot2": import_zod4.z.object({
2049
2259
  "DaneIdentyfikacyjne": TPodmiot14,
2050
2260
  "Adres": TAdres4,
@@ -2052,9 +2262,9 @@ var init_rr1_v10e = __esm({
2052
2262
  "DaneKontaktowe": import_zod4.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod4.z.array(import_zod4.z.object({
2053
2263
  "Email": TAdresEmail4.optional(),
2054
2264
  "Telefon": TNumerTelefonu4.optional()
2055
- })).min(0).max(3)).optional(),
2265
+ }).strict()).min(0).max(3)).optional(),
2056
2266
  "StatusInfoPodatnika": TStatusInfoPodatnika4.optional()
2057
- }),
2267
+ }).strict(),
2058
2268
  "Podmiot3": import_zod4.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod4.z.array(import_zod4.z.object({
2059
2269
  "DaneIdentyfikacyjne": TPodmiot34,
2060
2270
  "Adres": TAdres4.optional(),
@@ -2062,11 +2272,11 @@ var init_rr1_v10e = __esm({
2062
2272
  "DaneKontaktowe": import_zod4.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod4.z.array(import_zod4.z.object({
2063
2273
  "Email": TAdresEmail4.optional(),
2064
2274
  "Telefon": TNumerTelefonu4.optional()
2065
- })).min(0).max(3)).optional(),
2275
+ }).strict()).min(0).max(3)).optional(),
2066
2276
  "Rola": TRolaPodmiotu34.optional(),
2067
2277
  "RolaInna": TWybor14.optional(),
2068
2278
  "OpisRoli": TZnakowy5.optional()
2069
- })).min(0).max(100)).optional(),
2279
+ }).strict()).min(0).max(100)).optional(),
2070
2280
  "FakturaRR": import_zod4.z.object({
2071
2281
  "KodWaluty": TKodWaluty4,
2072
2282
  "P_1M": TZnakowy5.optional(),
@@ -2089,20 +2299,20 @@ var init_rr1_v10e = __esm({
2089
2299
  "NrKSeF": TWybor14.optional(),
2090
2300
  "NrKSeFFaKorygowanej": TNumerKSeF4.optional(),
2091
2301
  "NrKSeFN": TWybor14.optional()
2092
- })).min(1).max(5e4)).optional(),
2302
+ }).strict()).min(1).max(5e4)).optional(),
2093
2303
  "NrFaKorygowany": TZnakowy5.optional(),
2094
2304
  "Podmiot1K": import_zod4.z.object({
2095
2305
  "DaneIdentyfikacyjne": TPodmiot14,
2096
2306
  "Adres": TAdres4
2097
- }).optional(),
2307
+ }).strict().optional(),
2098
2308
  "Podmiot2K": import_zod4.z.object({
2099
2309
  "DaneIdentyfikacyjne": TPodmiot14,
2100
2310
  "Adres": TAdres4
2101
- }).optional(),
2311
+ }).strict().optional(),
2102
2312
  "DokumentZaplaty": import_zod4.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod4.z.array(import_zod4.z.object({
2103
2313
  "NrDokumentu": TZnakowy5,
2104
2314
  "DataDokumentu": TData4.optional()
2105
- })).min(0).max(50)).optional(),
2315
+ }).strict()).min(0).max(50)).optional(),
2106
2316
  "DodatkowyOpis": import_zod4.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod4.z.array(TKluczWartosc4).min(0).max(1e4)).optional(),
2107
2317
  "FakturaRRWiersz": import_zod4.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod4.z.array(import_zod4.z.object({
2108
2318
  "NrWierszaFa": TNaturalny4,
@@ -2122,21 +2332,21 @@ var init_rr1_v10e = __esm({
2122
2332
  "P_11": TKwotowy5,
2123
2333
  "StanPrzed": TWybor14.optional(),
2124
2334
  "KursWaluty": TIlosci4.optional()
2125
- })).min(0).max(1e4)).optional(),
2335
+ }).strict()).min(0).max(1e4)).optional(),
2126
2336
  "Rozliczenie": import_zod4.z.object({
2127
2337
  "Obciazenia": import_zod4.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod4.z.array(import_zod4.z.object({
2128
2338
  "Kwota": TKwotowy5,
2129
2339
  "Powod": TZnakowy5
2130
- })).min(0).max(100)).optional(),
2340
+ }).strict()).min(0).max(100)).optional(),
2131
2341
  "SumaObciazen": TKwotowy5.optional(),
2132
2342
  "Odliczenia": import_zod4.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod4.z.array(import_zod4.z.object({
2133
2343
  "Kwota": TKwotowy5,
2134
2344
  "Powod": TZnakowy5
2135
- })).min(0).max(100)).optional(),
2345
+ }).strict()).min(0).max(100)).optional(),
2136
2346
  "SumaOdliczen": TKwotowy5.optional(),
2137
2347
  "DoZaplaty": TKwotowy5.optional(),
2138
2348
  "DoRozliczenia": TKwotowy5.optional()
2139
- }).optional(),
2349
+ }).strict().optional(),
2140
2350
  "Platnosc": import_zod4.z.object({
2141
2351
  "FormaPlatnosci": TFormaPlatnosci4.optional(),
2142
2352
  "PlatnoscInna": TWybor14.optional(),
@@ -2145,20 +2355,20 @@ var init_rr1_v10e = __esm({
2145
2355
  "RachunekBankowy2": import_zod4.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod4.z.array(TRachunekBankowy4).min(0).max(3)).optional(),
2146
2356
  "IPKSeF": import_zod4.z.string().min(1).max(13).regex(/^[0-9]{3}[a-zA-Z0-9]{10}$/).optional(),
2147
2357
  "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()
2148
- }).optional()
2149
- }),
2358
+ }).strict().optional()
2359
+ }).strict(),
2150
2360
  "Stopka": import_zod4.z.object({
2151
2361
  "Informacje": import_zod4.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod4.z.array(import_zod4.z.object({
2152
2362
  "StopkaFaktury": TTekstowy4.optional()
2153
- })).min(0).max(3)).optional(),
2363
+ }).strict()).min(0).max(3)).optional(),
2154
2364
  "Rejestry": import_zod4.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod4.z.array(import_zod4.z.object({
2155
2365
  "PelnaNazwa": TZnakowy5.optional(),
2156
2366
  "KRS": TNrKRS4.optional(),
2157
2367
  "REGON": TNrREGON4.optional(),
2158
2368
  "BDO": import_zod4.z.string().min(1).max(9).optional()
2159
- })).min(0).max(100)).optional()
2160
- }).optional()
2161
- });
2369
+ }).strict()).min(0).max(100)).optional()
2370
+ }).strict().optional()
2371
+ }).strict();
2162
2372
  }
2163
2373
  });
2164
2374
 
@@ -2227,7 +2437,7 @@ var init_pef3 = __esm({
2227
2437
  "WithholdingTaxTotal": import_zod5.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod5.z.array(import_zod5.z.any()).min(0)).optional(),
2228
2438
  "LegalMonetaryTotal": import_zod5.z.any(),
2229
2439
  "InvoiceLine": import_zod5.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod5.z.array(import_zod5.z.any()).min(1))
2230
- });
2440
+ }).strict();
2231
2441
  PEF3Schema = InvoiceType;
2232
2442
  }
2233
2443
  });
@@ -2294,132 +2504,498 @@ var init_pef_kor3 = __esm({
2294
2504
  "TaxTotal": import_zod6.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod6.z.array(import_zod6.z.any()).min(0)).optional(),
2295
2505
  "LegalMonetaryTotal": import_zod6.z.any(),
2296
2506
  "CreditNoteLine": import_zod6.z.preprocess((v) => Array.isArray(v) ? v : v == null ? [] : [v], import_zod6.z.array(import_zod6.z.any()).min(1))
2297
- });
2507
+ }).strict();
2298
2508
  PEF_KOR3Schema = CreditNoteType;
2299
2509
  }
2300
2510
  });
2301
2511
 
2302
- // src/services/auth.ts
2303
- var AuthService;
2304
- var init_auth = __esm({
2305
- "src/services/auth.ts"() {
2512
+ // src/validation/schemas/index.ts
2513
+ var NAMESPACE_MAP;
2514
+ var init_schemas = __esm({
2515
+ "src/validation/schemas/index.ts"() {
2306
2516
  "use strict";
2307
- init_ksef_feature();
2308
- init_rest_request();
2309
- init_routes();
2310
- AuthService = class {
2311
- restClient;
2312
- constructor(restClient) {
2313
- this.restClient = restClient;
2314
- }
2315
- async getChallenge() {
2316
- const request = RestRequest.post(Routes.Authorization.challenge);
2317
- const response = await this.restClient.execute(request);
2318
- return response.body;
2319
- }
2320
- async submitXadesAuthRequest(signedXml, verifyCertificateChain = false, enforceXadesCompliance = false) {
2321
- const request = RestRequest.post(Routes.Authorization.xadesSignature).body(signedXml).header("Content-Type", "application/xml").query("verifyCertificateChain", String(verifyCertificateChain));
2322
- if (enforceXadesCompliance) {
2323
- request.header(KSEF_FEATURE_HEADER, ENFORCE_XADES_COMPLIANCE);
2324
- }
2325
- const response = await this.restClient.execute(request);
2326
- return response.body;
2327
- }
2328
- async submitKsefTokenAuthRequest(payload) {
2329
- const request = RestRequest.post(Routes.Authorization.ksefToken).body(payload);
2330
- const response = await this.restClient.execute(request);
2331
- return response.body;
2332
- }
2333
- async getAuthStatus(referenceNumber, authToken) {
2334
- const request = RestRequest.get(Routes.Authorization.status(referenceNumber)).accessToken(authToken);
2335
- const response = await this.restClient.execute(request);
2336
- return response.body;
2337
- }
2338
- async getAccessToken(authToken) {
2339
- const request = RestRequest.post(Routes.Authorization.Token.redeem).accessToken(authToken);
2340
- const response = await this.restClient.execute(request);
2341
- return response.body;
2342
- }
2343
- async refreshAccessToken(refreshToken) {
2344
- const request = RestRequest.post(Routes.Authorization.Token.refresh).accessToken(refreshToken).skipAuthRetry();
2345
- const response = await this.restClient.execute(request);
2346
- return response.body;
2347
- }
2517
+ init_fa3();
2518
+ init_fa2();
2519
+ init_rr1_v11e();
2520
+ init_rr1_v10e();
2521
+ init_pef3();
2522
+ init_pef_kor3();
2523
+ NAMESPACE_MAP = {
2524
+ "http://crd.gov.pl/wzor/2025/06/25/13775/": "FA3",
2525
+ "http://crd.gov.pl/wzor/2023/06/29/12648/": "FA2",
2526
+ "http://crd.gov.pl/wzor/2026/03/06/14189/": "RR1_V11E",
2527
+ "http://crd.gov.pl/wzor/2026/02/17/14164/": "RR1_V10E",
2528
+ "urn:oasis:names:specification:ubl:schema:xsd:Invoice-2": "PEF3",
2529
+ "urn:oasis:names:specification:ubl:schema:xsd:CreditNote-2": "PEF_KOR3"
2348
2530
  };
2349
2531
  }
2350
2532
  });
2351
2533
 
2352
- // src/services/active-sessions.ts
2353
- var ActiveSessionsService;
2354
- var init_active_sessions = __esm({
2355
- "src/services/active-sessions.ts"() {
2534
+ // src/validation/schema-registry.ts
2535
+ async function loadSchema(type) {
2536
+ const cached = schemaCache.get(type);
2537
+ if (cached) return cached;
2538
+ let mod;
2539
+ switch (type) {
2540
+ case "FA3":
2541
+ mod = await Promise.resolve().then(() => (init_fa3(), fa3_exports));
2542
+ break;
2543
+ case "FA2":
2544
+ mod = await Promise.resolve().then(() => (init_fa2(), fa2_exports));
2545
+ break;
2546
+ case "RR1_V11E":
2547
+ mod = await Promise.resolve().then(() => (init_rr1_v11e(), rr1_v11e_exports));
2548
+ break;
2549
+ case "RR1_V10E":
2550
+ mod = await Promise.resolve().then(() => (init_rr1_v10e(), rr1_v10e_exports));
2551
+ break;
2552
+ case "PEF3":
2553
+ mod = await Promise.resolve().then(() => (init_pef3(), pef3_exports));
2554
+ break;
2555
+ case "PEF_KOR3":
2556
+ mod = await Promise.resolve().then(() => (init_pef_kor3(), pef_kor3_exports));
2557
+ break;
2558
+ default:
2559
+ throw new Error(`Unknown schema type: ${type}`);
2560
+ }
2561
+ const exportName = `${type}Schema`;
2562
+ const schema = mod[exportName];
2563
+ if (!schema) {
2564
+ throw new Error(`Schema export "${exportName}" not found in module for type "${type}"`);
2565
+ }
2566
+ schemaCache.set(type, schema);
2567
+ return schema;
2568
+ }
2569
+ var ROOT_ELEMENT_MAP, schemaCache, SchemaRegistry;
2570
+ var init_schema_registry = __esm({
2571
+ "src/validation/schema-registry.ts"() {
2356
2572
  "use strict";
2357
- init_rest_request();
2358
- init_routes();
2359
- ActiveSessionsService = class {
2360
- restClient;
2361
- constructor(restClient) {
2362
- this.restClient = restClient;
2363
- }
2364
- async getActiveSessions(pageSize, continuationToken) {
2365
- const request = RestRequest.get(Routes.ActiveSessions.session);
2366
- if (pageSize !== void 0) request.query("pageSize", String(pageSize));
2367
- if (continuationToken !== void 0) request.header("x-continuation-token", continuationToken);
2368
- const response = await this.restClient.execute(request);
2369
- return response.body;
2370
- }
2371
- async revokeCurrentSession() {
2372
- const request = RestRequest.delete(Routes.ActiveSessions.currentSession);
2373
- await this.restClient.executeVoid(request);
2374
- }
2375
- async revokeSession(sessionRef) {
2376
- const request = RestRequest.delete(Routes.ActiveSessions.delete(sessionRef));
2377
- await this.restClient.executeVoid(request);
2573
+ init_schemas();
2574
+ ROOT_ELEMENT_MAP = {
2575
+ Invoice: "PEF3",
2576
+ CreditNote: "PEF_KOR3"
2577
+ };
2578
+ schemaCache = /* @__PURE__ */ new Map();
2579
+ SchemaRegistry = {
2580
+ /**
2581
+ * Get a Zod schema by type. Lazy-loads the module on first access.
2582
+ */
2583
+ async get(type) {
2584
+ return loadSchema(type);
2585
+ },
2586
+ /**
2587
+ * List all available schema types.
2588
+ */
2589
+ availableSchemas() {
2590
+ return ["FA3", "FA2", "RR1_V11E", "RR1_V10E", "PEF3", "PEF_KOR3"];
2591
+ },
2592
+ /**
2593
+ * Detect schema type from XML namespace URI and/or root element name.
2594
+ *
2595
+ * Detection priority:
2596
+ * 1. Namespace URI match (unique per FA/RR schemas)
2597
+ * 2. Root element name match (for PEF/PEF_KOR which use UBL namespaces)
2598
+ */
2599
+ detect(namespace, rootElement) {
2600
+ if (namespace) {
2601
+ const byNs = NAMESPACE_MAP[namespace];
2602
+ if (byNs) return byNs;
2603
+ }
2604
+ if (rootElement) {
2605
+ const byRoot = ROOT_ELEMENT_MAP[rootElement];
2606
+ if (byRoot) return byRoot;
2607
+ }
2608
+ return null;
2378
2609
  }
2379
2610
  };
2380
2611
  }
2381
2612
  });
2382
2613
 
2383
- // src/services/online-session.ts
2384
- var OnlineSessionService;
2385
- var init_online_session = __esm({
2386
- "src/services/online-session.ts"() {
2387
- "use strict";
2388
- init_ksef_feature();
2389
- init_rest_request();
2390
- init_routes();
2391
- OnlineSessionService = class {
2392
- restClient;
2393
- constructor(restClient) {
2394
- this.restClient = restClient;
2395
- }
2396
- async openSession(request, upoVersion) {
2397
- const req = RestRequest.post(Routes.Sessions.Online.open).body(request);
2398
- if (upoVersion) {
2399
- req.header(KSEF_FEATURE_HEADER, upoVersion);
2400
- }
2401
- const response = await this.restClient.execute(req);
2402
- return response.body;
2614
+ // src/validation/invoice-validator.ts
2615
+ var invoice_validator_exports = {};
2616
+ __export(invoice_validator_exports, {
2617
+ batchValidationDetails: () => batchValidationDetails,
2618
+ validate: () => validate,
2619
+ validateBatch: () => validateBatch,
2620
+ validateBusinessRules: () => validateBusinessRules,
2621
+ validateSchema: () => validateSchema,
2622
+ validateWellFormedness: () => validateWellFormedness
2623
+ });
2624
+ function validateWellFormedness(xml, _parsed) {
2625
+ if (!xml || !xml.trim()) {
2626
+ return {
2627
+ valid: false,
2628
+ schemaType: null,
2629
+ errors: [{ code: "MALFORMED_XML", message: "Empty XML input" }]
2630
+ };
2631
+ }
2632
+ const { object, rootElement, namespace, errors } = _parsed ?? xmlToObject(xml);
2633
+ if (errors.length > 0 || !object) {
2634
+ return {
2635
+ valid: false,
2636
+ schemaType: null,
2637
+ errors: errors.map((msg) => ({ code: "MALFORMED_XML", message: msg }))
2638
+ };
2639
+ }
2640
+ const schemaType = SchemaRegistry.detect(namespace, rootElement);
2641
+ return { valid: true, schemaType, errors: [] };
2642
+ }
2643
+ async function validateSchema(xml, options, _parsed) {
2644
+ const { object, rootElement, namespace, errors: parseErrors } = _parsed ?? xmlToObject(xml);
2645
+ if (parseErrors.length > 0 || !object) {
2646
+ return {
2647
+ valid: false,
2648
+ schemaType: null,
2649
+ errors: parseErrors.map((msg) => ({ code: "MALFORMED_XML", message: msg }))
2650
+ };
2651
+ }
2652
+ const schemaType = options?.schema ?? SchemaRegistry.detect(namespace, rootElement);
2653
+ if (!schemaType) {
2654
+ return {
2655
+ valid: false,
2656
+ schemaType: null,
2657
+ errors: [{
2658
+ code: "UNKNOWN_SCHEMA",
2659
+ message: `Cannot detect schema type from namespace "${namespace}" and root element "${rootElement}"`
2660
+ }]
2661
+ };
2662
+ }
2663
+ const schema = await SchemaRegistry.get(schemaType);
2664
+ const result = schema.safeParse(object);
2665
+ if (result.success) {
2666
+ return { valid: true, schemaType, errors: [] };
2667
+ }
2668
+ const prefix = rootElement ? `/${rootElement}/` : "/";
2669
+ const validationErrors = result.error.issues.map((issue) => {
2670
+ const zodPath = issue.path.join("/");
2671
+ const path2 = zodPath ? `${prefix}${zodPath}` : rootElement ? `/${rootElement}` : void 0;
2672
+ return {
2673
+ code: mapZodErrorCode(issue),
2674
+ message: issue.message,
2675
+ path: path2
2676
+ };
2677
+ });
2678
+ return { valid: false, schemaType, errors: validationErrors };
2679
+ }
2680
+ function mapZodErrorCode(issue) {
2681
+ switch (issue.code) {
2682
+ case "invalid_type":
2683
+ return issue.input === void 0 ? "MISSING_REQUIRED_ELEMENT" : "INVALID_VALUE";
2684
+ case "invalid_enum_value":
2685
+ // Zod v3
2686
+ case "invalid_value":
2687
+ return "INVALID_ENUM_VALUE";
2688
+ case "invalid_string":
2689
+ // Zod v3
2690
+ case "invalid_format":
2691
+ return "PATTERN_MISMATCH";
2692
+ case "too_big":
2693
+ return "MAX_OCCURS_EXCEEDED";
2694
+ case "unrecognized_keys":
2695
+ return "UNRECOGNIZED_KEY";
2696
+ default:
2697
+ return "SCHEMA_VALIDATION_ERROR";
2698
+ }
2699
+ }
2700
+ function validateBusinessRules(xml, _parsed) {
2701
+ const { object, rootElement, namespace, errors: parseErrors } = _parsed ?? xmlToObject(xml);
2702
+ if (parseErrors.length > 0 || !object) {
2703
+ return {
2704
+ valid: false,
2705
+ schemaType: null,
2706
+ errors: parseErrors.map((msg) => ({ code: "MALFORMED_XML", message: msg }))
2707
+ };
2708
+ }
2709
+ const schemaType = SchemaRegistry.detect(namespace, rootElement);
2710
+ const errors = [];
2711
+ collectNipPeselErrors(object, rootElement ? `/${rootElement}` : "", errors);
2712
+ collectDateErrors(object, rootElement, errors);
2713
+ return { valid: errors.length === 0, schemaType, errors };
2714
+ }
2715
+ function collectNipPeselErrors(obj, path2, errors) {
2716
+ for (const [key, value] of Object.entries(obj)) {
2717
+ const currentPath = path2 ? `${path2}/${key}` : key;
2718
+ if (key === "NIP" && typeof value === "string") {
2719
+ if (!isValidNip(value)) {
2720
+ errors.push({
2721
+ code: "INVALID_NIP_CHECKSUM",
2722
+ message: `Invalid NIP checksum: ${value}`,
2723
+ path: currentPath
2724
+ });
2403
2725
  }
2404
- async sendInvoice(sessionRef, request) {
2405
- const req = RestRequest.post(Routes.Sessions.Online.invoices(sessionRef)).body(request);
2406
- const response = await this.restClient.execute(req);
2407
- return response.body;
2726
+ } else if (key === "PESEL" && typeof value === "string") {
2727
+ if (!isValidPesel(value)) {
2728
+ errors.push({
2729
+ code: "INVALID_PESEL_CHECKSUM",
2730
+ message: `Invalid PESEL checksum: ${value}`,
2731
+ path: currentPath
2732
+ });
2408
2733
  }
2409
- async closeSession(sessionRef) {
2410
- const req = RestRequest.post(Routes.Sessions.Online.close(sessionRef));
2411
- await this.restClient.executeVoid(req);
2734
+ } else if (typeof value === "object" && value !== null) {
2735
+ if (Array.isArray(value)) {
2736
+ for (let i = 0; i < value.length; i++) {
2737
+ if (typeof value[i] === "object" && value[i] !== null) {
2738
+ collectNipPeselErrors(value[i], `${currentPath}/${i}`, errors);
2739
+ }
2740
+ }
2741
+ } else {
2742
+ collectNipPeselErrors(value, currentPath, errors);
2412
2743
  }
2413
- };
2744
+ }
2745
+ }
2746
+ }
2747
+ function getPolandLocalDate() {
2748
+ return new Intl.DateTimeFormat("sv-SE", { timeZone: "Europe/Warsaw" }).format(Date.now());
2749
+ }
2750
+ function collectDateErrors(obj, rootElement, errors) {
2751
+ const fa = obj["Fa"];
2752
+ if (!fa || typeof fa !== "object") return;
2753
+ const p1 = fa["P_1"];
2754
+ if (typeof p1 !== "string") return;
2755
+ const today = getPolandLocalDate();
2756
+ if (p1 > today) {
2757
+ const prefix = rootElement ? `/${rootElement}` : "";
2758
+ errors.push({
2759
+ code: "FUTURE_INVOICE_DATE",
2760
+ message: `Invoice date P_1 (${p1}) is in the future \u2014 KSeF rejects invoices with P_1 > today (${today})`,
2761
+ path: `${prefix}/Fa/P_1`
2762
+ });
2763
+ }
2764
+ }
2765
+ async function validate(xml, options) {
2766
+ const parsed = xml && xml.trim() ? xmlToObject(xml) : void 0;
2767
+ const l1 = validateWellFormedness(xml, parsed);
2768
+ if (!l1.valid) return l1;
2769
+ const l2 = await validateSchema(xml, options, parsed);
2770
+ if (!l2.valid) return l2;
2771
+ const l3 = validateBusinessRules(xml, parsed);
2772
+ return { ...l3, schemaType: l2.schemaType };
2773
+ }
2774
+ async function validateBatch(invoices, options) {
2775
+ const results = [];
2776
+ for (const { fileName, xml } of invoices) {
2777
+ results.push({ fileName, result: await validate(xml, options) });
2778
+ }
2779
+ return { valid: results.every((r) => r.result.valid), results };
2780
+ }
2781
+ function batchValidationDetails(batch) {
2782
+ return batch.results.filter((r) => !r.result.valid).flatMap((r) => r.result.errors.map((e) => ({
2783
+ field: e.path ? `${r.fileName}:${e.path}` : r.fileName,
2784
+ message: e.message
2785
+ })));
2786
+ }
2787
+ var init_invoice_validator = __esm({
2788
+ "src/validation/invoice-validator.ts"() {
2789
+ "use strict";
2790
+ init_xml_to_object();
2791
+ init_schema_registry();
2792
+ init_patterns();
2414
2793
  }
2415
2794
  });
2416
2795
 
2417
- // src/services/batch-session.ts
2418
- var BatchSessionService;
2419
- var init_batch_session = __esm({
2420
- "src/services/batch-session.ts"() {
2796
+ // src/models/document-structures/types.ts
2797
+ var SystemCode, FORM_CODES, DEFAULT_FORM_CODE, INVOICE_TYPES_BY_SYSTEM_CODE, FORM_CODE_KEYS;
2798
+ var init_types = __esm({
2799
+ "src/models/document-structures/types.ts"() {
2421
2800
  "use strict";
2422
- init_ksef_feature();
2801
+ SystemCode = {
2802
+ FA_2: "FA (2)",
2803
+ FA_3: "FA (3)",
2804
+ PEF_3: "PEF (3)",
2805
+ PEF_KOR_3: "PEF_KOR (3)",
2806
+ FA_RR_1: "FA_RR (1)"
2807
+ };
2808
+ FORM_CODES = {
2809
+ FA_2: { systemCode: "FA (2)", schemaVersion: "1-0E", value: "FA" },
2810
+ FA_3: { systemCode: "FA (3)", schemaVersion: "1-0E", value: "FA" },
2811
+ PEF_3: { systemCode: "PEF (3)", schemaVersion: "2-1", value: "PEF" },
2812
+ PEF_KOR_3: { systemCode: "PEF_KOR (3)", schemaVersion: "2-1", value: "PEF" },
2813
+ FA_RR_1_LEGACY: { systemCode: "FA_RR (1)", schemaVersion: "1-0E", value: "RR" },
2814
+ FA_RR_1_TRANSITION: { systemCode: "FA_RR (1)", schemaVersion: "1-1E", value: "RR" },
2815
+ FA_RR_1: { systemCode: "FA_RR (1)", schemaVersion: "1-1E", value: "FA_RR" }
2816
+ };
2817
+ DEFAULT_FORM_CODE = FORM_CODES.FA_3;
2818
+ INVOICE_TYPES_BY_SYSTEM_CODE = {
2819
+ [SystemCode.FA_2]: ["Vat", "Zal", "Kor", "Roz", "Upr", "KorZal", "KorRoz"],
2820
+ [SystemCode.FA_3]: ["Vat", "Zal", "Kor", "Roz", "Upr", "KorZal", "KorRoz"],
2821
+ [SystemCode.PEF_3]: ["VatPef", "VatPefSp", "KorPef"],
2822
+ [SystemCode.PEF_KOR_3]: ["KorPef"],
2823
+ [SystemCode.FA_RR_1]: ["VatRr", "KorVatRr"]
2824
+ };
2825
+ FORM_CODE_KEYS = {
2826
+ FA2: FORM_CODES.FA_2,
2827
+ FA3: FORM_CODES.FA_3,
2828
+ PEF3: FORM_CODES.PEF_3,
2829
+ PEFKOR3: FORM_CODES.PEF_KOR_3,
2830
+ FARR1: FORM_CODES.FA_RR_1
2831
+ };
2832
+ }
2833
+ });
2834
+
2835
+ // src/models/document-structures/helpers.ts
2836
+ function getFormCode(systemCode) {
2837
+ return SYSTEM_CODE_TO_FORM_CODE[systemCode];
2838
+ }
2839
+ function parseFormCode(raw) {
2840
+ const match = ALL_FORM_CODES.find(
2841
+ (fc) => fc.systemCode === raw.systemCode && fc.schemaVersion === raw.schemaVersion && fc.value === raw.value
2842
+ );
2843
+ return match ?? raw;
2844
+ }
2845
+ function validateFormCodeForSession(formCode, sessionType) {
2846
+ if (sessionType === "online") return true;
2847
+ return !BATCH_DISALLOWED_SYSTEM_CODES.has(formCode.systemCode);
2848
+ }
2849
+ var SYSTEM_CODE_TO_FORM_CODE, ALL_FORM_CODES, BATCH_DISALLOWED_SYSTEM_CODES;
2850
+ var init_helpers = __esm({
2851
+ "src/models/document-structures/helpers.ts"() {
2852
+ "use strict";
2853
+ init_types();
2854
+ SYSTEM_CODE_TO_FORM_CODE = {
2855
+ [SystemCode.FA_2]: FORM_CODES.FA_2,
2856
+ [SystemCode.FA_3]: FORM_CODES.FA_3,
2857
+ [SystemCode.PEF_3]: FORM_CODES.PEF_3,
2858
+ [SystemCode.PEF_KOR_3]: FORM_CODES.PEF_KOR_3,
2859
+ [SystemCode.FA_RR_1]: FORM_CODES.FA_RR_1
2860
+ };
2861
+ ALL_FORM_CODES = Object.values(FORM_CODES);
2862
+ BATCH_DISALLOWED_SYSTEM_CODES = /* @__PURE__ */ new Set([
2863
+ SystemCode.PEF_3,
2864
+ SystemCode.PEF_KOR_3
2865
+ ]);
2866
+ }
2867
+ });
2868
+
2869
+ // src/models/document-structures/index.ts
2870
+ var init_document_structures = __esm({
2871
+ "src/models/document-structures/index.ts"() {
2872
+ "use strict";
2873
+ init_types();
2874
+ init_helpers();
2875
+ }
2876
+ });
2877
+
2878
+ // src/services/auth.ts
2879
+ var AuthService;
2880
+ var init_auth = __esm({
2881
+ "src/services/auth.ts"() {
2882
+ "use strict";
2883
+ init_ksef_feature();
2884
+ init_rest_request();
2885
+ init_routes();
2886
+ AuthService = class {
2887
+ restClient;
2888
+ constructor(restClient) {
2889
+ this.restClient = restClient;
2890
+ }
2891
+ async getChallenge() {
2892
+ const request = RestRequest.post(Routes.Authorization.challenge);
2893
+ const response = await this.restClient.execute(request);
2894
+ return response.body;
2895
+ }
2896
+ async submitXadesAuthRequest(signedXml, verifyCertificateChain = false, enforceXadesCompliance = false) {
2897
+ const request = RestRequest.post(Routes.Authorization.xadesSignature).body(signedXml).header("Content-Type", "application/xml").query("verifyCertificateChain", String(verifyCertificateChain));
2898
+ if (enforceXadesCompliance) {
2899
+ request.header(KSEF_FEATURE_HEADER, ENFORCE_XADES_COMPLIANCE);
2900
+ }
2901
+ const response = await this.restClient.execute(request);
2902
+ return response.body;
2903
+ }
2904
+ async submitKsefTokenAuthRequest(payload) {
2905
+ const request = RestRequest.post(Routes.Authorization.ksefToken).body(payload);
2906
+ const response = await this.restClient.execute(request);
2907
+ return response.body;
2908
+ }
2909
+ async getAuthStatus(referenceNumber, authToken) {
2910
+ const request = RestRequest.get(Routes.Authorization.status(referenceNumber)).accessToken(authToken);
2911
+ const response = await this.restClient.execute(request);
2912
+ return response.body;
2913
+ }
2914
+ async getAccessToken(authToken) {
2915
+ const request = RestRequest.post(Routes.Authorization.Token.redeem).accessToken(authToken);
2916
+ const response = await this.restClient.execute(request);
2917
+ return response.body;
2918
+ }
2919
+ async refreshAccessToken(refreshToken) {
2920
+ const request = RestRequest.post(Routes.Authorization.Token.refresh).accessToken(refreshToken).skipAuthRetry();
2921
+ const response = await this.restClient.execute(request);
2922
+ return response.body;
2923
+ }
2924
+ };
2925
+ }
2926
+ });
2927
+
2928
+ // src/services/active-sessions.ts
2929
+ var ActiveSessionsService;
2930
+ var init_active_sessions = __esm({
2931
+ "src/services/active-sessions.ts"() {
2932
+ "use strict";
2933
+ init_rest_request();
2934
+ init_routes();
2935
+ ActiveSessionsService = class {
2936
+ restClient;
2937
+ constructor(restClient) {
2938
+ this.restClient = restClient;
2939
+ }
2940
+ async getActiveSessions(pageSize, continuationToken) {
2941
+ const request = RestRequest.get(Routes.ActiveSessions.session);
2942
+ if (pageSize !== void 0) request.query("pageSize", String(pageSize));
2943
+ if (continuationToken !== void 0) request.header("x-continuation-token", continuationToken);
2944
+ const response = await this.restClient.execute(request);
2945
+ return response.body;
2946
+ }
2947
+ async revokeCurrentSession() {
2948
+ const request = RestRequest.delete(Routes.ActiveSessions.currentSession);
2949
+ await this.restClient.executeVoid(request);
2950
+ }
2951
+ async revokeSession(sessionRef) {
2952
+ const request = RestRequest.delete(Routes.ActiveSessions.delete(sessionRef));
2953
+ await this.restClient.executeVoid(request);
2954
+ }
2955
+ };
2956
+ }
2957
+ });
2958
+
2959
+ // src/services/online-session.ts
2960
+ var OnlineSessionService;
2961
+ var init_online_session = __esm({
2962
+ "src/services/online-session.ts"() {
2963
+ "use strict";
2964
+ init_ksef_feature();
2965
+ init_rest_request();
2966
+ init_routes();
2967
+ OnlineSessionService = class {
2968
+ restClient;
2969
+ constructor(restClient) {
2970
+ this.restClient = restClient;
2971
+ }
2972
+ async openSession(request, upoVersion) {
2973
+ const req = RestRequest.post(Routes.Sessions.Online.open).body(request);
2974
+ if (upoVersion) {
2975
+ req.header(KSEF_FEATURE_HEADER, upoVersion);
2976
+ }
2977
+ const response = await this.restClient.execute(req);
2978
+ return response.body;
2979
+ }
2980
+ async sendInvoice(sessionRef, request) {
2981
+ const req = RestRequest.post(Routes.Sessions.Online.invoices(sessionRef)).body(request);
2982
+ const response = await this.restClient.execute(req);
2983
+ return response.body;
2984
+ }
2985
+ async closeSession(sessionRef) {
2986
+ const req = RestRequest.post(Routes.Sessions.Online.close(sessionRef));
2987
+ await this.restClient.executeVoid(req);
2988
+ }
2989
+ };
2990
+ }
2991
+ });
2992
+
2993
+ // src/services/batch-session.ts
2994
+ var BatchSessionService;
2995
+ var init_batch_session = __esm({
2996
+ "src/services/batch-session.ts"() {
2997
+ "use strict";
2998
+ init_ksef_feature();
2423
2999
  init_rest_request();
2424
3000
  init_routes();
2425
3001
  BatchSessionService = class {
@@ -2864,20 +3440,20 @@ var init_lighthouse = __esm({
2864
3440
  this.lighthouseUrl = options.lighthouseUrl;
2865
3441
  this.timeout = options.timeout;
2866
3442
  }
2867
- async fetchJson(path) {
3443
+ async fetchJson(path2) {
2868
3444
  if (!this.lighthouseUrl) {
2869
3445
  throw new KSeFError(
2870
3446
  "Lighthouse API is not available for the DEMO environment. Use TEST or PROD instead."
2871
3447
  );
2872
3448
  }
2873
- const response = await fetch(`${this.lighthouseUrl}${path}`, {
3449
+ const response = await fetch(`${this.lighthouseUrl}${path2}`, {
2874
3450
  headers: { Accept: "application/json" },
2875
3451
  signal: AbortSignal.timeout(this.timeout)
2876
3452
  });
2877
3453
  if (!response.ok) {
2878
3454
  const body = await response.text();
2879
3455
  throw new KSeFError(
2880
- `Lighthouse ${path} failed: HTTP ${response.status} \u2014 ${body}`
3456
+ `Lighthouse ${path2} failed: HTTP ${response.status} \u2014 ${body}`
2881
3457
  );
2882
3458
  }
2883
3459
  return await response.json();
@@ -3758,36 +4334,520 @@ var init_verification_link_service = __esm({
3758
4334
  }
3759
4335
  });
3760
4336
 
3761
- // src/client.ts
3762
- var client_exports = {};
3763
- __export(client_exports, {
3764
- KSeFClient: () => KSeFClient,
3765
- buildAuthTokenRequestXml: () => buildAuthTokenRequestXml
4337
+ // src/utils/zip.ts
4338
+ var zip_exports = {};
4339
+ __export(zip_exports, {
4340
+ createZip: () => createZip,
4341
+ unzip: () => unzip
3766
4342
  });
3767
- function buildAuthTokenRequestXml(challenge, nip, subjectIdentifierType = "certificateSubject") {
3768
- return buildUnsignedAuthTokenRequestXml({
3769
- challenge,
3770
- contextIdentifier: { type: "Nip", value: nip },
3771
- subjectIdentifierType
4343
+ async function createZip(entries) {
4344
+ return new Promise((resolve, reject) => {
4345
+ const zipfile = new import_yazl.ZipFile();
4346
+ for (const entry of entries) {
4347
+ zipfile.addBuffer(Buffer.from(entry.content), entry.fileName);
4348
+ }
4349
+ const chunks = [];
4350
+ zipfile.outputStream.on("data", (chunk) => chunks.push(chunk));
4351
+ zipfile.outputStream.on("error", (err) => reject(err));
4352
+ zipfile.outputStream.on("end", () => resolve(Buffer.concat(chunks)));
4353
+ zipfile.end();
3772
4354
  });
3773
4355
  }
3774
- function buildRestClientConfig(options, authManager) {
3775
- const config = { authManager };
3776
- if (options?.transport) {
3777
- config.transport = options.transport;
3778
- }
3779
- if (options?.retry) {
3780
- config.retryPolicy = { ...defaultRetryPolicy(), ...options.retry };
3781
- }
3782
- if (options?.rateLimit === null) {
3783
- config.rateLimitPolicy = null;
3784
- } else if (options?.rateLimit) {
3785
- config.rateLimitPolicy = new RateLimitPolicy({
3786
- globalRps: options.rateLimit.globalRps ?? 10,
3787
- endpointLimits: options.rateLimit.endpointLimits
4356
+ async function unzip(buffer, options = {}) {
4357
+ const limits = { ...DEFAULT_UNZIP_OPTIONS, ...options };
4358
+ return new Promise((resolve, reject) => {
4359
+ (0, import_yauzl.fromBuffer)(buffer, { lazyEntries: true }, (err, zipfile) => {
4360
+ if (err || !zipfile) {
4361
+ reject(err ?? new Error("Failed to open zip buffer"));
4362
+ return;
4363
+ }
4364
+ const files = /* @__PURE__ */ new Map();
4365
+ let totalUncompressed = 0;
4366
+ zipfile.readEntry();
4367
+ zipfile.on("entry", (entry) => {
4368
+ if (entry.fileName.endsWith("/")) {
4369
+ zipfile.readEntry();
4370
+ return;
4371
+ }
4372
+ if (limits.maxFiles > 0 && files.size >= limits.maxFiles) {
4373
+ reject(new Error("zip contains too many files"));
4374
+ return;
4375
+ }
4376
+ const uncompressedSize = entry.uncompressedSize ?? 0;
4377
+ const compressedSize = entry.compressedSize ?? 0;
4378
+ if (limits.maxFileUncompressedSize > 0 && uncompressedSize > limits.maxFileUncompressedSize) {
4379
+ reject(new Error("zip entry exceeds max_file_uncompressed_size"));
4380
+ return;
4381
+ }
4382
+ if (limits.maxTotalUncompressedSize > 0) {
4383
+ totalUncompressed += uncompressedSize;
4384
+ if (totalUncompressed > limits.maxTotalUncompressedSize) {
4385
+ reject(new Error("zip exceeds max_total_uncompressed_size"));
4386
+ return;
4387
+ }
4388
+ }
4389
+ if (limits.maxCompressionRatio !== null) {
4390
+ if (compressedSize === 0 && uncompressedSize > 0) {
4391
+ reject(new Error("zip entry has suspicious compression metadata"));
4392
+ return;
4393
+ }
4394
+ if (compressedSize > 0 && uncompressedSize > 0) {
4395
+ const ratio = uncompressedSize / compressedSize;
4396
+ if (ratio > limits.maxCompressionRatio) {
4397
+ reject(new Error("zip entry exceeds max_compression_ratio"));
4398
+ return;
4399
+ }
4400
+ }
4401
+ }
4402
+ zipfile.openReadStream(entry, (streamErr, stream) => {
4403
+ if (streamErr || !stream) {
4404
+ reject(streamErr ?? new Error("Failed to read zip entry"));
4405
+ return;
4406
+ }
4407
+ const chunks = [];
4408
+ stream.on("data", (chunk) => chunks.push(chunk));
4409
+ stream.on("error", (streamError) => reject(streamError));
4410
+ stream.on("end", () => {
4411
+ files.set(entry.fileName, Buffer.concat(chunks));
4412
+ zipfile.readEntry();
4413
+ });
4414
+ });
4415
+ });
4416
+ zipfile.on("end", () => resolve(files));
4417
+ zipfile.on("error", (zipErr) => reject(zipErr));
3788
4418
  });
4419
+ });
4420
+ }
4421
+ var import_yazl, import_yauzl, DEFAULT_UNZIP_OPTIONS;
4422
+ var init_zip = __esm({
4423
+ "src/utils/zip.ts"() {
4424
+ "use strict";
4425
+ import_yazl = require("yazl");
4426
+ import_yauzl = require("yauzl");
4427
+ DEFAULT_UNZIP_OPTIONS = {
4428
+ maxFiles: 1e4,
4429
+ maxTotalUncompressedSize: 2e9,
4430
+ maxFileUncompressedSize: 5e8,
4431
+ maxCompressionRatio: 200
4432
+ };
3789
4433
  }
3790
- if (options?.presignedUrlHosts) {
4434
+ });
4435
+
4436
+ // src/offline/deadline.ts
4437
+ function getDefaultReason(mode) {
4438
+ switch (mode) {
4439
+ case "offline24":
4440
+ return "PLANNED";
4441
+ case "offline":
4442
+ return "SYSTEM_UNAVAILABLE";
4443
+ case "awaryjny":
4444
+ return "EMERGENCY";
4445
+ case "awaria_calkowita":
4446
+ return "TOTAL_FAILURE";
4447
+ }
4448
+ }
4449
+ function nextBusinessDay(from) {
4450
+ const d = new Date(from);
4451
+ d.setUTCDate(d.getUTCDate() + 1);
4452
+ while (d.getUTCDay() === 0 || d.getUTCDay() === 6) {
4453
+ d.setUTCDate(d.getUTCDate() + 1);
4454
+ }
4455
+ return d;
4456
+ }
4457
+ function addBusinessDays(from, days) {
4458
+ if (!Number.isInteger(days) || days < 0) {
4459
+ throw new Error(`days must be a non-negative integer, got ${days}`);
4460
+ }
4461
+ const d = new Date(from);
4462
+ let remaining = days;
4463
+ while (remaining > 0) {
4464
+ d.setUTCDate(d.getUTCDate() + 1);
4465
+ if (d.getUTCDay() !== 0 && d.getUTCDay() !== 6) {
4466
+ remaining--;
4467
+ }
4468
+ }
4469
+ return d;
4470
+ }
4471
+ function endOfDay(d) {
4472
+ const result = new Date(d);
4473
+ result.setUTCHours(23, 59, 59, 999);
4474
+ return result;
4475
+ }
4476
+ function getMaintenanceEndFallback(mw) {
4477
+ if (mw.endTime) {
4478
+ return new Date(mw.endTime);
4479
+ }
4480
+ const start = new Date(mw.startTime);
4481
+ start.setUTCDate(start.getUTCDate() + 7);
4482
+ return start;
4483
+ }
4484
+ function calculateOfflineDeadline(mode, invoiceDate, maintenanceWindow) {
4485
+ const date = typeof invoiceDate === "string" ? new Date(invoiceDate) : invoiceDate;
4486
+ switch (mode) {
4487
+ case "offline24": {
4488
+ return endOfDay(nextBusinessDay(date));
4489
+ }
4490
+ case "offline": {
4491
+ const base = maintenanceWindow ? getMaintenanceEndFallback(maintenanceWindow) : date;
4492
+ return endOfDay(nextBusinessDay(base));
4493
+ }
4494
+ case "awaryjny": {
4495
+ const base = maintenanceWindow ? getMaintenanceEndFallback(maintenanceWindow) : date;
4496
+ return endOfDay(addBusinessDays(base, 7));
4497
+ }
4498
+ case "awaria_calkowita": {
4499
+ return new Date(FAR_FUTURE);
4500
+ }
4501
+ }
4502
+ }
4503
+ function extendDeadlineForMaintenance(currentDeadline, maintenanceWindow, mode = "awaryjny") {
4504
+ const current = typeof currentDeadline === "string" ? new Date(currentDeadline) : new Date(currentDeadline);
4505
+ const mwEnd = getMaintenanceEndFallback(maintenanceWindow);
4506
+ if (mwEnd.getTime() > current.getTime()) {
4507
+ switch (mode) {
4508
+ case "offline24":
4509
+ case "offline":
4510
+ return endOfDay(nextBusinessDay(mwEnd));
4511
+ case "awaryjny":
4512
+ return endOfDay(addBusinessDays(mwEnd, 7));
4513
+ case "awaria_calkowita":
4514
+ return new Date(FAR_FUTURE);
4515
+ }
4516
+ }
4517
+ return current;
4518
+ }
4519
+ function isExpired(submitBy) {
4520
+ const deadline = typeof submitBy === "string" ? new Date(submitBy) : submitBy;
4521
+ return Date.now() > deadline.getTime();
4522
+ }
4523
+ function getTimeUntilDeadline(submitBy) {
4524
+ const deadline = typeof submitBy === "string" ? new Date(submitBy) : submitBy;
4525
+ return Math.max(0, deadline.getTime() - Date.now());
4526
+ }
4527
+ var FAR_FUTURE;
4528
+ var init_deadline = __esm({
4529
+ "src/offline/deadline.ts"() {
4530
+ "use strict";
4531
+ FAR_FUTURE = /* @__PURE__ */ new Date("9999-12-31T23:59:59Z");
4532
+ }
4533
+ });
4534
+
4535
+ // src/workflows/offline-invoice-workflow.ts
4536
+ var import_node_crypto2, OfflineInvoiceWorkflow;
4537
+ var init_offline_invoice_workflow = __esm({
4538
+ "src/workflows/offline-invoice-workflow.ts"() {
4539
+ "use strict";
4540
+ import_node_crypto2 = __toESM(require("crypto"), 1);
4541
+ init_ksef_api_error();
4542
+ init_deadline();
4543
+ init_document_structures();
4544
+ OfflineInvoiceWorkflow = class {
4545
+ constructor(qrService) {
4546
+ this.qrService = qrService;
4547
+ }
4548
+ async generate(input, options) {
4549
+ if (!input.invoiceXml || input.invoiceXml.trim().length === 0) {
4550
+ throw new Error("invoiceXml must not be empty");
4551
+ }
4552
+ if (!input.invoiceNumber) {
4553
+ throw new Error("invoiceNumber is required");
4554
+ }
4555
+ if (!input.sellerNip) {
4556
+ throw new Error("sellerNip is required");
4557
+ }
4558
+ const mode = options?.mode ?? "offline24";
4559
+ const reason = getDefaultReason(mode);
4560
+ const invoiceHashBase64 = import_node_crypto2.default.createHash("sha256").update(input.invoiceXml).digest("base64");
4561
+ const kod1Url = this.qrService.buildInvoiceVerificationUrl(
4562
+ input.sellerNip,
4563
+ input.invoiceDate,
4564
+ invoiceHashBase64
4565
+ );
4566
+ let kod2Url;
4567
+ if (options?.certificate) {
4568
+ kod2Url = this.qrService.buildCertificateVerificationUrl(
4569
+ input.sellerIdentifier.type,
4570
+ input.sellerIdentifier.value,
4571
+ input.sellerNip,
4572
+ options.certificate.certificateSerial,
4573
+ invoiceHashBase64,
4574
+ options.certificate.privateKeyPem
4575
+ );
4576
+ }
4577
+ const submitBy = options?.customDeadline ? typeof options.customDeadline === "string" ? options.customDeadline : options.customDeadline.toISOString() : calculateOfflineDeadline(mode, input.invoiceDate, options?.maintenanceWindow).toISOString();
4578
+ const metadata = {
4579
+ id: import_node_crypto2.default.randomUUID(),
4580
+ mode,
4581
+ reason,
4582
+ status: "GENERATED",
4583
+ invoiceNumber: input.invoiceNumber,
4584
+ invoiceDate: input.invoiceDate,
4585
+ invoiceXml: input.invoiceXml,
4586
+ sellerNip: input.sellerNip,
4587
+ sellerIdentifier: input.sellerIdentifier,
4588
+ buyerIdentifier: input.buyerIdentifier,
4589
+ totalAmount: input.totalAmount,
4590
+ currency: input.currency,
4591
+ kod1Url,
4592
+ kod2Url,
4593
+ generatedAt: (/* @__PURE__ */ new Date()).toISOString(),
4594
+ submitBy,
4595
+ maintenanceWindowId: options?.maintenanceWindow?.id
4596
+ };
4597
+ if (options?.storage) {
4598
+ await options.storage.save(metadata);
4599
+ }
4600
+ return metadata;
4601
+ }
4602
+ async submit(client, options) {
4603
+ const { storage, checkExpiry = true } = options;
4604
+ let invoices;
4605
+ if (options.invoiceIds) {
4606
+ invoices = [];
4607
+ const notFound = [];
4608
+ for (const id of options.invoiceIds) {
4609
+ const inv = await storage.get(id);
4610
+ if (inv) {
4611
+ invoices.push(inv);
4612
+ } else {
4613
+ notFound.push(id);
4614
+ }
4615
+ }
4616
+ if (notFound.length > 0) {
4617
+ throw new Error(`Offline invoice(s) not found: ${notFound.join(", ")}`);
4618
+ }
4619
+ } else {
4620
+ invoices = await storage.list({ status: ["GENERATED", "QUEUED", "SUBMITTED"] });
4621
+ }
4622
+ const result = {
4623
+ total: invoices.length,
4624
+ submitted: 0,
4625
+ accepted: 0,
4626
+ rejected: 0,
4627
+ failed: 0,
4628
+ expired: 0,
4629
+ results: []
4630
+ };
4631
+ if (invoices.length === 0) return result;
4632
+ const pending = [];
4633
+ for (const inv of invoices) {
4634
+ if (checkExpiry && isExpired(inv.submitBy)) {
4635
+ await storage.update(inv.id, { status: "EXPIRED" });
4636
+ result.expired++;
4637
+ result.results.push({
4638
+ invoiceId: inv.id,
4639
+ invoiceNumber: inv.invoiceNumber,
4640
+ status: "EXPIRED"
4641
+ });
4642
+ } else {
4643
+ pending.push(inv);
4644
+ }
4645
+ }
4646
+ if (pending.length === 0) return result;
4647
+ await client.crypto.init();
4648
+ const encData = client.crypto.getEncryptionData();
4649
+ const formCode = options.formCode ?? DEFAULT_FORM_CODE;
4650
+ const openResp = await client.onlineSession.openSession(
4651
+ { formCode, encryption: encData.encryptionInfo }
4652
+ );
4653
+ const sessionRef = openResp.referenceNumber;
4654
+ try {
4655
+ for (const inv of pending) {
4656
+ await storage.update(inv.id, { status: "QUEUED" });
4657
+ try {
4658
+ const data = new TextEncoder().encode(inv.invoiceXml);
4659
+ const plainMeta = client.crypto.getFileMetadata(data);
4660
+ const encrypted = client.crypto.encryptAES256(data, encData.cipherKey, encData.cipherIv);
4661
+ const encMeta = client.crypto.getFileMetadata(encrypted);
4662
+ await storage.update(inv.id, { status: "SUBMITTED", submittedAt: (/* @__PURE__ */ new Date()).toISOString() });
4663
+ const resp = await client.onlineSession.sendInvoice(sessionRef, {
4664
+ invoiceHash: plainMeta.hashSHA,
4665
+ invoiceSize: plainMeta.fileSize,
4666
+ encryptedInvoiceHash: encMeta.hashSHA,
4667
+ encryptedInvoiceSize: encMeta.fileSize,
4668
+ encryptedInvoiceContent: Buffer.from(encrypted).toString("base64"),
4669
+ offlineMode: true
4670
+ });
4671
+ await storage.update(inv.id, {
4672
+ status: "ACCEPTED",
4673
+ acceptedAt: (/* @__PURE__ */ new Date()).toISOString(),
4674
+ ksefReferenceNumber: resp.referenceNumber
4675
+ });
4676
+ result.submitted++;
4677
+ result.accepted++;
4678
+ result.results.push({
4679
+ invoiceId: inv.id,
4680
+ invoiceNumber: inv.invoiceNumber,
4681
+ status: "ACCEPTED",
4682
+ ksefReferenceNumber: resp.referenceNumber
4683
+ });
4684
+ } catch (err) {
4685
+ const message = err instanceof Error ? err.message : String(err);
4686
+ if (err instanceof KSeFApiError) {
4687
+ await storage.update(inv.id, {
4688
+ status: "REJECTED",
4689
+ error: { code: err.statusCode, message }
4690
+ });
4691
+ result.submitted++;
4692
+ result.rejected++;
4693
+ result.results.push({
4694
+ invoiceId: inv.id,
4695
+ invoiceNumber: inv.invoiceNumber,
4696
+ status: "REJECTED",
4697
+ error: { code: err.statusCode, message }
4698
+ });
4699
+ } else {
4700
+ await storage.update(inv.id, {
4701
+ status: "QUEUED",
4702
+ error: { code: 0, message }
4703
+ });
4704
+ result.failed++;
4705
+ result.results.push({
4706
+ invoiceId: inv.id,
4707
+ invoiceNumber: inv.invoiceNumber,
4708
+ status: "QUEUED",
4709
+ error: { code: 0, message }
4710
+ });
4711
+ }
4712
+ }
4713
+ }
4714
+ } finally {
4715
+ try {
4716
+ await client.onlineSession.closeSession(sessionRef);
4717
+ } catch {
4718
+ }
4719
+ }
4720
+ return result;
4721
+ }
4722
+ // TODO(perf): Each correction opens a separate KSeF session.
4723
+ // For batch corrections, consider a correctBatch() sharing one session (like submit()).
4724
+ async correct(client, options) {
4725
+ const { storage, rejectedInvoiceId, correctedInvoiceXml } = options;
4726
+ const original = await storage.get(rejectedInvoiceId);
4727
+ if (!original) {
4728
+ throw new Error(`Offline invoice not found: ${rejectedInvoiceId}`);
4729
+ }
4730
+ if (original.status !== "REJECTED") {
4731
+ throw new Error(
4732
+ original.status === "CORRECTED" ? `Invoice ${rejectedInvoiceId} has already been corrected (by ${original.correctedBy})` : `Only rejected invoices can be corrected (current status: ${original.status})`
4733
+ );
4734
+ }
4735
+ const originalHash = import_node_crypto2.default.createHash("sha256").update(original.invoiceXml).digest("base64");
4736
+ await client.crypto.init();
4737
+ const encData = client.crypto.getEncryptionData();
4738
+ const formCode = options.formCode ?? DEFAULT_FORM_CODE;
4739
+ const openResp = await client.onlineSession.openSession(
4740
+ { formCode, encryption: encData.encryptionInfo }
4741
+ );
4742
+ const sessionRef = openResp.referenceNumber;
4743
+ try {
4744
+ const data = new TextEncoder().encode(correctedInvoiceXml);
4745
+ const plainMeta = client.crypto.getFileMetadata(data);
4746
+ const encrypted = client.crypto.encryptAES256(data, encData.cipherKey, encData.cipherIv);
4747
+ const encMeta = client.crypto.getFileMetadata(encrypted);
4748
+ const correctionId = import_node_crypto2.default.randomUUID();
4749
+ const submittedAt = (/* @__PURE__ */ new Date()).toISOString();
4750
+ const correctedHashBase64 = import_node_crypto2.default.createHash("sha256").update(correctedInvoiceXml).digest("base64");
4751
+ const kod1Url = this.qrService.buildInvoiceVerificationUrl(
4752
+ original.sellerNip,
4753
+ original.invoiceDate,
4754
+ correctedHashBase64
4755
+ );
4756
+ let kod2Url;
4757
+ if (options.certificate) {
4758
+ kod2Url = this.qrService.buildCertificateVerificationUrl(
4759
+ original.sellerIdentifier.type,
4760
+ original.sellerIdentifier.value,
4761
+ original.sellerNip,
4762
+ options.certificate.certificateSerial,
4763
+ correctedHashBase64,
4764
+ options.certificate.privateKeyPem
4765
+ );
4766
+ }
4767
+ const correctionMetadata = {
4768
+ id: correctionId,
4769
+ mode: original.mode,
4770
+ reason: original.reason,
4771
+ status: "SUBMITTED",
4772
+ invoiceNumber: original.invoiceNumber,
4773
+ invoiceDate: original.invoiceDate,
4774
+ invoiceXml: correctedInvoiceXml,
4775
+ sellerNip: original.sellerNip,
4776
+ sellerIdentifier: original.sellerIdentifier,
4777
+ buyerIdentifier: original.buyerIdentifier,
4778
+ kod1Url,
4779
+ kod2Url,
4780
+ generatedAt: submittedAt,
4781
+ submitBy: original.submitBy,
4782
+ submittedAt,
4783
+ correctedInvoiceId: rejectedInvoiceId
4784
+ };
4785
+ await storage.save(correctionMetadata);
4786
+ const resp = await client.onlineSession.sendInvoice(sessionRef, {
4787
+ invoiceHash: plainMeta.hashSHA,
4788
+ invoiceSize: plainMeta.fileSize,
4789
+ encryptedInvoiceHash: encMeta.hashSHA,
4790
+ encryptedInvoiceSize: encMeta.fileSize,
4791
+ encryptedInvoiceContent: Buffer.from(encrypted).toString("base64"),
4792
+ offlineMode: true,
4793
+ hashOfCorrectedInvoice: originalHash
4794
+ });
4795
+ await storage.update(correctionId, {
4796
+ status: "ACCEPTED",
4797
+ acceptedAt: (/* @__PURE__ */ new Date()).toISOString(),
4798
+ ksefReferenceNumber: resp.referenceNumber
4799
+ });
4800
+ await storage.update(rejectedInvoiceId, {
4801
+ status: "CORRECTED",
4802
+ correctedBy: correctionId
4803
+ });
4804
+ return {
4805
+ invoiceId: correctionId,
4806
+ invoiceNumber: correctionMetadata.invoiceNumber,
4807
+ status: "ACCEPTED",
4808
+ ksefReferenceNumber: resp.referenceNumber
4809
+ };
4810
+ } finally {
4811
+ try {
4812
+ await client.onlineSession.closeSession(sessionRef);
4813
+ } catch {
4814
+ }
4815
+ }
4816
+ }
4817
+ };
4818
+ }
4819
+ });
4820
+
4821
+ // src/client.ts
4822
+ var client_exports = {};
4823
+ __export(client_exports, {
4824
+ KSeFClient: () => KSeFClient,
4825
+ buildAuthTokenRequestXml: () => buildAuthTokenRequestXml
4826
+ });
4827
+ function buildAuthTokenRequestXml(challenge, nip, subjectIdentifierType = "certificateSubject") {
4828
+ return buildUnsignedAuthTokenRequestXml({
4829
+ challenge,
4830
+ contextIdentifier: { type: "Nip", value: nip },
4831
+ subjectIdentifierType
4832
+ });
4833
+ }
4834
+ function buildRestClientConfig(options, authManager) {
4835
+ const config = { authManager };
4836
+ if (options?.transport) {
4837
+ config.transport = options.transport;
4838
+ }
4839
+ if (options?.retry) {
4840
+ config.retryPolicy = { ...defaultRetryPolicy(), ...options.retry };
4841
+ }
4842
+ if (options?.rateLimit === null) {
4843
+ config.rateLimitPolicy = null;
4844
+ } else if (options?.rateLimit) {
4845
+ config.rateLimitPolicy = new RateLimitPolicy({
4846
+ globalRps: options.rateLimit.globalRps ?? 10,
4847
+ endpointLimits: options.rateLimit.endpointLimits
4848
+ });
4849
+ }
4850
+ if (options?.presignedUrlHosts) {
3791
4851
  const base = defaultPresignedUrlPolicy();
3792
4852
  config.presignedUrlPolicy = {
3793
4853
  ...base,
@@ -3823,6 +4883,7 @@ var init_client = __esm({
3823
4883
  init_cryptography_service();
3824
4884
  init_verification_link_service();
3825
4885
  init_auth_xml_builder();
4886
+ init_offline_invoice_workflow();
3826
4887
  KSeFClient = class {
3827
4888
  auth;
3828
4889
  activeSessions;
@@ -3841,6 +4902,7 @@ var init_client = __esm({
3841
4902
  qr;
3842
4903
  options;
3843
4904
  authManager;
4905
+ _offline;
3844
4906
  constructor(options) {
3845
4907
  this.options = resolveOptions(options);
3846
4908
  const authManager = options?.authManager ?? new DefaultAuthManager(async () => {
@@ -3869,6 +4931,12 @@ var init_client = __esm({
3869
4931
  this.testData = new TestDataService(restClient, this.options.environmentName);
3870
4932
  this.qr = new VerificationLinkService(this.options.baseQrUrl);
3871
4933
  }
4934
+ get offline() {
4935
+ if (!this._offline) {
4936
+ this._offline = new OfflineInvoiceWorkflow(this.qr);
4937
+ }
4938
+ return this._offline;
4939
+ }
3872
4940
  async loginWithToken(token, nip) {
3873
4941
  const challenge = await this.auth.getChallenge();
3874
4942
  await this.crypto.init();
@@ -3949,8 +5017,10 @@ __export(index_exports, {
3949
5017
  FORM_CODES: () => FORM_CODES,
3950
5018
  FORM_CODE_KEYS: () => FORM_CODE_KEYS,
3951
5019
  FileHwmStore: () => FileHwmStore,
5020
+ FileOfflineInvoiceStorage: () => FileOfflineInvoiceStorage,
3952
5021
  INVOICE_TYPES_BY_SYSTEM_CODE: () => INVOICE_TYPES_BY_SYSTEM_CODE,
3953
5022
  InMemoryHwmStore: () => InMemoryHwmStore,
5023
+ InMemoryOfflineInvoiceStorage: () => InMemoryOfflineInvoiceStorage,
3954
5024
  InternalId: () => InternalId,
3955
5025
  InvoiceDownloadService: () => InvoiceDownloadService,
3956
5026
  InvoiceQueryFilterBuilder: () => InvoiceQueryFilterBuilder,
@@ -3974,6 +5044,7 @@ __export(index_exports, {
3974
5044
  LimitsService: () => LimitsService,
3975
5045
  Nip: () => Nip,
3976
5046
  NipVatUe: () => NipVatUe,
5047
+ OfflineInvoiceWorkflow: () => OfflineInvoiceWorkflow,
3977
5048
  OnlineSessionService: () => OnlineSessionService,
3978
5049
  PERMISSION_DESCRIPTION_MAX_LENGTH: () => PERMISSION_DESCRIPTION_MAX_LENGTH,
3979
5050
  PERMISSION_DESCRIPTION_MIN_LENGTH: () => PERMISSION_DESCRIPTION_MIN_LENGTH,
@@ -3988,596 +5059,124 @@ __export(index_exports, {
3988
5059
  RateLimitPolicy: () => RateLimitPolicy,
3989
5060
  ReferenceNumber: () => ReferenceNumber,
3990
5061
  RestClient: () => RestClient,
3991
- RestRequest: () => RestRequest,
3992
- RouteBuilder: () => RouteBuilder,
3993
- Routes: () => Routes,
3994
- SUBUNIT_NAME_MAX_LENGTH: () => SUBUNIT_NAME_MAX_LENGTH,
3995
- SUBUNIT_NAME_MIN_LENGTH: () => SUBUNIT_NAME_MIN_LENGTH,
3996
- SchemaRegistry: () => SchemaRegistry,
3997
- SessionStatusService: () => SessionStatusService,
3998
- Sha256Base64: () => Sha256Base64,
3999
- SignatureService: () => SignatureService,
4000
- SystemCode: () => SystemCode,
4001
- TestDataService: () => TestDataService,
4002
- TokenService: () => TokenService,
4003
- UpoVersion: () => UpoVersion,
4004
- VatUe: () => VatUe,
4005
- VerificationLinkService: () => VerificationLinkService,
4006
- authenticateWithCertificate: () => authenticateWithCertificate,
4007
- authenticateWithExternalSignature: () => authenticateWithExternalSignature,
4008
- authenticateWithPkcs12: () => authenticateWithPkcs12,
4009
- authenticateWithToken: () => authenticateWithToken,
4010
- buildUnsignedAuthTokenRequestXml: () => buildUnsignedAuthTokenRequestXml,
4011
- calculateBackoff: () => calculateBackoff,
4012
- createZip: () => createZip,
4013
- decodeJwtPayload: () => decodeJwtPayload,
4014
- deduplicateByKsefNumber: () => deduplicateByKsefNumber,
4015
- defaultPresignedUrlPolicy: () => defaultPresignedUrlPolicy,
4016
- defaultRateLimitPolicy: () => defaultRateLimitPolicy,
4017
- defaultRetryPolicy: () => defaultRetryPolicy,
4018
- defaultTransport: () => defaultTransport,
4019
- exportAndDownload: () => exportAndDownload,
4020
- exportInvoices: () => exportInvoices,
4021
- getEffectiveStartDate: () => getEffectiveStartDate,
4022
- getFormCode: () => getFormCode,
4023
- incrementalExportAndDownload: () => incrementalExportAndDownload,
4024
- isRetryableError: () => isRetryableError,
4025
- isRetryableStatus: () => isRetryableStatus,
4026
- isValidBase64: () => isValidBase64,
4027
- isValidCertificateFingerprint: () => isValidCertificateFingerprint,
4028
- isValidCertificateName: () => isValidCertificateName,
4029
- isValidInternalId: () => isValidInternalId,
4030
- isValidIp4Address: () => isValidIp4Address,
4031
- isValidKsefNumber: () => isValidKsefNumber,
4032
- isValidKsefNumberV35: () => isValidKsefNumberV35,
4033
- isValidKsefNumberV36: () => isValidKsefNumberV36,
4034
- isValidNip: () => isValidNip,
4035
- isValidNipVatUe: () => isValidNipVatUe,
4036
- isValidPeppolId: () => isValidPeppolId,
4037
- isValidPesel: () => isValidPesel,
4038
- isValidReferenceNumber: () => isValidReferenceNumber,
4039
- isValidSha256Base64: () => isValidSha256Base64,
4040
- isValidVatUe: () => isValidVatUe,
4041
- openOnlineSession: () => openOnlineSession,
4042
- openSendAndClose: () => openSendAndClose,
4043
- parseFormCode: () => parseFormCode,
4044
- parseKSeFTokenContext: () => parseKSeFTokenContext,
4045
- parseRetryAfter: () => parseRetryAfter,
4046
- parseUpoXml: () => parseUpoXml,
4047
- pollUntil: () => pollUntil,
4048
- resolveOptions: () => resolveOptions,
4049
- sleep: () => sleep,
4050
- unzip: () => unzip,
4051
- updateContinuationPoint: () => updateContinuationPoint,
4052
- uploadBatch: () => uploadBatch,
4053
- uploadBatchParsed: () => uploadBatchParsed,
4054
- uploadBatchStream: () => uploadBatchStream,
4055
- uploadBatchStreamParsed: () => uploadBatchStreamParsed,
4056
- validate: () => validate,
4057
- validateBusinessRules: () => validateBusinessRules,
4058
- validateFormCodeForSession: () => validateFormCodeForSession,
4059
- validatePresignedUrl: () => validatePresignedUrl,
4060
- validateSchema: () => validateSchema,
4061
- validateWellFormedness: () => validateWellFormedness,
4062
- xmlToObject: () => xmlToObject
4063
- });
4064
- module.exports = __toCommonJS(index_exports);
4065
- init_config();
4066
- init_errors();
4067
-
4068
- // src/http/index.ts
4069
- init_route_builder();
4070
- init_rest_request();
4071
- init_rest_client();
4072
- init_routes();
4073
- init_transport();
4074
- init_retry_policy();
4075
- init_rate_limit_policy();
4076
- init_auth_manager();
4077
- init_presigned_url_policy();
4078
- init_ksef_feature();
4079
-
4080
- // src/validation/patterns.ts
4081
- var NIP_PATTERN_CORE = "[1-9]((\\d[1-9])|([1-9]\\d))\\d{7}";
4082
- var VAT_UE_PATTERN_CORE = "(ATU\\d{8}|BE[01]{1}\\d{9}|BG\\d{9,10}|CY\\d{8}[A-Z]|CZ\\d{8,10}|DE\\d{9}|DK\\d{8}|EE\\d{9}|EL\\d{9}|ES([A-Z]\\d{8}|\\d{8}[A-Z]|[A-Z]\\d{7}[A-Z])|FI\\d{8}|FR[A-Z0-9]{2}\\d{9}|HR\\d{11}|HU\\d{8}|IE(\\d{7}[A-Z]{2}|\\d[A-Z0-9+*]\\d{5}[A-Z])|IT\\d{11}|LT(\\d{9}|\\d{12})|LU\\d{8}|LV\\d{11}|MT\\d{8}|NL[A-Z0-9+*]{12}|PT\\d{9}|RO\\d{2,10}|SE\\d{12}|SI\\d{8}|SK\\d{10}|XI((\\d{9}|\\d{12})|(GD|HA)\\d{3}))";
4083
- var Nip = new RegExp(`^${NIP_PATTERN_CORE}$`);
4084
- var VatUe = new RegExp(`^${VAT_UE_PATTERN_CORE}$`);
4085
- var NipVatUe = new RegExp(`^${NIP_PATTERN_CORE}-${VAT_UE_PATTERN_CORE}$`);
4086
- var InternalId = /^[1-9]((\d[1-9])|([1-9]\d))\d{7}-\d{5}$/;
4087
- var PeppolId = /^P[A-Z]{2}[0-9]{6}$/;
4088
- var ReferenceNumber = /^(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-Z]{2})-([0-9A-F]{10})-([0-9A-F]{10})-([0-9A-F]{2})$/;
4089
- var KsefNumber = /^([1-9](\d[1-9]|[1-9]\d)\d{7})-(20[2-9][0-9]|2[1-9]\d{2}|[3-9]\d{3})(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])-([0-9A-F]{6})-?([0-9A-F]{6})-([0-9A-F]{2})$/;
4090
- var KsefNumberV35 = /^([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})$/;
4091
- var KsefNumberV36 = /^([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})$/;
4092
- var CertificateName = /^[a-zA-Z0-9_\- ąćęłńóśźżĄĆĘŁŃÓŚŹŻ]+$/;
4093
- var 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}$/;
4094
- var CertificateFingerprint = /^[0-9A-F]{64}$/;
4095
- var Base64String = /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/;
4096
- var Ip4Address = /^((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)\.?\b){4}$/;
4097
- var 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}$/;
4098
- var Ip4Mask = /^((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)\.?\b){4}\/(0|[1-9]|1[0-9]|2[0-9]|3[0-2])$/;
4099
- var Sha256Base64 = /^[A-Za-z0-9+/]{43}=$/;
4100
- var NIP_WEIGHTS = [6, 5, 7, 2, 3, 4, 5, 6, 7];
4101
- var PESEL_WEIGHTS = [1, 3, 7, 9, 1, 3, 7, 9, 1, 3];
4102
- var CRC8_POLY = 7;
4103
- function computeCrc8Hex(data) {
4104
- let crc = 0;
4105
- const bytes = new TextEncoder().encode(data);
4106
- for (const byte of bytes) {
4107
- crc ^= byte;
4108
- for (let i = 0; i < 8; i++) {
4109
- crc = (crc & 128) !== 0 ? (crc << 1 ^ CRC8_POLY) & 255 : crc << 1 & 255;
4110
- }
4111
- }
4112
- return crc.toString(16).toUpperCase().padStart(2, "0");
4113
- }
4114
- function isValidNip(value) {
4115
- if (!Nip.test(value)) return false;
4116
- let sum = 0;
4117
- for (let i = 0; i < 9; i++) {
4118
- sum += Number(value[i]) * NIP_WEIGHTS[i];
4119
- }
4120
- const checksum = sum % 11;
4121
- return checksum !== 10 && checksum === Number(value[9]);
4122
- }
4123
- function isValidVatUe(value) {
4124
- return VatUe.test(value);
4125
- }
4126
- function isValidNipVatUe(value) {
4127
- return NipVatUe.test(value);
4128
- }
4129
- function isValidInternalId(value) {
4130
- return InternalId.test(value);
4131
- }
4132
- function isValidPeppolId(value) {
4133
- return PeppolId.test(value);
4134
- }
4135
- function isValidReferenceNumber(value) {
4136
- return ReferenceNumber.test(value);
4137
- }
4138
- function isValidKsefNumber(value) {
4139
- if (!KsefNumber.test(value)) return false;
4140
- let normalized = value;
4141
- if (value.length === 36) {
4142
- const parts = value.split("-");
4143
- if (parts.length === 5) normalized = `${parts[0]}-${parts[1]}-${parts[2]}${parts[3]}-${parts[4]}`;
4144
- else return false;
4145
- }
4146
- if (normalized.length !== 35) return false;
4147
- return computeCrc8Hex(normalized.slice(0, 32)) === normalized.slice(-2);
4148
- }
4149
- function isValidKsefNumberV35(value) {
4150
- if (!KsefNumberV35.test(value)) return false;
4151
- return computeCrc8Hex(value.slice(0, 32)) === value.slice(-2);
4152
- }
4153
- function isValidKsefNumberV36(value) {
4154
- if (!KsefNumberV36.test(value)) return false;
4155
- const parts = value.split("-");
4156
- if (parts.length !== 5) return false;
4157
- const normalized = `${parts[0]}-${parts[1]}-${parts[2]}${parts[3]}-${parts[4]}`;
4158
- return computeCrc8Hex(normalized.slice(0, 32)) === normalized.slice(-2);
4159
- }
4160
- function isValidPesel(value) {
4161
- if (!Pesel.test(value)) return false;
4162
- let sum = 0;
4163
- for (let i = 0; i < 10; i++) {
4164
- sum += Number(value[i]) * PESEL_WEIGHTS[i];
4165
- }
4166
- const checksum = (10 - sum % 10) % 10;
4167
- return checksum === Number(value[10]);
4168
- }
4169
- function isValidCertificateName(value) {
4170
- return CertificateName.test(value);
4171
- }
4172
- function isValidCertificateFingerprint(value) {
4173
- return CertificateFingerprint.test(value);
4174
- }
4175
- function isValidBase64(value) {
4176
- return Base64String.test(value);
4177
- }
4178
- function isValidIp4Address(value) {
4179
- return Ip4Address.test(value);
4180
- }
4181
- function isValidSha256Base64(value) {
4182
- return Sha256Base64.test(value);
4183
- }
4184
-
4185
- // src/validation/constraints.ts
4186
- var REQUIRED_CHALLENGE_LENGTH = 36;
4187
- var CERTIFICATE_NAME_MIN_LENGTH = 5;
4188
- var CERTIFICATE_NAME_MAX_LENGTH = 100;
4189
- var SUBUNIT_NAME_MIN_LENGTH = 5;
4190
- var SUBUNIT_NAME_MAX_LENGTH = 256;
4191
- var PERMISSION_DESCRIPTION_MIN_LENGTH = 5;
4192
- var PERMISSION_DESCRIPTION_MAX_LENGTH = 256;
4193
-
4194
- // src/validation/xml-to-object.ts
4195
- var import_xmldom = require("@xmldom/xmldom");
4196
- function xmlToObject(xml) {
4197
- const errors = [];
4198
- const doc = new import_xmldom.DOMParser({
4199
- errorHandler: {
4200
- warning: (_msg) => {
4201
- },
4202
- error: (msg) => errors.push(msg),
4203
- fatalError: (msg) => errors.push(msg)
4204
- }
4205
- }).parseFromString(xml, "text/xml");
4206
- if (errors.length > 0 || !doc || !doc.documentElement) {
4207
- return { object: null, rootElement: null, namespace: null, errors };
4208
- }
4209
- const root = doc.documentElement;
4210
- const rootName = getLocalName(root);
4211
- const namespace = root.namespaceURI || null;
4212
- const obj = elementToObject(root);
4213
- return {
4214
- object: typeof obj === "object" && obj !== null ? obj : { "#text": obj },
4215
- rootElement: rootName,
4216
- namespace,
4217
- errors: []
4218
- };
4219
- }
4220
- function getLocalName(node) {
4221
- if (node.localName) return node.localName;
4222
- const name = node.nodeName;
4223
- const idx = name.indexOf(":");
4224
- return idx === -1 ? name : name.substring(idx + 1);
4225
- }
4226
- function elementToObject(el) {
4227
- const result = {};
4228
- let hasChildElements = false;
4229
- for (let i = 0; i < el.attributes.length; i++) {
4230
- const a = el.attributes.item(i);
4231
- if (!a) continue;
4232
- const name = a.nodeName;
4233
- if (name === "xmlns" || name.startsWith("xmlns:")) continue;
4234
- const attrLocal = getLocalName(a);
4235
- result[`@${attrLocal}`] = a.value;
4236
- }
4237
- const childCounts = /* @__PURE__ */ new Map();
4238
- for (let i = 0; i < el.childNodes.length; i++) {
4239
- const child = el.childNodes.item(i);
4240
- if (!child || child.nodeType !== 1) continue;
4241
- const name = getLocalName(child);
4242
- childCounts.set(name, (childCounts.get(name) || 0) + 1);
4243
- hasChildElements = true;
4244
- }
4245
- if (!hasChildElements) {
4246
- const text = getTextContent(el);
4247
- const hasAttrs = Object.keys(result).length > 0;
4248
- if (hasAttrs) {
4249
- result["#text"] = text;
4250
- return result;
4251
- }
4252
- return text;
4253
- }
4254
- for (let i = 0; i < el.childNodes.length; i++) {
4255
- const child = el.childNodes.item(i);
4256
- if (!child || child.nodeType !== 1) continue;
4257
- const name = getLocalName(child);
4258
- const value = elementToObject(child);
4259
- const count = childCounts.get(name) || 1;
4260
- if (count > 1) {
4261
- if (!Array.isArray(result[name])) {
4262
- result[name] = [];
4263
- }
4264
- result[name].push(value);
4265
- } else {
4266
- result[name] = value;
4267
- }
4268
- }
4269
- return result;
4270
- }
4271
- function getTextContent(el) {
4272
- let text = "";
4273
- for (let i = 0; i < el.childNodes.length; i++) {
4274
- const child = el.childNodes.item(i);
4275
- if (!child) continue;
4276
- if (child.nodeType === 3 || child.nodeType === 4) {
4277
- text += child.nodeValue || "";
4278
- }
4279
- }
4280
- return text.trim();
4281
- }
4282
-
4283
- // src/validation/schemas/index.ts
4284
- init_fa3();
4285
- init_fa2();
4286
- init_rr1_v11e();
4287
- init_rr1_v10e();
4288
- init_pef3();
4289
- init_pef_kor3();
4290
- var NAMESPACE_MAP = {
4291
- "http://crd.gov.pl/wzor/2025/06/25/13775/": "FA3",
4292
- "http://crd.gov.pl/wzor/2023/06/29/12648/": "FA2",
4293
- "http://crd.gov.pl/wzor/2026/03/06/14189/": "RR1_V11E",
4294
- "http://crd.gov.pl/wzor/2026/02/17/14164/": "RR1_V10E",
4295
- "urn:oasis:names:specification:ubl:schema:xsd:Invoice-2": "PEF3",
4296
- "urn:oasis:names:specification:ubl:schema:xsd:CreditNote-2": "PEF_KOR3"
4297
- };
4298
-
4299
- // src/validation/schema-registry.ts
4300
- var ROOT_ELEMENT_MAP = {
4301
- Invoice: "PEF3",
4302
- CreditNote: "PEF_KOR3"
4303
- };
4304
- var schemaCache = /* @__PURE__ */ new Map();
4305
- async function loadSchema(type) {
4306
- const cached = schemaCache.get(type);
4307
- if (cached) return cached;
4308
- let mod;
4309
- switch (type) {
4310
- case "FA3":
4311
- mod = await Promise.resolve().then(() => (init_fa3(), fa3_exports));
4312
- break;
4313
- case "FA2":
4314
- mod = await Promise.resolve().then(() => (init_fa2(), fa2_exports));
4315
- break;
4316
- case "RR1_V11E":
4317
- mod = await Promise.resolve().then(() => (init_rr1_v11e(), rr1_v11e_exports));
4318
- break;
4319
- case "RR1_V10E":
4320
- mod = await Promise.resolve().then(() => (init_rr1_v10e(), rr1_v10e_exports));
4321
- break;
4322
- case "PEF3":
4323
- mod = await Promise.resolve().then(() => (init_pef3(), pef3_exports));
4324
- break;
4325
- case "PEF_KOR3":
4326
- mod = await Promise.resolve().then(() => (init_pef_kor3(), pef_kor3_exports));
4327
- break;
4328
- default:
4329
- throw new Error(`Unknown schema type: ${type}`);
4330
- }
4331
- const exportName = `${type}Schema`;
4332
- const schema = mod[exportName];
4333
- if (!schema) {
4334
- throw new Error(`Schema export "${exportName}" not found in module for type "${type}"`);
4335
- }
4336
- schemaCache.set(type, schema);
4337
- return schema;
4338
- }
4339
- var SchemaRegistry = {
4340
- /**
4341
- * Get a Zod schema by type. Lazy-loads the module on first access.
4342
- */
4343
- async get(type) {
4344
- return loadSchema(type);
4345
- },
4346
- /**
4347
- * List all available schema types.
4348
- */
4349
- availableSchemas() {
4350
- return ["FA3", "FA2", "RR1_V11E", "RR1_V10E", "PEF3", "PEF_KOR3"];
4351
- },
4352
- /**
4353
- * Detect schema type from XML namespace URI and/or root element name.
4354
- *
4355
- * Detection priority:
4356
- * 1. Namespace URI match (unique per FA/RR schemas)
4357
- * 2. Root element name match (for PEF/PEF_KOR which use UBL namespaces)
4358
- */
4359
- detect(namespace, rootElement) {
4360
- if (namespace) {
4361
- const byNs = NAMESPACE_MAP[namespace];
4362
- if (byNs) return byNs;
4363
- }
4364
- if (rootElement) {
4365
- const byRoot = ROOT_ELEMENT_MAP[rootElement];
4366
- if (byRoot) return byRoot;
4367
- }
4368
- return null;
4369
- }
4370
- };
4371
-
4372
- // src/validation/invoice-validator.ts
4373
- function validateWellFormedness(xml, _parsed) {
4374
- if (!xml || !xml.trim()) {
4375
- return {
4376
- valid: false,
4377
- schemaType: null,
4378
- errors: [{ code: "MALFORMED_XML", message: "Empty XML input" }]
4379
- };
4380
- }
4381
- const { object, rootElement, namespace, errors } = _parsed ?? xmlToObject(xml);
4382
- if (errors.length > 0 || !object) {
4383
- return {
4384
- valid: false,
4385
- schemaType: null,
4386
- errors: errors.map((msg) => ({ code: "MALFORMED_XML", message: msg }))
4387
- };
4388
- }
4389
- const schemaType = SchemaRegistry.detect(namespace, rootElement);
4390
- return { valid: true, schemaType, errors: [] };
4391
- }
4392
- async function validateSchema(xml, options, _parsed) {
4393
- const { object, rootElement, namespace, errors: parseErrors } = _parsed ?? xmlToObject(xml);
4394
- if (parseErrors.length > 0 || !object) {
4395
- return {
4396
- valid: false,
4397
- schemaType: null,
4398
- errors: parseErrors.map((msg) => ({ code: "MALFORMED_XML", message: msg }))
4399
- };
4400
- }
4401
- const schemaType = options?.schema ?? SchemaRegistry.detect(namespace, rootElement);
4402
- if (!schemaType) {
4403
- return {
4404
- valid: false,
4405
- schemaType: null,
4406
- errors: [{
4407
- code: "UNKNOWN_SCHEMA",
4408
- message: `Cannot detect schema type from namespace "${namespace}" and root element "${rootElement}"`
4409
- }]
4410
- };
4411
- }
4412
- const schema = await SchemaRegistry.get(schemaType);
4413
- const result = schema.safeParse(object);
4414
- if (result.success) {
4415
- return { valid: true, schemaType, errors: [] };
4416
- }
4417
- const prefix = rootElement ? `/${rootElement}/` : "/";
4418
- const validationErrors = result.error.issues.map((issue) => {
4419
- const zodPath = issue.path.join("/");
4420
- const path = zodPath ? `${prefix}${zodPath}` : rootElement ? `/${rootElement}` : void 0;
4421
- return {
4422
- code: mapZodErrorCode(issue),
4423
- message: issue.message,
4424
- path
4425
- };
4426
- });
4427
- return { valid: false, schemaType, errors: validationErrors };
4428
- }
4429
- function mapZodErrorCode(issue) {
4430
- switch (issue.code) {
4431
- case "invalid_type":
4432
- return issue.input === void 0 ? "MISSING_REQUIRED_ELEMENT" : "INVALID_VALUE";
4433
- case "invalid_enum_value":
4434
- // Zod v3
4435
- case "invalid_value":
4436
- return "INVALID_ENUM_VALUE";
4437
- case "invalid_string":
4438
- // Zod v3
4439
- case "invalid_format":
4440
- return "PATTERN_MISMATCH";
4441
- case "too_big":
4442
- return "MAX_OCCURS_EXCEEDED";
4443
- default:
4444
- return "SCHEMA_VALIDATION_ERROR";
4445
- }
4446
- }
4447
- function validateBusinessRules(xml, _parsed) {
4448
- const { object, rootElement, namespace, errors: parseErrors } = _parsed ?? xmlToObject(xml);
4449
- if (parseErrors.length > 0 || !object) {
4450
- return {
4451
- valid: false,
4452
- schemaType: null,
4453
- errors: parseErrors.map((msg) => ({ code: "MALFORMED_XML", message: msg }))
4454
- };
4455
- }
4456
- const schemaType = SchemaRegistry.detect(namespace, rootElement);
4457
- const errors = [];
4458
- collectNipPeselErrors(object, rootElement ? `/${rootElement}` : "", errors);
4459
- collectDateErrors(object, rootElement, errors);
4460
- return { valid: errors.length === 0, schemaType, errors };
4461
- }
4462
- function collectNipPeselErrors(obj, path, errors) {
4463
- for (const [key, value] of Object.entries(obj)) {
4464
- const currentPath = path ? `${path}/${key}` : key;
4465
- if (key === "NIP" && typeof value === "string") {
4466
- if (!isValidNip(value)) {
4467
- errors.push({
4468
- code: "INVALID_NIP_CHECKSUM",
4469
- message: `Invalid NIP checksum: ${value}`,
4470
- path: currentPath
4471
- });
4472
- }
4473
- } else if (key === "PESEL" && typeof value === "string") {
4474
- if (!isValidPesel(value)) {
4475
- errors.push({
4476
- code: "INVALID_PESEL_CHECKSUM",
4477
- message: `Invalid PESEL checksum: ${value}`,
4478
- path: currentPath
4479
- });
4480
- }
4481
- } else if (typeof value === "object" && value !== null) {
4482
- if (Array.isArray(value)) {
4483
- for (let i = 0; i < value.length; i++) {
4484
- if (typeof value[i] === "object" && value[i] !== null) {
4485
- collectNipPeselErrors(value[i], `${currentPath}/${i}`, errors);
4486
- }
4487
- }
4488
- } else {
4489
- collectNipPeselErrors(value, currentPath, errors);
4490
- }
4491
- }
4492
- }
4493
- }
4494
- function getPolandLocalDate() {
4495
- return new Intl.DateTimeFormat("sv-SE", { timeZone: "Europe/Warsaw" }).format(Date.now());
4496
- }
4497
- function collectDateErrors(obj, rootElement, errors) {
4498
- const fa = obj["Fa"];
4499
- if (!fa || typeof fa !== "object") return;
4500
- const p1 = fa["P_1"];
4501
- if (typeof p1 !== "string") return;
4502
- const today = getPolandLocalDate();
4503
- if (p1 > today) {
4504
- const prefix = rootElement ? `/${rootElement}` : "";
4505
- errors.push({
4506
- code: "FUTURE_INVOICE_DATE",
4507
- message: `Invoice date P_1 (${p1}) is in the future \u2014 KSeF rejects invoices with P_1 > today (${today})`,
4508
- path: `${prefix}/Fa/P_1`
4509
- });
4510
- }
4511
- }
4512
- async function validate(xml, options) {
4513
- const parsed = xml && xml.trim() ? xmlToObject(xml) : void 0;
4514
- const l1 = validateWellFormedness(xml, parsed);
4515
- if (!l1.valid) return l1;
4516
- const l2 = await validateSchema(xml, options, parsed);
4517
- if (!l2.valid) return l2;
4518
- const l3 = validateBusinessRules(xml, parsed);
4519
- return { ...l3, schemaType: l2.schemaType };
4520
- }
5062
+ RestRequest: () => RestRequest,
5063
+ RouteBuilder: () => RouteBuilder,
5064
+ Routes: () => Routes,
5065
+ SUBUNIT_NAME_MAX_LENGTH: () => SUBUNIT_NAME_MAX_LENGTH,
5066
+ SUBUNIT_NAME_MIN_LENGTH: () => SUBUNIT_NAME_MIN_LENGTH,
5067
+ SchemaRegistry: () => SchemaRegistry,
5068
+ SessionStatusService: () => SessionStatusService,
5069
+ Sha256Base64: () => Sha256Base64,
5070
+ SignatureService: () => SignatureService,
5071
+ SystemCode: () => SystemCode,
5072
+ TestDataService: () => TestDataService,
5073
+ TokenService: () => TokenService,
5074
+ UpoVersion: () => UpoVersion,
5075
+ VatUe: () => VatUe,
5076
+ VerificationLinkService: () => VerificationLinkService,
5077
+ addBusinessDays: () => addBusinessDays,
5078
+ authenticateWithCertificate: () => authenticateWithCertificate,
5079
+ authenticateWithExternalSignature: () => authenticateWithExternalSignature,
5080
+ authenticateWithPkcs12: () => authenticateWithPkcs12,
5081
+ authenticateWithToken: () => authenticateWithToken,
5082
+ batchValidationDetails: () => batchValidationDetails,
5083
+ buildUnsignedAuthTokenRequestXml: () => buildUnsignedAuthTokenRequestXml,
5084
+ calculateBackoff: () => calculateBackoff,
5085
+ calculateOfflineDeadline: () => calculateOfflineDeadline,
5086
+ createZip: () => createZip,
5087
+ decodeJwtPayload: () => decodeJwtPayload,
5088
+ deduplicateByKsefNumber: () => deduplicateByKsefNumber,
5089
+ defaultPresignedUrlPolicy: () => defaultPresignedUrlPolicy,
5090
+ defaultRateLimitPolicy: () => defaultRateLimitPolicy,
5091
+ defaultRetryPolicy: () => defaultRetryPolicy,
5092
+ defaultTransport: () => defaultTransport,
5093
+ exportAndDownload: () => exportAndDownload,
5094
+ exportInvoices: () => exportInvoices,
5095
+ extendDeadlineForMaintenance: () => extendDeadlineForMaintenance,
5096
+ extractInvoiceFields: () => extractInvoiceFields,
5097
+ getDefaultReason: () => getDefaultReason,
5098
+ getEffectiveStartDate: () => getEffectiveStartDate,
5099
+ getFormCode: () => getFormCode,
5100
+ getTimeUntilDeadline: () => getTimeUntilDeadline,
5101
+ incrementalExportAndDownload: () => incrementalExportAndDownload,
5102
+ isExpired: () => isExpired,
5103
+ isRetryableError: () => isRetryableError,
5104
+ isRetryableStatus: () => isRetryableStatus,
5105
+ isValidBase64: () => isValidBase64,
5106
+ isValidCertificateFingerprint: () => isValidCertificateFingerprint,
5107
+ isValidCertificateName: () => isValidCertificateName,
5108
+ isValidInternalId: () => isValidInternalId,
5109
+ isValidIp4Address: () => isValidIp4Address,
5110
+ isValidKsefNumber: () => isValidKsefNumber,
5111
+ isValidKsefNumberV35: () => isValidKsefNumberV35,
5112
+ isValidKsefNumberV36: () => isValidKsefNumberV36,
5113
+ isValidNip: () => isValidNip,
5114
+ isValidNipVatUe: () => isValidNipVatUe,
5115
+ isValidPeppolId: () => isValidPeppolId,
5116
+ isValidPesel: () => isValidPesel,
5117
+ isValidReferenceNumber: () => isValidReferenceNumber,
5118
+ isValidSha256Base64: () => isValidSha256Base64,
5119
+ isValidVatUe: () => isValidVatUe,
5120
+ nextBusinessDay: () => nextBusinessDay,
5121
+ openOnlineSession: () => openOnlineSession,
5122
+ openSendAndClose: () => openSendAndClose,
5123
+ parseFormCode: () => parseFormCode,
5124
+ parseKSeFTokenContext: () => parseKSeFTokenContext,
5125
+ parseRetryAfter: () => parseRetryAfter,
5126
+ parseUpoXml: () => parseUpoXml,
5127
+ pollUntil: () => pollUntil,
5128
+ resolveOptions: () => resolveOptions,
5129
+ sleep: () => sleep,
5130
+ unzip: () => unzip,
5131
+ updateContinuationPoint: () => updateContinuationPoint,
5132
+ uploadBatch: () => uploadBatch,
5133
+ uploadBatchParsed: () => uploadBatchParsed,
5134
+ uploadBatchStream: () => uploadBatchStream,
5135
+ uploadBatchStreamParsed: () => uploadBatchStreamParsed,
5136
+ validate: () => validate,
5137
+ validateBatch: () => validateBatch,
5138
+ validateBusinessRules: () => validateBusinessRules,
5139
+ validateFormCodeForSession: () => validateFormCodeForSession,
5140
+ validatePresignedUrl: () => validatePresignedUrl,
5141
+ validateSchema: () => validateSchema,
5142
+ validateWellFormedness: () => validateWellFormedness,
5143
+ xmlToObject: () => xmlToObject
5144
+ });
5145
+ module.exports = __toCommonJS(index_exports);
5146
+ init_config();
5147
+ init_errors();
4521
5148
 
4522
- // src/models/document-structures/types.ts
4523
- var SystemCode = {
4524
- FA_2: "FA (2)",
4525
- FA_3: "FA (3)",
4526
- PEF_3: "PEF (3)",
4527
- PEF_KOR_3: "PEF_KOR (3)",
4528
- FA_RR_1: "FA_RR (1)"
4529
- };
4530
- var FORM_CODES = {
4531
- FA_2: { systemCode: "FA (2)", schemaVersion: "1-0E", value: "FA" },
4532
- FA_3: { systemCode: "FA (3)", schemaVersion: "1-0E", value: "FA" },
4533
- PEF_3: { systemCode: "PEF (3)", schemaVersion: "2-1", value: "PEF" },
4534
- PEF_KOR_3: { systemCode: "PEF_KOR (3)", schemaVersion: "2-1", value: "PEF" },
4535
- FA_RR_1_LEGACY: { systemCode: "FA_RR (1)", schemaVersion: "1-0E", value: "RR" },
4536
- FA_RR_1_TRANSITION: { systemCode: "FA_RR (1)", schemaVersion: "1-1E", value: "RR" },
4537
- FA_RR_1: { systemCode: "FA_RR (1)", schemaVersion: "1-1E", value: "FA_RR" }
4538
- };
4539
- var DEFAULT_FORM_CODE = FORM_CODES.FA_3;
4540
- var INVOICE_TYPES_BY_SYSTEM_CODE = {
4541
- [SystemCode.FA_2]: ["Vat", "Zal", "Kor", "Roz", "Upr", "KorZal", "KorRoz"],
4542
- [SystemCode.FA_3]: ["Vat", "Zal", "Kor", "Roz", "Upr", "KorZal", "KorRoz"],
4543
- [SystemCode.PEF_3]: ["VatPef", "VatPefSp", "KorPef"],
4544
- [SystemCode.PEF_KOR_3]: ["KorPef"],
4545
- [SystemCode.FA_RR_1]: ["VatRr", "KorVatRr"]
4546
- };
4547
- var FORM_CODE_KEYS = {
4548
- FA2: FORM_CODES.FA_2,
4549
- FA3: FORM_CODES.FA_3,
4550
- PEF3: FORM_CODES.PEF_3,
4551
- PEFKOR3: FORM_CODES.PEF_KOR_3,
4552
- FARR1: FORM_CODES.FA_RR_1
4553
- };
5149
+ // src/http/index.ts
5150
+ init_route_builder();
5151
+ init_rest_request();
5152
+ init_rest_client();
5153
+ init_routes();
5154
+ init_transport();
5155
+ init_retry_policy();
5156
+ init_rate_limit_policy();
5157
+ init_auth_manager();
5158
+ init_presigned_url_policy();
5159
+ init_ksef_feature();
4554
5160
 
4555
- // src/models/document-structures/helpers.ts
4556
- var SYSTEM_CODE_TO_FORM_CODE = {
4557
- [SystemCode.FA_2]: FORM_CODES.FA_2,
4558
- [SystemCode.FA_3]: FORM_CODES.FA_3,
4559
- [SystemCode.PEF_3]: FORM_CODES.PEF_3,
4560
- [SystemCode.PEF_KOR_3]: FORM_CODES.PEF_KOR_3,
4561
- [SystemCode.FA_RR_1]: FORM_CODES.FA_RR_1
4562
- };
4563
- var ALL_FORM_CODES = Object.values(FORM_CODES);
4564
- var BATCH_DISALLOWED_SYSTEM_CODES = /* @__PURE__ */ new Set([
4565
- SystemCode.PEF_3,
4566
- SystemCode.PEF_KOR_3
4567
- ]);
4568
- function getFormCode(systemCode) {
4569
- return SYSTEM_CODE_TO_FORM_CODE[systemCode];
4570
- }
4571
- function parseFormCode(raw) {
4572
- const match = ALL_FORM_CODES.find(
4573
- (fc) => fc.systemCode === raw.systemCode && fc.schemaVersion === raw.schemaVersion && fc.value === raw.value
4574
- );
4575
- return match ?? raw;
4576
- }
4577
- function validateFormCodeForSession(formCode, sessionType) {
4578
- if (sessionType === "online") return true;
4579
- return !BATCH_DISALLOWED_SYSTEM_CODES.has(formCode.systemCode);
4580
- }
5161
+ // src/validation/index.ts
5162
+ init_patterns();
5163
+
5164
+ // src/validation/constraints.ts
5165
+ var REQUIRED_CHALLENGE_LENGTH = 36;
5166
+ var CERTIFICATE_NAME_MIN_LENGTH = 5;
5167
+ var CERTIFICATE_NAME_MAX_LENGTH = 100;
5168
+ var SUBUNIT_NAME_MIN_LENGTH = 5;
5169
+ var SUBUNIT_NAME_MAX_LENGTH = 256;
5170
+ var PERMISSION_DESCRIPTION_MIN_LENGTH = 5;
5171
+ var PERMISSION_DESCRIPTION_MAX_LENGTH = 256;
5172
+
5173
+ // src/validation/index.ts
5174
+ init_xml_to_object();
5175
+ init_schema_registry();
5176
+ init_invoice_validator();
5177
+
5178
+ // src/models/index.ts
5179
+ init_document_structures();
4581
5180
 
4582
5181
  // src/services/index.ts
4583
5182
  init_auth();
@@ -5264,93 +5863,8 @@ function escapeXml2(str) {
5264
5863
  return str.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&apos;");
5265
5864
  }
5266
5865
 
5267
- // src/utils/zip.ts
5268
- var import_yazl = require("yazl");
5269
- var import_yauzl = require("yauzl");
5270
- var DEFAULT_UNZIP_OPTIONS = {
5271
- maxFiles: 1e4,
5272
- maxTotalUncompressedSize: 2e9,
5273
- maxFileUncompressedSize: 5e8,
5274
- maxCompressionRatio: 200
5275
- };
5276
- async function createZip(entries) {
5277
- return new Promise((resolve, reject) => {
5278
- const zipfile = new import_yazl.ZipFile();
5279
- for (const entry of entries) {
5280
- zipfile.addBuffer(Buffer.from(entry.content), entry.fileName);
5281
- }
5282
- const chunks = [];
5283
- zipfile.outputStream.on("data", (chunk) => chunks.push(chunk));
5284
- zipfile.outputStream.on("error", (err) => reject(err));
5285
- zipfile.outputStream.on("end", () => resolve(Buffer.concat(chunks)));
5286
- zipfile.end();
5287
- });
5288
- }
5289
- async function unzip(buffer, options = {}) {
5290
- const limits = { ...DEFAULT_UNZIP_OPTIONS, ...options };
5291
- return new Promise((resolve, reject) => {
5292
- (0, import_yauzl.fromBuffer)(buffer, { lazyEntries: true }, (err, zipfile) => {
5293
- if (err || !zipfile) {
5294
- reject(err ?? new Error("Failed to open zip buffer"));
5295
- return;
5296
- }
5297
- const files = /* @__PURE__ */ new Map();
5298
- let totalUncompressed = 0;
5299
- zipfile.readEntry();
5300
- zipfile.on("entry", (entry) => {
5301
- if (entry.fileName.endsWith("/")) {
5302
- zipfile.readEntry();
5303
- return;
5304
- }
5305
- if (limits.maxFiles > 0 && files.size >= limits.maxFiles) {
5306
- reject(new Error("zip contains too many files"));
5307
- return;
5308
- }
5309
- const uncompressedSize = entry.uncompressedSize ?? 0;
5310
- const compressedSize = entry.compressedSize ?? 0;
5311
- if (limits.maxFileUncompressedSize > 0 && uncompressedSize > limits.maxFileUncompressedSize) {
5312
- reject(new Error("zip entry exceeds max_file_uncompressed_size"));
5313
- return;
5314
- }
5315
- if (limits.maxTotalUncompressedSize > 0) {
5316
- totalUncompressed += uncompressedSize;
5317
- if (totalUncompressed > limits.maxTotalUncompressedSize) {
5318
- reject(new Error("zip exceeds max_total_uncompressed_size"));
5319
- return;
5320
- }
5321
- }
5322
- if (limits.maxCompressionRatio !== null) {
5323
- if (compressedSize === 0 && uncompressedSize > 0) {
5324
- reject(new Error("zip entry has suspicious compression metadata"));
5325
- return;
5326
- }
5327
- if (compressedSize > 0 && uncompressedSize > 0) {
5328
- const ratio = uncompressedSize / compressedSize;
5329
- if (ratio > limits.maxCompressionRatio) {
5330
- reject(new Error("zip entry exceeds max_compression_ratio"));
5331
- return;
5332
- }
5333
- }
5334
- }
5335
- zipfile.openReadStream(entry, (streamErr, stream) => {
5336
- if (streamErr || !stream) {
5337
- reject(streamErr ?? new Error("Failed to read zip entry"));
5338
- return;
5339
- }
5340
- const chunks = [];
5341
- stream.on("data", (chunk) => chunks.push(chunk));
5342
- stream.on("error", (streamError) => reject(streamError));
5343
- stream.on("end", () => {
5344
- files.set(entry.fileName, Buffer.concat(chunks));
5345
- zipfile.readEntry();
5346
- });
5347
- });
5348
- });
5349
- zipfile.on("end", () => resolve(files));
5350
- zipfile.on("error", (zipErr) => reject(zipErr));
5351
- });
5352
- });
5353
- }
5866
+ // src/utils/index.ts
5867
+ init_zip();
5354
5868
 
5355
5869
  // src/utils/jwt.ts
5356
5870
  function decodeJwtPayload(token) {
@@ -5414,6 +5928,9 @@ async function pollUntil(action, condition, options) {
5414
5928
  );
5415
5929
  }
5416
5930
 
5931
+ // src/workflows/online-session-workflow.ts
5932
+ init_document_structures();
5933
+
5417
5934
  // src/xml/upo-parser.ts
5418
5935
  var import_fast_xml_parser = require("fast-xml-parser");
5419
5936
  init_ksef_validation_error();
@@ -5532,7 +6049,48 @@ function parseUpoXml(xml) {
5532
6049
  };
5533
6050
  }
5534
6051
 
6052
+ // src/xml/invoice-field-extractor.ts
6053
+ var import_fast_xml_parser2 = require("fast-xml-parser");
6054
+ var invoiceParser = new import_fast_xml_parser2.XMLParser({
6055
+ ignoreAttributes: false,
6056
+ attributeNamePrefix: "@_",
6057
+ parseTagValue: false,
6058
+ parseAttributeValue: false,
6059
+ removeNSPrefix: true,
6060
+ trimValues: false
6061
+ });
6062
+ function extractInvoiceFields(xml) {
6063
+ const parsed = invoiceParser.parse(xml);
6064
+ const root = parsed?.Faktura;
6065
+ if (!root || typeof root !== "object") {
6066
+ throw new Error(
6067
+ "Cannot extract invoice fields: missing <Faktura> root element. Ensure the XML is a valid KSeF invoice (FA_2, FA_3, or FA_RR)."
6068
+ );
6069
+ }
6070
+ if (root.Fa && typeof root.Fa === "object") {
6071
+ const invoiceDate = nonEmptyString(root.Fa.P_1);
6072
+ const invoiceNumber = nonEmptyString(root.Fa.P_2);
6073
+ if (invoiceDate && invoiceNumber) {
6074
+ return { invoiceNumber, invoiceDate };
6075
+ }
6076
+ }
6077
+ if (root.FakturaRR && typeof root.FakturaRR === "object") {
6078
+ const invoiceDate = nonEmptyString(root.FakturaRR.P_4B);
6079
+ const invoiceNumber = nonEmptyString(root.FakturaRR.P_4C);
6080
+ if (invoiceDate && invoiceNumber) {
6081
+ return { invoiceNumber, invoiceDate };
6082
+ }
6083
+ }
6084
+ throw new Error(
6085
+ "Cannot extract invoice number and date from XML. Expected <Fa><P_1>/<P_2> (FA format) or <FakturaRR><P_4B>/<P_4C> (RR format)."
6086
+ );
6087
+ }
6088
+ function nonEmptyString(value) {
6089
+ return typeof value === "string" && value.length > 0 ? value : void 0;
6090
+ }
6091
+
5535
6092
  // src/workflows/online-session-workflow.ts
6093
+ init_invoice_validator();
5536
6094
  init_ksef_validation_error();
5537
6095
  async function openOnlineSession(client, options) {
5538
6096
  await client.crypto.init();
@@ -5613,8 +6171,27 @@ async function openSendAndClose(client, invoices, options) {
5613
6171
  }
5614
6172
 
5615
6173
  // src/workflows/batch-session-workflow.ts
6174
+ init_document_structures();
5616
6175
  async function uploadBatch(client, zipData, options) {
5617
6176
  await client.crypto.init();
6177
+ if (options?.validate) {
6178
+ const { unzip: unzip2 } = await Promise.resolve().then(() => (init_zip(), zip_exports));
6179
+ const { validateBatch: validateBatch2, batchValidationDetails: batchValidationDetails2 } = await Promise.resolve().then(() => (init_invoice_validator(), invoice_validator_exports));
6180
+ const { KSeFValidationError: KSeFValidationError2 } = await Promise.resolve().then(() => (init_ksef_validation_error(), ksef_validation_error_exports));
6181
+ const zipBuf = Buffer.isBuffer(zipData) ? zipData : Buffer.from(zipData.buffer, zipData.byteOffset, zipData.byteLength);
6182
+ const files = await unzip2(zipBuf);
6183
+ const invoices = [...files.entries()].filter(([name]) => name.endsWith(".xml")).map(([name, data]) => ({ fileName: name, xml: data.toString("utf-8") }));
6184
+ if (invoices.length > 0) {
6185
+ const result2 = await validateBatch2(invoices);
6186
+ if (!result2.valid) {
6187
+ const invalidCount = result2.results.filter((r) => !r.result.valid).length;
6188
+ throw new KSeFValidationError2(
6189
+ `Batch validation failed: ${invalidCount} of ${invoices.length} invoices invalid`,
6190
+ batchValidationDetails2(result2)
6191
+ );
6192
+ }
6193
+ }
6194
+ }
5618
6195
  const encData = client.crypto.getEncryptionData();
5619
6196
  const formCode = options?.formCode ?? DEFAULT_FORM_CODE;
5620
6197
  const encryptFn = (part) => client.crypto.encryptAES256(part, encData.cipherKey, encData.cipherIv);
@@ -5726,6 +6303,7 @@ async function uploadBatchParsed(client, zipData, options) {
5726
6303
  }
5727
6304
 
5728
6305
  // src/workflows/invoice-export-workflow.ts
6306
+ init_zip();
5729
6307
  async function doExport(client, filters, options) {
5730
6308
  await client.crypto.init();
5731
6309
  const encData = client.crypto.getEncryptionData();
@@ -6014,7 +6592,140 @@ async function authenticateWithPkcs12(client, options) {
6014
6592
  });
6015
6593
  }
6016
6594
 
6595
+ // src/offline/index.ts
6596
+ init_deadline();
6597
+
6598
+ // src/offline/storage.ts
6599
+ function matchesFilter(invoice, filter) {
6600
+ if (filter.status !== void 0) {
6601
+ const statuses = Array.isArray(filter.status) ? filter.status : [filter.status];
6602
+ if (!statuses.includes(invoice.status)) return false;
6603
+ }
6604
+ if (filter.mode !== void 0 && invoice.mode !== filter.mode) return false;
6605
+ if (filter.sellerNip !== void 0 && invoice.sellerNip !== filter.sellerNip) return false;
6606
+ if (filter.expiringBefore !== void 0) {
6607
+ const cutoff = typeof filter.expiringBefore === "string" ? new Date(filter.expiringBefore).getTime() : filter.expiringBefore.getTime();
6608
+ if (new Date(invoice.submitBy).getTime() >= cutoff) return false;
6609
+ }
6610
+ return true;
6611
+ }
6612
+ var InMemoryOfflineInvoiceStorage = class {
6613
+ store = /* @__PURE__ */ new Map();
6614
+ async save(invoice) {
6615
+ this.store.set(invoice.id, JSON.parse(JSON.stringify(invoice)));
6616
+ }
6617
+ async get(id) {
6618
+ const entry = this.store.get(id);
6619
+ return entry ? JSON.parse(JSON.stringify(entry)) : null;
6620
+ }
6621
+ async list(filter) {
6622
+ const all = [...this.store.values()];
6623
+ if (!filter) return all.map((i) => JSON.parse(JSON.stringify(i)));
6624
+ return all.filter((i) => matchesFilter(i, filter)).map((i) => JSON.parse(JSON.stringify(i)));
6625
+ }
6626
+ async update(id, updates) {
6627
+ const existing = this.store.get(id);
6628
+ if (!existing) throw new Error(`Offline invoice not found: ${id}`);
6629
+ this.store.set(id, JSON.parse(JSON.stringify({ ...existing, ...updates })));
6630
+ }
6631
+ async delete(id) {
6632
+ this.store.delete(id);
6633
+ }
6634
+ };
6635
+
6636
+ // src/offline/file-storage.ts
6637
+ var fs2 = __toESM(require("fs/promises"), 1);
6638
+ var path = __toESM(require("path"), 1);
6639
+ var os = __toESM(require("os"), 1);
6640
+ function resolveDir(dir) {
6641
+ if (dir === "~" || dir.startsWith("~/")) {
6642
+ return path.join(os.homedir(), dir.slice(1));
6643
+ }
6644
+ return dir;
6645
+ }
6646
+ var UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
6647
+ function validateId(id) {
6648
+ if (!UUID_RE.test(id)) {
6649
+ throw new Error(`Invalid invoice ID: ${id}`);
6650
+ }
6651
+ }
6652
+ var FileOfflineInvoiceStorage = class {
6653
+ dir;
6654
+ constructor(directory) {
6655
+ this.dir = resolveDir(directory ?? "~/.ksef/offline");
6656
+ }
6657
+ async ensureDir() {
6658
+ await fs2.mkdir(this.dir, { recursive: true });
6659
+ }
6660
+ filePath(id) {
6661
+ validateId(id);
6662
+ return path.join(this.dir, `${id}.json`);
6663
+ }
6664
+ async save(invoice) {
6665
+ await this.ensureDir();
6666
+ const file = this.filePath(invoice.id);
6667
+ const tmp = `${file}.tmp`;
6668
+ await fs2.writeFile(tmp, JSON.stringify(invoice, null, 2));
6669
+ await fs2.rename(tmp, file);
6670
+ }
6671
+ async get(id) {
6672
+ const file = this.filePath(id);
6673
+ try {
6674
+ return JSON.parse(await fs2.readFile(file, "utf-8"));
6675
+ } catch (err) {
6676
+ if (err instanceof Error && "code" in err && err.code === "ENOENT") {
6677
+ return null;
6678
+ }
6679
+ console.warn(`Warning: Failed to read offline invoice ${id}: ${err instanceof Error ? err.message : String(err)}`);
6680
+ return null;
6681
+ }
6682
+ }
6683
+ async list(filter) {
6684
+ let files;
6685
+ try {
6686
+ files = (await fs2.readdir(this.dir)).filter((f) => f.endsWith(".json"));
6687
+ } catch {
6688
+ return [];
6689
+ }
6690
+ const results = [];
6691
+ for (const file of files) {
6692
+ try {
6693
+ const data = JSON.parse(
6694
+ await fs2.readFile(path.join(this.dir, file), "utf-8")
6695
+ );
6696
+ if (!filter || matchesFilter(data, filter)) {
6697
+ results.push(data);
6698
+ }
6699
+ } catch (err) {
6700
+ console.warn(`Warning: Skipping corrupt offline invoice file ${file}: ${err instanceof Error ? err.message : String(err)}`);
6701
+ }
6702
+ }
6703
+ return results;
6704
+ }
6705
+ /**
6706
+ * Update invoice metadata (read-modify-write).
6707
+ *
6708
+ * Note: No file locking — concurrent updates to the same ID may cause
6709
+ * lost writes. Acceptable for CLI (single process). Library consumers
6710
+ * running parallel operations should use external locking.
6711
+ */
6712
+ async update(id, updates) {
6713
+ const existing = await this.get(id);
6714
+ if (!existing) throw new Error(`Offline invoice not found: ${id}`);
6715
+ await this.save({ ...existing, ...updates });
6716
+ }
6717
+ async delete(id) {
6718
+ const file = this.filePath(id);
6719
+ try {
6720
+ await fs2.unlink(file);
6721
+ } catch (e) {
6722
+ if (e instanceof Error && "code" in e && e.code !== "ENOENT") throw e;
6723
+ }
6724
+ }
6725
+ };
6726
+
6017
6727
  // src/index.ts
6728
+ init_offline_invoice_workflow();
6018
6729
  init_client();
6019
6730
  // Annotate the CommonJS export names for ESM import in node:
6020
6731
  0 && (module.exports = {
@@ -6045,8 +6756,10 @@ init_client();
6045
6756
  FORM_CODES,
6046
6757
  FORM_CODE_KEYS,
6047
6758
  FileHwmStore,
6759
+ FileOfflineInvoiceStorage,
6048
6760
  INVOICE_TYPES_BY_SYSTEM_CODE,
6049
6761
  InMemoryHwmStore,
6762
+ InMemoryOfflineInvoiceStorage,
6050
6763
  InternalId,
6051
6764
  InvoiceDownloadService,
6052
6765
  InvoiceQueryFilterBuilder,
@@ -6070,6 +6783,7 @@ init_client();
6070
6783
  LimitsService,
6071
6784
  Nip,
6072
6785
  NipVatUe,
6786
+ OfflineInvoiceWorkflow,
6073
6787
  OnlineSessionService,
6074
6788
  PERMISSION_DESCRIPTION_MAX_LENGTH,
6075
6789
  PERMISSION_DESCRIPTION_MIN_LENGTH,
@@ -6099,12 +6813,15 @@ init_client();
6099
6813
  UpoVersion,
6100
6814
  VatUe,
6101
6815
  VerificationLinkService,
6816
+ addBusinessDays,
6102
6817
  authenticateWithCertificate,
6103
6818
  authenticateWithExternalSignature,
6104
6819
  authenticateWithPkcs12,
6105
6820
  authenticateWithToken,
6821
+ batchValidationDetails,
6106
6822
  buildUnsignedAuthTokenRequestXml,
6107
6823
  calculateBackoff,
6824
+ calculateOfflineDeadline,
6108
6825
  createZip,
6109
6826
  decodeJwtPayload,
6110
6827
  deduplicateByKsefNumber,
@@ -6114,9 +6831,14 @@ init_client();
6114
6831
  defaultTransport,
6115
6832
  exportAndDownload,
6116
6833
  exportInvoices,
6834
+ extendDeadlineForMaintenance,
6835
+ extractInvoiceFields,
6836
+ getDefaultReason,
6117
6837
  getEffectiveStartDate,
6118
6838
  getFormCode,
6839
+ getTimeUntilDeadline,
6119
6840
  incrementalExportAndDownload,
6841
+ isExpired,
6120
6842
  isRetryableError,
6121
6843
  isRetryableStatus,
6122
6844
  isValidBase64,
@@ -6134,6 +6856,7 @@ init_client();
6134
6856
  isValidReferenceNumber,
6135
6857
  isValidSha256Base64,
6136
6858
  isValidVatUe,
6859
+ nextBusinessDay,
6137
6860
  openOnlineSession,
6138
6861
  openSendAndClose,
6139
6862
  parseFormCode,
@@ -6150,6 +6873,7 @@ init_client();
6150
6873
  uploadBatchStream,
6151
6874
  uploadBatchStreamParsed,
6152
6875
  validate,
6876
+ validateBatch,
6153
6877
  validateBusinessRules,
6154
6878
  validateFormCodeForSession,
6155
6879
  validatePresignedUrl,