@splitsoftware/splitio 10.16.0 → 10.16.2-rc.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 (67) hide show
  1. package/CHANGES.txt +9 -0
  2. package/CONTRIBUTORS-GUIDE.md +13 -12
  3. package/README.md +2 -1
  4. package/es/client/attributesDecoration.js +116 -0
  5. package/es/client/browser.js +2 -2
  6. package/es/engine/engine/murmur3/murmur3_128.js +1 -1
  7. package/es/engine/engine/murmur3/murmur3_128_x86.js +2 -3
  8. package/es/engine/evaluator/index.js +3 -4
  9. package/es/engine/matchers/index.js +20 -37
  10. package/es/engine/matchers/types.js +19 -72
  11. package/es/engine/transforms/matcherGroup.js +2 -2
  12. package/es/engine/transforms/matchers.js +2 -2
  13. package/es/engine/value/sanitize.js +12 -14
  14. package/es/impressions/hasher/hashImpression128.js +1 -1
  15. package/es/impressions/observer/observer.js +0 -1
  16. package/es/producer/updater/SplitChangesFromObject.js +3 -2
  17. package/es/storage/AttributesCache/InMemory.js +84 -0
  18. package/es/sync/PushManager/index.js +3 -11
  19. package/es/utils/inputValidation/attribute.js +22 -0
  20. package/es/utils/inputValidation/attributes.js +9 -0
  21. package/es/utils/logger/LoggerFactory.js +23 -16
  22. package/es/utils/settings/index.js +1 -1
  23. package/es/utils/settings/storage/browser.js +19 -4
  24. package/lib/client/attributesDecoration.js +128 -0
  25. package/lib/client/browser.js +5 -5
  26. package/lib/engine/engine/murmur3/murmur3_128.js +1 -1
  27. package/lib/engine/engine/murmur3/murmur3_128_x86.js +2 -3
  28. package/lib/engine/evaluator/index.js +3 -5
  29. package/lib/engine/matchers/index.js +21 -39
  30. package/lib/engine/matchers/types.js +23 -77
  31. package/lib/engine/transforms/matcherGroup.js +3 -3
  32. package/lib/engine/transforms/matchers.js +22 -22
  33. package/lib/engine/value/sanitize.js +11 -13
  34. package/lib/impressions/hasher/hashImpression128.js +2 -2
  35. package/lib/impressions/observer/observer.js +0 -1
  36. package/lib/producer/updater/SplitChangesFromObject.js +4 -2
  37. package/lib/storage/AttributesCache/InMemory.js +92 -0
  38. package/lib/sync/PushManager/index.js +3 -11
  39. package/lib/utils/inputValidation/attribute.js +32 -0
  40. package/lib/utils/inputValidation/attributes.js +12 -0
  41. package/lib/utils/logger/LoggerFactory.js +23 -17
  42. package/lib/utils/settings/index.js +1 -1
  43. package/lib/utils/settings/storage/browser.js +18 -3
  44. package/package.json +17 -17
  45. package/src/client/attributesDecoration.js +112 -0
  46. package/src/client/browser.js +2 -2
  47. package/src/engine/engine/murmur3/murmur3_128.js +1 -1
  48. package/src/engine/engine/murmur3/murmur3_128_x86.js +2 -3
  49. package/src/engine/evaluator/index.js +3 -4
  50. package/src/engine/matchers/index.js +22 -36
  51. package/src/engine/matchers/types.js +20 -55
  52. package/src/engine/transforms/matcherGroup.js +2 -5
  53. package/src/engine/transforms/matchers.js +2 -6
  54. package/src/engine/value/sanitize.js +12 -17
  55. package/src/impressions/hasher/hashImpression128.js +1 -1
  56. package/src/impressions/observer/observer.js +0 -2
  57. package/src/producer/updater/SplitChangesFromObject.js +2 -2
  58. package/src/storage/AttributesCache/InMemory.js +75 -0
  59. package/src/sync/PushManager/index.js +3 -10
  60. package/src/sync/constants.js +1 -1
  61. package/src/utils/inputValidation/attribute.js +22 -0
  62. package/src/utils/inputValidation/attributes.js +14 -0
  63. package/src/utils/logger/LoggerFactory.js +25 -16
  64. package/src/utils/settings/index.js +1 -1
  65. package/src/utils/settings/storage/browser.js +18 -3
  66. package/types/index.d.ts +1 -1
  67. package/types/splitio.d.ts +102 -27
