@frontegg/entitlements-javascript-commons 1.1.0-alpha.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 +7 -0
- package/package.json +1 -1
- 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
|
@@ -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("./plan.evaluator"), exports);
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/plans/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,mDAAiC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.evaluatePlan = void 0;
|
|
4
|
+
const rules_1 = require("../rules");
|
|
5
|
+
function evaluatePlan(plan, attributes) {
|
|
6
|
+
const treatableRule = findTreatableRule(plan, attributes);
|
|
7
|
+
if (treatableRule) {
|
|
8
|
+
return { treatment: treatableRule.treatment };
|
|
9
|
+
}
|
|
10
|
+
return { treatment: plan.defaultTreatment };
|
|
11
|
+
}
|
|
12
|
+
exports.evaluatePlan = evaluatePlan;
|
|
13
|
+
function findTreatableRule(plan, attributes) {
|
|
14
|
+
var _a;
|
|
15
|
+
return (_a = plan.rules) === null || _a === void 0 ? void 0 : _a.find((rule) => {
|
|
16
|
+
const evaluator = (0, rules_1.createRuleEvaluator)({ rule });
|
|
17
|
+
const result = evaluator(attributes);
|
|
18
|
+
return result === rules_1.RuleEvaluationResultEnum.Treatable;
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=plan.evaluator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plan.evaluator.js","sourceRoot":"","sources":["../../src/plans/plan.evaluator.ts"],"names":[],"mappings":";;;AAAA,oCAA+E;AAG/E,SAAgB,YAAY,CAAC,IAAU,EAAE,UAAmC;IAC1E,MAAM,aAAa,GAAG,iBAAiB,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;IAC1D,IAAI,aAAa,EAAE;QACjB,OAAO,EAAE,SAAS,EAAE,aAAa,CAAC,SAAS,EAAE,CAAC;KAC/C;IAED,OAAO,EAAE,SAAS,EAAE,IAAI,CAAC,gBAAgB,EAAE,CAAC;AAC9C,CAAC;AAPD,oCAOC;AAED,SAAS,iBAAiB,CAAC,IAAU,EAAE,UAAmC;;IACxE,OAAO,MAAA,IAAI,CAAC,KAAK,0CAAE,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE;QAC/B,MAAM,SAAS,GAAG,IAAA,2BAAmB,EAAC,EAAE,IAAI,EAAE,CAAC,CAAC;QAChD,MAAM,MAAM,GAAG,SAAS,CAAC,UAAU,CAAC,CAAC;QAErC,OAAO,MAAM,KAAK,gCAAwB,CAAC,SAAS,CAAC;IACvD,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/plans/types.ts"],"names":[],"mappings":""}
|
|
@@ -14,8 +14,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./is-entitled
|
|
17
|
+
__exportStar(require("./is-entitled-to-feature"), exports);
|
|
18
|
+
__exportStar(require("./is-entitled-to-permission"), exports);
|
|
18
19
|
__exportStar(require("./types"), exports);
|
|
19
|
-
__exportStar(require("./
|
|
20
|
-
__exportStar(require("./permissions.utils"), exports);
|
|
20
|
+
__exportStar(require("./utils"), exports);
|
|
21
21
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/user-entitlements/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/user-entitlements/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2DAAyC;AACzC,8DAA4C;AAC5C,0CAAwB;AACxB,0CAAwB"}
|
package/dist/user-entitlements/is-entitled-to-feature/evaluators/direct-entitlement.evaluator.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.directEntitlementEvalutor = void 0;
|
|
4
|
+
const types_1 = require("../../types");
|
|
5
|
+
function directEntitlementEvalutor(featureKey, userEntitlementsContext, attributes = {}) {
|
|
6
|
+
const feature = userEntitlementsContext.features[featureKey];
|
|
7
|
+
let hasExpired = false;
|
|
8
|
+
if (feature && feature.expireTime !== null) {
|
|
9
|
+
hasExpired = feature.expireTime !== types_1.NO_EXPIRATION_TIME && feature.expireTime < Date.now();
|
|
10
|
+
if (!hasExpired) {
|
|
11
|
+
return { isEntitled: true };
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
return {
|
|
15
|
+
isEntitled: false,
|
|
16
|
+
justification: hasExpired ? types_1.NotEntitledJustification.BUNDLE_EXPIRED : types_1.NotEntitledJustification.MISSING_FEATURE,
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
exports.directEntitlementEvalutor = directEntitlementEvalutor;
|
|
20
|
+
//# sourceMappingURL=direct-entitlement.evaluator.js.map
|
package/dist/user-entitlements/is-entitled-to-feature/evaluators/direct-entitlement.evaluator.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"direct-entitlement.evaluator.js","sourceRoot":"","sources":["../../../../src/user-entitlements/is-entitled-to-feature/evaluators/direct-entitlement.evaluator.ts"],"names":[],"mappings":";;;AAAA,uCAMqB;AAErB,SAAgB,yBAAyB,CACvC,UAAkB,EAClB,uBAAgD,EAChD,aAAyB,EAAE;IAE3B,MAAM,OAAO,GAAG,uBAAuB,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;IAC7D,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,OAAO;QACL,UAAU,EAAE,KAAK;QACjB,aAAa,EAAE,UAAU,CAAC,CAAC,CAAC,gCAAwB,CAAC,cAAc,CAAC,CAAC,CAAC,gCAAwB,CAAC,eAAe;KAC/G,CAAC;AACJ,CAAC;AAnBD,8DAmBC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.featureFlagEvaluator = void 0;
|
|
4
|
+
const types_1 = require("../../types");
|
|
5
|
+
const feature_flags_1 = require("../../../feature-flags");
|
|
6
|
+
const attributes_utils_1 = require("../../utils/attributes.utils");
|
|
7
|
+
const rules_1 = require("../../../rules");
|
|
8
|
+
function featureFlagEvaluator(featureKey, userEntitlementsContext, attributes = {}) {
|
|
9
|
+
const feature = userEntitlementsContext.features[featureKey];
|
|
10
|
+
if (feature && feature.featureFlag) {
|
|
11
|
+
const preparedAttributes = (0, attributes_utils_1.prepareAttributes)(attributes);
|
|
12
|
+
const { treatment } = (0, feature_flags_1.evaluateFeatureFlag)(feature.featureFlag, preparedAttributes);
|
|
13
|
+
if (treatment === rules_1.TreatmentEnum.True) {
|
|
14
|
+
return { isEntitled: true };
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return {
|
|
18
|
+
isEntitled: false,
|
|
19
|
+
justification: types_1.NotEntitledJustification.MISSING_FEATURE,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
exports.featureFlagEvaluator = featureFlagEvaluator;
|
|
23
|
+
//# sourceMappingURL=feature-flag.evaluator.js.map
|
package/dist/user-entitlements/is-entitled-to-feature/evaluators/feature-flag.evaluator.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"feature-flag.evaluator.js","sourceRoot":"","sources":["../../../../src/user-entitlements/is-entitled-to-feature/evaluators/feature-flag.evaluator.ts"],"names":[],"mappings":";;;AAAA,uCAA+G;AAC/G,0DAA6D;AAC7D,mEAAiE;AACjE,0CAA+C;AAE/C,SAAgB,oBAAoB,CAClC,UAAkB,EAClB,uBAAgD,EAChD,aAAyB,EAAE;IAE3B,MAAM,OAAO,GAAG,uBAAuB,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;IAC7D,IAAI,OAAO,IAAI,OAAO,CAAC,WAAW,EAAE;QAClC,MAAM,kBAAkB,GAAG,IAAA,oCAAiB,EAAC,UAAU,CAAC,CAAC;QACzD,MAAM,EAAE,SAAS,EAAE,GAAG,IAAA,mCAAmB,EAAC,OAAO,CAAC,WAAW,EAAE,kBAAkB,CAAC,CAAC;QACnF,IAAI,SAAS,KAAK,qBAAa,CAAC,IAAI,EAAE;YACpC,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC;SAC7B;KACF;IAED,OAAO;QACL,UAAU,EAAE,KAAK;QACjB,aAAa,EAAE,gCAAwB,CAAC,eAAe;KACxD,CAAC;AACJ,CAAC;AAlBD,oDAkBC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getIsEntitledEvaluators = void 0;
|
|
4
|
+
const direct_entitlement_evaluator_1 = require("./direct-entitlement.evaluator");
|
|
5
|
+
const feature_flag_evaluator_1 = require("./feature-flag.evaluator");
|
|
6
|
+
const plan_targeting_rules_evaluator_1 = require("./plan-targeting-rules.evaluator");
|
|
7
|
+
function getIsEntitledEvaluators() {
|
|
8
|
+
return [direct_entitlement_evaluator_1.directEntitlementEvalutor, feature_flag_evaluator_1.featureFlagEvaluator, plan_targeting_rules_evaluator_1.planTargetingRulesEvalutor];
|
|
9
|
+
}
|
|
10
|
+
exports.getIsEntitledEvaluators = getIsEntitledEvaluators;
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/user-entitlements/is-entitled-to-feature/evaluators/index.ts"],"names":[],"mappings":";;;AAAA,iFAA2E;AAC3E,qEAAgE;AAChE,qFAA8E;AAG9E,SAAgB,uBAAuB;IACrC,OAAO,CAAC,wDAAyB,EAAE,6CAAoB,EAAE,2DAA0B,CAAC,CAAC;AACvF,CAAC;AAFD,0DAEC"}
|
package/dist/user-entitlements/is-entitled-to-feature/evaluators/plan-targeting-rules.evaluator.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.planTargetingRulesEvalutor = void 0;
|
|
4
|
+
const types_1 = require("../../types");
|
|
5
|
+
const attributes_utils_1 = require("../../utils/attributes.utils");
|
|
6
|
+
const rules_1 = require("../../../rules");
|
|
7
|
+
const plans_1 = require("../../../plans");
|
|
8
|
+
function planTargetingRulesEvalutor(featureKey, userEntitlementsContext, attributes = {}) {
|
|
9
|
+
const feature = userEntitlementsContext.features[featureKey];
|
|
10
|
+
if (feature && feature.planIds && feature.planIds.length > 0) {
|
|
11
|
+
const preparedAttributes = (0, attributes_utils_1.prepareAttributes)(attributes);
|
|
12
|
+
const plans = userEntitlementsContext.plans;
|
|
13
|
+
for (const planId of feature.planIds) {
|
|
14
|
+
const plan = plans[planId];
|
|
15
|
+
if (plan) {
|
|
16
|
+
const { treatment } = (0, plans_1.evaluatePlan)(plan, preparedAttributes);
|
|
17
|
+
if (treatment === rules_1.TreatmentEnum.True) {
|
|
18
|
+
return { isEntitled: true };
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return {
|
|
24
|
+
isEntitled: false,
|
|
25
|
+
justification: types_1.NotEntitledJustification.MISSING_FEATURE,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
exports.planTargetingRulesEvalutor = planTargetingRulesEvalutor;
|
|
29
|
+
//# sourceMappingURL=plan-targeting-rules.evaluator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plan-targeting-rules.evaluator.js","sourceRoot":"","sources":["../../../../src/user-entitlements/is-entitled-to-feature/evaluators/plan-targeting-rules.evaluator.ts"],"names":[],"mappings":";;;AAAA,uCAA+G;AAC/G,mEAAiE;AACjE,0CAA+C;AAC/C,0CAA8C;AAE9C,SAAgB,0BAA0B,CACxC,UAAkB,EAClB,uBAAgD,EAChD,aAAyB,EAAE;IAE3B,MAAM,OAAO,GAAG,uBAAuB,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;IAC7D,IAAI,OAAO,IAAI,OAAO,CAAC,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE;QAC5D,MAAM,kBAAkB,GAAG,IAAA,oCAAiB,EAAC,UAAU,CAAC,CAAC;QACzD,MAAM,KAAK,GAAG,uBAAuB,CAAC,KAAK,CAAC;QAC5C,KAAK,MAAM,MAAM,IAAI,OAAO,CAAC,OAAO,EAAE;YACpC,MAAM,IAAI,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC;YAC3B,IAAI,IAAI,EAAE;gBACR,MAAM,EAAE,SAAS,EAAE,GAAG,IAAA,oBAAY,EAAC,IAAI,EAAE,kBAAkB,CAAC,CAAC;gBAC7D,IAAI,SAAS,KAAK,qBAAa,CAAC,IAAI,EAAE;oBACpC,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC;iBAC7B;aACF;SACF;KACF;IAED,OAAO;QACL,UAAU,EAAE,KAAK;QACjB,aAAa,EAAE,gCAAwB,CAAC,eAAe;KACxD,CAAC;AACJ,CAAC;AAxBD,gEAwBC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/user-entitlements/is-entitled-to-feature/evaluators/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './is-entitled-to-feature.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-to-feature.evaluator"), exports);
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/user-entitlements/is-entitled-to-feature/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,qEAAmD"}
|
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
import { EntitlementResult, UserEntitlementsContext, Attributes } from '
|
|
1
|
+
import { EntitlementResult, UserEntitlementsContext, Attributes } from '../types';
|
|
2
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,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.evaluateIsEntitledToFeature = void 0;
|
|
4
|
+
const utils_1 = require("../utils");
|
|
5
|
+
const evaluators_1 = require("./evaluators");
|
|
6
|
+
function evaluateIsEntitledToFeature(featureKey, userEntitlementsContext, attributes = {}) {
|
|
7
|
+
const entitlementResults = [];
|
|
8
|
+
for (const evaluator of (0, evaluators_1.getIsEntitledEvaluators)()) {
|
|
9
|
+
entitlementResults.push(evaluator(featureKey, userEntitlementsContext, attributes));
|
|
10
|
+
if (!(0, utils_1.shouldContinue)(entitlementResults)) {
|
|
11
|
+
break;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
return (0, utils_1.getResult)(entitlementResults);
|
|
15
|
+
}
|
|
16
|
+
exports.evaluateIsEntitledToFeature = evaluateIsEntitledToFeature;
|
|
17
|
+
//# sourceMappingURL=is-entitled-to-feature.evaluator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-entitled-to-feature.evaluator.js","sourceRoot":"","sources":["../../../src/user-entitlements/is-entitled-to-feature/is-entitled-to-feature.evaluator.ts"],"names":[],"mappings":";;;AACA,oCAAqD;AACrD,6CAAuD;AACvD,SAAgB,2BAA2B,CACzC,UAAkB,EAClB,uBAAgD,EAChD,aAAyB,EAAE;IAE3B,MAAM,kBAAkB,GAAwB,EAAE,CAAC;IACnD,KAAK,MAAM,SAAS,IAAI,IAAA,oCAAuB,GAAE,EAAE;QACjD,kBAAkB,CAAC,IAAI,CAAC,SAAS,CAAC,UAAU,EAAE,uBAAuB,EAAE,UAAU,CAAC,CAAC,CAAC;QACpF,IAAI,CAAC,IAAA,sBAAc,EAAC,kBAAkB,CAAC,EAAE;YACvC,MAAM;SACP;KACF;IAED,OAAO,IAAA,iBAAS,EAAC,kBAAkB,CAAC,CAAC;AACvC,CAAC;AAdD,kEAcC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './is-entitled-to-permission.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-to-permission.evaluator"), exports);
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/user-entitlements/is-entitled-to-permission/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,wEAAsD"}
|
package/dist/user-entitlements/is-entitled-to-permission/is-entitled-to-permission.evaluator.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.evaluateIsEntitledToPermissions = void 0;
|
|
4
|
+
const is_entitled_to_feature_evaluator_1 = require("../is-entitled-to-feature/is-entitled-to-feature.evaluator");
|
|
5
|
+
const types_1 = require("../types");
|
|
6
|
+
const utils_1 = require("../utils");
|
|
7
|
+
const permissions_utils_1 = require("../utils/permissions.utils");
|
|
8
|
+
function evaluateIsEntitledToPermissions(permissionKey, userEntitlementsContext, attributes) {
|
|
9
|
+
const hasPermission = (0, permissions_utils_1.checkPermission)(userEntitlementsContext.permissions, permissionKey);
|
|
10
|
+
if (!hasPermission) {
|
|
11
|
+
return { isEntitled: false, justification: types_1.NotEntitledJustification.MISSING_PERMISSION };
|
|
12
|
+
}
|
|
13
|
+
const linkedFeatures = getLinkedFeatures(permissionKey, userEntitlementsContext);
|
|
14
|
+
if (!linkedFeatures.length) {
|
|
15
|
+
return { isEntitled: true };
|
|
16
|
+
}
|
|
17
|
+
const entitlementResults = [];
|
|
18
|
+
for (const featureKey of linkedFeatures) {
|
|
19
|
+
entitlementResults.push((0, is_entitled_to_feature_evaluator_1.evaluateIsEntitledToFeature)(featureKey, userEntitlementsContext, attributes));
|
|
20
|
+
if (!(0, utils_1.shouldContinue)(entitlementResults)) {
|
|
21
|
+
break;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return (0, utils_1.getResult)(entitlementResults);
|
|
25
|
+
}
|
|
26
|
+
exports.evaluateIsEntitledToPermissions = evaluateIsEntitledToPermissions;
|
|
27
|
+
function getLinkedFeatures(permissionKey, userEntitlementsContext) {
|
|
28
|
+
return Object.keys(userEntitlementsContext.features).filter((featureKey) => userEntitlementsContext.features[featureKey].linkedPermissions.includes(permissionKey));
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=is-entitled-to-permission.evaluator.js.map
|
package/dist/user-entitlements/is-entitled-to-permission/is-entitled-to-permission.evaluator.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-entitled-to-permission.evaluator.js","sourceRoot":"","sources":["../../../src/user-entitlements/is-entitled-to-permission/is-entitled-to-permission.evaluator.ts"],"names":[],"mappings":";;;AAAA,iHAAyG;AACzG,oCAA4G;AAC5G,oCAAqD;AACrD,kEAA6D;AAE7D,SAAgB,+BAA+B,CAC7C,aAAqB,EACrB,uBAAgD,EAChD,UAAuB;IAEvB,MAAM,aAAa,GAAG,IAAA,mCAAe,EAAC,uBAAuB,CAAC,WAAW,EAAE,aAAa,CAAC,CAAC;IAC1F,IAAI,CAAC,aAAa,EAAE;QAClB,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,aAAa,EAAE,gCAAwB,CAAC,kBAAkB,EAAE,CAAC;KAC1F;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,MAAM,kBAAkB,GAAwB,EAAE,CAAC;IACnD,KAAK,MAAM,UAAU,IAAI,cAAc,EAAE;QACvC,kBAAkB,CAAC,IAAI,CAAC,IAAA,8DAA2B,EAAC,UAAU,EAAE,uBAAuB,EAAE,UAAU,CAAC,CAAC,CAAC;QAEtG,IAAI,CAAC,IAAA,sBAAc,EAAC,kBAAkB,CAAC,EAAE;YACvC,MAAM;SACP;KACF;IAED,OAAO,IAAA,iBAAS,EAAC,kBAAkB,CAAC,CAAC;AACvC,CAAC;AA1BD,0EA0BC;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"}
|
|
@@ -1,15 +1,20 @@
|
|
|
1
1
|
import { FeatureFlag } from '../feature-flags/types';
|
|
2
|
+
import { Plan } from '../plans';
|
|
2
3
|
export type UserEntitlementsContext = {
|
|
3
4
|
features: Record<string, {
|
|
5
|
+
planIds: string[];
|
|
4
6
|
expireTime: number | null;
|
|
5
7
|
linkedPermissions: string[];
|
|
6
8
|
featureFlag?: FeatureFlag;
|
|
7
9
|
}>;
|
|
10
|
+
plans: Record<string, Plan>;
|
|
8
11
|
permissions: Permissions;
|
|
9
12
|
};
|
|
10
13
|
export type EntitlementResult = {
|
|
11
|
-
isEntitled:
|
|
12
|
-
|
|
14
|
+
isEntitled: true;
|
|
15
|
+
} | {
|
|
16
|
+
isEntitled: false;
|
|
17
|
+
justification: NotEntitledJustification;
|
|
13
18
|
};
|
|
14
19
|
export declare enum NotEntitledJustification {
|
|
15
20
|
MISSING_FEATURE = "MISSING_FEATURE",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/user-entitlements/types.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/user-entitlements/types.ts"],"names":[],"mappings":";;;AAyBA,IAAY,wBAIX;AAJD,WAAY,wBAAwB;IAClC,+DAAmC,CAAA;IACnC,qEAAyC,CAAA;IACzC,6DAAiC,CAAA;AACnC,CAAC,EAJW,wBAAwB,GAAxB,gCAAwB,KAAxB,gCAAwB,QAInC;AAaY,QAAA,kBAAkB,GAAG,CAAC,CAAC,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Attributes, JwtAttributes, FronteggAttributes } from '
|
|
1
|
+
import { Attributes, JwtAttributes, FronteggAttributes } from '../types';
|
|
2
2
|
/**
|
|
3
3
|
* Merges both `custom` and `jwt` records, map Frontegg attributes and modifies record keys with corrisponding prefixes
|
|
4
4
|
*
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attributes.utils.js","sourceRoot":"","sources":["../../../src/user-entitlements/utils/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,GAAG,CAAC,QAAkB;QAChC,MAAM,EAAE,GAAG,CAAC,EAAY;KACzB,CAAC;AACJ,CAAC;AAPD,0EAOC;AAED,SAAgB,0BAA0B,CAAC,MAA+B,EAAE,MAAc;IACxF,OAAO,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,cAAc,EAAE,UAAU,EAAE,EAAE;QAC/D,cAAc,CAAC,GAAG,MAAM,GAAG,UAAU,EAAE,CAAC,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC;QAC9D,OAAO,cAAc,CAAC;IACxB,CAAC,EAAE,EAAE,CAAC,CAAC;AACT,CAAC;AALD,gEAKC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.shouldContinue = exports.getResult = void 0;
|
|
4
|
+
const types_1 = require("../types");
|
|
5
|
+
function getResult(entitlementResults) {
|
|
6
|
+
let hasExpired = false;
|
|
7
|
+
for (const entitlementResult of entitlementResults) {
|
|
8
|
+
if (entitlementResult.isEntitled) {
|
|
9
|
+
return entitlementResult;
|
|
10
|
+
}
|
|
11
|
+
if (entitlementResult.justification === types_1.NotEntitledJustification.BUNDLE_EXPIRED) {
|
|
12
|
+
hasExpired = true;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
return {
|
|
16
|
+
isEntitled: false,
|
|
17
|
+
justification: hasExpired ? types_1.NotEntitledJustification.BUNDLE_EXPIRED : types_1.NotEntitledJustification.MISSING_FEATURE,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
exports.getResult = getResult;
|
|
21
|
+
function shouldContinue(entitlementResults) {
|
|
22
|
+
return entitlementResults.every(({ isEntitled }) => !isEntitled);
|
|
23
|
+
}
|
|
24
|
+
exports.shouldContinue = shouldContinue;
|
|
25
|
+
//# sourceMappingURL=entitlement-results.utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entitlement-results.utils.js","sourceRoot":"","sources":["../../../src/user-entitlements/utils/entitlement-results.utils.ts"],"names":[],"mappings":";;;AAAA,oCAAuE;AACvE,SAAgB,SAAS,CAAC,kBAAuC;IAC/D,IAAI,UAAU,GAAG,KAAK,CAAC;IACvB,KAAK,MAAM,iBAAiB,IAAI,kBAAkB,EAAE;QAClD,IAAI,iBAAiB,CAAC,UAAU,EAAE;YAChC,OAAO,iBAAiB,CAAC;SAC1B;QAED,IAAI,iBAAiB,CAAC,aAAa,KAAK,gCAAwB,CAAC,cAAc,EAAE;YAC/E,UAAU,GAAG,IAAI,CAAC;SACnB;KACF;IAED,OAAO;QACL,UAAU,EAAE,KAAK;QACjB,aAAa,EAAE,UAAU,CAAC,CAAC,CAAC,gCAAwB,CAAC,cAAc,CAAC,CAAC,CAAC,gCAAwB,CAAC,eAAe;KAC/G,CAAC;AACJ,CAAC;AAhBD,8BAgBC;AAED,SAAgB,cAAc,CAAC,kBAAuC;IACpE,OAAO,kBAAkB,CAAC,KAAK,CAAC,CAAC,EAAE,UAAU,EAAE,EAAE,EAAE,CAAC,CAAC,UAAU,CAAC,CAAC;AACnE,CAAC;AAFD,wCAEC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flatten.utils.js","sourceRoot":"","sources":["../../../src/user-entitlements/utils/flatten.utils.ts"],"names":[],"mappings":";;;AAQA,SAAgB,OAAO,CAAmB,MAAe,EAAE,IAAqB;IAC9E,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC;IAElB,MAAM,SAAS,GAAG,CAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,SAAS,KAAI,GAAG,CAAC;IACzC,MAAM,QAAQ,GAAG,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,QAAQ,CAAC;IAChC,MAAM,YAAY,GAAG,CAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,YAAY,KAAI,WAAW,CAAC;IACvD,MAAM,MAAM,GAAG,EAAE,CAAC;IAElB,SAAS,IAAI,CAAC,MAAM,EAAE,IAAK,EAAE,YAAa;QACxC,YAAY,GAAG,YAAY,IAAI,CAAC,CAAC;QACjC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,UAAU,GAAG;YACvC,MAAM,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;YAC1B,MAAM,OAAO,GAAG,CAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,IAAI,KAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;YACnD,MAAM,IAAI,GAAG,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACnD,MAAM,QAAQ,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;YACjC,MAAM,QAAQ,GAAG,IAAI,KAAK,iBAAiB,IAAI,IAAI,KAAK,gBAAgB,CAAC;YAEzE,MAAM,MAAM,GAAG,IAAI,CAAC,CAAC,CAAC,IAAI,GAAG,SAAS,GAAG,YAAY,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC;YAC/E,IACE,CAAC,OAAO;gBACR,CAAC,QAAQ;gBACT,QAAQ;gBACR,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,MAAM;gBACzB,CAAC,CAAC,CAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,QAAQ,CAAA,IAAI,CAAC,QAAQ,IAAI,YAAY,GAAG,QAAQ,CAAC,CAAC,EAC1D;gBACA,OAAO,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,YAAY,GAAG,CAAC,CAAC,CAAC;aAC9C;YAED,MAAM,CAAC,MAAM,CAAC,GAAG,KAAK,CAAC;QACzB,CAAC,CAAC,CAAC;IACL,CAAC;IAED,IAAI,CAAC,MAAM,CAAC,CAAC;IAEb,OAAO,MAAiB,CAAC;AAC3B,CAAC;AAnCD,0BAmCC;AAED,SAAS,QAAQ,CAAC,GAAG;IACnB,OAAO,GAAG,IAAI,GAAG,CAAC,WAAW,IAAI,OAAO,GAAG,CAAC,WAAW,CAAC,QAAQ,KAAK,UAAU,IAAI,GAAG,CAAC,WAAW,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;AACnH,CAAC;AAED,SAAS,WAAW,CAAC,GAAG;IACtB,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
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("./permissions.utils"), exports);
|
|
18
|
+
__exportStar(require("./attributes.utils"), exports);
|
|
19
|
+
__exportStar(require("./entitlement-results.utils"), exports);
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/user-entitlements/utils/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,sDAAoC;AACpC,qDAAmC;AACnC,8DAA4C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"permissions.utils.js","sourceRoot":"","sources":["../../../src/user-entitlements/utils/permissions.utils.ts"],"names":[],"mappings":";;;AACA,SAAgB,eAAe,CAAC,WAAwB,EAAE,kBAA0B;IAClF,OAAO,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,CAAC,aAAa,EAAE,EAAE,CACrD,0BAA0B,CAAC,aAAa,CAAC,CAAC,IAAI,CAAC,kBAAkB,CAAC,CACnE,CAAC;AACJ,CAAC;AAJD,0CAIC;AAED,SAAgB,0BAA0B,CAAC,aAAqB;IAC9D,OAAO,IAAI,MAAM,CAAC,GAAG,GAAG,aAAa,CAAC,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,GAAG,GAAG,EAAE,IAAI,CAAC,CAAC;AAChG,CAAC;AAFD,gEAEC"}
|
package/docs/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
# [1.1.0-alpha.2](https://github.com/frontegg/entitlements-javascript-commons/compare/v-1.1.0-alpha.1...v-1.1.0-alpha.2) (2024-01-07)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* **plans:** add plan evaluation to is entitled evaluator ([0e1b876](https://github.com/frontegg/entitlements-javascript-commons/commit/0e1b876a81e3b6f0457bc1e32251f2b0f9e267eb))
|
|
7
|
+
|
|
1
8
|
# [1.1.0-alpha.1](https://github.com/frontegg/entitlements-javascript-commons/compare/v-1.0.1...v-1.1.0-alpha.1) (2023-12-31)
|
|
2
9
|
|
|
3
10
|
|
package/package.json
CHANGED
package/src/user-entitlements/is-entitled-to-feature/evaluators/direct-entitlement.evaluator.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Attributes,
|
|
3
|
+
EntitlementResult,
|
|
4
|
+
NO_EXPIRATION_TIME,
|
|
5
|
+
NotEntitledJustification,
|
|
6
|
+
UserEntitlementsContext,
|
|
7
|
+
} from '../../types';
|
|
8
|
+
|
|
9
|
+
export function directEntitlementEvalutor(
|
|
10
|
+
featureKey: string,
|
|
11
|
+
userEntitlementsContext: UserEntitlementsContext,
|
|
12
|
+
attributes: Attributes = {},
|
|
13
|
+
): EntitlementResult {
|
|
14
|
+
const feature = userEntitlementsContext.features[featureKey];
|
|
15
|
+
let hasExpired = false;
|
|
16
|
+
if (feature && feature.expireTime !== null) {
|
|
17
|
+
hasExpired = feature.expireTime !== NO_EXPIRATION_TIME && feature.expireTime < Date.now();
|
|
18
|
+
|
|
19
|
+
if (!hasExpired) {
|
|
20
|
+
return { isEntitled: true };
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return {
|
|
25
|
+
isEntitled: false,
|
|
26
|
+
justification: hasExpired ? NotEntitledJustification.BUNDLE_EXPIRED : NotEntitledJustification.MISSING_FEATURE,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Attributes, EntitlementResult, NotEntitledJustification, UserEntitlementsContext } from '../../types';
|
|
2
|
+
import { evaluateFeatureFlag } from '../../../feature-flags';
|
|
3
|
+
import { prepareAttributes } from '../../utils/attributes.utils';
|
|
4
|
+
import { TreatmentEnum } from '../../../rules';
|
|
5
|
+
|
|
6
|
+
export function featureFlagEvaluator(
|
|
7
|
+
featureKey: string,
|
|
8
|
+
userEntitlementsContext: UserEntitlementsContext,
|
|
9
|
+
attributes: Attributes = {},
|
|
10
|
+
): EntitlementResult {
|
|
11
|
+
const feature = userEntitlementsContext.features[featureKey];
|
|
12
|
+
if (feature && feature.featureFlag) {
|
|
13
|
+
const preparedAttributes = prepareAttributes(attributes);
|
|
14
|
+
const { treatment } = evaluateFeatureFlag(feature.featureFlag, preparedAttributes);
|
|
15
|
+
if (treatment === TreatmentEnum.True) {
|
|
16
|
+
return { isEntitled: true };
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return {
|
|
21
|
+
isEntitled: false,
|
|
22
|
+
justification: NotEntitledJustification.MISSING_FEATURE,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { directEntitlementEvalutor } from './direct-entitlement.evaluator';
|
|
2
|
+
import { featureFlagEvaluator } from './feature-flag.evaluator';
|
|
3
|
+
import { planTargetingRulesEvalutor } from './plan-targeting-rules.evaluator';
|
|
4
|
+
import { IsEntitledEvaluator } from './types';
|
|
5
|
+
|
|
6
|
+
export function getIsEntitledEvaluators(): IsEntitledEvaluator[] {
|
|
7
|
+
return [directEntitlementEvalutor, featureFlagEvaluator, planTargetingRulesEvalutor];
|
|
8
|
+
}
|