@splitsoftware/splitio-commons 1.3.1-rc.0 → 1.3.2-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 (212) hide show
  1. package/CHANGES.txt +2 -1
  2. package/cjs/consent/sdkUserConsent.js +1 -1
  3. package/cjs/listeners/browser.js +5 -4
  4. package/cjs/logger/constants.js +2 -1
  5. package/cjs/logger/messages/error.js +2 -1
  6. package/cjs/logger/messages/info.js +3 -3
  7. package/cjs/logger/messages/warn.js +2 -2
  8. package/cjs/sdkClient/client.js +17 -3
  9. package/cjs/sdkClient/sdkClient.js +4 -1
  10. package/cjs/sdkFactory/index.js +16 -19
  11. package/cjs/services/splitApi.js +15 -14
  12. package/cjs/services/splitHttpClient.js +15 -13
  13. package/cjs/storages/AbstractSegmentsCacheSync.js +0 -5
  14. package/cjs/storages/KeyBuilderSS.js +12 -19
  15. package/cjs/storages/findLatencyIndex.js +11 -6
  16. package/cjs/storages/inLocalStorage/MySegmentsCacheInLocal.js +13 -1
  17. package/cjs/storages/inLocalStorage/index.js +4 -1
  18. package/cjs/storages/inMemory/InMemoryStorage.js +2 -0
  19. package/cjs/storages/inMemory/InMemoryStorageCS.js +3 -0
  20. package/cjs/storages/inMemory/MySegmentsCacheInMemory.js +6 -0
  21. package/cjs/storages/inMemory/SegmentsCacheInMemory.js +6 -0
  22. package/cjs/storages/inMemory/TelemetryCacheInMemory.js +165 -0
  23. package/cjs/storages/inRedis/TelemetryCacheInRedis.js +29 -0
  24. package/cjs/storages/inRedis/index.js +2 -4
  25. package/cjs/storages/pluggable/TelemetryCachePluggable.js +27 -0
  26. package/cjs/storages/pluggable/index.js +2 -1
  27. package/cjs/sync/polling/updaters/mySegmentsUpdater.js +0 -3
  28. package/cjs/sync/polling/updaters/segmentChangesUpdater.js +1 -8
  29. package/cjs/sync/polling/updaters/splitChangesUpdater.js +1 -4
  30. package/cjs/sync/streaming/SSEHandler/NotificationKeeper.js +20 -13
  31. package/cjs/sync/streaming/SSEHandler/index.js +21 -15
  32. package/cjs/sync/streaming/pushManager.js +7 -4
  33. package/cjs/sync/submitters/eventsSubmitter.js +28 -0
  34. package/cjs/sync/submitters/{impressionCountsSyncTask.js → impressionCountsSubmitter.js} +10 -7
  35. package/cjs/sync/submitters/{impressionsSyncTask.js → impressionsSubmitter.js} +8 -8
  36. package/cjs/sync/submitters/{submitterSyncTask.js → submitter.js} +34 -13
  37. package/cjs/sync/submitters/submitterManager.js +12 -10
  38. package/cjs/sync/submitters/telemetrySubmitter.js +128 -0
  39. package/cjs/sync/syncManagerOnline.js +6 -2
  40. package/cjs/trackers/eventTracker.js +5 -1
  41. package/cjs/trackers/impressionsTracker.js +11 -3
  42. package/cjs/trackers/telemetryTracker.js +63 -0
  43. package/cjs/utils/constants/index.js +40 -1
  44. package/cjs/utils/inputValidation/apiKey.js +12 -11
  45. package/cjs/utils/settingsValidation/index.js +20 -6
  46. package/cjs/utils/settingsValidation/url.js +4 -0
  47. package/cjs/utils/timeTracker/index.js +1 -0
  48. package/cjs/utils/timeTracker/timer.js +2 -2
  49. package/esm/consent/sdkUserConsent.js +1 -1
  50. package/esm/listeners/browser.js +3 -2
  51. package/esm/logger/constants.js +1 -0
  52. package/esm/logger/messages/error.js +2 -1
  53. package/esm/logger/messages/info.js +3 -3
  54. package/esm/logger/messages/warn.js +2 -2
  55. package/esm/sdkClient/client.js +18 -4
  56. package/esm/sdkClient/sdkClient.js +4 -1
  57. package/esm/sdkFactory/index.js +16 -19
  58. package/esm/services/splitApi.js +15 -14
  59. package/esm/services/splitHttpClient.js +15 -13
  60. package/esm/storages/AbstractSegmentsCacheSync.js +0 -5
  61. package/esm/storages/KeyBuilderSS.js +12 -19
  62. package/esm/storages/findLatencyIndex.js +11 -6
  63. package/esm/storages/inLocalStorage/MySegmentsCacheInLocal.js +13 -1
  64. package/esm/storages/inLocalStorage/index.js +5 -2
  65. package/esm/storages/inMemory/InMemoryStorage.js +3 -1
  66. package/esm/storages/inMemory/InMemoryStorageCS.js +4 -1
  67. package/esm/storages/inMemory/MySegmentsCacheInMemory.js +6 -0
  68. package/esm/storages/inMemory/SegmentsCacheInMemory.js +6 -0
  69. package/esm/storages/inMemory/TelemetryCacheInMemory.js +161 -0
  70. package/esm/storages/inRedis/TelemetryCacheInRedis.js +26 -0
  71. package/esm/storages/inRedis/index.js +2 -4
  72. package/esm/storages/pluggable/TelemetryCachePluggable.js +24 -0
  73. package/esm/storages/pluggable/index.js +2 -1
  74. package/esm/sync/polling/updaters/mySegmentsUpdater.js +0 -3
  75. package/esm/sync/polling/updaters/segmentChangesUpdater.js +1 -8
  76. package/esm/sync/polling/updaters/splitChangesUpdater.js +1 -4
  77. package/esm/sync/streaming/SSEHandler/NotificationKeeper.js +8 -1
  78. package/esm/sync/streaming/SSEHandler/index.js +21 -15
  79. package/esm/sync/streaming/pushManager.js +7 -4
  80. package/esm/sync/submitters/eventsSubmitter.js +24 -0
  81. package/esm/sync/submitters/{impressionCountsSyncTask.js → impressionCountsSubmitter.js} +8 -5
  82. package/esm/sync/submitters/{impressionsSyncTask.js → impressionsSubmitter.js} +6 -6
  83. package/esm/sync/submitters/submitter.js +60 -0
  84. package/esm/sync/submitters/submitterManager.js +12 -10
  85. package/esm/sync/submitters/telemetrySubmitter.js +122 -0
  86. package/esm/sync/syncManagerOnline.js +6 -2
  87. package/esm/trackers/eventTracker.js +6 -2
  88. package/esm/trackers/impressionsTracker.js +12 -4
  89. package/esm/trackers/telemetryTracker.js +59 -0
  90. package/esm/utils/constants/index.js +38 -0
  91. package/esm/utils/inputValidation/apiKey.js +2 -1
  92. package/esm/utils/settingsValidation/index.js +18 -4
  93. package/esm/utils/settingsValidation/url.js +4 -0
  94. package/esm/utils/timeTracker/index.js +1 -0
  95. package/esm/utils/timeTracker/timer.js +2 -2
  96. package/package.json +1 -1
  97. package/src/consent/sdkUserConsent.ts +1 -1
  98. package/src/listeners/browser.ts +3 -2
  99. package/src/logger/constants.ts +1 -0
  100. package/src/logger/messages/error.ts +2 -1
  101. package/src/logger/messages/info.ts +3 -3
  102. package/src/logger/messages/warn.ts +2 -2
  103. package/src/sdkClient/client.ts +23 -4
  104. package/src/sdkClient/sdkClient.ts +4 -1
  105. package/src/sdkFactory/index.ts +22 -24
  106. package/src/sdkFactory/types.ts +31 -14
  107. package/src/services/splitApi.ts +17 -14
  108. package/src/services/splitHttpClient.ts +15 -14
  109. package/src/services/types.ts +7 -5
  110. package/src/storages/AbstractSegmentsCacheSync.ts +8 -3
  111. package/src/storages/KeyBuilderSS.ts +13 -50
  112. package/src/storages/findLatencyIndex.ts +12 -3
  113. package/src/storages/inLocalStorage/MySegmentsCacheInLocal.ts +13 -1
  114. package/src/storages/inLocalStorage/index.ts +5 -2
  115. package/src/storages/inMemory/InMemoryStorage.ts +3 -1
  116. package/src/storages/inMemory/InMemoryStorageCS.ts +4 -1
  117. package/src/storages/inMemory/MySegmentsCacheInMemory.ts +8 -0
  118. package/src/storages/inMemory/SegmentsCacheInMemory.ts +6 -0
  119. package/src/storages/inMemory/TelemetryCacheInMemory.ts +210 -0
  120. package/src/storages/inRedis/TelemetryCacheInRedis.ts +29 -0
  121. package/src/storages/inRedis/index.ts +2 -4
  122. package/src/storages/pluggable/TelemetryCachePluggable.ts +26 -0
  123. package/src/storages/pluggable/index.ts +2 -1
  124. package/src/storages/types.ts +84 -32
  125. package/src/sync/offline/syncManagerOffline.ts +4 -3
  126. package/src/sync/polling/pollingManagerCS.ts +2 -2
  127. package/src/sync/polling/pollingManagerSS.ts +2 -2
  128. package/src/sync/polling/updaters/mySegmentsUpdater.ts +0 -4
  129. package/src/sync/polling/updaters/segmentChangesUpdater.ts +2 -10
  130. package/src/sync/polling/updaters/splitChangesUpdater.ts +1 -5
  131. package/src/sync/streaming/SSEHandler/NotificationKeeper.ts +11 -1
  132. package/src/sync/streaming/SSEHandler/index.ts +21 -14
  133. package/src/sync/streaming/pushManager.ts +11 -7
  134. package/src/sync/submitters/eventsSubmitter.ts +35 -0
  135. package/src/sync/submitters/{impressionCountsSyncTask.ts → impressionCountsSubmitter.ts} +15 -15
  136. package/src/sync/submitters/{impressionsSyncTask.ts → impressionsSubmitter.ts} +12 -16
  137. package/src/sync/submitters/{submitterSyncTask.ts → submitter.ts} +33 -15
  138. package/src/sync/submitters/submitterManager.ts +14 -11
  139. package/src/sync/submitters/telemetrySubmitter.ts +143 -0
  140. package/src/sync/submitters/types.ts +123 -0
  141. package/src/sync/syncManagerOnline.ts +13 -7
  142. package/src/sync/types.ts +0 -15
  143. package/src/trackers/eventTracker.ts +7 -3
  144. package/src/trackers/impressionsTracker.ts +13 -5
  145. package/src/trackers/telemetryTracker.ts +63 -0
  146. package/src/trackers/types.ts +24 -0
  147. package/src/types.ts +35 -6
  148. package/src/utils/constants/index.ts +45 -0
  149. package/src/utils/inputValidation/apiKey.ts +2 -1
  150. package/src/utils/settingsValidation/index.ts +18 -4
  151. package/src/utils/settingsValidation/url.ts +4 -0
  152. package/src/utils/timeTracker/index.ts +1 -1
  153. package/src/utils/timeTracker/timer.ts +3 -3
  154. package/types/logger/constants.d.ts +1 -0
  155. package/types/sdkFactory/types.d.ts +28 -13
  156. package/types/services/splitApi.d.ts +2 -1
  157. package/types/services/types.d.ts +8 -5
  158. package/types/storages/AbstractSegmentsCacheSync.d.ts +7 -3
  159. package/types/storages/KeyBuilderSS.d.ts +3 -3
  160. package/types/storages/findLatencyIndex.d.ts +7 -1
  161. package/types/storages/inLocalStorage/MySegmentsCacheInLocal.d.ts +2 -0
  162. package/types/storages/inMemory/MySegmentsCacheInMemory.d.ts +2 -0
  163. package/types/storages/inMemory/SegmentsCacheInMemory.d.ts +1 -0
  164. package/types/storages/inMemory/TelemetryCacheInMemory.d.ts +6 -2
  165. package/types/storages/inRedis/TelemetryCacheInRedis.d.ts +6 -8
  166. package/types/storages/pluggable/TelemetryCachePluggable.d.ts +4 -6
  167. package/types/storages/types.d.ts +71 -22
  168. package/types/sync/offline/syncManagerOffline.d.ts +3 -2
  169. package/types/sync/polling/pollingManagerCS.d.ts +2 -2
  170. package/types/sync/polling/pollingManagerSS.d.ts +2 -2
  171. package/types/sync/streaming/SSEHandler/NotificationKeeper.d.ts +2 -1
  172. package/types/sync/streaming/SSEHandler/index.d.ts +2 -1
  173. package/types/sync/streaming/pushManager.d.ts +2 -2
  174. package/types/sync/submitters/eventsSubmitter.d.ts +5 -0
  175. package/types/sync/submitters/impressionCountsSubmitter.d.ts +10 -0
  176. package/types/sync/submitters/impressionsSubmitter.d.ts +11 -0
  177. package/types/sync/submitters/submitter.d.ts +12 -0
  178. package/types/sync/submitters/submitterManager.d.ts +2 -2
  179. package/types/sync/submitters/telemetrySubmitter.d.ts +24 -0
  180. package/types/sync/submitters/telemetrySyncTask.d.ts +0 -27
  181. package/types/sync/submitters/types.d.ts +107 -0
  182. package/types/sync/syncManagerOnline.d.ts +3 -2
  183. package/types/sync/types.d.ts +0 -13
  184. package/types/trackers/eventTracker.d.ts +2 -2
  185. package/types/trackers/impressionsTracker.d.ts +2 -2
  186. package/types/trackers/telemetryTracker.d.ts +3 -0
  187. package/types/trackers/types.d.ts +22 -0
  188. package/types/types.d.ts +33 -4
  189. package/types/utils/constants/index.d.ts +37 -0
  190. package/types/utils/inputValidation/apiKey.d.ts +1 -0
  191. package/types/utils/settingsValidation/index.d.ts +40 -0
  192. package/types/utils/timeTracker/index.d.ts +1 -1
  193. package/types/utils/timeTracker/timer.d.ts +1 -1
  194. package/cjs/storages/inMemory/CountsCacheInMemory.js +0 -38
  195. package/cjs/storages/inMemory/LatenciesCacheInMemory.js +0 -43
  196. package/cjs/storages/inRedis/CountsCacheInRedis.js +0 -16
  197. package/cjs/storages/inRedis/LatenciesCacheInRedis.js +0 -18
  198. package/cjs/sync/submitters/eventsSyncTask.js +0 -44
  199. package/cjs/sync/submitters/metricsSyncTask.js +0 -31
  200. package/esm/storages/inMemory/CountsCacheInMemory.js +0 -35
  201. package/esm/storages/inMemory/LatenciesCacheInMemory.js +0 -40
  202. package/esm/storages/inRedis/CountsCacheInRedis.js +0 -13
  203. package/esm/storages/inRedis/LatenciesCacheInRedis.js +0 -15
  204. package/esm/sync/submitters/eventsSyncTask.js +0 -40
  205. package/esm/sync/submitters/metricsSyncTask.js +0 -26
  206. package/esm/sync/submitters/submitterSyncTask.js +0 -40
  207. package/src/storages/inMemory/CountsCacheInMemory.ts +0 -37
  208. package/src/storages/inMemory/LatenciesCacheInMemory.ts +0 -45
  209. package/src/storages/inRedis/CountsCacheInRedis.ts +0 -20
  210. package/src/storages/inRedis/LatenciesCacheInRedis.ts +0 -23
  211. package/src/sync/submitters/eventsSyncTask.ts +0 -57
  212. package/src/sync/submitters/metricsSyncTask.ts +0 -49
