@frontegg/redux-store 6.117.0-alpha.1 → 6.118.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 (38) hide show
  1. package/auth/EntitlementsState/index.js +2 -1
  2. package/auth/EntitlementsState/interfaces.d.ts +14 -3
  3. package/auth/EntitlementsState/saga.d.ts +4 -3
  4. package/auth/EntitlementsState/saga.js +15 -3
  5. package/auth/EntitlementsState/utils.d.ts +24 -6
  6. package/auth/EntitlementsState/utils.js +73 -6
  7. package/auth/GroupsState/index.d.ts +1 -1
  8. package/auth/GroupsState/interfaces.d.ts +3 -2
  9. package/auth/GroupsState/saga.js +5 -4
  10. package/auth/LoginState/interfaces.d.ts +1 -0
  11. package/auth/LoginState/interfaces.js +2 -1
  12. package/auth/LoginState/saga.d.ts +2 -2
  13. package/auth/LoginState/saga.js +10 -6
  14. package/auth/MSP/AllAccountsState/index.js +1 -2
  15. package/auth/MSP/AllAccountsState/saga.js +0 -32
  16. package/auth/TeamState/index.d.ts +8 -3
  17. package/auth/TeamState/index.js +3 -0
  18. package/auth/TeamState/interfaces.d.ts +5 -3
  19. package/auth/TeamState/saga.js +79 -14
  20. package/auth/index.d.ts +3 -2
  21. package/auth/reducer.d.ts +3 -2
  22. package/index.d.ts +1 -0
  23. package/index.js +1 -1
  24. package/node/auth/EntitlementsState/index.js +2 -1
  25. package/node/auth/EntitlementsState/saga.js +15 -2
  26. package/node/auth/EntitlementsState/utils.js +76 -7
  27. package/node/auth/GroupsState/saga.js +5 -4
  28. package/node/auth/LoginState/interfaces.js +4 -1
  29. package/node/auth/LoginState/saga.js +10 -6
  30. package/node/auth/MSP/AllAccountsState/index.js +1 -2
  31. package/node/auth/MSP/AllAccountsState/saga.js +0 -32
  32. package/node/auth/TeamState/index.js +3 -0
  33. package/node/auth/TeamState/saga.js +79 -14
  34. package/node/index.js +1 -1
  35. package/node/toolkit/index.js +5 -2
  36. package/package.json +3 -2
  37. package/toolkit/index.d.ts +2 -1
  38. package/toolkit/index.js +5 -2
@@ -4,7 +4,8 @@ import { authStoreName } from '../../constants';
4
4
  const entitlementsState = {
5
5
  entitlements: undefined,
6
6
  loading: false,
7
- error: undefined
7
+ error: undefined,
8
+ options: undefined
8
9
  };
