@nibssplc/cams-sdk-react 1.0.0-rc.17 → 1.0.0-rc.19

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
@@ -383,17 +383,18 @@ var deleteCookie$1 = function (name) {
383
383
 
384
384
  function useCAMSMSALAuth(options) {
385
385
  var _this = this;
386
- var storageKey = options.storageKey || "CAMS-MSAL-AUTH-SDK";
387
- var _a = useMsal(), instance = _a.instance, inProgress = _a.inProgress, accounts = _a.accounts;
386
+ var optStorageKey = options.storageKey, optScopes = options.scopes, prompt = options.prompt, appCode = options.appCode, MFAEndpoint = options.MFAEndpoint, onAuthSuccess = options.onAuthSuccess, onAuthError = options.onAuthError, _a = options.activeCookiePeriod, activeCookiePeriod = _a === void 0 ? 1 : _a;
387
+ var storageKey = optStorageKey || "CAMS-MSAL-AUTH-SDK";
388
+ var _b = useMsal(), instance = _b.instance, inProgress = _b.inProgress, accounts = _b.accounts;
388
389
  var account = useAccount(accounts[0] || {});
389
- var _b = useState(null), error = _b[0], setError = _b[1];
390
- var _c = useState(""), idToken = _c[0], setIdToken = _c[1];
391
- var _d = useState(""), accessToken = _d[0], setAccessToken = _d[1];
392
- var _e = useState(null), mfaAuthenticator = _e[0], setMfaAuthenticator = _e[1];
393
- var _f = useState(false), requiresMFA = _f[0], setRequiresMFA = _f[1];
390
+ var _c = useState(null), error = _c[0], setError = _c[1];
391
+ var _d = useState(""), idToken = _d[0], setIdToken = _d[1];
392
+ var _e = useState(""), accessToken = _e[0], setAccessToken = _e[1];
393
+ var _f = useState(null), mfaAuthenticator = _f[0], setMfaAuthenticator = _f[1];
394
+ var _g = useState(false), requiresMFA = _g[0], setRequiresMFA = _g[1];
394
395
  var isLoading = inProgress !== InteractionStatus.None;
395
396
  var isAuthenticated = !!account && !!accessToken && !requiresMFA;
396
- var scopes = options.scopes || ["openid", "profile", "email"];
397
+ var scopes = optScopes || ["openid", "profile", "email"];
397
398
  var isTokenValid = function (token) {
398
399
  try {
399
400
  var payload = JSON.parse(atob(token.split(".")[1]));
@@ -417,9 +418,9 @@ function useCAMSMSALAuth(options) {
417
418
  var mfaConfig = {
418
419
  accessToken: accessToken_1,
419
420
  idToken: idToken_1,
420
- appCode: options.appCode,
421
+ appCode: appCode,
421
422
  provider: "MSAL",
422
- apiEndpoint: options.MFAEndpoint,
423
+ apiEndpoint: MFAEndpoint,
423
424
  };
424
425
  var authenticator = new CAMSMFAAuthenticator(mfaConfig);
425
426
  setMfaAuthenticator(authenticator);
@@ -468,24 +469,24 @@ function useCAMSMSALAuth(options) {
468
469
  // }, []);
469
470
  var login = useCallback(function () { return __awaiter$1(_this, void 0, void 0, function () {
470
471
  var response, mfaConfig, authenticator, err_1, camsError_1, camsError;
471
- var _a, _b, _c, _d;
472
- return __generator$1(this, function (_e) {
473
- switch (_e.label) {
472
+ var _a;
473
+ return __generator$1(this, function (_b) {
474
+ switch (_b.label) {
474
475
  case 0:
475
476
  if (inProgress !== InteractionStatus.None) {
476
477
  Logger.warn("Authentication already in progress, ignoring duplicate call");
477
478
  return [2 /*return*/];
478
479
  }
479
480
  setError(null);
480
- _e.label = 1;
481
+ _b.label = 1;
481
482
  case 1:
482
- _e.trys.push([1, 3, , 4]);
483
+ _b.trys.push([1, 3, , 4]);
483
484
  return [4 /*yield*/, instance.loginPopup({
484
485
  scopes: scopes,
485
- prompt: options.prompt || "login",
486
+ prompt: prompt || "login",
486
487
  })];
487
488
  case 2:
488
- response = _e.sent();
489
+ response = _b.sent();
489
490
  console.log("Login Token response:", {
490
491
  accessToken: response.accessToken,
491
492
  idToken: response.idToken,
@@ -495,9 +496,9 @@ function useCAMSMSALAuth(options) {
495
496
  mfaConfig = {
496
497
  accessToken: response.accessToken,
497
498
  idToken: response.idToken,
498
- appCode: options.appCode,
499
+ appCode: appCode,
499
500
  provider: "MSAL",
500
- apiEndpoint: options.MFAEndpoint,
501
+ apiEndpoint: MFAEndpoint,
501
502
  };
502
503
  authenticator = new CAMSMFAAuthenticator(mfaConfig);
503
504
  setMfaAuthenticator(authenticator);
@@ -511,10 +512,10 @@ function useCAMSMSALAuth(options) {
511
512
  idToken: response.idToken,
512
513
  }));
513
514
  }
514
- (_a = options.onAuthSuccess) === null || _a === void 0 ? void 0 : _a.call(options, response.accessToken);
515
+ onAuthSuccess === null || onAuthSuccess === void 0 ? void 0 : onAuthSuccess(response.accessToken);
515
516
  return [3 /*break*/, 4];
516
517
  case 3:
517
- err_1 = _e.sent();
518
+ err_1 = _b.sent();
518
519
  // Handle interaction_in_progress error
519
520
  if (err_1.errorCode === "interaction_in_progress") {
520
521
  Logger.warn("Interaction already in progress, please wait");
@@ -528,20 +529,20 @@ function useCAMSMSALAuth(options) {
528
529
  }
529
530
  // If popup is blocked
530
531
  if (err_1.errorCode === "popup_window_error" ||
531
- ((_b = err_1.message) === null || _b === void 0 ? void 0 : _b.includes("popup"))) {
532
+ ((_a = err_1.message) === null || _a === void 0 ? void 0 : _a.includes("popup"))) {
532
533
  camsError_1 = new CAMSError(CAMSErrorType.POPUP_BLOCKED, "Popup blocked by browser. Please allow popups and try again.");
533
534
  setError(camsError_1);
534
- (_c = options.onAuthError) === null || _c === void 0 ? void 0 : _c.call(options, camsError_1);
535
+ onAuthError === null || onAuthError === void 0 ? void 0 : onAuthError(camsError_1);
535
536
  return [2 /*return*/];
536
537
  }
537
538
  camsError = new CAMSError(CAMSErrorType.API_VALIDATION_ERROR, "Login failed: " + err_1.message || err_1);
538
539
  setError(camsError);
539
- (_d = options.onAuthError) === null || _d === void 0 ? void 0 : _d.call(options, camsError);
540
+ onAuthError === null || onAuthError === void 0 ? void 0 : onAuthError(camsError);
540
541
  return [3 /*break*/, 4];
541
542
  case 4: return [2 /*return*/];
542
543
  }
543
544
  });
544
- }); }, [instance, scopes, options, inProgress]);
545
+ }); }, [instance, scopes, prompt, appCode, MFAEndpoint, onAuthSuccess, onAuthError, storageKey, inProgress]);
545
546
  var completeMFA = useCallback(function (data) { return __awaiter$1(_this, void 0, void 0, function () {
546
547
  return __generator$1(this, function (_a) {
547
548
  if (!mfaAuthenticator) {
@@ -557,7 +558,7 @@ function useCAMSMSALAuth(options) {
557
558
  accessToken: accessToken,
558
559
  idToken: idToken,
559
560
  }));
560
- setCookie$1("CAMS-MSAL-AUTH-SDK-PROFILE", JSON.stringify({ type: "AUTH_SUCCESS", userProfile: __assign({}, data) }), options.activeCookiePeriod);
561
+ setCookie$1("CAMS-MSAL-AUTH-SDK-PROFILE", JSON.stringify({ type: "AUTH_SUCCESS", userProfile: __assign({}, data) }), activeCookiePeriod);
561
562
  setRequiresMFA(false);
562
563
  // Set requiresMFA to false after storage update
563
564
  Logger.debug("MFA completed successfully, storage updated", {
@@ -576,7 +577,7 @@ function useCAMSMSALAuth(options) {
576
577
  }
577
578
  return [2 /*return*/];
578
579
  });
579
- }); }, [mfaAuthenticator, accessToken, idToken, storageKey]);
580
+ }); }, [mfaAuthenticator, accessToken, idToken, storageKey, activeCookiePeriod]);
580
581
  var sendEmailOTP = useCallback(function () { return __awaiter$1(_this, void 0, void 0, function () {
581
582
  return __generator$1(this, function (_a) {
582
583
  switch (_a.label) {
@@ -627,12 +628,13 @@ function useCAMSMSALAuth(options) {
627
628
  error: error,
628
629
  idToken: idToken,
629
630
  accessToken: accessToken,
630
- appCode: options.appCode,
631
+ appCode: appCode,
631
632
  mfaAuthenticator: mfaAuthenticator,
632
633
  requiresMFA: requiresMFA,
633
634
  completeMFA: completeMFA,
634
635
  sendEmailOTP: sendEmailOTP,
635
636
  setRequiresMFA: setRequiresMFA,
637
+ activeCookiePeriod: activeCookiePeriod,
636
638
  };
637
639
  }
638
640
 
@@ -1301,7 +1303,7 @@ function CAMSMSALProviderInner(_a) {
1301
1303
  useEffect(function () {
1302
1304
  if (typeof window !== "undefined") {
1303
1305
  if (userProfile) {
1304
- setCookie(profileStorageKey, JSON.stringify(userProfile), authOptions.activeCookiePeriod); // Store for 1 day
1306
+ setCookie(profileStorageKey, JSON.stringify(userProfile), auth.activeCookiePeriod); // Store for 1 day
1305
1307
  }
1306
1308
  else {
1307
1309
  deleteCookie(profileStorageKey);