@frontegg/redux-store 7.82.0-alpha.0 → 7.82.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.
@@ -2,7 +2,7 @@ import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import { ApplicationAccessType } from '@frontegg/rest-api';
3
3
  import { deepResetState, errorHandler, retryIfNeeded } from '../../helpers';
4
4
  import { initialState } from './state';
5
- import { getFlattenAppIds } from './helpers';
5
+ import { getFlattenAppIds, combineUserApplicationsWithTenantFreeAccess } from './helpers';
6
6
  export default ((store, api, sharedActions) => {
7
7
  const actions = sharedActions;
8
8
  const setApplicationsState = payload => {
@@ -11,6 +11,16 @@ export default ((store, api, sharedActions) => {
11
11
  const resetApplicationsState = () => {
12
12
  deepResetState(store, ['auth', 'applicationsState'], initialState);
13
13
  };
14
+ const updateCombinedUserApplications = () => {
15
+ const {
16
+ userApplications,
17
+ accountApplications
18
+ } = store.auth.applicationsState;
19
+ const combinedUserApplications = combineUserApplicationsWithTenantFreeAccess(userApplications, accountApplications);
20
+ setApplicationsState({
21
+ combinedUserApplications
22
+ });
23
+ };
14
24
  const loadUserApplications = async payload => {
15
25
  setApplicationsState({
16
26
  loading: true,
@@ -31,6 +41,7 @@ export default ((store, api, sharedActions) => {
31
41
  fetching: false,
32
42
  loading: false
33
43
  });
44
+ updateCombinedUserApplications();
34
45
  } catch (e) {
35
46
  setApplicationsState({
36
47
  loading: false,
@@ -77,6 +88,7 @@ export default ((store, api, sharedActions) => {
77
88
  fetching: false,
78
89
  loading: false
79
90
  });
91
+ updateCombinedUserApplications();
80
92
  } catch (e) {
81
93
  setApplicationsState({
82
94
  loading: false,
@@ -90,17 +102,40 @@ export default ((store, api, sharedActions) => {
90
102
  retryConfig
91
103
  }) => {
92
104
  try {
93
- const usersAppIds = await retryIfNeeded(() => api.applications.getUsersApplicationsId({
105
+ // Step 1: Fetch all assignment data in parallel
106
+ const [usersAppIds, tenantAppAssignments] = await Promise.all([retryIfNeeded(() => api.applications.getUsersApplicationsId({
94
107
  userIds
95
- }), retryConfig);
96
- const appIds = getFlattenAppIds(usersAppIds);
97
- const accountApplications = await retryIfNeeded(() => api.applications.getApplicationsData({
98
- appIds
99
- }), retryConfig);
108
+ }), retryConfig), retryIfNeeded(() => api.applications.getTenantsApplicationsV2(), retryConfig)]);
109
+
110
+ // Step 2: Identify tenant-level free apps
111
+ const tenantFreeAppIds = tenantAppAssignments.flatMap(tenant => tenant.assignments).filter(assignment => assignment.accessType === ApplicationAccessType.FREE_ACCESS).map(assignment => assignment.appId);
112
+
113
+ // Step 3: Get all app IDs that need to be fetched (user assignments + tenant-free apps)
114
+ const userAssignedAppIds = getFlattenAppIds(usersAppIds);
115
+ const appIdsToFetch = [...new Set([...userAssignedAppIds, ...tenantFreeAppIds])];
116
+
117
+ // Step 4: Fetch details for all apps
118
+ let fetchedAppsMap = new Map();
119
+ if (appIdsToFetch.length > 0) {
120
+ const fetchedApps = await retryIfNeeded(() => api.applications.getApplicationsData({
121
+ appIds: appIdsToFetch
122
+ }), retryConfig);
123
+ fetchedAppsMap = new Map(fetchedApps.map(app => [app.id, app]));
124
+ }
125
+
126
+ // Step 5: For each user, assemble their final list of applications.
100
127
  return userIds.reduce((acc, userId) => {
101
- var _usersAppIds$find, _userAppIds$map$filte, _userAppIds$map;
102
- const userAppIds = (_usersAppIds$find = usersAppIds.find(app => app.userId == userId)) == null ? void 0 : _usersAppIds$find.appIds;
103
- acc[userId] = [...accountApplications.filter(app => app.accessType === ApplicationAccessType.FREE_ACCESS), ...((_userAppIds$map$filte = userAppIds == null ? void 0 : (_userAppIds$map = userAppIds.map(appId => accountApplications.find(app => appId === app.id))) == null ? void 0 : _userAppIds$map.filter(app => !!app)) != null ? _userAppIds$map$filte : [])];
128
+ var _usersAppIds$find$app, _usersAppIds$find;
129
+ const finalApps = [];
130
+ const userSpecificAppIds = new Set((_usersAppIds$find$app = (_usersAppIds$find = usersAppIds.find(app => app.userId === userId)) == null ? void 0 : _usersAppIds$find.appIds) != null ? _usersAppIds$find$app : []);
131
+
132
+ // Add apps that are assigned to the user OR are app-level free OR are tenant-level free
133
+ fetchedAppsMap.forEach((app, appId) => {
134
+ if (userSpecificAppIds.has(appId) || app.accessType === ApplicationAccessType.FREE_ACCESS || tenantFreeAppIds.includes(appId)) {
135
+ finalApps.push(app);
136
+ }
137
+ });
138
+ acc[userId] = finalApps;
104
139
  return acc;
105
140
  }, {});
106
141
  } catch (e) {
@@ -186,7 +221,7 @@ export default ((store, api, sharedActions) => {
186
221
  return;
187
222
  }
188
223
  const apps = (_store$auth6 = store.auth) == null ? void 0 : (_store$auth6$applicat = _store$auth6.applicationsState) == null ? void 0 : _store$auth6$applicat.accountApplications;
189
- const defaultApps = (_apps$filter = apps == null ? void 0 : apps.filter(app => app.accessType === ApplicationAccessType.FREE_ACCESS)) != null ? _apps$filter : [];
224
+ const defaultApps = (_apps$filter = apps == null ? void 0 : apps.filter(app => app.accessType === ApplicationAccessType.FREE_ACCESS || app.tenantApplicationAccessType === ApplicationAccessType.FREE_ACCESS)) != null ? _apps$filter : [];
190
225
  if (appIds != null && appIds.length) {
191
226
  var _store$auth$user$tena3, _store$auth7, _store$auth7$user;
192
227
  const tenantId = (_store$auth$user$tena3 = (_store$auth7 = store.auth) == null ? void 0 : (_store$auth7$user = _store$auth7.user) == null ? void 0 : _store$auth7$user.tenantId) != null ? _store$auth$user$tena3 : '';
@@ -1,3 +1,8 @@
1
+ import { ApplicationAccessType, IApplicationsResponse } from '@frontegg/rest-api';
1
2
  export declare const getFlattenAppIds: <T extends {
2
3
  appIds?: string[];
3
4
  }>(listWithAppIds: T[]) => string[];
5
+ export declare const combineUserApplicationsWithTenantFreeAccess: (userApplications?: IApplicationsResponse[], accountApplications?: (IApplicationsResponse & {
6
+ userIds?: string[];
7
+ tenantApplicationAccessType?: ApplicationAccessType;
8
+ })[]) => IApplicationsResponse[];
@@ -1,3 +1,4 @@
1
+ import { ApplicationAccessType } from '@frontegg/rest-api';
1
2
  export const getFlattenAppIds = listWithAppIds => {
2
3
  var _listWithAppIds$map$r;
3
4
  return (_listWithAppIds$map$r = listWithAppIds.map(({
@@ -10,4 +11,16 @@ export const getFlattenAppIds = listWithAppIds => {
10
11
  });
11
12
  return allAppIds;
12
13
  }, [])) != null ? _listWithAppIds$map$r : [];
14
+ };
15
+ export const combineUserApplicationsWithTenantFreeAccess = (userApplications, accountApplications) => {
16
+ if (!userApplications && !accountApplications) return [];
17
+ const userAppIds = new Set((userApplications == null ? void 0 : userApplications.map(app => app.id)) || []);
18
+ const tenantFreeApps = (accountApplications == null ? void 0 : accountApplications.filter(app => app.tenantApplicationAccessType === ApplicationAccessType.FREE_ACCESS)) || [];
19
+
20
+ // Add tenant-free apps that aren't already in user apps
21
+ const additionalApps = tenantFreeApps.filter(app => !userAppIds.has(app.id));
22
+
23
+ // Create a combined list
24
+ const combinedApps = [...(userApplications || []), ...additionalApps];
25
+ return combinedApps;
13
26
  };
@@ -9,5 +9,6 @@ export interface ApplicationsState {
9
9
  userIds?: string[];
10
10
  tenantApplicationAccessType?: ApplicationAccessType;
11
11
  })[];
12
+ combinedUserApplications?: IApplicationsResponse[];
12
13
  }
13
14
  export type UserAppsAssignmentPayload = Pick<IAssignUserToApplicationsBody, 'userId' | 'appIds'>;
@@ -4,6 +4,7 @@ export const initialState = {
4
4
  fetching: true,
5
5
  error: null,
6
6
  userApplications: [],
7
- accountApplications: []
7
+ accountApplications: [],
8
+ combinedUserApplications: []
8
9
  };
9
10
  export default (overrideState => createProxy(initialState, overrideState));
package/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /** @license Frontegg v7.82.0-alpha.0
1
+ /** @license Frontegg v7.82.0-alpha.2
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.
@@ -18,6 +18,16 @@ var _default = (store, api, sharedActions) => {
18
18
  const resetApplicationsState = () => {
19
19
  (0, _helpers.deepResetState)(store, ['auth', 'applicationsState'], _state.initialState);
20
20
  };
21
+ const updateCombinedUserApplications = () => {
22
+ const {
23
+ userApplications,
24
+ accountApplications
25
+ } = store.auth.applicationsState;
26
+ const combinedUserApplications = (0, _helpers2.combineUserApplicationsWithTenantFreeAccess)(userApplications, accountApplications);
27
+ setApplicationsState({
28
+ combinedUserApplications
29
+ });
30
+ };
21
31
  const loadUserApplications = async payload => {
22
32
  setApplicationsState({
23
33
  loading: true,
@@ -38,6 +48,7 @@ var _default = (store, api, sharedActions) => {
38
48
  fetching: false,
39
49
  loading: false
40
50
  });
51
+ updateCombinedUserApplications();
41
52
  } catch (e) {
42
53
  setApplicationsState({
43
54
  loading: false,
@@ -84,6 +95,7 @@ var _default = (store, api, sharedActions) => {
84
95
  fetching: false,
85
96
  loading: false
86
97
  });
98
+ updateCombinedUserApplications();
87
99
  } catch (e) {
88
100
  setApplicationsState({
89
101
  loading: false,
@@ -97,17 +109,40 @@ var _default = (store, api, sharedActions) => {
97
109
  retryConfig
98
110
  }) => {
99
111
  try {
100
- const usersAppIds = await (0, _helpers.retryIfNeeded)(() => api.applications.getUsersApplicationsId({
112
+ // Step 1: Fetch all assignment data in parallel
113
+ const [usersAppIds, tenantAppAssignments] = await Promise.all([(0, _helpers.retryIfNeeded)(() => api.applications.getUsersApplicationsId({
101
114
  userIds
102
- }), retryConfig);
103
- const appIds = (0, _helpers2.getFlattenAppIds)(usersAppIds);
104
- const accountApplications = await (0, _helpers.retryIfNeeded)(() => api.applications.getApplicationsData({
105
- appIds
106
- }), retryConfig);
115
+ }), retryConfig), (0, _helpers.retryIfNeeded)(() => api.applications.getTenantsApplicationsV2(), retryConfig)]);
116
+
117
+ // Step 2: Identify tenant-level free apps
118
+ const tenantFreeAppIds = tenantAppAssignments.flatMap(tenant => tenant.assignments).filter(assignment => assignment.accessType === _restApi.ApplicationAccessType.FREE_ACCESS).map(assignment => assignment.appId);
119
+
120
+ // Step 3: Get all app IDs that need to be fetched (user assignments + tenant-free apps)
121
+ const userAssignedAppIds = (0, _helpers2.getFlattenAppIds)(usersAppIds);
122
+ const appIdsToFetch = [...new Set([...userAssignedAppIds, ...tenantFreeAppIds])];
123
+
124
+ // Step 4: Fetch details for all apps
125
+ let fetchedAppsMap = new Map();
126
+ if (appIdsToFetch.length > 0) {
127
+ const fetchedApps = await (0, _helpers.retryIfNeeded)(() => api.applications.getApplicationsData({
128
+ appIds: appIdsToFetch
129
+ }), retryConfig);
130
+ fetchedAppsMap = new Map(fetchedApps.map(app => [app.id, app]));
131
+ }
132
+
133
+ // Step 5: For each user, assemble their final list of applications.
107
134
  return userIds.reduce((acc, userId) => {
108
- var _usersAppIds$find, _userAppIds$map$filte, _userAppIds$map;
109
- const userAppIds = (_usersAppIds$find = usersAppIds.find(app => app.userId == userId)) == null ? void 0 : _usersAppIds$find.appIds;
110
- acc[userId] = [...accountApplications.filter(app => app.accessType === _restApi.ApplicationAccessType.FREE_ACCESS), ...((_userAppIds$map$filte = userAppIds == null ? void 0 : (_userAppIds$map = userAppIds.map(appId => accountApplications.find(app => appId === app.id))) == null ? void 0 : _userAppIds$map.filter(app => !!app)) != null ? _userAppIds$map$filte : [])];
135
+ var _usersAppIds$find$app, _usersAppIds$find;
136
+ const finalApps = [];
137
+ const userSpecificAppIds = new Set((_usersAppIds$find$app = (_usersAppIds$find = usersAppIds.find(app => app.userId === userId)) == null ? void 0 : _usersAppIds$find.appIds) != null ? _usersAppIds$find$app : []);
138
+
139
+ // Add apps that are assigned to the user OR are app-level free OR are tenant-level free
140
+ fetchedAppsMap.forEach((app, appId) => {
141
+ if (userSpecificAppIds.has(appId) || app.accessType === _restApi.ApplicationAccessType.FREE_ACCESS || tenantFreeAppIds.includes(appId)) {
142
+ finalApps.push(app);
143
+ }
144
+ });
145
+ acc[userId] = finalApps;
111
146
  return acc;
112
147
  }, {});
113
148
  } catch (e) {
@@ -193,7 +228,7 @@ var _default = (store, api, sharedActions) => {
193
228
  return;
194
229
  }
195
230
  const apps = (_store$auth6 = store.auth) == null ? void 0 : (_store$auth6$applicat = _store$auth6.applicationsState) == null ? void 0 : _store$auth6$applicat.accountApplications;
196
- const defaultApps = (_apps$filter = apps == null ? void 0 : apps.filter(app => app.accessType === _restApi.ApplicationAccessType.FREE_ACCESS)) != null ? _apps$filter : [];
231
+ const defaultApps = (_apps$filter = apps == null ? void 0 : apps.filter(app => app.accessType === _restApi.ApplicationAccessType.FREE_ACCESS || app.tenantApplicationAccessType === _restApi.ApplicationAccessType.FREE_ACCESS)) != null ? _apps$filter : [];
197
232
  if (appIds != null && appIds.length) {
198
233
  var _store$auth$user$tena3, _store$auth7, _store$auth7$user;
199
234
  const tenantId = (_store$auth$user$tena3 = (_store$auth7 = store.auth) == null ? void 0 : (_store$auth7$user = _store$auth7.user) == null ? void 0 : _store$auth7$user.tenantId) != null ? _store$auth$user$tena3 : '';
@@ -3,7 +3,8 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.getFlattenAppIds = void 0;
6
+ exports.getFlattenAppIds = exports.combineUserApplicationsWithTenantFreeAccess = void 0;
7
+ var _restApi = require("@frontegg/rest-api");
7
8
  const getFlattenAppIds = listWithAppIds => {
8
9
  var _listWithAppIds$map$r;
9
10
  return (_listWithAppIds$map$r = listWithAppIds.map(({
@@ -17,4 +18,17 @@ const getFlattenAppIds = listWithAppIds => {
17
18
  return allAppIds;
18
19
  }, [])) != null ? _listWithAppIds$map$r : [];
19
20
  };
20
- exports.getFlattenAppIds = getFlattenAppIds;
21
+ exports.getFlattenAppIds = getFlattenAppIds;
22
+ const combineUserApplicationsWithTenantFreeAccess = (userApplications, accountApplications) => {
23
+ if (!userApplications && !accountApplications) return [];
24
+ const userAppIds = new Set((userApplications == null ? void 0 : userApplications.map(app => app.id)) || []);
25
+ const tenantFreeApps = (accountApplications == null ? void 0 : accountApplications.filter(app => app.tenantApplicationAccessType === _restApi.ApplicationAccessType.FREE_ACCESS)) || [];
26
+
27
+ // Add tenant-free apps that aren't already in user apps
28
+ const additionalApps = tenantFreeApps.filter(app => !userAppIds.has(app.id));
29
+
30
+ // Create a combined list
31
+ const combinedApps = [...(userApplications || []), ...additionalApps];
32
+ return combinedApps;
33
+ };
34
+ exports.combineUserApplicationsWithTenantFreeAccess = combineUserApplicationsWithTenantFreeAccess;
@@ -10,7 +10,8 @@ const initialState = {
10
10
  fetching: true,
11
11
  error: null,
12
12
  userApplications: [],
13
- accountApplications: []
13
+ accountApplications: [],
14
+ combinedUserApplications: []
14
15
  };
15
16
  exports.initialState = initialState;
16
17
  var _default = overrideState => (0, _proxy.createProxy)(initialState, overrideState);
package/node/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /** @license Frontegg v7.82.0-alpha.0
1
+ /** @license Frontegg v7.82.0-alpha.2
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.
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@frontegg/redux-store",
3
- "version": "7.82.0-alpha.0",
3
+ "version": "7.82.0-alpha.2",
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.82.0-alpha.0",
10
+ "@frontegg/rest-api": "7.82.0-alpha.2",
11
11
  "fast-deep-equal": "3.1.3",
12
12
  "get-value": "^3.0.1",
13
13
  "proxy-compare": "^3.0.0",