@splitsoftware/splitio-commons 0.1.1-canary.9 → 0.1.1-rc.18

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 (254) hide show
  1. package/cjs/evaluator/matchers/matcherTypes.js +4 -4
  2. package/cjs/evaluator/matchersTransform/index.js +11 -11
  3. package/cjs/evaluator/value/sanitize.js +6 -6
  4. package/cjs/listeners/browser.js +1 -2
  5. package/cjs/listeners/node.js +0 -3
  6. package/cjs/logger/constants.js +3 -1
  7. package/cjs/logger/messages/error.js +3 -2
  8. package/cjs/logger/messages/info.js +2 -2
  9. package/cjs/logger/messages/warn.js +2 -1
  10. package/cjs/readiness/readinessManager.js +10 -7
  11. package/cjs/sdkFactory/index.js +1 -4
  12. package/cjs/services/splitApi.js +1 -1
  13. package/cjs/services/splitHttpClient.js +5 -4
  14. package/cjs/storages/AbstractSplitsCacheSync.js +1 -1
  15. package/cjs/storages/inLocalStorage/index.js +5 -2
  16. package/cjs/storages/inMemory/InMemoryStorage.js +2 -0
  17. package/cjs/storages/inMemory/InMemoryStorageCS.js +2 -0
  18. package/cjs/storages/inRedis/SplitsCacheInRedis.js +6 -2
  19. package/cjs/storages/inRedis/index.js +5 -2
  20. package/cjs/storages/pluggable/SplitsCachePluggable.js +6 -2
  21. package/cjs/storages/pluggable/inMemoryWrapper.js +6 -7
  22. package/cjs/storages/pluggable/index.js +5 -2
  23. package/cjs/storages/pluggable/wrapperAdapter.js +0 -1
  24. package/cjs/sync/offline/splitsParser/splitsParserFromFile.js +92 -89
  25. package/cjs/sync/offline/splitsParser/splitsParserFromSettings.js +45 -42
  26. package/cjs/sync/offline/syncTasks/fromObjectSyncTask.js +14 -4
  27. package/cjs/sync/polling/updaters/mySegmentsUpdater.js +30 -10
  28. package/cjs/sync/streaming/SSEClient/index.js +0 -11
  29. package/cjs/sync/streaming/SSEHandler/NotificationKeeper.js +7 -0
  30. package/cjs/sync/streaming/SSEHandler/NotificationParser.js +4 -1
  31. package/cjs/sync/streaming/SSEHandler/index.js +8 -9
  32. package/cjs/sync/streaming/SSEHandler/types.js +14 -0
  33. package/cjs/sync/streaming/UpdateWorkers/MySegmentsUpdateWorker.js +5 -5
  34. package/cjs/sync/streaming/UpdateWorkers/SegmentsUpdateWorker.js +2 -1
  35. package/cjs/sync/streaming/UpdateWorkers/SplitsUpdateWorker.js +5 -3
  36. package/cjs/sync/streaming/constants.js +3 -1
  37. package/cjs/sync/streaming/mySegmentsV2utils.js +75 -0
  38. package/cjs/sync/streaming/pushManager.js +141 -40
  39. package/cjs/sync/submitters/metricsSyncTask.js +1 -1
  40. package/cjs/sync/submitters/submitterSyncTask.js +2 -2
  41. package/cjs/sync/syncManagerFromFile.js +15 -0
  42. package/cjs/sync/syncManagerFromObject.js +14 -0
  43. package/cjs/sync/syncManagerOffline.js +3 -3
  44. package/cjs/sync/syncManagerOnline.js +5 -3
  45. package/cjs/trackers/impressionObserver/ImpressionObserver.js +0 -2
  46. package/cjs/trackers/impressionObserver/buildKey.js +3 -9
  47. package/cjs/trackers/impressionObserver/impressionObserverCS.js +2 -2
  48. package/cjs/trackers/impressionObserver/impressionObserverSS.js +3 -3
  49. package/cjs/utils/constants/index.js +4 -1
  50. package/cjs/utils/decompress/index.js +427 -0
  51. package/cjs/utils/murmur3/{commons.js → common.js} +2 -6
  52. package/cjs/utils/murmur3/murmur3.js +11 -12
  53. package/cjs/utils/murmur3/murmur3_128.js +7 -142
  54. package/cjs/utils/murmur3/murmur3_128_x86.js +154 -0
  55. package/cjs/utils/murmur3/murmur3_64.js +36 -0
  56. package/cjs/utils/murmur3/utfx.js +100 -106
  57. package/cjs/utils/promise/wrapper.js +14 -11
  58. package/cjs/utils/settingsValidation/index.js +5 -2
  59. package/cjs/utils/settingsValidation/localhost/index.js +20 -0
  60. package/cjs/utils/settingsValidation/splitFilters.js +0 -1
  61. package/cjs/utils/settingsValidation/storage/storageCS.js +18 -8
  62. package/cjs/utils/settingsValidation/url.js +1 -1
  63. package/esm/evaluator/matchers/matcherTypes.js +2 -2
  64. package/esm/evaluator/matchersTransform/index.js +12 -12
  65. package/esm/evaluator/value/sanitize.js +7 -7
  66. package/esm/listeners/browser.js +1 -2
  67. package/esm/listeners/node.js +0 -3
  68. package/esm/logger/constants.js +2 -0
  69. package/esm/logger/messages/error.js +3 -2
  70. package/esm/logger/messages/info.js +2 -2
  71. package/esm/logger/messages/warn.js +2 -1
  72. package/esm/readiness/readinessManager.js +10 -7
  73. package/esm/sdkFactory/index.js +1 -4
  74. package/esm/services/splitApi.js +1 -1
  75. package/esm/services/splitHttpClient.js +5 -4
  76. package/esm/storages/AbstractSplitsCacheSync.js +1 -1
  77. package/esm/storages/inLocalStorage/index.js +5 -2
  78. package/esm/storages/inMemory/InMemoryStorage.js +2 -0
  79. package/esm/storages/inMemory/InMemoryStorageCS.js +2 -0
  80. package/esm/storages/inRedis/SplitsCacheInRedis.js +6 -2
  81. package/esm/storages/inRedis/index.js +5 -2
  82. package/esm/storages/pluggable/SplitsCachePluggable.js +6 -2
  83. package/esm/storages/pluggable/inMemoryWrapper.js +6 -7
  84. package/esm/storages/pluggable/index.js +5 -2
  85. package/esm/storages/pluggable/wrapperAdapter.js +0 -1
  86. package/esm/sync/offline/splitsParser/splitsParserFromFile.js +90 -88
  87. package/esm/sync/offline/splitsParser/splitsParserFromSettings.js +43 -41
  88. package/esm/sync/offline/syncTasks/fromObjectSyncTask.js +15 -5
  89. package/esm/sync/polling/updaters/mySegmentsUpdater.js +30 -10
  90. package/esm/sync/streaming/SSEClient/index.js +0 -11
  91. package/esm/sync/streaming/SSEHandler/NotificationKeeper.js +7 -0
  92. package/esm/sync/streaming/SSEHandler/NotificationParser.js +4 -1
  93. package/esm/sync/streaming/SSEHandler/index.js +9 -10
  94. package/esm/sync/streaming/SSEHandler/types.js +13 -1
  95. package/esm/sync/streaming/UpdateWorkers/MySegmentsUpdateWorker.js +5 -5
  96. package/esm/sync/streaming/UpdateWorkers/SegmentsUpdateWorker.js +2 -1
  97. package/esm/sync/streaming/UpdateWorkers/SplitsUpdateWorker.js +5 -3
  98. package/esm/sync/streaming/constants.js +2 -0
  99. package/esm/sync/streaming/mySegmentsV2utils.js +69 -0
  100. package/esm/sync/streaming/pushManager.js +143 -42
  101. package/esm/sync/submitters/metricsSyncTask.js +1 -1
  102. package/esm/sync/submitters/submitterSyncTask.js +2 -2
  103. package/esm/sync/syncManagerFromFile.js +11 -0
  104. package/esm/sync/syncManagerFromObject.js +10 -0
  105. package/esm/sync/syncManagerOffline.js +3 -3
  106. package/esm/sync/syncManagerOnline.js +5 -3
  107. package/esm/trackers/impressionObserver/ImpressionObserver.js +0 -2
  108. package/esm/trackers/impressionObserver/buildKey.js +2 -9
  109. package/esm/trackers/impressionObserver/impressionObserverCS.js +2 -2
  110. package/esm/trackers/impressionObserver/impressionObserverSS.js +3 -3
  111. package/esm/utils/constants/index.js +3 -0
  112. package/esm/utils/decompress/index.js +424 -0
  113. package/esm/utils/murmur3/{commons.js → common.js} +1 -4
  114. package/esm/utils/murmur3/murmur3.js +1 -2
  115. package/esm/utils/murmur3/murmur3_128.js +7 -142
  116. package/esm/utils/murmur3/murmur3_128_x86.js +150 -0
  117. package/esm/utils/murmur3/murmur3_64.js +32 -0
  118. package/esm/utils/murmur3/utfx.js +96 -106
  119. package/esm/utils/promise/wrapper.js +14 -11
  120. package/esm/utils/settingsValidation/index.js +5 -2
  121. package/esm/utils/settingsValidation/localhost/index.js +16 -0
  122. package/esm/utils/settingsValidation/splitFilters.js +0 -1
  123. package/esm/utils/settingsValidation/storage/storageCS.js +16 -7
  124. package/esm/utils/settingsValidation/url.js +1 -1
  125. package/package.json +5 -5
  126. package/src/evaluator/matchers/matcherTypes.ts +2 -2
  127. package/src/evaluator/matchersTransform/index.ts +12 -12
  128. package/src/evaluator/value/sanitize.ts +7 -7
  129. package/src/listeners/browser.ts +1 -1
  130. package/src/listeners/node.ts +1 -2
  131. package/src/logger/constants.ts +2 -0
  132. package/src/logger/messages/error.ts +3 -2
  133. package/src/logger/messages/info.ts +2 -2
  134. package/src/logger/messages/warn.ts +3 -1
  135. package/src/readiness/readinessManager.ts +9 -7
  136. package/src/sdkFactory/index.ts +1 -3
  137. package/src/sdkFactory/types.ts +3 -3
  138. package/src/services/splitApi.ts +2 -3
  139. package/src/services/splitHttpClient.ts +6 -5
  140. package/src/services/types.ts +5 -5
  141. package/src/storages/AbstractSplitsCacheSync.ts +1 -1
  142. package/src/storages/inLocalStorage/index.ts +8 -4
  143. package/src/storages/inMemory/InMemoryStorage.ts +3 -0
  144. package/src/storages/inMemory/InMemoryStorageCS.ts +3 -0
  145. package/src/storages/inRedis/SplitsCacheInRedis.ts +3 -1
  146. package/src/storages/inRedis/index.ts +8 -4
  147. package/src/storages/pluggable/SplitsCachePluggable.ts +3 -1
  148. package/src/storages/pluggable/inMemoryWrapper.ts +6 -7
  149. package/src/storages/pluggable/index.ts +8 -4
  150. package/src/storages/pluggable/wrapperAdapter.ts +0 -1
  151. package/src/storages/types.ts +18 -15
  152. package/src/sync/offline/splitsParser/splitsParserFromFile.ts +110 -105
  153. package/src/sync/offline/splitsParser/splitsParserFromSettings.ts +45 -41
  154. package/src/sync/offline/syncTasks/fromObjectSyncTask.ts +15 -5
  155. package/src/sync/polling/types.ts +2 -1
  156. package/src/sync/polling/updaters/mySegmentsUpdater.ts +28 -10
  157. package/src/sync/streaming/AuthClient/types.ts +3 -0
  158. package/src/sync/streaming/SSEClient/index.ts +1 -15
  159. package/src/sync/streaming/SSEClient/types.ts +0 -1
  160. package/src/sync/streaming/SSEHandler/NotificationKeeper.ts +8 -0
  161. package/src/sync/streaming/SSEHandler/NotificationParser.ts +4 -2
  162. package/src/sync/streaming/SSEHandler/index.ts +11 -20
  163. package/src/sync/streaming/SSEHandler/types.ts +37 -3
  164. package/src/sync/streaming/UpdateWorkers/MySegmentsUpdateWorker.ts +7 -6
  165. package/src/sync/streaming/UpdateWorkers/SegmentsUpdateWorker.ts +2 -1
  166. package/src/sync/streaming/UpdateWorkers/SplitsUpdateWorker.ts +4 -3
  167. package/src/sync/streaming/UpdateWorkers/types.ts +1 -1
  168. package/src/sync/streaming/constants.ts +2 -0
  169. package/src/sync/streaming/mySegmentsV2utils.ts +77 -0
  170. package/src/sync/streaming/pushManager.ts +139 -42
  171. package/src/sync/streaming/types.ts +14 -22
  172. package/src/sync/submitters/metricsSyncTask.ts +1 -1
  173. package/src/sync/submitters/submitterSyncTask.ts +2 -1
  174. package/src/sync/syncManagerFromFile.ts +13 -0
  175. package/src/sync/syncManagerFromObject.ts +12 -0
  176. package/src/sync/syncManagerOffline.ts +3 -3
  177. package/src/sync/syncManagerOnline.ts +6 -3
  178. package/src/trackers/impressionObserver/ImpressionObserver.ts +4 -6
  179. package/src/trackers/impressionObserver/buildKey.ts +2 -16
  180. package/src/trackers/impressionObserver/impressionObserverCS.ts +2 -2
  181. package/src/trackers/impressionObserver/impressionObserverSS.ts +3 -3
  182. package/src/types.ts +16 -2
  183. package/src/utils/constants/index.ts +6 -1
  184. package/src/utils/decompress/index.ts +429 -0
  185. package/src/utils/murmur3/{commons.ts → common.ts} +1 -5
  186. package/src/utils/murmur3/murmur3.ts +5 -5
  187. package/src/utils/murmur3/murmur3_128.ts +7 -180
  188. package/src/utils/murmur3/murmur3_128_x86.ts +188 -0
  189. package/src/utils/murmur3/murmur3_64.ts +36 -0
  190. package/src/utils/murmur3/utfx.ts +92 -110
  191. package/src/utils/promise/wrapper.ts +12 -9
  192. package/src/utils/settingsValidation/index.ts +8 -4
  193. package/src/utils/settingsValidation/localhost/index.ts +19 -0
  194. package/src/utils/settingsValidation/splitFilters.ts +0 -1
  195. package/src/utils/settingsValidation/storage/storageCS.ts +21 -8
  196. package/src/utils/settingsValidation/types.ts +2 -11
  197. package/src/utils/settingsValidation/url.ts +1 -1
  198. package/types/evaluator/matchers/matcherTypes.d.ts +2 -2
  199. package/types/listeners/browser.d.ts +1 -0
  200. package/types/listeners/node.d.ts +0 -1
  201. package/types/logger/constants.d.ts +2 -0
  202. package/types/sdkFactory/types.d.ts +3 -3
  203. package/types/services/types.d.ts +1 -0
  204. package/types/storages/inLocalStorage/index.d.ts +2 -2
  205. package/types/storages/inMemory/InMemoryStorage.d.ts +3 -0
  206. package/types/storages/inMemory/InMemoryStorageCS.d.ts +3 -0
  207. package/types/storages/inRedis/index.d.ts +2 -2
  208. package/types/storages/pluggable/index.d.ts +2 -2
  209. package/types/storages/types.d.ts +15 -15
  210. package/types/sync/offline/splitsParser/splitsParserFromFile.d.ts +2 -7
  211. package/types/sync/offline/splitsParser/splitsParserFromSettings.d.ts +1 -5
  212. package/types/sync/polling/types.d.ts +2 -1
  213. package/types/sync/streaming/AuthClient/indexV1.d.ts +12 -0
  214. package/types/sync/streaming/AuthClient/indexV2.d.ts +8 -0
  215. package/types/sync/streaming/AuthClient/types.d.ts +2 -0
  216. package/types/sync/streaming/SSEClient/index.d.ts +1 -9
  217. package/types/sync/streaming/SSEClient/types.d.ts +0 -1
  218. package/types/sync/streaming/SSEHandler/NotificationParser.d.ts +3 -2
  219. package/types/sync/streaming/SSEHandler/types.d.ts +30 -2
  220. package/types/sync/streaming/UpdateWorkers/MySegmentsUpdateWorker.d.ts +4 -3
  221. package/types/sync/streaming/UpdateWorkers/SegmentsUpdateWorker.d.ts +2 -1
  222. package/types/sync/streaming/UpdateWorkers/SplitsUpdateWorker.d.ts +3 -2
  223. package/types/sync/streaming/UpdateWorkers/types.d.ts +1 -1
  224. package/types/sync/streaming/constants.d.ts +3 -1
  225. package/types/sync/streaming/mySegmentsV2utils.d.ts +27 -0
  226. package/types/sync/streaming/pushManagerNoUsers.d.ts +13 -0
  227. package/types/sync/streaming/types.d.ts +9 -5
  228. package/types/sync/submitters/submitterSyncTask.d.ts +1 -1
  229. package/types/sync/syncManagerFromFile.d.ts +2 -0
  230. package/types/sync/syncManagerFromObject.d.ts +2 -0
  231. package/types/sync/syncManagerOffline.d.ts +1 -1
  232. package/types/trackers/impressionObserver/ImpressionObserver.d.ts +2 -2
  233. package/types/trackers/impressionObserver/buildKey.d.ts +1 -1
  234. package/types/trackers/impressionObserver/impressionObserverCS.d.ts +2 -2
  235. package/types/trackers/impressionObserver/impressionObserverSS.d.ts +2 -2
  236. package/types/types.d.ts +16 -2
  237. package/types/utils/constants/index.d.ts +5 -1
  238. package/types/utils/decompress/index.d.ts +16 -0
  239. package/types/utils/murmur3/common.d.ts +12 -0
  240. package/types/utils/murmur3/murmur3.d.ts +2 -2
  241. package/types/utils/murmur3/murmur3_128.d.ts +5 -0
  242. package/types/utils/murmur3/murmur3_128_x86.d.ts +7 -0
  243. package/types/utils/murmur3/murmur3_64.d.ts +10 -0
  244. package/types/utils/murmur3/utfx.d.ts +24 -6
  245. package/types/utils/settingsValidation/index.d.ts +3 -2
  246. package/types/utils/settingsValidation/localhost/index.d.ts +9 -0
  247. package/types/utils/settingsValidation/storage/storageCS.d.ts +7 -1
  248. package/types/utils/settingsValidation/types.d.ts +2 -10
  249. package/cjs/sync/streaming/pushManagerCS.js +0 -179
  250. package/cjs/sync/streaming/pushManagerSS.js +0 -128
  251. package/esm/sync/streaming/pushManagerCS.js +0 -175
  252. package/esm/sync/streaming/pushManagerSS.js +0 -124
  253. package/src/sync/streaming/pushManagerCS.ts +0 -238
  254. package/src/sync/streaming/pushManagerSS.ts +0 -177
