@frontegg/react-hooks 6.178.0-alpha.3 → 6.179.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.
Files changed (139) hide show
  1. package/FronteggProvider/index.d.ts +12 -1
  2. package/FronteggProvider/index.js +133 -1
  3. package/FronteggStoreContext/index.d.ts +13 -1
  4. package/FronteggStoreContext/index.js +14 -1
  5. package/audits/auditLogs.d.ts +4 -2
  6. package/audits/auditLogs.js +6 -8
  7. package/audits/auditsMetadata.d.ts +4 -2
  8. package/audits/auditsMetadata.js +6 -8
  9. package/audits/hooks.d.ts +8 -0
  10. package/audits/hooks.js +30 -6
  11. package/auth/{allAccounts.d.ts → MSP/allAccounts.d.ts} +4 -2
  12. package/auth/MSP/allAccounts.js +15 -0
  13. package/auth/acceptInvitation.js +5 -10
  14. package/auth/activateAccount.js +4 -10
  15. package/auth/apiTokens.d.ts +2 -0
  16. package/auth/apiTokens.js +6 -8
  17. package/auth/customLogin.d.ts +5 -2
  18. package/auth/customLogin.js +11 -10
  19. package/auth/entitlements.d.ts +14 -14
  20. package/auth/entitlements.js +21 -25
  21. package/auth/forgotPassword.d.ts +2 -0
  22. package/auth/forgotPassword.js +6 -8
  23. package/auth/groups.d.ts +4 -0
  24. package/auth/groups.js +13 -12
  25. package/auth/hooks.d.ts +11 -10
  26. package/auth/hooks.js +58 -30
  27. package/auth/impersonate.d.ts +2 -0
  28. package/auth/impersonate.js +6 -7
  29. package/auth/index.d.ts +18 -15
  30. package/auth/index.js +19 -16
  31. package/auth/login.d.ts +1 -1
  32. package/auth/login.js +4 -13
  33. package/auth/mfa.d.ts +1 -1
  34. package/auth/mfa.js +4 -13
  35. package/auth/passkeys.d.ts +4 -1
  36. package/auth/passkeys.js +6 -7
  37. package/auth/profile.d.ts +4 -2
  38. package/auth/profile.js +8 -9
  39. package/auth/provisioning.d.ts +3 -1
  40. package/auth/provisioning.js +6 -7
  41. package/auth/resetPhoneNumber.d.ts +3 -1
  42. package/auth/resetPhoneNumber.js +6 -7
  43. package/auth/roles.d.ts +3 -1
  44. package/auth/roles.js +6 -7
  45. package/auth/security/restrictions.d.ts +2 -0
  46. package/auth/security/restrictions.js +10 -10
  47. package/auth/security/securityCenter.d.ts +4 -1
  48. package/auth/security/securityCenter.js +6 -8
  49. package/auth/security/securityPolicy.d.ts +11 -5
  50. package/auth/security/securityPolicy.js +30 -19
  51. package/auth/security/sessionsPolicy.d.ts +3 -1
  52. package/auth/security/sessionsPolicy.js +6 -8
  53. package/auth/sessions.d.ts +3 -1
  54. package/auth/sessions.js +6 -7
  55. package/auth/signup.d.ts +1 -1
  56. package/auth/signup.js +4 -13
  57. package/auth/sms.d.ts +4 -1
  58. package/auth/sms.js +6 -7
  59. package/auth/socialLogin.d.ts +1 -1
  60. package/auth/socialLogin.js +4 -10
  61. package/auth/sso.d.ts +1 -1
  62. package/auth/sso.js +4 -10
  63. package/auth/stepUp/index.d.ts +2 -0
  64. package/auth/stepUp/index.js +2 -0
  65. package/auth/stepUp/interfaces.d.ts +2 -0
  66. package/auth/stepUp/interfaces.js +1 -0
  67. package/auth/{stepUp.d.ts → stepUp/stepUp.d.ts} +2 -0
  68. package/auth/{stepUp.js → stepUp/stepUp.js} +6 -9
  69. package/auth/team.d.ts +1 -9
  70. package/auth/team.js +4 -22
  71. package/auth/tenants.d.ts +3 -1
  72. package/auth/tenants.js +6 -8
  73. package/common/CustomComponentHolder.js +1 -3
  74. package/common/index.js +3 -3
  75. package/connectivity/hooks.d.ts +5 -2
  76. package/connectivity/hooks.js +9 -6
  77. package/index.d.ts +2 -2
  78. package/index.js +3 -3
  79. package/node/FronteggProvider/index.js +134 -9
  80. package/node/FronteggStoreContext/index.js +35 -11
  81. package/node/audits/auditLogs.js +6 -8
  82. package/node/audits/auditsMetadata.js +6 -8
  83. package/node/audits/hooks.js +34 -7
  84. package/node/auth/MSP/allAccounts.js +24 -0
  85. package/node/auth/acceptInvitation.js +5 -7
  86. package/node/auth/activateAccount.js +4 -7
  87. package/node/auth/apiTokens.js +6 -8
  88. package/node/auth/customLogin.js +12 -11
  89. package/node/auth/entitlements.js +20 -24
  90. package/node/auth/forgotPassword.js +6 -8
  91. package/node/auth/groups.js +12 -12
  92. package/node/auth/hooks.js +62 -33
  93. package/node/auth/impersonate.js +6 -7
  94. package/node/auth/index.js +120 -91
  95. package/node/auth/login.js +4 -10
  96. package/node/auth/mfa.js +4 -10
  97. package/node/auth/passkeys.js +6 -7
  98. package/node/auth/profile.js +9 -10
  99. package/node/auth/provisioning.js +6 -7
  100. package/node/auth/resetPhoneNumber.js +6 -7
  101. package/node/auth/roles.js +6 -7
  102. package/node/auth/security/restrictions.js +10 -10
  103. package/node/auth/security/securityCenter.js +6 -8
  104. package/node/auth/security/securityPolicy.js +30 -16
  105. package/node/auth/security/sessionsPolicy.js +6 -8
  106. package/node/auth/sessions.js +6 -7
  107. package/node/auth/signup.js +4 -10
  108. package/node/auth/sms.js +6 -7
  109. package/node/auth/socialLogin.js +4 -7
  110. package/node/auth/sso.js +4 -7
  111. package/node/auth/stepUp/index.js +27 -0
  112. package/node/auth/stepUp/interfaces.js +5 -0
  113. package/node/auth/{stepUp.js → stepUp/stepUp.js} +7 -10
  114. package/node/auth/team.js +4 -25
  115. package/node/auth/tenants.js +6 -8
  116. package/node/common/CustomComponentHolder.js +1 -3
  117. package/node/common/index.js +2 -2
  118. package/node/connectivity/hooks.js +8 -5
  119. package/node/index.js +16 -16
  120. package/node/subscriptions/hooks.js +51 -84
  121. package/node/tests/hooks.tsc-test.js +318 -0
  122. package/node/vendor/hooks.js +6 -5
  123. package/package.json +3 -3
  124. package/subscriptions/hooks.d.ts +10 -32
  125. package/subscriptions/hooks.js +49 -81
  126. package/tests/hooks.tsc-test.js +317 -0
  127. package/vendor/hooks.d.ts +1 -0
  128. package/vendor/hooks.js +7 -9
  129. package/FronteggProvider/FronteggProvider.d.ts +0 -12
  130. package/FronteggProvider/FronteggProvider.js +0 -134
  131. package/FronteggStoreContext/FronteggStoreContext.d.ts +0 -9
  132. package/FronteggStoreContext/FronteggStoreContext.js +0 -16
  133. package/auth/allAccounts.js +0 -20
  134. package/auth/security/index.d.ts +0 -4
  135. package/auth/security/index.js +0 -4
  136. package/node/FronteggProvider/FronteggProvider.js +0 -140
  137. package/node/FronteggStoreContext/FronteggStoreContext.js +0 -26
  138. package/node/auth/allAccounts.js +0 -27
  139. package/node/auth/security/index.js +0 -49
