@frontegg/entitlements-javascript-commons 1.0.0-alpha.4 → 1.0.0-alpha.6
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/conditions/condition.evaluator.js +13 -1
- package/dist/conditions/condition.evaluator.js.map +1 -1
- package/dist/conditions/types.d.ts +2 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/dist/operations/boolean/index.d.ts +1 -0
- package/dist/operations/boolean/index.js +1 -0
- package/dist/operations/boolean/index.js.map +1 -1
- 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/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/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/numeric/index.d.ts +1 -0
- package/dist/operations/numeric/index.js +1 -0
- package/dist/operations/numeric/index.js.map +1 -1
- 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/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/types/index.d.ts +9 -0
- package/dist/operations/types/index.js.map +1 -1
- package/dist/user-entitlements/index.d.ts +1 -0
- package/dist/user-entitlements/index.js +18 -0
- package/dist/user-entitlements/index.js.map +1 -0
- package/dist/user-entitlements/is-entitled.evaluator.d.ts +3 -0
- package/dist/user-entitlements/is-entitled.evaluator.js +53 -0
- package/dist/user-entitlements/is-entitled.evaluator.js.map +1 -0
- package/dist/user-entitlements/types.d.ts +20 -0
- package/dist/user-entitlements/types.js +11 -0
- package/dist/user-entitlements/types.js.map +1 -0
- package/docs/CHANGELOG.md +14 -0
- package/package.json +1 -1
- package/src/conditions/condition.evaluator.ts +16 -1
- package/src/conditions/types.ts +2 -2
- package/src/index.ts +1 -0
- package/src/operations/boolean/index.ts +1 -0
- package/src/operations/boolean/sanitizers.ts +18 -0
- package/src/operations/boolean/{operations.spec.ts → tests/operations.spec.ts} +1 -1
- package/src/operations/boolean/tests/sanitizers.spec.ts +22 -0
- package/src/operations/components/sanitizers.resolver.ts +16 -0
- package/src/operations/components/tests/sanitizers.resolver.spec.ts +14 -0
- package/src/operations/date/sanitizers.ts +27 -0
- package/src/operations/date/{operations.spec.ts → tests/operations.spec.ts} +1 -1
- package/src/operations/date/tests/sanitizers.spec.ts +43 -0
- package/src/operations/numeric/index.ts +1 -0
- package/src/operations/numeric/sanitizers.ts +34 -0
- package/src/operations/numeric/tests/sanitizers.spec.ts +44 -0
- package/src/operations/string/sanitizers.ts +33 -0
- package/src/operations/string/tests/sanitizers.spec.ts +45 -0
- package/src/operations/types/index.ts +8 -0
- package/src/user-entitlements/index.ts +1 -0
- package/src/user-entitlements/is-entitled.evaluator.ts +71 -0
- package/src/user-entitlements/tests/is-entitled.evaluator.spec.ts +291 -0
- package/src/user-entitlements/types.ts +27 -0
- package/src/operations/numeric/operations.spec.ts +0 -63
- package/src/operations/string/operations.spec.ts +0 -38
|
@@ -2,8 +2,20 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createConditionEvaluator = void 0;
|
|
4
4
|
const operation_resolver_1 = require("../operations/components/operation.resolver");
|
|
5
|
+
const sanitizers_resolver_1 = require("../operations/components/sanitizers.resolver");
|
|
6
|
+
function failingConditionEvaluator() {
|
|
7
|
+
return () => false;
|
|
8
|
+
}
|
|
5
9
|
function createConditionEvaluator(payload) {
|
|
6
|
-
const
|
|
10
|
+
const sanitizer = (0, sanitizers_resolver_1.useSanitizer)(payload.condition.op);
|
|
11
|
+
if (!sanitizer) {
|
|
12
|
+
return failingConditionEvaluator();
|
|
13
|
+
}
|
|
14
|
+
const { isSanitized, sanitizedValue } = sanitizer(payload.condition.value);
|
|
15
|
+
if (!isSanitized || sanitizedValue === undefined) {
|
|
16
|
+
return failingConditionEvaluator();
|
|
17
|
+
}
|
|
18
|
+
const operation = (0, operation_resolver_1.useOperation)(payload.condition.op, sanitizedValue);
|
|
7
19
|
return (attributes) => {
|
|
8
20
|
const attributeKey = payload.condition.attribute;
|
|
9
21
|
const value = attributes[attributeKey];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"condition.evaluator.js","sourceRoot":"","sources":["../../src/conditions/condition.evaluator.ts"],"names":[],"mappings":";;;AACA,oFAA2E;
|
|
1
|
+
{"version":3,"file":"condition.evaluator.js","sourceRoot":"","sources":["../../src/conditions/condition.evaluator.ts"],"names":[],"mappings":";;;AACA,oFAA2E;AAC3E,sFAA4E;AAQ5E,SAAS,yBAAyB;IAChC,OAAO,GAAG,EAAE,CAAC,KAAK,CAAC;AACrB,CAAC;AAED,SAAgB,wBAAwB,CAAC,OAAwC;IAC/E,MAAM,SAAS,GAAG,IAAA,kCAAY,EAAC,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC;IACrD,IAAI,CAAC,SAAS,EAAE;QACd,OAAO,yBAAyB,EAAE,CAAC;KACpC;IAED,MAAM,EAAE,WAAW,EAAE,cAAc,EAAE,GAAG,SAAS,CAAC,OAAO,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IAC3E,IAAI,CAAC,WAAW,IAAI,cAAc,KAAK,SAAS,EAAE;QAChD,OAAO,yBAAyB,EAAE,CAAC;KACpC;IAED,MAAM,SAAS,GAAG,IAAA,iCAAY,EAAC,OAAO,CAAC,SAAS,CAAC,EAAE,EAAE,cAAc,CAAC,CAAC;IAErE,OAAO,CAAC,UAAmC,EAAE,EAAE;QAC7C,MAAM,YAAY,GAAG,OAAO,CAAC,SAAS,CAAC,SAAS,CAAC;QACjD,MAAM,KAAK,GAAG,UAAU,CAAC,YAAY,CAAC,CAAC;QACvC,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,KAAK,KAAK,SAAS,IAAI,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;QAErG,OAAO,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC;IACrD,CAAC,CAAC;AACJ,CAAC;AApBD,4DAoBC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { OperationEnum, RawConditionValue } from '../operations/types';
|
|
2
2
|
export interface Condition {
|
|
3
3
|
attribute: string;
|
|
4
4
|
negate: boolean;
|
|
5
5
|
op: OperationEnum;
|
|
6
|
-
value:
|
|
6
|
+
value: RawConditionValue;
|
|
7
7
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -2,3 +2,4 @@ export { FeatureFlagEvaluationResult, FeatureFlag, evaluateFeatureFlag } from '.
|
|
|
2
2
|
export { TreatmentEnum, Rule } from './rules';
|
|
3
3
|
export { Condition } from './conditions';
|
|
4
4
|
export { OperationEnum, ConditionValue } from './operations/types';
|
|
5
|
+
export { evaluateIsEntitledToFeature, evaluateIsEntitledToPermissions } from './user-entitlements';
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.OperationEnum = exports.TreatmentEnum = exports.evaluateFeatureFlag = void 0;
|
|
3
|
+
exports.evaluateIsEntitledToPermissions = exports.evaluateIsEntitledToFeature = exports.OperationEnum = exports.TreatmentEnum = exports.evaluateFeatureFlag = void 0;
|
|
4
4
|
var feature_flags_1 = require("./feature-flags");
|
|
5
5
|
Object.defineProperty(exports, "evaluateFeatureFlag", { enumerable: true, get: function () { return feature_flags_1.evaluateFeatureFlag; } });
|
|
6
6
|
var rules_1 = require("./rules");
|
|
7
7
|
Object.defineProperty(exports, "TreatmentEnum", { enumerable: true, get: function () { return rules_1.TreatmentEnum; } });
|
|
8
8
|
var types_1 = require("./operations/types");
|
|
9
9
|
Object.defineProperty(exports, "OperationEnum", { enumerable: true, get: function () { return types_1.OperationEnum; } });
|
|
10
|
+
var user_entitlements_1 = require("./user-entitlements");
|
|
11
|
+
Object.defineProperty(exports, "evaluateIsEntitledToFeature", { enumerable: true, get: function () { return user_entitlements_1.evaluateIsEntitledToFeature; } });
|
|
12
|
+
Object.defineProperty(exports, "evaluateIsEntitledToPermissions", { enumerable: true, get: function () { return user_entitlements_1.evaluateIsEntitledToPermissions; } });
|
|
10
13
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,iDAAgG;AAA7C,oHAAA,mBAAmB,OAAA;AACtE,iCAA8C;AAArC,sGAAA,aAAa,OAAA;AAEtB,4CAAmE;AAA1D,sGAAA,aAAa,OAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,iDAAgG;AAA7C,oHAAA,mBAAmB,OAAA;AACtE,iCAA8C;AAArC,sGAAA,aAAa,OAAA;AAEtB,4CAAmE;AAA1D,sGAAA,aAAa,OAAA;AACtB,yDAAmG;AAA1F,gIAAA,2BAA2B,OAAA;AAAE,oIAAA,+BAA+B,OAAA"}
|
|
@@ -18,6 +18,7 @@ exports.BooleanOperationsMapper = void 0;
|
|
|
18
18
|
const types_1 = require("../types");
|
|
19
19
|
const operations_1 = require("./operations");
|
|
20
20
|
__exportStar(require("./operations"), exports);
|
|
21
|
+
__exportStar(require("./sanitizers"), exports);
|
|
21
22
|
exports.BooleanOperationsMapper = {
|
|
22
23
|
[types_1.OperationEnum.Is]: (value) => (0, operations_1.useIsOperation)(value),
|
|
23
24
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/operations/boolean/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,oCAA2D;AAC3D,6CAA8C;AAG9C,+CAA6B;AAEhB,QAAA,uBAAuB,GAAqB;IACvD,CAAC,qBAAa,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,IAAA,2BAAc,EAAC,KAAgC,CAAC;CAChF,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/operations/boolean/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,oCAA2D;AAC3D,6CAA8C;AAG9C,+CAA6B;AAC7B,+CAA6B;AAEhB,QAAA,uBAAuB,GAAqB;IACvD,CAAC,qBAAa,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,IAAA,2BAAc,EAAC,KAAgC,CAAC;CAChF,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { Sanitizer, SanitizersMapper } from '../types';
|
|
2
|
+
import { BooleanOperationPayload } from './types';
|
|
3
|
+
export declare const singleBooleanSanitizer: Sanitizer<BooleanOperationPayload>;
|
|
4
|
+
export declare const BooleanSanitizersMapper: SanitizersMapper<BooleanOperationPayload>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BooleanSanitizersMapper = exports.singleBooleanSanitizer = void 0;
|
|
4
|
+
const types_1 = require("../types");
|
|
5
|
+
const isBoolean = (value) => typeof value === 'boolean';
|
|
6
|
+
const singleBooleanSanitizer = (value) => {
|
|
7
|
+
const sanitizedValue = value.boolean !== undefined && isBoolean(value.boolean) ? { boolean: value.boolean } : undefined;
|
|
8
|
+
return {
|
|
9
|
+
isSanitized: !!sanitizedValue,
|
|
10
|
+
sanitizedValue,
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
exports.singleBooleanSanitizer = singleBooleanSanitizer;
|
|
14
|
+
exports.BooleanSanitizersMapper = {
|
|
15
|
+
[types_1.OperationEnum.Is]: exports.singleBooleanSanitizer,
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=sanitizers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sanitizers.js","sourceRoot":"","sources":["../../../src/operations/boolean/sanitizers.ts"],"names":[],"mappings":";;;AAAA,oCAAyF;AAGzF,MAAM,SAAS,GAAG,CAAC,KAAc,EAAoB,EAAE,CAAC,OAAO,KAAK,KAAK,SAAS,CAAC;AAE5E,MAAM,sBAAsB,GAAuC,CAAC,KAAwB,EAAE,EAAE;IACrG,MAAM,cAAc,GAClB,KAAK,CAAC,OAAO,KAAK,SAAS,IAAI,SAAS,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;IAEnG,OAAO;QACL,WAAW,EAAE,CAAC,CAAC,cAAc;QAC7B,cAAc;KACf,CAAC;AACJ,CAAC,CAAC;AARW,QAAA,sBAAsB,0BAQjC;AAEW,QAAA,uBAAuB,GAA8C;IAChF,CAAC,qBAAa,CAAC,EAAE,CAAC,EAAE,8BAAsB;CAC3C,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useSanitizer = void 0;
|
|
4
|
+
const boolean_1 = require("../boolean");
|
|
5
|
+
const sanitizers_1 = require("../string/sanitizers");
|
|
6
|
+
const sanitizers_2 = require("../date/sanitizers");
|
|
7
|
+
const numeric_1 = require("../numeric");
|
|
8
|
+
const SanitizersMapper = {
|
|
9
|
+
...sanitizers_1.StringSanitizersMapper,
|
|
10
|
+
...numeric_1.NumericSanitizersMapper,
|
|
11
|
+
...sanitizers_2.DateSanitizersMapper,
|
|
12
|
+
...boolean_1.BooleanSanitizersMapper,
|
|
13
|
+
};
|
|
14
|
+
function useSanitizer(operation) {
|
|
15
|
+
return SanitizersMapper[operation];
|
|
16
|
+
}
|
|
17
|
+
exports.useSanitizer = useSanitizer;
|
|
18
|
+
//# sourceMappingURL=sanitizers.resolver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sanitizers.resolver.js","sourceRoot":"","sources":["../../../src/operations/components/sanitizers.resolver.ts"],"names":[],"mappings":";;;AACA,wCAAqD;AACrD,qDAA8D;AAC9D,mDAA0D;AAC1D,wCAAqD;AAErD,MAAM,gBAAgB,GAAqC;IACzD,GAAG,mCAAsB;IACzB,GAAG,iCAAuB;IAC1B,GAAG,iCAAoB;IACvB,GAAG,iCAAuB;CAC3B,CAAC;AAEF,SAAgB,YAAY,CAAC,SAAwB;IACnD,OAAO,gBAAgB,CAAC,SAAS,CAAC,CAAC;AACrC,CAAC;AAFD,oCAEC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Sanitizer, SanitizersMapper } from '../types';
|
|
2
|
+
import { BetweenDateOperationPayload, DateOperationPayload, SingleDateOperationPayload } from './types';
|
|
3
|
+
export declare const sanitizeSingleDate: Sanitizer<SingleDateOperationPayload>;
|
|
4
|
+
export declare const sanitizeDateRange: Sanitizer<BetweenDateOperationPayload>;
|
|
5
|
+
export declare const DateSanitizersMapper: SanitizersMapper<DateOperationPayload>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DateSanitizersMapper = exports.sanitizeDateRange = exports.sanitizeSingleDate = void 0;
|
|
4
|
+
const types_1 = require("../types");
|
|
5
|
+
const sanitizeSingleDate = (value) => {
|
|
6
|
+
const sanitizedValue = value.date ? { date: value.date } : undefined;
|
|
7
|
+
return {
|
|
8
|
+
isSanitized: !!sanitizedValue,
|
|
9
|
+
sanitizedValue,
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
exports.sanitizeSingleDate = sanitizeSingleDate;
|
|
13
|
+
const sanitizeDateRange = (value) => {
|
|
14
|
+
const sanitizedValue = value.start && value.end ? { start: value.start, end: value.end } : undefined;
|
|
15
|
+
return {
|
|
16
|
+
isSanitized: !!sanitizedValue,
|
|
17
|
+
sanitizedValue,
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
exports.sanitizeDateRange = sanitizeDateRange;
|
|
21
|
+
exports.DateSanitizersMapper = {
|
|
22
|
+
[types_1.OperationEnum.On]: exports.sanitizeSingleDate,
|
|
23
|
+
[types_1.OperationEnum.OnOrAfter]: exports.sanitizeDateRange,
|
|
24
|
+
[types_1.OperationEnum.OnOrBefore]: exports.sanitizeSingleDate,
|
|
25
|
+
[types_1.OperationEnum.BetweenDate]: exports.sanitizeSingleDate,
|
|
26
|
+
};
|
|
27
|
+
//# sourceMappingURL=sanitizers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sanitizers.js","sourceRoot":"","sources":["../../../src/operations/date/sanitizers.ts"],"names":[],"mappings":";;;AAAA,oCAAsE;AAG/D,MAAM,kBAAkB,GAA0C,CAAC,KAAK,EAAE,EAAE;IACjF,MAAM,cAAc,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,CAAC,IAAY,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;IAE7E,OAAO;QACL,WAAW,EAAE,CAAC,CAAC,cAAc;QAC7B,cAAc;KACf,CAAC;AACJ,CAAC,CAAC;AAPW,QAAA,kBAAkB,sBAO7B;AAEK,MAAM,iBAAiB,GAA2C,CAAC,KAAK,EAAE,EAAE;IACjF,MAAM,cAAc,GAAG,KAAK,CAAC,KAAK,IAAI,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,KAAa,EAAE,GAAG,EAAE,KAAK,CAAC,GAAW,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;IAErH,OAAO;QACL,WAAW,EAAE,CAAC,CAAC,cAAc;QAC7B,cAAc;KACf,CAAC;AACJ,CAAC,CAAC;AAPW,QAAA,iBAAiB,qBAO5B;AAEW,QAAA,oBAAoB,GAA2C;IAC1E,CAAC,qBAAa,CAAC,EAAE,CAAC,EAAE,0BAAkB;IACtC,CAAC,qBAAa,CAAC,SAAS,CAAC,EAAE,yBAAiB;IAC5C,CAAC,qBAAa,CAAC,UAAU,CAAC,EAAE,0BAAkB;IAC9C,CAAC,qBAAa,CAAC,WAAW,CAAC,EAAE,0BAAkB;CAChD,CAAC"}
|
|
@@ -18,6 +18,7 @@ exports.NumericOperationsMapper = void 0;
|
|
|
18
18
|
const types_1 = require("../types");
|
|
19
19
|
const operations_1 = require("./operations");
|
|
20
20
|
__exportStar(require("./operations"), exports);
|
|
21
|
+
__exportStar(require("./sanitizers"), exports);
|
|
21
22
|
__exportStar(require("./types"), exports);
|
|
22
23
|
exports.NumericOperationsMapper = {
|
|
23
24
|
[types_1.OperationEnum.Equal]: (value) => (0, operations_1.useEqualsOperation)(value),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/operations/numeric/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,oCAA2D;AAC3D,6CAOsB;AAGtB,+CAA6B;AAC7B,0CAAwB;AAEX,QAAA,uBAAuB,GAAqB;IACvD,CAAC,qBAAa,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,IAAA,+BAAkB,EAAC,KAAsC,CAAC;IAC5F,CAAC,qBAAa,CAAC,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,IAAA,oCAAuB,EAAC,KAAsC,CAAC;IACvG,CAAC,qBAAa,CAAC,gBAAgB,CAAC,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,IAAA,yCAA4B,EAAC,KAAsC,CAAC;IACjH,CAAC,qBAAa,CAAC,UAAU,CAAC,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,IAAA,mCAAsB,EAAC,KAAsC,CAAC;IACrG,CAAC,qBAAa,CAAC,eAAe,CAAC,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,IAAA,wCAA2B,EAAC,KAAsC,CAAC;IAC/G,CAAC,qBAAa,CAAC,cAAc,CAAC,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,IAAA,uCAA0B,EAAC,KAAuC,CAAC;CAC/G,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/operations/numeric/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,oCAA2D;AAC3D,6CAOsB;AAGtB,+CAA6B;AAC7B,+CAA6B;AAC7B,0CAAwB;AAEX,QAAA,uBAAuB,GAAqB;IACvD,CAAC,qBAAa,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,IAAA,+BAAkB,EAAC,KAAsC,CAAC;IAC5F,CAAC,qBAAa,CAAC,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,IAAA,oCAAuB,EAAC,KAAsC,CAAC;IACvG,CAAC,qBAAa,CAAC,gBAAgB,CAAC,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,IAAA,yCAA4B,EAAC,KAAsC,CAAC;IACjH,CAAC,qBAAa,CAAC,UAAU,CAAC,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,IAAA,mCAAsB,EAAC,KAAsC,CAAC;IACrG,CAAC,qBAAa,CAAC,eAAe,CAAC,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,IAAA,wCAA2B,EAAC,KAAsC,CAAC;IAC/G,CAAC,qBAAa,CAAC,cAAc,CAAC,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,IAAA,uCAA0B,EAAC,KAAuC,CAAC;CAC/G,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Sanitizer, SanitizersMapper } from '../types';
|
|
2
|
+
import { BetweenNumericOperationPayload, NumericOperationPayload, SingleNumericOperationPayload } from './types';
|
|
3
|
+
export declare const sanitizeSingleNumber: Sanitizer<SingleNumericOperationPayload>;
|
|
4
|
+
export declare const sanitizeNumericRange: Sanitizer<BetweenNumericOperationPayload>;
|
|
5
|
+
export declare const NumericSanitizersMapper: SanitizersMapper<NumericOperationPayload>;
|
|
@@ -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,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"}
|
|
@@ -6,10 +6,19 @@ import { BooleanOperationPayload } from '../boolean/types';
|
|
|
6
6
|
export interface OperationResult {
|
|
7
7
|
isValid: boolean;
|
|
8
8
|
}
|
|
9
|
+
export type RawConditionValue = Record<string, unknown>;
|
|
9
10
|
export type ConditionValue = StringOperationPayload | NumericOperationPayload | DateOperationPayload | BooleanOperationPayload;
|
|
10
11
|
export type OperationHandler = (attribute: any) => OperationResult;
|
|
11
12
|
export type OperationContextEnricher = (value: ConditionValue) => OperationHandler;
|
|
12
13
|
export type OperationsMapper = {
|
|
13
14
|
[key in OperationEnum]?: OperationContextEnricher;
|
|
14
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
|
+
};
|
|
15
24
|
export * from './operation.enum';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/operations/types/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/operations/types/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AA6BA,mDAAiC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './is-entitled.evaluator';
|
|
@@ -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("./is-entitled.evaluator"), exports);
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/user-entitlements/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0DAAwC"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { Attributes, EntitlementResult, UserEntitlementsContext } 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;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
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 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, attributes);
|
|
18
|
+
if (treatment === rules_1.TreatmentEnum.True) {
|
|
19
|
+
return { isEntitled: true };
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return { isEntitled: false, justification: hasExpired ? types_1.Justification.BundleExpired : types_1.Justification.MissingFeature };
|
|
23
|
+
}
|
|
24
|
+
exports.evaluateIsEntitledToFeature = evaluateIsEntitledToFeature;
|
|
25
|
+
function evaluateIsEntitledToPermissions(permissionKey, userEntitlementsContext, attributes) {
|
|
26
|
+
const permission = userEntitlementsContext.permissions[permissionKey];
|
|
27
|
+
if (!permission) {
|
|
28
|
+
return { isEntitled: false, justification: types_1.Justification.MissingPermission };
|
|
29
|
+
}
|
|
30
|
+
const linkedFeatures = getLinkedFeatures(permissionKey, userEntitlementsContext);
|
|
31
|
+
if (!linkedFeatures.length) {
|
|
32
|
+
return { isEntitled: true };
|
|
33
|
+
}
|
|
34
|
+
let hasExpired = false;
|
|
35
|
+
for (const featureKey of linkedFeatures) {
|
|
36
|
+
const { isEntitled, justification } = evaluateIsEntitledToFeature(featureKey, userEntitlementsContext, attributes);
|
|
37
|
+
if (isEntitled) {
|
|
38
|
+
return { isEntitled: true };
|
|
39
|
+
}
|
|
40
|
+
if (justification === types_1.Justification.BundleExpired) {
|
|
41
|
+
hasExpired = true;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return {
|
|
45
|
+
isEntitled: false,
|
|
46
|
+
justification: hasExpired ? types_1.Justification.BundleExpired : types_1.Justification.MissingFeature,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
exports.evaluateIsEntitledToPermissions = evaluateIsEntitledToPermissions;
|
|
50
|
+
function getLinkedFeatures(permissionKey, userEntitlementsContext) {
|
|
51
|
+
return Object.keys(userEntitlementsContext.features).filter((featureKey) => userEntitlementsContext.features[featureKey].linkedPermissions.includes(permissionKey));
|
|
52
|
+
}
|
|
53
|
+
//# 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":";;;AAAA,mCAAoH;AACpH,oDAAuD;AACvD,oCAAyC;AACzC,SAAgB,2BAA2B,CACzC,UAAkB,EAClB,uBAAgD,EAChD,UAAsB;IAEtB,MAAM,OAAO,GAAG,uBAAuB,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;IAE7D,IAAI,UAAU,GAAG,KAAK,CAAC;IACvB,IAAI,OAAO,IAAI,OAAO,CAAC,UAAU,KAAK,IAAI,EAAE;QAC1C,UAAU,GAAG,OAAO,CAAC,UAAU,KAAK,0BAAkB,IAAI,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QAE1F,IAAI,CAAC,UAAU,EAAE;YACf,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC;SAC7B;KACF;IAED,IAAI,OAAO,IAAI,OAAO,CAAC,WAAW,EAAE;QAClC,MAAM,EAAE,SAAS,EAAE,GAAG,IAAA,mCAAmB,EAAC,OAAO,CAAC,WAAW,EAAE,UAAU,CAAC,CAAC;QAC3E,IAAI,SAAS,KAAK,qBAAa,CAAC,IAAI,EAAE;YACpC,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC;SAC7B;KACF;IAED,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,aAAa,EAAE,UAAU,CAAC,CAAC,CAAC,qBAAa,CAAC,aAAa,CAAC,CAAC,CAAC,qBAAa,CAAC,cAAc,EAAE,CAAC;AACvH,CAAC;AAxBD,kEAwBC;AAED,SAAgB,+BAA+B,CAC7C,aAAqB,EACrB,uBAAgD,EAChD,UAAsB;IAEtB,MAAM,UAAU,GAAG,uBAAuB,CAAC,WAAW,CAAC,aAAa,CAAC,CAAC;IAEtE,IAAI,CAAC,UAAU,EAAE;QACf,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,aAAa,EAAE,qBAAa,CAAC,iBAAiB,EAAE,CAAC;KAC9E;IAED,MAAM,cAAc,GAAG,iBAAiB,CAAC,aAAa,EAAE,uBAAuB,CAAC,CAAC;IAEjF,IAAI,CAAC,cAAc,CAAC,MAAM,EAAE;QAC1B,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC;KAC7B;IAED,IAAI,UAAU,GAAG,KAAK,CAAC;IAEvB,KAAK,MAAM,UAAU,IAAI,cAAc,EAAE;QACvC,MAAM,EAAE,UAAU,EAAE,aAAa,EAAE,GAAG,2BAA2B,CAAC,UAAU,EAAE,uBAAuB,EAAE,UAAU,CAAC,CAAC;QAEnH,IAAI,UAAU,EAAE;YACd,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC;SAC7B;QAED,IAAI,aAAa,KAAK,qBAAa,CAAC,aAAa,EAAE;YACjD,UAAU,GAAG,IAAI,CAAC;SACnB;KACF;IAED,OAAO;QACL,UAAU,EAAE,KAAK;QACjB,aAAa,EAAE,UAAU,CAAC,CAAC,CAAC,qBAAa,CAAC,aAAa,CAAC,CAAC,CAAC,qBAAa,CAAC,cAAc;KACvF,CAAC;AACJ,CAAC;AAnCD,0EAmCC;AAED,SAAS,iBAAiB,CAAC,aAAqB,EAAE,uBAAgD;IAChG,OAAO,MAAM,CAAC,IAAI,CAAC,uBAAuB,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC,UAAU,EAAE,EAAE,CACzE,uBAAuB,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,iBAAiB,CAAC,QAAQ,CAAC,aAAa,CAAC,CACvF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
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?: Justification;
|
|
13
|
+
};
|
|
14
|
+
export declare enum Justification {
|
|
15
|
+
MissingFeature = "MISSING_FEATURE",
|
|
16
|
+
MissingPermission = "MISSING_PERMISSION",
|
|
17
|
+
BundleExpired = "BUNDLE_EXPIRED"
|
|
18
|
+
}
|
|
19
|
+
export type Attributes = Record<string, string | number | boolean | Date>;
|
|
20
|
+
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.Justification = void 0;
|
|
4
|
+
var Justification;
|
|
5
|
+
(function (Justification) {
|
|
6
|
+
Justification["MissingFeature"] = "MISSING_FEATURE";
|
|
7
|
+
Justification["MissingPermission"] = "MISSING_PERMISSION";
|
|
8
|
+
Justification["BundleExpired"] = "BUNDLE_EXPIRED";
|
|
9
|
+
})(Justification = exports.Justification || (exports.Justification = {}));
|
|
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,aAIX;AAJD,WAAY,aAAa;IACvB,mDAAkC,CAAA;IAClC,yDAAwC,CAAA;IACxC,iDAAgC,CAAA;AAClC,CAAC,EAJW,aAAa,GAAb,qBAAa,KAAb,qBAAa,QAIxB;AAIY,QAAA,kBAAkB,GAAG,CAAC,CAAC,CAAC"}
|
package/docs/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
# [1.0.0-alpha.6](https://github.com/frontegg/entitlements-javascript-commons/compare/v-1.0.0-alpha.5...v-1.0.0-alpha.6) (2023-10-10)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* **user-entitlements:** add user entitlements evaluation logic ([d924a05](https://github.com/frontegg/entitlements-javascript-commons/commit/d924a056498b4b040dd765b262cde42201644653))
|
|
7
|
+
|
|
8
|
+
# [1.0.0-alpha.5](https://github.com/frontegg/entitlements-javascript-commons/compare/v-1.0.0-alpha.4...v-1.0.0-alpha.5) (2023-10-10)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Features
|
|
12
|
+
|
|
13
|
+
* **sanitizers:** add value sanitizers ([#12](https://github.com/frontegg/entitlements-javascript-commons/issues/12)) ([1decf2c](https://github.com/frontegg/entitlements-javascript-commons/commit/1decf2c01e0a86055bc856db5ff115a2318f1c59))
|
|
14
|
+
|
|
1
15
|
# [1.0.0-alpha.4](https://github.com/frontegg/entitlements-javascript-commons/compare/v-1.0.0-alpha.3...v-1.0.0-alpha.4) (2023-10-10)
|
|
2
16
|
|
|
3
17
|
|
package/package.json
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Condition } from './types';
|
|
2
2
|
import { useOperation } from '../operations/components/operation.resolver';
|
|
3
|
+
import { useSanitizer } from '../operations/components/sanitizers.resolver';
|
|
3
4
|
|
|
4
5
|
export interface CreateConditionEvaluatorPayload {
|
|
5
6
|
condition: Condition;
|
|
@@ -7,8 +8,22 @@ export interface CreateConditionEvaluatorPayload {
|
|
|
7
8
|
|
|
8
9
|
export type ConditionEvaluator = (attributes: Record<string, unknown>) => boolean;
|
|
9
10
|
|
|
11
|
+
function failingConditionEvaluator(): ConditionEvaluator {
|
|
12
|
+
return () => false;
|
|
13
|
+
}
|
|
14
|
+
|
|
10
15
|
export function createConditionEvaluator(payload: CreateConditionEvaluatorPayload): ConditionEvaluator {
|
|
11
|
-
const
|
|
16
|
+
const sanitizer = useSanitizer(payload.condition.op);
|
|
17
|
+
if (!sanitizer) {
|
|
18
|
+
return failingConditionEvaluator();
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const { isSanitized, sanitizedValue } = sanitizer(payload.condition.value);
|
|
22
|
+
if (!isSanitized || sanitizedValue === undefined) {
|
|
23
|
+
return failingConditionEvaluator();
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const operation = useOperation(payload.condition.op, sanitizedValue);
|
|
12
27
|
|
|
13
28
|
return (attributes: Record<string, unknown>) => {
|
|
14
29
|
const attributeKey = payload.condition.attribute;
|
package/src/conditions/types.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { OperationEnum, RawConditionValue } from '../operations/types';
|
|
2
2
|
|
|
3
3
|
export interface Condition {
|
|
4
4
|
attribute: string;
|
|
5
5
|
negate: boolean;
|
|
6
6
|
op: OperationEnum;
|
|
7
|
-
value:
|
|
7
|
+
value: RawConditionValue;
|
|
8
8
|
}
|
package/src/index.ts
CHANGED
|
@@ -2,3 +2,4 @@ export { FeatureFlagEvaluationResult, FeatureFlag, evaluateFeatureFlag } from '.
|
|
|
2
2
|
export { TreatmentEnum, Rule } from './rules';
|
|
3
3
|
export { Condition } from './conditions';
|
|
4
4
|
export { OperationEnum, ConditionValue } from './operations/types';
|
|
5
|
+
export { evaluateIsEntitledToFeature, evaluateIsEntitledToPermissions } from './user-entitlements';
|
|
@@ -3,6 +3,7 @@ import { useIsOperation } from './operations';
|
|
|
3
3
|
import { BooleanOperationPayload } from './types';
|
|
4
4
|
|
|
5
5
|
export * from './operations';
|
|
6
|
+
export * from './sanitizers';
|
|
6
7
|
|
|
7
8
|
export const BooleanOperationsMapper: OperationsMapper = {
|
|
8
9
|
[OperationEnum.Is]: (value) => useIsOperation(value as BooleanOperationPayload),
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { OperationEnum, RawConditionValue, Sanitizer, SanitizersMapper } from '../types';
|
|
2
|
+
import { BooleanOperationPayload } from './types';
|
|
3
|
+
|
|
4
|
+
const isBoolean = (value: unknown): value is boolean => typeof value === 'boolean';
|
|
5
|
+
|
|
6
|
+
export const singleBooleanSanitizer: Sanitizer<BooleanOperationPayload> = (value: RawConditionValue) => {
|
|
7
|
+
const sanitizedValue =
|
|
8
|
+
value.boolean !== undefined && isBoolean(value.boolean) ? { boolean: value.boolean } : undefined;
|
|
9
|
+
|
|
10
|
+
return {
|
|
11
|
+
isSanitized: !!sanitizedValue,
|
|
12
|
+
sanitizedValue,
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export const BooleanSanitizersMapper: SanitizersMapper<BooleanOperationPayload> = {
|
|
17
|
+
[OperationEnum.Is]: singleBooleanSanitizer,
|
|
18
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { fc, test } from '@fast-check/jest';
|
|
2
|
+
import { singleBooleanSanitizer } from '../sanitizers';
|
|
3
|
+
|
|
4
|
+
describe('Boolean sanitizers', () => {
|
|
5
|
+
test.prop([fc.record({ boolean: fc.boolean() })], { verbose: true })(
|
|
6
|
+
'should return sanitized when boolean value exists',
|
|
7
|
+
(value) => {
|
|
8
|
+
const sanitizationResult = singleBooleanSanitizer(value);
|
|
9
|
+
|
|
10
|
+
expect(sanitizationResult.isSanitized).toBe(true);
|
|
11
|
+
expect(typeof sanitizationResult.sanitizedValue?.boolean).toBe('boolean');
|
|
12
|
+
expect(sanitizationResult.sanitizedValue?.boolean).toBe(value.boolean);
|
|
13
|
+
},
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
test.prop([fc.object()], { verbose: true })('should return undefined when no boolean value exists', (value) => {
|
|
17
|
+
const sanitizationResult = singleBooleanSanitizer(value);
|
|
18
|
+
|
|
19
|
+
expect(sanitizationResult.isSanitized).toBe(false);
|
|
20
|
+
expect(sanitizationResult.sanitizedValue).toBeUndefined();
|
|
21
|
+
});
|
|
22
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ConditionValue, OperationEnum, Sanitizer, SanitizersMapper } from '../types';
|
|
2
|
+
import { BooleanSanitizersMapper } from '../boolean';
|
|
3
|
+
import { StringSanitizersMapper } from '../string/sanitizers';
|
|
4
|
+
import { DateSanitizersMapper } from '../date/sanitizers';
|
|
5
|
+
import { NumericSanitizersMapper } from '../numeric';
|
|
6
|
+
|
|
7
|
+
const SanitizersMapper: SanitizersMapper<ConditionValue> = {
|
|
8
|
+
...StringSanitizersMapper,
|
|
9
|
+
...NumericSanitizersMapper,
|
|
10
|
+
...DateSanitizersMapper,
|
|
11
|
+
...BooleanSanitizersMapper,
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export function useSanitizer(operation: OperationEnum): Sanitizer<ConditionValue> | undefined {
|
|
15
|
+
return SanitizersMapper[operation];
|
|
16
|
+
}
|