@frontegg/redux-store 7.81.0 → 7.82.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.
@@ -90,17 +90,40 @@ export default ((store, api, sharedActions) => {
90
90
  retryConfig
91
91
  }) => {
92
92
  try {
93
- const usersAppIds = await retryIfNeeded(() => api.applications.getUsersApplicationsId({
93
+ // Step 1: Fetch all assignment data in parallel
94
+ const [usersAppIds, tenantAppAssignments] = await Promise.all([retryIfNeeded(() => api.applications.getUsersApplicationsId({
94
95
  userIds
95
- }), retryConfig);
96
- const appIds = getFlattenAppIds(usersAppIds);
97
- const accountApplications = await retryIfNeeded(() => api.applications.getApplicationsData({
98
- appIds
99
- }), retryConfig);
96
+ }), retryConfig), retryIfNeeded(() => api.applications.getTenantsApplicationsV2(), retryConfig)]);
97
+
98
+ // Step 2: Identify tenant-level free apps
99
+ const tenantFreeAppIds = tenantAppAssignments.flatMap(tenant => tenant.assignments).filter(assignment => assignment.accessType === ApplicationAccessType.FREE_ACCESS).map(assignment => assignment.appId);
100
+
101
+ // Step 3: Get all app IDs that need to be fetched (user assignments + tenant-free apps)
102
+ const userAssignedAppIds = getFlattenAppIds(usersAppIds);
103
+ const appIdsToFetch = [...new Set([...userAssignedAppIds, ...tenantFreeAppIds])];
104
+
105
+ // Step 4: Fetch details for all apps
106
+ let fetchedAppsMap = new Map();
107
+ if (appIdsToFetch.length > 0) {
108
+ const fetchedApps = await retryIfNeeded(() => api.applications.getApplicationsData({
109
+ appIds: appIdsToFetch
110
+ }), retryConfig);
111
+ fetchedAppsMap = new Map(fetchedApps.map(app => [app.id, app]));
112
+ }
113
+
114
+ // Step 5: For each user, assemble their final list of applications.
100
115
  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 : [])];
116
+ var _usersAppIds$find$app, _usersAppIds$find;
117
+ const finalApps = [];
118
+ 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 : []);
119
+
120
+ // Add apps that are assigned to the user OR are app-level free OR are tenant-level free
121
+ fetchedAppsMap.forEach((app, appId) => {
122
+ if (userSpecificAppIds.has(appId) || app.accessType === ApplicationAccessType.FREE_ACCESS || tenantFreeAppIds.includes(appId)) {
123
+ finalApps.push(app);
124
+ }
125
+ });
126
+ acc[userId] = finalApps;
104
127
  return acc;
105
128
  }, {});
106
129
  } catch (e) {
@@ -186,7 +209,7 @@ export default ((store, api, sharedActions) => {
186
209
  return;
187
210
  }
188
211
  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 : [];
212
+ 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
213
  if (appIds != null && appIds.length) {
191
214
  var _store$auth$user$tena3, _store$auth7, _store$auth7$user;
192
215
  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 : '';
package/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /** @license Frontegg v7.81.0
1
+ /** @license Frontegg v7.82.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.
@@ -97,17 +97,40 @@ var _default = (store, api, sharedActions) => {
97
97
  retryConfig
98
98
  }) => {
99
99
  try {
100
- const usersAppIds = await (0, _helpers.retryIfNeeded)(() => api.applications.getUsersApplicationsId({
100
+ // Step 1: Fetch all assignment data in parallel
101
+ const [usersAppIds, tenantAppAssignments] = await Promise.all([(0, _helpers.retryIfNeeded)(() => api.applications.getUsersApplicationsId({
101
102
  userIds
102
- }), retryConfig);
103
- const appIds = (0, _helpers2.getFlattenAppIds)(usersAppIds);
104
- const accountApplications = await (0, _helpers.retryIfNeeded)(() => api.applications.getApplicationsData({
105
- appIds
106
- }), retryConfig);
103
+ }), retryConfig), (0, _helpers.retryIfNeeded)(() => api.applications.getTenantsApplicationsV2(), retryConfig)]);
104
+
105
+ // Step 2: Identify tenant-level free apps
106
+ const tenantFreeAppIds = tenantAppAssignments.flatMap(tenant => tenant.assignments).filter(assignment => assignment.accessType === _restApi.ApplicationAccessType.FREE_ACCESS).map(assignment => assignment.appId);
107
+
108
+ // Step 3: Get all app IDs that need to be fetched (user assignments + tenant-free apps)
109
+ const userAssignedAppIds = (0, _helpers2.getFlattenAppIds)(usersAppIds);
110
+ const appIdsToFetch = [...new Set([...userAssignedAppIds, ...tenantFreeAppIds])];
111
+
112
+ // Step 4: Fetch details for all apps
113
+ let fetchedAppsMap = new Map();
114
+ if (appIdsToFetch.length > 0) {
115
+ const fetchedApps = await (0, _helpers.retryIfNeeded)(() => api.applications.getApplicationsData({
116
+ appIds: appIdsToFetch
117
+ }), retryConfig);
118
+ fetchedAppsMap = new Map(fetchedApps.map(app => [app.id, app]));
119
+ }
120
+
121
+ // Step 5: For each user, assemble their final list of applications.
107
122
  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 : [])];
123
+ var _usersAppIds$find$app, _usersAppIds$find;
124
+ const finalApps = [];
125
+ 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 : []);
126
+
127
+ // Add apps that are assigned to the user OR are app-level free OR are tenant-level free
128
+ fetchedAppsMap.forEach((app, appId) => {
129
+ if (userSpecificAppIds.has(appId) || app.accessType === _restApi.ApplicationAccessType.FREE_ACCESS || tenantFreeAppIds.includes(appId)) {
130
+ finalApps.push(app);
131
+ }
132
+ });
133
+ acc[userId] = finalApps;
111
134
  return acc;
112
135
  }, {});
113
136
  } catch (e) {
@@ -193,7 +216,7 @@ var _default = (store, api, sharedActions) => {
193
216
  return;
194
217
  }
195
218
  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 : [];
219
+ 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
220
  if (appIds != null && appIds.length) {
198
221
  var _store$auth$user$tena3, _store$auth7, _store$auth7$user;
199
222
  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 : '';
package/node/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /** @license Frontegg v7.81.0
1
+ /** @license Frontegg v7.82.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.
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@frontegg/redux-store",
3
- "version": "7.81.0",
3
+ "version": "7.82.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.81.0",
10
+ "@frontegg/rest-api": "7.82.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",