@splitsoftware/splitio-commons 1.17.1-rc.2 → 2.0.0-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 (195) hide show
  1. package/CHANGES.txt +7 -3
  2. package/cjs/evaluator/index.js +2 -2
  3. package/cjs/evaluator/matchers/semver_inlist.js +1 -2
  4. package/cjs/evaluator/matchers/whitelist.js +1 -2
  5. package/cjs/listeners/browser.js +1 -2
  6. package/cjs/logger/browser/DebugLogger.js +1 -2
  7. package/cjs/logger/browser/ErrorLogger.js +1 -2
  8. package/cjs/logger/browser/InfoLogger.js +1 -2
  9. package/cjs/logger/browser/WarnLogger.js +1 -2
  10. package/cjs/logger/index.js +1 -2
  11. package/cjs/sdkClient/clientCS.js +5 -8
  12. package/cjs/sdkClient/sdkClientMethodCS.js +1 -1
  13. package/cjs/sdkFactory/index.js +1 -3
  14. package/cjs/services/decorateHeaders.js +1 -2
  15. package/cjs/storages/AbstractSplitsCacheAsync.js +7 -0
  16. package/cjs/storages/AbstractSplitsCacheSync.js +7 -0
  17. package/cjs/storages/KeyBuilderCS.js +0 -9
  18. package/cjs/storages/dataLoader.js +32 -65
  19. package/cjs/storages/inLocalStorage/MySegmentsCacheInLocal.js +1 -21
  20. package/cjs/storages/inLocalStorage/SplitsCacheInLocal.js +14 -7
  21. package/cjs/storages/inLocalStorage/index.js +1 -4
  22. package/cjs/storages/inMemory/InMemoryStorageCS.js +4 -16
  23. package/cjs/storages/inMemory/SegmentsCacheInMemory.js +3 -4
  24. package/cjs/storages/inMemory/SplitsCacheInMemory.js +2 -3
  25. package/cjs/storages/inMemory/UniqueKeysCacheInMemory.js +2 -3
  26. package/cjs/storages/inMemory/UniqueKeysCacheInMemoryCS.js +2 -3
  27. package/cjs/storages/inRedis/RedisAdapter.js +2 -3
  28. package/cjs/storages/inRedis/SplitsCacheInRedis.js +1 -1
  29. package/cjs/storages/inRedis/TelemetryCacheInRedis.js +3 -4
  30. package/cjs/storages/inRedis/UniqueKeysCacheInRedis.js +1 -2
  31. package/cjs/storages/pluggable/SplitsCachePluggable.js +1 -1
  32. package/cjs/storages/pluggable/TelemetryCachePluggable.js +6 -7
  33. package/cjs/storages/pluggable/UniqueKeysCachePluggable.js +1 -2
  34. package/cjs/storages/pluggable/inMemoryWrapper.js +7 -8
  35. package/cjs/sync/offline/syncTasks/fromObjectSyncTask.js +7 -2
  36. package/cjs/sync/polling/pollingManagerSS.js +3 -3
  37. package/cjs/sync/polling/updaters/splitChangesUpdater.js +13 -5
  38. package/cjs/sync/streaming/parseUtils.js +0 -1
  39. package/cjs/sync/streaming/pushManager.js +2 -3
  40. package/cjs/utils/LRUCache/index.js +1 -2
  41. package/cjs/utils/constants/browser.js +1 -4
  42. package/cjs/utils/lang/index.js +6 -9
  43. package/cjs/utils/lang/objectAssign.js +12 -77
  44. package/cjs/utils/lang/sets.js +3 -110
  45. package/cjs/utils/settingsValidation/index.js +0 -9
  46. package/cjs/utils/settingsValidation/logger/builtinLogger.js +1 -2
  47. package/cjs/utils/settingsValidation/storage/storageCS.js +12 -1
  48. package/esm/evaluator/index.js +3 -3
  49. package/esm/evaluator/matchers/semver_inlist.js +1 -2
  50. package/esm/evaluator/matchers/whitelist.js +1 -2
  51. package/esm/listeners/browser.js +1 -2
  52. package/esm/logger/browser/DebugLogger.js +1 -2
  53. package/esm/logger/browser/ErrorLogger.js +1 -2
  54. package/esm/logger/browser/InfoLogger.js +1 -2
  55. package/esm/logger/browser/WarnLogger.js +1 -2
  56. package/esm/logger/index.js +1 -2
  57. package/esm/sdkClient/clientCS.js +5 -8
  58. package/esm/sdkClient/sdkClientMethodCS.js +1 -1
  59. package/esm/sdkFactory/index.js +2 -4
  60. package/esm/services/decorateHeaders.js +1 -2
  61. package/esm/storages/AbstractSplitsCacheAsync.js +7 -0
  62. package/esm/storages/AbstractSplitsCacheSync.js +7 -0
  63. package/esm/storages/KeyBuilderCS.js +0 -9
  64. package/esm/storages/dataLoader.js +30 -62
  65. package/esm/storages/inLocalStorage/MySegmentsCacheInLocal.js +1 -21
  66. package/esm/storages/inLocalStorage/SplitsCacheInLocal.js +14 -7
  67. package/esm/storages/inLocalStorage/index.js +2 -5
  68. package/esm/storages/inMemory/InMemoryStorageCS.js +4 -16
  69. package/esm/storages/inMemory/SegmentsCacheInMemory.js +3 -4
  70. package/esm/storages/inMemory/SplitsCacheInMemory.js +2 -3
  71. package/esm/storages/inMemory/UniqueKeysCacheInMemory.js +2 -3
  72. package/esm/storages/inMemory/UniqueKeysCacheInMemoryCS.js +2 -3
  73. package/esm/storages/inRedis/RedisAdapter.js +2 -3
  74. package/esm/storages/inRedis/SplitsCacheInRedis.js +2 -2
  75. package/esm/storages/inRedis/TelemetryCacheInRedis.js +3 -4
  76. package/esm/storages/inRedis/UniqueKeysCacheInRedis.js +1 -2
  77. package/esm/storages/pluggable/SplitsCachePluggable.js +2 -2
  78. package/esm/storages/pluggable/TelemetryCachePluggable.js +6 -7
  79. package/esm/storages/pluggable/UniqueKeysCachePluggable.js +1 -2
  80. package/esm/storages/pluggable/inMemoryWrapper.js +7 -8
  81. package/esm/sync/offline/syncTasks/fromObjectSyncTask.js +8 -3
  82. package/esm/sync/polling/pollingManagerSS.js +3 -3
  83. package/esm/sync/polling/updaters/splitChangesUpdater.js +14 -6
  84. package/esm/sync/streaming/parseUtils.js +0 -1
  85. package/esm/sync/streaming/pushManager.js +2 -3
  86. package/esm/utils/LRUCache/index.js +1 -2
  87. package/esm/utils/constants/browser.js +0 -3
  88. package/esm/utils/lang/index.js +6 -9
  89. package/esm/utils/lang/objectAssign.js +12 -77
  90. package/esm/utils/lang/sets.js +2 -107
  91. package/esm/utils/settingsValidation/index.js +0 -9
  92. package/esm/utils/settingsValidation/logger/builtinLogger.js +1 -2
  93. package/esm/utils/settingsValidation/storage/storageCS.js +10 -0
  94. package/package.json +2 -2
  95. package/src/evaluator/index.ts +5 -5
  96. package/src/evaluator/matchers/semver_inlist.ts +1 -2
  97. package/src/evaluator/matchers/whitelist.ts +1 -3
  98. package/src/listeners/browser.ts +1 -2
  99. package/src/logger/browser/DebugLogger.ts +1 -2
  100. package/src/logger/browser/ErrorLogger.ts +1 -2
  101. package/src/logger/browser/InfoLogger.ts +1 -2
  102. package/src/logger/browser/WarnLogger.ts +1 -2
  103. package/src/logger/index.ts +3 -4
  104. package/src/sdkClient/clientCS.ts +5 -8
  105. package/src/sdkClient/sdkClientMethodCS.ts +1 -1
  106. package/src/sdkFactory/index.ts +2 -5
  107. package/src/sdkFactory/types.ts +1 -1
  108. package/src/services/decorateHeaders.ts +1 -2
  109. package/src/storages/AbstractSplitsCacheAsync.ts +9 -2
  110. package/src/storages/AbstractSplitsCacheSync.ts +9 -2
  111. package/src/storages/KeyBuilderCS.ts +0 -13
  112. package/src/storages/dataLoader.ts +32 -63
  113. package/src/storages/inLocalStorage/MySegmentsCacheInLocal.ts +1 -21
  114. package/src/storages/inLocalStorage/SplitsCacheInLocal.ts +16 -8
  115. package/src/storages/inLocalStorage/index.ts +2 -6
  116. package/src/storages/inMemory/InMemoryStorageCS.ts +4 -19
  117. package/src/storages/inMemory/SegmentsCacheInMemory.ts +4 -5
  118. package/src/storages/inMemory/SplitsCacheInMemory.ts +4 -5
  119. package/src/storages/inMemory/UniqueKeysCacheInMemory.ts +4 -5
  120. package/src/storages/inMemory/UniqueKeysCacheInMemoryCS.ts +4 -5
  121. package/src/storages/inRedis/RedisAdapter.ts +3 -4
  122. package/src/storages/inRedis/SplitsCacheInRedis.ts +3 -3
  123. package/src/storages/inRedis/TelemetryCacheInRedis.ts +3 -4
  124. package/src/storages/inRedis/UniqueKeysCacheInRedis.ts +1 -2
  125. package/src/storages/pluggable/SegmentsCachePluggable.ts +0 -1
  126. package/src/storages/pluggable/SplitsCachePluggable.ts +3 -3
  127. package/src/storages/pluggable/TelemetryCachePluggable.ts +6 -7
  128. package/src/storages/pluggable/UniqueKeysCachePluggable.ts +1 -2
  129. package/src/storages/pluggable/inMemoryWrapper.ts +8 -9
  130. package/src/storages/types.ts +9 -5
  131. package/src/sync/offline/syncTasks/fromObjectSyncTask.ts +7 -3
  132. package/src/sync/polling/pollingManagerSS.ts +2 -3
  133. package/src/sync/polling/updaters/splitChangesUpdater.ts +15 -8
  134. package/src/sync/streaming/parseUtils.ts +0 -1
  135. package/src/sync/streaming/pushManager.ts +3 -4
  136. package/src/sync/submitters/types.ts +3 -4
  137. package/src/types.ts +9 -18
  138. package/src/utils/LRUCache/index.ts +2 -3
  139. package/src/utils/constants/browser.ts +0 -4
  140. package/src/utils/lang/index.ts +6 -7
  141. package/src/utils/lang/objectAssign.ts +13 -92
  142. package/src/utils/lang/sets.ts +3 -125
  143. package/src/utils/settingsValidation/index.ts +0 -10
  144. package/src/utils/settingsValidation/logger/builtinLogger.ts +1 -2
  145. package/src/utils/settingsValidation/storage/storageCS.ts +13 -0
  146. package/src/utils/settingsValidation/types.ts +0 -2
  147. package/types/logger/index.d.ts +1 -2
  148. package/types/sdkClient/clientCS.d.ts +2 -3
  149. package/types/sdkFactory/types.d.ts +1 -1
  150. package/types/storages/AbstractSplitsCacheAsync.d.ts +6 -2
  151. package/types/storages/AbstractSplitsCacheSync.d.ts +6 -2
  152. package/types/storages/KeyBuilderCS.d.ts +0 -2
  153. package/types/storages/dataLoader.d.ts +6 -17
  154. package/types/storages/inLocalStorage/SplitsCacheInLocal.d.ts +7 -2
  155. package/types/storages/inMemory/SplitsCacheInMemory.d.ts +1 -2
  156. package/types/storages/inMemory/UniqueKeysCacheInMemory.d.ts +2 -3
  157. package/types/storages/inRedis/SplitsCacheInRedis.d.ts +1 -2
  158. package/types/storages/pluggable/SplitsCachePluggable.d.ts +1 -2
  159. package/types/storages/pluggable/inMemoryWrapper.d.ts +1 -2
  160. package/types/storages/types.d.ts +7 -5
  161. package/types/sync/polling/updaters/splitChangesUpdater.d.ts +1 -2
  162. package/types/sync/submitters/types.d.ts +3 -4
  163. package/types/types.d.ts +9 -17
  164. package/types/utils/LRUCache/index.d.ts +1 -2
  165. package/types/utils/constants/browser.d.ts +0 -2
  166. package/types/utils/lang/objectAssign.d.ts +3 -0
  167. package/types/utils/lang/sets.d.ts +1 -61
  168. package/types/utils/settingsValidation/index.d.ts +0 -1
  169. package/types/utils/settingsValidation/storage/storageCS.d.ts +5 -0
  170. package/types/utils/settingsValidation/types.d.ts +0 -2
  171. package/cjs/integrations/browser.js +0 -31
  172. package/cjs/integrations/ga/GaToSplit.js +0 -257
  173. package/cjs/integrations/ga/GoogleAnalyticsToSplit.js +0 -14
  174. package/cjs/integrations/ga/SplitToGa.js +0 -123
  175. package/cjs/integrations/ga/SplitToGoogleAnalytics.js +0 -14
  176. package/cjs/integrations/ga/types.js +0 -2
  177. package/cjs/sdkClient/sdkClientMethodCSWithTT.js +0 -76
  178. package/cjs/utils/lang/maps.js +0 -96
  179. package/esm/integrations/browser.js +0 -27
  180. package/esm/integrations/ga/GaToSplit.js +0 -250
  181. package/esm/integrations/ga/GoogleAnalyticsToSplit.js +0 -10
  182. package/esm/integrations/ga/SplitToGa.js +0 -120
  183. package/esm/integrations/ga/SplitToGoogleAnalytics.js +0 -10
  184. package/esm/integrations/ga/types.js +0 -1
  185. package/esm/sdkClient/sdkClientMethodCSWithTT.js +0 -72
  186. package/esm/utils/lang/maps.js +0 -92
  187. package/src/integrations/browser.ts +0 -35
  188. package/src/integrations/ga/GaToSplit.ts +0 -299
  189. package/src/integrations/ga/GoogleAnalyticsToSplit.ts +0 -14
  190. package/src/integrations/ga/SplitToGa.ts +0 -135
  191. package/src/integrations/ga/SplitToGoogleAnalytics.ts +0 -14
  192. package/src/integrations/ga/autoRequire.js +0 -33
  193. package/src/integrations/ga/types.ts +0 -153
  194. package/src/sdkClient/sdkClientMethodCSWithTT.ts +0 -98
  195. package/src/utils/lang/maps.ts +0 -108
