@nibssplc/cams-sdk-react 1.0.0-rc.127 → 1.0.0-rc.130

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.
@@ -10,6 +10,7 @@ export interface UseCAMSMSALAuthOptions {
10
10
  allowedOrigins?: string[];
11
11
  ValidateUserEndpoint: string;
12
12
  activeCookiePeriod?: number;
13
+ DisableCAMSUserProfileValidation?: boolean;
13
14
  }
14
15
  export interface UseCAMSMSALAuthReturn {
15
16
  login: () => Promise<void>;
package/dist/index.cjs.js CHANGED
@@ -412,52 +412,61 @@ if (typeof window !== "undefined" && !((_a = window.crypto) === null || _a === v
412
412
 
413
413
  function useCAMSMSALAuth(options) {
414
414
  var _this = this;
415
- var optStorageKey = options.storageKey, optScopes = options.scopes, prompt = options.prompt, appCode = options.appCode, ValidateUserEndpoint = options.ValidateUserEndpoint, _a = options.activeCookiePeriod, activeCookiePeriod = _a === void 0 ? 1 : _a;
415
+ var optStorageKey = options.storageKey, optScopes = options.scopes, prompt = options.prompt, appCode = options.appCode, ValidateUserEndpoint = options.ValidateUserEndpoint, _a = options.activeCookiePeriod, activeCookiePeriod = _a === void 0 ? 1 : _a, _b = options.DisableCAMSUserProfileValidation, DisableCAMSUserProfileValidation = _b === void 0 ? false : _b;
416
416
  var storageKey = optStorageKey || "CAMS-MSAL-AUTH-SDK";
417
- var _b = msalReact.useMsal(), instance = _b.instance, inProgress = _b.inProgress, accounts = _b.accounts;
417
+ var _c = msalReact.useMsal(), instance = _c.instance, inProgress = _c.inProgress, accounts = _c.accounts;
418
418
  var account = msalReact.useAccount(accounts[0] || {});
419
- var _c = React.useState(null), error = _c[0], setError = _c[1];
420
- var _d = React.useState(""), idToken = _d[0], setIdToken = _d[1];
421
- var _e = React.useState(""), accessToken = _e[0], setAccessToken = _e[1];
422
- var _f = React.useState(""), email = _f[0], setEmail = _f[1];
423
- var _g = React.useState(false), requiresMFA = _g[0], setRequiresMFA = _g[1];
424
- var _h = React.useState(false), isFetchingMFAConfig = _h[0], setIsFetchingMFAConfig = _h[1];
419
+ var _d = React.useState(null), error = _d[0], setError = _d[1];
420
+ var _e = React.useState(""), idToken = _e[0], setIdToken = _e[1];
421
+ var _f = React.useState(""), accessToken = _f[0], setAccessToken = _f[1];
422
+ var _g = React.useState(""), email = _g[0], setEmail = _g[1];
423
+ var _h = React.useState(false), requiresMFA = _h[0], setRequiresMFA = _h[1];
424
+ var _j = React.useState(false), isFetchingMFAConfig = _j[0], setIsFetchingMFAConfig = _j[1];
425
425
  var isLoading = inProgress !== msalBrowser.InteractionStatus.None || isFetchingMFAConfig;
426
426
  var isAuthenticated = !!account && !!accessToken && !requiresMFA;
427
427
  var scopes = optScopes || ["openid", "profile", "email"];
428
428
  var login = React.useCallback(function () { return __awaiter$1(_this, void 0, void 0, function () {
429
- var response, authenticator, userConfig, camsError, error_1, err_1, camsError_1, camsError;
430
- var _a, _b;
431
- return __generator$1(this, function (_c) {
432
- switch (_c.label) {
429
+ var response, authenticator, email_1, userConfig, camsError, error_1, err_1, camsError_1, camsError;
430
+ var _a, _b, _c, _d;
431
+ return __generator$1(this, function (_e) {
432
+ switch (_e.label) {
433
433
  case 0:
434
434
  if (inProgress !== msalBrowser.InteractionStatus.None) {
435
- camsSdk.Logger.warn("Authentication already in progress, ignoring duplicate call");
435
+ camsSdk.Logger.warn("Authentication Already in Progress, Ignoring Duplicate Call");
436
436
  return [2 /*return*/];
437
437
  }
438
438
  setError(null);
439
- _c.label = 1;
439
+ _e.label = 1;
440
440
  case 1:
441
- _c.trys.push([1, 7, , 8]);
441
+ _e.trys.push([1, 8, , 9]);
442
442
  return [4 /*yield*/, instance.loginPopup({
443
443
  scopes: scopes,
444
444
  prompt: prompt || "login",
445
445
  })];
446
446
  case 2:
447
- response = _c.sent();
447
+ response = _e.sent();
448
448
  authenticator = new camsSdk.CAMSMFAAuthenticator();
449
- setIsFetchingMFAConfig(true);
450
- _c.label = 3;
449
+ if (!DisableCAMSUserProfileValidation) return [3 /*break*/, 3];
450
+ email_1 = ((_a = response.account) === null || _a === void 0 ? void 0 : _a.username) || ((_b = response.idTokenClaims) === null || _b === void 0 ? void 0 : _b.preferred_username) || "";
451
+ setAccessToken(response.accessToken);
452
+ setIdToken(response.idToken);
453
+ setEmail(email_1);
454
+ setRequiresMFA(false);
455
+ camsSdk.Logger.info("CAMS User Profile Validation Disabled. Skipping MFA config fetch.");
456
+ return [3 /*break*/, 7];
451
457
  case 3:
452
- _c.trys.push([3, 5, , 6]);
458
+ setIsFetchingMFAConfig(true);
459
+ _e.label = 4;
460
+ case 4:
461
+ _e.trys.push([4, 6, , 7]);
453
462
  return [4 /*yield*/, authenticator.GetUserMFAConfig({
454
463
  accessToken: response.accessToken,
455
464
  idToken: response.idToken,
456
465
  provider: "MSAL",
457
466
  APIAuthEndpoint: ValidateUserEndpoint,
458
467
  })];
459
- case 4:
460
- userConfig = _c.sent();
468
+ case 5:
469
+ userConfig = _e.sent();
461
470
  setIsFetchingMFAConfig(false);
462
471
  camsSdk.Logger.info("CAMS MFA Authenticator initialized. MSAL User Auth is Completed...", {
463
472
  userConfig: userConfig,
@@ -472,14 +481,14 @@ function useCAMSMSALAuth(options) {
472
481
  }
473
482
  else {
474
483
  camsError = new camsSdk.CAMSError(camsSdk.CAMSErrorType.API_VALIDATION_ERROR, "Login failed: " + userConfig.message);
475
- sonner.toast.error((_a = userConfig.message) !== null && _a !== void 0 ? _a : "Login failed");
484
+ sonner.toast.error((_c = userConfig.message) !== null && _c !== void 0 ? _c : "Login failed");
476
485
  camsSdk.Logger.error("Login failed: " + userConfig.message);
477
486
  setError(camsError);
478
487
  setIsFetchingMFAConfig(false);
479
488
  }
480
- return [3 /*break*/, 6];
481
- case 5:
482
- error_1 = _c.sent();
489
+ return [3 /*break*/, 7];
490
+ case 6:
491
+ error_1 = _e.sent();
483
492
  if (error_1 instanceof camsSdk.CAMSError &&
484
493
  error_1.type === camsSdk.CAMSErrorType.NETWORK_ERROR) {
485
494
  sonner.toast.error(error_1.message);
@@ -488,10 +497,10 @@ function useCAMSMSALAuth(options) {
488
497
  setIsFetchingMFAConfig(false);
489
498
  return [2 /*return*/];
490
499
  }
491
- return [3 /*break*/, 6];
492
- case 6: return [3 /*break*/, 8];
493
- case 7:
494
- err_1 = _c.sent();
500
+ return [3 /*break*/, 7];
501
+ case 7: return [3 /*break*/, 9];
502
+ case 8:
503
+ err_1 = _e.sent();
495
504
  // Handle interaction_in_progress error
496
505
  if (err_1.errorCode === "interaction_in_progress") {
497
506
  camsSdk.Logger.warn("Interaction already in progress, please wait");
@@ -507,7 +516,7 @@ function useCAMSMSALAuth(options) {
507
516
  }
508
517
  // If popup is blocked
509
518
  if (err_1.errorCode === "popup_window_error" ||
510
- ((_b = err_1.message) === null || _b === void 0 ? void 0 : _b.includes("popup"))) {
519
+ ((_d = err_1.message) === null || _d === void 0 ? void 0 : _d.includes("popup"))) {
511
520
  camsError_1 = new camsSdk.CAMSError(camsSdk.CAMSErrorType.POPUP_BLOCKED, "Popup blocked by browser. Please allow popups and try again.");
512
521
  sonner.toast.error(camsError_1.message);
513
522
  setError(camsError_1);
@@ -516,8 +525,8 @@ function useCAMSMSALAuth(options) {
516
525
  camsError = new camsSdk.CAMSError(camsSdk.CAMSErrorType.API_VALIDATION_ERROR, "Login failed: " + err_1.message || err_1);
517
526
  setError(camsError);
518
527
  setIsFetchingMFAConfig(false);
519
- return [3 /*break*/, 8];
520
- case 8: return [2 /*return*/];
528
+ return [3 /*break*/, 9];
529
+ case 9: return [2 /*return*/];
521
530
  }
522
531
  });
523
532
  }); }, [
@@ -528,6 +537,7 @@ function useCAMSMSALAuth(options) {
528
537
  ValidateUserEndpoint,
529
538
  storageKey,
530
539
  inProgress,
540
+ DisableCAMSUserProfileValidation,
531
541
  ]);
532
542
  var completeMFA = React.useCallback(function (data) { return __awaiter$1(_this, void 0, void 0, function () {
533
543
  return __generator$1(this, function (_a) {