@nibssplc/cams-sdk-react 0.0.1-beta.64 → 0.0.1-beta.65

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
@@ -1210,7 +1210,7 @@ function CAMSProviderCore(props) {
1210
1210
  }, [mode, auth, userProfile]);
1211
1211
  var value = useMemo(function () {
1212
1212
  return (__assign(__assign({}, auth), { logout: enhancedLogout, userProfile: userProfile, setUserProfile: setUserProfile, authMode: mode }));
1213
- }, [auth, userProfile, mode]);
1213
+ }, [auth, userProfile, mode, mode === "MSAL" && "requiresMFA" in auth ? auth.requiresMFA : null]);
1214
1214
  return jsxRuntimeExports.jsx(CAMSContext.Provider, { value: value, children: children });
1215
1215
  }
1216
1216
  function UnifiedCAMSProvider(props) {
@@ -1717,33 +1717,54 @@ var MFAOptions = function (_a) {
1717
1717
  var _d = useState(false), otpVisible = _d[0], setOtpVisible = _d[1];
1718
1718
  var _e = useState(false), showSuccessAnimation = _e[0], setShowSuccessAnimation = _e[1];
1719
1719
  var _f = useState(null), authType = _f[0], setAuthType = _f[1];
1720
+ var _g = useState(""), lastOTPCode = _g[0], setLastOTPCode = _g[1];
1720
1721
  var context = useCAMSContext();
1721
- var sendEmailOTP = (context.authMode === "MSAL" && "sendEmailOTP" in context
1722
+ var _h = context.authMode === "MSAL" && "sendEmailOTP" in context
1722
1723
  ? context
1723
- : { sendEmailOTP: null }).sendEmailOTP;
1724
+ : { sendEmailOTP: null, completeMFA: null }, sendEmailOTP = _h.sendEmailOTP, completeMFA = _h.completeMFA;
1724
1725
  var accessToken = context.authMode === "MSAL" ? context.accessToken : "";
1725
1726
  var idToken = context.authMode === "MSAL" ? context.idToken : "";
1726
- var _g = useOTPHandler({
1727
+ var _j = useOTPHandler({
1727
1728
  accessToken: accessToken || "",
1728
1729
  idToken: idToken || "",
1729
1730
  provider: "MSAL",
1730
1731
  appCode: context.appCode || "",
1731
1732
  authenticationType: authType,
1732
1733
  MFAEndpoint: MFAEndpoint,
1733
- onAuthComplete: function (state, data) {
1734
- if (state) {
1735
- setShowSuccessAnimation(true);
1736
- toast.success(jsxRuntimeExports.jsxs("div", { className: "flex items-center gap-2 text-sm text-green-600 bg-green-50 p-3 rounded-lg", children: [jsxRuntimeExports.jsx(ShieldCheck, { className: "w-4 h-4" }), jsxRuntimeExports.jsx("span", { children: "Multi-Factor Authentication Successful" })] }));
1737
- setTimeout(function () { return onComplete === null || onComplete === void 0 ? void 0 : onComplete(true); }, 2000);
1738
- }
1739
- else {
1740
- toast.error(jsxRuntimeExports.jsxs("div", { className: "flex items-center gap-2 text-sm text-red-600 bg-red-50 p-3 rounded-lg", children: [jsxRuntimeExports.jsx(ShieldClose, { className: "w-4 h-4" }), jsxRuntimeExports.jsx("span", { children: (data === null || data === void 0 ? void 0 : data.message) || "Invalid code. Please try again." })] }));
1741
- if (isMaxAttemptsReached) {
1742
- setTimeout(function () { return onComplete === null || onComplete === void 0 ? void 0 : onComplete(false); }, 1000);
1734
+ onAuthComplete: function (state, data) { return __awaiter(void 0, void 0, void 0, function () {
1735
+ var error_1;
1736
+ return __generator(this, function (_a) {
1737
+ switch (_a.label) {
1738
+ case 0:
1739
+ if (!state) return [3 /*break*/, 5];
1740
+ if (!(completeMFA && authType && lastOTPCode)) return [3 /*break*/, 4];
1741
+ _a.label = 1;
1742
+ case 1:
1743
+ _a.trys.push([1, 3, , 4]);
1744
+ return [4 /*yield*/, completeMFA(lastOTPCode, authType)];
1745
+ case 2:
1746
+ _a.sent();
1747
+ return [3 /*break*/, 4];
1748
+ case 3:
1749
+ error_1 = _a.sent();
1750
+ console.error("Failed to complete MFA:", error_1);
1751
+ return [3 /*break*/, 4];
1752
+ case 4:
1753
+ setShowSuccessAnimation(true);
1754
+ toast.success(jsxRuntimeExports.jsxs("div", { className: "flex items-center gap-2 text-sm text-green-600 bg-green-50 p-3 rounded-lg", children: [jsxRuntimeExports.jsx(ShieldCheck, { className: "w-4 h-4" }), jsxRuntimeExports.jsx("span", { children: "Multi-Factor Authentication Successful" })] }));
1755
+ setTimeout(function () { return onComplete === null || onComplete === void 0 ? void 0 : onComplete(true); }, 2000);
1756
+ return [3 /*break*/, 6];
1757
+ case 5:
1758
+ toast.error(jsxRuntimeExports.jsxs("div", { className: "flex items-center gap-2 text-sm text-red-600 bg-red-50 p-3 rounded-lg", children: [jsxRuntimeExports.jsx(ShieldClose, { className: "w-4 h-4" }), jsxRuntimeExports.jsx("span", { children: (data === null || data === void 0 ? void 0 : data.message) || "Invalid code. Please try again." })] }));
1759
+ if (isMaxAttemptsReached) {
1760
+ setTimeout(function () { return onComplete === null || onComplete === void 0 ? void 0 : onComplete(false); }, 1000);
1761
+ }
1762
+ _a.label = 6;
1763
+ case 6: return [2 /*return*/];
1743
1764
  }
1744
- }
1745
- },
1746
- }), handleSubmitOTP = _g.handleSubmitOTP, loading = _g.loading, setLoading = _g.setLoading, attemptCount = _g.attemptCount, remainingAttempts = _g.remainingAttempts, isMaxAttemptsReached = _g.isMaxAttemptsReached, resetAttempts = _g.resetAttempts;
1765
+ });
1766
+ }); },
1767
+ }), handleSubmitOTP = _j.handleSubmitOTP, loading = _j.loading, setLoading = _j.setLoading, attemptCount = _j.attemptCount, remainingAttempts = _j.remainingAttempts, isMaxAttemptsReached = _j.isMaxAttemptsReached, resetAttempts = _j.resetAttempts;
1747
1768
  var handleGoBack = function () {
1748
1769
  setAuthType(null);
1749
1770
  setOtpVisible(false);
@@ -1752,9 +1773,9 @@ var MFAOptions = function (_a) {
1752
1773
  };
1753
1774
  // Show success animation if authentication is successful
1754
1775
  if (showSuccessAnimation) {
1755
- return (jsxRuntimeExports.jsx(Card, { className: "mx-auto space-y-6 p-6 bg-white rounded-lg shadow-md", children: jsxRuntimeExports.jsx(AuthSuccessAnimation, { onComplete: function () {
1756
- // Animation completed, can add additional logic here if needed
1757
- } }) }));
1776
+ return (jsxRuntimeExports.jsx("div", { className: "flex justify-center items-center h-dvh", children: jsxRuntimeExports.jsx(Card, { className: "mx-auto space-y-6 p-6 bg-white rounded-lg shadow-md", children: jsxRuntimeExports.jsx(AuthSuccessAnimation, { onComplete: function () {
1777
+ // Animation completed, can add additional logic here if needed
1778
+ } }) }) }));
1758
1779
  }
1759
1780
  var content = jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, {});
1760
1781
  if (!authType) {
@@ -1790,10 +1811,16 @@ var MFAOptions = function (_a) {
1790
1811
  setAuthType(null);
1791
1812
  setOtpVisible(false);
1792
1813
  setValue("");
1793
- }, children: [jsxRuntimeExports.jsx(DialogHeader, { children: jsxRuntimeExports.jsx(DialogTitle, { children: "Email OTP" }) }), jsxRuntimeExports.jsx(DialogContent, { className: "sm:max-w-[425px]", children: jsxRuntimeExports.jsxs("div", { className: "space-y-4", children: [jsxRuntimeExports.jsx(GenericOTPVerifier, { value: value, setValue: setValue, isDisabled: loading || isMaxAttemptsReached, onChangeOTP: handleSubmitOTP, fieldName: "EmailOTP", attemptCount: attemptCount, remainingAttempts: remainingAttempts, isMaxAttemptsReached: isMaxAttemptsReached }), jsxRuntimeExports.jsx(Button, { variant: "ghost", className: "w-full text-sm", onClick: handleGoBack, children: "\u2190 Choose different method" })] }) })] }));
1814
+ }, children: [jsxRuntimeExports.jsx(DialogHeader, { children: jsxRuntimeExports.jsx(DialogTitle, { children: "Email OTP" }) }), jsxRuntimeExports.jsx(DialogContent, { className: "sm:max-w-[425px]", children: jsxRuntimeExports.jsxs("div", { className: "space-y-4", children: [jsxRuntimeExports.jsx(GenericOTPVerifier, { value: value, setValue: setValue, isDisabled: loading || isMaxAttemptsReached, onChangeOTP: function (code) {
1815
+ setLastOTPCode(code);
1816
+ return handleSubmitOTP(code);
1817
+ }, fieldName: "EmailOTP", attemptCount: attemptCount, remainingAttempts: remainingAttempts, isMaxAttemptsReached: isMaxAttemptsReached }), jsxRuntimeExports.jsx(Button, { variant: "ghost", className: "w-full text-sm", onClick: handleGoBack, children: "\u2190 Choose different method" })] }) })] }));
1794
1818
  }
