flagsmith-nodejs 2.0.0-beta.6 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (94) hide show
  1. package/.github/workflows/pull_request.yaml +37 -29
  2. package/README.md +7 -0
  3. package/example/server/api/index.js +1 -1
  4. package/flagsmith-engine/features/models.ts +28 -6
  5. package/flagsmith-engine/features/util.ts +9 -0
  6. package/flagsmith-engine/identities/models.ts +1 -1
  7. package/flagsmith-engine/index.ts +7 -5
  8. package/flagsmith-engine/organisations/models.ts +1 -1
  9. package/flagsmith-engine/segments/models.ts +21 -4
  10. package/flagsmith-engine/segments/util.ts +8 -0
  11. package/flagsmith-engine/utils/collections.ts +1 -12
  12. package/flagsmith-engine/utils/hashing/index.ts +5 -2
  13. package/flagsmith-engine/utils/index.ts +6 -2
  14. package/package.json +4 -2
  15. package/sdk/analytics.ts +0 -2
  16. package/sdk/index.ts +84 -28
  17. package/sdk/polling_manager.ts +0 -1
  18. package/sdk/types.ts +8 -0
  19. package/sdk/utils.ts +4 -5
  20. package/tests/engine/unit/{egine.test.ts → engine.test.ts} +20 -0
  21. package/tests/engine/unit/features/models.test.ts +8 -4
  22. package/tests/engine/unit/identities/identities_builders.test.ts +13 -0
  23. package/tests/engine/unit/identities/identities_models.test.ts +3 -14
  24. package/tests/engine/unit/organization/models.test.ts +1 -1
  25. package/tests/engine/unit/segments/segments_model.test.ts +22 -1
  26. package/tests/engine/unit/utils.ts +1 -1
  27. package/tests/sdk/analytics.test.ts +11 -0
  28. package/tests/sdk/flagsmith-cache.test.ts +150 -0
  29. package/tests/sdk/flagsmith-environment-flags.test.ts +197 -0
  30. package/tests/sdk/flagsmith-identity-flags.test.ts +140 -0
  31. package/tests/sdk/flagsmith.test.ts +100 -85
  32. package/tests/sdk/polling.test.ts +25 -0
  33. package/tests/sdk/utils.ts +21 -2
  34. package/tsconfig.json +1 -1
  35. package/build/flagsmith-engine/environments/integrations/models.d.ts +0 -4
  36. package/build/flagsmith-engine/environments/integrations/models.js +0 -11
  37. package/build/flagsmith-engine/environments/models.d.ts +0 -25
  38. package/build/flagsmith-engine/environments/models.js +0 -29
  39. package/build/flagsmith-engine/environments/util.d.ts +0 -3
  40. package/build/flagsmith-engine/environments/util.js +0 -21
  41. package/build/flagsmith-engine/features/constants.d.ts +0 -4
  42. package/build/flagsmith-engine/features/constants.js +0 -7
  43. package/build/flagsmith-engine/features/models.d.ts +0 -32
  44. package/build/flagsmith-engine/features/models.js +0 -102
  45. package/build/flagsmith-engine/features/util.d.ts +0 -3
  46. package/build/flagsmith-engine/features/util.js +0 -20
  47. package/build/flagsmith-engine/identities/models.d.ts +0 -15
  48. package/build/flagsmith-engine/identities/models.js +0 -112
  49. package/build/flagsmith-engine/identities/traits/models.d.ts +0 -5
  50. package/build/flagsmith-engine/identities/traits/models.js +0 -11
  51. package/build/flagsmith-engine/identities/util.d.ts +0 -4
  52. package/build/flagsmith-engine/identities/util.js +0 -46
  53. package/build/flagsmith-engine/index.d.ts +0 -8
  54. package/build/flagsmith-engine/index.js +0 -113
  55. package/build/flagsmith-engine/organisations/models.d.ts +0 -9
  56. package/build/flagsmith-engine/organisations/models.js +0 -21
  57. package/build/flagsmith-engine/organisations/util.d.ts +0 -2
  58. package/build/flagsmith-engine/organisations/util.js +0 -8
  59. package/build/flagsmith-engine/projects/models.d.ts +0 -10
  60. package/build/flagsmith-engine/projects/models.js +0 -14
  61. package/build/flagsmith-engine/projects/util.d.ts +0 -2
  62. package/build/flagsmith-engine/projects/util.js +0 -15
  63. package/build/flagsmith-engine/segments/constants.d.ts +0 -26
  64. package/build/flagsmith-engine/segments/constants.js +0 -31
  65. package/build/flagsmith-engine/segments/evaluators.d.ts +0 -6
  66. package/build/flagsmith-engine/segments/evaluators.js +0 -37
  67. package/build/flagsmith-engine/segments/models.d.ts +0 -31
  68. package/build/flagsmith-engine/segments/models.js +0 -92
  69. package/build/flagsmith-engine/segments/util.d.ts +0 -4
  70. package/build/flagsmith-engine/segments/util.js +0 -25
  71. package/build/flagsmith-engine/utils/collections.d.ts +0 -4
  72. package/build/flagsmith-engine/utils/collections.js +0 -97
  73. package/build/flagsmith-engine/utils/errors.d.ts +0 -2
  74. package/build/flagsmith-engine/utils/errors.js +0 -26
  75. package/build/flagsmith-engine/utils/hashing/index.d.ts +0 -9
  76. package/build/flagsmith-engine/utils/hashing/index.js +0 -57
  77. package/build/flagsmith-engine/utils/index.d.ts +0 -1
  78. package/build/flagsmith-engine/utils/index.js +0 -14
  79. package/build/index.d.ts +0 -1
  80. package/build/index.js +0 -11
  81. package/build/sdk/analytics.d.ts +0 -28
  82. package/build/sdk/analytics.js +0 -103
  83. package/build/sdk/errors.d.ts +0 -4
  84. package/build/sdk/errors.js +0 -34
  85. package/build/sdk/index.d.ts +0 -118
  86. package/build/sdk/index.js +0 -386
  87. package/build/sdk/models.d.ts +0 -55
  88. package/build/sdk/models.js +0 -149
  89. package/build/sdk/polling_manager.d.ts +0 -9
  90. package/build/sdk/polling_manager.js +0 -73
  91. package/build/sdk/utils.d.ts +0 -12
  92. package/build/sdk/utils.js +0 -94
  93. package/tests/engine/engine-tests/engine-test-data/data/environment_n9fbf9h3v4fFgH3U3ngWhb.json +0 -12393
  94. package/tests/engine/engine-tests/engine-test-data/readme.md +0 -30
