@splitsoftware/splitio-commons 1.17.1-rc.3 → 1.17.1-rc.5

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 (275) hide show
  1. package/CHANGES.txt +28 -28
  2. package/LICENSE +1 -1
  3. package/README.md +4 -3
  4. package/cjs/consent/sdkUserConsent.js +4 -2
  5. package/cjs/evaluator/matchers/index.js +1 -3
  6. package/cjs/evaluator/matchers/matcherTypes.js +0 -1
  7. package/cjs/evaluator/matchers/segment.js +0 -6
  8. package/cjs/evaluator/matchersTransform/index.js +1 -4
  9. package/cjs/evaluator/matchersTransform/segment.js +1 -3
  10. package/cjs/logger/constants.js +2 -2
  11. package/cjs/logger/messages/info.js +1 -1
  12. package/cjs/logger/messages/warn.js +1 -1
  13. package/cjs/readiness/readinessManager.js +11 -12
  14. package/cjs/readiness/sdkReadinessManager.js +6 -5
  15. package/cjs/sdkClient/sdkClient.js +5 -5
  16. package/cjs/sdkClient/sdkClientMethod.js +1 -3
  17. package/cjs/sdkClient/sdkClientMethodCS.js +17 -15
  18. package/cjs/sdkClient/sdkClientMethodCSWithTT.js +17 -15
  19. package/cjs/sdkFactory/index.js +11 -38
  20. package/cjs/services/decorateHeaders.js +6 -1
  21. package/cjs/services/splitApi.js +5 -5
  22. package/cjs/services/splitHttpClient.js +5 -2
  23. package/cjs/storages/AbstractSegmentsCacheSync.js +12 -41
  24. package/cjs/storages/AbstractSplitsCacheAsync.js +7 -0
  25. package/cjs/storages/AbstractSplitsCacheSync.js +8 -2
  26. package/cjs/storages/KeyBuilderCS.js +5 -23
  27. package/cjs/storages/dataLoader.js +33 -65
  28. package/cjs/storages/inLocalStorage/MySegmentsCacheInLocal.js +52 -29
  29. package/cjs/storages/inLocalStorage/SplitsCacheInLocal.js +9 -1
  30. package/cjs/storages/inLocalStorage/index.js +3 -12
  31. package/cjs/storages/inMemory/InMemoryStorageCS.js +3 -20
  32. package/cjs/storages/inMemory/MySegmentsCacheInMemory.js +40 -9
  33. package/cjs/storages/inMemory/SegmentsCacheInMemory.js +1 -1
  34. package/cjs/storages/inMemory/SplitsCacheInMemory.js +8 -8
  35. package/cjs/storages/inMemory/TelemetryCacheInMemory.js +10 -7
  36. package/cjs/storages/inRedis/RedisAdapter.js +1 -1
  37. package/cjs/storages/inRedis/SegmentsCacheInRedis.js +2 -2
  38. package/cjs/storages/inRedis/index.js +11 -5
  39. package/cjs/storages/pluggable/SegmentsCachePluggable.js +2 -2
  40. package/cjs/storages/pluggable/inMemoryWrapper.js +1 -1
  41. package/cjs/storages/pluggable/index.js +32 -37
  42. package/cjs/sync/offline/syncTasks/fromObjectSyncTask.js +7 -2
  43. package/cjs/sync/polling/fetchers/mySegmentsFetcher.js +8 -5
  44. package/cjs/sync/polling/fetchers/segmentChangesFetcher.js +1 -1
  45. package/cjs/sync/polling/pollingManagerCS.js +1 -1
  46. package/cjs/sync/polling/pollingManagerSS.js +3 -3
  47. package/cjs/sync/polling/syncTasks/mySegmentsSyncTask.js +2 -2
  48. package/cjs/sync/polling/updaters/mySegmentsUpdater.js +21 -15
  49. package/cjs/sync/polling/updaters/segmentChangesUpdater.js +2 -2
  50. package/cjs/sync/polling/updaters/splitChangesUpdater.js +11 -2
  51. package/cjs/sync/streaming/AuthClient/index.js +1 -1
  52. package/cjs/sync/streaming/SSEHandler/index.js +5 -3
  53. package/cjs/sync/streaming/UpdateWorkers/MySegmentsUpdateWorker.js +48 -107
  54. package/cjs/sync/streaming/UpdateWorkers/SegmentsUpdateWorker.js +3 -3
  55. package/cjs/sync/streaming/constants.js +3 -3
  56. package/cjs/sync/streaming/parseUtils.js +9 -14
  57. package/cjs/sync/streaming/pushManager.js +67 -69
  58. package/cjs/sync/syncTask.js +2 -2
  59. package/cjs/trackers/eventTracker.js +9 -11
  60. package/cjs/trackers/impressionsTracker.js +13 -15
  61. package/cjs/trackers/uniqueKeysTracker.js +3 -5
  62. package/cjs/utils/constants/index.js +4 -5
  63. package/cjs/utils/settingsValidation/index.js +1 -2
  64. package/cjs/utils/settingsValidation/storage/storageCS.js +12 -1
  65. package/esm/consent/sdkUserConsent.js +4 -2
  66. package/esm/evaluator/matchers/index.js +1 -3
  67. package/esm/evaluator/matchers/matcherTypes.js +0 -1
  68. package/esm/evaluator/matchers/segment.js +0 -6
  69. package/esm/evaluator/matchersTransform/index.js +1 -4
  70. package/esm/evaluator/matchersTransform/segment.js +1 -3
  71. package/esm/logger/constants.js +1 -1
  72. package/esm/logger/messages/info.js +1 -1
  73. package/esm/logger/messages/warn.js +1 -1
  74. package/esm/readiness/readinessManager.js +11 -12
  75. package/esm/readiness/sdkReadinessManager.js +6 -5
  76. package/esm/sdkClient/sdkClient.js +5 -5
  77. package/esm/sdkClient/sdkClientMethod.js +1 -3
  78. package/esm/sdkClient/sdkClientMethodCS.js +15 -13
  79. package/esm/sdkClient/sdkClientMethodCSWithTT.js +15 -13
  80. package/esm/sdkFactory/index.js +12 -39
  81. package/esm/services/decorateHeaders.js +4 -0
  82. package/esm/services/splitApi.js +6 -6
  83. package/esm/services/splitHttpClient.js +6 -3
  84. package/esm/storages/AbstractSegmentsCacheSync.js +12 -41
  85. package/esm/storages/AbstractSplitsCacheAsync.js +7 -0
  86. package/esm/storages/AbstractSplitsCacheSync.js +9 -3
  87. package/esm/storages/KeyBuilderCS.js +4 -21
  88. package/esm/storages/dataLoader.js +31 -62
  89. package/esm/storages/inLocalStorage/MySegmentsCacheInLocal.js +52 -29
  90. package/esm/storages/inLocalStorage/SplitsCacheInLocal.js +9 -1
  91. package/esm/storages/inLocalStorage/index.js +5 -14
  92. package/esm/storages/inMemory/InMemoryStorageCS.js +3 -20
  93. package/esm/storages/inMemory/MySegmentsCacheInMemory.js +40 -9
  94. package/esm/storages/inMemory/SegmentsCacheInMemory.js +1 -1
  95. package/esm/storages/inMemory/SplitsCacheInMemory.js +8 -8
  96. package/esm/storages/inMemory/TelemetryCacheInMemory.js +10 -7
  97. package/esm/storages/inRedis/RedisAdapter.js +1 -1
  98. package/esm/storages/inRedis/SegmentsCacheInRedis.js +2 -2
  99. package/esm/storages/inRedis/index.js +11 -5
  100. package/esm/storages/pluggable/SegmentsCachePluggable.js +2 -2
  101. package/esm/storages/pluggable/inMemoryWrapper.js +1 -1
  102. package/esm/storages/pluggable/index.js +32 -37
  103. package/esm/sync/offline/syncTasks/fromObjectSyncTask.js +8 -3
  104. package/esm/sync/polling/fetchers/mySegmentsFetcher.js +8 -5
  105. package/esm/sync/polling/fetchers/segmentChangesFetcher.js +1 -1
  106. package/esm/sync/polling/pollingManagerCS.js +1 -1
  107. package/esm/sync/polling/pollingManagerSS.js +3 -3
  108. package/esm/sync/polling/syncTasks/mySegmentsSyncTask.js +2 -2
  109. package/esm/sync/polling/updaters/mySegmentsUpdater.js +21 -15
  110. package/esm/sync/polling/updaters/segmentChangesUpdater.js +2 -2
  111. package/esm/sync/polling/updaters/splitChangesUpdater.js +12 -3
  112. package/esm/sync/streaming/AuthClient/index.js +1 -1
  113. package/esm/sync/streaming/SSEHandler/index.js +6 -4
  114. package/esm/sync/streaming/UpdateWorkers/MySegmentsUpdateWorker.js +49 -108
  115. package/esm/sync/streaming/UpdateWorkers/SegmentsUpdateWorker.js +3 -3
  116. package/esm/sync/streaming/constants.js +2 -2
  117. package/esm/sync/streaming/parseUtils.js +8 -12
  118. package/esm/sync/streaming/pushManager.js +70 -72
  119. package/esm/sync/syncTask.js +2 -2
  120. package/esm/trackers/eventTracker.js +9 -11
  121. package/esm/trackers/impressionsTracker.js +13 -15
  122. package/esm/trackers/uniqueKeysTracker.js +3 -5
  123. package/esm/utils/constants/index.js +2 -3
  124. package/esm/utils/settingsValidation/index.js +1 -2
  125. package/esm/utils/settingsValidation/storage/storageCS.js +10 -0
  126. package/package.json +1 -1
  127. package/src/consent/sdkUserConsent.ts +3 -2
  128. package/src/dtos/types.ts +7 -21
  129. package/src/evaluator/matchers/index.ts +0 -2
  130. package/src/evaluator/matchers/matcherTypes.ts +0 -1
  131. package/src/evaluator/matchers/segment.ts +0 -7
  132. package/src/evaluator/matchersTransform/index.ts +1 -4
  133. package/src/evaluator/matchersTransform/segment.ts +3 -5
  134. package/src/logger/constants.ts +1 -1
  135. package/src/logger/messages/info.ts +1 -1
  136. package/src/logger/messages/warn.ts +1 -1
  137. package/src/readiness/readinessManager.ts +12 -16
  138. package/src/readiness/sdkReadinessManager.ts +7 -7
  139. package/src/readiness/types.ts +2 -3
  140. package/src/sdkClient/sdkClient.ts +5 -5
  141. package/src/sdkClient/sdkClientMethod.ts +1 -4
  142. package/src/sdkClient/sdkClientMethodCS.ts +14 -11
  143. package/src/sdkClient/sdkClientMethodCSWithTT.ts +14 -11
  144. package/src/sdkFactory/index.ts +13 -42
  145. package/src/sdkFactory/types.ts +1 -5
  146. package/src/services/decorateHeaders.ts +5 -0
  147. package/src/services/splitApi.ts +7 -7
  148. package/src/services/splitHttpClient.ts +7 -4
  149. package/src/services/types.ts +2 -2
  150. package/src/storages/AbstractSegmentsCacheSync.ts +12 -53
  151. package/src/storages/AbstractSplitsCacheAsync.ts +8 -0
  152. package/src/storages/AbstractSplitsCacheSync.ts +11 -4
  153. package/src/storages/KeyBuilderCS.ts +5 -34
  154. package/src/storages/dataLoader.ts +33 -63
  155. package/src/storages/inLocalStorage/MySegmentsCacheInLocal.ts +59 -29
  156. package/src/storages/inLocalStorage/SplitsCacheInLocal.ts +10 -1
  157. package/src/storages/inLocalStorage/index.ts +6 -16
  158. package/src/storages/inMemory/InMemoryStorageCS.ts +3 -23
  159. package/src/storages/inMemory/MySegmentsCacheInMemory.ts +44 -10
  160. package/src/storages/inMemory/SegmentsCacheInMemory.ts +1 -1
  161. package/src/storages/inMemory/SplitsCacheInMemory.ts +8 -7
  162. package/src/storages/inMemory/TelemetryCacheInMemory.ts +11 -7
  163. package/src/storages/inRedis/RedisAdapter.ts +1 -1
  164. package/src/storages/inRedis/SegmentsCacheInRedis.ts +2 -2
  165. package/src/storages/inRedis/index.ts +12 -6
  166. package/src/storages/pluggable/SegmentsCachePluggable.ts +2 -2
  167. package/src/storages/pluggable/inMemoryWrapper.ts +1 -1
  168. package/src/storages/pluggable/index.ts +33 -38
  169. package/src/storages/types.ts +15 -15
  170. package/src/sync/offline/syncTasks/fromObjectSyncTask.ts +7 -3
  171. package/src/sync/polling/fetchers/mySegmentsFetcher.ts +10 -8
  172. package/src/sync/polling/fetchers/segmentChangesFetcher.ts +1 -1
  173. package/src/sync/polling/fetchers/types.ts +2 -3
  174. package/src/sync/polling/pollingManagerCS.ts +4 -4
  175. package/src/sync/polling/pollingManagerSS.ts +2 -3
  176. package/src/sync/polling/syncTasks/mySegmentsSyncTask.ts +5 -4
  177. package/src/sync/polling/types.ts +6 -7
  178. package/src/sync/polling/updaters/mySegmentsUpdater.ts +22 -19
  179. package/src/sync/polling/updaters/segmentChangesUpdater.ts +2 -2
  180. package/src/sync/polling/updaters/splitChangesUpdater.ts +12 -4
  181. package/src/sync/streaming/AuthClient/index.ts +1 -1
  182. package/src/sync/streaming/SSEClient/index.ts +6 -4
  183. package/src/sync/streaming/SSEHandler/index.ts +8 -5
  184. package/src/sync/streaming/SSEHandler/types.ts +15 -15
  185. package/src/sync/streaming/UpdateWorkers/MySegmentsUpdateWorker.ts +49 -116
  186. package/src/sync/streaming/UpdateWorkers/SegmentsUpdateWorker.ts +4 -4
  187. package/src/sync/streaming/UpdateWorkers/SplitsUpdateWorker.ts +1 -1
  188. package/src/sync/streaming/UpdateWorkers/types.ts +2 -2
  189. package/src/sync/streaming/constants.ts +2 -2
  190. package/src/sync/streaming/parseUtils.ts +11 -19
  191. package/src/sync/streaming/pushManager.ts +72 -73
  192. package/src/sync/streaming/types.ts +10 -10
  193. package/src/sync/submitters/types.ts +5 -8
  194. package/src/sync/syncTask.ts +2 -2
  195. package/src/trackers/eventTracker.ts +7 -10
  196. package/src/trackers/impressionsTracker.ts +9 -12
  197. package/src/trackers/types.ts +0 -1
  198. package/src/trackers/uniqueKeysTracker.ts +4 -6
  199. package/src/types.ts +9 -16
  200. package/src/utils/constants/index.ts +2 -3
  201. package/src/utils/settingsValidation/index.ts +2 -3
  202. package/src/utils/settingsValidation/storage/storageCS.ts +13 -0
  203. package/src/utils/settingsValidation/types.ts +1 -1
  204. package/types/dtos/types.d.ts +7 -18
  205. package/types/evaluator/matchersTransform/segment.d.ts +2 -2
  206. package/types/logger/constants.d.ts +1 -1
  207. package/types/readiness/readinessManager.d.ts +2 -2
  208. package/types/readiness/sdkReadinessManager.d.ts +3 -2
  209. package/types/readiness/types.d.ts +2 -3
  210. package/types/sdkClient/sdkClientMethod.d.ts +1 -1
  211. package/types/sdkFactory/types.d.ts +1 -4
  212. package/types/services/decorateHeaders.d.ts +1 -0
  213. package/types/services/splitApi.d.ts +1 -1
  214. package/types/services/splitHttpClient.d.ts +1 -1
  215. package/types/services/types.d.ts +2 -2
  216. package/types/storages/AbstractSegmentsCacheSync.d.ts +11 -9
  217. package/types/storages/AbstractSplitsCacheAsync.d.ts +5 -0
  218. package/types/storages/AbstractSplitsCacheSync.d.ts +6 -1
  219. package/types/storages/KeyBuilderCS.d.ts +2 -9
  220. package/types/storages/dataLoader.d.ts +6 -17
  221. package/types/storages/inLocalStorage/MySegmentsCacheInLocal.d.ts +14 -4
  222. package/types/storages/inLocalStorage/SplitsCacheInLocal.d.ts +6 -0
  223. package/types/storages/inMemory/MySegmentsCacheInMemory.d.ts +9 -3
  224. package/types/storages/inMemory/SegmentsCacheInMemory.d.ts +1 -1
  225. package/types/storages/inMemory/SplitsCacheInMemory.d.ts +1 -1
  226. package/types/storages/inMemory/TelemetryCacheInMemory.d.ts +6 -4
  227. package/types/storages/inRedis/SegmentsCacheInRedis.d.ts +1 -1
  228. package/types/storages/inRedis/index.d.ts +1 -1
  229. package/types/storages/pluggable/SegmentsCachePluggable.d.ts +1 -1
  230. package/types/storages/pluggable/inMemoryWrapper.d.ts +1 -1
  231. package/types/storages/types.d.ts +11 -11
  232. package/types/sync/polling/fetchers/mySegmentsFetcher.d.ts +2 -2
  233. package/types/sync/polling/fetchers/types.d.ts +2 -2
  234. package/types/sync/polling/syncTasks/mySegmentsSyncTask.d.ts +2 -2
  235. package/types/sync/polling/types.d.ts +4 -7
  236. package/types/sync/polling/updaters/mySegmentsUpdater.d.ts +3 -4
  237. package/types/sync/streaming/SSEHandler/types.d.ts +14 -16
  238. package/types/sync/streaming/UpdateWorkers/MySegmentsUpdateWorker.d.ts +2 -4
  239. package/types/sync/streaming/UpdateWorkers/SegmentsUpdateWorker.d.ts +1 -2
  240. package/types/sync/streaming/UpdateWorkers/SplitsUpdateWorker.d.ts +2 -3
  241. package/types/sync/streaming/UpdateWorkers/types.d.ts +2 -2
  242. package/types/sync/streaming/constants.d.ts +2 -2
  243. package/types/sync/streaming/parseUtils.d.ts +5 -4
  244. package/types/sync/streaming/types.d.ts +8 -8
  245. package/types/sync/submitters/types.d.ts +4 -7
  246. package/types/trackers/eventTracker.d.ts +1 -1
  247. package/types/trackers/impressionsTracker.d.ts +1 -1
  248. package/types/trackers/types.d.ts +0 -1
  249. package/types/types.d.ts +9 -15
  250. package/types/utils/constants/index.d.ts +2 -3
  251. package/types/utils/settingsValidation/storage/storageCS.d.ts +5 -0
  252. package/types/utils/settingsValidation/types.d.ts +1 -1
  253. package/cjs/evaluator/matchers/large_segment.js +0 -16
  254. package/cjs/sdkClient/identity.js +0 -7
  255. package/esm/evaluator/matchers/large_segment.js +0 -12
  256. package/esm/sdkClient/identity.js +0 -3
  257. package/src/evaluator/matchers/large_segment.ts +0 -18
  258. package/src/sdkClient/identity.ts +0 -5
  259. package/types/evaluator/matchers/large_segment.d.ts +0 -5
  260. package/types/evaluator/matchers/sember_inlist.d.ts +0 -3
  261. package/types/evaluator/matchersTransform/set.d.ts +0 -5
  262. package/types/evaluator/matchersTransform/string.d.ts +0 -7
  263. package/types/sdkClient/identity.d.ts +0 -2
  264. package/types/storages/AbstractMySegmentsCacheSync.d.ts +0 -39
  265. package/types/storages/AbstractSplitsCache.d.ts +0 -46
  266. package/types/sync/streaming/mySegmentsV2utils.d.ts +0 -27
  267. package/types/sync/streaming/pushManagerCS_Spec1_3.d.ts +0 -9
  268. package/types/sync/streaming/pushManager_Spec1_3.d.ts +0 -9
  269. package/types/trackers/impressionObserver/utils.d.ts +0 -5
  270. package/types/utils/inputValidation/sdkKey.d.ts +0 -7
  271. package/types/utils/inputValidation/splitExistance.d.ts +0 -7
  272. package/types/utils/inputValidation/trafficTypeExistance.d.ts +0 -9
  273. package/types/utils/redis/RedisMock.d.ts +0 -4
  274. package/types/utils/settingsValidation/logger/globalLogLevel.d.ts +0 -8
  275. /package/types/utils/{semVer.d.ts → Semver.d.ts} +0 -0
