@digitaldefiance/express-suite-react-components 4.26.26 → 4.27.1
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/package.json +2 -1
- package/src/components/RegisterForm.d.ts +31 -0
- package/src/components/RegisterForm.d.ts.map +1 -1
- package/src/components/RegisterForm.js +98 -24
- package/src/components/TotpSetupForm.d.ts +24 -0
- package/src/components/TotpSetupForm.d.ts.map +1 -0
- package/src/components/TotpSetupForm.js +82 -0
- package/src/components/TotpVerificationForm.d.ts +23 -0
- package/src/components/TotpVerificationForm.d.ts.map +1 -0
- package/src/components/TotpVerificationForm.js +66 -0
- package/src/components/UserSettingsForm.d.ts +53 -0
- package/src/components/UserSettingsForm.d.ts.map +1 -1
- package/src/components/UserSettingsForm.js +128 -2
- package/src/components/index.d.ts +2 -0
- package/src/components/index.d.ts.map +1 -1
- package/src/components/index.js +2 -0
- package/src/contexts/AuthProvider.d.ts +33 -0
- package/src/contexts/AuthProvider.d.ts.map +1 -1
- package/src/contexts/AuthProvider.js +3 -0
- package/src/services/authService.d.ts +32 -0
- package/src/services/authService.d.ts.map +1 -1
- package/src/services/authService.js +116 -0
- package/src/wrappers/LoginFormWrapper.d.ts +12 -0
- package/src/wrappers/LoginFormWrapper.d.ts.map +1 -1
- package/src/wrappers/LoginFormWrapper.js +36 -9
- package/src/wrappers/RegisterFormWrapper.d.ts +6 -0
- package/src/wrappers/RegisterFormWrapper.d.ts.map +1 -1
- package/src/wrappers/RegisterFormWrapper.js +10 -3
- package/src/wrappers/UserSettingsFormWrapper.d.ts +21 -0
- package/src/wrappers/UserSettingsFormWrapper.d.ts.map +1 -1
- package/src/wrappers/UserSettingsFormWrapper.js +67 -3
|
@@ -1,7 +1,28 @@
|
|
|
1
1
|
import { FC } from 'react';
|
|
2
2
|
import { UserSettingsFormProps } from '../components/UserSettingsForm';
|
|
3
|
+
import { IConstants } from '@digitaldefiance/suite-core-lib';
|
|
4
|
+
import { IECIESConfig } from '@digitaldefiance/ecies-lib';
|
|
3
5
|
export interface UserSettingsFormWrapperProps {
|
|
4
6
|
onSuccess?: () => void;
|
|
7
|
+
/**
|
|
8
|
+
* Constants for AuthService (required for TOTP methods).
|
|
9
|
+
* If not provided, TOTP callbacks will not be wired up.
|
|
10
|
+
*/
|
|
11
|
+
constants?: IConstants;
|
|
12
|
+
/**
|
|
13
|
+
* ECIES config for AuthService (required for TOTP methods).
|
|
14
|
+
* If not provided, TOTP callbacks will not be wired up.
|
|
15
|
+
*/
|
|
16
|
+
eciesConfig?: IECIESConfig;
|
|
17
|
+
/**
|
|
18
|
+
* Email domain for AuthService (required for TOTP methods).
|
|
19
|
+
*/
|
|
20
|
+
emailDomain?: string;
|
|
21
|
+
/**
|
|
22
|
+
* When false (default), TOTP management controls are not shown.
|
|
23
|
+
* Set to true when TOTP_AVAILABLE is enabled in the server environment.
|
|
24
|
+
*/
|
|
25
|
+
totpAvailable?: boolean;
|
|
5
26
|
componentProps?: Partial<Omit<UserSettingsFormProps, 'initialValues' | 'onSubmit' | 'languages'>>;
|
|
6
27
|
}
|
|
7
28
|
export declare const UserSettingsFormWrapper: FC<UserSettingsFormWrapperProps>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UserSettingsFormWrapper.d.ts","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-express-suite-react-components/src/wrappers/UserSettingsFormWrapper.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,
|
|
1
|
+
{"version":3,"file":"UserSettingsFormWrapper.d.ts","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-express-suite-react-components/src/wrappers/UserSettingsFormWrapper.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAA6C,MAAM,OAAO,CAAC;AACtE,OAAO,EAA4C,qBAAqB,EAAE,MAAM,gCAAgC,CAAC;AAGjH,OAAO,EAA2B,UAAU,EAAsB,MAAM,iCAAiC,CAAC;AAG1G,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAE1D,MAAM,WAAW,4BAA4B;IAC3C,SAAS,CAAC,EAAE,MAAM,IAAI,CAAC;IACvB;;;OAGG;IACH,SAAS,CAAC,EAAE,UAAU,CAAC;IACvB;;;OAGG;IACH,WAAW,CAAC,EAAE,YAAY,CAAC;IAC3B;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;OAGG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,cAAc,CAAC,EAAE,OAAO,CAAC,IAAI,CAAC,qBAAqB,EAAE,eAAe,GAAG,UAAU,GAAG,WAAW,CAAC,CAAC,CAAC;CACnG;AAED,eAAO,MAAM,uBAAuB,EAAE,EAAE,CAAC,4BAA4B,CAqGpE,CAAC"}
|
|
@@ -2,13 +2,38 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.UserSettingsFormWrapper = void 0;
|
|
4
4
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const react_1 = require("react");
|
|
5
6
|
const UserSettingsForm_1 = require("../components/UserSettingsForm");
|
|
6
7
|
const contexts_1 = require("../contexts");
|
|
7
8
|
const hooks_1 = require("../hooks");
|
|
8
9
|
const suite_core_lib_1 = require("@digitaldefiance/suite-core-lib");
|
|
9
|
-
const
|
|
10
|
+
const authService_1 = require("../services/authService");
|
|
11
|
+
const authenticatedApi_1 = require("../services/authenticatedApi");
|
|
12
|
+
const UserSettingsFormWrapper = ({ onSuccess, constants, eciesConfig, emailDomain = '', totpAvailable = false, componentProps = {}, }) => {
|
|
10
13
|
const { settings, updateSettings } = (0, hooks_1.useUserSettingsPublic)();
|
|
11
|
-
const { languages } = (0, contexts_1.useSuiteConfig)();
|
|
14
|
+
const { languages, baseUrl } = (0, contexts_1.useSuiteConfig)();
|
|
15
|
+
const { isAuthenticated } = (0, contexts_1.useAuth)();
|
|
16
|
+
// Fetch totpEnabled from the settings API
|
|
17
|
+
const [totpEnabled, setTotpEnabled] = (0, react_1.useState)(undefined);
|
|
18
|
+
const authenticatedApi = (0, react_1.useMemo)(() => (0, authenticatedApi_1.createAuthenticatedApiClient)(baseUrl), [baseUrl]);
|
|
19
|
+
const authService = (0, react_1.useMemo)(() => {
|
|
20
|
+
if (!constants || !eciesConfig)
|
|
21
|
+
return null;
|
|
22
|
+
return (0, authService_1.createAuthService)(constants, baseUrl, eciesConfig, emailDomain);
|
|
23
|
+
}, [constants, eciesConfig, baseUrl, emailDomain]);
|
|
24
|
+
// Fetch totpEnabled from GET /user/settings
|
|
25
|
+
(0, react_1.useEffect)(() => {
|
|
26
|
+
if (!isAuthenticated)
|
|
27
|
+
return;
|
|
28
|
+
authenticatedApi
|
|
29
|
+
.get('/user/settings')
|
|
30
|
+
.then((res) => {
|
|
31
|
+
setTotpEnabled(res.data?.settings?.totpEnabled ?? false);
|
|
32
|
+
})
|
|
33
|
+
.catch(() => {
|
|
34
|
+
// If the endpoint fails, leave totpEnabled undefined (no TOTP controls shown)
|
|
35
|
+
});
|
|
36
|
+
}, [isAuthenticated, authenticatedApi]);
|
|
12
37
|
const handleSubmit = async (values) => {
|
|
13
38
|
const result = await updateSettings(values);
|
|
14
39
|
if ('success' in result && result.success && onSuccess) {
|
|
@@ -16,11 +41,50 @@ const UserSettingsFormWrapper = ({ onSuccess, componentProps = {}, }) => {
|
|
|
16
41
|
}
|
|
17
42
|
return result;
|
|
18
43
|
};
|
|
44
|
+
// TOTP callbacks — only wired when authService is available
|
|
45
|
+
const handleTotpSetup = (0, react_1.useCallback)(async () => {
|
|
46
|
+
if (!authService)
|
|
47
|
+
return { error: 'AuthService not configured' };
|
|
48
|
+
return authService.setupTotp();
|
|
49
|
+
}, [authService]);
|
|
50
|
+
const handleTotpConfirm = (0, react_1.useCallback)(async (code) => {
|
|
51
|
+
if (!authService)
|
|
52
|
+
return { error: 'AuthService not configured' };
|
|
53
|
+
const result = await authService.confirmTotp(code);
|
|
54
|
+
if ('success' in result && result.success) {
|
|
55
|
+
setTotpEnabled(true);
|
|
56
|
+
}
|
|
57
|
+
return result;
|
|
58
|
+
}, [authService]);
|
|
59
|
+
const handleTotpDisable = (0, react_1.useCallback)(async (code) => {
|
|
60
|
+
if (!authService)
|
|
61
|
+
return { error: 'AuthService not configured' };
|
|
62
|
+
const result = await authService.disableTotp(code);
|
|
63
|
+
if ('success' in result && result.success) {
|
|
64
|
+
setTotpEnabled(false);
|
|
65
|
+
}
|
|
66
|
+
return result;
|
|
67
|
+
}, [authService]);
|
|
68
|
+
const handleTotpReset = (0, react_1.useCallback)(async (code) => {
|
|
69
|
+
if (!authService)
|
|
70
|
+
return { error: 'AuthService not configured' };
|
|
71
|
+
return authService.resetTotp(code);
|
|
72
|
+
}, [authService]);
|
|
19
73
|
// Only show loading on initial load, not during updates
|
|
20
74
|
// Once we have settings, keep showing the form even during updates
|
|
21
75
|
if (!settings) {
|
|
22
76
|
return (0, jsx_runtime_1.jsxs)("div", { children: [(0, suite_core_lib_1.getSuiteCoreTranslation)(suite_core_lib_1.SuiteCoreStringKey.Common_Loading), "..."] });
|
|
23
77
|
}
|
|
24
|
-
|
|
78
|
+
// Only pass TOTP props when totpAvailable is true, authService is available, and totpEnabled has been fetched
|
|
79
|
+
const totpProps = totpAvailable && authService && totpEnabled !== undefined
|
|
80
|
+
? {
|
|
81
|
+
totpEnabled,
|
|
82
|
+
onTotpSetup: handleTotpSetup,
|
|
83
|
+
onTotpConfirm: handleTotpConfirm,
|
|
84
|
+
onTotpDisable: handleTotpDisable,
|
|
85
|
+
onTotpReset: handleTotpReset,
|
|
86
|
+
}
|
|
87
|
+
: {};
|
|
88
|
+
return ((0, jsx_runtime_1.jsx)(UserSettingsForm_1.UserSettingsForm, { initialValues: settings, onSubmit: handleSubmit, languages: languages, ...totpProps, ...componentProps }));
|
|
25
89
|
};
|
|
26
90
|
exports.UserSettingsFormWrapper = UserSettingsFormWrapper;
|