@splitsoftware/splitio-commons 1.17.1-rc.3 → 2.0.0-rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (216) hide show
  1. package/CHANGES.txt +7 -3
  2. package/cjs/evaluator/index.js +2 -2
  3. package/cjs/evaluator/matchers/semver_inlist.js +1 -2
  4. package/cjs/evaluator/matchers/whitelist.js +1 -2
  5. package/cjs/listeners/browser.js +1 -2
  6. package/cjs/logger/browser/DebugLogger.js +1 -2
  7. package/cjs/logger/browser/ErrorLogger.js +1 -2
  8. package/cjs/logger/browser/InfoLogger.js +1 -2
  9. package/cjs/logger/browser/WarnLogger.js +1 -2
  10. package/cjs/logger/index.js +1 -2
  11. package/cjs/readiness/readinessManager.js +5 -7
  12. package/cjs/sdkClient/clientCS.js +5 -8
  13. package/cjs/sdkClient/sdkClientMethodCS.js +5 -8
  14. package/cjs/sdkFactory/index.js +10 -33
  15. package/cjs/services/decorateHeaders.js +1 -2
  16. package/cjs/storages/AbstractSplitsCacheAsync.js +7 -0
  17. package/cjs/storages/AbstractSplitsCacheSync.js +7 -0
  18. package/cjs/storages/KeyBuilderCS.js +0 -9
  19. package/cjs/storages/dataLoader.js +32 -64
  20. package/cjs/storages/inLocalStorage/MySegmentsCacheInLocal.js +1 -21
  21. package/cjs/storages/inLocalStorage/SplitsCacheInLocal.js +14 -7
  22. package/cjs/storages/inLocalStorage/index.js +1 -6
  23. package/cjs/storages/inMemory/InMemoryStorageCS.js +4 -16
  24. package/cjs/storages/inMemory/SegmentsCacheInMemory.js +3 -4
  25. package/cjs/storages/inMemory/SplitsCacheInMemory.js +2 -3
  26. package/cjs/storages/inMemory/UniqueKeysCacheInMemory.js +2 -3
  27. package/cjs/storages/inMemory/UniqueKeysCacheInMemoryCS.js +2 -3
  28. package/cjs/storages/inRedis/RedisAdapter.js +3 -4
  29. package/cjs/storages/inRedis/SplitsCacheInRedis.js +1 -1
  30. package/cjs/storages/inRedis/TelemetryCacheInRedis.js +3 -4
  31. package/cjs/storages/inRedis/UniqueKeysCacheInRedis.js +1 -2
  32. package/cjs/storages/pluggable/SplitsCachePluggable.js +1 -1
  33. package/cjs/storages/pluggable/TelemetryCachePluggable.js +6 -7
  34. package/cjs/storages/pluggable/UniqueKeysCachePluggable.js +1 -2
  35. package/cjs/storages/pluggable/inMemoryWrapper.js +7 -8
  36. package/cjs/storages/pluggable/index.js +32 -37
  37. package/cjs/sync/offline/syncTasks/fromObjectSyncTask.js +7 -2
  38. package/cjs/sync/polling/pollingManagerSS.js +3 -3
  39. package/cjs/sync/polling/updaters/splitChangesUpdater.js +13 -5
  40. package/cjs/sync/streaming/parseUtils.js +0 -1
  41. package/cjs/sync/streaming/pushManager.js +2 -3
  42. package/cjs/trackers/eventTracker.js +9 -11
  43. package/cjs/trackers/impressionsTracker.js +13 -15
  44. package/cjs/trackers/uniqueKeysTracker.js +3 -5
  45. package/cjs/utils/LRUCache/index.js +1 -2
  46. package/cjs/utils/constants/browser.js +1 -4
  47. package/cjs/utils/lang/index.js +6 -9
  48. package/cjs/utils/lang/objectAssign.js +12 -77
  49. package/cjs/utils/lang/sets.js +3 -110
  50. package/cjs/utils/settingsValidation/index.js +0 -9
  51. package/cjs/utils/settingsValidation/logger/builtinLogger.js +1 -2
  52. package/cjs/utils/settingsValidation/storage/storageCS.js +12 -1
  53. package/esm/evaluator/index.js +3 -3
  54. package/esm/evaluator/matchers/semver_inlist.js +1 -2
  55. package/esm/evaluator/matchers/whitelist.js +1 -2
  56. package/esm/listeners/browser.js +1 -2
  57. package/esm/logger/browser/DebugLogger.js +1 -2
  58. package/esm/logger/browser/ErrorLogger.js +1 -2
  59. package/esm/logger/browser/InfoLogger.js +1 -2
  60. package/esm/logger/browser/WarnLogger.js +1 -2
  61. package/esm/logger/index.js +1 -2
  62. package/esm/readiness/readinessManager.js +5 -7
  63. package/esm/sdkClient/clientCS.js +5 -8
  64. package/esm/sdkClient/sdkClientMethodCS.js +5 -8
  65. package/esm/sdkFactory/index.js +11 -34
  66. package/esm/services/decorateHeaders.js +1 -2
  67. package/esm/storages/AbstractSplitsCacheAsync.js +7 -0
  68. package/esm/storages/AbstractSplitsCacheSync.js +7 -0
  69. package/esm/storages/KeyBuilderCS.js +0 -9
  70. package/esm/storages/dataLoader.js +30 -61
  71. package/esm/storages/inLocalStorage/MySegmentsCacheInLocal.js +1 -21
  72. package/esm/storages/inLocalStorage/SplitsCacheInLocal.js +14 -7
  73. package/esm/storages/inLocalStorage/index.js +2 -7
  74. package/esm/storages/inMemory/InMemoryStorageCS.js +4 -16
  75. package/esm/storages/inMemory/SegmentsCacheInMemory.js +3 -4
  76. package/esm/storages/inMemory/SplitsCacheInMemory.js +2 -3
  77. package/esm/storages/inMemory/UniqueKeysCacheInMemory.js +2 -3
  78. package/esm/storages/inMemory/UniqueKeysCacheInMemoryCS.js +2 -3
  79. package/esm/storages/inRedis/RedisAdapter.js +3 -4
  80. package/esm/storages/inRedis/SplitsCacheInRedis.js +2 -2
  81. package/esm/storages/inRedis/TelemetryCacheInRedis.js +3 -4
  82. package/esm/storages/inRedis/UniqueKeysCacheInRedis.js +1 -2
  83. package/esm/storages/pluggable/SplitsCachePluggable.js +2 -2
  84. package/esm/storages/pluggable/TelemetryCachePluggable.js +6 -7
  85. package/esm/storages/pluggable/UniqueKeysCachePluggable.js +1 -2
  86. package/esm/storages/pluggable/inMemoryWrapper.js +7 -8
  87. package/esm/storages/pluggable/index.js +32 -37
  88. package/esm/sync/offline/syncTasks/fromObjectSyncTask.js +8 -3
  89. package/esm/sync/polling/pollingManagerSS.js +3 -3
  90. package/esm/sync/polling/updaters/splitChangesUpdater.js +14 -6
  91. package/esm/sync/streaming/parseUtils.js +0 -1
  92. package/esm/sync/streaming/pushManager.js +2 -3
  93. package/esm/trackers/eventTracker.js +9 -11
  94. package/esm/trackers/impressionsTracker.js +13 -15
  95. package/esm/trackers/uniqueKeysTracker.js +3 -5
  96. package/esm/utils/LRUCache/index.js +1 -2
  97. package/esm/utils/constants/browser.js +0 -3
  98. package/esm/utils/lang/index.js +6 -9
  99. package/esm/utils/lang/objectAssign.js +12 -77
  100. package/esm/utils/lang/sets.js +2 -107
  101. package/esm/utils/settingsValidation/index.js +0 -9
  102. package/esm/utils/settingsValidation/logger/builtinLogger.js +1 -2
  103. package/esm/utils/settingsValidation/storage/storageCS.js +10 -0
  104. package/package.json +2 -2
  105. package/src/evaluator/index.ts +5 -5
  106. package/src/evaluator/matchers/semver_inlist.ts +1 -2
  107. package/src/evaluator/matchers/whitelist.ts +1 -3
  108. package/src/listeners/browser.ts +1 -2
  109. package/src/logger/browser/DebugLogger.ts +1 -2
  110. package/src/logger/browser/ErrorLogger.ts +1 -2
  111. package/src/logger/browser/InfoLogger.ts +1 -2
  112. package/src/logger/browser/WarnLogger.ts +1 -2
  113. package/src/logger/index.ts +3 -4
  114. package/src/readiness/readinessManager.ts +7 -9
  115. package/src/readiness/types.ts +0 -1
  116. package/src/sdkClient/clientCS.ts +5 -8
  117. package/src/sdkClient/sdkClientMethodCS.ts +3 -6
  118. package/src/sdkFactory/index.ts +12 -37
  119. package/src/sdkFactory/types.ts +1 -4
  120. package/src/services/decorateHeaders.ts +1 -2
  121. package/src/storages/AbstractSplitsCacheAsync.ts +9 -2
  122. package/src/storages/AbstractSplitsCacheSync.ts +9 -2
  123. package/src/storages/KeyBuilderCS.ts +0 -13
  124. package/src/storages/dataLoader.ts +32 -62
  125. package/src/storages/inLocalStorage/MySegmentsCacheInLocal.ts +1 -21
  126. package/src/storages/inLocalStorage/SplitsCacheInLocal.ts +16 -8
  127. package/src/storages/inLocalStorage/index.ts +2 -8
  128. package/src/storages/inMemory/InMemoryStorageCS.ts +4 -19
  129. package/src/storages/inMemory/SegmentsCacheInMemory.ts +4 -5
  130. package/src/storages/inMemory/SplitsCacheInMemory.ts +4 -5
  131. package/src/storages/inMemory/UniqueKeysCacheInMemory.ts +4 -5
  132. package/src/storages/inMemory/UniqueKeysCacheInMemoryCS.ts +4 -5
  133. package/src/storages/inRedis/RedisAdapter.ts +4 -5
  134. package/src/storages/inRedis/SplitsCacheInRedis.ts +3 -3
  135. package/src/storages/inRedis/TelemetryCacheInRedis.ts +3 -4
  136. package/src/storages/inRedis/UniqueKeysCacheInRedis.ts +1 -2
  137. package/src/storages/pluggable/SegmentsCachePluggable.ts +0 -1
  138. package/src/storages/pluggable/SplitsCachePluggable.ts +3 -3
  139. package/src/storages/pluggable/TelemetryCachePluggable.ts +6 -7
  140. package/src/storages/pluggable/UniqueKeysCachePluggable.ts +1 -2
  141. package/src/storages/pluggable/inMemoryWrapper.ts +8 -9
  142. package/src/storages/pluggable/index.ts +33 -38
  143. package/src/storages/types.ts +9 -6
  144. package/src/sync/offline/syncTasks/fromObjectSyncTask.ts +7 -3
  145. package/src/sync/polling/pollingManagerSS.ts +2 -3
  146. package/src/sync/polling/updaters/splitChangesUpdater.ts +15 -8
  147. package/src/sync/streaming/parseUtils.ts +0 -1
  148. package/src/sync/streaming/pushManager.ts +3 -4
  149. package/src/sync/submitters/types.ts +3 -4
  150. package/src/trackers/eventTracker.ts +7 -10
  151. package/src/trackers/impressionsTracker.ts +9 -12
  152. package/src/trackers/types.ts +0 -1
  153. package/src/trackers/uniqueKeysTracker.ts +4 -6
  154. package/src/types.ts +9 -18
  155. package/src/utils/LRUCache/index.ts +2 -3
  156. package/src/utils/constants/browser.ts +0 -4
  157. package/src/utils/lang/index.ts +6 -7
  158. package/src/utils/lang/objectAssign.ts +13 -92
  159. package/src/utils/lang/sets.ts +3 -125
  160. package/src/utils/settingsValidation/index.ts +0 -10
  161. package/src/utils/settingsValidation/logger/builtinLogger.ts +1 -2
  162. package/src/utils/settingsValidation/storage/storageCS.ts +13 -0
  163. package/src/utils/settingsValidation/types.ts +0 -2
  164. package/types/logger/index.d.ts +1 -2
  165. package/types/readiness/types.d.ts +0 -1
  166. package/types/sdkClient/clientCS.d.ts +2 -3
  167. package/types/sdkFactory/types.d.ts +1 -3
  168. package/types/storages/AbstractSplitsCacheAsync.d.ts +6 -2
  169. package/types/storages/AbstractSplitsCacheSync.d.ts +6 -2
  170. package/types/storages/KeyBuilderCS.d.ts +0 -2
  171. package/types/storages/dataLoader.d.ts +6 -17
  172. package/types/storages/inLocalStorage/SplitsCacheInLocal.d.ts +7 -2
  173. package/types/storages/inMemory/SplitsCacheInMemory.d.ts +1 -2
  174. package/types/storages/inMemory/UniqueKeysCacheInMemory.d.ts +2 -3
  175. package/types/storages/inRedis/SplitsCacheInRedis.d.ts +1 -2
  176. package/types/storages/pluggable/SplitsCachePluggable.d.ts +1 -2
  177. package/types/storages/pluggable/inMemoryWrapper.d.ts +1 -2
  178. package/types/storages/types.d.ts +7 -6
  179. package/types/sync/polling/updaters/splitChangesUpdater.d.ts +1 -2
  180. package/types/sync/submitters/types.d.ts +3 -4
  181. package/types/trackers/eventTracker.d.ts +1 -1
  182. package/types/trackers/impressionsTracker.d.ts +1 -1
  183. package/types/trackers/types.d.ts +0 -1
  184. package/types/types.d.ts +9 -17
  185. package/types/utils/LRUCache/index.d.ts +1 -2
  186. package/types/utils/constants/browser.d.ts +0 -2
  187. package/types/utils/lang/objectAssign.d.ts +3 -0
  188. package/types/utils/lang/sets.d.ts +1 -61
  189. package/types/utils/settingsValidation/index.d.ts +0 -1
  190. package/types/utils/settingsValidation/storage/storageCS.d.ts +5 -0
  191. package/types/utils/settingsValidation/types.d.ts +0 -2
  192. package/cjs/integrations/browser.js +0 -31
  193. package/cjs/integrations/ga/GaToSplit.js +0 -257
  194. package/cjs/integrations/ga/GoogleAnalyticsToSplit.js +0 -14
  195. package/cjs/integrations/ga/SplitToGa.js +0 -123
  196. package/cjs/integrations/ga/SplitToGoogleAnalytics.js +0 -14
  197. package/cjs/integrations/ga/types.js +0 -2
  198. package/cjs/sdkClient/sdkClientMethodCSWithTT.js +0 -79
  199. package/cjs/utils/lang/maps.js +0 -96
  200. package/esm/integrations/browser.js +0 -27
  201. package/esm/integrations/ga/GaToSplit.js +0 -250
  202. package/esm/integrations/ga/GoogleAnalyticsToSplit.js +0 -10
  203. package/esm/integrations/ga/SplitToGa.js +0 -120
  204. package/esm/integrations/ga/SplitToGoogleAnalytics.js +0 -10
  205. package/esm/integrations/ga/types.js +0 -1
  206. package/esm/sdkClient/sdkClientMethodCSWithTT.js +0 -75
  207. package/esm/utils/lang/maps.js +0 -92
  208. package/src/integrations/browser.ts +0 -35
  209. package/src/integrations/ga/GaToSplit.ts +0 -299
  210. package/src/integrations/ga/GoogleAnalyticsToSplit.ts +0 -14
  211. package/src/integrations/ga/SplitToGa.ts +0 -135
  212. package/src/integrations/ga/SplitToGoogleAnalytics.ts +0 -14
  213. package/src/integrations/ga/autoRequire.js +0 -33
  214. package/src/integrations/ga/types.ts +0 -153
  215. package/src/sdkClient/sdkClientMethodCSWithTT.ts +0 -101
  216. package/src/utils/lang/maps.ts +0 -108
