@nibssplc/cams-sdk-react 0.0.1-beta.82 → 0.0.1-beta.84

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.
@@ -1,7 +1,7 @@
1
1
  interface ADLoginModalProps {
2
2
  open: boolean;
3
3
  onOpenChange: (open: boolean) => void;
4
- onLogin: (username: string, password: string, mfaCode: string) => Promise<void>;
4
+ onLogin: (credentials: Credentials) => Promise<void>;
5
5
  }
6
- export declare const ADLoginModal: ({ open, onOpenChange, onLogin }: ADLoginModalProps) => import("react/jsx-runtime").JSX.Element;
6
+ export declare const ADLoginModal: ({ open, onOpenChange, onLogin, }: ADLoginModalProps) => import("react/jsx-runtime").JSX.Element;
7
7
  export {};
@@ -1,8 +1,7 @@
1
1
  interface MFAGateProps {
2
2
  children: React.ReactNode;
3
3
  fallback?: React.ReactNode;
4
- loginComponent?: React.ComponentType;
5
4
  MFAEndpoint?: string;
6
5
  }
7
- declare const MFAGate: ({ children, fallback, loginComponent: LoginComponent, MFAEndpoint, }: MFAGateProps) => string | number | bigint | boolean | Iterable<import("react").ReactNode> | Promise<string | number | bigint | boolean | import("react").ReactPortal | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | Iterable<import("react").ReactNode> | null | undefined> | import("react/jsx-runtime").JSX.Element | null;
6
+ declare const MFAGate: ({ children, fallback, MFAEndpoint, }: MFAGateProps) => string | number | bigint | boolean | Iterable<import("react").ReactNode> | Promise<string | number | bigint | boolean | import("react").ReactPortal | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | Iterable<import("react").ReactNode> | null | undefined> | import("react/jsx-runtime").JSX.Element | null;
8
7
  export default MFAGate;
@@ -15,3 +15,16 @@ export declare const useOTPHandler: ({ provider, accessToken, idToken, appCode,
15
15
  resetAttempts: () => void;
16
16
  remainingAttempts: number;
17
17
  };
18
+ export declare const useCredentialsHandler: (credentials: Credentials, appCode: string, CredAuthEndpoint: string, onAuthComplete: (state: boolean, data: UserValidatedResponse | null) => void) => {
19
+ handleSubmitCredentials: ({ username, password, MFACode, appCode, }: {
20
+ username: string;
21
+ password: string;
22
+ MFACode: string;
23
+ appCode: string;
24
+ }) => Promise<boolean>;
25
+ loading: boolean;
26
+ setLoading: import("react").Dispatch<import("react").SetStateAction<boolean>>;
27
+ attemptCount: number;
28
+ isMaxAttemptsReached: boolean;
29
+ remainingAttempts: number;
30
+ };
package/dist/index.cjs.js CHANGED
@@ -534,56 +534,6 @@ function useCAMSMSALAuth(options) {
534
534
  };
535
535
  }
536
536
 