package/CHANGES.txt CHANGED
@@ -1,3 +1,12 @@
1
+ 10.17.0 (January XXX, 2022)
2
+ - Added Attribute binding feature to allow to optionally keep user attributes loaded within the SDK, along with the user ID, for easier usage when requesting flag.
3
+ - Bugfixing - Fixed issue returning dynamic configs if treatment name contains a dot (".")
4
+
5
+ 10.16.1 (October 25, 2021)
6
+ - Updated some internal modules to optimize the time efficiency of split evaluations (i.e., `getTreatment(s)` method calls).
7
+ - Updated some dependencies for vulnerability fixes (ioredis, @babel/cli, eslint, eslint-plugin-compat).
8
+ - Bugfixing - Fixed localhost mode with localStorage, to use a mock in memory instead of localStorage API directly but keep emitting emit SDK_READY_FROM_CACHE event.
9
+
1
10
  10.16.0 (September 28, 2021)
2
11
  - Updated localhost mode to emit SDK_READY_FROM_CACHE event in Browser when using localStorage (issue https://github.com/splitio/react-client/issues/34).
3
12
  - Updated streaming logic to use the newest version of our streaming service, including:
@@ -7,18 +7,19 @@ Split SDK is an open source project and we welcome feedback and contribution. Th
7
7
  ### Development process
8
8
 
9
9
  1. Fork the repository and create a topic branch from `development` branch. Please use a descriptive name for your branch.
10
- 2. While developing, use descriptive messages in your commits. Avoid short or meaningless sentences like: "fix bug".
11
- 3. Make sure to add tests for both positive and negative cases.
12
- 4. If your changes have any impact on the public API, make sure you update the TypeScript delcarations as well as it's related test file.
13
- 5. Run the linter script of the project and fix any issues you find.
14
- 6. Run the build script and make sure it runs with no errors.
15
- 7. Run all tests and make sure there are no failures.
16
- 8. Run the TypeScript declarations tests and make sure it compiles correctly.
17
- 9. `git push` your changes to GitHub within your topic branch.
18
- 10. Open a Pull Request(PR) from your forked repo and into the `development` branch of the original repository.
19
- 11. When creating your PR, please fill out all the fields of the PR template, as applicable, for the project.
20
- 12. Check for conflicts once the pull request is created to make sure your PR can be merged cleanly into `development`.
21
- 13. Keep an eye out for any feedback or comments from Split's SDK team.
10
+ 2. Run `nvm use` to ensure that you are using the right npm and node version, and `npm install` to have the dependencies up to date.
11
+ 3. While developing, use descriptive messages in your commits. Avoid short or meaningless sentences like: "fix bug".
12
+ 4. Make sure to add tests for both positive and negative cases.
13
+ 5. If your changes have any impact on the public API, make sure you update the TypeScript delcarations as well as it's related test file.
14
+ 6. Run the linter script of the project and fix any issues you find.
15
+ 7. Run the build script and make sure it runs with no errors.
16
+ 8. Run all tests and make sure there are no failures.
17
+ 9. Run the TypeScript declarations tests and make sure it compiles correctly.
18
+ 10. `git push` your changes to GitHub within your topic branch.
19
+ 11. Open a Pull Request(PR) from your forked repo and into the `development` branch of the original repository.
20
+ 12. When creating your PR, please fill out all the fields of the PR template, as applicable, for the project.
21
+ 13. Check for conflicts once the pull request is created to make sure your PR can be merged cleanly into `development`.
22
+ 14. Keep an eye out for any feedback or comments from Split's SDK team.
22
23
 
23
24
  ### Building the SDK
24
25
 
package/README.md CHANGED
@@ -68,11 +68,12 @@ Split has built and maintains SDKs for:
68
68
  * iOS [Github](https://github.com/splitio/ios-client) [Docs](https://help.split.io/hc/en-us/articles/360020401491-iOS-SDK)
69
69
  * Java [Github](https://github.com/splitio/java-client) [Docs](https://help.split.io/hc/en-us/articles/360020405151-Java-SDK)
70
70
  * Javascript [Github](https://github.com/splitio/javascript-client) [Docs](https://help.split.io/hc/en-us/articles/360020448791-JavaScript-SDK)
71
+ * Javascript for Browser [Github](https://github.com/splitio/javascript-browser-client) [Docs](https://help.split.io/hc/en-us/articles/360058730852-Browser-SDK)
71
72
  * Node [Github](https://github.com/splitio/javascript-client) [Docs](https://help.split.io/hc/en-us/articles/360020564931-Node-js-SDK)
72
- * Javascript for Browser [Github](https://github.com/splitio/javascript-browser-client) [Docs](https://help.split.io/hc/en-us/articles/360058730852)
73
73
  * PHP [Github](https://github.com/splitio/php-client) [Docs](https://help.split.io/hc/en-us/articles/360020350372-PHP-SDK)
74
74
  * Python [Github](https://github.com/splitio/python-client) [Docs](https://help.split.io/hc/en-us/articles/360020359652-Python-SDK)
75
75
  * React [Github](https://github.com/splitio/react-client) [Docs](https://help.split.io/hc/en-us/articles/360038825091-React-SDK)
76
+ * React Native [Github](https://github.com/splitio/react-native-client) [Docs](https://help.split.io/hc/en-us/articles/4406066357901-React-Native-SDK)
76
77
  * Redux [Github](https://github.com/splitio/redux-client) [Docs](https://help.split.io/hc/en-us/articles/360038851551-Redux-SDK)
77
78
  * Ruby [Github](https://github.com/splitio/ruby-client) [Docs](https://help.split.io/hc/en-us/articles/360020673251-Ruby-SDK)
78
79
 
@@ -0,0 +1,116 @@
1
+ import ClientInputValidationLayer from './inputValidation';
2
+ import AttributesCacheInMemory from '../storage/AttributesCache/InMemory';
3
+ import { validateAttributesDeep } from '../utils/inputValidation/attributes';
4
+ import logFactory from '../utils/logger';
5
+ import objectAssign from 'object-assign';
6
+ var log = logFactory('splitio-client');
7
+ /**
8
+ * Add in memory attributes storage methods and combine them with any attribute received from the getTreatment/s call
9
+ */
10
+
11
+ export default function ClientAttributesDecorationLayer(context, isKeyBinded, isTTBinded) {
12
+ var client = ClientInputValidationLayer(context, isKeyBinded, isTTBinded);
13
+ var attributeStorage = new AttributesCacheInMemory(); // Keep a reference to the original methods
14
+
15
+ var clientGetTreatment = client.getTreatment;
16
+ var clientGetTreatmentWithConfig = client.getTreatmentWithConfig;
17
+ var clientGetTreatments = client.getTreatments;
18
+ var clientGetTreatmentsWithConfig = client.getTreatmentsWithConfig;
19
+ /**
20
+ * Add an attribute to client's in memory attributes storage
21
+ *
22
+ * @param {string} attributeName Attrinute name
23
+ * @param {string, number, boolean, list} attributeValue Attribute value
24
+ * @returns {boolean} true if the attribute was stored and false otherways
25
+ */
26
+
27
+ client.setAttribute = function (attributeName, attributeValue) {
28
+ var attribute = {};
29
+ attribute[attributeName] = attributeValue;
30
+ if (!validateAttributesDeep(attribute)) return false;
31
+ log.debug("stored " + attributeValue + " for attribute " + attributeName);
32
+ return attributeStorage.setAttribute(attributeName, attributeValue);
33
+ };
34
+ /**
35
+ * Returns the attribute with the given key
36
+ *
37
+ * @param {string} attributeName Attribute name
38
+ * @returns {Object} Attribute with the given key
39
+ */
40
+
41
+
42
+ client.getAttribute = function (attributeName) {
43
+ log.debug("retrieved attribute " + attributeName);
44
+ return attributeStorage.getAttribute(attributeName + '');
45
+ };
46
+ /**
47
+ * Add to client's in memory attributes storage the attributes in 'attributes'
48
+ *
49
+ * @param {Object} attributes Object with attributes to store
50
+ * @returns true if attributes were stored an false otherways
51
+ */
52
+
53
+
54
+ client.setAttributes = function (attributes) {
55
+ if (!validateAttributesDeep(attributes)) return false;
56
+ return attributeStorage.setAttributes(attributes);
57
+ };
58
+ /**
59
+ * Return all the attributes stored in client's in memory attributes storage
60
+ *
61
+ * @returns {Object} returns all the stored attributes
62
+ */
63
+
64
+
65
+ client.getAttributes = function () {
66
+ return attributeStorage.getAll();
67
+ };
68
+ /**
69
+ * Removes from client's in memory attributes storage the attribute with the given key
70
+ *
71
+ * @param {string} attributeName
72
+ * @returns {boolean} true if attribute was removed and false otherways
73
+ */
74
+
75
+
76
+ client.removeAttribute = function (attributeName) {
77
+ log.debug("removed attribute " + attributeName);
78
+ return attributeStorage.removeAttribute(attributeName + '');
79
+ };
80
+ /**
81
+ * Remove all the stored attributes in the client's in memory attribute storage
82
+ */
83
+
84
+
85
+ client.clearAttributes = function () {
86
+ return attributeStorage.clear();
87
+ };
88
+
89
+ client.getTreatment = function (maybeKey, maybeSplit, maybeAttributes) {
90
+ return clientGetTreatment(maybeKey, maybeSplit, combineAttributes(maybeAttributes));
91
+ };
92
+
93
+ client.getTreatmentWithConfig = function (maybeKey, maybeSplit, maybeAttributes) {
94
+ return clientGetTreatmentWithConfig(maybeKey, maybeSplit, combineAttributes(maybeAttributes));
95
+ };
96
+
97
+ client.getTreatments = function (maybeKey, maybeSplits, maybeAttributes) {
98
+ return clientGetTreatments(maybeKey, maybeSplits, combineAttributes(maybeAttributes));
99
+ };
100
+
101
+ client.getTreatmentsWithConfig = function (maybeKey, maybeSplits, maybeAttributes) {
102
+ return clientGetTreatmentsWithConfig(maybeKey, maybeSplits, combineAttributes(maybeAttributes));
103
+ };
104
+
105
+ function combineAttributes(maybeAttributes) {
106
+ var storedAttributes = attributeStorage.getAll();
107
+
108
+ if (Object.keys(storedAttributes).length > 0) {
109
+ return objectAssign({}, storedAttributes, maybeAttributes);
110
+ }
111
+
112
+ return maybeAttributes;
113
+ }
114
+
115
+ return client;
116
+ }
@@ -1,5 +1,5 @@
1
1
  import { get } from '../utils/lang';
2
- import ClientWithInputValidationLayer from './inputValidation';
2
+ import ClientAttributesDecorationLayer from './attributesDecoration';
3
3
  import { LOCALHOST_MODE } from '../utils/constants';
4
4
  import { validateKey, validateTrafficType } from '../utils/inputValidation';
5
5
 
@@ -25,7 +25,7 @@ function BrowserClientFactory(context) {
25
25
  trackBindings.push(tt);
26
26
  }
27
27
 
28
- var client = ClientWithInputValidationLayer(context, true, trackBindings.length > 1);
28
+ var client = ClientAttributesDecorationLayer(context, true, trackBindings.length > 1);
29
29
  client.isBrowserClient = true; // In the browser land, we can bind the key and the traffic type (if provided)
30
30
 
31
31
  client.getTreatment = client.getTreatment.bind(client, settings.core.key);
@@ -234,7 +234,7 @@ function hash128x64(key
234
234
  }
235
235
  /**
236
236
  * x64 version of Murmur3 for 128bits.
237
- * Used in hashImpression128.
237
+ *
238
238
  * @param {string} str
239
239
  */
240
240
 
@@ -166,10 +166,9 @@ function hash128x86(key
166
166
  }
167
167
  /**
168
168
  * x86 version of Murmur3 for 128bits.
169
- * @param {string} str
169
+ * Used by hashImpression128 because in JS it is more efficient than the x64 version, no matter the underlying OS/CPU arch.
170
170
  *
171
- * @TODO Test and use in hashImpression128 instead of the x64 version,
172
- * because it is more time efficient in JS, no matter the underlying CPU arch.
171
+ * @param {string} str
173
172
  */
174
173
 
175
174
 
@@ -16,7 +16,6 @@ limitations under the License.
16
16
  import Engine from '../';
17
17
  import thenable from '../../utils/promise/thenable';
18
18
  import * as LabelsConstants from '../../utils/labels';
19
- import { get } from '../../utils/lang';
20
19
  import { CONTROL } from '../../utils/constants';
21
20
  var treatmentException = {
22
21
  treatment: CONTROL,
@@ -74,18 +73,18 @@ function getEvaluation(stringifiedSplit, key, attributes, storage) {
74
73
  if (stringifiedSplit) {
75
74
  var splitJSON = JSON.parse(stringifiedSplit);
76
75
  var split = Engine.parse(splitJSON, storage);
77
- evaluation = split.getTreatment(key, attributes, evaluateFeature); // If the storage is async, evaluation and changeNumber will return a thenable
76
+ evaluation = split.getTreatment(key, attributes, evaluateFeature); // If the storage is async and the evaluated split uses segment, evaluation is thenable
78
77
 
79
78
  if (thenable(evaluation)) {
80
79
  return evaluation.then(function (result) {
81
80
  result.changeNumber = split.getChangeNumber();
82
- result.config = get(splitJSON, "configurations." + result.treatment, null);
81
+ result.config = splitJSON.configurations && splitJSON.configurations[result.treatment] || null;
83
82
  return result;
84
83
  });
85
84
  } else {
86
85
  evaluation.changeNumber = split.getChangeNumber(); // Always sync and optional
87
86
 
88
- evaluation.config = get(splitJSON, "configurations." + evaluation.treatment, null);
87
+ evaluation.config = splitJSON.configurations && splitJSON.configurations[evaluation.treatment] || null;
89
88
  }
90
89
  }
91
90
 
@@ -13,7 +13,6 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
13
  See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
15
  **/
16
- import { types } from './types';
17
16
  import allMatcher from './all';
18
17
  import segmentMatcher from './segment';
19
18
  import whitelistMatcher from './whitelist';
@@ -31,6 +30,25 @@ import containsStrMatcher from './cont_str';
31
30
  import dependencyMatcher from './dependency';
32
31
  import booleanMatcher from './boolean';
33
32
  import stringMatcher from './string';
33
+ var matchers = [undefined, // UNDEFINED: 0,
34
+ allMatcher, // ALL_KEYS: 1,
35
+ segmentMatcher, // IN_SEGMENT: 2,
36
+ whitelistMatcher, // WHITELIST: 3,
37
+ eqMatcher, // EQUAL_TO: 4,
38
+ gteMatcher, // GREATER_THAN_OR_EQUAL_TO: 5,
39
+ lteMatcher, // LESS_THAN_OR_EQUAL_TO: 6,
40
+ betweenMatcher, // BETWEEN: 7,
41
+ equalToSetMatcher, // EQUAL_TO_SET: 8,
42
+ containsAnySetMatcher, // CONTAINS_ANY_OF_SET: 9,
43
+ containsAllSetMatcher, // CONTAINS_ALL_OF_SET: 10,
44
+ partOfSetMatcher, // PART_OF_SET: 11,
45
+ ewMatcher, // ENDS_WITH: 12,
46
+ swMatcher, // STARTS_WITH: 13,
47
+ containsStrMatcher, // CONTAINS_STRING: 14,
48
+ dependencyMatcher, // IN_SPLIT_TREATMENT: 15,
49
+ booleanMatcher, // EQUAL_TO_BOOLEAN: 16,
50
+ stringMatcher // MATCHES_STRING: 17
51
+ ];
34
52
  /**
35
53
  * Matcher factory.
36
54
  */
@@ -39,42 +57,7 @@ function MatcherFactory(matcherDto, storage) {
39
57
  var type = matcherDto.type,
40
58
  value = matcherDto.value;
41
59
  var matcherFn;
42
-
43
- if (type === types.ALL) {
44
- matcherFn = allMatcher(value);
45
- } else if (type === types.SEGMENT) {
46
- matcherFn = segmentMatcher(value, storage);
47
- } else if (type === types.WHITELIST) {
48
- matcherFn = whitelistMatcher(value);
49
- } else if (type === types.EQUAL_TO) {
50
- matcherFn = eqMatcher(value);
51
- } else if (type === types.GREATER_THAN_OR_EQUAL_TO) {
52
- matcherFn = gteMatcher(value);
53
- } else if (type === types.LESS_THAN_OR_EQUAL_TO) {
54
- matcherFn = lteMatcher(value);
55
- } else if (type === types.BETWEEN) {
56
- matcherFn = betweenMatcher(value);
57
- } else if (type === types.EQUAL_TO_SET) {
58
- matcherFn = equalToSetMatcher(value);
59
- } else if (type === types.CONTAINS_ANY_OF_SET) {
60
- matcherFn = containsAnySetMatcher(value);
61
- } else if (type === types.CONTAINS_ALL_OF_SET) {
62
- matcherFn = containsAllSetMatcher(value);
63
- } else if (type === types.PART_OF_SET) {
64
- matcherFn = partOfSetMatcher(value);
65
- } else if (type === types.STARTS_WITH) {
66
- matcherFn = swMatcher(value);
67
- } else if (type === types.ENDS_WITH) {
68
- matcherFn = ewMatcher(value);
69
- } else if (type === types.CONTAINS_STRING) {
70
- matcherFn = containsStrMatcher(value);
71
- } else if (type === types.IN_SPLIT_TREATMENT) {
72
- matcherFn = dependencyMatcher(value, storage);
73
- } else if (type === types.EQUAL_TO_BOOLEAN) {
74
- matcherFn = booleanMatcher(value);
75
- } else if (type === types.MATCHES_STRING) {
76
- matcherFn = stringMatcher(value);
77
- }
60
+ if (matchers[type]) matcherFn = matchers[type](value, storage); // There is no index-out-of-bound exception in JavaScript
78
61
 
79
62
  return matcherFn;
80
63
  }
@@ -14,27 +14,27 @@ See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
15
  **/
16
16
  // @WARNING Symbol is not correctly working in PhantomJS
17
- export var types = {
18
- ALL: 1,
19
- SEGMENT: 2,
17
+ export var matcherTypes = {
18
+ UNDEFINED: 0,
19
+ ALL_KEYS: 1,
20
+ IN_SEGMENT: 2,
20
21
  WHITELIST: 3,
21
22
  EQUAL_TO: 4,
22
23
  GREATER_THAN_OR_EQUAL_TO: 5,
23
24
  LESS_THAN_OR_EQUAL_TO: 6,
24
25
  BETWEEN: 7,
25
- UNDEFINED: 8,
26
- EQUAL_TO_SET: 9,
27
- CONTAINS_ANY_OF_SET: 10,
28
- CONTAINS_ALL_OF_SET: 11,
29
- PART_OF_SET: 12,
30
- ENDS_WITH: 13,
31
- STARTS_WITH: 14,
32
- CONTAINS_STRING: 15,
33
- IN_SPLIT_TREATMENT: 16,
34
- EQUAL_TO_BOOLEAN: 17,
35
- MATCHES_STRING: 18
26
+ EQUAL_TO_SET: 8,
27
+ CONTAINS_ANY_OF_SET: 9,
28
+ CONTAINS_ALL_OF_SET: 10,
29
+ PART_OF_SET: 11,
30
+ ENDS_WITH: 12,
31
+ STARTS_WITH: 13,
32
+ CONTAINS_STRING: 14,
33
+ IN_SPLIT_TREATMENT: 15,
34
+ EQUAL_TO_BOOLEAN: 16,
35
+ MATCHES_STRING: 17
36
36
  };
37
- export var dataTypes = {
37
+ export var matcherDataTypes = {
38
38
  BOOLEAN: 'BOOLEAN',
39
39
  STRING: 'STRING',
40
40
  NUMBER: 'NUMBER',
@@ -42,60 +42,7 @@ export var dataTypes = {
42
42
  DATETIME: 'DATETIME',
43
43
  NOT_SPECIFIED: 'NOT_SPECIFIED'
44
44
  };
45
- export var mapper = function mapper(matcherType) {
46
- switch (matcherType) {
47
- case 'ALL_KEYS':
48
- return types.ALL;
49
-
50
- case 'IN_SEGMENT':
51
- return types.SEGMENT;
52
-
53
- case 'WHITELIST':
54
- return types.WHITELIST;
55
-
56
- case 'EQUAL_TO':
57
- return types.EQUAL_TO;
58
-
59
- case 'GREATER_THAN_OR_EQUAL_TO':
60
- return types.GREATER_THAN_OR_EQUAL_TO;
61
-
62
- case 'LESS_THAN_OR_EQUAL_TO':
63
- return types.LESS_THAN_OR_EQUAL_TO;
64
-
65
- case 'BETWEEN':
66
- return types.BETWEEN;
67
-
68
- case 'EQUAL_TO_SET':
69
- return types.EQUAL_TO_SET;
70
-
71
- case 'CONTAINS_ANY_OF_SET':
72
- return types.CONTAINS_ANY_OF_SET;
73
-
74
- case 'CONTAINS_ALL_OF_SET':
75
- return types.CONTAINS_ALL_OF_SET;
76
-
77
- case 'PART_OF_SET':
78
- return types.PART_OF_SET;
79
-
80
- case 'ENDS_WITH':
81
- return types.ENDS_WITH;
82
-
83
- case 'STARTS_WITH':
84
- return types.STARTS_WITH;
85
-
86
- case 'CONTAINS_STRING':
87
- return types.CONTAINS_STRING;
88
-
89
- case 'IN_SPLIT_TREATMENT':
90
- return types.IN_SPLIT_TREATMENT;
91
-
92
- case 'EQUAL_TO_BOOLEAN':
93
- return types.EQUAL_TO_BOOLEAN;
94
-
95
- case 'MATCHES_STRING':
96
- return types.MATCHES_STRING;
97
-
98
- default:
99
- return types.UNDEFINED;
100
- }
101
- };
45
+ export function matcherTypesMapper(matcherType) {
46
+ var type = matcherTypes[matcherType];
47
+ if (type) return type;else return matcherTypes.UNDEFINED;
48
+ }
@@ -13,7 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
13
  See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
15
  **/
16
- import { types as matcherTypes, mapper as matcherTypesMapper } from '../matchers/types';
16
+ import { matcherTypes, matcherTypesMapper } from '../matchers/types';
17
17
  import segmentTransform from './segment';
18
18
  import whitelistTransform from './whitelist';
19
19
  /**
@@ -28,7 +28,7 @@ function transform(matcherGroup) {
28
28
  var type = matcherTypesMapper(matcherType);
29
29
  var value = undefined;
30
30
 
31
- if (type === matcherTypes.SEGMENT) {
31
+ if (type === matcherTypes.IN_SEGMENT) {
32
32
  value = segmentTransform(segmentObject);
33
33
  } else if (type === matcherTypes.WHITELIST) {
34
34
  value = whitelistTransform(whitelistObject);
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
15
  **/
16
16
  import { findIndex } from '../../utils/lang';
17
- import { types as matcherTypes, mapper as matcherTypesMapper, dataTypes as matcherDataTypes } from '../matchers/types';
17
+ import { matcherTypes, matcherTypesMapper, matcherDataTypes } from '../matchers/types';
18
18
  import segmentTransform from './segment';
19
19
  import whitelistTransform from './whitelist';
20
20
  import setTransform from './set';
@@ -39,7 +39,7 @@ function transform(matchers) {
39
39
  var dataType = matcherDataTypes.STRING;
40
40
  var value = undefined;
41
41
 
42
- if (type === matcherTypes.SEGMENT) {
42
+ if (type === matcherTypes.IN_SEGMENT) {
43
43
  value = segmentTransform(segmentObject);
44
44
  } else if (type === matcherTypes.WHITELIST) {
45
45
  value = whitelistTransform(whitelistObject);
@@ -17,9 +17,7 @@ import logFactory from '../../utils/logger';
17
17
  var log = logFactory('splitio-engine:sanitize');
18
18
  import { isObject, uniq, toString, toNumber } from '../../utils/lang';
19
19
  import { zeroSinceHH, zeroSinceSS } from '../convertions';
20
- import { types as matcherTypes, dataTypes as matcherDataTypes } from '../matchers/types';
21
- var MATCHERS = matcherTypes;
22
- var DATA_TYPES = matcherDataTypes;
20
+ import { matcherTypes, matcherDataTypes } from '../matchers/types';
23
21
 
24
22
  function sanitizeNumber(val) {
25
23
  var num = toNumber(val);
@@ -70,15 +68,15 @@ function dependencyProcessor(sanitizedValue, attributes) {
70
68
 
71
69
  function getProcessingFunction(matcherTypeID, dataType) {
72
70
  switch (matcherTypeID) {
73
- case MATCHERS.EQUAL_TO:
71
+ case matcherTypes.EQUAL_TO:
74
72
  return dataType === 'DATETIME' ? zeroSinceHH : undefined;
75
73
 
76
- case MATCHERS.GREATER_THAN_OR_EQUAL_TO:
77
- case MATCHERS.LESS_THAN_OR_EQUAL_TO:
78
- case MATCHERS.BETWEEN:
74
+ case matcherTypes.GREATER_THAN_OR_EQUAL_TO:
75
+ case matcherTypes.LESS_THAN_OR_EQUAL_TO:
76
+ case matcherTypes.BETWEEN:
79
77
  return dataType === 'DATETIME' ? zeroSinceSS : undefined;
80
78
 
81
- case MATCHERS.IN_SPLIT_TREATMENT:
79
+ case matcherTypes.IN_SPLIT_TREATMENT:
82
80
  return dependencyProcessor;
83
81
 
84
82
  default:
@@ -91,24 +89,24 @@ function sanitizeValue(matcherTypeID, value, dataType, attributes) {
91
89
  var sanitizedValue;
92
90
 
93
91
  switch (dataType) {
94
- case DATA_TYPES.NUMBER:
95
- case DATA_TYPES.DATETIME:
92
+ case matcherDataTypes.NUMBER:
93
+ case matcherDataTypes.DATETIME:
96
94
  sanitizedValue = sanitizeNumber(value);
97
95
  break;
98
96
 
99
- case DATA_TYPES.STRING:
97
+ case matcherDataTypes.STRING:
100
98
  sanitizedValue = sanitizeString(value);
101
99
  break;
102
100
 
103
- case DATA_TYPES.SET:
101
+ case matcherDataTypes.SET:
104
102
  sanitizedValue = sanitizeArray(value);
105
103
  break;
106
104
 
107
- case DATA_TYPES.BOOLEAN:
105
+ case matcherDataTypes.BOOLEAN:
108
106
  sanitizedValue = sanitizeBoolean(value);
109
107
  break;
110
108
 
111
- case DATA_TYPES.NOT_SPECIFIED:
109
+ case matcherDataTypes.NOT_SPECIFIED:
112
110
  sanitizedValue = value;
113
111
  break;
114
112
 
@@ -1,4 +1,4 @@
1
- import { hash128 } from '../../engine/engine/murmur3/murmur3_128';
1
+ import { hash128 } from '../../engine/engine/murmur3/murmur3_128_x86';
2
2
  import { buildKey } from './buildKey';
3
3
  export function hashImpression128(impression) {
4
4
  return hash128(buildKey(impression));
@@ -9,7 +9,6 @@ var ImpressionObserver = /*#__PURE__*/function () {
9
9
  var _proto = ImpressionObserver.prototype;
10
10
 
11
11
  _proto.testAndSet = function testAndSet(impression) {
12
- if (!impression) return null;
13
12
  var hash = this.hasher(impression);
14
13
  var previous = this.cache.get(hash);
15
14
  this.cache.set(hash, impression.time);
@@ -13,6 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
13
  See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
15
  **/
16
+ import { STORAGE_LOCALSTORAGE } from '../../utils/constants';
16
17
  import { forOwn } from '../../utils/lang';
17
18
  import logFactory from '../../utils/logger';
18
19
  var log = logFactory('splitio-producer:offline');
@@ -52,13 +53,13 @@ function FromObjectUpdaterFactory(Fetcher, context) {
52
53
  })]);
53
54
  });
54
55
  return Promise.all([storage.splits.flush(), // required to sync removed splits from mock
55
- storage.splits.setChangeNumber(Date.now()), storage.splits.addSplits(splits)]).then(function () {
56
+ storage.splits.addSplits(splits)]).then(function () {
56
57
  readiness.splits.emit(readiness.splits.SDK_SPLITS_ARRIVED);
57
58
 
58
59
  if (startingUp) {
59
60
  startingUp = false; // Emits SDK_READY_FROM_CACHE
60
61
 
61
- if (storage.splits.checkCache()) readiness.splits.emit(readiness.splits.SDK_SPLITS_CACHE_LOADED); // Only emits SDK_SEGMENTS_ARRIVED the first time for SDK_READY
62
+ if (settings.storage.__originalType === STORAGE_LOCALSTORAGE) readiness.splits.emit(readiness.splits.SDK_SPLITS_CACHE_LOADED); // Only emits SDK_SEGMENTS_ARRIVED the first time for SDK_READY
62
63
 
63
64
  readiness.segments.emit(readiness.segments.SDK_SEGMENTS_ARRIVED);
64
65
  }
@@ -0,0 +1,84 @@
1
+ import objectAssign from 'object-assign';
2
+
3
+ var AttributesCacheInMemory = /*#__PURE__*/function () {
4
+ function AttributesCacheInMemory() {
5
+ this.attributesCache = {};
6
+ }
7
+ /**
8
+ * Create or update the value for the given attribute
9
+ *
10
+ * @param {string} attributeName attribute name
11
+ * @param {Object} attributeValue attribute value
12
+ * @returns {boolean} the attribute was stored
13
+ */
14
+
15
+
16
+ var _proto = AttributesCacheInMemory.prototype;
17
+
18
+ _proto.setAttribute = function setAttribute(attributeName, attributeValue) {
19
+ this.attributesCache[attributeName] = attributeValue;
20
+ return true;
21
+ }
22
+ /**
23
+ * Retrieves the value of a given attribute
24
+ *
25
+ * @param {string} attributeName attribute name
26
+ * @returns {Object?} stored attribute value
27
+ */
28
+ ;
29
+
30
+ _proto.getAttribute = function getAttribute(attributeName) {
31
+ return this.attributesCache[attributeName];
32
+ }
33
+ /**
34
+ * Create or update all the given attributes
35
+ *
36
+ * @param {[string, Object]} attributes attributes to create or update
37
+ * @returns {boolean} attributes were stored
38
+ */
39
+ ;
40
+
41
+ _proto.setAttributes = function setAttributes(attributes) {
42
+ this.attributesCache = objectAssign(this.attributesCache, attributes);
43
+ return true;
44
+ }
45
+ /**
46
+ * Retrieve the full attributes map
47
+ *
48
+ * @returns {Map<string, Object>} stored attributes
49
+ */
50
+ ;
51
+
52
+ _proto.getAll = function getAll() {
53
+ return this.attributesCache;
54
+ }
55
+ /**
56
+ * Removes a given attribute from the map
57
+ *
58
+ * @param {string} attributeName attribute to remove
59
+ * @returns {boolean} attribute removed
60
+ */
61
+ ;
62
+
63
+ _proto.removeAttribute = function removeAttribute(attributeName) {
64
+ if (Object.keys(this.attributesCache).indexOf(attributeName) >= 0) {
65
+ delete this.attributesCache[attributeName];
66
+ return true;
67
+ }
68
+
69
+ return false;
70
+ }
71
+ /**
72
+ * Clears all attributes stored in the SDK
73
+ *
74
+ */
75
+ ;
76
+
77
+ _proto.clear = function clear() {
78
+ this.attributesCache = {};
79
+ };
80
+
81
+ return AttributesCacheInMemory;
82
+ }();
83
+
84
+ export default AttributesCacheInMemory;