@frontegg/react-hooks 6.178.0-alpha.2 → 6.178.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,39 +1,50 @@
1
+ import { securityPolicyActions, securityPolicyReducers } from '@frontegg/redux-store';
2
+ import { reducerActionsGenerator, stateHookGenerator } from '../hooks';
1
3
  import { useEffect } from 'react';
2
- import { useStore } from '../../FronteggStoreContext';
3
- import { useSnapshot } from 'valtio/react';
4
-
5
- // TODO: remove useless stateMapper, valtio already does this
6
-
7
4
  const defaultMapper = state => state;
8
- // @deprecated use useSecurityPolicyState() instead
9
5
  export function useSecurityPolicyState(stateMapper = defaultMapper) {
10
- const state = useStore().store.auth.securityPolicyState;
11
- return stateMapper(useSnapshot(state));
6
+ return stateHookGenerator(stateMapper, 'securityPolicyState');
12
7
  }
13
- export const useSecurityPolicyActions = () => {
14
- return useStore().stateActions.auth.securityPolicyActions;
15
- };
8
+ export const useSecurityPolicyActions = () => reducerActionsGenerator(securityPolicyActions, securityPolicyReducers);
16
9
  export const usePublicPolicySettings = (loadOnMount = false) => {
17
10
  const {
18
- publicPolicy
19
- } = useSecurityPolicyState();
11
+ loading,
12
+ policy,
13
+ saving,
14
+ error
15
+ } = useSecurityPolicyState(state => state.publicPolicy);
20
16
  const {
21
17
  loadPublicSecurityPolicy
22
18
  } = useSecurityPolicyActions();
23
19
  useEffect(() => {
24
- (loadOnMount || !publicPolicy.policy) && loadPublicSecurityPolicy();
20
+ (loadOnMount || !policy) && loadPublicSecurityPolicy();
21
+ // eslint-disable-next-line react-hooks/exhaustive-deps
25
22
  }, [loadOnMount, loadPublicSecurityPolicy]);
26
- return publicPolicy;
23
+ return {
24
+ loading,
25
+ saving,
26
+ error,
27
+ policy
28
+ };
27
29
  };
28
30
  export const usePublicAuthStrategiesPolicySettings = (loadOnMount = false) => {
29
31
  const {
30
- publicAuthStrategyPolicy
31
- } = useSecurityPolicyState();
32
+ loading,
33
+ policy,
34
+ saving,
35
+ error
36
+ } = useSecurityPolicyState(state => state.publicAuthStrategyPolicy);
32
37
  const {
33
38
  loadPublicAuthStrategiesPolicy
34
39
  } = useSecurityPolicyActions();
35
40
  useEffect(() => {
36
- (loadOnMount || !publicAuthStrategyPolicy.policy) && loadPublicAuthStrategiesPolicy();
41
+ (loadOnMount || !policy) && loadPublicAuthStrategiesPolicy();
42
+ // eslint-disable-next-line react-hooks/exhaustive-deps
37
43
  }, [loadOnMount, loadPublicAuthStrategiesPolicy]);
38
- return publicAuthStrategyPolicy;
44
+ return {
45
+ loading,
46
+ saving,
47
+ error,
48
+ policy
49
+ };
39
50
  };
@@ -1,3 +1,5 @@
1
- import type { SessionsPolicyState, SessionsPolicyActions } from '@frontegg/redux-store';
1
+ import { SessionsPolicyState, SessionsPolicyActions } from '@frontegg/redux-store';
2
+ export declare type SessionsPolicyStateMapper<S> = (state: SessionsPolicyState) => S;
2
3
  export declare function useSessionsPolicyState(): SessionsPolicyState;
4
+ export declare function useSessionsPolicyState<S>(stateMapper: SessionsPolicyStateMapper<S>): S;
3
5
  export declare const useSessionsPolicyActions: () => SessionsPolicyActions;