@@ -30,3 +30,7 @@ export function decorateHeaders(settings, headers) {
30
30
  }
31
31
  return headers;
32
32
  }
33
+ export function removeNonISO88591(input) {
34
+ // eslint-disable-next-line no-control-regex
35
+ return input.replace(/[^\x00-\xFF]/g, '');
36
+ }
@@ -1,6 +1,6 @@
1
1
  import { splitHttpClientFactory } from './splitHttpClient';
2
2
  import { objectAssign } from '../utils/lang/objectAssign';
3
- import { SPLITS, IMPRESSIONS, IMPRESSIONS_COUNT, EVENTS, TELEMETRY, TOKEN, SEGMENT, MEMBERSHIPS } from '../utils/constants';
3
+ import { SPLITS, IMPRESSIONS, IMPRESSIONS_COUNT, EVENTS, TELEMETRY, TOKEN, SEGMENT, MY_SEGMENT } from '../utils/constants';
4
4
  import { ERROR_TOO_MANY_SETS } from '../logger/constants';
5
5
  var noCacheHeaderOptions = { headers: { 'Cache-Control': 'no-cache' } };
6
6
  function userKeyToQueryParam(userKey) {
@@ -51,15 +51,15 @@ export function splitApiFactory(settings, platform, telemetryTracker) {
51
51
  var url = urls.sdk + "/segmentChanges/" + segmentName + "?since=" + since + (till ? '&till=' + till : '');
52
52
  return splitHttpClient(url, noCache ? noCacheHeaderOptions : undefined, telemetryTracker.trackHttp(SEGMENT));
53
53
  },
54
- fetchMemberships: function (userMatchingKey, noCache, till) {
54
+ fetchMySegments: function (userMatchingKey, noCache) {
55
55
  /**
56
56
  * URI encoding of user keys in order to:
57
- * - avoid 400 responses (due to URI malformed). E.g.: '/api/memberships/%'
58
- * - avoid 404 responses. E.g.: '/api/memberships/foo/bar'
57
+ * - avoid 400 responses (due to URI malformed). E.g.: '/api/mySegments/%'
58
+ * - avoid 404 responses. E.g.: '/api/mySegments/foo/bar'
59
59
  * - match user keys with special characters. E.g.: 'foo%bar', 'foo/bar'
60
60
  */
61
- var url = urls.sdk + "/memberships/" + encodeURIComponent(userMatchingKey) + (till ? '?till=' + till : '');
62
- return splitHttpClient(url, noCache ? noCacheHeaderOptions : undefined, telemetryTracker.trackHttp(MEMBERSHIPS));
61
+ var url = urls.sdk + "/mySegments/" + encodeURIComponent(userMatchingKey);
62
+ return splitHttpClient(url, noCache ? noCacheHeaderOptions : undefined, telemetryTracker.trackHttp(MY_SEGMENT));
63
63
  },
64
64
  /**
65
65
  * Post events.
@@ -1,6 +1,8 @@
1
1
  import { objectAssign } from '../utils/lang/objectAssign';
2
2
  import { ERROR_HTTP, ERROR_CLIENT_CANNOT_GET_READY } from '../logger/constants';
3
- import { decorateHeaders } from './decorateHeaders';
3
+ import { decorateHeaders, removeNonISO88591 } from './decorateHeaders';
4
+ import { timeout } from '../utils/promise/timeout';
5
+ var PENDING_FETCH_ERROR_TIMEOUT = 100;
4
6
  var messageNoFetch = 'Global fetch API is not available.';
5
7
  /**
6
8
  * Factory of Split HTTP clients, which are HTTP clients with predefined headers for Split endpoints.
@@ -25,7 +27,7 @@ export function splitHttpClientFactory(settings, _a) {
25
27
  if (ip)
26
28
  commonHeaders['SplitSDKMachineIP'] = ip;
27
29
  if (hostname)
28
- commonHeaders['SplitSDKMachineName'] = hostname;
30
+ commonHeaders['SplitSDKMachineName'] = removeNonISO88591(hostname);
29
31
  return function httpClient(url, reqOpts, latencyTracker, logErrorsAsInfo) {
30
32
  if (reqOpts === void 0) { reqOpts = {}; }
31
33
  if (latencyTracker === void 0) { latencyTracker = function () { }; }
@@ -40,7 +42,8 @@ export function splitHttpClientFactory(settings, _a) {
40
42
  // https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch#Checking_that_the_fetch_was_successful
41
43
  .then(function (response) {
42
44
  if (!response.ok) {
43
- return response.text().then(function (message) { return Promise.reject({ response: response, message: message }); });
45
+ // `text()` promise might not settle in some fetch implementations and cases (e.g. no content)
46
+ return timeout(PENDING_FETCH_ERROR_TIMEOUT, response.text()).then(function (message) { return Promise.reject({ response: response, message: message }); }, function () { return Promise.reject({ response: response }); });
44
47
  }
45
48
  latencyTracker();
46
49
  return response;
@@ -5,55 +5,26 @@
5
5
  var AbstractSegmentsCacheSync = /** @class */ (function () {
6
6
  function AbstractSegmentsCacheSync() {
7
7
  }
8
- /**
9
- * clear the cache.
10
- */
11
- AbstractSegmentsCacheSync.prototype.clear = function () {
12
- this.resetSegments({});
13
- };
14
8
  /**
15
9
  * For server-side synchronizer: add the given list of segments to the cache, with an empty list of keys. The segments that already exist are not modified.
16
10
  * For client-side synchronizer: the method is not used.
17
11
  */
18
12
  AbstractSegmentsCacheSync.prototype.registerSegments = function (names) { return false; };
13
+ /**
14
+ * For server-side synchronizer: set the change number of `name` segment.
15
+ * For client-side synchronizer: the method is not used.
16
+ */
17
+ AbstractSegmentsCacheSync.prototype.setChangeNumber = function (name, changeNumber) { return true; };
18
+ /**
19
+ * For server-side synchronizer: get the change number of `name` segment.
20
+ * For client-side synchronizer: the method is not used.
21
+ */
22
+ AbstractSegmentsCacheSync.prototype.getChangeNumber = function (name) { return -1; };
19
23
  /**
20
24
  * For server-side synchronizer: the method is not used.
21
- * For client-side synchronizer: it resets or updates the cache.
25
+ * For client-side synchronizer: reset the cache with the given list of segments.
22
26
  */
23
- AbstractSegmentsCacheSync.prototype.resetSegments = function (segmentsData) {
24
- var _this = this;
25
- this.setChangeNumber(undefined, segmentsData.cn);
26
- var _a = segmentsData, added = _a.added, removed = _a.removed;
27
- if (added && removed) {
28
- var isDiff_1 = false;
29
- added.forEach(function (segment) {
30
- isDiff_1 = _this.addToSegment(segment) || isDiff_1;
31
- });
32
- removed.forEach(function (segment) {
33
- isDiff_1 = _this.removeFromSegment(segment) || isDiff_1;
34
- });
35
- return isDiff_1;
36
- }
37
- var names = (segmentsData.k || []).map(function (s) { return s.n; }).sort();
38
- var storedSegmentKeys = this.getRegisteredSegments().sort();
39
- // Extreme fast => everything is empty
40
- if (!names.length && !storedSegmentKeys.length)
41
- return false;
42
- var index = 0;
43
- while (index < names.length && index < storedSegmentKeys.length && names[index] === storedSegmentKeys[index])
44
- index++;
45
- // Quick path => no changes
46
- if (index === names.length && index === storedSegmentKeys.length)
47
- return false;
48
- // Slowest path => add and/or remove segments
49
- for (var removeIndex = index; removeIndex < storedSegmentKeys.length; removeIndex++) {
50
- this.removeFromSegment(storedSegmentKeys[removeIndex]);
51
- }
52
- for (var addIndex = index; addIndex < names.length; addIndex++) {
53
- this.addToSegment(names[addIndex]);
54
- }
55
- return true;
56
- };
27
+ AbstractSegmentsCacheSync.prototype.resetSegments = function (names) { return true; };
57
28
  return AbstractSegmentsCacheSync;
58
29
  }());
59
30
  export { AbstractSegmentsCacheSync };
@@ -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.
@@ -1,5 +1,5 @@
1
1
  import { objectAssign } from '../utils/lang/objectAssign';
2
- import { IN_SEGMENT, IN_LARGE_SEGMENT } from '../utils/constants';
2
+ import { IN_SEGMENT } from '../utils/constants';
3
3
  /**
4
4
  * This class provides a skeletal implementation of the ISplitsCacheSync interface
5
5
  * to minimize the effort required to implement this interface.
@@ -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.
@@ -60,8 +67,7 @@ export function usesSegments(split) {
60
67
  for (var i = 0; i < conditions.length; i++) {
61
68
  var matchers = conditions[i].matcherGroup.matchers;
62
69
  for (var j = 0; j < matchers.length; j++) {
63
- var matcher = matchers[j].matcherType;
64
- if (matcher === IN_SEGMENT || matcher === IN_LARGE_SEGMENT)
70
+ if (matchers[j].matcherType === IN_SEGMENT)
65
71
  return true;
66
72
  }
67
73
  }
@@ -21,6 +21,10 @@ var KeyBuilderCS = /** @class */ (function (_super) {
21
21
  return builtSegmentKeyName.substr(prefix.length);
22
22
  };
23
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.buildOldSegmentNameKey = function (segmentName) {
25
+ return this.matchingKey + "." + this.prefix + ".segment." + segmentName;
26
+ };
27
+ // @BREAKING: The key used to start with the matching key instead of the prefix, this was changed on version 10.17.3
24
28
  KeyBuilderCS.prototype.extractOldSegmentKey = function (builtSegmentKeyName) {
25
29
  var prefix = this.matchingKey + "." + this.prefix + ".segment.";
26
30
  if (startsWith(builtSegmentKeyName, prefix))
@@ -32,27 +36,6 @@ var KeyBuilderCS = /** @class */ (function (_super) {
32
36
  KeyBuilderCS.prototype.isSplitsCacheKey = function (key) {
33
37
  return this.regexSplitsCacheKey.test(key);
34
38
  };
35
- KeyBuilderCS.prototype.buildTillKey = function () {
36
- return this.prefix + "." + this.matchingKey + ".segments.till";
37
- };
38
39
  return KeyBuilderCS;
39
40
  }(KeyBuilder));
40
41
  export { KeyBuilderCS };
41
- export function myLargeSegmentsKeyBuilder(prefix, matchingKey) {
42
- return {
43
- buildSegmentNameKey: function (segmentName) {
44
- return prefix + "." + matchingKey + ".largeSegment." + segmentName;
45
- },
46
- extractSegmentName: function (builtSegmentKeyName) {
47
- var p = prefix + "." + matchingKey + ".largeSegment.";
48
- if (startsWith(builtSegmentKeyName, p))
49
- return builtSegmentKeyName.substr(p.length);
50
- },
51
- extractOldSegmentKey: function () {
52
- return undefined;
53
- },
54
- buildTillKey: function () {
55
- return prefix + "." + matchingKey + ".largeSegments.till";
56
- }
57
- };
58
- }
@@ -1,78 +1,47 @@
1
- import { setToArray } from '../utils/lang/sets';
2
- import { getMatching } from '../utils/key';
1
+ import { DEFAULT_CACHE_EXPIRATION_IN_MILLIS } from '../utils/constants/browser';
3
2
  /**
4
- * Storage-agnostic adaptation of `loadDataIntoLocalStorage` function
5
- * (https://github.com/godaddy/split-javascript-data-loader/blob/master/src/load-data.js)
3
+ * Factory of client-side storage loader
6
4
  *
7
- * @param preloadedData validated data following the format proposed in https://github.com/godaddy/split-javascript-data-loader and extended with a `mySegmentsData` property.
8
- * @param storage object containing `splits` and `segments` cache (client-side variant)
9
- * @param userKey user key (matching key) of the provided MySegmentsCache
10
- *
11
- * @TODO extend to load largeSegments
12
- * @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.
13
- * @TODO add logs, and input validation in this module, in favor of size reduction.
14
- * @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
15
8
  */
16
- export function loadData(preloadedData, storage, matchingKey) {
17
- // Do not load data if current preloadedData is empty
18
- if (Object.keys(preloadedData).length === 0)
19
- return;
20
- 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;
21
- 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;
22
25
  var storedSince = storage.splits.getChangeNumber();
23
- // Do not load data if current data is more recent
24
- 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)
25
30
  return;
26
31
  // cleaning up the localStorage data, since some cached splits might need be part of the preloaded data
27
32
  storage.splits.clear();
28
33
  storage.splits.setChangeNumber(since);
29
34
  // splitsData in an object where the property is the split name and the pertaining value is a stringified json of its data
30
- storage.splits.addSplits(splitsData.map(function (split) { return ([split.name, split]); }));
31
- }
32
- if (matchingKey) { // add mySegments data (client-side)
33
- var mySegmentsData = preloadedData.mySegmentsData && preloadedData.mySegmentsData[matchingKey];
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];
34
38
  if (!mySegmentsData) {
35
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
36
40
  mySegmentsData = Object.keys(segmentsData).filter(function (segmentName) {
37
- var matchingKeys = segmentsData[segmentName];
38
- return matchingKeys.indexOf(matchingKey) > -1;
41
+ var userIds = JSON.parse(segmentsData[segmentName]).added;
42
+ return Array.isArray(userIds) && userIds.indexOf(userId) > -1;
39
43
  });
40
44
  }
41
- storage.segments.resetSegments({ k: mySegmentsData.map(function (s) { return ({ n: s }); }) });
42
- }
43
- else { // add segments data (server-side)
44
- Object.keys(segmentsData).filter(function (segmentName) {
45
- var matchingKeys = segmentsData[segmentName];
46
- storage.segments.addToSegment(segmentName, matchingKeys);
47
- });
48
- }
49
- }
50
- export function getSnapshot(storage, userKeys) {
51
- return {
52
- // lastUpdated: Date.now(),
53
- since: storage.splits.getChangeNumber(),
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
- prev[getMatching(userKey)] = storage.shared ?
64
- // Client-side segments
65
- // @ts-ignore accessing private prop
66
- Object.keys(storage.shared(userKey).segments.segmentCache) :
67
- // Server-side segments
68
- // @ts-ignore accessing private prop
69
- Object.keys(storage.segments.segmentCache).reduce(function (prev, segmentName) {
70
- return storage.segments.segmentCache[segmentName].has(userKey) ?
71
- prev.concat(segmentName) :
72
- prev;
73
- }, []);
74
- return prev;
75
- }, {}) :
76
- undefined
45
+ storage.segments.resetSegments(mySegmentsData);
77
46
  };
