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

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