@frontegg/react-hooks 7.0.0-alpha.0 → 7.0.0-alpha.10

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 (141) hide show
  1. package/FronteggProvider/FronteggProvider.d.ts +12 -0
  2. package/FronteggProvider/FronteggProvider.js +141 -0
  3. package/FronteggProvider/index.d.ts +1 -12
  4. package/FronteggProvider/index.js +1 -133
  5. package/FronteggStoreContext/FronteggStoreContext.d.ts +9 -0
  6. package/FronteggStoreContext/FronteggStoreContext.js +16 -0
  7. package/FronteggStoreContext/index.d.ts +1 -13
  8. package/FronteggStoreContext/index.js +1 -14
  9. package/audits/auditLogs.d.ts +2 -4
  10. package/audits/auditLogs.js +8 -6
  11. package/audits/auditsMetadata.d.ts +2 -4
  12. package/audits/auditsMetadata.js +8 -6
  13. package/audits/hooks.d.ts +0 -8
  14. package/audits/hooks.js +6 -30
  15. package/auth/acceptInvitation.js +10 -5
  16. package/auth/activateAccount.js +10 -4
  17. package/auth/{MSP/allAccounts.d.ts → allAccounts.d.ts} +2 -4
  18. package/auth/allAccounts.js +20 -0
  19. package/auth/apiTokens.d.ts +0 -2
  20. package/auth/apiTokens.js +8 -6
  21. package/auth/applications.d.ts +3 -0
  22. package/auth/applications.js +9 -0
  23. package/auth/customLogin.d.ts +2 -5
  24. package/auth/customLogin.js +10 -11
  25. package/auth/entitlements.d.ts +32 -13
  26. package/auth/entitlements.js +103 -21
  27. package/auth/forgotPassword.d.ts +0 -2
  28. package/auth/forgotPassword.js +8 -6
  29. package/auth/groups.d.ts +0 -4
  30. package/auth/groups.js +12 -13
  31. package/auth/hooks.d.ts +44 -12
  32. package/auth/hooks.js +77 -62
  33. package/auth/impersonate.d.ts +0 -2
  34. package/auth/impersonate.js +7 -6
  35. package/auth/index.d.ts +16 -16
  36. package/auth/index.js +16 -16
  37. package/auth/login.d.ts +1 -3
  38. package/auth/login.js +7 -6
  39. package/auth/mfa.d.ts +1 -1
  40. package/auth/mfa.js +13 -4
  41. package/auth/passkeys.d.ts +1 -4
  42. package/auth/passkeys.js +7 -6
  43. package/auth/profile.d.ts +2 -4
  44. package/auth/profile.js +9 -8
  45. package/auth/provisioning.d.ts +1 -3
  46. package/auth/provisioning.js +7 -6
  47. package/auth/resetPhoneNumber.d.ts +1 -3
  48. package/auth/resetPhoneNumber.js +7 -6
  49. package/auth/roles.d.ts +1 -3
  50. package/auth/roles.js +7 -6
  51. package/auth/security/index.d.ts +4 -0
  52. package/auth/security/index.js +4 -0
  53. package/auth/security/restrictions.d.ts +0 -2
  54. package/auth/security/restrictions.js +10 -10
  55. package/auth/security/securityCenter.d.ts +1 -4
  56. package/auth/security/securityCenter.js +8 -6
  57. package/auth/security/securityPolicy.d.ts +5 -11
  58. package/auth/security/securityPolicy.js +19 -30
  59. package/auth/security/sessionsPolicy.d.ts +1 -3
  60. package/auth/security/sessionsPolicy.js +8 -6
  61. package/auth/sessions.d.ts +1 -3
  62. package/auth/sessions.js +7 -6
  63. package/auth/signup.d.ts +1 -1
  64. package/auth/signup.js +13 -4
  65. package/auth/sms.d.ts +3 -0
  66. package/auth/sms.js +8 -0
  67. package/auth/socialLogin.d.ts +1 -1
  68. package/auth/socialLogin.js +10 -4
  69. package/auth/sso.d.ts +1 -1
  70. package/auth/sso.js +10 -4
  71. package/auth/stepUp.d.ts +16 -0
  72. package/auth/stepUp.js +51 -0
  73. package/auth/team.d.ts +9 -1
  74. package/auth/team.js +22 -4
  75. package/auth/tenants.d.ts +1 -3
  76. package/auth/tenants.js +8 -6
  77. package/common/CustomComponentHolder.js +3 -1
  78. package/common/index.d.ts +5 -0
  79. package/common/index.js +11 -4
  80. package/connectivity/hooks.d.ts +2 -5
  81. package/connectivity/hooks.js +6 -9
  82. package/index.d.ts +2 -2
  83. package/index.js +3 -3
  84. package/node/FronteggProvider/FronteggProvider.js +149 -0
  85. package/node/FronteggProvider/index.js +9 -134
  86. package/node/FronteggStoreContext/FronteggStoreContext.js +28 -0
  87. package/node/FronteggStoreContext/index.js +11 -35
  88. package/node/audits/auditLogs.js +8 -6
  89. package/node/audits/auditsMetadata.js +8 -6
  90. package/node/audits/hooks.js +7 -34
  91. package/node/auth/acceptInvitation.js +7 -5
  92. package/node/auth/activateAccount.js +7 -4
  93. package/node/auth/allAccounts.js +27 -0
  94. package/node/auth/apiTokens.js +8 -6
  95. package/node/auth/applications.js +17 -0
  96. package/node/auth/customLogin.js +11 -12
  97. package/node/auth/entitlements.js +106 -22
  98. package/node/auth/forgotPassword.js +8 -6
  99. package/node/auth/groups.js +12 -12
  100. package/node/auth/hooks.js +80 -66
  101. package/node/auth/impersonate.js +7 -6
  102. package/node/auth/index.js +107 -93
  103. package/node/auth/login.js +7 -6
  104. package/node/auth/mfa.js +10 -4
  105. package/node/auth/passkeys.js +7 -6
  106. package/node/auth/profile.js +10 -9
  107. package/node/auth/provisioning.js +7 -6
  108. package/node/auth/resetPhoneNumber.js +7 -6
  109. package/node/auth/roles.js +7 -6
  110. package/node/auth/security/index.js +49 -0
  111. package/node/auth/security/restrictions.js +10 -10
  112. package/node/auth/security/securityCenter.js +8 -6
  113. package/node/auth/security/securityPolicy.js +16 -30
  114. package/node/auth/security/sessionsPolicy.js +8 -6
  115. package/node/auth/sessions.js +7 -6
  116. package/node/auth/signup.js +10 -4
  117. package/node/auth/sms.js +16 -0
  118. package/node/auth/socialLogin.js +7 -4
  119. package/node/auth/sso.js +7 -4
  120. package/node/auth/stepUp.js +62 -0
  121. package/node/auth/team.js +25 -4
  122. package/node/auth/tenants.js +8 -6
  123. package/node/common/CustomComponentHolder.js +3 -1
  124. package/node/common/index.js +10 -3
  125. package/node/connectivity/hooks.js +5 -8
  126. package/node/index.js +16 -16
  127. package/node/subscriptions/hooks.js +84 -51
  128. package/node/tests/hooks.tsc-test.js +339 -0
  129. package/node/useSnapshot/index.js +137 -0
  130. package/node/vendor/hooks.js +5 -6
  131. package/package.json +4 -5
  132. package/subscriptions/hooks.d.ts +32 -10
  133. package/subscriptions/hooks.js +81 -49
  134. package/tests/hooks.tsc-test.js +338 -0
  135. package/useSnapshot/index.d.ts +78 -0
  136. package/useSnapshot/index.js +128 -0
  137. package/useSnapshot/package.json +6 -0
  138. package/vendor/hooks.d.ts +0 -1
  139. package/vendor/hooks.js +9 -7
  140. package/auth/MSP/allAccounts.js +0 -15
  141. package/node/auth/MSP/allAccounts.js +0 -24