@@ -19,7 +19,6 @@ export function impressionsTrackerFactory(
19
19
  settings: ISettings,
20
20
  impressionsCache: IImpressionsCacheBase,
21
21
  strategy: IStrategy,
22
- whenInit: (cb: () => void) => void,
23
22
  integrationsManager?: IImpressionsHandler,
24
23
  telemetryCache?: ITelemetryCacheSync | ITelemetryCacheAsync,
25
24
  ): IImpressionsTracker {
@@ -68,18 +67,16 @@ export function impressionsTrackerFactory(
68
67
  };
69
68
 
70
69
  // Wrap in a timeout because we don't want it to be blocking.
71
- whenInit(() => {
72
- setTimeout(() => {
73
- // integrationsManager.handleImpression does not throw errors
74
- if (integrationsManager) integrationsManager.handleImpression(impressionData);
70
+ setTimeout(function () {
71
+ // integrationsManager.handleImpression does not throw errors
72
+ if (integrationsManager) integrationsManager.handleImpression(impressionData);
75
73
 
76
- try { // @ts-ignore. An exception on the listeners should not break the SDK.
77
- if (impressionListener) impressionListener.logImpression(impressionData);
78
- } catch (err) {
79
- log.error(ERROR_IMPRESSIONS_LISTENER, [err]);
80
- }
81
- });
82
- });
74
+ try { // @ts-ignore. An exception on the listeners should not break the SDK.
75
+ if (impressionListener) impressionListener.logImpression(impressionData);
76
+ } catch (err) {
77
+ log.error(ERROR_IMPRESSIONS_LISTENER, [err]);
78
+ }
79
+ }, 0);
83
80
  }