78
47
  }
@@ -1,5 +1,4 @@
1
1
  import { __extends } from "tslib";
2
- import { isNaNNumber } from '../../utils/lang';
3
2
  import { AbstractSegmentsCacheSync } from '../AbstractSegmentsCacheSync';
4
3
  import { LOG_PREFIX, DEFINED } from './constants';
5
4
  var MySegmentsCacheInLocal = /** @class */ (function (_super) {
@@ -11,11 +10,19 @@ var MySegmentsCacheInLocal = /** @class */ (function (_super) {
11
10
  return _this;
12
11
  // There is not need to flush segments cache like splits cache, since resetSegments receives the up-to-date list of active segments
13
12
  }
13
+ /**
14
+ * Removes list of segments from localStorage
15
+ * @NOTE this method is not being used at the moment.
16
+ */
17
+ MySegmentsCacheInLocal.prototype.clear = function () {
18
+ this.log.info(LOG_PREFIX + 'Flushing MySegments data from localStorage');
19
+ // We cannot simply call `localStorage.clear()` since that implies removing user items from the storage
20
+ // We could optimize next sentence, since it implies iterating over all localStorage items
21
+ this.resetSegments([]);
22
+ };
14
23
  MySegmentsCacheInLocal.prototype.addToSegment = function (name) {
15
24
  var segmentKey = this.keys.buildSegmentNameKey(name);
16
25
  try {
17
- if (localStorage.getItem(segmentKey) === DEFINED)
18
- return false;
19
26
  localStorage.setItem(segmentKey, DEFINED);
20
27
  return true;
21
28
  }
@@ -27,8 +34,6 @@ var MySegmentsCacheInLocal = /** @class */ (function (_super) {
27
34
  MySegmentsCacheInLocal.prototype.removeFromSegment = function (name) {
28
35
  var segmentKey = this.keys.buildSegmentNameKey(name);
29
36
  try {
30
- if (localStorage.getItem(segmentKey) !== DEFINED)
31
- return false;
32
37
  localStorage.removeItem(segmentKey);
33
38
  return true;
34
39
  }
@@ -40,22 +45,30 @@ var MySegmentsCacheInLocal = /** @class */ (function (_super) {
40
45
  MySegmentsCacheInLocal.prototype.isInSegment = function (name) {
41
46
  return localStorage.getItem(this.keys.buildSegmentNameKey(name)) === DEFINED;
42
47
  };
43
- MySegmentsCacheInLocal.prototype.getRegisteredSegments = function () {
48
+ /**
49
+ * Reset (update) the cached list of segments with the given list, removing and adding segments if necessary.
50
+ *
51
+ * @param {string[]} segmentNames list of segment names
52
+ * @returns boolean indicating if the cache was updated (i.e., given list was different from the cached one)
53
+ */
54
+ MySegmentsCacheInLocal.prototype.resetSegments = function (names) {
44
55
  var _this = this;
56
+ var isDiff = false;
57
+ var index;
45
58
  // Scan current values from localStorage
46
- return Object.keys(localStorage).reduce(function (accum, key) {
59
+ var storedSegmentNames = Object.keys(localStorage).reduce(function (accum, key) {
47
60
  var segmentName = _this.keys.extractSegmentName(key);
48
61
  if (segmentName) {
49
62
  accum.push(segmentName);
50
63
  }
51
64
  else {
52
- // @TODO @BREAKING: This is only to clean up "old" keys. Remove this whole else code block
65
+ // @TODO @BREAKING: This is only to clean up "old" keys. Remove this whole else code block and reuse `getRegisteredSegments` method.
53
66
  segmentName = _this.keys.extractOldSegmentKey(key);
54
67
  if (segmentName) { // this was an old segment key, let's clean up.
55
68
  var newSegmentKey = _this.keys.buildSegmentNameKey(segmentName);
56
69
  try {
57
70
  // If the new format key is not there, create it.
58
- if (!localStorage.getItem(newSegmentKey)) {
71
+ if (!localStorage.getItem(newSegmentKey) && names.indexOf(segmentName) > -1) {
59
72
  localStorage.setItem(newSegmentKey, DEFINED);
60
73
  // we are migrating a segment, let's track it.
61
74
  accum.push(segmentName);
@@ -69,29 +82,39 @@ var MySegmentsCacheInLocal = /** @class */ (function (_super) {
69
82
  }
70
83
  return accum;
71
84
  }, []);
72
- };
73
- MySegmentsCacheInLocal.prototype.getKeysCount = function () {
74
- return 1;
75
- };
76
- MySegmentsCacheInLocal.prototype.setChangeNumber = function (name, changeNumber) {
77
- try {
78
- if (changeNumber)
79
- localStorage.setItem(this.keys.buildTillKey(), changeNumber + '');
80
- else
81
- localStorage.removeItem(this.keys.buildTillKey());
85
+ // Extreme fast => everything is empty
86
+ if (names.length === 0 && storedSegmentNames.length === names.length)
87
+ return isDiff;
88
+ // Quick path
89
+ if (storedSegmentNames.length !== names.length) {
90
+ isDiff = true;
91
+ storedSegmentNames.forEach(function (name) { return _this.removeFromSegment(name); });
92
+ names.forEach(function (name) { return _this.addToSegment(name); });
82
93
  }
83
- catch (e) {
84
- this.log.error(e);
94
+ else {
95
+ // Slowest path => we need to find at least 1 difference because
96
+ for (index = 0; index < names.length && storedSegmentNames.indexOf(names[index]) !== -1; index++) {
97
+ // TODO: why empty statement?
98
+ }
99
+ if (index < names.length) {
100
+ isDiff = true;
101
+ storedSegmentNames.forEach(function (name) { return _this.removeFromSegment(name); });
102
+ names.forEach(function (name) { return _this.addToSegment(name); });
103
+ }
85
104
  }
105
+ return isDiff;
86
106
  };
87
- MySegmentsCacheInLocal.prototype.getChangeNumber = function () {
88
- var n = -1;
89
- var value = localStorage.getItem(this.keys.buildTillKey());
90
- if (value !== null) {
91
- value = parseInt(value, 10);
92
- return isNaNNumber(value) ? n : value;
93
- }
94
- return n;
107
+ MySegmentsCacheInLocal.prototype.getRegisteredSegments = function () {
108
+ var _this = this;
109
+ return Object.keys(localStorage).reduce(function (accum, key) {
110
+ var segmentName = _this.keys.extractSegmentName(key);
111
+ if (segmentName)
112
+ accum.push(segmentName);
113
+ return accum;
114
+ }, []);
115
+ };
116
+ MySegmentsCacheInLocal.prototype.getKeysCount = function () {
117
+ return 1;
95
118
  };
96
119
  return MySegmentsCacheInLocal;
97
120
  }(AbstractSegmentsCacheSync));
@@ -183,6 +183,14 @@ var SplitsCacheInLocal = /** @class */ (function (_super) {
183
183
  return true;
184
184
  }
185
185
  };
186
+ /**
187
+ * Check if the splits information is already stored in browser LocalStorage.
188
+ * In this function we could add more code to check if the data is valid.
189
+ * @override
190
+ */
191
+ SplitsCacheInLocal.prototype.checkCache = function () {
192
+ return this.getChangeNumber() > -1;
193
+ };
186
194
  /**
187
195
  * Clean Splits cache if its `lastUpdated` timestamp is older than the given `expirationTimestamp`,
188
196
  *
@@ -205,7 +213,7 @@ var SplitsCacheInLocal = /** @class */ (function (_super) {
205
213
  // mark cache to update the new query filter on first successful splits fetch
206
214
  this.updateNewFilter = true;
207
215
  // if there is cache, clear it
208
- if (this.getChangeNumber() > -1)
216
+ if (this.checkCache())
209
217
  this.clear();
210
218
  }
211
219
  catch (e) {
@@ -2,7 +2,7 @@ import { ImpressionsCacheInMemory } from '../inMemory/ImpressionsCacheInMemory';
2
2
  import { ImpressionCountsCacheInMemory } from '../inMemory/ImpressionCountsCacheInMemory';
3
3
  import { EventsCacheInMemory } from '../inMemory/EventsCacheInMemory';
4
4
  import { validatePrefix } from '../KeyBuilder';
5
- import { KeyBuilderCS, myLargeSegmentsKeyBuilder } from '../KeyBuilderCS';
5
+ import { KeyBuilderCS } from '../KeyBuilderCS';
6
6
  import { isLocalStorageAvailable } from '../../utils/env/isLocalStorageAvailable';
7
7
  import { SplitsCacheInLocal } from './SplitsCacheInLocal';
8
8
  import { MySegmentsCacheInLocal } from './MySegmentsCacheInLocal';
@@ -11,7 +11,7 @@ import { SplitsCacheInMemory } from '../inMemory/SplitsCacheInMemory';
11
11
  import { DEFAULT_CACHE_EXPIRATION_IN_MILLIS } from '../../utils/constants/browser';
12
12
  import { InMemoryStorageCSFactory } from '../inMemory/InMemoryStorageCS';
13
13
  import { LOG_PREFIX } from './constants';
14
- import { DEBUG, LOCALHOST_MODE, NONE, STORAGE_LOCALSTORAGE } from '../../utils/constants';
14
+ import { DEBUG, NONE, STORAGE_LOCALSTORAGE } from '../../utils/constants';
15
15
  import { shouldRecordTelemetry, TelemetryCacheInMemory } from '../inMemory/TelemetryCacheInMemory';
16
16
  import { UniqueKeysCacheInMemoryCS } from '../inMemory/UniqueKeysCacheInMemoryCS';
17
17
  import { getMatching } from '../../utils/key';
@@ -27,32 +27,24 @@ export function InLocalStorage(options) {
27
27
  params.settings.log.warn(LOG_PREFIX + 'LocalStorage API is unavailable. Falling back to default MEMORY storage');
28
28
  return InMemoryStorageCSFactory(params);
29
29
  }
30
- var onReadyFromCacheCb = params.onReadyFromCacheCb, settings = params.settings, _a = params.settings, log = _a.log, _b = _a.scheduler, impressionsQueueSize = _b.impressionsQueueSize, eventsQueueSize = _b.eventsQueueSize, _c = _a.sync, impressionsMode = _c.impressionsMode, __splitFiltersValidation = _c.__splitFiltersValidation;
30
+ var settings = params.settings, _a = params.settings, log = _a.log, _b = _a.scheduler, impressionsQueueSize = _b.impressionsQueueSize, eventsQueueSize = _b.eventsQueueSize, _c = _a.sync, impressionsMode = _c.impressionsMode, __splitFiltersValidation = _c.__splitFiltersValidation;
31
31
  var matchingKey = getMatching(settings.core.key);
32
32
  var keys = new KeyBuilderCS(prefix, matchingKey);
33
33
  var expirationTimestamp = Date.now() - DEFAULT_CACHE_EXPIRATION_IN_MILLIS;
34
34
  var splits = new SplitsCacheInLocal(settings, keys, expirationTimestamp);
35
35
  var segments = new MySegmentsCacheInLocal(log, keys);
36
- var largeSegments = new MySegmentsCacheInLocal(log, myLargeSegmentsKeyBuilder(prefix, matchingKey));
37
36
  return {
38
37
  splits: splits,
39
38
  segments: segments,
40
- largeSegments: largeSegments,
41
39
  impressions: new ImpressionsCacheInMemory(impressionsQueueSize),
42
40
  impressionCounts: impressionsMode !== DEBUG ? new ImpressionCountsCacheInMemory() : undefined,
43
41
  events: new EventsCacheInMemory(eventsQueueSize),
44
42
  telemetry: shouldRecordTelemetry(params) ? new TelemetryCacheInMemory(splits, segments) : undefined,
45
43
  uniqueKeys: impressionsMode === NONE ? new UniqueKeysCacheInMemoryCS() : undefined,
46
- init: function () {
47
- if (settings.mode === LOCALHOST_MODE || splits.getChangeNumber() > -1) {
48
- Promise.resolve().then(onReadyFromCacheCb);
49
- }
50
- },
51
44
  destroy: function () {
52
45
  var _a;
53
46
  this.splits = new SplitsCacheInMemory(__splitFiltersValidation);
54
47
  this.segments = new MySegmentsCacheInMemory();
55
- this.largeSegments = new MySegmentsCacheInMemory();
56
48
  this.impressions.clear();
57
49
  this.impressionCounts && this.impressionCounts.clear();
58
50
  this.events.clear();
@@ -60,10 +52,10 @@ export function InLocalStorage(options) {
60
52
  },
61
53
  // When using shared instanciation with MEMORY we reuse everything but segments (they are customer per key).
62
54
  shared: function (matchingKey) {
55
+ var childKeysBuilder = new KeyBuilderCS(prefix, matchingKey);
63
56
  return {
64
57
  splits: this.splits,
65
- segments: new MySegmentsCacheInLocal(log, new KeyBuilderCS(prefix, matchingKey)),
66
- largeSegments: new MySegmentsCacheInLocal(log, myLargeSegmentsKeyBuilder(prefix, matchingKey)),
58
+ segments: new MySegmentsCacheInLocal(log, childKeysBuilder),
67
59
  impressions: this.impressions,
68
60
  impressionCounts: this.impressionCounts,
69
61
  events: this.events,
@@ -71,7 +63,6 @@ export function InLocalStorage(options) {
71
63
  destroy: function () {
72
64
  this.splits = new SplitsCacheInMemory(__splitFiltersValidation);
73
65
  this.segments = new MySegmentsCacheInMemory();
74
- this.largeSegments = new MySegmentsCacheInMemory();
75
66
  }
76
67
  };
77
68
  },
@@ -6,22 +6,18 @@ import { ImpressionCountsCacheInMemory } from './ImpressionCountsCacheInMemory';
6
6
  import { DEBUG, LOCALHOST_MODE, NONE, STORAGE_MEMORY } from '../../utils/constants';
7
7
  import { shouldRecordTelemetry, TelemetryCacheInMemory } from './TelemetryCacheInMemory';
8
8
  import { UniqueKeysCacheInMemoryCS } from './UniqueKeysCacheInMemoryCS';
9
- import { getMatching } from '../../utils/key';
10
- import { loadData } from '../dataLoader';
11
9
  /**
12
10
  * InMemory storage factory for standalone client-side SplitFactory
13
11
  *
14
12
  * @param params parameters required by EventsCacheSync
15
13
  */
16
14
  export function InMemoryStorageCSFactory(params) {
17
- var _a = params.settings, _b = _a.scheduler, impressionsQueueSize = _b.impressionsQueueSize, eventsQueueSize = _b.eventsQueueSize, _c = _a.sync, impressionsMode = _c.impressionsMode, __splitFiltersValidation = _c.__splitFiltersValidation, preloadedData = _a.preloadedData, onReadyFromCacheCb = params.onReadyFromCacheCb;
15
+ var _a = params.settings, _b = _a.scheduler, impressionsQueueSize = _b.impressionsQueueSize, eventsQueueSize = _b.eventsQueueSize, _c = _a.sync, impressionsMode = _c.impressionsMode, __splitFiltersValidation = _c.__splitFiltersValidation;
18
16
  var splits = new SplitsCacheInMemory(__splitFiltersValidation);
19
17
  var segments = new MySegmentsCacheInMemory();
20
- var largeSegments = new MySegmentsCacheInMemory();
21
18
  var storage = {
22
19
  splits: splits,
23
20
  segments: segments,
24
- largeSegments: largeSegments,
25
21
  impressions: new ImpressionsCacheInMemory(impressionsQueueSize),
26
22
  impressionCounts: impressionsMode !== DEBUG ? new ImpressionCountsCacheInMemory() : undefined,
27
23
  events: new EventsCacheInMemory(eventsQueueSize),
@@ -31,23 +27,16 @@ export function InMemoryStorageCSFactory(params) {
31
27
  destroy: function () {
32
28
  this.splits.clear();
33
29
  this.segments.clear();
34
- this.largeSegments.clear();
35
30
  this.impressions.clear();
36
31
  this.impressionCounts && this.impressionCounts.clear();
37
32
  this.events.clear();
38
33
  this.uniqueKeys && this.uniqueKeys.clear();
39
34
  },
40
35
  // When using shared instanciation with MEMORY we reuse everything but segments (they are unique per key)
41
- shared: function (matchingKey) {
42
- var segments = new MySegmentsCacheInMemory();
43
- var largeSegments = new MySegmentsCacheInMemory();
44
- if (preloadedData) {
45
- loadData(preloadedData, { segments: segments, largeSegments: largeSegments }, matchingKey);
46
- }
36
+ shared: function () {
47
37
  return {
48
38
  splits: this.splits,
49
- segments: segments,
50
- largeSegments: largeSegments,
39
+ segments: new MySegmentsCacheInMemory(),
51
40
  impressions: this.impressions,
52
41
  impressionCounts: this.impressionCounts,
53
42
  events: this.events,
@@ -56,7 +45,6 @@ export function InMemoryStorageCSFactory(params) {
56
45
  destroy: function () {
57
46
  this.splits = new SplitsCacheInMemory(__splitFiltersValidation);
58
47
  this.segments.clear();
59
- this.largeSegments.clear();
60
48
  }
61
49
  };
62
50
  },
@@ -72,11 +60,6 @@ export function InMemoryStorageCSFactory(params) {
72
60
  if (storage.uniqueKeys)
73
61
  storage.uniqueKeys.track = noopTrack;
74
62
  }
75
- if (preloadedData) {
76
- loadData(preloadedData, storage, getMatching(params.settings.core.key));
77
- if (splits.getChangeNumber() > -1)
78
- onReadyFromCacheCb();
79
- }
80
63
  return storage;
81
64
  }
82
65
  InMemoryStorageCSFactory.type = STORAGE_MEMORY;