@frontegg/redux-store 7.80.0 → 7.81.0-alpha.1

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.
@@ -1,6 +1,6 @@
1
1
  import { FronteggState, RestApi, SharedActions, WithCallback, WithRetryConfig } from '../../interfaces';
2
2
  import { ApplicationsState, UserAppsAssignmentPayload } from './interfaces';
3
- import { IApplicationsResponse, ITeamUser } from '@frontegg/rest-api';
3
+ import { ApplicationAccessType, IApplicationsResponse, ITeamUser } from '@frontegg/rest-api';
4
4
  declare const _default: (store: FronteggState, api: RestApi, sharedActions: SharedActions) => {
5
5
  setApplicationsState: (payload: Partial<ApplicationsState>) => void;
6
6
  resetApplicationsState: () => void;
@@ -16,6 +16,7 @@ declare const _default: (store: FronteggState, api: RestApi, sharedActions: Shar
16
16
  user: ITeamUser;
17
17
  }) => Promise<((IApplicationsResponse & {
18
18
  userIds?: string[];
19
+ tenantApplicationAccessType?: ApplicationAccessType;
19
20
  }) | never[])[] | undefined>;
20
21
  mapUsersWithApplicationData: ({ shouldLoadApps, users, retryConfig, }: WithRetryConfig<{
21
22
  shouldLoadApps?: boolean;
@@ -46,18 +46,30 @@ export default ((store, api, sharedActions) => {
46
46
  fetching: true
47
47
  });
48
48
  try {
49
- const tenantAppIds = await retryIfNeeded(() => api.applications.getTenantsApplications(), retryConfig);
50
- const appIds = getFlattenAppIds(tenantAppIds);
49
+ const tenantAppAssignments = await retryIfNeeded(() => api.applications.getTenantsApplicationsV2(), retryConfig);
50
+
51
+ // Extract appIds from the new assignments structure
52
+ const appIds = [...new Set(tenantAppAssignments.flatMap(tenant => tenant.assignments.map(assignment => assignment.appId)))];
51
53
  const accountApplications = await retryIfNeeded(() => api.applications.getApplicationsData({
52
54
  appIds
53
55
  }), retryConfig);
54
56
  const usersOfApplications = await retryIfNeeded(() => api.applications.getUsersOfApplications({
55
57
  appIds
56
58
  }), retryConfig);
59
+
60
+ // Create a map of appId to accessType from tenant assignments (once)
61
+ const appAccessTypeMap = new Map();
62
+ tenantAppAssignments.forEach(tenant => {
63
+ tenant.assignments.forEach(assignment => {
64
+ appAccessTypeMap.set(assignment.appId, assignment.accessType);
65
+ });
66
+ });
57
67
  const accountApplicationsWithUsers = accountApplications.map(app => {
58
68
  var _usersOfApplications$;
59
69
  return _extends({}, app, {
60
- userIds: (_usersOfApplications$ = usersOfApplications.find(u => u.appId === app.id)) == null ? void 0 : _usersOfApplications$.userIds
70
+ userIds: (_usersOfApplications$ = usersOfApplications.find(u => u.appId === app.id)) == null ? void 0 : _usersOfApplications$.userIds,
71
+ // Add tenant-specific access type as a separate attribute
72
+ tenantApplicationAccessType: appAccessTypeMap.get(app.id)
61
73
  });
62
74
  });
63
75
  setApplicationsState({
@@ -1,4 +1,4 @@
1
- import { FronteggApiError, IApplicationsResponse, IAssignUserToApplicationsBody } from '@frontegg/rest-api';
1
+ import { FronteggApiError, IApplicationsResponse, IAssignUserToApplicationsBody, ApplicationAccessType } from '@frontegg/rest-api';
2
2
  export interface ApplicationsState {
3
3
  error?: FronteggApiError | null | string;
4
4
  fetching?: boolean;
@@ -7,6 +7,7 @@ export interface ApplicationsState {
7
7
  userApplications?: IApplicationsResponse[];
8
8
  accountApplications?: (IApplicationsResponse & {
9
9
  userIds?: string[];
10
+ tenantApplicationAccessType?: ApplicationAccessType;
10
11
  })[];
11
12
  }
12
13
  export type UserAppsAssignmentPayload = Pick<IAssignUserToApplicationsBody, 'userId' | 'appIds'>;
@@ -19,6 +19,7 @@ declare const _default: (store: FronteggState, api: RestApi, sharedActions: Shar
19
19
  loadRoles: (payload?: import("../../../interfaces").WithRetryConfig<import("../interfaces").LoadRolesAndPermissionsPayload>) => Promise<void>;
20
20
  loadUsers: (payload: WithCallback<import("../../../interfaces").WithSilentLoad<import("@frontegg/rest-api").ILoadUsers>, import("@frontegg/rest-api").ITeamUser[]>) => Promise<void>;
21
21
  loadUsersV2: (payload: WithCallback<import("../../../interfaces").WithRetryConfig<import("../../../interfaces").WithSilentLoad<import("../interfaces").IGetUsersV2Payload>>, import("@frontegg/rest-api").ITeamUser[]>) => Promise<void>;
22
+ loadUsersV3: (payload: WithCallback<import("../../../interfaces").WithRetryConfig<import("../../../interfaces").WithSilentLoad<import("../interfaces").IGetUsersV3Payload>>, import("@frontegg/rest-api").ITeamUser[]>) => Promise<void>;
22
23
  addUser: (payload: WithCallback<import("../interfaces").AddUserPayload, import("@frontegg/rest-api").ITeamUser>) => Promise<void>;
23
24
  addUsersBulk: (payload: WithCallback<import("../interfaces").IAddUsers, import("../interfaces").BulkInvintationData>) => Promise<void>;
24
25
  updateUser: (payload: WithCallback<import("@frontegg/rest-api").IUpdateUser, import("@frontegg/rest-api").ITeamUser>) => Promise<void>;
@@ -1,10 +1,11 @@
1
1
  import { IDeleteUser, ILoadUsers, ITeamUser, IUpdateUser, IUpdateUserExpiration } from '@frontegg/rest-api';
2
2
  import { FronteggState, RestApi, SharedActions, WithCallback, WithRetryConfig, WithSilentLoad } from '../../../interfaces';
3
- import { AddUserPayload, BulkInvintationData, IAddUsers, IGetUsersV2Payload, LoadRolesAndPermissionsPayload } from '../interfaces';
3
+ import { AddUserPayload, BulkInvintationData, IAddUsers, IGetUsersV2Payload, IGetUsersV3Payload, LoadRolesAndPermissionsPayload } from '../interfaces';
4
4
  declare const _default: (store: FronteggState, api: RestApi, sharedActions: SharedActions) => {
5
5
  loadRoles: (payload?: WithRetryConfig<LoadRolesAndPermissionsPayload>) => Promise<void>;
6
6
  loadUsers: (payload: WithCallback<WithSilentLoad<ILoadUsers>, ITeamUser[]>) => Promise<void>;
7
7
  loadUsersV2: (payload: WithCallback<WithRetryConfig<WithSilentLoad<IGetUsersV2Payload>>, ITeamUser[]>) => Promise<void>;
8
+ loadUsersV3: (payload: WithCallback<WithRetryConfig<WithSilentLoad<IGetUsersV3Payload>>, ITeamUser[]>) => Promise<void>;
8
9
  addUser: (payload: WithCallback<AddUserPayload, ITeamUser>) => Promise<void>;
9
10
  addUsersBulk: (payload: WithCallback<IAddUsers, BulkInvintationData>) => Promise<void>;
10
11
  updateUser: (payload: WithCallback<IUpdateUser, ITeamUser>) => Promise<void>;
@@ -64,7 +64,7 @@ export default ((store, api, sharedActions) => {
64
64
  });
65
65
  }
66
66
  };
67
- /*** @deprecated loadUsers is deprecated, use loadUsersV2 instead */
67
+ /*** @deprecated loadUsers is deprecated, use loadUsersV3 instead */
68
68
  const loadUsers = async payload => {
69
69
  var _payload$pageSize, _payload$pageOffset, _payload$filter, _payload$sort;
70
70
  const {
@@ -120,6 +120,8 @@ export default ((store, api, sharedActions) => {
120
120
  value: false
121
121
  });
122
122
  };
123
+
124
+ /*** @deprecated loadUsersV2 is deprecated, use loadUsersV3 instead */
123
125
  const loadUsersV2 = async payload => {
124
126
  var _payload$pageSize2, _payload$pageOffset2, _payload$filter2, _payload$sort2, _payload$shouldShowSu;
125
127
  const {
@@ -166,11 +168,7 @@ export default ((store, api, sharedActions) => {
166
168
  _offset: pageOffset,
167
169
  _limit: pageSize,
168
170
  _includeSubTenants: shouldIncludeSubTenants
169
- })), retryConfig), retryIfNeeded(() => api.teams.loadAvailableRoles(), retryConfig),
170
- // TODO: check rest-api types
171
- retryIfNeeded(() => api.teams.loadAvailablePermissions(), retryConfig),
172
- // TODO: check rest-api types
173
- __getGroupsForUsers(retryConfig), shouldLoadRoles ? loadRoles({
171
+ })), retryConfig), retryIfNeeded(() => api.teams.loadAvailableRoles(), retryConfig), retryIfNeeded(() => api.teams.loadAvailablePermissions(), retryConfig), __getGroupsForUsers(retryConfig), shouldLoadRoles ? loadRoles({
174
172
  retryConfig
175
173
  }) : undefined]);
176
174
 
@@ -215,6 +213,129 @@ export default ((store, api, sharedActions) => {
215
213
  value: false
216
214
  });
217
215
  };
216
+ const loadUsersV3 = async payload => {
217
+ var _payload$pageSize3, _payload$pageOffset3, _payload$sort3, _payload$shouldShowSu2;
218
+ const {
219
+ silentLoading,
220
+ callback,
221
+ shouldLoadRoles = true,
222
+ shouldLoadApps,
223
+ retryConfig
224
+ } = payload;
225
+ const teamState = store.auth.teamState;
226
+ const pageSize = (_payload$pageSize3 = payload.pageSize) != null ? _payload$pageSize3 : teamState.pageSize;
227
+ const pageOffset = (_payload$pageOffset3 = payload.pageOffset) != null ? _payload$pageOffset3 : teamState.pageOffset;
228
+ const sort = (_payload$sort3 = payload.sort) != null ? _payload$sort3 : teamState.sortV2;
229
+ const shouldIncludeSubTenants = (_payload$shouldShowSu2 = payload == null ? void 0 : payload.shouldShowSubTenantUsersIfReseller) != null ? _payload$shouldShowSu2 : teamState == null ? void 0 : teamState.shouldShowSubTenantUsersIfReseller;
230
+ actions.setTeamLoader({
231
+ key: TeamStateKeys.USERS,
232
+ value: !silentLoading
233
+ });
234
+ actions.setTeamState({
235
+ pageSize,
236
+ pageOffset
237
+ });
238
+ try {
239
+ // First fetch users with v3 API
240
+ const {
241
+ items: users,
242
+ _metadata: {
243
+ totalPages,
244
+ totalItems
245
+ }
246
+ } = await api.users.getUsersV3(_extends({}, sort && {
247
+ _sortBy: sort
248
+ }, payload.order && {
249
+ _order: payload.order
250
+ }, {
251
+ _offset: pageOffset,
252
+ _limit: pageSize,
253
+ _includeSubTenants: shouldIncludeSubTenants
254
+ }, getIdentifierFilterForUsersV3(payload)));
255
+
256
+ // Get user IDs for fetching roles and groups
257
+ const userIds = users.map(user => user.id);
258
+
259
+ // Fetch roles, permissions, user roles, user groups, and all groups in parallel
260
+ const [{
261
+ items: roles
262
+ }, permissions, userRoles, userGroups, groups] = await Promise.all([api.teams.loadAvailableRoles(), api.teams.loadAvailablePermissions(), userIds.length > 0 ? api.users.getUsersRoles({
263
+ ids: userIds
264
+ }) : [], userIds.length > 0 ? api.users.getUsersGroups({
265
+ ids: userIds
266
+ }) : [], __getGroupsForUsers(retryConfig), shouldLoadRoles ? loadRoles({
267
+ retryConfig
268
+ }) : undefined]);
269
+
270
+ // Map user roles and groups to users
271
+ const usersWithRolesAndGroups = users.map(user => {
272
+ // Find user's role IDs
273
+ const userRoleData = userRoles.find(ur => ur.userId === user.id);
274
+ const userRoleIds = (userRoleData == null ? void 0 : userRoleData.roleIds) || [];
275
+ const userRolesFull = roles.filter(role => userRoleIds.includes(role.id));
276
+
277
+ // Find user's group IDs
278
+ const userGroupData = userGroups.find(ug => ug.userId === user.id);
279
+ const userGroupIds = (userGroupData == null ? void 0 : userGroupData.groupIds) || [];
280
+ const userGroupsFull = groups.filter(g => userGroupIds.includes(g.id));
281
+
282
+ //@ts-ignore
283
+ return _extends({}, user, {
284
+ roles: userRolesFull,
285
+ roleIds: userRoleIds,
286
+ groups: userGroupsFull,
287
+ permissions: userRolesFull.flatMap(role => role.permissions)
288
+ });
289
+ });
290
+ const mappedUsers = await sharedActions.mapUsersWithApplicationData({
291
+ shouldLoadApps,
292
+ users: usersWithRolesAndGroups,
293
+ retryConfig
294
+ });
295
+ sharedActions.setTeamState({
296
+ users: mappedUsers,
297
+ totalPages,
298
+ totalItems,
299
+ roles,
300
+ permissions
301
+ });
302
+ callback == null ? void 0 : callback(usersWithRolesAndGroups);
303
+ } catch (e) {
304
+ console.error('Failed to load users v3', e);
305
+ actions.setTeamError({
306
+ key: TeamStateKeys.USERS,
307
+ value: errorHandler(e)
308
+ });
309
+ actions.setTeamState({
310
+ totalPages: 0,
311
+ users: []
312
+ });
313
+ callback == null ? void 0 : callback(null, e);
314
+ }
315
+ actions.setTeamLoader({
316
+ key: TeamStateKeys.USERS,
317
+ value: false
318
+ });
319
+ };
320
+ const getIdentifierFilterForUsersV3 = payload => {
321
+ const {
322
+ identifier,
323
+ identifierType,
324
+ email
325
+ } = payload;
326
+ if (identifierType === 'username' && identifier != null && identifier.length) {
327
+ return {
328
+ _identifier: identifier,
329
+ _identifierType: 'username'
330
+ };
331
+ }
332
+ if (email != null && email.length) {
333
+ return {
334
+ _email: email
335
+ };
336
+ }
337
+ return {};
338
+ };
218
339
  const addUser = async payload => {
219
340
  const {
220
341
  callback,
@@ -236,7 +357,9 @@ export default ((store, api, sharedActions) => {
236
357
  userWithoutRoleIds = _objectWithoutPropertiesLoose(res, _excluded2);
237
358
  const roleIds = (_roles$map = roles == null ? void 0 : roles.map(role => role.id)) != null ? _roles$map : [];
238
359
  const newUser = _extends({}, userWithoutRoleIds, {
239
- roleIds
360
+ roleIds,
361
+ roles: roles || [],
362
+ groups: []
240
363
  });
241
364
  const apps = await sharedActions.assignNewUserToApps({
242
365
  appIds,
@@ -572,6 +695,7 @@ export default ((store, api, sharedActions) => {
572
695
  loadRoles,
573
696
  loadUsers,
574
697
  loadUsersV2,
698
+ loadUsersV3,
575
699
  addUser,
576
700
  addUsersBulk,
577
701
  updateUser,
@@ -1,4 +1,4 @@
1
- import { ITeamUserRole, ITeamUser, ITeamUserPermission, ISubTenantUser, SortByEnum, ISearchUserQueryParamsV2, QueryFilter, QuerySort, IRole, IUsersV3Data, ITemporaryUserConfiguration, IAddUser, FronteggApiError } from '@frontegg/rest-api';
1
+ import { ITeamUserRole, ITeamUser, ITeamUserPermission, ISubTenantUser, SortByEnum, ISearchUserQueryParamsV2, QueryFilter, QuerySort, IRole, IUsersV3Data, ITemporaryUserConfiguration, IAddUser, FronteggApiError, ISearchUserQueryParamsV3 } from '@frontegg/rest-api';
2
2
  import { GroupsState } from '../GroupsState/interfaces';
3
3
  import { LoaderIndicatorState, WithCallback } from '../../interfaces';
4
4
  import { ApplicationsState } from '../ApplicationsState/interfaces';
@@ -112,6 +112,18 @@ export interface IGetUsersV2Payload {
112
112
  shouldLoadApps?: boolean;
113
113
  shouldLoadRoles?: boolean;
114
114
  }
115
+ export interface IGetUsersV3Payload {
116
+ pageSize?: ISearchUserQueryParamsV3['_limit'];
117
+ pageOffset?: ISearchUserQueryParamsV3['_offset'];
118
+ email?: ISearchUserQueryParamsV3['_email'];
119
+ sort?: ISearchUserQueryParamsV3['_sortBy'];
120
+ order?: ISearchUserQueryParamsV3['_order'];
121
+ shouldShowSubTenantUsersIfReseller?: ISearchUserQueryParamsV3['_includeSubTenants'];
122
+ shouldLoadApps?: boolean;
123
+ shouldLoadRoles?: boolean;
124
+ identifier?: ISearchUserQueryParamsV3['_identifier'];
125
+ identifierType?: ISearchUserQueryParamsV3['_identifierType'];
126
+ }
115
127
  export interface IUserV3 extends IUsersV3Data {
116
128
  roles?: IRole[];
117
129
  }
package/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /** @license Frontegg v7.80.0
1
+ /** @license Frontegg v7.81.0-alpha.1
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.
@@ -14,6 +14,7 @@ declare const _default: (store: FronteggState, api: RestApi, actions: SharedActi
14
14
  user: import("dist/@frontegg/rest-api").ITeamUser;
15
15
  }) => Promise<((import("dist/@frontegg/rest-api").IApplicationsResponse & {
16
16
  userIds?: string[];
17
+ tenantApplicationAccessType?: import("dist/@frontegg/rest-api").ApplicationAccessType;
17
18
  }) | never[])[] | undefined>;
18
19
  mapUsersWithApplicationData: ({ shouldLoadApps, users, retryConfig, }: import("../../interfaces").WithRetryConfig<{
19
20
  shouldLoadApps?: boolean;
@@ -19,6 +19,7 @@ declare const _default: (store: FronteggState, api: RestApi, actions: SharedActi
19
19
  loadRoles: (payload?: import("../../interfaces").WithRetryConfig<LoadRolesAndPermissionsPayload>) => Promise<void>;
20
20
  loadUsers: (payload: WithCallback<WithSilentLoad<import("@frontegg/rest-api").ILoadUsers>, ITeamUser[]>) => Promise<void>;
21
21
  loadUsersV2: (payload: WithCallback<import("../../interfaces").WithRetryConfig<WithSilentLoad<IGetUsersV2Payload>>, ITeamUser[]>) => Promise<void>;
22
+ loadUsersV3: (payload: WithCallback<import("../../interfaces").WithRetryConfig<WithSilentLoad<import("../../auth").IGetUsersV3Payload>>, ITeamUser[]>) => Promise<void>;
22
23
  addUser: (payload: WithCallback<import("../../auth").AddUserPayload, ITeamUser>) => Promise<void>;
23
24
  addUsersBulk: (payload: WithCallback<import("../../auth").IAddUsers, import("../../auth").BulkInvintationData>) => Promise<void>;
24
25
  updateUser: (payload: WithCallback<IUpdateUser, ITeamUser>) => Promise<void>;
@@ -20,7 +20,7 @@ import { mockActionsExpect } from '../helpers';
20
20
  export default ((store, api, actions) => {
21
21
  const originalActions = buildTeamActions(store, api, actions);
22
22
  const mockedActions = mockActionsExpect(originalActions, ['setTeamState', 'resetTeamState', 'setTeamLoader', 'setTeamError', 'openAddUserDialog', 'closeAddUserDialog', 'openDeleteUserDialog', 'closeDeleteUserDialog']);
23
- mockedActions.loadUsersV2 = async payload => {
23
+ mockedActions.loadUsersV3 = async payload => {
24
24
  var _payload$pageSize, _payload$pageOffset, _payload$filter, _payload$sort;
25
25
  const {
26
26
  silentLoading,
@@ -53,18 +53,30 @@ var _default = (store, api, sharedActions) => {
53
53
  fetching: true
54
54
  });
55
55
  try {
56
- const tenantAppIds = await (0, _helpers.retryIfNeeded)(() => api.applications.getTenantsApplications(), retryConfig);
57
- const appIds = (0, _helpers2.getFlattenAppIds)(tenantAppIds);
56
+ const tenantAppAssignments = await (0, _helpers.retryIfNeeded)(() => api.applications.getTenantsApplicationsV2(), retryConfig);
57
+
58
+ // Extract appIds from the new assignments structure
59
+ const appIds = [...new Set(tenantAppAssignments.flatMap(tenant => tenant.assignments.map(assignment => assignment.appId)))];
58
60
  const accountApplications = await (0, _helpers.retryIfNeeded)(() => api.applications.getApplicationsData({
59
61
  appIds
60
62
  }), retryConfig);
61
63
  const usersOfApplications = await (0, _helpers.retryIfNeeded)(() => api.applications.getUsersOfApplications({
62
64
  appIds
63
65
  }), retryConfig);
66
+
67
+ // Create a map of appId to accessType from tenant assignments (once)
68
+ const appAccessTypeMap = new Map();
69
+ tenantAppAssignments.forEach(tenant => {
70
+ tenant.assignments.forEach(assignment => {
71
+ appAccessTypeMap.set(assignment.appId, assignment.accessType);
72
+ });
73
+ });
64
74
  const accountApplicationsWithUsers = accountApplications.map(app => {
65
75
  var _usersOfApplications$;
66
76
  return (0, _extends2.default)({}, app, {
67
- userIds: (_usersOfApplications$ = usersOfApplications.find(u => u.appId === app.id)) == null ? void 0 : _usersOfApplications$.userIds
77
+ userIds: (_usersOfApplications$ = usersOfApplications.find(u => u.appId === app.id)) == null ? void 0 : _usersOfApplications$.userIds,
78
+ // Add tenant-specific access type as a separate attribute
79
+ tenantApplicationAccessType: appAccessTypeMap.get(app.id)
68
80
  });
69
81
  });
70
82
  setApplicationsState({
@@ -71,7 +71,7 @@ var _default = (store, api, sharedActions) => {
71
71
  });
72
72
  }
73
73
  };
74
- /*** @deprecated loadUsers is deprecated, use loadUsersV2 instead */
74
+ /*** @deprecated loadUsers is deprecated, use loadUsersV3 instead */
75
75
  const loadUsers = async payload => {
76
76
  var _payload$pageSize, _payload$pageOffset, _payload$filter, _payload$sort;
77
77
  const {
@@ -127,6 +127,8 @@ var _default = (store, api, sharedActions) => {
127
127
  value: false
128
128
  });
129
129
  };
130
+
131
+ /*** @deprecated loadUsersV2 is deprecated, use loadUsersV3 instead */
130
132
  const loadUsersV2 = async payload => {
131
133
  var _payload$pageSize2, _payload$pageOffset2, _payload$filter2, _payload$sort2, _payload$shouldShowSu;
132
134
  const {
@@ -173,11 +175,7 @@ var _default = (store, api, sharedActions) => {
173
175
  _offset: pageOffset,
174
176
  _limit: pageSize,
175
177
  _includeSubTenants: shouldIncludeSubTenants
176
- })), retryConfig), (0, _helpers.retryIfNeeded)(() => api.teams.loadAvailableRoles(), retryConfig),
177
- // TODO: check rest-api types
178
- (0, _helpers.retryIfNeeded)(() => api.teams.loadAvailablePermissions(), retryConfig),
179
- // TODO: check rest-api types
180
- __getGroupsForUsers(retryConfig), shouldLoadRoles ? loadRoles({
178
+ })), retryConfig), (0, _helpers.retryIfNeeded)(() => api.teams.loadAvailableRoles(), retryConfig), (0, _helpers.retryIfNeeded)(() => api.teams.loadAvailablePermissions(), retryConfig), __getGroupsForUsers(retryConfig), shouldLoadRoles ? loadRoles({
181
179
  retryConfig
182
180
  }) : undefined]);
183
181
 
@@ -222,6 +220,129 @@ var _default = (store, api, sharedActions) => {
222
220
  value: false
223
221
  });
224
222
  };
223
+ const loadUsersV3 = async payload => {
224
+ var _payload$pageSize3, _payload$pageOffset3, _payload$sort3, _payload$shouldShowSu2;
225
+ const {
226
+ silentLoading,
227
+ callback,
228
+ shouldLoadRoles = true,
229
+ shouldLoadApps,
230
+ retryConfig
231
+ } = payload;
232
+ const teamState = store.auth.teamState;
233
+ const pageSize = (_payload$pageSize3 = payload.pageSize) != null ? _payload$pageSize3 : teamState.pageSize;
234
+ const pageOffset = (_payload$pageOffset3 = payload.pageOffset) != null ? _payload$pageOffset3 : teamState.pageOffset;
235
+ const sort = (_payload$sort3 = payload.sort) != null ? _payload$sort3 : teamState.sortV2;
236
+ const shouldIncludeSubTenants = (_payload$shouldShowSu2 = payload == null ? void 0 : payload.shouldShowSubTenantUsersIfReseller) != null ? _payload$shouldShowSu2 : teamState == null ? void 0 : teamState.shouldShowSubTenantUsersIfReseller;
237
+ actions.setTeamLoader({
238
+ key: _interfaces.TeamStateKeys.USERS,
239
+ value: !silentLoading
240
+ });
241
+ actions.setTeamState({
242
+ pageSize,
243
+ pageOffset
244
+ });
245
+ try {
246
+ // First fetch users with v3 API
247
+ const {
248
+ items: users,
249
+ _metadata: {
250
+ totalPages,
251
+ totalItems
252
+ }
253
+ } = await api.users.getUsersV3((0, _extends2.default)({}, sort && {
254
+ _sortBy: sort
255
+ }, payload.order && {
256
+ _order: payload.order
257
+ }, {
258
+ _offset: pageOffset,
259
+ _limit: pageSize,
260
+ _includeSubTenants: shouldIncludeSubTenants
261
+ }, getIdentifierFilterForUsersV3(payload)));
262
+
263
+ // Get user IDs for fetching roles and groups
264
+ const userIds = users.map(user => user.id);
265
+
266
+ // Fetch roles, permissions, user roles, user groups, and all groups in parallel
267
+ const [{
268
+ items: roles
269
+ }, permissions, userRoles, userGroups, groups] = await Promise.all([api.teams.loadAvailableRoles(), api.teams.loadAvailablePermissions(), userIds.length > 0 ? api.users.getUsersRoles({
270
+ ids: userIds
271
+ }) : [], userIds.length > 0 ? api.users.getUsersGroups({
272
+ ids: userIds
273
+ }) : [], __getGroupsForUsers(retryConfig), shouldLoadRoles ? loadRoles({
274
+ retryConfig
275
+ }) : undefined]);
276
+
277
+ // Map user roles and groups to users
278
+ const usersWithRolesAndGroups = users.map(user => {
279
+ // Find user's role IDs
280
+ const userRoleData = userRoles.find(ur => ur.userId === user.id);
281
+ const userRoleIds = (userRoleData == null ? void 0 : userRoleData.roleIds) || [];
282
+ const userRolesFull = roles.filter(role => userRoleIds.includes(role.id));
283
+
284
+ // Find user's group IDs
285
+ const userGroupData = userGroups.find(ug => ug.userId === user.id);
286
+ const userGroupIds = (userGroupData == null ? void 0 : userGroupData.groupIds) || [];
287
+ const userGroupsFull = groups.filter(g => userGroupIds.includes(g.id));
288
+
289
+ //@ts-ignore
290
+ return (0, _extends2.default)({}, user, {
291
+ roles: userRolesFull,
292
+ roleIds: userRoleIds,
293
+ groups: userGroupsFull,
294
+ permissions: userRolesFull.flatMap(role => role.permissions)
295
+ });
296
+ });
297
+ const mappedUsers = await sharedActions.mapUsersWithApplicationData({
298
+ shouldLoadApps,
299
+ users: usersWithRolesAndGroups,
300
+ retryConfig
301
+ });
302
+ sharedActions.setTeamState({
303
+ users: mappedUsers,
304
+ totalPages,
305
+ totalItems,
306
+ roles,
307
+ permissions
308
+ });
309
+ callback == null ? void 0 : callback(usersWithRolesAndGroups);
310
+ } catch (e) {
311
+ console.error('Failed to load users v3', e);
312
+ actions.setTeamError({
313
+ key: _interfaces.TeamStateKeys.USERS,
314
+ value: (0, _helpers.errorHandler)(e)
315
+ });
316
+ actions.setTeamState({
317
+ totalPages: 0,
318
+ users: []
319
+ });
320
+ callback == null ? void 0 : callback(null, e);
321
+ }
322
+ actions.setTeamLoader({
323
+ key: _interfaces.TeamStateKeys.USERS,
324
+ value: false
325
+ });
326
+ };
327
+ const getIdentifierFilterForUsersV3 = payload => {
328
+ const {
329
+ identifier,
330
+ identifierType,
331
+ email
332
+ } = payload;
333
+ if (identifierType === 'username' && identifier != null && identifier.length) {
334
+ return {
335
+ _identifier: identifier,
336
+ _identifierType: 'username'
337
+ };
338
+ }
339
+ if (email != null && email.length) {
340
+ return {
341
+ _email: email
342
+ };
343
+ }
344
+ return {};
345
+ };
225
346
  const addUser = async payload => {
226
347
  const {
227
348
  callback,
@@ -243,7 +364,9 @@ var _default = (store, api, sharedActions) => {
243
364
  userWithoutRoleIds = (0, _objectWithoutPropertiesLoose2.default)(res, _excluded2);
244
365
  const roleIds = (_roles$map = roles == null ? void 0 : roles.map(role => role.id)) != null ? _roles$map : [];
245
366
  const newUser = (0, _extends2.default)({}, userWithoutRoleIds, {
246
- roleIds
367
+ roleIds,
368
+ roles: roles || [],
369
+ groups: []
247
370
  });
248
371
  const apps = await sharedActions.assignNewUserToApps({
249
372
  appIds,
@@ -579,6 +702,7 @@ var _default = (store, api, sharedActions) => {
579
702
  loadRoles,
580
703
  loadUsers,
581
704
  loadUsersV2,
705
+ loadUsersV3,
582
706
  addUser,
583
707
  addUsersBulk,
584
708
  updateUser,
package/node/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /** @license Frontegg v7.80.0
1
+ /** @license Frontegg v7.81.0-alpha.1
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,7 @@ const _excluded = ["callback"],
27
27
  var _default = (store, api, actions) => {
28
28
  const originalActions = (0, _TeamState.buildTeamActions)(store, api, actions);
29
29
  const mockedActions = (0, _helpers2.mockActionsExpect)(originalActions, ['setTeamState', 'resetTeamState', 'setTeamLoader', 'setTeamError', 'openAddUserDialog', 'closeAddUserDialog', 'openDeleteUserDialog', 'closeDeleteUserDialog']);
30
- mockedActions.loadUsersV2 = async payload => {
30
+ mockedActions.loadUsersV3 = async payload => {
31
31
  var _payload$pageSize, _payload$pageOffset, _payload$filter, _payload$sort;
32
32
  const {
33
33
  silentLoading,
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@frontegg/redux-store",
3
- "version": "7.80.0",
3
+ "version": "7.81.0-alpha.1",
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
9
  "@frontegg/entitlements-javascript-commons": "1.1.2",
10
- "@frontegg/rest-api": "7.80.0",
10
+ "@frontegg/rest-api": "7.81.0-alpha.1",
11
11
  "fast-deep-equal": "3.1.3",
12
12
  "get-value": "^3.0.1",
13
13
  "proxy-compare": "^3.0.0",