flagsmith-nodejs 2.4.0 → 2.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,18 @@
1
+ {
2
+ "version": "1.0.0",
3
+ "configurations": [
4
+ {
5
+ "type": "node",
6
+ "request": "launch",
7
+ "name": "Jest: current file",
8
+ //"env": { "NODE_ENV": "test" },
9
+ "program": "${workspaceFolder}/node_modules/.bin/jest",
10
+ "args": ["${file}", "--config", "jest.config.js"],
11
+ "console": "integratedTerminal",
12
+ "disableOptimisticBPs": true,
13
+ "windows": {
14
+ "program": "${workspaceFolder}/node_modules/jest/bin/jest"
15
+ }
16
+ }
17
+ ]
18
+ }
@@ -415,7 +415,8 @@ var Flagsmith = /** @class */ (function () {
415
415
  flags = models_3.Flags.fromFeatureStateModels({
416
416
  featureStates: featureStates,
417
417
  analyticsProcessor: this.analyticsProcessor,
418
- defaultFlagHandler: this.defaultFlagHandler
418
+ defaultFlagHandler: this.defaultFlagHandler,
419
+ identityID: identityModel.djangoID || identityModel.identityUuid
419
420
  });
420
421
  if (!!!this.cache) return [3 /*break*/, 2];
421
422
  // @ts-ignore node-cache types are incorrect, ttl should be optional
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flagsmith-nodejs",
3
- "version": "2.4.0",
3
+ "version": "2.4.1",
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": {
package/sdk/index.ts CHANGED
@@ -323,7 +323,8 @@ export class Flagsmith {
323
323
  const flags = Flags.fromFeatureStateModels({
324
324
  featureStates: featureStates,
325
325
  analyticsProcessor: this.analyticsProcessor,
326
- defaultFlagHandler: this.defaultFlagHandler
326
+ defaultFlagHandler: this.defaultFlagHandler,
327
+ identityID: identityModel.djangoID || identityModel.identityUuid
327
328
  });
328
329
 
329
330
  if (!!this.cache) {
@@ -63,8 +63,30 @@
63
63
  "type": "STANDARD",
64
64
  "id": 1
65
65
  },
66
- "segment_id": null,
66
+ "feature_segment": null,
67
67
  "enabled": true
68
+ },
69
+ {
70
+ "multivariate_feature_state_values": [
71
+ {
72
+ "percentage_allocation": 100,
73
+ "multivariate_feature_option": {
74
+ "value": "bar",
75
+ "id": 1
76
+ },
77
+ "mv_fs_value_uuid": "42d5cdf9-8ec9-4b8d-a3ca-fd43c64d5f05",
78
+ "id": 1
79
+ }
80
+ ],
81
+ "feature_state_value": "foo",
82
+ "feature": {
83
+ "name": "mv_feature",
84
+ "type": "MULTIVARIATE",
85
+ "id": 2
86
+ },
87
+ "feature_segment": null,
88
+ "featurestate_uuid": "96fc3503-09d7-48f1-a83b-2dc903d5c08a",
89
+ "enabled": false
68
90
  }
69
91
  ]
70
92
  }
@@ -27,7 +27,7 @@ test('test_get_identity_flags_calls_api_when_no_local_environment_no_traits', as
27
27
  expect(identityFlags[0].featureName).toBe('some_feature');
28
28
  });
29
29
 
30
- test('test_get_identity_flags_calls_api_when_local_environment_no_traits', async () => {
30
+ test('test_get_identity_flags_uses_environment_when_local_environment_no_traits', async () => {
31
31
  // @ts-ignore
32
32
  fetch.mockReturnValue(Promise.resolve(new Response(environmentJSON())));
33
33
  const identifier = 'identifier';
@@ -138,3 +138,20 @@ test('test_default_flag_is_used_when_no_identity_flags_returned_and_no_custom_de
138
138
  expect(flag.enabled).toBe(false);
139
139
  });
140
140
 
141
+
142
+ test('test_get_identity_flags_multivariate_value_with_local_evaluation_enabled', async () => {
143
+ // @ts-ignore
144
+ fetch.mockReturnValue(Promise.resolve(new Response(environmentJSON())));
145
+ const identifier = 'identifier';
146
+
147
+ const flg = flagsmith({
148
+ environmentKey: 'ser.key',
149
+ enableLocalEvaluation: true,
150
+
151
+ });
152
+
153
+ const identityFlags = (await flg.getIdentityFlags(identifier))
154
+
155
+ expect(identityFlags.getFeatureValue('mv_feature')).toBe('bar');
156
+ expect(identityFlags.isFeatureEnabled('mv_feature')).toBe(false);
157
+ });
@@ -45,16 +45,11 @@ test('test_update_environment_sets_environment', async () => {
45
45
  await flg.updateEnvironment();
46
46
  expect(flg.environment).toBeDefined();
47
47
 
48
- // @ts-ignore
49
- flg.environment.featureStates[0].featurestateUUID = undefined;
50
- // @ts-ignore
51
- flg.environment.project.segments[0].featureStates[0].featurestateUUID = undefined;
52
- // @ts-ignore
53
48
  const model = environmentModel(JSON.parse(environmentJSON()));
54
- // @ts-ignore
55
- model.featureStates[0].featurestateUUID = undefined;
56
- // @ts-ignore
57
- model.project.segments[0].featureStates[0].featurestateUUID = undefined;
49
+
50
+ wipeFeatureStateUUIDs(flg.environment)
51
+ wipeFeatureStateUUIDs(model)
52
+
58
53
  expect(flg.environment).toStrictEqual(model);
59
54
  });
60
55
 
@@ -231,3 +226,24 @@ test('test onEnvironmentChange is called after error', async () => {
231
226
 
232
227
  expect(callbackSpy).toBeCalled();
233
228
  });
229
+
230
+
231
+
232
+ async function wipeFeatureStateUUIDs (enviromentModel: EnvironmentModel) {
233
+ // TODO: this has been pulled out of tests above as a helper function.
234
+ // I'm not entirely sure why it's necessary, however, we should look to remove.
235
+ enviromentModel.featureStates.forEach(fs => {
236
+ // @ts-ignore
237
+ fs.featurestateUUID = undefined;
238
+ fs.multivariateFeatureStateValues.forEach(mvfsv => {
239
+ // @ts-ignore
240
+ mvfsv.mvFsValueUuid = undefined;
241
+ })
242
+ });
243
+ enviromentModel.project.segments.forEach(s => {
244
+ s.featureStates.forEach(fs => {
245
+ // @ts-ignore
246
+ fs.featurestateUUID = undefined;
247
+ })
248
+ })
249
+ }