@nibssplc/cams-sdk-react 1.0.0-rc.16 → 1.0.0-rc.18

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.
@@ -11,6 +11,7 @@ export interface UseCAMSMSALAuthOptions {
11
11
  appCode: string;
12
12
  allowedOrigins?: string[];
13
13
  MFAEndpoint?: string;
14
+ activeCookiePeriod?: number;
14
15
  }
15
16
  export interface UseCAMSMSALAuthReturn {
16
17
  login: () => Promise<void>;
@@ -27,5 +28,6 @@ export interface UseCAMSMSALAuthReturn {
27
28
  completeMFA: (data: UserValidatedResponse) => Promise<MFAResponse>;
28
29
  setRequiresMFA: React.Dispatch<React.SetStateAction<boolean>>;
29
30
  sendEmailOTP: () => Promise<boolean>;
31
+ activeCookiePeriod: number;
30
32
  }
31
33
  export declare function useCAMSMSALAuth(options: UseCAMSMSALAuthOptions): UseCAMSMSALAuthReturn;
package/dist/index.cjs.js CHANGED
@@ -383,6 +383,7 @@ function useCAMSAuth(options) {
383
383
  }
384
384
 
385
385
  var setCookie$1 = function (name, value, days) {
386
+ if (days === void 0) { days = 1; }
386
387
  var expires = new Date(Date.now() + days * 24 * 60 * 60 * 1000).toUTCString();
387
388
  document.cookie = "".concat(name, "=").concat(encodeURIComponent(value), "; expires=").concat(expires, "; path=/; samesite=Lax");
388
389
  };
@@ -561,7 +562,7 @@ function useCAMSMSALAuth(options) {
561
562
  case 4: return [2 /*return*/];
562
563
  }
563
564
  });
564
- }); }, [instance, scopes, options, inProgress]);
565
+ }); }, [instance, scopes, options.prompt, options.appCode, options.MFAEndpoint, options.onAuthSuccess, options.onAuthError, storageKey, inProgress]);
565
566
  var completeMFA = React.useCallback(function (data) { return __awaiter$1(_this, void 0, void 0, function () {
566
567
  return __generator$1(this, function (_a) {
567
568
  if (!mfaAuthenticator) {
@@ -577,7 +578,7 @@ function useCAMSMSALAuth(options) {
577
578
  accessToken: accessToken,
578
579
  idToken: idToken,
579
580
  }));
580
- setCookie$1("CAMS-MSAL-AUTH-SDK-PROFILE", JSON.stringify({ type: "AUTH_SUCCESS", userProfile: __assign({}, data) }), 1);
581
+ setCookie$1("CAMS-MSAL-AUTH-SDK-PROFILE", JSON.stringify({ type: "AUTH_SUCCESS", userProfile: __assign({}, data) }), options.activeCookiePeriod);
581
582
  setRequiresMFA(false);
582
583
  // Set requiresMFA to false after storage update
583
584
  camsSdk.Logger.debug("MFA completed successfully, storage updated", {
@@ -596,7 +597,7 @@ function useCAMSMSALAuth(options) {
596
597
  }
597
598
  return [2 /*return*/];
598
599
  });
599
- }); }, [mfaAuthenticator, accessToken, idToken, storageKey]);
600
+ }); }, [mfaAuthenticator, accessToken, idToken, storageKey, options.activeCookiePeriod]);
600
601
  var sendEmailOTP = React.useCallback(function () { return __awaiter$1(_this, void 0, void 0, function () {
601
602
  return __generator$1(this, function (_a) {
602
603
  switch (_a.label) {
@@ -653,6 +654,7 @@ function useCAMSMSALAuth(options) {
653
654
  completeMFA: completeMFA,
654
655
  sendEmailOTP: sendEmailOTP,
655
656
  setRequiresMFA: setRequiresMFA,
657
+ activeCookiePeriod: options.activeCookiePeriod || 1,
656
658
  };
657
659
  }
658
660
 
@@ -1246,7 +1248,9 @@ function ProtectedRoute(_a) {
1246
1248
 
1247
1249
  var CAMSMSALContext = React.createContext(null);
1248
1250
  var setCookie = function (name, value, days) {
1251
+ if (days === void 0) { days = 1; }
1249
1252
  var expires = new Date(Date.now() + days * 864e5).toUTCString();
1253
+ camsSdk.Logger.debug("Auth Cookie Expires >>>", { name: name, value: value, expires: expires });
1250
1254
  document.cookie = "".concat(name, "=").concat(encodeURIComponent(value), "; expires=").concat(expires, "; path=/; samesite=Lax");
1251
1255
  };
1252
1256
  var getCookie = function (name) {
@@ -1319,7 +1323,7 @@ function CAMSMSALProviderInner(_a) {
1319
1323
  React.useEffect(function () {
1320
1324
  if (typeof window !== "undefined") {
1321
1325
  if (userProfile) {
1322
- setCookie(profileStorageKey, JSON.stringify(userProfile), 1); // Store for 1 day
1326
+ setCookie(profileStorageKey, JSON.stringify(userProfile), auth.activeCookiePeriod); // Store for 1 day
1323
1327
  }
1324
1328
  else {
1325
1329
  deleteCookie(profileStorageKey);
@@ -1470,7 +1474,8 @@ function CAMSProviderCore(props) {
1470
1474
  userProfile,
1471
1475
  ]);
1472
1476
  var value = React.useMemo(function () {
1473
- return (__assign(__assign({}, auth), { logout: enhancedLogout, userProfile: userProfile, setUserProfile: setUserProfile, authMode: mode }));
1477
+ auth.logout; var authRest = __rest(auth, ["logout"]);
1478
+ return __assign(__assign({}, authRest), { logout: enhancedLogout, userProfile: userProfile, setUserProfile: setUserProfile, authMode: mode });
1474
1479
  }, [auth, userProfile, mode]);
1475
1480
  return jsxRuntimeExports.jsx(CAMSContext.Provider, { value: value, children: children });
1476
1481
  }