@@ -0,0 +1,12 @@
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 {};
@@ -0,0 +1,141 @@
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 { createStore } from '@frontegg/redux-store';
6
+ import { ContextHolder } from '@frontegg/rest-api';
7
+ import { Provider } from '../FronteggStoreContext';
8
+ import { useAuth, useAuthRoutes } from '../auth';
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
+ const customLoginBox = !app || (app == null ? void 0 : (_app$options = app.options) == null ? void 0 : _app$options.customLoginBox) === true;
71
+ const isNextJS = (app == null ? void 0 : (_app$options2 = app.options) == null ? void 0 : _app$options2.framework) === 'nextjs';
72
+ const alwaysShowChildren = customLoginBox || isNextJS;
73
+ const loadingRef = useRef(undefined);
74
+ if (isLoading !== loadingRef.current && !isNextJS) {
75
+ loadingRef.current = isLoading;
76
+ setTimeout(() => {
77
+ setLoading(isLoading);
78
+ });
79
+ }
80
+ if (alwaysShowChildren) {
81
+ return /*#__PURE__*/_jsx(_Fragment, {
82
+ children: children
83
+ });
84
+ }
85
+ if (isLoading && !isNextJS) {
86
+ return null;
87
+ }
88
+ return /*#__PURE__*/_jsx(HideChildrenIfFronteggRoutes, {
89
+ basename: app == null ? void 0 : app.options.basename,
90
+ children: children
91
+ });
92
+ };
93
+ export const FronteggStoreProvider = props => {
94
+ var _app$options$contextO, _app$options3, _app$options$previewM, _app$options4, _app$options$builderM, _app$options5, _app$options6, _app$options7, _app$options8, _app$name;
95
+ const {
96
+ children,
97
+ app,
98
+ contextOptions,
99
+ setLoading = defaultSetLoading,
100
+ alwaysVisibleChildren
101
+ } = props;
102
+
103
+ // TODO: make this optionals more readable
104
+ const context = (_app$options$contextO = app == null ? void 0 : (_app$options3 = app.options) == null ? void 0 : _app$options3.contextOptions) != null ? _app$options$contextO : contextOptions;
105
+ if (!context) {
106
+ throw Error('contextOptions must not be null or undefined');
107
+ }
108
+ const previewMode = (_app$options$previewM = app == null ? void 0 : (_app$options4 = app.options) == null ? void 0 : _app$options4.previewMode) != null ? _app$options$previewM : false;
109
+ const builderMode = (_app$options$builderM = app == null ? void 0 : (_app$options5 = app.options) == null ? void 0 : _app$options5.builderMode) != null ? _app$options$builderM : false;
110
+ const auditsOptions = app == null ? void 0 : (_app$options6 = app.options) == null ? void 0 : _app$options6.auditsOptions;
111
+ const authOptions = app != null && (_app$options7 = app.options) != null && _app$options7.authOptions ? _extends({}, app.options.authOptions, {
112
+ hostedLoginBox: app.options.hostedLoginBox
113
+ }) : {
114
+ hostedLoginBox: app == null ? void 0 : (_app$options8 = app.options) == null ? void 0 : _app$options8.hostedLoginBox
115
+ };
116
+ const appName = (_app$name = app == null ? void 0 : app.name) != null ? _app$name : 'default';
117
+ ContextHolder.for(appName).setContext(context);
118
+ const store = useMemo(() => {
119
+ var _app$store, _app$options9;
120
+ return (_app$store = app == null ? void 0 : app.store) != null ? _app$store : createStore({
121
+ name: appName,
122
+ context,
123
+ previewMode,
124
+ builderMode,
125
+ initialState: {
126
+ auth: authOptions,
127
+ audits: auditsOptions
128
+ },
129
+ urlStrategy: app == null ? void 0 : (_app$options9 = app.options) == null ? void 0 : _app$options9.urlStrategy,
130
+ storeHolder: app
131
+ });
132
+ }, [app, previewMode]);
133
+ return /*#__PURE__*/_jsxs(Provider, {
134
+ store: store,
135
+ children: [alwaysVisibleChildren, /*#__PURE__*/_jsx(FronteggContent, {
136
+ setLoading: setLoading,
137
+ app: app,
138
+ children: children
139
+ })]
140
+ });
141
+ };
@@ -1,12 +1 @@
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
+ export * from './FronteggProvider';
@@ -1,133 +1 @@
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
+ export * from './FronteggProvider';
@@ -0,0 +1,9 @@
1
+ import React, { FC, ReactNode } from 'react';
2
+ import type { FronteggStore } from '@frontegg/redux-store';
3
+ export declare const FronteggStoreContext: React.Context<FronteggStore>;
4
+ export declare const useStore: () => FronteggStore;
5
+ export declare const Provider: FC<{
6
+ children?: ReactNode;
7
+ store: FronteggStore;
8
+ }>;
9
+ export default FronteggStoreContext;
@@ -0,0 +1,16 @@
1
+ import React, { createContext, useContext } from 'react';
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ export const FronteggStoreContext = /*#__PURE__*/createContext(null);
4
+
5
+ // @ts-ignore
6
+ if (process.env.NODE_ENV !== 'production') {
7
+ FronteggStoreContext.displayName = 'FronteggStoreContext';
8
+ }
9
+ export const useStore = () => useContext(FronteggStoreContext);
10
+ export const Provider = props => {
11
+ return /*#__PURE__*/_jsx(FronteggStoreContext.Provider, {
12
+ value: props.store,
13
+ children: props.children
14
+ });
15
+ };
16
+ export default FronteggStoreContext;
@@ -1,13 +1 @@
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
+ export * from './FronteggStoreContext';
@@ -1,14 +1 @@
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
+ export * from './FronteggStoreContext';
@@ -1,5 +1,3 @@
1
- import { AuditLogsActions, AuditLogsState } from '@frontegg/redux-store';
2
- export declare type AuditLogsStateMapper<S> = (state: AuditLogsState) => S;
1
+ import { AuditLogsState, AuditsActions } from '@frontegg/redux-store';
3
2
  export declare function useAuditLogsState(): AuditLogsState;
