flagsmith-nodejs 2.5.1 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/publish.yml +25 -0
- package/examples/README.md +3 -0
- package/flagsmith-engine/identities/models.ts +3 -1
- package/flagsmith-engine/segments/evaluators.ts +4 -3
- package/package.json +1 -1
- package/sdk/index.ts +2 -2
- package/sdk/utils.ts +13 -7
- package/tests/engine/unit/segments/segment_evaluators.test.ts +46 -6
- package/tests/engine/unit/utils/utils.test.ts +0 -1
- package/tests/sdk/flagsmith.test.ts +27 -1
- package/.vscode/launch.json +0 -18
- 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 -37
- package/build/flagsmith-engine/features/models.js +0 -122
- package/build/flagsmith-engine/features/util.d.ts +0 -4
- package/build/flagsmith-engine/features/util.js +0 -27
- 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 -15
- package/build/flagsmith-engine/index.js +0 -129
- 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 -34
- package/build/flagsmith-engine/segments/constants.js +0 -39
- package/build/flagsmith-engine/segments/evaluators.d.ts +0 -7
- package/build/flagsmith-engine/segments/evaluators.js +0 -44
- package/build/flagsmith-engine/segments/models.d.ts +0 -37
- package/build/flagsmith-engine/segments/models.js +0 -144
- package/build/flagsmith-engine/segments/util.d.ts +0 -6
- package/build/flagsmith-engine/segments/util.js +0 -33
- package/build/flagsmith-engine/utils/collections.d.ts +0 -3
- package/build/flagsmith-engine/utils/collections.js +0 -26
- 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 -60
- package/build/flagsmith-engine/utils/index.d.ts +0 -1
- package/build/flagsmith-engine/utils/index.js +0 -17
- package/build/index.d.ts +0 -2
- package/build/index.js +0 -24
- package/build/sdk/analytics.d.ts +0 -31
- package/build/sdk/analytics.js +0 -116
- package/build/sdk/errors.d.ts +0 -4
- package/build/sdk/errors.js +0 -34
- package/build/sdk/index.d.ts +0 -120
- package/build/sdk/index.js +0 -528
- 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 -72
- package/build/sdk/types.d.ts +0 -27
- package/build/sdk/types.js +0 -2
- package/build/sdk/utils.d.ts +0 -12
- package/build/sdk/utils.js +0 -93
- package/examples/api-proxy/.babelrc +0 -3
- package/examples/api-proxy/.eslintrc +0 -8
- package/examples/api-proxy/README.md +0 -12
- package/examples/api-proxy/package-lock.json +0 -10889
- package/examples/api-proxy/package.json +0 -57
- package/examples/api-proxy/src/api/index.js +0 -42
- package/examples/api-proxy/src/index.js +0 -29
- package/examples/basic/.babelrc +0 -3
- package/examples/basic/.eslintrc +0 -8
- package/examples/basic/README.md +0 -10
- package/examples/basic/package-lock.json +0 -10779
- package/examples/basic/package.json +0 -56
- package/examples/basic/src/api/index.js +0 -33
- package/examples/basic/src/index.js +0 -29
- package/examples/caching/.babelrc +0 -3
- package/examples/caching/.eslintrc +0 -8
- package/examples/caching/README.md +0 -9
- package/examples/caching/package-lock.json +0 -6750
- package/examples/caching/package.json +0 -56
- package/examples/caching/src/api/index.js +0 -38
- package/examples/caching/src/index.js +0 -29
- package/examples/custom-fetch-agent/.babelrc +0 -3
- package/examples/custom-fetch-agent/.eslintrc +0 -8
- package/examples/custom-fetch-agent/README.md +0 -12
- package/examples/custom-fetch-agent/package-lock.json +0 -6750
- package/examples/custom-fetch-agent/package.json +0 -56
- package/examples/custom-fetch-agent/src/api/index.js +0 -34
- package/examples/custom-fetch-agent/src/index.js +0 -29
- package/examples/local-evaluation/.babelrc +0 -3
- package/examples/local-evaluation/.eslintrc +0 -8
- package/examples/local-evaluation/README.md +0 -18
- package/examples/local-evaluation/package-lock.json +0 -6668
- package/examples/local-evaluation/package.json +0 -56
- package/examples/local-evaluation/src/api/index.js +0 -39
- package/examples/local-evaluation/src/index.js +0 -29
- package/tests/engine/engine-tests/engine-test-data/data/environment_n9fbf9h3v4fFgH3U3ngWhb.json +0 -12591
- package/tests/engine/engine-tests/engine-test-data/readme.md +0 -30
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
14
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
15
|
-
if (!m) return o;
|
|
16
|
-
var i = m.call(o), r, ar = [], e;
|
|
17
|
-
try {
|
|
18
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
19
|
-
}
|
|
20
|
-
catch (error) { e = { error: error }; }
|
|
21
|
-
finally {
|
|
22
|
-
try {
|
|
23
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
24
|
-
}
|
|
25
|
-
finally { if (e) throw e.error; }
|
|
26
|
-
}
|
|
27
|
-
return ar;
|
|
28
|
-
};
|
|
29
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
30
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
31
|
-
};
|
|
32
|
-
var _a, _b;
|
|
33
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
34
|
-
exports.SegmentModel = exports.SegmentRuleModel = exports.SegmentConditionModel = exports.getMatchingFunctions = exports.semverMatchingFunction = exports.matchingFunctions = exports.any = exports.all = void 0;
|
|
35
|
-
var semver_1 = __importDefault(require("semver"));
|
|
36
|
-
var utils_1 = require("../utils");
|
|
37
|
-
var constants_1 = require("./constants");
|
|
38
|
-
var util_1 = require("./util");
|
|
39
|
-
var all = function (iterable) { return iterable.filter(function (e) { return !!e; }).length === iterable.length; };
|
|
40
|
-
exports.all = all;
|
|
41
|
-
var any = function (iterable) { return iterable.filter(function (e) { return !!e; }).length > 0; };
|
|
42
|
-
exports.any = any;
|
|
43
|
-
exports.matchingFunctions = (_a = {},
|
|
44
|
-
_a[constants_1.CONDITION_OPERATORS.EQUAL] = function (thisValue, otherValue) { return thisValue == otherValue; },
|
|
45
|
-
_a[constants_1.CONDITION_OPERATORS.GREATER_THAN] = function (thisValue, otherValue) { return otherValue > thisValue; },
|
|
46
|
-
_a[constants_1.CONDITION_OPERATORS.GREATER_THAN_INCLUSIVE] = function (thisValue, otherValue) {
|
|
47
|
-
return otherValue >= thisValue;
|
|
48
|
-
},
|
|
49
|
-
_a[constants_1.CONDITION_OPERATORS.LESS_THAN] = function (thisValue, otherValue) { return thisValue > otherValue; },
|
|
50
|
-
_a[constants_1.CONDITION_OPERATORS.LESS_THAN_INCLUSIVE] = function (thisValue, otherValue) {
|
|
51
|
-
return thisValue >= otherValue;
|
|
52
|
-
},
|
|
53
|
-
_a[constants_1.CONDITION_OPERATORS.NOT_EQUAL] = function (thisValue, otherValue) { return thisValue != otherValue; },
|
|
54
|
-
_a[constants_1.CONDITION_OPERATORS.CONTAINS] = function (thisValue, otherValue) {
|
|
55
|
-
return otherValue.includes(thisValue);
|
|
56
|
-
},
|
|
57
|
-
_a);
|
|
58
|
-
exports.semverMatchingFunction = __assign(__assign({}, exports.matchingFunctions), (_b = {}, _b[constants_1.CONDITION_OPERATORS.EQUAL] = function (thisValue, otherValue) { return semver_1.default.eq(thisValue, otherValue); }, _b[constants_1.CONDITION_OPERATORS.GREATER_THAN] = function (thisValue, otherValue) { return semver_1.default.gt(otherValue, thisValue); }, _b[constants_1.CONDITION_OPERATORS.GREATER_THAN_INCLUSIVE] = function (thisValue, otherValue) {
|
|
59
|
-
return semver_1.default.gte(otherValue, thisValue);
|
|
60
|
-
}, _b[constants_1.CONDITION_OPERATORS.LESS_THAN] = function (thisValue, otherValue) { return semver_1.default.gt(thisValue, otherValue); }, _b[constants_1.CONDITION_OPERATORS.LESS_THAN_INCLUSIVE] = function (thisValue, otherValue) {
|
|
61
|
-
return semver_1.default.gte(thisValue, otherValue);
|
|
62
|
-
}, _b));
|
|
63
|
-
var getMatchingFunctions = function (semver) { return (semver ? exports.semverMatchingFunction : exports.matchingFunctions); };
|
|
64
|
-
exports.getMatchingFunctions = getMatchingFunctions;
|
|
65
|
-
var SegmentConditionModel = /** @class */ (function () {
|
|
66
|
-
function SegmentConditionModel(operator, value, property) {
|
|
67
|
-
var _a;
|
|
68
|
-
this.EXCEPTION_OPERATOR_METHODS = (_a = {},
|
|
69
|
-
_a[constants_1.NOT_CONTAINS] = 'evaluateNotContains',
|
|
70
|
-
_a[constants_1.REGEX] = 'evaluateRegex',
|
|
71
|
-
_a[constants_1.MODULO] = 'evaluateModulo',
|
|
72
|
-
_a[constants_1.IN] = 'evaluateIn',
|
|
73
|
-
_a);
|
|
74
|
-
this.operator = operator;
|
|
75
|
-
this.value = value;
|
|
76
|
-
this.property_ = property;
|
|
77
|
-
}
|
|
78
|
-
SegmentConditionModel.prototype.matchesTraitValue = function (traitValue) {
|
|
79
|
-
var _this = this;
|
|
80
|
-
var evaluators = {
|
|
81
|
-
evaluateNotContains: function (traitValue) {
|
|
82
|
-
return !traitValue.includes(_this.value);
|
|
83
|
-
},
|
|
84
|
-
evaluateRegex: function (traitValue) {
|
|
85
|
-
return !!_this.value && !!traitValue.match(new RegExp(_this.value));
|
|
86
|
-
},
|
|
87
|
-
evaluateModulo: function (traitValue) {
|
|
88
|
-
if (isNaN(parseFloat(traitValue)) || !_this.value) {
|
|
89
|
-
return false;
|
|
90
|
-
}
|
|
91
|
-
var parts = (_this.value).split("|");
|
|
92
|
-
var _a = __read([parseFloat(parts[0]), parseFloat(parts[1])], 2), divisor = _a[0], reminder = _a[1];
|
|
93
|
-
return traitValue % divisor === reminder;
|
|
94
|
-
},
|
|
95
|
-
evaluateIn: function (traitValue) {
|
|
96
|
-
var _a;
|
|
97
|
-
return (_a = _this.value) === null || _a === void 0 ? void 0 : _a.split(',').includes(traitValue.toString());
|
|
98
|
-
},
|
|
99
|
-
};
|
|
100
|
-
// TODO: move this logic to the evaluator module
|
|
101
|
-
if (this.EXCEPTION_OPERATOR_METHODS[this.operator]) {
|
|
102
|
-
var evaluatorFunction = evaluators[this.EXCEPTION_OPERATOR_METHODS[this.operator]];
|
|
103
|
-
return evaluatorFunction(traitValue);
|
|
104
|
-
}
|
|
105
|
-
var defaultFunction = function (x, y) { return false; };
|
|
106
|
-
var matchingFunctionSet = (0, exports.getMatchingFunctions)((0, util_1.isSemver)(this.value));
|
|
107
|
-
var matchingFunction = matchingFunctionSet[this.operator] || defaultFunction;
|
|
108
|
-
var traitType = (0, util_1.isSemver)(this.value) ? 'semver' : typeof traitValue;
|
|
109
|
-
var castToTypeOfTraitValue = (0, utils_1.getCastingFunction)(traitType);
|
|
110
|
-
return matchingFunction(castToTypeOfTraitValue(this.value), traitValue);
|
|
111
|
-
};
|
|
112
|
-
return SegmentConditionModel;
|
|
113
|
-
}());
|
|
114
|
-
exports.SegmentConditionModel = SegmentConditionModel;
|
|
115
|
-
var SegmentRuleModel = /** @class */ (function () {
|
|
116
|
-
function SegmentRuleModel(type) {
|
|
117
|
-
this.rules = [];
|
|
118
|
-
this.conditions = [];
|
|
119
|
-
this.type = type;
|
|
120
|
-
}
|
|
121
|
-
SegmentRuleModel.none = function (iterable) {
|
|
122
|
-
return iterable.filter(function (e) { return !!e; }).length === 0;
|
|
123
|
-
};
|
|
124
|
-
SegmentRuleModel.prototype.matchingFunction = function () {
|
|
125
|
-
var _a;
|
|
126
|
-
return (_a = {},
|
|
127
|
-
_a[constants_1.ANY_RULE] = exports.any,
|
|
128
|
-
_a[constants_1.ALL_RULE] = exports.all,
|
|
129
|
-
_a[constants_1.NONE_RULE] = SegmentRuleModel.none,
|
|
130
|
-
_a)[this.type];
|
|
131
|
-
};
|
|
132
|
-
return SegmentRuleModel;
|
|
133
|
-
}());
|
|
134
|
-
exports.SegmentRuleModel = SegmentRuleModel;
|
|
135
|
-
var SegmentModel = /** @class */ (function () {
|
|
136
|
-
function SegmentModel(id, name) {
|
|
137
|
-
this.rules = [];
|
|
138
|
-
this.featureStates = [];
|
|
139
|
-
this.id = id;
|
|
140
|
-
this.name = name;
|
|
141
|
-
}
|
|
142
|
-
return SegmentModel;
|
|
143
|
-
}());
|
|
144
|
-
exports.SegmentModel = SegmentModel;
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { SegmentConditionModel, SegmentModel, SegmentRuleModel } from './models';
|
|
2
|
-
export declare function buildSegmentConditionModel(segmentConditionJSON: any): SegmentConditionModel;
|
|
3
|
-
export declare function buildSegmentRuleModel(ruleModelJSON: any): SegmentRuleModel;
|
|
4
|
-
export declare function buildSegmentModel(segmentModelJSON: any): SegmentModel;
|
|
5
|
-
export declare function isSemver(value: any): boolean;
|
|
6
|
-
export declare function removeSemverSuffix(value: string): string;
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.removeSemverSuffix = exports.isSemver = exports.buildSegmentModel = exports.buildSegmentRuleModel = exports.buildSegmentConditionModel = void 0;
|
|
4
|
-
var util_1 = require("../features/util");
|
|
5
|
-
var models_1 = require("./models");
|
|
6
|
-
function buildSegmentConditionModel(segmentConditionJSON) {
|
|
7
|
-
return new models_1.SegmentConditionModel(segmentConditionJSON.operator, segmentConditionJSON.value, segmentConditionJSON.property_);
|
|
8
|
-
}
|
|
9
|
-
exports.buildSegmentConditionModel = buildSegmentConditionModel;
|
|
10
|
-
function buildSegmentRuleModel(ruleModelJSON) {
|
|
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
|
-
return ruleModel;
|
|
15
|
-
}
|
|
16
|
-
exports.buildSegmentRuleModel = buildSegmentRuleModel;
|
|
17
|
-
function buildSegmentModel(segmentModelJSON) {
|
|
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); });
|
|
23
|
-
return model;
|
|
24
|
-
}
|
|
25
|
-
exports.buildSegmentModel = buildSegmentModel;
|
|
26
|
-
function isSemver(value) {
|
|
27
|
-
return typeof value == 'string' && value.endsWith(':semver');
|
|
28
|
-
}
|
|
29
|
-
exports.isSemver = isSemver;
|
|
30
|
-
function removeSemverSuffix(value) {
|
|
31
|
-
return value.replace(':semver', '');
|
|
32
|
-
}
|
|
33
|
-
exports.removeSemverSuffix = removeSemverSuffix;
|
|
@@ -1,26 +0,0 @@
|
|
|
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
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.IdentityFeaturesList = void 0;
|
|
19
|
-
var IdentityFeaturesList = /** @class */ (function (_super) {
|
|
20
|
-
__extends(IdentityFeaturesList, _super);
|
|
21
|
-
function IdentityFeaturesList() {
|
|
22
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
23
|
-
}
|
|
24
|
-
return IdentityFeaturesList;
|
|
25
|
-
}(Array));
|
|
26
|
-
exports.IdentityFeaturesList = IdentityFeaturesList;
|
|
@@ -1,26 +0,0 @@
|
|
|
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
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.FeatureStateNotFound = void 0;
|
|
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));
|
|
26
|
-
exports.FeatureStateNotFound = FeatureStateNotFound;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Given a list of object ids, get a floating point number between 0 and 1 based on
|
|
3
|
-
* the hash of those ids. This should give the same value every time for any list of ids.
|
|
4
|
-
*
|
|
5
|
-
* @param {Array<any>} objectIds list of object ids to calculate the has for
|
|
6
|
-
* @param {} iterations=1 num times to include each id in the generated string to hash
|
|
7
|
-
* @returns number number between 0 (inclusive) and 100 (exclusive)
|
|
8
|
-
*/
|
|
9
|
-
export declare function getHashedPercentateForObjIds(objectIds: Array<any>, iterations?: number): number;
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.getHashedPercentateForObjIds = void 0;
|
|
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
|
-
};
|
|
12
|
-
// https://stackoverflow.com/questions/12532871/how-to-convert-a-very-large-hex-number-to-decimal-in-javascript
|
|
13
|
-
function h2d(s) {
|
|
14
|
-
function add(x, y) {
|
|
15
|
-
var c = 0, r = [];
|
|
16
|
-
var x = x.split('').map(Number);
|
|
17
|
-
var y = y.split('').map(Number);
|
|
18
|
-
while (x.length || y.length) {
|
|
19
|
-
var s = (x.pop() || 0) + (y.pop() || 0) + c;
|
|
20
|
-
r.unshift(s < 10 ? s : s - 10);
|
|
21
|
-
c = s < 10 ? 0 : 1;
|
|
22
|
-
}
|
|
23
|
-
if (c)
|
|
24
|
-
r.unshift(c);
|
|
25
|
-
return r.join('');
|
|
26
|
-
}
|
|
27
|
-
var dec = '0';
|
|
28
|
-
s.split('').forEach(function (chr) {
|
|
29
|
-
var n = parseInt(chr, 16);
|
|
30
|
-
for (var t = 8; t; t >>= 1) {
|
|
31
|
-
dec = add(dec, dec);
|
|
32
|
-
if (n & t)
|
|
33
|
-
dec = add(dec, '1');
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
return dec;
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Given a list of object ids, get a floating point number between 0 and 1 based on
|
|
40
|
-
* the hash of those ids. This should give the same value every time for any list of ids.
|
|
41
|
-
*
|
|
42
|
-
* @param {Array<any>} objectIds list of object ids to calculate the has for
|
|
43
|
-
* @param {} iterations=1 num times to include each id in the generated string to hash
|
|
44
|
-
* @returns number number between 0 (inclusive) and 100 (exclusive)
|
|
45
|
-
*/
|
|
46
|
-
function getHashedPercentateForObjIds(objectIds, iterations) {
|
|
47
|
-
if (iterations === void 0) { iterations = 1; }
|
|
48
|
-
var toHash = makeRepeated(objectIds, iterations).join(',');
|
|
49
|
-
var hashedValue = (0, md5_1.default)(toHash);
|
|
50
|
-
var hashedInt = (0, big_integer_1.default)(h2d(hashedValue));
|
|
51
|
-
var value = (hashedInt.mod(9999).toJSNumber() / 9998) * 100;
|
|
52
|
-
// we ignore this for it's nearly impossible use case to catch
|
|
53
|
-
/* istanbul ignore next */
|
|
54
|
-
if (value === 100) {
|
|
55
|
-
/* istanbul ignore next */
|
|
56
|
-
return getHashedPercentateForObjIds(objectIds, iterations + 1);
|
|
57
|
-
}
|
|
58
|
-
return value;
|
|
59
|
-
}
|
|
60
|
-
exports.getHashedPercentateForObjIds = getHashedPercentateForObjIds;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function getCastingFunction(traitType: 'boolean' | 'string' | 'number' | 'semver' | any): CallableFunction;
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getCastingFunction = void 0;
|
|
4
|
-
var util_1 = require("../segments/util");
|
|
5
|
-
function getCastingFunction(traitType) {
|
|
6
|
-
switch (traitType) {
|
|
7
|
-
case 'boolean':
|
|
8
|
-
return function (x) { return !['False', 'false'].includes(x); };
|
|
9
|
-
case 'number':
|
|
10
|
-
return function (x) { return parseFloat(x); };
|
|
11
|
-
case 'semver':
|
|
12
|
-
return function (x) { return (0, util_1.removeSemverSuffix)(x); };
|
|
13
|
-
default:
|
|
14
|
-
return function (x) { return String(x); };
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
exports.getCastingFunction = getCastingFunction;
|
package/build/index.d.ts
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
export { AnalyticsProcessor, FlagsmithAPIError, FlagsmithClientError, EnvironmentDataPollingManager, FlagsmithCache, DefaultFlag, Flags, default } from './sdk';
|
|
2
|
-
export { EnvironmentModel, IntegrationModel, FeatureStateModel, IdentityModel, TraitModel, SegmentModel, OrganisationModel } from './flagsmith-engine';
|
package/build/index.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.OrganisationModel = exports.SegmentModel = exports.TraitModel = exports.IdentityModel = exports.FeatureStateModel = exports.IntegrationModel = exports.EnvironmentModel = exports.default = exports.Flags = exports.DefaultFlag = exports.EnvironmentDataPollingManager = exports.FlagsmithClientError = exports.FlagsmithAPIError = exports.AnalyticsProcessor = void 0;
|
|
7
|
-
var sdk_1 = __importDefault(require("./sdk"));
|
|
8
|
-
var sdk_2 = require("./sdk");
|
|
9
|
-
Object.defineProperty(exports, "AnalyticsProcessor", { enumerable: true, get: function () { return sdk_2.AnalyticsProcessor; } });
|
|
10
|
-
Object.defineProperty(exports, "FlagsmithAPIError", { enumerable: true, get: function () { return sdk_2.FlagsmithAPIError; } });
|
|
11
|
-
Object.defineProperty(exports, "FlagsmithClientError", { enumerable: true, get: function () { return sdk_2.FlagsmithClientError; } });
|
|
12
|
-
Object.defineProperty(exports, "EnvironmentDataPollingManager", { enumerable: true, get: function () { return sdk_2.EnvironmentDataPollingManager; } });
|
|
13
|
-
Object.defineProperty(exports, "DefaultFlag", { enumerable: true, get: function () { return sdk_2.DefaultFlag; } });
|
|
14
|
-
Object.defineProperty(exports, "Flags", { enumerable: true, get: function () { return sdk_2.Flags; } });
|
|
15
|
-
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return __importDefault(sdk_2).default; } });
|
|
16
|
-
var flagsmith_engine_1 = require("./flagsmith-engine");
|
|
17
|
-
Object.defineProperty(exports, "EnvironmentModel", { enumerable: true, get: function () { return flagsmith_engine_1.EnvironmentModel; } });
|
|
18
|
-
Object.defineProperty(exports, "IntegrationModel", { enumerable: true, get: function () { return flagsmith_engine_1.IntegrationModel; } });
|
|
19
|
-
Object.defineProperty(exports, "FeatureStateModel", { enumerable: true, get: function () { return flagsmith_engine_1.FeatureStateModel; } });
|
|
20
|
-
Object.defineProperty(exports, "IdentityModel", { enumerable: true, get: function () { return flagsmith_engine_1.IdentityModel; } });
|
|
21
|
-
Object.defineProperty(exports, "TraitModel", { enumerable: true, get: function () { return flagsmith_engine_1.TraitModel; } });
|
|
22
|
-
Object.defineProperty(exports, "SegmentModel", { enumerable: true, get: function () { return flagsmith_engine_1.SegmentModel; } });
|
|
23
|
-
Object.defineProperty(exports, "OrganisationModel", { enumerable: true, get: function () { return flagsmith_engine_1.OrganisationModel; } });
|
|
24
|
-
module.exports = sdk_1.default;
|
package/build/sdk/analytics.d.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { Logger } from 'pino';
|
|
2
|
-
export declare class AnalyticsProcessor {
|
|
3
|
-
private analyticsEndpoint;
|
|
4
|
-
private environmentKey;
|
|
5
|
-
private lastFlushed;
|
|
6
|
-
analyticsData: {
|
|
7
|
-
[key: string]: any;
|
|
8
|
-
};
|
|
9
|
-
private requestTimeoutMs;
|
|
10
|
-
private logger;
|
|
11
|
-
/**
|
|
12
|
-
* AnalyticsProcessor is used to track how often individual Flags are evaluated within
|
|
13
|
-
* the Flagsmith SDK. Docs: https://docs.flagsmith.com/advanced-use/flag-analytics.
|
|
14
|
-
*
|
|
15
|
-
* @param data.environmentKey environment key obtained from the Flagsmith UI
|
|
16
|
-
* @param data.baseApiUrl base api url to override when using self hosted version
|
|
17
|
-
* @param data.requestTimeoutMs used to tell requests to stop waiting for a response after a
|
|
18
|
-
given number of milliseconds
|
|
19
|
-
*/
|
|
20
|
-
constructor(data: {
|
|
21
|
-
environmentKey: string;
|
|
22
|
-
baseApiUrl: string;
|
|
23
|
-
requestTimeoutMs?: number;
|
|
24
|
-
logger?: Logger;
|
|
25
|
-
});
|
|
26
|
-
/**
|
|
27
|
-
* Sends all the collected data to the api asynchronously and resets the timer
|
|
28
|
-
*/
|
|
29
|
-
flush(): Promise<void>;
|
|
30
|
-
trackFeature(featureName: string): void;
|
|
31
|
-
}
|
package/build/sdk/analytics.js
DELETED
|
@@ -1,116 +0,0 @@
|
|
|
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
|
-
};
|
|
38
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
-
};
|
|
41
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
-
exports.AnalyticsProcessor = void 0;
|
|
43
|
-
var node_fetch_1 = __importDefault(require("node-fetch"));
|
|
44
|
-
var pino_1 = __importDefault(require("pino"));
|
|
45
|
-
var ANALYTICS_ENDPOINT = 'analytics/flags/';
|
|
46
|
-
// Used to control how often we send data(in seconds)
|
|
47
|
-
var ANALYTICS_TIMER = 10;
|
|
48
|
-
var AnalyticsProcessor = /** @class */ (function () {
|
|
49
|
-
/**
|
|
50
|
-
* AnalyticsProcessor is used to track how often individual Flags are evaluated within
|
|
51
|
-
* the Flagsmith SDK. Docs: https://docs.flagsmith.com/advanced-use/flag-analytics.
|
|
52
|
-
*
|
|
53
|
-
* @param data.environmentKey environment key obtained from the Flagsmith UI
|
|
54
|
-
* @param data.baseApiUrl base api url to override when using self hosted version
|
|
55
|
-
* @param data.requestTimeoutMs used to tell requests to stop waiting for a response after a
|
|
56
|
-
given number of milliseconds
|
|
57
|
-
*/
|
|
58
|
-
function AnalyticsProcessor(data) {
|
|
59
|
-
this.requestTimeoutMs = 3000;
|
|
60
|
-
this.analyticsEndpoint = data.baseApiUrl + ANALYTICS_ENDPOINT;
|
|
61
|
-
this.environmentKey = data.environmentKey;
|
|
62
|
-
this.lastFlushed = Date.now();
|
|
63
|
-
this.analyticsData = {};
|
|
64
|
-
this.requestTimeoutMs = data.requestTimeoutMs || this.requestTimeoutMs;
|
|
65
|
-
this.logger = data.logger || (0, pino_1.default)();
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Sends all the collected data to the api asynchronously and resets the timer
|
|
69
|
-
*/
|
|
70
|
-
AnalyticsProcessor.prototype.flush = function () {
|
|
71
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
72
|
-
var error_1;
|
|
73
|
-
return __generator(this, function (_a) {
|
|
74
|
-
switch (_a.label) {
|
|
75
|
-
case 0:
|
|
76
|
-
if (!Object.keys(this.analyticsData).length) {
|
|
77
|
-
return [2 /*return*/];
|
|
78
|
-
}
|
|
79
|
-
_a.label = 1;
|
|
80
|
-
case 1:
|
|
81
|
-
_a.trys.push([1, 3, , 4]);
|
|
82
|
-
return [4 /*yield*/, (0, node_fetch_1.default)(this.analyticsEndpoint, {
|
|
83
|
-
method: 'POST',
|
|
84
|
-
body: JSON.stringify(this.analyticsData),
|
|
85
|
-
timeout: this.requestTimeoutMs,
|
|
86
|
-
headers: {
|
|
87
|
-
'Content-Type': 'application/json',
|
|
88
|
-
'X-Environment-Key': this.environmentKey
|
|
89
|
-
}
|
|
90
|
-
})];
|
|
91
|
-
case 2:
|
|
92
|
-
_a.sent();
|
|
93
|
-
return [3 /*break*/, 4];
|
|
94
|
-
case 3:
|
|
95
|
-
error_1 = _a.sent();
|
|
96
|
-
// We don't want failing to write analytics to cause any exceptions in the main
|
|
97
|
-
// thread so we just swallow them here.
|
|
98
|
-
this.logger.warn('Failed to post analytics to Flagsmith API. Not clearing data, will retry.');
|
|
99
|
-
return [2 /*return*/];
|
|
100
|
-
case 4:
|
|
101
|
-
this.analyticsData = {};
|
|
102
|
-
this.lastFlushed = Date.now();
|
|
103
|
-
return [2 /*return*/];
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
});
|
|
107
|
-
};
|
|
108
|
-
AnalyticsProcessor.prototype.trackFeature = function (featureName) {
|
|
109
|
-
this.analyticsData[featureName] = (this.analyticsData[featureName] || 0) + 1;
|
|
110
|
-
if (Date.now() - this.lastFlushed > ANALYTICS_TIMER * 1000) {
|
|
111
|
-
this.flush();
|
|
112
|
-
}
|
|
113
|
-
};
|
|
114
|
-
return AnalyticsProcessor;
|
|
115
|
-
}());
|
|
116
|
-
exports.AnalyticsProcessor = AnalyticsProcessor;
|
package/build/sdk/errors.d.ts
DELETED
package/build/sdk/errors.js
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
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
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.FlagsmithAPIError = exports.FlagsmithClientError = void 0;
|
|
19
|
-
var FlagsmithClientError = /** @class */ (function (_super) {
|
|
20
|
-
__extends(FlagsmithClientError, _super);
|
|
21
|
-
function FlagsmithClientError() {
|
|
22
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
23
|
-
}
|
|
24
|
-
return FlagsmithClientError;
|
|
25
|
-
}(Error));
|
|
26
|
-
exports.FlagsmithClientError = FlagsmithClientError;
|
|
27
|
-
var FlagsmithAPIError = /** @class */ (function (_super) {
|
|
28
|
-
__extends(FlagsmithAPIError, _super);
|
|
29
|
-
function FlagsmithAPIError() {
|
|
30
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
31
|
-
}
|
|
32
|
-
return FlagsmithAPIError;
|
|
33
|
-
}(Error));
|
|
34
|
-
exports.FlagsmithAPIError = FlagsmithAPIError;
|