flagsmith-nodejs 3.3.3 → 4.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.
Files changed (193) hide show
  1. package/.github/workflows/publish.yml +2 -2
  2. package/.github/workflows/pull_request.yaml +7 -14
  3. package/build/{flagsmith-engine → cjs/flagsmith-engine}/environments/models.d.ts +3 -3
  4. package/build/{flagsmith-engine → cjs/flagsmith-engine}/environments/models.js +20 -13
  5. package/build/{flagsmith-engine → cjs/flagsmith-engine}/environments/util.d.ts +1 -1
  6. package/build/cjs/flagsmith-engine/environments/util.js +23 -0
  7. package/build/cjs/flagsmith-engine/features/models.js +118 -0
  8. package/build/{flagsmith-engine → cjs/flagsmith-engine}/features/util.d.ts +1 -1
  9. package/build/cjs/flagsmith-engine/features/util.js +27 -0
  10. package/build/{flagsmith-engine → cjs/flagsmith-engine}/identities/models.d.ts +2 -2
  11. package/build/cjs/flagsmith-engine/identities/models.js +48 -0
  12. package/build/{flagsmith-engine → cjs/flagsmith-engine}/identities/traits/models.js +5 -4
  13. package/build/{flagsmith-engine → cjs/flagsmith-engine}/identities/util.d.ts +2 -2
  14. package/build/cjs/flagsmith-engine/identities/util.js +22 -0
  15. package/build/cjs/flagsmith-engine/index.d.ts +14 -0
  16. package/build/cjs/flagsmith-engine/index.js +75 -0
  17. package/build/cjs/flagsmith-engine/organisations/models.js +21 -0
  18. package/build/{flagsmith-engine → cjs/flagsmith-engine}/organisations/util.d.ts +1 -1
  19. package/build/cjs/flagsmith-engine/organisations/util.js +8 -0
  20. package/build/{flagsmith-engine → cjs/flagsmith-engine}/projects/models.d.ts +2 -2
  21. package/build/{flagsmith-engine → cjs/flagsmith-engine}/projects/models.js +8 -5
  22. package/build/{flagsmith-engine → cjs/flagsmith-engine}/projects/util.d.ts +1 -1
  23. package/build/cjs/flagsmith-engine/projects/util.js +15 -0
  24. package/build/{flagsmith-engine → cjs/flagsmith-engine}/segments/evaluators.d.ts +4 -4
  25. package/build/cjs/flagsmith-engine/segments/evaluators.js +37 -0
  26. package/build/{flagsmith-engine → cjs/flagsmith-engine}/segments/models.d.ts +1 -1
  27. package/build/cjs/flagsmith-engine/segments/models.js +111 -0
  28. package/build/{flagsmith-engine → cjs/flagsmith-engine}/segments/util.d.ts +1 -1
  29. package/build/{flagsmith-engine → cjs/flagsmith-engine}/segments/util.js +9 -11
  30. package/build/{flagsmith-engine → cjs/flagsmith-engine}/utils/collections.d.ts +1 -1
  31. package/build/cjs/flagsmith-engine/utils/collections.js +6 -0
  32. package/build/cjs/flagsmith-engine/utils/errors.js +6 -0
  33. package/build/cjs/flagsmith-engine/utils/hashing/index.js +29 -0
  34. package/build/{flagsmith-engine → cjs/flagsmith-engine}/utils/index.js +5 -5
  35. package/build/{index.d.ts → cjs/index.d.ts} +3 -3
  36. package/build/cjs/index.js +18 -0
  37. package/build/cjs/package.json +1 -0
  38. package/build/{sdk → cjs/sdk}/analytics.d.ts +3 -0
  39. package/build/cjs/sdk/analytics.js +73 -0
  40. package/build/cjs/sdk/errors.js +9 -0
  41. package/build/{sdk → cjs/sdk}/index.d.ts +19 -18
  42. package/build/cjs/sdk/index.js +400 -0
  43. package/build/{sdk → cjs/sdk}/models.d.ts +2 -2
  44. package/build/cjs/sdk/models.js +101 -0
  45. package/build/{sdk → cjs/sdk}/offline_handlers.d.ts +1 -1
  46. package/build/cjs/sdk/offline_handlers.js +23 -0
  47. package/build/{sdk → cjs/sdk}/polling_manager.d.ts +1 -1
  48. package/build/cjs/sdk/polling_manager.js +29 -0
  49. package/build/{sdk → cjs/sdk}/types.d.ts +15 -7
  50. package/build/cjs/sdk/utils.d.ts +36 -0
  51. package/build/cjs/sdk/utils.js +63 -0
  52. package/build/esm/flagsmith-engine/environments/models.d.ts +22 -0
  53. package/build/esm/flagsmith-engine/environments/models.js +32 -0
  54. package/build/esm/flagsmith-engine/environments/util.d.ts +3 -0
  55. package/build/esm/flagsmith-engine/environments/util.js +18 -0
  56. package/build/esm/flagsmith-engine/features/constants.d.ts +4 -0
  57. package/build/esm/flagsmith-engine/features/constants.js +4 -0
  58. package/build/esm/flagsmith-engine/features/models.d.ts +37 -0
  59. package/build/esm/flagsmith-engine/features/models.js +110 -0
  60. package/build/esm/flagsmith-engine/features/util.d.ts +4 -0
  61. package/build/esm/flagsmith-engine/features/util.js +21 -0
  62. package/build/esm/flagsmith-engine/identities/models.d.ts +15 -0
  63. package/build/esm/flagsmith-engine/identities/models.js +44 -0
  64. package/build/esm/flagsmith-engine/identities/traits/models.d.ts +5 -0
  65. package/build/esm/flagsmith-engine/identities/traits/models.js +8 -0
  66. package/build/esm/flagsmith-engine/identities/util.d.ts +4 -0
  67. package/build/esm/flagsmith-engine/identities/util.js +17 -0
  68. package/build/esm/flagsmith-engine/index.d.ts +14 -0
  69. package/build/esm/flagsmith-engine/index.js +62 -0
  70. package/build/esm/flagsmith-engine/organisations/models.d.ts +9 -0
  71. package/build/esm/flagsmith-engine/organisations/models.js +17 -0
  72. package/build/esm/flagsmith-engine/organisations/util.d.ts +2 -0
  73. package/build/esm/flagsmith-engine/organisations/util.js +4 -0
  74. package/build/esm/flagsmith-engine/projects/models.d.ts +10 -0
  75. package/build/esm/flagsmith-engine/projects/models.js +13 -0
  76. package/build/esm/flagsmith-engine/projects/util.d.ts +2 -0
  77. package/build/esm/flagsmith-engine/projects/util.js +11 -0
  78. package/build/esm/flagsmith-engine/segments/constants.d.ts +34 -0
  79. package/build/esm/flagsmith-engine/segments/constants.js +36 -0
  80. package/build/esm/flagsmith-engine/segments/evaluators.d.ts +7 -0
  81. package/build/esm/flagsmith-engine/segments/evaluators.js +31 -0
  82. package/build/esm/flagsmith-engine/segments/models.d.ts +37 -0
  83. package/build/esm/flagsmith-engine/segments/models.js +102 -0
  84. package/build/esm/flagsmith-engine/segments/util.d.ts +6 -0
  85. package/build/esm/flagsmith-engine/segments/util.js +23 -0
  86. package/build/esm/flagsmith-engine/utils/collections.d.ts +3 -0
  87. package/build/esm/flagsmith-engine/utils/collections.js +2 -0
  88. package/build/esm/flagsmith-engine/utils/errors.d.ts +2 -0
  89. package/build/esm/flagsmith-engine/utils/errors.js +2 -0
  90. package/build/esm/flagsmith-engine/utils/hashing/index.d.ts +9 -0
  91. package/build/esm/flagsmith-engine/utils/hashing/index.js +25 -0
  92. package/build/esm/flagsmith-engine/utils/index.d.ts +1 -0
  93. package/build/esm/flagsmith-engine/utils/index.js +13 -0
  94. package/build/esm/index.d.ts +3 -0
  95. package/build/esm/index.js +2 -0
  96. package/build/esm/sdk/analytics.d.ts +35 -0
  97. package/build/esm/sdk/analytics.js +69 -0
  98. package/build/esm/sdk/errors.d.ts +4 -0
  99. package/build/esm/sdk/errors.js +4 -0
  100. package/build/esm/sdk/index.d.ts +131 -0
  101. package/build/esm/sdk/index.js +390 -0
  102. package/build/esm/sdk/models.d.ts +55 -0
  103. package/build/esm/sdk/models.js +94 -0
  104. package/build/esm/sdk/offline_handlers.d.ts +9 -0
  105. package/build/esm/sdk/offline_handlers.js +18 -0
  106. package/build/esm/sdk/polling_manager.d.ts +9 -0
  107. package/build/esm/sdk/polling_manager.js +25 -0
  108. package/build/esm/sdk/types.d.ts +38 -0
  109. package/build/esm/sdk/types.js +1 -0
  110. package/build/esm/sdk/utils.d.ts +36 -0
  111. package/build/esm/sdk/utils.js +56 -0
  112. package/flagsmith-engine/environments/models.ts +3 -3
  113. package/flagsmith-engine/environments/util.ts +4 -4
  114. package/flagsmith-engine/features/models.ts +2 -2
  115. package/flagsmith-engine/features/util.ts +1 -1
  116. package/flagsmith-engine/identities/models.ts +4 -5
  117. package/flagsmith-engine/identities/traits/models.ts +0 -1
  118. package/flagsmith-engine/identities/util.ts +4 -4
  119. package/flagsmith-engine/index.ts +13 -13
  120. package/flagsmith-engine/organisations/util.ts +1 -1
  121. package/flagsmith-engine/projects/models.ts +2 -2
  122. package/flagsmith-engine/projects/util.ts +4 -4
  123. package/flagsmith-engine/segments/evaluators.ts +6 -6
  124. package/flagsmith-engine/segments/models.ts +5 -5
  125. package/flagsmith-engine/segments/util.ts +3 -3
  126. package/flagsmith-engine/utils/collections.ts +1 -1
  127. package/flagsmith-engine/utils/hashing/index.ts +5 -29
  128. package/flagsmith-engine/utils/index.ts +1 -1
  129. package/index.ts +4 -8
  130. package/package.json +21 -16
  131. package/sdk/analytics.ts +7 -5
  132. package/sdk/index.ts +55 -46
  133. package/sdk/models.ts +2 -3
  134. package/sdk/offline_handlers.ts +2 -2
  135. package/sdk/polling_manager.ts +2 -3
  136. package/sdk/types.ts +35 -24
  137. package/sdk/utils.ts +49 -37
  138. package/tests/engine/e2e/engine.test.ts +8 -11
  139. package/tests/engine/unit/engine.test.ts +5 -5
  140. package/tests/engine/unit/segments/segment_evaluators.test.ts +9 -9
  141. package/tests/engine/unit/utils/utils.test.ts +2 -2
  142. package/tests/sdk/analytics.test.ts +8 -13
  143. package/tests/sdk/data/identity-with-transient-traits.json +41 -0
  144. package/tests/sdk/data/transient-identity.json +29 -0
  145. package/tests/sdk/flagsmith-cache.test.ts +16 -32
  146. package/tests/sdk/flagsmith-environment-flags.test.ts +21 -36
  147. package/tests/sdk/flagsmith-identity-flags.test.ts +83 -32
  148. package/tests/sdk/flagsmith.test.ts +67 -99
  149. package/tests/sdk/offline-handlers.test.ts +5 -6
  150. package/tests/sdk/polling.test.ts +6 -8
  151. package/tests/sdk/utils.ts +19 -15
  152. package/tsconfig.cjs.json +7 -0
  153. package/tsconfig.esm.json +7 -0
  154. package/tsconfig.json +8 -4
  155. package/vitest.config.ts +17 -0
  156. package/build/flagsmith-engine/environments/util.js +0 -27
  157. package/build/flagsmith-engine/features/models.js +0 -132
  158. package/build/flagsmith-engine/features/util.js +0 -27
  159. package/build/flagsmith-engine/identities/models.js +0 -113
  160. package/build/flagsmith-engine/identities/util.js +0 -46
  161. package/build/flagsmith-engine/index.d.ts +0 -14
  162. package/build/flagsmith-engine/index.js +0 -127
  163. package/build/flagsmith-engine/organisations/models.js +0 -21
  164. package/build/flagsmith-engine/organisations/util.js +0 -8
  165. package/build/flagsmith-engine/projects/util.js +0 -15
  166. package/build/flagsmith-engine/segments/evaluators.js +0 -45
  167. package/build/flagsmith-engine/segments/models.js +0 -147
  168. package/build/flagsmith-engine/utils/collections.js +0 -26
  169. package/build/flagsmith-engine/utils/errors.js +0 -26
  170. package/build/flagsmith-engine/utils/hashing/index.js +0 -60
  171. package/build/index.js +0 -23
  172. package/build/sdk/analytics.js +0 -120
  173. package/build/sdk/errors.js +0 -34
  174. package/build/sdk/index.js +0 -594
  175. package/build/sdk/models.js +0 -149
  176. package/build/sdk/offline_handlers.js +0 -66
  177. package/build/sdk/polling_manager.js +0 -72
  178. package/build/sdk/utils.d.ts +0 -12
  179. package/build/sdk/utils.js +0 -107
  180. package/jest.config.js +0 -5
  181. package/tests/index.js +0 -0
  182. /package/build/{flagsmith-engine → cjs/flagsmith-engine}/features/constants.d.ts +0 -0
  183. /package/build/{flagsmith-engine → cjs/flagsmith-engine}/features/constants.js +0 -0
  184. /package/build/{flagsmith-engine → cjs/flagsmith-engine}/features/models.d.ts +0 -0
  185. /package/build/{flagsmith-engine → cjs/flagsmith-engine}/identities/traits/models.d.ts +0 -0
  186. /package/build/{flagsmith-engine → cjs/flagsmith-engine}/organisations/models.d.ts +0 -0
  187. /package/build/{flagsmith-engine → cjs/flagsmith-engine}/segments/constants.d.ts +0 -0
  188. /package/build/{flagsmith-engine → cjs/flagsmith-engine}/segments/constants.js +0 -0
  189. /package/build/{flagsmith-engine → cjs/flagsmith-engine}/utils/errors.d.ts +0 -0
  190. /package/build/{flagsmith-engine → cjs/flagsmith-engine}/utils/hashing/index.d.ts +0 -0
  191. /package/build/{flagsmith-engine → cjs/flagsmith-engine}/utils/index.d.ts +0 -0
  192. /package/build/{sdk → cjs/sdk}/errors.d.ts +0 -0
  193. /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;
@@ -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;
package/build/index.js DELETED
@@ -1,23 +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.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, "FeatureStateModel", { enumerable: true, get: function () { return flagsmith_engine_1.FeatureStateModel; } });
19
- Object.defineProperty(exports, "IdentityModel", { enumerable: true, get: function () { return flagsmith_engine_1.IdentityModel; } });
20
- Object.defineProperty(exports, "TraitModel", { enumerable: true, get: function () { return flagsmith_engine_1.TraitModel; } });
21
- Object.defineProperty(exports, "SegmentModel", { enumerable: true, get: function () { return flagsmith_engine_1.SegmentModel; } });
22
- Object.defineProperty(exports, "OrganisationModel", { enumerable: true, get: function () { return flagsmith_engine_1.OrganisationModel; } });
23
- module.exports = sdk_1.default;
@@ -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;
@@ -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;