4
- export declare function useAuditLogsState<S>(stateMapper: AuditLogsStateMapper<S>): S;
5
- export declare const useAuditLogsActions: () => AuditLogsActions;
3
+ export declare const useAuditLogsActions: () => AuditsActions;
@@ -1,7 +1,9 @@
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');
1
+ import { useStore } from '../FronteggStoreContext';
2
+ import { useSnapshot } from '../useSnapshot';
3
+ export function useAuditLogsState() {
4
+ const state = useStore().store.auditLogs.auditLogsState;
5
+ return useSnapshot(state);
6
6
  }
7
- export const useAuditLogsActions = () => reducerActionsGenerator(auditLogsActions, auditLogsReducers);
7
+ export const useAuditLogsActions = () => {
8
+ return useStore().stateActions.auditLogs;
9
+ };
@@ -1,5 +1,3 @@
1
- import { AuditsMetadataActions, AuditsMetadataState } from '@frontegg/redux-store';
2
- export declare type AuditsMetadataStateMapper<S> = (state: AuditsMetadataState) => S;
1
+ import { AuditsActions, AuditsMetadataState } from '@frontegg/redux-store';
3
2
  export declare function useAuditsMetadataState(): AuditsMetadataState;
4
- export declare function useAuditsMetadataState<S>(stateMapper: AuditsMetadataStateMapper<S>): S;
5
- export declare const useAuditsMetadataActions: () => AuditsMetadataActions;
3
+ export declare const useAuditsMetadataActions: () => AuditsActions;
@@ -1,7 +1,9 @@
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');
1
+ import { useStore } from '../FronteggStoreContext';
2
+ import { useSnapshot } from '../useSnapshot';
3
+ export function useAuditsMetadataState() {
4
+ const state = useStore().store.auditLogs.auditsMetadataState;
5
+ return useSnapshot(state);
6
6
  }