84
81
  }
85
82
  }
@@ -65,7 +65,6 @@ export interface IImpressionSenderAdapter {
65
65
 
66
66
  /** Unique keys tracker */
67
67
  export interface IUniqueKeysTracker {
68
- start(): void;
69
68
  stop(): void;
70
69
  track(key: string, featureName: string): void;
71
70
  }
@@ -25,6 +25,10 @@ export function uniqueKeysTrackerFactory(
25
25
  ): IUniqueKeysTracker {
26
26
  let intervalId: any;
27
27
 
28
+ if (filterAdapter.refreshRate) {
29
+ intervalId = setInterval(filterAdapter.clear, filterAdapter.refreshRate);
30
+ }
31
+
28
32
  return {
29
33
 
30
34
  track(key: string, featureName: string): void {
@@ -35,12 +39,6 @@ export function uniqueKeysTrackerFactory(
35
39
  uniqueKeysCache.track(key, featureName);
36
40
  },
37
41
 
38
- start(): void {
39
- if (filterAdapter.refreshRate) {
40
- intervalId = setInterval(filterAdapter.clear, filterAdapter.refreshRate);
41
- }
42
- },
43
-
44
42
  stop(): void {
45
43
  clearInterval(intervalId);
46
44
  }
package/src/types.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ISplit, ISplitFiltersValidation } from './dtos/types';
1
+ import { ISplitFiltersValidation } from './dtos/types';
2
2
  import { IIntegration, IIntegrationFactoryParams } from './integrations/types';
3
3
  import { ILogger } from './logger/types';
4
4
  import { ISdkFactoryContext } from './sdkFactory/types';
@@ -71,7 +71,6 @@ export interface ISettings {
71
71
  readonly core: {
72
72
  authorizationKey: string,
73
73
  key: SplitIO.SplitKey,
74
- trafficType?: string,
75
74
  labelsEnabled: boolean,
76
75
  IPAddressesEnabled: boolean
77
76
  },
@@ -98,7 +97,6 @@ export interface ISettings {
98
97
  eventsFirstPushWindow: number
99
98
  },
100
99
  readonly storage: IStorageSyncFactory | IStorageAsyncFactory,
101
- readonly preloadedData?: SplitIO.PreloadedData,
102
100
  readonly integrations: Array<{
103
101
  readonly type: string,
104
102
  (params: IIntegrationFactoryParams): IIntegration | void
@@ -772,20 +770,21 @@ export namespace SplitIO {
772
770
  * If this value is older than 10 days ago (expiration time policy), the data is not used to update the storage content.
773
771
  * @TODO configurable expiration time policy?
774
772
  */
775
- // lastUpdated: number,
773
+ lastUpdated: number,
776
774
  /**
777
775
  * Change number of the preloaded data.
778
776
  * If this value is older than the current changeNumber at the storage, the data is not used to update the storage content.
779
777
  */
780
778
  since: number,
781
779
  /**
782
- * List of feature flag definitions.
783
- * @TODO rename to flags
780
+ * Map of feature flags to their stringified definitions.
784
781
  */
785
- splitsData: ISplit[],
782
+ splitsData: {
783
+ [splitName: string]: string
784
+ },
786
785
  /**
787
786
  * Optional map of user keys to their list of segments.
788
- * @TODO rename to memberships
787
+ * @TODO remove when releasing first version
789
788
  */
790
789
  mySegmentsData?: {
791
790
  [key: string]: string[]
@@ -793,10 +792,9 @@ export namespace SplitIO {
793
792
  /**
794
793
  * Optional map of segments to their stringified definitions.
795
794
  * This property is ignored if `mySegmentsData` was provided.
796
- * @TODO rename to segments
797
795
  */
798
796
  segmentsData?: {
799
- [segmentName: string]: string[]
797
+ [segmentName: string]: string
800
798
  },
801
799
  }
802
800
  /**
@@ -924,12 +922,6 @@ export namespace SplitIO {
924
922
  * @property {SplitKey} key
925
923
  */
926
924
  key: SplitKey,
927
- /**
928
- * Traffic type associated with the customer identifier. @see {@link https://help.split.io/hc/en-us/articles/360019916311-Traffic-type}
929
- * If no provided as a setting it will be required on the client.track() calls.
930
- * @property {string} trafficType
931
- */
932
- trafficType?: string,
933
925
  /**
934
926
  * Disable labels from being sent to Split backend. Labels may contain sensitive information.
935
927
  * @property {boolean} labelsEnabled
@@ -1038,10 +1030,9 @@ export namespace SplitIO {
1038
1030
  * Returns a shared client of the SDK, with the given key and optional traffic type.
1039
1031
  * @function client
1040
1032
  * @param {SplitKey} key The key for the new client instance.
1041
- * @param {string=} trafficType The traffic type of the provided key.
1042
1033
  * @returns {ICsClient} The client instance.
1043
1034
  */
1044
- client(key: SplitKey, trafficType?: string): ICsClient,
1035
+ client(key: SplitKey): ICsClient,
1045
1036
  /**
1046
1037
  * Returns a manager instance of the SDK to explore available information.
1047
1038
  * @function manager
@@ -1,14 +1,13 @@
1
- import { IMap, _Map } from '../lang/maps';
2
1
  import { LinkedList, Node } from './LinkedList';
3
2
 
4
3
  export class LRUCache<K, V> {
5
4
  maxLen: number;
6
- items: IMap<K, Node<{ key: K, value: V }>>;
5
+ items: Map<K, Node<{ key: K, value: V }>>;
7
6
  lru: LinkedList<{ key: K, value: V }>;
8
7
 
9
8
  constructor(maxSize?: number) {
10
9
  this.maxLen = maxSize || 1;
11
- this.items = new _Map();
10
+ this.items = new Map();
12
11
  this.lru = new LinkedList();
13
12
  }
14
13
 
@@ -1,6 +1,2 @@
1
- // Integration types
2
- export const GOOGLE_ANALYTICS_TO_SPLIT = 'GOOGLE_ANALYTICS_TO_SPLIT';
3
- export const SPLIT_TO_GOOGLE_ANALYTICS = 'SPLIT_TO_GOOGLE_ANALYTICS';
4
-
5
1
  // This value might be eventually set via a config parameter
6
2
  export const DEFAULT_CACHE_EXPIRATION_IN_MILLIS = 864000000; // 10 days
@@ -122,10 +122,9 @@ export function isBoolean(val: any): boolean {
122
122
  */
123
123
  export function isFiniteNumber(val: any): boolean {
124
124
  if (val instanceof Number) val = val.valueOf();
125
- // @TODO remove `isFinite` once `Number.isFinite` is fully supported by targets
126
- // eslint-disable-next-line compat/compat
127
- if (typeof val === 'number') return Number.isFinite ? Number.isFinite(val) : isFinite(val);
128
- return false;
125
+ return typeof val === 'number' ?
126
+ Number.isFinite ? Number.isFinite(val) : isFinite(val) :
127
+ false;
129
128
  }
130
129
 
131
130
  /**
@@ -134,9 +133,9 @@ export function isFiniteNumber(val: any): boolean {
134
133
  */
135
134
  export function isIntegerNumber(val: any): boolean {
136
135
  if (val instanceof Number) val = val.valueOf();
137
- // eslint-disable-next-line compat/compat
138
- if (typeof val === 'number') return Number.isInteger ? Number.isInteger(val) : isFinite(val) && Math.floor(val) === val;
139
- return false;
136
+ return typeof val === 'number' ?
137
+ Number.isInteger ? Number.isInteger(val) : isFinite(val) && Math.floor(val) === val :
138
+ false;
140
139
  }
141
140
 
142
141
  /**
@@ -1,71 +1,6 @@
1
- /*
2
- Adaptation of "object-assign" library (https://www.npmjs.com/package/object-assign)
3
- exported as an ES module instead of CommonJS, to avoid extra configuration steps when using
4
- the ESM build of the SDK with tools that doesn't support CommonJS by default (e.g. Rollup).
5
-
6
- object-assign
7
- (c) Sindre Sorhus
8
- @license MIT
9
- */
10
-
11
- /* eslint-disable */
12
- // @ts-nocheck
13
-
14
- var getOwnPropertySymbols = Object.getOwnPropertySymbols;
15
- var hasOwnProperty = Object.prototype.hasOwnProperty;
16
- var propIsEnumerable = Object.prototype.propertyIsEnumerable;
17
-
18
- function toObject(val) {
19
- if (val === null || val === undefined) {
20
- throw new TypeError('Object.assign cannot be called with null or undefined');
21
- }
22
-
23
- return Object(val);
24
- }
25
-
26
- function shouldUseNative() {
27
- try {
28
- if (!Object.assign) {
29
- return false;
30
- }
31
-
32
- // Detect buggy property enumeration order in older V8 versions.
33
-
34
- // https://bugs.chromium.org/p/v8/issues/detail?id=4118
35
- var test1 = new String('abc');
36
- test1[5] = 'de';
37
- if (Object.getOwnPropertyNames(test1)[0] === '5') {
38
- return false;
39
- }
40
-
41
- // https://bugs.chromium.org/p/v8/issues/detail?id=3056
42
- var test2 = {};
43
- for (var i = 0; i < 10; i++) {
44
- test2['_' + String.fromCharCode(i)] = i;
45
- }
46
- var order2 = Object.getOwnPropertyNames(test2).map(function (n) {
47
- return test2[n];
48
- });
49
- if (order2.join('') !== '0123456789') {
50
- return false;
51
- }
52
-
53
- // https://bugs.chromium.org/p/v8/issues/detail?id=3056
54
- var test3 = {};
55
- 'abcdefghijklmnopqrst'.split('').forEach(function (letter) {
56
- test3[letter] = letter;
57
- });
58
- if (Object.keys(Object.assign({}, test3)).join('') !==
59
- 'abcdefghijklmnopqrst') {
60
- return false;
61
- }
62
-
63
- return true;
64
- } catch (err) {
65
- // We don't expect any of the above to throw, but better to be safe.
66
- return false;
67
- }
68
- }
1
+ /**
2
+ * A tiny polyfill for Object.assign
3
+ */
69
4
 
70
5
  // https://www.npmjs.com/package/@types/object-assign
71
6
  type ObjectAssign = (<T, U>(target: T, source: U) => T & U) &
@@ -74,31 +9,17 @@ type ObjectAssign = (<T, U>(target: T, source: U) => T & U) &
74
9
  (<T, U, V, W, Q>(target: T, source1: U, source2: V, source3: W, source4: Q) => T & U & V & W & Q) &
75
10
  (<T, U, V, W, Q, R>(target: T, source1: U, source2: V, source3: W, source4: Q, source5: R) => T & U & V & W & Q & R) &
76
11
  ((target: any, ...sources: any[]) => any);
77
-
78
- export const objectAssign: ObjectAssign = shouldUseNative() ? Object.assign : function (target, source) {
79
- var from;
80
- var to = toObject(target);
81
- var symbols;
82
-
83
- for (var s = 1; s < arguments.length; s++) {
84
- from = Object(arguments[s]);
85
-
86
- // eslint-disable-next-line no-restricted-syntax
87
- for (var key in from) {
88
- if (hasOwnProperty.call(from, key)) {
89
- to[key] = from[key];
90
- }
91
- }
92
-
93
- if (getOwnPropertySymbols) {
94
- symbols = getOwnPropertySymbols(from);
95
- for (var i = 0; i < symbols.length; i++) {
96
- if (propIsEnumerable.call(from, symbols[i])) {
97
- to[symbols[i]] = from[symbols[i]];
98
- }
12
+ export const objectAssign: ObjectAssign = Object.assign || function (target: any) {
13
+ if (target === null || target === undefined) throw new TypeError('Object.assign cannot be called with null or undefined');
14
+ target = Object(target);
15
+
16
+ for (let i = 1; i < arguments.length; i++) {
17
+ const source = Object(arguments[i]); // eslint-disable-next-line no-restricted-syntax
18
+ for (const key in source) {
19
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
20
+ target[key] = source[key];
99
21
  }
100
22
  }
101
23
  }
102
-
103
- return to;
24
+ return target;
104
25
  };
@@ -1,129 +1,7 @@
1
- /**
2
- * Set implementation based on es6-set polyfill (https://github.com/medikoo/es6-set/blob/master/polyfill.js),
3
- * with the minimal features used by the SDK.
4
-
5
- Copyright (C) 2013 Mariusz Nowak (www.medikoo.com)
6
-
7
- Permission is hereby granted, free of charge, to any person obtaining a copy
8
- of this software and associated documentation files (the "Software"), to deal
9
- in the Software without restriction, including without limitation the rights
10
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
- copies of the Software, and to permit persons to whom the Software is
12
- furnished to do so, subject to the following conditions:
13
-
14
- The above copyright notice and this permission notice shall be included in
15
- all copies or substantial portions of the Software.
16
-
17
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23
- THE SOFTWARE.
24
- **/
25
-
26
- export interface ISet<T> {
27
- add(value: T): this;
28
- clear(): void;
29
- delete(value: T): boolean;
30
- forEach(callbackfn: (value: T, value2: T, set: ISet<T>) => void, thisArg?: any): void;
31
- has(value: T): boolean;
32
- readonly size: number;
33
- }
34
-
35
- export class SetPoly<T> implements ISet<T>{
36
- __setData__: T[] = [];
37
-
38
- // unlike ES6 `Set`, it only accepts an array as first argument iterable
39
- constructor(values?: readonly T[] | null) {
40
- if (Array.isArray(values)) values.forEach(value => { this.add(value); });
41
- }
42
-
43
- clear() {
44
- if (!this.__setData__.length) return;
45
- this.__setData__.length = 0;
46
- }
47
-
48
- add(value: T) {
49
- if (this.has(value)) return this;
50
- this.__setData__.push(value);
51
- return this;
52
- }
53
-
54
- delete(value: T) {
55
- let index = this.__setData__.indexOf(value);
56
- if (index === -1) return false;
57
- this.__setData__.splice(index, 1);
58
- return true;
59
- }
60
-
61
- has(value: T) {
62
- return this.__setData__.indexOf(value) !== -1;
63
- }
64
-
65
- forEach(callbackfn: (value: T, value2: T, set: SetPoly<T>) => void, thisArg?: any): void {
66
- if (typeof callbackfn !== 'function') throw new TypeError(callbackfn + ' is not a function');
67
-
68
- for (let i = 0; i < this.__setData__.length; i++) {
69
- const value = this.__setData__[i];
70
- callbackfn.call(thisArg, value, value, this);
71
- }
72
- }
73
-
74
- get size() {
75
- return this.__setData__.length;
76
- }
77
-
78
- }
79
-
80
-
81
- /**
82
- * return an array containing the items of the given set.
83
- * @param set Set or SetPoly instance
84
- */
85
- export function setToArray<T>(set: ISet<T>): T[] {
86
- if (set instanceof SetPoly) {
87
- return set.__setData__.slice();
88
- }
89
- // if not using SetPoly as set, it means Array.from is supported
90
- // eslint-disable-next-line compat/compat
91
- return Array.from(set as Set<T>);
92
- }
93
-
94
- interface ISetConstructor {
95
- new <T = any>(values?: readonly T[] | null): ISet<T>;
96
- readonly prototype: ISet<any>;
97
- }
98
-
99
- /**
100
- * return the Set constructor to use. If `Array.from` built-in or native Set is not available or it doesn't support the required features,
101
- * a ponyfill with minimal features is returned instead.
102
- *
103
- * Exported for testing purposes only.
104
- */
105
- export function __getSetConstructor(): ISetConstructor {
106
- // eslint-disable-next-line compat/compat
107
- if (typeof Array.from === 'function' && typeof Set === 'function' && Set.prototype && Set.prototype.values) {
108
- return Set;
109
- }
110
- return SetPoly;
111
- }
112
-
113
- export const _Set = __getSetConstructor();
114
-
115
- export function returnSetsUnion<T>(set: ISet<T>, set2: ISet<T>): ISet<T> {
116
- const result = new _Set(setToArray(set));
117
- set2.forEach(value => {
118
- result.add(value);
119
- });
120
- return result;
1
+ export function returnSetsUnion<T>(set: Set<T>, set2: Set<T>): Set<T> {
2
+ return new Set(Array.from(set).concat(Array.from(set2)));
121
3
  }
122
4
 
123
5
  export function returnDifference<T>(list: T[] = [], list2: T[] = []): T[] {
124
- const result = new _Set(list);
125
- list2.forEach(item => {
126
- result.delete(item);
127
- });
128
- return setToArray(result);
6
+ return list.filter(item => list2.indexOf(item) === -1);
129
7
  }
@@ -6,7 +6,6 @@ import { validImpressionsMode } from './impressionsMode';
6
6
  import { ISettingsValidationParams } from './types';
7
7
  import { ISettings } from '../../types';
8
8
  import { validateKey } from '../inputValidation/key';
9
- import { validateTrafficType } from '../inputValidation/trafficType';
10
9
  import { ERROR_MIN_CONFIG_PARAM, LOG_PREFIX_CLIENT_INSTANTIATION } from '../../logger/constants';
11
10
 
12
11
  // Exported for telemetry
@@ -19,8 +18,6 @@ export const base = {
19
18
  authorizationKey: undefined,
20
19
  // key used in your system (only required for browser version)
21
20
  key: undefined,
22
- // traffic type for the given key (only used on browser version)
23
- trafficType: undefined,
24
21
  // toggle impressions tracking of labels
25
22
  labelsEnabled: true,
26
23
  // toggle sendind (true) or not sending (false) IP and Host Name with impressions, events, and telemetries requests (only used on nodejs version)
@@ -168,13 +165,6 @@ export function settingsValidation(config: unknown, validationParams: ISettingsV
168
165
  // @ts-ignore, @TODO handle invalid keys as a non-recoverable error?
169
166
  withDefaults.core.key = validateKey(log, maybeKey, LOG_PREFIX_CLIENT_INSTANTIATION);
170
167
  }
171
-
172
- if (validationParams.acceptTT) {
173
- const maybeTT = withDefaults.core.trafficType;
174
- if (maybeTT !== undefined) { // @ts-ignore
175
- withDefaults.core.trafficType = validateTrafficType(log, maybeTT, LOG_PREFIX_CLIENT_INSTANTIATION);
176
- }
177
- }
178
168
  } else {
179
169
  // On server-side, key is undefined and used to distinguish from client-side
180
170
  if (maybeKey !== undefined) log.warn('Provided `key` is ignored in server-side SDK.'); // @ts-ignore
@@ -3,11 +3,10 @@ import { ILogger } from '../../../logger/types';
3
3
  import { isLocalStorageAvailable } from '../../env/isLocalStorageAvailable';
4
4
  import { isNode } from '../../env/isNode';
5
5
  import { codesDebug } from '../../../logger/messages/debug';
6
- import { _Map } from '../../lang/maps';
7
6
  import { getLogLevel } from './commons';
8
7
  import { LogLevel } from '../../../types';
9
8
 
10
- const allCodes = new _Map(codesDebug);
9
+ const allCodes = new Map(codesDebug);
11
10
 
12
11
  // @TODO set default debug setting instead of initialLogLevel when integrating in JS and Node packages
13
12
  const LS_KEY = 'splitio_debug';
@@ -3,6 +3,14 @@ import { ISettings, SDKMode } from '../../../types';
3
3
  import { ILogger } from '../../../logger/types';
4
4
  import { ERROR_STORAGE_INVALID } from '../../../logger/constants';
5
5
  import { LOCALHOST_MODE, STANDALONE_MODE, STORAGE_PLUGGABLE, STORAGE_LOCALSTORAGE, STORAGE_MEMORY } from '../../../utils/constants';
6
+ import { IStorageFactoryParams, IStorageSync } from '../../../storages/types';
7
+
8
+ export function __InLocalStorageMockFactory(params: IStorageFactoryParams): IStorageSync {
9
+ const result = InMemoryStorageCSFactory(params);
10
+ result.splits.checkCache = () => true; // to emit SDK_READY_FROM_CACHE
11
+ return result;
12
+ }
13
+ __InLocalStorageMockFactory.type = STORAGE_MEMORY;
6
14
 
7
15
  /**
8
16
  * This function validates `settings.storage` object
@@ -22,6 +30,11 @@ export function validateStorageCS(settings: { log: ILogger, storage?: any, mode:
22
30
  log.error(ERROR_STORAGE_INVALID);
23
31
  }
24
32
 
33
+ // In localhost mode with InLocalStorage, fallback to a mock InLocalStorage to emit SDK_READY_FROM_CACHE
34
+ if (mode === LOCALHOST_MODE && storage.type === STORAGE_LOCALSTORAGE) {
35
+ return __InLocalStorageMockFactory;
36
+ }
37
+
25
38
  if ([LOCALHOST_MODE, STANDALONE_MODE].indexOf(mode) === -1) {
26
39
  // Consumer modes require an async storage
27
40
  if (storage.type !== STORAGE_PLUGGABLE) throw new Error('A PluggableStorage instance is required on consumer mode');
@@ -12,8 +12,6 @@ export interface ISettingsValidationParams {
12
12
  defaults: Partial<ISettings> & { version: string } & { startup: ISettings['startup'] },
13
13
  /** If true, validates core.key */
14
14
  acceptKey?: boolean,
15
- /** If true, validates core.trafficType */
16
- acceptTT?: boolean,
17
15
  /** Define runtime values (`settings.runtime`) */
18
16
  runtime: (settings: ISettings) => ISettings['runtime'],
19
17
  /** Storage validator (`settings.storage`) */
@@ -1,6 +1,5 @@
1
1
  import { ILoggerOptions, ILogger } from './types';
2
2
  import { LogLevel } from '../types';
3
- import { IMap } from '../utils/lang/maps';
4
3
  export declare const LogLevels: {
5
4
  [level: string]: LogLevel;
6
5
  };
@@ -10,7 +9,7 @@ export declare class Logger implements ILogger {
10
9
  private options;
11
10
  private codes;
12
11
  private logLevel;
13
- constructor(options?: ILoggerOptions, codes?: IMap<number, string>);
12
+ constructor(options?: ILoggerOptions, codes?: Map<number, string>);
14
13
  setLogLevel(logLevel: LogLevel): void;
15
14
  debug(msg: string | number, args?: any[]): void;
16
15
  info(msg: string | number, args?: any[]): void;
@@ -46,7 +46,6 @@ export interface IReadinessManager {
46
46
  timeout(): void;
47
47
  setDestroyed(): void;
48
48
  destroy(): void;
49
- init(): void;
50
49
  /** for client-side */
51
50
  shared(): IReadinessManager;
52
51
  }
@@ -1,10 +1,9 @@
1
1
  import { ILogger } from '../logger/types';
2
2
  import { SplitIO } from '../types';
3
3
  /**
4
- * Decorator that binds a key and (optionally) a traffic type to client methods
4
+ * Decorator that binds a key to client methods
5
5
  *
6
6
  * @param client sync client instance
7
7
  * @param key validated split key
8
- * @param trafficType validated traffic type
9
8
  */
10
- export declare function clientCSDecorator(log: ILogger, client: SplitIO.IClient, key: SplitIO.SplitKey, trafficType?: string): SplitIO.ICsClient;
9
+ export declare function clientCSDecorator(log: ILogger, client: SplitIO.IClient, key: SplitIO.SplitKey): SplitIO.ICsClient;
@@ -48,7 +48,6 @@ export interface ISdkFactoryContext {
48
48
  splitApi?: ISplitApi;
49
49
  syncManager?: ISyncManager;
50
50
  clients: Record<string, IBasicClient>;
51
- whenInit(cb: () => void): void;
52
51
  }
53
52
  export interface ISdkFactoryContextSync extends ISdkFactoryContext {
54
53
  storage: IStorageSync;
@@ -64,7 +63,6 @@ export interface ISdkFactoryContextAsync extends ISdkFactoryContext {
64
63
  * Object parameter with the modules required to create an SDK factory instance
65
64
  */
66
65
  export interface ISdkFactoryParams {
67
- isPure?: boolean;
68
66
  settings: ISettings;
69
67
  platform: IPlatform;
70
68
  storageFactory: (params: IStorageFactoryParams) => IStorageSync | IStorageAsync;
@@ -73,7 +71,7 @@ export interface ISdkFactoryParams {
73
71
  sdkManagerFactory: typeof sdkManagerFactory;
74
72
  sdkClientMethodFactory: (params: ISdkFactoryContext) => ({
75
73
  (): SplitIO.ICsClient;
76
- (key: SplitIO.SplitKey, trafficType?: string | undefined): SplitIO.ICsClient;
74
+ (key: SplitIO.SplitKey): SplitIO.ICsClient;
77
75
  } | (() => SplitIO.IClient) | (() => SplitIO.IAsyncClient));
78
76
  impressionsObserverFactory: () => IImpressionObserver;
79
77
  filterAdapterFactory?: () => IFilterAdapter;
@@ -1,6 +1,5 @@
1
1
  import { ISplitsCacheAsync } from './types';
2
2
  import { ISplit } from '../dtos/types';
3
- import { ISet } from '../utils/lang/sets';
4
3
  /**
5
4
  * This class provides a skeletal implementation of the ISplitsCacheAsync interface
6
5
  * to minimize the effort required to implement this interface.
@@ -15,10 +14,15 @@ export declare abstract class AbstractSplitsCacheAsync implements ISplitsCacheAs
15
14
  abstract getChangeNumber(): Promise<number>;
16
15
  abstract getAll(): Promise<ISplit[]>;
17
16
  abstract getSplitNames(): Promise<string[]>;
18
- abstract getNamesByFlagSets(flagSets: string[]): Promise<ISet<string>[]>;
17
+ abstract getNamesByFlagSets(flagSets: string[]): Promise<Set<string>[]>;
19
18
  abstract trafficTypeExists(trafficType: string): Promise<boolean>;
20
19
  abstract clear(): Promise<boolean | void>;
21
20
  usesSegments(): Promise<boolean>;
21
+ /**
22
+ * Check if the splits information is already stored in cache.
23
+ * Noop, just keeping the interface. This is used by client-side implementations only.
24
+ */
25
+ checkCache(): Promise<boolean>;
22
26
  /**
23
27
  * Kill `name` split and set `defaultTreatment` and `changeNumber`.
24
28
  * Used for SPLIT_KILL push notifications.
@@ -1,6 +1,5 @@
1
1
  import { ISplitsCacheSync } from './types';
2
2
  import { ISplit } from '../dtos/types';
3
- import { ISet } from '../utils/lang/sets';
4
3
  /**
5
4
  * This class provides a skeletal implementation of the ISplitsCacheSync interface
6
5
  * to minimize the effort required to implement this interface.
@@ -19,6 +18,11 @@ export declare abstract class AbstractSplitsCacheSync implements ISplitsCacheSyn
19
18
  abstract trafficTypeExists(trafficType: string): boolean;
20
19
  abstract usesSegments(): boolean;
21
20
  abstract clear(): void;
21
+ /**
22
+ * Check if the splits information is already stored in cache. This data can be preloaded.
23
+ * It is used as condition to emit SDK_SPLITS_CACHE_LOADED, and then SDK_READY_FROM_CACHE.
24
+ */
25
+ checkCache(): boolean;
22
26
  /**
23
27
  * Kill `name` split and set `defaultTreatment` and `changeNumber`.
24
28
  * Used for SPLIT_KILL push notifications.
@@ -30,7 +34,7 @@ export declare abstract class AbstractSplitsCacheSync implements ISplitsCacheSyn
30
34
  * for instance, if the `changeNumber` is old, or if the split is not found (e.g., `/splitchanges` hasn't been fetched yet), or if the storage fails to apply the update.
31
35
  */
32
36
  killLocally(name: string, defaultTreatment: string, changeNumber: number): boolean;
33
- abstract getNamesByFlagSets(flagSets: string[]): ISet<string>[];
37
+ abstract getNamesByFlagSets(flagSets: string[]): Set<string>[];
34
38
  }
35
39
  /**
36
40
  * Given a parsed split, it returns a boolean flagging if its conditions use segments matchers (rules & whitelists).