@nibssplc/cams-sdk-react 0.0.1-beta.58 → 0.0.1-beta.60
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/components/ClientOnly.d.ts +2 -2
- package/dist/components/LoginButton.d.ts +2 -0
- package/dist/components/MFAGate.d.ts +2 -1
- package/dist/components/UnifiedCAMSProvider.d.ts +2 -1
- package/dist/index.cjs.js +69 -60
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.esm.js +70 -62
- package/dist/index.esm.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -7,5 +7,7 @@ export * from './components/ClientOnly';
|
|
|
7
7
|
export * from './components/UnifiedCAMSProvider';
|
|
8
8
|
export { default as MFAOptions } from './components/MFAOptions';
|
|
9
9
|
export { default as MFAGate } from './components/MFAGate';
|
|
10
|
+
export { default as LoginButton } from './components/LoginButton';
|
|
11
|
+
export { default as ClientOnly } from './components/ClientOnly';
|
|
10
12
|
export { useCAMSContext } from './context/CAMSContext';
|
|
11
13
|
export * from '@nibssplc/cams-sdk';
|
package/dist/index.esm.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import React__default, { useState, useRef, useEffect, useCallback, createContext, useContext, useMemo } from 'react';
|
|
3
|
-
import { isPopupWindow, initializePopupAuth, CAMSSessionManager, CAMSError, CAMSErrorType,
|
|
3
|
+
import { isPopupWindow, initializePopupAuth, CAMSSessionManager, Logger, CAMSError, CAMSErrorType, CAMSMFAAuthenticator } from '@nibssplc/cams-sdk';
|
|
4
4
|
export * from '@nibssplc/cams-sdk';
|
|
5
5
|
import { useMsal, useAccount, MsalProvider } from '@azure/msal-react';
|
|
6
6
|
import { InteractionStatus, PublicClientApplication } from '@azure/msal-browser';
|
|
@@ -310,74 +310,67 @@ function useCAMSMSALAuth(options) {
|
|
|
310
310
|
// handleRedirect();
|
|
311
311
|
// }, []);
|
|
312
312
|
var login = useCallback(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
313
|
-
var err_1, camsError_1, camsError;
|
|
314
|
-
var _a, _b, _c;
|
|
315
|
-
return __generator(this, function (
|
|
316
|
-
switch (
|
|
313
|
+
var response, mfaConfig, authenticator, err_1, camsError_1, camsError;
|
|
314
|
+
var _a, _b, _c, _d;
|
|
315
|
+
return __generator(this, function (_e) {
|
|
316
|
+
switch (_e.label) {
|
|
317
317
|
case 0:
|
|
318
318
|
setError(null);
|
|
319
|
-
|
|
319
|
+
_e.label = 1;
|
|
320
320
|
case 1:
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
// scopes,
|
|
324
|
-
// prompt: options.prompt || "login",
|
|
325
|
-
// });
|
|
326
|
-
return [4 /*yield*/, instance
|
|
327
|
-
.loginPopup({
|
|
321
|
+
_e.trys.push([1, 3, , 4]);
|
|
322
|
+
return [4 /*yield*/, instance.loginPopup({
|
|
328
323
|
scopes: scopes,
|
|
329
324
|
prompt: options.prompt || "login",
|
|
330
|
-
})
|
|
331
|
-
.then(function (response) {
|
|
332
|
-
var _a;
|
|
333
|
-
Logger.debug("Login Token response:", {
|
|
334
|
-
accessToken: response.accessToken,
|
|
335
|
-
idToken: response.idToken,
|
|
336
|
-
});
|
|
337
|
-
setAccessToken(response.accessToken);
|
|
338
|
-
setIdToken(response.idToken);
|
|
339
|
-
// Initialize MFA authenticator
|
|
340
|
-
var mfaConfig = {
|
|
341
|
-
accessToken: response.accessToken,
|
|
342
|
-
idToken: response.idToken,
|
|
343
|
-
appCode: options.appCode,
|
|
344
|
-
provider: "MSAL",
|
|
345
|
-
apiEndpoint: options.mfaApiEndpoint,
|
|
346
|
-
};
|
|
347
|
-
var authenticator = new CAMSMFAAuthenticator(mfaConfig);
|
|
348
|
-
setMfaAuthenticator(authenticator);
|
|
349
|
-
setRequiresMFA(true);
|
|
350
|
-
// Don't persist as authenticated until MFA is complete
|
|
351
|
-
if (typeof window !== "undefined") {
|
|
352
|
-
localStorage.setItem(options.storageKey, JSON.stringify({
|
|
353
|
-
isAuthenticated: false,
|
|
354
|
-
requiresMFA: true,
|
|
355
|
-
accessToken: response.accessToken,
|
|
356
|
-
idToken: response.idToken,
|
|
357
|
-
}));
|
|
358
|
-
}
|
|
359
|
-
(_a = options.onAuthSuccess) === null || _a === void 0 ? void 0 : _a.call(options, response.accessToken);
|
|
360
325
|
})];
|
|
361
326
|
case 2:
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
327
|
+
response = _e.sent();
|
|
328
|
+
Logger.debug("Login Token response:", {
|
|
329
|
+
accessToken: response.accessToken,
|
|
330
|
+
idToken: response.idToken,
|
|
331
|
+
});
|
|
332
|
+
setAccessToken(response.accessToken);
|
|
333
|
+
setIdToken(response.idToken);
|
|
334
|
+
mfaConfig = {
|
|
335
|
+
accessToken: response.accessToken,
|
|
336
|
+
idToken: response.idToken,
|
|
337
|
+
appCode: options.appCode,
|
|
338
|
+
provider: "MSAL",
|
|
339
|
+
apiEndpoint: options.mfaApiEndpoint,
|
|
340
|
+
};
|
|
341
|
+
authenticator = new CAMSMFAAuthenticator(mfaConfig);
|
|
342
|
+
setMfaAuthenticator(authenticator);
|
|
343
|
+
setRequiresMFA(true);
|
|
344
|
+
// Don't persist as authenticated until MFA is complete
|
|
345
|
+
if (typeof window !== "undefined") {
|
|
346
|
+
localStorage.setItem(options.storageKey, JSON.stringify({
|
|
347
|
+
isAuthenticated: false,
|
|
348
|
+
requiresMFA: true,
|
|
349
|
+
accessToken: response.accessToken,
|
|
350
|
+
idToken: response.idToken,
|
|
351
|
+
}));
|
|
352
|
+
}
|
|
353
|
+
(_a = options.onAuthSuccess) === null || _a === void 0 ? void 0 : _a.call(options, response.accessToken);
|
|
367
354
|
return [3 /*break*/, 4];
|
|
368
355
|
case 3:
|
|
369
|
-
err_1 =
|
|
356
|
+
err_1 = _e.sent();
|
|
357
|
+
// Handle user cancellation gracefully
|
|
358
|
+
if (err_1.errorCode === "user_cancelled") {
|
|
359
|
+
Logger.info("User cancelled login");
|
|
360
|
+
setError(null); // Don't treat cancellation as an error
|
|
361
|
+
return [2 /*return*/];
|
|
362
|
+
}
|
|
370
363
|
// If popup is blocked
|
|
371
364
|
if (err_1.errorCode === "popup_window_error" ||
|
|
372
|
-
((
|
|
373
|
-
camsError_1 = new CAMSError(CAMSErrorType.POPUP_BLOCKED, "
|
|
365
|
+
((_b = err_1.message) === null || _b === void 0 ? void 0 : _b.includes("popup"))) {
|
|
366
|
+
camsError_1 = new CAMSError(CAMSErrorType.POPUP_BLOCKED, "Popup blocked by browser. Please allow popups and try again.");
|
|
374
367
|
setError(camsError_1);
|
|
375
|
-
(
|
|
368
|
+
(_c = options.onAuthError) === null || _c === void 0 ? void 0 : _c.call(options, camsError_1);
|
|
376
369
|
return [2 /*return*/];
|
|
377
370
|
}
|
|
378
|
-
camsError = new CAMSError(CAMSErrorType.API_VALIDATION_ERROR, "Login failed: " + err_1);
|
|
371
|
+
camsError = new CAMSError(CAMSErrorType.API_VALIDATION_ERROR, "Login failed: " + err_1.message || err_1);
|
|
379
372
|
setError(camsError);
|
|
380
|
-
(
|
|
373
|
+
(_d = options.onAuthError) === null || _d === void 0 ? void 0 : _d.call(options, camsError);
|
|
381
374
|
return [3 /*break*/, 4];
|
|
382
375
|
case 4: return [2 /*return*/];
|
|
383
376
|
}
|
|
@@ -1082,7 +1075,7 @@ function useCAMSMSALContext() {
|
|
|
1082
1075
|
return context;
|
|
1083
1076
|
}
|
|
1084
1077
|
|
|
1085
|
-
function
|
|
1078
|
+
var ClientOnly = function (_a) {
|
|
1086
1079
|
var children = _a.children, _b = _a.fallback, fallback = _b === void 0 ? null : _b;
|
|
1087
1080
|
var _c = useState(false), hasMounted = _c[0], setHasMounted = _c[1];
|
|
1088
1081
|
useEffect(function () {
|
|
@@ -1092,7 +1085,7 @@ function ClientOnly(_a) {
|
|
|
1092
1085
|
return jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: fallback });
|
|
1093
1086
|
}
|
|
1094
1087
|
return jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: children });
|
|
1095
|
-
}
|
|
1088
|
+
};
|
|
1096
1089
|
|
|
1097
1090
|
var CAMSContext = createContext(null);
|
|
1098
1091
|
function useCAMSContext() {
|
|
@@ -1123,7 +1116,7 @@ var getCookie = function (name) {
|
|
|
1123
1116
|
var deleteCookie = function (name) {
|
|
1124
1117
|
document.cookie = name + "=; Max-Age=-99999999; path=/";
|
|
1125
1118
|
};
|
|
1126
|
-
function
|
|
1119
|
+
function CAMSProviderCore(props) {
|
|
1127
1120
|
var _this = this;
|
|
1128
1121
|
var _a = props, children = _a.children, mode = _a.mode, appCode = _a.appCode, validateTokenUrl = _a.validateTokenUrl;
|
|
1129
1122
|
// Always call both hooks to satisfy Rules of Hooks
|
|
@@ -1219,9 +1212,9 @@ function UnifiedCAMSProvider(props) {
|
|
|
1219
1212
|
if (props.mode === "MSAL") {
|
|
1220
1213
|
var msalConfig = props.msalConfig, msalInstance = props.msalInstance;
|
|
1221
1214
|
var instance = msalInstance || new PublicClientApplication(msalConfig);
|
|
1222
|
-
return (jsxRuntimeExports.jsx(MsalProvider, { instance: instance, children: jsxRuntimeExports.jsx(
|
|
1215
|
+
return (jsxRuntimeExports.jsx(MsalProvider, { instance: instance, children: jsxRuntimeExports.jsx(CAMSProviderCore, __assign({}, props)) }));
|
|
1223
1216
|
}
|
|
1224
|
-
return jsxRuntimeExports.jsx(
|
|
1217
|
+
return (jsxRuntimeExports.jsx(ClientOnly, { fallback: jsxRuntimeExports.jsx("div", { children: "Loading..." }), children: jsxRuntimeExports.jsx(CAMSProviderCore, __assign({}, props)) }));
|
|
1225
1218
|
}
|
|
1226
1219
|
// Backward compatibility exports
|
|
1227
1220
|
var CAMSProvider = function (props) { return (jsxRuntimeExports.jsx(UnifiedCAMSProvider, __assign({}, props, { mode: "REGULAR" }))); };
|
|
@@ -1745,8 +1738,23 @@ var MFAOptions = function (_a) {
|
|
|
1745
1738
|
return (jsxRuntimeExports.jsxs(Card, { className: "mx-auto space-y-6 p-6 bg-white rounded-lg shadow-md", children: [jsxRuntimeExports.jsxs(CardHeader, { children: [jsxRuntimeExports.jsx("img", { src: "/OTPAuthentication1.svg", 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-sm -tracking-wide text-center", children: "Your Microsoft account has been validated. Please complete two-factor authentication to continue." })] }), jsxRuntimeExports.jsx(CardContent, { 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" })] })] }));
|
|
1746
1739
|
};
|
|
1747
1740
|
|
|
1741
|
+
var LoginButton = function () {
|
|
1742
|
+
var context = useCAMSContext();
|
|
1743
|
+
var login = context.login, isLoading = context.isLoading, error = context.error, authMode = context.authMode;
|
|
1744
|
+
var handleLogin = function () {
|
|
1745
|
+
if (authMode === "MSAL") {
|
|
1746
|
+
login();
|
|
1747
|
+
}
|
|
1748
|
+
else {
|
|
1749
|
+
// For regular mode, you'd need to provide CAMSConfig
|
|
1750
|
+
console.warn("Regular CAMS login requires configuration");
|
|
1751
|
+
}
|
|
1752
|
+
};
|
|
1753
|
+
return (jsxRuntimeExports.jsxs("div", { className: "flex flex-col items-center gap-4 p-6", children: [jsxRuntimeExports.jsx(Button, { onClick: handleLogin, disabled: isLoading, className: "min-w-[200px]", children: isLoading ? 'Logging in...' : 'Login with Microsoft' }), error && (jsxRuntimeExports.jsxs("p", { className: "text-red-600 text-sm text-center", children: ["Error: ", error.message] }))] }));
|
|
1754
|
+
};
|
|
1755
|
+
|
|
1748
1756
|
var MFAGate = function (_a) {
|
|
1749
|
-
var children = _a.children, fallback = _a.fallback;
|
|
1757
|
+
var children = _a.children, fallback = _a.fallback, LoginComponent = _a.loginComponent;
|
|
1750
1758
|
var context = useCAMSContext();
|
|
1751
1759
|
// Only apply MFA gate for MSAL mode
|
|
1752
1760
|
if (context.authMode !== "MSAL") {
|
|
@@ -1764,10 +1772,10 @@ var MFAGate = function (_a) {
|
|
|
1764
1772
|
} }));
|
|
1765
1773
|
}
|
|
1766
1774
|
if (!isAuthenticated) {
|
|
1767
|
-
return fallback || jsxRuntimeExports.jsx(
|
|
1775
|
+
return fallback || (LoginComponent ? jsxRuntimeExports.jsx(LoginComponent, {}) : jsxRuntimeExports.jsx(LoginButton, {}));
|
|
1768
1776
|
}
|
|
1769
1777
|
return jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: children });
|
|
1770
1778
|
};
|
|
1771
1779
|
|
|
1772
|
-
export { CAMSMSALProvider, CAMSProvider, ClientOnly, MFAGate, MFAOptions, ProtectedRoute, UnifiedCAMSProvider, useCAMSAuth, useCAMSContext, useCAMSMSALAuth, useCAMSMSALContext, useCAMSPopupAuth };
|
|
1780
|
+
export { CAMSMSALProvider, CAMSProvider, ClientOnly, LoginButton, MFAGate, MFAOptions, ProtectedRoute, UnifiedCAMSProvider, useCAMSAuth, useCAMSContext, useCAMSMSALAuth, useCAMSMSALContext, useCAMSPopupAuth };
|
|
1773
1781
|
//# sourceMappingURL=index.esm.js.map
|