7
- export const useAuditsMetadataActions = () => reducerActionsGenerator(auditsMetadataActions, auditsMetadataReducers);
7
+ export const useAuditsMetadataActions = () => {
8
+ return useStore().stateActions.auditLogs;
9
+ };
package/audits/hooks.d.ts CHANGED
@@ -1,17 +1,9 @@
1
- import { CaseReducerActions, SliceCaseReducers } from '@frontegg/redux-store';
2
1
  import { AuditsActions, AuditsState } from '@frontegg/redux-store';
3
2
  export declare type AuditsMapper = {
4
3
  state: (state: AuditsState) => any;
5
4
  actions: (actions: AuditsActions) => any;
6
5
  };
7
- export declare type StateHookFunction<T> = (() => T) & (<S extends object>(mapper: (state: T) => S) => S);
8
6
  export declare type AuditsStateMapper<S> = (state: AuditsState) => S;
9
7
  export declare function useAuditsState(): AuditsState;
10
8
  export declare function useAuditsState<S>(stateMapper: AuditsStateMapper<S>): S;
11
9
  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,38 +1,14 @@
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';
1
+ import { useStore } from '../FronteggStoreContext';
2
+ import { useSnapshot } from '../useSnapshot';
7
3
  const defaultMapper = {
8
4
  state: state => state,
9
5
  actions: actions => actions
10
6
  };
