@nibssplc/cams-sdk-react 0.0.1-beta.52 → 0.0.1-beta.54

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs.js CHANGED
@@ -907,7 +907,7 @@ class Logger {
907
907
  /*! @azure/msal-common v14.16.1 2025-08-05 */
908
908
  /* eslint-disable header/header */
909
909
  const name$2 = "@azure/msal-common";
910
- const version$2 = "14.16.1";
910
+ const version$3 = "14.16.1";
911
911
 
912
912
  /*! @azure/msal-common v14.16.1 2025-08-05 */
913
913
  /*
@@ -2541,7 +2541,7 @@ class CacheManager {
2541
2541
  constructor(clientId, cryptoImpl, logger, staticAuthorityOptions) {
2542
2542
  this.clientId = clientId;
2543
2543
  this.cryptoImpl = cryptoImpl;
2544
- this.commonLogger = logger.clone(name$2, version$2);
2544
+ this.commonLogger = logger.clone(name$2, version$3);
2545
2545
  this.staticAuthorityOptions = staticAuthorityOptions;
2546
2546
  }
2547
2547
  /**
@@ -3791,7 +3791,7 @@ const DEFAULT_NETWORK_IMPLEMENTATION = {
3791
3791
  };
3792
3792
  const DEFAULT_LIBRARY_INFO = {
3793
3793
  sku: Constants.SKU,
3794
- version: version$2,
3794
+ version: version$3,
3795
3795
  cpu: Constants.EMPTY_STRING,
3796
3796
  os: Constants.EMPTY_STRING,
3797
3797
  };
@@ -5916,7 +5916,7 @@ class BaseClient {
5916
5916
  // Set the configuration
5917
5917
  this.config = buildClientConfiguration(configuration);
5918
5918
  // Initialize the logger
5919
- this.logger = new Logger(this.config.loggerOptions, name$2, version$2);
5919
+ this.logger = new Logger(this.config.loggerOptions, name$2, version$3);
5920
5920
  // Initialize crypto
5921
5921
  this.cryptoUtils = this.config.cryptoInterface;
5922
5922
  // Initialize storage interface
@@ -8988,7 +8988,7 @@ function buildConfiguration({ auth: userInputAuth, cache: userInputCache, system
8988
8988
  /*! @azure/msal-browser v3.30.0 2025-08-05 */
8989
8989
  /* eslint-disable header/header */
8990
8990
  const name$1 = "@azure/msal-browser";
8991
- const version$1 = "3.30.0";
8991
+ const version$2 = "3.30.0";
8992
8992
 
8993
8993
  /*! @azure/msal-browser v3.30.0 2025-08-05 */
8994
8994
 
@@ -9062,7 +9062,7 @@ class BaseOperatingContext {
9062
9062
  if (piiLoggingEnabled !== undefined) {
9063
9063
  loggerOptions.piiLoggingEnabled = piiLoggingEnabled;
9064
9064
  }
9065
- this.logger = new Logger(loggerOptions, name$1, version$1);
9065
+ this.logger = new Logger(loggerOptions, name$1, version$2);
9066
9066
  this.available = false;
9067
9067
  }
9068
9068
  /**
@@ -9920,8 +9920,8 @@ class BrowserCacheManager extends CacheManager {
9920
9920
  if (previousVersion) {
9921
9921
  this.logger.info(`MSAL.js was last initialized with version ${previousVersion}`);
9922
9922
  }
9923
- if (previousVersion !== version$1) {
9924
- this.browserStorage.setItem(StaticCacheKeys.VERSION, version$1);
9923
+ if (previousVersion !== version$2) {
9924
+ this.browserStorage.setItem(StaticCacheKeys.VERSION, version$2);
9925
9925
  }
9926
9926
  const idTokenKey = `${Constants.CACHE_PREFIX}.${PersistentCacheKeys.ID_TOKEN}`;
9927
9927
  const clientInfoKey = `${Constants.CACHE_PREFIX}.${PersistentCacheKeys.CLIENT_INFO}`;
@@ -11403,7 +11403,7 @@ class BaseInteractionClient {
11403
11403
  this.navigationClient = navigationClient;
11404
11404
  this.nativeMessageHandler = nativeMessageHandler;
11405
11405
  this.correlationId = correlationId || createNewGuid();
11406
- this.logger = logger.clone(BrowserConstants.MSAL_SKU, version$1, this.correlationId);
11406
+ this.logger = logger.clone(BrowserConstants.MSAL_SKU, version$2, this.correlationId);
11407
11407
  this.performanceClient = performanceClient;
11408
11408
  }
11409
11409
  async clearCacheOnLogout(account) {
@@ -11793,7 +11793,7 @@ class StandardInteractionClient extends BaseInteractionClient {
11793
11793
  serverTelemetryManager: serverTelemetryManager,
11794
11794
  libraryInfo: {
11795
11795
  sku: BrowserConstants.MSAL_SKU,
11796
- version: version$1,
11796
+ version: version$2,
11797
11797
  cpu: Constants.EMPTY_STRING,
11798
11798
  os: Constants.EMPTY_STRING,
11799
11799
  },
@@ -12000,7 +12000,7 @@ class NativeInteractionClient extends BaseInteractionClient {
12000
12000
  : undefined;
12001
12001
  this.skus = ServerTelemetryManager.makeExtraSkuString({
12002
12002
  libraryName: BrowserConstants.MSAL_SKU,
12003
- libraryVersion: version$1,
12003
+ libraryVersion: version$2,
12004
12004
  extensionName: extensionName,
12005
12005
  extensionVersion: this.nativeMessageHandler.getExtensionVersion(),
12006
12006
  });
@@ -16535,7 +16535,7 @@ function getAccountByIdentifiers(allAccounts, accountIdentifiers) {
16535
16535
  /*! @azure/msal-react v2.2.0 2024-11-05 */
16536
16536
  /* eslint-disable header/header */
16537
16537
  const name = "@azure/msal-react";
16538
- const version = "2.2.0";
16538
+ const version$1 = "2.2.0";
16539
16539
 
16540
16540
  /*! @azure/msal-react v2.2.0 2024-11-05 */
16541
16541
 
@@ -16607,11 +16607,11 @@ const reducer = (previousState, action) => {
16607
16607
  */
16608
16608
  function MsalProvider({ instance, children, }) {
16609
16609
  React__default.useEffect(() => {
16610
- instance.initializeWrapperLibrary(WrapperSKU.React, version);
16610
+ instance.initializeWrapperLibrary(WrapperSKU.React, version$1);
16611
16611
  }, [instance]);
16612
16612
  // Create a logger instance for msal-react with the same options as PublicClientApplication
16613
16613
  const logger = React__default.useMemo(() => {
16614
- return instance.getLogger().clone(name, version);
16614
+ return instance.getLogger().clone(name, version$1);
16615
16615
  }, [instance]);
16616
16616
  const [state, updateState] = React__default.useReducer(reducer, undefined, () => {
16617
16617
  // Lazy initialization of the initial state
@@ -17390,7 +17390,32 @@ if (process.env.NODE_ENV === 'production') {
17390
17390
 
17391
17391
  var jsxRuntimeExports = jsxRuntime.exports;
17392
17392
 
17393
- var CAMSContext = React__default.createContext(null);
17393
+ var CAMSContext$1 = React__default.createContext(null);
17394
+ function useCAMSContext$1() {
17395
+ var context = React__default.useContext(CAMSContext$1);
17396
+ if (!context) {
17397
+ throw new Error('useCAMSContext must be used within a CAMSProvider');
17398
+ }
17399
+ return context;
17400
+ }
17401
+
17402
+ function ProtectedRoute(_a) {
17403
+ var children = _a.children, fallback = _a.fallback, redirectTo = _a.redirectTo;
17404
+ var _b = useCAMSContext$1(), isAuthenticated = _b.isAuthenticated, isLoading = _b.isLoading;
17405
+ if (isLoading) {
17406
+ return fallback || jsxRuntimeExports.jsx("div", { children: "Loading..." });
17407
+ }
17408
+ if (!isAuthenticated) {
17409
+ if (redirectTo && typeof window !== 'undefined') {
17410
+ window.location.href = redirectTo;
17411
+ return null;
17412
+ }
17413
+ return fallback || jsxRuntimeExports.jsx("div", { children: "Access denied. Please log in." });
17414
+ }
17415
+ return jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: children });
17416
+ }
17417
+
17418
+ var CAMSMSALContext = React__default.createContext(null);
17394
17419
  var setCookie$1 = function (name, value, days) {
17395
17420
  var expires = new Date(Date.now() + days * 864e5).toUTCString();
17396
17421
  document.cookie = "".concat(name, "=").concat(encodeURIComponent(value), "; expires=").concat(expires, "; path=/; samesite=Lax");
@@ -17409,10 +17434,19 @@ var getCookie$1 = function (name) {
17409
17434
  var deleteCookie$1 = function (name) {
17410
17435
  document.cookie = name + "=; Max-Age=-99999999; path=/";
17411
17436
  };
17412
- function CAMSProvider(_a) {
17437
+ var isTokenValid = function (token) {
17438
+ try {
17439
+ var payload = JSON.parse(atob(token.split(".")[1]));
17440
+ return payload.exp * 1000 > Date.now();
17441
+ }
17442
+ catch (_a) {
17443
+ return false;
17444
+ }
17445
+ };
17446
+ function CAMSMSALProviderInner(_a) {
17413
17447
  var _this = this;
17414
17448
  var children = _a.children, authOptions = __rest(_a, ["children"]);
17415
- var auth = useCAMSAuth(authOptions);
17449
+ var auth = useCAMSMSALAuth(authOptions);
17416
17450
  var profileStorageKey = "".concat(auth.storageKey, "-PROFILE");
17417
17451
  var getInitialProfile = function () {
17418
17452
  if (typeof window === "undefined") {
@@ -17430,6 +17464,7 @@ function CAMSProvider(_a) {
17430
17464
  // Load profile from storage on mount
17431
17465
  React__default.useEffect(function () {
17432
17466
  if (typeof window !== "undefined") {
17467
+ // const storedProfile = localStorage.get Item(profileStorageKey);
17433
17468
  var storedProfile = getCookie$1(profileStorageKey);
17434
17469
  if (storedProfile) {
17435
17470
  try {
@@ -17439,11 +17474,23 @@ function CAMSProvider(_a) {
17439
17474
  }
17440
17475
  }
17441
17476
  }, [profileStorageKey]);
17477
+ // Persist tokens and profile
17478
+ React__default.useEffect(function () {
17479
+ if (auth.accessToken &&
17480
+ isTokenValid(auth.accessToken) &&
17481
+ typeof window !== "undefined") {
17482
+ localStorage.setItem(auth.storageKey, JSON.stringify({
17483
+ accessToken: auth.accessToken,
17484
+ idToken: auth.idToken,
17485
+ appCode: auth.appCode
17486
+ }));
17487
+ }
17488
+ }, [auth.accessToken, auth.idToken, auth.storageKey]);
17442
17489
  // Persist profile separately
17443
17490
  React__default.useEffect(function () {
17444
17491
  if (typeof window !== "undefined") {
17445
17492
  if (userProfile) {
17446
- setCookie$1(profileStorageKey, JSON.stringify(userProfile), 1);
17493
+ setCookie$1(profileStorageKey, JSON.stringify(userProfile), 1); // Store for 1 day
17447
17494
  }
17448
17495
  else {
17449
17496
  deleteCookie$1(profileStorageKey);
@@ -17466,35 +17513,1722 @@ function CAMSProvider(_a) {
17466
17513
  });
17467
17514
  }); };
17468
17515
  var value = React__default.useMemo(function () { return (__assign(__assign({}, auth), { logout: enhancedLogout, userProfile: userProfile, setUserProfile: setUserProfile })); }, [auth, userProfile]);
17469
- return (jsxRuntimeExports.jsx(CAMSContext.Provider, { value: value, children: children }));
17516
+ return (jsxRuntimeExports.jsx(CAMSMSALContext.Provider, { value: value, children: children }));
17470
17517
  }
17471
- function useCAMSContext() {
17472
- var context = React__default.useContext(CAMSContext);
17518
+ function CAMSMSALProvider(props) {
17519
+ var msalConfig = props.msalConfig, msalInstance = props.msalInstance;
17520
+ var instance = msalInstance || new PublicClientApplication(msalConfig);
17521
+ return (jsxRuntimeExports.jsx(MsalProvider, { instance: instance, children: jsxRuntimeExports.jsx(CAMSMSALProviderInner, __assign({}, props)) }));
17522
+ }
17523
+ function useCAMSMSALContext() {
17524
+ var context = React__default.useContext(CAMSMSALContext);
17473
17525
  if (!context) {
17474
- throw new Error('useCAMSContext must be used within a CAMSProvider');
17526
+ throw new Error("useCAMSMSALContext must be used within a CAMSMSALProvider");
17475
17527
  }
17476
17528
  return context;
17477
17529
  }
17478
17530
 
17479
- function ProtectedRoute(_a) {
17480
- var children = _a.children, fallback = _a.fallback, redirectTo = _a.redirectTo;
17481
- var _b = useCAMSContext(), isAuthenticated = _b.isAuthenticated, isLoading = _b.isLoading;
17482
- if (isLoading) {
17483
- return fallback || jsxRuntimeExports.jsx("div", { children: "Loading..." });
17531
+ function ClientOnly(_a) {
17532
+ var children = _a.children, _b = _a.fallback, fallback = _b === void 0 ? null : _b;
17533
+ var _c = React__default.useState(false), hasMounted = _c[0], setHasMounted = _c[1];
17534
+ React__default.useEffect(function () {
17535
+ setHasMounted(true);
17536
+ }, []);
17537
+ if (!hasMounted) {
17538
+ return jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: fallback });
17484
17539
  }
17485
- if (!isAuthenticated) {
17486
- if (redirectTo && typeof window !== 'undefined') {
17487
- window.location.href = redirectTo;
17488
- return null;
17540
+ return jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: children });
17541
+ }
17542
+
17543
+ /** A special constant with type `never` */
17544
+ function $constructor(name, initializer, params) {
17545
+ function init(inst, def) {
17546
+ var _a;
17547
+ Object.defineProperty(inst, "_zod", {
17548
+ value: inst._zod ?? {},
17549
+ enumerable: false,
17550
+ });
17551
+ (_a = inst._zod).traits ?? (_a.traits = new Set());
17552
+ inst._zod.traits.add(name);
17553
+ initializer(inst, def);
17554
+ // support prototype modifications
17555
+ for (const k in _.prototype) {
17556
+ if (!(k in inst))
17557
+ Object.defineProperty(inst, k, { value: _.prototype[k].bind(inst) });
17489
17558
  }
17490
- return fallback || jsxRuntimeExports.jsx("div", { children: "Access denied. Please log in." });
17559
+ inst._zod.constr = _;
17560
+ inst._zod.def = def;
17491
17561
  }
17492
- return jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: children });
17562
+ // doesn't work if Parent has a constructor with arguments
17563
+ const Parent = params?.Parent ?? Object;
17564
+ class Definition extends Parent {
17565
+ }
17566
+ Object.defineProperty(Definition, "name", { value: name });
17567
+ function _(def) {
17568
+ var _a;
17569
+ const inst = params?.Parent ? new Definition() : this;
17570
+ init(inst, def);
17571
+ (_a = inst._zod).deferred ?? (_a.deferred = []);
17572
+ for (const fn of inst._zod.deferred) {
17573
+ fn();
17574
+ }
17575
+ return inst;
17576
+ }
17577
+ Object.defineProperty(_, "init", { value: init });
17578
+ Object.defineProperty(_, Symbol.hasInstance, {
17579
+ value: (inst) => {
17580
+ if (params?.Parent && inst instanceof params.Parent)
17581
+ return true;
17582
+ return inst?._zod?.traits?.has(name);
17583
+ },
17584
+ });
17585
+ Object.defineProperty(_, "name", { value: name });
17586
+ return _;
17587
+ }
17588
+ class $ZodAsyncError extends Error {
17589
+ constructor() {
17590
+ super(`Encountered Promise during synchronous parse. Use .parseAsync() instead.`);
17591
+ }
17592
+ }
17593
+ const globalConfig = {};
17594
+ function config(newConfig) {
17595
+ return globalConfig;
17493
17596
  }
17494
17597
 
17495
- var CAMSMSALContext = React__default.createContext(null);
17598
+ // functions
17599
+ function jsonStringifyReplacer(_, value) {
17600
+ if (typeof value === "bigint")
17601
+ return value.toString();
17602
+ return value;
17603
+ }
17604
+ function nullish(input) {
17605
+ return input === null || input === undefined;
17606
+ }
17607
+ function cleanRegex(source) {
17608
+ const start = source.startsWith("^") ? 1 : 0;
17609
+ const end = source.endsWith("$") ? source.length - 1 : source.length;
17610
+ return source.slice(start, end);
17611
+ }
17612
+ const EVALUATING = Symbol("evaluating");
17613
+ function defineLazy(object, key, getter) {
17614
+ let value = undefined;
17615
+ Object.defineProperty(object, key, {
17616
+ get() {
17617
+ if (value === EVALUATING) {
17618
+ // Circular reference detected, return undefined to break the cycle
17619
+ return undefined;
17620
+ }
17621
+ if (value === undefined) {
17622
+ value = EVALUATING;
17623
+ value = getter();
17624
+ }
17625
+ return value;
17626
+ },
17627
+ set(v) {
17628
+ Object.defineProperty(object, key, {
17629
+ value: v,
17630
+ // configurable: true,
17631
+ });
17632
+ // object[key] = v;
17633
+ },
17634
+ configurable: true,
17635
+ });
17636
+ }
17637
+ const captureStackTrace = ("captureStackTrace" in Error ? Error.captureStackTrace : (..._args) => { });
17638
+ function isObject(data) {
17639
+ return typeof data === "object" && data !== null && !Array.isArray(data);
17640
+ }
17641
+ function isPlainObject(o) {
17642
+ if (isObject(o) === false)
17643
+ return false;
17644
+ // modified constructor
17645
+ const ctor = o.constructor;
17646
+ if (ctor === undefined)
17647
+ return true;
17648
+ // modified prototype
17649
+ const prot = ctor.prototype;
17650
+ if (isObject(prot) === false)
17651
+ return false;
17652
+ // ctor doesn't have static `isPrototypeOf`
17653
+ if (Object.prototype.hasOwnProperty.call(prot, "isPrototypeOf") === false) {
17654
+ return false;
17655
+ }
17656
+ return true;
17657
+ }
17658
+ function shallowClone(o) {
17659
+ if (isPlainObject(o))
17660
+ return { ...o };
17661
+ return o;
17662
+ }
17663
+ function escapeRegex(str) {
17664
+ return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
17665
+ }
17666
+ // zod-specific utils
17667
+ function clone(inst, def, params) {
17668
+ const cl = new inst._zod.constr(def ?? inst._zod.def);
17669
+ if (!def || params?.parent)
17670
+ cl._zod.parent = inst;
17671
+ return cl;
17672
+ }
17673
+ function normalizeParams(_params) {
17674
+ const params = _params;
17675
+ if (!params)
17676
+ return {};
17677
+ if (typeof params === "string")
17678
+ return { error: () => params };
17679
+ if (params?.message !== undefined) {
17680
+ if (params?.error !== undefined)
17681
+ throw new Error("Cannot specify both `message` and `error` params");
17682
+ params.error = params.message;
17683
+ }
17684
+ delete params.message;
17685
+ if (typeof params.error === "string")
17686
+ return { ...params, error: () => params.error };
17687
+ return params;
17688
+ }
17689
+ // invalid_type | too_big | too_small | invalid_format | not_multiple_of | unrecognized_keys | invalid_union | invalid_key | invalid_element | invalid_value | custom
17690
+ function aborted(x, startIndex = 0) {
17691
+ for (let i = startIndex; i < x.issues.length; i++) {
17692
+ if (x.issues[i]?.continue !== true) {
17693
+ return true;
17694
+ }
17695
+ }
17696
+ return false;
17697
+ }
17698
+ function prefixIssues(path, issues) {
17699
+ return issues.map((iss) => {
17700
+ var _a;
17701
+ (_a = iss).path ?? (_a.path = []);
17702
+ iss.path.unshift(path);
17703
+ return iss;
17704
+ });
17705
+ }
17706
+ function unwrapMessage(message) {
17707
+ return typeof message === "string" ? message : message?.message;
17708
+ }
17709
+ function finalizeIssue(iss, ctx, config) {
17710
+ const full = { ...iss, path: iss.path ?? [] };
17711
+ // for backwards compatibility
17712
+ if (!iss.message) {
17713
+ const message = unwrapMessage(iss.inst?._zod.def?.error?.(iss)) ??
17714
+ unwrapMessage(ctx?.error?.(iss)) ??
17715
+ unwrapMessage(config.customError?.(iss)) ??
17716
+ unwrapMessage(config.localeError?.(iss)) ??
17717
+ "Invalid input";
17718
+ full.message = message;
17719
+ }
17720
+ // delete (full as any).def;
17721
+ delete full.inst;
17722
+ delete full.continue;
17723
+ if (!ctx?.reportInput) {
17724
+ delete full.input;
17725
+ }
17726
+ return full;
17727
+ }
17728
+ function getLengthableOrigin(input) {
17729
+ if (Array.isArray(input))
17730
+ return "array";
17731
+ if (typeof input === "string")
17732
+ return "string";
17733
+ return "unknown";
17734
+ }
17735
+ function issue(...args) {
17736
+ const [iss, input, inst] = args;
17737
+ if (typeof iss === "string") {
17738
+ return {
17739
+ message: iss,
17740
+ code: "custom",
17741
+ input,
17742
+ inst,
17743
+ };
17744
+ }
17745
+ return { ...iss };
17746
+ }
17747
+
17748
+ const initializer$1 = (inst, def) => {
17749
+ inst.name = "$ZodError";
17750
+ Object.defineProperty(inst, "_zod", {
17751
+ value: inst._zod,
17752
+ enumerable: false,
17753
+ });
17754
+ Object.defineProperty(inst, "issues", {
17755
+ value: def,
17756
+ enumerable: false,
17757
+ });
17758
+ inst.message = JSON.stringify(def, jsonStringifyReplacer, 2);
17759
+ Object.defineProperty(inst, "toString", {
17760
+ value: () => inst.message,
17761
+ enumerable: false,
17762
+ });
17763
+ };
17764
+ const $ZodError = $constructor("$ZodError", initializer$1);
17765
+ const $ZodRealError = $constructor("$ZodError", initializer$1, { Parent: Error });
17766
+ function flattenError(error, mapper = (issue) => issue.message) {
17767
+ const fieldErrors = {};
17768
+ const formErrors = [];
17769
+ for (const sub of error.issues) {
17770
+ if (sub.path.length > 0) {
17771
+ fieldErrors[sub.path[0]] = fieldErrors[sub.path[0]] || [];
17772
+ fieldErrors[sub.path[0]].push(mapper(sub));
17773
+ }
17774
+ else {
17775
+ formErrors.push(mapper(sub));
17776
+ }
17777
+ }
17778
+ return { formErrors, fieldErrors };
17779
+ }
17780
+ function formatError(error, _mapper) {
17781
+ const mapper = _mapper ||
17782
+ function (issue) {
17783
+ return issue.message;
17784
+ };
17785
+ const fieldErrors = { _errors: [] };
17786
+ const processError = (error) => {
17787
+ for (const issue of error.issues) {
17788
+ if (issue.code === "invalid_union" && issue.errors.length) {
17789
+ issue.errors.map((issues) => processError({ issues }));
17790
+ }
17791
+ else if (issue.code === "invalid_key") {
17792
+ processError({ issues: issue.issues });
17793
+ }
17794
+ else if (issue.code === "invalid_element") {
17795
+ processError({ issues: issue.issues });
17796
+ }
17797
+ else if (issue.path.length === 0) {
17798
+ fieldErrors._errors.push(mapper(issue));
17799
+ }
17800
+ else {
17801
+ let curr = fieldErrors;
17802
+ let i = 0;
17803
+ while (i < issue.path.length) {
17804
+ const el = issue.path[i];
17805
+ const terminal = i === issue.path.length - 1;
17806
+ if (!terminal) {
17807
+ curr[el] = curr[el] || { _errors: [] };
17808
+ }
17809
+ else {
17810
+ curr[el] = curr[el] || { _errors: [] };
17811
+ curr[el]._errors.push(mapper(issue));
17812
+ }
17813
+ curr = curr[el];
17814
+ i++;
17815
+ }
17816
+ }
17817
+ }
17818
+ };
17819
+ processError(error);
17820
+ return fieldErrors;
17821
+ }
17822
+
17823
+ const _parse = (_Err) => (schema, value, _ctx, _params) => {
17824
+ const ctx = _ctx ? Object.assign(_ctx, { async: false }) : { async: false };
17825
+ const result = schema._zod.run({ value, issues: [] }, ctx);
17826
+ if (result instanceof Promise) {
17827
+ throw new $ZodAsyncError();
17828
+ }
17829
+ if (result.issues.length) {
17830
+ const e = new (_params?.Err ?? _Err)(result.issues.map((iss) => finalizeIssue(iss, ctx, config())));
17831
+ captureStackTrace(e, _params?.callee);
17832
+ throw e;
17833
+ }
17834
+ return result.value;
17835
+ };
17836
+ const _parseAsync = (_Err) => async (schema, value, _ctx, params) => {
17837
+ const ctx = _ctx ? Object.assign(_ctx, { async: true }) : { async: true };
17838
+ let result = schema._zod.run({ value, issues: [] }, ctx);
17839
+ if (result instanceof Promise)
17840
+ result = await result;
17841
+ if (result.issues.length) {
17842
+ const e = new (params?.Err ?? _Err)(result.issues.map((iss) => finalizeIssue(iss, ctx, config())));
17843
+ captureStackTrace(e, params?.callee);
17844
+ throw e;
17845
+ }
17846
+ return result.value;
17847
+ };
17848
+ const _safeParse = (_Err) => (schema, value, _ctx) => {
17849
+ const ctx = _ctx ? { ..._ctx, async: false } : { async: false };
17850
+ const result = schema._zod.run({ value, issues: [] }, ctx);
17851
+ if (result instanceof Promise) {
17852
+ throw new $ZodAsyncError();
17853
+ }
17854
+ return result.issues.length
17855
+ ? {
17856
+ success: false,
17857
+ error: new (_Err ?? $ZodError)(result.issues.map((iss) => finalizeIssue(iss, ctx, config()))),
17858
+ }
17859
+ : { success: true, data: result.value };
17860
+ };
17861
+ const safeParse$1 = /* @__PURE__*/ _safeParse($ZodRealError);
17862
+ const _safeParseAsync = (_Err) => async (schema, value, _ctx) => {
17863
+ const ctx = _ctx ? Object.assign(_ctx, { async: true }) : { async: true };
17864
+ let result = schema._zod.run({ value, issues: [] }, ctx);
17865
+ if (result instanceof Promise)
17866
+ result = await result;
17867
+ return result.issues.length
17868
+ ? {
17869
+ success: false,
17870
+ error: new _Err(result.issues.map((iss) => finalizeIssue(iss, ctx, config()))),
17871
+ }
17872
+ : { success: true, data: result.value };
17873
+ };
17874
+ const safeParseAsync$1 = /* @__PURE__*/ _safeParseAsync($ZodRealError);
17875
+
17876
+ /** Returns a regex for validating an RFC 9562/4122 UUID.
17877
+ *
17878
+ * @param version Optionally specify a version 1-8. If no version is specified, all versions are supported. */
17879
+ const uuid$1 = (version) => {
17880
+ if (!version)
17881
+ return /^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000)$/;
17882
+ return new RegExp(`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${version}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`);
17883
+ };
17884
+ const string = (params) => {
17885
+ const regex = params ? `[\\s\\S]{${params?.minimum ?? 0},${params?.maximum ?? ""}}` : `[\\s\\S]*`;
17886
+ return new RegExp(`^${regex}$`);
17887
+ };
17888
+ // regex for string with no uppercase letters
17889
+ const lowercase = /^[^A-Z]*$/;
17890
+ // regex for string with no lowercase letters
17891
+ const uppercase = /^[^a-z]*$/;
17892
+
17893
+ // import { $ZodType } from "./schemas.js";
17894
+ const $ZodCheck = /*@__PURE__*/ $constructor("$ZodCheck", (inst, def) => {
17895
+ var _a;
17896
+ inst._zod ?? (inst._zod = {});
17897
+ inst._zod.def = def;
17898
+ (_a = inst._zod).onattach ?? (_a.onattach = []);
17899
+ });
17900
+ const $ZodCheckMaxLength = /*@__PURE__*/ $constructor("$ZodCheckMaxLength", (inst, def) => {
17901
+ var _a;
17902
+ $ZodCheck.init(inst, def);
17903
+ (_a = inst._zod.def).when ?? (_a.when = (payload) => {
17904
+ const val = payload.value;
17905
+ return !nullish(val) && val.length !== undefined;
17906
+ });
17907
+ inst._zod.onattach.push((inst) => {
17908
+ const curr = (inst._zod.bag.maximum ?? Number.POSITIVE_INFINITY);
17909
+ if (def.maximum < curr)
17910
+ inst._zod.bag.maximum = def.maximum;
17911
+ });
17912
+ inst._zod.check = (payload) => {
17913
+ const input = payload.value;
17914
+ const length = input.length;
17915
+ if (length <= def.maximum)
17916
+ return;
17917
+ const origin = getLengthableOrigin(input);
17918
+ payload.issues.push({
17919
+ origin,
17920
+ code: "too_big",
17921
+ maximum: def.maximum,
17922
+ inclusive: true,
17923
+ input,
17924
+ inst,
17925
+ continue: !def.abort,
17926
+ });
17927
+ };
17928
+ });
17929
+ const $ZodCheckMinLength = /*@__PURE__*/ $constructor("$ZodCheckMinLength", (inst, def) => {
17930
+ var _a;
17931
+ $ZodCheck.init(inst, def);
17932
+ (_a = inst._zod.def).when ?? (_a.when = (payload) => {
17933
+ const val = payload.value;
17934
+ return !nullish(val) && val.length !== undefined;
17935
+ });
17936
+ inst._zod.onattach.push((inst) => {
17937
+ const curr = (inst._zod.bag.minimum ?? Number.NEGATIVE_INFINITY);
17938
+ if (def.minimum > curr)
17939
+ inst._zod.bag.minimum = def.minimum;
17940
+ });
17941
+ inst._zod.check = (payload) => {
17942
+ const input = payload.value;
17943
+ const length = input.length;
17944
+ if (length >= def.minimum)
17945
+ return;
17946
+ const origin = getLengthableOrigin(input);
17947
+ payload.issues.push({
17948
+ origin,
17949
+ code: "too_small",
17950
+ minimum: def.minimum,
17951
+ inclusive: true,
17952
+ input,
17953
+ inst,
17954
+ continue: !def.abort,
17955
+ });
17956
+ };
17957
+ });
17958
+ const $ZodCheckLengthEquals = /*@__PURE__*/ $constructor("$ZodCheckLengthEquals", (inst, def) => {
17959
+ var _a;
17960
+ $ZodCheck.init(inst, def);
17961
+ (_a = inst._zod.def).when ?? (_a.when = (payload) => {
17962
+ const val = payload.value;
17963
+ return !nullish(val) && val.length !== undefined;
17964
+ });
17965
+ inst._zod.onattach.push((inst) => {
17966
+ const bag = inst._zod.bag;
17967
+ bag.minimum = def.length;
17968
+ bag.maximum = def.length;
17969
+ bag.length = def.length;
17970
+ });
17971
+ inst._zod.check = (payload) => {
17972
+ const input = payload.value;
17973
+ const length = input.length;
17974
+ if (length === def.length)
17975
+ return;
17976
+ const origin = getLengthableOrigin(input);
17977
+ const tooBig = length > def.length;
17978
+ payload.issues.push({
17979
+ origin,
17980
+ ...(tooBig ? { code: "too_big", maximum: def.length } : { code: "too_small", minimum: def.length }),
17981
+ inclusive: true,
17982
+ exact: true,
17983
+ input: payload.value,
17984
+ inst,
17985
+ continue: !def.abort,
17986
+ });
17987
+ };
17988
+ });
17989
+ const $ZodCheckStringFormat = /*@__PURE__*/ $constructor("$ZodCheckStringFormat", (inst, def) => {
17990
+ var _a, _b;
17991
+ $ZodCheck.init(inst, def);
17992
+ inst._zod.onattach.push((inst) => {
17993
+ const bag = inst._zod.bag;
17994
+ bag.format = def.format;
17995
+ if (def.pattern) {
17996
+ bag.patterns ?? (bag.patterns = new Set());
17997
+ bag.patterns.add(def.pattern);
17998
+ }
17999
+ });
18000
+ if (def.pattern)
18001
+ (_a = inst._zod).check ?? (_a.check = (payload) => {
18002
+ def.pattern.lastIndex = 0;
18003
+ if (def.pattern.test(payload.value))
18004
+ return;
18005
+ payload.issues.push({
18006
+ origin: "string",
18007
+ code: "invalid_format",
18008
+ format: def.format,
18009
+ input: payload.value,
18010
+ ...(def.pattern ? { pattern: def.pattern.toString() } : {}),
18011
+ inst,
18012
+ continue: !def.abort,
18013
+ });
18014
+ });
18015
+ else
18016
+ (_b = inst._zod).check ?? (_b.check = () => { });
18017
+ });
18018
+ const $ZodCheckRegex = /*@__PURE__*/ $constructor("$ZodCheckRegex", (inst, def) => {
18019
+ $ZodCheckStringFormat.init(inst, def);
18020
+ inst._zod.check = (payload) => {
18021
+ def.pattern.lastIndex = 0;
18022
+ if (def.pattern.test(payload.value))
18023
+ return;
18024
+ payload.issues.push({
18025
+ origin: "string",
18026
+ code: "invalid_format",
18027
+ format: "regex",
18028
+ input: payload.value,
18029
+ pattern: def.pattern.toString(),
18030
+ inst,
18031
+ continue: !def.abort,
18032
+ });
18033
+ };
18034
+ });
18035
+ const $ZodCheckLowerCase = /*@__PURE__*/ $constructor("$ZodCheckLowerCase", (inst, def) => {
18036
+ def.pattern ?? (def.pattern = lowercase);
18037
+ $ZodCheckStringFormat.init(inst, def);
18038
+ });
18039
+ const $ZodCheckUpperCase = /*@__PURE__*/ $constructor("$ZodCheckUpperCase", (inst, def) => {
18040
+ def.pattern ?? (def.pattern = uppercase);
18041
+ $ZodCheckStringFormat.init(inst, def);
18042
+ });
18043
+ const $ZodCheckIncludes = /*@__PURE__*/ $constructor("$ZodCheckIncludes", (inst, def) => {
18044
+ $ZodCheck.init(inst, def);
18045
+ const escapedRegex = escapeRegex(def.includes);
18046
+ const pattern = new RegExp(typeof def.position === "number" ? `^.{${def.position}}${escapedRegex}` : escapedRegex);
18047
+ def.pattern = pattern;
18048
+ inst._zod.onattach.push((inst) => {
18049
+ const bag = inst._zod.bag;
18050
+ bag.patterns ?? (bag.patterns = new Set());
18051
+ bag.patterns.add(pattern);
18052
+ });
18053
+ inst._zod.check = (payload) => {
18054
+ if (payload.value.includes(def.includes, def.position))
18055
+ return;
18056
+ payload.issues.push({
18057
+ origin: "string",
18058
+ code: "invalid_format",
18059
+ format: "includes",
18060
+ includes: def.includes,
18061
+ input: payload.value,
18062
+ inst,
18063
+ continue: !def.abort,
18064
+ });
18065
+ };
18066
+ });
18067
+ const $ZodCheckStartsWith = /*@__PURE__*/ $constructor("$ZodCheckStartsWith", (inst, def) => {
18068
+ $ZodCheck.init(inst, def);
18069
+ const pattern = new RegExp(`^${escapeRegex(def.prefix)}.*`);
18070
+ def.pattern ?? (def.pattern = pattern);
18071
+ inst._zod.onattach.push((inst) => {
18072
+ const bag = inst._zod.bag;
18073
+ bag.patterns ?? (bag.patterns = new Set());
18074
+ bag.patterns.add(pattern);
18075
+ });
18076
+ inst._zod.check = (payload) => {
18077
+ if (payload.value.startsWith(def.prefix))
18078
+ return;
18079
+ payload.issues.push({
18080
+ origin: "string",
18081
+ code: "invalid_format",
18082
+ format: "starts_with",
18083
+ prefix: def.prefix,
18084
+ input: payload.value,
18085
+ inst,
18086
+ continue: !def.abort,
18087
+ });
18088
+ };
18089
+ });
18090
+ const $ZodCheckEndsWith = /*@__PURE__*/ $constructor("$ZodCheckEndsWith", (inst, def) => {
18091
+ $ZodCheck.init(inst, def);
18092
+ const pattern = new RegExp(`.*${escapeRegex(def.suffix)}$`);
18093
+ def.pattern ?? (def.pattern = pattern);
18094
+ inst._zod.onattach.push((inst) => {
18095
+ const bag = inst._zod.bag;
18096
+ bag.patterns ?? (bag.patterns = new Set());
18097
+ bag.patterns.add(pattern);
18098
+ });
18099
+ inst._zod.check = (payload) => {
18100
+ if (payload.value.endsWith(def.suffix))
18101
+ return;
18102
+ payload.issues.push({
18103
+ origin: "string",
18104
+ code: "invalid_format",
18105
+ format: "ends_with",
18106
+ suffix: def.suffix,
18107
+ input: payload.value,
18108
+ inst,
18109
+ continue: !def.abort,
18110
+ });
18111
+ };
18112
+ });
18113
+ const $ZodCheckOverwrite = /*@__PURE__*/ $constructor("$ZodCheckOverwrite", (inst, def) => {
18114
+ $ZodCheck.init(inst, def);
18115
+ inst._zod.check = (payload) => {
18116
+ payload.value = def.tx(payload.value);
18117
+ };
18118
+ });
18119
+
18120
+ const version = {
18121
+ major: 4,
18122
+ minor: 0,
18123
+ patch: 17,
18124
+ };
18125
+
18126
+ const $ZodType = /*@__PURE__*/ $constructor("$ZodType", (inst, def) => {
18127
+ var _a;
18128
+ inst ?? (inst = {});
18129
+ inst._zod.def = def; // set _def property
18130
+ inst._zod.bag = inst._zod.bag || {}; // initialize _bag object
18131
+ inst._zod.version = version;
18132
+ const checks = [...(inst._zod.def.checks ?? [])];
18133
+ // if inst is itself a checks.$ZodCheck, run it as a check
18134
+ if (inst._zod.traits.has("$ZodCheck")) {
18135
+ checks.unshift(inst);
18136
+ }
18137
+ //
18138
+ for (const ch of checks) {
18139
+ for (const fn of ch._zod.onattach) {
18140
+ fn(inst);
18141
+ }
18142
+ }
18143
+ if (checks.length === 0) {
18144
+ // deferred initializer
18145
+ // inst._zod.parse is not yet defined
18146
+ (_a = inst._zod).deferred ?? (_a.deferred = []);
18147
+ inst._zod.deferred?.push(() => {
18148
+ inst._zod.run = inst._zod.parse;
18149
+ });
18150
+ }
18151
+ else {
18152
+ const runChecks = (payload, checks, ctx) => {
18153
+ let isAborted = aborted(payload);
18154
+ let asyncResult;
18155
+ for (const ch of checks) {
18156
+ if (ch._zod.def.when) {
18157
+ const shouldRun = ch._zod.def.when(payload);
18158
+ if (!shouldRun)
18159
+ continue;
18160
+ }
18161
+ else if (isAborted) {
18162
+ continue;
18163
+ }
18164
+ const currLen = payload.issues.length;
18165
+ const _ = ch._zod.check(payload);
18166
+ if (_ instanceof Promise && ctx?.async === false) {
18167
+ throw new $ZodAsyncError();
18168
+ }
18169
+ if (asyncResult || _ instanceof Promise) {
18170
+ asyncResult = (asyncResult ?? Promise.resolve()).then(async () => {
18171
+ await _;
18172
+ const nextLen = payload.issues.length;
18173
+ if (nextLen === currLen)
18174
+ return;
18175
+ if (!isAborted)
18176
+ isAborted = aborted(payload, currLen);
18177
+ });
18178
+ }
18179
+ else {
18180
+ const nextLen = payload.issues.length;
18181
+ if (nextLen === currLen)
18182
+ continue;
18183
+ if (!isAborted)
18184
+ isAborted = aborted(payload, currLen);
18185
+ }
18186
+ }
18187
+ if (asyncResult) {
18188
+ return asyncResult.then(() => {
18189
+ return payload;
18190
+ });
18191
+ }
18192
+ return payload;
18193
+ };
18194
+ inst._zod.run = (payload, ctx) => {
18195
+ const result = inst._zod.parse(payload, ctx);
18196
+ if (result instanceof Promise) {
18197
+ if (ctx.async === false)
18198
+ throw new $ZodAsyncError();
18199
+ return result.then((result) => runChecks(result, checks, ctx));
18200
+ }
18201
+ return runChecks(result, checks, ctx);
18202
+ };
18203
+ }
18204
+ inst["~standard"] = {
18205
+ validate: (value) => {
18206
+ try {
18207
+ const r = safeParse$1(inst, value);
18208
+ return r.success ? { value: r.data } : { issues: r.error?.issues };
18209
+ }
18210
+ catch (_) {
18211
+ return safeParseAsync$1(inst, value).then((r) => (r.success ? { value: r.data } : { issues: r.error?.issues }));
18212
+ }
18213
+ },
18214
+ vendor: "zod",
18215
+ version: 1,
18216
+ };
18217
+ });
18218
+ const $ZodString = /*@__PURE__*/ $constructor("$ZodString", (inst, def) => {
18219
+ $ZodType.init(inst, def);
18220
+ inst._zod.pattern = [...(inst?._zod.bag?.patterns ?? [])].pop() ?? string(inst._zod.bag);
18221
+ inst._zod.parse = (payload, _) => {
18222
+ if (def.coerce)
18223
+ try {
18224
+ payload.value = String(payload.value);
18225
+ }
18226
+ catch (_) { }
18227
+ if (typeof payload.value === "string")
18228
+ return payload;
18229
+ payload.issues.push({
18230
+ expected: "string",
18231
+ code: "invalid_type",
18232
+ input: payload.value,
18233
+ inst,
18234
+ });
18235
+ return payload;
18236
+ };
18237
+ });
18238
+ const $ZodStringFormat = /*@__PURE__*/ $constructor("$ZodStringFormat", (inst, def) => {
18239
+ // check initialization must come first
18240
+ $ZodCheckStringFormat.init(inst, def);
18241
+ $ZodString.init(inst, def);
18242
+ });
18243
+ const $ZodUUID = /*@__PURE__*/ $constructor("$ZodUUID", (inst, def) => {
18244
+ if (def.version) {
18245
+ const versionMap = {
18246
+ v1: 1,
18247
+ v2: 2,
18248
+ v3: 3,
18249
+ v4: 4,
18250
+ v5: 5,
18251
+ v6: 6,
18252
+ v7: 7,
18253
+ v8: 8,
18254
+ };
18255
+ const v = versionMap[def.version];
18256
+ if (v === undefined)
18257
+ throw new Error(`Invalid UUID version: "${def.version}"`);
18258
+ def.pattern ?? (def.pattern = uuid$1(v));
18259
+ }
18260
+ else
18261
+ def.pattern ?? (def.pattern = uuid$1());
18262
+ $ZodStringFormat.init(inst, def);
18263
+ });
18264
+ function handleArrayResult(result, final, index) {
18265
+ if (result.issues.length) {
18266
+ final.issues.push(...prefixIssues(index, result.issues));
18267
+ }
18268
+ final.value[index] = result.value;
18269
+ }
18270
+ const $ZodArray = /*@__PURE__*/ $constructor("$ZodArray", (inst, def) => {
18271
+ $ZodType.init(inst, def);
18272
+ inst._zod.parse = (payload, ctx) => {
18273
+ const input = payload.value;
18274
+ if (!Array.isArray(input)) {
18275
+ payload.issues.push({
18276
+ expected: "array",
18277
+ code: "invalid_type",
18278
+ input,
18279
+ inst,
18280
+ });
18281
+ return payload;
18282
+ }
18283
+ payload.value = Array(input.length);
18284
+ const proms = [];
18285
+ for (let i = 0; i < input.length; i++) {
18286
+ const item = input[i];
18287
+ const result = def.element._zod.run({
18288
+ value: item,
18289
+ issues: [],
18290
+ }, ctx);
18291
+ if (result instanceof Promise) {
18292
+ proms.push(result.then((result) => handleArrayResult(result, payload, i)));
18293
+ }
18294
+ else {
18295
+ handleArrayResult(result, payload, i);
18296
+ }
18297
+ }
18298
+ if (proms.length) {
18299
+ return Promise.all(proms).then(() => payload);
18300
+ }
18301
+ return payload; //handleArrayResultsAsync(parseResults, final);
18302
+ };
18303
+ });
18304
+ function handleUnionResults(results, final, inst, ctx) {
18305
+ for (const result of results) {
18306
+ if (result.issues.length === 0) {
18307
+ final.value = result.value;
18308
+ return final;
18309
+ }
18310
+ }
18311
+ const nonaborted = results.filter((r) => !aborted(r));
18312
+ if (nonaborted.length === 1) {
18313
+ final.value = nonaborted[0].value;
18314
+ return nonaborted[0];
18315
+ }
18316
+ final.issues.push({
18317
+ code: "invalid_union",
18318
+ input: final.value,
18319
+ inst,
18320
+ errors: results.map((result) => result.issues.map((iss) => finalizeIssue(iss, ctx, config()))),
18321
+ });
18322
+ return final;
18323
+ }
18324
+ const $ZodUnion = /*@__PURE__*/ $constructor("$ZodUnion", (inst, def) => {
18325
+ $ZodType.init(inst, def);
18326
+ defineLazy(inst._zod, "optin", () => def.options.some((o) => o._zod.optin === "optional") ? "optional" : undefined);
18327
+ defineLazy(inst._zod, "optout", () => def.options.some((o) => o._zod.optout === "optional") ? "optional" : undefined);
18328
+ defineLazy(inst._zod, "values", () => {
18329
+ if (def.options.every((o) => o._zod.values)) {
18330
+ return new Set(def.options.flatMap((option) => Array.from(option._zod.values)));
18331
+ }
18332
+ return undefined;
18333
+ });
18334
+ defineLazy(inst._zod, "pattern", () => {
18335
+ if (def.options.every((o) => o._zod.pattern)) {
18336
+ const patterns = def.options.map((o) => o._zod.pattern);
18337
+ return new RegExp(`^(${patterns.map((p) => cleanRegex(p.source)).join("|")})$`);
18338
+ }
18339
+ return undefined;
18340
+ });
18341
+ const single = def.options.length === 1;
18342
+ const first = def.options[0]._zod.run;
18343
+ inst._zod.parse = (payload, ctx) => {
18344
+ if (single) {
18345
+ return first(payload, ctx);
18346
+ }
18347
+ let async = false;
18348
+ const results = [];
18349
+ for (const option of def.options) {
18350
+ const result = option._zod.run({
18351
+ value: payload.value,
18352
+ issues: [],
18353
+ }, ctx);
18354
+ if (result instanceof Promise) {
18355
+ results.push(result);
18356
+ async = true;
18357
+ }
18358
+ else {
18359
+ if (result.issues.length === 0)
18360
+ return result;
18361
+ results.push(result);
18362
+ }
18363
+ }
18364
+ if (!async)
18365
+ return handleUnionResults(results, payload, inst, ctx);
18366
+ return Promise.all(results).then((results) => {
18367
+ return handleUnionResults(results, payload, inst, ctx);
18368
+ });
18369
+ };
18370
+ });
18371
+ const $ZodIntersection = /*@__PURE__*/ $constructor("$ZodIntersection", (inst, def) => {
18372
+ $ZodType.init(inst, def);
18373
+ inst._zod.parse = (payload, ctx) => {
18374
+ const input = payload.value;
18375
+ const left = def.left._zod.run({ value: input, issues: [] }, ctx);
18376
+ const right = def.right._zod.run({ value: input, issues: [] }, ctx);
18377
+ const async = left instanceof Promise || right instanceof Promise;
18378
+ if (async) {
18379
+ return Promise.all([left, right]).then(([left, right]) => {
18380
+ return handleIntersectionResults(payload, left, right);
18381
+ });
18382
+ }
18383
+ return handleIntersectionResults(payload, left, right);
18384
+ };
18385
+ });
18386
+ function mergeValues(a, b) {
18387
+ // const aType = parse.t(a);
18388
+ // const bType = parse.t(b);
18389
+ if (a === b) {
18390
+ return { valid: true, data: a };
18391
+ }
18392
+ if (a instanceof Date && b instanceof Date && +a === +b) {
18393
+ return { valid: true, data: a };
18394
+ }
18395
+ if (isPlainObject(a) && isPlainObject(b)) {
18396
+ const bKeys = Object.keys(b);
18397
+ const sharedKeys = Object.keys(a).filter((key) => bKeys.indexOf(key) !== -1);
18398
+ const newObj = { ...a, ...b };
18399
+ for (const key of sharedKeys) {
18400
+ const sharedValue = mergeValues(a[key], b[key]);
18401
+ if (!sharedValue.valid) {
18402
+ return {
18403
+ valid: false,
18404
+ mergeErrorPath: [key, ...sharedValue.mergeErrorPath],
18405
+ };
18406
+ }
18407
+ newObj[key] = sharedValue.data;
18408
+ }
18409
+ return { valid: true, data: newObj };
18410
+ }
18411
+ if (Array.isArray(a) && Array.isArray(b)) {
18412
+ if (a.length !== b.length) {
18413
+ return { valid: false, mergeErrorPath: [] };
18414
+ }
18415
+ const newArray = [];
18416
+ for (let index = 0; index < a.length; index++) {
18417
+ const itemA = a[index];
18418
+ const itemB = b[index];
18419
+ const sharedValue = mergeValues(itemA, itemB);
18420
+ if (!sharedValue.valid) {
18421
+ return {
18422
+ valid: false,
18423
+ mergeErrorPath: [index, ...sharedValue.mergeErrorPath],
18424
+ };
18425
+ }
18426
+ newArray.push(sharedValue.data);
18427
+ }
18428
+ return { valid: true, data: newArray };
18429
+ }
18430
+ return { valid: false, mergeErrorPath: [] };
18431
+ }
18432
+ function handleIntersectionResults(result, left, right) {
18433
+ if (left.issues.length) {
18434
+ result.issues.push(...left.issues);
18435
+ }
18436
+ if (right.issues.length) {
18437
+ result.issues.push(...right.issues);
18438
+ }
18439
+ if (aborted(result))
18440
+ return result;
18441
+ const merged = mergeValues(left.value, right.value);
18442
+ if (!merged.valid) {
18443
+ throw new Error(`Unmergable intersection. Error path: ` + `${JSON.stringify(merged.mergeErrorPath)}`);
18444
+ }
18445
+ result.value = merged.data;
18446
+ return result;
18447
+ }
18448
+ const $ZodTransform = /*@__PURE__*/ $constructor("$ZodTransform", (inst, def) => {
18449
+ $ZodType.init(inst, def);
18450
+ inst._zod.parse = (payload, _ctx) => {
18451
+ const _out = def.transform(payload.value, payload);
18452
+ if (_ctx.async) {
18453
+ const output = _out instanceof Promise ? _out : Promise.resolve(_out);
18454
+ return output.then((output) => {
18455
+ payload.value = output;
18456
+ return payload;
18457
+ });
18458
+ }
18459
+ if (_out instanceof Promise) {
18460
+ throw new $ZodAsyncError();
18461
+ }
18462
+ payload.value = _out;
18463
+ return payload;
18464
+ };
18465
+ });
18466
+ function handleOptionalResult(result, input) {
18467
+ if (result.issues.length && input === undefined) {
18468
+ return { issues: [], value: undefined };
18469
+ }
18470
+ return result;
18471
+ }
18472
+ const $ZodOptional = /*@__PURE__*/ $constructor("$ZodOptional", (inst, def) => {
18473
+ $ZodType.init(inst, def);
18474
+ inst._zod.optin = "optional";
18475
+ inst._zod.optout = "optional";
18476
+ defineLazy(inst._zod, "values", () => {
18477
+ return def.innerType._zod.values ? new Set([...def.innerType._zod.values, undefined]) : undefined;
18478
+ });
18479
+ defineLazy(inst._zod, "pattern", () => {
18480
+ const pattern = def.innerType._zod.pattern;
18481
+ return pattern ? new RegExp(`^(${cleanRegex(pattern.source)})?$`) : undefined;
18482
+ });
18483
+ inst._zod.parse = (payload, ctx) => {
18484
+ if (def.innerType._zod.optin === "optional") {
18485
+ const result = def.innerType._zod.run(payload, ctx);
18486
+ if (result instanceof Promise)
18487
+ return result.then((r) => handleOptionalResult(r, payload.value));
18488
+ return handleOptionalResult(result, payload.value);
18489
+ }
18490
+ if (payload.value === undefined) {
18491
+ return payload;
18492
+ }
18493
+ return def.innerType._zod.run(payload, ctx);
18494
+ };
18495
+ });
18496
+ const $ZodNullable = /*@__PURE__*/ $constructor("$ZodNullable", (inst, def) => {
18497
+ $ZodType.init(inst, def);
18498
+ defineLazy(inst._zod, "optin", () => def.innerType._zod.optin);
18499
+ defineLazy(inst._zod, "optout", () => def.innerType._zod.optout);
18500
+ defineLazy(inst._zod, "pattern", () => {
18501
+ const pattern = def.innerType._zod.pattern;
18502
+ return pattern ? new RegExp(`^(${cleanRegex(pattern.source)}|null)$`) : undefined;
18503
+ });
18504
+ defineLazy(inst._zod, "values", () => {
18505
+ return def.innerType._zod.values ? new Set([...def.innerType._zod.values, null]) : undefined;
18506
+ });
18507
+ inst._zod.parse = (payload, ctx) => {
18508
+ if (payload.value === null)
18509
+ return payload;
18510
+ return def.innerType._zod.run(payload, ctx);
18511
+ };
18512
+ });
18513
+ const $ZodDefault = /*@__PURE__*/ $constructor("$ZodDefault", (inst, def) => {
18514
+ $ZodType.init(inst, def);
18515
+ // inst._zod.qin = "true";
18516
+ inst._zod.optin = "optional";
18517
+ defineLazy(inst._zod, "values", () => def.innerType._zod.values);
18518
+ inst._zod.parse = (payload, ctx) => {
18519
+ if (payload.value === undefined) {
18520
+ payload.value = def.defaultValue;
18521
+ /**
18522
+ * $ZodDefault always returns the default value immediately.
18523
+ * It doesn't pass the default value into the validator ("prefault"). There's no reason to pass the default value through validation. The validity of the default is enforced by TypeScript statically. Otherwise, it's the responsibility of the user to ensure the default is valid. In the case of pipes with divergent in/out types, you can specify the default on the `in` schema of your ZodPipe to set a "prefault" for the pipe. */
18524
+ return payload;
18525
+ }
18526
+ const result = def.innerType._zod.run(payload, ctx);
18527
+ if (result instanceof Promise) {
18528
+ return result.then((result) => handleDefaultResult(result, def));
18529
+ }
18530
+ return handleDefaultResult(result, def);
18531
+ };
18532
+ });
18533
+ function handleDefaultResult(payload, def) {
18534
+ if (payload.value === undefined) {
18535
+ payload.value = def.defaultValue;
18536
+ }
18537
+ return payload;
18538
+ }
18539
+ const $ZodPrefault = /*@__PURE__*/ $constructor("$ZodPrefault", (inst, def) => {
18540
+ $ZodType.init(inst, def);
18541
+ inst._zod.optin = "optional";
18542
+ defineLazy(inst._zod, "values", () => def.innerType._zod.values);
18543
+ inst._zod.parse = (payload, ctx) => {
18544
+ if (payload.value === undefined) {
18545
+ payload.value = def.defaultValue;
18546
+ }
18547
+ return def.innerType._zod.run(payload, ctx);
18548
+ };
18549
+ });
18550
+ const $ZodNonOptional = /*@__PURE__*/ $constructor("$ZodNonOptional", (inst, def) => {
18551
+ $ZodType.init(inst, def);
18552
+ defineLazy(inst._zod, "values", () => {
18553
+ const v = def.innerType._zod.values;
18554
+ return v ? new Set([...v].filter((x) => x !== undefined)) : undefined;
18555
+ });
18556
+ inst._zod.parse = (payload, ctx) => {
18557
+ const result = def.innerType._zod.run(payload, ctx);
18558
+ if (result instanceof Promise) {
18559
+ return result.then((result) => handleNonOptionalResult(result, inst));
18560
+ }
18561
+ return handleNonOptionalResult(result, inst);
18562
+ };
18563
+ });
18564
+ function handleNonOptionalResult(payload, inst) {
18565
+ if (!payload.issues.length && payload.value === undefined) {
18566
+ payload.issues.push({
18567
+ code: "invalid_type",
18568
+ expected: "nonoptional",
18569
+ input: payload.value,
18570
+ inst,
18571
+ });
18572
+ }
18573
+ return payload;
18574
+ }
18575
+ const $ZodCatch = /*@__PURE__*/ $constructor("$ZodCatch", (inst, def) => {
18576
+ $ZodType.init(inst, def);
18577
+ defineLazy(inst._zod, "optin", () => def.innerType._zod.optin);
18578
+ defineLazy(inst._zod, "optout", () => def.innerType._zod.optout);
18579
+ defineLazy(inst._zod, "values", () => def.innerType._zod.values);
18580
+ inst._zod.parse = (payload, ctx) => {
18581
+ const result = def.innerType._zod.run(payload, ctx);
18582
+ if (result instanceof Promise) {
18583
+ return result.then((result) => {
18584
+ payload.value = result.value;
18585
+ if (result.issues.length) {
18586
+ payload.value = def.catchValue({
18587
+ ...payload,
18588
+ error: {
18589
+ issues: result.issues.map((iss) => finalizeIssue(iss, ctx, config())),
18590
+ },
18591
+ input: payload.value,
18592
+ });
18593
+ payload.issues = [];
18594
+ }
18595
+ return payload;
18596
+ });
18597
+ }
18598
+ payload.value = result.value;
18599
+ if (result.issues.length) {
18600
+ payload.value = def.catchValue({
18601
+ ...payload,
18602
+ error: {
18603
+ issues: result.issues.map((iss) => finalizeIssue(iss, ctx, config())),
18604
+ },
18605
+ input: payload.value,
18606
+ });
18607
+ payload.issues = [];
18608
+ }
18609
+ return payload;
18610
+ };
18611
+ });
18612
+ const $ZodPipe = /*@__PURE__*/ $constructor("$ZodPipe", (inst, def) => {
18613
+ $ZodType.init(inst, def);
18614
+ defineLazy(inst._zod, "values", () => def.in._zod.values);
18615
+ defineLazy(inst._zod, "optin", () => def.in._zod.optin);
18616
+ defineLazy(inst._zod, "optout", () => def.out._zod.optout);
18617
+ defineLazy(inst._zod, "propValues", () => def.in._zod.propValues);
18618
+ inst._zod.parse = (payload, ctx) => {
18619
+ const left = def.in._zod.run(payload, ctx);
18620
+ if (left instanceof Promise) {
18621
+ return left.then((left) => handlePipeResult(left, def, ctx));
18622
+ }
18623
+ return handlePipeResult(left, def, ctx);
18624
+ };
18625
+ });
18626
+ function handlePipeResult(left, def, ctx) {
18627
+ if (left.issues.length) {
18628
+ return left;
18629
+ }
18630
+ return def.out._zod.run({ value: left.value, issues: left.issues }, ctx);
18631
+ }
18632
+ const $ZodReadonly = /*@__PURE__*/ $constructor("$ZodReadonly", (inst, def) => {
18633
+ $ZodType.init(inst, def);
18634
+ defineLazy(inst._zod, "propValues", () => def.innerType._zod.propValues);
18635
+ defineLazy(inst._zod, "values", () => def.innerType._zod.values);
18636
+ defineLazy(inst._zod, "optin", () => def.innerType._zod.optin);
18637
+ defineLazy(inst._zod, "optout", () => def.innerType._zod.optout);
18638
+ inst._zod.parse = (payload, ctx) => {
18639
+ const result = def.innerType._zod.run(payload, ctx);
18640
+ if (result instanceof Promise) {
18641
+ return result.then(handleReadonlyResult);
18642
+ }
18643
+ return handleReadonlyResult(result);
18644
+ };
18645
+ });
18646
+ function handleReadonlyResult(payload) {
18647
+ payload.value = Object.freeze(payload.value);
18648
+ return payload;
18649
+ }
18650
+ const $ZodCustom = /*@__PURE__*/ $constructor("$ZodCustom", (inst, def) => {
18651
+ $ZodCheck.init(inst, def);
18652
+ $ZodType.init(inst, def);
18653
+ inst._zod.parse = (payload, _) => {
18654
+ return payload;
18655
+ };
18656
+ inst._zod.check = (payload) => {
18657
+ const input = payload.value;
18658
+ const r = def.fn(input);
18659
+ if (r instanceof Promise) {
18660
+ return r.then((r) => handleRefineResult(r, payload, input, inst));
18661
+ }
18662
+ handleRefineResult(r, payload, input, inst);
18663
+ return;
18664
+ };
18665
+ });
18666
+ function handleRefineResult(result, payload, input, inst) {
18667
+ if (!result) {
18668
+ const _iss = {
18669
+ code: "custom",
18670
+ input,
18671
+ inst, // incorporates params.error into issue reporting
18672
+ path: [...(inst._zod.def.path ?? [])], // incorporates params.error into issue reporting
18673
+ continue: !inst._zod.def.abort,
18674
+ // params: inst._zod.def.params,
18675
+ };
18676
+ if (inst._zod.def.params)
18677
+ _iss.params = inst._zod.def.params;
18678
+ payload.issues.push(issue(_iss));
18679
+ }
18680
+ }
18681
+
18682
+ class $ZodRegistry {
18683
+ constructor() {
18684
+ this._map = new Map();
18685
+ this._idmap = new Map();
18686
+ }
18687
+ add(schema, ..._meta) {
18688
+ const meta = _meta[0];
18689
+ this._map.set(schema, meta);
18690
+ if (meta && typeof meta === "object" && "id" in meta) {
18691
+ if (this._idmap.has(meta.id)) {
18692
+ throw new Error(`ID ${meta.id} already exists in the registry`);
18693
+ }
18694
+ this._idmap.set(meta.id, schema);
18695
+ }
18696
+ return this;
18697
+ }
18698
+ clear() {
18699
+ this._map = new Map();
18700
+ this._idmap = new Map();
18701
+ return this;
18702
+ }
18703
+ remove(schema) {
18704
+ const meta = this._map.get(schema);
18705
+ if (meta && typeof meta === "object" && "id" in meta) {
18706
+ this._idmap.delete(meta.id);
18707
+ }
18708
+ this._map.delete(schema);
18709
+ return this;
18710
+ }
18711
+ get(schema) {
18712
+ // return this._map.get(schema) as any;
18713
+ // inherit metadata
18714
+ const p = schema._zod.parent;
18715
+ if (p) {
18716
+ const pm = { ...(this.get(p) ?? {}) };
18717
+ delete pm.id; // do not inherit id
18718
+ const f = { ...pm, ...this._map.get(schema) };
18719
+ return Object.keys(f).length ? f : undefined;
18720
+ }
18721
+ return this._map.get(schema);
18722
+ }
18723
+ has(schema) {
18724
+ return this._map.has(schema);
18725
+ }
18726
+ }
18727
+ // registries
18728
+ function registry() {
18729
+ return new $ZodRegistry();
18730
+ }
18731
+ const globalRegistry = /*@__PURE__*/ registry();
18732
+
18733
+ function _uuid(Class, params) {
18734
+ return new Class({
18735
+ type: "string",
18736
+ format: "uuid",
18737
+ check: "string_format",
18738
+ abort: false,
18739
+ ...normalizeParams(params),
18740
+ });
18741
+ }
18742
+ function _maxLength(maximum, params) {
18743
+ const ch = new $ZodCheckMaxLength({
18744
+ check: "max_length",
18745
+ ...normalizeParams(params),
18746
+ maximum,
18747
+ });
18748
+ return ch;
18749
+ }
18750
+ function _minLength(minimum, params) {
18751
+ return new $ZodCheckMinLength({
18752
+ check: "min_length",
18753
+ ...normalizeParams(params),
18754
+ minimum,
18755
+ });
18756
+ }
18757
+ function _length(length, params) {
18758
+ return new $ZodCheckLengthEquals({
18759
+ check: "length_equals",
18760
+ ...normalizeParams(params),
18761
+ length,
18762
+ });
18763
+ }
18764
+ function _regex(pattern, params) {
18765
+ return new $ZodCheckRegex({
18766
+ check: "string_format",
18767
+ format: "regex",
18768
+ ...normalizeParams(params),
18769
+ pattern,
18770
+ });
18771
+ }
18772
+ function _lowercase(params) {
18773
+ return new $ZodCheckLowerCase({
18774
+ check: "string_format",
18775
+ format: "lowercase",
18776
+ ...normalizeParams(params),
18777
+ });
18778
+ }
18779
+ function _uppercase(params) {
18780
+ return new $ZodCheckUpperCase({
18781
+ check: "string_format",
18782
+ format: "uppercase",
18783
+ ...normalizeParams(params),
18784
+ });
18785
+ }
18786
+ function _includes(includes, params) {
18787
+ return new $ZodCheckIncludes({
18788
+ check: "string_format",
18789
+ format: "includes",
18790
+ ...normalizeParams(params),
18791
+ includes,
18792
+ });
18793
+ }
18794
+ function _startsWith(prefix, params) {
18795
+ return new $ZodCheckStartsWith({
18796
+ check: "string_format",
18797
+ format: "starts_with",
18798
+ ...normalizeParams(params),
18799
+ prefix,
18800
+ });
18801
+ }
18802
+ function _endsWith(suffix, params) {
18803
+ return new $ZodCheckEndsWith({
18804
+ check: "string_format",
18805
+ format: "ends_with",
18806
+ ...normalizeParams(params),
18807
+ suffix,
18808
+ });
18809
+ }
18810
+ function _overwrite(tx) {
18811
+ return new $ZodCheckOverwrite({
18812
+ check: "overwrite",
18813
+ tx,
18814
+ });
18815
+ }
18816
+ // normalize
18817
+ function _normalize(form) {
18818
+ return _overwrite((input) => input.normalize(form));
18819
+ }
18820
+ // trim
18821
+ function _trim() {
18822
+ return _overwrite((input) => input.trim());
18823
+ }
18824
+ // toLowerCase
18825
+ function _toLowerCase() {
18826
+ return _overwrite((input) => input.toLowerCase());
18827
+ }
18828
+ // toUpperCase
18829
+ function _toUpperCase() {
18830
+ return _overwrite((input) => input.toUpperCase());
18831
+ }
18832
+ function _array(Class, element, params) {
18833
+ return new Class({
18834
+ type: "array",
18835
+ element,
18836
+ // get element() {
18837
+ // return element;
18838
+ // },
18839
+ ...normalizeParams(params),
18840
+ });
18841
+ }
18842
+ // same as _custom but defaults to abort:false
18843
+ function _refine(Class, fn, _params) {
18844
+ const schema = new Class({
18845
+ type: "custom",
18846
+ check: "custom",
18847
+ fn: fn,
18848
+ ...normalizeParams(_params),
18849
+ });
18850
+ return schema;
18851
+ }
18852
+ function _superRefine(fn) {
18853
+ const ch = _check((payload) => {
18854
+ payload.addIssue = (issue$1) => {
18855
+ if (typeof issue$1 === "string") {
18856
+ payload.issues.push(issue(issue$1, payload.value, ch._zod.def));
18857
+ }
18858
+ else {
18859
+ // for Zod 3 backwards compatibility
18860
+ const _issue = issue$1;
18861
+ if (_issue.fatal)
18862
+ _issue.continue = false;
18863
+ _issue.code ?? (_issue.code = "custom");
18864
+ _issue.input ?? (_issue.input = payload.value);
18865
+ _issue.inst ?? (_issue.inst = ch);
18866
+ _issue.continue ?? (_issue.continue = !ch._zod.def.abort);
18867
+ payload.issues.push(issue(_issue));
18868
+ }
18869
+ };
18870
+ return fn(payload.value, payload);
18871
+ });
18872
+ return ch;
18873
+ }
18874
+ function _check(fn, params) {
18875
+ const ch = new $ZodCheck({
18876
+ check: "custom",
18877
+ ...normalizeParams(params),
18878
+ });
18879
+ ch._zod.check = fn;
18880
+ return ch;
18881
+ }
18882
+
18883
+ const initializer = (inst, issues) => {
18884
+ $ZodError.init(inst, issues);
18885
+ inst.name = "ZodError";
18886
+ Object.defineProperties(inst, {
18887
+ format: {
18888
+ value: (mapper) => formatError(inst, mapper),
18889
+ // enumerable: false,
18890
+ },
18891
+ flatten: {
18892
+ value: (mapper) => flattenError(inst, mapper),
18893
+ // enumerable: false,
18894
+ },
18895
+ addIssue: {
18896
+ value: (issue) => {
18897
+ inst.issues.push(issue);
18898
+ inst.message = JSON.stringify(inst.issues, jsonStringifyReplacer, 2);
18899
+ },
18900
+ // enumerable: false,
18901
+ },
18902
+ addIssues: {
18903
+ value: (issues) => {
18904
+ inst.issues.push(...issues);
18905
+ inst.message = JSON.stringify(inst.issues, jsonStringifyReplacer, 2);
18906
+ },
18907
+ // enumerable: false,
18908
+ },
18909
+ isEmpty: {
18910
+ get() {
18911
+ return inst.issues.length === 0;
18912
+ },
18913
+ // enumerable: false,
18914
+ },
18915
+ });
18916
+ // Object.defineProperty(inst, "isEmpty", {
18917
+ // get() {
18918
+ // return inst.issues.length === 0;
18919
+ // },
18920
+ // });
18921
+ };
18922
+ const ZodRealError = $constructor("ZodError", initializer, {
18923
+ Parent: Error,
18924
+ });
18925
+ // /** @deprecated Use `z.core.$ZodErrorMapCtx` instead. */
18926
+ // export type ErrorMapCtx = core.$ZodErrorMapCtx;
18927
+
18928
+ const parse = /* @__PURE__ */ _parse(ZodRealError);
18929
+ const parseAsync = /* @__PURE__ */ _parseAsync(ZodRealError);
18930
+ const safeParse = /* @__PURE__ */ _safeParse(ZodRealError);
18931
+ const safeParseAsync = /* @__PURE__ */ _safeParseAsync(ZodRealError);
18932
+
18933
+ const ZodType = /*@__PURE__*/ $constructor("ZodType", (inst, def) => {
18934
+ $ZodType.init(inst, def);
18935
+ inst.def = def;
18936
+ Object.defineProperty(inst, "_def", { value: def });
18937
+ // base methods
18938
+ inst.check = (...checks) => {
18939
+ return inst.clone({
18940
+ ...def,
18941
+ checks: [
18942
+ ...(def.checks ?? []),
18943
+ ...checks.map((ch) => typeof ch === "function" ? { _zod: { check: ch, def: { check: "custom" }, onattach: [] } } : ch),
18944
+ ],
18945
+ }
18946
+ // { parent: true }
18947
+ );
18948
+ };
18949
+ inst.clone = (def, params) => clone(inst, def, params);
18950
+ inst.brand = () => inst;
18951
+ inst.register = ((reg, meta) => {
18952
+ reg.add(inst, meta);
18953
+ return inst;
18954
+ });
18955
+ // parsing
18956
+ inst.parse = (data, params) => parse(inst, data, params, { callee: inst.parse });
18957
+ inst.safeParse = (data, params) => safeParse(inst, data, params);
18958
+ inst.parseAsync = async (data, params) => parseAsync(inst, data, params, { callee: inst.parseAsync });
18959
+ inst.safeParseAsync = async (data, params) => safeParseAsync(inst, data, params);
18960
+ inst.spa = inst.safeParseAsync;
18961
+ // refinements
18962
+ inst.refine = (check, params) => inst.check(refine(check, params));
18963
+ inst.superRefine = (refinement) => inst.check(superRefine(refinement));
18964
+ inst.overwrite = (fn) => inst.check(_overwrite(fn));
18965
+ // wrappers
18966
+ inst.optional = () => optional(inst);
18967
+ inst.nullable = () => nullable(inst);
18968
+ inst.nullish = () => optional(nullable(inst));
18969
+ inst.nonoptional = (params) => nonoptional(inst, params);
18970
+ inst.array = () => array(inst);
18971
+ inst.or = (arg) => union([inst, arg]);
18972
+ inst.and = (arg) => intersection(inst, arg);
18973
+ inst.transform = (tx) => pipe(inst, transform(tx));
18974
+ inst.default = (def) => _default(inst, def);
18975
+ inst.prefault = (def) => prefault(inst, def);
18976
+ // inst.coalesce = (def, params) => coalesce(inst, def, params);
18977
+ inst.catch = (params) => _catch(inst, params);
18978
+ inst.pipe = (target) => pipe(inst, target);
18979
+ inst.readonly = () => readonly(inst);
18980
+ // meta
18981
+ inst.describe = (description) => {
18982
+ const cl = inst.clone();
18983
+ globalRegistry.add(cl, { description });
18984
+ return cl;
18985
+ };
18986
+ Object.defineProperty(inst, "description", {
18987
+ get() {
18988
+ return globalRegistry.get(inst)?.description;
18989
+ },
18990
+ configurable: true,
18991
+ });
18992
+ inst.meta = (...args) => {
18993
+ if (args.length === 0) {
18994
+ return globalRegistry.get(inst);
18995
+ }
18996
+ const cl = inst.clone();
18997
+ globalRegistry.add(cl, args[0]);
18998
+ return cl;
18999
+ };
19000
+ // helpers
19001
+ inst.isOptional = () => inst.safeParse(undefined).success;
19002
+ inst.isNullable = () => inst.safeParse(null).success;
19003
+ return inst;
19004
+ });
19005
+ /** @internal */
19006
+ const _ZodString = /*@__PURE__*/ $constructor("_ZodString", (inst, def) => {
19007
+ $ZodString.init(inst, def);
19008
+ ZodType.init(inst, def);
19009
+ const bag = inst._zod.bag;
19010
+ inst.format = bag.format ?? null;
19011
+ inst.minLength = bag.minimum ?? null;
19012
+ inst.maxLength = bag.maximum ?? null;
19013
+ // validations
19014
+ inst.regex = (...args) => inst.check(_regex(...args));
19015
+ inst.includes = (...args) => inst.check(_includes(...args));
19016
+ inst.startsWith = (...args) => inst.check(_startsWith(...args));
19017
+ inst.endsWith = (...args) => inst.check(_endsWith(...args));
19018
+ inst.min = (...args) => inst.check(_minLength(...args));
19019
+ inst.max = (...args) => inst.check(_maxLength(...args));
19020
+ inst.length = (...args) => inst.check(_length(...args));
19021
+ inst.nonempty = (...args) => inst.check(_minLength(1, ...args));
19022
+ inst.lowercase = (params) => inst.check(_lowercase(params));
19023
+ inst.uppercase = (params) => inst.check(_uppercase(params));
19024
+ // transforms
19025
+ inst.trim = () => inst.check(_trim());
19026
+ inst.normalize = (...args) => inst.check(_normalize(...args));
19027
+ inst.toLowerCase = () => inst.check(_toLowerCase());
19028
+ inst.toUpperCase = () => inst.check(_toUpperCase());
19029
+ });
19030
+ const ZodStringFormat = /*@__PURE__*/ $constructor("ZodStringFormat", (inst, def) => {
19031
+ $ZodStringFormat.init(inst, def);
19032
+ _ZodString.init(inst, def);
19033
+ });
19034
+ const ZodUUID = /*@__PURE__*/ $constructor("ZodUUID", (inst, def) => {
19035
+ // ZodStringFormat.init(inst, def);
19036
+ $ZodUUID.init(inst, def);
19037
+ ZodStringFormat.init(inst, def);
19038
+ });
19039
+ function uuid(params) {
19040
+ return _uuid(ZodUUID, params);
19041
+ }
19042
+ const ZodArray = /*@__PURE__*/ $constructor("ZodArray", (inst, def) => {
19043
+ $ZodArray.init(inst, def);
19044
+ ZodType.init(inst, def);
19045
+ inst.element = def.element;
19046
+ inst.min = (minLength, params) => inst.check(_minLength(minLength, params));
19047
+ inst.nonempty = (params) => inst.check(_minLength(1, params));
19048
+ inst.max = (maxLength, params) => inst.check(_maxLength(maxLength, params));
19049
+ inst.length = (len, params) => inst.check(_length(len, params));
19050
+ inst.unwrap = () => inst.element;
19051
+ });
19052
+ function array(element, params) {
19053
+ return _array(ZodArray, element, params);
19054
+ }
19055
+ const ZodUnion = /*@__PURE__*/ $constructor("ZodUnion", (inst, def) => {
19056
+ $ZodUnion.init(inst, def);
19057
+ ZodType.init(inst, def);
19058
+ inst.options = def.options;
19059
+ });
19060
+ function union(options, params) {
19061
+ return new ZodUnion({
19062
+ type: "union",
19063
+ options: options,
19064
+ ...normalizeParams(params),
19065
+ });
19066
+ }
19067
+ const ZodIntersection = /*@__PURE__*/ $constructor("ZodIntersection", (inst, def) => {
19068
+ $ZodIntersection.init(inst, def);
19069
+ ZodType.init(inst, def);
19070
+ });
19071
+ function intersection(left, right) {
19072
+ return new ZodIntersection({
19073
+ type: "intersection",
19074
+ left: left,
19075
+ right: right,
19076
+ });
19077
+ }
19078
+ const ZodTransform = /*@__PURE__*/ $constructor("ZodTransform", (inst, def) => {
19079
+ $ZodTransform.init(inst, def);
19080
+ ZodType.init(inst, def);
19081
+ inst._zod.parse = (payload, _ctx) => {
19082
+ payload.addIssue = (issue$1) => {
19083
+ if (typeof issue$1 === "string") {
19084
+ payload.issues.push(issue(issue$1, payload.value, def));
19085
+ }
19086
+ else {
19087
+ // for Zod 3 backwards compatibility
19088
+ const _issue = issue$1;
19089
+ if (_issue.fatal)
19090
+ _issue.continue = false;
19091
+ _issue.code ?? (_issue.code = "custom");
19092
+ _issue.input ?? (_issue.input = payload.value);
19093
+ _issue.inst ?? (_issue.inst = inst);
19094
+ // _issue.continue ??= true;
19095
+ payload.issues.push(issue(_issue));
19096
+ }
19097
+ };
19098
+ const output = def.transform(payload.value, payload);
19099
+ if (output instanceof Promise) {
19100
+ return output.then((output) => {
19101
+ payload.value = output;
19102
+ return payload;
19103
+ });
19104
+ }
19105
+ payload.value = output;
19106
+ return payload;
19107
+ };
19108
+ });
19109
+ function transform(fn) {
19110
+ return new ZodTransform({
19111
+ type: "transform",
19112
+ transform: fn,
19113
+ });
19114
+ }
19115
+ const ZodOptional = /*@__PURE__*/ $constructor("ZodOptional", (inst, def) => {
19116
+ $ZodOptional.init(inst, def);
19117
+ ZodType.init(inst, def);
19118
+ inst.unwrap = () => inst._zod.def.innerType;
19119
+ });
19120
+ function optional(innerType) {
19121
+ return new ZodOptional({
19122
+ type: "optional",
19123
+ innerType: innerType,
19124
+ });
19125
+ }
19126
+ const ZodNullable = /*@__PURE__*/ $constructor("ZodNullable", (inst, def) => {
19127
+ $ZodNullable.init(inst, def);
19128
+ ZodType.init(inst, def);
19129
+ inst.unwrap = () => inst._zod.def.innerType;
19130
+ });
19131
+ function nullable(innerType) {
19132
+ return new ZodNullable({
19133
+ type: "nullable",
19134
+ innerType: innerType,
19135
+ });
19136
+ }
19137
+ const ZodDefault = /*@__PURE__*/ $constructor("ZodDefault", (inst, def) => {
19138
+ $ZodDefault.init(inst, def);
19139
+ ZodType.init(inst, def);
19140
+ inst.unwrap = () => inst._zod.def.innerType;
19141
+ inst.removeDefault = inst.unwrap;
19142
+ });
19143
+ function _default(innerType, defaultValue) {
19144
+ return new ZodDefault({
19145
+ type: "default",
19146
+ innerType: innerType,
19147
+ get defaultValue() {
19148
+ return typeof defaultValue === "function" ? defaultValue() : shallowClone(defaultValue);
19149
+ },
19150
+ });
19151
+ }
19152
+ const ZodPrefault = /*@__PURE__*/ $constructor("ZodPrefault", (inst, def) => {
19153
+ $ZodPrefault.init(inst, def);
19154
+ ZodType.init(inst, def);
19155
+ inst.unwrap = () => inst._zod.def.innerType;
19156
+ });
19157
+ function prefault(innerType, defaultValue) {
19158
+ return new ZodPrefault({
19159
+ type: "prefault",
19160
+ innerType: innerType,
19161
+ get defaultValue() {
19162
+ return typeof defaultValue === "function" ? defaultValue() : shallowClone(defaultValue);
19163
+ },
19164
+ });
19165
+ }
19166
+ const ZodNonOptional = /*@__PURE__*/ $constructor("ZodNonOptional", (inst, def) => {
19167
+ $ZodNonOptional.init(inst, def);
19168
+ ZodType.init(inst, def);
19169
+ inst.unwrap = () => inst._zod.def.innerType;
19170
+ });
19171
+ function nonoptional(innerType, params) {
19172
+ return new ZodNonOptional({
19173
+ type: "nonoptional",
19174
+ innerType: innerType,
19175
+ ...normalizeParams(params),
19176
+ });
19177
+ }
19178
+ const ZodCatch = /*@__PURE__*/ $constructor("ZodCatch", (inst, def) => {
19179
+ $ZodCatch.init(inst, def);
19180
+ ZodType.init(inst, def);
19181
+ inst.unwrap = () => inst._zod.def.innerType;
19182
+ inst.removeCatch = inst.unwrap;
19183
+ });
19184
+ function _catch(innerType, catchValue) {
19185
+ return new ZodCatch({
19186
+ type: "catch",
19187
+ innerType: innerType,
19188
+ catchValue: (typeof catchValue === "function" ? catchValue : () => catchValue),
19189
+ });
19190
+ }
19191
+ const ZodPipe = /*@__PURE__*/ $constructor("ZodPipe", (inst, def) => {
19192
+ $ZodPipe.init(inst, def);
19193
+ ZodType.init(inst, def);
19194
+ inst.in = def.in;
19195
+ inst.out = def.out;
19196
+ });
19197
+ function pipe(in_, out) {
19198
+ return new ZodPipe({
19199
+ type: "pipe",
19200
+ in: in_,
19201
+ out: out,
19202
+ // ...util.normalizeParams(params),
19203
+ });
19204
+ }
19205
+ const ZodReadonly = /*@__PURE__*/ $constructor("ZodReadonly", (inst, def) => {
19206
+ $ZodReadonly.init(inst, def);
19207
+ ZodType.init(inst, def);
19208
+ inst.unwrap = () => inst._zod.def.innerType;
19209
+ });
19210
+ function readonly(innerType) {
19211
+ return new ZodReadonly({
19212
+ type: "readonly",
19213
+ innerType: innerType,
19214
+ });
19215
+ }
19216
+ const ZodCustom = /*@__PURE__*/ $constructor("ZodCustom", (inst, def) => {
19217
+ $ZodCustom.init(inst, def);
19218
+ ZodType.init(inst, def);
19219
+ });
19220
+ function refine(fn, _params = {}) {
19221
+ return _refine(ZodCustom, fn, _params);
19222
+ }
19223
+ // superRefine
19224
+ function superRefine(fn) {
19225
+ return _superRefine(fn);
19226
+ }
19227
+
19228
+ var GuidSchema = uuid("appCode must be a valid GUID");
19229
+ var CAMSContext = React__default.createContext(null);
17496
19230
  var setCookie = function (name, value, days) {
17497
- var expires = new Date(Date.now() + days * 864e5).toUTCString();
19231
+ var expires = new Date(Date.now() + days * 24 * 60 * 60 * 1000).toUTCString();
17498
19232
  document.cookie = "".concat(name, "=").concat(encodeURIComponent(value), "; expires=").concat(expires, "; path=/; samesite=Lax");
17499
19233
  };
17500
19234
  var getCookie = function (name) {
@@ -17511,24 +19245,19 @@ var getCookie = function (name) {
17511
19245
  var deleteCookie = function (name) {
17512
19246
  document.cookie = name + "=; Max-Age=-99999999; path=/";
17513
19247
  };
17514
- var isTokenValid = function (token) {
17515
- try {
17516
- var payload = JSON.parse(atob(token.split(".")[1]));
17517
- return payload.exp * 1000 > Date.now();
17518
- }
17519
- catch (_a) {
17520
- return false;
17521
- }
17522
- };
17523
- function CAMSMSALProviderInner(_a) {
19248
+ function CAMSProviderInner(props) {
17524
19249
  var _this = this;
17525
- var children = _a.children, authOptions = __rest(_a, ["children"]);
17526
- var auth = useCAMSMSALAuth(authOptions);
19250
+ var children = props.children, mode = props.mode, appCode = props.appCode;
19251
+ // Always call both hooks to satisfy Rules of Hooks
19252
+ var regularAuth = useCAMSAuth(mode === "REGULAR"
19253
+ ? __assign(__assign({}, props), { appCode: appCode })
19254
+ : { appCode: "" });
19255
+ var msalAuth = useCAMSMSALAuth(mode === "MSAL" ? props : {});
19256
+ var auth = mode === "REGULAR" ? regularAuth : msalAuth;
17527
19257
  var profileStorageKey = "".concat(auth.storageKey, "-PROFILE");
17528
19258
  var getInitialProfile = function () {
17529
- if (typeof window === "undefined") {
19259
+ if (typeof window === "undefined")
17530
19260
  return null;
17531
- }
17532
19261
  try {
17533
19262
  var storedProfile = getCookie(profileStorageKey);
17534
19263
  return storedProfile ? JSON.parse(storedProfile) : null;
@@ -17537,11 +19266,9 @@ function CAMSMSALProviderInner(_a) {
17537
19266
  return null;
17538
19267
  }
17539
19268
  };
17540
- var _b = React__default.useState(getInitialProfile), userProfile = _b[0], setUserProfile = _b[1];
17541
- // Load profile from storage on mount
19269
+ var _a = React__default.useState(getInitialProfile), userProfile = _a[0], setUserProfile = _a[1];
17542
19270
  React__default.useEffect(function () {
17543
19271
  if (typeof window !== "undefined") {
17544
- // const storedProfile = localStorage.get Item(profileStorageKey);
17545
19272
  var storedProfile = getCookie(profileStorageKey);
17546
19273
  if (storedProfile) {
17547
19274
  try {
@@ -17551,30 +19278,16 @@ function CAMSMSALProviderInner(_a) {
17551
19278
  }
17552
19279
  }
17553
19280
  }, [profileStorageKey]);
17554
- // Persist tokens and profile
17555
- React__default.useEffect(function () {
17556
- if (auth.accessToken &&
17557
- isTokenValid(auth.accessToken) &&
17558
- typeof window !== "undefined") {
17559
- localStorage.setItem(auth.storageKey, JSON.stringify({
17560
- accessToken: auth.accessToken,
17561
- idToken: auth.idToken,
17562
- appCode: auth.appCode
17563
- }));
17564
- }
17565
- }, [auth.accessToken, auth.idToken, auth.storageKey]);
17566
- // Persist profile separately
17567
19281
  React__default.useEffect(function () {
17568
19282
  if (typeof window !== "undefined") {
17569
19283
  if (userProfile) {
17570
- setCookie(profileStorageKey, JSON.stringify(userProfile), 1); // Store for 1 day
19284
+ setCookie(profileStorageKey, JSON.stringify(userProfile), 1);
17571
19285
  }
17572
19286
  else {
17573
19287
  deleteCookie(profileStorageKey);
17574
19288
  }
17575
19289
  }
17576
19290
  }, [userProfile, profileStorageKey]);
17577
- // Enhanced logout that also clears profile
17578
19291
  var enhancedLogout = function () { return __awaiter(_this, void 0, void 0, function () {
17579
19292
  return __generator(this, function (_a) {
17580
19293
  switch (_a.label) {
@@ -17589,38 +19302,39 @@ function CAMSMSALProviderInner(_a) {
17589
19302
  }
17590
19303
  });
17591
19304
  }); };
17592
- var value = React__default.useMemo(function () { return (__assign(__assign({}, auth), { logout: enhancedLogout, userProfile: userProfile, setUserProfile: setUserProfile })); }, [auth, userProfile]);
17593
- return (jsxRuntimeExports.jsx(CAMSMSALContext.Provider, { value: value, children: children }));
19305
+ var value = React__default.useMemo(function () {
19306
+ return (__assign(__assign({}, auth), { logout: enhancedLogout, userProfile: userProfile, setUserProfile: setUserProfile, authMode: mode }));
19307
+ }, [auth, userProfile, mode]);
19308
+ return jsxRuntimeExports.jsx(CAMSContext.Provider, { value: value, children: children });
17594
19309
  }
17595
- function CAMSMSALProvider(props) {
17596
- var msalConfig = props.msalConfig, msalInstance = props.msalInstance;
17597
- var instance = msalInstance || new PublicClientApplication(msalConfig);
17598
- return (jsxRuntimeExports.jsx(MsalProvider, { instance: instance, children: jsxRuntimeExports.jsx(CAMSMSALProviderInner, __assign({}, props)) }));
19310
+ function UnifiedCAMSProvider(props) {
19311
+ // Validate appCode is a valid GUID
19312
+ var validationResult = GuidSchema.safeParse(props.appCode);
19313
+ if (!validationResult.success) {
19314
+ throw new Error("Invalid appCode: ".concat(validationResult.error.issues[0].message));
19315
+ }
19316
+ if (props.mode === "MSAL") {
19317
+ var msalConfig = props.msalConfig, msalInstance = props.msalInstance;
19318
+ var instance = msalInstance || new PublicClientApplication(msalConfig);
19319
+ return (jsxRuntimeExports.jsx(MsalProvider, { instance: instance, children: jsxRuntimeExports.jsx(CAMSProviderInner, __assign({}, props)) }));
19320
+ }
19321
+ return jsxRuntimeExports.jsx(CAMSProviderInner, __assign({}, props));
17599
19322
  }
17600
- function useCAMSMSALContext() {
17601
- var context = React__default.useContext(CAMSMSALContext);
19323
+ function useCAMSContext() {
19324
+ var context = React__default.useContext(CAMSContext);
17602
19325
  if (!context) {
17603
- throw new Error("useCAMSMSALContext must be used within a CAMSMSALProvider");
19326
+ throw new Error("useCAMSContext must be used within a UnifiedCAMSProvider");
17604
19327
  }
17605
19328
  return context;
17606
19329
  }
17607
-
17608
- function ClientOnly(_a) {
17609
- var children = _a.children, _b = _a.fallback, fallback = _b === void 0 ? null : _b;
17610
- var _c = React__default.useState(false), hasMounted = _c[0], setHasMounted = _c[1];
17611
- React__default.useEffect(function () {
17612
- setHasMounted(true);
17613
- }, []);
17614
- if (!hasMounted) {
17615
- return jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: fallback });
17616
- }
17617
- return jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: children });
17618
- }
19330
+ // Backward compatibility exports
19331
+ var CAMSProvider = function (props) { return (jsxRuntimeExports.jsx(UnifiedCAMSProvider, __assign({}, props, { mode: "REGULAR" }))); };
17619
19332
 
17620
19333
  exports.CAMSMSALProvider = CAMSMSALProvider;
17621
19334
  exports.CAMSProvider = CAMSProvider;
17622
19335
  exports.ClientOnly = ClientOnly;
17623
19336
  exports.ProtectedRoute = ProtectedRoute;
19337
+ exports.UnifiedCAMSProvider = UnifiedCAMSProvider;
17624
19338
  exports.useCAMSAuth = useCAMSAuth;
17625
19339
  exports.useCAMSContext = useCAMSContext;
17626
19340
  exports.useCAMSMSALAuth = useCAMSMSALAuth;