@nibssplc/cams-sdk-react 0.0.1-beta.79 → 0.0.1-beta.80

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
@@ -273,596 +273,45 @@ function useCAMSAuth(options) {
273
273
  };
274
274
  }
275
275
 
276
- var jsxRuntime = {exports: {}};
277
-
278
- var reactJsxRuntime_production = {};
279
-
280
- /**
281
- * @license React
282
- * react-jsx-runtime.production.js
283
- *
284
- * Copyright (c) Meta Platforms, Inc. and affiliates.
285
- *
286
- * This source code is licensed under the MIT license found in the
287
- * LICENSE file in the root directory of this source tree.
288
- */
289
-
290
- var hasRequiredReactJsxRuntime_production;
291
-
292
- function requireReactJsxRuntime_production () {
293
- if (hasRequiredReactJsxRuntime_production) return reactJsxRuntime_production;
294
- hasRequiredReactJsxRuntime_production = 1;
295
- var REACT_ELEMENT_TYPE = Symbol.for("react.transitional.element"),
296
- REACT_FRAGMENT_TYPE = Symbol.for("react.fragment");
297
- function jsxProd(type, config, maybeKey) {
298
- var key = null;
299
- void 0 !== maybeKey && (key = "" + maybeKey);
300
- void 0 !== config.key && (key = "" + config.key);
301
- if ("key" in config) {
302
- maybeKey = {};
303
- for (var propName in config)
304
- "key" !== propName && (maybeKey[propName] = config[propName]);
305
- } else maybeKey = config;
306
- config = maybeKey.ref;
307
- return {
308
- $$typeof: REACT_ELEMENT_TYPE,
309
- type: type,
310
- key: key,
311
- ref: void 0 !== config ? config : null,
312
- props: maybeKey
313
- };
314
- }
315
- reactJsxRuntime_production.Fragment = REACT_FRAGMENT_TYPE;
316
- reactJsxRuntime_production.jsx = jsxProd;
317
- reactJsxRuntime_production.jsxs = jsxProd;
318
- return reactJsxRuntime_production;
319
- }
320
-
321
- var reactJsxRuntime_development = {};
322
-
323
- /**
324
- * @license React
325
- * react-jsx-runtime.development.js
326
- *
327
- * Copyright (c) Meta Platforms, Inc. and affiliates.
328
- *
329
- * This source code is licensed under the MIT license found in the
330
- * LICENSE file in the root directory of this source tree.
331
- */
332
-
333
- var hasRequiredReactJsxRuntime_development;
276
+ var setCookie$1 = function (name, value, days) {
277
+ var expires = new Date(Date.now() + days * 24 * 60 * 60 * 1000).toUTCString();
278
+ document.cookie = "".concat(name, "=").concat(encodeURIComponent(value), "; expires=").concat(expires, "; path=/; samesite=Lax");
279
+ };
280
+ var getCookie$1 = function (name) {
281
+ var _a;
282
+ return ((_a = document.cookie
283
+ .split("; ")
284
+ .find(function (row) { return row.startsWith(name + "="); })) === null || _a === void 0 ? void 0 : _a.split("=")[1])
285
+ ? decodeURIComponent(document.cookie
286
+ .split("; ")
287
+ .find(function (row) { return row.startsWith(name + "="); })
288
+ .split("=")[1])
289
+ : null;
290
+ };
291
+ var deleteCookie$1 = function (name) {
292
+ document.cookie = name + "=; Max-Age=-99999999; path=/";
293
+ };
334
294
 
