flagsmith-nodejs 2.0.0-beta.5 → 2.0.0-beta.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/build/flagsmith-engine/environments/integrations/models.js +7 -4
- package/build/flagsmith-engine/environments/models.js +12 -23
- package/build/flagsmith-engine/environments/util.js +9 -7
- package/build/flagsmith-engine/features/models.js +64 -47
- package/build/flagsmith-engine/features/util.js +5 -5
- package/build/flagsmith-engine/identities/models.js +96 -31
- package/build/flagsmith-engine/identities/traits/models.js +4 -5
- package/build/flagsmith-engine/identities/util.js +33 -9
- package/build/flagsmith-engine/index.js +74 -22
- package/build/flagsmith-engine/organisations/models.js +11 -11
- package/build/flagsmith-engine/organisations/util.js +1 -1
- package/build/flagsmith-engine/projects/models.js +5 -8
- package/build/flagsmith-engine/projects/util.js +6 -6
- package/build/flagsmith-engine/segments/evaluators.js +17 -9
- package/build/flagsmith-engine/segments/models.js +67 -58
- package/build/flagsmith-engine/segments/util.js +10 -8
- package/build/flagsmith-engine/utils/collections.js +90 -9
- package/build/flagsmith-engine/utils/errors.js +22 -2
- package/build/flagsmith-engine/utils/hashing/index.js +11 -8
- package/build/flagsmith-engine/utils/index.js +3 -3
- package/build/index.js +1 -1
- package/build/sdk/analytics.js +72 -29
- package/build/sdk/errors.js +29 -4
- package/build/sdk/index.js +263 -140
- package/build/sdk/models.js +95 -47
- package/build/sdk/polling_manager.js +58 -16
- package/build/sdk/utils.js +67 -18
- package/example/package-lock.json +1 -996
- package/example/server/api/index.js +1 -1
- package/package.json +2 -1
- package/tsconfig.json +2 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.buildOrganizationModel = void 0;
|
|
4
|
-
|
|
4
|
+
var models_1 = require("./models");
|
|
5
5
|
function buildOrganizationModel(organizationJSON) {
|
|
6
6
|
return new models_1.OrganisationModel(organizationJSON.id, organizationJSON.name, organizationJSON.feature_analytics, organizationJSON.stop_serving_flags, organizationJSON.persist_trait_data);
|
|
7
7
|
}
|
|
@@ -1,17 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ProjectModel = void 0;
|
|
4
|
-
|
|
5
|
-
id
|
|
6
|
-
|
|
7
|
-
organisation;
|
|
8
|
-
hideDisabledFlags;
|
|
9
|
-
segments = [];
|
|
10
|
-
constructor(id, name, hideDisabledFlags, organization) {
|
|
4
|
+
var ProjectModel = /** @class */ (function () {
|
|
5
|
+
function ProjectModel(id, name, hideDisabledFlags, organization) {
|
|
6
|
+
this.segments = [];
|
|
11
7
|
this.id = id;
|
|
12
8
|
this.name = name;
|
|
13
9
|
this.hideDisabledFlags = hideDisabledFlags;
|
|
14
10
|
this.organisation = organization;
|
|
15
11
|
}
|
|
16
|
-
|
|
12
|
+
return ProjectModel;
|
|
13
|
+
}());
|
|
17
14
|
exports.ProjectModel = ProjectModel;
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.buildProjectModel = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
var util_1 = require("../organisations/util");
|
|
5
|
+
var util_2 = require("../segments/util");
|
|
6
|
+
var models_1 = require("./models");
|
|
7
7
|
function buildProjectModel(projectJSON) {
|
|
8
|
-
|
|
9
|
-
? projectJSON['segments'].map((s)
|
|
8
|
+
var segments = projectJSON['segments']
|
|
9
|
+
? projectJSON['segments'].map(function (s) { return (0, util_2.buildSegmentModel)(s); })
|
|
10
10
|
: [];
|
|
11
|
-
|
|
11
|
+
var model = new models_1.ProjectModel(projectJSON.id, projectJSON.name, projectJSON.hide_disabled_flags, (0, util_1.buildOrganizationModel)(projectJSON.organisation));
|
|
12
12
|
model.segments = segments;
|
|
13
13
|
return model;
|
|
14
14
|
}
|
|
@@ -1,29 +1,37 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.evaluateIdentityInSegment = exports.getIdentitySegments = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
var hashing_1 = require("../utils/hashing");
|
|
5
|
+
var constants_1 = require("./constants");
|
|
6
6
|
function getIdentitySegments(environment, identity, overrideTraits) {
|
|
7
|
-
return environment.project.segments.filter(
|
|
7
|
+
return environment.project.segments.filter(function (segment) {
|
|
8
|
+
return evaluateIdentityInSegment(identity, segment, overrideTraits);
|
|
9
|
+
});
|
|
8
10
|
}
|
|
9
11
|
exports.getIdentitySegments = getIdentitySegments;
|
|
10
12
|
function evaluateIdentityInSegment(identity, segment, overrideTraits) {
|
|
11
13
|
return (segment.rules.length > 0 &&
|
|
12
|
-
segment.rules.filter(
|
|
14
|
+
segment.rules.filter(function (rule) {
|
|
15
|
+
return traitsMatchSegmentRule(overrideTraits || identity.identityTraits, rule, segment.id, identity.compositeKey);
|
|
16
|
+
}).length === segment.rules.length);
|
|
13
17
|
}
|
|
14
18
|
exports.evaluateIdentityInSegment = evaluateIdentityInSegment;
|
|
15
19
|
function traitsMatchSegmentRule(identityTraits, rule, segmentId, identityId) {
|
|
16
|
-
|
|
17
|
-
? rule.matchingFunction()(rule.conditions.map(
|
|
20
|
+
var matchesConditions = rule.conditions.length > 0
|
|
21
|
+
? rule.matchingFunction()(rule.conditions.map(function (condition) {
|
|
22
|
+
return traitsMatchSegmentCondition(identityTraits, condition, segmentId, identityId);
|
|
23
|
+
}))
|
|
18
24
|
: true;
|
|
19
25
|
return (matchesConditions &&
|
|
20
|
-
rule.rules.filter(
|
|
26
|
+
rule.rules.filter(function (rule) {
|
|
27
|
+
return traitsMatchSegmentRule(identityTraits, rule, segmentId, identityId);
|
|
28
|
+
}).length === rule.rules.length);
|
|
21
29
|
}
|
|
22
30
|
function traitsMatchSegmentCondition(identityTraits, condition, segmentId, identityId) {
|
|
23
31
|
if (condition.operator == constants_1.PERCENTAGE_SPLIT) {
|
|
24
32
|
return (0, hashing_1.getHashedPercentateForObjIds)([segmentId, identityId]) <= parseFloat(condition.value);
|
|
25
33
|
}
|
|
26
|
-
|
|
27
|
-
|
|
34
|
+
var traits = identityTraits.filter(function (t) { return t.traitKey === condition.property_; });
|
|
35
|
+
var trait = traits.length > 0 ? traits[0] : undefined;
|
|
28
36
|
return trait ? condition.matchesTraitValue(trait.traitValue) : false;
|
|
29
37
|
}
|
|
@@ -1,83 +1,92 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var _a;
|
|
2
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
4
|
exports.SegmentModel = exports.SegmentRuleModel = exports.SegmentConditionModel = exports.matchingFunctions = exports.any = exports.all = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
var utils_1 = require("../utils");
|
|
6
|
+
var constants_1 = require("./constants");
|
|
7
|
+
var all = function (iterable) { return iterable.filter(function (e) { return !!e; }).length === iterable.length; };
|
|
7
8
|
exports.all = all;
|
|
8
|
-
|
|
9
|
+
var any = function (iterable) { return iterable.filter(function (e) { return !!e; }).length > 0; };
|
|
9
10
|
exports.any = any;
|
|
10
|
-
exports.matchingFunctions = {
|
|
11
|
-
[constants_1.CONDITION_OPERATORS.EQUAL]
|
|
12
|
-
[constants_1.CONDITION_OPERATORS.GREATER_THAN]
|
|
13
|
-
[constants_1.CONDITION_OPERATORS.GREATER_THAN_INCLUSIVE]
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
[constants_1.CONDITION_OPERATORS.
|
|
17
|
-
[constants_1.CONDITION_OPERATORS.
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
11
|
+
exports.matchingFunctions = (_a = {},
|
|
12
|
+
_a[constants_1.CONDITION_OPERATORS.EQUAL] = function (thisValue, otherValue) { return thisValue == otherValue; },
|
|
13
|
+
_a[constants_1.CONDITION_OPERATORS.GREATER_THAN] = function (thisValue, otherValue) { return otherValue > thisValue; },
|
|
14
|
+
_a[constants_1.CONDITION_OPERATORS.GREATER_THAN_INCLUSIVE] = function (thisValue, otherValue) {
|
|
15
|
+
return otherValue >= thisValue;
|
|
16
|
+
},
|
|
17
|
+
_a[constants_1.CONDITION_OPERATORS.LESS_THAN] = function (thisValue, otherValue) { return thisValue > otherValue; },
|
|
18
|
+
_a[constants_1.CONDITION_OPERATORS.LESS_THAN_INCLUSIVE] = function (thisValue, otherValue) {
|
|
19
|
+
return thisValue >= otherValue;
|
|
20
|
+
},
|
|
21
|
+
_a[constants_1.CONDITION_OPERATORS.NOT_EQUAL] = function (thisValue, otherValue) { return thisValue != otherValue; },
|
|
22
|
+
_a[constants_1.CONDITION_OPERATORS.CONTAINS] = function (thisValue, otherValue) {
|
|
23
|
+
return otherValue.includes(thisValue);
|
|
24
|
+
},
|
|
25
|
+
_a[constants_1.CONDITION_OPERATORS.NOT_CONTAINS] = function (thisValue, otherValue) {
|
|
26
|
+
return !otherValue.includes(thisValue);
|
|
27
|
+
},
|
|
28
|
+
_a);
|
|
29
|
+
var SegmentConditionModel = /** @class */ (function () {
|
|
30
|
+
function SegmentConditionModel(operator, value, property) {
|
|
31
|
+
var _a;
|
|
32
|
+
this.EXCEPTION_OPERATOR_METHODS = (_a = {},
|
|
33
|
+
_a[constants_1.NOT_CONTAINS] = 'evaluateNotContains',
|
|
34
|
+
_a[constants_1.REGEX] = 'evaluateRegex',
|
|
35
|
+
_a);
|
|
29
36
|
this.operator = operator;
|
|
30
37
|
this.value = value;
|
|
31
38
|
this.property_ = property;
|
|
32
39
|
}
|
|
33
|
-
matchesTraitValue(traitValue) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
40
|
+
SegmentConditionModel.prototype.matchesTraitValue = function (traitValue) {
|
|
41
|
+
var _this = this;
|
|
42
|
+
var evaluators = {
|
|
43
|
+
evaluateNotContains: function (traitValue) {
|
|
44
|
+
return !traitValue.includes(_this.value);
|
|
37
45
|
},
|
|
38
|
-
evaluateRegex: (traitValue)
|
|
39
|
-
return !!traitValue.match(new RegExp(
|
|
46
|
+
evaluateRegex: function (traitValue) {
|
|
47
|
+
return !!traitValue.match(new RegExp(_this.value));
|
|
40
48
|
}
|
|
41
49
|
};
|
|
42
50
|
// TODO: move this logic to the evaluator module
|
|
43
51
|
if (this.EXCEPTION_OPERATOR_METHODS[this.operator]) {
|
|
44
|
-
|
|
52
|
+
var evaluatorFunction = evaluators[this.EXCEPTION_OPERATOR_METHODS[this.operator]];
|
|
45
53
|
return evaluatorFunction(traitValue);
|
|
46
54
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
55
|
+
var defaultFunction = function (x, y) { return false; };
|
|
56
|
+
var matchingFunction = exports.matchingFunctions[this.operator] || defaultFunction;
|
|
57
|
+
var castToTypeOfTraitValue = (0, utils_1.getCastingFunction)(traitValue);
|
|
50
58
|
return matchingFunction(castToTypeOfTraitValue(this.value), traitValue);
|
|
51
|
-
}
|
|
52
|
-
|
|
59
|
+
};
|
|
60
|
+
return SegmentConditionModel;
|
|
61
|
+
}());
|
|
53
62
|
exports.SegmentConditionModel = SegmentConditionModel;
|
|
54
|
-
|
|
55
|
-
type
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
constructor(type) {
|
|
63
|
+
var SegmentRuleModel = /** @class */ (function () {
|
|
64
|
+
function SegmentRuleModel(type) {
|
|
65
|
+
this.rules = [];
|
|
66
|
+
this.conditions = [];
|
|
59
67
|
this.type = type;
|
|
60
68
|
}
|
|
61
|
-
|
|
62
|
-
return iterable.filter(e
|
|
63
|
-
}
|
|
64
|
-
matchingFunction() {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
[constants_1.
|
|
68
|
-
[constants_1.
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
}
|
|
69
|
+
SegmentRuleModel.none = function (iterable) {
|
|
70
|
+
return iterable.filter(function (e) { return !!e; }).length === 0;
|
|
71
|
+
};
|
|
72
|
+
SegmentRuleModel.prototype.matchingFunction = function () {
|
|
73
|
+
var _a;
|
|
74
|
+
return (_a = {},
|
|
75
|
+
_a[constants_1.ANY_RULE] = exports.any,
|
|
76
|
+
_a[constants_1.ALL_RULE] = exports.all,
|
|
77
|
+
_a[constants_1.NONE_RULE] = SegmentRuleModel.none,
|
|
78
|
+
_a)[this.type];
|
|
79
|
+
};
|
|
80
|
+
return SegmentRuleModel;
|
|
81
|
+
}());
|
|
72
82
|
exports.SegmentRuleModel = SegmentRuleModel;
|
|
73
|
-
|
|
74
|
-
id
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
featureStates = [];
|
|
78
|
-
constructor(id, name) {
|
|
83
|
+
var SegmentModel = /** @class */ (function () {
|
|
84
|
+
function SegmentModel(id, name) {
|
|
85
|
+
this.rules = [];
|
|
86
|
+
this.featureStates = [];
|
|
79
87
|
this.id = id;
|
|
80
88
|
this.name = name;
|
|
81
89
|
}
|
|
82
|
-
|
|
90
|
+
return SegmentModel;
|
|
91
|
+
}());
|
|
83
92
|
exports.SegmentModel = SegmentModel;
|
|
@@ -1,23 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.buildSegmentModel = exports.buildSegmentRuleModel = exports.buildSegmentConditionModel = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
var util_1 = require("../features/util");
|
|
5
|
+
var models_1 = require("./models");
|
|
6
6
|
function buildSegmentConditionModel(segmentConditionJSON) {
|
|
7
7
|
return new models_1.SegmentConditionModel(segmentConditionJSON.operator, segmentConditionJSON.value, segmentConditionJSON.property_);
|
|
8
8
|
}
|
|
9
9
|
exports.buildSegmentConditionModel = buildSegmentConditionModel;
|
|
10
10
|
function buildSegmentRuleModel(ruleModelJSON) {
|
|
11
|
-
|
|
12
|
-
ruleModel.rules = ruleModelJSON.rules.map((r)
|
|
13
|
-
ruleModel.conditions = ruleModelJSON.conditions.map((c)
|
|
11
|
+
var ruleModel = new models_1.SegmentRuleModel(ruleModelJSON.type);
|
|
12
|
+
ruleModel.rules = ruleModelJSON.rules.map(function (r) { return buildSegmentRuleModel(r); });
|
|
13
|
+
ruleModel.conditions = ruleModelJSON.conditions.map(function (c) { return buildSegmentConditionModel(c); });
|
|
14
14
|
return ruleModel;
|
|
15
15
|
}
|
|
16
16
|
exports.buildSegmentRuleModel = buildSegmentRuleModel;
|
|
17
17
|
function buildSegmentModel(segmentModelJSON) {
|
|
18
|
-
|
|
19
|
-
model.featureStates = segmentModelJSON['feature_states'].map((fs)
|
|
20
|
-
|
|
18
|
+
var model = new models_1.SegmentModel(segmentModelJSON.id, segmentModelJSON.name);
|
|
19
|
+
model.featureStates = segmentModelJSON['feature_states'].map(function (fs) {
|
|
20
|
+
return (0, util_1.buildFeatureStateModel)(fs);
|
|
21
|
+
});
|
|
22
|
+
model.rules = segmentModelJSON['rules'].map(function (r) { return buildSegmentRuleModel(r); });
|
|
21
23
|
return model;
|
|
22
24
|
}
|
|
23
25
|
exports.buildSegmentModel = buildSegmentModel;
|
|
@@ -1,16 +1,97 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
var __values = (this && this.__values) || function(o) {
|
|
18
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
19
|
+
if (m) return m.call(o);
|
|
20
|
+
if (o && typeof o.length === "number") return {
|
|
21
|
+
next: function () {
|
|
22
|
+
if (o && i >= o.length) o = void 0;
|
|
23
|
+
return { value: o && o[i++], done: !o };
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
27
|
+
};
|
|
28
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
29
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
30
|
+
if (!m) return o;
|
|
31
|
+
var i = m.call(o), r, ar = [], e;
|
|
32
|
+
try {
|
|
33
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
34
|
+
}
|
|
35
|
+
catch (error) { e = { error: error }; }
|
|
36
|
+
finally {
|
|
37
|
+
try {
|
|
38
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
39
|
+
}
|
|
40
|
+
finally { if (e) throw e.error; }
|
|
41
|
+
}
|
|
42
|
+
return ar;
|
|
43
|
+
};
|
|
44
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
45
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
46
|
+
if (ar || !(i in from)) {
|
|
47
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
48
|
+
ar[i] = from[i];
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
52
|
+
};
|
|
2
53
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
54
|
exports.IdentityFeaturesList = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
55
|
+
var IdentityFeaturesList = /** @class */ (function (_super) {
|
|
56
|
+
__extends(IdentityFeaturesList, _super);
|
|
57
|
+
function IdentityFeaturesList() {
|
|
58
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
59
|
+
}
|
|
60
|
+
IdentityFeaturesList.prototype.push = function () {
|
|
61
|
+
var e_1, _a, e_2, _b;
|
|
62
|
+
var e = [];
|
|
63
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
64
|
+
e[_i] = arguments[_i];
|
|
65
|
+
}
|
|
66
|
+
try {
|
|
67
|
+
for (var _c = __values(e.entries()), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
68
|
+
var _e = __read(_d.value, 2), _ = _e[0], item = _e[1];
|
|
69
|
+
try {
|
|
70
|
+
for (var _f = (e_2 = void 0, __values(this.entries())), _g = _f.next(); !_g.done; _g = _f.next()) {
|
|
71
|
+
var _h = __read(_g.value, 2), k = _h[0], v = _h[1];
|
|
72
|
+
if (v.djangoID === item.djangoID) {
|
|
73
|
+
throw new Error('feature state for this feature already exists');
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
78
|
+
finally {
|
|
79
|
+
try {
|
|
80
|
+
if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
|
|
81
|
+
}
|
|
82
|
+
finally { if (e_2) throw e_2.error; }
|
|
10
83
|
}
|
|
11
84
|
}
|
|
12
85
|
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
86
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
87
|
+
finally {
|
|
88
|
+
try {
|
|
89
|
+
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
90
|
+
}
|
|
91
|
+
finally { if (e_1) throw e_1.error; }
|
|
92
|
+
}
|
|
93
|
+
return _super.prototype.push.apply(this, __spreadArray([], __read(e), false));
|
|
94
|
+
};
|
|
95
|
+
return IdentityFeaturesList;
|
|
96
|
+
}(Array));
|
|
16
97
|
exports.IdentityFeaturesList = IdentityFeaturesList;
|
|
@@ -1,6 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
2
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
18
|
exports.FeatureStateNotFound = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
19
|
+
var FeatureStateNotFound = /** @class */ (function (_super) {
|
|
20
|
+
__extends(FeatureStateNotFound, _super);
|
|
21
|
+
function FeatureStateNotFound() {
|
|
22
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
23
|
+
}
|
|
24
|
+
return FeatureStateNotFound;
|
|
25
|
+
}(Error));
|
|
6
26
|
exports.FeatureStateNotFound = FeatureStateNotFound;
|
|
@@ -4,9 +4,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.getHashedPercentateForObjIds = void 0;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
var md5_1 = __importDefault(require("md5"));
|
|
8
|
+
var big_integer_1 = __importDefault(require("big-integer"));
|
|
9
|
+
var makeRepeated = function (arr, repeats) {
|
|
10
|
+
return Array.from({ length: repeats }, function () { return arr; }).flat();
|
|
11
|
+
};
|
|
10
12
|
// https://stackoverflow.com/questions/12532871/how-to-convert-a-very-large-hex-number-to-decimal-in-javascript
|
|
11
13
|
function h2d(s) {
|
|
12
14
|
function add(x, y) {
|
|
@@ -41,11 +43,12 @@ function h2d(s) {
|
|
|
41
43
|
* @param {} iterations=1 num times to include each id in the generated string to hash
|
|
42
44
|
* @returns number number between 0 (inclusive) and 100 (exclusive)
|
|
43
45
|
*/
|
|
44
|
-
function getHashedPercentateForObjIds(objectIds, iterations
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
46
|
+
function getHashedPercentateForObjIds(objectIds, iterations) {
|
|
47
|
+
if (iterations === void 0) { iterations = 1; }
|
|
48
|
+
var to_hash = makeRepeated(objectIds, iterations).join(',');
|
|
49
|
+
var hashedValue = (0, md5_1.default)(to_hash);
|
|
50
|
+
var hashedInt = (0, big_integer_1.default)(h2d(hashedValue));
|
|
51
|
+
var value = (hashedInt.mod(9999).toJSNumber() / 9998) * 100;
|
|
49
52
|
if (value === 100) {
|
|
50
53
|
return getHashedPercentateForObjIds(objectIds, iterations + 1);
|
|
51
54
|
}
|
|
@@ -4,11 +4,11 @@ exports.getCastingFunction = void 0;
|
|
|
4
4
|
function getCastingFunction(input) {
|
|
5
5
|
switch (typeof input) {
|
|
6
6
|
case 'boolean':
|
|
7
|
-
return (x)
|
|
7
|
+
return function (x) { return !['False', 'false'].includes(x); };
|
|
8
8
|
case 'number':
|
|
9
|
-
return (x)
|
|
9
|
+
return function (x) { return parseFloat(x); };
|
|
10
10
|
default:
|
|
11
|
-
return (x)
|
|
11
|
+
return function (x) { return String(x); };
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
14
|
exports.getCastingFunction = getCastingFunction;
|
package/build/index.js
CHANGED
|
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.Flagsmith = void 0;
|
|
7
|
-
|
|
7
|
+
var sdk_1 = __importDefault(require("./sdk"));
|
|
8
8
|
var sdk_2 = require("./sdk");
|
|
9
9
|
Object.defineProperty(exports, "Flagsmith", { enumerable: true, get: function () { return sdk_2.Flagsmith; } });
|
|
10
10
|
// export default Flagsmith;
|
package/build/sdk/analytics.js
CHANGED
|
@@ -1,20 +1,51 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (_) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
2
38
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
39
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
40
|
};
|
|
5
41
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
42
|
exports.AnalyticsProcessor = void 0;
|
|
7
|
-
|
|
8
|
-
|
|
43
|
+
var node_fetch_1 = __importDefault(require("node-fetch"));
|
|
44
|
+
var ANALYTICS_ENDPOINT = 'analytics/flags/';
|
|
9
45
|
// Used to control how often we send data(in seconds)
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
analyticsEndpoint;
|
|
14
|
-
environmentKey;
|
|
15
|
-
lastFlushed;
|
|
16
|
-
analyticsData;
|
|
17
|
-
timeout = 3;
|
|
46
|
+
var ANALYTICS_TIMER = 10;
|
|
47
|
+
var delay = function (ms) { return new Promise(function (resolve) { return setTimeout(function () { return resolve(undefined); }, ms); }); };
|
|
48
|
+
var AnalyticsProcessor = /** @class */ (function () {
|
|
18
49
|
/**
|
|
19
50
|
* AnalyticsProcessor is used to track how often individual Flags are evaluated within
|
|
20
51
|
* the Flagsmith SDK. Docs: https://docs.flagsmith.com/advanced-use/flag-analytics.
|
|
@@ -24,7 +55,8 @@ class AnalyticsProcessor {
|
|
|
24
55
|
* @param data.timeout used to tell requests to stop waiting for a response after a
|
|
25
56
|
given number of seconds
|
|
26
57
|
*/
|
|
27
|
-
|
|
58
|
+
function AnalyticsProcessor(data) {
|
|
59
|
+
this.timeout = 3;
|
|
28
60
|
this.analyticsEndpoint = data.baseApiUrl + ANALYTICS_ENDPOINT;
|
|
29
61
|
this.environmentKey = data.environmentKey;
|
|
30
62
|
this.lastFlushed = Date.now();
|
|
@@ -34,27 +66,38 @@ class AnalyticsProcessor {
|
|
|
34
66
|
/**
|
|
35
67
|
* Sends all the collected data to the api asynchronously and resets the timer
|
|
36
68
|
*/
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
return
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
69
|
+
AnalyticsProcessor.prototype.flush = function () {
|
|
70
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
71
|
+
return __generator(this, function (_a) {
|
|
72
|
+
switch (_a.label) {
|
|
73
|
+
case 0:
|
|
74
|
+
if (!Object.keys(this.analyticsData).length) {
|
|
75
|
+
return [2 /*return*/];
|
|
76
|
+
}
|
|
77
|
+
return [4 /*yield*/, (0, node_fetch_1.default)(this.analyticsEndpoint, {
|
|
78
|
+
method: 'POST',
|
|
79
|
+
body: JSON.stringify(this.analyticsData),
|
|
80
|
+
timeout: this.timeout,
|
|
81
|
+
headers: {
|
|
82
|
+
'Content-Type': 'application/json',
|
|
83
|
+
'X-Environment-Key': this.environmentKey
|
|
84
|
+
}
|
|
85
|
+
})];
|
|
86
|
+
case 1:
|
|
87
|
+
_a.sent();
|
|
88
|
+
this.analyticsData = {};
|
|
89
|
+
this.lastFlushed = Date.now();
|
|
90
|
+
return [2 /*return*/];
|
|
91
|
+
}
|
|
92
|
+
});
|
|
49
93
|
});
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
53
|
-
trackFeature(featureId) {
|
|
94
|
+
};
|
|
95
|
+
AnalyticsProcessor.prototype.trackFeature = function (featureId) {
|
|
54
96
|
this.analyticsData[featureId] = (this.analyticsData[featureId] || 0) + 1;
|
|
55
97
|
if (Date.now() - this.lastFlushed > ANALYTICS_TIMER * 1000) {
|
|
56
98
|
this.flush();
|
|
57
99
|
}
|
|
58
|
-
}
|
|
59
|
-
|
|
100
|
+
};
|
|
101
|
+
return AnalyticsProcessor;
|
|
102
|
+
}());
|
|
60
103
|
exports.AnalyticsProcessor = AnalyticsProcessor;
|