@@ -1 +1,12 @@
1
- export * from './FronteggProvider';
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
+ alwaysVisibleChildren?: ReactNode;
10
+ };
11
+ export declare const FronteggStoreProvider: FC<FronteggProviderProps>;
12
+ export {};
@@ -1 +1,133 @@
1
- export * from './FronteggProvider';
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
3
+ const _excluded = ["authenticatedUrl", "signUpSuccessUrl"];
4
+ import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
5
+ import { createFronteggStore } from '@frontegg/redux-store';
6
+ import { ContextHolder } from '@frontegg/rest-api';
7
+ import { useAuth, useAuthRoutes } from '../auth';
8
+ import { Provider, FronteggStoreContext } from '../FronteggStoreContext';
9
+ import { Fragment as _Fragment } from "react/jsx-runtime";
10
+ import { jsx as _jsx } from "react/jsx-runtime";
11
+ import { jsxs as _jsxs } from "react/jsx-runtime";
12
+ const defaultSetLoading = loading => {
13
+ if (loading) {
14
+ document.body.classList.add('frontegg-loading');
15
+ } else {
16
+ document.body.classList.remove('frontegg-loading');
17
+ }
18
+ };
19
+ const HideChildrenIfFronteggRoutes = ({
20
+ children,
21
+ basename
22
+ }) => {
23
+ const routes = useAuthRoutes();
24
+ const uriRef = useRef(window.location.pathname);
25
+ const animationFrameRef = useRef(0);
26
+ const [uri, setUri] = useState(window.location.pathname);
27
+ const checker = useCallback(() => {
28
+ if (uriRef.current !== window.location.pathname) {
29
+ uriRef.current = window.location.pathname;
30
+ setUri(document.location.pathname);
31
+ }
32
+ animationFrameRef.current = window.requestAnimationFrame(checker);
33
+ }, []);
34
+ useEffect(() => {
35
+ document.addEventListener('frontegg_onRedirectTo_fired', () => {
36
+ if (uriRef.current !== window.location.pathname) {
37
+ uriRef.current = window.location.pathname;
38
+ setUri(document.location.pathname);
39
+ }
40
+ });
41
+ window.addEventListener('popstate', () => {
42
+ if (uriRef.current !== window.location.pathname) {
43
+ uriRef.current = window.location.pathname;
44
+ setUri(document.location.pathname);
45
+ }
46
+ });
47
+ animationFrameRef.current = window.requestAnimationFrame(checker);
48
+ return () => {
49
+ window.cancelAnimationFrame(animationFrameRef.current);
50
+ };
51
+ }, [checker, setUri]);
52
+ const calculatedBasename = basename ? basename.endsWith('/') ? basename.substring(0, basename.length - 1) : '' : '';
53
+ const checkRoutes = _objectWithoutPropertiesLoose(routes, _excluded);
54
+ if (Object.values(checkRoutes).map(url => `${calculatedBasename}${url}`).indexOf(uri) !== -1) {
55
+ return null;
56
+ }
57
+ return /*#__PURE__*/_jsx(_Fragment, {
58
+ children: children
59
+ });
60
+ };
61
+ const FronteggContent = ({
62
+ children,
63
+ app,
64
+ setLoading
65
+ }) => {
66
+ var _app$options, _app$options2;
67
+ const {
68
+ isLoading
69
+ } = useAuth(({
70
+ isLoading
71
+ }) => ({
72
+ isLoading
73
+ }));
74
+ const customLoginBox = !app || (app == null ? void 0 : (_app$options = app.options) == null ? void 0 : _app$options.customLoginBox) === true;
75
+ const isNextJS = (app == null ? void 0 : (_app$options2 = app.options) == null ? void 0 : _app$options2.framework) === 'nextjs';
76
+ const alwaysShowChildren = customLoginBox || isNextJS;
77
+ const loadingRef = useRef(undefined);
78
+ if (isLoading !== loadingRef.current && !isNextJS) {
79
+ loadingRef.current = isLoading;
80
+ setLoading(isLoading);
81
+ }
82
+ if (alwaysShowChildren) {
83
+ return /*#__PURE__*/_jsx(_Fragment, {
84
+ children: children
85
+ });
86
+ }
87
+ if (isLoading && !isNextJS) {
88
+ return null;
89
+ }
90
+ return /*#__PURE__*/_jsx(HideChildrenIfFronteggRoutes, {
91
+ basename: app == null ? void 0 : app.options.basename,
92
+ children: children
93
+ });
94
+ };
95
+ export const FronteggStoreProvider = props => {
96
+ var _app$options$contextO, _app$options3, _app$options$previewM, _app$options4, _app$options5, _app$options6;
97
+ const {
98
+ children,
99
+ app,
100
+ contextOptions,
101
+ setLoading = defaultSetLoading,
102
+ alwaysVisibleChildren
103
+ } = props;
104
+
105
+ // TODO: make this optionals more readable
106
+ const context = (_app$options$contextO = app == null ? void 0 : (_app$options3 = app.options) == null ? void 0 : _app$options3.contextOptions) != null ? _app$options$contextO : contextOptions;
107
+ if (!context) {
108
+ throw Error('contextOptions must not be null or undefined');
109
+ }
110
+ const previewMode = (_app$options$previewM = app == null ? void 0 : (_app$options4 = app.options) == null ? void 0 : _app$options4.previewMode) != null ? _app$options$previewM : false;
111
+ const authOptions = app != null && (_app$options5 = app.options) != null && _app$options5.authOptions ? _extends({}, app.options.authOptions, {
112
+ hostedLoginBox: app.options.hostedLoginBox
113
+ }) : {
114
+ hostedLoginBox: app == null ? void 0 : (_app$options6 = app.options) == null ? void 0 : _app$options6.hostedLoginBox
115
+ };
116
+ ContextHolder.setContext(context);
117
+ const store = useMemo(() => {
118
+ var _app$name, _app$options7;
119
+ return createFronteggStore({
120
+ context,
121
+ appName: (_app$name = app == null ? void 0 : app.name) != null ? _app$name : 'default'
122
+ }, app, previewMode, authOptions, undefined, false, app == null ? void 0 : (_app$options7 = app.options) == null ? void 0 : _app$options7.urlStrategy);
123
+ }, [app, previewMode]);
124
+ return /*#__PURE__*/_jsxs(Provider, {
125
+ context: FronteggStoreContext,
126
+ store: store,
127
+ children: [alwaysVisibleChildren, /*#__PURE__*/_jsx(FronteggContent, {
128
+ setLoading: setLoading,
129
+ app: app,
130
+ children: children
131
+ })]
132
+ });
133
+ };
@@ -1 +1,13 @@
1
- export * from './FronteggStoreContext';
1
+ import React, { FC, ReactNode } from 'react';
2
+ import { ReactReduxContextValue, ProviderProps } from 'react-redux';
3
+ import type { Action, AnyAction } from '@frontegg/redux-store';
4
+ export declare const FronteggStoreContext: React.Context<ReactReduxContextValue<any, AnyAction>>;
5
+ export declare const useSelector: <Selected extends unknown>(selector: (state: any) => Selected, equalityFn?: ((previous: Selected, next: Selected) => boolean) | undefined) => Selected;
6
+ export declare const useDispatch: () => import("redux").Dispatch<AnyAction>;
7
+ export declare const useStore: () => import("redux").Store<any, AnyAction>;
8
+ export { shallowEqual, Provider as ReactReduxProvider } from 'react-redux';
9
+ declare type ProviderWithChildren<A extends Action = AnyAction> = FC<ProviderProps<A> & {
10
+ children?: ReactNode | undefined;
11
+ }>;
12
+ export declare const Provider: ProviderWithChildren;
13
+ export default FronteggStoreContext;
@@ -1 +1,14 @@
1
- export * from './FronteggStoreContext';
1
+ import React from 'react';
2
+ import { createSelectorHook, createDispatchHook, createStoreHook, Provider as ReactReduxProvider } from 'react-redux';
3
+ export const FronteggStoreContext = /*#__PURE__*/React.createContext(null);
4
+
5
+ // @ts-ignore
6
+ if (process.env.NODE_ENV !== 'production') {
7
+ FronteggStoreContext.displayName = 'FronteggStoreContext';
8
+ }
9
+ export const useSelector = createSelectorHook(FronteggStoreContext);
10
+ export const useDispatch = createDispatchHook(FronteggStoreContext);
11
+ export const useStore = createStoreHook(FronteggStoreContext);
12
+ export { shallowEqual, Provider as ReactReduxProvider } from 'react-redux';
13
+ export const Provider = ReactReduxProvider;
14
+ export default FronteggStoreContext;
@@ -1,3 +1,5 @@
1
- import { AuditLogsState, AuditsActions } from '@frontegg/redux-store';
1
+ import { AuditLogsActions, AuditLogsState } from '@frontegg/redux-store';
2
+ export declare type AuditLogsStateMapper<S> = (state: AuditLogsState) => S;
2
3
  export declare function useAuditLogsState(): AuditLogsState;
