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

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 (137) hide show
  1. package/FronteggProvider/FronteggProvider.d.ts +12 -0
  2. package/FronteggProvider/FronteggProvider.js +138 -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/customLogin.d.ts +2 -5
  22. package/auth/customLogin.js +10 -11
  23. package/auth/entitlements.d.ts +32 -13
  24. package/auth/entitlements.js +116 -21
  25. package/auth/forgotPassword.d.ts +0 -2
  26. package/auth/forgotPassword.js +8 -6
  27. package/auth/groups.d.ts +0 -4
  28. package/auth/groups.js +12 -13
  29. package/auth/hooks.d.ts +44 -12
  30. package/auth/hooks.js +73 -62
  31. package/auth/impersonate.d.ts +0 -2
  32. package/auth/impersonate.js +7 -6
  33. package/auth/index.d.ts +15 -16
  34. package/auth/index.js +16 -17
  35. package/auth/login.d.ts +1 -3
  36. package/auth/login.js +7 -6
  37. package/auth/mfa.d.ts +1 -1
  38. package/auth/mfa.js +13 -4
  39. package/auth/passkeys.d.ts +1 -4
  40. package/auth/passkeys.js +7 -6
  41. package/auth/profile.d.ts +2 -4
  42. package/auth/profile.js +9 -8
  43. package/auth/provisioning.d.ts +1 -3
  44. package/auth/provisioning.js +7 -6
  45. package/auth/resetPhoneNumber.d.ts +1 -3
  46. package/auth/resetPhoneNumber.js +7 -6
  47. package/auth/roles.d.ts +1 -3
  48. package/auth/roles.js +7 -6
  49. package/auth/security/index.d.ts +4 -0
  50. package/auth/security/index.js +4 -0
  51. package/auth/security/restrictions.d.ts +0 -2
  52. package/auth/security/restrictions.js +10 -10
  53. package/auth/security/securityCenter.d.ts +1 -4
  54. package/auth/security/securityCenter.js +8 -6
  55. package/auth/security/securityPolicy.d.ts +5 -11
  56. package/auth/security/securityPolicy.js +19 -30
  57. package/auth/security/sessionsPolicy.d.ts +1 -3
  58. package/auth/security/sessionsPolicy.js +8 -6
  59. package/auth/sessions.d.ts +1 -3
  60. package/auth/sessions.js +7 -6
  61. package/auth/signup.d.ts +1 -1
  62. package/auth/signup.js +13 -4
  63. package/auth/sms.d.ts +3 -0
  64. package/auth/sms.js +8 -0
  65. package/auth/socialLogin.d.ts +1 -1
  66. package/auth/socialLogin.js +10 -4
  67. package/auth/sso.d.ts +1 -1
  68. package/auth/sso.js +10 -4
  69. package/auth/stepUp.d.ts +16 -0
  70. package/auth/stepUp.js +51 -0
  71. package/auth/team.d.ts +9 -1
  72. package/auth/team.js +22 -4
  73. package/auth/tenants.d.ts +1 -3
  74. package/auth/tenants.js +8 -6
  75. package/common/CustomComponentHolder.js +3 -1
  76. package/common/index.js +3 -3
  77. package/connectivity/hooks.d.ts +2 -5
  78. package/connectivity/hooks.js +6 -9
  79. package/index.d.ts +2 -2
  80. package/index.js +3 -3
  81. package/node/FronteggProvider/FronteggProvider.js +146 -0
  82. package/node/FronteggProvider/index.js +9 -134
  83. package/node/FronteggStoreContext/FronteggStoreContext.js +28 -0
  84. package/node/FronteggStoreContext/index.js +11 -35
  85. package/node/audits/auditLogs.js +8 -6
  86. package/node/audits/auditsMetadata.js +8 -6
  87. package/node/audits/hooks.js +7 -34
  88. package/node/auth/acceptInvitation.js +7 -5
  89. package/node/auth/activateAccount.js +7 -4
  90. package/node/auth/allAccounts.js +27 -0
  91. package/node/auth/apiTokens.js +8 -6
  92. package/node/auth/customLogin.js +11 -12
  93. package/node/auth/entitlements.js +119 -22
  94. package/node/auth/forgotPassword.js +8 -6
  95. package/node/auth/groups.js +12 -12
  96. package/node/auth/hooks.js +77 -67
  97. package/node/auth/impersonate.js +7 -6
  98. package/node/auth/index.js +103 -101
  99. package/node/auth/login.js +7 -6
  100. package/node/auth/mfa.js +10 -4
  101. package/node/auth/passkeys.js +7 -6
  102. package/node/auth/profile.js +10 -9
  103. package/node/auth/provisioning.js +7 -6
  104. package/node/auth/resetPhoneNumber.js +7 -6
  105. package/node/auth/roles.js +7 -6
  106. package/node/auth/security/index.js +49 -0
  107. package/node/auth/security/restrictions.js +10 -10
  108. package/node/auth/security/securityCenter.js +8 -6
  109. package/node/auth/security/securityPolicy.js +16 -30
  110. package/node/auth/security/sessionsPolicy.js +8 -6
  111. package/node/auth/sessions.js +7 -6
  112. package/node/auth/signup.js +10 -4
  113. package/node/auth/sms.js +16 -0
  114. package/node/auth/socialLogin.js +7 -4
  115. package/node/auth/sso.js +7 -4
  116. package/node/auth/stepUp.js +62 -0
  117. package/node/auth/team.js +25 -4
  118. package/node/auth/tenants.js +8 -6
  119. package/node/common/CustomComponentHolder.js +3 -1
  120. package/node/common/index.js +2 -2
  121. package/node/connectivity/hooks.js +5 -8
  122. package/node/index.js +16 -16
  123. package/node/subscriptions/hooks.js +84 -51
  124. package/node/tests/hooks.tsc-test.js +339 -0
  125. package/node/useSnapshot/index.js +137 -0
  126. package/node/vendor/hooks.js +5 -6
  127. package/package.json +3 -3
  128. package/subscriptions/hooks.d.ts +32 -10
  129. package/subscriptions/hooks.js +81 -49
  130. package/tests/hooks.tsc-test.js +338 -0
  131. package/useSnapshot/index.d.ts +78 -0
  132. package/useSnapshot/index.js +128 -0
  133. package/useSnapshot/package.json +6 -0
  134. package/vendor/hooks.d.ts +0 -1
  135. package/vendor/hooks.js +9 -7
  136. package/auth/MSP/allAccounts.js +0 -15
  137. package/node/auth/MSP/allAccounts.js +0 -24