@@ -1,4 +1,4 @@
1
- import { IMySegmentsUpdateData } from './SSEHandler/types';
1
+ import { IMySegmentsUpdateData, IMySegmentsUpdateV2Data, ISegmentUpdateData, ISplitUpdateData, ISplitKillData } from './SSEHandler/types';
2
2
  import { ITask } from '../types';
3
3
  import { IPollingManager, ISegmentsSyncTask } from '../polling/types';
4
4
  import { IReadinessManager } from '../../readiness/types';
@@ -6,6 +6,7 @@ import { IFetchAuth } from '../../services/types';
6
6
  import { IStorageSync } from '../../storages/types';
7
7
  import { IEventEmitter, ISettings } from '../../types';
8
8
  import { IPlatform } from '../../sdkFactory/types';
9
+ import { ControlType } from './constants';
9
10
 
10
11
  // Internal SDK events, subscribed by SyncManager and PushManager
11
12
  export type PUSH_SUBSYSTEM_UP = 'PUSH_SUBSYSTEM_UP'
@@ -15,6 +16,7 @@ export type PUSH_RETRYABLE_ERROR = 'PUSH_RETRYABLE_ERROR'
15
16
 
16
17
  // Update-type push notifications, handled by NotificationProcessor
17
18
  export type MY_SEGMENTS_UPDATE = 'MY_SEGMENTS_UPDATE';
