flagsmith-nodejs 2.3.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.
Files changed (35) hide show
  1. package/.vscode/launch.json +18 -0
  2. package/build/flagsmith-engine/segments/constants.d.ts +6 -0
  3. package/build/flagsmith-engine/segments/constants.js +8 -2
  4. package/build/flagsmith-engine/segments/evaluators.d.ts +2 -1
  5. package/build/flagsmith-engine/segments/evaluators.js +9 -2
  6. package/build/flagsmith-engine/segments/models.d.ts +3 -3
  7. package/build/flagsmith-engine/segments/models.js +26 -1
  8. package/build/sdk/index.js +2 -1
  9. package/examples/caching/package-lock.json +2488 -6600
  10. package/examples/caching/package.json +1 -1
  11. package/examples/custom-fetch-agent/package-lock.json +2583 -6609
  12. package/examples/custom-fetch-agent/package.json +1 -1
  13. package/examples/local-evaluation/package-lock.json +2493 -6601
  14. package/examples/local-evaluation/package.json +1 -1
  15. package/flagsmith-engine/segments/constants.ts +7 -1
  16. package/flagsmith-engine/segments/evaluators.ts +10 -6
  17. package/flagsmith-engine/segments/models.ts +15 -5
  18. package/package.json +1 -1
  19. package/sdk/index.ts +2 -1
  20. package/tests/engine/engine-tests/engine-test-data/data/environment_n9fbf9h3v4fFgH3U3ngWhb.json +12591 -0
  21. package/tests/engine/engine-tests/engine-test-data/readme.md +30 -0
  22. package/tests/engine/unit/segments/segment_evaluators.test.ts +27 -0
  23. package/tests/engine/unit/segments/segments_model.test.ts +8 -1
  24. package/tests/sdk/data/environment.json +23 -1
  25. package/tests/sdk/flagsmith-identity-flags.test.ts +18 -1
  26. package/tests/sdk/flagsmith.test.ts +25 -9
  27. package/.idea/flagsmith-nodejs-client.iml +0 -12
  28. package/.idea/modules.xml +0 -8
  29. package/.idea/vcs.xml +0 -6
  30. package/examples/api-proxy/.idea/api-proxy.iml +0 -12
  31. package/examples/api-proxy/.idea/codeStyles/Project.xml +0 -60
  32. package/examples/api-proxy/.idea/codeStyles/codeStyleConfig.xml +0 -5
  33. package/examples/api-proxy/.idea/inspectionProfiles/Project_Default.xml +0 -6
  34. package/examples/api-proxy/.idea/modules.xml +0 -8
  35. package/examples/api-proxy/.idea/vcs.xml +0 -6