11
7
  export function useAuditsState(stateMapper = defaultMapper.state) {
12
- return useSelector(state => stateMapper(state[auditsStoreName]), shallowEqual);
8
+ const state = useStore().store.auditLogs;
9
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
10
+ return stateMapper(useSnapshot(state));
13
11
  }
14
12
  export const useAuditsActions = () => {
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]);
13
+ return useStore().stateActions.auditLogs;
38
14
  };
@@ -1,8 +1,13 @@
1
- import { acceptInvitationReducers, acceptInvitationActions } from '@frontegg/redux-store';
2
- import { reducerActionsGenerator, stateHookGenerator } from './hooks';
3
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1
+ import { useStore } from '../FronteggStoreContext';
2
+ import { useSnapshot } from '../useSnapshot';
3
+
4
+ // TODO: remove useless stateMapper, valtio already does this
5
+
4
6
  const defaultMapper = state => state;
5
7
  export function useAcceptInvitationState(stateMapper = defaultMapper) {
6
- return stateHookGenerator(stateMapper, 'acceptInvitationState');
8
+ const state = useStore().store.auth.acceptInvitationState;
9
+ return stateMapper(useSnapshot(state));
7
10
  }
8
- export const useAcceptInvitationActions = () => reducerActionsGenerator(acceptInvitationActions, acceptInvitationReducers);
11
+ export const useAcceptInvitationActions = () => {
12
+ return useStore().stateActions.auth.acceptInvitationActions;
13
+ };
@@ -1,7 +1,13 @@
1
- import { activateAccountReducers, activateAccountActions } from '@frontegg/redux-store';
2
- import { reducerActionsGenerator, stateHookGenerator } from './hooks';
1
+ import { useStore } from '../FronteggStoreContext';
2
+ import { useSnapshot } from '../useSnapshot';
3
+
4
+ // TODO: remove useless stateMapper, valtio already does this
5
+
3
6
  const defaultMapper = state => state;
4
7
  export function useActivateAccountState(stateMapper = defaultMapper) {
5
- return stateHookGenerator(stateMapper, 'activateState');
8
+ const state = useStore().store.auth.activateAccountState;
9
+ return stateMapper(useSnapshot(state));
6
10
  }
7
- export const useActivateAccountActions = () => reducerActionsGenerator(activateAccountActions, activateAccountReducers);
11
+ export const useActivateAccountActions = () => {
12
+ return useStore().stateActions.auth.activateAccountActions;
13
+ };
@@ -1,9 +1,7 @@
1
- import { IAllAccountsState, AllAccountsActions, IAllAccountsDialogsState, AllAccountsDialogsActions } from '@frontegg/redux-store';
1
+ import { IAllAccountsState, AllAccountsActions, IAllAccountsDialogsState, AllAccountsDialogActions } 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;
7
6
  export declare function useAllAccountsDialogsState(): IAllAccountsDialogsState;
8
- export declare function useAllAccountsDialogsState<S>(stateMapper: AllAccountsDialogsStateMapper<S>): S;
9
- export declare const useAllAccountsDialogsActions: () => AllAccountsDialogsActions;
7
+ export declare const useAllAccountsDialogsActions: () => AllAccountsDialogActions;
@@ -0,0 +1,20 @@
1
+ import { useStore } from '../FronteggStoreContext';
2
+ import { useSnapshot } from '../useSnapshot';
3
+
4
+ // TODO: remove useless stateMapper, valtio already does this
5
+
6
+ const defaultMapper = state => state;
7
+ export function useAllAccountsState(stateMapper = defaultMapper) {
8
+ const state = useStore().store.auth.allAccountsState;
9
+ return stateMapper(useSnapshot(state));
10
+ }
11
+ export const useAllAccountsActions = () => {
12
+ return useStore().stateActions.auth.allAccountsActions;
13
+ };
14
+ export function useAllAccountsDialogsState() {
15
+ const state = useStore().store.auth.allAccountsDialogsState;
16
+ return useSnapshot(state);
17
+ }
18
+ export const useAllAccountsDialogsActions = () => {
19
+ return useStore().stateActions.auth.allAccountsDialogActions;
20
+ };
@@ -1,5 +1,3 @@
1
1
  import { ApiTokensActions, ApiTokensState } from '@frontegg/redux-store';
