@digitaldefiance/express-suite-react-components 2.4.4 → 2.5.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/README.md +131 -0
- package/package.json +6 -6
- package/src/contexts/AuthProvider.d.ts.map +1 -1
- package/src/contexts/AuthProvider.js +19 -5
- package/src/contexts/SuiteConfigProvider.d.ts +44 -0
- package/src/contexts/SuiteConfigProvider.d.ts.map +1 -0
- package/src/contexts/SuiteConfigProvider.js +43 -0
- package/src/contexts/ThemeProvider.d.ts +1 -0
- package/src/contexts/ThemeProvider.d.ts.map +1 -1
- package/src/contexts/ThemeProvider.js +3 -0
- package/src/contexts/index.d.ts +1 -0
- package/src/contexts/index.d.ts.map +1 -1
- package/src/contexts/index.js +1 -0
- package/src/hooks/index.d.ts +3 -0
- package/src/hooks/index.d.ts.map +1 -1
- package/src/hooks/index.js +3 -0
- package/src/hooks/useBackupCodes.d.ts +15 -0
- package/src/hooks/useBackupCodes.d.ts.map +1 -0
- package/src/hooks/useBackupCodes.js +70 -0
- package/src/hooks/useEmailVerification.d.ts +10 -0
- package/src/hooks/useEmailVerification.d.ts.map +1 -0
- package/src/hooks/useEmailVerification.js +36 -0
- package/src/hooks/useUserSettings.d.ts +29 -0
- package/src/hooks/useUserSettings.d.ts.map +1 -0
- package/src/hooks/useUserSettings.js +103 -0
- package/src/wrappers/BackupCodeLoginWrapper.d.ts +8 -0
- package/src/wrappers/BackupCodeLoginWrapper.d.ts.map +1 -0
- package/src/wrappers/BackupCodeLoginWrapper.js +21 -0
- package/src/wrappers/BackupCodesWrapper.d.ts +7 -0
- package/src/wrappers/BackupCodesWrapper.d.ts.map +1 -0
- package/src/wrappers/BackupCodesWrapper.js +17 -0
- package/src/wrappers/ChangePasswordFormWrapper.d.ts +8 -0
- package/src/wrappers/ChangePasswordFormWrapper.d.ts.map +1 -0
- package/src/wrappers/ChangePasswordFormWrapper.js +21 -0
- package/src/wrappers/LoginFormWrapper.d.ts +9 -0
- package/src/wrappers/LoginFormWrapper.d.ts.map +1 -0
- package/src/wrappers/LoginFormWrapper.js +43 -0
- package/src/wrappers/LogoutPageWrapper.d.ts +9 -0
- package/src/wrappers/LogoutPageWrapper.d.ts.map +1 -0
- package/src/wrappers/LogoutPageWrapper.js +21 -0
- package/src/wrappers/RegisterFormWrapper.d.ts +9 -0
- package/src/wrappers/RegisterFormWrapper.d.ts.map +1 -0
- package/src/wrappers/RegisterFormWrapper.js +26 -0
- package/src/wrappers/UserSettingsFormWrapper.d.ts +8 -0
- package/src/wrappers/UserSettingsFormWrapper.d.ts.map +1 -0
- package/src/wrappers/UserSettingsFormWrapper.js +23 -0
- package/src/wrappers/VerifyEmailPageWrapper.d.ts +8 -0
- package/src/wrappers/VerifyEmailPageWrapper.d.ts.map +1 -0
- package/src/wrappers/VerifyEmailPageWrapper.js +20 -0
- package/src/wrappers/index.d.ts +16 -22
- package/src/wrappers/index.d.ts.map +1 -1
- package/src/wrappers/index.js +17 -158
package/README.md
CHANGED
|
@@ -31,6 +31,19 @@ yarn add @digitaldefiance/express-suite-react-components
|
|
|
31
31
|
- **DashboardPage** - Basic dashboard layout
|
|
32
32
|
- **ApiAccess** - API token display and copy component
|
|
33
33
|
|
|
34
|
+
### Wrapper Components
|
|
35
|
+
|
|
36
|
+
Pre-configured components that integrate with application contexts. See the [Component Wrappers Guide](WRAPPERS.md) for detailed usage.
|
|
37
|
+
|
|
38
|
+
- **LoginFormWrapper** - Pre-configured login with auth context integration
|
|
39
|
+
- **RegisterFormWrapper** - Pre-configured registration with auth context integration
|
|
40
|
+
- **ChangePasswordFormWrapper** - Pre-configured password change with auth context
|
|
41
|
+
- **BackupCodeLoginWrapper** - Pre-configured backup code login
|
|
42
|
+
- **BackupCodesWrapper** - Pre-configured backup codes management
|
|
43
|
+
- **UserSettingsFormWrapper** - Pre-configured settings form with auto-fetch
|
|
44
|
+
- **VerifyEmailPageWrapper** - Pre-configured email verification
|
|
45
|
+
- **LogoutPageWrapper** - Pre-configured logout with navigation
|
|
46
|
+
|
|
34
47
|
### UI Components
|
|
35
48
|
|
|
36
49
|
- **ConfirmationDialog** - Reusable confirmation dialog
|
|
@@ -49,14 +62,19 @@ yarn add @digitaldefiance/express-suite-react-components
|
|
|
49
62
|
|
|
50
63
|
- **useLocalStorage** - React hook for localStorage with state sync
|
|
51
64
|
- **useExpiringValue** - React hook for values that expire after a duration
|
|
65
|
+
- **useBackupCodes** - Manage backup code generation and retrieval
|
|
66
|
+
- **useUserSettings** - Fetch and update user settings with context integration
|
|
67
|
+
- **useEmailVerification** - Handle email verification flow
|
|
52
68
|
|
|
53
69
|
### Contexts & Providers
|
|
54
70
|
|
|
55
71
|
- **I18nProvider** - Internationalization context with i18n engine integration
|
|
56
72
|
- **AppThemeProvider** - MUI theme provider with dark/light mode toggle
|
|
57
73
|
- **ThemeToggleButton** - Button component for theme switching
|
|
74
|
+
- **SuiteConfigProvider** - Centralized configuration context (baseUrl, routes, languages)
|
|
58
75
|
- **useI18n** - Hook for accessing i18n context
|
|
59
76
|
- **useTheme** - Hook for accessing theme context
|
|
77
|
+
- **useSuiteConfig** - Hook for accessing suite configuration
|
|
60
78
|
|
|
61
79
|
### Services
|
|
62
80
|
|
|
@@ -70,6 +88,44 @@ yarn add @digitaldefiance/express-suite-react-components
|
|
|
70
88
|
|
|
71
89
|
## Usage
|
|
72
90
|
|
|
91
|
+
### Getting Started with Wrappers
|
|
92
|
+
|
|
93
|
+
For the quickest setup, use wrapper components that handle context integration automatically. See the [Component Wrappers Guide](WRAPPERS.md) for comprehensive examples.
|
|
94
|
+
|
|
95
|
+
```tsx
|
|
96
|
+
import {
|
|
97
|
+
SuiteConfigProvider,
|
|
98
|
+
AuthProvider,
|
|
99
|
+
LoginFormWrapper
|
|
100
|
+
} from '@digitaldefiance/express-suite-react-components';
|
|
101
|
+
|
|
102
|
+
function App() {
|
|
103
|
+
return (
|
|
104
|
+
<SuiteConfigProvider
|
|
105
|
+
baseUrl="https://api.example.com"
|
|
106
|
+
routes={{
|
|
107
|
+
dashboard: '/dashboard',
|
|
108
|
+
login: '/login',
|
|
109
|
+
}}
|
|
110
|
+
languages={[
|
|
111
|
+
{ code: 'en-US', label: 'English (US)' },
|
|
112
|
+
]}
|
|
113
|
+
>
|
|
114
|
+
<AuthProvider baseUrl="https://api.example.com" onAuthError={() => {}}>
|
|
115
|
+
{/* Use wrappers for instant integration */}
|
|
116
|
+
<LoginFormWrapper />
|
|
117
|
+
|
|
118
|
+
{/* Or customize via props */}
|
|
119
|
+
<LoginFormWrapper
|
|
120
|
+
redirectTo="/custom-dashboard"
|
|
121
|
+
componentProps={{ loginType: 'username' }}
|
|
122
|
+
/>
|
|
123
|
+
</AuthProvider>
|
|
124
|
+
</SuiteConfigProvider>
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
```
|
|
128
|
+
|
|
73
129
|
### Menu System
|
|
74
130
|
|
|
75
131
|
The menu system supports extensible menu types. See the [Menu Type Extensibility Guide](docs/MENU_TYPE_EXTENSIBILITY.md) for details on creating custom menus.
|
|
@@ -295,8 +351,75 @@ interface RegisterFormProps {
|
|
|
295
351
|
|
|
296
352
|
MIT © Digital Defiance
|
|
297
353
|
|
|
354
|
+
## Documentation
|
|
355
|
+
|
|
356
|
+
- **[Overview](docs/OVERVIEW.md)** - Package architecture and getting started guide
|
|
357
|
+
- **[Components Documentation](docs/COMPONENTS.md)** - API reference for presentational components
|
|
358
|
+
- **[Hooks Documentation](docs/HOOKS.md)** - API reference for custom React hooks
|
|
359
|
+
- **[Wrappers API Documentation](docs/WRAPPERS_API.md)** - API reference for wrapper components
|
|
360
|
+
- **[Component Wrappers Guide](WRAPPERS.md)** - Comprehensive guide to using wrappers, hooks, and components
|
|
361
|
+
- **[Menu Type Extensibility Guide](docs/MENU_TYPE_EXTENSIBILITY.md)** - Creating custom menu types
|
|
362
|
+
|
|
298
363
|
## ChangeLog
|
|
299
364
|
|
|
365
|
+
### Version 2.5.1
|
|
366
|
+
|
|
367
|
+
- Upgrade libs
|
|
368
|
+
|
|
369
|
+
### Version 2.5.0
|
|
370
|
+
|
|
371
|
+
#### Added
|
|
372
|
+
|
|
373
|
+
- **SuiteConfigProvider** - Centralized configuration context for baseUrl, routes, languages, and timezones
|
|
374
|
+
- **Component Wrappers** - Pre-configured wrapper components for all major forms and pages
|
|
375
|
+
- LoginFormWrapper, RegisterFormWrapper, ChangePasswordFormWrapper
|
|
376
|
+
- BackupCodeLoginWrapper, BackupCodesWrapper
|
|
377
|
+
- UserSettingsFormWrapper, VerifyEmailPageWrapper, LogoutPageWrapper
|
|
378
|
+
- **Business Logic Hooks** - Reusable hooks for common operations
|
|
379
|
+
- useBackupCodes - Manage backup code generation and retrieval
|
|
380
|
+
- useUserSettings - Fetch and update user settings with context integration
|
|
381
|
+
- useEmailVerification - Handle email verification flow
|
|
382
|
+
- **Component Wrappers Guide** - Comprehensive documentation at `WRAPPERS.md`
|
|
383
|
+
|
|
384
|
+
#### Changed
|
|
385
|
+
|
|
386
|
+
- **Wrapper Architecture** - All wrappers now use centralized SuiteConfigProvider
|
|
387
|
+
- **Consistent API** - All wrappers support `onSuccess`, `componentProps`, and configurable routing
|
|
388
|
+
- **Improved Testability** - Business logic extracted into hooks for easier testing
|
|
389
|
+
- **Better DX** - Three levels of abstraction: Wrappers (easy), Hooks (flexible), Components (full control)
|
|
390
|
+
|
|
391
|
+
#### Breaking Changes
|
|
392
|
+
|
|
393
|
+
- **BackupCodesWrapper** - No longer requires `baseUrl` prop (uses SuiteConfigProvider)
|
|
394
|
+
- **VerifyEmailPageWrapper** - No longer requires `baseUrl` prop (uses SuiteConfigProvider)
|
|
395
|
+
- **UserSettingsFormWrapper** - No longer requires `baseUrl` or `languages` props (uses SuiteConfigProvider)
|
|
396
|
+
|
|
397
|
+
#### Migration Guide
|
|
398
|
+
|
|
399
|
+
```tsx
|
|
400
|
+
// Old (v2.4.x)
|
|
401
|
+
<BackupCodesWrapper baseUrl="https://api.example.com" />
|
|
402
|
+
<UserSettingsFormWrapper
|
|
403
|
+
baseUrl="https://api.example.com"
|
|
404
|
+
languages={[...]}
|
|
405
|
+
/>
|
|
406
|
+
|
|
407
|
+
// New (v2.5.0)
|
|
408
|
+
<SuiteConfigProvider
|
|
409
|
+
baseUrl="https://api.example.com"
|
|
410
|
+
languages={[...]}
|
|
411
|
+
>
|
|
412
|
+
<BackupCodesWrapper />
|
|
413
|
+
<UserSettingsFormWrapper />
|
|
414
|
+
</SuiteConfigProvider>
|
|
415
|
+
```
|
|
416
|
+
|
|
417
|
+
See [Component Wrappers Guide](WRAPPERS.md) for complete migration examples.
|
|
418
|
+
|
|
419
|
+
### Version 2.4.5
|
|
420
|
+
|
|
421
|
+
- DarkMode improvements
|
|
422
|
+
|
|
300
423
|
### Version 2.4.4
|
|
301
424
|
|
|
302
425
|
- Fix t(tComponent( calls
|
|
@@ -321,23 +444,27 @@ MIT © Digital Defiance
|
|
|
321
444
|
### Version 2.4.0
|
|
322
445
|
|
|
323
446
|
#### Changed
|
|
447
|
+
|
|
324
448
|
- **Version Bump**: Updated from 2.3.5 to 2.4.0
|
|
325
449
|
- **Dependency Update**: Upgraded `@digitaldefiance/suite-core-lib` from ^2.2.5 to ^2.2.10
|
|
326
450
|
- **Translation Keys**: Replaced `Login_UseEmail` with `Login_UseEmailAddress` in BackupCodeLoginForm and LoginForm
|
|
327
451
|
- **Error Messages**: Updated password login error to use `Error_Login_PasswordLoginNotSetup` instead of `PasswordLogin_Setup_NotAvailable` in AuthProvider
|
|
328
452
|
|
|
329
453
|
#### Added
|
|
454
|
+
|
|
330
455
|
- **Error Handling**: LoginForm now displays error messages via Alert component with Formik status
|
|
331
456
|
- **Error Recovery**: LoginForm onSubmit wrapped with try-catch to capture and display errors
|
|
332
457
|
- **Menu Context Integration**: TopMenu now uses `useMenu()` hook and `getTopMenus()` method
|
|
333
458
|
- **Menu Types**: Added `AccountCircle` icon import and `IMenuConfig` interface import
|
|
334
459
|
|
|
335
460
|
#### Fixed
|
|
461
|
+
|
|
336
462
|
- **Import Path**: Corrected `IAppConfig` import path from `../interfaces/AppConfig` to `../interfaces/IAppConfig`
|
|
337
463
|
- **Menu Rendering**: Simplified TopMenu additional menus logic to use centralized menu context
|
|
338
464
|
- **Error Type**: Added `errorType: 'PasswordLoginNotSetup'` to password login error responses
|
|
339
465
|
|
|
340
466
|
#### Technical
|
|
467
|
+
|
|
341
468
|
- Enhanced error propagation in authentication flows
|
|
342
469
|
- Improved menu configuration architecture with context-based management
|
|
343
470
|
- Better alignment with suite-core-lib translation key naming conventions
|
|
@@ -365,10 +492,12 @@ MIT © Digital Defiance
|
|
|
365
492
|
### v2.3.0
|
|
366
493
|
|
|
367
494
|
#### Breaking Changes
|
|
495
|
+
|
|
368
496
|
- **Removed `IncludeOnMenu` enum** - Replaced with extensible `MenuType` system using branded string types
|
|
369
497
|
- Menu system now requires `MenuTypes` constant instead of enum values
|
|
370
498
|
|
|
371
499
|
#### Added
|
|
500
|
+
|
|
372
501
|
- **Extensible Menu Type System** - New `MenuType` branded string type with `createMenuType()` factory function
|
|
373
502
|
- **`MenuTypes` constant** - Built-in menu types (SideMenu, TopMenu, UserMenu) replacing enum
|
|
374
503
|
- **`createMenuType()` function** - Factory for creating custom menu types with type safety
|
|
@@ -377,6 +506,7 @@ MIT © Digital Defiance
|
|
|
377
506
|
- **Menu Type Extensibility Guide** - Comprehensive documentation at `docs/MENU_TYPE_EXTENSIBILITY.md`
|
|
378
507
|
|
|
379
508
|
#### Changed
|
|
509
|
+
|
|
380
510
|
- **IMenuOption.includeOnMenus** - Now uses `MenuType[]` instead of `IncludeOnMenu[]`
|
|
381
511
|
- **DropdownMenu.menuType** - Now accepts `MenuType` instead of `IncludeOnMenu`
|
|
382
512
|
- **MenuContext.getMenuOptions** - Now accepts `MenuType` parameter instead of `IncludeOnMenu`
|
|
@@ -384,6 +514,7 @@ MIT © Digital Defiance
|
|
|
384
514
|
- Updated README with menu system usage examples and extensibility guide link
|
|
385
515
|
|
|
386
516
|
#### Migration Guide
|
|
517
|
+
|
|
387
518
|
```typescript
|
|
388
519
|
// Old (v2.2.x)
|
|
389
520
|
import { IncludeOnMenu } from '@digitaldefiance/express-suite-react-components';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@digitaldefiance/express-suite-react-components",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.5.1",
|
|
4
4
|
"description": "React MUI components for Digital Defiance Express Suite",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"types": "src/index.d.ts",
|
|
@@ -8,9 +8,9 @@
|
|
|
8
8
|
"build": "npx nx build digitaldefiance-express-suite-react-components",
|
|
9
9
|
"build:stream": "npx nx build --outputStyle=stream digitaldefiance-express-suite-react-components",
|
|
10
10
|
"build:logged": "npx nx build --outputStyle=stream digitaldefiance-express-suite-react-components 2>&1 | ansifilter -o build.log",
|
|
11
|
-
"test": "npx nx test digitaldefiance-express-suite-react-components",
|
|
12
|
-
"test:stream": "npx nx test --outputStyle=stream digitaldefiance-express-suite-react-components",
|
|
13
|
-
"test:logged": "npx nx test --outputStyle=stream digitaldefiance-express-suite-react-components 2>&1 | ansifilter -o test.log",
|
|
11
|
+
"test": "NODE_OPTIONS='--max-old-space-size=6144' npx nx test digitaldefiance-express-suite-react-components",
|
|
12
|
+
"test:stream": "NODE_OPTIONS='--max-old-space-size=6144' npx nx test --outputStyle=stream digitaldefiance-express-suite-react-components",
|
|
13
|
+
"test:logged": "NODE_OPTIONS='--max-old-space-size=6144' npx nx test --outputStyle=stream digitaldefiance-express-suite-react-components 2>&1 | ansifilter -o test.log",
|
|
14
14
|
"test:coverage": "npx jest --coverage --testPathPattern=digitaldefiance-express-suite-react-components --coverageReporters=text",
|
|
15
15
|
"lint": "npx nx lint digitaldefiance-express-suite-react-components",
|
|
16
16
|
"lint:fix": "npx nx lint digitaldefiance-express-suite-react-components --fix",
|
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
"react-router-dom": "6.29.0"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@digitaldefiance/i18n-lib": "3.6.
|
|
29
|
-
"@digitaldefiance/suite-core-lib": "^2.2.
|
|
28
|
+
"@digitaldefiance/i18n-lib": "3.6.2",
|
|
29
|
+
"@digitaldefiance/suite-core-lib": "^2.2.19",
|
|
30
30
|
"@emotion/react": "^11.14.0",
|
|
31
31
|
"@emotion/styled": "^11.14.0",
|
|
32
32
|
"@mui/icons-material": "^7.0.2",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AuthProvider.d.ts","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-express-suite-react-components/src/contexts/AuthProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,cAAc,EAE/B,WAAW,EACX,YAAY,EACZ,YAAY,EAIb,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAEL,YAAY,EAEb,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAEL,SAAS,EAMV,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"AuthProvider.d.ts","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-express-suite-react-components/src/contexts/AuthProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,cAAc,EAE/B,WAAW,EACX,YAAY,EACZ,YAAY,EAIb,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAEL,YAAY,EAEb,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAEL,SAAS,EAMV,MAAM,OAAO,CAAC;AAOf,OAAO,EAAE,eAAe,EAAE,eAAe,EAA4C,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAEzI,MAAM,WAAW,eAAe;IAC9B;;OAEG;IACH,KAAK,EAAE,OAAO,CAAC;IACf;;OAEG;I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AG;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACvM,OAAO,EAAE,CAAC,IAAI,EAAE,eAAe,GAAG,IAAI,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACzD,SAAS,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,eAAe,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IAC9D,IAAI,EAAE,cAAc,GAAG,IAAI,CAAC;IAC5B,QAAQ,EAAE,eAAe,GAAG,IAAI,CAAC;IACjC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,uBAAuB,EAAE,MAAM,CAAC;IAChC,WAAW,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;CAClD;AAED,MAAM,MAAM,iBAAiB,GAAG;IAC9B,QAAQ,EAAE,SAAS,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,UAAU,CAAC;IACtB,WAAW,EAAE,YAAY,CAAC;IAC1B;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAC;CACvB,CAAC;AAEF,eAAO,MAAM,WAAW,0CAEvB,CAAC;AAkhBF,eAAO,MAAM,YAAY,GAAI,yDAAyD,iBAAiB,4CAMtG,CAAC;AAEF,eAAO,MAAM,OAAO,uBAEnB,CAAC"}
|
|
@@ -6,6 +6,7 @@ const ecies_lib_1 = require("@digitaldefiance/ecies-lib");
|
|
|
6
6
|
const i18n_lib_1 = require("@digitaldefiance/i18n-lib");
|
|
7
7
|
const react_1 = require("react");
|
|
8
8
|
const I18nProvider_1 = require("./I18nProvider");
|
|
9
|
+
const ThemeProvider_1 = require("./ThemeProvider");
|
|
9
10
|
const authService_1 = require("../services/authService");
|
|
10
11
|
const authenticatedApi_1 = require("../services/authenticatedApi");
|
|
11
12
|
const useExpiringValue_1 = require("../hooks/useExpiringValue");
|
|
@@ -14,6 +15,7 @@ const suite_core_lib_1 = require("@digitaldefiance/suite-core-lib");
|
|
|
14
15
|
exports.AuthContext = (0, react_1.createContext)({});
|
|
15
16
|
const AuthProviderInner = ({ children, baseUrl, constants, eciesConfig, onLogout }) => {
|
|
16
17
|
const { changeLanguage, currentLanguage, t, tComponent } = (0, I18nProvider_1.useI18n)();
|
|
18
|
+
const { setColorMode } = (0, ThemeProvider_1.useTheme)();
|
|
17
19
|
const authService = (0, react_1.useMemo)(() => (0, authService_1.createAuthService)(constants, baseUrl, eciesConfig), [constants, baseUrl, eciesConfig]);
|
|
18
20
|
const authenticatedApi = (0, react_1.useMemo)(() => (0, authenticatedApi_1.createAuthenticatedApiClient)(baseUrl), [baseUrl]);
|
|
19
21
|
// Use the custom hooks for expiring values
|
|
@@ -97,6 +99,8 @@ const AuthProviderInner = ({ children, baseUrl, constants, eciesConfig, onLogout
|
|
|
97
99
|
setIsGlobalAdmin(userData.roles.some((r) => r.admin));
|
|
98
100
|
setIsAuthenticated(true);
|
|
99
101
|
setToken(token);
|
|
102
|
+
// Set theme based on user's darkMode preference
|
|
103
|
+
setColorMode(userData.darkMode ? 'dark' : 'light');
|
|
100
104
|
}
|
|
101
105
|
}
|
|
102
106
|
catch (error) {
|
|
@@ -109,7 +113,7 @@ const AuthProviderInner = ({ children, baseUrl, constants, eciesConfig, onLogout
|
|
|
109
113
|
setLoading(false);
|
|
110
114
|
setIsCheckingAuth(false);
|
|
111
115
|
}
|
|
112
|
-
}, [authService, clearMnemonic, clearWallet]);
|
|
116
|
+
}, [authService, clearMnemonic, clearWallet, setColorMode]);
|
|
113
117
|
(0, react_1.useEffect)(() => {
|
|
114
118
|
const token = localStorage.getItem('authToken');
|
|
115
119
|
if (token) {
|
|
@@ -137,10 +141,12 @@ const AuthProviderInner = ({ children, baseUrl, constants, eciesConfig, onLogout
|
|
|
137
141
|
setAuthState((prev) => prev + 1);
|
|
138
142
|
localStorage.setItem('authToken', loginResult.token);
|
|
139
143
|
localStorage.setItem('user', JSON.stringify(loginResult.user));
|
|
144
|
+
// Set theme based on user's darkMode preference
|
|
145
|
+
setColorMode(loginResult.user.darkMode ? 'dark' : 'light');
|
|
140
146
|
return loginResult;
|
|
141
147
|
}
|
|
142
148
|
return loginResult;
|
|
143
|
-
}, [authService, setMnemonic, setWallet]);
|
|
149
|
+
}, [authService, setMnemonic, setWallet, setColorMode]);
|
|
144
150
|
const emailChallengeLogin = (0, react_1.useCallback)(async (mnemonic, token, username, email, expireMnemonicSeconds, expireWalletSeconds) => {
|
|
145
151
|
setLoading(true);
|
|
146
152
|
const loginResult = await authService.emailChallengeLogin(mnemonic, token, username, email);
|
|
@@ -156,10 +162,12 @@ const AuthProviderInner = ({ children, baseUrl, constants, eciesConfig, onLogout
|
|
|
156
162
|
setAuthState((prev) => prev + 1);
|
|
157
163
|
localStorage.setItem('authToken', loginResult.token);
|
|
158
164
|
localStorage.setItem('user', JSON.stringify(loginResult.user));
|
|
165
|
+
// Set theme based on user's darkMode preference
|
|
166
|
+
setColorMode(loginResult.user.darkMode ? 'dark' : 'light');
|
|
159
167
|
return loginResult;
|
|
160
168
|
}
|
|
161
169
|
return loginResult;
|
|
162
|
-
}, [authService, setMnemonic, setWallet]);
|
|
170
|
+
}, [authService, setMnemonic, setWallet, setColorMode]);
|
|
163
171
|
const getPasswordLoginService = (0, react_1.useCallback)(() => {
|
|
164
172
|
const eciesService = new ecies_lib_1.ECIESService(eciesConfig);
|
|
165
173
|
return new ecies_lib_1.PasswordLoginService(eciesService, new ecies_lib_1.Pbkdf2Service(ecies_lib_1.Constants.PBKDF2_PROFILES, ecies_lib_1.Constants.ECIES, ecies_lib_1.Constants.PBKDF2));
|
|
@@ -179,8 +187,12 @@ const AuthProviderInner = ({ children, baseUrl, constants, eciesConfig, onLogout
|
|
|
179
187
|
setLoading(false);
|
|
180
188
|
setWallet(wallet);
|
|
181
189
|
setMnemonic(mnemonic);
|
|
190
|
+
// Set theme based on user's darkMode preference if login succeeded
|
|
191
|
+
if ('user' in loginResult) {
|
|
192
|
+
setColorMode(loginResult.user.darkMode ? 'dark' : 'light');
|
|
193
|
+
}
|
|
182
194
|
return loginResult;
|
|
183
|
-
}, [authService, getPasswordLoginService, setMnemonic, setWallet, t, tComponent, isPasswordLoginAvailable]);
|
|
195
|
+
}, [authService, getPasswordLoginService, setMnemonic, setWallet, t, tComponent, isPasswordLoginAvailable, setColorMode]);
|
|
184
196
|
const refreshToken = (0, react_1.useCallback)(async () => {
|
|
185
197
|
try {
|
|
186
198
|
const result = await authService.refreshToken();
|
|
@@ -232,6 +244,8 @@ const AuthProviderInner = ({ children, baseUrl, constants, eciesConfig, onLogout
|
|
|
232
244
|
if (loginResult.user) {
|
|
233
245
|
setUser(loginResult.user);
|
|
234
246
|
setIsAuthenticated(true);
|
|
247
|
+
// Set theme based on user's darkMode preference
|
|
248
|
+
setColorMode(loginResult.user.darkMode ? 'dark' : 'light');
|
|
235
249
|
}
|
|
236
250
|
setAuthState((prev) => prev + 1);
|
|
237
251
|
return {
|
|
@@ -242,7 +256,7 @@ const AuthProviderInner = ({ children, baseUrl, constants, eciesConfig, onLogout
|
|
|
242
256
|
};
|
|
243
257
|
}
|
|
244
258
|
return loginResult;
|
|
245
|
-
}, [baseUrl]);
|
|
259
|
+
}, [baseUrl, setColorMode]);
|
|
246
260
|
const logout = (0, react_1.useCallback)(async () => {
|
|
247
261
|
localStorage.removeItem('user');
|
|
248
262
|
localStorage.removeItem('authToken');
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
export interface SuiteConfigRoutes {
|
|
3
|
+
dashboard?: string;
|
|
4
|
+
login?: string;
|
|
5
|
+
register?: string;
|
|
6
|
+
verifyEmail?: string;
|
|
7
|
+
forgotPassword?: string;
|
|
8
|
+
resetPassword?: string;
|
|
9
|
+
settings?: string;
|
|
10
|
+
}
|
|
11
|
+
export interface SuiteConfigContextData {
|
|
12
|
+
/**
|
|
13
|
+
* Base URL for API calls
|
|
14
|
+
*/
|
|
15
|
+
baseUrl: string;
|
|
16
|
+
/**
|
|
17
|
+
* Application routes for navigation
|
|
18
|
+
*/
|
|
19
|
+
routes: SuiteConfigRoutes;
|
|
20
|
+
/**
|
|
21
|
+
* Available languages for the application
|
|
22
|
+
*/
|
|
23
|
+
languages: Array<{
|
|
24
|
+
code: string;
|
|
25
|
+
label: string;
|
|
26
|
+
}>;
|
|
27
|
+
/**
|
|
28
|
+
* Available timezones
|
|
29
|
+
*/
|
|
30
|
+
timezones?: string[];
|
|
31
|
+
}
|
|
32
|
+
export interface SuiteConfigProviderProps {
|
|
33
|
+
children: ReactNode;
|
|
34
|
+
baseUrl: string;
|
|
35
|
+
routes?: Partial<SuiteConfigRoutes>;
|
|
36
|
+
languages?: Array<{
|
|
37
|
+
code: string;
|
|
38
|
+
label: string;
|
|
39
|
+
}>;
|
|
40
|
+
timezones?: string[];
|
|
41
|
+
}
|
|
42
|
+
export declare const SuiteConfigProvider: ({ children, baseUrl, routes, languages, timezones, }: SuiteConfigProviderProps) => import("react/jsx-runtime").JSX.Element;
|
|
43
|
+
export declare const useSuiteConfig: () => SuiteConfigContextData;
|
|
44
|
+
//# sourceMappingURL=SuiteConfigProvider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SuiteConfigProvider.d.ts","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-express-suite-react-components/src/contexts/SuiteConfigProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAiB,SAAS,EAAc,MAAM,OAAO,CAAC;AAE7D,MAAM,WAAW,iBAAiB;IAChC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,sBAAsB;IACrC;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,MAAM,EAAE,iBAAiB,CAAC;IAE1B;;OAEG;IACH,SAAS,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAElD;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;CACtB;AAyBD,MAAM,WAAW,wBAAwB;IACvC,QAAQ,EAAE,SAAS,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,OAAO,CAAC,iBAAiB,CAAC,CAAC;IACpC,SAAS,CAAC,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACnD,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;CACtB;AAED,eAAO,MAAM,mBAAmB,GAAI,sDAMjC,wBAAwB,4CAa1B,CAAC;AAEF,eAAO,MAAM,cAAc,QAAO,sBAMjC,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useSuiteConfig = exports.SuiteConfigProvider = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const react_1 = require("react");
|
|
6
|
+
const defaultRoutes = {
|
|
7
|
+
dashboard: '/dashboard',
|
|
8
|
+
login: '/login',
|
|
9
|
+
register: '/register',
|
|
10
|
+
verifyEmail: '/verify-email',
|
|
11
|
+
forgotPassword: '/forgot-password',
|
|
12
|
+
resetPassword: '/reset-password',
|
|
13
|
+
settings: '/settings',
|
|
14
|
+
};
|
|
15
|
+
const defaultLanguages = [
|
|
16
|
+
{ code: 'en-US', label: 'English (US)' },
|
|
17
|
+
{ code: 'en-GB', label: 'English (UK)' },
|
|
18
|
+
{ code: 'es-ES', label: 'Español' },
|
|
19
|
+
{ code: 'fr-FR', label: 'Français' },
|
|
20
|
+
{ code: 'de-DE', label: 'Deutsch' },
|
|
21
|
+
{ code: 'ja', label: '日本語' },
|
|
22
|
+
{ code: 'zh-CN', label: '中文 (简体)' },
|
|
23
|
+
{ code: 'uk', label: 'Українська' },
|
|
24
|
+
];
|
|
25
|
+
const SuiteConfigContext = (0, react_1.createContext)(undefined);
|
|
26
|
+
const SuiteConfigProvider = ({ children, baseUrl, routes = {}, languages = defaultLanguages, timezones, }) => {
|
|
27
|
+
const value = {
|
|
28
|
+
baseUrl,
|
|
29
|
+
routes: { ...defaultRoutes, ...routes },
|
|
30
|
+
languages,
|
|
31
|
+
timezones,
|
|
32
|
+
};
|
|
33
|
+
return ((0, jsx_runtime_1.jsx)(SuiteConfigContext.Provider, { value: value, children: children }));
|
|
34
|
+
};
|
|
35
|
+
exports.SuiteConfigProvider = SuiteConfigProvider;
|
|
36
|
+
const useSuiteConfig = () => {
|
|
37
|
+
const context = (0, react_1.useContext)(SuiteConfigContext);
|
|
38
|
+
if (!context) {
|
|
39
|
+
throw new Error('useSuiteConfig must be used within a SuiteConfigProvider');
|
|
40
|
+
}
|
|
41
|
+
return context;
|
|
42
|
+
};
|
|
43
|
+
exports.useSuiteConfig = useSuiteConfig;
|
|
@@ -2,6 +2,7 @@ import { PaletteMode, Theme } from '@mui/material';
|
|
|
2
2
|
import { FC, ReactNode } from 'react';
|
|
3
3
|
export interface ThemeContextType {
|
|
4
4
|
toggleColorMode: () => void;
|
|
5
|
+
setColorMode: (mode: PaletteMode) => void;
|
|
5
6
|
mode: PaletteMode;
|
|
6
7
|
}
|
|
7
8
|
export declare const useTheme: () => ThemeContextType;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ThemeProvider.d.ts","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-express-suite-react-components/src/contexts/ThemeProvider.tsx"],"names":[],"mappings":"AACA,OAAO,EAGL,WAAW,EAEX,KAAK,EACN,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,EAAE,EAAE,SAAS,EAAgD,MAAM,OAAO,CAAC;AAEpF,MAAM,WAAW,gBAAgB;IAC/B,eAAe,EAAE,MAAM,IAAI,CAAC;IAC5B,IAAI,EAAE,WAAW,CAAC;CACnB;AAID,eAAO,MAAM,QAAQ,wBAMpB,CAAC;AAEF,MAAM,WAAW,qBAAqB;IACpC,QAAQ,EAAE,SAAS,CAAC;IACpB,WAAW,CAAC,EAAE,CAAC,IAAI,EAAE,WAAW,KAAK,KAAK,CAAC;CAC5C;AAED,eAAO,MAAM,gBAAgB,EAAE,EAAE,CAAC,qBAAqB,
|
|
1
|
+
{"version":3,"file":"ThemeProvider.d.ts","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-express-suite-react-components/src/contexts/ThemeProvider.tsx"],"names":[],"mappings":"AACA,OAAO,EAGL,WAAW,EAEX,KAAK,EACN,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,EAAE,EAAE,SAAS,EAAgD,MAAM,OAAO,CAAC;AAEpF,MAAM,WAAW,gBAAgB;IAC/B,eAAe,EAAE,MAAM,IAAI,CAAC;IAC5B,YAAY,EAAE,CAAC,IAAI,EAAE,WAAW,KAAK,IAAI,CAAC;IAC1C,IAAI,EAAE,WAAW,CAAC;CACnB;AAID,eAAO,MAAM,QAAQ,wBAMpB,CAAC;AAEF,MAAM,WAAW,qBAAqB;IACpC,QAAQ,EAAE,SAAS,CAAC;IACpB,WAAW,CAAC,EAAE,CAAC,IAAI,EAAE,WAAW,KAAK,KAAK,CAAC;CAC5C;AAED,eAAO,MAAM,gBAAgB,EAAE,EAAE,CAAC,qBAAqB,CA0BtD,CAAC;AAEF,eAAO,MAAM,iBAAiB,EAAE,EAO/B,CAAC"}
|
|
@@ -20,6 +20,9 @@ const AppThemeProvider = ({ children, customTheme }) => {
|
|
|
20
20
|
toggleColorMode: () => {
|
|
21
21
|
setMode((prevMode) => (prevMode === 'light' ? 'dark' : 'light'));
|
|
22
22
|
},
|
|
23
|
+
setColorMode: (newMode) => {
|
|
24
|
+
setMode(newMode);
|
|
25
|
+
},
|
|
23
26
|
mode,
|
|
24
27
|
}), [mode]);
|
|
25
28
|
const theme = (0, react_1.useMemo)(() => (customTheme ? customTheme(mode) : (0, material_1.createTheme)({ palette: { mode } })), [mode, customTheme]);
|
package/src/contexts/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-express-suite-react-components/src/contexts/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-express-suite-react-components/src/contexts/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,uBAAuB,CAAC"}
|
package/src/contexts/index.js
CHANGED
|
@@ -5,3 +5,4 @@ tslib_1.__exportStar(require("./AuthProvider"), exports);
|
|
|
5
5
|
tslib_1.__exportStar(require("./MenuContext"), exports);
|
|
6
6
|
tslib_1.__exportStar(require("./I18nProvider"), exports);
|
|
7
7
|
tslib_1.__exportStar(require("./ThemeProvider"), exports);
|
|
8
|
+
tslib_1.__exportStar(require("./SuiteConfigProvider"), exports);
|
package/src/hooks/index.d.ts
CHANGED
package/src/hooks/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-express-suite-react-components/src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-express-suite-react-components/src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,wBAAwB,CAAC"}
|
package/src/hooks/index.js
CHANGED
|
@@ -3,3 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
tslib_1.__exportStar(require("./useExpiringValue"), exports);
|
|
5
5
|
tslib_1.__exportStar(require("./useLocalStorage"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./useBackupCodes"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./useUserSettings"), exports);
|
|
8
|
+
tslib_1.__exportStar(require("./useEmailVerification"), exports);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export interface UseBackupCodesOptions {
|
|
2
|
+
initialCodeCount?: number | null;
|
|
3
|
+
}
|
|
4
|
+
export interface UseBackupCodesResult {
|
|
5
|
+
backupCodesRemaining: number | null;
|
|
6
|
+
isLoading: boolean;
|
|
7
|
+
error: Error | null;
|
|
8
|
+
generateBackupCodes: (password?: string, mnemonic?: string) => Promise<{
|
|
9
|
+
message: string;
|
|
10
|
+
backupCodes: string[];
|
|
11
|
+
}>;
|
|
12
|
+
refreshCodeCount: () => Promise<void>;
|
|
13
|
+
}
|
|
14
|
+
export declare const useBackupCodes: (options?: UseBackupCodesOptions) => UseBackupCodesResult;
|
|
15
|
+
//# sourceMappingURL=useBackupCodes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useBackupCodes.d.ts","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-express-suite-react-components/src/hooks/useBackupCodes.ts"],"names":[],"mappings":"AAKA,MAAM,WAAW,qBAAqB;IACpC,gBAAgB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAClC;AAED,MAAM,WAAW,oBAAoB;IACnC,oBAAoB,EAAE,MAAM,GAAG,IAAI,CAAC;IACpC,SAAS,EAAE,OAAO,CAAC;IACnB,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IACpB,mBAAmB,EAAE,CAAC,QAAQ,CAAC,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC;QACrE,OAAO,EAAE,MAAM,CAAC;QAChB,WAAW,EAAE,MAAM,EAAE,CAAC;KACvB,CAAC,CAAC;IACH,gBAAgB,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CACvC;AAED,eAAO,MAAM,cAAc,GACzB,UAAS,qBAA0B,KAClC,oBA8DF,CAAC"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useBackupCodes = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const services_1 = require("../services");
|
|
6
|
+
const contexts_1 = require("../contexts");
|
|
7
|
+
const suite_core_lib_1 = require("@digitaldefiance/suite-core-lib");
|
|
8
|
+
const useBackupCodes = (options = {}) => {
|
|
9
|
+
const { baseUrl } = (0, contexts_1.useSuiteConfig)();
|
|
10
|
+
const [backupCodesRemaining, setBackupCodesRemaining] = (0, react_1.useState)(options.initialCodeCount ?? null);
|
|
11
|
+
const [isLoading, setIsLoading] = (0, react_1.useState)(false);
|
|
12
|
+
const [error, setError] = (0, react_1.useState)(null);
|
|
13
|
+
const requestedOnMountRef = (0, react_1.useRef)(false);
|
|
14
|
+
const api = (0, react_1.useMemo)(() => (0, services_1.createAuthenticatedApiClient)(baseUrl), [baseUrl]);
|
|
15
|
+
const refreshCodeCount = (0, react_1.useCallback)(async () => {
|
|
16
|
+
setIsLoading(true);
|
|
17
|
+
setError(null);
|
|
18
|
+
try {
|
|
19
|
+
const result = await api.get('/user/backup-codes');
|
|
20
|
+
if (result?.data?.codeCount !== undefined) {
|
|
21
|
+
setBackupCodesRemaining(result.data.codeCount);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
catch (err) {
|
|
25
|
+
setError(err instanceof Error ? err : new suite_core_lib_1.TranslatableSuiteError(suite_core_lib_1.SuiteCoreStringKey.BackupCodes_FailedToFetch));
|
|
26
|
+
setBackupCodesRemaining(0);
|
|
27
|
+
}
|
|
28
|
+
finally {
|
|
29
|
+
setIsLoading(false);
|
|
30
|
+
}
|
|
31
|
+
}, [api]);
|
|
32
|
+
(0, react_1.useEffect)(() => {
|
|
33
|
+
if (requestedOnMountRef.current)
|
|
34
|
+
return;
|
|
35
|
+
if (backupCodesRemaining !== null)
|
|
36
|
+
return;
|
|
37
|
+
requestedOnMountRef.current = true;
|
|
38
|
+
refreshCodeCount();
|
|
39
|
+
}, [backupCodesRemaining, refreshCodeCount]);
|
|
40
|
+
const generateBackupCodes = async (password, mnemonic) => {
|
|
41
|
+
setIsLoading(true);
|
|
42
|
+
setError(null);
|
|
43
|
+
try {
|
|
44
|
+
const result = await api.post('/user/backup-codes', {
|
|
45
|
+
...(password ? { password } : {}),
|
|
46
|
+
...(mnemonic ? { mnemonic } : {}),
|
|
47
|
+
});
|
|
48
|
+
return {
|
|
49
|
+
message: result.data.message,
|
|
50
|
+
backupCodes: result.data.backupCodes,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
catch (err) {
|
|
54
|
+
const error = err instanceof Error ? err : new suite_core_lib_1.TranslatableSuiteError(suite_core_lib_1.SuiteCoreStringKey.BackupCodes_FailedToGenerate);
|
|
55
|
+
setError(error);
|
|
56
|
+
throw error;
|
|
57
|
+
}
|
|
58
|
+
finally {
|
|
59
|
+
setIsLoading(false);
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
return {
|
|
63
|
+
backupCodesRemaining,
|
|
64
|
+
isLoading,
|
|
65
|
+
error,
|
|
66
|
+
generateBackupCodes,
|
|
67
|
+
refreshCodeCount,
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
exports.useBackupCodes = useBackupCodes;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export interface UseEmailVerificationResult {
|
|
2
|
+
isVerifying: boolean;
|
|
3
|
+
error: Error | null;
|
|
4
|
+
verifyEmail: (token: string) => Promise<{
|
|
5
|
+
success: boolean;
|
|
6
|
+
message?: string;
|
|
7
|
+
}>;
|
|
8
|
+
}
|
|
9
|
+
export declare const useEmailVerification: () => UseEmailVerificationResult;
|
|
10
|
+
//# sourceMappingURL=useEmailVerification.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useEmailVerification.d.ts","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-express-suite-react-components/src/hooks/useEmailVerification.ts"],"names":[],"mappings":"AAKA,MAAM,WAAW,0BAA0B;IACzC,WAAW,EAAE,OAAO,CAAC;IACrB,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IACpB,WAAW,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC;QAAE,OAAO,EAAE,OAAO,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CACjF;AAED,eAAO,MAAM,oBAAoB,QAAO,0BA2BvC,CAAC"}
|