@nibssplc/cams-sdk-react 1.0.0-rc.47 → 1.0.0-rc.48

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
@@ -413,7 +413,7 @@ var deleteCookie = function (name) {
413
413
 
414
414
  function useCAMSMSALAuth(options) {
415
415
  var _this = this;
416
- 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;
416
+ var optStorageKey = options.storageKey, optScopes = options.scopes, prompt = options.prompt, appCode = options.appCode, MFAEndpoint = options.MFAEndpoint, _a = options.activeCookiePeriod, activeCookiePeriod = _a === void 0 ? 1 : _a;
417
417
  var storageKey = optStorageKey || "CAMS-MSAL-AUTH-SDK";
418
418
  var _b = useMsal(), instance = _b.instance, inProgress = _b.inProgress, accounts = _b.accounts;
419
419
  var account = useAccount(accounts[0] || {});
@@ -542,10 +542,6 @@ function useCAMSMSALAuth(options) {
542
542
  idToken: response.idToken,
543
543
  }));
544
544
  }
545
- onAuthSuccess === null || onAuthSuccess === void 0 ? void 0 : onAuthSuccess({
546
- accessToken: response.accessToken,
547
- idToken: response.idToken,
548
- });
549
545
  return [3 /*break*/, 4];
550
546
  case 3:
551
547
  err_1 = _b.sent();
@@ -565,12 +561,10 @@ function useCAMSMSALAuth(options) {
565
561
  ((_a = err_1.message) === null || _a === void 0 ? void 0 : _a.includes("popup"))) {
566
562
  camsError_1 = new CAMSError(CAMSErrorType.POPUP_BLOCKED, "Popup blocked by browser. Please allow popups and try again.");
567
563
  setError(camsError_1);
568
- onAuthError === null || onAuthError === void 0 ? void 0 : onAuthError(camsError_1);
569
564
  return [2 /*return*/];
570
565
  }
571
566
  camsError = new CAMSError(CAMSErrorType.API_VALIDATION_ERROR, "Login failed: " + err_1.message || err_1);
572
567
  setError(camsError);
573
- onAuthError === null || onAuthError === void 0 ? void 0 : onAuthError(camsError);
574
568
  return [3 /*break*/, 4];
575
569
  case 4: return [2 /*return*/];
576
570
  }
@@ -581,8 +575,6 @@ function useCAMSMSALAuth(options) {
581
575
  prompt,
582
576
  appCode,
583
577
  MFAEndpoint,
584
- onAuthSuccess,
585
- onAuthError,
586
578
  storageKey,
587
579
  inProgress,
588
580
  ]);
@@ -1475,8 +1467,8 @@ function CAMSProviderCore(props) {
1475
1467
  ]);
1476
1468
  var value = useMemo(function () {
1477
1469
  auth.logout; var authRest = __rest(auth, ["logout"]);
1478
- return __assign(__assign({}, authRest), { logout: enhancedLogout, userProfile: userProfile, setUserProfile: setUserProfile, authMode: mode });
1479
- }, [auth, userProfile, mode]);
1470
+ return __assign(__assign({}, authRest), { logout: enhancedLogout, userProfile: userProfile, setUserProfile: setUserProfile, authMode: mode, onAuthSuccess: mode === "MSAL" ? props.onAuthSuccess : undefined, onAuthError: mode === "MSAL" ? props.onAuthError : undefined });
1471
+ }, [auth, userProfile, mode, props]);
1480
1472
  return jsxRuntimeExports.jsx(CAMSContext.Provider, { value: value, children: children });
1481
1473
  }
1482
1474
  function UnifiedCAMSProvider(props) {
@@ -2397,7 +2389,7 @@ var MFAGate = function (_a) {
2397
2389
  // loginComponent: LoginComponent = DefaultLoginPage,
2398
2390
  _c = _a.usePassKey,
2399
2391
  // loginComponent: LoginComponent = DefaultLoginPage,
2400
- usePassKey = _c === void 0 ? false : _c, _d = _a.useADLogin, useADLogin = _d === void 0 ? false : _d, CredentialsAuthEndpoint = _a.CredentialsAuthEndpoint, PassKeysRegisterProps = _a.PassKeysRegisterProps, MFAEndpoints = _a.MFAEndpoints;
2392
+ usePassKey = _c === void 0 ? false : _c, _d = _a.useADLogin, useADLogin = _d === void 0 ? false : _d, CredentialsAuthEndpoint = _a.CredentialsAuthEndpoint, PassKeysRegisterProps = _a.PassKeysRegisterProps, MFAEndpoints = _a.MFAEndpoints, requiresMFA = _a.requiresMFA;
2401
2393
  var context = useCAMSContext();
2402
2394
  var validatedMFAEndpoints = useMemo(function () {
2403
2395
  var parsed = MFAEndpointsSchema.safeParse(MFAEndpoints);
@@ -2408,19 +2400,32 @@ var MFAGate = function (_a) {
2408
2400
  return parsed.data;
2409
2401
  }, [MFAEndpoints]);
2410
2402
  var handleComplete = useCallback(function (success) {
2411
- if (!success)
2403
+ var _a;
2404
+ if (success && context.authMode === "MSAL") {
2405
+ (_a = context.onAuthSuccess) === null || _a === void 0 ? void 0 : _a.call(context, {
2406
+ accessToken: context.accessToken,
2407
+ idToken: context.idToken,
2408
+ });
2409
+ }
2410
+ else if (!success) {
2412
2411
  Logger.error("MFA authentication failed");
2413
- }, []);
2412
+ }
2413
+ }, [context]);
2414
2414
  var handleAuthFailed = useCallback(function () { return __awaiter$1(void 0, void 0, void 0, function () {
2415
- return __generator$1(this, function (_a) {
2416
- switch (_a.label) {
2417
- case 0: return [4 /*yield*/, context.logout()];
2415
+ var _a;
2416
+ return __generator$1(this, function (_b) {
2417
+ switch (_b.label) {
2418
+ case 0:
2419
+ if (context.authMode === "MSAL" && context.error) {
2420
+ (_a = context.onAuthError) === null || _a === void 0 ? void 0 : _a.call(context, context.error);
2421
+ }
2422
+ return [4 /*yield*/, context.logout()];
2418
2423
  case 1:
2419
- _a.sent();
2424
+ _b.sent();
2420
2425
  return [2 /*return*/];
2421
2426
  }
2422
2427
  });
2423
- }); }, [context.logout]);
2428
+ }); }, [context]);
2424
2429
  if (useADLogin && !CredentialsAuthEndpoint)
2425
2430
  return jsxRuntimeExports.jsx(ErrorFallback, { message: "Invalid AD Login Configuration." });
2426
2431
  if (!validatedMFAEndpoints)
@@ -2429,7 +2434,8 @@ var MFAGate = function (_a) {
2429
2434
  return jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: children });
2430
2435
  if (context.isLoading)
2431
2436
  return fallback;
2432
- if (context.requiresMFA) {
2437
+ var shouldRequireMFA = requiresMFA !== null && requiresMFA !== void 0 ? requiresMFA : context.requiresMFA;
2438
+ if (shouldRequireMFA) {
2433
2439
  return (jsxRuntimeExports.jsx(MFAOptions, { MFAEndpoints: validatedMFAEndpoints, usePassKey: usePassKey, onComplete: handleComplete, onAuthFailed: handleAuthFailed }));
2434
2440
  }
2435
2441
  if (!context.isAuthenticated) {