@@ -0,0 +1,3 @@
1
+ import { ITelemetryCacheSync, ITelemetryCacheAsync } from '../storages/types';
2
+ import { ITelemetryTracker } from './types';
3
+ export declare function telemetryTrackerFactory(telemetryCache?: ITelemetryCacheSync | ITelemetryCacheAsync, now?: () => number): ITelemetryTracker;
@@ -1,5 +1,7 @@
1
1
  import { SplitIO, ImpressionDTO } from '../types';
2
+ import { StreamingEventType, Method, OperationType } from '../sync/submitters/types';
2
3
  import { IEventsCacheBase } from '../storages/types';
4
+ import { NetworkError } from '../services/types';
3
5
  /** Events tracker */
4
6
  export interface IEventsHandler {
5
7
  handleEvent(eventData: SplitIO.EventData): any;
@@ -12,3 +14,23 @@ export interface IImpressionsHandler {
12
14
  export interface IImpressionsTracker {
13
15
  track(impressions: ImpressionDTO[], attributes?: SplitIO.Attributes): void;
14
16
  }
17
+ /** Telemetry tracker */
18
+ export declare type AUTH_REJECTION = 80;
19
+ export interface ITelemetryTracker {
20
+ /**
21
+ * Creates a telemetry evaluator tracker, to record Latencies, Exceptions and NonReadyUsage of client operations (getTreatments and track method calls)
22
+ */
23
+ trackEval(method: Method): (label?: string) => void;
24
+ /**
25
+ * Creates a telemetry runtime tracker, to record Latencies and Exceptions of HTTP requests
26
+ */
27
+ trackHttp(method: OperationType): (error?: NetworkError) => void;
28
+ /**
29
+ * Records session length
30
+ */
31
+ sessionLength(): void;
32
+ /**
33
+ * Records streaming event
34
+ */
35
+ streamingEvent(e: StreamingEventType | AUTH_REJECTION, d?: number): void;
36
+ }
package/types/types.d.ts CHANGED
@@ -1,8 +1,9 @@
1
1
  import { ISplitFiltersValidation } from './dtos/types';
2
2
  import { IIntegration, IIntegrationFactoryParams } from './integrations/types';
3
3
  import { ILogger } from './logger/types';
4
+ import { ISdkFactoryContext } from './sdkFactory/types';
4
5
  import { IStorageFactoryParams, IStorageSync, IStorageAsync, IStorageSyncFactory, IStorageAsyncFactory } from './storages/types';
5
- import { ISyncManagerFactoryParams, ISyncManagerCS } from './sync/types';
6
+ import { ISyncManagerCS } from './sync/types';
6
7
  /**
7
8
  * Reduced version of NodeJS.EventEmitter interface with the minimal methods used by the SDK
8
9
  * @see {@link https://nodejs.org/api/events.html}
@@ -73,7 +74,11 @@ export interface ISettings {
73
74
  featuresRefreshRate: number;
74
75
  impressionsRefreshRate: number;
75
76
  impressionsQueueSize: number;
76
- metricsRefreshRate: number;
77
+ /**
78
+ * @deprecated
79
+ */
80
+ metricsRefreshRate?: number;
81
+ telemetryRefreshRate: number;
77
82
  segmentsRefreshRate: number;
78
83
  offlineRefreshRate: number;
79
84
  eventsPushRate: number;
@@ -87,12 +92,16 @@ export interface ISettings {
87
92
  eventsFirstPushWindow: number;
88
93
  };
89
94
  readonly storage: IStorageSyncFactory | IStorageAsyncFactory;
90
- readonly integrations?: Array<(params: IIntegrationFactoryParams) => IIntegration | void>;
95
+ readonly integrations: Array<{
96
+ readonly type: string;
97
+ (params: IIntegrationFactoryParams): IIntegration | void;
98
+ }>;
91
99
  readonly urls: {
92
100
  events: string;
93
101
  sdk: string;
94
102
  auth: string;
95
103
  streaming: string;
104
+ telemetry: string;
96
105
  };
97
106
  readonly debug: boolean | LogLevel | ILogger;
98
107
  readonly version: string;
@@ -267,8 +276,15 @@ interface INodeBasicSettings extends ISharedSettings {
267
276
  * The SDK sends diagnostic metrics to Split servers. This parameters controls this metric flush period in seconds.
268
277
  * @property {number} metricsRefreshRate
269
278
  * @default 120
279
+ * @deprecated This parameter is ignored now.
270
280
  */
271
281
  metricsRefreshRate?: number;
282
+ /**
283
+ * The SDK sends diagnostic metrics to Split servers. This parameters controls this metric flush period in seconds.
284
+ * @property {number} telemetryRefreshRate
285
+ * @default 3600
286
+ */
287
+ telemetryRefreshRate?: number;
272
288
  /**
273
289
  * The SDK polls Split servers for changes to segment definitions. This parameter controls this polling period in seconds.
274
290
  * @property {number} segmentsRefreshRate
@@ -598,7 +614,7 @@ export declare namespace SplitIO {
598
614
  */
599
615
  type LocalhostFactory = {
600
616
  type: 'LocalhostFromObject' | 'LocalhostFromFile';
601
- (params: ISyncManagerFactoryParams): ISyncManagerCS;
617
+ (params: ISdkFactoryContext): ISyncManagerCS;
602
618
  };
603
619
  /**
604
620
  * Impression listener interface. This is the interface that needs to be implemented
@@ -662,6 +678,12 @@ export declare namespace SplitIO {
662
678
  * @default 'https://streaming.split.io'
663
679
  */
664
680
  streaming?: string;
681
+ /**
682
+ * String property to override the base URL where the SDK will post telemetry data.
683
+ * @property {string} telemetry
684
+ * @default 'https://telemetry.split.io'
685
+ */
686
+ telemetry?: string;
665
687
  };
666
688
  /**
667
689
  * SplitFilter type.
@@ -791,8 +813,15 @@ export declare namespace SplitIO {
791
813
  * The SDK sends diagnostic metrics to Split servers. This parameters controls this metric flush period in seconds.
792
814
  * @property {number} metricsRefreshRate
793
815
  * @default 120
816
+ * @deprecated This parameter is ignored now.
794
817
  */
795
818
  metricsRefreshRate?: number;
819
+ /**
820
+ * The SDK sends diagnostic metrics to Split servers. This parameters controls this metric flush period in seconds.
821
+ * @property {number} telemetryRefreshRate
822
+ * @default 3600
823
+ */
824
+ telemetryRefreshRate?: number;
796
825
  /**
797
826
  * The SDK polls Split servers for changes to segment definitions. This parameter controls this polling period in seconds.
798
827
  * @property {number} segmentsRefreshRate
@@ -23,3 +23,40 @@ export declare const STORAGE_PLUGGABLE: StorageType;
23
23
  export declare const CONSENT_GRANTED = "GRANTED";
24
24
  export declare const CONSENT_DECLINED = "DECLINED";
25
25
  export declare const CONSENT_UNKNOWN = "UNKNOWN";
26
+ export declare const QUEUED = 0;
27
+ export declare const DROPPED = 1;
28
+ export declare const DEDUPED = 2;
29
+ export declare const STANDALONE_ENUM = 0;
30
+ export declare const CONSUMER_ENUM = 1;
31
+ export declare const CONSUMER_PARTIAL_ENUM = 2;
32
+ export declare const OPTIMIZED_ENUM = 0;
33
+ export declare const DEBUG_ENUM = 1;
34
+ export declare const SPLITS = "sp";
35
+ export declare const IMPRESSIONS = "im";
36
+ export declare const IMPRESSIONS_COUNT = "ic";
37
+ export declare const EVENTS = "ev";
38
+ export declare const TELEMETRY = "te";
39
+ export declare const TOKEN = "to";
40
+ export declare const SEGMENT = "se";
41
+ export declare const MY_SEGMENT = "ms";
42
+ export declare const TREATMENT = "t";
43
+ export declare const TREATMENTS = "ts";
44
+ export declare const TREATMENT_WITH_CONFIG = "tc";
45
+ export declare const TREATMENTS_WITH_CONFIG = "tcs";
46
+ export declare const TRACK = "tr";
47
+ export declare const CONNECTION_ESTABLISHED = 0;
48
+ export declare const OCCUPANCY_PRI = 10;
49
+ export declare const OCCUPANCY_SEC = 20;
50
+ export declare const STREAMING_STATUS = 30;
51
+ export declare const SSE_CONNECTION_ERROR = 40;
52
+ export declare const TOKEN_REFRESH = 50;
53
+ export declare const ABLY_ERROR = 60;
54
+ export declare const SYNC_MODE_UPDATE = 70;
55
+ export declare const AUTH_REJECTION = 80;
56
+ export declare const STREAMING = 0;
57
+ export declare const POLLING = 1;
58
+ export declare const REQUESTED = 0;
59
+ export declare const NON_REQUESTED = 1;
60
+ export declare const DISABLED = 0;
61
+ export declare const ENABLED = 1;
62
+ export declare const PAUSED = 2;
@@ -1,6 +1,7 @@
1
1
  import { ILogger } from '../../logger/types';
2
2
  /** validates the given api key */
3
3
  export declare function validateApiKey(log: ILogger, maybeApiKey: any): string | false;
4
+ export declare const usedKeysMap: Record<string, number>;
4
5
  /** validates the given api key and also warns if it is in use */
5
6
  export declare function validateAndTrackApiKey(log: ILogger, maybeApiKey: any): string | false;
6
7
  export declare function releaseApiKey(apiKey: string): void;
@@ -1,5 +1,45 @@
1
1
  import { ISettingsValidationParams } from './types';
2
2
  import { ISettings } from '../../types';
3
+ export declare const base: {
4
+ mode: import("../../types").SDKMode;
5
+ core: {
6
+ authorizationKey: undefined;
7
+ key: undefined;
8
+ trafficType: undefined;
9
+ labelsEnabled: boolean;
10
+ IPAddressesEnabled: undefined;
11
+ };
12
+ scheduler: {
13
+ featuresRefreshRate: number;
14
+ segmentsRefreshRate: number;
15
+ telemetryRefreshRate: number;
16
+ impressionsRefreshRate: number;
17
+ offlineRefreshRate: number;
18
+ eventsPushRate: number;
19
+ eventsQueueSize: number;
20
+ impressionsQueueSize: number;
21
+ pushRetryBackoffBase: number;
22
+ };
23
+ urls: {
24
+ sdk: string;
25
+ events: string;
26
+ auth: string;
27
+ streaming: string;
28
+ telemetry: string;
29
+ };
30
+ storage: undefined;
31
+ debug: undefined;
32
+ impressionListener: undefined;
33
+ version: undefined;
34
+ integrations: undefined;
35
+ streamingEnabled: boolean;
36
+ sync: {
37
+ splitFilters: undefined;
38
+ impressionsMode: string;
39
+ localhostMode: undefined;
40
+ };
41
+ log: undefined;
42
+ };
3
43
  /**
4
44
  * Validates the given config and use it to build a settings object.
5
45
  * NOTE: it doesn't validate the Api Key. Call `validateApikey` or `validateAndTrackApiKey` for that after settings validation.
@@ -31,7 +31,7 @@ export declare const TrackerAPI: {
31
31
  * @param {Promise} promise - (optional) The promise we are tracking.
32
32
  * @return {Function | Promise} The stop function for this specific task or the promise received with the callbacks registered.
33
33
  */
34
- start(log: ILogger, task: string, collectors?: Record<string, MetricsCollector> | undefined, promise?: Promise<IResponse> | undefined, now?: (() => number) | undefined): Promise<IResponse> | (() => number);
34
+ start(log: ILogger, task: string, collectors?: Record<string, MetricsCollector> | undefined, promise?: Promise<IResponse> | undefined, now?: () => number): Promise<IResponse> | (() => number);
35
35
  /**
36
36
  * Setup the collector for a task that reports metrics.
37
37
  *
@@ -1 +1 @@
1
- export declare function timer(now?: () => number): () => number;
1
+ export declare function timer(now: () => number): () => number;
@@ -1,38 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CountsCacheInMemory = void 0;
4
- var CountsCacheInMemory = /** @class */ (function () {
5
- function CountsCacheInMemory() {
6
- this.counters = {};
7
- }
8
- /**
9
- * Add counts.
10
- */
11
- CountsCacheInMemory.prototype.track = function (metricName) {
12
- if (this.counters[metricName] === undefined)
13
- this.counters[metricName] = 1;
14
- else
15
- this.counters[metricName]++;
16
- return true;
17
- };
18
- /**
19
- * Clear the collector
20
- */
21
- CountsCacheInMemory.prototype.clear = function () {
22
- this.counters = {};
23
- };
24
- /**
25
- * Get the collected data, used as payload for posting.
26
- */
27
- CountsCacheInMemory.prototype.state = function () {
28
- return this.counters;
29
- };
30
- /**
31
- * Check if the cache is empty.
32
- */
33
- CountsCacheInMemory.prototype.isEmpty = function () {
34
- return Object.keys(this.counters).length === 0;
35
- };
36
- return CountsCacheInMemory;
37
- }());
38
- exports.CountsCacheInMemory = CountsCacheInMemory;
@@ -1,43 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.LatenciesCacheInMemory = void 0;
4
- var findLatencyIndex_1 = require("../findLatencyIndex");
5
- var LatenciesCacheInMemory = /** @class */ (function () {
6
- function LatenciesCacheInMemory() {
7
- this.counters = {};
8
- }
9
- /**
10
- * Add latencies.
11
- */
12
- LatenciesCacheInMemory.prototype.track = function (metricName, latency) {
13
- // Initialize if needed
14
- if (this.counters[metricName] === undefined) {
15
- this.counters[metricName] = [
16
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
17
- ];
18
- }
19
- // +1 based on the latency number
20
- this.counters[metricName][(0, findLatencyIndex_1.findLatencyIndex)(latency)]++;
21
- return true;
22
- };
23
- /**
24
- * Clear the collector
25
- */
26
- LatenciesCacheInMemory.prototype.clear = function () {
27
- this.counters = {};
28
- };
29
- /**
30
- * Get the collected data, used as payload for posting.
31
- */
32
- LatenciesCacheInMemory.prototype.state = function () {
33
- return this.counters;
34
- };
35
- /**
36
- * Check if the cache is empty.
37
- */
38
- LatenciesCacheInMemory.prototype.isEmpty = function () {
39
- return Object.keys(this.counters).length === 0;
40
- };
41
- return LatenciesCacheInMemory;
42
- }());
43
- exports.LatenciesCacheInMemory = LatenciesCacheInMemory;
@@ -1,16 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CountsCacheInRedis = void 0;
4
- var CountsCacheInRedis = /** @class */ (function () {
5
- function CountsCacheInRedis(keys, redis) {
6
- this.keys = keys;
7
- this.redis = redis;
8
- }
9
- CountsCacheInRedis.prototype.track = function (metricName) {
10
- return this.redis.incr(this.keys.buildCountKey(metricName)).catch(function () {
11
- // noop, for telemetry metrics there's no need to throw.
12
- }).then(function () { return true; });
13
- };
14
- return CountsCacheInRedis;
15
- }());
16
- exports.CountsCacheInRedis = CountsCacheInRedis;
@@ -1,18 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.LatenciesCacheInRedis = void 0;
4
- var findLatencyIndex_1 = require("../findLatencyIndex");
5
- var LatenciesCacheInRedis = /** @class */ (function () {
6
- function LatenciesCacheInRedis(keys, redis) {
7
- this.keys = keys;
8
- this.redis = redis;
9
- }
10
- LatenciesCacheInRedis.prototype.track = function (metricName, latency) {
11
- var bucketNumber = (0, findLatencyIndex_1.findLatencyIndex)(latency);
12
- return this.redis.incr(this.keys.buildLatencyKey(metricName, bucketNumber)).catch(function () {
13
- // noop, for telemetry metrics there's no need to throw.
14
- }).then(function () { return true; });
15
- };
16
- return LatenciesCacheInRedis;
17
- }());
18
- exports.LatenciesCacheInRedis = LatenciesCacheInRedis;
@@ -1,44 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.eventsSyncTaskFactory = void 0;
4
- var submitterSyncTask_1 = require("./submitterSyncTask");
5
- var constants_1 = require("../../logger/constants");
6
- var DATA_NAME = 'events';
7
- /**
8
- * Sync task that periodically posts tracked events
9
- */
10
- function eventsSyncTaskFactory(log, postEventsBulk, eventsCache, eventsPushRate, eventsFirstPushWindow, latencyTracker) {
11
- // don't retry events.
12
- var syncTask = (0, submitterSyncTask_1.submitterSyncTaskFactory)(log, postEventsBulk, eventsCache, eventsPushRate, DATA_NAME, latencyTracker);
13
- // Set a timer for the first push window of events.
14
- // Not implemented in the base submitter or sync task, since this feature is only used by the events submitter.
15
- if (eventsFirstPushWindow > 0) {
16
- var running_1 = false;
17
- var stopEventPublisherTimeout_1;
18
- var originalStart_1 = syncTask.start;
19
- syncTask.start = function () {
20
- running_1 = true;
21
- stopEventPublisherTimeout_1 = setTimeout(originalStart_1, eventsFirstPushWindow);
22
- };
23
- var originalStop_1 = syncTask.stop;
24
- syncTask.stop = function () {
25
- running_1 = false;
26
- clearTimeout(stopEventPublisherTimeout_1);
27
- originalStop_1();
28
- };
29
- syncTask.isRunning = function () {
30
- return running_1;
31
- };
32
- }
33
- // register events submitter to be executed when events cache is full
34
- eventsCache.setOnFullQueueCb(function () {
35
- if (syncTask.isRunning()) {
36
- log.info(constants_1.SUBMITTERS_PUSH_FULL_QUEUE, [DATA_NAME]);
37
- syncTask.execute();
38
- }
39
- // If submitter is stopped (e.g., user consent declined or unknown, or app state offline), we don't send the data.
40
- // Data will be sent when submitter is resumed.
41
- });
42
- return syncTask;
43
- }
44
- exports.eventsSyncTaskFactory = eventsSyncTaskFactory;
@@ -1,31 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.latenciesSyncTaskFactory = exports.countsSyncTaskFactory = void 0;
4
- var lang_1 = require("../../utils/lang");
5
- var submitterSyncTask_1 = require("./submitterSyncTask");
6
- // extract POST payload object from cache
7
- function fromCache(propertyName) {
8
- return function (data) {
9
- var result = [];
10
- (0, lang_1.forOwn)(data, function (value, key) {
11
- var _a;
12
- result.push((_a = { name: key }, _a[propertyName] = value, _a));
13
- });
14
- return result;
15
- };
16
- }
17
- /**
18
- * Sync task that periodically posts telemetry counts
19
- */
20
- function countsSyncTaskFactory(log, postMetricsCounters, countsCache, metricsRefreshRate, latencyTracker) {
21
- return (0, submitterSyncTask_1.submitterSyncTaskFactory)(log, postMetricsCounters, countsCache, metricsRefreshRate, 'count metrics', latencyTracker, fromCache('delta'));
22
- }
23
- exports.countsSyncTaskFactory = countsSyncTaskFactory;
24
- /**
25
- * Sync task that periodically posts telemetry latencies
26
- */
27
- function latenciesSyncTaskFactory(log, postMetricsLatencies, latenciesCache, metricsRefreshRate, latencyTracker) {
28
- // don't retry metrics.
29
- return (0, submitterSyncTask_1.submitterSyncTaskFactory)(log, postMetricsLatencies, latenciesCache, metricsRefreshRate, 'latency metrics', latencyTracker, fromCache('latencies'), 0, true);
30
- }
31
- exports.latenciesSyncTaskFactory = latenciesSyncTaskFactory;
@@ -1,35 +0,0 @@
1
- var CountsCacheInMemory = /** @class */ (function () {
2
- function CountsCacheInMemory() {
3
- this.counters = {};
4
- }
5
- /**
6
- * Add counts.
7
- */
8
- CountsCacheInMemory.prototype.track = function (metricName) {
9
- if (this.counters[metricName] === undefined)
10
- this.counters[metricName] = 1;
11
- else
12
- this.counters[metricName]++;
13
- return true;
14
- };
15
- /**
16
- * Clear the collector
17
- */
18
- CountsCacheInMemory.prototype.clear = function () {
19
- this.counters = {};
20
- };
21
- /**
22
- * Get the collected data, used as payload for posting.
23
- */
24
- CountsCacheInMemory.prototype.state = function () {
25
- return this.counters;
26
- };
27
- /**
28
- * Check if the cache is empty.
29
- */
30
- CountsCacheInMemory.prototype.isEmpty = function () {
31
- return Object.keys(this.counters).length === 0;
32
- };
33
- return CountsCacheInMemory;
34
- }());
35
- export { CountsCacheInMemory };
@@ -1,40 +0,0 @@
1
- import { findLatencyIndex } from '../findLatencyIndex';
2
- var LatenciesCacheInMemory = /** @class */ (function () {
3
- function LatenciesCacheInMemory() {
4
- this.counters = {};
5
- }
6
- /**
7
- * Add latencies.
8
- */
9
- LatenciesCacheInMemory.prototype.track = function (metricName, latency) {
10
- // Initialize if needed
11
- if (this.counters[metricName] === undefined) {
12
- this.counters[metricName] = [
13
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
14
- ];
15
- }
16
- // +1 based on the latency number
17
- this.counters[metricName][findLatencyIndex(latency)]++;
18
- return true;
19
- };
20
- /**
21
- * Clear the collector
22
- */
23
- LatenciesCacheInMemory.prototype.clear = function () {
24
- this.counters = {};
25
- };
26
- /**
27
- * Get the collected data, used as payload for posting.
28
- */
29
- LatenciesCacheInMemory.prototype.state = function () {
30
- return this.counters;
31
- };
32
- /**
33
- * Check if the cache is empty.
34
- */
35
- LatenciesCacheInMemory.prototype.isEmpty = function () {
36
- return Object.keys(this.counters).length === 0;
37
- };
38
- return LatenciesCacheInMemory;
39
- }());
40
- export { LatenciesCacheInMemory };
@@ -1,13 +0,0 @@
1
- var CountsCacheInRedis = /** @class */ (function () {
2
- function CountsCacheInRedis(keys, redis) {
3
- this.keys = keys;
4
- this.redis = redis;
5
- }
6
- CountsCacheInRedis.prototype.track = function (metricName) {
7
- return this.redis.incr(this.keys.buildCountKey(metricName)).catch(function () {
8
- // noop, for telemetry metrics there's no need to throw.
9
- }).then(function () { return true; });
10
- };
11
- return CountsCacheInRedis;
12
- }());
13
- export { CountsCacheInRedis };
@@ -1,15 +0,0 @@
1
- import { findLatencyIndex } from '../findLatencyIndex';
2
- var LatenciesCacheInRedis = /** @class */ (function () {
3
- function LatenciesCacheInRedis(keys, redis) {
4
- this.keys = keys;
5
- this.redis = redis;
6
- }
7
- LatenciesCacheInRedis.prototype.track = function (metricName, latency) {
8
- var bucketNumber = findLatencyIndex(latency);
9
- return this.redis.incr(this.keys.buildLatencyKey(metricName, bucketNumber)).catch(function () {
10
- // noop, for telemetry metrics there's no need to throw.
11
- }).then(function () { return true; });
12
- };
13
- return LatenciesCacheInRedis;
14
- }());
15
- export { LatenciesCacheInRedis };
@@ -1,40 +0,0 @@
1
- import { submitterSyncTaskFactory } from './submitterSyncTask';
2
- import { SUBMITTERS_PUSH_FULL_QUEUE } from '../../logger/constants';
3
- var DATA_NAME = 'events';
4
- /**
5
- * Sync task that periodically posts tracked events
6
- */
7
- export function eventsSyncTaskFactory(log, postEventsBulk, eventsCache, eventsPushRate, eventsFirstPushWindow, latencyTracker) {
8
- // don't retry events.
9
- var syncTask = submitterSyncTaskFactory(log, postEventsBulk, eventsCache, eventsPushRate, DATA_NAME, latencyTracker);
10
- // Set a timer for the first push window of events.
11
- // Not implemented in the base submitter or sync task, since this feature is only used by the events submitter.
12
- if (eventsFirstPushWindow > 0) {
13
- var running_1 = false;
14
- var stopEventPublisherTimeout_1;
15
- var originalStart_1 = syncTask.start;
16
- syncTask.start = function () {
17
- running_1 = true;
18
- stopEventPublisherTimeout_1 = setTimeout(originalStart_1, eventsFirstPushWindow);
19
- };
20
- var originalStop_1 = syncTask.stop;
21
- syncTask.stop = function () {
22
- running_1 = false;
23
- clearTimeout(stopEventPublisherTimeout_1);
24
- originalStop_1();
25
- };
26
- syncTask.isRunning = function () {
27
- return running_1;
28
- };
29
- }
30
- // register events submitter to be executed when events cache is full
31
- eventsCache.setOnFullQueueCb(function () {
32
- if (syncTask.isRunning()) {
33
- log.info(SUBMITTERS_PUSH_FULL_QUEUE, [DATA_NAME]);
34
- syncTask.execute();
35
- }
36
- // If submitter is stopped (e.g., user consent declined or unknown, or app state offline), we don't send the data.
37
- // Data will be sent when submitter is resumed.
38
- });
39
- return syncTask;
40
- }
@@ -1,26 +0,0 @@
1
- import { forOwn } from '../../utils/lang';
2
- import { submitterSyncTaskFactory } from './submitterSyncTask';
3
- // extract POST payload object from cache
4
- function fromCache(propertyName) {
5
- return function (data) {
6
- var result = [];
7
- forOwn(data, function (value, key) {
8
- var _a;
9
- result.push((_a = { name: key }, _a[propertyName] = value, _a));
10
- });
11
- return result;
12
- };
13
- }
14
- /**
15
- * Sync task that periodically posts telemetry counts
16
- */
17
- export function countsSyncTaskFactory(log, postMetricsCounters, countsCache, metricsRefreshRate, latencyTracker) {
18
- return submitterSyncTaskFactory(log, postMetricsCounters, countsCache, metricsRefreshRate, 'count metrics', latencyTracker, fromCache('delta'));
19
- }
20
- /**
21
- * Sync task that periodically posts telemetry latencies
22
- */
23
- export function latenciesSyncTaskFactory(log, postMetricsLatencies, latenciesCache, metricsRefreshRate, latencyTracker) {
24
- // don't retry metrics.
25
- return submitterSyncTaskFactory(log, postMetricsLatencies, latenciesCache, metricsRefreshRate, 'latency metrics', latencyTracker, fromCache('latencies'), 0, true);
26
- }
@@ -1,40 +0,0 @@
1
- import { syncTaskFactory } from '../syncTask';
2
- import { SUBMITTERS_PUSH, SUBMITTERS_PUSH_FAILS, SUBMITTERS_PUSH_RETRY } from '../../logger/constants';
3
- /**
4
- * Base function to create submitter sync tasks, such as ImpressionsSyncTask and EventsSyncTask
5
- */
6
- export function submitterSyncTaskFactory(log, postClient, sourceCache, postRate, dataName, latencyTracker, fromCacheToPayload, maxRetries, debugLogs) {
7
- if (maxRetries === void 0) { maxRetries = 0; }
8
- var retries = 0;
9
- function postData() {
10
- if (sourceCache.isEmpty())
11
- return Promise.resolve();
12
- var data = sourceCache.state();
13
- var dataCount = typeof data.length === 'number' ? data.length : '';
14
- log[debugLogs ? 'debug' : 'info'](SUBMITTERS_PUSH, [dataCount, dataName]);
15
- var latencyTrackerStop = latencyTracker && latencyTracker.start();
16
- var jsonPayload = JSON.stringify(fromCacheToPayload ? fromCacheToPayload(data) : data);
17
- if (!maxRetries)
18
- sourceCache.clear();
19
- var postPromise = postClient(jsonPayload).then(function () {
20
- retries = 0;
21
- sourceCache.clear(); // we clear the queue if request successes.
22
- }).catch(function (err) {
23
- if (!maxRetries) {
24
- log.warn(SUBMITTERS_PUSH_FAILS, [dataCount, dataName, err]);
25
- }
26
- else if (retries === maxRetries) {
27
- retries = 0;
28
- sourceCache.clear(); // we clear the queue if request fails after retries.
29
- log.warn(SUBMITTERS_PUSH_FAILS, [dataCount, dataName, err]);
30
- }
31
- else {
32
- retries++;
33
- log.warn(SUBMITTERS_PUSH_RETRY, [dataCount, dataName, err]);
34
- }
35
- });
36
- // if latencyTracker provided, attach stop callback to postEventsPromise
37
- return latencyTrackerStop ? postPromise.then(latencyTrackerStop).catch(latencyTrackerStop) : postPromise;
38
- }
39
- return syncTaskFactory(log, postData, postRate, dataName + ' submitter');
40
- }