flagsmith-nodejs 2.0.0-beta.5 → 2.0.0-beta.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. package/build/flagsmith-engine/environments/integrations/models.js +7 -4
  2. package/build/flagsmith-engine/environments/models.js +12 -23
  3. package/build/flagsmith-engine/environments/util.js +9 -7
  4. package/build/flagsmith-engine/features/models.js +64 -47
  5. package/build/flagsmith-engine/features/util.js +5 -5
  6. package/build/flagsmith-engine/identities/models.js +96 -31
  7. package/build/flagsmith-engine/identities/traits/models.js +4 -5
  8. package/build/flagsmith-engine/identities/util.js +33 -9
  9. package/build/flagsmith-engine/index.js +74 -22
  10. package/build/flagsmith-engine/organisations/models.js +11 -11
  11. package/build/flagsmith-engine/organisations/util.js +1 -1
  12. package/build/flagsmith-engine/projects/models.js +5 -8
  13. package/build/flagsmith-engine/projects/util.js +6 -6
  14. package/build/flagsmith-engine/segments/evaluators.js +17 -9
  15. package/build/flagsmith-engine/segments/models.js +67 -58
  16. package/build/flagsmith-engine/segments/util.js +10 -8
  17. package/build/flagsmith-engine/utils/collections.js +90 -9
  18. package/build/flagsmith-engine/utils/errors.js +22 -2
  19. package/build/flagsmith-engine/utils/hashing/index.js +11 -8
  20. package/build/flagsmith-engine/utils/index.js +3 -3
  21. package/build/index.js +1 -1
  22. package/build/sdk/analytics.js +72 -29
  23. package/build/sdk/errors.js +29 -4
  24. package/build/sdk/index.js +263 -140
  25. package/build/sdk/models.js +95 -47
  26. package/build/sdk/polling_manager.js +58 -16
  27. package/build/sdk/utils.js +67 -18
  28. package/example/package-lock.json +1 -996
  29. package/example/server/api/index.js +1 -1
  30. package/package.json +2 -1
  31. package/tsconfig.json +2 -1
@@ -1,8 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.IntegrationModel = void 0;
4
- class IntegrationModel {
5
- api_key = undefined;
6
- base_url = undefined;
7
- }
4
+ var IntegrationModel = /** @class */ (function () {
5
+ function IntegrationModel() {
6
+ this.api_key = undefined;
7
+ this.base_url = undefined;
8
+ }
9
+ return IntegrationModel;
10
+ }());
8
11
  exports.IntegrationModel = IntegrationModel;