19
+ export type MY_SEGMENTS_UPDATE_V2 = 'MY_SEGMENTS_UPDATE_V2';
18
20
  export type SEGMENT_UPDATE = 'SEGMENT_UPDATE';
19
21
  export type SPLIT_KILL = 'SPLIT_KILL';
20
22
  export type SPLIT_UPDATE = 'SPLIT_UPDATE';
@@ -23,33 +25,23 @@ export type SPLIT_UPDATE = 'SPLIT_UPDATE';
23
25
  export type CONTROL = 'CONTROL';
24
26
  export type OCCUPANCY = 'OCCUPANCY';
25
27
 
26
- export type IPushEvent = PUSH_SUBSYSTEM_UP | PUSH_SUBSYSTEM_DOWN | PUSH_NONRETRYABLE_ERROR | PUSH_RETRYABLE_ERROR | MY_SEGMENTS_UPDATE | SEGMENT_UPDATE | SPLIT_UPDATE | SPLIT_KILL
28
+ export type IPushEvent = PUSH_SUBSYSTEM_UP | PUSH_SUBSYSTEM_DOWN | PUSH_NONRETRYABLE_ERROR | PUSH_RETRYABLE_ERROR | MY_SEGMENTS_UPDATE | MY_SEGMENTS_UPDATE_V2 | SEGMENT_UPDATE | SPLIT_UPDATE | SPLIT_KILL | ControlType.STREAMING_RESET
29
+
30
+ type IParsedData<T extends IPushEvent> =
31
+ T extends MY_SEGMENTS_UPDATE ? IMySegmentsUpdateData :
32
+ T extends MY_SEGMENTS_UPDATE_V2 ? IMySegmentsUpdateV2Data :
33
+ T extends SEGMENT_UPDATE ? ISegmentUpdateData :
34
+ T extends SPLIT_UPDATE ? ISplitUpdateData :
35
+ T extends SPLIT_KILL ? ISplitKillData : undefined;
27
36
 
