flagsmith-nodejs 3.3.3 → 4.0.0-beta.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/publish.yml +2 -2
- package/.github/workflows/pull_request.yaml +3 -4
- package/build/{flagsmith-engine → cjs/flagsmith-engine}/environments/models.d.ts +3 -3
- package/build/{flagsmith-engine → cjs/flagsmith-engine}/environments/models.js +20 -13
- package/build/{flagsmith-engine → cjs/flagsmith-engine}/environments/util.d.ts +1 -1
- package/build/cjs/flagsmith-engine/environments/util.js +23 -0
- package/build/cjs/flagsmith-engine/features/models.js +118 -0
- package/build/{flagsmith-engine → cjs/flagsmith-engine}/features/util.d.ts +1 -1
- package/build/cjs/flagsmith-engine/features/util.js +27 -0
- package/build/{flagsmith-engine → cjs/flagsmith-engine}/identities/models.d.ts +2 -2
- package/build/cjs/flagsmith-engine/identities/models.js +48 -0
- package/build/{flagsmith-engine → cjs/flagsmith-engine}/identities/traits/models.js +5 -4
- package/build/{flagsmith-engine → cjs/flagsmith-engine}/identities/util.d.ts +2 -2
- package/build/cjs/flagsmith-engine/identities/util.js +22 -0
- package/build/cjs/flagsmith-engine/index.d.ts +14 -0
- package/build/cjs/flagsmith-engine/index.js +75 -0
- package/build/cjs/flagsmith-engine/organisations/models.js +21 -0
- package/build/{flagsmith-engine → cjs/flagsmith-engine}/organisations/util.d.ts +1 -1
- package/build/cjs/flagsmith-engine/organisations/util.js +8 -0
- package/build/{flagsmith-engine → cjs/flagsmith-engine}/projects/models.d.ts +2 -2
- package/build/{flagsmith-engine → cjs/flagsmith-engine}/projects/models.js +8 -5
- package/build/{flagsmith-engine → cjs/flagsmith-engine}/projects/util.d.ts +1 -1
- package/build/cjs/flagsmith-engine/projects/util.js +15 -0
- package/build/{flagsmith-engine → cjs/flagsmith-engine}/segments/evaluators.d.ts +4 -4
- package/build/cjs/flagsmith-engine/segments/evaluators.js +37 -0
- package/build/{flagsmith-engine → cjs/flagsmith-engine}/segments/models.d.ts +1 -1
- package/build/cjs/flagsmith-engine/segments/models.js +114 -0
- package/build/{flagsmith-engine → cjs/flagsmith-engine}/segments/util.d.ts +1 -1
- package/build/{flagsmith-engine → cjs/flagsmith-engine}/segments/util.js +9 -11
- package/build/{flagsmith-engine → cjs/flagsmith-engine}/utils/collections.d.ts +1 -1
- package/build/cjs/flagsmith-engine/utils/collections.js +6 -0
- package/build/cjs/flagsmith-engine/utils/errors.js +6 -0
- package/build/{flagsmith-engine → cjs/flagsmith-engine}/utils/hashing/index.js +8 -11
- package/build/{flagsmith-engine → cjs/flagsmith-engine}/utils/index.js +5 -5
- package/build/{index.d.ts → cjs/index.d.ts} +3 -3
- package/build/{index.js → cjs/index.js} +17 -17
- package/build/cjs/package.json +1 -0
- package/build/{sdk → cjs/sdk}/analytics.d.ts +3 -0
- package/build/cjs/sdk/analytics.js +73 -0
- package/build/cjs/sdk/errors.js +9 -0
- package/build/{sdk → cjs/sdk}/index.d.ts +19 -18
- package/build/cjs/sdk/index.js +400 -0
- package/build/{sdk → cjs/sdk}/models.d.ts +2 -2
- package/build/cjs/sdk/models.js +101 -0
- package/build/{sdk → cjs/sdk}/offline_handlers.d.ts +1 -1
- package/build/cjs/sdk/offline_handlers.js +46 -0
- package/build/{sdk → cjs/sdk}/polling_manager.d.ts +1 -1
- package/build/cjs/sdk/polling_manager.js +29 -0
- package/build/{sdk → cjs/sdk}/types.d.ts +15 -7
- package/build/cjs/sdk/utils.d.ts +36 -0
- package/build/cjs/sdk/utils.js +63 -0
- package/build/esm/flagsmith-engine/environments/models.d.ts +22 -0
- package/build/esm/flagsmith-engine/environments/models.js +32 -0
- package/build/esm/flagsmith-engine/environments/util.d.ts +3 -0
- package/build/esm/flagsmith-engine/environments/util.js +18 -0
- package/build/esm/flagsmith-engine/features/constants.d.ts +4 -0
- package/build/esm/flagsmith-engine/features/constants.js +4 -0
- package/build/esm/flagsmith-engine/features/models.d.ts +37 -0
- package/build/esm/flagsmith-engine/features/models.js +110 -0
- package/build/esm/flagsmith-engine/features/util.d.ts +4 -0
- package/build/esm/flagsmith-engine/features/util.js +21 -0
- package/build/esm/flagsmith-engine/identities/models.d.ts +15 -0
- package/build/esm/flagsmith-engine/identities/models.js +44 -0
- package/build/esm/flagsmith-engine/identities/traits/models.d.ts +5 -0
- package/build/esm/flagsmith-engine/identities/traits/models.js +8 -0
- package/build/esm/flagsmith-engine/identities/util.d.ts +4 -0
- package/build/esm/flagsmith-engine/identities/util.js +17 -0
- package/build/esm/flagsmith-engine/index.d.ts +14 -0
- package/build/esm/flagsmith-engine/index.js +62 -0
- package/build/esm/flagsmith-engine/organisations/models.d.ts +9 -0
- package/build/esm/flagsmith-engine/organisations/models.js +17 -0
- package/build/esm/flagsmith-engine/organisations/util.d.ts +2 -0
- package/build/esm/flagsmith-engine/organisations/util.js +4 -0
- package/build/esm/flagsmith-engine/projects/models.d.ts +10 -0
- package/build/esm/flagsmith-engine/projects/models.js +13 -0
- package/build/esm/flagsmith-engine/projects/util.d.ts +2 -0
- package/build/esm/flagsmith-engine/projects/util.js +11 -0
- package/build/esm/flagsmith-engine/segments/constants.d.ts +34 -0
- package/build/esm/flagsmith-engine/segments/constants.js +36 -0
- package/build/esm/flagsmith-engine/segments/evaluators.d.ts +7 -0
- package/build/esm/flagsmith-engine/segments/evaluators.js +31 -0
- package/build/esm/flagsmith-engine/segments/models.d.ts +37 -0
- package/build/esm/flagsmith-engine/segments/models.js +102 -0
- package/build/esm/flagsmith-engine/segments/util.d.ts +6 -0
- package/build/esm/flagsmith-engine/segments/util.js +23 -0
- package/build/esm/flagsmith-engine/utils/collections.d.ts +3 -0
- package/build/esm/flagsmith-engine/utils/collections.js +2 -0
- package/build/esm/flagsmith-engine/utils/errors.d.ts +2 -0
- package/build/esm/flagsmith-engine/utils/errors.js +2 -0
- package/build/esm/flagsmith-engine/utils/hashing/index.d.ts +9 -0
- package/build/esm/flagsmith-engine/utils/hashing/index.js +50 -0
- package/build/esm/flagsmith-engine/utils/index.d.ts +1 -0
- package/build/esm/flagsmith-engine/utils/index.js +13 -0
- package/build/esm/index.d.ts +3 -0
- package/build/esm/index.js +4 -0
- package/build/esm/sdk/analytics.d.ts +35 -0
- package/build/esm/sdk/analytics.js +69 -0
- package/build/esm/sdk/errors.d.ts +4 -0
- package/build/esm/sdk/errors.js +4 -0
- package/build/esm/sdk/index.d.ts +131 -0
- package/build/esm/sdk/index.js +390 -0
- package/build/esm/sdk/models.d.ts +55 -0
- package/build/esm/sdk/models.js +94 -0
- package/build/esm/sdk/offline_handlers.d.ts +9 -0
- package/build/esm/sdk/offline_handlers.js +18 -0
- package/build/esm/sdk/polling_manager.d.ts +9 -0
- package/build/esm/sdk/polling_manager.js +25 -0
- package/build/esm/sdk/types.d.ts +38 -0
- package/build/esm/sdk/types.js +1 -0
- package/build/esm/sdk/utils.d.ts +36 -0
- package/build/esm/sdk/utils.js +56 -0
- package/flagsmith-engine/environments/models.ts +3 -3
- package/flagsmith-engine/environments/util.ts +4 -4
- package/flagsmith-engine/features/models.ts +1 -1
- package/flagsmith-engine/features/util.ts +1 -1
- package/flagsmith-engine/identities/models.ts +3 -4
- package/flagsmith-engine/identities/traits/models.ts +0 -1
- package/flagsmith-engine/identities/util.ts +4 -4
- package/flagsmith-engine/index.ts +13 -13
- package/flagsmith-engine/organisations/util.ts +1 -1
- package/flagsmith-engine/projects/models.ts +2 -2
- package/flagsmith-engine/projects/util.ts +4 -4
- package/flagsmith-engine/segments/evaluators.ts +6 -6
- package/flagsmith-engine/segments/models.ts +4 -4
- package/flagsmith-engine/segments/util.ts +3 -3
- package/flagsmith-engine/utils/collections.ts +1 -1
- package/flagsmith-engine/utils/index.ts +1 -1
- package/index.ts +4 -4
- package/package.json +21 -9
- package/sdk/analytics.ts +7 -5
- package/sdk/index.ts +55 -46
- package/sdk/models.ts +2 -3
- package/sdk/offline_handlers.ts +2 -2
- package/sdk/polling_manager.ts +2 -3
- package/sdk/types.ts +35 -24
- package/sdk/utils.ts +49 -37
- package/tests/engine/e2e/engine.test.ts +5 -5
- package/tests/engine/unit/engine.test.ts +5 -5
- package/tests/engine/unit/segments/segment_evaluators.test.ts +9 -9
- package/tests/engine/unit/utils/utils.test.ts +1 -1
- package/tests/sdk/analytics.test.ts +8 -13
- package/tests/sdk/data/identity-with-transient-traits.json +41 -0
- package/tests/sdk/data/transient-identity.json +29 -0
- package/tests/sdk/flagsmith-cache.test.ts +16 -32
- package/tests/sdk/flagsmith-environment-flags.test.ts +21 -36
- package/tests/sdk/flagsmith-identity-flags.test.ts +83 -32
- package/tests/sdk/flagsmith.test.ts +67 -99
- package/tests/sdk/offline-handlers.test.ts +4 -5
- package/tests/sdk/polling.test.ts +6 -8
- package/tests/sdk/utils.ts +19 -15
- package/tsconfig.cjs.json +7 -0
- package/tsconfig.esm.json +7 -0
- package/tsconfig.json +7 -3
- package/vitest.config.ts +17 -0
- package/build/flagsmith-engine/environments/util.js +0 -27
- package/build/flagsmith-engine/features/models.js +0 -132
- package/build/flagsmith-engine/features/util.js +0 -27
- package/build/flagsmith-engine/identities/models.js +0 -113
- package/build/flagsmith-engine/identities/util.js +0 -46
- package/build/flagsmith-engine/index.d.ts +0 -14
- package/build/flagsmith-engine/index.js +0 -127
- package/build/flagsmith-engine/organisations/models.js +0 -21
- package/build/flagsmith-engine/organisations/util.js +0 -8
- package/build/flagsmith-engine/projects/util.js +0 -15
- package/build/flagsmith-engine/segments/evaluators.js +0 -45
- package/build/flagsmith-engine/segments/models.js +0 -147
- package/build/flagsmith-engine/utils/collections.js +0 -26
- package/build/flagsmith-engine/utils/errors.js +0 -26
- package/build/sdk/analytics.js +0 -120
- package/build/sdk/errors.js +0 -34
- package/build/sdk/index.js +0 -594
- package/build/sdk/models.js +0 -149
- package/build/sdk/offline_handlers.js +0 -66
- package/build/sdk/polling_manager.js +0 -72
- package/build/sdk/utils.d.ts +0 -12
- package/build/sdk/utils.js +0 -107
- package/jest.config.js +0 -5
- package/tests/index.js +0 -0
- /package/build/{flagsmith-engine → cjs/flagsmith-engine}/features/constants.d.ts +0 -0
- /package/build/{flagsmith-engine → cjs/flagsmith-engine}/features/constants.js +0 -0
- /package/build/{flagsmith-engine → cjs/flagsmith-engine}/features/models.d.ts +0 -0
- /package/build/{flagsmith-engine → cjs/flagsmith-engine}/identities/traits/models.d.ts +0 -0
- /package/build/{flagsmith-engine → cjs/flagsmith-engine}/organisations/models.d.ts +0 -0
- /package/build/{flagsmith-engine → cjs/flagsmith-engine}/segments/constants.d.ts +0 -0
- /package/build/{flagsmith-engine → cjs/flagsmith-engine}/segments/constants.js +0 -0
- /package/build/{flagsmith-engine → cjs/flagsmith-engine}/utils/errors.d.ts +0 -0
- /package/build/{flagsmith-engine → cjs/flagsmith-engine}/utils/hashing/index.d.ts +0 -0
- /package/build/{flagsmith-engine → cjs/flagsmith-engine}/utils/index.d.ts +0 -0
- /package/build/{sdk → cjs/sdk}/errors.d.ts +0 -0
- /package/build/{sdk → cjs/sdk}/types.js +0 -0
|
@@ -1,147 +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 && 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
|
-
var _a;
|
|
83
|
-
return typeof traitValue == "string" &&
|
|
84
|
-
!!_this.value &&
|
|
85
|
-
!traitValue.includes((_a = _this.value) === null || _a === void 0 ? void 0 : _a.toString());
|
|
86
|
-
},
|
|
87
|
-
evaluateRegex: function (traitValue) {
|
|
88
|
-
return !!_this.value && !!(traitValue === null || traitValue === void 0 ? void 0 : traitValue.toString().match(new RegExp(_this.value)));
|
|
89
|
-
},
|
|
90
|
-
evaluateModulo: function (traitValue) {
|
|
91
|
-
if (isNaN(parseFloat(traitValue)) || !_this.value) {
|
|
92
|
-
return false;
|
|
93
|
-
}
|
|
94
|
-
var parts = (_this.value).split("|");
|
|
95
|
-
var _a = __read([parseFloat(parts[0]), parseFloat(parts[1])], 2), divisor = _a[0], reminder = _a[1];
|
|
96
|
-
return traitValue % divisor === reminder;
|
|
97
|
-
},
|
|
98
|
-
evaluateIn: function (traitValue) {
|
|
99
|
-
var _a;
|
|
100
|
-
return (_a = _this.value) === null || _a === void 0 ? void 0 : _a.split(',').includes(traitValue.toString());
|
|
101
|
-
},
|
|
102
|
-
};
|
|
103
|
-
// TODO: move this logic to the evaluator module
|
|
104
|
-
if (this.EXCEPTION_OPERATOR_METHODS[this.operator]) {
|
|
105
|
-
var evaluatorFunction = evaluators[this.EXCEPTION_OPERATOR_METHODS[this.operator]];
|
|
106
|
-
return evaluatorFunction(traitValue);
|
|
107
|
-
}
|
|
108
|
-
var defaultFunction = function (x, y) { return false; };
|
|
109
|
-
var matchingFunctionSet = (0, exports.getMatchingFunctions)((0, util_1.isSemver)(this.value));
|
|
110
|
-
var matchingFunction = matchingFunctionSet[this.operator] || defaultFunction;
|
|
111
|
-
var traitType = (0, util_1.isSemver)(this.value) ? 'semver' : typeof traitValue;
|
|
112
|
-
var castToTypeOfTraitValue = (0, utils_1.getCastingFunction)(traitType);
|
|
113
|
-
return matchingFunction(castToTypeOfTraitValue(this.value), traitValue);
|
|
114
|
-
};
|
|
115
|
-
return SegmentConditionModel;
|
|
116
|
-
}());
|
|
117
|
-
exports.SegmentConditionModel = SegmentConditionModel;
|
|
118
|
-
var SegmentRuleModel = /** @class */ (function () {
|
|
119
|
-
function SegmentRuleModel(type) {
|
|
120
|
-
this.rules = [];
|
|
121
|
-
this.conditions = [];
|
|
122
|
-
this.type = type;
|
|
123
|
-
}
|
|
124
|
-
SegmentRuleModel.none = function (iterable) {
|
|
125
|
-
return iterable.filter(function (e) { return !!e; }).length === 0;
|
|
126
|
-
};
|
|
127
|
-
SegmentRuleModel.prototype.matchingFunction = function () {
|
|
128
|
-
var _a;
|
|
129
|
-
return (_a = {},
|
|
130
|
-
_a[constants_1.ANY_RULE] = exports.any,
|
|
131
|
-
_a[constants_1.ALL_RULE] = exports.all,
|
|
132
|
-
_a[constants_1.NONE_RULE] = SegmentRuleModel.none,
|
|
133
|
-
_a)[this.type];
|
|
134
|
-
};
|
|
135
|
-
return SegmentRuleModel;
|
|
136
|
-
}());
|
|
137
|
-
exports.SegmentRuleModel = SegmentRuleModel;
|
|
138
|
-
var SegmentModel = /** @class */ (function () {
|
|
139
|
-
function SegmentModel(id, name) {
|
|
140
|
-
this.rules = [];
|
|
141
|
-
this.featureStates = [];
|
|
142
|
-
this.id = id;
|
|
143
|
-
this.name = name;
|
|
144
|
-
}
|
|
145
|
-
return SegmentModel;
|
|
146
|
-
}());
|
|
147
|
-
exports.SegmentModel = SegmentModel;
|
|
@@ -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;
|
package/build/sdk/analytics.js
DELETED
|
@@ -1,120 +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 (this.currentFlush || !Object.keys(this.analyticsData).length) {
|
|
77
|
-
return [2 /*return*/];
|
|
78
|
-
}
|
|
79
|
-
_a.label = 1;
|
|
80
|
-
case 1:
|
|
81
|
-
_a.trys.push([1, 3, 4, 5]);
|
|
82
|
-
this.currentFlush = (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
|
-
return [4 /*yield*/, this.currentFlush];
|
|
92
|
-
case 2:
|
|
93
|
-
_a.sent();
|
|
94
|
-
return [3 /*break*/, 5];
|
|
95
|
-
case 3:
|
|
96
|
-
error_1 = _a.sent();
|
|
97
|
-
// We don't want failing to write analytics to cause any exceptions in the main
|
|
98
|
-
// thread so we just swallow them here.
|
|
99
|
-
this.logger.warn('Failed to post analytics to Flagsmith API. Not clearing data, will retry.');
|
|
100
|
-
return [2 /*return*/];
|
|
101
|
-
case 4:
|
|
102
|
-
this.currentFlush = undefined;
|
|
103
|
-
return [7 /*endfinally*/];
|
|
104
|
-
case 5:
|
|
105
|
-
this.analyticsData = {};
|
|
106
|
-
this.lastFlushed = Date.now();
|
|
107
|
-
return [2 /*return*/];
|
|
108
|
-
}
|
|
109
|
-
});
|
|
110
|
-
});
|
|
111
|
-
};
|
|
112
|
-
AnalyticsProcessor.prototype.trackFeature = function (featureName) {
|
|
113
|
-
this.analyticsData[featureName] = (this.analyticsData[featureName] || 0) + 1;
|
|
114
|
-
if (Date.now() - this.lastFlushed > ANALYTICS_TIMER * 1000) {
|
|
115
|
-
this.flush();
|
|
116
|
-
}
|
|
117
|
-
};
|
|
118
|
-
return AnalyticsProcessor;
|
|
119
|
-
}());
|
|
120
|
-
exports.AnalyticsProcessor = AnalyticsProcessor;
|
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;
|