@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
package/types/types.d.ts CHANGED
@@ -1,7 +1,9 @@
1
1
  /// <reference types="node" />
2
+ import { ISplitFiltersValidation } from './dtos/types';
2
3
  import { IIntegration, IIntegrationFactoryParams } from './integrations/types';
3
4
  import { ILogger } from './logger/types';
4
- import { IStorageFactoryParams, IStorageSyncCS, IStorageSync, IStorageAsync } from './storages/types';
5
+ import { IStorageFactoryParams, IStorageSyncCS, IStorageSync, IStorageAsync, IStorageSyncFactory } from './storages/types';
6
+ import { ISyncManagerFactoryParams, ISyncManagerCS } from './sync/types';
5
7
  /**
6
8
  * EventEmitter interface with the minimal methods used by the SDK
7
9
  */
@@ -50,6 +52,8 @@ export declare type SDKMode = 'standalone' | 'consumer' | 'localhost';
50
52
  * Settings interface. This is a representation of the settings the SDK expose, that's why
51
53
  * most of it's props are readonly. Only features should be rewritten when localhost mode is active.
52
54
  * @interface ISettings
55
+ *
56
+ * NOTE: same ISettings interface from public type declarations extended with private properties.
53
57
  */
54
58
  export interface ISettings {
55
59
  readonly core: {
@@ -76,7 +80,7 @@ export interface ISettings {
76
80
  retriesOnFailureBeforeReady: number;
77
81
  eventsFirstPushWindow: number;
78
82
  };
79
- readonly storage: (params: IStorageFactoryParams) => IStorageSyncCS;
83
+ readonly storage: IStorageSyncFactory;
80
84
  readonly integrations?: Array<(params: IIntegrationFactoryParams) => IIntegration | void>;
81
85
  readonly urls: {
82
86
  events: string;
@@ -91,12 +95,15 @@ export interface ISettings {
91
95
  readonly sync: {
92
96
  splitFilters: SplitIO.SplitFilter[];
93
97
  impressionsMode: SplitIO.ImpressionsMode;
98
+ __splitFiltersValidation: ISplitFiltersValidation;
99
+ localhostMode: SplitIO.LocalhostFactory;
94
100
  };
95
101
  readonly runtime: {
96
102
  ip: string | false;
97
103
  hostname: string | false;
98
104
  };
99
105
  readonly log: ILogger;
106
+ readonly impressionListener?: unknown;
100
107
  }
101
108
  /**
102
109
  * Log levels.
@@ -571,6 +578,13 @@ export declare namespace SplitIO {
571
578
  * @typedef {Promise<SplitNames>} SplitNamesAsync
572
579
  */
573
580
  type SplitNamesAsync = Promise<SplitNames>;
581
+ /**
582
+ * Localhost mode factory.
583
+ */
584
+ type LocalhostFactory = {
585
+ type?: 'localhost';
586
+ (params: ISyncManagerFactoryParams): ISyncManagerCS;
587
+ };
574
588
  /**
575
589
  * Impression listener interface. This is the interface that needs to be implemented
576
590
  * by the element you provide to the SDK as impression listener.
@@ -1,3 +1,4 @@
1
+ import { StorageType } from '../../storages/types';
1
2
  export declare const CONTROL = "control";
2
3
  export declare const CONTROL_WITH_CONFIG: {
3
4
  treatment: string;
@@ -13,4 +14,7 @@ export declare const LOCALHOST_MODE = "localhost";
13
14
  export declare const STANDALONE_MODE = "standalone";
14
15
  export declare const PRODUCER_MODE = "producer";
15
16
  export declare const CONSUMER_MODE = "consumer";
16
- export declare const STORAGE_MEMORY = "MEMORY";
17
+ export declare const STORAGE_MEMORY: StorageType;
18
+ export declare const STORAGE_LOCALSTORAGE: StorageType;
19
+ export declare const STORAGE_REDIS: StorageType;
20
+ export declare const STORAGE_CUSTOM: StorageType;
@@ -0,0 +1,16 @@
1
+ export declare const algorithms: string | {
2
+ /**
3
+ * Expands GZIP data
4
+ * @param data The data to decompress
5
+ * @param out Where to write the data. GZIP already encodes the output size, so providing this doesn't save memory.
6
+ * @returns The decompressed version of the data
7
+ */
8
+ gunzipSync(data: Uint8Array, out?: Uint8Array | undefined): Uint8Array;
9
+ /**
10
+ * Expands Zlib data
11
+ * @param data The data to decompress
12
+ * @param out Where to write the data. Saves memory if you know the decompressed size and provide an output buffer of that length.
13
+ * @returns The decompressed version of the data
14
+ */
15
+ unzlibSync(data: Uint8Array, out?: Uint8Array | undefined): Uint8Array;
16
+ };
@@ -0,0 +1,12 @@
1
+ export declare function UTF16ToUTF8(key: string): string | undefined;
2
+ /*!
3
+ * +----------------------------------------------------------------------------------+
4
+ * | murmurHash3.js v3.0.0 (http://github.com/karanlyons/murmurHash3.js) |
5
+ * | A TypeScript/JavaScript implementation of MurmurHash3's hashing algorithms. |
6
+ * |----------------------------------------------------------------------------------|
7
+ * | Copyright (c) 2012-2020 Karan Lyons. Freely distributable under the MIT license. |
8
+ * +----------------------------------------------------------------------------------+
9
+ */
10
+ export declare function x86Multiply(m: number, n: number): number;
11
+ export declare function x86Rotl(m: number, n: number): number;
12
+ export declare function x86Fmix(h: number): number;
@@ -1,2 +1,2 @@
1
- export declare function hash(str?: string, seed?: number): number;
2
- export declare function bucket(str?: string, seed?: number): number;
1
+ export declare function hash(str: string, seed?: number): number;
2
+ export declare function bucket(str: string, seed?: number): number;
@@ -1 +1,6 @@
1
+ /**
2
+ * x64 version of Murmur3 for 128bits.
3
+ *
4
+ * @param {string} str
5
+ */
1
6
  export declare function hash128(str: string, seed?: number): string;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * x86 version of Murmur3 for 128bits.
3
+ * Used by hashImpression128 because in JS it is more efficient than the x64 version, no matter the underlying OS/CPU arch.
4
+ *
5
+ * @param {string} str
6
+ */
7
+ export declare function hash128(str: string, seed?: number): string;
@@ -0,0 +1,10 @@
1
+ export declare type Hash64 = {
2
+ hex: string;
3
+ dec: string;
4
+ };
5
+ /**
6
+ * Gets the higher 64 bits of the x64 version of Murmur3 for 128bits, as decimal and hexadecimal number strings.
7
+ * Used for MySegments channel V2 notifications.
8
+ * @param {string} str
9
+ */
10
+ export declare function hash64(str: string): Hash64;
@@ -1,9 +1,27 @@
1
1
  export interface utfx {
2
- stringSource(key: string): () => number | null;
3
- stringDestination(): (...args: number[]) => string | undefined;
4
2
  encodeUTF16toUTF8(src: () => number | null, dst: (...args: number[]) => string | undefined): void;
5
- UTF16toUTF8(src: () => number | null, dst: (cp: number) => void): void;
6
- encodeUTF8(src: (() => number | null) | number, dst: (cp: number) => void): void;
7
3
  }
8
- declare const _default: utfx;
9
- export default _default;
4
+ /**
5
+ * Converts and encodes UTF16 characters to UTF8 bytes.
6
+ * @param {!function():number|null} src Characters source as a function returning the next char code respectively `null`
7
+ * if there are no more characters left.
8
+ * @param {!function(number)} dst Bytes destination as a function successively called with the next byte.
9
+ * @expose
10
+ */
11
+ export declare function encodeUTF16toUTF8(src: () => number | null, dst: (...args: number[]) => string | undefined): void;
12
+ /**
13
+ * Creates a source function for a string.
14
+ * @param {string} s String to read from
15
+ * @returns {!function():number|null} Source function returning the next char code respectively `null` if there are
16
+ * no more characters left.
17
+ * @throws {TypeError} If the argument is invalid
18
+ * @expose
19
+ */
20
+ export declare function stringSource(s: string): () => number | null;
21
+ /**
22
+ * Creates a destination function for a string.
23
+ * @returns {function(number=):undefined|string} Destination function successively called with the next char code.
24
+ * Returns the final string when called without arguments.
25
+ * @expose
26
+ */
27
+ export declare function stringDestination(): (...args: number[]) => string | undefined;
@@ -1,4 +1,5 @@
1
- import { ISettingsInternal, ISettingsValidationParams } from './types';
1
+ import { ISettingsValidationParams } from './types';
2
+ import { ISettings } from '../../types';
2
3
  /**
3
4
  * Validates the given config and use it to build a settings object.
4
5
  * NOTE: it doesn't validate the Api Key. Call `validateApikey` or `validateAndTrackApiKey` for that after settings validation.
@@ -6,4 +7,4 @@ import { ISettingsInternal, ISettingsValidationParams } from './types';
6
7
  * @param config user defined configuration
7
8
  * @param validationParams defaults and fields validators used to validate and creates a settings object from a given config
8
9
  */
9
- export declare function settingsValidation(config: unknown, validationParams: ISettingsValidationParams): ISettingsInternal;
10
+ export declare function settingsValidation(config: unknown, validationParams: ISettingsValidationParams): ISettings;
@@ -0,0 +1,9 @@
1
+ import { ISettings } from '../../../types';
2
+ /**
3
+ * This function validates `settings.storage` object
4
+ *
5
+ * @param {any} settings config object provided by the user to initialize the sdk
6
+ *
7
+ * @returns {Object} valid storage factory. It might be the default `InMemoryStorageCSFactory` if the provided storage is invalid.
8
+ */
9
+ export declare function validateLocalhost(settings: ISettings): import("../../../types").SplitIO.LocalhostFactory;
@@ -1,5 +1,10 @@
1
- import { ISettings } from '../../../types';
1
+ import { ISettings, SDKMode } from '../../../types';
2
2
  import { ILogger } from '../../../logger/types';
3
+ import { IStorageFactoryParams, IStorageSyncCS } from '../../../storages/types';
4
+ export declare function __InLocalStorageMockFactory(params: IStorageFactoryParams): IStorageSyncCS;
5
+ export declare namespace __InLocalStorageMockFactory {
6
+ var type: import("../../../storages/types").StorageType;
7
+ }
3
8
  /**
4
9
  * This function validates `settings.storage` object
5
10
  *
@@ -10,4 +15,5 @@ import { ILogger } from '../../../logger/types';
10
15
  export declare function validateStorageCS(settings: {
11
16
  log: ILogger;
12
17
  storage?: any;
18
+ mode?: SDKMode;
13
19
  }): ISettings['storage'];
@@ -1,4 +1,3 @@
1
- import { ISplitFiltersValidation } from '../../dtos/types';
2
1
  import { ISettings } from '../../types';
3
2
  /**
4
3
  * Parameters used to specialize the settings validation for each API variant
@@ -22,13 +21,6 @@ export interface ISettingsValidationParams {
22
21
  integrations?: (settings: ISettings) => ISettings['integrations'];
23
22
  /** Logger validator */
24
23
  logger: (settings: ISettings) => ISettings['log'];
25
- }
26
- /**
27
- * Settings interface extended with private properties used for internal purposes.
28
- */
29
- export interface ISettingsInternal extends ISettings {
30
- readonly sync: ISettings['sync'] & {
31
- __splitFiltersValidation: ISplitFiltersValidation;
32
- };
33
- readonly impressionListener?: unknown;
24
+ /** Localhost mode validator */
25
+ localhost?: (settings: ISettings) => ISettings['sync']['localhostMode'];
34
26
  }
@@ -1,179 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- var tslib_1 = require("tslib");
4
- var object_assign_1 = tslib_1.__importDefault(require("object-assign"));
5
- var constants_1 = require("./constants");
6
- var Backoff_1 = tslib_1.__importDefault(require("../../utils/Backoff"));
7
- var SSEHandler_1 = tslib_1.__importDefault(require("./SSEHandler"));
8
- var MySegmentsUpdateWorker_1 = tslib_1.__importDefault(require("./UpdateWorkers/MySegmentsUpdateWorker"));
9
- var SplitsUpdateWorker_1 = tslib_1.__importDefault(require("./UpdateWorkers/SplitsUpdateWorker"));
10
- var AuthClient_1 = require("./AuthClient");
11
- var lang_1 = require("../../utils/lang");
12
- var SSEClient_1 = tslib_1.__importDefault(require("./SSEClient"));
13
- var key_1 = require("../../utils/key");
14
- var constants_2 = require("../../logger/constants");
15
- /**
16
- * PushManager factory for client-side, with support for multiple clients.
17
- * It assumes settings contains a key.
18
- */
19
- function pushManagerCSFactory(pollingManager, storage, readiness, fetchAuth, platform, settings) {
20
- var log = settings.log;
21
- var sseClient;
22
- try {
23
- // `useHeaders` false for client-side, even if the platform EventSource supports headers (e.g., React Native).
24
- sseClient = new SSEClient_1.default(settings, false, platform.getEventSource);
25
- }
26
- catch (e) {
27
- log.warn(constants_2.STREAMING_FALLBACK, [e]);
28
- return;
29
- }
30
- var authenticate = AuthClient_1.authenticateFactory(fetchAuth);
31
- // init feedback loop
32
- var pushEmitter = new platform.EventEmitter();
33
- var sseHandler = SSEHandler_1.default(log, pushEmitter);
34
- sseClient.setEventHandler(sseHandler);
35
- // [Only for client-side] map of hashes to user keys, to dispatch MY_SEGMENTS_UPDATE events to the corresponding MySegmentsUpdateWorker
36
- var userKeyHashes = {};
37
- var userKey = key_1.getMatching(settings.core.key); // matching key of main client
38
- var hash = AuthClient_1.hashUserKey(userKey);
39
- userKeyHashes[hash] = userKey;
40
- // [Only for client-side] map of user keys to their corresponding MySegmentsUpdateWorkers. It has a two-fold intention:
41
- // - stop workers all together when push is disconnected
42
- // - keep the current list of user keys to authenticate
43
- var workers = {};
44
- // init workers
45
- var mySegmentsUpdateWorker = new MySegmentsUpdateWorker_1.default(pollingManager.segmentsSyncTask);
46
- workers[userKey] = mySegmentsUpdateWorker;
47
- var splitsUpdateWorker = new SplitsUpdateWorker_1.default(storage.splits, pollingManager.splitsSyncTask, readiness.splits);
48
- // [Only for client-side] variable to flag that a new client was added. It is needed to reconnect streaming.
49
- var connectForNewClient = false;
50
- // flag that indicates if `disconnectPush` was called, either by the SyncManager (when the client is destroyed) or by a PUSH_NONRETRYABLE_ERROR error.
51
- // It is used to halt the `connectPush` process if it was in progress.
52
- var disconnected;
53
- /** PushManager functions related to initialization */
54
- var connectPushRetryBackoff = new Backoff_1.default(connectPush, settings.scheduler.pushRetryBackoffBase);
55
- var timeoutId;
56
- function scheduleTokenRefresh(issuedAt, expirationTime) {
57
- // clear scheduled token refresh if exists (needed when resuming PUSH)
58
- if (timeoutId)
59
- clearTimeout(timeoutId);
60
- // Set token refresh 10 minutes before expirationTime
61
- var delayInSeconds = expirationTime - issuedAt - constants_1.SECONDS_BEFORE_EXPIRATION;
62
- log.info(constants_2.STREAMING_REFRESH_TOKEN, [delayInSeconds]);
63
- timeoutId = setTimeout(connectPush, delayInSeconds * 1000);
64
- }
65
- function connectPush() {
66
- disconnected = false;
67
- log.info(constants_2.STREAMING_CONNECTING);
68
- var userKeys = Object.keys(workers); // [Only for client-side]
69
- authenticate(userKeys).then(function (authData) {
70
- if (disconnected)
71
- return;
72
- // 'pushEnabled: false' is handled as a PUSH_NONRETRYABLE_ERROR instead of PUSH_SUBSYSTEM_DOWN, in order to
73
- // close the sseClient in case the org has been bloqued while the instance was connected to streaming
74
- if (!authData.pushEnabled) {
75
- log.info(constants_2.STREAMING_DISABLED);
76
- pushEmitter.emit(constants_1.PUSH_NONRETRYABLE_ERROR);
77
- return;
78
- }
79
- // [Only for client-side] don't open SSE connection if a new shared client was added, since it means that a new authentication is taking place
80
- if (userKeys && userKeys.length < Object.keys(workers).length)
81
- return;
82
- // Connect to SSE and schedule refresh token
83
- var decodedToken = authData.decodedToken;
84
- sseClient.open(authData);
85
- scheduleTokenRefresh(decodedToken.iat, decodedToken.exp);
86
- }).catch(function (error) {
87
- if (disconnected)
88
- return;
89
- log.error(constants_2.ERROR_STREAMING_AUTH, [error.message]);
90
- // Handle 4XX HTTP errors: 401 (invalid API Key) or 400 (using incorrect API Key, i.e., client-side API Key on server-side)
91
- if (error.statusCode >= 400 && error.statusCode < 500) {
92
- pushEmitter.emit(constants_1.PUSH_NONRETRYABLE_ERROR);
93
- return;
94
- }
95
- // Handle other HTTP and network errors as recoverable errors
96
- pushEmitter.emit(constants_1.PUSH_RETRYABLE_ERROR);
97
- });
98
- }
99
- // close SSE connection and cancel scheduled tasks
100
- function disconnectPush() {
101
- sseClient.close();
102
- disconnected = true;
103
- log.info(constants_2.STREAMING_DISCONNECTING);
104
- if (timeoutId)
105
- clearTimeout(timeoutId);
106
- connectPushRetryBackoff.reset();
107
- stopWorkers();
108
- }
109
- // cancel scheduled fetch retries of Splits, Segments, and MySegments Update Workers
110
- function stopWorkers() {
111
- splitsUpdateWorker.backoff.reset();
112
- lang_1.forOwn(workers, function (worker) { return worker.backoff.reset(); });
113
- }
114
- pushEmitter.on(constants_1.PUSH_SUBSYSTEM_DOWN, stopWorkers);
115
- // restart backoff retry counter once push is connected
116
- pushEmitter.on(constants_1.PUSH_SUBSYSTEM_UP, function () { connectPushRetryBackoff.reset(); });
117
- /** Fallbacking without retry due to: STREAMING_DISABLED control event, or 'pushEnabled: false', or non-recoverable SSE and Authentication errors */
118
- pushEmitter.on(constants_1.PUSH_NONRETRYABLE_ERROR, function handleNonRetryableError() {
119
- // Note: `stopWorkers` is been called twice, but it is not harmful
120
- disconnectPush();
121
- pushEmitter.emit(constants_1.PUSH_SUBSYSTEM_DOWN); // no harm if polling already
122
- });
123
- /** Fallbacking with retry due to recoverable SSE and Authentication errors */
124
- pushEmitter.on(constants_1.PUSH_RETRYABLE_ERROR, function handleRetryableError() {
125
- // SSE connection is closed to avoid repeated errors due to retries
126
- sseClient.close();
127
- // retry streaming reconnect with backoff algorithm
128
- var delayInMillis = connectPushRetryBackoff.scheduleCall();
129
- log.info(constants_2.STREAMING_RECONNECT, [delayInMillis / 1000]);
130
- pushEmitter.emit(constants_1.PUSH_SUBSYSTEM_DOWN); // no harm if polling already
131
- });
132
- /** Functions related to synchronization (Queues and Workers in the spec) */
133
- pushEmitter.on(constants_1.SPLIT_KILL, splitsUpdateWorker.killSplit);
134
- pushEmitter.on(constants_1.SPLIT_UPDATE, splitsUpdateWorker.put);
135
- // [Only for client-side]
136
- pushEmitter.on(constants_1.MY_SEGMENTS_UPDATE, function handleMySegmentsUpdate(parsedData, channel) {
137
- var userKeyHash = channel.split('_')[2];
138
- var userKey = userKeyHashes[userKeyHash];
139
- if (userKey && workers[userKey]) { // check context since it can be undefined if client has been destroyed
140
- var mySegmentsUpdateWorker_1 = workers[userKey];
141
- mySegmentsUpdateWorker_1.put(parsedData.changeNumber, parsedData.includesPayload ? parsedData.segmentList ? parsedData.segmentList : [] : undefined);
142
- }
143
- });
144
- return object_assign_1.default(
145
- // Expose Event Emitter functionality and Event constants
146
- Object.create(pushEmitter), {
147
- // Expose functionality for starting and stoping push mode:
148
- stop: disconnectPush,
149
- start: function () {
150
- // Run in next event-loop cycle for optimization: if multiple clients are created in the same cycle than the factory, only one authentication is performed.
151
- setTimeout(connectPush);
152
- },
153
- // [Only for client-side]
154
- add: function (userKey, mySegmentsSyncTask) {
155
- var mySegmentsUpdateWorker = new MySegmentsUpdateWorker_1.default(mySegmentsSyncTask);
156
- workers[userKey] = mySegmentsUpdateWorker;
157
- var hash = AuthClient_1.hashUserKey(userKey);
158
- if (!userKeyHashes[hash]) {
159
- userKeyHashes[hash] = userKey;
160
- connectForNewClient = true; // we must reconnect on start, to listen the channel for the new user key
161
- }
162
- // Reconnects in case of a new client.
163
- // Run in next event-loop cycle to save authentication calls
164
- // in case the user is creating several clients in the current cycle.
165
- setTimeout(function checkForReconnect() {
166
- if (connectForNewClient) {
167
- connectForNewClient = false;
168
- connectPush();
169
- }
170
- }, 0);
171
- },
172
- // [Only for client-side]
173
- remove: function (userKey) {
174
- var hash = AuthClient_1.hashUserKey(userKey);
175
- delete userKeyHashes[hash];
176
- }
177
- });
178
- }
179
- exports.default = pushManagerCSFactory;
@@ -1,128 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- var tslib_1 = require("tslib");
4
- var object_assign_1 = tslib_1.__importDefault(require("object-assign"));
5
- var constants_1 = require("./constants");
6
- var Backoff_1 = tslib_1.__importDefault(require("../../utils/Backoff"));
7
- var SSEHandler_1 = tslib_1.__importDefault(require("./SSEHandler"));
8
- var SegmentsUpdateWorker_1 = tslib_1.__importDefault(require("./UpdateWorkers/SegmentsUpdateWorker"));
9
- var SplitsUpdateWorker_1 = tslib_1.__importDefault(require("./UpdateWorkers/SplitsUpdateWorker"));
10
- var AuthClient_1 = require("./AuthClient");
11
- var SSEClient_1 = tslib_1.__importDefault(require("./SSEClient"));
12
- var constants_2 = require("../../logger/constants");
13
- /**
14
- * PushManager factory for server-side
15
- */
16
- function pushManagerSSFactory(pollingManager, storage, readiness, fetchAuth, platform, settings) {
17
- var log = settings.log;
18
- var sseClient;
19
- try {
20
- sseClient = new SSEClient_1.default(settings, true, platform.getEventSource);
21
- }
22
- catch (e) {
23
- log.warn(constants_2.STREAMING_FALLBACK, [e]);
24
- return;
25
- }
26
- var authenticate = AuthClient_1.authenticateFactory(fetchAuth);
27
- // init feedback loop (pushEmitter)
28
- var pushEmitter = new platform.EventEmitter();
29
- var sseHandler = SSEHandler_1.default(log, pushEmitter);
30
- sseClient.setEventHandler(sseHandler);
31
- // init workers
32
- var splitsUpdateWorker = new SplitsUpdateWorker_1.default(storage.splits, pollingManager.splitsSyncTask, readiness.splits, pollingManager.segmentsSyncTask);
33
- var segmentsUpdateWorker = new SegmentsUpdateWorker_1.default(storage.segments, pollingManager.segmentsSyncTask);
34
- // flag that indicates if `disconnectPush` was called, either by the SyncManager (when the client is destroyed) or by a PUSH_NONRETRYABLE_ERROR error.
35
- // It is used to halt the `connectPush` process if it was in progress.
36
- var disconnected;
37
- /** PushManager functions related to initialization */
38
- var connectPushRetryBackoff = new Backoff_1.default(connectPush, settings.scheduler.pushRetryBackoffBase);
39
- var timeoutId;
40
- function scheduleTokenRefresh(issuedAt, expirationTime) {
41
- // clear scheduled token refresh if exists (needed when resuming PUSH)
42
- if (timeoutId)
43
- clearTimeout(timeoutId);
44
- // Set token refresh 10 minutes before expirationTime
45
- var delayInSeconds = expirationTime - issuedAt - constants_1.SECONDS_BEFORE_EXPIRATION;
46
- log.info(constants_2.STREAMING_REFRESH_TOKEN, [delayInSeconds]);
47
- timeoutId = setTimeout(connectPush, delayInSeconds * 1000);
48
- }
49
- function connectPush() {
50
- disconnected = false;
51
- log.info(constants_2.STREAMING_CONNECTING);
52
- authenticate().then(function (authData) {
53
- if (disconnected)
54
- return;
55
- // 'pushEnabled: false' is handled as a PUSH_NONRETRYABLE_ERROR instead of PUSH_SUBSYSTEM_DOWN, in order to
56
- // close the sseClient in case the org has been bloqued while the instance was connected to streaming
57
- if (!authData.pushEnabled) {
58
- log.info(constants_2.STREAMING_DISABLED);
59
- pushEmitter.emit(constants_1.PUSH_NONRETRYABLE_ERROR);
60
- return;
61
- }
62
- // Connect to SSE and schedule refresh token
63
- var decodedToken = authData.decodedToken;
64
- sseClient.open(authData);
65
- scheduleTokenRefresh(decodedToken.iat, decodedToken.exp);
66
- }).catch(function (error) {
67
- if (disconnected)
68
- return;
69
- log.error(constants_2.ERROR_STREAMING_AUTH, [error.message]);
70
- // Handle 4XX HTTP errors: 401 (invalid API Key) or 400 (using incorrect API Key, i.e., client-side API Key on server-side)
71
- if (error.statusCode >= 400 && error.statusCode < 500) {
72
- pushEmitter.emit(constants_1.PUSH_NONRETRYABLE_ERROR);
73
- return;
74
- }
75
- // Handle other HTTP and network errors as recoverable errors
76
- pushEmitter.emit(constants_1.PUSH_RETRYABLE_ERROR);
77
- });
78
- }
79
- // close SSE connection and cancel scheduled tasks
80
- function disconnectPush() {
81
- sseClient.close();
82
- disconnected = true;
83
- log.info(constants_2.STREAMING_DISCONNECTING);
84
- if (timeoutId)
85
- clearTimeout(timeoutId);
86
- connectPushRetryBackoff.reset();
87
- stopWorkers();
88
- }
89
- // cancel scheduled fetch retries of Splits, Segments, and MySegments Update Workers
90
- function stopWorkers() {
91
- splitsUpdateWorker.backoff.reset();
92
- segmentsUpdateWorker.backoff.reset();
93
- }
94
- pushEmitter.on(constants_1.PUSH_SUBSYSTEM_DOWN, stopWorkers);
95
- // restart backoff retry counter once push is connected
96
- pushEmitter.on(constants_1.PUSH_SUBSYSTEM_UP, function () { connectPushRetryBackoff.reset(); });
97
- /** Fallbacking without retry due to: STREAMING_DISABLED control event, or 'pushEnabled: false', or non-recoverable SSE and Authentication errors */
98
- pushEmitter.on(constants_1.PUSH_NONRETRYABLE_ERROR, function handleNonRetryableError() {
99
- // Note: `stopWorkers` is been called twice, but it is not harmful
100
- disconnectPush();
101
- pushEmitter.emit(constants_1.PUSH_SUBSYSTEM_DOWN); // no harm if polling already
102
- });
103
- /** Fallbacking with retry due to recoverable SSE and Authentication errors */
104
- pushEmitter.on(constants_1.PUSH_RETRYABLE_ERROR, function handleRetryableError() {
105
- // SSE connection is closed to avoid repeated errors due to retries
106
- sseClient.close();
107
- // retry streaming reconnect with backoff algorithm
108
- var delayInMillis = connectPushRetryBackoff.scheduleCall();
109
- log.info(constants_2.STREAMING_RECONNECT, [delayInMillis / 1000]);
110
- pushEmitter.emit(constants_1.PUSH_SUBSYSTEM_DOWN); // no harm if polling already
111
- });
112
- /** Functions related to synchronization (Queues and Workers in the spec) */
113
- pushEmitter.on(constants_1.SPLIT_KILL, splitsUpdateWorker.killSplit);
114
- pushEmitter.on(constants_1.SPLIT_UPDATE, splitsUpdateWorker.put);
115
- // [Only for server-side]
116
- pushEmitter.on(constants_1.SEGMENT_UPDATE, segmentsUpdateWorker.put);
117
- return object_assign_1.default(
118
- // Expose Event Emitter functionality and Event constants
119
- Object.create(pushEmitter), {
120
- // Expose functionality for starting and stoping push mode:
121
- stop: disconnectPush,
122
- start: function () {
123
- // Run in next event-loop cycle as in browser
124
- setTimeout(connectPush);
125
- }
126
- });
127
- }
128
- exports.default = pushManagerSSFactory;