1795
1819
  else if (authType === "AuthenticatorCode") {
1796
- content = (jsxRuntimeExports.jsxs(Dialog, { open: otpVisible, onOpenChange: handleGoBack, children: [jsxRuntimeExports.jsx(DialogHeader, { children: jsxRuntimeExports.jsx(DialogTitle, { children: "Authenticator App" }) }), jsxRuntimeExports.jsx(DialogContent, { className: "sm:max-w-[425px]", children: loading ? (jsxRuntimeExports.jsx("div", { className: "p-3 flex justify-center items-center", children: jsxRuntimeExports.jsx(LoadingSpinner, {}) })) : (jsxRuntimeExports.jsxs("div", { className: "space-y-4", children: [jsxRuntimeExports.jsx("p", { className: "text-sm text-gray-600 text-center", children: "Enter the 6-digit Code from your Authenticator app" }), jsxRuntimeExports.jsx(GenericOTPVerifier, { value: value, setValue: setValue, isDisabled: loading || isMaxAttemptsReached, onChangeOTP: handleSubmitOTP, fieldName: "AuthenticatorCode", attemptCount: attemptCount, remainingAttempts: remainingAttempts, isMaxAttemptsReached: isMaxAttemptsReached })] })) })] }));
1820
+ content = (jsxRuntimeExports.jsxs(Dialog, { open: otpVisible, onOpenChange: handleGoBack, children: [jsxRuntimeExports.jsx(DialogHeader, { children: jsxRuntimeExports.jsx(DialogTitle, { children: "Authenticator App" }) }), jsxRuntimeExports.jsx(DialogContent, { className: "sm:max-w-[425px]", children: loading ? (jsxRuntimeExports.jsx("div", { className: "p-3 flex justify-center items-center", children: jsxRuntimeExports.jsx(LoadingSpinner, {}) })) : (jsxRuntimeExports.jsxs("div", { className: "space-y-4", children: [jsxRuntimeExports.jsx("p", { className: "text-sm text-gray-600 text-center", children: "Enter the 6-digit Code from your Authenticator app" }), jsxRuntimeExports.jsx(GenericOTPVerifier, { value: value, setValue: setValue, isDisabled: loading || isMaxAttemptsReached, onChangeOTP: function (code) {
1821
+ setLastOTPCode(code);
1822
+ return handleSubmitOTP(code);
1823
+ }, fieldName: "AuthenticatorCode", attemptCount: attemptCount, remainingAttempts: remainingAttempts, isMaxAttemptsReached: isMaxAttemptsReached })] })) })] }));
1797
1824
  }