9
10
  const reducers = {
10
11
  setEntitlementsState: typeReducerForKey('entitlementsState')
@@ -1,9 +1,20 @@
1
1
  import { WithStatus } from '../../interfaces';
2
- import { EntitlementsResponse } from '@frontegg/rest-api';
2
+ import { UserEntitlementsResponse, NotEntitledReason } from '@frontegg/rest-api';
3
3
  export declare type EntitlementsState = WithStatus & {
4
- entitlements: EntitlementsResponse | undefined;
4
+ entitlements: UserEntitlementsResponse | undefined;
5
+ options?: EntitlementsOptions | undefined;
5
6
  };
7
+ export interface EntitlementsOptions {
8
+ enabled: boolean;
9
+ }
6
10
  export interface Entitlement {
7
11
  isEntitled: boolean;
12
+ justification?: NotEntitledReason;
13
+ }
14
+ export declare type EntitledToOptions = EntitledToFeature | EntitledToPermission;
15
+ export interface EntitledToFeature {
16
+ featureKey: string;
17
+ }
18
+ export interface EntitledToPermission {
19
+ permissionKey: string;
8
20
  }
9
- export declare type Entitlements = Entitlement[];
@@ -1,9 +1,10 @@
1
- import { EntitlementsResponse } from '@frontegg/rest-api';
1
+ import { UserEntitlementsResponse } from '@frontegg/rest-api';
2
2
  /**
3
3
  Load entitlements list
4
+ Don't update entitlements data in the store when data is equal (deep check)
4
5
  */
5
- export declare function loadEntitlements(): Generator<import("redux-saga/effects").PutEffect<{
6
+ export declare function loadEntitlements(): Generator<import("redux-saga/effects").SelectEffect | import("redux-saga/effects").PutEffect<{
6
7
  payload: Partial<import("./interfaces").EntitlementsState>;
7
8
  type: string;
8
- }> | import("redux-saga/effects").CallEffect<EntitlementsResponse>, void, EntitlementsResponse>;
9
+ }> | import("redux-saga/effects").CallEffect<UserEntitlementsResponse>, void, UserEntitlementsResponse>;
9
10
  export declare function entitlementsSagas(): Generator<import("redux-saga/effects").ForkEffect<never>, void, unknown>;
@@ -1,9 +1,11 @@
1
- import { call, put, takeLeading } from 'redux-saga/effects';
1
+ import isEqual from 'fast-deep-equal';
2
+ import { call, put, takeLeading, select } from 'redux-saga/effects';
2
3
  import { api } from '@frontegg/rest-api';
3
4
  import { actions } from '../reducer';
4
5
 
5
6
  /**
6
7
  Load entitlements list
8
+ Don't update entitlements data in the store when data is equal (deep check)
7
9
  */
8
10
  export function* loadEntitlements() {
9
11
  yield put(actions.setEntitlementsState({
@@ -11,9 +13,19 @@ export function* loadEntitlements() {
11
13
  error: null
12
14
  }));
13
15
  try {
14
- const entitlements = yield call(api.entitlements.loadEntitlements);
16
+ const newEntitlements = yield call(api.entitlements.loadEntitlements);
17
+ const oldEntitlements = yield select(state => {
18
+ var _state$auth$entitleme;
19
+ return (_state$auth$entitleme = state.auth.entitlementsState) == null ? void 0 : _state$auth$entitleme.entitlements;
20
+ });
21
+ if (isEqual(oldEntitlements, newEntitlements)) {
22
+ yield put(actions.setEntitlementsState({
23
+ loading: false
24
+ }));
25
+ return;
26
+ }
15
27
  yield put(actions.setEntitlementsState({
16
- entitlements,
28
+ entitlements: newEntitlements,
17
29
  loading: false
18
30
  }));
19
31
  } catch (e) {
@@ -1,8 +1,26 @@
1
- import { EntitlementsResponse } from '@frontegg/rest-api';
2
- import { Entitlements } from './interfaces';
1
+ import { UserEntitlementsResponse } from '@frontegg/rest-api';
2
+ import { EntitlementsOptions, EntitledToOptions, Entitlement } from './interfaces';
3
3
  /**
4
- @param entitlementsByKey
5
- @param keys The requested entitlement keys
6
- @returns Entitlements contain true/false for every key (state of is key entitled)
4
+ @param entitlements
5
+ @param key
6
+ @param entitlementsVendorConfig entitlements frontegg provider configuration
7
+ @returns if the user is entitled to the given permission. Attaching the justification if not
8
+ @throws when entitlement is not enabled via frontegg options
7
9
  */
8
- export declare const getEntitlements: (entitlementsByKey: EntitlementsResponse | undefined, keys: string[]) => Entitlements;
10
+ export declare const getPermissionEntitlements: (entitlements: UserEntitlementsResponse | undefined, key: string, entitlementsVendorConfig: EntitlementsOptions | undefined) => Entitlement;
11
+ /**
12
+ @param entitlements
13
+ @param key
14
+ @param entitlementsVendorConfig entitlements frontegg provider configuration
15
+ @returns if the user is entitled to the given feature. Attaching the justification if not
16
+ @throws when entitlement is not enabled via frontegg options
17
+ */
18
+ export declare const getFeatureEntitlements: (entitlements: UserEntitlementsResponse | undefined, key: string, entitlementsVendorConfig: EntitlementsOptions | undefined) => Entitlement;
19
+ /**
20
+ @param entitlements
21
+ @param entitledToOptions including permission or feature
22
+ @param entitlementsVendorConfig entitlements frontegg provider configuration
23
+ @returns if the user is entitled to the given feature or permission (check only one). Attaching the justification if not
24
+ @throws when entitlement is not enabled via frontegg options
25
+ */
26
+ export declare const getEntitlements: (entitlements: UserEntitlementsResponse | undefined, options: EntitledToOptions, entitlementsVendorConfig: EntitlementsOptions | undefined) => Entitlement;
@@ -1,8 +1,75 @@
1
+ import { NotEntitledReason } from '@frontegg/rest-api';
2
+ const ENTITLEMENTS_NOT_ENABLED_EXCEPTION_TEXT = 'You must first enable entitlements via Frontegg options to use this function';
3
+
1
4
  /**
2
- @param entitlementsByKey
3
- @param keys The requested entitlement keys
4
- @returns Entitlements contain true/false for every key (state of is key entitled)
5
+ * Guard entitlements feature by checking if it is enabled by the vendor
6
+ * @throws when entitlement is not enabled via frontegg options
5
7
  */
6
- export const getEntitlements = (entitlementsByKey = {}, keys) => keys.reduce((result, key) => [...result, {
7
- isEntitled: entitlementsByKey[key] || false
8
- }], []);
8
+ const guardEntitlementsUsage = entitlementsOptions => {
9
+ if (entitlementsOptions != null && entitlementsOptions.enabled) return;
10
+ throw new Error(ENTITLEMENTS_NOT_ENABLED_EXCEPTION_TEXT);
11
+ };
12
+
13
+ /**
14
+ @param keyEntitlements permission or feature data object
15
+ @param entitlementsVendorConfig entitlements frontegg provider configuration
16
+ @param missingKeyEnum missing key for scenario that the key does not exist in entitlementsValuePerKeys
17
+ @returns if the user is entitled to the given key. Attaching the justification if not
18
+ @throws when entitlement is not enabled via frontegg options
19
+ */
20
+ const getEntitlementsHelper = (keyEntitlements, entitlementsVendorConfig, missingKeyEnum) => {
21
+ guardEntitlementsUsage(entitlementsVendorConfig);
22
+ if (!keyEntitlements) {
23
+ return {
24
+ isEntitled: false,
25
+ justification: missingKeyEnum
26
+ };
27
+ }
28
+ if (keyEntitlements.isEntitled) {
29
+ return {
30
+ isEntitled: true
31
+ };
32
+ }
33
+ return {
34
+ isEntitled: false,
35
+ justification: keyEntitlements.notEntitledReason
36
+ };
37
+ };
38
+
39
+ /**
40
+ @param entitlements
41
+ @param key
42
+ @param entitlementsVendorConfig entitlements frontegg provider configuration
43
+ @returns if the user is entitled to the given permission. Attaching the justification if not
44
+ @throws when entitlement is not enabled via frontegg options
45
+ */
46
+ export const getPermissionEntitlements = (entitlements, key, entitlementsVendorConfig) => {
47
+ var _entitlements$permiss;
48
+ return getEntitlementsHelper(entitlements == null ? void 0 : (_entitlements$permiss = entitlements.permissions) == null ? void 0 : _entitlements$permiss[key], entitlementsVendorConfig, NotEntitledReason.MISSING_PERMISSION);
49
+ };
50
+
51
+ /**
52
+ @param entitlements
53
+ @param key
54
+ @param entitlementsVendorConfig entitlements frontegg provider configuration
55
+ @returns if the user is entitled to the given feature. Attaching the justification if not
56
+ @throws when entitlement is not enabled via frontegg options
57
+ */
58
+ export const getFeatureEntitlements = (entitlements, key, entitlementsVendorConfig) => {
59
+ var _entitlements$feature;
60
+ return getEntitlementsHelper(entitlements == null ? void 0 : (_entitlements$feature = entitlements.features) == null ? void 0 : _entitlements$feature[key], entitlementsVendorConfig, NotEntitledReason.MISSING_FEATURE);
61
+ };
62
+
63
+ /**
64
+ @param entitlements
65
+ @param entitledToOptions including permission or feature
66
+ @param entitlementsVendorConfig entitlements frontegg provider configuration
67
+ @returns if the user is entitled to the given feature or permission (check only one). Attaching the justification if not
68
+ @throws when entitlement is not enabled via frontegg options
69
+ */
70
+ export const getEntitlements = (entitlements, options, entitlementsVendorConfig) => {
71
+ if ('permissionKey' in options) {
72
+ return getPermissionEntitlements(entitlements, options.permissionKey, entitlementsVendorConfig);
73
+ }
74
+ return getFeatureEntitlements(entitlements, options.featureKey, entitlementsVendorConfig);
75
+ };
@@ -154,7 +154,7 @@ declare const actions: {
154
154
  }], import("@frontegg/rest-api").IUpdateGroupConfig & {
155
155
  groupId: string;
156
156
  }, string, never, never>;
157
- getTeamUsers: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[import("@frontegg/rest-api").ILoadUsers], import("@frontegg/rest-api").ILoadUsers, string, never, never>;
157
+ getTeamUsers: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[import("..").IGetUsersV2Payload], import("..").IGetUsersV2Payload, string, never, never>;
158
158
  };
159
159
  declare type DispatchedActions = {
160
160
  setUsersGroupsLoader: (payload: GroupsStateIndicator) => void;
@@ -1,6 +1,7 @@
1
1
  import { LoaderIndicatorState, WithCallback } from '../../interfaces';
2
2
  import { IGroupConfigResponse, IGroupResponse, IGetGroup, ICreateGroup, IUpdateGroup, IUpdateGroupRoles, IUpdateGroupUsers, IUpdateGroupConfig, IGroupUser } from '@frontegg/rest-api';
3
- import { ILoadUsers, ITeamUser } from '@frontegg/rest-api';
3
+ import { ITeamUser } from '@frontegg/rest-api';
4
+ import { IGetUsersV2Payload } from '../TeamState/interfaces';
4
5
  export declare enum GroupsStateKeys {
5
6
  CREATE_GROUP = "CREATE_GROUP",
6
7
  GET_GROUP = "GET_GROUP",
@@ -54,7 +55,7 @@ export interface IGroupsStateActionsPayloads {
54
55
  updateGroupConfiguration: IUpdateGroupConfig & {
55
56
  groupId: string;
56
57
  };
57
- getTeamUsers: ILoadUsers;
58
+ getTeamUsers: IGetUsersV2Payload;
58
59
  }
59
60
  export interface IGroupsStateActions {
60
61
  loadGroups: () => void;
@@ -20,10 +20,11 @@ function* getTeamUsers({
20
20
  try {
21
21
  const {
22
22
  items: users
23
- } = yield call(api.teams.loadUsers, {
24
- filter: payload.filter,
25
- pageOffset: payload.pageOffset,
26
- pageSize: payload.pageSize
23
+ } = yield call(api.users.getUsersV2, {
24
+ _filter: payload.filter,
25
+ _offset: payload.pageOffset,
26
+ _limit: payload.pageSize,
27
+ _includeSubTenants: false
27
28
  });
28
29
  yield put(actions.setGroupsState({
29
30
  teamUsers: users
@@ -94,3 +94,4 @@ export declare type IVerifyMFAWebAuthnPayload = WithCallback<WithDeviceId<Omit<I
94
94
  export interface IRecoverMFATokenPayload extends WithCallback<IRecoverMFAToken> {
95
95
  recaptchaToken?: string;
96
96
  }
97
+ export declare const ADMIN_PORTAL_ENTITLEMENTS_FF = "admin_portal_entitlements";
@@ -29,4 +29,5 @@ export let QuickLoginStrategy;
29
29
  QuickLoginStrategy["Android"] = "android";
30
30
  QuickLoginStrategy["Sms"] = "sms";
31
31
  })(QuickLoginStrategy || (QuickLoginStrategy = {}));
32
- export { AuthStrategyEnum };
32
+ export { AuthStrategyEnum };
33
+ export const ADMIN_PORTAL_ENTITLEMENTS_FF = 'admin_portal_entitlements';
@@ -51,8 +51,8 @@ export declare function getMfaRequiredState(user: any): Generator<import("redux-
51
51
  isAllowedToRemember: any;
52
52
  mfaDeviceExpiration: any;
53
53
  }>;
54
- export declare function refreshToken(): Generator<import("redux-saga/effects").SelectEffect | Generator<import("redux-saga/effects").SelectEffect | CallEffect<boolean[]> | CallEffect<void>, void, AuthState & boolean[]> | CallEffect<any>, void, AuthState>;
55
- export declare function refreshTokenForSocialLogins(): Generator<import("redux-saga/effects").SelectEffect | Generator<import("redux-saga/effects").SelectEffect | CallEffect<boolean[]> | CallEffect<void>, void, AuthState & boolean[]> | CallEffect<any>, void, AuthState>;
54
+ export declare function refreshToken(): Generator<import("redux-saga/effects").SelectEffect | Generator<import("redux-saga/effects").SelectEffect | CallEffect<boolean[]> | CallEffect<void>, void, (false & boolean[]) | (true & boolean[])> | CallEffect<any>, void, AuthState>;
55
+ export declare function refreshTokenForSocialLogins(): Generator<import("redux-saga/effects").SelectEffect | Generator<import("redux-saga/effects").SelectEffect | CallEffect<boolean[]> | CallEffect<void>, void, (false & boolean[]) | (true & boolean[])> | CallEffect<any>, void, AuthState>;
56
56
  export declare function shouldShowPromptPasskeys(): Generator<import("redux-saga/effects").SelectEffect | CallEffect<boolean[]> | CallEffect<IWebAuthnDevices> | import("redux-saga/effects").PutEffect<{
57
57
  payload: Partial<import("../..").PasskeysState>;
58
58
  type: string;
@@ -25,7 +25,7 @@ import { api, AuthStrategyEnum, ContextHolder, fetch, MFAStrategyEnum, WebAuthnD
25
25
  import { actions } from '../reducer';
26
26
  import { FRONTEGG_AFTER_AUTH_REDIRECT_URL, HOSTED_LOGIN_VERIFIER_KEY } from '../../constants';
27
27
  import { UserVeirifedOriginTypes } from '../interfaces';
28
- import { LoginFlow, LoginStep } from './interfaces';
28
+ import { LoginFlow, LoginStep, ADMIN_PORTAL_ENTITLEMENTS_FF } from './interfaces';
29
29
  import { loadAllowSignUps } from '../SignUp/saga';
30
30
  import { MFAStep } from '../MfaState/interfaces';
31
31
  import { dummyIps, userDemo } from '../dummy';
@@ -46,7 +46,6 @@ const authStrategyLoginStepMap = {
46
46
  [AuthStrategyEnum.MagicLink]: LoginStep.magicLinkPreLoginSuccess,
47
47
  [AuthStrategyEnum.SmsCode]: LoginStep.loginWithSmsOtc
48
48
  };
49
- const ADMIN_PORTAL_ENTITLEMENTS_FF = 'admin_portal_entitlements';
50
49
  export function* afterAuthNavigation() {
51
50
  const onRedirectTo = ContextHolder.onRedirectTo;
52
51
  const {
@@ -232,10 +231,15 @@ function* shouldNevigateToRegisterQuickLogin(user) {
232
231
  return quickLoginToRegister && localStorage.getItem(`${user.id}-${quickLoginToRegister}`) !== 'true' && !window.location.pathname.endsWith(routes.logoutUrl);
233
232
  }
234
233
  function* handleLoadEntitlements() {
235
- const {
236
- user
237
- } = yield select(state => state.auth);
238
- if (!user) {
234
+ const isAuthenticated = yield select(state => {
235
+ var _state$auth;
236
+ return (_state$auth = state.auth) == null ? void 0 : _state$auth.isAuthenticated;
237
+ });
238
+ const isEntitlementsEnabledByUser = yield select(state => {
239
+ var _state$auth2, _state$auth2$entitlem, _state$auth2$entitlem2;
240
+ return (_state$auth2 = state.auth) == null ? void 0 : (_state$auth2$entitlem = _state$auth2.entitlementsState) == null ? void 0 : (_state$auth2$entitlem2 = _state$auth2$entitlem.options) == null ? void 0 : _state$auth2$entitlem2.enabled;
241
+ });
242
+ if (!isAuthenticated || !isEntitlementsEnabledByUser) {
239
243
  return;
240
244
  }
241
245
  const [isEntitlementsFFOn] = yield call(getFeatureFlags, [ADMIN_PORTAL_ENTITLEMENTS_FF]);
@@ -36,8 +36,7 @@ export const allAccountsInitialState = {
36
36
  },
37
37
  usersPageOffset: 0,
38
38
  accountSettings: {}
39
- },
40
- teamUsers: []
39
+ }
41
40
  };
42
41
  const reducers = {
43
42
  setAllAccountsLoader: loadersReducerForKey('allAccountsState'),
@@ -12,37 +12,6 @@ import { getAccountsWithUsersCount } from './utils/getAccountsWithUsersCount';
12
12
  export const selectUserState = () => sagaSelect(_ => _[authStoreName].user);
13
13
  export const selectTenantsState = () => sagaSelect(_ => _[authStoreName].tenantsState);
14
14
  export const selectAllAccountsState = () => sagaSelect(_ => _[authStoreName].allAccountsState);
15
- function* getTeamUsers({
16
- payload
17
- }) {
18
- const key = AllAccountsStateKeys.GET_TEAM_USERS;
19
- yield put(actions.setAllAccountsLoader({
20
- key,
21
- value: true
22
- }));
23
- try {
24
- const {
25
- items: users
26
- } = yield call(api.teams.loadUsers, {
27
- filter: payload.filter,
28
- pageOffset: payload.pageOffset,
29
- pageSize: payload.pageSize
30
- });
31
- yield put(actions.setAllAccountsState({
32
- teamUsers: users
33
- }));
34
- } catch (e) {
35
- yield put(actions.setAllAccountsError({
36
- key,
37
- value: errorHandler(e)
38
- }));
39
- } finally {
40
- yield put(actions.setAllAccountsLoader({
41
- key,
42
- value: false
43
- }));
44
- }
45
- }
46
15
  function* loadAccounts({
47
16
  payload
48
17
  }) {
@@ -773,7 +742,6 @@ export function* allAccountsSagas() {
773
742
  yield takeLatest(actions.addUsersToAccount, addUsersToAccount);
774
743
  yield takeLatest(actions.deleteUsersFromAccount, deleteUserFromAccount);
775
744
  yield takeLatest(actions.setUserRolesForSubAccount, setUserRolesForSubAccount);
776
- yield takeLatest(actions.getTeamUsers, getTeamUsers);
777
745
  yield takeLatest(actions.getAccountUsers, getAccountUsers);
778
746
  yield takeLatest(actions.setSelectedSubAccountData, setSelectedSubAccountData);
779
747
  }
@@ -1,4 +1,4 @@
1
- import { IAddUser, IDeleteUser, IResendActivationLink, IResendInvitationLink, IResendInvitationEmail, ITeamUser, IUpdateUser, ICreateOrUpdateInviteUserLink, ILoadAllUsers, ISubTenantUser, AddUserToSubTenantsRequest, RemoveUserFromSubTenantsRequest, UpdateUserRolesForSubTenantsRequestDto } from '@frontegg/rest-api';
1
+ import { IAddUser, IDeleteUser, IResendActivationLink, IResendInvitationLink, IResendInvitationEmail, ITeamUser, IUpdateUser, ICreateOrUpdateInviteUserLink, ILoadAllUsers, ISubTenantUser, AddUserToSubTenantsRequest, RemoveUserFromSubTenantsRequest, UpdateUserRolesForSubTenantsRequestDto, ILoadUsers } from '@frontegg/rest-api';
2
2
  import { ISetAddUserDialog, ISetDeleteUserDialog, TeamState, TeamStateIndicator, LoadRolesAndPermissionsPayload, IAddUsers, BulkInvintationData, IGetUsersV2Payload } from './interfaces';
3
3
  import { WithCallback, WithSilentLoad } from '../../interfaces';
4
4
  declare const teamState: TeamState;
@@ -121,7 +121,8 @@ declare const reducers: {
121
121
  };
122
122
  };
123
123
  declare const actions: {
124
- loadUsers: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[WithCallback<WithSilentLoad<IGetUsersV2Payload>, ITeamUser[]>], WithCallback<WithSilentLoad<IGetUsersV2Payload>, ITeamUser[]>, string, never, never>;
124
+ loadUsersV2: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[WithCallback<WithSilentLoad<IGetUsersV2Payload>, ITeamUser[]>], WithCallback<WithSilentLoad<IGetUsersV2Payload>, ITeamUser[]>, string, never, never>;
125
+ loadUsers: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[WithCallback<WithSilentLoad<ILoadUsers>, ITeamUser[]>], WithCallback<WithSilentLoad<ILoadUsers>, ITeamUser[]>, string, never, never>;
125
126
  loadAllSubTenantsUsers: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[WithCallback<WithSilentLoad<Partial<ILoadAllUsers>>, ISubTenantUser[]>], WithCallback<WithSilentLoad<Partial<ILoadAllUsers>>, ISubTenantUser[]>, string, never, never>;
126
127
  loadRoles: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[({
127
128
  callback?: import("../../interfaces").CallbackMethod<{
@@ -174,7 +175,11 @@ declare type DispatchedActions = {
174
175
  setTeamError: (payload: TeamStateIndicator) => void;
175
176
  setTeamState: (payload: Partial<TeamState>) => void;
176
177
  resetTeamState: () => void;
177
- loadUsers: (payload: WithCallback<WithSilentLoad<IGetUsersV2Payload>, ITeamUser[]>) => void;
178
+ loadUsersV2: (payload: WithCallback<WithSilentLoad<IGetUsersV2Payload>, ITeamUser[]>) => void;
179
+ /**
180
+ * @deprecated loadUsers is deprecated, use loadUsersV2 instead
181
+ */
182
+ loadUsers: (payload: WithCallback<WithSilentLoad<ILoadUsers>, ITeamUser[]>) => void;
178
183
  loadAllSubTenantsUsers: (payload: WithCallback<WithSilentLoad<Partial<ILoadAllUsers>>, ISubTenantUser[]>) => void;
179
184
  loadRoles: (payload?: LoadRolesAndPermissionsPayload) => void;
180
185
  addUsersBulk: (payload: WithCallback<IAddUsers, BulkInvintationData>) => void;
@@ -41,6 +41,9 @@ const reducers = {
41
41
  })
42
42
  };
43
43
  const actions = {
44
+ loadUsersV2: createAction(`${authStoreName}/loadUsersV2`, payload => ({
45
+ payload
46
+ })),
44
47
  loadUsers: createAction(`${authStoreName}/loadUsers`, payload => ({
45
48
  payload
46
49
  })),
@@ -1,4 +1,4 @@
1
- import { ITeamUserRole, ITeamUser, ITeamUserPermission, ISubTenantUser, SortByEnum, ISearchUserQueryParamsV2 } from '@frontegg/rest-api';
1
+ import { ITeamUserRole, ITeamUser, ITeamUserPermission, ISubTenantUser, SortByEnum, ISearchUserQueryParamsV2, QueryFilter, QuerySort } from '@frontegg/rest-api';
2
2
  import { GroupsState } from '../GroupsState/interfaces';
3
3
  import { LoaderIndicatorState, WithCallback } from '../../interfaces';
4
4
  export declare enum TeamStateKeys {
@@ -59,8 +59,10 @@ export interface TeamState {
59
59
  totalPages: number;
60
60
  roles: ITeamUserRole[];
61
61
  permissions: ITeamUserPermission[];
62
- filter?: string;
63
- sort?: SortByEnum;
62
+ filter?: QueryFilter[];
63
+ sort?: QuerySort[];
64
+ filterV2?: string;
65
+ sortV2?: SortByEnum;
64
66
  totalItems?: number;
65
67
  addedThisWeek?: number;
66
68
  shouldShowSubTenantUsersIfReseller?: boolean;
@@ -45,7 +45,7 @@ function* getGroupsForUsers() {
45
45
  }
46
46
 
47
47
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
48
- function* loadUsers({
48
+ function* loadUsersV2({
49
49
  payload
50
50
  }) {
51
51
  var _payload$pageSize, _payload$pageOffset, _payload$filter, _payload$sort, _payload$shouldShowSu;
@@ -56,8 +56,8 @@ function* loadUsers({
56
56
  const teamState = yield selectTeamState();
57
57
  const pageSize = (_payload$pageSize = payload.pageSize) != null ? _payload$pageSize : teamState.pageSize;
58
58
  const pageOffset = (_payload$pageOffset = payload.pageOffset) != null ? _payload$pageOffset : teamState.pageOffset;
59
- const filter = (_payload$filter = payload.filter) != null ? _payload$filter : teamState.filter;
60
- const sort = (_payload$sort = payload.sort) != null ? _payload$sort : teamState.sort;
59
+ const filter = (_payload$filter = payload.filter) != null ? _payload$filter : teamState.filterV2;
60
+ const sort = (_payload$sort = payload.sort) != null ? _payload$sort : teamState.sortV2;
61
61
  const shouldIncludeSubTenants = (_payload$shouldShowSu = payload == null ? void 0 : payload.shouldShowSubTenantUsersIfReseller) != null ? _payload$shouldShowSu : teamState == null ? void 0 : teamState.shouldShowSubTenantUsersIfReseller;
62
62
  yield put(actions.setTeamLoader({
63
63
  key: TeamStateKeys.USERS,
@@ -66,8 +66,8 @@ function* loadUsers({
66
66
  yield put(actions.setTeamState({
67
67
  pageSize,
68
68
  pageOffset,
69
- filter,
70
- sort
69
+ filterV2: filter,
70
+ sortV2: sort
71
71
  }));
72
72
  try {
73
73
  const [{
@@ -127,6 +127,70 @@ function* loadUsers({
127
127
  }));
128
128
  }
129
129
 
130
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
131
+ function* loadUsers({
132
+ payload
133
+ }) {
134
+ var _payload$pageSize2, _payload$pageOffset2, _payload$filter2, _payload$sort2;
135
+ const {
136
+ silentLoading,
137
+ callback
138
+ } = payload;
139
+ const teamState = yield selectTeamState();
140
+ const pageSize = (_payload$pageSize2 = payload.pageSize) != null ? _payload$pageSize2 : teamState.pageSize;
141
+ const pageOffset = (_payload$pageOffset2 = payload.pageOffset) != null ? _payload$pageOffset2 : teamState.pageOffset;
142
+ const filter = (_payload$filter2 = payload.filter) != null ? _payload$filter2 : teamState.filter;
143
+ const sort = (_payload$sort2 = payload.sort) != null ? _payload$sort2 : teamState.sort;
144
+ yield put(actions.setTeamLoader({
145
+ key: TeamStateKeys.USERS,
146
+ value: !silentLoading
147
+ }));
148
+ yield put(actions.setTeamState({
149
+ pageSize,
150
+ pageOffset,
151
+ filter: filter,
152
+ sort: sort
153
+ }));
154
+ try {
155
+ const [{
156
+ items: users,
157
+ totalPages,
158
+ totalItems
159
+ }, {
160
+ items: roles
161
+ }, {
162
+ items: permissions
163
+ }] = yield all([call(api.teams.loadUsers, {
164
+ pageSize,
165
+ pageOffset,
166
+ filter,
167
+ sort
168
+ }), call(api.teams.loadAvailableRoles), call(api.teams.loadAvailablePermissions)]);
169
+ yield put(actions.setTeamState({
170
+ users,
171
+ totalPages,
172
+ totalItems,
173
+ roles,
174
+ permissions
175
+ }));
176
+ callback == null ? void 0 : callback(users);
177
+ } catch (e) {
178
+ yield put(actions.setTeamError({
179
+ key: TeamStateKeys.USERS,
180
+ value: e.message
181
+ }));
182
+ yield put(actions.setTeamState({
183
+ totalPages: 0,
184
+ users: []
185
+ }));
186
+ callback == null ? void 0 : callback(null, e);
187
+ }
188
+ yield put(actions.setTeamLoader({
189
+ key: TeamStateKeys.USERS,
190
+ value: false
191
+ }));
192
+ }
193
+
130
194
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
131
195
  function* loadAllSubTenantsUsers({
132
196
  payload
@@ -308,7 +372,7 @@ function* addUsersBulk({
308
372
  filter: '',
309
373
  silentLoading: payload.emails.length > 0
310
374
  };
311
- yield put(actions.loadUsers(queryObject));
375
+ yield put(actions.loadUsersV2(queryObject));
312
376
  yield put(actions.setTeamState({
313
377
  addUserDialogState: {
314
378
  loading: false
@@ -839,6 +903,7 @@ function* closeDeleteUserDialog({
839
903
  }
840
904
  export function* teamSagas() {
841
905
  yield takeLatest(actions.loadUsers, loadUsers);
906
+ yield takeLatest(actions.loadUsersV2, loadUsersV2);
842
907
  yield takeLatest(actions.loadAllSubTenantsUsers, loadAllSubTenantsUsers);
843
908
  yield takeLatest(actions.loadRoles, loadRoles);
844
909
  yield takeEvery(actions.addUser, addUser);
@@ -869,16 +934,16 @@ export function* teamSagas() {
869
934
  function* loadUsersMock({
870
935
  payload
871
936
  }) {
872
- var _payload$pageSize2, _payload$pageOffset2, _payload$filter2, _payload$sort2;
937
+ var _payload$pageSize3, _payload$pageOffset3, _payload$filter3, _payload$sort3;
873
938
  const {
874
939
  silentLoading,
875
940
  callback
876
941
  } = payload;
877
942
  const teamState = yield selectTeamState();
878
- const pageSize = (_payload$pageSize2 = payload.pageSize) != null ? _payload$pageSize2 : teamState.pageSize;
879
- const pageOffset = (_payload$pageOffset2 = payload.pageOffset) != null ? _payload$pageOffset2 : teamState.pageOffset;
880
- const filter = (_payload$filter2 = payload.filter) != null ? _payload$filter2 : teamState.filter;
881
- const sort = (_payload$sort2 = payload.sort) != null ? _payload$sort2 : teamState.sort;
943
+ const pageSize = (_payload$pageSize3 = payload.pageSize) != null ? _payload$pageSize3 : teamState.pageSize;
944
+ const pageOffset = (_payload$pageOffset3 = payload.pageOffset) != null ? _payload$pageOffset3 : teamState.pageOffset;
945
+ const filter = (_payload$filter3 = payload.filter) != null ? _payload$filter3 : teamState.filterV2;
946
+ const sort = (_payload$sort3 = payload.sort) != null ? _payload$sort3 : teamState.sortV2;
882
947
  yield put(actions.setTeamLoader({
883
948
  key: TeamStateKeys.USERS,
884
949
  value: !silentLoading
@@ -886,8 +951,8 @@ function* loadUsersMock({
886
951
  yield put(actions.setTeamState({
887
952
  pageSize,
888
953
  pageOffset,
889
- filter,
890
- sort
954
+ filterV2: filter,
955
+ sortV2: sort
891
956
  }));
892
957
  const totalPages = 2;
893
958
  const totalItems = 10;
@@ -1194,7 +1259,7 @@ function* resendInvitationLinkToAllSubTenantsMock({
1194
1259
  }));
1195
1260
  }
1196
1261
  export function* teamSagasMock() {
1197
- yield takeLatest(actions.loadUsers, loadUsersMock);
1262
+ yield takeLatest(actions.loadUsersV2, loadUsersMock);
1198
1263
  yield takeLatest(actions.loadAllSubTenantsUsers, loadAllSubTenantsUsersMock);
1199
1264
  yield takeLatest(actions.loadRoles, loadRolesMock);
1200
1265
  yield takeEvery(actions.addUser, addUserMock);
package/auth/index.d.ts CHANGED
@@ -250,8 +250,9 @@ declare const _default: {
250
250
  }], import("@frontegg/rest-api").IUpdateGroupConfig & {
251
251
  groupId: string;
252
252
  }, string, never, never>;
253
- getTeamUsers: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[import("@frontegg/rest-api").ILoadUsers], import("@frontegg/rest-api").ILoadUsers, string, never, never>;
254
- loadUsers: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[import("..").WithCallback<import("..").WithSilentLoad<import("./TeamState/interfaces").IGetUsersV2Payload>, import("@frontegg/rest-api").ITeamUser[]>], import("..").WithCallback<import("..").WithSilentLoad<import("./TeamState/interfaces").IGetUsersV2Payload>, import("@frontegg/rest-api").ITeamUser[]>, string, never, never>;
253
+ getTeamUsers: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[import("./TeamState/interfaces").IGetUsersV2Payload], import("./TeamState/interfaces").IGetUsersV2Payload, string, never, never>;
254
+ loadUsersV2: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[import("..").WithCallback<import("..").WithSilentLoad<import("./TeamState/interfaces").IGetUsersV2Payload>, import("@frontegg/rest-api").ITeamUser[]>], import("..").WithCallback<import("..").WithSilentLoad<import("./TeamState/interfaces").IGetUsersV2Payload>, import("@frontegg/rest-api").ITeamUser[]>, string, never, never>;
255
+ loadUsers: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[import("..").WithCallback<import("..").WithSilentLoad<import("@frontegg/rest-api").ILoadUsers>, import("@frontegg/rest-api").ITeamUser[]>], import("..").WithCallback<import("..").WithSilentLoad<import("@frontegg/rest-api").ILoadUsers>, import("@frontegg/rest-api").ITeamUser[]>, string, never, never>;
255
256
  loadAllSubTenantsUsers: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[import("..").WithCallback<import("..").WithSilentLoad<Partial<import("@frontegg/rest-api").ILoadAllUsers>>, import("@frontegg/rest-api").ISubTenantUser[]>], import("..").WithCallback<import("..").WithSilentLoad<Partial<import("@frontegg/rest-api").ILoadAllUsers>>, import("@frontegg/rest-api").ISubTenantUser[]>, string, never, never>;
256
257
  loadRoles: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[({
257
258
  callback?: import("..").CallbackMethod<{
package/auth/reducer.d.ts CHANGED
@@ -211,8 +211,9 @@ declare const actions: {
211
211
  }], import("@frontegg/rest-api").IUpdateGroupConfig & {
212
212
  groupId: string;
213
213
  }, string, never, never>;
214
- getTeamUsers: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[import("@frontegg/rest-api").ILoadUsers], import("@frontegg/rest-api").ILoadUsers, string, never, never>;
215
- loadUsers: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[import("..").WithCallback<import("..").WithSilentLoad<import(".").IGetUsersV2Payload>, import("@frontegg/rest-api").ITeamUser[]>], import("..").WithCallback<import("..").WithSilentLoad<import(".").IGetUsersV2Payload>, import("@frontegg/rest-api").ITeamUser[]>, string, never, never>;
214
+ getTeamUsers: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[import(".").IGetUsersV2Payload], import(".").IGetUsersV2Payload, string, never, never>;
215
+ loadUsersV2: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[import("..").WithCallback<import("..").WithSilentLoad<import(".").IGetUsersV2Payload>, import("@frontegg/rest-api").ITeamUser[]>], import("..").WithCallback<import("..").WithSilentLoad<import(".").IGetUsersV2Payload>, import("@frontegg/rest-api").ITeamUser[]>, string, never, never>;
216
+ loadUsers: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[import("..").WithCallback<import("..").WithSilentLoad<import("@frontegg/rest-api").ILoadUsers>, import("@frontegg/rest-api").ITeamUser[]>], import("..").WithCallback<import("..").WithSilentLoad<import("@frontegg/rest-api").ILoadUsers>, import("@frontegg/rest-api").ITeamUser[]>, string, never, never>;
216
217
  loadAllSubTenantsUsers: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[import("..").WithCallback<import("..").WithSilentLoad<Partial<import("@frontegg/rest-api").ILoadAllUsers>>, import("@frontegg/rest-api").ISubTenantUser[]>], import("..").WithCallback<import("..").WithSilentLoad<Partial<import("@frontegg/rest-api").ILoadAllUsers>>, import("@frontegg/rest-api").ISubTenantUser[]>, string, never, never>;
217
218
  loadRoles: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[({
218
219
  callback?: import("..").CallbackMethod<{
package/index.d.ts CHANGED
@@ -20,6 +20,7 @@ export * from './toolkit';
20
20
  export * from './helpers';
21
21
  export * from './utils';
22
22
  export type { WithCallback, WithSilentLoad, CallbackMethod } from './interfaces';
23
+ export type { NotEntitledReason } from '@frontegg/rest-api';
23
24
  export declare type FronteggState = {
24
25
  root: RootState;
25
26
  auth: AuthState;
package/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /** @license Frontegg v6.117.0-alpha.1
1
+ /** @license Frontegg v6.118.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.
@@ -27,7 +27,8 @@ Object.keys(_utils2).forEach(function (key) {
27
27
  const entitlementsState = {
28
28
  entitlements: undefined,
29
29
  loading: false,
30
- error: undefined
30
+ error: undefined,
31
+ options: undefined
31
32
  };
32
33
  exports.entitlementsState = entitlementsState;
33
34
  const reducers = {
@@ -1,15 +1,18 @@
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
7
  exports.entitlementsSagas = entitlementsSagas;
7
8
  exports.loadEntitlements = loadEntitlements;
9
+ var _fastDeepEqual = _interopRequireDefault(require("fast-deep-equal"));
8
10
  var _effects = require("redux-saga/effects");
9
11
  var _restApi = require("@frontegg/rest-api");
10
12
  var _reducer = require("../reducer");
11
13
  /**
12
14
  Load entitlements list
15
+ Don't update entitlements data in the store when data is equal (deep check)
13
16
  */
14
17
  function* loadEntitlements() {
15
18
  yield (0, _effects.put)(_reducer.actions.setEntitlementsState({
@@ -17,9 +20,19 @@ function* loadEntitlements() {
17
20
  error: null
18
21
  }));
19
22
  try {
20
- const entitlements = yield (0, _effects.call)(_restApi.api.entitlements.loadEntitlements);
23
+ const newEntitlements = yield (0, _effects.call)(_restApi.api.entitlements.loadEntitlements);
24
+ const oldEntitlements = yield (0, _effects.select)(state => {
25
+ var _state$auth$entitleme;
26
+ return (_state$auth$entitleme = state.auth.entitlementsState) == null ? void 0 : _state$auth$entitleme.entitlements;
27
+ });
28
+ if ((0, _fastDeepEqual.default)(oldEntitlements, newEntitlements)) {
29
+ yield (0, _effects.put)(_reducer.actions.setEntitlementsState({
30
+ loading: false
31
+ }));
32
+ return;
33
+ }
21
34
  yield (0, _effects.put)(_reducer.actions.setEntitlementsState({
22
- entitlements,
35
+ entitlements: newEntitlements,
23
36
  loading: false
24
37
  }));
25
38
  } catch (e) {
@@ -3,13 +3,82 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.getEntitlements = void 0;
6
+ exports.getPermissionEntitlements = exports.getFeatureEntitlements = exports.getEntitlements = void 0;
7
+ var _restApi = require("@frontegg/rest-api");
8
+ const ENTITLEMENTS_NOT_ENABLED_EXCEPTION_TEXT = 'You must first enable entitlements via Frontegg options to use this function';
9
+
10
+ /**
11
+ * Guard entitlements feature by checking if it is enabled by the vendor
12
+ * @throws when entitlement is not enabled via frontegg options
13
+ */
14
+ const guardEntitlementsUsage = entitlementsOptions => {
15
+ if (entitlementsOptions != null && entitlementsOptions.enabled) return;
16
+ throw new Error(ENTITLEMENTS_NOT_ENABLED_EXCEPTION_TEXT);
17
+ };
18
+
19
+ /**
20
+ @param keyEntitlements permission or feature data object
21
+ @param entitlementsVendorConfig entitlements frontegg provider configuration
22
+ @param missingKeyEnum missing key for scenario that the key does not exist in entitlementsValuePerKeys
23
+ @returns if the user is entitled to the given key. Attaching the justification if not
24
+ @throws when entitlement is not enabled via frontegg options
25
+ */
26
+ const getEntitlementsHelper = (keyEntitlements, entitlementsVendorConfig, missingKeyEnum) => {
27
+ guardEntitlementsUsage(entitlementsVendorConfig);
28
+ if (!keyEntitlements) {
29
+ return {
30
+ isEntitled: false,
31
+ justification: missingKeyEnum
32
+ };
33
+ }
34
+ if (keyEntitlements.isEntitled) {
35
+ return {
36
+ isEntitled: true
37
+ };
38
+ }
39
+ return {
40
+ isEntitled: false,
41
+ justification: keyEntitlements.notEntitledReason
42
+ };
43
+ };
44
+
45
+ /**
46
+ @param entitlements
47
+ @param key
48
+ @param entitlementsVendorConfig entitlements frontegg provider configuration
49
+ @returns if the user is entitled to the given permission. Attaching the justification if not
50
+ @throws when entitlement is not enabled via frontegg options
51
+ */
52
+ const getPermissionEntitlements = (entitlements, key, entitlementsVendorConfig) => {
53
+ var _entitlements$permiss;
54
+ return getEntitlementsHelper(entitlements == null ? void 0 : (_entitlements$permiss = entitlements.permissions) == null ? void 0 : _entitlements$permiss[key], entitlementsVendorConfig, _restApi.NotEntitledReason.MISSING_PERMISSION);
55
+ };
56
+
57
+ /**
58
+ @param entitlements
59
+ @param key
60
+ @param entitlementsVendorConfig entitlements frontegg provider configuration
61
+ @returns if the user is entitled to the given feature. Attaching the justification if not
62
+ @throws when entitlement is not enabled via frontegg options
63
+ */
64
+ exports.getPermissionEntitlements = getPermissionEntitlements;
65
+ const getFeatureEntitlements = (entitlements, key, entitlementsVendorConfig) => {
66
+ var _entitlements$feature;
67
+ return getEntitlementsHelper(entitlements == null ? void 0 : (_entitlements$feature = entitlements.features) == null ? void 0 : _entitlements$feature[key], entitlementsVendorConfig, _restApi.NotEntitledReason.MISSING_FEATURE);
68
+ };
69
+
7
70
  /**
8
- @param entitlementsByKey
9
- @param keys The requested entitlement keys
10
- @returns Entitlements contain true/false for every key (state of is key entitled)
71
+ @param entitlements
72
+ @param entitledToOptions including permission or feature
73
+ @param entitlementsVendorConfig entitlements frontegg provider configuration
74
+ @returns if the user is entitled to the given feature or permission (check only one). Attaching the justification if not
75
+ @throws when entitlement is not enabled via frontegg options
11
76
  */
12
- const getEntitlements = (entitlementsByKey = {}, keys) => keys.reduce((result, key) => [...result, {
13
- isEntitled: entitlementsByKey[key] || false
14
- }], []);
77
+ exports.getFeatureEntitlements = getFeatureEntitlements;
78
+ const getEntitlements = (entitlements, options, entitlementsVendorConfig) => {
79
+ if ('permissionKey' in options) {
80
+ return getPermissionEntitlements(entitlements, options.permissionKey, entitlementsVendorConfig);
81
+ }
82
+ return getFeatureEntitlements(entitlements, options.featureKey, entitlementsVendorConfig);
83
+ };
15
84
  exports.getEntitlements = getEntitlements;
@@ -28,10 +28,11 @@ function* getTeamUsers({
28
28
  try {
29
29
  const {
30
30
  items: users
31
- } = yield (0, _effects.call)(_restApi.api.teams.loadUsers, {
32
- filter: payload.filter,
33
- pageOffset: payload.pageOffset,
34
- pageSize: payload.pageSize
31
+ } = yield (0, _effects.call)(_restApi.api.users.getUsersV2, {
32
+ _filter: payload.filter,
33
+ _offset: payload.pageOffset,
34
+ _limit: payload.pageSize,
35
+ _includeSubTenants: false
35
36
  });
36
37
  yield (0, _effects.put)(_reducer.actions.setGroupsState({
37
38
  teamUsers: users
@@ -3,6 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ exports.ADMIN_PORTAL_ENTITLEMENTS_FF = void 0;
6
7
  Object.defineProperty(exports, "AuthStrategyEnum", {
7
8
  enumerable: true,
8
9
  get: function () {
@@ -43,4 +44,6 @@ exports.QuickLoginStrategy = QuickLoginStrategy;
43
44
  QuickLoginStrategy["UsbKey"] = "usb-key";
44
45
  QuickLoginStrategy["Android"] = "android";
45
46
  QuickLoginStrategy["Sms"] = "sms";
46
- })(QuickLoginStrategy || (exports.QuickLoginStrategy = QuickLoginStrategy = {}));
47
+ })(QuickLoginStrategy || (exports.QuickLoginStrategy = QuickLoginStrategy = {}));
48
+ const ADMIN_PORTAL_ENTITLEMENTS_FF = 'admin_portal_entitlements';
49
+ exports.ADMIN_PORTAL_ENTITLEMENTS_FF = ADMIN_PORTAL_ENTITLEMENTS_FF;
@@ -62,7 +62,6 @@ const authStrategyLoginStepMap = {
62
62
  [_restApi.AuthStrategyEnum.MagicLink]: _interfaces2.LoginStep.magicLinkPreLoginSuccess,
63
63
  [_restApi.AuthStrategyEnum.SmsCode]: _interfaces2.LoginStep.loginWithSmsOtc
64
64
  };
65
- const ADMIN_PORTAL_ENTITLEMENTS_FF = 'admin_portal_entitlements';
66
65
  function* afterAuthNavigation() {
67
66
  const onRedirectTo = _restApi.ContextHolder.onRedirectTo;
68
67
  const {
@@ -249,13 +248,18 @@ function* shouldNevigateToRegisterQuickLogin(user) {
249
248
  return quickLoginToRegister && localStorage.getItem(`${user.id}-${quickLoginToRegister}`) !== 'true' && !window.location.pathname.endsWith(routes.logoutUrl);
250
249
  }
251
250
  function* handleLoadEntitlements() {
252
- const {
253
- user
254
- } = yield (0, _effects.select)(state => state.auth);
255
- if (!user) {
251
+ const isAuthenticated = yield (0, _effects.select)(state => {
252
+ var _state$auth;
253
+ return (_state$auth = state.auth) == null ? void 0 : _state$auth.isAuthenticated;
254
+ });
255
+ const isEntitlementsEnabledByUser = yield (0, _effects.select)(state => {
256
+ var _state$auth2, _state$auth2$entitlem, _state$auth2$entitlem2;
257
+ return (_state$auth2 = state.auth) == null ? void 0 : (_state$auth2$entitlem = _state$auth2.entitlementsState) == null ? void 0 : (_state$auth2$entitlem2 = _state$auth2$entitlem.options) == null ? void 0 : _state$auth2$entitlem2.enabled;
258
+ });
259
+ if (!isAuthenticated || !isEntitlementsEnabledByUser) {
256
260
  return;
257
261
  }
258
- const [isEntitlementsFFOn] = yield (0, _effects.call)(_helpers.getFeatureFlags, [ADMIN_PORTAL_ENTITLEMENTS_FF]);
262
+ const [isEntitlementsFFOn] = yield (0, _effects.call)(_helpers.getFeatureFlags, [_interfaces2.ADMIN_PORTAL_ENTITLEMENTS_FF]);
259
263
  if (isEntitlementsFFOn) {
260
264
  yield (0, _effects.call)(_saga4.loadEntitlements);
261
265
  }
@@ -59,8 +59,7 @@ const allAccountsInitialState = {
59
59
  },
60
60
  usersPageOffset: 0,
61
61
  accountSettings: {}
62
- },
63
- teamUsers: []
62
+ }
64
63
  };
65
64
  exports.allAccountsState = exports.allAccountsInitialState = allAccountsInitialState;
66
65
  const reducers = {
@@ -23,37 +23,6 @@ const selectTenantsState = () => (0, _effects.select)(_ => _[_constants.authStor
23
23
  exports.selectTenantsState = selectTenantsState;
24
24
  const selectAllAccountsState = () => (0, _effects.select)(_ => _[_constants.authStoreName].allAccountsState);
25
25
  exports.selectAllAccountsState = selectAllAccountsState;
26
- function* getTeamUsers({
27
- payload
28
- }) {
29
- const key = _stateTypes.AllAccountsStateKeys.GET_TEAM_USERS;
30
- yield (0, _effects.put)(_reducer.actions.setAllAccountsLoader({
31
- key,
32
- value: true
33
- }));
34
- try {
35
- const {
36
- items: users
37
- } = yield (0, _effects.call)(_restApi.api.teams.loadUsers, {
38
- filter: payload.filter,
39
- pageOffset: payload.pageOffset,
40
- pageSize: payload.pageSize
41
- });
42
- yield (0, _effects.put)(_reducer.actions.setAllAccountsState({
43
- teamUsers: users
44
- }));
45
- } catch (e) {
46
- yield (0, _effects.put)(_reducer.actions.setAllAccountsError({
47
- key,
48
- value: (0, _utils.errorHandler)(e)
49
- }));
50
- } finally {
51
- yield (0, _effects.put)(_reducer.actions.setAllAccountsLoader({
52
- key,
53
- value: false
54
- }));
55
- }
56
- }
57
26
  function* loadAccounts({
58
27
  payload
59
28
  }) {
@@ -784,7 +753,6 @@ function* allAccountsSagas() {
784
753
  yield (0, _effects.takeLatest)(_reducer.actions.addUsersToAccount, addUsersToAccount);
785
754
  yield (0, _effects.takeLatest)(_reducer.actions.deleteUsersFromAccount, deleteUserFromAccount);
786
755
  yield (0, _effects.takeLatest)(_reducer.actions.setUserRolesForSubAccount, setUserRolesForSubAccount);
787
- yield (0, _effects.takeLatest)(_reducer.actions.getTeamUsers, getTeamUsers);
788
756
  yield (0, _effects.takeLatest)(_reducer.actions.getAccountUsers, getAccountUsers);
789
757
  yield (0, _effects.takeLatest)(_reducer.actions.setSelectedSubAccountData, setSelectedSubAccountData);
790
758
  }
@@ -49,6 +49,9 @@ const reducers = {
49
49
  };
50
50
  exports.teamReducers = reducers;
51
51
  const actions = {
52
+ loadUsersV2: (0, _toolkit.createAction)(`${_constants.authStoreName}/loadUsersV2`, payload => ({
53
+ payload
54
+ })),
52
55
  loadUsers: (0, _toolkit.createAction)(`${_constants.authStoreName}/loadUsers`, payload => ({
53
56
  payload
54
57
  })),
@@ -53,7 +53,7 @@ function* getGroupsForUsers() {
53
53
  }
54
54
 
55
55
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
56
- function* loadUsers({
56
+ function* loadUsersV2({
57
57
  payload
58
58
  }) {
59
59
  var _payload$pageSize, _payload$pageOffset, _payload$filter, _payload$sort, _payload$shouldShowSu;
@@ -64,8 +64,8 @@ function* loadUsers({
64
64
  const teamState = yield selectTeamState();
65
65
  const pageSize = (_payload$pageSize = payload.pageSize) != null ? _payload$pageSize : teamState.pageSize;
66
66
  const pageOffset = (_payload$pageOffset = payload.pageOffset) != null ? _payload$pageOffset : teamState.pageOffset;
67
- const filter = (_payload$filter = payload.filter) != null ? _payload$filter : teamState.filter;
68
- const sort = (_payload$sort = payload.sort) != null ? _payload$sort : teamState.sort;
67
+ const filter = (_payload$filter = payload.filter) != null ? _payload$filter : teamState.filterV2;
68
+ const sort = (_payload$sort = payload.sort) != null ? _payload$sort : teamState.sortV2;
69
69
  const shouldIncludeSubTenants = (_payload$shouldShowSu = payload == null ? void 0 : payload.shouldShowSubTenantUsersIfReseller) != null ? _payload$shouldShowSu : teamState == null ? void 0 : teamState.shouldShowSubTenantUsersIfReseller;
70
70
  yield (0, _effects.put)(_reducer.actions.setTeamLoader({
71
71
  key: _interfaces.TeamStateKeys.USERS,
@@ -74,8 +74,8 @@ function* loadUsers({
74
74
  yield (0, _effects.put)(_reducer.actions.setTeamState({
75
75
  pageSize,
76
76
  pageOffset,
77
- filter,
78
- sort
77
+ filterV2: filter,
78
+ sortV2: sort
79
79
  }));
80
80
  try {
81
81
  const [{
@@ -135,6 +135,70 @@ function* loadUsers({
135
135
  }));
136
136
  }
137
137
 
138
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
139
+ function* loadUsers({
140
+ payload
141
+ }) {
142
+ var _payload$pageSize2, _payload$pageOffset2, _payload$filter2, _payload$sort2;
143
+ const {
144
+ silentLoading,
145
+ callback
146
+ } = payload;
147
+ const teamState = yield selectTeamState();
148
+ const pageSize = (_payload$pageSize2 = payload.pageSize) != null ? _payload$pageSize2 : teamState.pageSize;
149
+ const pageOffset = (_payload$pageOffset2 = payload.pageOffset) != null ? _payload$pageOffset2 : teamState.pageOffset;
150
+ const filter = (_payload$filter2 = payload.filter) != null ? _payload$filter2 : teamState.filter;
151
+ const sort = (_payload$sort2 = payload.sort) != null ? _payload$sort2 : teamState.sort;
152
+ yield (0, _effects.put)(_reducer.actions.setTeamLoader({
153
+ key: _interfaces.TeamStateKeys.USERS,
154
+ value: !silentLoading
155
+ }));
156
+ yield (0, _effects.put)(_reducer.actions.setTeamState({
157
+ pageSize,
158
+ pageOffset,
159
+ filter: filter,
160
+ sort: sort
161
+ }));
162
+ try {
163
+ const [{
164
+ items: users,
165
+ totalPages,
166
+ totalItems
167
+ }, {
168
+ items: roles
169
+ }, {
170
+ items: permissions
171
+ }] = yield (0, _effects.all)([(0, _effects.call)(_restApi.api.teams.loadUsers, {
172
+ pageSize,
173
+ pageOffset,
174
+ filter,
175
+ sort
176
+ }), (0, _effects.call)(_restApi.api.teams.loadAvailableRoles), (0, _effects.call)(_restApi.api.teams.loadAvailablePermissions)]);
177
+ yield (0, _effects.put)(_reducer.actions.setTeamState({
178
+ users,
179
+ totalPages,
180
+ totalItems,
181
+ roles,
182
+ permissions
183
+ }));
184
+ callback == null ? void 0 : callback(users);
185
+ } catch (e) {
186
+ yield (0, _effects.put)(_reducer.actions.setTeamError({
187
+ key: _interfaces.TeamStateKeys.USERS,
188
+ value: e.message
189
+ }));
190
+ yield (0, _effects.put)(_reducer.actions.setTeamState({
191
+ totalPages: 0,
192
+ users: []
193
+ }));
194
+ callback == null ? void 0 : callback(null, e);
195
+ }
196
+ yield (0, _effects.put)(_reducer.actions.setTeamLoader({
197
+ key: _interfaces.TeamStateKeys.USERS,
198
+ value: false
199
+ }));
200
+ }
201
+
138
202
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
139
203
  function* loadAllSubTenantsUsers({
140
204
  payload
@@ -316,7 +380,7 @@ function* addUsersBulk({
316
380
  filter: '',
317
381
  silentLoading: payload.emails.length > 0
318
382
  };
319
- yield (0, _effects.put)(_reducer.actions.loadUsers(queryObject));
383
+ yield (0, _effects.put)(_reducer.actions.loadUsersV2(queryObject));
320
384
  yield (0, _effects.put)(_reducer.actions.setTeamState({
321
385
  addUserDialogState: {
322
386
  loading: false
@@ -847,6 +911,7 @@ function* closeDeleteUserDialog({
847
911
  }
848
912
  function* teamSagas() {
849
913
  yield (0, _effects.takeLatest)(_reducer.actions.loadUsers, loadUsers);
914
+ yield (0, _effects.takeLatest)(_reducer.actions.loadUsersV2, loadUsersV2);
850
915
  yield (0, _effects.takeLatest)(_reducer.actions.loadAllSubTenantsUsers, loadAllSubTenantsUsers);
851
916
  yield (0, _effects.takeLatest)(_reducer.actions.loadRoles, loadRoles);
852
917
  yield (0, _effects.takeEvery)(_reducer.actions.addUser, addUser);
@@ -877,16 +942,16 @@ function* teamSagas() {
877
942
  function* loadUsersMock({
878
943
  payload
879
944
  }) {
880
- var _payload$pageSize2, _payload$pageOffset2, _payload$filter2, _payload$sort2;
945
+ var _payload$pageSize3, _payload$pageOffset3, _payload$filter3, _payload$sort3;
881
946
  const {
882
947
  silentLoading,
883
948
  callback
884
949
  } = payload;
885
950
  const teamState = yield selectTeamState();
886
- const pageSize = (_payload$pageSize2 = payload.pageSize) != null ? _payload$pageSize2 : teamState.pageSize;
887
- const pageOffset = (_payload$pageOffset2 = payload.pageOffset) != null ? _payload$pageOffset2 : teamState.pageOffset;
888
- const filter = (_payload$filter2 = payload.filter) != null ? _payload$filter2 : teamState.filter;
889
- const sort = (_payload$sort2 = payload.sort) != null ? _payload$sort2 : teamState.sort;
951
+ const pageSize = (_payload$pageSize3 = payload.pageSize) != null ? _payload$pageSize3 : teamState.pageSize;
952
+ const pageOffset = (_payload$pageOffset3 = payload.pageOffset) != null ? _payload$pageOffset3 : teamState.pageOffset;
953
+ const filter = (_payload$filter3 = payload.filter) != null ? _payload$filter3 : teamState.filterV2;
954
+ const sort = (_payload$sort3 = payload.sort) != null ? _payload$sort3 : teamState.sortV2;
890
955
  yield (0, _effects.put)(_reducer.actions.setTeamLoader({
891
956
  key: _interfaces.TeamStateKeys.USERS,
892
957
  value: !silentLoading
@@ -894,8 +959,8 @@ function* loadUsersMock({
894
959
  yield (0, _effects.put)(_reducer.actions.setTeamState({
895
960
  pageSize,
896
961
  pageOffset,
897
- filter,
898
- sort
962
+ filterV2: filter,
963
+ sortV2: sort
899
964
  }));
900
965
  const totalPages = 2;
901
966
  const totalItems = 10;
@@ -1202,7 +1267,7 @@ function* resendInvitationLinkToAllSubTenantsMock({
1202
1267
  }));
1203
1268
  }
1204
1269
  function* teamSagasMock() {
1205
- yield (0, _effects.takeLatest)(_reducer.actions.loadUsers, loadUsersMock);
1270
+ yield (0, _effects.takeLatest)(_reducer.actions.loadUsersV2, loadUsersMock);
1206
1271
  yield (0, _effects.takeLatest)(_reducer.actions.loadAllSubTenantsUsers, loadAllSubTenantsUsersMock);
1207
1272
  yield (0, _effects.takeLatest)(_reducer.actions.loadRoles, loadRolesMock);
1208
1273
  yield (0, _effects.takeEvery)(_reducer.actions.addUser, addUserMock);
package/node/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /** @license Frontegg v6.117.0-alpha.1
1
+ /** @license Frontegg v6.118.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.
@@ -89,7 +89,7 @@ const createFronteggStore = (rootInitialState, storeHolder, previewMode = false,
89
89
  holder = window;
90
90
  }
91
91
  if (!holder.store) {
92
- var _overrideInitialState, _authInitialState$rou, _overrideInitialState2, _overrideInitialState3, _overrideInitialState4, _overrideInitialState5, _overrideInitialState6, _overrideInitialState7, _overrideInitialState8, _overrideInitialState9;
92
+ var _overrideInitialState, _authInitialState$rou, _overrideInitialState2, _overrideInitialState3, _authStore$initialSta, _overrideInitialState4, _overrideInitialState5, _overrideInitialState6, _overrideInitialState7, _overrideInitialState8, _overrideInitialState9;
93
93
  if (!previewMode && !builderMode) {
94
94
  _restApi.ContextHolder.setContext(rootInitialState.context);
95
95
  }
@@ -108,7 +108,10 @@ const createFronteggStore = (rootInitialState, storeHolder, previewMode = false,
108
108
  urlStrategy: urlStrategy
109
109
  }),
110
110
  [_auth.default.storeName]: (0, _extends2.default)({}, _auth.default.initialState, authInitialState, (_overrideInitialState = overrideInitialState == null ? void 0 : overrideInitialState.auth) != null ? _overrideInitialState : {}, {
111
- routes: (0, _extends2.default)({}, _auth.default.initialState.routes, (_authInitialState$rou = authInitialState == null ? void 0 : authInitialState.routes) != null ? _authInitialState$rou : {}, (_overrideInitialState2 = overrideInitialState == null ? void 0 : (_overrideInitialState3 = overrideInitialState.auth) == null ? void 0 : _overrideInitialState3.routes) != null ? _overrideInitialState2 : {})
111
+ routes: (0, _extends2.default)({}, _auth.default.initialState.routes, (_authInitialState$rou = authInitialState == null ? void 0 : authInitialState.routes) != null ? _authInitialState$rou : {}, (_overrideInitialState2 = overrideInitialState == null ? void 0 : (_overrideInitialState3 = overrideInitialState.auth) == null ? void 0 : _overrideInitialState3.routes) != null ? _overrideInitialState2 : {}),
112
+ entitlementsState: (0, _extends2.default)({}, _auth.default.initialState.entitlementsState, {
113
+ options: (0, _extends2.default)({}, (_authStore$initialSta = _auth.default.initialState.entitlementsState) == null ? void 0 : _authStore$initialSta.options, overrideInitialState == null ? void 0 : overrideInitialState.entitlementsOptions)
114
+ })
112
115
  }),
113
116
  [_audits.default.storeName]: (0, _extends2.default)({}, _audits.default.initialState, (_overrideInitialState4 = overrideInitialState == null ? void 0 : overrideInitialState.auditLogs) != null ? _overrideInitialState4 : {}, {
114
117
  auditLogsState: (0, _extends2.default)({}, _audits.default.initialState.auditLogsState, (_overrideInitialState5 = overrideInitialState == null ? void 0 : (_overrideInitialState6 = overrideInitialState.auditLogs) == null ? void 0 : _overrideInitialState6.auditLogsState) != null ? _overrideInitialState5 : {}),
package/package.json CHANGED
@@ -1,13 +1,14 @@
1
1
  {
2
2
  "name": "@frontegg/redux-store",
3
- "version": "6.117.0-alpha.1",
3
+ "version": "6.118.0",
4
4
  "main": "./node/index.js",
5
5
  "license": "MIT",
6
6
  "author": "Frontegg LTD",
7
7
  "dependencies": {
8
8
  "@babel/runtime": "^7.18.6",
9
- "@frontegg/rest-api": "3.0.127",
9
+ "@frontegg/rest-api": "3.0.136",
10
10
  "@reduxjs/toolkit": "1.8.5",
11
+ "fast-deep-equal": "3.1.3",
11
12
  "redux-saga": "^1.2.1",
12
13
  "uuid": "^8.3.2"
13
14
  },
@@ -1,4 +1,4 @@
1
- import { AuthPageRoutes, AuthState } from '../auth';
1
+ import { AuthPageRoutes, AuthState, EntitlementsOptions } from '../auth';
2
2
  import { ContextOptions } from '@frontegg/rest-api';
3
3
  import { AuditsState } from '../audits';
4
4
  import { OldAuditsState } from '../audits/backward-compatibility';
@@ -25,4 +25,5 @@ export declare const createFronteggStore: (rootInitialState: InitialState, store
25
25
  };
26
26
  auditLogs: Partial<AuditsState>;
27
27
  audits: Partial<OldAuditsState>;
28
+ entitlementsOptions: Partial<EntitlementsOptions>;
28
29
  }> | undefined, builderMode?: boolean, urlStrategy?: 'hash' | 'path') => EnhancedStore;
package/toolkit/index.js CHANGED
@@ -50,7 +50,7 @@ export const createFronteggStore = (rootInitialState, storeHolder, previewMode =
50
50
  holder = window;
51
51
  }
52
52
  if (!holder.store) {
53
- var _overrideInitialState, _authInitialState$rou, _overrideInitialState2, _overrideInitialState3, _overrideInitialState4, _overrideInitialState5, _overrideInitialState6, _overrideInitialState7, _overrideInitialState8, _overrideInitialState9;
53
+ var _overrideInitialState, _authInitialState$rou, _overrideInitialState2, _overrideInitialState3, _authStore$initialSta, _overrideInitialState4, _overrideInitialState5, _overrideInitialState6, _overrideInitialState7, _overrideInitialState8, _overrideInitialState9;
54
54
  if (!previewMode && !builderMode) {
55
55
  ContextHolder.setContext(rootInitialState.context);
56
56
  }
@@ -69,7 +69,10 @@ export const createFronteggStore = (rootInitialState, storeHolder, previewMode =
69
69
  urlStrategy: urlStrategy
70
70
  }),
71
71
  [authStore.storeName]: _extends({}, authStore.initialState, authInitialState, (_overrideInitialState = overrideInitialState == null ? void 0 : overrideInitialState.auth) != null ? _overrideInitialState : {}, {
72
- routes: _extends({}, authStore.initialState.routes, (_authInitialState$rou = authInitialState == null ? void 0 : authInitialState.routes) != null ? _authInitialState$rou : {}, (_overrideInitialState2 = overrideInitialState == null ? void 0 : (_overrideInitialState3 = overrideInitialState.auth) == null ? void 0 : _overrideInitialState3.routes) != null ? _overrideInitialState2 : {})
72
+ routes: _extends({}, authStore.initialState.routes, (_authInitialState$rou = authInitialState == null ? void 0 : authInitialState.routes) != null ? _authInitialState$rou : {}, (_overrideInitialState2 = overrideInitialState == null ? void 0 : (_overrideInitialState3 = overrideInitialState.auth) == null ? void 0 : _overrideInitialState3.routes) != null ? _overrideInitialState2 : {}),
73
+ entitlementsState: _extends({}, authStore.initialState.entitlementsState, {
74
+ options: _extends({}, (_authStore$initialSta = authStore.initialState.entitlementsState) == null ? void 0 : _authStore$initialSta.options, overrideInitialState == null ? void 0 : overrideInitialState.entitlementsOptions)
75
+ })
73
76
  }),
74
77
  [auditsStore.storeName]: _extends({}, auditsStore.initialState, (_overrideInitialState4 = overrideInitialState == null ? void 0 : overrideInitialState.auditLogs) != null ? _overrideInitialState4 : {}, {
75
78
  auditLogsState: _extends({}, auditsStore.initialState.auditLogsState, (_overrideInitialState5 = overrideInitialState == null ? void 0 : (_overrideInitialState6 = overrideInitialState.auditLogs) == null ? void 0 : _overrideInitialState6.auditLogsState) != null ? _overrideInitialState5 : {}),