@@ -1,31 +0,0 @@
1
- import { FeatureStateModel } from '../features/models';
2
- export declare const all: (iterable: Array<any>) => boolean;
3
- export declare const any: (iterable: Array<any>) => boolean;
4
- export declare const matchingFunctions: {
5
- [x: string]: (thisValue: any, otherValue: any) => any;
6
- };
7
- export declare class SegmentConditionModel {
8
- EXCEPTION_OPERATOR_METHODS: {
9
- [key: string]: string;
10
- };
11
- operator: string;
12
- value: string;
13
- property_: string | undefined;
14
- constructor(operator: string, value: string, property?: string);
15
- matchesTraitValue(traitValue: any): any;
16
- }
17
- export declare class SegmentRuleModel {
18
- type: string;
19
- rules: SegmentRuleModel[];
20
- conditions: SegmentConditionModel[];
21
- constructor(type: string);
22
- static none(iterable: Array<any>): boolean;
23
- matchingFunction(): CallableFunction;
24
- }
25
- export declare class SegmentModel {
26
- id: number;
27
- name: string;
28
- rules: SegmentRuleModel[];
29
- featureStates: FeatureStateModel[];
30
- constructor(id: number, name: string);
31
- }
@@ -1,92 +0,0 @@
1
- "use strict";
2
- var _a;
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.SegmentModel = exports.SegmentRuleModel = exports.SegmentConditionModel = exports.matchingFunctions = exports.any = exports.all = void 0;
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; };
8
- exports.all = all;
9
- var any = function (iterable) { return iterable.filter(function (e) { return !!e; }).length > 0; };
10
- exports.any = any;
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);
36
- this.operator = operator;
37
- this.value = value;
38
- this.property_ = property;
39
- }
40
- SegmentConditionModel.prototype.matchesTraitValue = function (traitValue) {
41
- var _this = this;
42
- var evaluators = {
43
- evaluateNotContains: function (traitValue) {
44
- return !traitValue.includes(_this.value);
45
- },
46
- evaluateRegex: function (traitValue) {
47
- return !!traitValue.match(new RegExp(_this.value));
48
- }
49
- };
50
- // TODO: move this logic to the evaluator module
51
- if (this.EXCEPTION_OPERATOR_METHODS[this.operator]) {
52
- var evaluatorFunction = evaluators[this.EXCEPTION_OPERATOR_METHODS[this.operator]];
53
- return evaluatorFunction(traitValue);
54
- }
55
- var defaultFunction = function (x, y) { return false; };
56
- var matchingFunction = exports.matchingFunctions[this.operator] || defaultFunction;
57
- var castToTypeOfTraitValue = (0, utils_1.getCastingFunction)(traitValue);
58
- return matchingFunction(castToTypeOfTraitValue(this.value), traitValue);
59
- };
60
- return SegmentConditionModel;
61
- }());
62
- exports.SegmentConditionModel = SegmentConditionModel;
63
- var SegmentRuleModel = /** @class */ (function () {
64
- function SegmentRuleModel(type) {
65
- this.rules = [];
66
- this.conditions = [];
67
- this.type = type;
68
- }
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
- }());
82
- exports.SegmentRuleModel = SegmentRuleModel;
83
- var SegmentModel = /** @class */ (function () {
84
- function SegmentModel(id, name) {
85
- this.rules = [];
86
- this.featureStates = [];
87
- this.id = id;
88
- this.name = name;
89
- }
90
- return SegmentModel;
91
- }());
92
- exports.SegmentModel = SegmentModel;
@@ -1,4 +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;
@@ -1,25 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- 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;
@@ -1,4 +0,0 @@
1
- import { FeatureStateModel } from '../features/models';
2
- export declare class IdentityFeaturesList extends Array<FeatureStateModel> {
3
- push(...e: FeatureStateModel[]): number;
4
- }
@@ -1,97 +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
- 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
- };
53
- Object.defineProperty(exports, "__esModule", { value: true });
54
- exports.IdentityFeaturesList = void 0;
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; }
83
- }
84
- }
85
- }
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));
97
- exports.IdentityFeaturesList = IdentityFeaturesList;
@@ -1,2 +0,0 @@
1
- export declare class FeatureStateNotFound extends Error {
2
- }
@@ -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,57 +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 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;
52
- if (value === 100) {
53
- return getHashedPercentateForObjIds(objectIds, iterations + 1);
54
- }
55
- return value;
56
- }
57
- exports.getHashedPercentateForObjIds = getHashedPercentateForObjIds;
@@ -1 +0,0 @@
1
- export declare function getCastingFunction(input: any): CallableFunction;
@@ -1,14 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getCastingFunction = void 0;
4
- function getCastingFunction(input) {
5
- switch (typeof input) {
6
- case 'boolean':
7
- return function (x) { return !['False', 'false'].includes(x); };
8
- case 'number':
9
- return function (x) { return parseFloat(x); };
10
- default:
11
- return function (x) { return String(x); };
12
- }
13
- }
14
- exports.getCastingFunction = getCastingFunction;
package/build/index.d.ts DELETED
@@ -1 +0,0 @@
1
- export { Flagsmith } from './sdk';
package/build/index.js DELETED
@@ -1,11 +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.Flagsmith = void 0;
7
- var sdk_1 = __importDefault(require("./sdk"));
8
- var sdk_2 = require("./sdk");
9
- Object.defineProperty(exports, "Flagsmith", { enumerable: true, get: function () { return sdk_2.Flagsmith; } });
10
- // export default Flagsmith;
11
- module.exports = sdk_1.default;
@@ -1,28 +0,0 @@
1
- export declare class AnalyticsProcessor {
2
- private analyticsEndpoint;
3
- private environmentKey;
4
- private lastFlushed;
5
- analyticsData: {
6
- [key: string]: any;
7
- };
8
- private timeout;
9
- /**
10
- * AnalyticsProcessor is used to track how often individual Flags are evaluated within
11
- * the Flagsmith SDK. Docs: https://docs.flagsmith.com/advanced-use/flag-analytics.
12
- *
13
- * @param data.environmentKey environment key obtained from the Flagsmith UI
14
- * @param data.baseApiUrl base api url to override when using self hosted version
15
- * @param data.timeout used to tell requests to stop waiting for a response after a
16
- given number of seconds
17
- */
18
- constructor(data: {
19
- environmentKey: string;
20
- baseApiUrl: string;
21
- timeout?: number;
22
- });
23
- /**
24
- * Sends all the collected data to the api asynchronously and resets the timer
25
- */
26
- flush(): Promise<void>;
27
- trackFeature(featureId: number): void;
28
- }
@@ -1,103 +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 ANALYTICS_ENDPOINT = 'analytics/flags/';
45
- // Used to control how often we send data(in seconds)
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 () {
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.timeout used to tell requests to stop waiting for a response after a
56
- given number of seconds
57
- */
58
- function AnalyticsProcessor(data) {
59
- this.timeout = 3;
60
- this.analyticsEndpoint = data.baseApiUrl + ANALYTICS_ENDPOINT;
61
- this.environmentKey = data.environmentKey;
62
- this.lastFlushed = Date.now();
63
- this.analyticsData = {};
64
- this.timeout = data.timeout || this.timeout;
65
- }
66
- /**
67
- * Sends all the collected data to the api asynchronously and resets the timer
68
- */
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
- });
93
- });
94
- };
95
- AnalyticsProcessor.prototype.trackFeature = function (featureId) {
96
- this.analyticsData[featureId] = (this.analyticsData[featureId] || 0) + 1;
97
- if (Date.now() - this.lastFlushed > ANALYTICS_TIMER * 1000) {
98
- this.flush();
99
- }
100
- };
101
- return AnalyticsProcessor;
102
- }());
103
- exports.AnalyticsProcessor = AnalyticsProcessor;
@@ -1,4 +0,0 @@
1
- export declare class FlagsmithClientError extends Error {
2
- }
3
- export declare class FlagsmithAPIError extends Error {
4
- }
@@ -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;