@frontegg/redux-store 7.0.0-alpha.2 → 7.0.0-alpha.3
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.
- package/auth/ApplicationsState/actions.d.ts +25 -0
- package/auth/ApplicationsState/actions.js +221 -0
- package/auth/ApplicationsState/helpers.d.ts +3 -0
- package/auth/ApplicationsState/helpers.js +13 -0
- package/auth/ApplicationsState/index.d.ts +3 -0
- package/auth/ApplicationsState/index.js +3 -0
- package/auth/ApplicationsState/interfaces.d.ts +12 -0
- package/auth/ApplicationsState/interfaces.js +1 -0
- package/auth/ApplicationsState/state.d.ts +4 -0
- package/auth/ApplicationsState/state.js +9 -0
- package/auth/Entitlements/actions.js +1 -4
- package/auth/Entitlements/helpers.d.ts +21 -22
- package/auth/Entitlements/helpers.js +23 -68
- package/auth/ImpersonateState/actions.js +7 -1
- package/auth/LoginState/actions/afterAuthNavigation.actions.d.ts +1 -1
- package/auth/LoginState/actions/afterAuthNavigation.actions.js +22 -10
- package/auth/LoginState/actions/hostedLoginAuthorize.actions.d.ts +1 -0
- package/auth/LoginState/actions/hostedLoginAuthorize.actions.js +1 -0
- package/auth/LoginState/actions/index.d.ts +2 -1
- package/auth/LoginState/actions/index.js +25 -8
- package/auth/LoginState/interfaces.d.ts +1 -0
- package/auth/MSP/actions.d.ts +1 -0
- package/auth/MSP/actions.js +76 -2
- package/auth/MSP/dialogs/actions.d.ts +5 -1
- package/auth/MSP/dialogs/actions.js +24 -0
- package/auth/MSP/dialogs/state.js +14 -0
- package/auth/MSP/helpers/getAccountsWithUsersCount.d.ts +1 -0
- package/auth/MSP/helpers/getAccountsWithUsersCount.js +2 -1
- package/auth/MSP/helpers/updateNodeIsReseller.d.ts +2 -0
- package/auth/MSP/helpers/updateNodeIsReseller.js +14 -0
- package/auth/MSP/interfaces/dialogsStateTypes.d.ts +8 -0
- package/auth/MSP/interfaces/stateTypes.d.ts +6 -1
- package/auth/MSP/interfaces/stateTypes.js +1 -0
- package/auth/RolesState/actions.d.ts +2 -1
- package/auth/RolesState/actions.js +36 -5
- package/auth/SSOState/actions/actions.v2.js +1 -1
- package/auth/SessionsState/actions.js +3 -0
- package/auth/SmsState/actions.js +5 -5
- package/auth/StepUpState/actions/stepUpHostedLogin.actions.js +1 -1
- package/auth/TeamState/actions/index.d.ts +2 -2
- package/auth/TeamState/actions/users.actions.d.ts +3 -3
- package/auth/TeamState/actions/users.actions.js +33 -9
- package/auth/TeamState/interfaces.d.ts +7 -1
- package/auth/TenantsState/actions.d.ts +3 -3
- package/auth/TenantsState/interfaces.d.ts +3 -1
- package/auth/index.d.ts +5 -1
- package/auth/index.js +5 -0
- package/auth/interfaces.d.ts +2 -0
- package/index.js +1 -1
- package/mocks/auth-mocks/allAccountsActions.mocks.d.ts +3 -0
- package/mocks/auth-mocks/applicationsActions.mocks.d.ts +23 -0
- package/mocks/auth-mocks/applicationsActions.mocks.js +7 -0
- package/mocks/auth-mocks/index.js +4 -1
- package/mocks/auth-mocks/loginActions.mocks.d.ts +2 -1
- package/mocks/auth-mocks/rolesActions.mocks.d.ts +1 -0
- package/mocks/auth-mocks/teamActions.mocks.d.ts +3 -3
- package/mocks/dummy.d.ts +3 -1
- package/mocks/dummy.js +382 -7
- package/node/auth/ApplicationsState/actions.js +229 -0
- package/node/auth/ApplicationsState/helpers.js +20 -0
- package/node/auth/ApplicationsState/index.js +20 -0
- package/node/auth/ApplicationsState/interfaces.js +5 -0
- package/node/auth/ApplicationsState/state.js +17 -0
- package/node/auth/Entitlements/actions.js +1 -4
- package/node/auth/Entitlements/helpers.js +22 -67
- package/node/auth/ImpersonateState/actions.js +7 -1
- package/node/auth/LoginState/actions/afterAuthNavigation.actions.js +22 -10
- package/node/auth/LoginState/actions/hostedLoginAuthorize.actions.js +1 -0
- package/node/auth/LoginState/actions/index.js +25 -8
- package/node/auth/MSP/actions.js +76 -2
- package/node/auth/MSP/dialogs/actions.js +24 -0
- package/node/auth/MSP/dialogs/state.js +14 -0
- package/node/auth/MSP/helpers/getAccountsWithUsersCount.js +2 -1
- package/node/auth/MSP/helpers/updateNodeIsReseller.js +22 -0
- package/node/auth/MSP/interfaces/stateTypes.js +1 -0
- package/node/auth/RolesState/actions.js +36 -5
- package/node/auth/SSOState/actions/actions.v2.js +1 -1
- package/node/auth/SessionsState/actions.js +3 -0
- package/node/auth/SmsState/actions.js +5 -5
- package/node/auth/StepUpState/actions/stepUpHostedLogin.actions.js +1 -1
- package/node/auth/TeamState/actions/users.actions.js +33 -9
- package/node/auth/index.js +50 -34
- package/node/index.js +1 -1
- package/node/mocks/auth-mocks/applicationsActions.mocks.js +14 -0
- package/node/mocks/auth-mocks/index.js +4 -1
- package/node/mocks/dummy.js +384 -7
- package/node/toolkit/FronteggNativeModule.js +6 -0
- package/package.json +2 -2
- package/toolkit/FronteggNativeModule.d.ts +2 -0
- package/toolkit/FronteggNativeModule.js +6 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { FronteggState, RestApi, SharedActions, WithCallback } from '../../interfaces';
|
|
2
|
+
import { ApplicationsState, UserAppsAssignmentPayload } from './interfaces';
|
|
3
|
+
import { IApplicationsResponse, ITeamUser } from '@frontegg/rest-api';
|
|
4
|
+
declare const _default: (store: FronteggState, api: RestApi, sharedActions: SharedActions) => {
|
|
5
|
+
setApplicationsState: (payload: Partial<ApplicationsState>) => void;
|
|
6
|
+
resetApplicationsState: () => void;
|
|
7
|
+
loadUserApplications: () => Promise<void>;
|
|
8
|
+
loadAccountApplications: () => Promise<void>;
|
|
9
|
+
loadMultipleUsersApplications: ({ userIds }: {
|
|
10
|
+
userIds: string[];
|
|
11
|
+
}) => Promise<Record<string, IApplicationsResponse[]> | undefined>;
|
|
12
|
+
assignUserToApps: (payload: WithCallback<UserAppsAssignmentPayload>) => Promise<void>;
|
|
13
|
+
unassignUserFromApps: (payload: WithCallback<UserAppsAssignmentPayload>) => Promise<void>;
|
|
14
|
+
assignNewUserToApps: ({ appIds, user }: {
|
|
15
|
+
appIds?: string[] | undefined;
|
|
16
|
+
user: ITeamUser;
|
|
17
|
+
}) => Promise<((IApplicationsResponse & {
|
|
18
|
+
userIds?: string[] | undefined;
|
|
19
|
+
}) | never[])[] | undefined>;
|
|
20
|
+
mapUsersWithApplicationData: ({ shouldLoadApps, users, }: {
|
|
21
|
+
shouldLoadApps?: boolean | undefined;
|
|
22
|
+
users: ITeamUser[];
|
|
23
|
+
}) => Promise<ITeamUser[]>;
|
|
24
|
+
};
|
|
25
|
+
export default _default;
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import { ApplicationAccessType } from '@frontegg/rest-api';
|
|
3
|
+
import { deepClone, errorHandler } from '../../helpers';
|
|
4
|
+
import { initialState } from './state';
|
|
5
|
+
import { getFlattenAppIds } from './helpers';
|
|
6
|
+
export default ((store, api, sharedActions) => {
|
|
7
|
+
const actions = sharedActions;
|
|
8
|
+
const setApplicationsState = payload => {
|
|
9
|
+
Object.assign(store.auth.applicationsState, payload);
|
|
10
|
+
};
|
|
11
|
+
const resetApplicationsState = () => {
|
|
12
|
+
store.auth.applicationsState = deepClone(initialState);
|
|
13
|
+
};
|
|
14
|
+
const loadUserApplications = async () => {
|
|
15
|
+
setApplicationsState({
|
|
16
|
+
loading: true,
|
|
17
|
+
fetching: true
|
|
18
|
+
});
|
|
19
|
+
try {
|
|
20
|
+
var _store$auth$user$id, _store$auth$user;
|
|
21
|
+
const userId = (_store$auth$user$id = (_store$auth$user = store.auth.user) == null ? void 0 : _store$auth$user.id) != null ? _store$auth$user$id : '';
|
|
22
|
+
const appIds = await api.applications.getUserApplicationsId({
|
|
23
|
+
userId
|
|
24
|
+
});
|
|
25
|
+
const userApplications = await api.applications.getApplicationsData({
|
|
26
|
+
appIds
|
|
27
|
+
});
|
|
28
|
+
setApplicationsState({
|
|
29
|
+
userApplications,
|
|
30
|
+
fetching: false,
|
|
31
|
+
loading: false
|
|
32
|
+
});
|
|
33
|
+
} catch (e) {
|
|
34
|
+
setApplicationsState({
|
|
35
|
+
loading: false,
|
|
36
|
+
fetching: false,
|
|
37
|
+
error: errorHandler(e)
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
const loadAccountApplications = async () => {
|
|
42
|
+
setApplicationsState({
|
|
43
|
+
loading: true,
|
|
44
|
+
fetching: true
|
|
45
|
+
});
|
|
46
|
+
try {
|
|
47
|
+
const tenantAppIds = await api.applications.getTenantsApplications();
|
|
48
|
+
const appIds = getFlattenAppIds(tenantAppIds);
|
|
49
|
+
const accountApplications = await api.applications.getApplicationsData({
|
|
50
|
+
appIds
|
|
51
|
+
});
|
|
52
|
+
const usersOfApplications = await api.applications.getUsersOfApplications({
|
|
53
|
+
appIds
|
|
54
|
+
});
|
|
55
|
+
const accountApplicationsWithUsers = accountApplications.map(app => {
|
|
56
|
+
var _usersOfApplications$;
|
|
57
|
+
return _extends({}, app, {
|
|
58
|
+
userIds: (_usersOfApplications$ = usersOfApplications.find(u => u.appId === app.id)) == null ? void 0 : _usersOfApplications$.userIds
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
setApplicationsState({
|
|
62
|
+
accountApplications: accountApplicationsWithUsers,
|
|
63
|
+
fetching: false,
|
|
64
|
+
loading: false
|
|
65
|
+
});
|
|
66
|
+
} catch (e) {
|
|
67
|
+
setApplicationsState({
|
|
68
|
+
loading: false,
|
|
69
|
+
fetching: false,
|
|
70
|
+
error: errorHandler(e)
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
const loadMultipleUsersApplications = async ({
|
|
75
|
+
userIds
|
|
76
|
+
}) => {
|
|
77
|
+
try {
|
|
78
|
+
const usersAppIds = await api.applications.getUsersApplicationsId({
|
|
79
|
+
userIds
|
|
80
|
+
});
|
|
81
|
+
const appIds = getFlattenAppIds(usersAppIds);
|
|
82
|
+
const accountApplications = await api.applications.getApplicationsData({
|
|
83
|
+
appIds
|
|
84
|
+
});
|
|
85
|
+
return userIds.reduce((acc, userId) => {
|
|
86
|
+
var _usersAppIds$find, _userAppIds$map$filte, _userAppIds$map;
|
|
87
|
+
const userAppIds = (_usersAppIds$find = usersAppIds.find(app => app.userId == userId)) == null ? void 0 : _usersAppIds$find.appIds;
|
|
88
|
+
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 : [])];
|
|
89
|
+
return acc;
|
|
90
|
+
}, {});
|
|
91
|
+
} catch (e) {
|
|
92
|
+
setApplicationsState({
|
|
93
|
+
error: errorHandler(e)
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
const ASSIGNMENT_DEFAULT_ERROR_MESSAGE = 'Assignment action failed. Try again or contact support.';
|
|
98
|
+
const assignUserToApps = async payload => {
|
|
99
|
+
const {
|
|
100
|
+
userId,
|
|
101
|
+
appIds,
|
|
102
|
+
callback
|
|
103
|
+
} = payload;
|
|
104
|
+
try {
|
|
105
|
+
var _store$auth$user$tena, _store$auth, _store$auth$user2, _store$auth2, _store$auth2$applicat, _store$auth$teamState, _store$auth3, _store$auth3$teamStat, _accountApps$filter;
|
|
106
|
+
const tenantId = (_store$auth$user$tena = (_store$auth = store.auth) == null ? void 0 : (_store$auth$user2 = _store$auth.user) == null ? void 0 : _store$auth$user2.tenantId) != null ? _store$auth$user$tena : '';
|
|
107
|
+
await api.applications.assignUserToApplications({
|
|
108
|
+
userId,
|
|
109
|
+
appIds,
|
|
110
|
+
tenantId
|
|
111
|
+
});
|
|
112
|
+
const accountApps = (_store$auth2 = store.auth) == null ? void 0 : (_store$auth2$applicat = _store$auth2.applicationsState) == null ? void 0 : _store$auth2$applicat.accountApplications;
|
|
113
|
+
const users = (_store$auth$teamState = (_store$auth3 = store.auth) == null ? void 0 : (_store$auth3$teamStat = _store$auth3.teamState) == null ? void 0 : _store$auth3$teamStat.users) != null ? _store$auth$teamState : [];
|
|
114
|
+
const newApps = (_accountApps$filter = accountApps == null ? void 0 : accountApps.filter(app => appIds.includes(app.id))) != null ? _accountApps$filter : [];
|
|
115
|
+
if (newApps != null && newApps.length) {
|
|
116
|
+
sharedActions.setTeamState({
|
|
117
|
+
users: users.map(user => {
|
|
118
|
+
var _user$applications;
|
|
119
|
+
return user.id === userId ? _extends({}, user, {
|
|
120
|
+
applications: [...((_user$applications = user.applications) != null ? _user$applications : []), ...newApps]
|
|
121
|
+
}) : user;
|
|
122
|
+
})
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
callback == null ? void 0 : callback(true);
|
|
126
|
+
} catch (e) {
|
|
127
|
+
setApplicationsState({
|
|
128
|
+
error: errorHandler(e, ASSIGNMENT_DEFAULT_ERROR_MESSAGE)
|
|
129
|
+
});
|
|
130
|
+
callback == null ? void 0 : callback(false);
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
const unassignUserFromApps = async payload => {
|
|
134
|
+
const {
|
|
135
|
+
userId,
|
|
136
|
+
appIds,
|
|
137
|
+
callback
|
|
138
|
+
} = payload;
|
|
139
|
+
try {
|
|
140
|
+
var _store$auth$user$tena2, _store$auth4, _store$auth4$user, _store$auth$teamState2, _store$auth5, _store$auth5$teamStat, _users$find;
|
|
141
|
+
const tenantId = (_store$auth$user$tena2 = (_store$auth4 = store.auth) == null ? void 0 : (_store$auth4$user = _store$auth4.user) == null ? void 0 : _store$auth4$user.tenantId) != null ? _store$auth$user$tena2 : '';
|
|
142
|
+
await api.applications.unassignUserFromApplications({
|
|
143
|
+
userId,
|
|
144
|
+
appIds,
|
|
145
|
+
tenantId
|
|
146
|
+
});
|
|
147
|
+
const users = (_store$auth$teamState2 = (_store$auth5 = store.auth) == null ? void 0 : (_store$auth5$teamStat = _store$auth5.teamState) == null ? void 0 : _store$auth5$teamStat.users) != null ? _store$auth$teamState2 : [];
|
|
148
|
+
const userApps = (_users$find = users.find(user => user.id === userId)) == null ? void 0 : _users$find.applications;
|
|
149
|
+
if (userApps != null && userApps.length && appIds.length) {
|
|
150
|
+
sharedActions.setTeamState({
|
|
151
|
+
users: users.map(user => user.id === userId ? _extends({}, user, {
|
|
152
|
+
applications: userApps.filter(app => !appIds.includes(app.id))
|
|
153
|
+
}) : user)
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
callback == null ? void 0 : callback(true);
|
|
157
|
+
} catch (e) {
|
|
158
|
+
setApplicationsState({
|
|
159
|
+
error: errorHandler(e, ASSIGNMENT_DEFAULT_ERROR_MESSAGE)
|
|
160
|
+
});
|
|
161
|
+
callback == null ? void 0 : callback(false);
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
const assignNewUserToApps = async ({
|
|
165
|
+
appIds,
|
|
166
|
+
user
|
|
167
|
+
}) => {
|
|
168
|
+
var _store$auth6, _store$auth6$applicat, _apps$filter;
|
|
169
|
+
const [multiAppsFlag] = sharedActions.__getFeatureFlags(['multi-apps-admin-portal']);
|
|
170
|
+
if (!multiAppsFlag) {
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
const apps = (_store$auth6 = store.auth) == null ? void 0 : (_store$auth6$applicat = _store$auth6.applicationsState) == null ? void 0 : _store$auth6$applicat.accountApplications;
|
|
174
|
+
const defaultApps = (_apps$filter = apps == null ? void 0 : apps.filter(app => app.accessType === ApplicationAccessType.FREE_ACCESS)) != null ? _apps$filter : [];
|
|
175
|
+
if (appIds != null && appIds.length) {
|
|
176
|
+
var _store$auth$user$tena3, _store$auth7, _store$auth7$user;
|
|
177
|
+
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 : '';
|
|
178
|
+
await api.applications.assignUserToApplications({
|
|
179
|
+
userId: user.id,
|
|
180
|
+
appIds,
|
|
181
|
+
tenantId
|
|
182
|
+
});
|
|
183
|
+
return appIds.map(appId => {
|
|
184
|
+
var _apps$find;
|
|
185
|
+
return (_apps$find = apps == null ? void 0 : apps.find(app => app.id === appId)) != null ? _apps$find : [];
|
|
186
|
+
}).concat(defaultApps);
|
|
187
|
+
} else {
|
|
188
|
+
return defaultApps;
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
const mapUsersWithApplicationData = async ({
|
|
192
|
+
shouldLoadApps,
|
|
193
|
+
users
|
|
194
|
+
}) => {
|
|
195
|
+
const [multiAppsFlag] = sharedActions.__getFeatureFlags(['multi-apps-admin-portal']);
|
|
196
|
+
if (!multiAppsFlag || !shouldLoadApps) {
|
|
197
|
+
return users;
|
|
198
|
+
}
|
|
199
|
+
const userIds = users.map(user => user.id);
|
|
200
|
+
const userApps = await loadMultipleUsersApplications({
|
|
201
|
+
userIds
|
|
202
|
+
});
|
|
203
|
+
if (!userApps) {
|
|
204
|
+
return users;
|
|
205
|
+
}
|
|
206
|
+
return users.map(user => userApps != null && userApps[user.id] ? _extends({}, user, {
|
|
207
|
+
applications: userApps[user.id]
|
|
208
|
+
}) : user);
|
|
209
|
+
};
|
|
210
|
+
return {
|
|
211
|
+
setApplicationsState,
|
|
212
|
+
resetApplicationsState,
|
|
213
|
+
loadUserApplications,
|
|
214
|
+
loadAccountApplications,
|
|
215
|
+
loadMultipleUsersApplications,
|
|
216
|
+
assignUserToApps,
|
|
217
|
+
unassignUserFromApps,
|
|
218
|
+
assignNewUserToApps,
|
|
219
|
+
mapUsersWithApplicationData
|
|
220
|
+
};
|
|
221
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export const getFlattenAppIds = listWithAppIds => {
|
|
2
|
+
var _listWithAppIds$map$r;
|
|
3
|
+
return (_listWithAppIds$map$r = listWithAppIds.map(({
|
|
4
|
+
appIds
|
|
5
|
+
}) => appIds).reduce((allAppIds, currentAppIds) => {
|
|
6
|
+
currentAppIds == null ? void 0 : currentAppIds.forEach(item => {
|
|
7
|
+
if (allAppIds && !allAppIds.includes(item)) {
|
|
8
|
+
allAppIds.push(item);
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
return allAppIds;
|
|
12
|
+
}, [])) != null ? _listWithAppIds$map$r : [];
|
|
13
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { IApplicationsResponse, IAssignUserToApplicationsBody } from '@frontegg/rest-api';
|
|
2
|
+
export interface ApplicationsState {
|
|
3
|
+
error?: string | null;
|
|
4
|
+
fetching?: boolean;
|
|
5
|
+
loading?: boolean;
|
|
6
|
+
saving?: boolean;
|
|
7
|
+
userApplications?: IApplicationsResponse[];
|
|
8
|
+
accountApplications?: (IApplicationsResponse & {
|
|
9
|
+
userIds?: string[];
|
|
10
|
+
})[];
|
|
11
|
+
}
|
|
12
|
+
export declare type UserAppsAssignmentPayload = Pick<IAssignUserToApplicationsBody, 'userId' | 'appIds'>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { createProxy } from '../../toolkit/proxy';
|
|
2
|
+
export const initialState = {
|
|
3
|
+
loading: true,
|
|
4
|
+
fetching: true,
|
|
5
|
+
error: null,
|
|
6
|
+
userApplications: [],
|
|
7
|
+
accountApplications: []
|
|
8
|
+
};
|
|
9
|
+
export default (overrideState => createProxy(initialState, overrideState));
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { isEntitlementsDeeplyEqual } from './helpers';
|
|
2
|
-
import { USE_ENTITLEMENTS_V2_ENDPOINT_FF } from '@frontegg/rest-api';
|
|
3
2
|
export default ((store, api, sharedActions) => {
|
|
4
3
|
const actions = sharedActions;
|
|
5
4
|
const setEntitlements = entitlements => {
|
|
@@ -25,10 +24,8 @@ export default ((store, api, sharedActions) => {
|
|
|
25
24
|
*/
|
|
26
25
|
const loadEntitlements = async payload => {
|
|
27
26
|
const callback = payload == null ? void 0 : payload.callback;
|
|
28
|
-
const [useEntitlementsV2] = await actions.__getFeatureFlags([USE_ENTITLEMENTS_V2_ENDPOINT_FF]);
|
|
29
27
|
try {
|
|
30
|
-
|
|
31
|
-
const entitlements = await (useEntitlementsV2 ? api.entitlements.loadEntitlementsV2() : api.entitlements.loadEntitlements());
|
|
28
|
+
const entitlements = await api.entitlements.loadEntitlementsV2();
|
|
32
29
|
handleFetchedEntitlements(entitlements);
|
|
33
30
|
callback == null ? void 0 : callback(true);
|
|
34
31
|
} catch (e) {
|
|
@@ -1,34 +1,33 @@
|
|
|
1
|
-
import { UserEntitlementsResponse } from '@frontegg/rest-api';
|
|
2
1
|
import { EntitledToOptions, Entitlement } from './interfaces';
|
|
3
2
|
import type { UserEntitlementsContext as UserEntitlementsResponseV2 } from '@frontegg/entitlements-javascript-commons';
|
|
4
3
|
import type { Attributes } from '@frontegg/entitlements-javascript-commons';
|
|
5
4
|
/**
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
5
|
+
@param entitlements
|
|
6
|
+
@param key permission key
|
|
7
|
+
@param attributes entitlements query attributes including consumer and frontegg attributes
|
|
8
|
+
@param isV2 not in use. should be removed after removing from frontegg-vue
|
|
9
|
+
@returns if the user is entitled to the given permission. Attaching the justification if not
|
|
10
|
+
@throws when entitlement is not enabled via frontegg options
|
|
12
11
|
*/
|
|
13
|
-
export declare const getPermissionEntitlements: (entitlements: UserEntitlementsResponseV2 |
|
|
12
|
+
export declare const getPermissionEntitlements: (entitlements: UserEntitlementsResponseV2 | undefined, key: string, attributes?: Attributes | undefined, isV2?: boolean | undefined) => Entitlement;
|
|
14
13
|
/**
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
14
|
+
@param entitlements
|
|
15
|
+
@param key feature key
|
|
16
|
+
@param attributes entitlements query attributes including consumer and frontegg attributes
|
|
17
|
+
@param isV2 not in use. should be removed after removing from frontegg-vue
|
|
18
|
+
@returns if the user is entitled to the given feature. Attaching the justification if not
|
|
19
|
+
@throws when entitlement is not enabled via frontegg options
|
|
21
20
|
*/
|
|
22
|
-
export declare const getFeatureEntitlements: (entitlements: UserEntitlementsResponseV2 |
|
|
21
|
+
export declare const getFeatureEntitlements: (entitlements: UserEntitlementsResponseV2 | undefined, key: string, attributes?: Attributes | undefined, isV2?: boolean | undefined) => Entitlement;
|
|
23
22
|
/**
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
23
|
+
@param entitlements
|
|
24
|
+
@param options including permission or feature
|
|
25
|
+
@param attributes entitlements query attributes including consumer and frontegg attributes
|
|
26
|
+
@param isV2 not in use. should be removed after removing from frontegg-vue
|
|
27
|
+
@returns if the user is entitled to the given feature or permission (check only one). Attaching the justification if not
|
|
28
|
+
@throws when entitlement is not enabled via frontegg options
|
|
30
29
|
*/
|
|
31
|
-
export declare const getEntitlements: (entitlements: UserEntitlementsResponseV2 |
|
|
30
|
+
export declare const getEntitlements: (entitlements: UserEntitlementsResponseV2 | undefined, options: EntitledToOptions, attributes?: Attributes | undefined, isV2?: boolean | undefined) => Entitlement;
|
|
32
31
|
/**
|
|
33
32
|
* @param oldEntitlements
|
|
34
33
|
* @param newEntitlements
|
|
@@ -1,17 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ContextHolder } from '@frontegg/rest-api';
|
|
2
2
|
import isEqual from 'fast-deep-equal';
|
|
3
3
|
import { evaluateIsEntitledToFeature, evaluateIsEntitledToPermissions } from '@frontegg/entitlements-javascript-commons';
|
|
4
|
-
/**
|
|
5
|
-
* NOTE: This file including the usage of user entitlements API V1 and V2. The BE API response is diffrent.
|
|
6
|
-
* V1 is the initial implementation.
|
|
7
|
-
* V2 is using the entitlenents package for Rule Based entitlements.
|
|
8
|
-
*
|
|
9
|
-
* V1 is still supported with feature flag but it's depracated.
|
|
10
|
-
*
|
|
11
|
-
* The entitlements query functions supports both APIs by an optional argument of [isV2] to decide what version to choose.
|
|
12
|
-
* The function returns the same type.
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
4
|
const ENTITLEMENTS_NOT_ENABLED_EXCEPTION_TEXT = 'You must first enable entitlements via Frontegg options to use this function';
|
|
16
5
|
|
|
17
6
|
/**
|
|
@@ -24,78 +13,44 @@ const guardEntitlementsUsage = () => {
|
|
|
24
13
|
};
|
|
25
14
|
|
|
26
15
|
/**
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
*/
|
|
34
|
-
const getEntitlementsHelperV1 = (keyEntitlements, missingKeyEnum) => {
|
|
35
|
-
if (!keyEntitlements) {
|
|
36
|
-
return {
|
|
37
|
-
isEntitled: false,
|
|
38
|
-
justification: missingKeyEnum
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
if (keyEntitlements.isEntitled) {
|
|
42
|
-
return {
|
|
43
|
-
isEntitled: true
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
return {
|
|
47
|
-
isEntitled: false,
|
|
48
|
-
justification: keyEntitlements.justification
|
|
49
|
-
};
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
@param entitlements
|
|
54
|
-
@param key permission key
|
|
55
|
-
@param attributes entitlements query attributes including comnsumer and frontegg attributes
|
|
56
|
-
@param isV2 true when need to use entitlements API V2
|
|
57
|
-
@returns if the user is entitled to the given permission. Attaching the justification if not
|
|
58
|
-
@throws when entitlement is not enabled via frontegg options
|
|
16
|
+
@param entitlements
|
|
17
|
+
@param key permission key
|
|
18
|
+
@param attributes entitlements query attributes including consumer and frontegg attributes
|
|
19
|
+
@param isV2 not in use. should be removed after removing from frontegg-vue
|
|
20
|
+
@returns if the user is entitled to the given permission. Attaching the justification if not
|
|
21
|
+
@throws when entitlement is not enabled via frontegg options
|
|
59
22
|
*/
|
|
60
23
|
export const getPermissionEntitlements = (entitlements, key, attributes, isV2) => {
|
|
61
|
-
var _permissions;
|
|
62
24
|
guardEntitlementsUsage();
|
|
63
|
-
|
|
64
|
-
return evaluateIsEntitledToPermissions(key, entitlements, attributes);
|
|
65
|
-
}
|
|
66
|
-
return getEntitlementsHelperV1(entitlements == null ? void 0 : (_permissions = entitlements.permissions) == null ? void 0 : _permissions[key], NotEntitledJustification.MISSING_PERMISSION);
|
|
25
|
+
return evaluateIsEntitledToPermissions(key, entitlements, attributes);
|
|
67
26
|
};
|
|
68
27
|
|
|
69
28
|
/**
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
29
|
+
@param entitlements
|
|
30
|
+
@param key feature key
|
|
31
|
+
@param attributes entitlements query attributes including consumer and frontegg attributes
|
|
32
|
+
@param isV2 not in use. should be removed after removing from frontegg-vue
|
|
33
|
+
@returns if the user is entitled to the given feature. Attaching the justification if not
|
|
34
|
+
@throws when entitlement is not enabled via frontegg options
|
|
76
35
|
*/
|
|
77
36
|
export const getFeatureEntitlements = (entitlements, key, attributes, isV2) => {
|
|
78
|
-
var _features;
|
|
79
37
|
guardEntitlementsUsage();
|
|
80
|
-
|
|
81
|
-
return evaluateIsEntitledToFeature(key, entitlements, attributes);
|
|
82
|
-
}
|
|
83
|
-
return getEntitlementsHelperV1(entitlements == null ? void 0 : (_features = entitlements.features) == null ? void 0 : _features[key], NotEntitledJustification.MISSING_FEATURE);
|
|
38
|
+
return evaluateIsEntitledToFeature(key, entitlements, attributes);
|
|
84
39
|
};
|
|
85
40
|
|
|
86
41
|
/**
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
42
|
+
@param entitlements
|
|
43
|
+
@param options including permission or feature
|
|
44
|
+
@param attributes entitlements query attributes including consumer and frontegg attributes
|
|
45
|
+
@param isV2 not in use. should be removed after removing from frontegg-vue
|
|
46
|
+
@returns if the user is entitled to the given feature or permission (check only one). Attaching the justification if not
|
|
47
|
+
@throws when entitlement is not enabled via frontegg options
|
|
93
48
|
*/
|
|
94
49
|
export const getEntitlements = (entitlements, options, attributes, isV2) => {
|
|
95
50
|
if ('permissionKey' in options) {
|
|
96
|
-
return getPermissionEntitlements(entitlements, options.permissionKey, attributes
|
|
51
|
+
return getPermissionEntitlements(entitlements, options.permissionKey, attributes);
|
|
97
52
|
}
|
|
98
|
-
return getFeatureEntitlements(entitlements, options.featureKey, attributes
|
|
53
|
+
return getFeatureEntitlements(entitlements, options.featureKey, attributes);
|
|
99
54
|
};
|
|
100
55
|
|
|
101
56
|
/**
|
|
@@ -28,7 +28,13 @@ export default ((store, api, sharedActions) => {
|
|
|
28
28
|
step: ImpersonateStep.success
|
|
29
29
|
});
|
|
30
30
|
await delay(1000);
|
|
31
|
-
|
|
31
|
+
/**
|
|
32
|
+
* We want to avoid cleaning the origin of the redirect URL
|
|
33
|
+
* because we want to refresh the page and redirect to the same origin on embedded mode
|
|
34
|
+
*/
|
|
35
|
+
await actions.afterAuthNavigation({
|
|
36
|
+
preventRedirectUrlOriginCleaning: true
|
|
37
|
+
});
|
|
32
38
|
resetImpersonateState();
|
|
33
39
|
callback == null ? void 0 : callback(true);
|
|
34
40
|
} catch (e) {
|
|
@@ -4,7 +4,7 @@ import { AfterAuthNavigationUtilOptions } from '../interfaces';
|
|
|
4
4
|
import { AuthState } from '../../interfaces';
|
|
5
5
|
declare const _default: (store: FronteggState, api: RestApi, sharedActions: SharedActions) => {
|
|
6
6
|
afterAuthNavigationUtil: (resetStateAction: (() => void) | (() => Promise<void>), options?: AfterAuthNavigationUtilOptions) => Promise<void>;
|
|
7
|
-
afterAuthNavigation: () => Promise<void>;
|
|
7
|
+
afterAuthNavigation: (payload?: Pick<AfterAuthNavigationUtilOptions, "preventRedirectUrlOriginCleaning"> | undefined) => Promise<void>;
|
|
8
8
|
afterStepUpAuthNavigation: () => Promise<void>;
|
|
9
9
|
__afterAuthenticationStateUpdate: ({ user, tenants, activeTenant }: ILoginResponseV3, additionalUpdate?: Partial<AuthState>) => Promise<void>;
|
|
10
10
|
};
|
|
@@ -10,9 +10,11 @@ export default ((store, api, sharedActions) => {
|
|
|
10
10
|
/**
|
|
11
11
|
* @param url
|
|
12
12
|
* @returns url without the origin if it's the same origin as the current window origin
|
|
13
|
-
* @
|
|
13
|
+
* @deprecated
|
|
14
|
+
* Don't use this unless you must
|
|
15
|
+
* In case the url is equal to the window.location.origin, it will return an empty string
|
|
14
16
|
*/
|
|
15
|
-
function
|
|
17
|
+
function cleanUrlIfSameOrigin(url) {
|
|
16
18
|
var _window, _window2;
|
|
17
19
|
if (!url.startsWith((_window = window) == null ? void 0 : _window.location.origin)) {
|
|
18
20
|
return url;
|
|
@@ -48,7 +50,10 @@ export default ((store, api, sharedActions) => {
|
|
|
48
50
|
* @param customLoginAuthenticatedUrl custom login authenticated url if exists
|
|
49
51
|
* @returns the authenticated url to redirect to after auth navigation
|
|
50
52
|
*/
|
|
51
|
-
async function __getUrlForAfterAuthNavigation(
|
|
53
|
+
async function __getUrlForAfterAuthNavigation({
|
|
54
|
+
customLoginAuthenticatedUrl,
|
|
55
|
+
preventRedirectUrlOriginCleaning
|
|
56
|
+
}) {
|
|
52
57
|
const {
|
|
53
58
|
routes,
|
|
54
59
|
includeQueryParam = false,
|
|
@@ -75,9 +80,11 @@ export default ((store, api, sharedActions) => {
|
|
|
75
80
|
enforceRedirectToSameSite,
|
|
76
81
|
allowedRedirectOrigins
|
|
77
82
|
});
|
|
78
|
-
|
|
83
|
+
if (preventRedirectUrlOriginCleaning) {
|
|
84
|
+
return redirectUrl;
|
|
85
|
+
}
|
|
79
86
|
// clean origin if it's the same origin as the current window origin to avoid refresh in afterAuthNavigationUtil
|
|
80
|
-
return
|
|
87
|
+
return cleanUrlIfSameOrigin(redirectUrl);
|
|
81
88
|
}
|
|
82
89
|
|
|
83
90
|
/**
|
|
@@ -89,7 +96,8 @@ export default ((store, api, sharedActions) => {
|
|
|
89
96
|
const {
|
|
90
97
|
customLoginAuthenticatedUrl,
|
|
91
98
|
forceStepUpUrl,
|
|
92
|
-
shouldStepUpDuringLogin
|
|
99
|
+
shouldStepUpDuringLogin,
|
|
100
|
+
preventRedirectUrlOriginCleaning = false
|
|
93
101
|
} = options;
|
|
94
102
|
|
|
95
103
|
// TODO: change to store.root.onRedirectTo
|
|
@@ -110,7 +118,10 @@ export default ((store, api, sharedActions) => {
|
|
|
110
118
|
}
|
|
111
119
|
}
|
|
112
120
|
if (!redirectUrl) {
|
|
113
|
-
redirectUrl = await __getUrlForAfterAuthNavigation(
|
|
121
|
+
redirectUrl = await __getUrlForAfterAuthNavigation({
|
|
122
|
+
customLoginAuthenticatedUrl,
|
|
123
|
+
preventRedirectUrlOriginCleaning
|
|
124
|
+
});
|
|
114
125
|
}
|
|
115
126
|
(_window3 = window) == null ? void 0 : _window3.localStorage.removeItem(FRONTEGG_AFTER_AUTH_REDIRECT_URL);
|
|
116
127
|
}
|
|
@@ -125,8 +136,8 @@ export default ((store, api, sharedActions) => {
|
|
|
125
136
|
* After auth navigation for login flow
|
|
126
137
|
* Handling also step up scenario when user silently logout to continue to step up
|
|
127
138
|
*/
|
|
128
|
-
const afterAuthNavigation = async
|
|
129
|
-
var _window4;
|
|
139
|
+
const afterAuthNavigation = async payload => {
|
|
140
|
+
var _window4, _payload$preventRedir;
|
|
130
141
|
const {
|
|
131
142
|
customLoginAuthenticatedUrl,
|
|
132
143
|
stepUpUrl
|
|
@@ -152,7 +163,8 @@ export default ((store, api, sharedActions) => {
|
|
|
152
163
|
}
|
|
153
164
|
return afterAuthNavigationUtil(actions.resetLoginState, {
|
|
154
165
|
customLoginAuthenticatedUrl: customLoginURL,
|
|
155
|
-
shouldStepUpDuringLogin: !!shouldStepUp
|
|
166
|
+
shouldStepUpDuringLogin: !!shouldStepUp,
|
|
167
|
+
preventRedirectUrlOriginCleaning: (_payload$preventRedir = payload == null ? void 0 : payload.preventRedirectUrlOriginCleaning) != null ? _payload$preventRedir : false
|
|
156
168
|
});
|
|
157
169
|
};
|
|
158
170
|
|
|
@@ -8,6 +8,7 @@ declare const _default: (store: FronteggState, api: RestApi, sharedActions: Shar
|
|
|
8
8
|
firstTime?: boolean | undefined;
|
|
9
9
|
loginDirectAction?: LoginDirectAction | undefined;
|
|
10
10
|
} | undefined) => Promise<void>;
|
|
11
|
+
__requestHostedLoginAuthorize: (additionalParams?: Record<string, string> | undefined) => Promise<void>;
|
|
11
12
|
__requestHostedLoginSilentAuthorize: () => Promise<void>;
|
|
12
13
|
handleHostedLoginCallback: (payload: HostedLoginCallback) => Promise<void>;
|
|
13
14
|
};
|
|
@@ -194,6 +194,7 @@ export default ((store, api, sharedActions) => {
|
|
|
194
194
|
return {
|
|
195
195
|
requestHostedLoginAuthorize: refreshOrRequestHostedLoginAuthorize,
|
|
196
196
|
requestHostedLoginAuthorizeV2: refreshOrRequestHostedLoginAuthorizeV2,
|
|
197
|
+
__requestHostedLoginAuthorize: requestHostedLoginAuthorize,
|
|
197
198
|
__requestHostedLoginSilentAuthorize,
|
|
198
199
|
handleHostedLoginCallback
|
|
199
200
|
};
|
|
@@ -27,7 +27,7 @@ declare const _default: (store: FronteggState, api: RestApi, sharedActions: Shar
|
|
|
27
27
|
handleVerifyMFAResponse: (payload: ILoginResponseV3, isStepUp?: boolean) => Promise<void>;
|
|
28
28
|
__getFeatureFlags: (flags: string[]) => Promise<boolean[]>;
|
|
29
29
|
afterAuthNavigationUtil: (resetStateAction: (() => void) | (() => Promise<void>), options?: import("../interfaces").AfterAuthNavigationUtilOptions) => Promise<void>;
|
|
30
|
-
afterAuthNavigation: () => Promise<void>;
|
|
30
|
+
afterAuthNavigation: (payload?: Pick<import("../interfaces").AfterAuthNavigationUtilOptions, "preventRedirectUrlOriginCleaning"> | undefined) => Promise<void>;
|
|
31
31
|
afterStepUpAuthNavigation: () => Promise<void>;
|
|
32
32
|
__afterAuthenticationStateUpdate: ({ user, tenants, activeTenant }: ILoginResponseV3, additionalUpdate?: Partial<AuthState>) => Promise<void>;
|
|
33
33
|
requestHostedLoginAuthorize: (additionalParams?: Record<string, string> | undefined) => Promise<void>;
|
|
@@ -37,6 +37,7 @@ declare const _default: (store: FronteggState, api: RestApi, sharedActions: Shar
|
|
|
37
37
|
firstTime?: boolean | undefined;
|
|
38
38
|
loginDirectAction?: import("../interfaces").LoginDirectAction | undefined;
|
|
39
39
|
} | undefined) => Promise<void>;
|
|
40
|
+
__requestHostedLoginAuthorize: (additionalParams?: Record<string, string> | undefined) => Promise<void>;
|
|
40
41
|
__requestHostedLoginSilentAuthorize: () => Promise<void>;
|
|
41
42
|
handleHostedLoginCallback: (payload: import("../interfaces").HostedLoginCallback) => Promise<void>;
|
|
42
43
|
setLoginState: (state: Partial<LoginState>) => void;
|