2
- export declare type ApiTokensStateMapper<S> = (state: ApiTokensState) => S;
3
2
  export declare function useApiTokensState(): ApiTokensState;
4
- export declare function useApiTokensState<S>(stateMapper: ApiTokensStateMapper<S>): S;
5
3
  export declare const useApiTokensActions: () => ApiTokensActions;
package/auth/apiTokens.js CHANGED
@@ -1,7 +1,9 @@
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');
1
+ import { useStore } from '../FronteggStoreContext';
2
+ import { useSnapshot } from '../useSnapshot';
3
+ export function useApiTokensState() {
4
+ const state = useStore().store.auth.apiTokensState;
5
+ return useSnapshot(state);
6
6
  }
7
- export const useApiTokensActions = () => reducerActionsGenerator(apiTokensActions, apiTokensReducers);
7
+ export const useApiTokensActions = () => {
8
+ return useStore().stateActions.auth.apiTokensActions;
9
+ };
@@ -0,0 +1,3 @@
1
+ import { ApplicationsActions, ApplicationsState } from '@frontegg/redux-store';
2
+ export declare function useApplicationsState(): ApplicationsState;
3
+ export declare const useApplicationsActions: () => ApplicationsActions;
@@ -0,0 +1,9 @@
1
+ import { useStore } from '../FronteggStoreContext';
2
+ import { useSnapshot } from '../useSnapshot';
3
+ export function useApplicationsState() {
4
+ const state = useStore().store.auth.applicationsState;
5
+ return useSnapshot(state);
6
+ }
7
+ export const useApplicationsActions = () => {
8
+ return useStore().stateActions.auth.applicationsActions;
9
+ };
@@ -1,10 +1,7 @@
1
- import { CustomLoginActions } from '@frontegg/redux-store';
2
- import { CustomLoginState } from '@frontegg/types';
3
- export declare type CustomLoginStateMapper<S> = (state: CustomLoginState) => S;
1
+ import { CustomLoginState, CustomLoginActions } from '@frontegg/redux-store';
4
2
  export declare function useCustomLoginState(): CustomLoginState;
5
- export declare function useCustomLoginState<S>(stateMapper: CustomLoginStateMapper<S>): S;
6
3
  export declare const useCustomLoginActions: () => CustomLoginActions;
7
4
  export declare const useCustomLoginTheme: () => {
8
- customLoginTheme: import("@frontegg/types").LoginBoxThemeOptions | undefined;
5
+ customLoginTheme: any;
9
6
  getCustomLoginThemeValue: (path?: string | undefined) => any;
10
7
  };
@@ -1,18 +1,17 @@
1
- import { customLoginActions, customLoginReducers } from '@frontegg/redux-store';
2
- import { reducerActionsGenerator, stateHookGenerator } from './hooks';
3
- import getValue from 'get-value';
4
1
  import { useCallback } from 'react';
5
- const defaultMapper = state => state;
6
- export function useCustomLoginState(stateMapper = defaultMapper) {
7
- return stateHookGenerator(stateMapper, 'customLoginState');
2
+ import getValue from 'get-value';
3
+ import { useStore } from '../FronteggStoreContext';
4
+ import { useSnapshot } from '../useSnapshot';
5
+ export function useCustomLoginState() {
6
+ const state = useStore().store.auth.customLoginState;
7
+ return useSnapshot(state);
8
8
  }
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;
9
+ export const useCustomLoginActions = () => {
10
+ return useStore().stateActions.auth.customLoginActions;
13
11
  };
14
12
  export const useCustomLoginTheme = () => {
15
- const customLoginTheme = useCustomLoginState(themeMapper);
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;
16
15
  const getCustomLoginThemeValue = useCallback(path => {
17
16
  return path && customLoginTheme ? getValue(customLoginTheme, path) : customLoginTheme;
18
17
  }, [customLoginTheme]);