@frontegg/entitlements-javascript-commons 1.0.0-alpha.1 → 1.0.0-alpha.10
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/.github/workflows/publish.yaml +1 -1
- package/.releaserc.yaml +2 -2
- package/dist/conditions/condition.evaluator.d.ts +6 -0
- package/dist/conditions/condition.evaluator.js +27 -0
- package/dist/conditions/condition.evaluator.js.map +1 -0
- package/dist/conditions/index.d.ts +2 -0
- package/dist/conditions/index.js +19 -0
- package/dist/conditions/index.js.map +1 -0
- package/dist/conditions/types.d.ts +7 -0
- package/dist/conditions/types.js +3 -0
- package/dist/conditions/types.js.map +1 -0
- package/dist/feature-flags/feature-flag.evaluator.d.ts +2 -0
- package/dist/feature-flags/feature-flag.evaluator.js +24 -0
- package/dist/feature-flags/feature-flag.evaluator.js.map +1 -0
- package/dist/feature-flags/index.d.ts +2 -0
- package/dist/feature-flags/index.js +18 -0
- package/dist/feature-flags/index.js.map +1 -0
- package/dist/feature-flags/types.d.ts +10 -0
- package/dist/feature-flags/types.js +3 -0
- package/dist/feature-flags/types.js.map +1 -0
- package/dist/index.d.ts +5 -1
- package/dist/index.js +11 -5
- package/dist/index.js.map +1 -1
- package/dist/operations/boolean/index.d.ts +4 -0
- package/dist/operations/boolean/index.js +25 -0
- package/dist/operations/boolean/index.js.map +1 -0
- package/dist/operations/boolean/operations.d.ts +3 -0
- package/dist/operations/boolean/operations.js +8 -0
- package/dist/operations/boolean/operations.js.map +1 -0
- package/dist/operations/boolean/sanitizers.d.ts +4 -0
- package/dist/operations/boolean/sanitizers.js +17 -0
- package/dist/operations/boolean/sanitizers.js.map +1 -0
- package/dist/operations/boolean/types.d.ts +3 -0
- package/dist/operations/boolean/types.js +3 -0
- package/dist/operations/boolean/types.js.map +1 -0
- package/dist/operations/components/operation.resolver.d.ts +2 -0
- package/dist/operations/components/operation.resolver.js +19 -0
- package/dist/operations/components/operation.resolver.js.map +1 -0
- package/dist/operations/components/sanitizers.resolver.d.ts +2 -0
- package/dist/operations/components/sanitizers.resolver.js +18 -0
- package/dist/operations/components/sanitizers.resolver.js.map +1 -0
- package/dist/operations/date/index.d.ts +4 -0
- package/dist/operations/date/index.js +28 -0
- package/dist/operations/date/index.js.map +1 -0
- package/dist/operations/date/operations.d.ts +6 -0
- package/dist/operations/date/operations.js +22 -0
- package/dist/operations/date/operations.js.map +1 -0
- package/dist/operations/date/sanitizers.d.ts +5 -0
- package/dist/operations/date/sanitizers.js +27 -0
- package/dist/operations/date/sanitizers.js.map +1 -0
- package/dist/operations/date/types.d.ts +8 -0
- package/dist/operations/date/types.js +3 -0
- package/dist/operations/date/types.js.map +1 -0
- package/dist/operations/numeric/index.d.ts +5 -0
- package/dist/operations/numeric/index.js +31 -0
- package/dist/operations/numeric/index.js.map +1 -0
- package/dist/operations/numeric/operations.d.ts +8 -0
- package/dist/operations/numeric/operations.js +28 -0
- package/dist/operations/numeric/operations.js.map +1 -0
- package/dist/operations/numeric/sanitizers.d.ts +5 -0
- package/dist/operations/numeric/sanitizers.js +32 -0
- package/dist/operations/numeric/sanitizers.js.map +1 -0
- package/dist/operations/numeric/types.d.ts +8 -0
- package/dist/operations/numeric/types.js +3 -0
- package/dist/operations/numeric/types.js.map +1 -0
- package/dist/operations/string/index.d.ts +4 -0
- package/dist/operations/string/index.js +29 -0
- package/dist/operations/string/index.js.map +1 -0
- package/dist/operations/string/operations.d.ts +7 -0
- package/dist/operations/string/operations.js +33 -0
- package/dist/operations/string/operations.js.map +1 -0
- package/dist/operations/string/sanitizers.d.ts +5 -0
- package/dist/operations/string/sanitizers.js +31 -0
- package/dist/operations/string/sanitizers.js.map +1 -0
- package/dist/operations/string/types.d.ts +7 -0
- package/dist/operations/string/types.js +3 -0
- package/dist/operations/string/types.js.map +1 -0
- package/dist/operations/types/index.d.ts +24 -0
- package/dist/operations/types/index.js +18 -0
- package/dist/operations/types/index.js.map +1 -0
- package/dist/operations/types/operation.enum.d.ts +18 -0
- package/dist/operations/types/operation.enum.js +27 -0
- package/dist/operations/types/operation.enum.js.map +1 -0
- package/dist/rules/index.d.ts +2 -0
- package/dist/rules/index.js +19 -0
- package/dist/rules/index.js.map +1 -0
- package/dist/rules/rule.evaluator.d.ts +2 -0
- package/dist/rules/rule.evaluator.js +16 -0
- package/dist/rules/rule.evaluator.js.map +1 -0
- package/dist/rules/types.d.ts +21 -0
- package/dist/rules/types.js +18 -0
- package/dist/rules/types.js.map +1 -0
- package/dist/user-entitlements/index.d.ts +2 -0
- package/dist/user-entitlements/index.js +19 -0
- package/dist/user-entitlements/index.js.map +1 -0
- package/dist/user-entitlements/is-entitled.evaluator.d.ts +11 -0
- package/dist/user-entitlements/is-entitled.evaluator.js +75 -0
- package/dist/user-entitlements/is-entitled.evaluator.js.map +1 -0
- package/dist/user-entitlements/types.d.ts +31 -0
- package/dist/user-entitlements/types.js +11 -0
- package/dist/user-entitlements/types.js.map +1 -0
- package/docs/CHANGELOG.md +68 -0
- package/jest.config.js +26 -0
- package/package.json +2 -2
- package/src/conditions/condition.evaluator.ts +35 -0
- package/src/conditions/index.ts +2 -0
- package/src/conditions/tests/condition.evaluator.spec.ts +52 -0
- package/src/conditions/types.ts +8 -0
- package/src/feature-flags/feature-flag.evaluator.ts +27 -0
- package/src/feature-flags/index.ts +2 -0
- package/src/feature-flags/tests/feature-flag.evaluator.spec.ts +176 -0
- package/src/feature-flags/types.ts +12 -0
- package/src/index.ts +14 -3
- package/src/operations/boolean/index.ts +10 -0
- package/src/operations/boolean/operations.ts +6 -0
- package/src/operations/boolean/sanitizers.ts +18 -0
- package/src/operations/boolean/tests/operations.spec.ts +13 -0
- package/src/operations/boolean/tests/sanitizers.spec.ts +22 -0
- package/src/operations/boolean/types.ts +3 -0
- package/src/operations/components/operation.resolver.ts +18 -0
- package/src/operations/components/sanitizers.resolver.ts +16 -0
- package/src/operations/components/tests/operation.resolver.spec.ts +8 -0
- package/src/operations/components/tests/sanitizers.resolver.spec.ts +14 -0
- package/src/operations/date/index.ts +18 -0
- package/src/operations/date/operations.ts +20 -0
- package/src/operations/date/sanitizers.ts +27 -0
- package/src/operations/date/tests/operations.spec.ts +45 -0
- package/src/operations/date/tests/sanitizers.spec.ts +43 -0
- package/src/operations/date/types.ts +10 -0
- package/src/operations/numeric/index.ts +23 -0
- package/src/operations/numeric/operations.ts +26 -0
- package/src/operations/numeric/sanitizers.ts +34 -0
- package/src/operations/numeric/tests/operations.spec.ts +64 -0
- package/src/operations/numeric/tests/sanitizers.spec.ts +44 -0
- package/src/operations/numeric/types.ts +10 -0
- package/src/operations/string/index.ts +20 -0
- package/src/operations/string/operations.ts +32 -0
- package/src/operations/string/sanitizers.ts +33 -0
- package/src/operations/string/tests/operations.spec.ts +38 -0
- package/src/operations/string/tests/sanitizers.spec.ts +45 -0
- package/src/operations/string/types.ts +9 -0
- package/src/operations/types/index.ts +30 -0
- package/src/operations/types/operation.enum.ts +25 -0
- package/src/rules/index.ts +2 -0
- package/src/rules/rule.evaluator.ts +14 -0
- package/src/rules/tests/rule.evaluator.spec.ts +135 -0
- package/src/rules/types.ts +27 -0
- package/src/user-entitlements/index.ts +2 -0
- package/src/user-entitlements/is-entitled.evaluator.ts +99 -0
- package/src/user-entitlements/tests/is-entitled.evaluator.spec.ts +315 -0
- package/src/user-entitlements/types.ts +37 -0
- package/src/index.spec.ts +0 -5
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NumericSanitizersMapper = exports.sanitizeNumericRange = exports.sanitizeSingleNumber = void 0;
|
|
4
|
+
const types_1 = require("../types");
|
|
5
|
+
const isNumber = (value) => typeof value === 'number';
|
|
6
|
+
const sanitizeSingleNumber = (value) => {
|
|
7
|
+
const sanitizedValue = value.number !== undefined && isNumber(value.number) ? { number: value.number } : undefined;
|
|
8
|
+
return {
|
|
9
|
+
isSanitized: !!sanitizedValue,
|
|
10
|
+
sanitizedValue,
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
exports.sanitizeSingleNumber = sanitizeSingleNumber;
|
|
14
|
+
const sanitizeNumericRange = (value) => {
|
|
15
|
+
const sanitizedValue = value.start !== undefined && value.end !== undefined && isNumber(value.start) && isNumber(value.end)
|
|
16
|
+
? { start: value.start, end: value.end }
|
|
17
|
+
: undefined;
|
|
18
|
+
return {
|
|
19
|
+
isSanitized: !!sanitizedValue,
|
|
20
|
+
sanitizedValue,
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
exports.sanitizeNumericRange = sanitizeNumericRange;
|
|
24
|
+
exports.NumericSanitizersMapper = {
|
|
25
|
+
[types_1.OperationEnum.Equal]: exports.sanitizeSingleNumber,
|
|
26
|
+
[types_1.OperationEnum.GreaterThan]: exports.sanitizeNumericRange,
|
|
27
|
+
[types_1.OperationEnum.GreaterThanEqual]: exports.sanitizeSingleNumber,
|
|
28
|
+
[types_1.OperationEnum.LesserThan]: exports.sanitizeSingleNumber,
|
|
29
|
+
[types_1.OperationEnum.LesserThanEqual]: exports.sanitizeNumericRange,
|
|
30
|
+
[types_1.OperationEnum.BetweenNumeric]: exports.sanitizeNumericRange,
|
|
31
|
+
};
|
|
32
|
+
//# sourceMappingURL=sanitizers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sanitizers.js","sourceRoot":"","sources":["../../../src/operations/numeric/sanitizers.ts"],"names":[],"mappings":";;;AAAA,oCAAsE;AAGtE,MAAM,QAAQ,GAAG,CAAC,KAAc,EAAmB,EAAE,CAAC,OAAO,KAAK,KAAK,QAAQ,CAAC;AAEzE,MAAM,oBAAoB,GAA6C,CAAC,KAAK,EAAE,EAAE;IACtF,MAAM,cAAc,GAAG,KAAK,CAAC,MAAM,KAAK,SAAS,IAAI,QAAQ,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;IAEnH,OAAO;QACL,WAAW,EAAE,CAAC,CAAC,cAAc;QAC7B,cAAc;KACf,CAAC;AACJ,CAAC,CAAC;AAPW,QAAA,oBAAoB,wBAO/B;AAEK,MAAM,oBAAoB,GAA8C,CAAC,KAAK,EAAE,EAAE;IACvF,MAAM,cAAc,GAClB,KAAK,CAAC,KAAK,KAAK,SAAS,IAAI,KAAK,CAAC,GAAG,KAAK,SAAS,IAAI,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC;QAClG,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,GAAG,EAAE,KAAK,CAAC,GAAG,EAAE;QACxC,CAAC,CAAC,SAAS,CAAC;IAEhB,OAAO;QACL,WAAW,EAAE,CAAC,CAAC,cAAc;QAC7B,cAAc;KACf,CAAC;AACJ,CAAC,CAAC;AAVW,QAAA,oBAAoB,wBAU/B;AAEW,QAAA,uBAAuB,GAA8C;IAChF,CAAC,qBAAa,CAAC,KAAK,CAAC,EAAE,4BAAoB;IAC3C,CAAC,qBAAa,CAAC,WAAW,CAAC,EAAE,4BAAoB;IACjD,CAAC,qBAAa,CAAC,gBAAgB,CAAC,EAAE,4BAAoB;IACtD,CAAC,qBAAa,CAAC,UAAU,CAAC,EAAE,4BAAoB;IAChD,CAAC,qBAAa,CAAC,eAAe,CAAC,EAAE,4BAAoB;IACrD,CAAC,qBAAa,CAAC,cAAc,CAAC,EAAE,4BAAoB;CACrD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/operations/numeric/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.StringOperationsMapper = void 0;
|
|
18
|
+
const types_1 = require("../types");
|
|
19
|
+
const operations_1 = require("./operations");
|
|
20
|
+
__exportStar(require("./operations"), exports);
|
|
21
|
+
__exportStar(require("./types"), exports);
|
|
22
|
+
exports.StringOperationsMapper = {
|
|
23
|
+
[types_1.OperationEnum.StartsWith]: (value) => (0, operations_1.useStartsWithOperation)(value),
|
|
24
|
+
[types_1.OperationEnum.EndsWith]: (value) => (0, operations_1.useEndsWithOperation)(value),
|
|
25
|
+
[types_1.OperationEnum.Contains]: (value) => (0, operations_1.useContainsOperation)(value),
|
|
26
|
+
[types_1.OperationEnum.InList]: (value) => (0, operations_1.useInListOperation)(value),
|
|
27
|
+
[types_1.OperationEnum.Matches]: (value) => (0, operations_1.useMatchesOperation)(value),
|
|
28
|
+
};
|
|
29
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/operations/string/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,oCAA2D;AAC3D,6CAMsB;AAGtB,+CAA6B;AAC7B,0CAAwB;AAEX,QAAA,sBAAsB,GAAqB;IACtD,CAAC,qBAAa,CAAC,UAAU,CAAC,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,IAAA,mCAAsB,EAAC,KAAmC,CAAC;IAClG,CAAC,qBAAa,CAAC,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,IAAA,iCAAoB,EAAC,KAAmC,CAAC;IAC9F,CAAC,qBAAa,CAAC,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,IAAA,iCAAoB,EAAC,KAAmC,CAAC;IAC9F,CAAC,qBAAa,CAAC,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,IAAA,+BAAkB,EAAC,KAAmC,CAAC;IAC1F,CAAC,qBAAa,CAAC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,IAAA,gCAAmB,EAAC,KAAqC,CAAC;CAC/F,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { OperationHandler } from '../types';
|
|
2
|
+
import { ListStringOperationPayload, SingleStringOperationPayload } from './types';
|
|
3
|
+
export declare function useStartsWithOperation(payload: ListStringOperationPayload): OperationHandler;
|
|
4
|
+
export declare function useEndsWithOperation(payload: ListStringOperationPayload): OperationHandler;
|
|
5
|
+
export declare function useContainsOperation(payload: ListStringOperationPayload): OperationHandler;
|
|
6
|
+
export declare function useInListOperation(payload: ListStringOperationPayload): OperationHandler;
|
|
7
|
+
export declare function useMatchesOperation(payload: SingleStringOperationPayload): OperationHandler;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useMatchesOperation = exports.useInListOperation = exports.useContainsOperation = exports.useEndsWithOperation = exports.useStartsWithOperation = void 0;
|
|
4
|
+
function useStartsWithOperation(payload) {
|
|
5
|
+
return (attribute) => ({ isValid: payload.list.some((value) => attribute.startsWith(value)) });
|
|
6
|
+
}
|
|
7
|
+
exports.useStartsWithOperation = useStartsWithOperation;
|
|
8
|
+
function useEndsWithOperation(payload) {
|
|
9
|
+
return (attribute) => ({ isValid: payload.list.some((value) => attribute.endsWith(value)) });
|
|
10
|
+
}
|
|
11
|
+
exports.useEndsWithOperation = useEndsWithOperation;
|
|
12
|
+
function useContainsOperation(payload) {
|
|
13
|
+
return (attribute) => ({ isValid: payload.list.some((value) => attribute.includes(value)) });
|
|
14
|
+
}
|
|
15
|
+
exports.useContainsOperation = useContainsOperation;
|
|
16
|
+
function useInListOperation(payload) {
|
|
17
|
+
return (attribute) => ({ isValid: payload.list.includes(attribute) });
|
|
18
|
+
}
|
|
19
|
+
exports.useInListOperation = useInListOperation;
|
|
20
|
+
function useMatchesOperation(payload) {
|
|
21
|
+
return (attribute) => {
|
|
22
|
+
let expression;
|
|
23
|
+
try {
|
|
24
|
+
expression = new RegExp(payload.string);
|
|
25
|
+
}
|
|
26
|
+
catch (e) {
|
|
27
|
+
return { isValid: false };
|
|
28
|
+
}
|
|
29
|
+
return { isValid: expression.test(attribute) };
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
exports.useMatchesOperation = useMatchesOperation;
|
|
33
|
+
//# sourceMappingURL=operations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"operations.js","sourceRoot":"","sources":["../../../src/operations/string/operations.ts"],"names":[],"mappings":";;;AAGA,SAAgB,sBAAsB,CAAC,OAAmC;IACxE,OAAO,CAAC,SAAiB,EAAE,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,SAAS,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC;AACzG,CAAC;AAFD,wDAEC;AAED,SAAgB,oBAAoB,CAAC,OAAmC;IACtE,OAAO,CAAC,SAAiB,EAAE,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,SAAS,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC;AACvG,CAAC;AAFD,oDAEC;AAED,SAAgB,oBAAoB,CAAC,OAAmC;IACtE,OAAO,CAAC,SAAiB,EAAE,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,SAAS,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC;AACvG,CAAC;AAFD,oDAEC;AAED,SAAgB,kBAAkB,CAAC,OAAmC;IACpE,OAAO,CAAC,SAAiB,EAAE,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC;AAChF,CAAC;AAFD,gDAEC;AAED,SAAgB,mBAAmB,CAAC,OAAqC;IACvE,OAAO,CAAC,SAAiB,EAAE,EAAE;QAC3B,IAAI,UAAkB,CAAC;QAEvB,IAAI;YACF,UAAU,GAAG,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;SACzC;QAAC,OAAO,CAAC,EAAE;YACV,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;SAC3B;QAED,OAAO,EAAE,OAAO,EAAE,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC;IACjD,CAAC,CAAC;AACJ,CAAC;AAZD,kDAYC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Sanitizer, SanitizersMapper } from '../types';
|
|
2
|
+
import { ListStringOperationPayload, SingleStringOperationPayload, StringOperationPayload } from './types';
|
|
3
|
+
export declare const sanitizeSingleString: Sanitizer<SingleStringOperationPayload>;
|
|
4
|
+
export declare const sanitizeListString: Sanitizer<ListStringOperationPayload>;
|
|
5
|
+
export declare const StringSanitizersMapper: SanitizersMapper<StringOperationPayload>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StringSanitizersMapper = exports.sanitizeListString = exports.sanitizeSingleString = void 0;
|
|
4
|
+
const types_1 = require("../types");
|
|
5
|
+
const isString = (value) => typeof value === 'string';
|
|
6
|
+
const sanitizeSingleString = (value) => {
|
|
7
|
+
const sanitizedValue = value.string !== undefined && isString(value.string) ? { string: value.string } : undefined;
|
|
8
|
+
return {
|
|
9
|
+
isSanitized: !!sanitizedValue,
|
|
10
|
+
sanitizedValue,
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
exports.sanitizeSingleString = sanitizeSingleString;
|
|
14
|
+
const sanitizeListString = (value) => {
|
|
15
|
+
const sanitizedValue = value.list !== undefined && value.list.every((str) => isString(str))
|
|
16
|
+
? { list: value.list }
|
|
17
|
+
: undefined;
|
|
18
|
+
return {
|
|
19
|
+
isSanitized: !!sanitizedValue,
|
|
20
|
+
sanitizedValue,
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
exports.sanitizeListString = sanitizeListString;
|
|
24
|
+
exports.StringSanitizersMapper = {
|
|
25
|
+
[types_1.OperationEnum.Matches]: exports.sanitizeSingleString,
|
|
26
|
+
[types_1.OperationEnum.Contains]: exports.sanitizeListString,
|
|
27
|
+
[types_1.OperationEnum.StartsWith]: exports.sanitizeSingleString,
|
|
28
|
+
[types_1.OperationEnum.EndsWith]: exports.sanitizeSingleString,
|
|
29
|
+
[types_1.OperationEnum.InList]: exports.sanitizeListString,
|
|
30
|
+
};
|
|
31
|
+
//# sourceMappingURL=sanitizers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sanitizers.js","sourceRoot":"","sources":["../../../src/operations/string/sanitizers.ts"],"names":[],"mappings":";;;AAAA,oCAAsE;AAGtE,MAAM,QAAQ,GAAG,CAAC,KAAc,EAAmB,EAAE,CAAC,OAAO,KAAK,KAAK,QAAQ,CAAC;AAEzE,MAAM,oBAAoB,GAA4C,CAAC,KAAK,EAAE,EAAE;IACrF,MAAM,cAAc,GAAG,KAAK,CAAC,MAAM,KAAK,SAAS,IAAI,QAAQ,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;IAEnH,OAAO;QACL,WAAW,EAAE,CAAC,CAAC,cAAc;QAC7B,cAAc;KACf,CAAC;AACJ,CAAC,CAAC;AAPW,QAAA,oBAAoB,wBAO/B;AAEK,MAAM,kBAAkB,GAA0C,CAAC,KAAK,EAAE,EAAE;IACjF,MAAM,cAAc,GAClB,KAAK,CAAC,IAAI,KAAK,SAAS,IAAgB,KAAK,CAAC,IAAK,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;QAC/E,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,CAAC,IAAgB,EAAE;QAClC,CAAC,CAAC,SAAS,CAAC;IAEhB,OAAO;QACL,WAAW,EAAE,CAAC,CAAC,cAAc;QAC7B,cAAc;KACf,CAAC;AACJ,CAAC,CAAC;AAVW,QAAA,kBAAkB,sBAU7B;AAEW,QAAA,sBAAsB,GAA6C;IAC9E,CAAC,qBAAa,CAAC,OAAO,CAAC,EAAE,4BAAoB;IAC7C,CAAC,qBAAa,CAAC,QAAQ,CAAC,EAAE,0BAAkB;IAC5C,CAAC,qBAAa,CAAC,UAAU,CAAC,EAAE,4BAAoB;IAChD,CAAC,qBAAa,CAAC,QAAQ,CAAC,EAAE,4BAAoB;IAC9C,CAAC,qBAAa,CAAC,MAAM,CAAC,EAAE,0BAAkB;CAC3C,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/operations/string/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { OperationEnum } from './operation.enum';
|
|
2
|
+
import { StringOperationPayload } from '../string';
|
|
3
|
+
import { NumericOperationPayload } from '../numeric';
|
|
4
|
+
import { DateOperationPayload } from '../date';
|
|
5
|
+
import { BooleanOperationPayload } from '../boolean/types';
|
|
6
|
+
export interface OperationResult {
|
|
7
|
+
isValid: boolean;
|
|
8
|
+
}
|
|
9
|
+
export type RawConditionValue = Record<string, unknown>;
|
|
10
|
+
export type ConditionValue = StringOperationPayload | NumericOperationPayload | DateOperationPayload | BooleanOperationPayload;
|
|
11
|
+
export type OperationHandler = (attribute: any) => OperationResult;
|
|
12
|
+
export type OperationContextEnricher = (value: ConditionValue) => OperationHandler;
|
|
13
|
+
export type OperationsMapper = {
|
|
14
|
+
[key in OperationEnum]?: OperationContextEnricher;
|
|
15
|
+
};
|
|
16
|
+
export interface SanitizationResult<T extends ConditionValue> {
|
|
17
|
+
isSanitized: boolean;
|
|
18
|
+
sanitizedValue: T | undefined;
|
|
19
|
+
}
|
|
20
|
+
export type Sanitizer<T extends ConditionValue> = (value: RawConditionValue) => SanitizationResult<T>;
|
|
21
|
+
export type SanitizersMapper<T extends ConditionValue> = {
|
|
22
|
+
[key in OperationEnum]?: Sanitizer<T>;
|
|
23
|
+
};
|
|
24
|
+
export * from './operation.enum';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./operation.enum"), exports);
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/operations/types/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AA6BA,mDAAiC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export declare enum OperationEnum {
|
|
2
|
+
InList = "in_list",
|
|
3
|
+
StartsWith = "starts_with",
|
|
4
|
+
EndsWith = "ends_with",
|
|
5
|
+
Contains = "contains",
|
|
6
|
+
Matches = "matches",
|
|
7
|
+
Equal = "equal",
|
|
8
|
+
GreaterThan = "greater_than",
|
|
9
|
+
GreaterThanEqual = "greater_than_equal",
|
|
10
|
+
LesserThan = "lower_than",
|
|
11
|
+
LesserThanEqual = "lower_than_equal",
|
|
12
|
+
BetweenNumeric = "between_numeric",
|
|
13
|
+
Is = "is",
|
|
14
|
+
On = "on",
|
|
15
|
+
BetweenDate = "between_date",
|
|
16
|
+
OnOrAfter = "on_or_after",
|
|
17
|
+
OnOrBefore = "on_or_before"
|
|
18
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OperationEnum = void 0;
|
|
4
|
+
var OperationEnum;
|
|
5
|
+
(function (OperationEnum) {
|
|
6
|
+
// String Operations
|
|
7
|
+
OperationEnum["InList"] = "in_list";
|
|
8
|
+
OperationEnum["StartsWith"] = "starts_with";
|
|
9
|
+
OperationEnum["EndsWith"] = "ends_with";
|
|
10
|
+
OperationEnum["Contains"] = "contains";
|
|
11
|
+
OperationEnum["Matches"] = "matches";
|
|
12
|
+
// Numeric Operations
|
|
13
|
+
OperationEnum["Equal"] = "equal";
|
|
14
|
+
OperationEnum["GreaterThan"] = "greater_than";
|
|
15
|
+
OperationEnum["GreaterThanEqual"] = "greater_than_equal";
|
|
16
|
+
OperationEnum["LesserThan"] = "lower_than";
|
|
17
|
+
OperationEnum["LesserThanEqual"] = "lower_than_equal";
|
|
18
|
+
OperationEnum["BetweenNumeric"] = "between_numeric";
|
|
19
|
+
// Boolean Operations
|
|
20
|
+
OperationEnum["Is"] = "is";
|
|
21
|
+
// Date Operations
|
|
22
|
+
OperationEnum["On"] = "on";
|
|
23
|
+
OperationEnum["BetweenDate"] = "between_date";
|
|
24
|
+
OperationEnum["OnOrAfter"] = "on_or_after";
|
|
25
|
+
OperationEnum["OnOrBefore"] = "on_or_before";
|
|
26
|
+
})(OperationEnum = exports.OperationEnum || (exports.OperationEnum = {}));
|
|
27
|
+
//# sourceMappingURL=operation.enum.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"operation.enum.js","sourceRoot":"","sources":["../../../src/operations/types/operation.enum.ts"],"names":[],"mappings":";;;AAAA,IAAY,aAwBX;AAxBD,WAAY,aAAa;IACvB,oBAAoB;IACpB,mCAAkB,CAAA;IAClB,2CAA0B,CAAA;IAC1B,uCAAsB,CAAA;IACtB,sCAAqB,CAAA;IACrB,oCAAmB,CAAA;IAEnB,qBAAqB;IACrB,gCAAe,CAAA;IACf,6CAA4B,CAAA;IAC5B,wDAAuC,CAAA;IACvC,0CAAyB,CAAA;IACzB,qDAAoC,CAAA;IACpC,mDAAkC,CAAA;IAElC,qBAAqB;IACrB,0BAAS,CAAA;IAET,kBAAkB;IAClB,0BAAS,CAAA;IACT,6CAA4B,CAAA;IAC5B,0CAAyB,CAAA;IACzB,4CAA2B,CAAA;AAC7B,CAAC,EAxBW,aAAa,GAAb,qBAAa,KAAb,qBAAa,QAwBxB"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./types"), exports);
|
|
18
|
+
__exportStar(require("./rule.evaluator"), exports);
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/rules/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAwB;AACxB,mDAAiC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createRuleEvaluator = void 0;
|
|
4
|
+
const types_1 = require("./types");
|
|
5
|
+
const conditions_1 = require("../conditions");
|
|
6
|
+
function createRuleEvaluator(payload) {
|
|
7
|
+
return (attributes) => {
|
|
8
|
+
const isRuleTreatable = payload.rule.conditions.every((condition) => {
|
|
9
|
+
const evaluator = (0, conditions_1.createConditionEvaluator)({ condition });
|
|
10
|
+
return evaluator(attributes);
|
|
11
|
+
});
|
|
12
|
+
return isRuleTreatable ? types_1.RuleEvaluationResultEnum.Treatable : types_1.RuleEvaluationResultEnum.Insufficient;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
exports.createRuleEvaluator = createRuleEvaluator;
|
|
16
|
+
//# sourceMappingURL=rule.evaluator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rule.evaluator.js","sourceRoot":"","sources":["../../src/rules/rule.evaluator.ts"],"names":[],"mappings":";;;AAAA,mCAA8F;AAC9F,8CAAyD;AAEzD,SAAgB,mBAAmB,CAAC,OAAmC;IACrE,OAAO,CAAC,UAAmC,EAA4B,EAAE;QACvE,MAAM,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,SAAS,EAAE,EAAE;YAClE,MAAM,SAAS,GAAG,IAAA,qCAAwB,EAAC,EAAE,SAAS,EAAE,CAAC,CAAC;YAE1D,OAAO,SAAS,CAAC,UAAU,CAAC,CAAC;QAC/B,CAAC,CAAC,CAAC;QAEH,OAAO,eAAe,CAAC,CAAC,CAAC,gCAAwB,CAAC,SAAS,CAAC,CAAC,CAAC,gCAAwB,CAAC,YAAY,CAAC;IACtG,CAAC,CAAC;AACJ,CAAC;AAVD,kDAUC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Condition } from '../conditions';
|
|
2
|
+
export interface Rule {
|
|
3
|
+
conditionLogic: ConditionLogicEnum.And;
|
|
4
|
+
conditions: Condition[];
|
|
5
|
+
treatment: TreatmentEnum;
|
|
6
|
+
}
|
|
7
|
+
export declare enum ConditionLogicEnum {
|
|
8
|
+
And = "and"
|
|
9
|
+
}
|
|
10
|
+
export declare enum TreatmentEnum {
|
|
11
|
+
True = "true",
|
|
12
|
+
False = "false"
|
|
13
|
+
}
|
|
14
|
+
export declare enum RuleEvaluationResultEnum {
|
|
15
|
+
Treatable = "treatable",
|
|
16
|
+
Insufficient = "insufficient"
|
|
17
|
+
}
|
|
18
|
+
export interface CreateRuleEvaluatorPayload {
|
|
19
|
+
rule: Rule;
|
|
20
|
+
}
|
|
21
|
+
export type RuleEvaluator = (attributes: Record<string, unknown>) => RuleEvaluationResultEnum;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RuleEvaluationResultEnum = exports.TreatmentEnum = exports.ConditionLogicEnum = void 0;
|
|
4
|
+
var ConditionLogicEnum;
|
|
5
|
+
(function (ConditionLogicEnum) {
|
|
6
|
+
ConditionLogicEnum["And"] = "and";
|
|
7
|
+
})(ConditionLogicEnum = exports.ConditionLogicEnum || (exports.ConditionLogicEnum = {}));
|
|
8
|
+
var TreatmentEnum;
|
|
9
|
+
(function (TreatmentEnum) {
|
|
10
|
+
TreatmentEnum["True"] = "true";
|
|
11
|
+
TreatmentEnum["False"] = "false";
|
|
12
|
+
})(TreatmentEnum = exports.TreatmentEnum || (exports.TreatmentEnum = {}));
|
|
13
|
+
var RuleEvaluationResultEnum;
|
|
14
|
+
(function (RuleEvaluationResultEnum) {
|
|
15
|
+
RuleEvaluationResultEnum["Treatable"] = "treatable";
|
|
16
|
+
RuleEvaluationResultEnum["Insufficient"] = "insufficient";
|
|
17
|
+
})(RuleEvaluationResultEnum = exports.RuleEvaluationResultEnum || (exports.RuleEvaluationResultEnum = {}));
|
|
18
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/rules/types.ts"],"names":[],"mappings":";;;AAQA,IAAY,kBAEX;AAFD,WAAY,kBAAkB;IAC5B,iCAAW,CAAA;AACb,CAAC,EAFW,kBAAkB,GAAlB,0BAAkB,KAAlB,0BAAkB,QAE7B;AAED,IAAY,aAGX;AAHD,WAAY,aAAa;IACvB,8BAAa,CAAA;IACb,gCAAe,CAAA;AACjB,CAAC,EAHW,aAAa,GAAb,qBAAa,KAAb,qBAAa,QAGxB;AAED,IAAY,wBAGX;AAHD,WAAY,wBAAwB;IAClC,mDAAuB,CAAA;IACvB,yDAA6B,CAAA;AAC/B,CAAC,EAHW,wBAAwB,GAAxB,gCAAwB,KAAxB,gCAAwB,QAGnC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./is-entitled.evaluator"), exports);
|
|
18
|
+
__exportStar(require("./types"), exports);
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/user-entitlements/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0DAAwC;AACxC,0CAAwB"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { EntitlementResult, UserEntitlementsContext, Attributes } from './types';
|
|
2
|
+
export declare function evaluateIsEntitledToFeature(featureKey: string, userEntitlementsContext: UserEntitlementsContext, attributes?: Attributes): EntitlementResult;
|
|
3
|
+
export declare function evaluateIsEntitledToPermissions(permissionKey: string, userEntitlementsContext: UserEntitlementsContext, attributes?: Attributes): EntitlementResult;
|
|
4
|
+
/**
|
|
5
|
+
* Merges the `custom` and `frontegg` Records into a single Record,
|
|
6
|
+
* Alters the `frontegg` Record keys with a prefix
|
|
7
|
+
* Example:
|
|
8
|
+
* Input: { 'custom': { 'customAttribute': 'someValue' }, 'frontegg': { 'email': 'user@email.com' } }
|
|
9
|
+
* Output: { 'customAttribute': 'someValue', 'imported.email': 'user@email.com' }
|
|
10
|
+
*/
|
|
11
|
+
export declare function prepareAttributes(attributes?: Attributes): Record<string, unknown>;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.prepareAttributes = exports.evaluateIsEntitledToPermissions = exports.evaluateIsEntitledToFeature = void 0;
|
|
4
|
+
const types_1 = require("./types");
|
|
5
|
+
const feature_flags_1 = require("../feature-flags");
|
|
6
|
+
const rules_1 = require("../rules");
|
|
7
|
+
function evaluateIsEntitledToFeature(featureKey, userEntitlementsContext, attributes) {
|
|
8
|
+
const feature = userEntitlementsContext.features[featureKey];
|
|
9
|
+
let hasExpired = false;
|
|
10
|
+
if (feature && feature.expireTime !== null) {
|
|
11
|
+
hasExpired = feature.expireTime !== types_1.NO_EXPIRATION_TIME && feature.expireTime < Date.now();
|
|
12
|
+
if (!hasExpired) {
|
|
13
|
+
return { isEntitled: true };
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
if (feature && feature.featureFlag) {
|
|
17
|
+
const { treatment } = (0, feature_flags_1.evaluateFeatureFlag)(feature.featureFlag, prepareAttributes(attributes));
|
|
18
|
+
if (treatment === rules_1.TreatmentEnum.True) {
|
|
19
|
+
return { isEntitled: true };
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return {
|
|
23
|
+
isEntitled: false,
|
|
24
|
+
justification: hasExpired ? types_1.NotEntitledJustification.BUNDLE_EXPIRED : types_1.NotEntitledJustification.MISSING_FEATURE,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
exports.evaluateIsEntitledToFeature = evaluateIsEntitledToFeature;
|
|
28
|
+
function evaluateIsEntitledToPermissions(permissionKey, userEntitlementsContext, attributes) {
|
|
29
|
+
const permission = userEntitlementsContext.permissions[permissionKey];
|
|
30
|
+
if (!permission) {
|
|
31
|
+
return { isEntitled: false, justification: types_1.NotEntitledJustification.MISSING_PERMISSION };
|
|
32
|
+
}
|
|
33
|
+
const linkedFeatures = getLinkedFeatures(permissionKey, userEntitlementsContext);
|
|
34
|
+
if (!linkedFeatures.length) {
|
|
35
|
+
return { isEntitled: true };
|
|
36
|
+
}
|
|
37
|
+
let hasExpired = false;
|
|
38
|
+
for (const featureKey of linkedFeatures) {
|
|
39
|
+
const { isEntitled, justification } = evaluateIsEntitledToFeature(featureKey, userEntitlementsContext, attributes);
|
|
40
|
+
if (isEntitled) {
|
|
41
|
+
return { isEntitled: true };
|
|
42
|
+
}
|
|
43
|
+
if (justification === types_1.NotEntitledJustification.BUNDLE_EXPIRED) {
|
|
44
|
+
hasExpired = true;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return {
|
|
48
|
+
isEntitled: false,
|
|
49
|
+
justification: hasExpired ? types_1.NotEntitledJustification.BUNDLE_EXPIRED : types_1.NotEntitledJustification.MISSING_FEATURE,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
exports.evaluateIsEntitledToPermissions = evaluateIsEntitledToPermissions;
|
|
53
|
+
function getLinkedFeatures(permissionKey, userEntitlementsContext) {
|
|
54
|
+
return Object.keys(userEntitlementsContext.features).filter((featureKey) => userEntitlementsContext.features[featureKey].linkedPermissions.includes(permissionKey));
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Merges the `custom` and `frontegg` Records into a single Record,
|
|
58
|
+
* Alters the `frontegg` Record keys with a prefix
|
|
59
|
+
* Example:
|
|
60
|
+
* Input: { 'custom': { 'customAttribute': 'someValue' }, 'frontegg': { 'email': 'user@email.com' } }
|
|
61
|
+
* Output: { 'customAttribute': 'someValue', 'imported.email': 'user@email.com' }
|
|
62
|
+
*/
|
|
63
|
+
function prepareAttributes(attributes = {}) {
|
|
64
|
+
const { custom = {}, frontegg = {} } = attributes;
|
|
65
|
+
const importedAttributesPrefix = 'imported.'; // Not Final
|
|
66
|
+
return {
|
|
67
|
+
...custom,
|
|
68
|
+
...Object.keys(frontegg).reduce((modifiedImportedAttributes, key) => {
|
|
69
|
+
modifiedImportedAttributes[`${importedAttributesPrefix}${key}`] = frontegg[key];
|
|
70
|
+
return modifiedImportedAttributes;
|
|
71
|
+
}, {}),
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
exports.prepareAttributes = prepareAttributes;
|
|
75
|
+
//# sourceMappingURL=is-entitled.evaluator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-entitled.evaluator.js","sourceRoot":"","sources":["../../src/user-entitlements/is-entitled.evaluator.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { FeatureFlag } from '../feature-flags/types';
|
|
2
|
+
export type UserEntitlementsContext = {
|
|
3
|
+
features: Record<string, {
|
|
4
|
+
expireTime: number | null;
|
|
5
|
+
linkedPermissions: string[];
|
|
6
|
+
featureFlag?: FeatureFlag;
|
|
7
|
+
}>;
|
|
8
|
+
permissions: Record<string, true>;
|
|
9
|
+
};
|
|
10
|
+
export type EntitlementResult = {
|
|
11
|
+
isEntitled: boolean;
|
|
12
|
+
justification?: NotEntitledJustification;
|
|
13
|
+
};
|
|
14
|
+
export declare enum NotEntitledJustification {
|
|
15
|
+
MISSING_FEATURE = "MISSING_FEATURE",
|
|
16
|
+
MISSING_PERMISSION = "MISSING_PERMISSION",
|
|
17
|
+
BUNDLE_EXPIRED = "BUNDLE_EXPIRED"
|
|
18
|
+
}
|
|
19
|
+
export type CustomAttributes = Record<string, string | number | boolean | Date>;
|
|
20
|
+
export type FronteggAttributes = {
|
|
21
|
+
tenantId?: string;
|
|
22
|
+
userId?: string;
|
|
23
|
+
email?: string;
|
|
24
|
+
email_verified?: boolean;
|
|
25
|
+
[unmappedAttribute: string]: unknown;
|
|
26
|
+
};
|
|
27
|
+
export type Attributes = {
|
|
28
|
+
custom?: CustomAttributes;
|
|
29
|
+
frontegg?: FronteggAttributes;
|
|
30
|
+
};
|
|
31
|
+
export declare const NO_EXPIRATION_TIME = -1;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NO_EXPIRATION_TIME = exports.NotEntitledJustification = void 0;
|
|
4
|
+
var NotEntitledJustification;
|
|
5
|
+
(function (NotEntitledJustification) {
|
|
6
|
+
NotEntitledJustification["MISSING_FEATURE"] = "MISSING_FEATURE";
|
|
7
|
+
NotEntitledJustification["MISSING_PERMISSION"] = "MISSING_PERMISSION";
|
|
8
|
+
NotEntitledJustification["BUNDLE_EXPIRED"] = "BUNDLE_EXPIRED";
|
|
9
|
+
})(NotEntitledJustification = exports.NotEntitledJustification || (exports.NotEntitledJustification = {}));
|
|
10
|
+
exports.NO_EXPIRATION_TIME = -1;
|
|
11
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/user-entitlements/types.ts"],"names":[],"mappings":";;;AAkBA,IAAY,wBAIX;AAJD,WAAY,wBAAwB;IAClC,+DAAmC,CAAA;IACnC,qEAAyC,CAAA;IACzC,6DAAiC,CAAA;AACnC,CAAC,EAJW,wBAAwB,GAAxB,gCAAwB,KAAxB,gCAAwB,QAInC;AAcY,QAAA,kBAAkB,GAAG,CAAC,CAAC,CAAC"}
|