28
37
  /**
29
38
  * EventEmitter used as Feedback Loop between the SyncManager and PushManager,
30
39
  * where the latter pushes messages and the former consumes it
31
40
  */
32
41
  export interface IPushEventEmitter extends IEventEmitter {
33
- once<T extends IPushEvent>(event: T, listener: (...args:
34
- T extends MY_SEGMENTS_UPDATE ? [parsedData: IMySegmentsUpdateData, channel: string] :
35
- T extends SEGMENT_UPDATE ? [changeNumber: number, segmentName: string] :
36
- T extends SPLIT_UPDATE ? [changeNumber: number] :
37
- T extends SPLIT_KILL ? [changeNumber: number, splitName: string, defaultTreatment: string] :
38
- any[]) => void): this;
39
-
40
- on<T extends IPushEvent>(event: T, listener: (...args:
41
- T extends MY_SEGMENTS_UPDATE ? [parsedData: IMySegmentsUpdateData, channel: string] :
42
- T extends SEGMENT_UPDATE ? [changeNumber: number, segmentName: string] :
43
- T extends SPLIT_UPDATE ? [changeNumber: number] :
44
- T extends SPLIT_KILL ? [changeNumber: number, splitName: string, defaultTreatment: string] :
45
- any[]) => void): this;
46
-
47
- emit<T extends IPushEvent>(event: T, ...args:
48
- T extends MY_SEGMENTS_UPDATE ? [parsedData: IMySegmentsUpdateData, channel: string] :
49
- T extends SEGMENT_UPDATE ? [changeNumber: number, segmentName: string] :
50
- T extends SPLIT_UPDATE ? [changeNumber: number] :
51
- T extends SPLIT_KILL ? [changeNumber: number, splitName: string, defaultTreatment: string] :
52
- any[]): boolean;
42
+ once<T extends IPushEvent>(event: T, listener: (parsedData: IParsedData<T>, channel: T extends MY_SEGMENTS_UPDATE ? string : undefined) => void): this;
43
+ on<T extends IPushEvent>(event: T, listener: (parsedData: IParsedData<T>, channel: T extends MY_SEGMENTS_UPDATE ? string : undefined) => void): this;
44
+ emit<T extends IPushEvent>(event: T, parsedData?: IParsedData<T>, channel?: T extends MY_SEGMENTS_UPDATE ? string : undefined): boolean;
53
45
  }
