flagsmith-nodejs 2.0.0-beta.7 → 2.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 (75) hide show
  1. package/.tool-versions +1 -0
  2. package/flagsmith-engine/features/models.ts +29 -3
  3. package/flagsmith-engine/features/util.ts +9 -0
  4. package/flagsmith-engine/index.ts +6 -4
  5. package/flagsmith-engine/segments/models.ts +21 -2
  6. package/flagsmith-engine/segments/util.ts +8 -0
  7. package/flagsmith-engine/utils/index.ts +6 -2
  8. package/package.json +4 -2
  9. package/sdk/index.ts +1 -2
  10. package/sdk/utils.ts +4 -5
  11. package/tests/engine/unit/features/models.test.ts +1 -1
  12. package/tests/engine/unit/segments/segments_model.test.ts +20 -0
  13. package/.idea/flagsmith-nodejs-client.iml +0 -12
  14. package/.idea/modules.xml +0 -8
  15. package/.idea/vcs.xml +0 -6
  16. package/build/flagsmith-engine/environments/integrations/models.d.ts +0 -4
  17. package/build/flagsmith-engine/environments/integrations/models.js +0 -11
  18. package/build/flagsmith-engine/environments/models.d.ts +0 -25
  19. package/build/flagsmith-engine/environments/models.js +0 -29
  20. package/build/flagsmith-engine/environments/util.d.ts +0 -3
  21. package/build/flagsmith-engine/environments/util.js +0 -21
  22. package/build/flagsmith-engine/features/constants.d.ts +0 -4
  23. package/build/flagsmith-engine/features/constants.js +0 -7
  24. package/build/flagsmith-engine/features/models.d.ts +0 -31
  25. package/build/flagsmith-engine/features/models.js +0 -99
  26. package/build/flagsmith-engine/features/util.d.ts +0 -3
  27. package/build/flagsmith-engine/features/util.js +0 -20
  28. package/build/flagsmith-engine/identities/models.d.ts +0 -15
  29. package/build/flagsmith-engine/identities/models.js +0 -112
  30. package/build/flagsmith-engine/identities/traits/models.d.ts +0 -5
  31. package/build/flagsmith-engine/identities/traits/models.js +0 -11
  32. package/build/flagsmith-engine/identities/util.d.ts +0 -4
  33. package/build/flagsmith-engine/identities/util.js +0 -46
  34. package/build/flagsmith-engine/index.d.ts +0 -8
  35. package/build/flagsmith-engine/index.js +0 -113
  36. package/build/flagsmith-engine/organisations/models.d.ts +0 -9
  37. package/build/flagsmith-engine/organisations/models.js +0 -21
  38. package/build/flagsmith-engine/organisations/util.d.ts +0 -2
  39. package/build/flagsmith-engine/organisations/util.js +0 -8
  40. package/build/flagsmith-engine/projects/models.d.ts +0 -10
  41. package/build/flagsmith-engine/projects/models.js +0 -14
  42. package/build/flagsmith-engine/projects/util.d.ts +0 -2
  43. package/build/flagsmith-engine/projects/util.js +0 -15
  44. package/build/flagsmith-engine/segments/constants.d.ts +0 -26
  45. package/build/flagsmith-engine/segments/constants.js +0 -31
  46. package/build/flagsmith-engine/segments/evaluators.d.ts +0 -6
  47. package/build/flagsmith-engine/segments/evaluators.js +0 -37
  48. package/build/flagsmith-engine/segments/models.d.ts +0 -31
  49. package/build/flagsmith-engine/segments/models.js +0 -89
  50. package/build/flagsmith-engine/segments/util.d.ts +0 -4
  51. package/build/flagsmith-engine/segments/util.js +0 -25
  52. package/build/flagsmith-engine/utils/collections.d.ts +0 -3
  53. package/build/flagsmith-engine/utils/collections.js +0 -26
  54. package/build/flagsmith-engine/utils/errors.d.ts +0 -2
  55. package/build/flagsmith-engine/utils/errors.js +0 -26
  56. package/build/flagsmith-engine/utils/hashing/index.d.ts +0 -9
  57. package/build/flagsmith-engine/utils/hashing/index.js +0 -60
  58. package/build/flagsmith-engine/utils/index.d.ts +0 -1
  59. package/build/flagsmith-engine/utils/index.js +0 -14
  60. package/build/index.d.ts +0 -1
  61. package/build/index.js +0 -11
  62. package/build/sdk/analytics.d.ts +0 -28
  63. package/build/sdk/analytics.js +0 -102
  64. package/build/sdk/errors.d.ts +0 -4
  65. package/build/sdk/errors.js +0 -34
  66. package/build/sdk/index.d.ts +0 -123
  67. package/build/sdk/index.js +0 -484
  68. package/build/sdk/models.d.ts +0 -55
  69. package/build/sdk/models.js +0 -149
  70. package/build/sdk/polling_manager.d.ts +0 -9
  71. package/build/sdk/polling_manager.js +0 -72
  72. package/build/sdk/types.d.ts +0 -7
  73. package/build/sdk/types.js +0 -2
  74. package/build/sdk/utils.d.ts +0 -12
  75. package/build/sdk/utils.js +0 -94
