@nibssplc/cams-sdk-react 0.0.1-beta.83 → 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.
- package/dist/components/ADLoginModal.d.ts +2 -2
- package/dist/components/MFAGate.d.ts +1 -2
- package/dist/hooks/useOTPHandler.d.ts +13 -0
- package/dist/index.cjs.js +19 -9
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +19 -9
- package/dist/index.esm.js.map +1 -1
- package/package.json +2 -2
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
interface ADLoginModalProps {
|
|
2
2
|
open: boolean;
|
|
3
3
|
onOpenChange: (open: boolean) => void;
|
|
4
|
-
onLogin: (
|
|
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,
|
|
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
|
@@ -1627,12 +1627,12 @@ var GenerateDeviceId = function () {
|
|
|
1627
1627
|
return (_a = deviceId.replace(/[^a-zA-Z0-9-_]/g, "_")) !== null && _a !== void 0 ? _a : "unknown-device";
|
|
1628
1628
|
};
|
|
1629
1629
|
|
|
1630
|
+
var MAX_ATTEMPTS = 3;
|
|
1630
1631
|
var useOTPHandler = function (_a) {
|
|
1631
1632
|
var provider = _a.provider, accessToken = _a.accessToken, idToken = _a.idToken, appCode = _a.appCode, authenticationType = _a.authenticationType, MFAEndpoint = _a.MFAEndpoint, onAuthComplete = _a.onAuthComplete;
|
|
1632
1633
|
var _b = React.useState(false), loading = _b[0], setLoading = _b[1];
|
|
1633
1634
|
var _c = React.useState(0), attemptCount = _c[0], setAttemptCount = _c[1];
|
|
1634
1635
|
var _d = React.useState(false), isMaxAttemptsReached = _d[0], setIsMaxAttemptsReached = _d[1];
|
|
1635
|
-
var MAX_ATTEMPTS = 3;
|
|
1636
1636
|
var handleSubmitOTP = React.useMemo(function () { return function (authenticationValue) { return __awaiter(void 0, void 0, void 0, function () {
|
|
1637
1637
|
var currentAttempt, response, error_1, currentAttempt;
|
|
1638
1638
|
return __generator(this, function (_a) {
|
|
@@ -1847,7 +1847,10 @@ var credentialsSchema = z.z.object({
|
|
|
1847
1847
|
var ADLoginModal = function (_a) {
|
|
1848
1848
|
var open = _a.open, onOpenChange = _a.onOpenChange, onLogin = _a.onLogin;
|
|
1849
1849
|
var _b = React.useState("credentials"), step = _b[0], setStep = _b[1];
|
|
1850
|
-
var _c = React.useState({
|
|
1850
|
+
var _c = React.useState({
|
|
1851
|
+
username: "",
|
|
1852
|
+
password: "",
|
|
1853
|
+
}), credentials = _c[0], setCredentials = _c[1];
|
|
1851
1854
|
var _d = React.useState(""), mfaCode = _d[0], setMfaCode = _d[1];
|
|
1852
1855
|
var _e = React.useState(false), isLoading = _e[0], setIsLoading = _e[1];
|
|
1853
1856
|
var form = reactHookForm.useForm({
|
|
@@ -1870,7 +1873,11 @@ var ADLoginModal = function (_a) {
|
|
|
1870
1873
|
_a.label = 1;
|
|
1871
1874
|
case 1:
|
|
1872
1875
|
_a.trys.push([1, 3, 4, 5]);
|
|
1873
|
-
return [4 /*yield*/, onLogin(
|
|
1876
|
+
return [4 /*yield*/, onLogin({
|
|
1877
|
+
username: credentials.username,
|
|
1878
|
+
password: credentials.password,
|
|
1879
|
+
MFACode: code,
|
|
1880
|
+
})];
|
|
1874
1881
|
case 2:
|
|
1875
1882
|
_a.sent();
|
|
1876
1883
|
onOpenChange(false);
|
|
@@ -1895,7 +1902,7 @@ var ADLoginModal = function (_a) {
|
|
|
1895
1902
|
form.reset();
|
|
1896
1903
|
setMfaCode("");
|
|
1897
1904
|
};
|
|
1898
|
-
return (jsxRuntimeExports.jsx(Dialog, { open: open, onOpenChange: handleClose, children: jsxRuntimeExports.jsxs(DialogContent, { className: "sm:max-w-
|
|
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) {
|
|
1899
1906
|
var field = _a.field;
|
|
1900
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, {})] }));
|
|
1901
1908
|
} }), jsxRuntimeExports.jsx(FormField, { control: form.control, name: "password", render: function (_a) {
|
|
@@ -1935,10 +1942,11 @@ var DefaultLoginPage = function () {
|
|
|
1935
1942
|
// variant="outline"
|
|
1936
1943
|
, {
|
|
1937
1944
|
// variant="outline"
|
|
1938
|
-
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
|
|
1939
|
-
|
|
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) {
|
|
1940
1948
|
// Implement your AD login logic here
|
|
1941
|
-
console.log("AD Login:", { username: username, password: password,
|
|
1949
|
+
console.log("AD Login:", { username: username, password: password, MFACode: MFACode });
|
|
1942
1950
|
return [2 /*return*/];
|
|
1943
1951
|
});
|
|
1944
1952
|
}); } })] }));
|
|
@@ -1951,7 +1959,9 @@ var ErrorFallback = function (_a) {
|
|
|
1951
1959
|
|
|
1952
1960
|
var MFAEndpointUrlSchema = z.url("MFAEndpoint must be a valid URL");
|
|
1953
1961
|
var MFAGate = function (_a) {
|
|
1954
|
-
var children = _a.children, _b = _a.fallback, fallback = _b === void 0 ? jsxRuntimeExports.jsx(LoadingSpinner, {}) : _b,
|
|
1962
|
+
var children = _a.children, _b = _a.fallback, fallback = _b === void 0 ? jsxRuntimeExports.jsx(LoadingSpinner, {}) : _b,
|
|
1963
|
+
// loginComponent: LoginComponent = DefaultLoginPage,
|
|
1964
|
+
MFAEndpoint = _a.MFAEndpoint;
|
|
1955
1965
|
var context = useCAMSContext();
|
|
1956
1966
|
var validatedMFAEndpoint = React.useMemo(function () {
|
|
1957
1967
|
var parsed = MFAEndpointUrlSchema.safeParse(MFAEndpoint);
|
|
@@ -1986,7 +1996,7 @@ var MFAGate = function (_a) {
|
|
|
1986
1996
|
return (jsxRuntimeExports.jsx(MFAOptions, { MFAEndpoint: validatedMFAEndpoint, onComplete: handleComplete, onAuthFailed: handleAuthFailed }));
|
|
1987
1997
|
}
|
|
1988
1998
|
if (!context.isAuthenticated) {
|
|
1989
|
-
return jsxRuntimeExports.jsx(
|
|
1999
|
+
return jsxRuntimeExports.jsx(DefaultLoginPage, {});
|
|
1990
2000
|
}
|
|
1991
2001
|
return jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: children });
|
|
1992
2002
|
};
|