flagsmith-nodejs 2.3.0 → 2.4.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 (29) hide show
  1. package/build/flagsmith-engine/segments/constants.d.ts +6 -0
  2. package/build/flagsmith-engine/segments/constants.js +8 -2
  3. package/build/flagsmith-engine/segments/evaluators.d.ts +2 -1
  4. package/build/flagsmith-engine/segments/evaluators.js +9 -2
  5. package/build/flagsmith-engine/segments/models.d.ts +3 -3
  6. package/build/flagsmith-engine/segments/models.js +26 -1
  7. package/examples/caching/package-lock.json +2488 -6600
  8. package/examples/caching/package.json +1 -1
  9. package/examples/custom-fetch-agent/package-lock.json +2583 -6609
  10. package/examples/custom-fetch-agent/package.json +1 -1
  11. package/examples/local-evaluation/package-lock.json +2493 -6601
  12. package/examples/local-evaluation/package.json +1 -1
  13. package/flagsmith-engine/segments/constants.ts +7 -1
  14. package/flagsmith-engine/segments/evaluators.ts +10 -6
  15. package/flagsmith-engine/segments/models.ts +15 -5
  16. package/package.json +1 -1
  17. package/tests/engine/engine-tests/engine-test-data/data/environment_n9fbf9h3v4fFgH3U3ngWhb.json +12591 -0
  18. package/tests/engine/engine-tests/engine-test-data/readme.md +30 -0
  19. package/tests/engine/unit/segments/segment_evaluators.test.ts +27 -0
  20. package/tests/engine/unit/segments/segments_model.test.ts +8 -1
  21. package/.idea/flagsmith-nodejs-client.iml +0 -12
  22. package/.idea/modules.xml +0 -8
  23. package/.idea/vcs.xml +0 -6
  24. package/examples/api-proxy/.idea/api-proxy.iml +0 -12
  25. package/examples/api-proxy/.idea/codeStyles/Project.xml +0 -60
  26. package/examples/api-proxy/.idea/codeStyles/codeStyleConfig.xml +0 -5
  27. package/examples/api-proxy/.idea/inspectionProfiles/Project_Default.xml +0 -6
  28. package/examples/api-proxy/.idea/modules.xml +0 -8
  29. 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
+ });
@@ -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>