@frontegg/redux-store 7.99.0 → 7.100.0-alpha.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.
@@ -11,14 +11,35 @@ export default ((store, api, sharedActions) => {
11
11
  const resetProfileState = () => {
12
12
  deepResetState(store, ['auth', 'profileState'], initialState);
13
13
  };
14
+
15
+ /**
16
+ * Helper function to preserve groups from currentUser if profile doesn't have them
17
+ * The authorization API returns merged roles/permissions but may not include groups array
18
+ * @param profileData - User profile data from API (may or may not have groups)
19
+ * @param currentUser - Current user from store (has groups if they were loaded before)
20
+ * @returns Groups array to use (prefers profile.groups if they exist, otherwise currentUser.groups)
21
+ */
22
+ const preserveGroups = (profileData, currentUser) => {
23
+ if (profileData != null && profileData.groups && profileData.groups.length > 0) {
24
+ return profileData.groups;
25
+ }
26
+ if (currentUser != null && currentUser.groups && currentUser.groups.length > 0) {
27
+ return currentUser.groups;
28
+ }
29
+ return profileData == null ? void 0 : profileData.groups;
30
+ };
14
31
  const loadProfile = async () => {
15
32
  setProfileState({
16
33
  loading: true
17
34
  });
18
35
  try {
19
- const profile = await retry(api.teams.getProfile, 3, 2000);
36
+ const profile = await retry(api.auth.getMeAndEntitlements, 3, 2000);
20
37
  const currentUser = store.auth.user;
21
- actions.setUser(_extends({}, currentUser, profile));
38
+ const preservedGroups = preserveGroups(profile, currentUser);
39
+ const mergedUser = _extends({}, currentUser, profile, {
40
+ groups: preservedGroups
41
+ });
42
+ actions.setUser(mergedUser);
22
43
  setProfileState({
23
44
  profile,
24
45
  loading: false
@@ -117,13 +138,16 @@ export default ((store, api, sharedActions) => {
117
138
  const newProfileData = _extends({}, oldProfileData, payload, {
118
139
  profilePictureUrl: newProfilePictureUrl
119
140
  });
120
-
121
- //TODO: change the payload type to IUpdateUserProfile which is the right type to send, currently we send more data then actually needed.
122
- const profile = await api.users.updateUserProfileV2(newProfileData);
141
+ await api.users.updateUserProfileV2(newProfileData);
123
142
  const currentUser = store.auth.user;
124
- actions.setUser(_extends({}, currentUser, profile));
143
+ const completeUserData = await retry(api.auth.getMeAndEntitlements, 3, 2000);
144
+ const preservedGroups = preserveGroups(completeUserData, currentUser);
145
+ const mergedUser = _extends({}, currentUser, completeUserData, {
146
+ groups: preservedGroups
147
+ });
148
+ actions.setUser(mergedUser);
125
149
  actions.setProfileState({
126
- profile,
150
+ profile: completeUserData,
127
151
  saving: false,
128
152
  loading: false
129
153
  });
package/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /** @license Frontegg v7.99.0
1
+ /** @license Frontegg v7.100.0-alpha.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.
@@ -18,14 +18,35 @@ var _default = (store, api, sharedActions) => {
18
18
  const resetProfileState = () => {
19
19
  (0, _helpers.deepResetState)(store, ['auth', 'profileState'], _state.initialState);
20
20
  };
21
+
22
+ /**
23
+ * Helper function to preserve groups from currentUser if profile doesn't have them
24
+ * The authorization API returns merged roles/permissions but may not include groups array
25
+ * @param profileData - User profile data from API (may or may not have groups)
26
+ * @param currentUser - Current user from store (has groups if they were loaded before)
27
+ * @returns Groups array to use (prefers profile.groups if they exist, otherwise currentUser.groups)
28
+ */
29
+ const preserveGroups = (profileData, currentUser) => {
30
+ if (profileData != null && profileData.groups && profileData.groups.length > 0) {
31
+ return profileData.groups;
32
+ }
33
+ if (currentUser != null && currentUser.groups && currentUser.groups.length > 0) {
34
+ return currentUser.groups;
35
+ }
36
+ return profileData == null ? void 0 : profileData.groups;
37
+ };
21
38
  const loadProfile = async () => {
22
39
  setProfileState({
23
40
  loading: true
24
41
  });
25
42
  try {
26
- const profile = await (0, _helpers.retry)(api.teams.getProfile, 3, 2000);
43
+ const profile = await (0, _helpers.retry)(api.auth.getMeAndEntitlements, 3, 2000);
27
44
  const currentUser = store.auth.user;
28
- actions.setUser((0, _extends2.default)({}, currentUser, profile));
45
+ const preservedGroups = preserveGroups(profile, currentUser);
46
+ const mergedUser = (0, _extends2.default)({}, currentUser, profile, {
47
+ groups: preservedGroups
48
+ });
49
+ actions.setUser(mergedUser);
29
50
  setProfileState({
30
51
  profile,
31
52
  loading: false
@@ -124,13 +145,16 @@ var _default = (store, api, sharedActions) => {
124
145
  const newProfileData = (0, _extends2.default)({}, oldProfileData, payload, {
125
146
  profilePictureUrl: newProfilePictureUrl
126
147
  });
127
-
128
- //TODO: change the payload type to IUpdateUserProfile which is the right type to send, currently we send more data then actually needed.
129
- const profile = await api.users.updateUserProfileV2(newProfileData);
148
+ await api.users.updateUserProfileV2(newProfileData);
130
149
  const currentUser = store.auth.user;
131
- actions.setUser((0, _extends2.default)({}, currentUser, profile));
150
+ const completeUserData = await (0, _helpers.retry)(api.auth.getMeAndEntitlements, 3, 2000);
151
+ const preservedGroups = preserveGroups(completeUserData, currentUser);
152
+ const mergedUser = (0, _extends2.default)({}, currentUser, completeUserData, {
153
+ groups: preservedGroups
154
+ });
155
+ actions.setUser(mergedUser);
132
156
  actions.setProfileState({
133
- profile,
157
+ profile: completeUserData,
134
158
  saving: false,
135
159
  loading: false
136
160
  });
package/node/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /** @license Frontegg v7.99.0
1
+ /** @license Frontegg v7.100.0-alpha.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.
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@frontegg/redux-store",
3
- "version": "7.99.0",
3
+ "version": "7.100.0-alpha.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
9
  "@frontegg/entitlements-javascript-commons": "1.1.2",
10
- "@frontegg/rest-api": "7.99.0",
10
+ "@frontegg/rest-api": "7.100.0-alpha.0",
11
11
  "fast-deep-equal": "3.1.3",
12
12
  "get-value": "^3.0.1",
13
13
  "proxy-compare": "^3.0.0",