@marteye/studiojs 1.1.48-beta.1 → 1.1.49-beta.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.esm.js CHANGED
@@ -588,37 +588,73 @@ function buildMembersQueryParams(options) {
588
588
  }
589
589
  return Object.keys(queryParams).length > 0 ? queryParams : undefined;
590
590
  }
591
+ function getRole(filters) {
592
+ var _a;
593
+ return (_a = filters.role) !== null && _a !== void 0 ? _a : "both";
594
+ }
595
+ function getSourceCustomerType(filters) {
596
+ var _a;
597
+ if (filters.sourceCustomerType) {
598
+ return filters.sourceCustomerType;
599
+ }
600
+ return filters.sourceSaleId || ((_a = filters.sourceCustomerIds) === null || _a === void 0 ? void 0 : _a.length)
601
+ ? "seller"
602
+ : null;
603
+ }
604
+ function getSourceCustomerIdField(sourceCustomerType) {
605
+ return sourceCustomerType === "buyer"
606
+ ? "buyerCustomerId"
607
+ : "sellerCustomerId";
608
+ }
591
609
  function buildPreviewQueryParams(filters) {
592
610
  var _a;
593
611
  let params = {};
594
612
  let filter = buildFilterExpression(filters);
595
613
  let excludeFilters = buildExcludeFilters(filters);
614
+ let sourceCustomerType = getSourceCustomerType(filters);
596
615
  if (filter) {
597
616
  params.filter = filter;
598
617
  }
599
618
  if (excludeFilters.length > 0) {
600
619
  params.excludeFilters = JSON.stringify(excludeFilters);
601
620
  }
602
- params.role = (_a = filters.role) !== null && _a !== void 0 ? _a : "both";
621
+ params.role = getRole(filters);
603
622
  if (filters.geoBounds) {
604
623
  params.bounds = JSON.stringify(filters.geoBounds);
605
624
  }
606
625
  if (filters.secondaryFilter) {
626
+ let secondarySourceCustomerType = getSourceCustomerType(filters.secondaryFilter);
607
627
  params.secondaryFilter = JSON.stringify({
608
- role: filters.secondaryFilter.role,
628
+ role: getRole(filters.secondaryFilter),
609
629
  filter: buildFilterExpression(filters.secondaryFilter),
630
+ ...(secondarySourceCustomerType
631
+ ? { sourceCustomerType: secondarySourceCustomerType }
632
+ : {}),
633
+ ...(((_a = filters.secondaryFilter.sourceCustomerIds) === null || _a === void 0 ? void 0 : _a.length)
634
+ ? { sourceCustomerIds: filters.secondaryFilter.sourceCustomerIds }
635
+ : {}),
610
636
  ...(filters.secondaryFilter.geoBounds
611
637
  ? { bounds: filters.secondaryFilter.geoBounds }
612
638
  : {}),
613
639
  });
614
640
  }
641
+ if (sourceCustomerType) {
642
+ params.sourceCustomerType = sourceCustomerType;
643
+ }
644
+ if (filters.sourceSaleId) {
645
+ params.sourceSaleId = filters.sourceSaleId;
646
+ }
647
+ if (filters.sourceCustomerIds && filters.sourceCustomerIds.length > 0) {
648
+ params.sourceCustomerIds = JSON.stringify(filters.sourceCustomerIds);
649
+ }
615
650
  return params;
616
651
  }
