@frontegg/react-hooks 5.61.0 → 6.0.1-alpha.0
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/FronteggProvider.d.ts +11 -10
- package/FronteggProvider.js +137 -0
- package/FronteggStoreContext.d.ts +8 -8
- package/FronteggStoreContext.js +13 -0
- package/audits/auditLogs.d.ts +5 -5
- package/audits/auditLogs.js +4 -0
- package/audits/auditsMetadata.d.ts +5 -5
- package/audits/auditsMetadata.js +4 -0
- package/audits/hooks.d.ts +12 -12
- package/audits/hooks.js +35 -0
- package/audits/index.d.ts +3 -3
- package/audits/index.js +3 -5
- package/auth/acceptInvitation.d.ts +5 -5
- package/auth/acceptInvitation.js +4 -0
- package/auth/activateAccount.d.ts +5 -5
- package/auth/activateAccount.js +4 -0
- package/auth/apiTokens.d.ts +5 -5
- package/auth/apiTokens.js +4 -0
- package/auth/forgotPassword.d.ts +5 -5
- package/auth/forgotPassword.js +4 -0
- package/auth/hooks.d.ts +62 -62
- package/auth/hooks.js +79 -0
- package/auth/index.d.ts +16 -16
- package/auth/index.js +16 -7
- package/auth/login.d.ts +5 -5
- package/auth/login.js +4 -0
- package/auth/mfa.d.ts +4 -4
- package/auth/mfa.js +4 -0
- package/auth/profile.d.ts +6 -6
- package/auth/profile.js +16 -0
- package/auth/resetPhoneNumber.d.ts +5 -5
- package/auth/resetPhoneNumber.js +4 -0
- package/auth/roles.d.ts +5 -5
- package/auth/roles.js +4 -0
- package/auth/securityPolicy.d.ts +11 -17
- package/auth/securityPolicy.js +25 -0
- package/auth/signup.d.ts +5 -5
- package/auth/signup.js +4 -0
- package/auth/socialLogin.d.ts +5 -5
- package/auth/socialLogin.js +4 -0
- package/auth/sso.d.ts +4 -4
- package/auth/sso.js +4 -0
- package/auth/team.d.ts +5 -5
- package/auth/team.js +4 -0
- package/auth/tenants.d.ts +5 -5
- package/auth/tenants.js +4 -0
- package/common/index.d.ts +17 -17
- package/common/index.js +30 -0
- package/common/package.json +6 -0
- package/connectivity/hooks.d.ts +5 -5
- package/connectivity/hooks.js +15 -0
- package/connectivity/index.d.ts +1 -1
- package/connectivity/index.js +1 -5
- package/index.d.ts +8 -8
- package/index.js +13 -93
- package/node/FronteggProvider.js +160 -0
- package/node/FronteggStoreContext.js +49 -0
- package/node/audits/auditLogs.js +18 -0
- package/node/audits/auditsMetadata.js +18 -0
- package/node/audits/hooks.js +62 -0
- package/node/audits/index.js +46 -13
- package/node/auth/acceptInvitation.js +18 -0
- package/node/auth/activateAccount.js +18 -0
- package/node/auth/apiTokens.js +18 -0
- package/node/auth/forgotPassword.js +18 -0
- package/node/auth/hooks.js +127 -0
- package/node/auth/index.js +275 -55
- package/node/auth/login.js +18 -0
- package/node/auth/mfa.js +18 -0
- package/node/auth/profile.js +34 -0
- package/node/auth/resetPhoneNumber.js +18 -0
- package/node/auth/roles.js +18 -0
- package/node/auth/securityPolicy.js +43 -0
- package/node/auth/signup.js +18 -0
- package/node/auth/socialLogin.js +18 -0
- package/node/auth/sso.js +18 -0
- package/node/auth/team.js +18 -0
- package/node/auth/tenants.js +18 -0
- package/node/common/index.js +44 -0
- package/node/connectivity/hooks.js +31 -0
- package/node/connectivity/index.js +17 -12
- package/node/index.js +111 -188
- package/node/subscriptions/hooks.js +131 -0
- package/node/subscriptions/index.js +15 -27
- package/node/vendor/hooks.js +31 -0
- package/node/vendor/index.js +17 -12
- package/package.json +12 -7
- package/subscriptions/hooks.d.ts +19 -19
- package/subscriptions/hooks.js +69 -0
- package/subscriptions/index.d.ts +1 -1
- package/subscriptions/index.js +1 -5
- package/vendor/hooks.d.ts +5 -5
- package/vendor/hooks.js +15 -0
- package/vendor/index.d.ts +1 -1
- package/vendor/index.js +1 -5
- package/FronteggStoreContext-d6c3b684.js +0 -9
- package/auditsMetadata-9ab88593.js +0 -35
- package/hooks-6400e233.js +0 -14
- package/hooks-7fc5d634.js +0 -64
- package/hooks-eaf879c9.js +0 -14
- package/node/FronteggStoreContext-6cfac56c.js +0 -18
- package/node/auditsMetadata-d15799a1.js +0 -42
- package/node/hooks-429ffd3a.js +0 -83
- package/node/hooks-5d5a445e.js +0 -17
- package/node/hooks-cf739b27.js +0 -17
- package/node/roles-33447247.js +0 -225
- package/roles-18da4c43.js +0 -181
package/FronteggProvider.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { FC } from 'react';
|
|
2
|
-
import { ContextOptions } from '@frontegg/rest-api';
|
|
3
|
-
import { FronteggAppInstance } from '@frontegg/types';
|
|
4
|
-
declare type FronteggProviderProps = {
|
|
5
|
-
app?: FronteggAppInstance;
|
|
6
|
-
contextOptions?: ContextOptions;
|
|
7
|
-
setLoading?: (loading: boolean) => void;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
export
|
|
1
|
+
import { FC, ReactNode } from 'react';
|
|
2
|
+
import { ContextOptions } from '@frontegg/rest-api';
|
|
3
|
+
import { FronteggAppInstance } from '@frontegg/types';
|
|
4
|
+
declare type FronteggProviderProps = {
|
|
5
|
+
app?: FronteggAppInstance;
|
|
6
|
+
contextOptions?: ContextOptions;
|
|
7
|
+
setLoading?: (loading: boolean) => void;
|
|
8
|
+
children?: ReactNode | undefined;
|
|
9
|
+
};
|
|
10
|
+
export declare const FronteggStoreProvider: FC<FronteggProviderProps>;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
2
|
+
const _excluded = ["authenticatedUrl", "signUpSuccessUrl"];
|
|
3
|
+
import React, { useEffect, useMemo, useRef, useState } from 'react';
|
|
4
|
+
import { Provider } from 'react-redux';
|
|
5
|
+
import { createFronteggStore } from '@frontegg/redux-store';
|
|
6
|
+
import { ContextHolder } from '@frontegg/rest-api';
|
|
7
|
+
import { useAuth, useAuthRoutes } from './auth';
|
|
8
|
+
import { FronteggStoreContext } from './FronteggStoreContext';
|
|
9
|
+
import { Fragment as _Fragment } from "react/jsx-runtime";
|
|
10
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
11
|
+
|
|
12
|
+
const setLoading = loading => {
|
|
13
|
+
const isSSR = typeof document === 'undefined' || typeof window === 'undefined';
|
|
14
|
+
|
|
15
|
+
if (!isSSR) {
|
|
16
|
+
if (loading) {
|
|
17
|
+
document.body.classList.add('frontegg-loading');
|
|
18
|
+
} else {
|
|
19
|
+
document.body.classList.remove('frontegg-loading');
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const HideChildrenIfFronteggRoutes = ({
|
|
25
|
+
children,
|
|
26
|
+
basename
|
|
27
|
+
}) => {
|
|
28
|
+
const routes = useAuthRoutes();
|
|
29
|
+
const uriRef = useRef(window.location.pathname);
|
|
30
|
+
const animationFrameRef = useRef(0);
|
|
31
|
+
const [uri, setUri] = useState(window.location.pathname);
|
|
32
|
+
|
|
33
|
+
const checker = () => {
|
|
34
|
+
if (uriRef.current !== window.location.pathname) {
|
|
35
|
+
uriRef.current = window.location.pathname;
|
|
36
|
+
setUri(document.location.pathname);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
animationFrameRef.current = window.requestAnimationFrame(checker);
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
useEffect(() => {
|
|
43
|
+
document.addEventListener('frontegg_onRedirectTo_fired', () => {
|
|
44
|
+
if (uriRef.current !== window.location.pathname) {
|
|
45
|
+
uriRef.current = window.location.pathname;
|
|
46
|
+
setUri(document.location.pathname);
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
window.addEventListener('popstate', () => {
|
|
50
|
+
if (uriRef.current !== window.location.pathname) {
|
|
51
|
+
uriRef.current = window.location.pathname;
|
|
52
|
+
setUri(document.location.pathname);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
animationFrameRef.current = window.requestAnimationFrame(checker);
|
|
56
|
+
return () => {
|
|
57
|
+
window.cancelAnimationFrame(animationFrameRef.current);
|
|
58
|
+
};
|
|
59
|
+
}, [setUri]);
|
|
60
|
+
const calculatedBasename = basename ? basename.endsWith('/') ? basename.substring(0, basename.length - 1) : '' : '';
|
|
61
|
+
|
|
62
|
+
const checkRoutes = _objectWithoutPropertiesLoose(routes, _excluded);
|
|
63
|
+
|
|
64
|
+
if (Object.values(checkRoutes).map(url => `${calculatedBasename}${url}`).indexOf(uri) !== -1) {
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return _jsx(_Fragment, {
|
|
69
|
+
children: children
|
|
70
|
+
});
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
const FronteggContent = ({
|
|
74
|
+
children,
|
|
75
|
+
app,
|
|
76
|
+
setLoading
|
|
77
|
+
}) => {
|
|
78
|
+
var _app$options, _app$options2, _app$options3;
|
|
79
|
+
|
|
80
|
+
const {
|
|
81
|
+
isLoading
|
|
82
|
+
} = useAuth(({
|
|
83
|
+
isLoading
|
|
84
|
+
}) => ({
|
|
85
|
+
isLoading
|
|
86
|
+
}));
|
|
87
|
+
const customLoginBox = !app || (app == null ? void 0 : (_app$options = app.options) == null ? void 0 : _app$options.customLoginBox) === true;
|
|
88
|
+
const alwaysShowChildren = customLoginBox || (app == null ? void 0 : (_app$options2 = app.options) == null ? void 0 : _app$options2.hostedLoginBox) === true && (app == null ? void 0 : (_app$options3 = app.options) == null ? void 0 : _app$options3.framework) === 'nextjs';
|
|
89
|
+
const loadingRef = useRef(undefined);
|
|
90
|
+
|
|
91
|
+
if (isLoading !== loadingRef.current) {
|
|
92
|
+
loadingRef.current = isLoading;
|
|
93
|
+
setLoading(isLoading);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (isLoading) {
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (alwaysShowChildren) {
|
|
101
|
+
return _jsx(_Fragment, {
|
|
102
|
+
children: children
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return _jsx(HideChildrenIfFronteggRoutes, {
|
|
107
|
+
basename: app == null ? void 0 : app.options.basename,
|
|
108
|
+
children: children
|
|
109
|
+
});
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
export const FronteggStoreProvider = props => {
|
|
113
|
+
var _app$options$contextO, _app$options4, _app$options$previewM, _app$options5, _app$options$authOpti, _app$options6;
|
|
114
|
+
|
|
115
|
+
const {
|
|
116
|
+
children,
|
|
117
|
+
app,
|
|
118
|
+
contextOptions,
|
|
119
|
+
setLoading: setLoadingProps
|
|
120
|
+
} = props;
|
|
121
|
+
const context = (_app$options$contextO = app == null ? void 0 : (_app$options4 = app.options) == null ? void 0 : _app$options4.contextOptions) != null ? _app$options$contextO : contextOptions;
|
|
122
|
+
const previewMode = (_app$options$previewM = app == null ? void 0 : (_app$options5 = app.options) == null ? void 0 : _app$options5.previewMode) != null ? _app$options$previewM : false;
|
|
123
|
+
const authOptions = (_app$options$authOpti = app == null ? void 0 : (_app$options6 = app.options) == null ? void 0 : _app$options6.authOptions) != null ? _app$options$authOpti : {};
|
|
124
|
+
ContextHolder.setContext(context);
|
|
125
|
+
const store = useMemo(() => createFronteggStore({
|
|
126
|
+
context: context
|
|
127
|
+
}, app, previewMode, authOptions), [app, previewMode]);
|
|
128
|
+
return _jsx(Provider, {
|
|
129
|
+
context: FronteggStoreContext,
|
|
130
|
+
store: store,
|
|
131
|
+
children: _jsx(FronteggContent, {
|
|
132
|
+
setLoading: setLoadingProps != null ? setLoadingProps : setLoading,
|
|
133
|
+
app: app,
|
|
134
|
+
children: children
|
|
135
|
+
})
|
|
136
|
+
});
|
|
137
|
+
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { ReactReduxContextValue } from 'react-redux';
|
|
3
|
-
export declare const FronteggStoreContext: React.Context<ReactReduxContextValue<any, import("redux").AnyAction>>;
|
|
4
|
-
export declare const useSelector: <Selected extends unknown>(selector: (state: any) => Selected, equalityFn?: ((previous: Selected, next: Selected) => boolean) | undefined) => Selected;
|
|
5
|
-
export declare const useDispatch: () => import("redux").Dispatch<import("redux").AnyAction>;
|
|
6
|
-
export declare const useStore: () => import("redux").Store<any, import("redux").AnyAction>;
|
|
7
|
-
export { shallowEqual, connectAdvanced, Provider } from 'react-redux';
|
|
8
|
-
export default FronteggStoreContext;
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { ReactReduxContextValue } from 'react-redux';
|
|
3
|
+
export declare const FronteggStoreContext: React.Context<ReactReduxContextValue<any, import("redux").AnyAction>>;
|
|
4
|
+
export declare const useSelector: <Selected extends unknown>(selector: (state: any) => Selected, equalityFn?: ((previous: Selected, next: Selected) => boolean) | undefined) => Selected;
|
|
5
|
+
export declare const useDispatch: () => import("redux").Dispatch<import("redux").AnyAction>;
|
|
6
|
+
export declare const useStore: () => import("redux").Store<any, import("redux").AnyAction>;
|
|
7
|
+
export { shallowEqual, connectAdvanced, Provider } from 'react-redux';
|
|
8
|
+
export default FronteggStoreContext;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { createSelectorHook, createDispatchHook, createStoreHook } from 'react-redux';
|
|
3
|
+
export const FronteggStoreContext = React.createContext(null);
|
|
4
|
+
|
|
5
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
6
|
+
FronteggStoreContext.displayName = 'FronteggStoreContext';
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export const useSelector = createSelectorHook(FronteggStoreContext);
|
|
10
|
+
export const useDispatch = createDispatchHook(FronteggStoreContext);
|
|
11
|
+
export const useStore = createStoreHook(FronteggStoreContext);
|
|
12
|
+
export { shallowEqual, connectAdvanced, Provider } from 'react-redux';
|
|
13
|
+
export default FronteggStoreContext;
|
package/audits/auditLogs.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { StateHookFunction } from './hooks';
|
|
2
|
-
import { AuditLogsActions, AuditLogsState } from '@frontegg/redux-store';
|
|
3
|
-
export declare type AuditLogsStateMapper<S extends object> = (state: AuditLogsState) => S;
|
|
4
|
-
export declare const useAuditLogsState: StateHookFunction<AuditLogsState>;
|
|
5
|
-
export declare const useAuditLogsActions: () => AuditLogsActions;
|
|
1
|
+
import { StateHookFunction } from './hooks';
|
|
2
|
+
import { AuditLogsActions, AuditLogsState } from '@frontegg/redux-store';
|
|
3
|
+
export declare type AuditLogsStateMapper<S extends object> = (state: AuditLogsState) => S;
|
|
4
|
+
export declare const useAuditLogsState: StateHookFunction<AuditLogsState>;
|
|
5
|
+
export declare const useAuditLogsActions: () => AuditLogsActions;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { reducerActionsGenerator, stateHookGenerator } from './hooks';
|
|
2
|
+
import { auditLogsActions, auditLogsReducers } from '@frontegg/redux-store';
|
|
3
|
+
export const useAuditLogsState = stateMapper => stateHookGenerator(stateMapper, 'auditLogsState');
|
|
4
|
+
export const useAuditLogsActions = () => reducerActionsGenerator(auditLogsActions, auditLogsReducers);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { StateHookFunction } from './hooks';
|
|
2
|
-
import { AuditsMetadataActions, AuditsMetadataState } from '@frontegg/redux-store';
|
|
3
|
-
export declare type AuditsMetadataStateMapper<S extends object> = (state: AuditsMetadataState) => S;
|
|
4
|
-
export declare const useAuditsMetadataState: StateHookFunction<AuditsMetadataState>;
|
|
5
|
-
export declare const useAuditsMetadataActions: () => AuditsMetadataActions;
|
|
1
|
+
import { StateHookFunction } from './hooks';
|
|
2
|
+
import { AuditsMetadataActions, AuditsMetadataState } from '@frontegg/redux-store';
|
|
3
|
+
export declare type AuditsMetadataStateMapper<S extends object> = (state: AuditsMetadataState) => S;
|
|
4
|
+
export declare const useAuditsMetadataState: StateHookFunction<AuditsMetadataState>;
|
|
5
|
+
export declare const useAuditsMetadataActions: () => AuditsMetadataActions;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { reducerActionsGenerator, stateHookGenerator } from './hooks';
|
|
2
|
+
import { auditsMetadataActions, auditsMetadataReducers } from '@frontegg/redux-store';
|
|
3
|
+
export const useAuditsMetadataState = stateMapper => stateHookGenerator(stateMapper, 'auditsMetadataState');
|
|
4
|
+
export const useAuditsMetadataActions = () => reducerActionsGenerator(auditsMetadataActions, auditsMetadataReducers);
|
package/audits/hooks.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { CaseReducerActions, SliceCaseReducers } from '@frontegg/redux-store';
|
|
2
|
-
import { AuditsActions, AuditsState } from '@frontegg/redux-store';
|
|
3
|
-
export declare type AuthStateMapper<S extends object> = (state: AuditsState) => S;
|
|
4
|
-
export declare type StateHookFunction<T> = (() => T) & (<S extends object>(mapper: (state: T) => S) => S);
|
|
5
|
-
export declare const useAuditsState: <S extends object>(stateMapper?: AuthStateMapper<S> | undefined) => S;
|
|
6
|
-
export declare const useAuditsActions: () => AuditsActions;
|
|
7
|
-
/**
|
|
8
|
-
* hooks helpers
|
|
9
|
-
*/
|
|
10
|
-
export declare const sliceReducerActionsBy: <T extends SliceCaseReducers<any>>(reducer: T) => CaseReducerActions<T>;
|
|
11
|
-
export declare const stateHookGenerator: (stateMapper: any, subState: keyof AuditsState) => any;
|
|
12
|
-
export declare const reducerActionsGenerator: (actions: any, reducers: SliceCaseReducers<any>) => any;
|
|
1
|
+
import { CaseReducerActions, SliceCaseReducers } from '@frontegg/redux-store';
|
|
2
|
+
import { AuditsActions, AuditsState } from '@frontegg/redux-store';
|
|
3
|
+
export declare type AuthStateMapper<S extends object> = (state: AuditsState) => S;
|
|
4
|
+
export declare type StateHookFunction<T> = (() => T) & (<S extends object>(mapper: (state: T) => S) => S);
|
|
5
|
+
export declare const useAuditsState: <S extends object>(stateMapper?: AuthStateMapper<S> | undefined) => S;
|
|
6
|
+
export declare const useAuditsActions: () => AuditsActions;
|
|
7
|
+
/**
|
|
8
|
+
* hooks helpers
|
|
9
|
+
*/
|
|
10
|
+
export declare const sliceReducerActionsBy: <T extends SliceCaseReducers<any>>(reducer: T) => CaseReducerActions<T>;
|
|
11
|
+
export declare const stateHookGenerator: (stateMapper: any, subState: keyof AuditsState) => any;
|
|
12
|
+
export declare const reducerActionsGenerator: (actions: any, reducers: SliceCaseReducers<any>) => any;
|
package/audits/hooks.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import { useMemo } from 'react';
|
|
3
|
+
import { bindActionCreators } from '@frontegg/redux-store';
|
|
4
|
+
import { shallowEqual } from 'react-redux';
|
|
5
|
+
import { useSelector, useDispatch } from '../FronteggStoreContext';
|
|
6
|
+
import { auditsActions, auditsStoreName } from '@frontegg/redux-store';
|
|
7
|
+
export const useAuditsState = stateMapper => {
|
|
8
|
+
return useSelector(state => {
|
|
9
|
+
var _stateMapper;
|
|
10
|
+
|
|
11
|
+
return (_stateMapper = stateMapper == null ? void 0 : stateMapper(state[auditsStoreName])) != null ? _stateMapper : state[auditsStoreName];
|
|
12
|
+
}, shallowEqual);
|
|
13
|
+
};
|
|
14
|
+
export const useAuditsActions = () => {
|
|
15
|
+
const dispatch = useDispatch();
|
|
16
|
+
return useMemo(() => bindActionCreators(auditsActions, dispatch), [auditsActions]);
|
|
17
|
+
};
|
|
18
|
+
export const sliceReducerActionsBy = reducer => {
|
|
19
|
+
const reducerKeys = Object.keys(reducer);
|
|
20
|
+
const reducerActions = reducerKeys.map(key => ({
|
|
21
|
+
[key]: auditsActions[key]
|
|
22
|
+
}));
|
|
23
|
+
return reducerActions.reduce((p, n) => _extends({}, p, n), {});
|
|
24
|
+
};
|
|
25
|
+
export const stateHookGenerator = (stateMapper, subState) => {
|
|
26
|
+
return useSelector(state => {
|
|
27
|
+
var _stateMapper2;
|
|
28
|
+
|
|
29
|
+
return (_stateMapper2 = stateMapper == null ? void 0 : stateMapper(state[auditsStoreName][subState])) != null ? _stateMapper2 : state[auditsStoreName][subState];
|
|
30
|
+
}, shallowEqual);
|
|
31
|
+
};
|
|
32
|
+
export const reducerActionsGenerator = (actions, reducers) => {
|
|
33
|
+
const dispatch = useDispatch();
|
|
34
|
+
return useMemo(() => bindActionCreators(_extends({}, actions, sliceReducerActionsBy(reducers)), dispatch), [dispatch]);
|
|
35
|
+
};
|
package/audits/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { useAuditsState, useAuditsActions } from './hooks';
|
|
2
|
-
export * from './auditLogs';
|
|
3
|
-
export * from './auditsMetadata';
|
|
1
|
+
export { useAuditsState, useAuditsActions } from './hooks';
|
|
2
|
+
export * from './auditLogs';
|
|
3
|
+
export * from './auditsMetadata';
|
package/audits/index.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
export {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import 'react-redux';
|
|
5
|
-
import '../FronteggStoreContext-d6c3b684.js';
|
|
1
|
+
export { useAuditsState, useAuditsActions } from './hooks';
|
|
2
|
+
export * from './auditLogs';
|
|
3
|
+
export * from './auditsMetadata';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { AcceptInvitationState, AcceptInvitationActions } from '@frontegg/redux-store';
|
|
2
|
-
import { StateHookFunction } from './hooks';
|
|
3
|
-
export declare type AcceptInvitationStateMapper<S extends object> = (state: AcceptInvitationState) => S;
|
|
4
|
-
export declare const useAcceptInvitationState: StateHookFunction<AcceptInvitationState>;
|
|
5
|
-
export declare const useAcceptInvitationActions: () => AcceptInvitationActions;
|
|
1
|
+
import { AcceptInvitationState, AcceptInvitationActions } from '@frontegg/redux-store';
|
|
2
|
+
import { StateHookFunction } from './hooks';
|
|
3
|
+
export declare type AcceptInvitationStateMapper<S extends object> = (state: AcceptInvitationState) => S;
|
|
4
|
+
export declare const useAcceptInvitationState: StateHookFunction<AcceptInvitationState>;
|
|
5
|
+
export declare const useAcceptInvitationActions: () => AcceptInvitationActions;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { acceptInvitationReducers, acceptInvitationActions } from '@frontegg/redux-store';
|
|
2
|
+
import { reducerActionsGenerator, stateHookGenerator } from './hooks';
|
|
3
|
+
export const useAcceptInvitationState = stateMapper => stateHookGenerator(stateMapper, 'acceptInvitationState');
|
|
4
|
+
export const useAcceptInvitationActions = () => reducerActionsGenerator(acceptInvitationActions, acceptInvitationReducers);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ActivateAccountState, ActivateAccountActions } from '@frontegg/redux-store';
|
|
2
|
-
import { StateHookFunction } from './hooks';
|
|
3
|
-
export declare type ActivateAccountStateMapper<S extends object> = (state: ActivateAccountState) => S;
|
|
4
|
-
export declare const useActivateAccountState: StateHookFunction<ActivateAccountState>;
|
|
5
|
-
export declare const useActivateAccountActions: () => ActivateAccountActions;
|
|
1
|
+
import { ActivateAccountState, ActivateAccountActions } from '@frontegg/redux-store';
|
|
2
|
+
import { StateHookFunction } from './hooks';
|
|
3
|
+
export declare type ActivateAccountStateMapper<S extends object> = (state: ActivateAccountState) => S;
|
|
4
|
+
export declare const useActivateAccountState: StateHookFunction<ActivateAccountState>;
|
|
5
|
+
export declare const useActivateAccountActions: () => ActivateAccountActions;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { activateAccountReducers, activateAccountActions } from '@frontegg/redux-store';
|
|
2
|
+
import { reducerActionsGenerator, stateHookGenerator } from './hooks';
|
|
3
|
+
export const useActivateAccountState = stateMapper => stateHookGenerator(stateMapper, 'activateState');
|
|
4
|
+
export const useActivateAccountActions = () => reducerActionsGenerator(activateAccountActions, activateAccountReducers);
|
package/auth/apiTokens.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ApiTokensActions, ApiTokensState } from '@frontegg/redux-store';
|
|
2
|
-
import { StateHookFunction } from './hooks';
|
|
3
|
-
export declare type ApiTokensStateMapper<S extends object> = (state: ApiTokensState) => S;
|
|
4
|
-
export declare const useApiTokensState: StateHookFunction<ApiTokensState>;
|
|
5
|
-
export declare const useApiTokensActions: () => ApiTokensActions;
|
|
1
|
+
import { ApiTokensActions, ApiTokensState } from '@frontegg/redux-store';
|
|
2
|
+
import { StateHookFunction } from './hooks';
|
|
3
|
+
export declare type ApiTokensStateMapper<S extends object> = (state: ApiTokensState) => S;
|
|
4
|
+
export declare const useApiTokensState: StateHookFunction<ApiTokensState>;
|
|
5
|
+
export declare const useApiTokensActions: () => ApiTokensActions;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { apiTokensActions, apiTokensReducers } from '@frontegg/redux-store';
|
|
2
|
+
import { reducerActionsGenerator, stateHookGenerator } from './hooks';
|
|
3
|
+
export const useApiTokensState = stateMapper => stateHookGenerator(stateMapper, 'apiTokensState');
|
|
4
|
+
export const useApiTokensActions = () => reducerActionsGenerator(apiTokensActions, apiTokensReducers);
|
package/auth/forgotPassword.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ForgotPasswordState, ForgotPasswordActions } from '@frontegg/redux-store';
|
|
2
|
-
import { StateHookFunction } from './hooks';
|
|
3
|
-
export declare type ForgotPasswordStateMapper<S extends object> = (state: ForgotPasswordState) => S;
|
|
4
|
-
export declare const useForgotPasswordState: StateHookFunction<ForgotPasswordState>;
|
|
5
|
-
export declare const useForgotPasswordActions: () => ForgotPasswordActions;
|
|
1
|
+
import { ForgotPasswordState, ForgotPasswordActions } from '@frontegg/redux-store';
|
|
2
|
+
import { StateHookFunction } from './hooks';
|
|
3
|
+
export declare type ForgotPasswordStateMapper<S extends object> = (state: ForgotPasswordState) => S;
|
|
4
|
+
export declare const useForgotPasswordState: StateHookFunction<ForgotPasswordState>;
|
|
5
|
+
export declare const useForgotPasswordActions: () => ForgotPasswordActions;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { forgotPasswordReducers, forgotPasswordActions } from '@frontegg/redux-store';
|
|
2
|
+
import { reducerActionsGenerator, stateHookGenerator } from './hooks';
|
|
3
|
+
export const useForgotPasswordState = stateMapper => stateHookGenerator(stateMapper, 'forgotPasswordState');
|
|
4
|
+
export const useForgotPasswordActions = () => reducerActionsGenerator(forgotPasswordActions, forgotPasswordReducers);
|
package/auth/hooks.d.ts
CHANGED
|
@@ -1,62 +1,62 @@
|
|
|
1
|
-
import { CaseReducerActions, SliceCaseReducers } from '@frontegg/redux-store';
|
|
2
|
-
import { AuthActions, AuthPageRoutes, AuthState, User } from '@frontegg/redux-store';
|
|
3
|
-
import { RedirectOptions } from '@frontegg/rest-api';
|
|
4
|
-
export declare type AuthMapper = {
|
|
5
|
-
state: (state: AuthState) => any;
|
|
6
|
-
actions: (actions: AuthActions) => any;
|
|
7
|
-
};
|
|
8
|
-
export declare type AuthStateMapper<S extends object> = (state: AuthState) => S;
|
|
9
|
-
export declare type AuthActionsMapper<A> = (state: AuthActions) => A;
|
|
10
|
-
export declare type StateHookFunction<T> = (() => T) & (<S extends object>(mapper: (state: T) => S) => S);
|
|
11
|
-
export declare const useAuth: <S extends object>(stateMapper?: AuthStateMapper<S>) => S;
|
|
12
|
-
/**
|
|
13
|
-
* ```jsx
|
|
14
|
-
* export const MyFunctionComponent = () => {
|
|
15
|
-
* const { isAuthenticated, user } = useAuth();
|
|
16
|
-
* const loginWithRedirect = useLoginWithRedirect();
|
|
17
|
-
*
|
|
18
|
-
* if (!isAuthenticated) {
|
|
19
|
-
* loginWithRedirect();
|
|
20
|
-
* return <></>;
|
|
21
|
-
* }
|
|
22
|
-
*
|
|
23
|
-
* return (<div>Hello User {user.name}</div>);
|
|
24
|
-
* }
|
|
25
|
-
* ```
|
|
26
|
-
*
|
|
27
|
-
* use this frontegg hook function to get if user is "Authenticated"
|
|
28
|
-
*/
|
|
29
|
-
export declare const useLoginWithRedirect: () => AuthActions['requestHostedLoginAuthorize'];
|
|
30
|
-
export declare const useAuthActions: () => AuthActions;
|
|
31
|
-
export declare const useOnRedirectTo: () => (path: string, opts?: RedirectOptions | undefined) => void;
|
|
32
|
-
export declare const useAuthRoutes: () => AuthPageRoutes;
|
|
33
|
-
/**
|
|
34
|
-
* ```jsx
|
|
35
|
-
* export const MyFunctionComponent = () => {
|
|
36
|
-
* const isAuthenticated = useIsAuthenticated();
|
|
37
|
-
* return isAuthenticated ? <div>Hello User</div> : <Redirect to={'/login'}/>
|
|
38
|
-
* }
|
|
39
|
-
* ```
|
|
40
|
-
*
|
|
41
|
-
* use this frontegg hook function to get if user is "Authenticated"
|
|
42
|
-
*/
|
|
43
|
-
export declare const useIsAuthenticated: () => boolean;
|
|
44
|
-
/**
|
|
45
|
-
* ```jsx
|
|
46
|
-
* export const MyFunctionComponent = () => {
|
|
47
|
-
* const user = useAuthUser();
|
|
48
|
-
* return user ? <div>Hello {user.name}!</div> : <div>Hello Guest!</div>
|
|
49
|
-
* }
|
|
50
|
-
* ```
|
|
51
|
-
*
|
|
52
|
-
* use this frontegg hook function to get the authenticated user
|
|
53
|
-
* the return user is null if not authenticated
|
|
54
|
-
*/
|
|
55
|
-
export declare const useAuthUser: () => User;
|
|
56
|
-
export declare const useAuthUserOrNull: () => User | null;
|
|
57
|
-
/**
|
|
58
|
-
* hooks helpers
|
|
59
|
-
*/
|
|
60
|
-
export declare const sliceReducerActionsBy: <T extends SliceCaseReducers<any>>(reducer: T) => CaseReducerActions<T>;
|
|
61
|
-
export declare const stateHookGenerator: (stateMapper: any, subState: keyof AuthState) => any;
|
|
62
|
-
export declare const reducerActionsGenerator: (actions: any, reducers: SliceCaseReducers<any>) => any;
|
|
1
|
+
import { CaseReducerActions, SliceCaseReducers } from '@frontegg/redux-store';
|
|
2
|
+
import { AuthActions, AuthPageRoutes, AuthState, User } from '@frontegg/redux-store';
|
|
3
|
+
import { RedirectOptions } from '@frontegg/rest-api';
|
|
4
|
+
export declare type AuthMapper = {
|
|
5
|
+
state: (state: AuthState) => any;
|
|
6
|
+
actions: (actions: AuthActions) => any;
|
|
7
|
+
};
|
|
8
|
+
export declare type AuthStateMapper<S extends object> = (state: AuthState) => S;
|
|
9
|
+
export declare type AuthActionsMapper<A> = (state: AuthActions) => A;
|
|
10
|
+
export declare type StateHookFunction<T> = (() => T) & (<S extends object>(mapper: (state: T) => S) => S);
|
|
11
|
+
export declare const useAuth: <S extends object>(stateMapper?: AuthStateMapper<S>) => S;
|
|
12
|
+
/**
|
|
13
|
+
* ```jsx
|
|
14
|
+
* export const MyFunctionComponent = () => {
|
|
15
|
+
* const { isAuthenticated, user } = useAuth();
|
|
16
|
+
* const loginWithRedirect = useLoginWithRedirect();
|
|
17
|
+
*
|
|
18
|
+
* if (!isAuthenticated) {
|
|
19
|
+
* loginWithRedirect();
|
|
20
|
+
* return <></>;
|
|
21
|
+
* }
|
|
22
|
+
*
|
|
23
|
+
* return (<div>Hello User {user.name}</div>);
|
|
24
|
+
* }
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* use this frontegg hook function to get if user is "Authenticated"
|
|
28
|
+
*/
|
|
29
|
+
export declare const useLoginWithRedirect: () => AuthActions['requestHostedLoginAuthorize'];
|
|
30
|
+
export declare const useAuthActions: () => AuthActions;
|
|
31
|
+
export declare const useOnRedirectTo: () => (path: string, opts?: RedirectOptions | undefined) => void;
|
|
32
|
+
export declare const useAuthRoutes: () => AuthPageRoutes;
|
|
33
|
+
/**
|
|
34
|
+
* ```jsx
|
|
35
|
+
* export const MyFunctionComponent = () => {
|
|
36
|
+
* const isAuthenticated = useIsAuthenticated();
|
|
37
|
+
* return isAuthenticated ? <div>Hello User</div> : <Redirect to={'/login'}/>
|
|
38
|
+
* }
|
|
39
|
+
* ```
|
|
40
|
+
*
|
|
41
|
+
* use this frontegg hook function to get if user is "Authenticated"
|
|
42
|
+
*/
|
|
43
|
+
export declare const useIsAuthenticated: () => boolean;
|
|
44
|
+
/**
|
|
45
|
+
* ```jsx
|
|
46
|
+
* export const MyFunctionComponent = () => {
|
|
47
|
+
* const user = useAuthUser();
|
|
48
|
+
* return user ? <div>Hello {user.name}!</div> : <div>Hello Guest!</div>
|
|
49
|
+
* }
|
|
50
|
+
* ```
|
|
51
|
+
*
|
|
52
|
+
* use this frontegg hook function to get the authenticated user
|
|
53
|
+
* the return user is null if not authenticated
|
|
54
|
+
*/
|
|
55
|
+
export declare const useAuthUser: () => User;
|
|
56
|
+
export declare const useAuthUserOrNull: () => User | null;
|
|
57
|
+
/**
|
|
58
|
+
* hooks helpers
|
|
59
|
+
*/
|
|
60
|
+
export declare const sliceReducerActionsBy: <T extends SliceCaseReducers<any>>(reducer: T) => CaseReducerActions<T>;
|
|
61
|
+
export declare const stateHookGenerator: (stateMapper: any, subState: keyof AuthState) => any;
|
|
62
|
+
export declare const reducerActionsGenerator: (actions: any, reducers: SliceCaseReducers<any>) => any;
|
package/auth/hooks.js
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import { useContext, useMemo } from 'react';
|
|
3
|
+
import { bindActionCreators } from '@frontegg/redux-store';
|
|
4
|
+
import { authActions, authStoreName } from '@frontegg/redux-store';
|
|
5
|
+
import { shallowEqual } from 'react-redux';
|
|
6
|
+
import { useSelector, useDispatch } from '../FronteggStoreContext';
|
|
7
|
+
import { ContextHolder } from '@frontegg/rest-api';
|
|
8
|
+
import { ShadowDomContext } from '../common';
|
|
9
|
+
const defaultMapper = {
|
|
10
|
+
state: state => state,
|
|
11
|
+
actions: actions => actions
|
|
12
|
+
};
|
|
13
|
+
export const useAuth = (stateMapper = defaultMapper.state) => {
|
|
14
|
+
return useSelector(state => stateMapper(state[authStoreName]), shallowEqual);
|
|
15
|
+
};
|
|
16
|
+
export const useLoginWithRedirect = () => {
|
|
17
|
+
const dispatch = useDispatch();
|
|
18
|
+
return useMemo(() => bindActionCreators(authActions.requestHostedLoginAuthorize, dispatch), [authActions.requestHostedLoginAuthorize]);
|
|
19
|
+
};
|
|
20
|
+
export const useAuthActions = () => {
|
|
21
|
+
const dispatch = useDispatch();
|
|
22
|
+
return useMemo(() => bindActionCreators(authActions, dispatch), [authActions]);
|
|
23
|
+
};
|
|
24
|
+
export const useOnRedirectTo = () => {
|
|
25
|
+
var _context$onRedirectTo;
|
|
26
|
+
|
|
27
|
+
const context = useContext(ShadowDomContext);
|
|
28
|
+
return (_context$onRedirectTo = context == null ? void 0 : context.onRedirectTo) != null ? _context$onRedirectTo : ContextHolder.onRedirectTo;
|
|
29
|
+
};
|
|
30
|
+
export const useAuthRoutes = () => useAuth(state => _extends({}, state.routes));
|
|
31
|
+
export const useIsAuthenticated = () => useSelector(({
|
|
32
|
+
[authStoreName]: {
|
|
33
|
+
isAuthenticated
|
|
34
|
+
}
|
|
35
|
+
}) => isAuthenticated, shallowEqual);
|
|
36
|
+
export const useAuthUser = () => {
|
|
37
|
+
const routes = useAuthRoutes();
|
|
38
|
+
const onRedirectTo = useOnRedirectTo();
|
|
39
|
+
const user = useAuthUserOrNull();
|
|
40
|
+
|
|
41
|
+
if (user == null) {
|
|
42
|
+
onRedirectTo(routes.loginUrl, {
|
|
43
|
+
refresh: true
|
|
44
|
+
});
|
|
45
|
+
return {};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return user;
|
|
49
|
+
};
|
|
50
|
+
export const useAuthUserOrNull = () => {
|
|
51
|
+
const {
|
|
52
|
+
user
|
|
53
|
+
} = useSelector(({
|
|
54
|
+
[authStoreName]: {
|
|
55
|
+
user
|
|
56
|
+
}
|
|
57
|
+
}) => ({
|
|
58
|
+
user
|
|
59
|
+
}), shallowEqual);
|
|
60
|
+
return user || null;
|
|
61
|
+
};
|
|
62
|
+
export const sliceReducerActionsBy = reducer => {
|
|
63
|
+
const reducerKeys = Object.keys(reducer);
|
|
64
|
+
const reducerActions = reducerKeys.map(key => ({
|
|
65
|
+
[key]: authActions[key]
|
|
66
|
+
}));
|
|
67
|
+
return reducerActions.reduce((p, n) => _extends({}, p, n), {});
|
|
68
|
+
};
|
|
69
|
+
export const stateHookGenerator = (stateMapper, subState) => {
|
|
70
|
+
return useSelector(state => {
|
|
71
|
+
var _stateMapper;
|
|
72
|
+
|
|
73
|
+
return (_stateMapper = stateMapper == null ? void 0 : stateMapper(state[authStoreName][subState])) != null ? _stateMapper : state[authStoreName][subState];
|
|
74
|
+
}, shallowEqual);
|
|
75
|
+
};
|
|
76
|
+
export const reducerActionsGenerator = (actions, reducers) => {
|
|
77
|
+
const dispatch = useDispatch();
|
|
78
|
+
return useMemo(() => bindActionCreators(_extends({}, actions, sliceReducerActionsBy(reducers)), dispatch), [dispatch]);
|
|
79
|
+
};
|
package/auth/index.d.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
export { useAuth, useAuthActions, useOnRedirectTo, useAuthRoutes, useIsAuthenticated, useAuthUser, useAuthUserOrNull, useLoginWithRedirect } from './hooks';
|
|
2
|
-
export * from './acceptInvitation';
|
|
3
|
-
export * from './activateAccount';
|
|
4
|
-
export * from './apiTokens';
|
|
5
|
-
export * from './forgotPassword';
|
|
6
|
-
export * from './resetPhoneNumber';
|
|
7
|
-
export * from './login';
|
|
8
|
-
export * from './mfa';
|
|
9
|
-
export * from './profile';
|
|
10
|
-
export * from './signup';
|
|
11
|
-
export * from './socialLogin';
|
|
12
|
-
export * from './team';
|
|
13
|
-
export * from './sso';
|
|
14
|
-
export * from './securityPolicy';
|
|
15
|
-
export * from './tenants';
|
|
16
|
-
export * from './roles';
|
|
1
|
+
export { useAuth, useAuthActions, useOnRedirectTo, useAuthRoutes, useIsAuthenticated, useAuthUser, useAuthUserOrNull, useLoginWithRedirect } from './hooks';
|
|
2
|
+
export * from './acceptInvitation';
|
|
3
|
+
export * from './activateAccount';
|
|
4
|
+
export * from './apiTokens';
|
|
5
|
+
export * from './forgotPassword';
|
|
6
|
+
export * from './resetPhoneNumber';
|
|
7
|
+
export * from './login';
|
|
8
|
+
export * from './mfa';
|
|
9
|
+
export * from './profile';
|
|
10
|
+
export * from './signup';
|
|
11
|
+
export * from './socialLogin';
|
|
12
|
+
export * from './team';
|
|
13
|
+
export * from './sso';
|
|
14
|
+
export * from './securityPolicy';
|
|
15
|
+
export * from './tenants';
|
|
16
|
+
export * from './roles';
|