flagsmith-nodejs 2.0.0-beta.6 → 2.0.1
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/pull_request.yaml +37 -29
- package/README.md +7 -0
- package/example/server/api/index.js +1 -1
- package/flagsmith-engine/features/models.ts +28 -6
- package/flagsmith-engine/features/util.ts +9 -0
- package/flagsmith-engine/identities/models.ts +1 -1
- package/flagsmith-engine/index.ts +7 -5
- package/flagsmith-engine/organisations/models.ts +1 -1
- package/flagsmith-engine/segments/models.ts +21 -4
- package/flagsmith-engine/segments/util.ts +8 -0
- package/flagsmith-engine/utils/collections.ts +1 -12
- package/flagsmith-engine/utils/hashing/index.ts +5 -2
- package/flagsmith-engine/utils/index.ts +6 -2
- package/package.json +4 -2
- package/sdk/analytics.ts +0 -2
- package/sdk/index.ts +84 -28
- package/sdk/polling_manager.ts +0 -1
- package/sdk/types.ts +8 -0
- package/sdk/utils.ts +4 -5
- package/tests/engine/unit/{egine.test.ts → engine.test.ts} +20 -0
- package/tests/engine/unit/features/models.test.ts +8 -4
- package/tests/engine/unit/identities/identities_builders.test.ts +13 -0
- package/tests/engine/unit/identities/identities_models.test.ts +3 -14
- package/tests/engine/unit/organization/models.test.ts +1 -1
- package/tests/engine/unit/segments/segments_model.test.ts +22 -1
- package/tests/engine/unit/utils.ts +1 -1
- package/tests/sdk/analytics.test.ts +11 -0
- package/tests/sdk/flagsmith-cache.test.ts +150 -0
- package/tests/sdk/flagsmith-environment-flags.test.ts +197 -0
- package/tests/sdk/flagsmith-identity-flags.test.ts +140 -0
- package/tests/sdk/flagsmith.test.ts +100 -85
- package/tests/sdk/polling.test.ts +25 -0
- package/tests/sdk/utils.ts +21 -2
- package/tsconfig.json +1 -1
- package/build/flagsmith-engine/environments/integrations/models.d.ts +0 -4
- package/build/flagsmith-engine/environments/integrations/models.js +0 -11
- package/build/flagsmith-engine/environments/models.d.ts +0 -25
- package/build/flagsmith-engine/environments/models.js +0 -29
- package/build/flagsmith-engine/environments/util.d.ts +0 -3
- package/build/flagsmith-engine/environments/util.js +0 -21
- package/build/flagsmith-engine/features/constants.d.ts +0 -4
- package/build/flagsmith-engine/features/constants.js +0 -7
- package/build/flagsmith-engine/features/models.d.ts +0 -32
- package/build/flagsmith-engine/features/models.js +0 -102
- package/build/flagsmith-engine/features/util.d.ts +0 -3
- package/build/flagsmith-engine/features/util.js +0 -20
- package/build/flagsmith-engine/identities/models.d.ts +0 -15
- package/build/flagsmith-engine/identities/models.js +0 -112
- package/build/flagsmith-engine/identities/traits/models.d.ts +0 -5
- package/build/flagsmith-engine/identities/traits/models.js +0 -11
- package/build/flagsmith-engine/identities/util.d.ts +0 -4
- package/build/flagsmith-engine/identities/util.js +0 -46
- package/build/flagsmith-engine/index.d.ts +0 -8
- package/build/flagsmith-engine/index.js +0 -113
- package/build/flagsmith-engine/organisations/models.d.ts +0 -9
- package/build/flagsmith-engine/organisations/models.js +0 -21
- package/build/flagsmith-engine/organisations/util.d.ts +0 -2
- package/build/flagsmith-engine/organisations/util.js +0 -8
- package/build/flagsmith-engine/projects/models.d.ts +0 -10
- package/build/flagsmith-engine/projects/models.js +0 -14
- package/build/flagsmith-engine/projects/util.d.ts +0 -2
- package/build/flagsmith-engine/projects/util.js +0 -15
- package/build/flagsmith-engine/segments/constants.d.ts +0 -26
- package/build/flagsmith-engine/segments/constants.js +0 -31
- package/build/flagsmith-engine/segments/evaluators.d.ts +0 -6
- package/build/flagsmith-engine/segments/evaluators.js +0 -37
- package/build/flagsmith-engine/segments/models.d.ts +0 -31
- package/build/flagsmith-engine/segments/models.js +0 -92
- package/build/flagsmith-engine/segments/util.d.ts +0 -4
- package/build/flagsmith-engine/segments/util.js +0 -25
- package/build/flagsmith-engine/utils/collections.d.ts +0 -4
- package/build/flagsmith-engine/utils/collections.js +0 -97
- package/build/flagsmith-engine/utils/errors.d.ts +0 -2
- package/build/flagsmith-engine/utils/errors.js +0 -26
- package/build/flagsmith-engine/utils/hashing/index.d.ts +0 -9
- package/build/flagsmith-engine/utils/hashing/index.js +0 -57
- package/build/flagsmith-engine/utils/index.d.ts +0 -1
- package/build/flagsmith-engine/utils/index.js +0 -14
- package/build/index.d.ts +0 -1
- package/build/index.js +0 -11
- package/build/sdk/analytics.d.ts +0 -28
- package/build/sdk/analytics.js +0 -103
- package/build/sdk/errors.d.ts +0 -4
- package/build/sdk/errors.js +0 -34
- package/build/sdk/index.d.ts +0 -118
- package/build/sdk/index.js +0 -386
- package/build/sdk/models.d.ts +0 -55
- package/build/sdk/models.js +0 -149
- package/build/sdk/polling_manager.d.ts +0 -9
- package/build/sdk/polling_manager.js +0 -73
- package/build/sdk/utils.d.ts +0 -12
- package/build/sdk/utils.js +0 -94
- package/tests/engine/engine-tests/engine-test-data/data/environment_n9fbf9h3v4fFgH3U3ngWhb.json +0 -12393
- package/tests/engine/engine-tests/engine-test-data/readme.md +0 -30
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __values = (this && this.__values) || function(o) {
|
|
3
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
4
|
-
if (m) return m.call(o);
|
|
5
|
-
if (o && typeof o.length === "number") return {
|
|
6
|
-
next: function () {
|
|
7
|
-
if (o && i >= o.length) o = void 0;
|
|
8
|
-
return { value: o && o[i++], done: !o };
|
|
9
|
-
}
|
|
10
|
-
};
|
|
11
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
12
|
-
};
|
|
13
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
exports.FeatureStateModel = exports.MultivariateFeatureStateValueModel = exports.MultivariateFeatureOptionModel = exports.FeatureModel = void 0;
|
|
15
|
-
var uuid_1 = require("uuid");
|
|
16
|
-
var hashing_1 = require("../utils/hashing");
|
|
17
|
-
var FeatureModel = /** @class */ (function () {
|
|
18
|
-
function FeatureModel(id, name, type) {
|
|
19
|
-
this.id = id;
|
|
20
|
-
this.name = name;
|
|
21
|
-
this.type = type;
|
|
22
|
-
}
|
|
23
|
-
FeatureModel.prototype.eq = function (other) {
|
|
24
|
-
return !!other && this.id === other.id;
|
|
25
|
-
};
|
|
26
|
-
return FeatureModel;
|
|
27
|
-
}());
|
|
28
|
-
exports.FeatureModel = FeatureModel;
|
|
29
|
-
var MultivariateFeatureOptionModel = /** @class */ (function () {
|
|
30
|
-
function MultivariateFeatureOptionModel(value, id) {
|
|
31
|
-
this.value = value;
|
|
32
|
-
this.id = id;
|
|
33
|
-
}
|
|
34
|
-
return MultivariateFeatureOptionModel;
|
|
35
|
-
}());
|
|
36
|
-
exports.MultivariateFeatureOptionModel = MultivariateFeatureOptionModel;
|
|
37
|
-
var MultivariateFeatureStateValueModel = /** @class */ (function () {
|
|
38
|
-
function MultivariateFeatureStateValueModel(multivariate_feature_option, percentage_allocation, id, mvFsValueUuid) {
|
|
39
|
-
this.mvFsValueUuid = (0, uuid_1.v4)();
|
|
40
|
-
this.id = id;
|
|
41
|
-
this.percentageAllocation = percentage_allocation;
|
|
42
|
-
this.multivariateFeatureOption = multivariate_feature_option;
|
|
43
|
-
this.mvFsValueUuid = mvFsValueUuid || this.mvFsValueUuid;
|
|
44
|
-
}
|
|
45
|
-
return MultivariateFeatureStateValueModel;
|
|
46
|
-
}());
|
|
47
|
-
exports.MultivariateFeatureStateValueModel = MultivariateFeatureStateValueModel;
|
|
48
|
-
var FeatureStateModel = /** @class */ (function () {
|
|
49
|
-
function FeatureStateModel(feature, enabled, djangoID, value, featurestateUuid) {
|
|
50
|
-
if (featurestateUuid === void 0) { featurestateUuid = (0, uuid_1.v4)(); }
|
|
51
|
-
this.featurestateUUID = (0, uuid_1.v4)();
|
|
52
|
-
this.multivariateFeatureStateValues = [];
|
|
53
|
-
this.feature = feature;
|
|
54
|
-
this.enabled = enabled;
|
|
55
|
-
this.djangoID = djangoID;
|
|
56
|
-
this.value = value;
|
|
57
|
-
this.featurestateUUID = featurestateUuid;
|
|
58
|
-
}
|
|
59
|
-
FeatureStateModel.prototype.setValue = function (value) {
|
|
60
|
-
this.value = value;
|
|
61
|
-
};
|
|
62
|
-
FeatureStateModel.prototype.getValue = function (identityId) {
|
|
63
|
-
if (!!identityId && this.multivariateFeatureStateValues.length > 0) {
|
|
64
|
-
return this.getMultivariateValue(identityId);
|
|
65
|
-
}
|
|
66
|
-
return this.value;
|
|
67
|
-
};
|
|
68
|
-
FeatureStateModel.prototype.get_feature_state_value = function () {
|
|
69
|
-
return this.getValue();
|
|
70
|
-
};
|
|
71
|
-
FeatureStateModel.prototype.getMultivariateValue = function (identityID) {
|
|
72
|
-
var e_1, _a;
|
|
73
|
-
var percentageValue = (0, hashing_1.getHashedPercentateForObjIds)([
|
|
74
|
-
this.djangoID || this.featurestateUUID,
|
|
75
|
-
identityID
|
|
76
|
-
]);
|
|
77
|
-
var startPercentage = 0;
|
|
78
|
-
var sortedF = this.multivariateFeatureStateValues.sort(function (a, b) {
|
|
79
|
-
return !!(a.id && b.id) ? a.id - b.id : a.mvFsValueUuid > b.mvFsValueUuid ? -1 : 1;
|
|
80
|
-
});
|
|
81
|
-
try {
|
|
82
|
-
for (var sortedF_1 = __values(sortedF), sortedF_1_1 = sortedF_1.next(); !sortedF_1_1.done; sortedF_1_1 = sortedF_1.next()) {
|
|
83
|
-
var myValue = sortedF_1_1.value;
|
|
84
|
-
var limit = myValue.percentageAllocation + startPercentage;
|
|
85
|
-
if (startPercentage <= percentageValue && percentageValue < limit) {
|
|
86
|
-
return myValue.multivariateFeatureOption.value;
|
|
87
|
-
}
|
|
88
|
-
startPercentage = limit;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
92
|
-
finally {
|
|
93
|
-
try {
|
|
94
|
-
if (sortedF_1_1 && !sortedF_1_1.done && (_a = sortedF_1.return)) _a.call(sortedF_1);
|
|
95
|
-
}
|
|
96
|
-
finally { if (e_1) throw e_1.error; }
|
|
97
|
-
}
|
|
98
|
-
return this.value;
|
|
99
|
-
};
|
|
100
|
-
return FeatureStateModel;
|
|
101
|
-
}());
|
|
102
|
-
exports.FeatureStateModel = FeatureStateModel;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.buildFeatureStateModel = exports.buildFeatureModel = void 0;
|
|
4
|
-
var models_1 = require("./models");
|
|
5
|
-
function buildFeatureModel(featuresModelJSON) {
|
|
6
|
-
return new models_1.FeatureModel(featuresModelJSON.id, featuresModelJSON.name, featuresModelJSON.type);
|
|
7
|
-
}
|
|
8
|
-
exports.buildFeatureModel = buildFeatureModel;
|
|
9
|
-
function buildFeatureStateModel(featuresStateModelJSON) {
|
|
10
|
-
var featureStateModel = new models_1.FeatureStateModel(buildFeatureModel(featuresStateModelJSON.feature), featuresStateModelJSON.enabled, featuresStateModelJSON.django_id, featuresStateModelJSON.feature_state_value, featuresStateModelJSON.uuid);
|
|
11
|
-
var multivariateFeatureStateValues = featuresStateModelJSON.multivariate_feature_state_values
|
|
12
|
-
? featuresStateModelJSON.multivariate_feature_state_values.map(function (fsv) {
|
|
13
|
-
var featureOption = new models_1.MultivariateFeatureOptionModel(fsv.multivariate_feature_option.value, fsv.multivariate_feature_option.id);
|
|
14
|
-
return new models_1.MultivariateFeatureStateValueModel(featureOption, fsv.percentage_allocation, fsv.id);
|
|
15
|
-
})
|
|
16
|
-
: [];
|
|
17
|
-
featureStateModel.multivariateFeatureStateValues = multivariateFeatureStateValues;
|
|
18
|
-
return featureStateModel;
|
|
19
|
-
}
|
|
20
|
-
exports.buildFeatureStateModel = buildFeatureStateModel;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { IdentityFeaturesList } from '../utils/collections';
|
|
2
|
-
import { TraitModel } from './traits/models';
|
|
3
|
-
export declare class IdentityModel {
|
|
4
|
-
identifier: string;
|
|
5
|
-
environmentApiKey: string;
|
|
6
|
-
createdDate?: number;
|
|
7
|
-
identityFeatures: IdentityFeaturesList;
|
|
8
|
-
identityTraits: TraitModel[];
|
|
9
|
-
identityUuid: string;
|
|
10
|
-
djangoID: number | undefined;
|
|
11
|
-
constructor(created_date: string, identityTraits: TraitModel[], identityFeatures: IdentityFeaturesList, environmentApiKey: string, identifier: string, identityUuid?: string);
|
|
12
|
-
get compositeKey(): string;
|
|
13
|
-
static generateCompositeKey(env_key: string, identifier: string): string;
|
|
14
|
-
update_traits(traits: TraitModel[]): void;
|
|
15
|
-
}
|
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
3
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
4
|
-
if (!m) return o;
|
|
5
|
-
var i = m.call(o), r, ar = [], e;
|
|
6
|
-
try {
|
|
7
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
8
|
-
}
|
|
9
|
-
catch (error) { e = { error: error }; }
|
|
10
|
-
finally {
|
|
11
|
-
try {
|
|
12
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
13
|
-
}
|
|
14
|
-
finally { if (e) throw e.error; }
|
|
15
|
-
}
|
|
16
|
-
return ar;
|
|
17
|
-
};
|
|
18
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
19
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
20
|
-
if (ar || !(i in from)) {
|
|
21
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
22
|
-
ar[i] = from[i];
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
26
|
-
};
|
|
27
|
-
var __values = (this && this.__values) || function(o) {
|
|
28
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
29
|
-
if (m) return m.call(o);
|
|
30
|
-
if (o && typeof o.length === "number") return {
|
|
31
|
-
next: function () {
|
|
32
|
-
if (o && i >= o.length) o = void 0;
|
|
33
|
-
return { value: o && o[i++], done: !o };
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.IdentityModel = void 0;
|
|
40
|
-
var collections_1 = require("../utils/collections");
|
|
41
|
-
var uuidv4 = require('uuid').v4;
|
|
42
|
-
var IdentityModel = /** @class */ (function () {
|
|
43
|
-
function IdentityModel(created_date, identityTraits, identityFeatures, environmentApiKey, identifier, identityUuid) {
|
|
44
|
-
this.identityUuid = identityUuid || uuidv4();
|
|
45
|
-
this.createdDate = Date.parse(created_date) || Date.now();
|
|
46
|
-
this.identityTraits = identityTraits;
|
|
47
|
-
this.identityFeatures = new (collections_1.IdentityFeaturesList.bind.apply(collections_1.IdentityFeaturesList, __spreadArray([void 0], __read(identityFeatures), false)))();
|
|
48
|
-
this.environmentApiKey = environmentApiKey;
|
|
49
|
-
this.identifier = identifier;
|
|
50
|
-
}
|
|
51
|
-
Object.defineProperty(IdentityModel.prototype, "compositeKey", {
|
|
52
|
-
get: function () {
|
|
53
|
-
return IdentityModel.generateCompositeKey(this.environmentApiKey, this.identifier);
|
|
54
|
-
},
|
|
55
|
-
enumerable: false,
|
|
56
|
-
configurable: true
|
|
57
|
-
});
|
|
58
|
-
IdentityModel.generateCompositeKey = function (env_key, identifier) {
|
|
59
|
-
return "".concat(env_key, "_").concat(identifier);
|
|
60
|
-
};
|
|
61
|
-
IdentityModel.prototype.update_traits = function (traits) {
|
|
62
|
-
var e_1, _a, e_2, _b, e_3, _c;
|
|
63
|
-
var existingTraits = new Map();
|
|
64
|
-
try {
|
|
65
|
-
for (var _d = __values(this.identityTraits), _e = _d.next(); !_e.done; _e = _d.next()) {
|
|
66
|
-
var trait = _e.value;
|
|
67
|
-
existingTraits.set(trait.traitKey, trait);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
71
|
-
finally {
|
|
72
|
-
try {
|
|
73
|
-
if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
|
|
74
|
-
}
|
|
75
|
-
finally { if (e_1) throw e_1.error; }
|
|
76
|
-
}
|
|
77
|
-
try {
|
|
78
|
-
for (var traits_1 = __values(traits), traits_1_1 = traits_1.next(); !traits_1_1.done; traits_1_1 = traits_1.next()) {
|
|
79
|
-
var trait = traits_1_1.value;
|
|
80
|
-
if (!!trait.traitValue) {
|
|
81
|
-
existingTraits.set(trait.traitKey, trait);
|
|
82
|
-
}
|
|
83
|
-
else {
|
|
84
|
-
existingTraits.delete(trait.traitKey);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
89
|
-
finally {
|
|
90
|
-
try {
|
|
91
|
-
if (traits_1_1 && !traits_1_1.done && (_b = traits_1.return)) _b.call(traits_1);
|
|
92
|
-
}
|
|
93
|
-
finally { if (e_2) throw e_2.error; }
|
|
94
|
-
}
|
|
95
|
-
this.identityTraits = [];
|
|
96
|
-
try {
|
|
97
|
-
for (var _f = __values(existingTraits.entries()), _g = _f.next(); !_g.done; _g = _f.next()) {
|
|
98
|
-
var _h = __read(_g.value, 2), k = _h[0], v = _h[1];
|
|
99
|
-
this.identityTraits.push(v);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
103
|
-
finally {
|
|
104
|
-
try {
|
|
105
|
-
if (_g && !_g.done && (_c = _f.return)) _c.call(_f);
|
|
106
|
-
}
|
|
107
|
-
finally { if (e_3) throw e_3.error; }
|
|
108
|
-
}
|
|
109
|
-
};
|
|
110
|
-
return IdentityModel;
|
|
111
|
-
}());
|
|
112
|
-
exports.IdentityModel = IdentityModel;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TraitModel = void 0;
|
|
4
|
-
var TraitModel = /** @class */ (function () {
|
|
5
|
-
function TraitModel(key, value) {
|
|
6
|
-
this.traitKey = key;
|
|
7
|
-
this.traitValue = value;
|
|
8
|
-
}
|
|
9
|
-
return TraitModel;
|
|
10
|
-
}());
|
|
11
|
-
exports.TraitModel = TraitModel;
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
3
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
4
|
-
if (!m) return o;
|
|
5
|
-
var i = m.call(o), r, ar = [], e;
|
|
6
|
-
try {
|
|
7
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
8
|
-
}
|
|
9
|
-
catch (error) { e = { error: error }; }
|
|
10
|
-
finally {
|
|
11
|
-
try {
|
|
12
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
13
|
-
}
|
|
14
|
-
finally { if (e) throw e.error; }
|
|
15
|
-
}
|
|
16
|
-
return ar;
|
|
17
|
-
};
|
|
18
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
19
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
20
|
-
if (ar || !(i in from)) {
|
|
21
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
22
|
-
ar[i] = from[i];
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
26
|
-
};
|
|
27
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
|
-
exports.buildIdentityModel = exports.buildTraitModel = void 0;
|
|
29
|
-
var util_1 = require("../features/util");
|
|
30
|
-
var collections_1 = require("../utils/collections");
|
|
31
|
-
var models_1 = require("./models");
|
|
32
|
-
var models_2 = require("./traits/models");
|
|
33
|
-
function buildTraitModel(traitJSON) {
|
|
34
|
-
return new models_2.TraitModel(traitJSON.trait_key, traitJSON.trait_value);
|
|
35
|
-
}
|
|
36
|
-
exports.buildTraitModel = buildTraitModel;
|
|
37
|
-
function buildIdentityModel(identityJSON) {
|
|
38
|
-
var featureList = identityJSON.identity_features
|
|
39
|
-
? new (collections_1.IdentityFeaturesList.bind.apply(collections_1.IdentityFeaturesList, __spreadArray([void 0], __read(identityJSON.identity_features.map(function (f) { return (0, util_1.buildFeatureStateModel)(f); })), false)))() : [];
|
|
40
|
-
var model = new models_1.IdentityModel(identityJSON.created_date, identityJSON.identity_traits
|
|
41
|
-
? identityJSON.identity_traits.map(function (trait) { return buildTraitModel(trait); })
|
|
42
|
-
: [], featureList, identityJSON.environment_api_key, identityJSON.identifier, identityJSON.identity_uuid);
|
|
43
|
-
model.djangoID = identityJSON.django_id;
|
|
44
|
-
return model;
|
|
45
|
-
}
|
|
46
|
-
exports.buildIdentityModel = buildIdentityModel;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { EnvironmentModel } from './environments/models';
|
|
2
|
-
import { FeatureStateModel } from './features/models';
|
|
3
|
-
import { IdentityModel } from './identities/models';
|
|
4
|
-
import { TraitModel } from './identities/traits/models';
|
|
5
|
-
export declare function getIdentityFeatureState(environment: EnvironmentModel, identity: IdentityModel, featureName: string, overrideTraits?: TraitModel[]): FeatureStateModel;
|
|
6
|
-
export declare function getIdentityFeatureStates(environment: EnvironmentModel, identity: IdentityModel, overrideTraits?: TraitModel[]): FeatureStateModel[];
|
|
7
|
-
export declare function getEnvironmentFeatureState(environment: EnvironmentModel, featureName: string): FeatureStateModel;
|
|
8
|
-
export declare function getEnvironmentFeatureStates(environment: EnvironmentModel): FeatureStateModel[];
|
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __values = (this && this.__values) || function(o) {
|
|
3
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
4
|
-
if (m) return m.call(o);
|
|
5
|
-
if (o && typeof o.length === "number") return {
|
|
6
|
-
next: function () {
|
|
7
|
-
if (o && i >= o.length) o = void 0;
|
|
8
|
-
return { value: o && o[i++], done: !o };
|
|
9
|
-
}
|
|
10
|
-
};
|
|
11
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
12
|
-
};
|
|
13
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
exports.getEnvironmentFeatureStates = exports.getEnvironmentFeatureState = exports.getIdentityFeatureStates = exports.getIdentityFeatureState = void 0;
|
|
15
|
-
var evaluators_1 = require("./segments/evaluators");
|
|
16
|
-
var errors_1 = require("./utils/errors");
|
|
17
|
-
function getIdentityFeatureStatesDict(environment, identity, overrideTraits) {
|
|
18
|
-
var e_1, _a, e_2, _b, e_3, _c, e_4, _d;
|
|
19
|
-
// Get feature states from the environment
|
|
20
|
-
var featureStates = {};
|
|
21
|
-
try {
|
|
22
|
-
for (var _e = __values(environment.featureStates), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
23
|
-
var fs = _f.value;
|
|
24
|
-
featureStates[fs.feature.id] = fs;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
28
|
-
finally {
|
|
29
|
-
try {
|
|
30
|
-
if (_f && !_f.done && (_a = _e.return)) _a.call(_e);
|
|
31
|
-
}
|
|
32
|
-
finally { if (e_1) throw e_1.error; }
|
|
33
|
-
}
|
|
34
|
-
// Override with any feature states defined by matching segments
|
|
35
|
-
var identitySegments = (0, evaluators_1.getIdentitySegments)(environment, identity, overrideTraits);
|
|
36
|
-
try {
|
|
37
|
-
for (var identitySegments_1 = __values(identitySegments), identitySegments_1_1 = identitySegments_1.next(); !identitySegments_1_1.done; identitySegments_1_1 = identitySegments_1.next()) {
|
|
38
|
-
var matchingSegment = identitySegments_1_1.value;
|
|
39
|
-
try {
|
|
40
|
-
for (var _g = (e_3 = void 0, __values(matchingSegment.featureStates)), _h = _g.next(); !_h.done; _h = _g.next()) {
|
|
41
|
-
var featureState = _h.value;
|
|
42
|
-
// note that feature states are stored on the segment in descending priority
|
|
43
|
-
// order so we only care that the last one is added
|
|
44
|
-
// TODO: can we optimise this?
|
|
45
|
-
featureStates[featureState.feature.id] = featureState;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
49
|
-
finally {
|
|
50
|
-
try {
|
|
51
|
-
if (_h && !_h.done && (_c = _g.return)) _c.call(_g);
|
|
52
|
-
}
|
|
53
|
-
finally { if (e_3) throw e_3.error; }
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
58
|
-
finally {
|
|
59
|
-
try {
|
|
60
|
-
if (identitySegments_1_1 && !identitySegments_1_1.done && (_b = identitySegments_1.return)) _b.call(identitySegments_1);
|
|
61
|
-
}
|
|
62
|
-
finally { if (e_2) throw e_2.error; }
|
|
63
|
-
}
|
|
64
|
-
try {
|
|
65
|
-
// Override with any feature states defined directly the identity
|
|
66
|
-
for (var _j = __values(identity.identityFeatures || []), _k = _j.next(); !_k.done; _k = _j.next()) {
|
|
67
|
-
var fs = _k.value;
|
|
68
|
-
if (featureStates[fs.feature.id]) {
|
|
69
|
-
featureStates[fs.feature.id] = fs;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
74
|
-
finally {
|
|
75
|
-
try {
|
|
76
|
-
if (_k && !_k.done && (_d = _j.return)) _d.call(_j);
|
|
77
|
-
}
|
|
78
|
-
finally { if (e_4) throw e_4.error; }
|
|
79
|
-
}
|
|
80
|
-
return featureStates;
|
|
81
|
-
}
|
|
82
|
-
function getIdentityFeatureState(environment, identity, featureName, overrideTraits) {
|
|
83
|
-
var featureStates = getIdentityFeatureStatesDict(environment, identity, overrideTraits);
|
|
84
|
-
var matchingFeature = Object.values(featureStates).filter(function (f) { return f.feature.name === featureName; });
|
|
85
|
-
if (matchingFeature.length === 0) {
|
|
86
|
-
throw new errors_1.FeatureStateNotFound('Feature State Not Found');
|
|
87
|
-
}
|
|
88
|
-
return matchingFeature[0];
|
|
89
|
-
}
|
|
90
|
-
exports.getIdentityFeatureState = getIdentityFeatureState;
|
|
91
|
-
function getIdentityFeatureStates(environment, identity, overrideTraits) {
|
|
92
|
-
var featureStates = Object.values(getIdentityFeatureStatesDict(environment, identity, overrideTraits));
|
|
93
|
-
if (environment.project.hideDisabledFlags) {
|
|
94
|
-
return featureStates.filter(function (fs) { return !!fs.enabled; });
|
|
95
|
-
}
|
|
96
|
-
return featureStates;
|
|
97
|
-
}
|
|
98
|
-
exports.getIdentityFeatureStates = getIdentityFeatureStates;
|
|
99
|
-
function getEnvironmentFeatureState(environment, featureName) {
|
|
100
|
-
var featuresStates = environment.featureStates.filter(function (f) { return f.feature.name === featureName; });
|
|
101
|
-
if (featuresStates.length === 0) {
|
|
102
|
-
throw new Error('Feature State Not Found');
|
|
103
|
-
}
|
|
104
|
-
return featuresStates[0];
|
|
105
|
-
}
|
|
106
|
-
exports.getEnvironmentFeatureState = getEnvironmentFeatureState;
|
|
107
|
-
function getEnvironmentFeatureStates(environment) {
|
|
108
|
-
if (environment.project.hideDisabledFlags) {
|
|
109
|
-
return environment.featureStates.filter(function (fs) { return !!fs.enabled; });
|
|
110
|
-
}
|
|
111
|
-
return environment.featureStates;
|
|
112
|
-
}
|
|
113
|
-
exports.getEnvironmentFeatureStates = getEnvironmentFeatureStates;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export declare class OrganisationModel {
|
|
2
|
-
id: number;
|
|
3
|
-
name: string;
|
|
4
|
-
featureAnalytics: boolean;
|
|
5
|
-
stopServingFlags: boolean;
|
|
6
|
-
persistTraitData: boolean;
|
|
7
|
-
constructor(id: number, name: string, featureAnalytics: boolean, stopServingFlags: boolean, persistTraitData: boolean);
|
|
8
|
-
get unique_slug(): string;
|
|
9
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.OrganisationModel = void 0;
|
|
4
|
-
var OrganisationModel = /** @class */ (function () {
|
|
5
|
-
function OrganisationModel(id, name, featureAnalytics, stopServingFlags, persistTraitData) {
|
|
6
|
-
this.id = id;
|
|
7
|
-
this.name = name;
|
|
8
|
-
this.featureAnalytics = featureAnalytics;
|
|
9
|
-
this.stopServingFlags = stopServingFlags;
|
|
10
|
-
this.persistTraitData = persistTraitData;
|
|
11
|
-
}
|
|
12
|
-
Object.defineProperty(OrganisationModel.prototype, "unique_slug", {
|
|
13
|
-
get: function () {
|
|
14
|
-
return this.id.toString() + '-' + this.name;
|
|
15
|
-
},
|
|
16
|
-
enumerable: false,
|
|
17
|
-
configurable: true
|
|
18
|
-
});
|
|
19
|
-
return OrganisationModel;
|
|
20
|
-
}());
|
|
21
|
-
exports.OrganisationModel = OrganisationModel;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.buildOrganizationModel = void 0;
|
|
4
|
-
var models_1 = require("./models");
|
|
5
|
-
function buildOrganizationModel(organizationJSON) {
|
|
6
|
-
return new models_1.OrganisationModel(organizationJSON.id, organizationJSON.name, organizationJSON.feature_analytics, organizationJSON.stop_serving_flags, organizationJSON.persist_trait_data);
|
|
7
|
-
}
|
|
8
|
-
exports.buildOrganizationModel = buildOrganizationModel;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { OrganisationModel } from '../organisations/models';
|
|
2
|
-
import { SegmentModel } from '../segments/models';
|
|
3
|
-
export declare class ProjectModel {
|
|
4
|
-
id: number;
|
|
5
|
-
name: string;
|
|
6
|
-
organisation: OrganisationModel;
|
|
7
|
-
hideDisabledFlags: boolean;
|
|
8
|
-
segments: SegmentModel[];
|
|
9
|
-
constructor(id: number, name: string, hideDisabledFlags: boolean, organization: OrganisationModel);
|
|
10
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ProjectModel = void 0;
|
|
4
|
-
var ProjectModel = /** @class */ (function () {
|
|
5
|
-
function ProjectModel(id, name, hideDisabledFlags, organization) {
|
|
6
|
-
this.segments = [];
|
|
7
|
-
this.id = id;
|
|
8
|
-
this.name = name;
|
|
9
|
-
this.hideDisabledFlags = hideDisabledFlags;
|
|
10
|
-
this.organisation = organization;
|
|
11
|
-
}
|
|
12
|
-
return ProjectModel;
|
|
13
|
-
}());
|
|
14
|
-
exports.ProjectModel = ProjectModel;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.buildProjectModel = void 0;
|
|
4
|
-
var util_1 = require("../organisations/util");
|
|
5
|
-
var util_2 = require("../segments/util");
|
|
6
|
-
var models_1 = require("./models");
|
|
7
|
-
function buildProjectModel(projectJSON) {
|
|
8
|
-
var segments = projectJSON['segments']
|
|
9
|
-
? projectJSON['segments'].map(function (s) { return (0, util_2.buildSegmentModel)(s); })
|
|
10
|
-
: [];
|
|
11
|
-
var model = new models_1.ProjectModel(projectJSON.id, projectJSON.name, projectJSON.hide_disabled_flags, (0, util_1.buildOrganizationModel)(projectJSON.organisation));
|
|
12
|
-
model.segments = segments;
|
|
13
|
-
return model;
|
|
14
|
-
}
|
|
15
|
-
exports.buildProjectModel = buildProjectModel;
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
export declare const ALL_RULE = "ALL";
|
|
2
|
-
export declare const ANY_RULE = "ANY";
|
|
3
|
-
export declare const NONE_RULE = "NONE";
|
|
4
|
-
export declare const RULE_TYPES: string[];
|
|
5
|
-
export declare const EQUAL = "EQUAL";
|
|
6
|
-
export declare const GREATER_THAN = "GREATER_THAN";
|
|
7
|
-
export declare const LESS_THAN = "LESS_THAN";
|
|
8
|
-
export declare const LESS_THAN_INCLUSIVE = "LESS_THAN_INCLUSIVE";
|
|
9
|
-
export declare const CONTAINS = "CONTAINS";
|
|
10
|
-
export declare const GREATER_THAN_INCLUSIVE = "GREATER_THAN_INCLUSIVE";
|
|
11
|
-
export declare const NOT_CONTAINS = "NOT_CONTAINS";
|
|
12
|
-
export declare const NOT_EQUAL = "NOT_EQUAL";
|
|
13
|
-
export declare const REGEX = "REGEX";
|
|
14
|
-
export declare const PERCENTAGE_SPLIT = "PERCENTAGE_SPLIT";
|
|
15
|
-
export declare const CONDITION_OPERATORS: {
|
|
16
|
-
EQUAL: string;
|
|
17
|
-
GREATER_THAN: string;
|
|
18
|
-
LESS_THAN: string;
|
|
19
|
-
LESS_THAN_INCLUSIVE: string;
|
|
20
|
-
CONTAINS: string;
|
|
21
|
-
GREATER_THAN_INCLUSIVE: string;
|
|
22
|
-
NOT_CONTAINS: string;
|
|
23
|
-
NOT_EQUAL: string;
|
|
24
|
-
REGEX: string;
|
|
25
|
-
PERCENTAGE_SPLIT: string;
|
|
26
|
-
};
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CONDITION_OPERATORS = exports.PERCENTAGE_SPLIT = exports.REGEX = exports.NOT_EQUAL = exports.NOT_CONTAINS = exports.GREATER_THAN_INCLUSIVE = exports.CONTAINS = exports.LESS_THAN_INCLUSIVE = exports.LESS_THAN = exports.GREATER_THAN = exports.EQUAL = exports.RULE_TYPES = exports.NONE_RULE = exports.ANY_RULE = exports.ALL_RULE = void 0;
|
|
4
|
-
// Segment Rules
|
|
5
|
-
exports.ALL_RULE = 'ALL';
|
|
6
|
-
exports.ANY_RULE = 'ANY';
|
|
7
|
-
exports.NONE_RULE = 'NONE';
|
|
8
|
-
exports.RULE_TYPES = [exports.ALL_RULE, exports.ANY_RULE, exports.NONE_RULE];
|
|
9
|
-
// Segment Condition Operators
|
|
10
|
-
exports.EQUAL = 'EQUAL';
|
|
11
|
-
exports.GREATER_THAN = 'GREATER_THAN';
|
|
12
|
-
exports.LESS_THAN = 'LESS_THAN';
|
|
13
|
-
exports.LESS_THAN_INCLUSIVE = 'LESS_THAN_INCLUSIVE';
|
|
14
|
-
exports.CONTAINS = 'CONTAINS';
|
|
15
|
-
exports.GREATER_THAN_INCLUSIVE = 'GREATER_THAN_INCLUSIVE';
|
|
16
|
-
exports.NOT_CONTAINS = 'NOT_CONTAINS';
|
|
17
|
-
exports.NOT_EQUAL = 'NOT_EQUAL';
|
|
18
|
-
exports.REGEX = 'REGEX';
|
|
19
|
-
exports.PERCENTAGE_SPLIT = 'PERCENTAGE_SPLIT';
|
|
20
|
-
exports.CONDITION_OPERATORS = {
|
|
21
|
-
EQUAL: exports.EQUAL,
|
|
22
|
-
GREATER_THAN: exports.GREATER_THAN,
|
|
23
|
-
LESS_THAN: exports.LESS_THAN,
|
|
24
|
-
LESS_THAN_INCLUSIVE: exports.LESS_THAN_INCLUSIVE,
|
|
25
|
-
CONTAINS: exports.CONTAINS,
|
|
26
|
-
GREATER_THAN_INCLUSIVE: exports.GREATER_THAN_INCLUSIVE,
|
|
27
|
-
NOT_CONTAINS: exports.NOT_CONTAINS,
|
|
28
|
-
NOT_EQUAL: exports.NOT_EQUAL,
|
|
29
|
-
REGEX: exports.REGEX,
|
|
30
|
-
PERCENTAGE_SPLIT: exports.PERCENTAGE_SPLIT
|
|
31
|
-
};
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { EnvironmentModel } from '../environments/models';
|
|
2
|
-
import { IdentityModel } from '../identities/models';
|
|
3
|
-
import { TraitModel } from '../identities/traits/models';
|
|
4
|
-
import { SegmentModel } from './models';
|
|
5
|
-
export declare function getIdentitySegments(environment: EnvironmentModel, identity: IdentityModel, overrideTraits?: TraitModel[]): SegmentModel[];
|
|
6
|
-
export declare function evaluateIdentityInSegment(identity: IdentityModel, segment: SegmentModel, overrideTraits?: TraitModel[]): boolean;
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.evaluateIdentityInSegment = exports.getIdentitySegments = void 0;
|
|
4
|
-
var hashing_1 = require("../utils/hashing");
|
|
5
|
-
var constants_1 = require("./constants");
|
|
6
|
-
function getIdentitySegments(environment, identity, overrideTraits) {
|
|
7
|
-
return environment.project.segments.filter(function (segment) {
|
|
8
|
-
return evaluateIdentityInSegment(identity, segment, overrideTraits);
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
exports.getIdentitySegments = getIdentitySegments;
|
|
12
|
-
function evaluateIdentityInSegment(identity, segment, overrideTraits) {
|
|
13
|
-
return (segment.rules.length > 0 &&
|
|
14
|
-
segment.rules.filter(function (rule) {
|
|
15
|
-
return traitsMatchSegmentRule(overrideTraits || identity.identityTraits, rule, segment.id, identity.compositeKey);
|
|
16
|
-
}).length === segment.rules.length);
|
|
17
|
-
}
|
|
18
|
-
exports.evaluateIdentityInSegment = evaluateIdentityInSegment;
|
|
19
|
-
function traitsMatchSegmentRule(identityTraits, rule, segmentId, identityId) {
|
|
20
|
-
var matchesConditions = rule.conditions.length > 0
|
|
21
|
-
? rule.matchingFunction()(rule.conditions.map(function (condition) {
|
|
22
|
-
return traitsMatchSegmentCondition(identityTraits, condition, segmentId, identityId);
|
|
23
|
-
}))
|
|
24
|
-
: true;
|
|
25
|
-
return (matchesConditions &&
|
|
26
|
-
rule.rules.filter(function (rule) {
|
|
27
|
-
return traitsMatchSegmentRule(identityTraits, rule, segmentId, identityId);
|
|
28
|
-
}).length === rule.rules.length);
|
|
29
|
-
}
|
|
30
|
-
function traitsMatchSegmentCondition(identityTraits, condition, segmentId, identityId) {
|
|
31
|
-
if (condition.operator == constants_1.PERCENTAGE_SPLIT) {
|
|
32
|
-
return (0, hashing_1.getHashedPercentateForObjIds)([segmentId, identityId]) <= parseFloat(condition.value);
|
|
33
|
-
}
|
|
34
|
-
var traits = identityTraits.filter(function (t) { return t.traitKey === condition.property_; });
|
|
35
|
-
var trait = traits.length > 0 ? traits[0] : undefined;
|
|
36
|
-
return trait ? condition.matchesTraitValue(trait.traitValue) : false;
|
|
37
|
-
}
|