@frontegg/entitlements-javascript-commons 1.0.1 → 1.1.0-alpha.2
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/dist/plans/index.d.ts +2 -0
- package/dist/plans/index.js +18 -0
- package/dist/plans/index.js.map +1 -0
- package/dist/plans/plan.evaluator.d.ts +2 -0
- package/dist/plans/plan.evaluator.js +21 -0
- package/dist/plans/plan.evaluator.js.map +1 -0
- package/dist/plans/types.d.ts +8 -0
- package/dist/plans/types.js +3 -0
- package/dist/plans/types.js.map +1 -0
- package/dist/user-entitlements/index.d.ts +3 -3
- package/dist/user-entitlements/index.js +3 -3
- package/dist/user-entitlements/index.js.map +1 -1
- package/dist/user-entitlements/is-entitled-to-feature/evaluators/direct-entitlement.evaluator.d.ts +2 -0
- package/dist/user-entitlements/is-entitled-to-feature/evaluators/direct-entitlement.evaluator.js +20 -0
- package/dist/user-entitlements/is-entitled-to-feature/evaluators/direct-entitlement.evaluator.js.map +1 -0
- package/dist/user-entitlements/is-entitled-to-feature/evaluators/feature-flag.evaluator.d.ts +2 -0
- package/dist/user-entitlements/is-entitled-to-feature/evaluators/feature-flag.evaluator.js +23 -0
- package/dist/user-entitlements/is-entitled-to-feature/evaluators/feature-flag.evaluator.js.map +1 -0
- package/dist/user-entitlements/is-entitled-to-feature/evaluators/index.d.ts +2 -0
- package/dist/user-entitlements/is-entitled-to-feature/evaluators/index.js +11 -0
- package/dist/user-entitlements/is-entitled-to-feature/evaluators/index.js.map +1 -0
- package/dist/user-entitlements/is-entitled-to-feature/evaluators/plan-targeting-rules.evaluator.d.ts +2 -0
- package/dist/user-entitlements/is-entitled-to-feature/evaluators/plan-targeting-rules.evaluator.js +29 -0
- package/dist/user-entitlements/is-entitled-to-feature/evaluators/plan-targeting-rules.evaluator.js.map +1 -0
- package/dist/user-entitlements/is-entitled-to-feature/evaluators/types.d.ts +2 -0
- package/dist/user-entitlements/is-entitled-to-feature/evaluators/types.js +3 -0
- package/dist/user-entitlements/is-entitled-to-feature/evaluators/types.js.map +1 -0
- package/dist/user-entitlements/is-entitled-to-feature/index.d.ts +1 -0
- package/dist/user-entitlements/is-entitled-to-feature/index.js +18 -0
- package/dist/user-entitlements/is-entitled-to-feature/index.js.map +1 -0
- package/dist/user-entitlements/{is-entitled.evaluator.d.ts → is-entitled-to-feature/is-entitled-to-feature.evaluator.d.ts} +1 -2
- package/dist/user-entitlements/is-entitled-to-feature/is-entitled-to-feature.evaluator.js +17 -0
- package/dist/user-entitlements/is-entitled-to-feature/is-entitled-to-feature.evaluator.js.map +1 -0
- package/dist/user-entitlements/is-entitled-to-permission/index.d.ts +1 -0
- package/dist/user-entitlements/is-entitled-to-permission/index.js +18 -0
- package/dist/user-entitlements/is-entitled-to-permission/index.js.map +1 -0
- package/dist/user-entitlements/is-entitled-to-permission/is-entitled-to-permission.evaluator.d.ts +2 -0
- package/dist/user-entitlements/is-entitled-to-permission/is-entitled-to-permission.evaluator.js +30 -0
- package/dist/user-entitlements/is-entitled-to-permission/is-entitled-to-permission.evaluator.js.map +1 -0
- package/dist/user-entitlements/types.d.ts +7 -2
- package/dist/user-entitlements/types.js.map +1 -1
- package/dist/user-entitlements/{attributes.utils.d.ts → utils/attributes.utils.d.ts} +1 -1
- package/dist/user-entitlements/utils/attributes.utils.js.map +1 -0
- package/dist/user-entitlements/utils/entitlement-results.utils.d.ts +3 -0
- package/dist/user-entitlements/utils/entitlement-results.utils.js +25 -0
- package/dist/user-entitlements/utils/entitlement-results.utils.js.map +1 -0
- package/dist/user-entitlements/utils/flatten.utils.js.map +1 -0
- package/dist/user-entitlements/utils/index.d.ts +3 -0
- package/dist/user-entitlements/utils/index.js +20 -0
- package/dist/user-entitlements/utils/index.js.map +1 -0
- package/dist/user-entitlements/{permissions.utils.d.ts → utils/permissions.utils.d.ts} +1 -1
- package/dist/user-entitlements/utils/permissions.utils.js.map +1 -0
- package/docs/CHANGELOG.md +14 -0
- package/package.json +1 -1
- package/src/plans/index.ts +2 -0
- package/src/plans/plan.evaluator.ts +20 -0
- package/src/plans/tests/plans.evaluator.spec.ts +121 -0
- package/src/plans/types.ts +11 -0
- package/src/user-entitlements/index.ts +3 -3
- package/src/user-entitlements/is-entitled-to-feature/evaluators/direct-entitlement.evaluator.ts +28 -0
- package/src/user-entitlements/is-entitled-to-feature/evaluators/feature-flag.evaluator.ts +24 -0
- package/src/user-entitlements/is-entitled-to-feature/evaluators/index.ts +8 -0
- package/src/user-entitlements/is-entitled-to-feature/evaluators/plan-targeting-rules.evaluator.ts +30 -0
- package/src/user-entitlements/is-entitled-to-feature/evaluators/tests/direct-entitlements.evaluator.spec.ts +81 -0
- package/src/user-entitlements/is-entitled-to-feature/evaluators/tests/feature-flag.evaluator.spec.ts +57 -0
- package/src/user-entitlements/is-entitled-to-feature/evaluators/tests/plan-targeting-rules.evaluator.spec.ts +70 -0
- package/src/user-entitlements/is-entitled-to-feature/evaluators/types.ts +7 -0
- package/src/user-entitlements/is-entitled-to-feature/index.ts +1 -0
- package/src/user-entitlements/is-entitled-to-feature/is-entitled-to-feature.evaluator.ts +18 -0
- package/src/user-entitlements/is-entitled-to-feature/tests/is-entitled-to-feature.evaluator.spec.ts +68 -0
- package/src/user-entitlements/is-entitled-to-permission/index.ts +1 -0
- package/src/user-entitlements/is-entitled-to-permission/is-entitled-to-permission.evaluator.ts +38 -0
- package/src/user-entitlements/is-entitled-to-permission/tests/is-entitled-to-permission.evaluator.spec.ts +79 -0
- package/src/user-entitlements/types.ts +11 -4
- package/src/user-entitlements/{attributes.utils.ts → utils/attributes.utils.ts} +1 -1
- package/src/user-entitlements/utils/entitlement-results.utils.ts +22 -0
- package/src/user-entitlements/utils/index.ts +3 -0
- package/src/user-entitlements/{permissions.utils.ts → utils/permissions.utils.ts} +1 -1
- package/src/user-entitlements/{tests → utils/tests}/attributes.utils.spec.ts +1 -1
- package/src/user-entitlements/utils/tests/entitlement-results.utils.spec.ts +46 -0
- package/src/user-entitlements/{tests → utils/tests}/permissions.utils.spec.ts +1 -1
- package/dist/user-entitlements/attributes.utils.js.map +0 -1
- package/dist/user-entitlements/flatten.utils.js.map +0 -1
- package/dist/user-entitlements/is-entitled.evaluator.js +0 -59
- package/dist/user-entitlements/is-entitled.evaluator.js.map +0 -1
- package/dist/user-entitlements/permissions.utils.js.map +0 -1
- package/src/user-entitlements/is-entitled.evaluator.ts +0 -82
- package/src/user-entitlements/tests/is-entitled.evaluator.spec.ts +0 -298
- /package/dist/user-entitlements/{attributes.utils.js → utils/attributes.utils.js} +0 -0
- /package/dist/user-entitlements/{flatten.utils.d.ts → utils/flatten.utils.d.ts} +0 -0
- /package/dist/user-entitlements/{flatten.utils.js → utils/flatten.utils.js} +0 -0
- /package/dist/user-entitlements/{permissions.utils.js → utils/permissions.utils.js} +0 -0
- /package/src/user-entitlements/{flatten.utils.ts → utils/flatten.utils.ts} +0 -0
|
@@ -1,20 +1,27 @@
|
|
|
1
1
|
import { FeatureFlag } from '../feature-flags/types';
|
|
2
|
+
import { Plan } from '../plans';
|
|
2
3
|
export type UserEntitlementsContext = {
|
|
3
4
|
features: Record<
|
|
4
5
|
string,
|
|
5
6
|
{
|
|
7
|
+
planIds: string[];
|
|
6
8
|
expireTime: number | null;
|
|
7
9
|
linkedPermissions: string[];
|
|
8
10
|
featureFlag?: FeatureFlag;
|
|
9
11
|
}
|
|
10
12
|
>;
|
|
13
|
+
plans: Record<string, Plan>;
|
|
11
14
|
permissions: Permissions;
|
|
12
15
|
};
|
|
13
16
|
|
|
14
|
-
export type EntitlementResult =
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
17
|
+
export type EntitlementResult =
|
|
18
|
+
| {
|
|
19
|
+
isEntitled: true;
|
|
20
|
+
}
|
|
21
|
+
| {
|
|
22
|
+
isEntitled: false;
|
|
23
|
+
justification: NotEntitledJustification;
|
|
24
|
+
};
|
|
18
25
|
|
|
19
26
|
export enum NotEntitledJustification {
|
|
20
27
|
MISSING_FEATURE = 'MISSING_FEATURE',
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Attributes, JwtAttributes, FronteggAttributes } from '
|
|
1
|
+
import { Attributes, JwtAttributes, FronteggAttributes } from '../types';
|
|
2
2
|
import { flatten } from './flatten.utils';
|
|
3
3
|
/**
|
|
4
4
|
* Merges both `custom` and `jwt` records, map Frontegg attributes and modifies record keys with corrisponding prefixes
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { EntitlementResult, NotEntitledJustification } from '../types';
|
|
2
|
+
export function getResult(entitlementResults: EntitlementResult[]): EntitlementResult {
|
|
3
|
+
let hasExpired = false;
|
|
4
|
+
for (const entitlementResult of entitlementResults) {
|
|
5
|
+
if (entitlementResult.isEntitled) {
|
|
6
|
+
return entitlementResult;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
if (entitlementResult.justification === NotEntitledJustification.BUNDLE_EXPIRED) {
|
|
10
|
+
hasExpired = true;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return {
|
|
15
|
+
isEntitled: false,
|
|
16
|
+
justification: hasExpired ? NotEntitledJustification.BUNDLE_EXPIRED : NotEntitledJustification.MISSING_FEATURE,
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function shouldContinue(entitlementResults: EntitlementResult[]): boolean {
|
|
21
|
+
return entitlementResults.every(({ isEntitled }) => !isEntitled);
|
|
22
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Permissions } from '
|
|
1
|
+
import { Permissions } from '../types';
|
|
2
2
|
export function checkPermission(permissions: Permissions, requiredPermission: string): boolean {
|
|
3
3
|
return Object.keys(permissions).some((permissionKey) =>
|
|
4
4
|
createPermissionCheckRegex(permissionKey).test(requiredPermission),
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as AttributesUtils from '../attributes.utils';
|
|
2
|
-
import { Attributes, FronteggAttributes, JwtAttributes } from '
|
|
2
|
+
import { Attributes, FronteggAttributes, JwtAttributes } from '../../types';
|
|
3
3
|
describe('prepareAttributes', () => {
|
|
4
4
|
test('given custom & jwt attributes, expected is merged & flatten attributes record', () => {
|
|
5
5
|
const attributes: Attributes = {
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { EntitlementResult, NotEntitledJustification } from '../../types';
|
|
2
|
+
import { getResult, shouldContinue } from '../entitlement-results.utils';
|
|
3
|
+
describe('getResult', () => {
|
|
4
|
+
describe('entitled', () => {
|
|
5
|
+
test('given some of the results are truthy, exected is entitled', async () => {
|
|
6
|
+
const entitlementsResults: EntitlementResult[] = [
|
|
7
|
+
{ isEntitled: false, justification: NotEntitledJustification.MISSING_FEATURE },
|
|
8
|
+
{ isEntitled: true },
|
|
9
|
+
];
|
|
10
|
+
|
|
11
|
+
const result = getResult(entitlementsResults);
|
|
12
|
+
|
|
13
|
+
expect(result).toEqual({ isEntitled: true });
|
|
14
|
+
});
|
|
15
|
+
});
|
|
16
|
+
describe('not-entitled', () => {
|
|
17
|
+
test('given all of results are falsy with missing feature, expected is not entitled with missing feature justification', async () => {
|
|
18
|
+
const entitlementsResults: EntitlementResult[] = [
|
|
19
|
+
{ isEntitled: false, justification: NotEntitledJustification.MISSING_FEATURE },
|
|
20
|
+
{ isEntitled: false, justification: NotEntitledJustification.MISSING_FEATURE },
|
|
21
|
+
];
|
|
22
|
+
|
|
23
|
+
const result = getResult(entitlementsResults);
|
|
24
|
+
|
|
25
|
+
expect(result).toEqual({ isEntitled: false, justification: NotEntitledJustification.MISSING_FEATURE });
|
|
26
|
+
});
|
|
27
|
+
test('given all of results are falsy with some expired, expected is not entitled with expired justification', async () => {
|
|
28
|
+
const entitlementsResults: EntitlementResult[] = [
|
|
29
|
+
{ isEntitled: false, justification: NotEntitledJustification.MISSING_FEATURE },
|
|
30
|
+
{ isEntitled: false, justification: NotEntitledJustification.BUNDLE_EXPIRED },
|
|
31
|
+
];
|
|
32
|
+
|
|
33
|
+
const result = getResult(entitlementsResults);
|
|
34
|
+
|
|
35
|
+
expect(result).toEqual({ isEntitled: false, justification: NotEntitledJustification.BUNDLE_EXPIRED });
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
test('given empty results, expected is not entitled with missing feature justification', async () => {
|
|
39
|
+
const entitlementsResults: EntitlementResult[] = [];
|
|
40
|
+
|
|
41
|
+
const result = getResult(entitlementsResults);
|
|
42
|
+
|
|
43
|
+
expect(result).toEqual({ isEntitled: false, justification: NotEntitledJustification.MISSING_FEATURE });
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"attributes.utils.js","sourceRoot":"","sources":["../../src/user-entitlements/attributes.utils.ts"],"names":[],"mappings":";;;AACA,mDAA0C;AAC1C;;;;;;GAMG;AACH,SAAgB,iBAAiB,CAC/B,aAAyB,EAAE,EAC3B,8BAAqF;IAErF,MAAM,EAAE,MAAM,GAAG,EAAE,EAAE,GAAG,GAAG,EAAE,EAAE,GAAG,UAAU,CAAC;IAC7C,MAAM,iBAAiB,GAAG,IAAA,uBAAO,EAA+B,GAAG,CAAC,CAAC;IACrE,MAAM,kBAAkB,GAAG,8BAA8B;QACvD,CAAC,CAAC,8BAA8B,CAAC,GAAG,CAAC;QACrC,CAAC,CAAC,+BAA+B,CAAC,GAAG,CAAC,CAAC;IACzC,MAAM,wBAAwB,GAAG,WAAW,CAAC;IAC7C,MAAM,mBAAmB,GAAG,MAAM,CAAC;IAEnC,OAAO;QACL,GAAG,MAAM;QACT,GAAG,0BAA0B,CAAC,kBAAkB,EAAE,wBAAwB,CAAC;QAC3E,GAAG,0BAA0B,CAAC,iBAAiB,EAAE,mBAAmB,CAAC;KACtE,CAAC;AACJ,CAAC;AAjBD,8CAiBC;AAED,SAAgB,+BAA+B,CAAC,GAAkB;IAChE,OAAO;QACL,KAAK,EAAE,GAAG,CAAC,KAAe;QAC1B,aAAa,EAAE,GAAG,CAAC,cAAyB;QAC5C,QAAQ,EAAE,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ict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.evaluateIsEntitledToPermissions = exports.evaluateIsEntitledToFeature = void 0;
|
|
4
|
-
const types_1 = require("./types");
|
|
5
|
-
const feature_flags_1 = require("../feature-flags");
|
|
6
|
-
const attributes_utils_1 = require("./attributes.utils");
|
|
7
|
-
const rules_1 = require("../rules");
|
|
8
|
-
const permissions_utils_1 = require("./permissions.utils");
|
|
9
|
-
function evaluateIsEntitledToFeature(featureKey, userEntitlementsContext, attributes = {}) {
|
|
10
|
-
const feature = userEntitlementsContext.features[featureKey];
|
|
11
|
-
let hasExpired = false;
|
|
12
|
-
if (feature && feature.expireTime !== null) {
|
|
13
|
-
hasExpired = feature.expireTime !== types_1.NO_EXPIRATION_TIME && feature.expireTime < Date.now();
|
|
14
|
-
if (!hasExpired) {
|
|
15
|
-
return { isEntitled: true };
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
if (feature && feature.featureFlag) {
|
|
19
|
-
const preparedAttributes = (0, attributes_utils_1.prepareAttributes)(attributes);
|
|
20
|
-
const { treatment } = (0, feature_flags_1.evaluateFeatureFlag)(feature.featureFlag, preparedAttributes);
|
|
21
|
-
if (treatment === rules_1.TreatmentEnum.True) {
|
|
22
|
-
return { isEntitled: true };
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
return {
|
|
26
|
-
isEntitled: false,
|
|
27
|
-
justification: hasExpired ? types_1.NotEntitledJustification.BUNDLE_EXPIRED : types_1.NotEntitledJustification.MISSING_FEATURE,
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
exports.evaluateIsEntitledToFeature = evaluateIsEntitledToFeature;
|
|
31
|
-
function evaluateIsEntitledToPermissions(permissionKey, userEntitlementsContext, attributes) {
|
|
32
|
-
const hasPermission = (0, permissions_utils_1.checkPermission)(userEntitlementsContext.permissions, permissionKey);
|
|
33
|
-
if (!hasPermission) {
|
|
34
|
-
return { isEntitled: false, justification: types_1.NotEntitledJustification.MISSING_PERMISSION };
|
|
35
|
-
}
|
|
36
|
-
const linkedFeatures = getLinkedFeatures(permissionKey, userEntitlementsContext);
|
|
37
|
-
if (!linkedFeatures.length) {
|
|
38
|
-
return { isEntitled: true };
|
|
39
|
-
}
|
|
40
|
-
let hasExpired = false;
|
|
41
|
-
for (const featureKey of linkedFeatures) {
|
|
42
|
-
const { isEntitled, justification } = evaluateIsEntitledToFeature(featureKey, userEntitlementsContext, attributes);
|
|
43
|
-
if (isEntitled) {
|
|
44
|
-
return { isEntitled: true };
|
|
45
|
-
}
|
|
46
|
-
if (justification === types_1.NotEntitledJustification.BUNDLE_EXPIRED) {
|
|
47
|
-
hasExpired = true;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
return {
|
|
51
|
-
isEntitled: false,
|
|
52
|
-
justification: hasExpired ? types_1.NotEntitledJustification.BUNDLE_EXPIRED : types_1.NotEntitledJustification.MISSING_FEATURE,
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
exports.evaluateIsEntitledToPermissions = evaluateIsEntitledToPermissions;
|
|
56
|
-
function getLinkedFeatures(permissionKey, userEntitlementsContext) {
|
|
57
|
-
return Object.keys(userEntitlementsContext.features).filter((featureKey) => userEntitlementsContext.features[featureKey].linkedPermissions.includes(permissionKey));
|
|
58
|
-
}
|
|
59
|
-
//# sourceMappingURL=is-entitled.evaluator.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"is-entitled.evaluator.js","sourceRoot":"","sources":["../../src/user-entitlements/is-entitled.evaluator.ts"],"names":[],"mappings":";;;AAAA,mCAMiB;AAEjB,oDAAuD;AACvD,yDAAuD;AACvD,oCAAyC;AACzC,2DAAsD;AACtD,SAAgB,2BAA2B,CACzC,UAAkB,EAClB,uBAAgD,EAChD,aAAyB,EAAE;IAE3B,MAAM,OAAO,GAAG,uBAAuB,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;IAC7D,IAAI,UAAU,GAAG,KAAK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AAO,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,GAAG,GAAG,EAAE,IAAI,CAAC,CAAC;AAChG,CAAC;AAFD,gEAEC"}
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
EntitlementResult,
|
|
3
|
-
NotEntitledJustification,
|
|
4
|
-
NO_EXPIRATION_TIME,
|
|
5
|
-
UserEntitlementsContext,
|
|
6
|
-
Attributes,
|
|
7
|
-
} from './types';
|
|
8
|
-
|
|
9
|
-
import { evaluateFeatureFlag } from '../feature-flags';
|
|
10
|
-
import { prepareAttributes } from './attributes.utils';
|
|
11
|
-
import { TreatmentEnum } from '../rules';
|
|
12
|
-
import { checkPermission } from './permissions.utils';
|
|
13
|
-
export function evaluateIsEntitledToFeature(
|
|
14
|
-
featureKey: string,
|
|
15
|
-
userEntitlementsContext: UserEntitlementsContext,
|
|
16
|
-
attributes: Attributes = {},
|
|
17
|
-
): EntitlementResult {
|
|
18
|
-
const feature = userEntitlementsContext.features[featureKey];
|
|
19
|
-
let hasExpired = false;
|
|
20
|
-
if (feature && feature.expireTime !== null) {
|
|
21
|
-
hasExpired = feature.expireTime !== NO_EXPIRATION_TIME && feature.expireTime < Date.now();
|
|
22
|
-
|
|
23
|
-
if (!hasExpired) {
|
|
24
|
-
return { isEntitled: true };
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
if (feature && feature.featureFlag) {
|
|
29
|
-
const preparedAttributes = prepareAttributes(attributes);
|
|
30
|
-
const { treatment } = evaluateFeatureFlag(feature.featureFlag, preparedAttributes);
|
|
31
|
-
if (treatment === TreatmentEnum.True) {
|
|
32
|
-
return { isEntitled: true };
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
return {
|
|
37
|
-
isEntitled: false,
|
|
38
|
-
justification: hasExpired ? NotEntitledJustification.BUNDLE_EXPIRED : NotEntitledJustification.MISSING_FEATURE,
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export function evaluateIsEntitledToPermissions(
|
|
43
|
-
permissionKey: string,
|
|
44
|
-
userEntitlementsContext: UserEntitlementsContext,
|
|
45
|
-
attributes?: Attributes,
|
|
46
|
-
): EntitlementResult {
|
|
47
|
-
const hasPermission = checkPermission(userEntitlementsContext.permissions, permissionKey);
|
|
48
|
-
if (!hasPermission) {
|
|
49
|
-
return { isEntitled: false, justification: NotEntitledJustification.MISSING_PERMISSION };
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
const linkedFeatures = getLinkedFeatures(permissionKey, userEntitlementsContext);
|
|
53
|
-
|
|
54
|
-
if (!linkedFeatures.length) {
|
|
55
|
-
return { isEntitled: true };
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
let hasExpired = false;
|
|
59
|
-
|
|
60
|
-
for (const featureKey of linkedFeatures) {
|
|
61
|
-
const { isEntitled, justification } = evaluateIsEntitledToFeature(featureKey, userEntitlementsContext, attributes);
|
|
62
|
-
|
|
63
|
-
if (isEntitled) {
|
|
64
|
-
return { isEntitled: true };
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
if (justification === NotEntitledJustification.BUNDLE_EXPIRED) {
|
|
68
|
-
hasExpired = true;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
return {
|
|
73
|
-
isEntitled: false,
|
|
74
|
-
justification: hasExpired ? NotEntitledJustification.BUNDLE_EXPIRED : NotEntitledJustification.MISSING_FEATURE,
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
function getLinkedFeatures(permissionKey: string, userEntitlementsContext: UserEntitlementsContext): string[] {
|
|
79
|
-
return Object.keys(userEntitlementsContext.features).filter((featureKey) =>
|
|
80
|
-
userEntitlementsContext.features[featureKey].linkedPermissions.includes(permissionKey),
|
|
81
|
-
);
|
|
82
|
-
}
|
|
@@ -1,298 +0,0 @@
|
|
|
1
|
-
import * as IsEntitledEvaluators from '../is-entitled.evaluator';
|
|
2
|
-
import * as FeatureFlagEvalutor from '../../feature-flags/feature-flag.evaluator';
|
|
3
|
-
import * as AttributesUtils from '../attributes.utils';
|
|
4
|
-
import { TreatmentEnum } from '../../rules';
|
|
5
|
-
import { EntitlementResult, NotEntitledJustification, NO_EXPIRATION_TIME, UserEntitlementsContext } from '../types';
|
|
6
|
-
import { FeatureFlag } from '../../feature-flags/types';
|
|
7
|
-
|
|
8
|
-
const mockFeatureFlag: FeatureFlag = {
|
|
9
|
-
on: true,
|
|
10
|
-
defaultTreatment: TreatmentEnum.True,
|
|
11
|
-
offTreatment: TreatmentEnum.False,
|
|
12
|
-
rules: [],
|
|
13
|
-
};
|
|
14
|
-
const truthyEntitlementResult: EntitlementResult = {
|
|
15
|
-
isEntitled: true,
|
|
16
|
-
};
|
|
17
|
-
const falsyEntitlementResultMissingFeature: EntitlementResult = {
|
|
18
|
-
isEntitled: false,
|
|
19
|
-
justification: NotEntitledJustification.MISSING_FEATURE,
|
|
20
|
-
};
|
|
21
|
-
const falsyEntitlementResultBundleExpired: EntitlementResult = {
|
|
22
|
-
isEntitled: false,
|
|
23
|
-
justification: NotEntitledJustification.BUNDLE_EXPIRED,
|
|
24
|
-
};
|
|
25
|
-
const falsyEntitlementResultMissingPermission: EntitlementResult = {
|
|
26
|
-
isEntitled: false,
|
|
27
|
-
justification: NotEntitledJustification.MISSING_PERMISSION,
|
|
28
|
-
};
|
|
29
|
-
describe('evaluateIsEntitledToFeature', () => {
|
|
30
|
-
beforeAll(() => {
|
|
31
|
-
jest.spyOn(AttributesUtils, 'prepareAttributes').mockReturnValue({ testAttribute: 'test-value' });
|
|
32
|
-
});
|
|
33
|
-
describe('entitled', () => {
|
|
34
|
-
describe('feature-flag evaluated truthy', () => {
|
|
35
|
-
beforeAll(async () => {
|
|
36
|
-
jest.spyOn(FeatureFlagEvalutor, 'evaluateFeatureFlag').mockReturnValue({ treatment: TreatmentEnum.True });
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
test('feature granted with valid expiration date', async () => {
|
|
40
|
-
const userEntitlementContext: UserEntitlementsContext = {
|
|
41
|
-
features: {
|
|
42
|
-
'test-feature': {
|
|
43
|
-
expireTime: new Date().getTime() + 3600,
|
|
44
|
-
linkedPermissions: [],
|
|
45
|
-
featureFlag: mockFeatureFlag,
|
|
46
|
-
},
|
|
47
|
-
},
|
|
48
|
-
permissions: {},
|
|
49
|
-
};
|
|
50
|
-
const result = IsEntitledEvaluators.evaluateIsEntitledToFeature('test-feature', userEntitlementContext, {});
|
|
51
|
-
|
|
52
|
-
expect(result).toEqual(truthyEntitlementResult);
|
|
53
|
-
});
|
|
54
|
-
test('feature granted with expired expiration date', async () => {
|
|
55
|
-
const userEntitlementContext: UserEntitlementsContext = {
|
|
56
|
-
features: {
|
|
57
|
-
'test-feature': {
|
|
58
|
-
expireTime: new Date().getTime() - 3600,
|
|
59
|
-
linkedPermissions: [],
|
|
60
|
-
featureFlag: mockFeatureFlag,
|
|
61
|
-
},
|
|
62
|
-
},
|
|
63
|
-
permissions: {},
|
|
64
|
-
};
|
|
65
|
-
const result = IsEntitledEvaluators.evaluateIsEntitledToFeature('test-feature', userEntitlementContext, {});
|
|
66
|
-
|
|
67
|
-
expect(result).toEqual(truthyEntitlementResult);
|
|
68
|
-
});
|
|
69
|
-
test('feature granted with no expiration date', async () => {
|
|
70
|
-
const userEntitlementContext: UserEntitlementsContext = {
|
|
71
|
-
features: {
|
|
72
|
-
'test-feature': {
|
|
73
|
-
expireTime: NO_EXPIRATION_TIME,
|
|
74
|
-
linkedPermissions: [],
|
|
75
|
-
featureFlag: mockFeatureFlag,
|
|
76
|
-
},
|
|
77
|
-
},
|
|
78
|
-
permissions: {},
|
|
79
|
-
};
|
|
80
|
-
const result = IsEntitledEvaluators.evaluateIsEntitledToFeature('test-feature', userEntitlementContext, {});
|
|
81
|
-
|
|
82
|
-
expect(result).toEqual(truthyEntitlementResult);
|
|
83
|
-
});
|
|
84
|
-
test('feature has not been granted', async () => {
|
|
85
|
-
const userEntitlementContext: UserEntitlementsContext = {
|
|
86
|
-
features: {
|
|
87
|
-
'test-feature': {
|
|
88
|
-
expireTime: null,
|
|
89
|
-
linkedPermissions: [],
|
|
90
|
-
featureFlag: mockFeatureFlag,
|
|
91
|
-
},
|
|
92
|
-
},
|
|
93
|
-
permissions: {},
|
|
94
|
-
};
|
|
95
|
-
const result = IsEntitledEvaluators.evaluateIsEntitledToFeature('test-feature', userEntitlementContext, {});
|
|
96
|
-
|
|
97
|
-
expect(result).toEqual(truthyEntitlementResult);
|
|
98
|
-
});
|
|
99
|
-
});
|
|
100
|
-
describe('feature-flag evaluated falsy', () => {
|
|
101
|
-
beforeAll(async () => {
|
|
102
|
-
jest.spyOn(FeatureFlagEvalutor, 'evaluateFeatureFlag').mockReturnValue({ treatment: TreatmentEnum.False });
|
|
103
|
-
});
|
|
104
|
-
test('feature granted with no expiration date', async () => {
|
|
105
|
-
const userEntitlementContext: UserEntitlementsContext = {
|
|
106
|
-
features: {
|
|
107
|
-
'test-feature': {
|
|
108
|
-
expireTime: NO_EXPIRATION_TIME,
|
|
109
|
-
linkedPermissions: [],
|
|
110
|
-
featureFlag: mockFeatureFlag,
|
|
111
|
-
},
|
|
112
|
-
},
|
|
113
|
-
permissions: {},
|
|
114
|
-
};
|
|
115
|
-
const result = IsEntitledEvaluators.evaluateIsEntitledToFeature('test-feature', userEntitlementContext, {});
|
|
116
|
-
|
|
117
|
-
expect(result).toEqual(truthyEntitlementResult);
|
|
118
|
-
});
|
|
119
|
-
test('feature granted with valid expiration date', async () => {
|
|
120
|
-
const userEntitlementContext: UserEntitlementsContext = {
|
|
121
|
-
features: {
|
|
122
|
-
'test-feature': {
|
|
123
|
-
expireTime: Date.now() + 3600,
|
|
124
|
-
linkedPermissions: [],
|
|
125
|
-
featureFlag: mockFeatureFlag,
|
|
126
|
-
},
|
|
127
|
-
},
|
|
128
|
-
permissions: {},
|
|
129
|
-
};
|
|
130
|
-
const result = IsEntitledEvaluators.evaluateIsEntitledToFeature('test-feature', userEntitlementContext, {});
|
|
131
|
-
|
|
132
|
-
expect(result).toEqual(truthyEntitlementResult);
|
|
133
|
-
});
|
|
134
|
-
});
|
|
135
|
-
describe('no feature flag', () => {
|
|
136
|
-
test('feature granted with no expiration date', async () => {
|
|
137
|
-
const userEntitlementContext: UserEntitlementsContext = {
|
|
138
|
-
features: {
|
|
139
|
-
'test-feature': {
|
|
140
|
-
expireTime: NO_EXPIRATION_TIME,
|
|
141
|
-
linkedPermissions: [],
|
|
142
|
-
},
|
|
143
|
-
},
|
|
144
|
-
permissions: {},
|
|
145
|
-
};
|
|
146
|
-
const result = IsEntitledEvaluators.evaluateIsEntitledToFeature('test-feature', userEntitlementContext, {});
|
|
147
|
-
|
|
148
|
-
expect(result).toEqual(truthyEntitlementResult);
|
|
149
|
-
});
|
|
150
|
-
test('feature granted with valid expiration date', async () => {
|
|
151
|
-
const userEntitlementContext: UserEntitlementsContext = {
|
|
152
|
-
features: {
|
|
153
|
-
'test-feature': {
|
|
154
|
-
expireTime: Date.now() + 3600,
|
|
155
|
-
linkedPermissions: [],
|
|
156
|
-
},
|
|
157
|
-
},
|
|
158
|
-
permissions: {},
|
|
159
|
-
};
|
|
160
|
-
const result = IsEntitledEvaluators.evaluateIsEntitledToFeature('test-feature', userEntitlementContext, {});
|
|
161
|
-
|
|
162
|
-
expect(result).toEqual(truthyEntitlementResult);
|
|
163
|
-
});
|
|
164
|
-
});
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
describe('not entitled', () => {
|
|
168
|
-
describe('feature-flag evaluated falsy', () => {
|
|
169
|
-
beforeAll(async () => {
|
|
170
|
-
jest.spyOn(FeatureFlagEvalutor, 'evaluateFeatureFlag').mockReturnValue({ treatment: TreatmentEnum.False });
|
|
171
|
-
});
|
|
172
|
-
test('feature has not been granted', async () => {
|
|
173
|
-
const userEntitlementContext: UserEntitlementsContext = {
|
|
174
|
-
features: {
|
|
175
|
-
'test-feature': {
|
|
176
|
-
expireTime: null,
|
|
177
|
-
linkedPermissions: [],
|
|
178
|
-
featureFlag: mockFeatureFlag,
|
|
179
|
-
},
|
|
180
|
-
},
|
|
181
|
-
permissions: {},
|
|
182
|
-
};
|
|
183
|
-
const result = IsEntitledEvaluators.evaluateIsEntitledToFeature('test-feature', userEntitlementContext, {});
|
|
184
|
-
|
|
185
|
-
expect(result).toEqual(falsyEntitlementResultMissingFeature);
|
|
186
|
-
});
|
|
187
|
-
test('feature granted with expired expiration date', async () => {
|
|
188
|
-
const userEntitlementContext: UserEntitlementsContext = {
|
|
189
|
-
features: {
|
|
190
|
-
'test-feature': {
|
|
191
|
-
expireTime: Date.now() - 3600,
|
|
192
|
-
linkedPermissions: [],
|
|
193
|
-
featureFlag: mockFeatureFlag,
|
|
194
|
-
},
|
|
195
|
-
},
|
|
196
|
-
permissions: {},
|
|
197
|
-
};
|
|
198
|
-
const result = IsEntitledEvaluators.evaluateIsEntitledToFeature('test-feature', userEntitlementContext, {});
|
|
199
|
-
|
|
200
|
-
expect(result).toEqual(falsyEntitlementResultBundleExpired);
|
|
201
|
-
});
|
|
202
|
-
});
|
|
203
|
-
|
|
204
|
-
describe('no feature', () => {
|
|
205
|
-
test('feature does not exist', async () => {
|
|
206
|
-
const userEntitlementContext: UserEntitlementsContext = {
|
|
207
|
-
features: {},
|
|
208
|
-
permissions: {},
|
|
209
|
-
};
|
|
210
|
-
const result = IsEntitledEvaluators.evaluateIsEntitledToFeature('test-feature', userEntitlementContext, {});
|
|
211
|
-
|
|
212
|
-
expect(result).toEqual(falsyEntitlementResultMissingFeature);
|
|
213
|
-
});
|
|
214
|
-
});
|
|
215
|
-
});
|
|
216
|
-
});
|
|
217
|
-
|
|
218
|
-
describe('evaluateIsEntitledToPermission', () => {
|
|
219
|
-
describe('entitled', () => {
|
|
220
|
-
test('permission granted, no linked feature/s to it', async () => {
|
|
221
|
-
const userEntitlementContext: UserEntitlementsContext = {
|
|
222
|
-
features: {},
|
|
223
|
-
permissions: { 'test.permission': true },
|
|
224
|
-
};
|
|
225
|
-
const result = IsEntitledEvaluators.evaluateIsEntitledToPermissions(
|
|
226
|
-
'test.permission',
|
|
227
|
-
userEntitlementContext,
|
|
228
|
-
{},
|
|
229
|
-
);
|
|
230
|
-
|
|
231
|
-
expect(result).toEqual(truthyEntitlementResult);
|
|
232
|
-
});
|
|
233
|
-
test('permission granted with linked feature/s, feature is entitled', async () => {
|
|
234
|
-
jest.spyOn(IsEntitledEvaluators, 'evaluateIsEntitledToFeature').mockReturnValue({ isEntitled: true });
|
|
235
|
-
|
|
236
|
-
const userEntitlementContext: UserEntitlementsContext = {
|
|
237
|
-
features: { 'test-feature': { expireTime: NO_EXPIRATION_TIME, linkedPermissions: ['test.permission'] } },
|
|
238
|
-
permissions: { 'test.permission': true },
|
|
239
|
-
};
|
|
240
|
-
|
|
241
|
-
const result = IsEntitledEvaluators.evaluateIsEntitledToPermissions(
|
|
242
|
-
'test.permission',
|
|
243
|
-
userEntitlementContext,
|
|
244
|
-
{},
|
|
245
|
-
);
|
|
246
|
-
|
|
247
|
-
expect(result).toEqual(truthyEntitlementResult);
|
|
248
|
-
});
|
|
249
|
-
});
|
|
250
|
-
|
|
251
|
-
describe('not entitled', () => {
|
|
252
|
-
test('permission not granted', async () => {
|
|
253
|
-
const userEntitlementContext: UserEntitlementsContext = {
|
|
254
|
-
features: {},
|
|
255
|
-
permissions: {},
|
|
256
|
-
};
|
|
257
|
-
const result = IsEntitledEvaluators.evaluateIsEntitledToPermissions(
|
|
258
|
-
'test.permission',
|
|
259
|
-
userEntitlementContext,
|
|
260
|
-
{},
|
|
261
|
-
);
|
|
262
|
-
|
|
263
|
-
expect(result).toEqual(falsyEntitlementResultMissingPermission);
|
|
264
|
-
});
|
|
265
|
-
test('permission granted with linked feature/s, no feature is entiteld', async () => {
|
|
266
|
-
jest
|
|
267
|
-
.spyOn(IsEntitledEvaluators, 'evaluateIsEntitledToFeature')
|
|
268
|
-
.mockReturnValue({ isEntitled: false, justification: NotEntitledJustification.MISSING_FEATURE });
|
|
269
|
-
|
|
270
|
-
const userEntitlementContext: UserEntitlementsContext = {
|
|
271
|
-
features: { 'test-feature': { expireTime: null, linkedPermissions: ['test.permission'] } },
|
|
272
|
-
permissions: { 'test.permission': true },
|
|
273
|
-
};
|
|
274
|
-
|
|
275
|
-
const result = IsEntitledEvaluators.evaluateIsEntitledToPermissions(
|
|
276
|
-
'test.permission',
|
|
277
|
-
userEntitlementContext,
|
|
278
|
-
{},
|
|
279
|
-
);
|
|
280
|
-
|
|
281
|
-
expect(result).toEqual(falsyEntitlementResultMissingFeature);
|
|
282
|
-
});
|
|
283
|
-
test('permission granted with linked feature/s, no feature is entiteld with expired bundle', async () => {
|
|
284
|
-
jest
|
|
285
|
-
.spyOn(IsEntitledEvaluators, 'evaluateIsEntitledToFeature')
|
|
286
|
-
.mockReturnValue({ isEntitled: false, justification: NotEntitledJustification.BUNDLE_EXPIRED });
|
|
287
|
-
});
|
|
288
|
-
|
|
289
|
-
const userEntitlementContext: UserEntitlementsContext = {
|
|
290
|
-
features: { 'test-feature': { expireTime: Date.now() - 3600, linkedPermissions: ['test.permission'] } },
|
|
291
|
-
permissions: { 'test.permission': true },
|
|
292
|
-
};
|
|
293
|
-
|
|
294
|
-
const result = IsEntitledEvaluators.evaluateIsEntitledToPermissions('test.permission', userEntitlementContext, {});
|
|
295
|
-
|
|
296
|
-
expect(result).toEqual(falsyEntitlementResultBundleExpired);
|
|
297
|
-
});
|
|
298
|
-
});
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|