@@ -1,9 +1,7 @@
1
- import { useStore } from '../../FronteggStoreContext';
2
- import { useSnapshot } from 'valtio/react';
3
- export function useSessionsPolicyState() {
4
- const state = useStore().store.auth.sessionsPolicyState;
5
- return useSnapshot(state);
1
+ import { sessionsPolicyActions, sessionsPolicyReducers } from '@frontegg/redux-store';
2
+ import { reducerActionsGenerator, stateHookGenerator } from '../hooks';
3
+ const defaultMapper = state => state;
4
+ export function useSessionsPolicyState(stateMapper = defaultMapper) {
5
+ return stateHookGenerator(stateMapper, 'sessionsPolicyState');
6
6
  }
7
- export const useSessionsPolicyActions = () => {
8
- return useStore().stateActions.auth.sessionsPolicyActions;
9
- };
7
+ export const useSessionsPolicyActions = () => reducerActionsGenerator(sessionsPolicyActions, sessionsPolicyReducers);
@@ -1,3 +1,5 @@
1
- import type { SessionsState, SessionsActions } from '@frontegg/redux-store';
1
+ import { SessionsState, SessionsActions } from '@frontegg/redux-store';
2
+ export declare type SessionsStateMapper<S> = (state: SessionsState) => S;
2
3
  export declare function useSessionsState(): SessionsState;
4
+ export declare function useSessionsState<S>(stateMapper: SessionsStateMapper<S>): S;
3
5
  export declare const useSessionsActions: () => SessionsActions;
package/auth/sessions.js CHANGED
@@ -1,8 +1,7 @@
1
- import { useSnapshot } from 'valtio/react';
2
- import { useStore } from '../FronteggStoreContext';
3
- export function useSessionsState() {
4
- return useSnapshot(useStore().store.auth.sessionsState);
1
+ import { sessionsActions, sessionsReducers } from '@frontegg/redux-store';
2
+ import { reducerActionsGenerator, stateHookGenerator } from './hooks';
3
+ const defaultMapper = state => state;
4
+ export function useSessionsState(stateMapper = defaultMapper) {
5
+ return stateHookGenerator(stateMapper, 'sessionsState');
5
6
  }
6
- export const useSessionsActions = () => {
7
- return useStore().stateActions.auth.sessionsActions;
8
- };
7
+ export const useSessionsActions = () => reducerActionsGenerator(sessionsActions, sessionsReducers);
package/auth/signup.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { SignUpState, SignUpActions } from '@frontegg/redux-store';
1
+ import { SignUpState, SignUpActions } from '@frontegg/redux-store';
2
2
  export declare type SignUpStateMapper<S> = (state: SignUpState) => S;
3
3
  export declare function useSignUpState(): SignUpState;
4
4
  export declare function useSignUpState<S>(stateMapper: SignUpStateMapper<S>): S;
package/auth/signup.js CHANGED
@@ -1,16 +1,7 @@
1
- import { useSnapshot } from 'valtio/react';
2
- import { useStore } from '../FronteggStoreContext';
3
-
4
- // TODO: remove useless stateMapper, valtio already does this
5
-
1
+ import { signUpReducers, signUpActions } from '@frontegg/redux-store';
2
+ import { reducerActionsGenerator, stateHookGenerator } from './hooks';
6
3
  const defaultMapper = state => state;
7
- // @deprecated use useSignUpState() instead
8
4
  export function useSignUpState(stateMapper = defaultMapper) {
9
- const {
10
- signUpState
11
- } = useStore().store.auth;
12
- return stateMapper(useSnapshot(signUpState));
5
+ return stateHookGenerator(stateMapper, 'signUpState');
13
6
  }
14
- export const useSignUpActions = () => {
15
- return useStore().stateActions.auth.signUpActions;
16
- };
7
+ export const useSignUpActions = () => reducerActionsGenerator(signUpActions, signUpReducers);
package/auth/sms.d.ts CHANGED
@@ -1,3 +1,6 @@
1
- import type { SmsActions, SmsState } from '@frontegg/redux-store';
1
+ import { SmsActions, SmsState } from '@frontegg/redux-store';
2
+ declare type AuthSmsStateMapper<S> = (state: SmsState) => S;
2
3
  export declare function useSmsState(): SmsState;
4
+ export declare function useSmsState<S>(stateMapper: AuthSmsStateMapper<S>): S;
3
5
  export declare const useSmsActions: () => SmsActions;
6
+ export {};
package/auth/sms.js CHANGED
@@ -1,8 +1,7 @@
1
- import { useSnapshot } from 'valtio/react';
2
- import { useStore } from '../FronteggStoreContext';
3
- export function useSmsState() {
4
- return useSnapshot(useStore().store.auth.smsState);
1
+ import { smsActions, smsReducers } from '@frontegg/redux-store';
2
+ import { reducerActionsGenerator, stateHookGenerator } from './hooks';
3
+ const defaultMapper = state => state;
4
+ export function useSmsState(stateMapper = defaultMapper) {
5
+ return stateHookGenerator(stateMapper, 'smsState');
5
6
  }
6
- export const useSmsActions = () => {
7
- return useStore().stateActions.auth.smsActions;
8
- };
7
+ export const useSmsActions = () => reducerActionsGenerator(smsActions, smsReducers);
@@ -1,4 +1,4 @@
1
- import type { SocialLoginActions, SocialLoginState } from '@frontegg/redux-store';
1
+ import { SocialLoginActions, SocialLoginState } from '@frontegg/redux-store';
2
2
  export declare type SocialLoginStateMapper<S> = (state: SocialLoginState) => S;
3
3
  export declare function useSocialLoginState(): SocialLoginState;
4
4
  export declare function useSocialLoginState<S>(stateMapper: SocialLoginStateMapper<S>): S;
@@ -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 { socialLoginsActions, socialLoginsReducer } from '@frontegg/redux-store';
2
+ import { reducerActionsGenerator, stateHookGenerator } from './hooks';
6
3
  const defaultMapper = state => state;
7
- // @deprecated use useSocialLoginState() instead
8
4
  export function useSocialLoginState(stateMapper = defaultMapper) {
9
- return stateMapper(useSnapshot(useStore().store.auth.socialLoginState));
5
+ return stateHookGenerator(stateMapper, 'socialLoginState');
10
6
  }
11
- export const useSocialLoginActions = () => {
12
- return useStore().stateActions.auth.socialLoginActions;
13
- };
7
+ export const useSocialLoginActions = () => reducerActionsGenerator(socialLoginsActions, socialLoginsReducer);
package/auth/sso.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { SSOState, SSOActions } from '@frontegg/redux-store';
1
+ import { SSOState, SSOActions } from '@frontegg/redux-store';
2
2
  declare type AuthSSOStateMapper<S> = (state: SSOState) => S;
3
3
  export declare function useSSOState(): SSOState;
4
4
  export declare function useSSOState<S>(stateMapper: AuthSSOStateMapper<S>): S;
package/auth/sso.js CHANGED
@@ -1,13 +1,7 @@
1
- import { useSnapshot } from 'valtio/react';
2
- import { useStore } from '../FronteggStoreContext';
3
-
4
- // TODO: remove useless stateMapper, valtio already does this
5
-
1
+ import { ssoActions, ssoReducers } from '@frontegg/redux-store';
2
+ import { reducerActionsGenerator, stateHookGenerator } from './hooks';
6
3
  const defaultMapper = state => state;
7
- // @deprecated use useSSOState() instead
8
4
  export function useSSOState(stateMapper = defaultMapper) {
9
- return stateMapper(useSnapshot(useStore().store.auth.ssoState));
5
+ return stateHookGenerator(stateMapper, 'ssoState');
10
6
  }
11
- export const useSSOActions = () => {
12
- return useStore().stateActions.auth.ssoActions;
13
- };
7
+ export const useSSOActions = () => reducerActionsGenerator(ssoActions, ssoReducers);
@@ -0,0 +1,2 @@
1
+ export * from './stepUp';
2
+ export * from './interfaces';
@@ -0,0 +1,2 @@
1
+ export * from './stepUp';
2
+ export * from './interfaces';
@@ -0,0 +1,2 @@
1
+ import { StepUpState } from '@frontegg/redux-store';
2
+ export declare type StepUpStateMapper<S> = (state: StepUpState) => S;
@@ -0,0 +1 @@
1
+ export {};
@@ -1,5 +1,7 @@
1
1
  import { StepUpState, StepUpActions, IsSteppedUpOptions } from '@frontegg/redux-store';
2
+ import { StepUpStateMapper } from './interfaces';
2
3
  export declare function useStepUpState(): StepUpState;
4
+ export declare function useStepUpState<S>(stateMapper: StepUpStateMapper<S>): S;
3
5
  export declare const useStepUpActions: () => StepUpActions;
4
6
  /**
5
7
  * @returns max age from the query param as a number or null if not exists
@@ -1,14 +1,11 @@
1
- import { STEP_UP_MAX_AGE_PARAM_NAME, getSearchParam, redirectByStepUpUrl, isSteppedUp } from '@frontegg/redux-store';
2
- import { useSnapshot } from 'valtio/react';
3
- import { useStore } from '../FronteggStoreContext';
4
- import { useAuth, useAuthRoutes, useAuthUserOrNull, useOnRedirectTo } from './hooks';
1
+ import { stepUpReducers, stepUpActions, getSearchParam, isSteppedUp, STEP_UP_MAX_AGE_PARAM_NAME, redirectByStepUpUrl } from '@frontegg/redux-store';
2
+ import { reducerActionsGenerator, stateHookGenerator, useAuth, useAuthRoutes, useAuthUserOrNull, useOnRedirectTo } from '../hooks';
5
3
  import { useCallback } from 'react';
6
- export function useStepUpState() {
7
- return useSnapshot(useStore().store.auth.stepUpState);
4
+ const defaultMapper = state => state;
5
+ export function useStepUpState(stateMapper = defaultMapper) {
6
+ return stateHookGenerator(stateMapper, 'stepUpState');
8
7
  }
9
- export const useStepUpActions = () => {
10
- return useStore().stateActions.auth.stepUpActions;
11
- };
8
+ export const useStepUpActions = () => reducerActionsGenerator(stepUpActions, stepUpReducers);
12
9
 
13
10
  /**
14
11
  * @returns max age from the query param as a number or null if not exists
package/auth/team.d.ts CHANGED
@@ -1,13 +1,5 @@
1
- import { TeamActions, TeamState } from '@frontegg/redux-store';
2
- export declare function useTeamState(): TeamState;
3
- export declare const useTeamActions: () => TeamActions;
1
+ import { TeamState, TeamActions } from '@frontegg/redux-store';
4
2
  export declare type AuthTeamStateMapper<S> = (state: TeamState) => S;
5
- /**
6
- * @deprecated use useTeamState instead
7
- */
8
3
  export declare function useAuthTeamState(): TeamState;
9
4
  export declare function useAuthTeamState<S>(stateMapper: AuthTeamStateMapper<S>): S;
10
- /**
11
- * @deprecated use useTeamActions instead
12
- */
13
5
  export declare const useAuthTeamActions: () => TeamActions;
package/auth/team.js CHANGED
@@ -1,25 +1,7 @@
1
- import { useSnapshot } from 'valtio/react';
2
- import { useStore } from '../FronteggStoreContext';
3
- export function useTeamState() {
4
- const state = useStore().store.auth.teamState;
5
- return useSnapshot(state);
6
- }
7
- export const useTeamActions = () => {
8
- return useStore().stateActions.auth.teamActions;
9
- };
1
+ import { teamActions, teamReducers } from '@frontegg/redux-store';
2
+ import { reducerActionsGenerator, stateHookGenerator } from './hooks';
10
3
  const defaultMapper = state => state;
11
- /**
12
- * @deprecated use useTeamState instead
13
- */
14
-
15
- // @deprecated use useTeamState() instead
16
4
  export function useAuthTeamState(stateMapper = defaultMapper) {
17
- return stateMapper(useTeamState());
5
+ return stateHookGenerator(stateMapper, 'teamState');
18
6
  }
19
-
20
- /**
21
- * @deprecated use useTeamActions instead
22
- */
23
- export const useAuthTeamActions = () => {
24
- return useTeamActions();
25
- };
7
+ export const useAuthTeamActions = () => reducerActionsGenerator(teamActions, teamReducers);
package/auth/tenants.d.ts CHANGED
@@ -1,3 +1,5 @@
1
- import type { TenantsState, TenantsActions } from '@frontegg/redux-store';
1
+ import { TenantsState, TenantsActions } from '@frontegg/redux-store';
2
+ export declare type TenantsStateMapper<S> = (state: TenantsState) => S;
2
3
  export declare function useTenantsState(): TenantsState;
4
+ export declare function useTenantsState<S>(stateMapper: TenantsStateMapper<S>): S;
3
5
  export declare const useTenantsActions: () => TenantsActions;
package/auth/tenants.js CHANGED
@@ -1,9 +1,7 @@
1
- import { useStore } from '../FronteggStoreContext';
2
- import { useSnapshot } from 'valtio/react';
3
- export function useTenantsState() {
4
- const state = useStore().store.auth.tenantsState;
5
- return useSnapshot(state);
1
+ import { tenantsActions, tenantsReducers } from '@frontegg/redux-store';
2
+ import { reducerActionsGenerator, stateHookGenerator } from './hooks';
3
+ const defaultMapper = state => state;
4
+ export function useTenantsState(stateMapper = defaultMapper) {
5
+ return stateHookGenerator(stateMapper, 'tenantsState');
6
6
  }
7
- export const useTenantsActions = () => {
8
- return useStore().stateActions.auth.tenantsActions;
9
- };
7
+ export const useTenantsActions = () => reducerActionsGenerator(tenantsActions, tenantsReducers);
@@ -80,9 +80,7 @@ export const CustomComponentRegister = ({
80
80
  CustomComponentHolder.set(generatedKey, obj);
81
81
  return [generatedKey];
82
82
  }
83
- } catch (e) {
84
- /* empty */
85
- }
83
+ } catch (e) {}
86
84
  }
87
85
  if ( /*#__PURE__*/isValidElement(obj) || isElement(obj) || obj === null) {
88
86
  const generatedKey = `${keyPath}.${key}`;
package/common/index.js CHANGED
@@ -2,8 +2,8 @@ import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
3
3
  const _excluded = ["urlStrategy", "onRedirectTo", "renderByRoute", "customLoader", "customStyles", "contextOptions"];
4
4
  import { createContext, useContext } from 'react';
5
- import { useStore } from '../FronteggStoreContext';
6
- import { useSnapshot } from 'valtio/react';
5
+ import { useSelector } from '../FronteggStoreContext';
6
+ import { shallowEqual } from 'react-redux';
7
7
  export const ShadowDomContext = /*#__PURE__*/createContext({});
8
8
  export const useShadowDom = () => {
9
9
  const context = useContext(ShadowDomContext);
@@ -29,6 +29,6 @@ export const useShadowDom = () => {
29
29
  }, rest);
30
30
  };
31
31
  export const useRootState = () => {
32
- return useSnapshot(useStore().store.root);
32
+ return useSelector(state => state.root, shallowEqual);
33
33
  };
34
34
  export * from './CustomComponentHolder';
@@ -1,3 +1,6 @@
1
- import { ConnectivityState, ConnectivityActions } from '@frontegg/redux-store';
2
- export declare function useConnectivityState(): ConnectivityState;
1
+ import { ConnectivityActions, IConnectivityState } from '@frontegg/redux-store';
2
+ export declare type ConnectivityStateMapper<S> = (state: IConnectivityState) => S;
3
+ export declare type StateHookFunction<T> = (() => T) & (<S extends object>(mapper: (state: T) => S) => S);
4
+ export declare function useConnectivityState(): IConnectivityState;
5
+ export declare function useConnectivityState<S>(stateMapper: ConnectivityStateMapper<S>): S;
3
6
  export declare const useConnectivityActions: () => ConnectivityActions;
@@ -1,9 +1,12 @@
1
- import { useStore } from '../FronteggStoreContext';
2
- import { useSnapshot } from 'valtio/react';
3
- export function useConnectivityState() {
4
- const state = useStore().store.connectivity;
5
- return useSnapshot(state);
1
+ import { useMemo } from 'react';
2
+ import { shallowEqual } from 'react-redux';
3
+ import { useSelector, useDispatch } from '../FronteggStoreContext';
4
+ import { bindActionCreators, connectivityActions, connectivityStoreName } from '@frontegg/redux-store';
5
+ const defaultMapper = state => state;
6
+ export function useConnectivityState(stateMapper = defaultMapper) {
7
+ return useSelector(state => stateMapper(state[connectivityStoreName]), shallowEqual);
6
8
  }
7
9
  export const useConnectivityActions = () => {
8
- return useStore().stateActions.connectivity;
10
+ const dispatch = useDispatch();
11
+ return useMemo(() => bindActionCreators(connectivityActions, dispatch), [connectivityActions]);
9
12
  };
package/index.d.ts CHANGED
@@ -1,9 +1,9 @@
1
- export * from './auth';
1
+ export * from './common';
2
2
  export * from './audits';
3
+ export * from './auth';
3
4
  export * from './connectivity';
4
5
  export * from './subscriptions';
5
6
  export * from './vendor';
6
- export * from './common';
7
7
  export * from './flags';
8
8
  export * from './FronteggProvider';
9
9
  export * from './FronteggStoreContext';
package/index.js CHANGED
@@ -1,14 +1,14 @@
1
- /** @license Frontegg v6.178.0-alpha.2
1
+ /** @license Frontegg v6.178.0
2
2
  *
3
3
  * This source code is licensed under the MIT license found in the
4
4
  * LICENSE file in the root directory of this source tree.
5
5
  */
6
- export * from './auth';
6
+ export * from './common';
7
7
  export * from './audits';
8
+ export * from './auth';
8
9
  export * from './connectivity';
9
10
  export * from './subscriptions';
10
11
  export * from './vendor';
11
- export * from './common';
12
12
  export * from './flags';
13
13
  export * from './FronteggProvider';
14
14
  export * from './FronteggStoreContext';
@@ -1,16 +1,141 @@
1
1
  "use strict";
2
2
 
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
3
4
  Object.defineProperty(exports, "__esModule", {
4
5
  value: true
5
6
  });
6
- var _FronteggProvider = require("./FronteggProvider");
7
- Object.keys(_FronteggProvider).forEach(function (key) {
8
- if (key === "default" || key === "__esModule") return;
9
- if (key in exports && exports[key] === _FronteggProvider[key]) return;
10
- Object.defineProperty(exports, key, {
11
- enumerable: true,
12
- get: function () {
13
- return _FronteggProvider[key];
7
+ exports.FronteggStoreProvider = void 0;
8
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
9
+ var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
10
+ var _react = _interopRequireWildcard(require("react"));
11
+ var _reduxStore = require("@frontegg/redux-store");
12
+ var _restApi = require("@frontegg/rest-api");
13
+ var _auth = require("../auth");
14
+ var _FronteggStoreContext = require("../FronteggStoreContext");
15
+ var _jsxRuntime = require("react/jsx-runtime");
16
+ const _excluded = ["authenticatedUrl", "signUpSuccessUrl"];
17
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
18
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
19
+ const defaultSetLoading = loading => {
20
+ if (loading) {
21
+ document.body.classList.add('frontegg-loading');
22
+ } else {
23
+ document.body.classList.remove('frontegg-loading');
24
+ }
25
+ };
26
+ const HideChildrenIfFronteggRoutes = ({
27
+ children,
28
+ basename
29
+ }) => {
30
+ const routes = (0, _auth.useAuthRoutes)();
31
+ const uriRef = (0, _react.useRef)(window.location.pathname);
32
+ const animationFrameRef = (0, _react.useRef)(0);
33
+ const [uri, setUri] = (0, _react.useState)(window.location.pathname);
34
+ const checker = (0, _react.useCallback)(() => {
35
+ if (uriRef.current !== window.location.pathname) {
36
+ uriRef.current = window.location.pathname;
37
+ setUri(document.location.pathname);
14
38
  }
39
+ animationFrameRef.current = window.requestAnimationFrame(checker);
40
+ }, []);
41
+ (0, _react.useEffect)(() => {
42
+ document.addEventListener('frontegg_onRedirectTo_fired', () => {
43
+ if (uriRef.current !== window.location.pathname) {
44
+ uriRef.current = window.location.pathname;
45
+ setUri(document.location.pathname);
46
+ }
47
+ });
48
+ window.addEventListener('popstate', () => {
49
+ if (uriRef.current !== window.location.pathname) {
50
+ uriRef.current = window.location.pathname;
51
+ setUri(document.location.pathname);
52
+ }
53
+ });
54
+ animationFrameRef.current = window.requestAnimationFrame(checker);
55
+ return () => {
56
+ window.cancelAnimationFrame(animationFrameRef.current);
57
+ };
58
+ }, [checker, setUri]);
59
+ const calculatedBasename = basename ? basename.endsWith('/') ? basename.substring(0, basename.length - 1) : '' : '';
60
+ const checkRoutes = (0, _objectWithoutPropertiesLoose2.default)(routes, _excluded);
61
+ if (Object.values(checkRoutes).map(url => `${calculatedBasename}${url}`).indexOf(uri) !== -1) {
62
+ return null;
63
+ }
64
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
65
+ children: children
15
66
  });
16
- });
67
+ };
68
+ const FronteggContent = ({
69
+ children,
70
+ app,
71
+ setLoading
72
+ }) => {
73
+ var _app$options, _app$options2;
74
+ const {
75
+ isLoading
76
+ } = (0, _auth.useAuth)(({
77
+ isLoading
78
+ }) => ({
79
+ isLoading
80
+ }));
81
+ const customLoginBox = !app || (app == null ? void 0 : (_app$options = app.options) == null ? void 0 : _app$options.customLoginBox) === true;
82
+ const isNextJS = (app == null ? void 0 : (_app$options2 = app.options) == null ? void 0 : _app$options2.framework) === 'nextjs';
83
+ const alwaysShowChildren = customLoginBox || isNextJS;
84
+ const loadingRef = (0, _react.useRef)(undefined);
85
+ if (isLoading !== loadingRef.current && !isNextJS) {
86
+ loadingRef.current = isLoading;
87
+ setLoading(isLoading);
88
+ }
89
+ if (alwaysShowChildren) {
90
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
91
+ children: children
92
+ });
93
+ }
94
+ if (isLoading && !isNextJS) {
95
+ return null;
96
+ }
97
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(HideChildrenIfFronteggRoutes, {
98
+ basename: app == null ? void 0 : app.options.basename,
99
+ children: children
100
+ });
101
+ };
102
+ const FronteggStoreProvider = props => {
103
+ var _app$options$contextO, _app$options3, _app$options$previewM, _app$options4, _app$options5, _app$options6;
104
+ const {
105
+ children,
106
+ app,
107
+ contextOptions,
108
+ setLoading = defaultSetLoading,
109
+ alwaysVisibleChildren
110
+ } = props;
111
+
112
+ // TODO: make this optionals more readable
113
+ const context = (_app$options$contextO = app == null ? void 0 : (_app$options3 = app.options) == null ? void 0 : _app$options3.contextOptions) != null ? _app$options$contextO : contextOptions;
114
+ if (!context) {
115
+ throw Error('contextOptions must not be null or undefined');
116
+ }
117
+ const previewMode = (_app$options$previewM = app == null ? void 0 : (_app$options4 = app.options) == null ? void 0 : _app$options4.previewMode) != null ? _app$options$previewM : false;
118
+ const authOptions = app != null && (_app$options5 = app.options) != null && _app$options5.authOptions ? (0, _extends2.default)({}, app.options.authOptions, {
119
+ hostedLoginBox: app.options.hostedLoginBox
120
+ }) : {
121
+ hostedLoginBox: app == null ? void 0 : (_app$options6 = app.options) == null ? void 0 : _app$options6.hostedLoginBox
122
+ };
123
+ _restApi.ContextHolder.setContext(context);
124
+ const store = (0, _react.useMemo)(() => {
125
+ var _app$name, _app$options7;
126
+ return (0, _reduxStore.createFronteggStore)({
127
+ context,
128
+ appName: (_app$name = app == null ? void 0 : app.name) != null ? _app$name : 'default'
129
+ }, app, previewMode, authOptions, undefined, false, app == null ? void 0 : (_app$options7 = app.options) == null ? void 0 : _app$options7.urlStrategy);
130
+ }, [app, previewMode]);
131
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_FronteggStoreContext.Provider, {
132
+ context: _FronteggStoreContext.FronteggStoreContext,
133
+ store: store,
134
+ children: [alwaysVisibleChildren, /*#__PURE__*/(0, _jsxRuntime.jsx)(FronteggContent, {
135
+ setLoading: setLoading,
136
+ app: app,
137
+ children: children
138
+ })]
139
+ });
140
+ };
141
+ exports.FronteggStoreProvider = FronteggStoreProvider;