537
- /**
538
- * Hook for handling authentication in popup windows
539
- * This should be used by the popup app to complete authentication
540
- */
541
- function useCAMSPopupAuth(options) {
542
- if (options === void 0) { options = {}; }
543
- var _a = options.storageKey, storageKey = _a === void 0 ? "CAMS-SDK" : _a, targetOrigin = options.targetOrigin, onAuthComplete = options.onAuthComplete, onAuthError = options.onAuthError;
544
- React.useEffect(function () {
545
- if (typeof window === "undefined" || !camsSdk.isPopupWindow())
546
- return;
547
- // Initialize popup auth handler
548
- camsSdk.initializePopupAuth(targetOrigin);
549
- // Set up global handlers for the popup app
550
- var globalHandlers = window.__CAMS_POPUP_AUTH__;
551
- if (globalHandlers) {
552
- var originalCompleteAuth_1 = globalHandlers.completeAuth;
553
- var originalErrorAuth_1 = globalHandlers.errorAuth;
554
- globalHandlers.completeAuth = function (profile) {
555
- onAuthComplete === null || onAuthComplete === void 0 ? void 0 : onAuthComplete(profile);
556
- originalCompleteAuth_1(profile);
557
- };
558
- globalHandlers.errorAuth = function (error) {
559
- onAuthError === null || onAuthError === void 0 ? void 0 : onAuthError(error);
560
- originalErrorAuth_1(error);
561
- };
562
- }
563
- }, [targetOrigin, onAuthComplete, onAuthError]);
564
- var completeAuth = React.useCallback(function (profile) {
565
- if (!camsSdk.isPopupWindow()) {
566
- console.warn("completeAuth called outside of popup window");
567
- return;
568
- }
569
- var sessionManager = new camsSdk.CAMSSessionManager(localStorage, storageKey);
570
- sessionManager.completePopupAuth(profile, targetOrigin);
571
- }, [storageKey, targetOrigin]);
572
- var errorAuth = React.useCallback(function (error) {
573
- if (!camsSdk.isPopupWindow()) {
574
- console.warn("errorAuth called outside of popup window");
575
- return;
576
- }
577
- var sessionManager = new camsSdk.CAMSSessionManager(localStorage, storageKey);
578
- sessionManager.errorPopupAuth(error, targetOrigin);
579
- }, [storageKey, targetOrigin]);
580
- return {
581
- completeAuth: completeAuth,
582
- errorAuth: errorAuth,
583
- isPopup: camsSdk.isPopupWindow(),
584
- };
585
- }
586
-
587
537
  var jsxRuntime = {exports: {}};
588
538
 
589
539
  var reactJsxRuntime_production = {};
@@ -1677,12 +1627,12 @@ var GenerateDeviceId = function () {
1677
1627
  return (_a = deviceId.replace(/[^a-zA-Z0-9-_]/g, "_")) !== null && _a !== void 0 ? _a : "unknown-device";
1678
1628
  };
1679
1629
 