54
46
 
55
47
  /**
@@ -45,5 +45,5 @@ export function latenciesSyncTaskFactory(
45
45
  ): ISyncTask {
46
46
 
47
47
  // don't retry metrics.
48
- return submitterSyncTaskFactory(log, postMetricsLatencies, latenciesCache, metricsRefreshRate, 'latency metrics', latencyTracker, fromCache<number[]>('latencies'));
48
+ return submitterSyncTaskFactory(log, postMetricsLatencies, latenciesCache, metricsRefreshRate, 'latency metrics', latencyTracker, fromCache<number[]>('latencies'), 0, true);
49
49
  }
@@ -17,6 +17,7 @@ export function submitterSyncTaskFactory<TState extends { length?: number }>(
17
17
  latencyTracker?: ITimeTracker,
18
18
  fromCacheToPayload?: (cacheData: TState) => any,
19
19
  maxRetries: number = 0,
20
+ debugLogs?: boolean
20
21
  ): ISyncTask<[], void> {
21
22
 
22
23
  let retries = 0;
@@ -27,7 +28,7 @@ export function submitterSyncTaskFactory<TState extends { length?: number }>(
27
28
  const data = sourceCache.state();
28
29
 
29
30
  const dataCount: number | '' = typeof data.length === 'number' ? data.length : '';
30
- log.info(SUBMITTERS_PUSH, [dataCount, dataName]);
31
+ log[debugLogs ? 'debug' : 'info'](SUBMITTERS_PUSH, [dataCount, dataName]);
31
32
  const latencyTrackerStop = latencyTracker && latencyTracker.start();
32
33
 
33
34
  const jsonPayload = JSON.stringify(fromCacheToPayload ? fromCacheToPayload(data) : data);
@@ -0,0 +1,13 @@
1
+ import { splitsParserFromFileFactory } from './offline/splitsParser/splitsParserFromFile';
2
+ import { syncManagerOfflineFactory } from './syncManagerOffline';
3
+ import { SplitIO } from '../types';
4
+ import { LOCALHOST_MODE } from '../utils/constants';
5
+
6
+ // Factory of Localhost SyncManager based on yaml file.
7
+ // Requires Node 'fs' and 'path' APIs.
8
+ export function LocalhostFromFile(): SplitIO.LocalhostFactory {
9
+ const localhost = syncManagerOfflineFactory(splitsParserFromFileFactory);
10
+ // @ts-ignore
11
+ localhost.type = LOCALHOST_MODE;
12
+ return localhost;
13
+ }
@@ -0,0 +1,12 @@
1
+ import { splitsParserFromSettingsFactory } from './offline/splitsParser/splitsParserFromSettings';
2
+ import { syncManagerOfflineFactory } from './syncManagerOffline';
3
+ import { SplitIO } from '../types';
4
+ import { LOCALHOST_MODE } from '../utils/constants';
5
+
6
+ // Factory of Localhost SyncManager based on JS object.
7
+ export function LocalhostFromObject(): SplitIO.LocalhostFactory {
8
+ const localhost = syncManagerOfflineFactory(splitsParserFromSettingsFactory);
9
+ // @ts-ignore
10
+ localhost.type = LOCALHOST_MODE;
11
+ return localhost;
12
+ }
@@ -16,7 +16,7 @@ function flush() {
16
16
  * @param splitsParser e.g., `splitsParserFromFile`, `splitsParserFromSettings`.
17
17
  */