335
- function requireReactJsxRuntime_development () {
336
- if (hasRequiredReactJsxRuntime_development) return reactJsxRuntime_development;
337
- hasRequiredReactJsxRuntime_development = 1;
338
- "production" !== process.env.NODE_ENV &&
339
- (function () {
340
- function getComponentNameFromType(type) {
341
- if (null == type) return null;
342
- if ("function" === typeof type)
343
- return type.$$typeof === REACT_CLIENT_REFERENCE
344
- ? null
345
- : type.displayName || type.name || null;
346
- if ("string" === typeof type) return type;
347
- switch (type) {
348
- case REACT_FRAGMENT_TYPE:
349
- return "Fragment";
350
- case REACT_PROFILER_TYPE:
351
- return "Profiler";
352
- case REACT_STRICT_MODE_TYPE:
353
- return "StrictMode";
354
- case REACT_SUSPENSE_TYPE:
355
- return "Suspense";
356
- case REACT_SUSPENSE_LIST_TYPE:
357
- return "SuspenseList";
358
- case REACT_ACTIVITY_TYPE:
359
- return "Activity";
360
- }
361
- if ("object" === typeof type)
362
- switch (
363
- ("number" === typeof type.tag &&
364
- console.error(
365
- "Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."
366
- ),
367
- type.$$typeof)
368
- ) {
369
- case REACT_PORTAL_TYPE:
370
- return "Portal";
371
- case REACT_CONTEXT_TYPE:
372
- return (type.displayName || "Context") + ".Provider";
373
- case REACT_CONSUMER_TYPE:
374
- return (type._context.displayName || "Context") + ".Consumer";
375
- case REACT_FORWARD_REF_TYPE:
376
- var innerType = type.render;
377
- type = type.displayName;
378
- type ||
379
- ((type = innerType.displayName || innerType.name || ""),
380
- (type = "" !== type ? "ForwardRef(" + type + ")" : "ForwardRef"));
381
- return type;
382
- case REACT_MEMO_TYPE:
383
- return (
384
- (innerType = type.displayName || null),
385
- null !== innerType
386
- ? innerType
387
- : getComponentNameFromType(type.type) || "Memo"
388
- );
389
- case REACT_LAZY_TYPE:
390
- innerType = type._payload;
391
- type = type._init;
392
- try {
393
- return getComponentNameFromType(type(innerType));
394
- } catch (x) {}
395
- }
396
- return null;
397
- }
398
- function testStringCoercion(value) {
399
- return "" + value;
400
- }
401
- function checkKeyStringCoercion(value) {
402
- try {
403
- testStringCoercion(value);
404
- var JSCompiler_inline_result = !1;
405
- } catch (e) {
406
- JSCompiler_inline_result = true;
407
- }
408
- if (JSCompiler_inline_result) {
409
- JSCompiler_inline_result = console;
410
- var JSCompiler_temp_const = JSCompiler_inline_result.error;
411
- var JSCompiler_inline_result$jscomp$0 =
412
- ("function" === typeof Symbol &&
413
- Symbol.toStringTag &&
414
- value[Symbol.toStringTag]) ||
415
- value.constructor.name ||
416
- "Object";
417
- JSCompiler_temp_const.call(
418
- JSCompiler_inline_result,
419
- "The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",
420
- JSCompiler_inline_result$jscomp$0
421
- );
422
- return testStringCoercion(value);
423
- }
424
- }
425
- function getTaskName(type) {
426
- if (type === REACT_FRAGMENT_TYPE) return "<>";
427
- if (
428
- "object" === typeof type &&
429
- null !== type &&
430
- type.$$typeof === REACT_LAZY_TYPE
431
- )
432
- return "<...>";
433
- try {
434
- var name = getComponentNameFromType(type);
435
- return name ? "<" + name + ">" : "<...>";
436
- } catch (x) {
437
- return "<...>";
438
- }
439
- }
440
- function getOwner() {
441
- var dispatcher = ReactSharedInternals.A;
442
- return null === dispatcher ? null : dispatcher.getOwner();
443
- }
444
- function UnknownOwner() {
445
- return Error("react-stack-top-frame");
446
- }
447
- function hasValidKey(config) {
448
- if (hasOwnProperty.call(config, "key")) {
449
- var getter = Object.getOwnPropertyDescriptor(config, "key").get;
450
- if (getter && getter.isReactWarning) return false;
451
- }
452
- return void 0 !== config.key;
453
- }
454
- function defineKeyPropWarningGetter(props, displayName) {
455
- function warnAboutAccessingKey() {
456
- specialPropKeyWarningShown ||
457
- ((specialPropKeyWarningShown = true),
458
- console.error(
459
- "%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",
460
- displayName
461
- ));
462
- }
463
- warnAboutAccessingKey.isReactWarning = true;
464
- Object.defineProperty(props, "key", {
465
- get: warnAboutAccessingKey,
466
- configurable: true
467
- });
468
- }
469
- function elementRefGetterWithDeprecationWarning() {
470
- var componentName = getComponentNameFromType(this.type);
471
- didWarnAboutElementRef[componentName] ||
472
- ((didWarnAboutElementRef[componentName] = true),
473
- console.error(
474
- "Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release."
475
- ));
476
- componentName = this.props.ref;
477
- return void 0 !== componentName ? componentName : null;
478
- }
479
- function ReactElement(
480
- type,
481
- key,
482
- self,
483
- source,
484
- owner,
485
- props,
486
- debugStack,
487
- debugTask
488
- ) {
489
- self = props.ref;
490
- type = {
491
- $$typeof: REACT_ELEMENT_TYPE,
492
- type: type,
493
- key: key,
494
- props: props,
495
- _owner: owner
496
- };
497
- null !== (void 0 !== self ? self : null)
498
- ? Object.defineProperty(type, "ref", {
499
- enumerable: false,
500
- get: elementRefGetterWithDeprecationWarning
501
- })
502
- : Object.defineProperty(type, "ref", { enumerable: false, value: null });
503
- type._store = {};
504
- Object.defineProperty(type._store, "validated", {
505
- configurable: false,
506
- enumerable: false,
507
- writable: true,
508
- value: 0
509
- });
510
- Object.defineProperty(type, "_debugInfo", {
511
- configurable: false,
512
- enumerable: false,
513
- writable: true,
514
- value: null
515
- });
516
- Object.defineProperty(type, "_debugStack", {
517
- configurable: false,
518
- enumerable: false,
519
- writable: true,
520
- value: debugStack
521
- });
522
- Object.defineProperty(type, "_debugTask", {
523
- configurable: false,
524
- enumerable: false,
525
- writable: true,
526
- value: debugTask
527
- });
528
- Object.freeze && (Object.freeze(type.props), Object.freeze(type));
529
- return type;
530
- }
531
- function jsxDEVImpl(
532
- type,
533
- config,
534
- maybeKey,
535
- isStaticChildren,
536
- source,
537
- self,
538
- debugStack,
539
- debugTask
540
- ) {
541
- var children = config.children;
542
- if (void 0 !== children)
543
- if (isStaticChildren)
544
- if (isArrayImpl(children)) {
545
- for (
546
- isStaticChildren = 0;
547
- isStaticChildren < children.length;
548
- isStaticChildren++
549
- )
550
- validateChildKeys(children[isStaticChildren]);
551
- Object.freeze && Object.freeze(children);
552
- } else
553
- console.error(
554
- "React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead."
555
- );
556
- else validateChildKeys(children);
557
- if (hasOwnProperty.call(config, "key")) {
558
- children = getComponentNameFromType(type);
559
- var keys = Object.keys(config).filter(function (k) {
560
- return "key" !== k;
561
- });
562
- isStaticChildren =
563
- 0 < keys.length
564
- ? "{key: someKey, " + keys.join(": ..., ") + ": ...}"
565
- : "{key: someKey}";
566
- didWarnAboutKeySpread[children + isStaticChildren] ||
567
- ((keys =
568
- 0 < keys.length ? "{" + keys.join(": ..., ") + ": ...}" : "{}"),
569
- console.error(
570
- 'A props object containing a "key" prop is being spread into JSX:\n let props = %s;\n <%s {...props} />\nReact keys must be passed directly to JSX without using spread:\n let props = %s;\n <%s key={someKey} {...props} />',
571
- isStaticChildren,
572
- children,
573
- keys,
574
- children
575
- ),
576
- (didWarnAboutKeySpread[children + isStaticChildren] = true));
577
- }
578
- children = null;
579
- void 0 !== maybeKey &&
580
- (checkKeyStringCoercion(maybeKey), (children = "" + maybeKey));
581
- hasValidKey(config) &&
582
- (checkKeyStringCoercion(config.key), (children = "" + config.key));
583
- if ("key" in config) {
584
- maybeKey = {};
585
- for (var propName in config)
586
- "key" !== propName && (maybeKey[propName] = config[propName]);
587
- } else maybeKey = config;
588
- children &&
589
- defineKeyPropWarningGetter(
590
- maybeKey,
591
- "function" === typeof type
592
- ? type.displayName || type.name || "Unknown"
593
- : type
594
- );
595
- return ReactElement(
596
- type,
597
- children,
598
- self,
599
- source,
600
- getOwner(),
601
- maybeKey,
602
- debugStack,
603
- debugTask
604
- );
605
- }
606
- function validateChildKeys(node) {
607
- "object" === typeof node &&
608
- null !== node &&
609
- node.$$typeof === REACT_ELEMENT_TYPE &&
610
- node._store &&
611
- (node._store.validated = 1);
612
- }
613
- var React$1 = React,
614
- REACT_ELEMENT_TYPE = Symbol.for("react.transitional.element"),
615
- REACT_PORTAL_TYPE = Symbol.for("react.portal"),
616
- REACT_FRAGMENT_TYPE = Symbol.for("react.fragment"),
617
- REACT_STRICT_MODE_TYPE = Symbol.for("react.strict_mode"),
618
- REACT_PROFILER_TYPE = Symbol.for("react.profiler");
619
- var REACT_CONSUMER_TYPE = Symbol.for("react.consumer"),
620
- REACT_CONTEXT_TYPE = Symbol.for("react.context"),
621
- REACT_FORWARD_REF_TYPE = Symbol.for("react.forward_ref"),
622
- REACT_SUSPENSE_TYPE = Symbol.for("react.suspense"),
623
- REACT_SUSPENSE_LIST_TYPE = Symbol.for("react.suspense_list"),
624
- REACT_MEMO_TYPE = Symbol.for("react.memo"),
625
- REACT_LAZY_TYPE = Symbol.for("react.lazy"),
626
- REACT_ACTIVITY_TYPE = Symbol.for("react.activity"),
627
- REACT_CLIENT_REFERENCE = Symbol.for("react.client.reference"),
628
- ReactSharedInternals =
629
- React$1.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,
630
- hasOwnProperty = Object.prototype.hasOwnProperty,
631
- isArrayImpl = Array.isArray,
632
- createTask = console.createTask
633
- ? console.createTask
634
- : function () {
635
- return null;
636
- };
637
- React$1 = {
638
- react_stack_bottom_frame: function (callStackForError) {
639
- return callStackForError();
640
- }
641
- };
642
- var specialPropKeyWarningShown;
643
- var didWarnAboutElementRef = {};
644
- var unknownOwnerDebugStack = React$1.react_stack_bottom_frame.bind(
645
- React$1,
646
- UnknownOwner
647
- )();
648
- var unknownOwnerDebugTask = createTask(getTaskName(UnknownOwner));
649
- var didWarnAboutKeySpread = {};
650
- reactJsxRuntime_development.Fragment = REACT_FRAGMENT_TYPE;
651
- reactJsxRuntime_development.jsx = function (type, config, maybeKey, source, self) {
652
- var trackActualOwner =
653
- 1e4 > ReactSharedInternals.recentlyCreatedOwnerStacks++;
654
- return jsxDEVImpl(
655
- type,
656
- config,
657
- maybeKey,
658
- false,
659
- source,
660
- self,
661
- trackActualOwner
662
- ? Error("react-stack-top-frame")
663
- : unknownOwnerDebugStack,
664
- trackActualOwner ? createTask(getTaskName(type)) : unknownOwnerDebugTask
665
- );
666
- };
667
- reactJsxRuntime_development.jsxs = function (type, config, maybeKey, source, self) {
668
- var trackActualOwner =
669
- 1e4 > ReactSharedInternals.recentlyCreatedOwnerStacks++;
670
- return jsxDEVImpl(
671
- type,
672
- config,
673
- maybeKey,
674
- true,
675
- source,
676
- self,
677
- trackActualOwner
678
- ? Error("react-stack-top-frame")
679
- : unknownOwnerDebugStack,
680
- trackActualOwner ? createTask(getTaskName(type)) : unknownOwnerDebugTask
681
- );
682
- };
683
- })();
684
- return reactJsxRuntime_development;
685
- }
686
-
687
- if (process.env.NODE_ENV === 'production') {
688
- jsxRuntime.exports = requireReactJsxRuntime_production();
689
- } else {
690
- jsxRuntime.exports = requireReactJsxRuntime_development();
691
- }
692
-
693
- var jsxRuntimeExports = jsxRuntime.exports;
694
-
695
- var CAMSContext$1 = React.createContext(null);
696
- function useCAMSContext$1() {
697
- var context = React.useContext(CAMSContext$1);
698
- if (!context) {
699
- throw new Error("useCAMSContext must be used within a UnifiedCAMSProvider");
700
- }
701
- return context;
702
- }
703
-
704
- var ClientOnly = function (_a) {
705
- var children = _a.children, _b = _a.fallback, fallback = _b === void 0 ? null : _b;
706
- var _c = React.useState(false), hasMounted = _c[0], setHasMounted = _c[1];
707
- React.useEffect(function () {
708
- setHasMounted(true);
709
- }, []);
710
- if (!hasMounted) {
711
- return jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: fallback });
712
- }
713
- return jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: children });
714
- };
715
-
716
- var GuidSchema = z.z.uuid("appCode must be a valid GUID");
717
- var setCookie$1 = function (name, value, days) {
718
- if (days === void 0) { days = 1; }
719
- var expires = new Date(Date.now() + days * 24 * 60 * 60 * 1000).toUTCString();
720
- document.cookie = "".concat(name, "=").concat(encodeURIComponent(value), "; expires=").concat(expires, "; path=/; samesite=Lax");
721
- };
722
- var getCookie$1 = function (name) {
723
- var _a;
724
- return ((_a = document.cookie
725
- .split("; ")
726
- .find(function (row) { return row.startsWith(name + "="); })) === null || _a === void 0 ? void 0 : _a.split("=")[1])
727
- ? decodeURIComponent(document.cookie
728
- .split("; ")
729
- .find(function (row) { return row.startsWith(name + "="); })
730
- .split("=")[1])
731
- : null;
732
- };
733
- var deleteCookie$1 = function (name) {
734
- document.cookie = name + "=; Max-Age=-99999999; path=/";
735
- };
736
- function CAMSProviderCore(props) {
295
+ function useCAMSMSALAuth(options) {
737
296
  var _this = this;
738
- var children = props.children, mode = props.mode, appCode = props.appCode;
739
- // Always call both hooks to satisfy Rules of Hooks
740
- var regularAuth = useCAMSAuth(mode === "REGULAR"
741
- ? __assign(__assign({}, props), { appCode: appCode })
742
- : { appCode: "" });
743
- var msalAuth = useCAMSMSALAuth(mode === "MSAL"
744
- ? __assign(__assign({}, props), { appCode: appCode })
745
- : { appCode: "" });
746
- var auth = mode === "REGULAR" ? regularAuth : msalAuth;
747
- var profileStorageKey = "".concat(auth.storageKey, "-PROFILE");
748
- var getInitialProfile = function () {
749
- if (typeof window === "undefined")
750
- return null;
297
+ var storageKey = options.storageKey || "CAMS-MSAL-AUTH-SDK";
298
+ var _a = msalReact.useMsal(), instance = _a.instance, inProgress = _a.inProgress, accounts = _a.accounts;
299
+ var account = msalReact.useAccount(accounts[0] || {});
300
+ var _b = React.useState(null), error = _b[0], setError = _b[1];
301
+ var _c = React.useState(""), idToken = _c[0], setIdToken = _c[1];
302
+ var _d = React.useState(""), accessToken = _d[0], setAccessToken = _d[1];
303
+ var _e = React.useState(null), mfaAuthenticator = _e[0], setMfaAuthenticator = _e[1];
304
+ var _f = React.useState(false), requiresMFA = _f[0], setRequiresMFA = _f[1];
305
+ var isLoading = inProgress !== msalBrowser.InteractionStatus.None;
306
+ var isAuthenticated = !!account && !!accessToken && !requiresMFA;
307
+ var scopes = options.scopes || ["openid", "profile", "email"];
308
+ var isTokenValid = function (token) {
751
309
  try {
752
- var storedProfile = getCookie$1(profileStorageKey);
753
- return storedProfile ? JSON.parse(storedProfile) : null;
310
+ var payload = JSON.parse(atob(token.split(".")[1]));
311
+ return payload.exp * 1000 > Date.now();
754
312
  }
755
313
  catch (_a) {
756
- return null;
757
- }
758
- };
759
- var _a = React.useState(getInitialProfile), userProfile = _a[0], setUserProfile = _a[1];
760
- React.useEffect(function () {
761
- if (typeof window !== "undefined") {
762
- var storedProfile = getCookie$1(profileStorageKey);
763
- if (storedProfile) {
764
- try {
765
- setUserProfile(JSON.parse(storedProfile));
766
- }
767
- catch (_a) { }
768
- }
769
- }
770
- }, [profileStorageKey]);
771
- React.useEffect(function () {
772
- if (typeof window !== "undefined") {
773
- if (userProfile) {
774
- setCookie$1(profileStorageKey, JSON.stringify(userProfile), 1);
775
- }
776
- else {
777
- deleteCookie$1(profileStorageKey);
778
- }
779
- }
780
- }, [userProfile, profileStorageKey]);
781
- var enhancedLogout = function () { return __awaiter(_this, void 0, void 0, function () {
782
- return __generator(this, function (_a) {
783
- switch (_a.label) {
784
- case 0: return [4 /*yield*/, auth.logout()];
785
- case 1:
786
- _a.sent();
787
- setUserProfile(null);
788
- if (typeof window !== "undefined") {
789
- deleteCookie$1(profileStorageKey);
790
- }
791
- return [2 /*return*/];
792
- }
793
- });
794
- }); };
795
- // Handle MFA completion for MSAL mode
796
- React.useEffect(function () {
797
- if (mode === "MSAL" &&
798
- "requiresMFA" in auth &&
799
- !auth.requiresMFA &&
800
- auth.isAuthenticated) {
801
- // MFA completed, extract profile from localStorage
802
- var storedData = localStorage.getItem(auth.storageKey);
803
- console.log("MFA Complete - Checking for profile:", storedData);
804
- if (storedData) {
805
- try {
806
- var parsed = JSON.parse(storedData);
807
- console.log("Parsed storage data:", parsed);
808
- if (parsed.userProfile) {
809
- console.log("Setting user profile:", parsed.userProfile);
810
- setUserProfile(parsed.userProfile);
811
- }
812
- }
813
- catch (e) {
814
- console.error("Error parsing stored data:", e);
815
- }
816
- }
817
- }
818
- }, [
819
- mode,
820
- "requiresMFA" in auth ? auth.requiresMFA : false,
821
- auth.isAuthenticated,
822
- auth.storageKey,
823
- userProfile,
824
- ]);
825
- var value = React.useMemo(function () {
826
- return (__assign(__assign({}, auth), { logout: enhancedLogout, userProfile: userProfile, setUserProfile: setUserProfile, authMode: mode }));
827
- }, [auth, userProfile, mode]);
828
- return jsxRuntimeExports.jsx(CAMSContext$1.Provider, { value: value, children: children });
829
- }
830
- function UnifiedCAMSProvider(props) {
831
- // Validate appCode is a valid GUID
832
- var appCodeValidation = GuidSchema.safeParse(props.appCode);
833
- if (!appCodeValidation.success) {
834
- throw new Error("Invalid appCode: ".concat(appCodeValidation.error.issues[0].message));
835
- }
836
- if (props.mode === "MSAL") {
837
- var msalConfig = props.msalConfig, msalInstance = props.msalInstance;
838
- var instance = msalInstance || new msalBrowser.PublicClientApplication(msalConfig);
839
- return (jsxRuntimeExports.jsx(msalReact.MsalProvider, { instance: instance, children: jsxRuntimeExports.jsx(CAMSProviderCore, __assign({}, props)) }));
840
- }
841
- return (jsxRuntimeExports.jsx(ClientOnly, { fallback: jsxRuntimeExports.jsx("div", { children: "Loading..." }), children: jsxRuntimeExports.jsx(CAMSProviderCore, __assign({}, props)) }));
842
- }
843
- // Backward compatibility exports
844
- var CAMSProvider = function (props) { return (jsxRuntimeExports.jsx(UnifiedCAMSProvider, __assign({}, props, { mode: "REGULAR" }))); };
845
-
846
- function useCAMSMSALAuth(options) {
847
- var _this = this;
848
- var storageKey = options.storageKey || "CAMS-MSAL-AUTH-SDK";
849
- var _a = msalReact.useMsal(), instance = _a.instance, inProgress = _a.inProgress, accounts = _a.accounts;
850
- var account = msalReact.useAccount(accounts[0] || {});
851
- var _b = React.useState(null), error = _b[0], setError = _b[1];
852
- var _c = React.useState(""), idToken = _c[0], setIdToken = _c[1];
853
- var _d = React.useState(""), accessToken = _d[0], setAccessToken = _d[1];
854
- var _e = React.useState(null), mfaAuthenticator = _e[0], setMfaAuthenticator = _e[1];
855
- var _f = React.useState(false), requiresMFA = _f[0], setRequiresMFA = _f[1];
856
- var isLoading = inProgress !== msalBrowser.InteractionStatus.None;
857
- var isAuthenticated = !!account && !!accessToken && !requiresMFA;
858
- var scopes = options.scopes || ["openid", "profile", "email"];
859
- var isTokenValid = function (token) {
860
- try {
861
- var payload = JSON.parse(atob(token.split(".")[1]));
862
- return payload.exp * 1000 > Date.now();
863
- }
864
- catch (_a) {
865
- return false;
314
+ return false;
866
315
  }
867
316
  };
868
317
  React.useEffect(function () {
@@ -1089,59 +538,478 @@ function useCAMSMSALAuth(options) {
1089
538
  };
1090
539
  }
1091
540
 
1092
- /**
1093
- * Hook for handling authentication in popup windows
1094
- * This should be used by the popup app to complete authentication
1095
- */
1096
- function useCAMSPopupAuth(options) {
1097
- if (options === void 0) { options = {}; }
1098
- var _a = options.storageKey, storageKey = _a === void 0 ? "CAMS-SDK" : _a, targetOrigin = options.targetOrigin, onAuthComplete = options.onAuthComplete, onAuthError = options.onAuthError;
1099
- React.useEffect(function () {
1100
- if (typeof window === "undefined" || !camsSdk.isPopupWindow())
1101
- return;
1102
- // Initialize popup auth handler
1103
- camsSdk.initializePopupAuth(targetOrigin);
1104
- // Set up global handlers for the popup app
1105
- var globalHandlers = window.__CAMS_POPUP_AUTH__;
1106
- if (globalHandlers) {
1107
- var originalCompleteAuth_1 = globalHandlers.completeAuth;
1108
- var originalErrorAuth_1 = globalHandlers.errorAuth;
1109
- globalHandlers.completeAuth = function (profile) {
1110
- onAuthComplete === null || onAuthComplete === void 0 ? void 0 : onAuthComplete(profile);
1111
- originalCompleteAuth_1(profile);
1112
- };
1113
- globalHandlers.errorAuth = function (error) {
1114
- onAuthError === null || onAuthError === void 0 ? void 0 : onAuthError(error);
1115
- originalErrorAuth_1(error);
1116
- };
1117
- }
1118
- }, [targetOrigin, onAuthComplete, onAuthError]);
1119
- var completeAuth = React.useCallback(function (profile) {
1120
- if (!camsSdk.isPopupWindow()) {
1121
- console.warn("completeAuth called outside of popup window");
1122
- return;
1123
- }
1124
- var sessionManager = new camsSdk.CAMSSessionManager(localStorage, storageKey);
1125
- sessionManager.completePopupAuth(profile, targetOrigin);
1126
- }, [storageKey, targetOrigin]);
1127
- var errorAuth = React.useCallback(function (error) {
1128
- if (!camsSdk.isPopupWindow()) {
1129
- console.warn("errorAuth called outside of popup window");
1130
- return;
1131
- }
1132
- var sessionManager = new camsSdk.CAMSSessionManager(localStorage, storageKey);
1133
- sessionManager.errorPopupAuth(error, targetOrigin);
1134
- }, [storageKey, targetOrigin]);
1135
- return {
1136
- completeAuth: completeAuth,
1137
- errorAuth: errorAuth,
1138
- isPopup: camsSdk.isPopupWindow(),
1139
- };
541
+ /**
542
+ * Hook for handling authentication in popup windows
543
+ * This should be used by the popup app to complete authentication
544
+ */
545
+ function useCAMSPopupAuth(options) {
546
+ if (options === void 0) { options = {}; }
547
+ var _a = options.storageKey, storageKey = _a === void 0 ? "CAMS-SDK" : _a, targetOrigin = options.targetOrigin, onAuthComplete = options.onAuthComplete, onAuthError = options.onAuthError;
548
+ React.useEffect(function () {
549
+ if (typeof window === "undefined" || !camsSdk.isPopupWindow())
550
+ return;
551
+ // Initialize popup auth handler
552
+ camsSdk.initializePopupAuth(targetOrigin);
553
+ // Set up global handlers for the popup app
554
+ var globalHandlers = window.__CAMS_POPUP_AUTH__;
555
+ if (globalHandlers) {
556
+ var originalCompleteAuth_1 = globalHandlers.completeAuth;
557
+ var originalErrorAuth_1 = globalHandlers.errorAuth;
558
+ globalHandlers.completeAuth = function (profile) {
559
+ onAuthComplete === null || onAuthComplete === void 0 ? void 0 : onAuthComplete(profile);
560
+ originalCompleteAuth_1(profile);
561
+ };
562
+ globalHandlers.errorAuth = function (error) {
563
+ onAuthError === null || onAuthError === void 0 ? void 0 : onAuthError(error);
564
+ originalErrorAuth_1(error);
565
+ };
566
+ }
567
+ }, [targetOrigin, onAuthComplete, onAuthError]);
568
+ var completeAuth = React.useCallback(function (profile) {
569
+ if (!camsSdk.isPopupWindow()) {
570
+ console.warn("completeAuth called outside of popup window");
571
+ return;
572
+ }
573
+ var sessionManager = new camsSdk.CAMSSessionManager(localStorage, storageKey);
574
+ sessionManager.completePopupAuth(profile, targetOrigin);
575
+ }, [storageKey, targetOrigin]);
576
+ var errorAuth = React.useCallback(function (error) {
577
+ if (!camsSdk.isPopupWindow()) {
578
+ console.warn("errorAuth called outside of popup window");
579
+ return;
580
+ }
581
+ var sessionManager = new camsSdk.CAMSSessionManager(localStorage, storageKey);
582
+ sessionManager.errorPopupAuth(error, targetOrigin);
583
+ }, [storageKey, targetOrigin]);
584
+ return {
585
+ completeAuth: completeAuth,
586
+ errorAuth: errorAuth,
587
+ isPopup: camsSdk.isPopupWindow(),
588
+ };
589
+ }
590
+
591
+ var jsxRuntime = {exports: {}};
592
+
593
+ var reactJsxRuntime_production = {};
594
+
595
+ /**
596
+ * @license React
597
+ * react-jsx-runtime.production.js
598
+ *
599
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
600
+ *
601
+ * This source code is licensed under the MIT license found in the
602
+ * LICENSE file in the root directory of this source tree.
603
+ */
604
+
605
+ var hasRequiredReactJsxRuntime_production;
606
+
607
+ function requireReactJsxRuntime_production () {
608
+ if (hasRequiredReactJsxRuntime_production) return reactJsxRuntime_production;
609
+ hasRequiredReactJsxRuntime_production = 1;
610
+ var REACT_ELEMENT_TYPE = Symbol.for("react.transitional.element"),
611
+ REACT_FRAGMENT_TYPE = Symbol.for("react.fragment");
612
+ function jsxProd(type, config, maybeKey) {
613
+ var key = null;
614
+ void 0 !== maybeKey && (key = "" + maybeKey);
615
+ void 0 !== config.key && (key = "" + config.key);
616
+ if ("key" in config) {
617
+ maybeKey = {};
618
+ for (var propName in config)
619
+ "key" !== propName && (maybeKey[propName] = config[propName]);
620
+ } else maybeKey = config;
621
+ config = maybeKey.ref;
622
+ return {
623
+ $$typeof: REACT_ELEMENT_TYPE,
624
+ type: type,
625
+ key: key,
626
+ ref: void 0 !== config ? config : null,
627
+ props: maybeKey
628
+ };
629
+ }
630
+ reactJsxRuntime_production.Fragment = REACT_FRAGMENT_TYPE;
631
+ reactJsxRuntime_production.jsx = jsxProd;
632
+ reactJsxRuntime_production.jsxs = jsxProd;
633
+ return reactJsxRuntime_production;
634
+ }
635
+
636
+ var reactJsxRuntime_development = {};
637
+
638
+ /**
639
+ * @license React
640
+ * react-jsx-runtime.development.js
641
+ *
642
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
643
+ *
644
+ * This source code is licensed under the MIT license found in the
645
+ * LICENSE file in the root directory of this source tree.
646
+ */
647
+
648
+ var hasRequiredReactJsxRuntime_development;
649
+
650
+ function requireReactJsxRuntime_development () {
651
+ if (hasRequiredReactJsxRuntime_development) return reactJsxRuntime_development;
652
+ hasRequiredReactJsxRuntime_development = 1;
653
+ "production" !== process.env.NODE_ENV &&
654
+ (function () {
655
+ function getComponentNameFromType(type) {
656
+ if (null == type) return null;
657
+ if ("function" === typeof type)
658
+ return type.$$typeof === REACT_CLIENT_REFERENCE
659
+ ? null
660
+ : type.displayName || type.name || null;
661
+ if ("string" === typeof type) return type;
662
+ switch (type) {
663
+ case REACT_FRAGMENT_TYPE:
664
+ return "Fragment";
665
+ case REACT_PROFILER_TYPE:
666
+ return "Profiler";
667
+ case REACT_STRICT_MODE_TYPE:
668
+ return "StrictMode";
669
+ case REACT_SUSPENSE_TYPE:
670
+ return "Suspense";
671
+ case REACT_SUSPENSE_LIST_TYPE:
672
+ return "SuspenseList";
673
+ case REACT_ACTIVITY_TYPE:
674
+ return "Activity";
675
+ }
676
+ if ("object" === typeof type)
677
+ switch (
678
+ ("number" === typeof type.tag &&
679
+ console.error(
680
+ "Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."
681
+ ),
682
+ type.$$typeof)
683
+ ) {
684
+ case REACT_PORTAL_TYPE:
685
+ return "Portal";
686
+ case REACT_CONTEXT_TYPE:
687
+ return (type.displayName || "Context") + ".Provider";
688
+ case REACT_CONSUMER_TYPE:
689
+ return (type._context.displayName || "Context") + ".Consumer";
690
+ case REACT_FORWARD_REF_TYPE:
691
+ var innerType = type.render;
692
+ type = type.displayName;
693
+ type ||
694
+ ((type = innerType.displayName || innerType.name || ""),
695
+ (type = "" !== type ? "ForwardRef(" + type + ")" : "ForwardRef"));
696
+ return type;
697
+ case REACT_MEMO_TYPE:
698
+ return (
699
+ (innerType = type.displayName || null),
700
+ null !== innerType
701
+ ? innerType
702
+ : getComponentNameFromType(type.type) || "Memo"
703
+ );
704
+ case REACT_LAZY_TYPE:
705
+ innerType = type._payload;
706
+ type = type._init;
707
+ try {
708
+ return getComponentNameFromType(type(innerType));
709
+ } catch (x) {}
710
+ }
711
+ return null;
712
+ }
713
+ function testStringCoercion(value) {
714
+ return "" + value;
715
+ }
716
+ function checkKeyStringCoercion(value) {
717
+ try {
718
+ testStringCoercion(value);
719
+ var JSCompiler_inline_result = !1;
720
+ } catch (e) {
721
+ JSCompiler_inline_result = true;
722
+ }
723
+ if (JSCompiler_inline_result) {
724
+ JSCompiler_inline_result = console;
725
+ var JSCompiler_temp_const = JSCompiler_inline_result.error;
726
+ var JSCompiler_inline_result$jscomp$0 =
727
+ ("function" === typeof Symbol &&
728
+ Symbol.toStringTag &&
729
+ value[Symbol.toStringTag]) ||
730
+ value.constructor.name ||
731
+ "Object";
732
+ JSCompiler_temp_const.call(
733
+ JSCompiler_inline_result,
734
+ "The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",
735
+ JSCompiler_inline_result$jscomp$0
736
+ );
737
+ return testStringCoercion(value);
738
+ }
739
+ }
740
+ function getTaskName(type) {
741
+ if (type === REACT_FRAGMENT_TYPE) return "<>";
742
+ if (
743
+ "object" === typeof type &&
744
+ null !== type &&
745
+ type.$$typeof === REACT_LAZY_TYPE
746
+ )
747
+ return "<...>";
748
+ try {
749
+ var name = getComponentNameFromType(type);
750
+ return name ? "<" + name + ">" : "<...>";
751
+ } catch (x) {
752
+ return "<...>";
753
+ }
754
+ }
755
+ function getOwner() {
756
+ var dispatcher = ReactSharedInternals.A;
757
+ return null === dispatcher ? null : dispatcher.getOwner();
758
+ }
759
+ function UnknownOwner() {
760
+ return Error("react-stack-top-frame");
761
+ }
762
+ function hasValidKey(config) {
763
+ if (hasOwnProperty.call(config, "key")) {
764
+ var getter = Object.getOwnPropertyDescriptor(config, "key").get;
765
+ if (getter && getter.isReactWarning) return false;
766
+ }
767
+ return void 0 !== config.key;
768
+ }
769
+ function defineKeyPropWarningGetter(props, displayName) {
770
+ function warnAboutAccessingKey() {
771
+ specialPropKeyWarningShown ||
772
+ ((specialPropKeyWarningShown = true),
773
+ console.error(
774
+ "%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",
775
+ displayName
776
+ ));
777
+ }
778
+ warnAboutAccessingKey.isReactWarning = true;
779
+ Object.defineProperty(props, "key", {
780
+ get: warnAboutAccessingKey,
781
+ configurable: true
782
+ });
783
+ }
784
+ function elementRefGetterWithDeprecationWarning() {
785
+ var componentName = getComponentNameFromType(this.type);
786
+ didWarnAboutElementRef[componentName] ||
787
+ ((didWarnAboutElementRef[componentName] = true),
788
+ console.error(
789
+ "Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release."
790
+ ));
791
+ componentName = this.props.ref;
792
+ return void 0 !== componentName ? componentName : null;
793
+ }
794
+ function ReactElement(
795
+ type,
796
+ key,
797
+ self,
798
+ source,
799
+ owner,
800
+ props,
801
+ debugStack,
802
+ debugTask
803
+ ) {
804
+ self = props.ref;
805
+ type = {
806
+ $$typeof: REACT_ELEMENT_TYPE,
807
+ type: type,
808
+ key: key,
809
+ props: props,
810
+ _owner: owner
811
+ };
812
+ null !== (void 0 !== self ? self : null)
813
+ ? Object.defineProperty(type, "ref", {
814
+ enumerable: false,
815
+ get: elementRefGetterWithDeprecationWarning
816
+ })
817
+ : Object.defineProperty(type, "ref", { enumerable: false, value: null });
818
+ type._store = {};
819
+ Object.defineProperty(type._store, "validated", {
820
+ configurable: false,
821
+ enumerable: false,
822
+ writable: true,
823
+ value: 0
824
+ });
825
+ Object.defineProperty(type, "_debugInfo", {
826
+ configurable: false,
827
+ enumerable: false,
828
+ writable: true,
829
+ value: null
830
+ });
831
+ Object.defineProperty(type, "_debugStack", {
832
+ configurable: false,
833
+ enumerable: false,
834
+ writable: true,
835
+ value: debugStack
836
+ });
837
+ Object.defineProperty(type, "_debugTask", {
838
+ configurable: false,
839
+ enumerable: false,
840
+ writable: true,
841
+ value: debugTask
842
+ });
843
+ Object.freeze && (Object.freeze(type.props), Object.freeze(type));
844
+ return type;
845
+ }
846
+ function jsxDEVImpl(
847
+ type,
848
+ config,
849
+ maybeKey,
850
+ isStaticChildren,
851
+ source,
852
+ self,
853
+ debugStack,
854
+ debugTask
855
+ ) {
856
+ var children = config.children;
857
+ if (void 0 !== children)
858
+ if (isStaticChildren)
859
+ if (isArrayImpl(children)) {
860
+ for (
861
+ isStaticChildren = 0;
862
+ isStaticChildren < children.length;
863
+ isStaticChildren++
864
+ )
865
+ validateChildKeys(children[isStaticChildren]);
866
+ Object.freeze && Object.freeze(children);
867
+ } else
868
+ console.error(
869
+ "React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead."
870
+ );
871
+ else validateChildKeys(children);
872
+ if (hasOwnProperty.call(config, "key")) {
873
+ children = getComponentNameFromType(type);
874
+ var keys = Object.keys(config).filter(function (k) {
875
+ return "key" !== k;
876
+ });
877
+ isStaticChildren =
878
+ 0 < keys.length
879
+ ? "{key: someKey, " + keys.join(": ..., ") + ": ...}"
880
+ : "{key: someKey}";
881
+ didWarnAboutKeySpread[children + isStaticChildren] ||
882
+ ((keys =
883
+ 0 < keys.length ? "{" + keys.join(": ..., ") + ": ...}" : "{}"),
884
+ console.error(
885
+ 'A props object containing a "key" prop is being spread into JSX:\n let props = %s;\n <%s {...props} />\nReact keys must be passed directly to JSX without using spread:\n let props = %s;\n <%s key={someKey} {...props} />',
886
+ isStaticChildren,
887
+ children,
888
+ keys,
889
+ children
890
+ ),
891
+ (didWarnAboutKeySpread[children + isStaticChildren] = true));
892
+ }
893
+ children = null;
894
+ void 0 !== maybeKey &&
895
+ (checkKeyStringCoercion(maybeKey), (children = "" + maybeKey));
896
+ hasValidKey(config) &&
897
+ (checkKeyStringCoercion(config.key), (children = "" + config.key));
898
+ if ("key" in config) {
899
+ maybeKey = {};
900
+ for (var propName in config)
901
+ "key" !== propName && (maybeKey[propName] = config[propName]);
902
+ } else maybeKey = config;
903
+ children &&
904
+ defineKeyPropWarningGetter(
905
+ maybeKey,
906
+ "function" === typeof type
907
+ ? type.displayName || type.name || "Unknown"
908
+ : type
909
+ );
910
+ return ReactElement(
911
+ type,
912
+ children,
913
+ self,
914
+ source,
915
+ getOwner(),
916
+ maybeKey,
917
+ debugStack,
918
+ debugTask
919
+ );
920
+ }
921
+ function validateChildKeys(node) {
922
+ "object" === typeof node &&
923
+ null !== node &&
924
+ node.$$typeof === REACT_ELEMENT_TYPE &&
925
+ node._store &&
926
+ (node._store.validated = 1);
927
+ }
928
+ var React$1 = React,
929
+ REACT_ELEMENT_TYPE = Symbol.for("react.transitional.element"),
930
+ REACT_PORTAL_TYPE = Symbol.for("react.portal"),
931
+ REACT_FRAGMENT_TYPE = Symbol.for("react.fragment"),
932
+ REACT_STRICT_MODE_TYPE = Symbol.for("react.strict_mode"),
933
+ REACT_PROFILER_TYPE = Symbol.for("react.profiler");
934
+ var REACT_CONSUMER_TYPE = Symbol.for("react.consumer"),
935
+ REACT_CONTEXT_TYPE = Symbol.for("react.context"),
936
+ REACT_FORWARD_REF_TYPE = Symbol.for("react.forward_ref"),
937
+ REACT_SUSPENSE_TYPE = Symbol.for("react.suspense"),
938
+ REACT_SUSPENSE_LIST_TYPE = Symbol.for("react.suspense_list"),
939
+ REACT_MEMO_TYPE = Symbol.for("react.memo"),
940
+ REACT_LAZY_TYPE = Symbol.for("react.lazy"),
941
+ REACT_ACTIVITY_TYPE = Symbol.for("react.activity"),
942
+ REACT_CLIENT_REFERENCE = Symbol.for("react.client.reference"),
943
+ ReactSharedInternals =
944
+ React$1.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,
945
+ hasOwnProperty = Object.prototype.hasOwnProperty,
946
+ isArrayImpl = Array.isArray,
947
+ createTask = console.createTask
948
+ ? console.createTask
949
+ : function () {
950
+ return null;
951
+ };
952
+ React$1 = {
953
+ react_stack_bottom_frame: function (callStackForError) {
954
+ return callStackForError();
955
+ }
956
+ };
957
+ var specialPropKeyWarningShown;
958
+ var didWarnAboutElementRef = {};
959
+ var unknownOwnerDebugStack = React$1.react_stack_bottom_frame.bind(
960
+ React$1,
961
+ UnknownOwner
962
+ )();
963
+ var unknownOwnerDebugTask = createTask(getTaskName(UnknownOwner));
964
+ var didWarnAboutKeySpread = {};
965
+ reactJsxRuntime_development.Fragment = REACT_FRAGMENT_TYPE;
966
+ reactJsxRuntime_development.jsx = function (type, config, maybeKey, source, self) {
967
+ var trackActualOwner =
968
+ 1e4 > ReactSharedInternals.recentlyCreatedOwnerStacks++;
969
+ return jsxDEVImpl(
970
+ type,
971
+ config,
972
+ maybeKey,
973
+ false,
974
+ source,
975
+ self,
976
+ trackActualOwner
977
+ ? Error("react-stack-top-frame")
978
+ : unknownOwnerDebugStack,
979
+ trackActualOwner ? createTask(getTaskName(type)) : unknownOwnerDebugTask
980
+ );
981
+ };
982
+ reactJsxRuntime_development.jsxs = function (type, config, maybeKey, source, self) {
983
+ var trackActualOwner =
984
+ 1e4 > ReactSharedInternals.recentlyCreatedOwnerStacks++;
985
+ return jsxDEVImpl(
986
+ type,
987
+ config,
988
+ maybeKey,
989
+ true,
990
+ source,
991
+ self,
992
+ trackActualOwner
993
+ ? Error("react-stack-top-frame")
994
+ : unknownOwnerDebugStack,
995
+ trackActualOwner ? createTask(getTaskName(type)) : unknownOwnerDebugTask
996
+ );
997
+ };
998
+ })();
999
+ return reactJsxRuntime_development;
1000
+ }
1001
+
1002
+ if (process.env.NODE_ENV === 'production') {
1003
+ jsxRuntime.exports = requireReactJsxRuntime_production();
1004
+ } else {
1005
+ jsxRuntime.exports = requireReactJsxRuntime_development();
1140
1006
  }
1141
1007
 
1142
- var CAMSContext = React.createContext(null);
1143
- function useCAMSContext() {
1144
- var context = React.useContext(CAMSContext);
1008
+ var jsxRuntimeExports = jsxRuntime.exports;
1009
+
1010
+ var CAMSContext$1 = React.createContext(null);
1011
+ function useCAMSContext$1() {
1012
+ var context = React.useContext(CAMSContext$1);
1145
1013
  if (!context) {
1146
1014
  throw new Error('useCAMSContext must be used within a CAMSProvider');
1147
1015
  }
@@ -1150,7 +1018,7 @@ function useCAMSContext() {
1150
1018
 
1151
1019
  function ProtectedRoute(_a) {
1152
1020
  var children = _a.children, fallback = _a.fallback, redirectTo = _a.redirectTo;
1153
- var _b = useCAMSContext(), isAuthenticated = _b.isAuthenticated, isLoading = _b.isLoading;
1021
+ var _b = useCAMSContext$1(), isAuthenticated = _b.isAuthenticated, isLoading = _b.isLoading;
1154
1022
  if (isLoading) {
1155
1023
  return fallback || jsxRuntimeExports.jsx("div", { children: "Loading..." });
1156
1024
  }
@@ -1277,6 +1145,138 @@ function useCAMSMSALContext() {
1277
1145
  return context;
1278
1146
  }
1279
1147
 
1148
+ var ClientOnly = function (_a) {
1149
+ var children = _a.children, _b = _a.fallback, fallback = _b === void 0 ? null : _b;
1150
+ var _c = React.useState(false), hasMounted = _c[0], setHasMounted = _c[1];
1151
+ React.useEffect(function () {
1152
+ setHasMounted(true);
1153
+ }, []);
1154
+ if (!hasMounted) {
1155
+ return jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: fallback });
1156
+ }
1157
+ return jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: children });
1158
+ };
1159
+
1160
+ var CAMSContext = React.createContext(null);
1161
+ function useCAMSContext() {
1162
+ var context = React.useContext(CAMSContext);
1163
+ if (!context) {
1164
+ throw new Error("useCAMSContext must be used within a UnifiedCAMSProvider");
1165
+ }
1166
+ return context;
1167
+ }
1168
+
1169
+ var GuidSchema = z.z.uuid("appCode must be a valid GUID");
1170
+ function CAMSProviderCore(props) {
1171
+ var _this = this;
1172
+ var children = props.children, mode = props.mode, appCode = props.appCode;
1173
+ // Always call both hooks to satisfy Rules of Hooks
1174
+ var regularAuth = useCAMSAuth(mode === "REGULAR"
1175
+ ? __assign(__assign({}, props), { appCode: appCode })
1176
+ : { appCode: "" });
1177
+ var msalAuth = useCAMSMSALAuth(mode === "MSAL"
1178
+ ? __assign(__assign({}, props), { appCode: appCode })
1179
+ : { appCode: "" });
1180
+ var auth = mode === "REGULAR" ? regularAuth : msalAuth;
1181
+ var profileStorageKey = "".concat(auth.storageKey, "-PROFILE");
1182
+ var getInitialProfile = function () {
1183
+ if (typeof window === "undefined")
1184
+ return null;
1185
+ try {
1186
+ var storedProfile = getCookie$1(profileStorageKey);
1187
+ return storedProfile ? JSON.parse(storedProfile) : null;
1188
+ }
1189
+ catch (_a) {
1190
+ return null;
1191
+ }
1192
+ };
1193
+ var _a = React.useState(getInitialProfile), userProfile = _a[0], setUserProfile = _a[1];
1194
+ React.useEffect(function () {
1195
+ if (typeof window !== "undefined") {
1196
+ var storedProfile = getCookie$1(profileStorageKey);
1197
+ if (storedProfile) {
1198
+ try {
1199
+ setUserProfile(JSON.parse(storedProfile));
1200
+ }
1201
+ catch (_a) { }
1202
+ }
1203
+ }
1204
+ }, [profileStorageKey]);
1205
+ React.useEffect(function () {
1206
+ if (typeof window !== "undefined") {
1207
+ if (userProfile) {
1208
+ setCookie$1(profileStorageKey, JSON.stringify(userProfile), 1);
1209
+ }
1210
+ else {
1211
+ deleteCookie$1(profileStorageKey);
1212
+ }
1213
+ }
1214
+ }, [userProfile, profileStorageKey]);
1215
+ var enhancedLogout = function () { return __awaiter(_this, void 0, void 0, function () {
1216
+ return __generator(this, function (_a) {
1217
+ switch (_a.label) {
1218
+ case 0: return [4 /*yield*/, auth.logout()];
1219
+ case 1:
1220
+ _a.sent();
1221
+ setUserProfile(null);
1222
+ if (typeof window !== "undefined") {
1223
+ deleteCookie$1(profileStorageKey);
1224
+ }
1225
+ return [2 /*return*/];
1226
+ }
1227
+ });
1228
+ }); };
1229
+ // Handle MFA completion for MSAL mode
1230
+ React.useEffect(function () {
1231
+ if (mode === "MSAL" &&
1232
+ "requiresMFA" in auth &&
1233
+ !auth.requiresMFA &&
1234
+ auth.isAuthenticated) {
1235
+ // MFA completed, extract profile from localStorage
1236
+ var storedData = localStorage.getItem(auth.storageKey);
1237
+ console.log("MFA Complete - Checking for profile:", storedData);
1238
+ if (storedData) {
1239
+ try {
1240
+ var parsed = JSON.parse(storedData);
1241
+ console.log("Parsed storage data:", parsed);
1242
+ if (parsed.userProfile) {
1243
+ console.log("Setting user profile:", parsed.userProfile);
1244
+ setUserProfile(parsed.userProfile);
1245
+ }
1246
+ }
1247
+ catch (e) {
1248
+ console.error("Error parsing stored data:", e);
1249
+ }
1250
+ }
1251
+ }
1252
+ }, [
1253
+ mode,
1254
+ "requiresMFA" in auth ? auth.requiresMFA : false,
1255
+ auth.isAuthenticated,
1256
+ auth.storageKey,
1257
+ userProfile,
1258
+ ]);
1259
+ var value = React.useMemo(function () {
1260
+ return (__assign(__assign({}, auth), { logout: enhancedLogout, userProfile: userProfile, setUserProfile: setUserProfile, authMode: mode }));
1261
+ }, [auth, userProfile, mode]);
1262
+ return jsxRuntimeExports.jsx(CAMSContext.Provider, { value: value, children: children });
1263
+ }
1264
+ function UnifiedCAMSProvider(props) {
1265
+ // Validate appCode is a valid GUID
1266
+ var appCodeValidation = GuidSchema.safeParse(props.appCode);
1267
+ if (!appCodeValidation.success) {
1268
+ throw new Error("Invalid appCode: ".concat(appCodeValidation.error.issues[0].message));
1269
+ }
1270
+ if (props.mode === "MSAL") {
1271
+ var msalConfig = props.msalConfig, msalInstance = props.msalInstance;
1272
+ var instance = msalInstance || new msalBrowser.PublicClientApplication(msalConfig);
1273
+ return (jsxRuntimeExports.jsx(msalReact.MsalProvider, { instance: instance, children: jsxRuntimeExports.jsx(CAMSProviderCore, __assign({}, props)) }));
1274
+ }
1275
+ return (jsxRuntimeExports.jsx(ClientOnly, { fallback: jsxRuntimeExports.jsx("div", { children: "Loading..." }), children: jsxRuntimeExports.jsx(CAMSProviderCore, __assign({}, props)) }));
1276
+ }
1277
+ // Backward compatibility exports
1278
+ var CAMSProvider = function (props) { return (jsxRuntimeExports.jsx(UnifiedCAMSProvider, __assign({}, props, { mode: "REGULAR" }))); };
1279
+
1280
1280
  /** A special constant with type `never` */
1281
1281
  function $constructor(name, initializer, params) {
1282
1282
  function init(inst, def) {
@@ -1786,7 +1786,7 @@ var MFAOptions = function (_a) {
1786
1786
  var _d = React.useState(false), otpVisible = _d[0], setOtpVisible = _d[1];
1787
1787
  var _e = React.useState(false), showSuccessAnimation = _e[0], setShowSuccessAnimation = _e[1];
1788
1788
  var _f = React.useState(null), authType = _f[0], setAuthType = _f[1];
1789
- var context = useCAMSContext$1();
1789
+ var context = useCAMSContext();
1790
1790
  var _g = context.authMode === "MSAL" && "sendEmailOTP" in context
1791
1791
  ? context
1792
1792
  : { sendEmailOTP: null, completeMFA: null, logout: function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
@@ -1959,7 +1959,7 @@ var ADLoginModal = function (_a) {
1959
1959
  };
1960
1960
 
1961
1961
  var DefaultLoginPage = function () {
1962
- var context = useCAMSContext$1();
1962
+ var context = useCAMSContext();
1963
1963
  var login = context.login, isLoading = context.isLoading, authMode = context.authMode;
1964
1964
  var _a = React.useState(false), showADModal = _a[0], setShowADModal = _a[1];
1965
1965
  var handleLogin = function () {
@@ -2006,7 +2006,7 @@ var ErrorFallback = function (_a) {
2006
2006
  var MFAEndpointUrlSchema = z.url("MFAEndpoint must be a valid URL");
2007
2007
  var MFAGate = function (_a) {
2008
2008
  var children = _a.children, _b = _a.fallback, fallback = _b === void 0 ? jsxRuntimeExports.jsx(LoadingSpinner, {}) : _b, _c = _a.loginComponent, LoginComponent = _c === void 0 ? DefaultLoginPage : _c, MFAEndpoint = _a.MFAEndpoint;
2009
- var context = useCAMSContext$1();
2009
+ var context = useCAMSContext();
2010
2010
  var validatedMFAEndpoint = React.useMemo(function () {
2011
2011
  var parsed = MFAEndpointUrlSchema.safeParse(MFAEndpoint);
2012
2012
  if (!parsed.success) {
@@ -2053,9 +2053,8 @@ exports.MFAGate = MFAGate;
2053
2053
  exports.MFAOptions = MFAOptions;
2054
2054
  exports.ProtectedRoute = ProtectedRoute;
2055
2055
  exports.UnifiedCAMSProvider = UnifiedCAMSProvider;
2056
- exports.setCookie = setCookie$1;
2057
2056
  exports.useCAMSAuth = useCAMSAuth;
2058
- exports.useCAMSContext = useCAMSContext$1;
2057
+ exports.useCAMSContext = useCAMSContext;
2059
2058
  exports.useCAMSMSALAuth = useCAMSMSALAuth;
2060
2059
  exports.useCAMSMSALContext = useCAMSMSALContext;
2061
2060
  exports.useCAMSPopupAuth = useCAMSPopupAuth;