@@ -0,0 +1,30 @@
1
+ # Engine Test Data
2
+
3
+ This repository contains a single directory containing json files that can be used to test that any Flagsmith engine
4
+ written in a given language is correct.
5
+
6
+ Each JSON file should consist of a single object in the following format.
7
+
8
+ ```json
9
+ {
10
+ "environment": {...}, // the environment document as found in DynamoDB
11
+ "identities_and_responses": [
12
+ {
13
+ "identity": {...}, // the identity as found in DynamoDB,
14
+ "response": {...}, // the response that was obtained from the current API
15
+ }
16
+ ]
17
+ }
18
+ ```
19
+
20
+ To use this data, you will need to write a test case in the repository which contains the engine code and include
21
+ this repository as a submodule to get access to the json files.
22
+
23
+ To add the git submodule:
24
+
25
+ ```bash
26
+ git submodule add git@github.com:Flagsmith/engine-test-data.git tests/engine_tests/engine-test-data
27
+ ```
28
+
29
+ An example of how to use the test data can be found in the flagsmith-flag-engine repository
30
+ [here](https://github.com/Flagsmith/flagsmith-engine/blob/main/tests/engine_tests/test_engine.py).
@@ -0,0 +1,27 @@
1
+ import {
2
+ CONDITION_OPERATORS,
3
+ } from '../../../../flagsmith-engine/segments/constants';
4
+ import {
5
+ SegmentConditionModel,
6
+ } from '../../../../flagsmith-engine/segments/models';
7
+ import {traitsMatchSegmentCondition} from "../../../../flagsmith-engine/segments/evaluators";
8
+ import {TraitModel} from "../../../../flagsmith-engine";
9
+
10
+ let traitExistenceTestCases: [string, string | null | undefined, string | null | undefined, TraitModel [],boolean][] = [
11
+ [CONDITION_OPERATORS.IS_SET,'foo', null,[] , false],
12
+ [CONDITION_OPERATORS.IS_SET, 'foo',undefined , [new TraitModel('foo','bar')], true],
13
+ [CONDITION_OPERATORS.IS_SET, 'foo',undefined , [new TraitModel('foo','bar'), new TraitModel('fooBaz','baz')], true],
14
+ [CONDITION_OPERATORS.IS_NOT_SET, 'foo', undefined, [], true],
15
+ [CONDITION_OPERATORS.IS_NOT_SET, 'foo', null, [new TraitModel('foo','bar')], false],
16
+ [CONDITION_OPERATORS.IS_NOT_SET, 'foo', null, [new TraitModel('foo','bar'), new TraitModel('fooBaz','baz')], false]
17
+ ];
18
+
19
+ test('test_traits_match_segment_condition_for_trait_existence_operators', () => {
20
+ for (const testCase of traitExistenceTestCases) {
21
+ const [operator, conditionProperty, conditionValue, traits, expectedResult] = testCase
22
+ let segmentModel = new SegmentConditionModel(operator, conditionValue, conditionProperty)
23
+ expect(
24
+ traitsMatchSegmentCondition (traits, segmentModel, 'any','any')
25
+ ).toBe(expectedResult);
26
+ }
27
+ });
@@ -82,6 +82,13 @@ const conditionMatchCases: [string, string | number | boolean, string, boolean][
82
82
  [CONDITION_OPERATORS.LESS_THAN_INCLUSIVE, "1.0.0", "1.0.1:semver", true],
83
83
  [CONDITION_OPERATORS.LESS_THAN_INCLUSIVE, "1.0.0", "1.0.0:semver", true],
84
84
  [CONDITION_OPERATORS.LESS_THAN_INCLUSIVE, "1.0.1", "1.0.0:semver", false],
85
+ [CONDITION_OPERATORS.MODULO, 1, "2|0", false],
86
+ [CONDITION_OPERATORS.MODULO, 2, "2|0", true],
87
+ [CONDITION_OPERATORS.MODULO, 3, "2|0", false],
88
+ [CONDITION_OPERATORS.MODULO, 34.2, "4|3", false],
89
+ [CONDITION_OPERATORS.MODULO, 35.0, "4|3", true],
90
+ [CONDITION_OPERATORS.MODULO, "foo", "4|3", false],
91
+ [CONDITION_OPERATORS.MODULO, 35.0, "foo|bar", false],
85
92
  ['BAD_OP', 'a', 'a', false]
86
93
  ];
87
94
 
@@ -119,4 +126,4 @@ test('test_segment_rule_matching_function', () => {
119
126
  for (const testCase of testCases) {
120
127
  expect(new SegmentRuleModel(testCase[0]).matchingFunction()).toBe(testCase[1]);
121
128
  }
122
- });
129
+ });
@@ -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
+ }
@@ -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,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>
@@ -1,60 +0,0 @@
1
- <component name="ProjectCodeStyleConfiguration">
2
- <code_scheme name="Project" version="173">
3
- <HTMLCodeStyleSettings>
4
- <option name="HTML_SPACE_INSIDE_EMPTY_TAG" value="true" />
5
- <option name="HTML_KEEP_WHITESPACES_INSIDE" value="pre,textarea" />
6
- <option name="HTML_ENFORCE_QUOTES" value="true" />
7
- <option name="HTML_NEWLINE_AFTER_LAST_ATTRIBUTE" value="When multiline" />
8
- </HTMLCodeStyleSettings>
9
- <JSCodeStyleSettings version="0">
10
- <option name="FORCE_SEMICOLON_STYLE" value="true" />
11
- <option name="SPACE_BEFORE_FUNCTION_LEFT_PARENTH" value="false" />
12
- <option name="FORCE_QUOTE_STYlE" value="true" />
13
- <option name="ENFORCE_TRAILING_COMMA" value="Remove" />
14
- <option name="SPACES_WITHIN_OBJECT_LITERAL_BRACES" value="true" />
15
- <option name="SPACES_WITHIN_IMPORTS" value="true" />
16
- </JSCodeStyleSettings>
17
- <TypeScriptCodeStyleSettings version="0">
18
- <option name="FORCE_SEMICOLON_STYLE" value="true" />
19
- <option name="SPACE_BEFORE_FUNCTION_LEFT_PARENTH" value="false" />
20
- <option name="FORCE_QUOTE_STYlE" value="true" />
21
- <option name="ENFORCE_TRAILING_COMMA" value="Remove" />
22
- <option name="SPACES_WITHIN_OBJECT_LITERAL_BRACES" value="true" />
23
- <option name="SPACES_WITHIN_IMPORTS" value="true" />
24
- </TypeScriptCodeStyleSettings>
25
- <VueCodeStyleSettings>
26
- <option name="INTERPOLATION_NEW_LINE_AFTER_START_DELIMITER" value="false" />
27
- <option name="INTERPOLATION_NEW_LINE_BEFORE_END_DELIMITER" value="false" />
28
- </VueCodeStyleSettings>
29
- <codeStyleSettings language="HTML">
30
- <option name="SOFT_MARGINS" value="80" />
31
- <indentOptions>
32
- <option name="INDENT_SIZE" value="2" />
33
- <option name="CONTINUATION_INDENT_SIZE" value="2" />
34
- <option name="TAB_SIZE" value="2" />
35
- </indentOptions>
36
- </codeStyleSettings>
37
- <codeStyleSettings language="JavaScript">
38
- <option name="SOFT_MARGINS" value="80" />
39
- <indentOptions>
40
- <option name="INDENT_SIZE" value="2" />
41
- <option name="CONTINUATION_INDENT_SIZE" value="2" />
42
- <option name="TAB_SIZE" value="2" />
43
- </indentOptions>
44
- </codeStyleSettings>
45
- <codeStyleSettings language="TypeScript">
46
- <option name="SOFT_MARGINS" value="80" />
47
- <indentOptions>
48
- <option name="INDENT_SIZE" value="2" />
49
- <option name="CONTINUATION_INDENT_SIZE" value="2" />
50
- <option name="TAB_SIZE" value="2" />
51
- </indentOptions>
52
- </codeStyleSettings>
53
- <codeStyleSettings language="Vue">
54
- <option name="SOFT_MARGINS" value="80" />
55
- <indentOptions>
56
- <option name="CONTINUATION_INDENT_SIZE" value="2" />
57
- </indentOptions>
58
- </codeStyleSettings>
59
- </code_scheme>
60
- </component>
@@ -1,5 +0,0 @@
1
- <component name="ProjectCodeStyleConfiguration">
2
- <state>
3
- <option name="USE_PER_PROJECT_SETTINGS" value="true" />
4
- </state>
5
- </component>
@@ -1,6 +0,0 @@
1
- <component name="InspectionProjectProfileManager">
2
- <profile version="1.0">
3
- <option name="myName" value="Project Default" />
4
- <inspection_tool class="Eslint" enabled="true" level="WARNING" enabled_by_default="true" />
5
- </profile>
6
- </component>
@@ -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/api-proxy.iml" filepath="$PROJECT_DIR$/.idea/api-proxy.iml" />
6
- </modules>
7
- </component>
8
- </project>
@@ -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>