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