@frontegg/rest-api 3.0.136 → 3.0.138
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/ContextHolder/index.d.ts +19 -0
- package/ContextHolder/index.js +19 -0
- package/auth/index.js +36 -5
- package/auth/interfaces.d.ts +2 -1
- package/entitlements/interfaces.d.ts +4 -0
- package/entitlements/interfaces.js +3 -1
- package/index.js +1 -1
- package/node/ContextHolder/index.js +19 -0
- package/node/auth/index.js +38 -5
- package/node/entitlements/interfaces.js +5 -2
- package/node/index.js +1 -1
- package/package.json +1 -1
package/ContextHolder/index.d.ts
CHANGED
|
@@ -8,6 +8,8 @@ export declare class ContextHolder {
|
|
|
8
8
|
private requestSource;
|
|
9
9
|
private onRedirectTo;
|
|
10
10
|
private logout;
|
|
11
|
+
private shouldLoadEntitlements;
|
|
12
|
+
private appName;
|
|
11
13
|
private constructor();
|
|
12
14
|
static getInstance(): ContextHolder;
|
|
13
15
|
static setContext(context: ContextOptions): void;
|
|
@@ -16,12 +18,29 @@ export declare class ContextHolder {
|
|
|
16
18
|
static setRequestSource(requestSource: RequestSource | null): void;
|
|
17
19
|
static setOnRedirectTo(onRedirectTo: (path: string, opts?: RedirectOptions) => void): void;
|
|
18
20
|
static setLogout(logout: (callback?: () => void) => void, logoutUrl: string): void;
|
|
21
|
+
/**
|
|
22
|
+
* App name should also be set for entitlements
|
|
23
|
+
* @param shouldLoadEntitlements
|
|
24
|
+
*/
|
|
25
|
+
static setShouldLoadEntitlements(shouldLoadEntitlements: boolean): void;
|
|
26
|
+
/**
|
|
27
|
+
* @param appName for feature flags e.g.
|
|
28
|
+
*/
|
|
29
|
+
static setAppName(appName: string | null): void;
|
|
19
30
|
static getContext(): ContextOptions;
|
|
20
31
|
static getAccessToken(): string | null;
|
|
21
32
|
static getRequestSource(): RequestSource | null;
|
|
22
33
|
static getUser(): IUserProfile | null;
|
|
23
34
|
static onRedirectTo(path: string, opts?: RedirectOptions): void;
|
|
24
35
|
static logout(callback?: () => void): void;
|
|
36
|
+
/**
|
|
37
|
+
* @returns shouldLoadEntitlements value
|
|
38
|
+
*/
|
|
39
|
+
static shouldLoadEntitlements(): boolean | null;
|
|
40
|
+
/**
|
|
41
|
+
* @returns app name value
|
|
42
|
+
*/
|
|
43
|
+
static getAppName(): string | null;
|
|
25
44
|
}
|
|
26
45
|
export declare const FronteggContext: {
|
|
27
46
|
getContext: () => ContextOptions;
|
package/ContextHolder/index.js
CHANGED
|
@@ -8,6 +8,9 @@ export class ContextHolder {
|
|
|
8
8
|
this.onRedirectTo = path => window.location.href = path;
|
|
9
9
|
|
|
10
10
|
this.logout = () => window.location.href = '/account/logout';
|
|
11
|
+
|
|
12
|
+
this.shouldLoadEntitlements = null;
|
|
13
|
+
this.appName = null;
|
|
11
14
|
}
|
|
12
15
|
|
|
13
16
|
static getInstance() {
|
|
@@ -48,6 +51,14 @@ export class ContextHolder {
|
|
|
48
51
|
};
|
|
49
52
|
}
|
|
50
53
|
|
|
54
|
+
static setShouldLoadEntitlements(shouldLoadEntitlements) {
|
|
55
|
+
ContextHolder.getInstance().shouldLoadEntitlements = shouldLoadEntitlements;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
static setAppName(appName) {
|
|
59
|
+
ContextHolder.getInstance().appName = appName;
|
|
60
|
+
}
|
|
61
|
+
|
|
51
62
|
static getContext() {
|
|
52
63
|
var _ContextHolder$getIns;
|
|
53
64
|
|
|
@@ -78,6 +89,14 @@ export class ContextHolder {
|
|
|
78
89
|
return ContextHolder.getInstance().logout(callback);
|
|
79
90
|
}
|
|
80
91
|
|
|
92
|
+
static shouldLoadEntitlements() {
|
|
93
|
+
return ContextHolder.getInstance().shouldLoadEntitlements;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
static getAppName() {
|
|
97
|
+
return ContextHolder.getInstance().appName;
|
|
98
|
+
}
|
|
99
|
+
|
|
81
100
|
}
|
|
82
101
|
ContextHolder.instance = void 0;
|
|
83
102
|
export const FronteggContext = {
|
package/auth/index.js
CHANGED
|
@@ -11,6 +11,9 @@ import { ContextHolder } from "../ContextHolder";
|
|
|
11
11
|
import { Delete, Get, Patch, Post, Put } from "../fetch";
|
|
12
12
|
import { jwtDecode } from "../jwt";
|
|
13
13
|
import { getCurrentUserTenantsV3 } from '../users';
|
|
14
|
+
import { loadEntitlements } from '../entitlements';
|
|
15
|
+
import { ADMIN_PORTAL_ENTITLEMENTS_FF } from '../entitlements/interfaces';
|
|
16
|
+
import { FeatureFlags } from "../feature-flags";
|
|
14
17
|
export async function generateLoginResponse(loginResponse) {
|
|
15
18
|
if (!loginResponse.accessToken) {
|
|
16
19
|
return loginResponse;
|
|
@@ -44,24 +47,45 @@ export async function generateLoginResponseV2(loginResponse) {
|
|
|
44
47
|
tenants
|
|
45
48
|
};
|
|
46
49
|
}
|
|
50
|
+
|
|
51
|
+
async function shouldLoadEntitlements() {
|
|
52
|
+
if (!ContextHolder.shouldLoadEntitlements()) {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const [isEntitlementsFFOn] = await FeatureFlags.getFeatureFlags([ADMIN_PORTAL_ENTITLEMENTS_FF], ContextHolder.getAppName() || '');
|
|
57
|
+
return isEntitlementsFFOn;
|
|
58
|
+
}
|
|
59
|
+
|
|
47
60
|
export async function generateLoginResponseV3(loginResponse) {
|
|
48
|
-
|
|
61
|
+
const {
|
|
62
|
+
accessToken
|
|
63
|
+
} = loginResponse;
|
|
64
|
+
|
|
65
|
+
if (!accessToken) {
|
|
49
66
|
return {
|
|
50
67
|
user: loginResponse
|
|
51
68
|
};
|
|
52
69
|
}
|
|
53
70
|
|
|
54
|
-
ContextHolder.setAccessToken(
|
|
71
|
+
ContextHolder.setAccessToken(accessToken);
|
|
55
72
|
const [me, currentUserTenants] = await Promise.all([Get(`${urls.identity.users.v2}/me`), getCurrentUserTenantsV3()]);
|
|
56
|
-
const decodedContent =
|
|
73
|
+
const decodedContent = accessToken ? jwtDecode(accessToken) : {};
|
|
57
74
|
|
|
58
75
|
const user = _extends({}, loginResponse, decodedContent, me);
|
|
59
76
|
|
|
60
77
|
ContextHolder.setUser(user);
|
|
78
|
+
let entitlements;
|
|
79
|
+
|
|
80
|
+
if (await shouldLoadEntitlements()) {
|
|
81
|
+
entitlements = await loadEntitlements();
|
|
82
|
+
}
|
|
83
|
+
|
|
61
84
|
return {
|
|
62
85
|
user,
|
|
63
86
|
tenants: currentUserTenants.tenants,
|
|
64
|
-
activeTenant: currentUserTenants.activeTenant
|
|
87
|
+
activeTenant: currentUserTenants.activeTenant,
|
|
88
|
+
entitlements
|
|
65
89
|
};
|
|
66
90
|
}
|
|
67
91
|
export async function generateLoginResponseFromOAuthResponse(oauthResponse) {
|
|
@@ -94,10 +118,17 @@ export async function generateLoginResponseFromOAuthResponseV2(oauthResponse) {
|
|
|
94
118
|
});
|
|
95
119
|
|
|
96
120
|
ContextHolder.setUser(user);
|
|
121
|
+
let entitlements;
|
|
122
|
+
|
|
123
|
+
if (await shouldLoadEntitlements()) {
|
|
124
|
+
entitlements = await loadEntitlements();
|
|
125
|
+
}
|
|
126
|
+
|
|
97
127
|
return {
|
|
98
128
|
user,
|
|
99
129
|
tenants: currentUserTenants.tenants,
|
|
100
|
-
activeTenant: currentUserTenants.activeTenant
|
|
130
|
+
activeTenant: currentUserTenants.activeTenant,
|
|
131
|
+
entitlements
|
|
101
132
|
};
|
|
102
133
|
}
|
|
103
134
|
export async function preLogin(body) {
|
package/auth/interfaces.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ITenantsResponse, IUserProfile } from "..";
|
|
1
|
+
import { ITenantsResponse, IUserProfile, UserEntitlementsResponse } from "..";
|
|
2
2
|
import { AuthStrategyEnum, MachineToMachineAuthStrategy, SocialLoginProviders } from "./enums";
|
|
3
3
|
import { ISamlRolesGroup } from "../teams/interfaces";
|
|
4
4
|
export * from "./secutiry-poilicy/interfaces";
|
|
@@ -54,6 +54,7 @@ export declare type ILoginResponseV3 = {
|
|
|
54
54
|
user: ILoginResponse;
|
|
55
55
|
tenants?: ITenantsResponse[];
|
|
56
56
|
activeTenant?: ITenantsResponse;
|
|
57
|
+
entitlements?: UserEntitlementsResponse;
|
|
57
58
|
};
|
|
58
59
|
export declare type ILoginWithMfa = {
|
|
59
60
|
mfaToken: string;
|
|
@@ -4,4 +4,6 @@ export let NotEntitledReason;
|
|
|
4
4
|
NotEntitledReason["MISSING_PERMISSION"] = "MISSING_PERMISSION";
|
|
5
5
|
NotEntitledReason["MISSING_FEATURE"] = "MISSING_FEATURE";
|
|
6
6
|
NotEntitledReason["BUNDLE_EXPIRED"] = "BUNDLE_EXPIRED";
|
|
7
|
-
})(NotEntitledReason || (NotEntitledReason = {}));
|
|
7
|
+
})(NotEntitledReason || (NotEntitledReason = {}));
|
|
8
|
+
|
|
9
|
+
export const ADMIN_PORTAL_ENTITLEMENTS_FF = 'admin_portal_entitlements';
|
package/index.js
CHANGED
|
@@ -15,6 +15,9 @@ class ContextHolder {
|
|
|
15
15
|
this.onRedirectTo = path => window.location.href = path;
|
|
16
16
|
|
|
17
17
|
this.logout = () => window.location.href = '/account/logout';
|
|
18
|
+
|
|
19
|
+
this.shouldLoadEntitlements = null;
|
|
20
|
+
this.appName = null;
|
|
18
21
|
}
|
|
19
22
|
|
|
20
23
|
static getInstance() {
|
|
@@ -55,6 +58,14 @@ class ContextHolder {
|
|
|
55
58
|
};
|
|
56
59
|
}
|
|
57
60
|
|
|
61
|
+
static setShouldLoadEntitlements(shouldLoadEntitlements) {
|
|
62
|
+
ContextHolder.getInstance().shouldLoadEntitlements = shouldLoadEntitlements;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
static setAppName(appName) {
|
|
66
|
+
ContextHolder.getInstance().appName = appName;
|
|
67
|
+
}
|
|
68
|
+
|
|
58
69
|
static getContext() {
|
|
59
70
|
var _ContextHolder$getIns;
|
|
60
71
|
|
|
@@ -85,6 +96,14 @@ class ContextHolder {
|
|
|
85
96
|
return ContextHolder.getInstance().logout(callback);
|
|
86
97
|
}
|
|
87
98
|
|
|
99
|
+
static shouldLoadEntitlements() {
|
|
100
|
+
return ContextHolder.getInstance().shouldLoadEntitlements;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
static getAppName() {
|
|
104
|
+
return ContextHolder.getInstance().appName;
|
|
105
|
+
}
|
|
106
|
+
|
|
88
107
|
}
|
|
89
108
|
|
|
90
109
|
exports.ContextHolder = ContextHolder;
|
package/node/auth/index.js
CHANGED
|
@@ -338,6 +338,12 @@ var _jwt = require("../jwt");
|
|
|
338
338
|
|
|
339
339
|
var _users = require("../users");
|
|
340
340
|
|
|
341
|
+
var _entitlements = require("../entitlements");
|
|
342
|
+
|
|
343
|
+
var _interfaces = require("../entitlements/interfaces");
|
|
344
|
+
|
|
345
|
+
var _featureFlags = require("../feature-flags");
|
|
346
|
+
|
|
341
347
|
const _excluded = ["type"],
|
|
342
348
|
_excluded2 = ["type"],
|
|
343
349
|
_excluded3 = ["type"];
|
|
@@ -379,25 +385,45 @@ async function generateLoginResponseV2(loginResponse) {
|
|
|
379
385
|
};
|
|
380
386
|
}
|
|
381
387
|
|
|
388
|
+
async function shouldLoadEntitlements() {
|
|
389
|
+
if (!_ContextHolder.ContextHolder.shouldLoadEntitlements()) {
|
|
390
|
+
return false;
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
const [isEntitlementsFFOn] = await _featureFlags.FeatureFlags.getFeatureFlags([_interfaces.ADMIN_PORTAL_ENTITLEMENTS_FF], _ContextHolder.ContextHolder.getAppName() || '');
|
|
394
|
+
return isEntitlementsFFOn;
|
|
395
|
+
}
|
|
396
|
+
|
|
382
397
|
async function generateLoginResponseV3(loginResponse) {
|
|
383
|
-
|
|
398
|
+
const {
|
|
399
|
+
accessToken
|
|
400
|
+
} = loginResponse;
|
|
401
|
+
|
|
402
|
+
if (!accessToken) {
|
|
384
403
|
return {
|
|
385
404
|
user: loginResponse
|
|
386
405
|
};
|
|
387
406
|
}
|
|
388
407
|
|
|
389
|
-
_ContextHolder.ContextHolder.setAccessToken(
|
|
408
|
+
_ContextHolder.ContextHolder.setAccessToken(accessToken);
|
|
390
409
|
|
|
391
410
|
const [me, currentUserTenants] = await Promise.all([(0, _fetch.Get)(`${_constants.urls.identity.users.v2}/me`), (0, _users.getCurrentUserTenantsV3)()]);
|
|
392
|
-
const decodedContent =
|
|
411
|
+
const decodedContent = accessToken ? (0, _jwt.jwtDecode)(accessToken) : {};
|
|
393
412
|
const user = (0, _extends2.default)({}, loginResponse, decodedContent, me);
|
|
394
413
|
|
|
395
414
|
_ContextHolder.ContextHolder.setUser(user);
|
|
396
415
|
|
|
416
|
+
let entitlements;
|
|
417
|
+
|
|
418
|
+
if (await shouldLoadEntitlements()) {
|
|
419
|
+
entitlements = await (0, _entitlements.loadEntitlements)();
|
|
420
|
+
}
|
|
421
|
+
|
|
397
422
|
return {
|
|
398
423
|
user,
|
|
399
424
|
tenants: currentUserTenants.tenants,
|
|
400
|
-
activeTenant: currentUserTenants.activeTenant
|
|
425
|
+
activeTenant: currentUserTenants.activeTenant,
|
|
426
|
+
entitlements
|
|
401
427
|
};
|
|
402
428
|
}
|
|
403
429
|
|
|
@@ -434,10 +460,17 @@ async function generateLoginResponseFromOAuthResponseV2(oauthResponse) {
|
|
|
434
460
|
|
|
435
461
|
_ContextHolder.ContextHolder.setUser(user);
|
|
436
462
|
|
|
463
|
+
let entitlements;
|
|
464
|
+
|
|
465
|
+
if (await shouldLoadEntitlements()) {
|
|
466
|
+
entitlements = await (0, _entitlements.loadEntitlements)();
|
|
467
|
+
}
|
|
468
|
+
|
|
437
469
|
return {
|
|
438
470
|
user,
|
|
439
471
|
tenants: currentUserTenants.tenants,
|
|
440
|
-
activeTenant: currentUserTenants.activeTenant
|
|
472
|
+
activeTenant: currentUserTenants.activeTenant,
|
|
473
|
+
entitlements
|
|
441
474
|
};
|
|
442
475
|
}
|
|
443
476
|
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.NotEntitledReason = void 0;
|
|
6
|
+
exports.NotEntitledReason = exports.ADMIN_PORTAL_ENTITLEMENTS_FF = void 0;
|
|
7
7
|
let NotEntitledReason;
|
|
8
8
|
exports.NotEntitledReason = NotEntitledReason;
|
|
9
9
|
|
|
@@ -11,4 +11,7 @@ exports.NotEntitledReason = NotEntitledReason;
|
|
|
11
11
|
NotEntitledReason["MISSING_PERMISSION"] = "MISSING_PERMISSION";
|
|
12
12
|
NotEntitledReason["MISSING_FEATURE"] = "MISSING_FEATURE";
|
|
13
13
|
NotEntitledReason["BUNDLE_EXPIRED"] = "BUNDLE_EXPIRED";
|
|
14
|
-
})(NotEntitledReason || (exports.NotEntitledReason = NotEntitledReason = {}));
|
|
14
|
+
})(NotEntitledReason || (exports.NotEntitledReason = NotEntitledReason = {}));
|
|
15
|
+
|
|
16
|
+
const ADMIN_PORTAL_ENTITLEMENTS_FF = 'admin_portal_entitlements';
|
|
17
|
+
exports.ADMIN_PORTAL_ENTITLEMENTS_FF = ADMIN_PORTAL_ENTITLEMENTS_FF;
|
package/node/index.js
CHANGED