@@ -1,120 +1,13 @@
1
1
  "use strict";
2
- /**
3
- * Set implementation based on es6-set polyfill (https://github.com/medikoo/es6-set/blob/master/polyfill.js),
4
- * with the minimal features used by the SDK.
5
-
6
- Copyright (C) 2013 Mariusz Nowak (www.medikoo.com)
7
-
8
- Permission is hereby granted, free of charge, to any person obtaining a copy
9
- of this software and associated documentation files (the "Software"), to deal
10
- in the Software without restriction, including without limitation the rights
11
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
- copies of the Software, and to permit persons to whom the Software is
13
- furnished to do so, subject to the following conditions:
14
-
15
- The above copyright notice and this permission notice shall be included in
16
- all copies or substantial portions of the Software.
17
-
18
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
- THE SOFTWARE.
25
- **/
26
2
  Object.defineProperty(exports, "__esModule", { value: true });
27
- exports.returnDifference = exports.returnSetsUnion = exports._Set = exports.__getSetConstructor = exports.setToArray = exports.SetPoly = void 0;
28
- var SetPoly = /** @class */ (function () {
29
- // unlike ES6 `Set`, it only accepts an array as first argument iterable
30
- function SetPoly(values) {
31
- var _this = this;
32
- this.__setData__ = [];
33
- if (Array.isArray(values))
34
- values.forEach(function (value) { _this.add(value); });
35
- }
36
- SetPoly.prototype.clear = function () {
37
- if (!this.__setData__.length)
38
- return;
39
- this.__setData__.length = 0;
40
- };
41
- SetPoly.prototype.add = function (value) {
42
- if (this.has(value))
43
- return this;
44
- this.__setData__.push(value);
45
- return this;
46
- };
47
- SetPoly.prototype.delete = function (value) {
48
- var index = this.__setData__.indexOf(value);
49
- if (index === -1)
50
- return false;
51
- this.__setData__.splice(index, 1);
52
- return true;
53
- };
54
- SetPoly.prototype.has = function (value) {
55
- return this.__setData__.indexOf(value) !== -1;
56
- };
57
- SetPoly.prototype.forEach = function (callbackfn, thisArg) {
58
- if (typeof callbackfn !== 'function')
59
- throw new TypeError(callbackfn + ' is not a function');
60
- for (var i = 0; i < this.__setData__.length; i++) {
61
- var value = this.__setData__[i];
62
- callbackfn.call(thisArg, value, value, this);
63
- }
64
- };
65
- Object.defineProperty(SetPoly.prototype, "size", {
66
- get: function () {
67
- return this.__setData__.length;
68
- },
69
- enumerable: false,
70
- configurable: true
71
- });
72
- return SetPoly;
73
- }());
74
- exports.SetPoly = SetPoly;
75
- /**
76
- * return an array containing the items of the given set.
77
- * @param set Set or SetPoly instance
78
- */
79
- function setToArray(set) {
80
- if (set instanceof SetPoly) {
81
- return set.__setData__.slice();
82
- }
83
- // if not using SetPoly as set, it means Array.from is supported
84
- // eslint-disable-next-line compat/compat
85
- return Array.from(set);
86
- }
87
- exports.setToArray = setToArray;
88
- /**
89
- * return the Set constructor to use. If `Array.from` built-in or native Set is not available or it doesn't support the required features,
90
- * a ponyfill with minimal features is returned instead.
91
- *
92
- * Exported for testing purposes only.
93
- */
94
- function __getSetConstructor() {
95
- // eslint-disable-next-line compat/compat
96
- if (typeof Array.from === 'function' && typeof Set === 'function' && Set.prototype && Set.prototype.values) {
97
- return Set;
98
- }
99
- return SetPoly;
100
- }
101
- exports.__getSetConstructor = __getSetConstructor;
102
- exports._Set = __getSetConstructor();
3
+ exports.returnDifference = exports.returnSetsUnion = void 0;
103
4
  function returnSetsUnion(set, set2) {
104
- var result = new exports._Set(setToArray(set));
105
- set2.forEach(function (value) {
106
- result.add(value);
107
- });
108
- return result;
5
+ return new Set(Array.from(set).concat(Array.from(set2)));
109
6
  }