1630
+ var MAX_ATTEMPTS = 3;
1680
1631
  var useOTPHandler = function (_a) {
1681
1632
  var provider = _a.provider, accessToken = _a.accessToken, idToken = _a.idToken, appCode = _a.appCode, authenticationType = _a.authenticationType, MFAEndpoint = _a.MFAEndpoint, onAuthComplete = _a.onAuthComplete;
1682
1633
  var _b = React.useState(false), loading = _b[0], setLoading = _b[1];
1683
1634
  var _c = React.useState(0), attemptCount = _c[0], setAttemptCount = _c[1];
1684
1635
  var _d = React.useState(false), isMaxAttemptsReached = _d[0], setIsMaxAttemptsReached = _d[1];
1685
- var MAX_ATTEMPTS = 3;
1686
1636
  var handleSubmitOTP = React.useMemo(function () { return function (authenticationValue) { return __awaiter(void 0, void 0, void 0, function () {
1687
1637
  var currentAttempt, response, error_1, currentAttempt;
1688
1638
  return __generator(this, function (_a) {
@@ -1897,7 +1847,10 @@ var credentialsSchema = z.z.object({
1897
1847
  var ADLoginModal = function (_a) {
1898
1848
  var open = _a.open, onOpenChange = _a.onOpenChange, onLogin = _a.onLogin;
1899
1849
  var _b = React.useState("credentials"), step = _b[0], setStep = _b[1];
1900
- var _c = React.useState({ username: "", password: "" }), credentials = _c[0], setCredentials = _c[1];
1850
+ var _c = React.useState({
1851
+ username: "",
1852
+ password: "",
1853
+ }), credentials = _c[0], setCredentials = _c[1];
1901
1854
  var _d = React.useState(""), mfaCode = _d[0], setMfaCode = _d[1];
1902
1855
  var _e = React.useState(false), isLoading = _e[0], setIsLoading = _e[1];
1903
1856
  var form = reactHookForm.useForm({
@@ -1920,7 +1873,11 @@ var ADLoginModal = function (_a) {
1920
1873
  _a.label = 1;
1921
1874
  case 1:
1922
1875
  _a.trys.push([1, 3, 4, 5]);
1923
- return [4 /*yield*/, onLogin(credentials.username, credentials.password, code)];
1876
+ return [4 /*yield*/, onLogin({
1877
+ username: credentials.username,
1878
+ password: credentials.password,
1879
+ MFACode: code,
1880
+ })];
1924
1881
  case 2:
1925
1882
  _a.sent();
1926
1883
  onOpenChange(false);
@@ -1945,7 +1902,7 @@ var ADLoginModal = function (_a) {
1945
1902
  form.reset();
1946
1903
  setMfaCode("");
1947
1904
  };
1948
- return (jsxRuntimeExports.jsx(Dialog, { open: open, onOpenChange: handleClose, children: jsxRuntimeExports.jsxs(DialogContent, { className: "sm:max-w-md", children: [jsxRuntimeExports.jsx(DialogHeader, { children: jsxRuntimeExports.jsxs("div", { className: "flex items-center gap-2", children: [jsxRuntimeExports.jsx(lucideReact.KeyIcon, { className: "w-5 h-5 text-[#506f4a]" }), jsxRuntimeExports.jsx(DialogTitle, { children: "Sign in with AD" })] }) }), step === "credentials" ? (jsxRuntimeExports.jsx(Form, __assign({}, form, { children: jsxRuntimeExports.jsxs("form", { onSubmit: form.handleSubmit(handleCredentialsSubmit), className: "space-y-4", children: [jsxRuntimeExports.jsx(FormField, { control: form.control, name: "username", render: function (_a) {
1905
+ return (jsxRuntimeExports.jsx(Dialog, { open: open, onOpenChange: handleClose, children: jsxRuntimeExports.jsxs(DialogContent, { className: "sm:max-w-[85%]", children: [jsxRuntimeExports.jsx(DialogHeader, { children: jsxRuntimeExports.jsxs("div", { className: "flex items-center gap-2", children: [jsxRuntimeExports.jsx(lucideReact.KeyIcon, { className: "w-8 h-8 text-[#506f4a]" }), jsxRuntimeExports.jsx(DialogTitle, { className: "text-2xl", children: "Sign in with AD" })] }) }), step === "credentials" ? (jsxRuntimeExports.jsx(Form, __assign({}, form, { children: jsxRuntimeExports.jsxs("form", { onSubmit: form.handleSubmit(handleCredentialsSubmit), className: "space-y-4", children: [jsxRuntimeExports.jsx(FormField, { control: form.control, name: "username", render: function (_a) {
1949
1906
  var field = _a.field;
1950
1907
  return (jsxRuntimeExports.jsxs(FormItem, { children: [jsxRuntimeExports.jsx(FormLabel, { children: "Username" }), jsxRuntimeExports.jsx(FormControl, { children: jsxRuntimeExports.jsx(Input, __assign({ placeholder: "Enter your username" }, field)) }), jsxRuntimeExports.jsx(FormMessage, {})] }));
1951
1908
  } }), jsxRuntimeExports.jsx(FormField, { control: form.control, name: "password", render: function (_a) {
@@ -1985,10 +1942,11 @@ var DefaultLoginPage = function () {
1985
1942
  // variant="outline"
1986
1943
  , {
1987
1944
  // variant="outline"
1988
- className: "w-full flex items-center justify-center cursor-pointer bg-[#506f4a] hover:bg-[#506f4a] rounded-lg border border-transparent px-5 py-8 text-base font-medium transition-colors duration-250", onClick: function () { return setShowADModal(true); }, disabled: isLoading, children: [jsxRuntimeExports.jsx(lucideReact.KeyIcon, {}), jsxRuntimeExports.jsx("span", { children: isLoading ? "Logging in..." : "Sign in with AD" })] })] }), jsxRuntimeExports.jsxs(CardFooter, { className: "flex items-center justify-center mt-6 space-x-2 text-gray-400 text-sm", children: [jsxRuntimeExports.jsx(lucideReact.ShieldCheck, { className: "w-4 h-4 text-[#506f4a] pulse-glow" }), jsxRuntimeExports.jsx("span", { children: "Powered By NIBSS" })] })] }) }) }, "landing"), jsxRuntimeExports.jsx(ADLoginModal, { open: showADModal, onOpenChange: setShowADModal, onLogin: function (username, password, mfaCode) { return __awaiter(void 0, void 0, void 0, function () {
1989
- return __generator(this, function (_a) {
1945
+ className: "w-full flex items-center justify-center cursor-pointer bg-[#506f4a] hover:bg-[#506f4a] rounded-lg border border-transparent px-5 py-8 text-base font-medium transition-colors duration-250", onClick: function () { return setShowADModal(true); }, disabled: isLoading, children: [jsxRuntimeExports.jsx(lucideReact.KeyIcon, { className: "w-8 h-8 text-[#506f4a]" }), jsxRuntimeExports.jsx("span", { children: isLoading ? "Logging in..." : "Sign in with ActiveDirectory" })] })] }), jsxRuntimeExports.jsxs(CardFooter, { className: "flex items-center justify-center mt-6 space-x-2 text-gray-400 text-sm", children: [jsxRuntimeExports.jsx(lucideReact.ShieldCheck, { className: "w-4 h-4 text-[#506f4a] pulse-glow" }), jsxRuntimeExports.jsx("span", { children: "Powered By NIBSS" })] })] }) }) }, "landing"), jsxRuntimeExports.jsx(ADLoginModal, { open: showADModal, onOpenChange: setShowADModal, onLogin: function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
1946
+ var username = _b.username, password = _b.password, MFACode = _b.MFACode;
1947
+ return __generator(this, function (_c) {
1990
1948
  // Implement your AD login logic here
1991
- console.log("AD Login:", { username: username, password: password, mfaCode: mfaCode });
1949
+ console.log("AD Login:", { username: username, password: password, MFACode: MFACode });
1992
1950
  return [2 /*return*/];
1993
1951
  });
1994
1952
  }); } })] }));
@@ -2001,7 +1959,9 @@ var ErrorFallback = function (_a) {
2001
1959
 
2002
1960
  var MFAEndpointUrlSchema = z.url("MFAEndpoint must be a valid URL");
2003
1961
  var MFAGate = function (_a) {
2004
- var children = _a.children, _b = _a.fallback, fallback = _b === void 0 ? jsxRuntimeExports.jsx(LoadingSpinner, {}) : _b, _c = _a.loginComponent, LoginComponent = _c === void 0 ? DefaultLoginPage : _c, MFAEndpoint = _a.MFAEndpoint;
1962
+ var children = _a.children, _b = _a.fallback, fallback = _b === void 0 ? jsxRuntimeExports.jsx(LoadingSpinner, {}) : _b,
1963
+ // loginComponent: LoginComponent = DefaultLoginPage,
1964
+ MFAEndpoint = _a.MFAEndpoint;
2005
1965
  var context = useCAMSContext();
2006
1966
  var validatedMFAEndpoint = React.useMemo(function () {
2007
1967
  var parsed = MFAEndpointUrlSchema.safeParse(MFAEndpoint);
@@ -2036,7 +1996,7 @@ var MFAGate = function (_a) {
2036
1996
  return (jsxRuntimeExports.jsx(MFAOptions, { MFAEndpoint: validatedMFAEndpoint, onComplete: handleComplete, onAuthFailed: handleAuthFailed }));
2037
1997
  }
2038
1998
  if (!context.isAuthenticated) {
2039
- return jsxRuntimeExports.jsx(LoginComponent, {});
1999
+ return jsxRuntimeExports.jsx(DefaultLoginPage, {});
2040
2000
  }
2041
2001
  return jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: children });
2042
2002
  };
@@ -2053,7 +2013,6 @@ exports.useCAMSAuth = useCAMSAuth;
2053
2013
  exports.useCAMSContext = useCAMSContext;
2054
2014
  exports.useCAMSMSALAuth = useCAMSMSALAuth;
2055
2015
  exports.useCAMSMSALContext = useCAMSMSALContext;
2056
- exports.useCAMSPopupAuth = useCAMSPopupAuth;
2057
2016
  Object.keys(camsSdk).forEach(function (k) {
2058
2017
  if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
2059
2018
  enumerable: true,