3
- export declare const useAuditLogsActions: () => AuditsActions;
4
+ export declare function useAuditLogsState<S>(stateMapper: AuditLogsStateMapper<S>): S;
5
+ export declare const useAuditLogsActions: () => AuditLogsActions;
@@ -1,9 +1,7 @@
1
- import { useStore } from '../FronteggStoreContext';
2
- import { useSnapshot } from 'valtio/react';
3
- export function useAuditLogsState() {
4
- const state = useStore().store.auditLogs.auditLogsState;
5
- return useSnapshot(state);
1
+ import { reducerActionsGenerator, stateHookGenerator } from './hooks';
2
+ import { auditLogsActions, auditLogsReducers } from '@frontegg/redux-store';
3
+ const defaultMapper = state => state;
4
+ export function useAuditLogsState(stateMapper = defaultMapper) {
5
+ return stateHookGenerator(stateMapper, 'auditLogsState');
6
6
  }
7
- export const useAuditLogsActions = () => {
8
- return useStore().stateActions.auditLogs;
9
- };
7
+ export const useAuditLogsActions = () => reducerActionsGenerator(auditLogsActions, auditLogsReducers);
@@ -1,3 +1,5 @@
1
- import { AuditsActions, AuditsMetadataState } from '@frontegg/redux-store';
1
+ import { AuditsMetadataActions, AuditsMetadataState } from '@frontegg/redux-store';
2
+ export declare type AuditsMetadataStateMapper<S> = (state: AuditsMetadataState) => S;
2
3
  export declare function useAuditsMetadataState(): AuditsMetadataState;
3
- export declare const useAuditsMetadataActions: () => AuditsActions;
4
+ export declare function useAuditsMetadataState<S>(stateMapper: AuditsMetadataStateMapper<S>): S;
5
+ export declare const useAuditsMetadataActions: () => AuditsMetadataActions;
@@ -1,9 +1,7 @@
1
- import { useStore } from '../FronteggStoreContext';
2
- import { useSnapshot } from 'valtio/react';
3
- export function useAuditsMetadataState() {
4
- const state = useStore().store.auditLogs.auditsMetadataState;
5
- return useSnapshot(state);
1
+ import { auditsMetadataActions, auditsMetadataReducers } from '@frontegg/redux-store';
2
+ import { reducerActionsGenerator, stateHookGenerator } from './hooks';
3
+ const defaultMapper = state => state;
4
+ export function useAuditsMetadataState(stateMapper = defaultMapper) {
5
+ return stateHookGenerator(stateMapper, 'auditsMetadataState');
6
6
  }
7
- export const useAuditsMetadataActions = () => {
8
- return useStore().stateActions.auditLogs;
9
- };
7
+ export const useAuditsMetadataActions = () => reducerActionsGenerator(auditsMetadataActions, auditsMetadataReducers);
package/audits/hooks.d.ts CHANGED
@@ -1,9 +1,17 @@
1
+ import { CaseReducerActions, SliceCaseReducers } from '@frontegg/redux-store';
1
2
  import { AuditsActions, AuditsState } from '@frontegg/redux-store';
2
3
  export declare type AuditsMapper = {
3
4
  state: (state: AuditsState) => any;
4
5
  actions: (actions: AuditsActions) => any;
5
6
  };
7
+ export declare type StateHookFunction<T> = (() => T) & (<S extends object>(mapper: (state: T) => S) => S);
6
8
  export declare type AuditsStateMapper<S> = (state: AuditsState) => S;
7
9
  export declare function useAuditsState(): AuditsState;
8
10
  export declare function useAuditsState<S>(stateMapper: AuditsStateMapper<S>): S;
9
11
  export declare const useAuditsActions: () => AuditsActions;
12
+ /**
13
+ * hooks helpers
14
+ */
15
+ export declare const sliceReducerActionsBy: <T extends SliceCaseReducers<any>>(reducer: T) => CaseReducerActions<T>;
16
+ export declare const stateHookGenerator: (stateMapper: any, subState: keyof AuditsState) => any;
17
+ export declare const reducerActionsGenerator: (actions: any, reducers: SliceCaseReducers<any>) => any;
package/audits/hooks.js CHANGED
@@ -1,14 +1,38 @@
1
- import { useStore } from '../FronteggStoreContext';
2
- import { useSnapshot } from 'valtio/react';
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';
3
7
  const defaultMapper = {
4
8
  state: state => state,
5
9
  actions: actions => actions
6
10
  };
7
11
  export function useAuditsState(stateMapper = defaultMapper.state) {
8
- const state = useStore().store.auditLogs;
9
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
10
- return stateMapper(useSnapshot(state));
12
+ return useSelector(state => stateMapper(state[auditsStoreName]), shallowEqual);
11
13
  }
12
14
  export const useAuditsActions = () => {
13
- return useStore().stateActions.auditLogs;
15
+ const dispatch = useDispatch();
16
+ return useMemo(() => bindActionCreators(auditsActions, dispatch), [auditsActions]);
17
+ };
18
+
19
+ /**
20
+ * hooks helpers
21
+ */
22
+ export const sliceReducerActionsBy = reducer => {
23
+ const reducerKeys = Object.keys(reducer);
24
+ const reducerActions = reducerKeys.map(key => ({
25
+ [key]: auditsActions[key]
26
+ }));
27
+ return reducerActions.reduce((p, n) => _extends({}, p, n), {});
28
+ };
29
+ export const stateHookGenerator = (stateMapper, subState) => {
30
+ return useSelector(state => {
31
+ var _stateMapper;
32
+ return (_stateMapper = stateMapper == null ? void 0 : stateMapper(state[auditsStoreName][subState])) != null ? _stateMapper : state[auditsStoreName][subState];
33
+ }, shallowEqual);
34
+ };
35
+ export const reducerActionsGenerator = (actions, reducers) => {
36
+ const dispatch = useDispatch();
37
+ return useMemo(() => bindActionCreators(_extends({}, actions, sliceReducerActionsBy(reducers)), dispatch), [dispatch]);
14
38
  };
@@ -1,7 +1,9 @@
1
- import { IAllAccountsState, AllAccountsActions, IAllAccountsDialogsState, AllAccountsDialogActions } from '@frontegg/redux-store';
1
+ import { IAllAccountsState, AllAccountsActions, IAllAccountsDialogsState, AllAccountsDialogsActions } from '@frontegg/redux-store';
2
2
  export declare type AllAccountsStateMapper<S> = (state: IAllAccountsState) => S;
3
3
  export declare function useAllAccountsState(): IAllAccountsState;
4
4
  export declare function useAllAccountsState<S>(stateMapper: AllAccountsStateMapper<S>): S;
5
5
  export declare const useAllAccountsActions: () => AllAccountsActions;
6
+ export declare type AllAccountsDialogsStateMapper<S> = (state: IAllAccountsDialogsState) => S;
6
7
  export declare function useAllAccountsDialogsState(): IAllAccountsDialogsState;
7
- export declare const useAllAccountsDialogsActions: () => AllAccountsDialogActions;
8
+ export declare function useAllAccountsDialogsState<S>(stateMapper: AllAccountsDialogsStateMapper<S>): S;
9
+ export declare const useAllAccountsDialogsActions: () => AllAccountsDialogsActions;
@@ -0,0 +1,15 @@
1
+ import { allAccountsActions, allAccountsReducers, allAccountsDialogsReducers } from '@frontegg/redux-store';
2
+ import { reducerActionsGenerator, stateHookGenerator } from '../hooks';
3
+ const defaultMapper = state => state;
4
+ export function useAllAccountsState(stateMapper = defaultMapper) {
5
+ return stateHookGenerator(stateMapper, 'allAccountsState');
6
+ }
7
+ export const useAllAccountsActions = () => reducerActionsGenerator(allAccountsActions, allAccountsReducers);
8
+
9
+ //dialogs
10
+
11
+ const defaultDialogsMapper = state => state;
12
+ export function useAllAccountsDialogsState(stateMapper = defaultDialogsMapper) {
13
+ return stateHookGenerator(stateMapper, 'allAccountsDialogsState');
14
+ }
15
+ export const useAllAccountsDialogsActions = () => reducerActionsGenerator({}, allAccountsDialogsReducers);
@@ -1,13 +1,8 @@
1
- import { useStore } from '../FronteggStoreContext';
2
- import { useSnapshot } from 'valtio/react';
3
-
4
- // TODO: remove useless stateMapper, valtio already does this
5
-
1
+ import { acceptInvitationReducers, acceptInvitationActions } from '@frontegg/redux-store';
2
+ import { reducerActionsGenerator, stateHookGenerator } from './hooks';
3
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
6
4
  const defaultMapper = state => state;
7
5
  export function useAcceptInvitationState(stateMapper = defaultMapper) {
8
- const state = useStore().store.auth.acceptInvitationState;
9
- return stateMapper(useSnapshot(state));
6
+ return stateHookGenerator(stateMapper, 'acceptInvitationState');
10
7
  }
11
- export const useAcceptInvitationActions = () => {
12
- return useStore().stateActions.auth.acceptInvitationActions;
13
- };
8
+ export const useAcceptInvitationActions = () => reducerActionsGenerator(acceptInvitationActions, acceptInvitationReducers);
@@ -1,13 +1,7 @@
1
- import { useStore } from '../FronteggStoreContext';
2
- import { useSnapshot } from 'valtio/react';
3
-
4
- // TODO: remove useless stateMapper, valtio already does this
5
-
1
+ import { activateAccountReducers, activateAccountActions } from '@frontegg/redux-store';
2
+ import { reducerActionsGenerator, stateHookGenerator } from './hooks';
6
3
  const defaultMapper = state => state;
7
4
  export function useActivateAccountState(stateMapper = defaultMapper) {
8
- const state = useStore().store.auth.activateAccountState;
9
- return stateMapper(useSnapshot(state));
5
+ return stateHookGenerator(stateMapper, 'activateState');
10
6
  }
11
- export const useActivateAccountActions = () => {
12
- return useStore().stateActions.auth.activateAccountActions;
13
- };
7
+ export const useActivateAccountActions = () => reducerActionsGenerator(activateAccountActions, activateAccountReducers);
@@ -1,3 +1,5 @@
1
1
  import { ApiTokensActions, ApiTokensState } from '@frontegg/redux-store';
2
+ export declare type ApiTokensStateMapper<S> = (state: ApiTokensState) => S;
2
3
  export declare function useApiTokensState(): ApiTokensState;
4
+ export declare function useApiTokensState<S>(stateMapper: ApiTokensStateMapper<S>): S;
3
5
  export declare const useApiTokensActions: () => ApiTokensActions;
package/auth/apiTokens.js CHANGED
@@ -1,9 +1,7 @@
1
- import { useStore } from '../FronteggStoreContext';
2
- import { useSnapshot } from 'valtio/react';
3
- export function useApiTokensState() {
4
- const state = useStore().store.auth.apiTokensState;
5
- return useSnapshot(state);
1
+ import { apiTokensActions, apiTokensReducers } from '@frontegg/redux-store';
2
+ import { reducerActionsGenerator, stateHookGenerator } from './hooks';
3
+ const defaultMapper = state => state;
4
+ export function useApiTokensState(stateMapper = defaultMapper) {
5
+ return stateHookGenerator(stateMapper, 'apiTokensState');
6
6
  }
7
- export const useApiTokensActions = () => {
8
- return useStore().stateActions.auth.apiTokensActions;
9
- };
7
+ export const useApiTokensActions = () => reducerActionsGenerator(apiTokensActions, apiTokensReducers);
@@ -1,7 +1,10 @@
1
- import { CustomLoginState, CustomLoginActions } from '@frontegg/redux-store';
1
+ import { CustomLoginActions } from '@frontegg/redux-store';
2
+ import { CustomLoginState } from '@frontegg/types';
3
+ export declare type CustomLoginStateMapper<S> = (state: CustomLoginState) => S;
2
4
  export declare function useCustomLoginState(): CustomLoginState;
5
+ export declare function useCustomLoginState<S>(stateMapper: CustomLoginStateMapper<S>): S;
3
6
  export declare const useCustomLoginActions: () => CustomLoginActions;
4
7
  export declare const useCustomLoginTheme: () => {
5
- customLoginTheme: any;
8
+ customLoginTheme: import("@frontegg/types").LoginBoxThemeOptions | undefined;
6
9
  getCustomLoginThemeValue: (path?: string | undefined) => any;
7
10
  };
@@ -1,17 +1,18 @@
1
- import { useCallback } from 'react';
1
+ import { customLoginActions, customLoginReducers } from '@frontegg/redux-store';
2
+ import { reducerActionsGenerator, stateHookGenerator } from './hooks';
2
3
  import getValue from 'get-value';
3
- import { useStore } from '../FronteggStoreContext';
4
- import { useSnapshot } from 'valtio/react';
5
- export function useCustomLoginState() {
6
- const state = useStore().store.auth.customLoginState;
7
- return useSnapshot(state);
4
+ import { useCallback } from 'react';
5
+ const defaultMapper = state => state;
6
+ export function useCustomLoginState(stateMapper = defaultMapper) {
7
+ return stateHookGenerator(stateMapper, 'customLoginState');
8
8
  }
9
- export const useCustomLoginActions = () => {
10
- return useStore().stateActions.auth.customLoginActions;
9
+ export const useCustomLoginActions = () => reducerActionsGenerator(customLoginActions, customLoginReducers);
10
+ const themeMapper = state => {
11
+ var _state$tenantMetadata, _state$tenantMetadata2, _state$tenantMetadata3;
12
+ return (_state$tenantMetadata = state.tenantMetadata) == null ? void 0 : (_state$tenantMetadata2 = _state$tenantMetadata.configuration) == null ? void 0 : (_state$tenantMetadata3 = _state$tenantMetadata2.themeV2) == null ? void 0 : _state$tenantMetadata3.loginBox;
11
13
  };
12
14
  export const useCustomLoginTheme = () => {
13
- var _useCustomLoginState$, _useCustomLoginState$2, _useCustomLoginState$3;
14
- const customLoginTheme = (_useCustomLoginState$ = useCustomLoginState().tenantMetadata) == null ? void 0 : (_useCustomLoginState$2 = _useCustomLoginState$.configuration) == null ? void 0 : (_useCustomLoginState$3 = _useCustomLoginState$2.themeV2) == null ? void 0 : _useCustomLoginState$3.loginBox;
15
+ const customLoginTheme = useCustomLoginState(themeMapper);
15
16
  const getCustomLoginThemeValue = useCallback(path => {
16
17
  return path && customLoginTheme ? getValue(customLoginTheme, path) : customLoginTheme;
17
18
  }, [customLoginTheme]);
@@ -1,22 +1,22 @@
1
+ import { Entitlement, EntitledToOptions } from '@frontegg/redux-store';
1
2
  import { CustomAttributes } from '@frontegg/entitlements-javascript-commons';
2
- import { EntitledToOptions, Entitlement } from '@frontegg/redux-store';
3
3
  /**
4
- @param key feature key
5
- @param customAttributes user attributes
6
- @returns if the user is entitled to the given feature and attributes. Attaching the justification if not
7
- */
4
+ @param key feature key
5
+ @param customAttributes user attributes
6
+ @returns if the user is entitled to the given feature and attributes. Attaching the justification if not
7
+ */
8
8
  export declare const useFeatureEntitlements: (key: string, customAttributes?: Record<string, string | number | boolean | Date> | undefined) => Entitlement;
9
9
  /**
10
- @param key permission key
11
- @param customAttributes user attributes
12
- @returns if the user is entitled to the given permission and attributes. Attaching the justification if not
13
- */
10
+ @param key permission key
11
+ @param customAttributes user attributes
12
+ @returns if the user is entitled to the given permission and attributes. Attaching the justification if not
13
+ */
14
14
  export declare const usePermissionEntitlements: (key: string, customAttributes?: Record<string, string | number | boolean | Date> | undefined) => Entitlement;
15
15
  /**
16
- @param entitledToOptions including permission or feature key
17
- @param customAttributes user attributes
18
- @returns if the user is entitled to the given feature or permission and attributes (check only one). Attaching the justification if not
19
- */
16
+ @param entitledToOptions including permission or feature key
17
+ @param customAttributes user attributes
18
+ @returns if the user is entitled to the given feature or permission and attributes (check only one). Attaching the justification if not
19
+ */
20
20
  export declare const useEntitlements: (options: EntitledToOptions, customAttributes?: Record<string, string | number | boolean | Date> | undefined) => Entitlement;
21
21
  /**
22
22
  @param entitledToOptions including permission or feature key
@@ -27,7 +27,7 @@ export declare const useEntitlementsActions: () => {
27
27
  };
28
28
  /**
29
29
  @returns if the option to use entitlements is enabled
30
- */
30
+ */
31
31
  export declare const useEntitlementsOptions: () => {
32
32
  isEntitlementsEnabled: boolean;
33
33
  isEntitledTo: (options: EntitledToOptions, customAttributes?: Record<string, string | number | boolean | Date> | undefined) => Entitlement;
@@ -1,27 +1,23 @@
1
+ import { getPermissionEntitlements, getFeatureEntitlements, getEntitlements } from '@frontegg/redux-store';
1
2
  import { FeatureFlags, USE_ENTITLEMENTS_V2_ENDPOINT_FF } from '@frontegg/rest-api';
2
- import { useAuthUserOrNull } from './hooks';
3
+ import { useAuth } from './hooks';
3
4
  import { useMemo } from 'react';
4
5
  import { useRootState, useShadowDom } from '../common';
5
6
  import { useFeatureFlags } from '../flags';
6
- import { useStore } from '../FronteggStoreContext';
7
- import { useSnapshot } from 'valtio/react';
8
- import { getEntitlements, getFeatureEntitlements, getPermissionEntitlements } from '@frontegg/redux-store';
9
7
 
10
8
  /**
11
9
  * @returns entitlemenets state as stored in the user
12
10
  */
13
- const useEntitlementsState = () => {
14
- var _useSnapshot$user$ent, _useSnapshot$user;
15
- const state = useStore().store.auth;
16
- return (_useSnapshot$user$ent = (_useSnapshot$user = useSnapshot(state).user) == null ? void 0 : _useSnapshot$user.entitlements) != null ? _useSnapshot$user$ent : {};
17
- };
11
+ const useEntitlementsState = () => useAuth(({
12
+ user
13
+ }) => user == null ? void 0 : user.entitlements);
18
14
 
19
15
  /**
20
16
  * @returns user state
21
17
  */
22
- const useUserState = () => {
23
- return useAuthUserOrNull() || undefined;
24
- };
18
+ const useUserState = () => useAuth(({
19
+ user
20
+ }) => user);
25
21
 
26
22
  /**
27
23
  * @param customAttributes user attributes
@@ -46,10 +42,10 @@ const useEntitlementsQueryData = customAttributes => {
46
42
  };
47
43
 
48
44
  /**
49
- @param key feature key
50
- @param customAttributes user attributes
51
- @returns if the user is entitled to the given feature and attributes. Attaching the justification if not
52
- */
45
+ @param key feature key
46
+ @param customAttributes user attributes
47
+ @returns if the user is entitled to the given feature and attributes. Attaching the justification if not
48
+ */
53
49
  export const useFeatureEntitlements = (key, customAttributes) => {
54
50
  const {
55
51
  entitlements,
@@ -60,10 +56,10 @@ export const useFeatureEntitlements = (key, customAttributes) => {
60
56
  };
61
57
 
62
58
  /**
63
- @param key permission key
64
- @param customAttributes user attributes
65
- @returns if the user is entitled to the given permission and attributes. Attaching the justification if not
66
- */
59
+ @param key permission key
60
+ @param customAttributes user attributes
61
+ @returns if the user is entitled to the given permission and attributes. Attaching the justification if not
62
+ */
67
63
  export const usePermissionEntitlements = (key, customAttributes) => {
68
64
  const {
69
65
  entitlements,
@@ -74,10 +70,10 @@ export const usePermissionEntitlements = (key, customAttributes) => {
74
70
  };
75
71
 
76
72
  /**
77
- @param entitledToOptions including permission or feature key
78
- @param customAttributes user attributes
79
- @returns if the user is entitled to the given feature or permission and attributes (check only one). Attaching the justification if not
80
- */
73
+ @param entitledToOptions including permission or feature key
74
+ @param customAttributes user attributes
75
+ @returns if the user is entitled to the given feature or permission and attributes (check only one). Attaching the justification if not
76
+ */
81
77
  export const useEntitlements = (options, customAttributes) => {
82
78
  const {
83
79
  entitlements,
@@ -112,7 +108,7 @@ export const useEntitlementsActions = () => {
112
108
 
113
109
  /**
114
110
  @returns if the option to use entitlements is enabled
115
- */
111
+ */
116
112
  export const useEntitlementsOptions = () => {
117
113
  var _entitlementsOptions$;
118
114
  const {
@@ -1,3 +1,5 @@
1
1
  import { ForgotPasswordState, ForgotPasswordActions } from '@frontegg/redux-store';
2
+ export declare type ForgotPasswordStateMapper<S> = (state: ForgotPasswordState) => S;
2
3
  export declare function useForgotPasswordState(): ForgotPasswordState;
4
+ export declare function useForgotPasswordState<S>(stateMapper: ForgotPasswordStateMapper<S>): S;
3
5
  export declare const useForgotPasswordActions: () => ForgotPasswordActions;
@@ -1,9 +1,7 @@
1
- import { useStore } from '../FronteggStoreContext';
2
- import { useSnapshot } from 'valtio/react';
3
- export function useForgotPasswordState() {
4
- const state = useStore().store.auth.forgotPasswordState;
5
- return useSnapshot(state);
1
+ import { forgotPasswordReducers, forgotPasswordActions } from '@frontegg/redux-store';
2
+ import { reducerActionsGenerator, stateHookGenerator } from './hooks';
3
+ const defaultMapper = state => state;
4
+ export function useForgotPasswordState(stateMapper = defaultMapper) {
5
+ return stateHookGenerator(stateMapper, 'forgotPasswordState');
6
6
  }
7
- export const useForgotPasswordActions = () => {
8
- return useStore().stateActions.auth.forgotPasswordActions;
9
- };
7
+ export const useForgotPasswordActions = () => reducerActionsGenerator(forgotPasswordActions, forgotPasswordReducers);
package/auth/groups.d.ts CHANGED
@@ -1,5 +1,9 @@
1
1
  import { GroupsState, GroupsActions, GroupsDialogsState, GroupsDialogsActions } from '@frontegg/redux-store';
2
+ export declare type GroupsStateMapper<S> = (state: GroupsState) => S;
2
3
  export declare function useGroupsState(): GroupsState;
4
+ export declare function useGroupsState<S>(stateMapper: GroupsStateMapper<S>): S;
3
5
  export declare const useGroupsActions: () => GroupsActions;
6
+ export declare type GroupsDialogsStateMapper<S> = (state: GroupsDialogsState) => S;
4
7
  export declare function useGroupsDialogsState(): GroupsDialogsState;
8
+ export declare function useGroupsDialogsState<S>(stateMapper: GroupsDialogsStateMapper<S>): S;
5
9
  export declare const useGroupsDialogsActions: () => GroupsDialogsActions;
package/auth/groups.js CHANGED
@@ -1,14 +1,15 @@
1
- import { useStore } from '../FronteggStoreContext';
2
- import { useSnapshot } from 'valtio/react';
3
- export function useGroupsState() {
4
- return useSnapshot(useStore().store.auth.groupsState);
1
+ import { groupsActions, groupsReducers, groupsDialogsActions, groupsDialogsReducers } from '@frontegg/redux-store';
2
+ import { reducerActionsGenerator, stateHookGenerator } from './hooks';
3
+ const defaultMapper = state => state;
4
+ export function useGroupsState(stateMapper = defaultMapper) {
5
+ return stateHookGenerator(stateMapper, 'groupsState');
5
6
  }
6
- export const useGroupsActions = () => {
7
- return useStore().stateActions.auth.groupsActions;
8
- };
9
- export function useGroupsDialogsState() {
10
- return useSnapshot(useStore().store.auth.groupsDialogsState);
7
+ export const useGroupsActions = () => reducerActionsGenerator(groupsActions, groupsReducers);
8
+
9
+ //dialogs
10
+
11
+ const defaultDialogsMapper = state => state;
12
+ export function useGroupsDialogsState(stateMapper = defaultDialogsMapper) {
13
+ return stateHookGenerator(stateMapper, 'groupsDialogsState');
11
14
  }
12
- export const useGroupsDialogsActions = () => {
13
- return useStore().stateActions.auth.groupsDialogsActions;
14
- };
15
+ export const useGroupsDialogsActions = () => reducerActionsGenerator(groupsDialogsActions, groupsDialogsReducers);