package/.tool-versions ADDED
@@ -0,0 +1 @@
1
+ nodejs 16.14.0
@@ -51,6 +51,7 @@ export class FeatureStateModel {
51
51
  enabled: boolean;
52
52
  djangoID: number;
53
53
  featurestateUUID: string = uuidv4();
54
+ featureSegment?: FeatureSegment;
54
55
  private value: any;
55
56
  multivariateFeatureStateValues: MultivariateFeatureStateValueModel[] = [];
56
57
 
@@ -79,6 +80,23 @@ export class FeatureStateModel {
79
80
  return this.value;
80
81
  }
81
82
 
83
+ /*
84
+ Returns `True` if `this` is higher segment priority than `other`
85
+ (i.e. has lower value for featureSegment.priority)
86
+ NOTE:
87
+ A segment will be considered higher priority only if:
88
+ 1. `other` does not have a feature segment(i.e: it is an environment feature state or it's a
89
+ feature state with feature segment but from an old document that does not have `featureSegment.priority`)
90
+ but `this` does.
91
+ 2. `other` have a feature segment with high priority
92
+ */
93
+ isHigherSegmentPriority(other: FeatureStateModel): boolean {
94
+ if (!other.featureSegment || !this.featureSegment) {
95
+ return !!this.featureSegment && !other.featureSegment;
96
+ }
97
+ return this.featureSegment.priority < other.featureSegment.priority;
98
+ }
99
+
82
100
  getMultivariateValue(identityID: number | string) {
83
101
  const percentageValue = getHashedPercentateForObjIds([
84
102
  this.djangoID || this.featurestateUUID,
@@ -86,9 +104,9 @@ export class FeatureStateModel {
86
104
  ]);
87
105
 
88
106
  let startPercentage = 0;
89
- const sortedF = this.multivariateFeatureStateValues.sort((a, b) =>
90
- !!(a.id && b.id) ? a.id - b.id : a.mvFsValueUuid > b.mvFsValueUuid ? -1 : 1
91
- );
107
+ const sortedF = this.multivariateFeatureStateValues.sort((a, b) =>{
108
+ return a.id - b.id;
109
+ });
92
110
  for (const myValue of sortedF) {
93
111
  const limit = myValue.percentageAllocation + startPercentage;
94
112
  if (startPercentage <= percentageValue && percentageValue < limit) {
@@ -99,3 +117,11 @@ export class FeatureStateModel {
99
117
  return this.value;
100
118
  }
101
119
  }
120
+
121
+ export class FeatureSegment {
122
+ priority: number;
123
+
124
+ constructor(priority: number) {
125
+ this.priority = priority;
126
+ }
127
+ }
@@ -1,5 +1,6 @@
1
1
  import {
2
2
  FeatureModel,
3
+ FeatureSegment,
3
4
  FeatureStateModel,
4
5
  MultivariateFeatureOptionModel,
5
6
  MultivariateFeatureStateValueModel
@@ -18,6 +19,10 @@ export function buildFeatureStateModel(featuresStateModelJSON: any): FeatureStat
18
19
  featuresStateModelJSON.uuid
19
20
  );
20
21
 
22
+ featureStateModel.featureSegment = featuresStateModelJSON.feature_segment ?
23
+ buildFeatureSegment(featuresStateModelJSON.feature_segment) :
24
+ undefined;
25
+
21
26
  const multivariateFeatureStateValues = featuresStateModelJSON.multivariate_feature_state_values
22
27
  ? featuresStateModelJSON.multivariate_feature_state_values.map((fsv: any) => {
23
28
  const featureOption = new MultivariateFeatureOptionModel(
@@ -36,3 +41,7 @@ export function buildFeatureStateModel(featuresStateModelJSON: any): FeatureStat
36
41
 
37
42
  return featureStateModel;
38
43
  }
44
+
45
+ export function buildFeatureSegment(featureSegmentJSON: any): FeatureSegment {
46
+ return new FeatureSegment(featureSegmentJSON.priority);
47
+ }
@@ -25,15 +25,17 @@ function getIdentityFeatureStatesDict(
25
25
  );
26
26
  for (const matchingSegment of identitySegments) {
27
27
  for (const featureState of matchingSegment.featureStates) {
28
- // note that feature states are stored on the segment in descending priority
29
- // order so we only care that the last one is added
30
- // TODO: can we optimise this?
28
+ if (featureStates[featureState.feature.id]) {
29
+ if (featureStates[featureState.feature.id].isHigherSegmentPriority(featureState)) {
30
+ continue;
31
+ }
32
+ }
31
33
  featureStates[featureState.feature.id] = featureState;
32
34
  }
33
35
  }
34
36
 
35
37
  // Override with any feature states defined directly the identity
36
- for (const fs of identity.identityFeatures || []) {
38
+ for (const fs of identity.identityFeatures) {
37
39
  if (featureStates[fs.feature.id]) {
38
40
  featureStates[fs.feature.id] = fs;
39
41
  }
@@ -1,3 +1,5 @@
1
+ import semver from 'semver';
2
+
1
3
  import { FeatureStateModel } from '../features/models';
2
4
  import { getCastingFunction as getCastingFunction } from '../utils';
3
5
  import {
@@ -8,6 +10,7 @@ import {
8
10
  REGEX,
9
11
  CONDITION_OPERATORS
10
12
  } from './constants';
13
+ import { isSemver } from './util';
11
14
 
12
15
  export const all = (iterable: Array<any>) => iterable.filter(e => !!e).length === iterable.length;
13
16
  export const any = (iterable: Array<any>) => iterable.filter(e => !!e).length > 0;
@@ -25,6 +28,19 @@ export const matchingFunctions = {
25
28
  otherValue.includes(thisValue),
26
29
  };
27
30
 
31
+ export const semverMatchingFunction = {
32
+ ...matchingFunctions,
33
+ [CONDITION_OPERATORS.EQUAL]: (thisValue: any, otherValue: any) => semver.eq(thisValue, otherValue),
34
+ [CONDITION_OPERATORS.GREATER_THAN]: (thisValue: any, otherValue: any) => semver.gt(otherValue, thisValue),
35
+ [CONDITION_OPERATORS.GREATER_THAN_INCLUSIVE]: (thisValue: any, otherValue: any) =>
36
+ semver.gte(otherValue, thisValue),
37
+ [CONDITION_OPERATORS.LESS_THAN]: (thisValue: any, otherValue: any) => semver.gt(thisValue, otherValue),
38
+ [CONDITION_OPERATORS.LESS_THAN_INCLUSIVE]: (thisValue: any, otherValue: any) =>
39
+ semver.gte(thisValue, otherValue),
40
+ }
41
+
42
+ export const getMatchingFunctions = (semver: boolean) => (semver ? semverMatchingFunction : matchingFunctions);
43
+
28
44
  export class SegmentConditionModel {
29
45
  EXCEPTION_OPERATOR_METHODS: { [key: string]: string } = {
30
46
  [NOT_CONTAINS]: 'evaluateNotContains',
@@ -59,9 +75,12 @@ export class SegmentConditionModel {
59
75
 
60
76
  const defaultFunction = (x: any, y: any) => false;
61
77
 
62
- const matchingFunction = matchingFunctions[this.operator] || defaultFunction;
78
+ const matchingFunctionSet = getMatchingFunctions(isSemver(this.value));
79
+ const matchingFunction = matchingFunctionSet[this.operator] || defaultFunction;
80
+
81
+ const traitType = isSemver(this.value) ? 'semver' : typeof traitValue;
82
+ const castToTypeOfTraitValue = getCastingFunction(traitType);
63
83
 
64
- const castToTypeOfTraitValue = getCastingFunction(traitValue);
65
84
  return matchingFunction(castToTypeOfTraitValue(this.value), traitValue);
66
85
  }
67
86
  }
@@ -27,3 +27,11 @@ export function buildSegmentModel(segmentModelJSON: any): SegmentModel {
27
27
 
28
28
  return model;
29
29
  }
30
+
31
+ export function isSemver(value: any) {
32
+ return typeof value == 'string' && value.endsWith(':semver');
33
+ }
34
+
35
+ export function removeSemverSuffix(value: string) {
36
+ return value.replace(':semver', '');
37
+ }
@@ -1,9 +1,13 @@
1
- export function getCastingFunction(input: any): CallableFunction {
2
- switch (typeof input) {
1
+ import { removeSemverSuffix } from "../segments/util";
2
+
3
+ export function getCastingFunction(traitType: 'boolean' | 'string' | 'number' | 'semver' | any): CallableFunction {
4
+ switch (traitType) {
3
5
  case 'boolean':
4
6
  return (x: any) => !['False', 'false'].includes(x);
5
7
  case 'number':
6
8
  return (x: any) => parseFloat(x);
9
+ case 'semver':
10
+ return (x: any) => removeSemverSuffix(x);
7
11
  default:
8
12
  return (x: any) => String(x);
9
13
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flagsmith-nodejs",
3
- "version": "2.0.0-beta.7",
3
+ "version": "2.0.0",
4
4
  "description": "Flagsmith lets you manage features flags and remote config across web, mobile and server side applications. Deliver true Continuous Integration. Get builds out faster. Control who has access to new features.",
5
5
  "main": "build/index.js",
6
6
  "repository": {
@@ -53,12 +53,14 @@
53
53
  "big-integer": "^1.6.51",
54
54
  "md5": "^2.3.0",
55
55
  "node-fetch": "^2.1.2",
56
+ "semver": "^7.3.7",
56
57
  "uuid": "^8.3.2"
57
58
  },
58
59
  "devDependencies": {
59
60
  "@types/jest": "^27.4.1",
60
61
  "@types/md5": "^2.3.2",
61
62
  "@types/node-fetch": "^2.6.1",
63
+ "@types/semver": "^7.3.9",
62
64
  "@types/uuid": "^8.3.4",
63
65
  "esbuild": "^0.14.25",
64
66
  "husky": "^7.0.4",
@@ -67,4 +69,4 @@
67
69
  "ts-jest": "^27.1.3",
68
70
  "typescript": "^4.6.2"
69
71
  }
70
- }
72
+ }
package/sdk/index.ts CHANGED
@@ -14,7 +14,7 @@ import { SegmentModel } from '../flagsmith-engine/segments/models';
14
14
  import { getIdentitySegments } from '../flagsmith-engine/segments/evaluators';
15
15
  import { FlagsmithCache } from './types';
16
16
 
17
- const DEFAULT_API_URL = 'https://api.flagsmith.com/api/v1/';
17
+ const DEFAULT_API_URL = 'https://edge.api.flagsmith.com/api/v1/';
18
18
 
19
19
  export class Flagsmith {
20
20
  environmentKey?: string;
@@ -269,7 +269,6 @@ export class Flagsmith {
269
269
  headers: headers
270
270
  },
271
271
  this.retries,
272
- 1000,
273
272
  (this.requestTimeoutSeconds || 10) * 1000
274
273
  );
275
274
 
package/sdk/utils.ts CHANGED
@@ -2,8 +2,8 @@ import fetch, { Response } from 'node-fetch';
2
2
  // @ts-ignore
3
3
  if (typeof fetch.default !== 'undefined') fetch = fetch.default;
4
4
 
5
- export function generateIdentitiesData(identifier: string, traits?: { [key: string]: any }) {
6
- const traitsGenerated = Object.entries(traits || {}).map(trait => ({
5
+ export function generateIdentitiesData(identifier: string, traits: { [key: string]: any }) {
6
+ const traitsGenerated = Object.entries(traits).map(trait => ({
7
7
  trait_key: trait[0],
8
8
  trait_value: trait[1]
9
9
  }));
@@ -18,9 +18,8 @@ export const delay = (ms: number) =>
18
18
 
19
19
  export const retryFetch = (
20
20
  url: string,
21
- fetchOptions = {},
21
+ fetchOptions: any,
22
22
  retries = 3,
23
- retryDelay = 1000,
24
23
  timeout: number
25
24
  ): Promise<Response> => {
26
25
  return new Promise((resolve, reject) => {
@@ -32,7 +31,7 @@ export const retryFetch = (
32
31
  .then(res => resolve(res))
33
32
  .catch(async err => {
34
33
  if (n > 0) {
35
- await delay(retryDelay);
34
+ await delay(1000);
36
35
  wrapper(--n);
37
36
  } else {
38
37
  reject(err);
@@ -66,7 +66,7 @@ test('test_feature_state_get_value_mv_values', () => {
66
66
  const mvFeatureState = new FeatureStateModel(myFeature, true, 1);
67
67
  mvFeatureState.multivariateFeatureStateValues = [
68
68
  mvFeatureStateValue1,
69
- mvFeatureStateValue2
69
+ mvFeatureStateValue2,
70
70
  ];
71
71
 
72
72
  mvFeatureState.setValue(mvFeatureControlValue);
@@ -62,6 +62,26 @@ const conditionMatchCases: [string, string | number | boolean, string, boolean][
62
62
  [CONDITION_OPERATORS.NOT_CONTAINS, 'bar', 'baz', true],
63
63
  [CONDITION_OPERATORS.REGEX, 'foo', '[a-z]+', true],
64
64
  [CONDITION_OPERATORS.REGEX, 'FOO', '[a-z]+', false],
65
+ [CONDITION_OPERATORS.EQUAL, "1.0.0", "1.0.0:semver", true],
66
+ [CONDITION_OPERATORS.EQUAL, "1.0.0", "1.0.0:semver", true],
67
+ [CONDITION_OPERATORS.EQUAL, "1.0.0", "1.0.1:semver", false],
68
+ [CONDITION_OPERATORS.NOT_EQUAL, "1.0.0", "1.0.0:semver", false],
69
+ [CONDITION_OPERATORS.NOT_EQUAL, "1.0.0", "1.0.1:semver", true],
70
+ [CONDITION_OPERATORS.GREATER_THAN, "1.0.1", "1.0.0:semver", true],
71
+ [CONDITION_OPERATORS.GREATER_THAN, "1.0.0", "1.0.0-beta:semver", true],
72
+ [CONDITION_OPERATORS.GREATER_THAN, "1.0.1", "1.2.0:semver", false],
73
+ [CONDITION_OPERATORS.GREATER_THAN, "1.0.1", "1.0.1:semver", false],
74
+ [CONDITION_OPERATORS.GREATER_THAN, "1.2.4", "1.2.3-pre.2+build.4:semver", true],
75
+ [CONDITION_OPERATORS.LESS_THAN, "1.0.0", "1.0.1:semver", true],
76
+ [CONDITION_OPERATORS.LESS_THAN, "1.0.0", "1.0.0:semver", false],
77
+ [CONDITION_OPERATORS.LESS_THAN, "1.0.1", "1.0.0:semver", false],
78
+ [CONDITION_OPERATORS.LESS_THAN, "1.0.0-rc.2", "1.0.0-rc.3:semver", true],
79
+ [CONDITION_OPERATORS.GREATER_THAN_INCLUSIVE, "1.0.1", "1.0.0:semver", true],
80
+ [CONDITION_OPERATORS.GREATER_THAN_INCLUSIVE, "1.0.1", "1.2.0:semver", false],
81
+ [CONDITION_OPERATORS.GREATER_THAN_INCLUSIVE, "1.0.1", "1.0.1:semver", true],
82
+ [CONDITION_OPERATORS.LESS_THAN_INCLUSIVE, "1.0.0", "1.0.1:semver", true],
83
+ [CONDITION_OPERATORS.LESS_THAN_INCLUSIVE, "1.0.0", "1.0.0:semver", true],
84
+ [CONDITION_OPERATORS.LESS_THAN_INCLUSIVE, "1.0.1", "1.0.0:semver", false],
65
85
  ['BAD_OP', 'a', 'a', false]
66
86
  ];
67
87
 
@@ -1,12 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <module type="WEB_MODULE" version="4">
3
- <component name="NewModuleRootManager">
4
- <content url="file://$MODULE_DIR$">
5
- <excludeFolder url="file://$MODULE_DIR$/temp" />
6
- <excludeFolder url="file://$MODULE_DIR$/.tmp" />
7
- <excludeFolder url="file://$MODULE_DIR$/tmp" />
8
- </content>
9
- <orderEntry type="inheritedJdk" />
10
- <orderEntry type="sourceFolder" forTests="false" />
11
- </component>
12
- </module>
package/.idea/modules.xml DELETED
@@ -1,8 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <project version="4">
3
- <component name="ProjectModuleManager">
4
- <modules>
5
- <module fileurl="file://$PROJECT_DIR$/.idea/flagsmith-nodejs-client.iml" filepath="$PROJECT_DIR$/.idea/flagsmith-nodejs-client.iml" />
6
- </modules>
7
- </component>
8
- </project>
package/.idea/vcs.xml DELETED
@@ -1,6 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <project version="4">
3
- <component name="VcsDirectoryMappings">
4
- <mapping directory="$PROJECT_DIR$" vcs="Git" />
5
- </component>
6
- </project>
@@ -1,4 +0,0 @@
1
- export declare class IntegrationModel {
2
- api_key?: string;
3
- base_url?: string;
4
- }
@@ -1,11 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.IntegrationModel = void 0;
4
- var IntegrationModel = /** @class */ (function () {
5
- function IntegrationModel() {
6
- this.api_key = undefined;
7
- this.base_url = undefined;
8
- }
9
- return IntegrationModel;
10
- }());
11
- exports.IntegrationModel = IntegrationModel;
@@ -1,25 +0,0 @@
1
- import { FeatureStateModel } from '../features/models';
2
- import { ProjectModel } from '../projects/models';
3
- import { IntegrationModel } from './integrations/models';
4
- export declare class EnvironmentAPIKeyModel {
5
- id: number;
6
- key: string;
7
- createdAt: number;
8
- name: string;
9
- clientApiKey: string;
10
- expiresAt?: number;
11
- active: boolean;
12
- constructor(id: number, key: string, createdAt: number, name: string, clientApiKey: string, expiresAt?: number);
13
- isValid(): boolean;
14
- }
15
- export declare class EnvironmentModel {
16
- id: number;
17
- apiKey: string;
18
- project: ProjectModel;
19
- featureStates: FeatureStateModel[];
20
- amplitude_config?: IntegrationModel;
21
- segment_config?: IntegrationModel;
22
- mixpanel_config?: IntegrationModel;
23
- heap_config?: IntegrationModel;
24
- constructor(id: number, apiKey: string, project: ProjectModel);
25
- }
@@ -1,29 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.EnvironmentModel = exports.EnvironmentAPIKeyModel = void 0;
4
- var EnvironmentAPIKeyModel = /** @class */ (function () {
5
- function EnvironmentAPIKeyModel(id, key, createdAt, name, clientApiKey, expiresAt) {
6
- this.active = true;
7
- this.id = id;
8
- this.key = key;
9
- this.createdAt = createdAt;
10
- this.name = name;
11
- this.clientApiKey = clientApiKey;
12
- this.expiresAt = expiresAt;
13
- }
14
- EnvironmentAPIKeyModel.prototype.isValid = function () {
15
- return !!this.active && (!this.expiresAt || this.expiresAt > Date.now());
16
- };
17
- return EnvironmentAPIKeyModel;
18
- }());
19
- exports.EnvironmentAPIKeyModel = EnvironmentAPIKeyModel;
20
- var EnvironmentModel = /** @class */ (function () {
21
- function EnvironmentModel(id, apiKey, project) {
22
- this.featureStates = [];
23
- this.id = id;
24
- this.apiKey = apiKey;
25
- this.project = project;
26
- }
27
- return EnvironmentModel;
28
- }());
29
- exports.EnvironmentModel = EnvironmentModel;
@@ -1,3 +0,0 @@
1
- import { EnvironmentAPIKeyModel, EnvironmentModel } from './models';
2
- export declare function buildEnvironmentModel(environmentJSON: any): EnvironmentModel;
3
- export declare function buildEnvironmentAPIKeyModel(apiKeyJSON: any): EnvironmentAPIKeyModel;
@@ -1,21 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.buildEnvironmentAPIKeyModel = exports.buildEnvironmentModel = void 0;
4
- var util_1 = require("../features/util");
5
- var util_2 = require("../projects/util");
6
- var models_1 = require("./models");
7
- function buildEnvironmentModel(environmentJSON) {
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);
13
- environmentModel.featureStates = featureStates;
14
- return environmentModel;
15
- }
16
- exports.buildEnvironmentModel = buildEnvironmentModel;
17
- function buildEnvironmentAPIKeyModel(apiKeyJSON) {
18
- var model = new models_1.EnvironmentAPIKeyModel(apiKeyJSON.id, apiKeyJSON.key, Date.parse(apiKeyJSON.created_at), apiKeyJSON.name, apiKeyJSON.client_api_key);
19
- return model;
20
- }
21
- exports.buildEnvironmentAPIKeyModel = buildEnvironmentAPIKeyModel;
@@ -1,4 +0,0 @@
1
- export declare const CONSTANTS: {
2
- STANDARD: string;
3
- MULTIVARIATE: string;
4
- };
@@ -1,7 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CONSTANTS = void 0;
4
- exports.CONSTANTS = {
5
- STANDARD: 'STANDARD',
6
- MULTIVARIATE: 'MULTIVARIATE'
7
- };
@@ -1,31 +0,0 @@
1
- export declare class FeatureModel {
2
- id: number;
3
- name: string;
4
- type: string;
5
- constructor(id: number, name: string, type: string);
6
- eq(other: FeatureModel): boolean;
7
- }
8
- export declare class MultivariateFeatureOptionModel {
9
- value: any;
10
- id: number | undefined;
11
- constructor(value: any, id?: number);
12
- }
13
- export declare class MultivariateFeatureStateValueModel {
14
- multivariateFeatureOption: MultivariateFeatureOptionModel;
15
- percentageAllocation: number;
16
- id: number;
17
- mvFsValueUuid: string;
18
- constructor(multivariate_feature_option: MultivariateFeatureOptionModel, percentage_allocation: number, id: number, mvFsValueUuid?: string);
19
- }
20
- export declare class FeatureStateModel {
21
- feature: FeatureModel;
22
- enabled: boolean;
23
- djangoID: number;
24
- featurestateUUID: string;
25
- private value;
26
- multivariateFeatureStateValues: MultivariateFeatureStateValueModel[];
27
- constructor(feature: FeatureModel, enabled: boolean, djangoID: number, value?: any, featurestateUuid?: string);
28
- setValue(value: any): void;
29
- getValue(identityId?: number | string): any;
30
- getMultivariateValue(identityID: number | string): any;
31
- }
@@ -1,99 +0,0 @@
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
- };
13
- Object.defineProperty(exports, "__esModule", { value: true });
14
- exports.FeatureStateModel = exports.MultivariateFeatureStateValueModel = exports.MultivariateFeatureOptionModel = exports.FeatureModel = void 0;
15
- var uuid_1 = require("uuid");
16
- var hashing_1 = require("../utils/hashing");
17
- var FeatureModel = /** @class */ (function () {
18
- function FeatureModel(id, name, type) {
19
- this.id = id;
20
- this.name = name;
21
- this.type = type;
22
- }
23
- FeatureModel.prototype.eq = function (other) {
24
- return !!other && this.id === other.id;
25
- };
26
- return FeatureModel;
27
- }());
28
- exports.FeatureModel = FeatureModel;
29
- var MultivariateFeatureOptionModel = /** @class */ (function () {
30
- function MultivariateFeatureOptionModel(value, id) {
31
- this.value = value;
32
- this.id = id;
33
- }
34
- return MultivariateFeatureOptionModel;
35
- }());
36
- exports.MultivariateFeatureOptionModel = MultivariateFeatureOptionModel;
37
- var MultivariateFeatureStateValueModel = /** @class */ (function () {
38
- function MultivariateFeatureStateValueModel(multivariate_feature_option, percentage_allocation, id, mvFsValueUuid) {
39
- this.mvFsValueUuid = (0, uuid_1.v4)();
40
- this.id = id;
41
- this.percentageAllocation = percentage_allocation;
42
- this.multivariateFeatureOption = multivariate_feature_option;
43
- this.mvFsValueUuid = mvFsValueUuid || this.mvFsValueUuid;
44
- }
45
- return MultivariateFeatureStateValueModel;
46
- }());
47
- exports.MultivariateFeatureStateValueModel = MultivariateFeatureStateValueModel;
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 = [];
53
- this.feature = feature;
54
- this.enabled = enabled;
55
- this.djangoID = djangoID;
56
- this.value = value;
57
- this.featurestateUUID = featurestateUuid;
58
- }
59
- FeatureStateModel.prototype.setValue = function (value) {
60
- this.value = value;
61
- };
62
- FeatureStateModel.prototype.getValue = function (identityId) {
63
- if (!!identityId && this.multivariateFeatureStateValues.length > 0) {
64
- return this.getMultivariateValue(identityId);
65
- }
66
- return this.value;
67
- };
68
- FeatureStateModel.prototype.getMultivariateValue = function (identityID) {
69
- var e_1, _a;
70
- var percentageValue = (0, hashing_1.getHashedPercentateForObjIds)([
71
- this.djangoID || this.featurestateUUID,
72
- identityID
73
- ]);
74
- var startPercentage = 0;
75
- var sortedF = this.multivariateFeatureStateValues.sort(function (a, b) {
76
- return !!(a.id && b.id) ? a.id - b.id : a.mvFsValueUuid > b.mvFsValueUuid ? -1 : 1;
77
- });
78
- try {
79
- for (var sortedF_1 = __values(sortedF), sortedF_1_1 = sortedF_1.next(); !sortedF_1_1.done; sortedF_1_1 = sortedF_1.next()) {
80
- var myValue = sortedF_1_1.value;
81
- var limit = myValue.percentageAllocation + startPercentage;
82
- if (startPercentage <= percentageValue && percentageValue < limit) {
83
- return myValue.multivariateFeatureOption.value;
84
- }
85
- startPercentage = limit;
86
- }
87
- }
88
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
89
- finally {
90
- try {
91
- if (sortedF_1_1 && !sortedF_1_1.done && (_a = sortedF_1.return)) _a.call(sortedF_1);
92
- }
93
- finally { if (e_1) throw e_1.error; }
94
- }
95
- return this.value;
96
- };
97
- return FeatureStateModel;
98
- }());
99
- exports.FeatureStateModel = FeatureStateModel;
@@ -1,3 +0,0 @@
1
- import { FeatureModel, FeatureStateModel } from './models';
2
- export declare function buildFeatureModel(featuresModelJSON: any): FeatureModel;
3
- export declare function buildFeatureStateModel(featuresStateModelJSON: any): FeatureStateModel;
@@ -1,20 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.buildFeatureStateModel = exports.buildFeatureModel = void 0;
4
- var models_1 = require("./models");
5
- function buildFeatureModel(featuresModelJSON) {
6
- return new models_1.FeatureModel(featuresModelJSON.id, featuresModelJSON.name, featuresModelJSON.type);
7
- }
8
- exports.buildFeatureModel = buildFeatureModel;
9
- function buildFeatureStateModel(featuresStateModelJSON) {
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
- return new models_1.MultivariateFeatureStateValueModel(featureOption, fsv.percentage_allocation, fsv.id);
15
- })
16
- : [];
17
- featureStateModel.multivariateFeatureStateValues = multivariateFeatureStateValues;
18
- return featureStateModel;
19
- }
20
- exports.buildFeatureStateModel = buildFeatureStateModel;
@@ -1,15 +0,0 @@
1
- import { IdentityFeaturesList } from '../utils/collections';
2
- import { TraitModel } from './traits/models';
3
- export declare class IdentityModel {
4
- identifier: string;
5
- environmentApiKey: string;
6
- createdDate?: number;
7
- identityFeatures: IdentityFeaturesList;
8
- identityTraits: TraitModel[];
9
- identityUuid: string;
10
- djangoID: number | undefined;
11
- constructor(created_date: string, identityTraits: TraitModel[], identityFeatures: IdentityFeaturesList, environmentApiKey: string, identifier: string, identityUuid?: string);
12
- get compositeKey(): string;
13
- static generateCompositeKey(env_key: string, identifier: string): string;
14
- updateTraits(traits: TraitModel[]): void;
15
- }