1798
1825
  return (jsxRuntimeExports.jsx("div", { className: "flex justify-center items-center h-dvh", children: jsxRuntimeExports.jsxs(Card, { className: "mx-auto space-y-6 p-6 bg-white rounded-lg shadow-md", children: [jsxRuntimeExports.jsxs(CardHeader, { children: [jsxRuntimeExports.jsx("div", { className: "flex justify-center items", children: jsxRuntimeExports.jsx("img", { src: OTPAuthenticationImg, alt: "NIBSS Logo", width: 365, height: 365 }) }), jsxRuntimeExports.jsx(CardTitle, { className: "text-3xl font-bold mb-6 text-center", children: "Two-Factor Authentication" }), jsxRuntimeExports.jsx(CardTitle, { className: "text-gray-300 text-base -tracking-wide text-center", children: "Your Microsoft account has been validated. Please complete two-factor authentication to continue." })] }), jsxRuntimeExports.jsx(CardContent, { className: "max-w-[80%]", children: content }), jsxRuntimeExports.jsxs(CardFooter, { className: "flex items-center justify-center mt-6 space-x-2 text-gray-400 text-sm", children: [jsxRuntimeExports.jsx(ShieldCheck, { className: "w-4 h-4 text-[#506f4a] pulse-glow" }), jsxRuntimeExports.jsx("span", { children: "Powered By NIBSS" })] })] }) }));
1799
1826
  };