package/auth/login.js CHANGED
@@ -1,7 +1,8 @@
1
- import { loginReducers, loginActions } from '@frontegg/redux-store';
2
- import { reducerActionsGenerator, stateHookGenerator } from './hooks';
3
- const defaultMapper = state => state;
4
- export function useLoginState(stateMapper = defaultMapper) {
5
- return stateHookGenerator(stateMapper, 'loginState');
1
+ import { useSnapshot } from '../useSnapshot';
2
+ import { useStore } from '../FronteggStoreContext';
3
+ export function useLoginState() {
4
+ return useSnapshot(useStore().store.auth.loginState);
6
5
  }
7
- export const useLoginActions = () => reducerActionsGenerator(loginActions, loginReducers);
6
+ export const useLoginActions = () => {
7
+ return useStore().stateActions.auth.loginActions;
8
+ };
package/auth/mfa.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { MfaActions, MFAState } from '@frontegg/redux-store';
1
+ import type { MfaActions, MFAState } from '@frontegg/redux-store';
2
2
  declare type AuthMfaStateMapper<S> = (state: MFAState) => S;
3
3
  export declare function useMfaState(): MFAState;
4
4
  export declare function useMfaState<S>(stateMapper: AuthMfaStateMapper<S>): S;
package/auth/mfa.js CHANGED
@@ -1,7 +1,16 @@
1
- import { mfaActions, mfaReducers } from '@frontegg/redux-store';
2
- import { reducerActionsGenerator, stateHookGenerator } from './hooks';
1
+ import { useSnapshot } from '../useSnapshot';
2
+ import { useStore } from '../FronteggStoreContext';
3
+
4
+ // TODO: remove useless stateMapper, valtio already does this
5
+
3
6
  const defaultMapper = state => state;
7
+ // @deprecated use useMfaState() instead
4
8
  export function useMfaState(stateMapper = defaultMapper) {
5
- return stateHookGenerator(stateMapper, 'mfaState');
9
+ const {
10
+ mfaState
11
+ } = useStore().store.auth;
12
+ return stateMapper(useSnapshot(mfaState));
6
13
  }
7
- export const useMfaActions = () => reducerActionsGenerator(mfaActions, mfaReducers);
14
+ export const useMfaActions = () => {
15
+ return useStore().stateActions.auth.mfaActions;
16
+ };
@@ -1,6 +1,3 @@
1
- import { PasskeysActions, PasskeysState } from '@frontegg/redux-store';
2
- declare type AuthPasskeysStateMapper<S> = (state: PasskeysState) => S;
1
+ import type { PasskeysActions, PasskeysState } from '@frontegg/redux-store';
3
2
  export declare function usePasskeysState(): PasskeysState;
4
- export declare function usePasskeysState<S>(stateMapper: AuthPasskeysStateMapper<S>): S;
5
3
  export declare const usePasskeysActions: () => PasskeysActions;
6
- export {};
package/auth/passkeys.js CHANGED
@@ -1,7 +1,8 @@
1
- import { passkeysActions, passkeysReducers } from '@frontegg/redux-store';
2
- import { reducerActionsGenerator, stateHookGenerator } from './hooks';
3
- const defaultMapper = state => state;
4
- export function usePasskeysState(stateMapper = defaultMapper) {
5
- return stateHookGenerator(stateMapper, 'passkeysState');
1
+ import { useSnapshot } from '../useSnapshot';
2
+ import { useStore } from '../FronteggStoreContext';
3
+ export function usePasskeysState() {
4
+ return useSnapshot(useStore().store.auth.passkeysState);
6
5
  }
7
- export const usePasskeysActions = () => reducerActionsGenerator(passkeysActions, passkeysReducers);
6
+ export const usePasskeysActions = () => {
7
+ return useStore().stateActions.auth.passkeysActions;
8
+ };
package/auth/profile.d.ts CHANGED
@@ -1,6 +1,4 @@
1
- import { ProfileActions, ProfileState } from '@frontegg/redux-store';
2
- export declare const reloadProfileIfNeeded: () => void;
3
- export declare type ProfileStateMapper<S> = (state: ProfileState) => S;
1
+ import type { ProfileActions, ProfileState } from '@frontegg/redux-store';
4
2
  export declare function useProfileState(): ProfileState;
5
- export declare function useProfileState<S>(stateMapper: ProfileStateMapper<S>): S;
6
3
  export declare const useProfileActions: () => ProfileActions;
4
+ export declare const reloadProfileIfNeeded: () => void;
package/auth/profile.js CHANGED
@@ -1,6 +1,12 @@
1
1
  import { useEffect } from 'react';
2
- import { profileActions, profileReducers } from '@frontegg/redux-store';
3
- import { reducerActionsGenerator, stateHookGenerator } from './hooks';
2
+ import { useSnapshot } from '../useSnapshot';
3
+ import { useStore } from '../FronteggStoreContext';
4
+ export function useProfileState() {
5
+ return useSnapshot(useStore().store.auth.profileState);
6
+ }
7
+ export const useProfileActions = () => {
8
+ return useStore().stateActions.auth.profileActions;
9
+ };
4
10
  export const reloadProfileIfNeeded = () => {
5
11
  const {
6
12
  loading
@@ -11,9 +17,4 @@ export const reloadProfileIfNeeded = () => {
11
17
  useEffect(() => {
12
18
  !loading && loadProfile();
13
19
  }, []);
14
- };
15
- const defaultMapper = state => state;
16
- export function useProfileState(stateMapper = defaultMapper) {
17
- return stateHookGenerator(stateMapper, 'profileState');
18
- }
19
- export const useProfileActions = () => reducerActionsGenerator(profileActions, profileReducers);
20
+ };
@@ -1,5 +1,3 @@
1
- import { ProvisioningActions, ProvisioningState } from '@frontegg/redux-store';
2
- export declare type ProvisioningStateMapper<S> = (state: ProvisioningState) => S;
1
+ import type { ProvisioningActions, ProvisioningState } from '@frontegg/redux-store';
3
2
  export declare function useProvisioningState(): ProvisioningState;
4
- export declare function useProvisioningState<S>(stateMapper: ProvisioningStateMapper<S>): S;
5
3
  export declare const useProvisioningActions: () => ProvisioningActions;
@@ -1,7 +1,8 @@
1
- import { provisioningActions, provisioningReducers } from '@frontegg/redux-store';
2
- import { reducerActionsGenerator, stateHookGenerator } from './hooks';
3
- const defaultMapper = state => state;
4
- export function useProvisioningState(stateMapper = defaultMapper) {
5
- return stateHookGenerator(stateMapper, 'provisioningState');
1
+ import { useSnapshot } from '../useSnapshot';
2
+ import { useStore } from '../FronteggStoreContext';
3
+ export function useProvisioningState() {
4
+ return useSnapshot(useStore().store.auth.provisioningState);
6
5
  }
7
- export const useProvisioningActions = () => reducerActionsGenerator(provisioningActions, provisioningReducers);
6
+ export const useProvisioningActions = () => {
7
+ return useStore().stateActions.auth.provisioningActions;
8
+ };
@@ -1,5 +1,3 @@
1
- import { ResetPhoneNumberState, ResetPhoneNumberActions } from '@frontegg/redux-store';
2
- export declare type ResetPhoneNumberStateMapper<S> = (state: ResetPhoneNumberState) => S;
1
+ import type { ResetPhoneNumberState, ResetPhoneNumberActions } from '@frontegg/redux-store';
3
2
  export declare function useResetPhoneNumberState(): ResetPhoneNumberState;
4
- export declare function useResetPhoneNumberState<S>(stateMapper: ResetPhoneNumberStateMapper<S>): S;
5
3
  export declare const useResetPhoneNumberActions: () => ResetPhoneNumberActions;
@@ -1,7 +1,8 @@
1
- import { resetPhoneNumberReducers, resetPhoneNumberActions } from '@frontegg/redux-store';
2
- import { reducerActionsGenerator, stateHookGenerator } from './hooks';
3
- const defaultMapper = state => state;
4
- export function useResetPhoneNumberState(stateMapper = defaultMapper) {
5
- return stateHookGenerator(stateMapper, 'resetPhoneNumberState');
1
+ import { useSnapshot } from '../useSnapshot';
2
+ import { useStore } from '../FronteggStoreContext';
3
+ export function useResetPhoneNumberState() {
4
+ return useSnapshot(useStore().store.auth.resetPhoneNumberState);
6
5
  }
7
- export const useResetPhoneNumberActions = () => reducerActionsGenerator(resetPhoneNumberActions, resetPhoneNumberReducers);
6
+ export const useResetPhoneNumberActions = () => {
7
+ return useStore().stateActions.auth.resetPhoneNumberActions;
8
+ };
package/auth/roles.d.ts CHANGED
@@ -1,5 +1,3 @@
1
- import { RolesActions, RolesState } from '@frontegg/redux-store';
2
- export declare type RolesStateMapper<S> = (state: RolesState) => S;
1
+ import type { RolesActions, RolesState } from '@frontegg/redux-store';
3
2
  export declare function useRolesState(): RolesState;
4
- export declare function useRolesState<S>(stateMapper: RolesStateMapper<S>): S;
5
3
  export declare const useRolesActions: () => RolesActions;
package/auth/roles.js CHANGED
@@ -1,7 +1,8 @@
1
- import { rolesReducers, rolesActions } from '@frontegg/redux-store';
2
- import { reducerActionsGenerator, stateHookGenerator } from './hooks';
3
- const defaultMapper = state => state;
4
- export function useRolesState(stateMapper = defaultMapper) {
5
- return stateHookGenerator(stateMapper, 'rolesState');
1
+ import { useSnapshot } from '../useSnapshot';
2
+ import { useStore } from '../FronteggStoreContext';
3
+ export function useRolesState() {
4
+ return useSnapshot(useStore().store.auth.rolesState);
6
5
  }
7
- export const useRolesActions = () => reducerActionsGenerator(rolesActions, rolesReducers);
6
+ export const useRolesActions = () => {
7
+ return useStore().stateActions.auth.rolesActions;
8
+ };
@@ -0,0 +1,4 @@
1
+ export * from './restrictions';
2
+ export * from './securityCenter';
3
+ export * from './securityPolicy';
4
+ export * from './sessionsPolicy';
@@ -0,0 +1,4 @@
1
+ export * from './restrictions';
2
+ export * from './securityCenter';
3
+ export * from './securityPolicy';
4
+ export * from './sessionsPolicy';
@@ -1,7 +1,5 @@
1
1
  import { RestrictionsActions, RestrictionsState } from '@frontegg/redux-store';
2
- export declare type RestrictionsStateMapper<S> = (state: RestrictionsState) => S;
3
2
  export declare function useRestrictionsState(): RestrictionsState;
4
- export declare function useRestrictionsState<S>(stateMapper: RestrictionsStateMapper<S>): S;
5
3
  export declare const useRestrictionsActions: () => RestrictionsActions;
6
4
  export declare const useIpRestrictions: (loadOnMount?: boolean) => {
7
5
  loading: boolean;
@@ -1,11 +1,13 @@
1
- import { restrictionsReducers, restrictionsActions } from '@frontegg/redux-store';
2
1
  import { useEffect } from 'react';
3
- import { reducerActionsGenerator, stateHookGenerator } from '../hooks';
4
- const defaultMapper = state => state;
5
- export function useRestrictionsState(stateMapper = defaultMapper) {
6
- return stateHookGenerator(stateMapper, 'restrictionsState');
2
+ import { useStore } from '../../FronteggStoreContext';
3
+ import { useSnapshot } from '../../useSnapshot';
4
+ export function useRestrictionsState() {
5
+ const state = useStore().store.auth.restrictionsState;
6
+ return useSnapshot(state);
7
7
  }
8
- export const useRestrictionsActions = () => reducerActionsGenerator(restrictionsActions, restrictionsReducers);
8
+ export const useRestrictionsActions = () => {
9
+ return useStore().stateActions.auth.restrictionsActions;
10
+ };
9
11
  export const useIpRestrictions = (loadOnMount = false) => {
10
12
  const {
11
13
  loading,
@@ -15,13 +17,12 @@ export const useIpRestrictions = (loadOnMount = false) => {
15
17
  pagination,
16
18
  totalPages,
17
19
  userIpValid
18
- } = useRestrictionsState(state => state.ipRestrictions);
20
+ } = useRestrictionsState().ipRestrictions;
19
21
  const {
20
22
  loadIpRestrictions
21
23
  } = useRestrictionsActions();
22
24
  useEffect(() => {
23
25
  (loadOnMount || !data) && loadIpRestrictions();
24
- // eslint-disable-next-line react-hooks/exhaustive-deps
25
26
  }, [loadOnMount, loadIpRestrictions]);
26
27
  return {
27
28
  loading,
@@ -39,13 +40,12 @@ export const useEmailDomainRestrictions = (loadOnMount = false) => {
39
40
  data,
40
41
  saving,
41
42
  error
42
- } = useRestrictionsState(state => state.emailDomainRestrictions);
43
+ } = useRestrictionsState().emailDomainRestrictions;
43
44
  const {
44
45
  loadEmailDomainRestrictions
45
46
  } = useRestrictionsActions();
46
47
  useEffect(() => {
47
48
  (loadOnMount || !data) && loadEmailDomainRestrictions();
48
- // eslint-disable-next-line react-hooks/exhaustive-deps
49
49
  }, [loadOnMount, loadEmailDomainRestrictions]);
50
50
  return {
51
51
  loading,
@@ -1,6 +1,3 @@
1
- import { SecurityCenterActions, SecurityCenterState } from '@frontegg/redux-store';
2
- declare type AuthSecurityCenterStateMapper<S> = (state: SecurityCenterState) => S;
1
+ import type { SecurityCenterActions, SecurityCenterState } from '@frontegg/redux-store';
3
2
  export declare function useSecurityCenterState(): SecurityCenterState;
4
- export declare function useSecurityCenterState<S>(stateMapper: AuthSecurityCenterStateMapper<S>): S;
5
3
  export declare const useSecurityCenterActions: () => SecurityCenterActions;
6
- export {};
@@ -1,7 +1,9 @@
1
- import { securityCenterActions, securityCenterReducers } from '@frontegg/redux-store';
2
- import { reducerActionsGenerator, stateHookGenerator } from '../hooks';
3
- const defaultMapper = state => state;
4
- export function useSecurityCenterState(stateMapper = defaultMapper) {
5
- return stateHookGenerator(stateMapper, 'securityCenterState');
1
+ import { useStore } from '../../FronteggStoreContext';
2
+ import { useSnapshot } from '../../useSnapshot';
3
+ export function useSecurityCenterState() {
4
+ const state = useStore().store.auth.securityCenterState;
5
+ return useSnapshot(state);
6
6
  }
7
- export const useSecurityCenterActions = () => reducerActionsGenerator(securityCenterActions, securityCenterReducers);
7
+ export const useSecurityCenterActions = () => {
8
+ return useStore().stateActions.auth.securityCenterActions;
9
+ };
@@ -1,17 +1,11 @@
1
- import { SecurityPolicyActions, SecurityPolicyState } from '@frontegg/redux-store';
1
+ import type { SecurityPolicyActions, SecurityPolicyState } from '@frontegg/redux-store';
2
2
  export declare type SecurityPolicyStateMapper<S> = (state: SecurityPolicyState) => S;
3
3
  export declare function useSecurityPolicyState(): SecurityPolicyState;
4
4
  export declare function useSecurityPolicyState<S>(stateMapper: SecurityPolicyStateMapper<S>): S;
5
5
  export declare const useSecurityPolicyActions: () => SecurityPolicyActions;
6
- export declare const usePublicPolicySettings: (loadOnMount?: boolean) => {
7
- loading: boolean;
8
- saving: boolean | undefined;
9
- error: any;
10
- policy: import("@frontegg/rest-api").IVendorConfig | undefined;
6
+ export declare const usePublicPolicySettings: (loadOnMount?: boolean) => import("@frontegg/redux-store").WithStatus & {
7
+ policy?: import("@frontegg/rest-api").IVendorConfig | undefined;
11
8
  };
12
- export declare const usePublicAuthStrategiesPolicySettings: (loadOnMount?: boolean) => {
13
- loading: boolean;
14
- saving: boolean | undefined;
15
- error: any;
16
- policy: import("@frontegg/rest-api").IAuthStrategiesConfig | undefined;
9
+ export declare const usePublicAuthStrategiesPolicySettings: (loadOnMount?: boolean) => import("@frontegg/redux-store").WithStatus & {
10
+ policy?: import("@frontegg/rest-api").IAuthStrategiesConfig | undefined;
17
11
  };
@@ -1,50 +1,39 @@
1
- import { securityPolicyActions, securityPolicyReducers } from '@frontegg/redux-store';
2
- import { reducerActionsGenerator, stateHookGenerator } from '../hooks';
3
1
  import { useEffect } from 'react';
2
+ import { useStore } from '../../FronteggStoreContext';
3
+ import { useSnapshot } from '../../useSnapshot';
4
+
5
+ // TODO: remove useless stateMapper, valtio already does this
6
+
4
7
  const defaultMapper = state => state;
8
+ // @deprecated use useSecurityPolicyState() instead
5
9
  export function useSecurityPolicyState(stateMapper = defaultMapper) {
6
- return stateHookGenerator(stateMapper, 'securityPolicyState');
10
+ const state = useStore().store.auth.securityPolicyState;
11
+ return stateMapper(useSnapshot(state));
7
12
  }
8
- export const useSecurityPolicyActions = () => reducerActionsGenerator(securityPolicyActions, securityPolicyReducers);
13
+ export const useSecurityPolicyActions = () => {
14
+ return useStore().stateActions.auth.securityPolicyActions;
15
+ };
9
16
  export const usePublicPolicySettings = (loadOnMount = false) => {
10
17
  const {
11
- loading,
12
- policy,
13
- saving,
14
- error
15
- } = useSecurityPolicyState(state => state.publicPolicy);
18
+ publicPolicy
19
+ } = useSecurityPolicyState();
16
20
  const {
17
21
  loadPublicSecurityPolicy
18
22
  } = useSecurityPolicyActions();
19
23
  useEffect(() => {
20
- (loadOnMount || !policy) && loadPublicSecurityPolicy();
21
- // eslint-disable-next-line react-hooks/exhaustive-deps
24
+ (loadOnMount || !publicPolicy.policy) && loadPublicSecurityPolicy();
22
25
  }, [loadOnMount, loadPublicSecurityPolicy]);
23
- return {
24
- loading,
25
- saving,
26
- error,
27
- policy
28
- };
26
+ return publicPolicy;
29
27
  };
30
28
  export const usePublicAuthStrategiesPolicySettings = (loadOnMount = false) => {
31
29
  const {
32
- loading,
33
- policy,
34
- saving,
35
- error
36
- } = useSecurityPolicyState(state => state.publicAuthStrategyPolicy);
30
+ publicAuthStrategyPolicy
31
+ } = useSecurityPolicyState();
37
32
  const {
38
33
  loadPublicAuthStrategiesPolicy
39
34
  } = useSecurityPolicyActions();
40
35
  useEffect(() => {
41
- (loadOnMount || !policy) && loadPublicAuthStrategiesPolicy();
42
- // eslint-disable-next-line react-hooks/exhaustive-deps
36
+ (loadOnMount || !publicAuthStrategyPolicy.policy) && loadPublicAuthStrategiesPolicy();
43
37
  }, [loadOnMount, loadPublicAuthStrategiesPolicy]);
44
- return {
45
- loading,
46
- saving,
47
- error,
48
- policy
49
- };
38
+ return publicAuthStrategyPolicy;
50
39
  };
@@ -1,5 +1,3 @@
1
- import { SessionsPolicyState, SessionsPolicyActions } from '@frontegg/redux-store';
2
- export declare type SessionsPolicyStateMapper<S> = (state: SessionsPolicyState) => S;
1
+ import type { SessionsPolicyState, SessionsPolicyActions } from '@frontegg/redux-store';
3
2
  export declare function useSessionsPolicyState(): SessionsPolicyState;
4
- export declare function useSessionsPolicyState<S>(stateMapper: SessionsPolicyStateMapper<S>): S;
5
3
  export declare const useSessionsPolicyActions: () => SessionsPolicyActions;
@@ -1,7 +1,9 @@
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');
1
+ import { useStore } from '../../FronteggStoreContext';
2
+ import { useSnapshot } from '../../useSnapshot';
3
+ export function useSessionsPolicyState() {
4
+ const state = useStore().store.auth.sessionsPolicyState;
5
+ return useSnapshot(state);
6
6
  }
7
- export const useSessionsPolicyActions = () => reducerActionsGenerator(sessionsPolicyActions, sessionsPolicyReducers);
7
+ export const useSessionsPolicyActions = () => {
8
+ return useStore().stateActions.auth.sessionsPolicyActions;
9
+ };
@@ -1,5 +1,3 @@
1
- import { SessionsState, SessionsActions } from '@frontegg/redux-store';
2
- export declare type SessionsStateMapper<S> = (state: SessionsState) => S;
1
+ import type { SessionsState, SessionsActions } from '@frontegg/redux-store';
3
2
  export declare function useSessionsState(): SessionsState;
4
- export declare function useSessionsState<S>(stateMapper: SessionsStateMapper<S>): S;
5
3
  export declare const useSessionsActions: () => SessionsActions;
package/auth/sessions.js CHANGED
@@ -1,7 +1,8 @@
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');
1
+ import { useSnapshot } from '../useSnapshot';
2
+ import { useStore } from '../FronteggStoreContext';
3
+ export function useSessionsState() {
4
+ return useSnapshot(useStore().store.auth.sessionsState);
6
5
  }
7
- export const useSessionsActions = () => reducerActionsGenerator(sessionsActions, sessionsReducers);
6
+ export const useSessionsActions = () => {
7
+ return useStore().stateActions.auth.sessionsActions;
8
+ };
package/auth/signup.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { SignUpState, SignUpActions } from '@frontegg/redux-store';
1
+ import type { 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,7 +1,16 @@
1
- import { signUpReducers, signUpActions } from '@frontegg/redux-store';
2
- import { reducerActionsGenerator, stateHookGenerator } from './hooks';
1
+ import { useSnapshot } from '../useSnapshot';
2
+ import { useStore } from '../FronteggStoreContext';
3
+
4
+ // TODO: remove useless stateMapper, valtio already does this
5
+
3
6
  const defaultMapper = state => state;
7
+ // @deprecated use useSignUpState() instead
4
8
  export function useSignUpState(stateMapper = defaultMapper) {
5
- return stateHookGenerator(stateMapper, 'signUpState');
9
+ const {
10
+ signUpState
11
+ } = useStore().store.auth;
12
+ return stateMapper(useSnapshot(signUpState));
6
13
  }
7
- export const useSignUpActions = () => reducerActionsGenerator(signUpActions, signUpReducers);
14
+ export const useSignUpActions = () => {
15
+ return useStore().stateActions.auth.signUpActions;
16
+ };
package/auth/sms.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ import type { SmsActions, SmsState } from '@frontegg/redux-store';
2
+ export declare function useSmsState(): SmsState;
3
+ export declare const useSmsActions: () => SmsActions;
package/auth/sms.js ADDED
@@ -0,0 +1,8 @@
1
+ import { useStore } from '../FronteggStoreContext';
2
+ import { useSnapshot } from '../useSnapshot';
3
+ export function useSmsState() {
4
+ return useSnapshot(useStore().store.auth.smsState);
5
+ }
6
+ export const useSmsActions = () => {
7
+ return useStore().stateActions.auth.smsActions;
8
+ };
@@ -1,4 +1,4 @@
1
- import { SocialLoginActions, SocialLoginState } from '@frontegg/redux-store';
1
+ import type { 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,7 +1,13 @@
1
- import { socialLoginsActions, socialLoginsReducer } 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;
7
+ // @deprecated use useSocialLoginState() instead
4
8
  export function useSocialLoginState(stateMapper = defaultMapper) {
5
- return stateHookGenerator(stateMapper, 'socialLoginState');
9
+ return stateMapper(useSnapshot(useStore().store.auth.socialLoginState));
6
10
  }
7
- export const useSocialLoginActions = () => reducerActionsGenerator(socialLoginsActions, socialLoginsReducer);
11
+ export const useSocialLoginActions = () => {
12
+ return useStore().stateActions.auth.socialLoginActions;
13
+ };
package/auth/sso.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { SSOState, SSOActions } from '@frontegg/redux-store';
1
+ import type { 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,7 +1,13 @@
1
- import { ssoActions, ssoReducers } from '@frontegg/redux-store';
2
- import { reducerActionsGenerator, stateHookGenerator } from './hooks';
1
+ import { useSnapshot } from '../useSnapshot';
2
+ import { useStore } from '../FronteggStoreContext';
3
+
4
+ // TODO: remove useless stateMapper, valtio already does this
5
+
3
6
  const defaultMapper = state => state;
7
+ // @deprecated use useSSOState() instead
4
8
  export function useSSOState(stateMapper = defaultMapper) {
5
- return stateHookGenerator(stateMapper, 'ssoState');
9
+ return stateMapper(useSnapshot(useStore().store.auth.ssoState));
6
10
  }
7
- export const useSSOActions = () => reducerActionsGenerator(ssoActions, ssoReducers);
11
+ export const useSSOActions = () => {
12
+ return useStore().stateActions.auth.ssoActions;
13
+ };
@@ -0,0 +1,16 @@
1
+ import { StepUpState, StepUpActions, IsSteppedUpOptions } from '@frontegg/redux-store';
2
+ export declare function useStepUpState(): StepUpState;
3
+ export declare const useStepUpActions: () => StepUpActions;
4
+ /**
5
+ * @returns max age from the query param as a number or null if not exists
6
+ */
7
+ export declare const getMaxAgeFromQueryParam: () => number | undefined;
8
+ /**
9
+ * @returns step up function that redirects to the step up url with the max age param and set the redirect url in the local storage
10
+ */
11
+ export declare const useStepUp: () => any;
12
+ /**
13
+ * @param options.maxAge - max age of step up
14
+ * @returns true when the user is stepped up, false otherwise
15
+ */
16
+ export declare const useIsSteppedUp: (options?: IsSteppedUpOptions) => boolean;
package/auth/stepUp.js ADDED
@@ -0,0 +1,51 @@
1
+ import { STEP_UP_MAX_AGE_PARAM_NAME, getSearchParam, redirectByStepUpUrl, isSteppedUp } from '@frontegg/redux-store';
2
+ import { useSnapshot } from '../useSnapshot';
3
+ import { useStore } from '../FronteggStoreContext';
4
+ import { useAuth, useAuthRoutes, useAuthUserOrNull, useOnRedirectTo } from './hooks';
5
+ import { useCallback } from 'react';
6
+ export function useStepUpState() {
7
+ return useSnapshot(useStore().store.auth.stepUpState);
8
+ }
9
+ export const useStepUpActions = () => {
10
+ return useStore().stateActions.auth.stepUpActions;
11
+ };
12
+
13
+ /**
14
+ * @returns max age from the query param as a number or null if not exists
15
+ */
16
+ export const getMaxAgeFromQueryParam = () => {
17
+ const str = getSearchParam(STEP_UP_MAX_AGE_PARAM_NAME);
18
+ return str === undefined ? undefined : +str;
19
+ };
20
+
21
+ /**
22
+ * @returns step up function that redirects to the step up url with the max age param and set the redirect url in the local storage
23
+ */
24
+ export const useStepUp = () => {
25
+ const {
26
+ stepUpUrl
27
+ } = useAuthRoutes();
28
+ const {
29
+ hostedLoginBox
30
+ } = useAuth();
31
+ const {
32
+ stepUpHostedLogin
33
+ } = useStepUpActions();
34
+ const onRedirectTo = useOnRedirectTo();
35
+ return useCallback(options => {
36
+ if (hostedLoginBox) {
37
+ stepUpHostedLogin(options || {});
38
+ return;
39
+ }
40
+ redirectByStepUpUrl(stepUpUrl, onRedirectTo, options == null ? void 0 : options.maxAge);
41
+ }, [stepUpUrl, onRedirectTo, stepUpHostedLogin, hostedLoginBox]);
42
+ };
43
+
44
+ /**
45
+ * @param options.maxAge - max age of step up
46
+ * @returns true when the user is stepped up, false otherwise
47
+ */
48
+ export const useIsSteppedUp = (options = {}) => {
49
+ const user = useAuthUserOrNull();
50
+ return isSteppedUp(user, options);
51
+ };
package/auth/team.d.ts CHANGED
@@ -1,5 +1,13 @@
1
- import { TeamState, TeamActions } from '@frontegg/redux-store';
1
+ import { TeamActions, TeamState } from '@frontegg/redux-store';
2
+ export declare function useTeamState(): TeamState;
3
+ export declare const useTeamActions: () => TeamActions;
2
4
  export declare type AuthTeamStateMapper<S> = (state: TeamState) => S;
5
+ /**
6
+ * @deprecated use useTeamState instead
7
+ */
3
8
  export declare function useAuthTeamState(): TeamState;
4
9
  export declare function useAuthTeamState<S>(stateMapper: AuthTeamStateMapper<S>): S;
10
+ /**
11
+ * @deprecated use useTeamActions instead
12
+ */
5
13
  export declare const useAuthTeamActions: () => TeamActions;