617
652
  function filtersToCustomerListQuery(filters) {
618
653
  var _a;
619
654
  let excludeFilters = buildExcludeFilters(filters);
655
+ let sourceCustomerType = getSourceCustomerType(filters);
620
656
  let query = {
621
- role: (_a = filters.role) !== null && _a !== void 0 ? _a : "both",
657
+ role: getRole(filters),
622
658
  };
623
659
  let filter = buildFilterExpression(filters);
624
660
  if (filter) {
@@ -633,10 +669,26 @@ function filtersToCustomerListQuery(filters) {
633
669
  if (filters.rollingDateConfig) {
634
670
  query.rollingDateConfig = filters.rollingDateConfig;
635
671
  }
672
+ if (sourceCustomerType) {
673
+ query.sourceCustomerType = sourceCustomerType;
674
+ }
675
+ if (filters.sourceSaleId) {
676
+ query.sourceSaleId = filters.sourceSaleId;
677
+ }
678
+ if (filters.sourceCustomerIds && filters.sourceCustomerIds.length > 0) {
679
+ query.sourceCustomerIds = [...filters.sourceCustomerIds];
680
+ }
636
681
  if (filters.secondaryFilter) {
682
+ let secondarySourceCustomerType = getSourceCustomerType(filters.secondaryFilter);
637
683
  query.secondaryFilter = {
638
- role: filters.secondaryFilter.role,
684
+ role: getRole(filters.secondaryFilter),
639
685
  filter: buildFilterExpression(filters.secondaryFilter),
686
+ ...(secondarySourceCustomerType
687
+ ? { sourceCustomerType: secondarySourceCustomerType }
688
+ : {}),
689
+ ...(((_a = filters.secondaryFilter.sourceCustomerIds) === null || _a === void 0 ? void 0 : _a.length)
690
+ ? { sourceCustomerIds: [...filters.secondaryFilter.sourceCustomerIds] }
691
+ : {}),
640
692
  ...(filters.secondaryFilter.geoBounds
641
693
  ? { bounds: filters.secondaryFilter.geoBounds }
642
694
  : {}),
@@ -648,14 +700,27 @@ function filtersToCustomerListQuery(filters) {
648
700
  return query;
649
701
  }
650
702
  function queryToFilters(query) {
703
+ var _a, _b;
651
704
  if (!query) {
652
705
  return { role: "both", productCodes: [] };
653
706
  }
707
+ let sourceCustomerIds = query.sourceCustomerIds || [];
708
+ let sourceSaleId = query.sourceSaleId || null;
709
+ let sourceCustomerType = getSourceCustomerType({
710
+ sourceCustomerType: query.sourceCustomerType,
711
+ sourceSaleId,
712
+ sourceCustomerIds,
713
+ });
654
714
  let filters = {
655
- role: query.role,
715
+ role: query.role || "both",
656
716
  dateStart: extractDate(query.filter, ">="),
657
717
  dateEnd: extractDate(query.filter, "<="),
658
718
  productCodes: extractProductCodes(query.filter),
719
+ sourceCustomerType,
720
+ sourceCustomerIds: sourceCustomerIds.length > 0
721
+ ? sourceCustomerIds
722
+ : extractSourceCustomerIds(query.filter, sourceCustomerType),
723
+ sourceSaleId,
659
724
  excludedProductCodes: [],
660
725
  geoBounds: query.bounds || null,
661
726
  boughtOnlineOnly: /@boughtOnline\s*=\s*true/.test(query.filter || ""),
@@ -673,11 +738,20 @@ function queryToFilters(query) {
673
738
  filters.excludedProductCodes = uniqueStrings((filters.excludedProductCodes || []).concat(extractProductCodes(excludeFilter)));
674
739
  }
675
740
  if (query.secondaryFilter) {
741
+ let secondarySourceCustomerType = getSourceCustomerType(query.secondaryFilter) ||
742
+ (((_a = query.secondaryFilter.filter) === null || _a === void 0 ? void 0 : _a.includes("sellerCustomerId"))
743
+ ? "seller"
744
+ : ((_b = query.secondaryFilter.filter) === null || _b === void 0 ? void 0 : _b.includes("buyerCustomerId"))
745
+ ? "buyer"
746
+ : null);
676
747
  filters.secondaryFilter = {
677
- role: query.secondaryFilter.role,
748
+ role: query.secondaryFilter.role || "both",
678
749
  dateStart: extractDate(query.secondaryFilter.filter, ">="),
679
750
  dateEnd: extractDate(query.secondaryFilter.filter, "<="),
680
751
  productCodes: extractProductCodes(query.secondaryFilter.filter),
752
+ sourceCustomerType: secondarySourceCustomerType,
753
+ sourceCustomerIds: query.secondaryFilter.sourceCustomerIds ||
754
+ extractSourceCustomerIds(query.secondaryFilter.filter, secondarySourceCustomerType),
681
755
  geoBounds: query.secondaryFilter.bounds || null,
682
756
  rollingDateConfig: query.secondaryFilter.rollingDateConfig,
683
757
  };
@@ -694,6 +768,15 @@ function mergeCustomerListFilters(base, updates) {
694
768
  merged.dateEnd = updates.dateEnd;
695
769
  if (updates.productCodes !== undefined)
696
770
  merged.productCodes = [...updates.productCodes];
771
+ if (updates.sourceCustomerType !== undefined) {
772
+ merged.sourceCustomerType = updates.sourceCustomerType;
773
+ }
774
+ if (updates.sourceCustomerIds !== undefined) {
775
+ merged.sourceCustomerIds = [...updates.sourceCustomerIds];
776
+ }
777
+ if (updates.sourceSaleId !== undefined) {
778
+ merged.sourceSaleId = updates.sourceSaleId;
779
+ }
697
780
  if (updates.excludeDateStart !== undefined) {
698
781
  merged.excludeDateStart = updates.excludeDateStart;
699
782
  }
@@ -724,7 +807,10 @@ function mergeCustomerListFilters(base, updates) {
724
807
  else {
725
808
  let nextSecondary = merged.secondaryFilter
726
809
  ? { ...merged.secondaryFilter }
727
- : { role: updates.secondaryFilter.role || "both", productCodes: [] };
810
+ : {
811
+ role: updates.secondaryFilter.role || "both",
812
+ productCodes: [],
813
+ };
728
814
  if (updates.secondaryFilter.role !== undefined) {
729
815
  nextSecondary.role = updates.secondaryFilter.role;
730
816
  }
@@ -737,6 +823,15 @@ function mergeCustomerListFilters(base, updates) {
737
823
  if (updates.secondaryFilter.productCodes !== undefined) {
738
824
  nextSecondary.productCodes = [...updates.secondaryFilter.productCodes];
739
825
  }
826
+ if (updates.secondaryFilter.sourceCustomerType !== undefined) {
827
+ nextSecondary.sourceCustomerType =
828
+ updates.secondaryFilter.sourceCustomerType;
829
+ }
830
+ if (updates.secondaryFilter.sourceCustomerIds !== undefined) {
831
+ nextSecondary.sourceCustomerIds = [
832
+ ...updates.secondaryFilter.sourceCustomerIds,
833
+ ];
834
+ }
740
835
  if (updates.secondaryFilter.geoBounds !== undefined) {
741
836
  nextSecondary.geoBounds = updates.secondaryFilter.geoBounds;
742
837
  }
@@ -776,6 +871,7 @@ function buildExcludeFilters(filters) {
776
871
  return excludeFilters;
777
872
  }
778
873
  function buildFilterExpression(filters) {
874
+ var _a;
779
875
  let fixedClauses = [];
780
876
  let alternativeGroups = [];
781
877
  if (filters.dateStart)
@@ -785,6 +881,12 @@ function buildFilterExpression(filters) {
785
881
  if (filters.productCodes && filters.productCodes.length > 0) {
786
882
  alternativeGroups.push(filters.productCodes.map((code) => `productCode = "${code}"`));
787
883
  }
884
+ if (!filters.sourceSaleId &&
885
+ filters.sourceCustomerType &&
886
+ ((_a = filters.sourceCustomerIds) === null || _a === void 0 ? void 0 : _a.length)) {
887
+ let sourceCustomerIdField = getSourceCustomerIdField(filters.sourceCustomerType);
888
+ alternativeGroups.push(filters.sourceCustomerIds.map((id) => `${sourceCustomerIdField} = "${id.replace(/"/g, '\\"')}"`));
889
+ }
788
890
  if (filters.boughtOnlineOnly) {
789
891
  fixedClauses.push(`@boughtOnline = true`);
790
892
  }
@@ -926,6 +1028,21 @@ function extractProductCodes(filter) {
926
1028
  }
927
1029
  return uniqueStrings(extractAllMatches(filter, /productCode\s*=\s*"([^"]+)"/g));
928
1030
  }
1031
+ function extractSourceCustomerIds(filter, sourceCustomerType) {
1032
+ if (!filter || !sourceCustomerType) {
1033
+ return [];
1034
+ }
1035
+ let fieldName = getSourceCustomerIdField(sourceCustomerType);
1036
+ let escapedFieldName = fieldName.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
1037
+ let inMatch = filter.match(new RegExp(`${escapedFieldName}\\s+IN\\s*\\(([^)]+)\\)`));
1038
+ if (inMatch) {
1039
+ return uniqueStrings(inMatch[1]
1040
+ .split(",")
1041
+ .map((value) => value.trim().replace(/^"|"$/g, ""))
1042
+ .filter(Boolean));
1043
+ }
1044
+ return uniqueStrings(extractAllMatches(filter, new RegExp(`${escapedFieldName}\\s*=\\s*"([^"]+)"`, "g")));
1045
+ }
929
1046
  function extractAllMatches(filter, regex) {
930
1047
  if (!filter) {
931
1048
  return [];
@@ -947,7 +1064,7 @@ function isRateLimitError(error) {
947
1064
 
948
1065
  var util;
949
1066
  (function (util) {
950
- util.assertEqual = (val) => val;
1067
+ util.assertEqual = (_) => { };
951
1068
  function assertIs(_arg) { }
952
1069
  util.assertIs = assertIs;
953
1070
  function assertNever(_x) {
@@ -994,11 +1111,9 @@ var util;
994
1111
  };
995
1112
  util.isInteger = typeof Number.isInteger === "function"
996
1113
  ? (val) => Number.isInteger(val) // eslint-disable-line ban/ban
997
- : (val) => typeof val === "number" && isFinite(val) && Math.floor(val) === val;
1114
+ : (val) => typeof val === "number" && Number.isFinite(val) && Math.floor(val) === val;
998
1115
  function joinValues(array, separator = " | ") {
999
- return array
1000
- .map((val) => (typeof val === "string" ? `'${val}'` : val))
1001
- .join(separator);
1116
+ return array.map((val) => (typeof val === "string" ? `'${val}'` : val)).join(separator);
1002
1117
  }
1003
1118
  util.joinValues = joinValues;
1004
1119
  util.jsonStringifyReplacer = (_, value) => {
@@ -1047,7 +1162,7 @@ const getParsedType = (data) => {
1047
1162
  case "string":
1048
1163
  return ZodParsedType.string;
1049
1164
  case "number":
1050
- return isNaN(data) ? ZodParsedType.nan : ZodParsedType.number;
1165
+ return Number.isNaN(data) ? ZodParsedType.nan : ZodParsedType.number;
1051
1166
  case "boolean":
1052
1167
  return ZodParsedType.boolean;
1053
1168
  case "function":
@@ -1063,10 +1178,7 @@ const getParsedType = (data) => {
1063
1178
  if (data === null) {
1064
1179
  return ZodParsedType.null;
1065
1180
  }
1066
- if (data.then &&
1067
- typeof data.then === "function" &&
1068
- data.catch &&
1069
- typeof data.catch === "function") {
1181
+ if (data.then && typeof data.then === "function" && data.catch && typeof data.catch === "function") {
1070
1182
  return ZodParsedType.promise;
1071
1183
  }
1072
1184
  if (typeof Map !== "undefined" && data instanceof Map) {
@@ -1102,10 +1214,6 @@ const ZodIssueCode = util.arrayToEnum([
1102
1214
  "not_multiple_of",
1103
1215
  "not_finite",
1104
1216
  ]);
1105
- const quotelessJson = (obj) => {
1106
- const json = JSON.stringify(obj, null, 2);
1107
- return json.replace(/"([^"]+)":/g, "$1:");
1108
- };
1109
1217
  class ZodError extends Error {
1110
1218
  get errors() {
1111
1219
  return this.issues;
@@ -1198,8 +1306,9 @@ class ZodError extends Error {
1198
1306
  const formErrors = [];
1199
1307
  for (const sub of this.issues) {
1200
1308
  if (sub.path.length > 0) {
1201
- fieldErrors[sub.path[0]] = fieldErrors[sub.path[0]] || [];
1202
- fieldErrors[sub.path[0]].push(mapper(sub));
1309
+ const firstEl = sub.path[0];
1310
+ fieldErrors[firstEl] = fieldErrors[firstEl] || [];
1311
+ fieldErrors[firstEl].push(mapper(sub));
1203
1312
  }
1204
1313
  else {
1205
1314
  formErrors.push(mapper(sub));
@@ -1282,17 +1391,11 @@ const errorMap = (issue, _ctx) => {
1282
1391
  else if (issue.type === "string")
1283
1392
  message = `String must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `over`} ${issue.minimum} character(s)`;
1284
1393
  else if (issue.type === "number")
1285
- message = `Number must be ${issue.exact
1286
- ? `exactly equal to `
1287
- : issue.inclusive
1288
- ? `greater than or equal to `
1289
- : `greater than `}${issue.minimum}`;
1394
+ message = `Number must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${issue.minimum}`;
1395
+ else if (issue.type === "bigint")
1396
+ message = `Number must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${issue.minimum}`;
1290
1397
  else if (issue.type === "date")
1291
- message = `Date must be ${issue.exact
1292
- ? `exactly equal to `
1293
- : issue.inclusive
1294
- ? `greater than or equal to `
1295
- : `greater than `}${new Date(Number(issue.minimum))}`;
1398
+ message = `Date must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${new Date(Number(issue.minimum))}`;
1296
1399
  else
1297
1400
  message = "Invalid input";
1298
1401
  break;
@@ -1302,23 +1405,11 @@ const errorMap = (issue, _ctx) => {
1302
1405
  else if (issue.type === "string")
1303
1406
  message = `String must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `under`} ${issue.maximum} character(s)`;
1304
1407
  else if (issue.type === "number")
1305
- message = `Number must be ${issue.exact
1306
- ? `exactly`
1307
- : issue.inclusive
1308
- ? `less than or equal to`
1309
- : `less than`} ${issue.maximum}`;
1408
+ message = `Number must be ${issue.exact ? `exactly` : issue.inclusive ? `less than or equal to` : `less than`} ${issue.maximum}`;
1310
1409
  else if (issue.type === "bigint")
1311
- message = `BigInt must be ${issue.exact
1312
- ? `exactly`
1313
- : issue.inclusive
1314
- ? `less than or equal to`
1315
- : `less than`} ${issue.maximum}`;
1410
+ message = `BigInt must be ${issue.exact ? `exactly` : issue.inclusive ? `less than or equal to` : `less than`} ${issue.maximum}`;
1316
1411
  else if (issue.type === "date")
1317
- message = `Date must be ${issue.exact
1318
- ? `exactly`
1319
- : issue.inclusive
1320
- ? `smaller than or equal to`
1321
- : `smaller than`} ${new Date(Number(issue.maximum))}`;
1412
+ message = `Date must be ${issue.exact ? `exactly` : issue.inclusive ? `smaller than or equal to` : `smaller than`} ${new Date(Number(issue.maximum))}`;
1322
1413
  else
1323
1414
  message = "Invalid input";
1324
1415
  break;
@@ -1342,9 +1433,6 @@ const errorMap = (issue, _ctx) => {
1342
1433
  };
1343
1434
 
1344
1435
  let overrideErrorMap = errorMap;
1345
- function setErrorMap(map) {
1346
- overrideErrorMap = map;
1347
- }
1348
1436
  function getErrorMap() {
1349
1437
  return overrideErrorMap;
1350
1438
  }
@@ -1377,7 +1465,6 @@ const makeIssue = (params) => {
1377
1465
  message: errorMessage,
1378
1466
  };
1379
1467
  };
1380
- const EMPTY_PATH = [];
1381
1468
  function addIssueToContext(ctx, issueData) {
1382
1469
  const overrideMap = getErrorMap();
1383
1470
  const issue = makeIssue({
@@ -1440,8 +1527,7 @@ class ParseStatus {
1440
1527
  status.dirty();
1441
1528
  if (value.status === "dirty")
1442
1529
  status.dirty();
1443
- if (key.value !== "__proto__" &&
1444
- (typeof value.value !== "undefined" || pair.alwaysSet)) {
1530
+ if (key.value !== "__proto__" && (typeof value.value !== "undefined" || pair.alwaysSet)) {
1445
1531
  finalObject[key.value] = value.value;
1446
1532
  }
1447
1533
  }
@@ -1458,43 +1544,13 @@ const isDirty = (x) => x.status === "dirty";
1458
1544
  const isValid = (x) => x.status === "valid";
1459
1545
  const isAsync = (x) => typeof Promise !== "undefined" && x instanceof Promise;
1460
1546
 
1461
- /******************************************************************************
1462
- Copyright (c) Microsoft Corporation.
1463
-
1464
- Permission to use, copy, modify, and/or distribute this software for any
1465
- purpose with or without fee is hereby granted.
1466
-
1467
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
1468
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
1469
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
1470
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
1471
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
1472
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
1473
- PERFORMANCE OF THIS SOFTWARE.
1474
- ***************************************************************************** */
1475
-
1476
- function __classPrivateFieldGet(receiver, state, kind, f) {
1477
- if (typeof state === "function" ? receiver !== state || true : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
1478
- return state.get(receiver);
1479
- }
1480
-
1481
- function __classPrivateFieldSet(receiver, state, value, kind, f) {
1482
- if (typeof state === "function" ? receiver !== state || true : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
1483
- return (state.set(receiver, value)), value;
1484
- }
1485
-
1486
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
1487
- var e = new Error(message);
1488
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
1489
- };
1490
-
1491
1547
  var errorUtil;
1492
1548
  (function (errorUtil) {
1493
1549
  errorUtil.errToObj = (message) => typeof message === "string" ? { message } : message || {};
1494
- errorUtil.toString = (message) => typeof message === "string" ? message : message === null || message === void 0 ? void 0 : message.message;
1550
+ // biome-ignore lint:
1551
+ errorUtil.toString = (message) => typeof message === "string" ? message : message?.message;
1495
1552
  })(errorUtil || (errorUtil = {}));
1496
1553
 
1497
- var _ZodEnum_cache, _ZodNativeEnum_cache;
1498
1554
  class ParseInputLazyPath {
1499
1555
  constructor(parent, value, path, key) {
1500
1556
  this._cachedPath = [];
@@ -1505,7 +1561,7 @@ class ParseInputLazyPath {
1505
1561
  }
1506
1562
  get path() {
1507
1563
  if (!this._cachedPath.length) {
1508
- if (this._key instanceof Array) {
1564
+ if (Array.isArray(this._key)) {
1509
1565
  this._cachedPath.push(...this._path, ...this._key);
1510
1566
  }
1511
1567
  else {
@@ -1545,17 +1601,16 @@ function processCreateParams(params) {
1545
1601
  if (errorMap)
1546
1602
  return { errorMap: errorMap, description };
1547
1603
  const customMap = (iss, ctx) => {
1548
- var _a, _b;
1549
1604
  const { message } = params;
1550
1605
  if (iss.code === "invalid_enum_value") {
1551
- return { message: message !== null && message !== void 0 ? message : ctx.defaultError };
1606
+ return { message: message ?? ctx.defaultError };
1552
1607
  }
1553
1608
  if (typeof ctx.data === "undefined") {
1554
- return { message: (_a = message !== null && message !== void 0 ? message : required_error) !== null && _a !== void 0 ? _a : ctx.defaultError };
1609
+ return { message: message ?? required_error ?? ctx.defaultError };
1555
1610
  }
1556
1611
  if (iss.code !== "invalid_type")
1557
1612
  return { message: ctx.defaultError };
1558
- return { message: (_b = message !== null && message !== void 0 ? message : invalid_type_error) !== null && _b !== void 0 ? _b : ctx.defaultError };
1613
+ return { message: message ?? invalid_type_error ?? ctx.defaultError };
1559
1614
  };
1560
1615
  return { errorMap: customMap, description };
1561
1616
  }
@@ -1607,14 +1662,13 @@ class ZodType {
1607
1662
  throw result.error;
1608
1663
  }
1609
1664
  safeParse(data, params) {
1610
- var _a;
1611
1665
  const ctx = {
1612
1666
  common: {
1613
1667
  issues: [],
1614
- async: (_a = params === null || params === void 0 ? void 0 : params.async) !== null && _a !== void 0 ? _a : false,
1615
- contextualErrorMap: params === null || params === void 0 ? void 0 : params.errorMap,
1668
+ async: params?.async ?? false,
1669
+ contextualErrorMap: params?.errorMap,
1616
1670
  },
1617
- path: (params === null || params === void 0 ? void 0 : params.path) || [],
1671
+ path: params?.path || [],
1618
1672
  schemaErrorMap: this._def.errorMap,
1619
1673
  parent: null,
1620
1674
  data,
@@ -1624,7 +1678,6 @@ class ZodType {
1624
1678
  return handleResult(ctx, result);
1625
1679
  }
1626
1680
  "~validate"(data) {
1627
- var _a, _b;
1628
1681
  const ctx = {
1629
1682
  common: {
1630
1683
  issues: [],
@@ -1648,7 +1701,7 @@ class ZodType {
1648
1701
  };
1649
1702
  }
1650
1703
  catch (err) {
1651
- if ((_b = (_a = err === null || err === void 0 ? void 0 : err.message) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === null || _b === void 0 ? void 0 : _b.includes("encountered")) {
1704
+ if (err?.message?.toLowerCase()?.includes("encountered")) {
1652
1705
  this["~standard"].async = true;
1653
1706
  }
1654
1707
  ctx.common = {
@@ -1675,19 +1728,17 @@ class ZodType {
1675
1728
  const ctx = {
1676
1729
  common: {
1677
1730
  issues: [],
1678
- contextualErrorMap: params === null || params === void 0 ? void 0 : params.errorMap,
1731
+ contextualErrorMap: params?.errorMap,
1679
1732
  async: true,
1680
1733
  },
1681
- path: (params === null || params === void 0 ? void 0 : params.path) || [],
1734
+ path: params?.path || [],
1682
1735
  schemaErrorMap: this._def.errorMap,
1683
1736
  parent: null,
1684
1737
  data,
1685
1738
  parsedType: getParsedType(data),
1686
1739
  };
1687
1740
  const maybeAsyncResult = this._parse({ data, path: ctx.path, parent: ctx });
1688
- const result = await (isAsync(maybeAsyncResult)
1689
- ? maybeAsyncResult
1690
- : Promise.resolve(maybeAsyncResult));
1741
+ const result = await (isAsync(maybeAsyncResult) ? maybeAsyncResult : Promise.resolve(maybeAsyncResult));
1691
1742
  return handleResult(ctx, result);
1692
1743
  }
1693
1744
  refine(check, message) {
@@ -1731,9 +1782,7 @@ class ZodType {
1731
1782
  refinement(check, refinementData) {
1732
1783
  return this._refinement((val, ctx) => {
1733
1784
  if (!check(val)) {
1734
- ctx.addIssue(typeof refinementData === "function"
1735
- ? refinementData(val, ctx)
1736
- : refinementData);
1785
+ ctx.addIssue(typeof refinementData === "function" ? refinementData(val, ctx) : refinementData);
1737
1786
  return false;
1738
1787
  }
1739
1788
  else {
@@ -1905,15 +1954,15 @@ const base64urlRegex = /^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z
1905
1954
  const dateRegexSource = `((\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-((0[13578]|1[02])-(0[1-9]|[12]\\d|3[01])|(0[469]|11)-(0[1-9]|[12]\\d|30)|(02)-(0[1-9]|1\\d|2[0-8])))`;
1906
1955
  const dateRegex = new RegExp(`^${dateRegexSource}$`);
1907
1956
  function timeRegexSource(args) {
1908
- // let regex = `\\d{2}:\\d{2}:\\d{2}`;
1909
- let regex = `([01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d`;
1957
+ let secondsRegexSource = `[0-5]\\d`;
1910
1958
  if (args.precision) {
1911
- regex = `${regex}\\.\\d{${args.precision}}`;
1959
+ secondsRegexSource = `${secondsRegexSource}\\.\\d{${args.precision}}`;
1912
1960
  }
1913
1961
  else if (args.precision == null) {
1914
- regex = `${regex}(\\.\\d+)?`;
1962
+ secondsRegexSource = `${secondsRegexSource}(\\.\\d+)?`;
1915
1963
  }
1916
- return regex;
1964
+ const secondsQuantifier = args.precision ? "+" : "?"; // require seconds if precision is nonzero
1965
+ return `([01]\\d|2[0-3]):[0-5]\\d(:${secondsRegexSource})${secondsQuantifier}`;
1917
1966
  }
1918
1967
  function timeRegex(args) {
1919
1968
  return new RegExp(`^${timeRegexSource(args)}$`);
@@ -1942,6 +1991,8 @@ function isValidJWT(jwt, alg) {
1942
1991
  return false;
1943
1992
  try {
1944
1993
  const [header] = jwt.split(".");
1994
+ if (!header)
1995
+ return false;
1945
1996
  // Convert base64url to base64
1946
1997
  const base64 = header
1947
1998
  .replace(/-/g, "+")
@@ -1950,13 +2001,15 @@ function isValidJWT(jwt, alg) {
1950
2001
  const decoded = JSON.parse(atob(base64));
1951
2002
  if (typeof decoded !== "object" || decoded === null)
1952
2003
  return false;
1953
- if (!decoded.typ || !decoded.alg)
2004
+ if ("typ" in decoded && decoded?.typ !== "JWT")
2005
+ return false;
2006
+ if (!decoded.alg)
1954
2007
  return false;
1955
2008
  if (alg && decoded.alg !== alg)
1956
2009
  return false;
1957
2010
  return true;
1958
2011
  }
1959
- catch (_a) {
2012
+ catch {
1960
2013
  return false;
1961
2014
  }
1962
2015
  }
@@ -2127,7 +2180,7 @@ class ZodString extends ZodType {
2127
2180
  try {
2128
2181
  new URL(input.data);
2129
2182
  }
2130
- catch (_a) {
2183
+ catch {
2131
2184
  ctx = this._getOrReturnCtx(input, ctx);
2132
2185
  addIssueToContext(ctx, {
2133
2186
  validation: "url",
@@ -2357,7 +2410,6 @@ class ZodString extends ZodType {
2357
2410
  return this._addCheck({ kind: "cidr", ...errorUtil.errToObj(options) });
2358
2411
  }
2359
2412
  datetime(options) {
2360
- var _a, _b;
2361
2413
  if (typeof options === "string") {
2362
2414
  return this._addCheck({
2363
2415
  kind: "datetime",
@@ -2369,10 +2421,10 @@ class ZodString extends ZodType {
2369
2421
  }
2370
2422
  return this._addCheck({
2371
2423
  kind: "datetime",
2372
- precision: typeof (options === null || options === void 0 ? void 0 : options.precision) === "undefined" ? null : options === null || options === void 0 ? void 0 : options.precision,
2373
- offset: (_a = options === null || options === void 0 ? void 0 : options.offset) !== null && _a !== void 0 ? _a : false,
2374
- local: (_b = options === null || options === void 0 ? void 0 : options.local) !== null && _b !== void 0 ? _b : false,
2375
- ...errorUtil.errToObj(options === null || options === void 0 ? void 0 : options.message),
2424
+ precision: typeof options?.precision === "undefined" ? null : options?.precision,
2425
+ offset: options?.offset ?? false,
2426
+ local: options?.local ?? false,
2427
+ ...errorUtil.errToObj(options?.message),
2376
2428
  });
2377
2429
  }
2378
2430
  date(message) {
@@ -2388,8 +2440,8 @@ class ZodString extends ZodType {
2388
2440
  }
2389
2441
  return this._addCheck({
2390
2442
  kind: "time",
2391
- precision: typeof (options === null || options === void 0 ? void 0 : options.precision) === "undefined" ? null : options === null || options === void 0 ? void 0 : options.precision,
2392
- ...errorUtil.errToObj(options === null || options === void 0 ? void 0 : options.message),
2443
+ precision: typeof options?.precision === "undefined" ? null : options?.precision,
2444
+ ...errorUtil.errToObj(options?.message),
2393
2445
  });
2394
2446
  }
2395
2447
  duration(message) {
@@ -2406,8 +2458,8 @@ class ZodString extends ZodType {
2406
2458
  return this._addCheck({
2407
2459
  kind: "includes",
2408
2460
  value: value,
2409
- position: options === null || options === void 0 ? void 0 : options.position,
2410
- ...errorUtil.errToObj(options === null || options === void 0 ? void 0 : options.message),
2461
+ position: options?.position,
2462
+ ...errorUtil.errToObj(options?.message),
2411
2463
  });
2412
2464
  }
2413
2465
  startsWith(value, message) {
@@ -2540,11 +2592,10 @@ class ZodString extends ZodType {
2540
2592
  }
2541
2593
  }
2542
2594
  ZodString.create = (params) => {
2543
- var _a;
2544
2595
  return new ZodString({
2545
2596
  checks: [],
2546
2597
  typeName: ZodFirstPartyTypeKind.ZodString,
2547
- coerce: (_a = params === null || params === void 0 ? void 0 : params.coerce) !== null && _a !== void 0 ? _a : false,
2598
+ coerce: params?.coerce ?? false,
2548
2599
  ...processCreateParams(params),
2549
2600
  });
2550
2601
  };
@@ -2553,9 +2604,9 @@ function floatSafeRemainder(val, step) {
2553
2604
  const valDecCount = (val.toString().split(".")[1] || "").length;
2554
2605
  const stepDecCount = (step.toString().split(".")[1] || "").length;
2555
2606
  const decCount = valDecCount > stepDecCount ? valDecCount : stepDecCount;
2556
- const valInt = parseInt(val.toFixed(decCount).replace(".", ""));
2557
- const stepInt = parseInt(step.toFixed(decCount).replace(".", ""));
2558
- return (valInt % stepInt) / Math.pow(10, decCount);
2607
+ const valInt = Number.parseInt(val.toFixed(decCount).replace(".", ""));
2608
+ const stepInt = Number.parseInt(step.toFixed(decCount).replace(".", ""));
2609
+ return (valInt % stepInt) / 10 ** decCount;
2559
2610
  }
2560
2611
  class ZodNumber extends ZodType {
2561
2612
  constructor() {
@@ -2594,9 +2645,7 @@ class ZodNumber extends ZodType {
2594
2645
  }
2595
2646
  }
2596
2647
  else if (check.kind === "min") {
2597
- const tooSmall = check.inclusive
2598
- ? input.data < check.value
2599
- : input.data <= check.value;
2648
+ const tooSmall = check.inclusive ? input.data < check.value : input.data <= check.value;
2600
2649
  if (tooSmall) {
2601
2650
  ctx = this._getOrReturnCtx(input, ctx);
2602
2651
  addIssueToContext(ctx, {
@@ -2611,9 +2660,7 @@ class ZodNumber extends ZodType {
2611
2660
  }
2612
2661
  }
2613
2662
  else if (check.kind === "max") {
2614
- const tooBig = check.inclusive
2615
- ? input.data > check.value
2616
- : input.data >= check.value;
2663
+ const tooBig = check.inclusive ? input.data > check.value : input.data >= check.value;
2617
2664
  if (tooBig) {
2618
2665
  ctx = this._getOrReturnCtx(input, ctx);
2619
2666
  addIssueToContext(ctx, {
@@ -2771,15 +2818,13 @@ class ZodNumber extends ZodType {
2771
2818
  return max;
2772
2819
  }
2773
2820
  get isInt() {
2774
- return !!this._def.checks.find((ch) => ch.kind === "int" ||
2775
- (ch.kind === "multipleOf" && util.isInteger(ch.value)));
2821
+ return !!this._def.checks.find((ch) => ch.kind === "int" || (ch.kind === "multipleOf" && util.isInteger(ch.value)));
2776
2822
  }
2777
2823
  get isFinite() {
2778
- let max = null, min = null;
2824
+ let max = null;
2825
+ let min = null;
2779
2826
  for (const ch of this._def.checks) {
2780
- if (ch.kind === "finite" ||
2781
- ch.kind === "int" ||
2782
- ch.kind === "multipleOf") {
2827
+ if (ch.kind === "finite" || ch.kind === "int" || ch.kind === "multipleOf") {
2783
2828
  return true;
2784
2829
  }
2785
2830
  else if (ch.kind === "min") {
@@ -2798,7 +2843,7 @@ ZodNumber.create = (params) => {
2798
2843
  return new ZodNumber({
2799
2844
  checks: [],
2800
2845
  typeName: ZodFirstPartyTypeKind.ZodNumber,
2801
- coerce: (params === null || params === void 0 ? void 0 : params.coerce) || false,
2846
+ coerce: params?.coerce || false,
2802
2847
  ...processCreateParams(params),
2803
2848
  });
2804
2849
  };
@@ -2813,7 +2858,7 @@ class ZodBigInt extends ZodType {
2813
2858
  try {
2814
2859
  input.data = BigInt(input.data);
2815
2860
  }
2816
- catch (_a) {
2861
+ catch {
2817
2862
  return this._getInvalidInput(input);
2818
2863
  }
2819
2864
  }
@@ -2825,9 +2870,7 @@ class ZodBigInt extends ZodType {
2825
2870
  const status = new ParseStatus();
2826
2871
  for (const check of this._def.checks) {
2827
2872
  if (check.kind === "min") {
2828
- const tooSmall = check.inclusive
2829
- ? input.data < check.value
2830
- : input.data <= check.value;
2873
+ const tooSmall = check.inclusive ? input.data < check.value : input.data <= check.value;
2831
2874
  if (tooSmall) {
2832
2875
  ctx = this._getOrReturnCtx(input, ctx);
2833
2876
  addIssueToContext(ctx, {
@@ -2841,9 +2884,7 @@ class ZodBigInt extends ZodType {
2841
2884
  }
2842
2885
  }
2843
2886
  else if (check.kind === "max") {
2844
- const tooBig = check.inclusive
2845
- ? input.data > check.value
2846
- : input.data >= check.value;
2887
+ const tooBig = check.inclusive ? input.data > check.value : input.data >= check.value;
2847
2888
  if (tooBig) {
2848
2889
  ctx = this._getOrReturnCtx(input, ctx);
2849
2890
  addIssueToContext(ctx, {
@@ -2975,11 +3016,10 @@ class ZodBigInt extends ZodType {
2975
3016
  }
2976
3017
  }
2977
3018
  ZodBigInt.create = (params) => {
2978
- var _a;
2979
3019
  return new ZodBigInt({
2980
3020
  checks: [],
2981
3021
  typeName: ZodFirstPartyTypeKind.ZodBigInt,
2982
- coerce: (_a = params === null || params === void 0 ? void 0 : params.coerce) !== null && _a !== void 0 ? _a : false,
3022
+ coerce: params?.coerce ?? false,
2983
3023
  ...processCreateParams(params),
2984
3024
  });
2985
3025
  };
@@ -3004,7 +3044,7 @@ class ZodBoolean extends ZodType {
3004
3044
  ZodBoolean.create = (params) => {
3005
3045
  return new ZodBoolean({
3006
3046
  typeName: ZodFirstPartyTypeKind.ZodBoolean,
3007
- coerce: (params === null || params === void 0 ? void 0 : params.coerce) || false,
3047
+ coerce: params?.coerce || false,
3008
3048
  ...processCreateParams(params),
3009
3049
  });
3010
3050
  };
@@ -3023,7 +3063,7 @@ class ZodDate extends ZodType {
3023
3063
  });
3024
3064
  return INVALID;
3025
3065
  }
3026
- if (isNaN(input.data.getTime())) {
3066
+ if (Number.isNaN(input.data.getTime())) {
3027
3067
  const ctx = this._getOrReturnCtx(input);
3028
3068
  addIssueToContext(ctx, {
3029
3069
  code: ZodIssueCode.invalid_date,
@@ -3114,7 +3154,7 @@ class ZodDate extends ZodType {
3114
3154
  ZodDate.create = (params) => {
3115
3155
  return new ZodDate({
3116
3156
  checks: [],
3117
- coerce: (params === null || params === void 0 ? void 0 : params.coerce) || false,
3157
+ coerce: params?.coerce || false,
3118
3158
  typeName: ZodFirstPartyTypeKind.ZodDate,
3119
3159
  ...processCreateParams(params),
3120
3160
  });
@@ -3436,7 +3476,8 @@ class ZodObject extends ZodType {
3436
3476
  return this._cached;
3437
3477
  const shape = this._def.shape();
3438
3478
  const keys = util.objectKeys(shape);
3439
- return (this._cached = { shape, keys });
3479
+ this._cached = { shape, keys };
3480
+ return this._cached;
3440
3481
  }
3441
3482
  _parse(input) {
3442
3483
  const parsedType = this._getType(input);
@@ -3452,8 +3493,7 @@ class ZodObject extends ZodType {
3452
3493
  const { status, ctx } = this._processInputParams(input);
3453
3494
  const { shape, keys: shapeKeys } = this._getCached();
3454
3495
  const extraKeys = [];
3455
- if (!(this._def.catchall instanceof ZodNever &&
3456
- this._def.unknownKeys === "strip")) {
3496
+ if (!(this._def.catchall instanceof ZodNever && this._def.unknownKeys === "strip")) {
3457
3497
  for (const key in ctx.data) {
3458
3498
  if (!shapeKeys.includes(key)) {
3459
3499
  extraKeys.push(key);
@@ -3541,11 +3581,10 @@ class ZodObject extends ZodType {
3541
3581
  ...(message !== undefined
3542
3582
  ? {
3543
3583
  errorMap: (issue, ctx) => {
3544
- var _a, _b, _c, _d;
3545
- const defaultError = (_c = (_b = (_a = this._def).errorMap) === null || _b === void 0 ? void 0 : _b.call(_a, issue, ctx).message) !== null && _c !== void 0 ? _c : ctx.defaultError;
3584
+ const defaultError = this._def.errorMap?.(issue, ctx).message ?? ctx.defaultError;
3546
3585
  if (issue.code === "unrecognized_keys")
3547
3586
  return {
3548
- message: (_d = errorUtil.errToObj(message).message) !== null && _d !== void 0 ? _d : defaultError,
3587
+ message: errorUtil.errToObj(message).message ?? defaultError,
3549
3588
  };
3550
3589
  return {
3551
3590
  message: defaultError,
@@ -3677,11 +3716,11 @@ class ZodObject extends ZodType {
3677
3716
  }
3678
3717
  pick(mask) {
3679
3718
  const shape = {};
3680
- util.objectKeys(mask).forEach((key) => {
3719
+ for (const key of util.objectKeys(mask)) {
3681
3720
  if (mask[key] && this.shape[key]) {
3682
3721
  shape[key] = this.shape[key];
3683
3722
  }
3684
- });
3723
+ }
3685
3724
  return new ZodObject({
3686
3725
  ...this._def,
3687
3726
  shape: () => shape,
@@ -3689,11 +3728,11 @@ class ZodObject extends ZodType {
3689
3728
  }
3690
3729
  omit(mask) {
3691
3730
  const shape = {};
3692
- util.objectKeys(this.shape).forEach((key) => {
3731
+ for (const key of util.objectKeys(this.shape)) {
3693
3732
  if (!mask[key]) {
3694
3733
  shape[key] = this.shape[key];
3695
3734
  }
3696
- });
3735
+ }
3697
3736
  return new ZodObject({
3698
3737
  ...this._def,
3699
3738
  shape: () => shape,
@@ -3707,7 +3746,7 @@ class ZodObject extends ZodType {
3707
3746
  }
3708
3747
  partial(mask) {
3709
3748
  const newShape = {};
3710
- util.objectKeys(this.shape).forEach((key) => {
3749
+ for (const key of util.objectKeys(this.shape)) {
3711
3750
  const fieldSchema = this.shape[key];
3712
3751
  if (mask && !mask[key]) {
3713
3752
  newShape[key] = fieldSchema;
@@ -3715,7 +3754,7 @@ class ZodObject extends ZodType {
3715
3754
  else {
3716
3755
  newShape[key] = fieldSchema.optional();
3717
3756
  }
3718
- });
3757
+ }
3719
3758
  return new ZodObject({
3720
3759
  ...this._def,
3721
3760
  shape: () => newShape,
@@ -3723,7 +3762,7 @@ class ZodObject extends ZodType {
3723
3762
  }
3724
3763
  required(mask) {
3725
3764
  const newShape = {};
3726
- util.objectKeys(this.shape).forEach((key) => {
3765
+ for (const key of util.objectKeys(this.shape)) {
3727
3766
  if (mask && !mask[key]) {
3728
3767
  newShape[key] = this.shape[key];
3729
3768
  }
@@ -3735,7 +3774,7 @@ class ZodObject extends ZodType {
3735
3774
  }
3736
3775
  newShape[key] = newField;
3737
3776
  }
3738
- });
3777
+ }
3739
3778
  return new ZodObject({
3740
3779
  ...this._def,
3741
3780
  shape: () => newShape,
@@ -3868,137 +3907,6 @@ ZodUnion.create = (types, params) => {
3868
3907
  ...processCreateParams(params),
3869
3908
  });
3870
3909
  };
3871
- /////////////////////////////////////////////////////
3872
- /////////////////////////////////////////////////////
3873
- ////////// //////////
3874
- ////////// ZodDiscriminatedUnion //////////
3875
- ////////// //////////
3876
- /////////////////////////////////////////////////////
3877
- /////////////////////////////////////////////////////
3878
- const getDiscriminator = (type) => {
3879
- if (type instanceof ZodLazy) {
3880
- return getDiscriminator(type.schema);
3881
- }
3882
- else if (type instanceof ZodEffects) {
3883
- return getDiscriminator(type.innerType());
3884
- }
3885
- else if (type instanceof ZodLiteral) {
3886
- return [type.value];
3887
- }
3888
- else if (type instanceof ZodEnum) {
3889
- return type.options;
3890
- }
3891
- else if (type instanceof ZodNativeEnum) {
3892
- // eslint-disable-next-line ban/ban
3893
- return util.objectValues(type.enum);
3894
- }
3895
- else if (type instanceof ZodDefault) {
3896
- return getDiscriminator(type._def.innerType);
3897
- }
3898
- else if (type instanceof ZodUndefined) {
3899
- return [undefined];
3900
- }
3901
- else if (type instanceof ZodNull) {
3902
- return [null];
3903
- }
3904
- else if (type instanceof ZodOptional) {
3905
- return [undefined, ...getDiscriminator(type.unwrap())];
3906
- }
3907
- else if (type instanceof ZodNullable) {
3908
- return [null, ...getDiscriminator(type.unwrap())];
3909
- }
3910
- else if (type instanceof ZodBranded) {
3911
- return getDiscriminator(type.unwrap());
3912
- }
3913
- else if (type instanceof ZodReadonly) {
3914
- return getDiscriminator(type.unwrap());
3915
- }
3916
- else if (type instanceof ZodCatch) {
3917
- return getDiscriminator(type._def.innerType);
3918
- }
3919
- else {
3920
- return [];
3921
- }
3922
- };
3923
- class ZodDiscriminatedUnion extends ZodType {
3924
- _parse(input) {
3925
- const { ctx } = this._processInputParams(input);
3926
- if (ctx.parsedType !== ZodParsedType.object) {
3927
- addIssueToContext(ctx, {
3928
- code: ZodIssueCode.invalid_type,
3929
- expected: ZodParsedType.object,
3930
- received: ctx.parsedType,
3931
- });
3932
- return INVALID;
3933
- }
3934
- const discriminator = this.discriminator;
3935
- const discriminatorValue = ctx.data[discriminator];
3936
- const option = this.optionsMap.get(discriminatorValue);
3937
- if (!option) {
3938
- addIssueToContext(ctx, {
3939
- code: ZodIssueCode.invalid_union_discriminator,
3940
- options: Array.from(this.optionsMap.keys()),
3941
- path: [discriminator],
3942
- });
3943
- return INVALID;
3944
- }
3945
- if (ctx.common.async) {
3946
- return option._parseAsync({
3947
- data: ctx.data,
3948
- path: ctx.path,
3949
- parent: ctx,
3950
- });
3951
- }
3952
- else {
3953
- return option._parseSync({
3954
- data: ctx.data,
3955
- path: ctx.path,
3956
- parent: ctx,
3957
- });
3958
- }
3959
- }
3960
- get discriminator() {
3961
- return this._def.discriminator;
3962
- }
3963
- get options() {
3964
- return this._def.options;
3965
- }
3966
- get optionsMap() {
3967
- return this._def.optionsMap;
3968
- }
3969
- /**
3970
- * The constructor of the discriminated union schema. Its behaviour is very similar to that of the normal z.union() constructor.
3971
- * However, it only allows a union of objects, all of which need to share a discriminator property. This property must
3972
- * have a different value for each object in the union.
3973
- * @param discriminator the name of the discriminator property
3974
- * @param types an array of object schemas
3975
- * @param params
3976
- */
3977
- static create(discriminator, options, params) {
3978
- // Get all the valid discriminator values
3979
- const optionsMap = new Map();
3980
- // try {
3981
- for (const type of options) {
3982
- const discriminatorValues = getDiscriminator(type.shape[discriminator]);
3983
- if (!discriminatorValues.length) {
3984
- throw new Error(`A discriminator value for key \`${discriminator}\` could not be extracted from all schema options`);
3985
- }
3986
- for (const value of discriminatorValues) {
3987
- if (optionsMap.has(value)) {
3988
- throw new Error(`Discriminator property ${String(discriminator)} has duplicate value ${String(value)}`);
3989
- }
3990
- optionsMap.set(value, type);
3991
- }
3992
- }
3993
- return new ZodDiscriminatedUnion({
3994
- typeName: ZodFirstPartyTypeKind.ZodDiscriminatedUnion,
3995
- discriminator,
3996
- options,
3997
- optionsMap,
3998
- ...processCreateParams(params),
3999
- });
4000
- }
4001
- }
4002
3910
  function mergeValues(a, b) {
4003
3911
  const aType = getParsedType(a);
4004
3912
  const bType = getParsedType(b);
@@ -4007,9 +3915,7 @@ function mergeValues(a, b) {
4007
3915
  }
4008
3916
  else if (aType === ZodParsedType.object && bType === ZodParsedType.object) {
4009
3917
  const bKeys = util.objectKeys(b);
4010
- const sharedKeys = util
4011
- .objectKeys(a)
4012
- .filter((key) => bKeys.indexOf(key) !== -1);
3918
+ const sharedKeys = util.objectKeys(a).filter((key) => bKeys.indexOf(key) !== -1);
4013
3919
  const newObj = { ...a, ...b };
4014
3920
  for (const key of sharedKeys) {
4015
3921
  const sharedValue = mergeValues(a[key], b[key]);
@@ -4036,9 +3942,7 @@ function mergeValues(a, b) {
4036
3942
  }
4037
3943
  return { valid: true, data: newArray };
4038
3944
  }
4039
- else if (aType === ZodParsedType.date &&
4040
- bType === ZodParsedType.date &&
4041
- +a === +b) {
3945
+ else if (aType === ZodParsedType.date && bType === ZodParsedType.date && +a === +b) {
4042
3946
  return { valid: true, data: a };
4043
3947
  }
4044
3948
  else {
@@ -4099,6 +4003,7 @@ ZodIntersection.create = (left, right, params) => {
4099
4003
  ...processCreateParams(params),
4100
4004
  });
4101
4005
  };
4006
+ // type ZodTupleItems = [ZodTypeAny, ...ZodTypeAny[]];
4102
4007
  class ZodTuple extends ZodType {
4103
4008
  _parse(input) {
4104
4009
  const { status, ctx } = this._processInputParams(input);
@@ -4169,60 +4074,6 @@ ZodTuple.create = (schemas, params) => {
4169
4074
  ...processCreateParams(params),
4170
4075
  });
4171
4076
  };
4172
- class ZodRecord extends ZodType {
4173
- get keySchema() {
4174
- return this._def.keyType;
4175
- }
4176
- get valueSchema() {
4177
- return this._def.valueType;
4178
- }
4179
- _parse(input) {
4180
- const { status, ctx } = this._processInputParams(input);
4181
- if (ctx.parsedType !== ZodParsedType.object) {
4182
- addIssueToContext(ctx, {
4183
- code: ZodIssueCode.invalid_type,
4184
- expected: ZodParsedType.object,
4185
- received: ctx.parsedType,
4186
- });
4187
- return INVALID;
4188
- }
4189
- const pairs = [];
4190
- const keyType = this._def.keyType;
4191
- const valueType = this._def.valueType;
4192
- for (const key in ctx.data) {
4193
- pairs.push({
4194
- key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, key)),
4195
- value: valueType._parse(new ParseInputLazyPath(ctx, ctx.data[key], ctx.path, key)),
4196
- alwaysSet: key in ctx.data,
4197
- });
4198
- }
4199
- if (ctx.common.async) {
4200
- return ParseStatus.mergeObjectAsync(status, pairs);
4201
- }
4202
- else {
4203
- return ParseStatus.mergeObjectSync(status, pairs);
4204
- }
4205
- }
4206
- get element() {
4207
- return this._def.valueType;
4208
- }
4209
- static create(first, second, third) {
4210
- if (second instanceof ZodType) {
4211
- return new ZodRecord({
4212
- keyType: first,
4213
- valueType: second,
4214
- typeName: ZodFirstPartyTypeKind.ZodRecord,
4215
- ...processCreateParams(third),
4216
- });
4217
- }
4218
- return new ZodRecord({
4219
- keyType: ZodString.create(),
4220
- valueType: first,
4221
- typeName: ZodFirstPartyTypeKind.ZodRecord,
4222
- ...processCreateParams(second),
4223
- });
4224
- }
4225
- }
4226
4077
  class ZodMap extends ZodType {
4227
4078
  get keySchema() {
4228
4079
  return this._def.keyType;
@@ -4376,134 +4227,6 @@ ZodSet.create = (valueType, params) => {
4376
4227
  ...processCreateParams(params),
4377
4228
  });
4378
4229
  };
4379
- class ZodFunction extends ZodType {
4380
- constructor() {
4381
- super(...arguments);
4382
- this.validate = this.implement;
4383
- }
4384
- _parse(input) {
4385
- const { ctx } = this._processInputParams(input);
4386
- if (ctx.parsedType !== ZodParsedType.function) {
4387
- addIssueToContext(ctx, {
4388
- code: ZodIssueCode.invalid_type,
4389
- expected: ZodParsedType.function,
4390
- received: ctx.parsedType,
4391
- });
4392
- return INVALID;
4393
- }
4394
- function makeArgsIssue(args, error) {
4395
- return makeIssue({
4396
- data: args,
4397
- path: ctx.path,
4398
- errorMaps: [
4399
- ctx.common.contextualErrorMap,
4400
- ctx.schemaErrorMap,
4401
- getErrorMap(),
4402
- errorMap,
4403
- ].filter((x) => !!x),
4404
- issueData: {
4405
- code: ZodIssueCode.invalid_arguments,
4406
- argumentsError: error,
4407
- },
4408
- });
4409
- }
4410
- function makeReturnsIssue(returns, error) {
4411
- return makeIssue({
4412
- data: returns,
4413
- path: ctx.path,
4414
- errorMaps: [
4415
- ctx.common.contextualErrorMap,
4416
- ctx.schemaErrorMap,
4417
- getErrorMap(),
4418
- errorMap,
4419
- ].filter((x) => !!x),
4420
- issueData: {
4421
- code: ZodIssueCode.invalid_return_type,
4422
- returnTypeError: error,
4423
- },
4424
- });
4425
- }
4426
- const params = { errorMap: ctx.common.contextualErrorMap };
4427
- const fn = ctx.data;
4428
- if (this._def.returns instanceof ZodPromise) {
4429
- // Would love a way to avoid disabling this rule, but we need
4430
- // an alias (using an arrow function was what caused 2651).
4431
- // eslint-disable-next-line @typescript-eslint/no-this-alias
4432
- const me = this;
4433
- return OK(async function (...args) {
4434
- const error = new ZodError([]);
4435
- const parsedArgs = await me._def.args
4436
- .parseAsync(args, params)
4437
- .catch((e) => {
4438
- error.addIssue(makeArgsIssue(args, e));
4439
- throw error;
4440
- });
4441
- const result = await Reflect.apply(fn, this, parsedArgs);
4442
- const parsedReturns = await me._def.returns._def.type
4443
- .parseAsync(result, params)
4444
- .catch((e) => {
4445
- error.addIssue(makeReturnsIssue(result, e));
4446
- throw error;
4447
- });
4448
- return parsedReturns;
4449
- });
4450
- }
4451
- else {
4452
- // Would love a way to avoid disabling this rule, but we need
4453
- // an alias (using an arrow function was what caused 2651).
4454
- // eslint-disable-next-line @typescript-eslint/no-this-alias
4455
- const me = this;
4456
- return OK(function (...args) {
4457
- const parsedArgs = me._def.args.safeParse(args, params);
4458
- if (!parsedArgs.success) {
4459
- throw new ZodError([makeArgsIssue(args, parsedArgs.error)]);
4460
- }
4461
- const result = Reflect.apply(fn, this, parsedArgs.data);
4462
- const parsedReturns = me._def.returns.safeParse(result, params);
4463
- if (!parsedReturns.success) {
4464
- throw new ZodError([makeReturnsIssue(result, parsedReturns.error)]);
4465
- }
4466
- return parsedReturns.data;
4467
- });
4468
- }
4469
- }
4470
- parameters() {
4471
- return this._def.args;
4472
- }
4473
- returnType() {
4474
- return this._def.returns;
4475
- }
4476
- args(...items) {
4477
- return new ZodFunction({
4478
- ...this._def,
4479
- args: ZodTuple.create(items).rest(ZodUnknown.create()),
4480
- });
4481
- }
4482
- returns(returnType) {
4483
- return new ZodFunction({
4484
- ...this._def,
4485
- returns: returnType,
4486
- });
4487
- }
4488
- implement(func) {
4489
- const validatedFunc = this.parse(func);
4490
- return validatedFunc;
4491
- }
4492
- strictImplement(func) {
4493
- const validatedFunc = this.parse(func);
4494
- return validatedFunc;
4495
- }
4496
- static create(args, returns, params) {
4497
- return new ZodFunction({
4498
- args: (args
4499
- ? args
4500
- : ZodTuple.create([]).rest(ZodUnknown.create())),
4501
- returns: returns || ZodUnknown.create(),
4502
- typeName: ZodFirstPartyTypeKind.ZodFunction,
4503
- ...processCreateParams(params),
4504
- });
4505
- }
4506
- }
4507
4230
  class ZodLazy extends ZodType {
4508
4231
  get schema() {
4509
4232
  return this._def.getter();
@@ -4553,10 +4276,6 @@ function createZodEnum(values, params) {
4553
4276
  });
4554
4277
  }
4555
4278
  class ZodEnum extends ZodType {
4556
- constructor() {
4557
- super(...arguments);
4558
- _ZodEnum_cache.set(this, void 0);
4559
- }
4560
4279
  _parse(input) {
4561
4280
  if (typeof input.data !== "string") {
4562
4281
  const ctx = this._getOrReturnCtx(input);
@@ -4568,10 +4287,10 @@ class ZodEnum extends ZodType {
4568
4287
  });
4569
4288
  return INVALID;
4570
4289
  }
4571
- if (!__classPrivateFieldGet(this, _ZodEnum_cache)) {
4572
- __classPrivateFieldSet(this, _ZodEnum_cache, new Set(this._def.values));
4290
+ if (!this._cache) {
4291
+ this._cache = new Set(this._def.values);
4573
4292
  }
4574
- if (!__classPrivateFieldGet(this, _ZodEnum_cache).has(input.data)) {
4293
+ if (!this._cache.has(input.data)) {
4575
4294
  const ctx = this._getOrReturnCtx(input);
4576
4295
  const expectedValues = this._def.values;
4577
4296
  addIssueToContext(ctx, {
@@ -4620,18 +4339,12 @@ class ZodEnum extends ZodType {
4620
4339
  });
4621
4340
  }
4622
4341
  }
4623
- _ZodEnum_cache = new WeakMap();
4624
4342
  ZodEnum.create = createZodEnum;
4625
4343
  class ZodNativeEnum extends ZodType {
4626
- constructor() {
4627
- super(...arguments);
4628
- _ZodNativeEnum_cache.set(this, void 0);
4629
- }
4630
4344
  _parse(input) {
4631
4345
  const nativeEnumValues = util.getValidEnumValues(this._def.values);
4632
4346
  const ctx = this._getOrReturnCtx(input);
4633
- if (ctx.parsedType !== ZodParsedType.string &&
4634
- ctx.parsedType !== ZodParsedType.number) {
4347
+ if (ctx.parsedType !== ZodParsedType.string && ctx.parsedType !== ZodParsedType.number) {
4635
4348
  const expectedValues = util.objectValues(nativeEnumValues);
4636
4349
  addIssueToContext(ctx, {
4637
4350
  expected: util.joinValues(expectedValues),
@@ -4640,10 +4353,10 @@ class ZodNativeEnum extends ZodType {
4640
4353
  });
4641
4354
  return INVALID;
4642
4355
  }
4643
- if (!__classPrivateFieldGet(this, _ZodNativeEnum_cache)) {
4644
- __classPrivateFieldSet(this, _ZodNativeEnum_cache, new Set(util.getValidEnumValues(this._def.values)));
4356
+ if (!this._cache) {
4357
+ this._cache = new Set(util.getValidEnumValues(this._def.values));
4645
4358
  }
4646
- if (!__classPrivateFieldGet(this, _ZodNativeEnum_cache).has(input.data)) {
4359
+ if (!this._cache.has(input.data)) {
4647
4360
  const expectedValues = util.objectValues(nativeEnumValues);
4648
4361
  addIssueToContext(ctx, {
4649
4362
  received: ctx.data,
@@ -4658,7 +4371,6 @@ class ZodNativeEnum extends ZodType {
4658
4371
  return this._def.values;
4659
4372
  }
4660
4373
  }
4661
- _ZodNativeEnum_cache = new WeakMap();
4662
4374
  ZodNativeEnum.create = (values, params) => {
4663
4375
  return new ZodNativeEnum({
4664
4376
  values: values,
@@ -4672,8 +4384,7 @@ class ZodPromise extends ZodType {
4672
4384
  }
4673
4385
  _parse(input) {
4674
4386
  const { ctx } = this._processInputParams(input);
4675
- if (ctx.parsedType !== ZodParsedType.promise &&
4676
- ctx.common.async === false) {
4387
+ if (ctx.parsedType !== ZodParsedType.promise && ctx.common.async === false) {
4677
4388
  addIssueToContext(ctx, {
4678
4389
  code: ZodIssueCode.invalid_type,
4679
4390
  expected: ZodParsedType.promise,
@@ -4681,9 +4392,7 @@ class ZodPromise extends ZodType {
4681
4392
  });
4682
4393
  return INVALID;
4683
4394
  }
4684
- const promisified = ctx.parsedType === ZodParsedType.promise
4685
- ? ctx.data
4686
- : Promise.resolve(ctx.data);
4395
+ const promisified = ctx.parsedType === ZodParsedType.promise ? ctx.data : Promise.resolve(ctx.data);
4687
4396
  return OK(promisified.then((data) => {
4688
4397
  return this._def.type.parseAsync(data, {
4689
4398
  path: ctx.path,
@@ -4789,9 +4498,7 @@ class ZodEffects extends ZodType {
4789
4498
  return { status: status.value, value: inner.value };
4790
4499
  }
4791
4500
  else {
4792
- return this._def.schema
4793
- ._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx })
4794
- .then((inner) => {
4501
+ return this._def.schema._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx }).then((inner) => {
4795
4502
  if (inner.status === "aborted")
4796
4503
  return INVALID;
4797
4504
  if (inner.status === "dirty")
@@ -4810,7 +4517,7 @@ class ZodEffects extends ZodType {
4810
4517
  parent: ctx,
4811
4518
  });
4812
4519
  if (!isValid(base))
4813
- return base;
4520
+ return INVALID;
4814
4521
  const result = effect.transform(base.value, checkCtx);
4815
4522
  if (result instanceof Promise) {
4816
4523
  throw new Error(`Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.`);
@@ -4818,12 +4525,13 @@ class ZodEffects extends ZodType {
4818
4525
  return { status: status.value, value: result };
4819
4526
  }
4820
4527
  else {
4821
- return this._def.schema
4822
- ._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx })
4823
- .then((base) => {
4528
+ return this._def.schema._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx }).then((base) => {
4824
4529
  if (!isValid(base))
4825
- return base;
4826
- return Promise.resolve(effect.transform(base.value, checkCtx)).then((result) => ({ status: status.value, value: result }));
4530
+ return INVALID;
4531
+ return Promise.resolve(effect.transform(base.value, checkCtx)).then((result) => ({
4532
+ status: status.value,
4533
+ value: result,
4534
+ }));
4827
4535
  });
4828
4536
  }
4829
4537
  }
@@ -4905,9 +4613,7 @@ ZodDefault.create = (type, params) => {
4905
4613
  return new ZodDefault({
4906
4614
  innerType: type,
4907
4615
  typeName: ZodFirstPartyTypeKind.ZodDefault,
4908
- defaultValue: typeof params.default === "function"
4909
- ? params.default
4910
- : () => params.default,
4616
+ defaultValue: typeof params.default === "function" ? params.default : () => params.default,
4911
4617
  ...processCreateParams(params),
4912
4618
  });
4913
4619
  };
@@ -4991,7 +4697,6 @@ ZodNaN.create = (params) => {
4991
4697
  ...processCreateParams(params),
4992
4698
  });
4993
4699
  };
4994
- const BRAND = Symbol("zod_brand");
4995
4700
  class ZodBranded extends ZodType {
4996
4701
  _parse(input) {
4997
4702
  const { ctx } = this._processInputParams(input);
@@ -5073,9 +4778,7 @@ class ZodReadonly extends ZodType {
5073
4778
  }
5074
4779
  return data;
5075
4780
  };
5076
- return isAsync(result)
5077
- ? result.then((data) => freeze(data))
5078
- : freeze(result);
4781
+ return isAsync(result) ? result.then((data) => freeze(data)) : freeze(result);
5079
4782
  }
5080
4783
  unwrap() {
5081
4784
  return this._def.innerType;
@@ -5088,60 +4791,6 @@ ZodReadonly.create = (type, params) => {
5088
4791
  ...processCreateParams(params),
5089
4792
  });
5090
4793
  };
5091
- ////////////////////////////////////////
5092
- ////////////////////////////////////////
5093
- ////////// //////////
5094
- ////////// z.custom //////////
5095
- ////////// //////////
5096
- ////////////////////////////////////////
5097
- ////////////////////////////////////////
5098
- function cleanParams(params, data) {
5099
- const p = typeof params === "function"
5100
- ? params(data)
5101
- : typeof params === "string"
5102
- ? { message: params }
5103
- : params;
5104
- const p2 = typeof p === "string" ? { message: p } : p;
5105
- return p2;
5106
- }
5107
- function custom(check, _params = {},
5108
- /**
5109
- * @deprecated
5110
- *
5111
- * Pass `fatal` into the params object instead:
5112
- *
5113
- * ```ts
5114
- * z.string().custom((val) => val.length > 5, { fatal: false })
5115
- * ```
5116
- *
5117
- */
5118
- fatal) {
5119
- if (check)
5120
- return ZodAny.create().superRefine((data, ctx) => {
5121
- var _a, _b;
5122
- const r = check(data);
5123
- if (r instanceof Promise) {
5124
- return r.then((r) => {
5125
- var _a, _b;
5126
- if (!r) {
5127
- const params = cleanParams(_params, data);
5128
- const _fatal = (_b = (_a = params.fatal) !== null && _a !== void 0 ? _a : fatal) !== null && _b !== void 0 ? _b : true;
5129
- ctx.addIssue({ code: "custom", ...params, fatal: _fatal });
5130
- }
5131
- });
5132
- }
5133
- if (!r) {
5134
- const params = cleanParams(_params, data);
5135
- const _fatal = (_b = (_a = params.fatal) !== null && _a !== void 0 ? _a : fatal) !== null && _b !== void 0 ? _b : true;
5136
- ctx.addIssue({ code: "custom", ...params, fatal: _fatal });
5137
- }
5138
- return;
5139
- });
5140
- return ZodAny.create();
5141
- }
5142
- const late = {
5143
- object: ZodObject.lazycreate,
5144
- };
5145
4794
  var ZodFirstPartyTypeKind;
5146
4795
  (function (ZodFirstPartyTypeKind) {
5147
4796
  ZodFirstPartyTypeKind["ZodString"] = "ZodString";
@@ -5181,170 +4830,17 @@ var ZodFirstPartyTypeKind;
5181
4830
  ZodFirstPartyTypeKind["ZodPipeline"] = "ZodPipeline";
5182
4831
  ZodFirstPartyTypeKind["ZodReadonly"] = "ZodReadonly";
5183
4832
  })(ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {}));
5184
- const instanceOfType = (
5185
- // const instanceOfType = <T extends new (...args: any[]) => any>(
5186
- cls, params = {
5187
- message: `Input not instance of ${cls.name}`,
5188
- }) => custom((data) => data instanceof cls, params);
5189
4833
  const stringType = ZodString.create;
5190
- const numberType = ZodNumber.create;
5191
- const nanType = ZodNaN.create;
5192
- const bigIntType = ZodBigInt.create;
5193
- const booleanType = ZodBoolean.create;
5194
- const dateType = ZodDate.create;
5195
- const symbolType = ZodSymbol.create;
5196
- const undefinedType = ZodUndefined.create;
5197
- const nullType = ZodNull.create;
5198
- const anyType = ZodAny.create;
5199
- const unknownType = ZodUnknown.create;
5200
- const neverType = ZodNever.create;
5201
- const voidType = ZodVoid.create;
5202
- const arrayType = ZodArray.create;
4834
+ ZodNever.create;
4835
+ ZodArray.create;
5203
4836
  const objectType = ZodObject.create;
5204
- const strictObjectType = ZodObject.strictCreate;
5205
- const unionType = ZodUnion.create;
5206
- const discriminatedUnionType = ZodDiscriminatedUnion.create;
5207
- const intersectionType = ZodIntersection.create;
5208
- const tupleType = ZodTuple.create;
5209
- const recordType = ZodRecord.create;
5210
- const mapType = ZodMap.create;
5211
- const setType = ZodSet.create;
5212
- const functionType = ZodFunction.create;
5213
- const lazyType = ZodLazy.create;
5214
- const literalType = ZodLiteral.create;
4837
+ ZodUnion.create;
4838
+ ZodIntersection.create;
4839
+ ZodTuple.create;
5215
4840
  const enumType = ZodEnum.create;
5216
- const nativeEnumType = ZodNativeEnum.create;
5217
- const promiseType = ZodPromise.create;
5218
- const effectsType = ZodEffects.create;
5219
- const optionalType = ZodOptional.create;
5220
- const nullableType = ZodNullable.create;
5221
- const preprocessType = ZodEffects.createWithPreprocess;
5222
- const pipelineType = ZodPipeline.create;
5223
- const ostring = () => stringType().optional();
5224
- const onumber = () => numberType().optional();
5225
- const oboolean = () => booleanType().optional();
5226
- const coerce = {
5227
- string: ((arg) => ZodString.create({ ...arg, coerce: true })),
5228
- number: ((arg) => ZodNumber.create({ ...arg, coerce: true })),
5229
- boolean: ((arg) => ZodBoolean.create({
5230
- ...arg,
5231
- coerce: true,
5232
- })),
5233
- bigint: ((arg) => ZodBigInt.create({ ...arg, coerce: true })),
5234
- date: ((arg) => ZodDate.create({ ...arg, coerce: true })),
5235
- };
5236
- const NEVER = INVALID;
5237
-
5238
- var z = /*#__PURE__*/Object.freeze({
5239
- __proto__: null,
5240
- defaultErrorMap: errorMap,
5241
- setErrorMap: setErrorMap,
5242
- getErrorMap: getErrorMap,
5243
- makeIssue: makeIssue,
5244
- EMPTY_PATH: EMPTY_PATH,
5245
- addIssueToContext: addIssueToContext,
5246
- ParseStatus: ParseStatus,
5247
- INVALID: INVALID,
5248
- DIRTY: DIRTY,
5249
- OK: OK,
5250
- isAborted: isAborted,
5251
- isDirty: isDirty,
5252
- isValid: isValid,
5253
- isAsync: isAsync,
5254
- get util () { return util; },
5255
- get objectUtil () { return objectUtil; },
5256
- ZodParsedType: ZodParsedType,
5257
- getParsedType: getParsedType,
5258
- ZodType: ZodType,
5259
- datetimeRegex: datetimeRegex,
5260
- ZodString: ZodString,
5261
- ZodNumber: ZodNumber,
5262
- ZodBigInt: ZodBigInt,
5263
- ZodBoolean: ZodBoolean,
5264
- ZodDate: ZodDate,
5265
- ZodSymbol: ZodSymbol,
5266
- ZodUndefined: ZodUndefined,
5267
- ZodNull: ZodNull,
5268
- ZodAny: ZodAny,
5269
- ZodUnknown: ZodUnknown,
5270
- ZodNever: ZodNever,
5271
- ZodVoid: ZodVoid,
5272
- ZodArray: ZodArray,
5273
- ZodObject: ZodObject,
5274
- ZodUnion: ZodUnion,
5275
- ZodDiscriminatedUnion: ZodDiscriminatedUnion,
5276
- ZodIntersection: ZodIntersection,
5277
- ZodTuple: ZodTuple,
5278
- ZodRecord: ZodRecord,
5279
- ZodMap: ZodMap,
5280
- ZodSet: ZodSet,
5281
- ZodFunction: ZodFunction,
5282
- ZodLazy: ZodLazy,
5283
- ZodLiteral: ZodLiteral,
5284
- ZodEnum: ZodEnum,
5285
- ZodNativeEnum: ZodNativeEnum,
5286
- ZodPromise: ZodPromise,
5287
- ZodEffects: ZodEffects,
5288
- ZodTransformer: ZodEffects,
5289
- ZodOptional: ZodOptional,
5290
- ZodNullable: ZodNullable,
5291
- ZodDefault: ZodDefault,
5292
- ZodCatch: ZodCatch,
5293
- ZodNaN: ZodNaN,
5294
- BRAND: BRAND,
5295
- ZodBranded: ZodBranded,
5296
- ZodPipeline: ZodPipeline,
5297
- ZodReadonly: ZodReadonly,
5298
- custom: custom,
5299
- Schema: ZodType,
5300
- ZodSchema: ZodType,
5301
- late: late,
5302
- get ZodFirstPartyTypeKind () { return ZodFirstPartyTypeKind; },
5303
- coerce: coerce,
5304
- any: anyType,
5305
- array: arrayType,
5306
- bigint: bigIntType,
5307
- boolean: booleanType,
5308
- date: dateType,
5309
- discriminatedUnion: discriminatedUnionType,
5310
- effect: effectsType,
5311
- 'enum': enumType,
5312
- 'function': functionType,
5313
- 'instanceof': instanceOfType,
5314
- intersection: intersectionType,
5315
- lazy: lazyType,
5316
- literal: literalType,
5317
- map: mapType,
5318
- nan: nanType,
5319
- nativeEnum: nativeEnumType,
5320
- never: neverType,
5321
- 'null': nullType,
5322
- nullable: nullableType,
5323
- number: numberType,
5324
- object: objectType,
5325
- oboolean: oboolean,
5326
- onumber: onumber,
5327
- optional: optionalType,
5328
- ostring: ostring,
5329
- pipeline: pipelineType,
5330
- preprocess: preprocessType,
5331
- promise: promiseType,
5332
- record: recordType,
5333
- set: setType,
5334
- strictObject: strictObjectType,
5335
- string: stringType,
5336
- symbol: symbolType,
5337
- transformer: effectsType,
5338
- tuple: tupleType,
5339
- 'undefined': undefinedType,
5340
- union: unionType,
5341
- unknown: unknownType,
5342
- 'void': voidType,
5343
- NEVER: NEVER,
5344
- ZodIssueCode: ZodIssueCode,
5345
- quotelessJson: quotelessJson,
5346
- ZodError: ZodError
5347
- });
4841
+ ZodPromise.create;
4842
+ ZodOptional.create;
4843
+ ZodNullable.create;
5348
4844
 
5349
4845
  const BASE_CF_URL = "https://mediacrate.marteye.ie";
5350
4846
  /**
@@ -5352,9 +4848,9 @@ const BASE_CF_URL = "https://mediacrate.marteye.ie";
5352
4848
  | START OF MEDIA CRATE CODE
5353
4849
  |--------------------------------------------------
5354
4850
  */
5355
- z.object({
5356
- assetPath: z.string().url({ message: "URL is required" }),
5357
- suffix: z.string().min(1, { message: "Suffix Type is required" }),
4851
+ objectType({
4852
+ assetPath: stringType().url({ message: "URL is required" }),
4853
+ suffix: stringType().min(1, { message: "Suffix Type is required" }),
5358
4854
  });
5359
4855
  // Adding Sizes here will make more end points in the mainConfig object
5360
4856
  const IMAGE_SIZES_VALUES$1 = [
@@ -5364,8 +4860,8 @@ const IMAGE_SIZES_VALUES$1 = [
5364
4860
  "large",
5365
4861
  ];
5366
4862
  const VIDEO_TASKS_VALUES$1 = ["compressed", "thumbnail"];
5367
- z.enum(VIDEO_TASKS_VALUES$1);
5368
- z.enum(IMAGE_SIZES_VALUES$1);
4863
+ enumType(VIDEO_TASKS_VALUES$1);
4864
+ enumType(IMAGE_SIZES_VALUES$1);
5369
4865
  const UPLOAD_PATHS = {
5370
4866
  START_UPLOAD: "startMultipartUpload",
5371
4867
  UPLOAD_PART: "uploadChunk",
@@ -5946,8 +5442,8 @@ function create$a(httpClient) {
5946
5442
 
5947
5443
  function create$9(httpClient) {
5948
5444
  return {
5949
- list: async (marketId) => {
5950
- return httpClient.get(`/${marketId}/product-codes`);
5445
+ list: async (marketId, options) => {
5446
+ return httpClient.get(`/${marketId}/product-codes`, (options === null || options === void 0 ? void 0 : options.includeArchived) ? { includeArchived: "true" } : undefined);
5951
5447
  },
5952
5448
  get: async (marketId, id, options) => {
5953
5449
  return httpClient.get(`/${marketId}/product-codes/${id}`, (options === null || options === void 0 ? void 0 : options.at) ? { at: options.at } : undefined);
@@ -6219,6 +5715,7 @@ const SupportedSuperTypes = [
6219
5715
  "Cattle",
6220
5716
  "Pigs",
6221
5717
  "Horses",
5718
+ "Dogs",
6222
5719
  "Deer",
6223
5720
  "Poultry",
6224
5721
  "Machinery",
@@ -6235,6 +5732,12 @@ const LivestockSuperTypes = [
6235
5732
  "Poultry",
6236
5733
  ];
6237
5734
  const SupportedCurrencyCodes = ["GBP", "EUR", "USD"];
5735
+ const AccountTiers = {
5736
+ free: 0,
5737
+ basic: 1,
5738
+ standard: 2,
5739
+ premium: 3,
5740
+ };
6238
5741
  const SupportedUnitsOfSale = [
6239
5742
  "Per KG",
6240
5743
  "Per Item",
@@ -6286,6 +5789,7 @@ const supportedWebhookEvents = [
6286
5789
 
6287
5790
  var types = /*#__PURE__*/Object.freeze({
6288
5791
  __proto__: null,
5792
+ AccountTiers: AccountTiers,
6289
5793
  IMAGE_SIZES_VALUES: IMAGE_SIZES_VALUES,
6290
5794
  LivestockSuperTypes: LivestockSuperTypes,
6291
5795
  SupportedCurrencyCodes: SupportedCurrencyCodes,
@@ -6357,6 +5861,913 @@ function createAppManifest(appConfig) {
6357
5861
  };
6358
5862
  }
6359
5863
 
5864
+ const MEDIA_CRATE_V2_BASE_URL_ENV_VARS = [
5865
+ "MEDIA_CRATE_V2_BASE_URL",
5866
+ "NEXT_PUBLIC_MEDIA_CRATE_BASE_URL",
5867
+ ];
5868
+ const MEDIA_CRATE_SINGLE_UPLOAD_MAX_BYTES = 25 * 1024 * 1024;
5869
+ const MEDIA_CRATE_MULTIPART_MAX_CHUNK_BYTES = 100 * 1024 * 1024;
5870
+ const MEDIA_CRATE_DEFAULT_CHUNK_BYTES = 5 * 1024 * 1024;
5871
+ const MEDIA_CRATE_MEDIA_STATUSES = [
5872
+ "uploading",
5873
+ "processing",
5874
+ "done",
5875
+ "error",
5876
+ "deleted",
5877
+ "partial",
5878
+ "expired",
5879
+ "indeterminate",
5880
+ ];
5881
+ /** @deprecated Use MEDIA_CRATE_MEDIA_STATUSES. */
5882
+ const MEDIA_CRATE_ASSET_STATUSES = MEDIA_CRATE_MEDIA_STATUSES;
5883
+ function getMediaCrateVariant(source, variantName, opts = {}) {
5884
+ var _a, _b;
5885
+ const urls = getMediaCrateUrls(source);
5886
+ const variant = variantName === "original"
5887
+ ? urls.original
5888
+ : ((_b = (_a = urls.variants) === null || _a === void 0 ? void 0 : _a[variantName]) !== null && _b !== void 0 ? _b : (opts.fallbackToOriginal ? urls.original : undefined));
5889
+ if (!variant) {
5890
+ return undefined;
5891
+ }
5892
+ if (opts.requireReady && !variant.ready) {
5893
+ return undefined;
5894
+ }
5895
+ return variant;
5896
+ }
5897
+ function getMediaCrateVariantUrl(source, variantName, opts = {}) {
5898
+ var _a;
5899
+ return (_a = getMediaCrateVariant(source, variantName, opts)) === null || _a === void 0 ? void 0 : _a.url;
5900
+ }
5901
+ function requireMediaCrateVariantUrl(source, variantName, opts = {}) {
5902
+ const url = getMediaCrateVariantUrl(source, variantName, opts);
5903
+ if (!url) {
5904
+ const readyMessage = opts.requireReady ? " ready" : "";
5905
+ throw new Error(`Media Crate did not return a${readyMessage} ${variantName} variant`);
5906
+ }
5907
+ return url;
5908
+ }
5909
+ class MediaCrateHttpError extends Error {
5910
+ constructor(args) {
5911
+ super(args.message);
5912
+ this.name = "MediaCrateHttpError";
5913
+ this.status = args.status;
5914
+ this.method = args.method;
5915
+ this.url = args.url;
5916
+ this.body = args.body;
5917
+ this.collidingKeys = args.collidingKeys;
5918
+ }
5919
+ }
5920
+ class MediaCrateUploadSourceError extends Error {
5921
+ constructor(message) {
5922
+ super(message);
5923
+ this.name = "MediaCrateUploadSourceError";
5924
+ }
5925
+ }
5926
+ class InMemoryMediaCrateMultipartSessionStore {
5927
+ constructor() {
5928
+ this.sessions = new Map();
5929
+ }
5930
+ async get(key) {
5931
+ const session = this.sessions.get(key);
5932
+ return session ? copySession(session) : null;
5933
+ }
5934
+ async set(key, session) {
5935
+ this.sessions.set(key, copySession(session));
5936
+ }
5937
+ async delete(key) {
5938
+ this.sessions.delete(key);
5939
+ }
5940
+ }
5941
+ function createWebUploadSource(file, opts = {}) {
5942
+ var _a, _b, _c, _d, _e;
5943
+ const fileWithMetadata = file;
5944
+ const name = (_b = (_a = opts.name) !== null && _a !== void 0 ? _a : fileWithMetadata.name) !== null && _b !== void 0 ? _b : "asset";
5945
+ const type = (_d = (_c = opts.type) !== null && _c !== void 0 ? _c : file.type) !== null && _d !== void 0 ? _d : "application/octet-stream";
5946
+ const lastModified = (_e = opts.lastModified) !== null && _e !== void 0 ? _e : fileWithMetadata.lastModified;
5947
+ return {
5948
+ name,
5949
+ type,
5950
+ size: file.size,
5951
+ lastModified,
5952
+ fingerprint: opts.fingerprint,
5953
+ canUseSingleUpload: true,
5954
+ async getPart({ start, end }) {
5955
+ return file.slice(start, end, type);
5956
+ },
5957
+ };
5958
+ }
5959
+ class MediaCrateClient {
5960
+ constructor(opts) {
5961
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
5962
+ this.baseUrl = resolveMediaCrateBaseUrl(opts);
5963
+ this.marketId = opts.marketId;
5964
+ this.getFirebaseToken = opts.getFirebaseToken;
5965
+ this.fetchImpl = (_a = opts.fetchImpl) !== null && _a !== void 0 ? _a : getGlobalFetch();
5966
+ this.sessionStore =
5967
+ (_b = opts.sessionStore) !== null && _b !== void 0 ? _b : new InMemoryMediaCrateMultipartSessionStore();
5968
+ this.chunkSizeBytes =
5969
+ (_c = opts.chunkSizeBytes) !== null && _c !== void 0 ? _c : MEDIA_CRATE_DEFAULT_CHUNK_BYTES;
5970
+ this.maxPartAttempts = (_d = opts.maxPartAttempts) !== null && _d !== void 0 ? _d : 3;
5971
+ this.maxFinishAttempts = (_e = opts.maxFinishAttempts) !== null && _e !== void 0 ? _e : 3;
5972
+ this.retryBaseDelayMs = (_f = opts.retryBaseDelayMs) !== null && _f !== void 0 ? _f : 500;
5973
+ this.maxConcurrentParts = (_g = opts.maxConcurrentParts) !== null && _g !== void 0 ? _g : 3;
5974
+ this.defaultUploadStrategy = (_h = opts.defaultUploadStrategy) !== null && _h !== void 0 ? _h : "auto";
5975
+ this.sleep = (_j = opts.sleep) !== null && _j !== void 0 ? _j : defaultSleep;
5976
+ this.now = (_k = opts.now) !== null && _k !== void 0 ? _k : Date.now;
5977
+ this.random = (_l = opts.random) !== null && _l !== void 0 ? _l : Math.random;
5978
+ }
5979
+ createMediaPath(...segments) {
5980
+ if (segments.length === 0) {
5981
+ throw new Error("At least one media path segment is required");
5982
+ }
5983
+ return normalizeUploadPath([
5984
+ normalizeUploadPathSegment(this.marketId, "marketId"),
5985
+ ...segments.map((segment, index) => normalizeUploadPathSegment(segment, `path segment ${index + 1}`)),
5986
+ ].join("/"));
5987
+ }
5988
+ createLotMediaPath(args) {
5989
+ return this.createMediaPath(args.saleId, args.lotId, args.attributeId, args.fileName);
5990
+ }
5991
+ uploadLotMedia(opts) {
5992
+ var _a;
5993
+ const path = this.createLotMediaPath({
5994
+ saleId: opts.saleId,
5995
+ lotId: opts.lotId,
5996
+ attributeId: opts.attributeId,
5997
+ fileName: (_a = opts.fileName) !== null && _a !== void 0 ? _a : opts.source.name,
5998
+ });
5999
+ return this.upload({
6000
+ ...opts,
6001
+ mode: "lot",
6002
+ path,
6003
+ });
6004
+ }
6005
+ uploadMedia(opts) {
6006
+ return this.upload(opts);
6007
+ }
6008
+ async upload(opts) {
6009
+ const path = normalizeUploadPath(opts.path);
6010
+ this.assertPathMatchesMarket(path);
6011
+ const strategy = this.resolveUploadStrategy(opts.strategy, opts.source);
6012
+ if (strategy === "single") {
6013
+ return this.uploadSingle({ ...opts, path });
6014
+ }
6015
+ return this.uploadMultipart({ ...opts, path });
6016
+ }
6017
+ async getStatus(statusUrl) {
6018
+ const headers = await this.createBaseHeaders();
6019
+ const response = await this.fetchImpl(statusUrl, {
6020
+ method: "GET",
6021
+ headers,
6022
+ });
6023
+ await throwIfNotOk(response, "GET", statusUrl);
6024
+ return (await response.json());
6025
+ }
6026
+ async delete(opts) {
6027
+ const url = this.urlFor("/delete");
6028
+ const headers = await this.createBaseHeaders();
6029
+ headers.set("X-Market-Id", this.marketId);
6030
+ headers.set("Content-Type", "application/x-www-form-urlencoded");
6031
+ const body = new URLSearchParams({ fileUrl: opts.fileUrl });
6032
+ const response = await this.fetchImpl(url.toString(), {
6033
+ method: "DELETE",
6034
+ headers,
6035
+ body,
6036
+ });
6037
+ await throwIfNotOk(response, "DELETE", url.toString());
6038
+ }
6039
+ async duplicate(opts) {
6040
+ var _a;
6041
+ const url = this.urlFor("/duplicate");
6042
+ const targetFilePath = normalizeUploadPath(opts.targetFilePath);
6043
+ this.assertPathMatchesMarket(targetFilePath);
6044
+ const headers = await this.createBaseHeaders();
6045
+ headers.set("X-Market-Id", this.marketId);
6046
+ headers.set("Content-Type", "application/json");
6047
+ const response = await this.fetchImpl(url.toString(), {
6048
+ method: "POST",
6049
+ headers,
6050
+ body: JSON.stringify({
6051
+ sourceUrl: opts.sourceUrl,
6052
+ targetFilePath,
6053
+ targetFileName: opts.targetFileName,
6054
+ overwrite: (_a = opts.overwrite) !== null && _a !== void 0 ? _a : true,
6055
+ }),
6056
+ });
6057
+ await throwIfNotOk(response, "POST", url.toString());
6058
+ return (await response.json());
6059
+ }
6060
+ async cancelMultipartUpload(args) {
6061
+ const path = normalizeUploadPath(args.path);
6062
+ this.assertPathMatchesMarket(path);
6063
+ if (args.mode === "direct") {
6064
+ await this.cancelDirectMultipartUpload({ ...args, path });
6065
+ }
6066
+ else {
6067
+ await this.cancelProcessedMultipartUpload({ ...args, path });
6068
+ }
6069
+ if (args.sessionKey) {
6070
+ await this.sessionStore.delete(args.sessionKey);
6071
+ }
6072
+ }
6073
+ resolveUploadStrategy(strategy, source) {
6074
+ const resolved = strategy !== null && strategy !== void 0 ? strategy : this.defaultUploadStrategy;
6075
+ if (resolved === "single") {
6076
+ return "single";
6077
+ }
6078
+ if (resolved === "multipart") {
6079
+ return "multipart";
6080
+ }
6081
+ if (source.size <= MEDIA_CRATE_SINGLE_UPLOAD_MAX_BYTES &&
6082
+ source.canUseSingleUpload !== false) {
6083
+ return "single";
6084
+ }
6085
+ return "multipart";
6086
+ }
6087
+ async uploadSingle(opts) {
6088
+ var _a, _b, _c, _d;
6089
+ if (opts.source.canUseSingleUpload === false) {
6090
+ throw new MediaCrateUploadSourceError("This upload source cannot be used for single binary uploads. Use multipart instead.");
6091
+ }
6092
+ (_a = opts.onProgress) === null || _a === void 0 ? void 0 : _a.call(opts, {
6093
+ phase: "starting",
6094
+ bytesUploaded: 0,
6095
+ totalBytes: opts.source.size,
6096
+ totalParts: 1,
6097
+ partNumber: 1,
6098
+ });
6099
+ const body = await opts.source.getPart({
6100
+ start: 0,
6101
+ end: opts.source.size,
6102
+ partNumber: 1,
6103
+ });
6104
+ if (isReactNativeFormDataFile(body)) {
6105
+ throw new MediaCrateUploadSourceError("Single binary uploads require raw bytes. Use multipart for URI-backed sources.");
6106
+ }
6107
+ const url = this.urlFor(opts.mode === "direct" ? "/standalone/upload" : "/upload");
6108
+ url.searchParams.set("filePath", opts.path);
6109
+ const headers = await this.createUploadHeaders({
6110
+ mode: opts.mode,
6111
+ overwrite: opts.overwrite,
6112
+ contentType: (_b = opts.source.type) !== null && _b !== void 0 ? _b : "application/octet-stream",
6113
+ });
6114
+ try {
6115
+ const response = await this.fetchImpl(url.toString(), {
6116
+ method: "POST",
6117
+ headers,
6118
+ body: body,
6119
+ });
6120
+ await throwIfNotOk(response, "POST", url.toString());
6121
+ const result = (await response.json());
6122
+ (_c = opts.onProgress) === null || _c === void 0 ? void 0 : _c.call(opts, {
6123
+ phase: "uploaded",
6124
+ bytesUploaded: opts.source.size,
6125
+ totalBytes: opts.source.size,
6126
+ totalParts: 1,
6127
+ partNumber: 1,
6128
+ });
6129
+ return result;
6130
+ }
6131
+ catch (error) {
6132
+ (_d = opts.onProgress) === null || _d === void 0 ? void 0 : _d.call(opts, {
6133
+ phase: "error",
6134
+ bytesUploaded: 0,
6135
+ totalBytes: opts.source.size,
6136
+ totalParts: 1,
6137
+ partNumber: 1,
6138
+ });
6139
+ throw error;
6140
+ }
6141
+ }
6142
+ async uploadMultipart(opts) {
6143
+ var _a, _b, _c, _d, _e, _f, _g, _h;
6144
+ const chunkSize = (_a = opts.chunkSizeBytes) !== null && _a !== void 0 ? _a : this.chunkSizeBytes;
6145
+ assertValidChunkSize(chunkSize);
6146
+ const totalParts = Math.ceil(opts.source.size / chunkSize);
6147
+ const sessionKey = (_b = opts.sessionKey) !== null && _b !== void 0 ? _b : createMultipartSessionKey({
6148
+ baseUrl: this.baseUrl,
6149
+ marketId: this.marketId,
6150
+ mode: opts.mode,
6151
+ path: opts.path,
6152
+ source: opts.source,
6153
+ chunkSize,
6154
+ overwrite: (_c = opts.overwrite) !== null && _c !== void 0 ? _c : false,
6155
+ });
6156
+ let session = await this.getOrStartMultipartSession({
6157
+ ...opts,
6158
+ chunkSize,
6159
+ totalParts,
6160
+ sessionKey,
6161
+ });
6162
+ const completedPartNumbers = new Set(session.sections.map((section) => Number(section.partNumber)));
6163
+ let bytesUploaded = getCompletedBytes({
6164
+ completedPartNumbers,
6165
+ sourceSize: opts.source.size,
6166
+ chunkSize,
6167
+ });
6168
+ if (completedPartNumbers.size > 0) {
6169
+ (_d = opts.onProgress) === null || _d === void 0 ? void 0 : _d.call(opts, {
6170
+ phase: "resuming",
6171
+ bytesUploaded,
6172
+ totalBytes: opts.source.size,
6173
+ totalParts,
6174
+ uploadId: session.uploadId,
6175
+ });
6176
+ }
6177
+ try {
6178
+ const pendingParts = createPendingPartNumbers(totalParts, completedPartNumbers);
6179
+ let nextPendingIndex = 0;
6180
+ const concurrency = Math.max(1, Math.min((_e = opts.maxConcurrentParts) !== null && _e !== void 0 ? _e : this.maxConcurrentParts, pendingParts.length || 1));
6181
+ const uploadNextPart = async () => {
6182
+ var _a;
6183
+ while (nextPendingIndex < pendingParts.length) {
6184
+ const partNumber = pendingParts[nextPendingIndex];
6185
+ nextPendingIndex++;
6186
+ const section = await this.uploadPartWithRetry({
6187
+ mode: opts.mode,
6188
+ path: opts.path,
6189
+ source: opts.source,
6190
+ uploadId: session.uploadId,
6191
+ chunkSize,
6192
+ partNumber,
6193
+ totalParts,
6194
+ onProgress: (progress) => {
6195
+ var _a;
6196
+ (_a = opts.onProgress) === null || _a === void 0 ? void 0 : _a.call(opts, {
6197
+ ...progress,
6198
+ bytesUploaded,
6199
+ totalBytes: opts.source.size,
6200
+ uploadId: session.uploadId,
6201
+ });
6202
+ },
6203
+ });
6204
+ if (!completedPartNumbers.has(partNumber)) {
6205
+ completedPartNumbers.add(partNumber);
6206
+ session = {
6207
+ ...session,
6208
+ sections: [...session.sections, section],
6209
+ updatedAt: this.now(),
6210
+ };
6211
+ await this.sessionStore.set(sessionKey, session);
6212
+ bytesUploaded += getPartSize({
6213
+ partNumber,
6214
+ sourceSize: opts.source.size,
6215
+ chunkSize,
6216
+ });
6217
+ }
6218
+ (_a = opts.onProgress) === null || _a === void 0 ? void 0 : _a.call(opts, {
6219
+ phase: "uploading",
6220
+ bytesUploaded,
6221
+ totalBytes: opts.source.size,
6222
+ partNumber,
6223
+ totalParts,
6224
+ uploadId: session.uploadId,
6225
+ });
6226
+ }
6227
+ };
6228
+ await Promise.all(Array.from({ length: concurrency }, () => uploadNextPart()));
6229
+ (_f = opts.onProgress) === null || _f === void 0 ? void 0 : _f.call(opts, {
6230
+ phase: "finishing",
6231
+ bytesUploaded: opts.source.size,
6232
+ totalBytes: opts.source.size,
6233
+ totalParts,
6234
+ uploadId: session.uploadId,
6235
+ });
6236
+ const result = await this.finishMultipartUploadWithRetry({
6237
+ mode: opts.mode,
6238
+ path: opts.path,
6239
+ fileName: opts.source.name,
6240
+ uploadId: session.uploadId,
6241
+ sections: sortSections(session.sections),
6242
+ });
6243
+ await this.sessionStore.delete(sessionKey);
6244
+ (_g = opts.onProgress) === null || _g === void 0 ? void 0 : _g.call(opts, {
6245
+ phase: "uploaded",
6246
+ bytesUploaded: opts.source.size,
6247
+ totalBytes: opts.source.size,
6248
+ totalParts,
6249
+ uploadId: session.uploadId,
6250
+ });
6251
+ return result;
6252
+ }
6253
+ catch (error) {
6254
+ if (shouldForgetMultipartSession(error)) {
6255
+ await this.sessionStore.delete(sessionKey);
6256
+ }
6257
+ (_h = opts.onProgress) === null || _h === void 0 ? void 0 : _h.call(opts, {
6258
+ phase: "error",
6259
+ bytesUploaded,
6260
+ totalBytes: opts.source.size,
6261
+ totalParts,
6262
+ uploadId: session.uploadId,
6263
+ });
6264
+ throw error;
6265
+ }
6266
+ }
6267
+ async getOrStartMultipartSession(opts) {
6268
+ var _a, _b, _c;
6269
+ const existingSession = await this.sessionStore.get(opts.sessionKey);
6270
+ const sourceFingerprint = getSourceFingerprint(opts.source);
6271
+ if (existingSession &&
6272
+ existingSession.mode === opts.mode &&
6273
+ existingSession.path === opts.path &&
6274
+ existingSession.marketId === this.marketId &&
6275
+ existingSession.chunkSize === opts.chunkSize &&
6276
+ existingSession.totalBytes === opts.source.size &&
6277
+ existingSession.sourceFingerprint === sourceFingerprint &&
6278
+ existingSession.overwrite === ((_a = opts.overwrite) !== null && _a !== void 0 ? _a : false)) {
6279
+ return existingSession;
6280
+ }
6281
+ (_b = opts.onProgress) === null || _b === void 0 ? void 0 : _b.call(opts, {
6282
+ phase: "starting",
6283
+ bytesUploaded: 0,
6284
+ totalBytes: opts.source.size,
6285
+ totalParts: opts.totalParts,
6286
+ });
6287
+ const startResponse = await this.startMultipartUpload({
6288
+ mode: opts.mode,
6289
+ path: opts.path,
6290
+ fileName: opts.source.name,
6291
+ overwrite: opts.overwrite,
6292
+ });
6293
+ const uploadId = getMultipartUploadId(startResponse);
6294
+ if (!uploadId) {
6295
+ throw new Error("Media Crate did not return an uploadId");
6296
+ }
6297
+ const now = this.now();
6298
+ const startResult = hasUploadResultShape(startResponse)
6299
+ ? startResponse
6300
+ : undefined;
6301
+ const session = {
6302
+ key: opts.sessionKey,
6303
+ mode: opts.mode,
6304
+ path: opts.path,
6305
+ marketId: this.marketId,
6306
+ uploadId,
6307
+ chunkSize: opts.chunkSize,
6308
+ totalBytes: opts.source.size,
6309
+ totalParts: opts.totalParts,
6310
+ sourceFingerprint,
6311
+ overwrite: (_c = opts.overwrite) !== null && _c !== void 0 ? _c : false,
6312
+ sections: [],
6313
+ targetKey: getMultipartTargetKey(startResponse),
6314
+ startResult,
6315
+ createdAt: now,
6316
+ updatedAt: now,
6317
+ };
6318
+ await this.sessionStore.set(opts.sessionKey, session);
6319
+ return session;
6320
+ }
6321
+ async startMultipartUpload(args) {
6322
+ if (args.mode === "direct") {
6323
+ const url = this.urlFor("/standalone/multipart/start");
6324
+ const headers = await this.createUploadHeaders({
6325
+ mode: args.mode,
6326
+ overwrite: args.overwrite,
6327
+ contentType: "application/json",
6328
+ });
6329
+ const response = await this.fetchImpl(url.toString(), {
6330
+ method: "POST",
6331
+ headers,
6332
+ body: JSON.stringify({
6333
+ filePath: args.path,
6334
+ fileName: args.fileName,
6335
+ }),
6336
+ });
6337
+ await throwIfNotOk(response, "POST", url.toString());
6338
+ return (await response.json());
6339
+ }
6340
+ const url = this.urlFor("/startMultipartUpload");
6341
+ const headers = await this.createUploadHeaders({
6342
+ mode: args.mode,
6343
+ overwrite: args.overwrite,
6344
+ });
6345
+ const formData = new FormData();
6346
+ formData.append("filePath", args.path);
6347
+ formData.append("fileName", args.fileName);
6348
+ const response = await this.fetchImpl(url.toString(), {
6349
+ method: "POST",
6350
+ headers,
6351
+ body: formData,
6352
+ });
6353
+ await throwIfNotOk(response, "POST", url.toString());
6354
+ return (await response.json());
6355
+ }
6356
+ async uploadPartWithRetry(args) {
6357
+ return this.runWithRetry({
6358
+ attempts: this.maxPartAttempts,
6359
+ onRetry: (attempt) => {
6360
+ args.onProgress({
6361
+ phase: "retrying",
6362
+ partNumber: args.partNumber,
6363
+ totalParts: args.totalParts,
6364
+ attempt,
6365
+ uploadId: args.uploadId,
6366
+ });
6367
+ },
6368
+ operation: () => this.uploadMultipartPart(args),
6369
+ });
6370
+ }
6371
+ async uploadMultipartPart(args) {
6372
+ var _a;
6373
+ const start = args.chunkSize * (args.partNumber - 1);
6374
+ const end = Math.min(args.source.size, start + args.chunkSize);
6375
+ const partBody = await args.source.getPart({
6376
+ start,
6377
+ end,
6378
+ partNumber: args.partNumber,
6379
+ });
6380
+ const url = this.urlFor(args.mode === "direct" ? "/standalone/multipart/chunk" : "/uploadChunk");
6381
+ const headers = await this.createUploadHeaders({ mode: args.mode });
6382
+ const formData = new FormData();
6383
+ formData.append("filePath", args.path);
6384
+ formData.append("fileName", args.source.name);
6385
+ formData.append("uploadId", args.uploadId);
6386
+ formData.append("partNumber", String(args.partNumber));
6387
+ appendUploadPart(formData, "file", partBody, args.source.name, args.source.type);
6388
+ const response = await this.fetchImpl(url.toString(), {
6389
+ method: "POST",
6390
+ headers,
6391
+ body: formData,
6392
+ });
6393
+ await throwIfNotOk(response, "POST", url.toString());
6394
+ const json = (await response.json());
6395
+ const eTag = getMultipartPartEtag(json);
6396
+ const partNumber = (_a = getMultipartPartNumber(json)) !== null && _a !== void 0 ? _a : args.partNumber;
6397
+ if (typeof eTag !== "string" || !eTag) {
6398
+ throw new Error(`Media Crate did not return a valid eTag for part ${args.partNumber}`);
6399
+ }
6400
+ return {
6401
+ partNumber: String(partNumber),
6402
+ eTag,
6403
+ };
6404
+ }
6405
+ async finishMultipartUploadWithRetry(args) {
6406
+ return this.runWithRetry({
6407
+ attempts: this.maxFinishAttempts,
6408
+ operation: () => this.finishMultipartUpload(args),
6409
+ });
6410
+ }
6411
+ async finishMultipartUpload(args) {
6412
+ if (args.mode === "direct") {
6413
+ const url = this.urlFor("/standalone/multipart/finish");
6414
+ const headers = await this.createUploadHeaders({
6415
+ mode: args.mode,
6416
+ contentType: "application/json",
6417
+ });
6418
+ const response = await this.fetchImpl(url.toString(), {
6419
+ method: "POST",
6420
+ headers,
6421
+ body: JSON.stringify({
6422
+ filePath: args.path,
6423
+ fileName: args.fileName,
6424
+ uploadId: args.uploadId,
6425
+ sections: JSON.stringify(args.sections),
6426
+ }),
6427
+ });
6428
+ await throwIfNotOk(response, "POST", url.toString());
6429
+ return (await response.json());
6430
+ }
6431
+ const url = this.urlFor("/finishMultipartUpload");
6432
+ const headers = await this.createUploadHeaders({ mode: args.mode });
6433
+ const formData = new FormData();
6434
+ formData.append("filePath", args.path);
6435
+ formData.append("fileName", args.fileName);
6436
+ formData.append("uploadId", args.uploadId);
6437
+ formData.append("sections", JSON.stringify(args.sections));
6438
+ const response = await this.fetchImpl(url.toString(), {
6439
+ method: "POST",
6440
+ headers,
6441
+ body: formData,
6442
+ });
6443
+ await throwIfNotOk(response, "POST", url.toString());
6444
+ return (await response.json());
6445
+ }
6446
+ async cancelDirectMultipartUpload(args) {
6447
+ const url = this.urlFor("/standalone/multipart/cancel");
6448
+ const headers = await this.createUploadHeaders({
6449
+ mode: args.mode,
6450
+ contentType: "application/json",
6451
+ });
6452
+ const response = await this.fetchImpl(url.toString(), {
6453
+ method: "POST",
6454
+ headers,
6455
+ body: JSON.stringify({
6456
+ filePath: args.path,
6457
+ fileName: args.fileName,
6458
+ uploadId: args.uploadId,
6459
+ }),
6460
+ });
6461
+ await throwIfNotOk(response, "POST", url.toString());
6462
+ }
6463
+ async cancelProcessedMultipartUpload(args) {
6464
+ const url = this.urlFor("/cancelUpload");
6465
+ const headers = await this.createUploadHeaders({ mode: args.mode });
6466
+ const formData = new FormData();
6467
+ formData.append("filePath", args.path);
6468
+ formData.append("uploadId", args.uploadId);
6469
+ const response = await this.fetchImpl(url.toString(), {
6470
+ method: "POST",
6471
+ headers,
6472
+ body: formData,
6473
+ });
6474
+ await throwIfNotOk(response, "POST", url.toString());
6475
+ }
6476
+ async runWithRetry(args) {
6477
+ var _a;
6478
+ let lastError;
6479
+ for (let attempt = 1; attempt <= args.attempts; attempt++) {
6480
+ try {
6481
+ return await args.operation();
6482
+ }
6483
+ catch (error) {
6484
+ lastError = error;
6485
+ if (attempt >= args.attempts || !isRetryableError(error)) {
6486
+ break;
6487
+ }
6488
+ const nextAttempt = attempt + 1;
6489
+ (_a = args.onRetry) === null || _a === void 0 ? void 0 : _a.call(args, nextAttempt, error);
6490
+ await this.sleep(this.getRetryDelay(attempt));
6491
+ }
6492
+ }
6493
+ throw lastError instanceof Error ? lastError : new Error(String(lastError));
6494
+ }
6495
+ getRetryDelay(attempt) {
6496
+ const exponentialDelay = this.retryBaseDelayMs * Math.pow(2, attempt - 1);
6497
+ const jitter = Math.floor(this.random() * this.retryBaseDelayMs);
6498
+ return exponentialDelay + jitter;
6499
+ }
6500
+ async createBaseHeaders() {
6501
+ const token = await this.getFirebaseToken();
6502
+ const headers = new Headers();
6503
+ headers.set("Authorization", `Bearer ${token}`);
6504
+ return headers;
6505
+ }
6506
+ async createUploadHeaders(args) {
6507
+ const headers = await this.createBaseHeaders();
6508
+ headers.set("X-Market-Id", this.marketId);
6509
+ headers.set("X-Asset-Mode", args.mode);
6510
+ if (typeof args.overwrite === "boolean") {
6511
+ headers.set("X-Overwrite", String(args.overwrite));
6512
+ }
6513
+ if (args.contentType) {
6514
+ headers.set("Content-Type", args.contentType);
6515
+ }
6516
+ return headers;
6517
+ }
6518
+ assertPathMatchesMarket(path) {
6519
+ const pathMarketId = path.split("/")[0];
6520
+ if (pathMarketId !== this.marketId) {
6521
+ throw new Error(`Upload path must start with marketId "${this.marketId}". Received "${pathMarketId}".`);
6522
+ }
6523
+ }
6524
+ urlFor(path) {
6525
+ return new URL(path.replace(/^\/+/, ""), `${this.baseUrl}/`);
6526
+ }
6527
+ }
6528
+ function resolveMediaCrateBaseUrl(opts) {
6529
+ if (typeof opts.baseUrl === "string") {
6530
+ return normalizeBaseUrl(opts.baseUrl, "baseUrl");
6531
+ }
6532
+ return getMediaCrateBaseUrlFromEnv();
6533
+ }
6534
+ function getMediaCrateBaseUrlFromEnv(env = getProjectEnv()) {
6535
+ for (const envVarName of MEDIA_CRATE_V2_BASE_URL_ENV_VARS) {
6536
+ const value = env[envVarName];
6537
+ if (typeof value !== "undefined") {
6538
+ return normalizeBaseUrl(value, envVarName);
6539
+ }
6540
+ }
6541
+ throw new Error(`Media Crate base URL is required. Pass baseUrl to MediaCrateClient or set one of these environment variables in the host project: ${MEDIA_CRATE_V2_BASE_URL_ENV_VARS.join(", ")}.`);
6542
+ }
6543
+ function getProjectEnv() {
6544
+ var _a;
6545
+ const globalWithProcess = globalThis;
6546
+ const processEnv = (_a = globalWithProcess.process) === null || _a === void 0 ? void 0 : _a.env;
6547
+ const env = {};
6548
+ for (const envVarName of MEDIA_CRATE_V2_BASE_URL_ENV_VARS) {
6549
+ env[envVarName] = processEnv === null || processEnv === void 0 ? void 0 : processEnv[envVarName];
6550
+ }
6551
+ return env;
6552
+ }
6553
+ function normalizeBaseUrl(baseUrl, sourceLabel) {
6554
+ const trimmedBaseUrl = baseUrl.trim();
6555
+ if (!trimmedBaseUrl) {
6556
+ throw new Error(`Media Crate ${sourceLabel} must not be empty`);
6557
+ }
6558
+ return trimmedBaseUrl.replace(/\/+$/, "");
6559
+ }
6560
+ function normalizeUploadPath(path) {
6561
+ const normalizedPath = path.trim().replace(/^\/+/, "");
6562
+ if (!normalizedPath) {
6563
+ throw new Error("Upload path is required");
6564
+ }
6565
+ return normalizedPath;
6566
+ }
6567
+ function normalizeUploadPathSegment(segment, label) {
6568
+ const normalizedSegment = segment.trim().replace(/^\/+|\/+$/g, "");
6569
+ if (!normalizedSegment) {
6570
+ throw new Error(`${label} is required`);
6571
+ }
6572
+ if (normalizedSegment.includes("/")) {
6573
+ throw new Error(`${label} must not contain slashes`);
6574
+ }
6575
+ return normalizedSegment;
6576
+ }
6577
+ function assertValidChunkSize(chunkSize) {
6578
+ if (!Number.isFinite(chunkSize) || chunkSize <= 0) {
6579
+ throw new Error("Multipart chunk size must be greater than zero");
6580
+ }
6581
+ if (chunkSize > MEDIA_CRATE_MULTIPART_MAX_CHUNK_BYTES) {
6582
+ throw new Error(`Multipart chunk size must be <= ${MEDIA_CRATE_MULTIPART_MAX_CHUNK_BYTES} bytes`);
6583
+ }
6584
+ }
6585
+ function getGlobalFetch() {
6586
+ if (typeof fetch === "undefined") {
6587
+ throw new Error("fetch is not defined. Please provide fetchImpl.");
6588
+ }
6589
+ return fetch;
6590
+ }
6591
+ function defaultSleep(durationMs) {
6592
+ return new Promise((resolve) => setTimeout(resolve, durationMs));
6593
+ }
6594
+ function copySession(session) {
6595
+ return {
6596
+ ...session,
6597
+ sections: [...session.sections],
6598
+ startResult: session.startResult ? { ...session.startResult } : undefined,
6599
+ };
6600
+ }
6601
+ function getSourceFingerprint(source) {
6602
+ var _a, _b, _c;
6603
+ return [
6604
+ (_a = source.fingerprint) !== null && _a !== void 0 ? _a : "",
6605
+ source.name,
6606
+ source.size,
6607
+ (_b = source.type) !== null && _b !== void 0 ? _b : "",
6608
+ (_c = source.lastModified) !== null && _c !== void 0 ? _c : "",
6609
+ ].join("|");
6610
+ }
6611
+ function createMultipartSessionKey(args) {
6612
+ return [
6613
+ args.baseUrl,
6614
+ args.marketId,
6615
+ args.mode,
6616
+ args.path,
6617
+ getSourceFingerprint(args.source),
6618
+ args.chunkSize,
6619
+ args.overwrite,
6620
+ ].join("|");
6621
+ }
6622
+ function createPendingPartNumbers(totalParts, completedPartNumbers) {
6623
+ const pending = [];
6624
+ for (let partNumber = 1; partNumber <= totalParts; partNumber++) {
6625
+ if (!completedPartNumbers.has(partNumber)) {
6626
+ pending.push(partNumber);
6627
+ }
6628
+ }
6629
+ return pending;
6630
+ }
6631
+ function getPartSize(args) {
6632
+ const start = args.chunkSize * (args.partNumber - 1);
6633
+ const end = Math.min(args.sourceSize, start + args.chunkSize);
6634
+ return Math.max(0, end - start);
6635
+ }
6636
+ function getCompletedBytes(args) {
6637
+ let bytes = 0;
6638
+ for (let partNumber of args.completedPartNumbers) {
6639
+ bytes += getPartSize({
6640
+ partNumber,
6641
+ sourceSize: args.sourceSize,
6642
+ chunkSize: args.chunkSize,
6643
+ });
6644
+ }
6645
+ return bytes;
6646
+ }
6647
+ function sortSections(sections) {
6648
+ return [...sections].sort((a, b) => Number(a.partNumber) - Number(b.partNumber));
6649
+ }
6650
+ function appendUploadPart(formData, fieldName, partBody, fileName, mimeType) {
6651
+ if (isReactNativeFormDataFile(partBody)) {
6652
+ formData.append(fieldName, partBody);
6653
+ return;
6654
+ }
6655
+ if (typeof Blob !== "undefined" && partBody instanceof Blob) {
6656
+ formData.append(fieldName, partBody, fileName);
6657
+ return;
6658
+ }
6659
+ if (partBody instanceof ArrayBuffer || partBody instanceof Uint8Array) {
6660
+ formData.append(fieldName, new Blob([partBody], {
6661
+ type: mimeType !== null && mimeType !== void 0 ? mimeType : "application/octet-stream",
6662
+ }), fileName);
6663
+ return;
6664
+ }
6665
+ formData.append(fieldName, partBody);
6666
+ }
6667
+ function isReactNativeFormDataFile(value) {
6668
+ return (typeof value === "object" &&
6669
+ value !== null &&
6670
+ !(typeof Blob !== "undefined" && value instanceof Blob) &&
6671
+ !(value instanceof ArrayBuffer) &&
6672
+ !(value instanceof Uint8Array) &&
6673
+ typeof value.uri === "string");
6674
+ }
6675
+ function getMediaCrateUrls(source) {
6676
+ if ("expected" in source) {
6677
+ return source.expected;
6678
+ }
6679
+ if ("urls" in source) {
6680
+ return source.urls;
6681
+ }
6682
+ return source;
6683
+ }
6684
+ function getMultipartUploadId(response) {
6685
+ if ("uploadId" in response && typeof response.uploadId === "string") {
6686
+ return response.uploadId;
6687
+ }
6688
+ if ("data" in response &&
6689
+ response.data &&
6690
+ typeof response.data.uploadId === "string") {
6691
+ return response.data.uploadId;
6692
+ }
6693
+ return undefined;
6694
+ }
6695
+ function getMultipartTargetKey(response) {
6696
+ if ("targetKey" in response && typeof response.targetKey === "string") {
6697
+ return response.targetKey;
6698
+ }
6699
+ if ("data" in response &&
6700
+ response.data &&
6701
+ typeof response.data.key === "string") {
6702
+ return response.data.key;
6703
+ }
6704
+ return undefined;
6705
+ }
6706
+ function getMultipartPartEtag(response) {
6707
+ if ("data" in response) {
6708
+ return response.data.eTag;
6709
+ }
6710
+ return response.eTag;
6711
+ }
6712
+ function getMultipartPartNumber(response) {
6713
+ if ("data" in response) {
6714
+ return response.data.partNumber;
6715
+ }
6716
+ return response.partNumber;
6717
+ }
6718
+ function hasUploadResultShape(value) {
6719
+ if (!value || typeof value !== "object") {
6720
+ return false;
6721
+ }
6722
+ const maybeUploadResult = value;
6723
+ return (typeof maybeUploadResult.assetId === "string" &&
6724
+ typeof maybeUploadResult.statusUrl === "string" &&
6725
+ typeof maybeUploadResult.status === "string" &&
6726
+ typeof maybeUploadResult.expected === "object" &&
6727
+ maybeUploadResult.expected !== null);
6728
+ }
6729
+ async function throwIfNotOk(response, method, url) {
6730
+ if (response.ok) {
6731
+ return;
6732
+ }
6733
+ const responseText = await response.text().catch(() => "");
6734
+ let body = responseText || null;
6735
+ if (responseText) {
6736
+ try {
6737
+ body = JSON.parse(responseText);
6738
+ }
6739
+ catch (_error) {
6740
+ body = responseText;
6741
+ }
6742
+ }
6743
+ const message = typeof body === "object" && body !== null && "message" in body
6744
+ ? String(body.message)
6745
+ : responseText || response.statusText || `Media Crate request failed`;
6746
+ const collidingKeys = typeof body === "object" &&
6747
+ body !== null &&
6748
+ Array.isArray(body.collidingKeys)
6749
+ ? body.collidingKeys
6750
+ : undefined;
6751
+ throw new MediaCrateHttpError({
6752
+ status: response.status,
6753
+ method,
6754
+ url,
6755
+ message,
6756
+ body,
6757
+ collidingKeys,
6758
+ });
6759
+ }
6760
+ function isRetryableError(error) {
6761
+ if (error instanceof MediaCrateHttpError) {
6762
+ return error.status === 429 || error.status >= 500;
6763
+ }
6764
+ return true;
6765
+ }
6766
+ function shouldForgetMultipartSession(error) {
6767
+ return (error instanceof MediaCrateHttpError &&
6768
+ (error.status === 404 || error.status === 409));
6769
+ }
6770
+
6360
6771
  class EarTag {
6361
6772
  static get countryCodesByNumber() {
6362
6773
  let reversed = {};
@@ -6805,4 +7216,4 @@ function incrementAlphaSequence(alpha) {
6805
7216
  return chars.join("");
6806
7217
  }
6807
7218
 
6808
- export { CattlePassport, EarTag, Studio, StudioHeaders, types as StudioTypes, createAppManifest, Studio as default, lotComparator, nextLotNumber, sortByLotNumber };
7219
+ export { CattlePassport, EarTag, InMemoryMediaCrateMultipartSessionStore, MEDIA_CRATE_ASSET_STATUSES, MEDIA_CRATE_DEFAULT_CHUNK_BYTES, MEDIA_CRATE_MEDIA_STATUSES, MEDIA_CRATE_MULTIPART_MAX_CHUNK_BYTES, MEDIA_CRATE_SINGLE_UPLOAD_MAX_BYTES, MEDIA_CRATE_V2_BASE_URL_ENV_VARS, MediaCrateClient, MediaCrateHttpError, MediaCrateUploadSourceError, Studio, StudioHeaders, types as StudioTypes, createAppManifest, createWebUploadSource, Studio as default, getMediaCrateBaseUrlFromEnv, getMediaCrateVariant, getMediaCrateVariantUrl, lotComparator, nextLotNumber, requireMediaCrateVariantUrl, sortByLotNumber };