18
18
  export function syncManagerOfflineFactory(
19
- splitsParser: ISplitsParser
19
+ splitsParserFactory: () => ISplitsParser
20
20
  ): (params: ISyncManagerFactoryParams) => ISyncManagerCS {
21
21
 
22
22
  /**
@@ -29,7 +29,7 @@ export function syncManagerOfflineFactory(
29
29
  }: ISyncManagerFactoryParams): ISyncManagerCS {
30
30
 
31
31
  return objectAssign(
32
- fromObjectSyncTaskFactory(splitsParser, storage, readiness, settings),
32
+ fromObjectSyncTaskFactory(splitsParserFactory(), storage, readiness, settings),
33
33
  {
34
34
  // fake flush, that resolves immediately
35
35
  flush,
@@ -38,7 +38,7 @@ export function syncManagerOfflineFactory(
38
38
  shared(matchingKey: string, readinessManager: IReadinessManager): ISyncManager {
39
39
  return {
40
40
  start() {
41
- // In LOCALHOST mode, shared clients are ready in the next event cycle than created
41
+ // In LOCALHOST mode, shared clients are ready in the next event-loop cycle than created
42
42
  // SDK_READY cannot be emitted directly because this will not update the readiness status
43
43
  setTimeout(() => {
44
44
  readinessManager.segments.emit(SDK_SEGMENTS_ARRIVED); // SDK_SPLITS_ARRIVED emitted by main SyncManager
@@ -75,6 +75,11 @@ export function syncManagerOnlineFactory(
75
75
  pollingManager.syncAll();
76
76
  }
77
77
 
78
+ if (pushManager) {
79
+ pushManager.on(PUSH_SUBSYSTEM_UP, stopPollingAndSyncAll);
80
+ pushManager.on(PUSH_SUBSYSTEM_DOWN, startPolling);
81
+ }
82
+
78
83
  let running = false; // flag that indicates whether the syncManager has been started (true) or stopped (false)
79
84
  let startFirstTime = true; // flag to distinguish calling the `start` method for the first time, to support pausing and resuming the synchronization
80
85
 
@@ -87,11 +92,9 @@ export function syncManagerOnlineFactory(
87
92
  start() {
88
93
  // start syncing splits and segments
89
94
  if (pushManager) {
90
- // Avoid calling `syncAll` when the syncManager is resumed
95
+ // Doesn't call `syncAll` when the syncManager is resuming
91
96
  if (startFirstTime) {
92
97
  pollingManager.syncAll();
93
- pushManager.on(PUSH_SUBSYSTEM_UP, stopPollingAndSyncAll);
94
- pushManager.on(PUSH_SUBSYSTEM_DOWN, startPolling);
95
98
  startFirstTime = false;
96
99
  }
97
100
  pushManager.start();
@@ -2,18 +2,16 @@ import { ImpressionDTO } from '../../types';
2
2
  import LRUCache from '../../utils/LRUCache';
3
3
  import { IImpressionObserver } from './types';
4
4
 
5
- export default class ImpressionObserver implements IImpressionObserver {
6
- private cache: LRUCache<string | null, number>;
7
- private hasher: (impression: ImpressionDTO) => string | null;
5
+ export default class ImpressionObserver<K extends string | number> implements IImpressionObserver {
6
+ private cache: LRUCache<K, number>;
7
+ private hasher: (impression: ImpressionDTO) => K;
8
8
 
9
- constructor(size: number, hasher: (impression: ImpressionDTO) => string | null) {
9
+ constructor(size: number, hasher: (impression: ImpressionDTO) => K) {
10
10
  this.cache = new LRUCache(size);
11
11
  this.hasher = hasher;
12
12
  }
13
13
 
14
14
  testAndSet(impression: ImpressionDTO) {
15
- if (!impression) return;
16
-
17
15
  const hash = this.hasher(impression);
18
16
  const previous = this.cache.get(hash);
19
17
  this.cache.set(hash, impression.time);
@@ -1,19 +1,5 @@
1
1
  import { ImpressionDTO } from '../../types';
2
2
 
3
- const UNKNOWN = 'UNKNOWN';
4
-
5
- function _unknownIfNull(s: any) {
6
- return s ? s : UNKNOWN;
7
- }
8
-
9
- function _zeroIfNull(l: any) {
10
- return l ? l : 0;
11
- }
12
-
13
- export default function buildKey(impression: ImpressionDTO) {
14
- return `${_unknownIfNull(impression.keyName)}
15
- :${_unknownIfNull(impression.feature)}
16
- :${_unknownIfNull(impression.treatment)}
17
- :${_unknownIfNull(impression.label)}
18
- :${_zeroIfNull(impression.changeNumber)}`;
3
+ export function buildKey(impression: ImpressionDTO) {
4
+ return `${impression.keyName}:${impression.feature}:${impression.treatment}:${impression.label}:${impression.changeNumber}`;
19
5
  }
@@ -1,10 +1,10 @@
1
1
  import ImpressionObserver from './ImpressionObserver';
2
2
  import { hash } from '../../utils/murmur3/murmur3';
3
- import buildKey from './buildKey';
3
+ import { buildKey } from './buildKey';
4
4
  import { ImpressionDTO } from '../../types';
5
5
 
6
6
  export function hashImpression32(impression: ImpressionDTO) {
7
- return impression ? hash(buildKey(impression)).toString() : null;
7
+ return hash(buildKey(impression));
8
8
  }
9
9
 
10
10
  const LAST_SEEN_CACHE_SIZE = 500; // cache up to 500 impression hashes
@@ -1,10 +1,10 @@
1
1
  import ImpressionObserver from './ImpressionObserver';
2
- import { hash128 } from '../../utils/murmur3/murmur3_128';
3
- import buildKey from './buildKey';
2
+ import { hash128 } from '../../utils/murmur3/murmur3_128_x86';
3
+ import { buildKey } from './buildKey';
4
4
  import { ImpressionDTO } from '../../types';
5
5
 
6
6
  export function hashImpression128(impression: ImpressionDTO) {
7
- return impression ? hash128(buildKey(impression)).toString() : null;
7
+ return hash128(buildKey(impression));
8
8
  }
9
9
 
10
10
  const LAST_SEEN_CACHE_SIZE = 500000; // cache up to 500k impression hashes
package/src/types.ts CHANGED
@@ -1,8 +1,10 @@
1
+ import { ISplitFiltersValidation } from './dtos/types';
1
2
  import { IIntegration, IIntegrationFactoryParams } from './integrations/types';
2
3
  import { ILogger } from './logger/types';
3
4
  /* eslint-disable no-use-before-define */
4
5
 
5
- import { IStorageFactoryParams, IStorageSyncCS, IStorageSync, IStorageAsync } from './storages/types';
6
+ import { IStorageFactoryParams, IStorageSyncCS, IStorageSync, IStorageAsync, IStorageSyncFactory } from './storages/types';
7
+ import { ISyncManagerFactoryParams, ISyncManagerCS } from './sync/types';
6
8
 
7
9
  /**
8
10
  * EventEmitter interface with the minimal methods used by the SDK
@@ -55,6 +57,8 @@ export type SDKMode = 'standalone' | 'consumer' | 'localhost';
55
57
  * Settings interface. This is a representation of the settings the SDK expose, that's why
56
58
  * most of it's props are readonly. Only features should be rewritten when localhost mode is active.
57
59
  * @interface ISettings
60
+ *
61
+ * NOTE: same ISettings interface from public type declarations extended with private properties.
58
62
  */
59
63
  export interface ISettings {
60
64
  readonly core: {
@@ -81,7 +85,7 @@ export interface ISettings {
81
85
  retriesOnFailureBeforeReady: number,
82
86
  eventsFirstPushWindow: number
83
87
  },
84
- readonly storage: (params: IStorageFactoryParams) => IStorageSyncCS,
88
+ readonly storage: IStorageSyncFactory,
85
89
  readonly integrations?: Array<(params: IIntegrationFactoryParams) => IIntegration | void>,
86
90
  readonly urls: {
87
91
  events: string,
@@ -96,12 +100,15 @@ export interface ISettings {
96
100
  readonly sync: {
97
101
  splitFilters: SplitIO.SplitFilter[],
98
102
  impressionsMode: SplitIO.ImpressionsMode,
103
+ __splitFiltersValidation: ISplitFiltersValidation,
104
+ localhostMode: SplitIO.LocalhostFactory
99
105
  },
100
106
  readonly runtime: {
101
107
  ip: string | false
102
108
  hostname: string | false
103
109
  },
104
110
  readonly log: ILogger
111
+ readonly impressionListener?: unknown
105
112
  }
106
113
  /**
107
114
  * Log levels.
@@ -576,6 +583,13 @@ export namespace SplitIO {
576
583
  * @typedef {Promise<SplitNames>} SplitNamesAsync
577
584
  */
578
585
  export type SplitNamesAsync = Promise<SplitNames>;
586
+ /**
587
+ * Localhost mode factory.
588
+ */
589
+ export type LocalhostFactory = {
590
+ type?: 'localhost'
591
+ (params: ISyncManagerFactoryParams): ISyncManagerCS
592
+ }
579
593
  /**
580
594
  * Impression listener interface. This is the interface that needs to be implemented
581
595
  * by the element you provide to the SDK as impression listener.
@@ -1,3 +1,5 @@
1
+ import { StorageType } from '../../storages/types';
2
+
1
3
  // Special treatments
2
4
  export const CONTROL = 'control';
3
5
  export const CONTROL_WITH_CONFIG = {
@@ -24,4 +26,7 @@ export const PRODUCER_MODE = 'producer';
24
26
  export const CONSUMER_MODE = 'consumer';
25
27
 
26
28
  // Storage types
27
- export const STORAGE_MEMORY = 'MEMORY';
29
+ export const STORAGE_MEMORY: StorageType = 'MEMORY';
30
+ export const STORAGE_LOCALSTORAGE: StorageType = 'LOCALSTORAGE';
31
+ export const STORAGE_REDIS: StorageType = 'REDIS';
32
+ export const STORAGE_CUSTOM: StorageType = 'CUSTOM';