@frontegg/redux-store 6.184.0 → 6.185.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.
- package/auth/Entitlements/saga.js +2 -5
- package/auth/Entitlements/utils.d.ts +9 -10
- package/auth/Entitlements/utils.js +11 -56
- package/index.js +1 -1
- package/node/auth/Entitlements/saga.js +1 -3
- package/node/auth/Entitlements/utils.js +10 -55
- package/node/index.js +1 -1
- package/package.json +1 -1
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import isEqual from 'fast-deep-equal';
|
|
2
2
|
import { call, put, takeLeading, select } from 'redux-saga/effects';
|
|
3
|
-
import {
|
|
3
|
+
import { api } from '@frontegg/rest-api';
|
|
4
4
|
import { actions } from '../reducer';
|
|
5
|
-
import { getFeatureFlags } from '../../helpers';
|
|
6
|
-
|
|
7
5
|
/**
|
|
8
6
|
* @param oldEntitlements
|
|
9
7
|
* @param newEntitlements
|
|
@@ -40,9 +38,8 @@ export function* loadEntitlements({
|
|
|
40
38
|
payload
|
|
41
39
|
}) {
|
|
42
40
|
const callback = payload == null ? void 0 : payload.callback;
|
|
43
|
-
const [useEntitlementsV2] = yield call(getFeatureFlags, [USE_ENTITLEMENTS_V2_ENDPOINT_FF]);
|
|
44
41
|
try {
|
|
45
|
-
const entitlements = yield call(
|
|
42
|
+
const entitlements = yield call(api.entitlements.loadEntitlementsV2);
|
|
46
43
|
yield handleFetchedEntitlements(entitlements);
|
|
47
44
|
callback == null ? void 0 : callback(true);
|
|
48
45
|
} catch (e) {
|
|
@@ -1,31 +1,30 @@
|
|
|
1
|
-
import { UserEntitlementsResponse } from '@frontegg/rest-api';
|
|
2
1
|
import { EntitledToOptions, Entitlement } from './interfaces';
|
|
3
2
|
import { UserEntitlementsContext as UserEntitlementsResponseV2 } from '@frontegg/entitlements-javascript-commons';
|
|
4
3
|
import { Attributes } from '@frontegg/entitlements-javascript-commons';
|
|
5
4
|
/**
|
|
6
5
|
@param entitlements
|
|
7
6
|
@param key permission key
|
|
8
|
-
@param attributes entitlements query attributes including
|
|
9
|
-
@param isV2
|
|
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
|
|
10
9
|
@returns if the user is entitled to the given permission. Attaching the justification if not
|
|
11
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
14
|
@param entitlements
|
|
16
15
|
@param key feature key
|
|
17
|
-
@param attributes entitlements query attributes including
|
|
18
|
-
@param isV2
|
|
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
|
|
19
18
|
@returns if the user is entitled to the given feature. Attaching the justification if not
|
|
20
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
23
|
@param entitlements
|
|
25
24
|
@param options including permission or feature
|
|
26
|
-
@param attributes entitlements query attributes including
|
|
27
|
-
@param isV2
|
|
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
|
|
28
27
|
@returns if the user is entitled to the given feature or permission (check only one). Attaching the justification if not
|
|
29
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;
|
|
@@ -1,16 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ContextHolder } from '@frontegg/rest-api';
|
|
2
2
|
import { evaluateIsEntitledToFeature, evaluateIsEntitledToPermissions } from '@frontegg/entitlements-javascript-commons';
|
|
3
|
-
/**
|
|
4
|
-
* NOTE: This file including the usage of user entitlements API V1 and V2. The BE API response is diffrent.
|
|
5
|
-
* V1 is the initial implementation.
|
|
6
|
-
* V2 is using the entitlenents package for Rule Based entitlements.
|
|
7
|
-
*
|
|
8
|
-
* V1 is still supported with feature flag but it's depracated.
|
|
9
|
-
*
|
|
10
|
-
* The entitlements query functions supports both APIs by an optional argument of [isV2] to decide what version to choose.
|
|
11
|
-
* The function returns the same type.
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
3
|
const ENTITLEMENTS_NOT_ENABLED_EXCEPTION_TEXT = 'You must first enable entitlements via Frontegg options to use this function';
|
|
15
4
|
|
|
16
5
|
/**
|
|
@@ -22,77 +11,43 @@ const guardEntitlementsUsage = () => {
|
|
|
22
11
|
throw new Error(ENTITLEMENTS_NOT_ENABLED_EXCEPTION_TEXT);
|
|
23
12
|
};
|
|
24
13
|
|
|
25
|
-
/**
|
|
26
|
-
For user entitlements API V1
|
|
27
|
-
|
|
28
|
-
@param keyEntitlements permission or feature data object
|
|
29
|
-
@param missingKeyEnum missing key for scenario that the key does not exist in entitlementsValuePerKeys
|
|
30
|
-
@returns if the user is entitled to the given key. Attaching the justification if not
|
|
31
|
-
@throws when entitlement is not enabled via frontegg options
|
|
32
|
-
*/
|
|
33
|
-
const getEntitlementsHelperV1 = (keyEntitlements, missingKeyEnum) => {
|
|
34
|
-
if (!keyEntitlements) {
|
|
35
|
-
return {
|
|
36
|
-
isEntitled: false,
|
|
37
|
-
justification: missingKeyEnum
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
if (keyEntitlements.isEntitled) {
|
|
41
|
-
return {
|
|
42
|
-
isEntitled: true
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
return {
|
|
46
|
-
isEntitled: false,
|
|
47
|
-
justification: keyEntitlements.justification
|
|
48
|
-
};
|
|
49
|
-
};
|
|
50
|
-
|
|
51
14
|
/**
|
|
52
15
|
@param entitlements
|
|
53
16
|
@param key permission key
|
|
54
|
-
@param attributes entitlements query attributes including
|
|
55
|
-
@param isV2
|
|
17
|
+
@param attributes entitlements query attributes including consumer and frontegg attributes
|
|
18
|
+
@param isV2 not in use. should be removed after removing from frontegg-vue
|
|
56
19
|
@returns if the user is entitled to the given permission. Attaching the justification if not
|
|
57
20
|
@throws when entitlement is not enabled via frontegg options
|
|
58
21
|
*/
|
|
59
22
|
export const getPermissionEntitlements = (entitlements, key, attributes, isV2) => {
|
|
60
|
-
var _permissions;
|
|
61
23
|
guardEntitlementsUsage();
|
|
62
|
-
|
|
63
|
-
return evaluateIsEntitledToPermissions(key, entitlements, attributes);
|
|
64
|
-
}
|
|
65
|
-
return getEntitlementsHelperV1(entitlements == null ? void 0 : (_permissions = entitlements.permissions) == null ? void 0 : _permissions[key], NotEntitledJustification.MISSING_PERMISSION);
|
|
24
|
+
return evaluateIsEntitledToPermissions(key, entitlements, attributes);
|
|
66
25
|
};
|
|
67
26
|
|
|
68
27
|
/**
|
|
69
28
|
@param entitlements
|
|
70
29
|
@param key feature key
|
|
71
|
-
@param attributes entitlements query attributes including
|
|
72
|
-
@param isV2
|
|
30
|
+
@param attributes entitlements query attributes including consumer and frontegg attributes
|
|
31
|
+
@param isV2 not in use. should be removed after removing from frontegg-vue
|
|
73
32
|
@returns if the user is entitled to the given feature. Attaching the justification if not
|
|
74
33
|
@throws when entitlement is not enabled via frontegg options
|
|
75
34
|
*/
|
|
76
35
|
export const getFeatureEntitlements = (entitlements, key, attributes, isV2) => {
|
|
77
|
-
var _features;
|
|
78
36
|
guardEntitlementsUsage();
|
|
79
|
-
|
|
80
|
-
return evaluateIsEntitledToFeature(key, entitlements, attributes);
|
|
81
|
-
}
|
|
82
|
-
return getEntitlementsHelperV1(entitlements == null ? void 0 : (_features = entitlements.features) == null ? void 0 : _features[key], NotEntitledJustification.MISSING_FEATURE);
|
|
37
|
+
return evaluateIsEntitledToFeature(key, entitlements, attributes);
|
|
83
38
|
};
|
|
84
39
|
|
|
85
40
|
/**
|
|
86
41
|
@param entitlements
|
|
87
42
|
@param options including permission or feature
|
|
88
|
-
@param attributes entitlements query attributes including
|
|
89
|
-
@param isV2
|
|
43
|
+
@param attributes entitlements query attributes including consumer and frontegg attributes
|
|
44
|
+
@param isV2 not in use. should be removed after removing from frontegg-vue
|
|
90
45
|
@returns if the user is entitled to the given feature or permission (check only one). Attaching the justification if not
|
|
91
46
|
@throws when entitlement is not enabled via frontegg options
|
|
92
47
|
*/
|
|
93
48
|
export const getEntitlements = (entitlements, options, attributes, isV2) => {
|
|
94
49
|
if ('permissionKey' in options) {
|
|
95
|
-
return getPermissionEntitlements(entitlements, options.permissionKey, attributes
|
|
50
|
+
return getPermissionEntitlements(entitlements, options.permissionKey, attributes);
|
|
96
51
|
}
|
|
97
|
-
return getFeatureEntitlements(entitlements, options.featureKey, attributes
|
|
52
|
+
return getFeatureEntitlements(entitlements, options.featureKey, attributes);
|
|
98
53
|
};
|
package/index.js
CHANGED
|
@@ -12,7 +12,6 @@ var _fastDeepEqual = _interopRequireDefault(require("fast-deep-equal"));
|
|
|
12
12
|
var _effects = require("redux-saga/effects");
|
|
13
13
|
var _restApi = require("@frontegg/rest-api");
|
|
14
14
|
var _reducer = require("../reducer");
|
|
15
|
-
var _helpers = require("../../helpers");
|
|
16
15
|
/**
|
|
17
16
|
* @param oldEntitlements
|
|
18
17
|
* @param newEntitlements
|
|
@@ -49,9 +48,8 @@ function* loadEntitlements({
|
|
|
49
48
|
payload
|
|
50
49
|
}) {
|
|
51
50
|
const callback = payload == null ? void 0 : payload.callback;
|
|
52
|
-
const [useEntitlementsV2] = yield (0, _effects.call)(_helpers.getFeatureFlags, [_restApi.USE_ENTITLEMENTS_V2_ENDPOINT_FF]);
|
|
53
51
|
try {
|
|
54
|
-
const entitlements = yield (0, _effects.call)(
|
|
52
|
+
const entitlements = yield (0, _effects.call)(_restApi.api.entitlements.loadEntitlementsV2);
|
|
55
53
|
yield handleFetchedEntitlements(entitlements);
|
|
56
54
|
callback == null ? void 0 : callback(true);
|
|
57
55
|
} catch (e) {
|
|
@@ -6,17 +6,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.getPermissionEntitlements = exports.getFeatureEntitlements = exports.getEntitlements = void 0;
|
|
7
7
|
var _restApi = require("@frontegg/rest-api");
|
|
8
8
|
var _entitlementsJavascriptCommons = require("@frontegg/entitlements-javascript-commons");
|
|
9
|
-
/**
|
|
10
|
-
* NOTE: This file including the usage of user entitlements API V1 and V2. The BE API response is diffrent.
|
|
11
|
-
* V1 is the initial implementation.
|
|
12
|
-
* V2 is using the entitlenents package for Rule Based entitlements.
|
|
13
|
-
*
|
|
14
|
-
* V1 is still supported with feature flag but it's depracated.
|
|
15
|
-
*
|
|
16
|
-
* The entitlements query functions supports both APIs by an optional argument of [isV2] to decide what version to choose.
|
|
17
|
-
* The function returns the same type.
|
|
18
|
-
*/
|
|
19
|
-
|
|
20
9
|
const ENTITLEMENTS_NOT_ENABLED_EXCEPTION_TEXT = 'You must first enable entitlements via Frontegg options to use this function';
|
|
21
10
|
|
|
22
11
|
/**
|
|
@@ -28,80 +17,46 @@ const guardEntitlementsUsage = () => {
|
|
|
28
17
|
throw new Error(ENTITLEMENTS_NOT_ENABLED_EXCEPTION_TEXT);
|
|
29
18
|
};
|
|
30
19
|
|
|
31
|
-
/**
|
|
32
|
-
For user entitlements API V1
|
|
33
|
-
|
|
34
|
-
@param keyEntitlements permission or feature data object
|
|
35
|
-
@param missingKeyEnum missing key for scenario that the key does not exist in entitlementsValuePerKeys
|
|
36
|
-
@returns if the user is entitled to the given key. Attaching the justification if not
|
|
37
|
-
@throws when entitlement is not enabled via frontegg options
|
|
38
|
-
*/
|
|
39
|
-
const getEntitlementsHelperV1 = (keyEntitlements, missingKeyEnum) => {
|
|
40
|
-
if (!keyEntitlements) {
|
|
41
|
-
return {
|
|
42
|
-
isEntitled: false,
|
|
43
|
-
justification: missingKeyEnum
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
if (keyEntitlements.isEntitled) {
|
|
47
|
-
return {
|
|
48
|
-
isEntitled: true
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
return {
|
|
52
|
-
isEntitled: false,
|
|
53
|
-
justification: keyEntitlements.justification
|
|
54
|
-
};
|
|
55
|
-
};
|
|
56
|
-
|
|
57
20
|
/**
|
|
58
21
|
@param entitlements
|
|
59
22
|
@param key permission key
|
|
60
|
-
@param attributes entitlements query attributes including
|
|
61
|
-
@param isV2
|
|
23
|
+
@param attributes entitlements query attributes including consumer and frontegg attributes
|
|
24
|
+
@param isV2 not in use. should be removed after removing from frontegg-vue
|
|
62
25
|
@returns if the user is entitled to the given permission. Attaching the justification if not
|
|
63
26
|
@throws when entitlement is not enabled via frontegg options
|
|
64
27
|
*/
|
|
65
28
|
const getPermissionEntitlements = (entitlements, key, attributes, isV2) => {
|
|
66
|
-
var _permissions;
|
|
67
29
|
guardEntitlementsUsage();
|
|
68
|
-
|
|
69
|
-
return (0, _entitlementsJavascriptCommons.evaluateIsEntitledToPermissions)(key, entitlements, attributes);
|
|
70
|
-
}
|
|
71
|
-
return getEntitlementsHelperV1(entitlements == null ? void 0 : (_permissions = entitlements.permissions) == null ? void 0 : _permissions[key], _restApi.NotEntitledJustification.MISSING_PERMISSION);
|
|
30
|
+
return (0, _entitlementsJavascriptCommons.evaluateIsEntitledToPermissions)(key, entitlements, attributes);
|
|
72
31
|
};
|
|
73
32
|
|
|
74
33
|
/**
|
|
75
34
|
@param entitlements
|
|
76
35
|
@param key feature key
|
|
77
|
-
@param attributes entitlements query attributes including
|
|
78
|
-
@param isV2
|
|
36
|
+
@param attributes entitlements query attributes including consumer and frontegg attributes
|
|
37
|
+
@param isV2 not in use. should be removed after removing from frontegg-vue
|
|
79
38
|
@returns if the user is entitled to the given feature. Attaching the justification if not
|
|
80
39
|
@throws when entitlement is not enabled via frontegg options
|
|
81
40
|
*/
|
|
82
41
|
exports.getPermissionEntitlements = getPermissionEntitlements;
|
|
83
42
|
const getFeatureEntitlements = (entitlements, key, attributes, isV2) => {
|
|
84
|
-
var _features;
|
|
85
43
|
guardEntitlementsUsage();
|
|
86
|
-
|
|
87
|
-
return (0, _entitlementsJavascriptCommons.evaluateIsEntitledToFeature)(key, entitlements, attributes);
|
|
88
|
-
}
|
|
89
|
-
return getEntitlementsHelperV1(entitlements == null ? void 0 : (_features = entitlements.features) == null ? void 0 : _features[key], _restApi.NotEntitledJustification.MISSING_FEATURE);
|
|
44
|
+
return (0, _entitlementsJavascriptCommons.evaluateIsEntitledToFeature)(key, entitlements, attributes);
|
|
90
45
|
};
|
|
91
46
|
|
|
92
47
|
/**
|
|
93
48
|
@param entitlements
|
|
94
49
|
@param options including permission or feature
|
|
95
|
-
@param attributes entitlements query attributes including
|
|
96
|
-
@param isV2
|
|
50
|
+
@param attributes entitlements query attributes including consumer and frontegg attributes
|
|
51
|
+
@param isV2 not in use. should be removed after removing from frontegg-vue
|
|
97
52
|
@returns if the user is entitled to the given feature or permission (check only one). Attaching the justification if not
|
|
98
53
|
@throws when entitlement is not enabled via frontegg options
|
|
99
54
|
*/
|
|
100
55
|
exports.getFeatureEntitlements = getFeatureEntitlements;
|
|
101
56
|
const getEntitlements = (entitlements, options, attributes, isV2) => {
|
|
102
57
|
if ('permissionKey' in options) {
|
|
103
|
-
return getPermissionEntitlements(entitlements, options.permissionKey, attributes
|
|
58
|
+
return getPermissionEntitlements(entitlements, options.permissionKey, attributes);
|
|
104
59
|
}
|
|
105
|
-
return getFeatureEntitlements(entitlements, options.featureKey, attributes
|
|
60
|
+
return getFeatureEntitlements(entitlements, options.featureKey, attributes);
|
|
106
61
|
};
|
|
107
62
|
exports.getEntitlements = getEntitlements;
|
package/node/index.js
CHANGED