110
7
  exports.returnSetsUnion = returnSetsUnion;
111
8
  function returnDifference(list, list2) {
112
9
  if (list === void 0) { list = []; }
113
10
  if (list2 === void 0) { list2 = []; }
114
- var result = new exports._Set(list);
115
- list2.forEach(function (item) {
116
- result.delete(item);
117
- });
118
- return setToArray(result);
11
+ return list.filter(function (item) { return list2.indexOf(item) === -1; });
119
12
  }
120
13
  exports.returnDifference = returnDifference;
@@ -7,7 +7,6 @@ var splitFilters_1 = require("./splitFilters");
7
7
  var constants_1 = require("../constants");
8
8
  var impressionsMode_1 = require("./impressionsMode");
9
9
  var key_1 = require("../inputValidation/key");
10
- var trafficType_1 = require("../inputValidation/trafficType");
11
10
  var constants_2 = require("../../logger/constants");
12
11
  // Exported for telemetry
13
12
  exports.base = {
@@ -18,8 +17,6 @@ exports.base = {
18
17
  authorizationKey: undefined,
19
18
  // key used in your system (only required for browser version)
20
19
  key: undefined,
21
- // traffic type for the given key (only used on browser version)
22
- trafficType: undefined,
23
20
  // toggle impressions tracking of labels
24
21
  labelsEnabled: true,
25
22
  // toggle sendind (true) or not sending (false) IP and Host Name with impressions, events, and telemetries requests (only used on nodejs version)
@@ -148,12 +145,6 @@ function settingsValidation(config, validationParams) {
148
145
  // @ts-ignore, @TODO handle invalid keys as a non-recoverable error?
149
146
  withDefaults.core.key = (0, key_1.validateKey)(log, maybeKey, constants_2.LOG_PREFIX_CLIENT_INSTANTIATION);
150
147
  }
151
- if (validationParams.acceptTT) {
152
- var maybeTT = withDefaults.core.trafficType;
153
- if (maybeTT !== undefined) { // @ts-ignore
154
- withDefaults.core.trafficType = (0, trafficType_1.validateTrafficType)(log, maybeTT, constants_2.LOG_PREFIX_CLIENT_INSTANTIATION);
155
- }
156
- }
157
148
  }
158
149
  else {
159
150
  // On server-side, key is undefined and used to distinguish from client-side
@@ -5,9 +5,8 @@ var logger_1 = require("../../../logger");
5
5
  var isLocalStorageAvailable_1 = require("../../env/isLocalStorageAvailable");
6
6
  var isNode_1 = require("../../env/isNode");
7
7
  var debug_1 = require("../../../logger/messages/debug");
8
- var maps_1 = require("../../lang/maps");
9
8
  var commons_1 = require("./commons");
10
- var allCodes = new maps_1._Map(debug_1.codesDebug);
9
+ var allCodes = new Map(debug_1.codesDebug);
11
10
  // @TODO set default debug setting instead of initialLogLevel when integrating in JS and Node packages
12
11
  var LS_KEY = 'splitio_debug';
13
12
  var ENV_VAR_KEY = 'SPLITIO_DEBUG';
@@ -1,9 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.validateStorageCS = void 0;
3
+ exports.validateStorageCS = exports.__InLocalStorageMockFactory = void 0;
4
4
  var InMemoryStorageCS_1 = require("../../../storages/inMemory/InMemoryStorageCS");
5
5
  var constants_1 = require("../../../logger/constants");
6
6
  var constants_2 = require("../../../utils/constants");
7
+ function __InLocalStorageMockFactory(params) {
8
+ var result = (0, InMemoryStorageCS_1.InMemoryStorageCSFactory)(params);
9
+ result.splits.checkCache = function () { return true; }; // to emit SDK_READY_FROM_CACHE
10
+ return result;
11
+ }
12
+ exports.__InLocalStorageMockFactory = __InLocalStorageMockFactory;
13
+ __InLocalStorageMockFactory.type = constants_2.STORAGE_MEMORY;
7
14
  /**
8
15
  * This function validates `settings.storage` object
9
16
  *
@@ -20,6 +27,10 @@ function validateStorageCS(settings) {
20
27
  storage = InMemoryStorageCS_1.InMemoryStorageCSFactory;
21
28
  log.error(constants_1.ERROR_STORAGE_INVALID);
22
29
  }
30
+ // In localhost mode with InLocalStorage, fallback to a mock InLocalStorage to emit SDK_READY_FROM_CACHE
31
+ if (mode === constants_2.LOCALHOST_MODE && storage.type === constants_2.STORAGE_LOCALSTORAGE) {
32
+ return __InLocalStorageMockFactory;
33
+ }
23
34
  if ([constants_2.LOCALHOST_MODE, constants_2.STANDALONE_MODE].indexOf(mode) === -1) {
24
35
  // Consumer modes require an async storage
25
36
  if (storage.type !== constants_2.STORAGE_PLUGGABLE)
@@ -2,7 +2,7 @@ import { Engine } from './Engine';
2
2
  import { thenable } from '../utils/promise/thenable';
3
3
  import { EXCEPTION, SPLIT_NOT_FOUND } from '../utils/labels';
4
4
  import { CONTROL } from '../utils/constants';
5
- import { setToArray, returnSetsUnion, _Set } from '../utils/lang/sets';
5
+ import { returnSetsUnion } from '../utils/lang/sets';
6
6
  import { WARN_FLAGSET_WITHOUT_FLAGS } from '../logger/constants';
7
7
  var treatmentException = {
8
8
  treatment: CONTROL,
@@ -54,7 +54,7 @@ export function evaluateFeatures(log, key, splitNames, attributes, storage) {
54
54
  export function evaluateFeaturesByFlagSets(log, key, flagSets, attributes, storage, method) {
55
55
  var storedFlagNames;
56
56
  function evaluate(featureFlagsByFlagSets) {
57
- var featureFlags = new _Set();
57
+ var featureFlags = new Set();
58
58
  for (var i = 0; i < flagSets.length; i++) {
59
59
  var featureFlagByFlagSet = featureFlagsByFlagSets[i];
60
60
  if (featureFlagByFlagSet.size) {
@@ -65,7 +65,7 @@ export function evaluateFeaturesByFlagSets(log, key, flagSets, attributes, stora
65
65
  }
66
66
  }
67
67
  return featureFlags.size ?
68
- evaluateFeatures(log, key, setToArray(featureFlags), attributes, storage) :
68
+ evaluateFeatures(log, key, Array.from(featureFlags), attributes, storage) :
69
69
  {};
70
70
  }
71
71
  // get features by flag sets
@@ -1,10 +1,9 @@
1
- import { _Set } from '../../utils/lang/sets';
2
1
  import { Semver } from '../../utils/Semver';
3
2
  export function inListSemverMatcherContext(ruleAttr) {
4
3
  // @TODO ruleAttr validation should be done at the `parser` or `matchersTransform` level to reuse for all matchers
5
4
  if (!ruleAttr || ruleAttr.length === 0)
6
5
  throw new Error('whitelistMatcherData is required for IN_LIST_SEMVER matcher type');
7
- var listOfSemvers = new _Set(ruleAttr.map(function (version) { return new Semver(version).version; }));
6
+ var listOfSemvers = new Set(ruleAttr.map(function (version) { return new Semver(version).version; }));
8
7
  return function inListSemverMatcher(runtimeAttr) {
9
8
  var runtimeSemver = new Semver(runtimeAttr).version;
10
9
  var isInList = listOfSemvers.has(runtimeSemver);
@@ -1,6 +1,5 @@
1
- import { _Set } from '../../utils/lang/sets';
2
1
  export function whitelistMatcherContext(ruleAttr) {
3
- var whitelistSet = new _Set(ruleAttr);
2
+ var whitelistSet = new Set(ruleAttr);
4
3
  return function whitelistMatcher(runtimeAttr) {
5
4
  var isInWhitelist = whitelistSet.has(runtimeAttr);
6
5
  return isInWhitelist;
@@ -97,7 +97,6 @@ var BrowserSignalListener = /** @class */ (function () {
97
97
  * Returns true if beacon API was used successfully, false otherwise.
98
98
  */
99
99
  BrowserSignalListener.prototype._sendBeacon = function (url, data, extraMetadata) {
100
- // eslint-disable-next-line compat/compat
101
100
  if (typeof navigator !== 'undefined' && navigator.sendBeacon) {
102
101
  var json = {
103
102
  entries: data,
@@ -110,7 +109,7 @@ var BrowserSignalListener = /** @class */ (function () {
110
109
  // Stringify the payload
111
110
  var payload = JSON.stringify(json);
112
111
  // https://xgwang.me/posts/you-may-not-know-beacon/#it-may-throw-error%2C-be-sure-to-catch
113
- try { // eslint-disable-next-line compat/compat
112
+ try {
114
113
  return navigator.sendBeacon(url, payload);
115
114
  }
116
115
  catch (e) {
@@ -1,6 +1,5 @@
1
1
  import { Logger } from '../index';
2
2
  import { codesDebug } from '../messages/debug';
3
- import { _Map } from '../../utils/lang/maps';
4
3
  export function DebugLogger() {
5
- return new Logger({ logLevel: 'DEBUG' }, new _Map(codesDebug));
4
+ return new Logger({ logLevel: 'DEBUG' }, new Map(codesDebug));
6
5
  }
@@ -1,6 +1,5 @@
1
1
  import { Logger } from '../index';
2
2
  import { codesError } from '../messages/error';
3
- import { _Map } from '../../utils/lang/maps';
4
3
  export function ErrorLogger() {
5
- return new Logger({ logLevel: 'ERROR' }, new _Map(codesError));
4
+ return new Logger({ logLevel: 'ERROR' }, new Map(codesError));
6
5
  }
@@ -1,6 +1,5 @@
1
1
  import { Logger } from '../index';
2
2
  import { codesInfo } from '../messages/info';
3
- import { _Map } from '../../utils/lang/maps';
4
3
  export function InfoLogger() {
5
- return new Logger({ logLevel: 'INFO' }, new _Map(codesInfo));
4
+ return new Logger({ logLevel: 'INFO' }, new Map(codesInfo));
6
5
  }
@@ -1,6 +1,5 @@
1
1
  import { Logger } from '../index';
2
2
  import { codesWarn } from '../messages/warn';
3
- import { _Map } from '../../utils/lang/maps';
4
3
  export function WarnLogger() {
5
- return new Logger({ logLevel: 'WARN' }, new _Map(codesWarn));
4
+ return new Logger({ logLevel: 'WARN' }, new Map(codesWarn));
6
5
  }
@@ -1,6 +1,5 @@
1
1
  import { objectAssign } from '../utils/lang/objectAssign';
2
2
  import { find, isObject } from '../utils/lang';
3
- import { _Map } from '../utils/lang/maps';
4
3
  export var LogLevels = {
5
4
  DEBUG: 'DEBUG',
6
5
  INFO: 'INFO',
@@ -42,7 +41,7 @@ var defaultOptions = {
42
41
  var Logger = /** @class */ (function () {
43
42
  function Logger(options, codes) {
44
43
  this.options = objectAssign({}, defaultOptions, options);
45
- this.codes = codes || new _Map();
44
+ this.codes = codes || new Map();
46
45
  this.logLevel = LogLevelIndexes[this.options.logLevel];
47
46
  }
48
47
  Logger.prototype.setLogLevel = function (logLevel) {
@@ -1,16 +1,15 @@
1
1
  import { objectAssign } from '../utils/lang/objectAssign';
2
2
  import { clientAttributesDecoration } from './clientAttributesDecoration';
3
3
  /**
4
- * Decorator that binds a key and (optionally) a traffic type to client methods
4
+ * Decorator that binds a key to client methods
5
5
  *
6
6
  * @param client sync client instance
7
7
  * @param key validated split key
8
- * @param trafficType validated traffic type
9
8
  */
10
- export function clientCSDecorator(log, client, key, trafficType) {
9
+ export function clientCSDecorator(log, client, key) {
11
10
  var clientCS = clientAttributesDecoration(log, client);
12
11
  return objectAssign(clientCS, {
13
- // In the client-side API, we bind a key to the client `getTreatment*` methods
12
+ // In the client-side API, we bind a key to the client `getTreatment*` and `track` methods
14
13
  getTreatment: clientCS.getTreatment.bind(clientCS, key),
15
14
  getTreatmentWithConfig: clientCS.getTreatmentWithConfig.bind(clientCS, key),
16
15
  getTreatments: clientCS.getTreatments.bind(clientCS, key),
@@ -19,11 +18,9 @@ export function clientCSDecorator(log, client, key, trafficType) {
19
18
  getTreatmentsWithConfigByFlagSets: clientCS.getTreatmentsWithConfigByFlagSets.bind(clientCS, key),
20
19
  getTreatmentsByFlagSet: clientCS.getTreatmentsByFlagSet.bind(clientCS, key),
21
20
  getTreatmentsWithConfigByFlagSet: clientCS.getTreatmentsWithConfigByFlagSet.bind(clientCS, key),
22
- // Key is bound to the `track` method. Same thing happens with trafficType but only if provided
23
- track: trafficType ? clientCS.track.bind(clientCS, key, trafficType) : clientCS.track.bind(clientCS, key),
21
+ track: clientCS.track.bind(clientCS, key),
24
22
  // Not part of the public API. These properties are used to support other modules (e.g., Split Suite)
25
23
  isClientSide: true,
26
- key: key,
27
- trafficType: trafficType
24
+ key: key
28
25
  });
29
26
  }
@@ -22,7 +22,7 @@ export function sdkClientMethodCSFactory(params) {
22
22
  log.debug(RETRIEVE_CLIENT_DEFAULT);
23
23
  return mainClientInstance;
24
24
  }
25
- // Validate the key value. The trafficType (2nd argument) is ignored
25
+ // Validate the key value
26
26
  var validKey = validateKey(log, key, LOG_PREFIX_CLIENT_INSTANTIATION);
27
27
  if (validKey === false) {
28
28
  throw new Error('Shared Client needs a valid key.');
@@ -5,7 +5,7 @@ import { telemetryTrackerFactory } from '../trackers/telemetryTracker';
5
5
  import { validateAndTrackApiKey } from '../utils/inputValidation/apiKey';
6
6
  import { createLoggerAPI } from '../logger/sdkLogger';
7
7
  import { NEW_FACTORY, RETRIEVE_MANAGER } from '../logger/constants';
8
- import { SDK_SPLITS_ARRIVED, SDK_SEGMENTS_ARRIVED, SDK_SPLITS_CACHE_LOADED } from '../readiness/constants';
8
+ import { SDK_SPLITS_ARRIVED, SDK_SEGMENTS_ARRIVED } from '../readiness/constants';
9
9
  import { objectAssign } from '../utils/lang/objectAssign';
10
10
  import { strategyDebugFactory } from '../trackers/strategy/strategyDebug';
11
11
  import { strategyOptimizedFactory } from '../trackers/strategy/strategyOptimized';
@@ -35,10 +35,8 @@ export function sdkFactory(params) {
35
35
  readiness.splits.emit(SDK_SPLITS_ARRIVED);
36
36
  readiness.segments.emit(SDK_SEGMENTS_ARRIVED);
37
37
  },
38
- onReadyFromCacheCb: function () {
39
- readiness.splits.emit(SDK_SPLITS_CACHE_LOADED);
40
- }
41
38
  });
39
+ // @TODO add support for dataloader: `if (params.dataLoader) params.dataLoader(storage);`
42
40
  var clients = {};
43
41
  var telemetryTracker = telemetryTrackerFactory(storage.telemetry, platform.now);
44
42
  var integrationsManager = integrationsManagerFactory && integrationsManagerFactory({ settings: settings, storage: storage, telemetryTracker: telemetryTracker });
@@ -1,6 +1,5 @@
1
1
  import { objectAssign } from '../utils/lang/objectAssign';
2
- import { _Set } from '../utils/lang/sets';
3
- var FORBIDDEN_HEADERS = new _Set([
2
+ var FORBIDDEN_HEADERS = new Set([
4
3
  'splitsdkclientkey',
5
4
  'splitsdkversion',
6
5
  'splitsdkmachineip',
@@ -11,6 +11,13 @@ var AbstractSplitsCacheAsync = /** @class */ (function () {
11
11
  AbstractSplitsCacheAsync.prototype.usesSegments = function () {
12
12
  return Promise.resolve(true);
13
13
  };
14
+ /**
15
+ * Check if the splits information is already stored in cache.
16
+ * Noop, just keeping the interface. This is used by client-side implementations only.
17
+ */
18
+ AbstractSplitsCacheAsync.prototype.checkCache = function () {
19
+ return Promise.resolve(false);
20
+ };
14
21
  /**
15
22
  * Kill `name` split and set `defaultTreatment` and `changeNumber`.
16
23
  * Used for SPLIT_KILL push notifications.
@@ -27,6 +27,13 @@ var AbstractSplitsCacheSync = /** @class */ (function () {
27
27
  var _this = this;
28
28
  return this.getSplitNames().map(function (key) { return _this.getSplit(key); });
29
29
  };
30
+ /**
31
+ * Check if the splits information is already stored in cache. This data can be preloaded.
32
+ * It is used as condition to emit SDK_SPLITS_CACHE_LOADED, and then SDK_READY_FROM_CACHE.
33
+ */
34
+ AbstractSplitsCacheSync.prototype.checkCache = function () {
35
+ return false;
36
+ };
30
37
  /**
31
38
  * Kill `name` split and set `defaultTreatment` and `changeNumber`.
32
39
  * Used for SPLIT_KILL push notifications.
@@ -20,12 +20,6 @@ var KeyBuilderCS = /** @class */ (function (_super) {
20
20
  if (startsWith(builtSegmentKeyName, prefix))
21
21
  return builtSegmentKeyName.substr(prefix.length);
22
22
  };
23
- // @BREAKING: The key used to start with the matching key instead of the prefix, this was changed on version 10.17.3
24
- KeyBuilderCS.prototype.extractOldSegmentKey = function (builtSegmentKeyName) {
25
- var prefix = this.matchingKey + "." + this.prefix + ".segment.";
26
- if (startsWith(builtSegmentKeyName, prefix))
27
- return builtSegmentKeyName.substr(prefix.length);
28
- };
29
23
  KeyBuilderCS.prototype.buildLastUpdatedKey = function () {
30
24
  return this.prefix + ".splits.lastUpdated";
31
25
  };
@@ -48,9 +42,6 @@ export function myLargeSegmentsKeyBuilder(prefix, matchingKey) {
48
42
  if (startsWith(builtSegmentKeyName, p))
49
43
  return builtSegmentKeyName.substr(p.length);
50
44
  },
51
- extractOldSegmentKey: function () {
52
- return undefined;
53
- },
54
45
  buildTillKey: function () {
55
46
  return prefix + "." + matchingKey + ".largeSegments.till";
56
47
  }
@@ -1,79 +1,47 @@
1
- import { setToArray } from '../utils/lang/sets';
1
+ import { DEFAULT_CACHE_EXPIRATION_IN_MILLIS } from '../utils/constants/browser';
2
2
  /**
3
- * Storage-agnostic adaptation of `loadDataIntoLocalStorage` function
4
- * (https://github.com/godaddy/split-javascript-data-loader/blob/master/src/load-data.js)
3
+ * Factory of client-side storage loader
5
4
  *
6
- * @param preloadedData validated data following the format proposed in https://github.com/godaddy/split-javascript-data-loader and extended with a `mySegmentsData` property.
7
- * @param storage object containing `splits` and `segments` cache (client-side variant)
8
- * @param userKey user key (matching key) of the provided MySegmentsCache
9
- *
10
- * @TODO extend to load largeSegments
11
- * @TODO extend to load data on shared mySegments storages. Be specific when emitting SDK_READY_FROM_CACHE on shared clients. Maybe the serializer should provide the `useSegments` flag.
12
- * @TODO add logs, and input validation in this module, in favor of size reduction.
13
- * @TODO unit tests
5
+ * @param preloadedData validated data following the format proposed in https://github.com/godaddy/split-javascript-data-loader
6
+ * and extended with a `mySegmentsData` property.
7
+ * @returns function to preload the storage
14
8
  */
15
- export function loadData(preloadedData, storage, userKey) {
16
- // Do not load data if current preloadedData is empty
17
- if (Object.keys(preloadedData).length === 0)
18
- return;
19
- var _a = preloadedData.segmentsData, segmentsData = _a === void 0 ? {} : _a, _b = preloadedData.since, since = _b === void 0 ? -1 : _b, _c = preloadedData.splitsData, splitsData = _c === void 0 ? [] : _c;
20
- if (storage.splits) {
9
+ export function dataLoaderFactory(preloadedData) {
10
+ /**
11
+ * Storage-agnostic adaptation of `loadDataIntoLocalStorage` function
12
+ * (https://github.com/godaddy/split-javascript-data-loader/blob/master/src/load-data.js)
13
+ *
14
+ * @param storage object containing `splits` and `segments` cache (client-side variant)
15
+ * @param userId user key string of the provided MySegmentsCache
16
+ *
17
+ * @TODO extend to support SegmentsCache (server-side variant) by making `userId` optional and adding the corresponding logic.
18
+ * @TODO extend to load data on shared mySegments storages. Be specific when emitting SDK_READY_FROM_CACHE on shared clients. Maybe the serializer should provide the `useSegments` flag.
19
+ */
20
+ return function loadData(storage, userId) {
21
+ // Do not load data if current preloadedData is empty
22
+ if (Object.keys(preloadedData).length === 0)
23
+ return;
24
+ var _a = preloadedData.lastUpdated, lastUpdated = _a === void 0 ? -1 : _a, _b = preloadedData.segmentsData, segmentsData = _b === void 0 ? {} : _b, _c = preloadedData.since, since = _c === void 0 ? -1 : _c, _d = preloadedData.splitsData, splitsData = _d === void 0 ? {} : _d;
21
25
  var storedSince = storage.splits.getChangeNumber();
22
- // Do not load data if current data is more recent
23
- if (storedSince > since)
26
+ var expirationTimestamp = Date.now() - DEFAULT_CACHE_EXPIRATION_IN_MILLIS;
27
+ // Do not load data if current localStorage data is more recent,
28
+ // or if its `lastUpdated` timestamp is older than the given `expirationTimestamp`,
29
+ if (storedSince > since || lastUpdated < expirationTimestamp)
24
30
  return;
25
31
  // cleaning up the localStorage data, since some cached splits might need be part of the preloaded data
26
32
  storage.splits.clear();
27
33
  storage.splits.setChangeNumber(since);
28
34
  // splitsData in an object where the property is the split name and the pertaining value is a stringified json of its data
29
- storage.splits.addSplits(splitsData.map(function (split) { return ([split.name, split]); }));
30
- }
31
- if (userKey) { // add mySegments data (client-side)
32
- var mySegmentsData = preloadedData.mySegmentsData && preloadedData.mySegmentsData[userKey];
35
+ storage.splits.addSplits(Object.keys(splitsData).map(function (splitName) { return JSON.parse(splitsData[splitName]); }));
36
+ // add mySegments data
37
+ var mySegmentsData = preloadedData.mySegmentsData && preloadedData.mySegmentsData[userId];
33
38
  if (!mySegmentsData) {
34
39
  // segmentsData in an object where the property is the segment name and the pertaining value is a stringified object that contains the `added` array of userIds
35
40
  mySegmentsData = Object.keys(segmentsData).filter(function (segmentName) {
36
- var userKeys = segmentsData[segmentName];
37
- return userKeys.indexOf(userKey) > -1;
41
+ var userIds = JSON.parse(segmentsData[segmentName]).added;
42
+ return Array.isArray(userIds) && userIds.indexOf(userId) > -1;
38
43
  });
39
44
  }
40
45
  storage.segments.resetSegments({ k: mySegmentsData.map(function (s) { return ({ n: s }); }) });
41
- }
42
- else { // add segments data (server-side)
43
- Object.keys(segmentsData).filter(function (segmentName) {
44
- var userKeys = segmentsData[segmentName];
45
- storage.segments.addToSegment(segmentName, userKeys);
46
- });
47
- }
48
- }
49
- export function getSnapshot(storage, userKeys) {
50
- return {
51
- // lastUpdated: Date.now(),
52
- // @ts-ignore accessing private prop
53
- since: storage.splits.changeNumber,
54
- splitsData: storage.splits.getAll(),
55
- segmentsData: userKeys ?
56
- undefined : // @ts-ignore accessing private prop
57
- Object.keys(storage.segments.segmentCache).reduce(function (prev, cur) {
58
- prev[cur] = setToArray(storage.segments.segmentCache[cur]);
59
- return prev;
60
- }, {}),
61
- mySegmentsData: userKeys ?
62
- userKeys.reduce(function (prev, userKey) {
63
- // @ts-ignore accessing private prop
64
- prev[userKey] = storage.shared ?
65
- // Client-side segments
66
- // @ts-ignore accessing private prop
67
- Object.keys(storage.shared(userKey).segments.segmentCache) :
68
- // Server-side segments
69
- // @ts-ignore accessing private prop
70
- Object.keys(storage.segments.segmentCache).reduce(function (prev, segmentName) {
71
- return storage.segments.segmentCache[segmentName].has(userKey) ?
72
- prev.concat(segmentName) :
73
- prev;
74
- }, []);
75
- return prev;
76
- }, {}) :
77
- undefined
78
46
  };
79
47
  }
@@ -45,28 +45,8 @@ var MySegmentsCacheInLocal = /** @class */ (function (_super) {
45
45
  // Scan current values from localStorage
46
46
  return Object.keys(localStorage).reduce(function (accum, key) {
47
47
  var segmentName = _this.keys.extractSegmentName(key);
48
- if (segmentName) {
48
+ if (segmentName)
49
49
  accum.push(segmentName);
50
- }
51
- else {
52
- // @TODO @BREAKING: This is only to clean up "old" keys. Remove this whole else code block
53
- segmentName = _this.keys.extractOldSegmentKey(key);
54
- if (segmentName) { // this was an old segment key, let's clean up.
55
- var newSegmentKey = _this.keys.buildSegmentNameKey(segmentName);
56
- try {
57
- // If the new format key is not there, create it.
58
- if (!localStorage.getItem(newSegmentKey)) {
59
- localStorage.setItem(newSegmentKey, DEFINED);
60
- // we are migrating a segment, let's track it.
61
- accum.push(segmentName);
62
- }
63
- localStorage.removeItem(key); // we migrated the current key, let's delete it.
64
- }
65
- catch (e) {
66
- _this.log.error(e);
67
- }
68
- }
69
- }
70
50
  return accum;
71
51
  }, []);
72
52
  };