@@ -1,15 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.EnvironmentModel = exports.EnvironmentAPIKeyModel = void 0;
4
- class EnvironmentAPIKeyModel {
5
- id;
6
- key;
7
- createdAt;
8
- name;
9
- clientApiKey;
10
- expiresAt;
11
- active = true;
12
- constructor(id, key, createdAt, name, clientApiKey, expiresAt) {
4
+ var EnvironmentAPIKeyModel = /** @class */ (function () {
5
+ function EnvironmentAPIKeyModel(id, key, createdAt, name, clientApiKey, expiresAt) {
6
+ this.active = true;
13
7
  this.id = id;
14
8
  this.key = key;
15
9
  this.createdAt = createdAt;
@@ -17,24 +11,19 @@ class EnvironmentAPIKeyModel {
17
11
  this.clientApiKey = clientApiKey;
18
12
  this.expiresAt = expiresAt;
19
13
  }
20
- isValid() {
14
+ EnvironmentAPIKeyModel.prototype.isValid = function () {
21
15
  return !!this.active && (!this.expiresAt || this.expiresAt > Date.now());
22
- }
23
- }
16
+ };
17
+ return EnvironmentAPIKeyModel;
18
+ }());
24
19
  exports.EnvironmentAPIKeyModel = EnvironmentAPIKeyModel;
25
- class EnvironmentModel {
26
- id;
27
- apiKey;
28
- project;
29
- featureStates = [];
30
- amplitude_config;
31
- segment_config;
32
- mixpanel_config;
33
- heap_config;
34
- constructor(id, apiKey, project) {
20
+ var EnvironmentModel = /** @class */ (function () {
21
+ function EnvironmentModel(id, apiKey, project) {
22
+ this.featureStates = [];
35
23
  this.id = id;
36
24
  this.apiKey = apiKey;
37
25
  this.project = project;
38
26
  }
39
- }
27
+ return EnvironmentModel;
28
+ }());
40
29
  exports.EnvironmentModel = EnvironmentModel;
@@ -1,19 +1,21 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.buildEnvironmentAPIKeyModel = exports.buildEnvironmentModel = void 0;
4
- const util_1 = require("../features/util");
5
- const util_2 = require("../projects/util");
6
- const models_1 = require("./models");
4
+ var util_1 = require("../features/util");
5
+ var util_2 = require("../projects/util");
6
+ var models_1 = require("./models");
7
7
  function buildEnvironmentModel(environmentJSON) {
8
- const project = (0, util_2.buildProjectModel)(environmentJSON.project);
9
- const featureStates = environmentJSON.feature_states.map((fs) => (0, util_1.buildFeatureStateModel)(fs));
10
- const environmentModel = new models_1.EnvironmentModel(environmentJSON.id, environmentJSON.api_key, project);
8
+ var project = (0, util_2.buildProjectModel)(environmentJSON.project);
9
+ var featureStates = environmentJSON.feature_states.map(function (fs) {
10
+ return (0, util_1.buildFeatureStateModel)(fs);
11
+ });
12
+ var environmentModel = new models_1.EnvironmentModel(environmentJSON.id, environmentJSON.api_key, project);
11
13
  environmentModel.featureStates = featureStates;
12
14
  return environmentModel;
13
15
  }
14
16
  exports.buildEnvironmentModel = buildEnvironmentModel;
15
17
  function buildEnvironmentAPIKeyModel(apiKeyJSON) {
16
- const model = new models_1.EnvironmentAPIKeyModel(apiKeyJSON.id, apiKeyJSON.key, Date.parse(apiKeyJSON.created_at), apiKeyJSON.name, apiKeyJSON.client_api_key);
18
+ var model = new models_1.EnvironmentAPIKeyModel(apiKeyJSON.id, apiKeyJSON.key, Date.parse(apiKeyJSON.created_at), apiKeyJSON.name, apiKeyJSON.client_api_key);
17
19
  return model;
18
20
  }
19
21
  exports.buildEnvironmentAPIKeyModel = buildEnvironmentAPIKeyModel;
@@ -1,85 +1,102 @@
1
1
  "use strict";
2
+ var __values = (this && this.__values) || function(o) {
3
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
4
+ if (m) return m.call(o);
5
+ if (o && typeof o.length === "number") return {
6
+ next: function () {
7
+ if (o && i >= o.length) o = void 0;
8
+ return { value: o && o[i++], done: !o };
9
+ }
10
+ };
11
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
12
+ };
2
13
  Object.defineProperty(exports, "__esModule", { value: true });
3
14
  exports.FeatureStateModel = exports.MultivariateFeatureStateValueModel = exports.MultivariateFeatureOptionModel = exports.FeatureModel = void 0;
4
- const uuid_1 = require("uuid");
5
- const hashing_1 = require("../utils/hashing");
6
- class FeatureModel {
7
- id;
8
- name;
9
- type;
10
- constructor(id, name, type) {
15
+ var uuid_1 = require("uuid");
16
+ var hashing_1 = require("../utils/hashing");
17
+ var FeatureModel = /** @class */ (function () {
18
+ function FeatureModel(id, name, type) {
11
19
  this.id = id;
12
20
  this.name = name;
13
21
  this.type = type;
14
22
  }
15
- eq(other) {
23
+ FeatureModel.prototype.eq = function (other) {
16
24
  return !!other && this.id === other.id;
17
- }
18
- }
25
+ };
26
+ return FeatureModel;
27
+ }());
19
28
  exports.FeatureModel = FeatureModel;
20
- class MultivariateFeatureOptionModel {
21
- value;
22
- id;
23
- constructor(value, id) {
29
+ var MultivariateFeatureOptionModel = /** @class */ (function () {
30
+ function MultivariateFeatureOptionModel(value, id) {
24
31
  this.value = value;
25
32
  this.id = id;
26
33
  }
27
- }
34
+ return MultivariateFeatureOptionModel;
35
+ }());
28
36
  exports.MultivariateFeatureOptionModel = MultivariateFeatureOptionModel;
29
- class MultivariateFeatureStateValueModel {
30
- multivariateFeatureOption;
31
- percentageAllocation;
32
- id;
33
- mvFsValueUuid = (0, uuid_1.v4)();
34
- constructor(multivariate_feature_option, percentage_allocation, id, mvFsValueUuid) {
37
+ var MultivariateFeatureStateValueModel = /** @class */ (function () {
38
+ function MultivariateFeatureStateValueModel(multivariate_feature_option, percentage_allocation, id, mvFsValueUuid) {
39
+ this.mvFsValueUuid = (0, uuid_1.v4)();
35
40
  this.id = id;
36
41
  this.percentageAllocation = percentage_allocation;
37
42
  this.multivariateFeatureOption = multivariate_feature_option;
38
43
  this.mvFsValueUuid = mvFsValueUuid || this.mvFsValueUuid;
39
44
  }
40
- }
45
+ return MultivariateFeatureStateValueModel;
46
+ }());
41
47
  exports.MultivariateFeatureStateValueModel = MultivariateFeatureStateValueModel;
42
- class FeatureStateModel {
43
- feature;
44
- enabled;
45
- djangoID;
46
- featurestateUUID = (0, uuid_1.v4)();
47
- value;
48
- multivariateFeatureStateValues = [];
49
- constructor(feature, enabled, djangoID, value, featurestateUuid = (0, uuid_1.v4)()) {
48
+ var FeatureStateModel = /** @class */ (function () {
49
+ function FeatureStateModel(feature, enabled, djangoID, value, featurestateUuid) {
50
+ if (featurestateUuid === void 0) { featurestateUuid = (0, uuid_1.v4)(); }
51
+ this.featurestateUUID = (0, uuid_1.v4)();
52
+ this.multivariateFeatureStateValues = [];
50
53
  this.feature = feature;
51
54
  this.enabled = enabled;
52
55
  this.djangoID = djangoID;
53
56
  this.value = value;
54
57
  this.featurestateUUID = featurestateUuid;
55
58
  }
56
- setValue(value) {
59
+ FeatureStateModel.prototype.setValue = function (value) {
57
60
  this.value = value;
58
- }
59
- getValue(identityId) {
61
+ };
62
+ FeatureStateModel.prototype.getValue = function (identityId) {
60
63
  if (!!identityId && this.multivariateFeatureStateValues.length > 0) {
61
64
  return this.getMultivariateValue(identityId);
62
65
  }
63
66
  return this.value;
64
- }
65
- get_feature_state_value() {
67
+ };
68
+ FeatureStateModel.prototype.get_feature_state_value = function () {
66
69
  return this.getValue();
67
- }
68
- getMultivariateValue(identityID) {
69
- const percentageValue = (0, hashing_1.getHashedPercentateForObjIds)([
70
+ };
71
+ FeatureStateModel.prototype.getMultivariateValue = function (identityID) {
72
+ var e_1, _a;
73
+ var percentageValue = (0, hashing_1.getHashedPercentateForObjIds)([
70
74
  this.djangoID || this.featurestateUUID,
71
75
  identityID
72
76
  ]);
73
- let startPercentage = 0;
74
- const sortedF = this.multivariateFeatureStateValues.sort((a, b) => !!(a.id && b.id) ? a.id - b.id : a.mvFsValueUuid > b.mvFsValueUuid ? -1 : 1);
75
- for (const myValue of sortedF) {
76
- const limit = myValue.percentageAllocation + startPercentage;
77
- if (startPercentage <= percentageValue && percentageValue < limit) {
78
- return myValue.multivariateFeatureOption.value;
77
+ var startPercentage = 0;
78
+ var sortedF = this.multivariateFeatureStateValues.sort(function (a, b) {
79
+ return !!(a.id && b.id) ? a.id - b.id : a.mvFsValueUuid > b.mvFsValueUuid ? -1 : 1;
80
+ });
81
+ try {
82
+ for (var sortedF_1 = __values(sortedF), sortedF_1_1 = sortedF_1.next(); !sortedF_1_1.done; sortedF_1_1 = sortedF_1.next()) {
83
+ var myValue = sortedF_1_1.value;
84
+ var limit = myValue.percentageAllocation + startPercentage;
85
+ if (startPercentage <= percentageValue && percentageValue < limit) {
86
+ return myValue.multivariateFeatureOption.value;
87
+ }
88
+ startPercentage = limit;
89
+ }
90
+ }
91
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
92
+ finally {
93
+ try {
94
+ if (sortedF_1_1 && !sortedF_1_1.done && (_a = sortedF_1.return)) _a.call(sortedF_1);
79
95
  }
80
- startPercentage = limit;
96
+ finally { if (e_1) throw e_1.error; }
81
97
  }
82
98
  return this.value;
83
- }
84
- }
99
+ };
100
+ return FeatureStateModel;
101
+ }());
85
102
  exports.FeatureStateModel = FeatureStateModel;
@@ -1,16 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.buildFeatureStateModel = exports.buildFeatureModel = void 0;
4
- const models_1 = require("./models");
4
+ var models_1 = require("./models");
5
5
  function buildFeatureModel(featuresModelJSON) {
6
6
  return new models_1.FeatureModel(featuresModelJSON.id, featuresModelJSON.name, featuresModelJSON.type);
7
7
  }
8
8
  exports.buildFeatureModel = buildFeatureModel;
9
9
  function buildFeatureStateModel(featuresStateModelJSON) {
10
- const featureStateModel = new models_1.FeatureStateModel(buildFeatureModel(featuresStateModelJSON.feature), featuresStateModelJSON.enabled, featuresStateModelJSON.django_id, featuresStateModelJSON.feature_state_value, featuresStateModelJSON.uuid);
11
- const multivariateFeatureStateValues = featuresStateModelJSON.multivariate_feature_state_values
12
- ? featuresStateModelJSON.multivariate_feature_state_values.map((fsv) => {
13
- const featureOption = new models_1.MultivariateFeatureOptionModel(fsv.multivariate_feature_option.value, fsv.multivariate_feature_option.id);
10
+ var featureStateModel = new models_1.FeatureStateModel(buildFeatureModel(featuresStateModelJSON.feature), featuresStateModelJSON.enabled, featuresStateModelJSON.django_id, featuresStateModelJSON.feature_state_value, featuresStateModelJSON.uuid);
11
+ var multivariateFeatureStateValues = featuresStateModelJSON.multivariate_feature_state_values
12
+ ? featuresStateModelJSON.multivariate_feature_state_values.map(function (fsv) {
13
+ var featureOption = new models_1.MultivariateFeatureOptionModel(fsv.multivariate_feature_option.value, fsv.multivariate_feature_option.id);
14
14
  return new models_1.MultivariateFeatureStateValueModel(featureOption, fsv.percentage_allocation, fsv.id);
15
15
  })
16
16
  : [];
@@ -1,47 +1,112 @@
1
1
  "use strict";
2
+ var __read = (this && this.__read) || function (o, n) {
3
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
4
+ if (!m) return o;
5
+ var i = m.call(o), r, ar = [], e;
6
+ try {
7
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
8
+ }
9
+ catch (error) { e = { error: error }; }
10
+ finally {
11
+ try {
12
+ if (r && !r.done && (m = i["return"])) m.call(i);
13
+ }
14
+ finally { if (e) throw e.error; }
15
+ }
16
+ return ar;
17
+ };
18
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
19
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
20
+ if (ar || !(i in from)) {
21
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
22
+ ar[i] = from[i];
23
+ }
24
+ }
25
+ return to.concat(ar || Array.prototype.slice.call(from));
26
+ };
27
+ var __values = (this && this.__values) || function(o) {
28
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
29
+ if (m) return m.call(o);
30
+ if (o && typeof o.length === "number") return {
31
+ next: function () {
32
+ if (o && i >= o.length) o = void 0;
33
+ return { value: o && o[i++], done: !o };
34
+ }
35
+ };
36
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
37
+ };
2
38
  Object.defineProperty(exports, "__esModule", { value: true });
3
39
  exports.IdentityModel = void 0;
4
- const collections_1 = require("../utils/collections");
5
- const { v4: uuidv4 } = require('uuid');
6
- class IdentityModel {
7
- identifier;
8
- environmentApiKey;
9
- createdDate;
10
- identityFeatures;
11
- identityTraits;
12
- identityUuid;
13
- djangoID;
14
- constructor(created_date, identityTraits, identityFeatures, environmentApiKey, identifier, identityUuid) {
40
+ var collections_1 = require("../utils/collections");
41
+ var uuidv4 = require('uuid').v4;
42
+ var IdentityModel = /** @class */ (function () {
43
+ function IdentityModel(created_date, identityTraits, identityFeatures, environmentApiKey, identifier, identityUuid) {
15
44
  this.identityUuid = identityUuid || uuidv4();
16
45
  this.createdDate = Date.parse(created_date) || Date.now();
17
46
  this.identityTraits = identityTraits;
18
- this.identityFeatures = new collections_1.IdentityFeaturesList(...identityFeatures);
47
+ this.identityFeatures = new (collections_1.IdentityFeaturesList.bind.apply(collections_1.IdentityFeaturesList, __spreadArray([void 0], __read(identityFeatures), false)))();
19
48
  this.environmentApiKey = environmentApiKey;
20
49
  this.identifier = identifier;
21
50
  }
22
- get compositeKey() {
23
- return IdentityModel.generateCompositeKey(this.environmentApiKey, this.identifier);
24
- }
25
- static generateCompositeKey(env_key, identifier) {
26
- return `${env_key}_${identifier}`;
27
- }
28
- update_traits(traits) {
29
- const existingTraits = new Map();
30
- for (const trait of this.identityTraits) {
31
- existingTraits.set(trait.traitKey, trait);
32
- }
33
- for (const trait of traits) {
34
- if (!!trait.traitValue) {
51
+ Object.defineProperty(IdentityModel.prototype, "compositeKey", {
52
+ get: function () {
53
+ return IdentityModel.generateCompositeKey(this.environmentApiKey, this.identifier);
54
+ },
55
+ enumerable: false,
56
+ configurable: true
57
+ });
58
+ IdentityModel.generateCompositeKey = function (env_key, identifier) {
59
+ return "".concat(env_key, "_").concat(identifier);
60
+ };
61
+ IdentityModel.prototype.update_traits = function (traits) {
62
+ var e_1, _a, e_2, _b, e_3, _c;
63
+ var existingTraits = new Map();
64
+ try {
65
+ for (var _d = __values(this.identityTraits), _e = _d.next(); !_e.done; _e = _d.next()) {
66
+ var trait = _e.value;
35
67
  existingTraits.set(trait.traitKey, trait);
36
68
  }
37
- else {
38
- existingTraits.delete(trait.traitKey);
69
+ }
70
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
71
+ finally {
72
+ try {
73
+ if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
74
+ }
75
+ finally { if (e_1) throw e_1.error; }
76
+ }
77
+ try {
78
+ for (var traits_1 = __values(traits), traits_1_1 = traits_1.next(); !traits_1_1.done; traits_1_1 = traits_1.next()) {
79
+ var trait = traits_1_1.value;
80
+ if (!!trait.traitValue) {
81
+ existingTraits.set(trait.traitKey, trait);
82
+ }
83
+ else {
84
+ existingTraits.delete(trait.traitKey);
85
+ }
86
+ }
87
+ }
88
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
89
+ finally {
90
+ try {
91
+ if (traits_1_1 && !traits_1_1.done && (_b = traits_1.return)) _b.call(traits_1);
39
92
  }
93
+ finally { if (e_2) throw e_2.error; }
40
94
  }
41
95
  this.identityTraits = [];
42
- for (const [k, v] of existingTraits.entries()) {
43
- this.identityTraits.push(v);
96
+ try {
97
+ for (var _f = __values(existingTraits.entries()), _g = _f.next(); !_g.done; _g = _f.next()) {
98
+ var _h = __read(_g.value, 2), k = _h[0], v = _h[1];
99
+ this.identityTraits.push(v);
100
+ }
44
101
  }
45
- }
46
- }
102
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
103
+ finally {
104
+ try {
105
+ if (_g && !_g.done && (_c = _f.return)) _c.call(_f);
106
+ }
107
+ finally { if (e_3) throw e_3.error; }
108
+ }
109
+ };
110
+ return IdentityModel;
111
+ }());
47
112
  exports.IdentityModel = IdentityModel;
@@ -1,12 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.TraitModel = void 0;
4
- class TraitModel {
5
- traitKey;
6
- traitValue;
7
- constructor(key, value) {
4
+ var TraitModel = /** @class */ (function () {
5
+ function TraitModel(key, value) {
8
6
  this.traitKey = key;
9
7
  this.traitValue = value;
10
8
  }
11
- }
9
+ return TraitModel;
10
+ }());
12
11
  exports.TraitModel = TraitModel;
@@ -1,20 +1,44 @@
1
1
  "use strict";
2
+ var __read = (this && this.__read) || function (o, n) {
3
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
4
+ if (!m) return o;
5
+ var i = m.call(o), r, ar = [], e;
6
+ try {
7
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
8
+ }
9
+ catch (error) { e = { error: error }; }
10
+ finally {
11
+ try {
12
+ if (r && !r.done && (m = i["return"])) m.call(i);
13
+ }
14
+ finally { if (e) throw e.error; }
15
+ }
16
+ return ar;
17
+ };
18
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
19
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
20
+ if (ar || !(i in from)) {
21
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
22
+ ar[i] = from[i];
23
+ }
24
+ }
25
+ return to.concat(ar || Array.prototype.slice.call(from));
26
+ };
2
27
  Object.defineProperty(exports, "__esModule", { value: true });
3
28
  exports.buildIdentityModel = exports.buildTraitModel = void 0;
4
- const util_1 = require("../features/util");
5
- const collections_1 = require("../utils/collections");
6
- const models_1 = require("./models");
7
- const models_2 = require("./traits/models");
29
+ var util_1 = require("../features/util");
30
+ var collections_1 = require("../utils/collections");
31
+ var models_1 = require("./models");
32
+ var models_2 = require("./traits/models");
8
33
  function buildTraitModel(traitJSON) {
9
34
  return new models_2.TraitModel(traitJSON.trait_key, traitJSON.trait_value);
10
35
  }
11
36
  exports.buildTraitModel = buildTraitModel;
12
37
  function buildIdentityModel(identityJSON) {
13
- const featureList = identityJSON.identity_features
14
- ? new collections_1.IdentityFeaturesList(...identityJSON.identity_features.map((f) => (0, util_1.buildFeatureStateModel)(f)))
15
- : [];
16
- const model = new models_1.IdentityModel(identityJSON.created_date, identityJSON.identity_traits
17
- ? identityJSON.identity_traits.map((trait) => buildTraitModel(trait))
38
+ var featureList = identityJSON.identity_features
39
+ ? new (collections_1.IdentityFeaturesList.bind.apply(collections_1.IdentityFeaturesList, __spreadArray([void 0], __read(identityJSON.identity_features.map(function (f) { return (0, util_1.buildFeatureStateModel)(f); })), false)))() : [];
40
+ var model = new models_1.IdentityModel(identityJSON.created_date, identityJSON.identity_traits
41
+ ? identityJSON.identity_traits.map(function (trait) { return buildTraitModel(trait); })
18
42
  : [], featureList, identityJSON.environment_api_key, identityJSON.identifier, identityJSON.identity_uuid);
19
43
  model.djangoID = identityJSON.django_id;
20
44
  return model;
@@ -1,35 +1,87 @@
1
1
  "use strict";
2
+ var __values = (this && this.__values) || function(o) {
3
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
4
+ if (m) return m.call(o);
5
+ if (o && typeof o.length === "number") return {
6
+ next: function () {
7
+ if (o && i >= o.length) o = void 0;
8
+ return { value: o && o[i++], done: !o };
9
+ }
10
+ };
11
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
12
+ };
2
13
  Object.defineProperty(exports, "__esModule", { value: true });
3
14
  exports.getEnvironmentFeatureStates = exports.getEnvironmentFeatureState = exports.getIdentityFeatureStates = exports.getIdentityFeatureState = void 0;
4
- const evaluators_1 = require("./segments/evaluators");
5
- const errors_1 = require("./utils/errors");
15
+ var evaluators_1 = require("./segments/evaluators");
16
+ var errors_1 = require("./utils/errors");
6
17
  function getIdentityFeatureStatesDict(environment, identity, overrideTraits) {
18
+ var e_1, _a, e_2, _b, e_3, _c, e_4, _d;
7
19
  // Get feature states from the environment
8
- const featureStates = {};
9
- for (const fs of environment.featureStates) {
10
- featureStates[fs.feature.id] = fs;
20
+ var featureStates = {};
21
+ try {
22
+ for (var _e = __values(environment.featureStates), _f = _e.next(); !_f.done; _f = _e.next()) {
23
+ var fs = _f.value;
24
+ featureStates[fs.feature.id] = fs;
25
+ }
26
+ }
27
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
28
+ finally {
29
+ try {
30
+ if (_f && !_f.done && (_a = _e.return)) _a.call(_e);
31
+ }
32
+ finally { if (e_1) throw e_1.error; }
11
33
  }
12
34
  // Override with any feature states defined by matching segments
13
- const identitySegments = (0, evaluators_1.getIdentitySegments)(environment, identity, overrideTraits);
14
- for (const matchingSegment of identitySegments) {
15
- for (const featureState of matchingSegment.featureStates) {
16
- // note that feature states are stored on the segment in descending priority
17
- // order so we only care that the last one is added
18
- // TODO: can we optimise this?
19
- featureStates[featureState.feature.id] = featureState;
35
+ var identitySegments = (0, evaluators_1.getIdentitySegments)(environment, identity, overrideTraits);
36
+ try {
37
+ for (var identitySegments_1 = __values(identitySegments), identitySegments_1_1 = identitySegments_1.next(); !identitySegments_1_1.done; identitySegments_1_1 = identitySegments_1.next()) {
38
+ var matchingSegment = identitySegments_1_1.value;
39
+ try {
40
+ for (var _g = (e_3 = void 0, __values(matchingSegment.featureStates)), _h = _g.next(); !_h.done; _h = _g.next()) {
41
+ var featureState = _h.value;
42
+ // note that feature states are stored on the segment in descending priority
43
+ // order so we only care that the last one is added
44
+ // TODO: can we optimise this?
45
+ featureStates[featureState.feature.id] = featureState;
46
+ }
47
+ }
48
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
49
+ finally {
50
+ try {
51
+ if (_h && !_h.done && (_c = _g.return)) _c.call(_g);
52
+ }
53
+ finally { if (e_3) throw e_3.error; }
54
+ }
20
55
  }
21
56
  }
22
- // Override with any feature states defined directly the identity
23
- for (const fs of identity.identityFeatures || []) {
24
- if (featureStates[fs.feature.id]) {
25
- featureStates[fs.feature.id] = fs;
57
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
58
+ finally {
59
+ try {
60
+ if (identitySegments_1_1 && !identitySegments_1_1.done && (_b = identitySegments_1.return)) _b.call(identitySegments_1);
61
+ }
62
+ finally { if (e_2) throw e_2.error; }
63
+ }
64
+ try {
65
+ // Override with any feature states defined directly the identity
66
+ for (var _j = __values(identity.identityFeatures || []), _k = _j.next(); !_k.done; _k = _j.next()) {
67
+ var fs = _k.value;
68
+ if (featureStates[fs.feature.id]) {
69
+ featureStates[fs.feature.id] = fs;
70
+ }
71
+ }
72
+ }
73
+ catch (e_4_1) { e_4 = { error: e_4_1 }; }
74
+ finally {
75
+ try {
76
+ if (_k && !_k.done && (_d = _j.return)) _d.call(_j);
26
77
  }
78
+ finally { if (e_4) throw e_4.error; }
27
79
  }
28
80
  return featureStates;
29
81
  }
30
82
  function getIdentityFeatureState(environment, identity, featureName, overrideTraits) {
31
- const featureStates = getIdentityFeatureStatesDict(environment, identity, overrideTraits);
32
- const matchingFeature = Object.values(featureStates).filter(f => f.feature.name === featureName);
83
+ var featureStates = getIdentityFeatureStatesDict(environment, identity, overrideTraits);
84
+ var matchingFeature = Object.values(featureStates).filter(function (f) { return f.feature.name === featureName; });
33
85
  if (matchingFeature.length === 0) {
34
86
  throw new errors_1.FeatureStateNotFound('Feature State Not Found');
35
87
  }
@@ -37,15 +89,15 @@ function getIdentityFeatureState(environment, identity, featureName, overrideTra
37
89
  }
38
90
  exports.getIdentityFeatureState = getIdentityFeatureState;
39
91
  function getIdentityFeatureStates(environment, identity, overrideTraits) {
40
- const featureStates = Object.values(getIdentityFeatureStatesDict(environment, identity, overrideTraits));
92
+ var featureStates = Object.values(getIdentityFeatureStatesDict(environment, identity, overrideTraits));
41
93
  if (environment.project.hideDisabledFlags) {
42
- return featureStates.filter(fs => !!fs.enabled);
94
+ return featureStates.filter(function (fs) { return !!fs.enabled; });
43
95
  }
44
96
  return featureStates;
45
97
  }
46
98
  exports.getIdentityFeatureStates = getIdentityFeatureStates;
47
99
  function getEnvironmentFeatureState(environment, featureName) {
48
- const featuresStates = environment.featureStates.filter(f => f.feature.name === featureName);
100
+ var featuresStates = environment.featureStates.filter(function (f) { return f.feature.name === featureName; });
49
101
  if (featuresStates.length === 0) {
50
102
  throw new Error('Feature State Not Found');
51
103
  }
@@ -54,7 +106,7 @@ function getEnvironmentFeatureState(environment, featureName) {
54
106
  exports.getEnvironmentFeatureState = getEnvironmentFeatureState;
55
107
  function getEnvironmentFeatureStates(environment) {
56
108
  if (environment.project.hideDisabledFlags) {
57
- return environment.featureStates.filter(fs => !!fs.enabled);
109
+ return environment.featureStates.filter(function (fs) { return !!fs.enabled; });
58
110
  }
59
111
  return environment.featureStates;
60
112
  }
@@ -1,21 +1,21 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.OrganisationModel = void 0;
4
- class OrganisationModel {
5
- id;
6
- name;
7
- featureAnalytics;
8
- stopServingFlags;
9
- persistTraitData;
10
- constructor(id, name, featureAnalytics, stopServingFlags, persistTraitData) {
4
+ var OrganisationModel = /** @class */ (function () {
5
+ function OrganisationModel(id, name, featureAnalytics, stopServingFlags, persistTraitData) {
11
6
  this.id = id;
12
7
  this.name = name;
13
8
  this.featureAnalytics = featureAnalytics;
14
9
  this.stopServingFlags = stopServingFlags;
15
10
  this.persistTraitData = persistTraitData;
16
11
  }
17
- get unique_slug() {
18
- return this.id.toString() + '-' + this.name;
19
- }
20
- }
12
+ Object.defineProperty(OrganisationModel.prototype, "unique_slug", {
13
+ get: function () {
14
+ return this.id.toString() + '-' + this.name;
15
+ },
16
+ enumerable: false,
17
+ configurable: true
18
+ });
19
+ return OrganisationModel;
20
+ }());
21
21
  exports.OrganisationModel = OrganisationModel;