@splitsoftware/splitio-commons 1.3.1 → 1.3.2-rc.2

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 (219) hide show
  1. package/cjs/consent/sdkUserConsent.js +1 -1
  2. package/cjs/listeners/browser.js +5 -4
  3. package/cjs/logger/constants.js +2 -1
  4. package/cjs/logger/messages/error.js +2 -1
  5. package/cjs/logger/messages/info.js +3 -3
  6. package/cjs/logger/messages/warn.js +2 -2
  7. package/cjs/sdkClient/client.js +17 -3
  8. package/cjs/sdkClient/sdkClient.js +4 -1
  9. package/cjs/sdkFactory/index.js +16 -19
  10. package/cjs/services/splitApi.js +15 -14
  11. package/cjs/services/splitHttpClient.js +4 -1
  12. package/cjs/storages/AbstractSegmentsCacheSync.js +0 -5
  13. package/cjs/storages/KeyBuilderSS.js +12 -19
  14. package/cjs/storages/findLatencyIndex.js +11 -6
  15. package/cjs/storages/inLocalStorage/MySegmentsCacheInLocal.js +13 -1
  16. package/cjs/storages/inLocalStorage/index.js +4 -1
  17. package/cjs/storages/inMemory/InMemoryStorage.js +2 -0
  18. package/cjs/storages/inMemory/InMemoryStorageCS.js +3 -0
  19. package/cjs/storages/inMemory/MySegmentsCacheInMemory.js +6 -0
  20. package/cjs/storages/inMemory/SegmentsCacheInMemory.js +6 -0
  21. package/cjs/storages/inMemory/TelemetryCacheInMemory.js +165 -0
  22. package/cjs/storages/inRedis/TelemetryCacheInRedis.js +29 -0
  23. package/cjs/storages/inRedis/index.js +2 -4
  24. package/cjs/storages/pluggable/TelemetryCachePluggable.js +27 -0
  25. package/cjs/storages/pluggable/index.js +2 -1
  26. package/cjs/sync/polling/pollingManagerCS.js +1 -1
  27. package/cjs/sync/polling/syncTasks/splitsSyncTask.js +2 -2
  28. package/cjs/sync/polling/updaters/mySegmentsUpdater.js +0 -3
  29. package/cjs/sync/polling/updaters/segmentChangesUpdater.js +1 -8
  30. package/cjs/sync/polling/updaters/splitChangesUpdater.js +3 -6
  31. package/cjs/sync/streaming/SSEHandler/NotificationKeeper.js +20 -13
  32. package/cjs/sync/streaming/SSEHandler/index.js +21 -15
  33. package/cjs/sync/streaming/pushManager.js +7 -4
  34. package/cjs/sync/submitters/eventsSubmitter.js +28 -0
  35. package/cjs/sync/submitters/{impressionCountsSyncTask.js → impressionCountsSubmitter.js} +10 -7
  36. package/cjs/sync/submitters/{impressionsSyncTask.js → impressionsSubmitter.js} +8 -8
  37. package/cjs/sync/submitters/submitter.js +66 -0
  38. package/cjs/sync/submitters/submitterManager.js +12 -10
  39. package/cjs/sync/submitters/telemetrySubmitter.js +128 -0
  40. package/cjs/sync/syncManagerOnline.js +6 -2
  41. package/cjs/trackers/eventTracker.js +5 -1
  42. package/cjs/trackers/impressionsTracker.js +9 -1
  43. package/cjs/trackers/telemetryTracker.js +65 -0
  44. package/cjs/utils/constants/index.js +40 -1
  45. package/cjs/utils/inputValidation/apiKey.js +12 -11
  46. package/cjs/utils/settingsValidation/index.js +35 -11
  47. package/cjs/utils/settingsValidation/url.js +4 -0
  48. package/cjs/utils/timeTracker/index.js +1 -0
  49. package/cjs/utils/timeTracker/timer.js +2 -2
  50. package/esm/consent/sdkUserConsent.js +1 -1
  51. package/esm/listeners/browser.js +3 -2
  52. package/esm/logger/constants.js +1 -0
  53. package/esm/logger/messages/error.js +2 -1
  54. package/esm/logger/messages/info.js +3 -3
  55. package/esm/logger/messages/warn.js +2 -2
  56. package/esm/sdkClient/client.js +18 -4
  57. package/esm/sdkClient/sdkClient.js +4 -1
  58. package/esm/sdkFactory/index.js +16 -19
  59. package/esm/services/splitApi.js +15 -14
  60. package/esm/services/splitHttpClient.js +4 -1
  61. package/esm/storages/AbstractSegmentsCacheSync.js +0 -5
  62. package/esm/storages/KeyBuilderSS.js +12 -19
  63. package/esm/storages/findLatencyIndex.js +11 -6
  64. package/esm/storages/inLocalStorage/MySegmentsCacheInLocal.js +13 -1
  65. package/esm/storages/inLocalStorage/index.js +5 -2
  66. package/esm/storages/inMemory/InMemoryStorage.js +3 -1
  67. package/esm/storages/inMemory/InMemoryStorageCS.js +4 -1
  68. package/esm/storages/inMemory/MySegmentsCacheInMemory.js +6 -0
  69. package/esm/storages/inMemory/SegmentsCacheInMemory.js +6 -0
  70. package/esm/storages/inMemory/TelemetryCacheInMemory.js +161 -0
  71. package/esm/storages/inRedis/TelemetryCacheInRedis.js +26 -0
  72. package/esm/storages/inRedis/index.js +2 -4
  73. package/esm/storages/pluggable/TelemetryCachePluggable.js +24 -0
  74. package/esm/storages/pluggable/index.js +2 -1
  75. package/esm/sync/polling/pollingManagerCS.js +1 -1
  76. package/esm/sync/polling/syncTasks/splitsSyncTask.js +2 -2
  77. package/esm/sync/polling/updaters/mySegmentsUpdater.js +0 -3
  78. package/esm/sync/polling/updaters/segmentChangesUpdater.js +1 -8
  79. package/esm/sync/polling/updaters/splitChangesUpdater.js +3 -6
  80. package/esm/sync/streaming/SSEHandler/NotificationKeeper.js +8 -1
  81. package/esm/sync/streaming/SSEHandler/index.js +21 -15
  82. package/esm/sync/streaming/pushManager.js +7 -4
  83. package/esm/sync/submitters/eventsSubmitter.js +24 -0
  84. package/esm/sync/submitters/{impressionCountsSyncTask.js → impressionCountsSubmitter.js} +8 -5
  85. package/esm/sync/submitters/{impressionsSyncTask.js → impressionsSubmitter.js} +6 -6
  86. package/esm/sync/submitters/submitter.js +61 -0
  87. package/esm/sync/submitters/submitterManager.js +12 -10
  88. package/esm/sync/submitters/telemetrySubmitter.js +122 -0
  89. package/esm/sync/syncManagerOnline.js +6 -2
  90. package/esm/trackers/eventTracker.js +6 -2
  91. package/esm/trackers/impressionsTracker.js +10 -2
  92. package/esm/trackers/telemetryTracker.js +61 -0
  93. package/esm/utils/constants/index.js +38 -0
  94. package/esm/utils/inputValidation/apiKey.js +2 -1
  95. package/esm/utils/settingsValidation/index.js +34 -10
  96. package/esm/utils/settingsValidation/url.js +4 -0
  97. package/esm/utils/timeTracker/index.js +1 -0
  98. package/esm/utils/timeTracker/timer.js +2 -2
  99. package/package.json +1 -1
  100. package/src/consent/sdkUserConsent.ts +1 -1
  101. package/src/listeners/browser.ts +3 -2
  102. package/src/logger/constants.ts +1 -0
  103. package/src/logger/messages/error.ts +2 -1
  104. package/src/logger/messages/info.ts +3 -3
  105. package/src/logger/messages/warn.ts +2 -2
  106. package/src/sdkClient/client.ts +23 -4
  107. package/src/sdkClient/sdkClient.ts +4 -1
  108. package/src/sdkFactory/index.ts +22 -24
  109. package/src/sdkFactory/types.ts +32 -15
  110. package/src/services/splitApi.ts +17 -14
  111. package/src/services/splitHttpClient.ts +6 -3
  112. package/src/services/types.ts +7 -5
  113. package/src/storages/AbstractSegmentsCacheSync.ts +8 -3
  114. package/src/storages/KeyBuilderSS.ts +13 -50
  115. package/src/storages/findLatencyIndex.ts +12 -3
  116. package/src/storages/inLocalStorage/MySegmentsCacheInLocal.ts +13 -1
  117. package/src/storages/inLocalStorage/index.ts +5 -2
  118. package/src/storages/inMemory/InMemoryStorage.ts +3 -1
  119. package/src/storages/inMemory/InMemoryStorageCS.ts +4 -1
  120. package/src/storages/inMemory/MySegmentsCacheInMemory.ts +8 -0
  121. package/src/storages/inMemory/SegmentsCacheInMemory.ts +6 -0
  122. package/src/storages/inMemory/TelemetryCacheInMemory.ts +210 -0
  123. package/src/storages/inRedis/TelemetryCacheInRedis.ts +29 -0
  124. package/src/storages/inRedis/index.ts +2 -4
  125. package/src/storages/pluggable/TelemetryCachePluggable.ts +26 -0
  126. package/src/storages/pluggable/index.ts +2 -1
  127. package/src/storages/types.ts +84 -32
  128. package/src/sync/offline/syncManagerOffline.ts +4 -3
  129. package/src/sync/polling/pollingManagerCS.ts +3 -3
  130. package/src/sync/polling/pollingManagerSS.ts +2 -2
  131. package/src/sync/polling/syncTasks/splitsSyncTask.ts +2 -0
  132. package/src/sync/polling/updaters/mySegmentsUpdater.ts +0 -4
  133. package/src/sync/polling/updaters/segmentChangesUpdater.ts +2 -10
  134. package/src/sync/polling/updaters/splitChangesUpdater.ts +3 -6
  135. package/src/sync/streaming/SSEHandler/NotificationKeeper.ts +11 -1
  136. package/src/sync/streaming/SSEHandler/index.ts +21 -14
  137. package/src/sync/streaming/pushManager.ts +11 -7
  138. package/src/sync/submitters/eventsSubmitter.ts +35 -0
  139. package/src/sync/submitters/{impressionCountsSyncTask.ts → impressionCountsSubmitter.ts} +15 -15
  140. package/src/sync/submitters/{impressionsSyncTask.ts → impressionsSubmitter.ts} +12 -16
  141. package/src/sync/submitters/{submitterSyncTask.ts → submitter.ts} +34 -16
  142. package/src/sync/submitters/submitterManager.ts +14 -11
  143. package/src/sync/submitters/telemetrySubmitter.ts +143 -0
  144. package/src/sync/submitters/types.ts +123 -0
  145. package/src/sync/syncManagerOnline.ts +13 -7
  146. package/src/sync/types.ts +0 -15
  147. package/src/trackers/eventTracker.ts +7 -3
  148. package/src/trackers/impressionsTracker.ts +11 -3
  149. package/src/trackers/telemetryTracker.ts +63 -0
  150. package/src/trackers/types.ts +24 -0
  151. package/src/types.ts +35 -6
  152. package/src/utils/constants/index.ts +45 -0
  153. package/src/utils/inputValidation/apiKey.ts +2 -1
  154. package/src/utils/settingsValidation/index.ts +35 -11
  155. package/src/utils/settingsValidation/url.ts +4 -0
  156. package/src/utils/timeTracker/index.ts +1 -1
  157. package/src/utils/timeTracker/timer.ts +3 -3
  158. package/types/logger/constants.d.ts +1 -0
  159. package/types/sdkFactory/types.d.ts +29 -14
  160. package/types/services/splitApi.d.ts +2 -1
  161. package/types/services/types.d.ts +8 -5
  162. package/types/storages/AbstractSegmentsCacheSync.d.ts +7 -3
  163. package/types/storages/KeyBuilderSS.d.ts +3 -3
  164. package/types/storages/findLatencyIndex.d.ts +7 -1
  165. package/types/storages/inLocalStorage/MySegmentsCacheInLocal.d.ts +2 -0
  166. package/types/storages/inMemory/MySegmentsCacheInMemory.d.ts +2 -0
  167. package/types/storages/inMemory/SegmentsCacheInMemory.d.ts +1 -0
  168. package/types/storages/inMemory/TelemetryCacheInMemory.d.ts +6 -2
  169. package/types/storages/inRedis/TelemetryCacheInRedis.d.ts +3 -3
  170. package/types/storages/pluggable/TelemetryCachePluggable.d.ts +2 -2
  171. package/types/storages/types.d.ts +71 -22
  172. package/types/sync/offline/syncManagerOffline.d.ts +3 -2
  173. package/types/sync/polling/pollingManagerCS.d.ts +2 -2
  174. package/types/sync/polling/pollingManagerSS.d.ts +2 -2
  175. package/types/sync/polling/syncTasks/splitsSyncTask.d.ts +1 -1
  176. package/types/sync/polling/updaters/splitChangesUpdater.d.ts +1 -1
  177. package/types/sync/streaming/SSEHandler/NotificationKeeper.d.ts +2 -1
  178. package/types/sync/streaming/SSEHandler/index.d.ts +2 -1
  179. package/types/sync/streaming/pushManager.d.ts +2 -2
  180. package/types/sync/submitters/eventsSubmitter.d.ts +5 -0
  181. package/types/sync/submitters/impressionCountsSubmitter.d.ts +10 -0
  182. package/types/sync/submitters/impressionsSubmitter.d.ts +11 -0
  183. package/types/sync/submitters/submitter.d.ts +12 -0
  184. package/types/sync/submitters/submitterManager.d.ts +2 -2
  185. package/types/sync/submitters/telemetrySubmitter.d.ts +24 -0
  186. package/types/sync/submitters/telemetrySyncTask.d.ts +0 -27
  187. package/types/sync/submitters/types.d.ts +107 -0
  188. package/types/sync/syncManagerOnline.d.ts +3 -2
  189. package/types/sync/types.d.ts +0 -13
  190. package/types/trackers/eventTracker.d.ts +2 -2
  191. package/types/trackers/impressionsTracker.d.ts +2 -2
  192. package/types/trackers/telemetryTracker.d.ts +2 -3
  193. package/types/trackers/types.d.ts +22 -0
  194. package/types/types.d.ts +33 -4
  195. package/types/utils/constants/index.d.ts +37 -0
  196. package/types/utils/inputValidation/apiKey.d.ts +1 -0
  197. package/types/utils/settingsValidation/index.d.ts +40 -0
  198. package/types/utils/timeTracker/index.d.ts +1 -1
  199. package/types/utils/timeTracker/timer.d.ts +1 -1
  200. package/cjs/storages/inMemory/CountsCacheInMemory.js +0 -38
  201. package/cjs/storages/inMemory/LatenciesCacheInMemory.js +0 -43
  202. package/cjs/storages/inRedis/CountsCacheInRedis.js +0 -16
  203. package/cjs/storages/inRedis/LatenciesCacheInRedis.js +0 -18
  204. package/cjs/sync/submitters/eventsSyncTask.js +0 -44
  205. package/cjs/sync/submitters/metricsSyncTask.js +0 -31
  206. package/cjs/sync/submitters/submitterSyncTask.js +0 -44
  207. package/esm/storages/inMemory/CountsCacheInMemory.js +0 -35
  208. package/esm/storages/inMemory/LatenciesCacheInMemory.js +0 -40
  209. package/esm/storages/inRedis/CountsCacheInRedis.js +0 -13
  210. package/esm/storages/inRedis/LatenciesCacheInRedis.js +0 -15
  211. package/esm/sync/submitters/eventsSyncTask.js +0 -40
  212. package/esm/sync/submitters/metricsSyncTask.js +0 -26
  213. package/esm/sync/submitters/submitterSyncTask.js +0 -40
  214. package/src/storages/inMemory/CountsCacheInMemory.ts +0 -37
  215. package/src/storages/inMemory/LatenciesCacheInMemory.ts +0 -45
  216. package/src/storages/inRedis/CountsCacheInRedis.ts +0 -20
  217. package/src/storages/inRedis/LatenciesCacheInRedis.ts +0 -23
  218. package/src/sync/submitters/eventsSyncTask.ts +0 -57
  219. package/src/sync/submitters/metricsSyncTask.ts +0 -49
@@ -58,3 +58,110 @@ export declare type StoredEventWithMetadata = {
58
58
  /** Stored event */
59
59
  e: SplitIO.EventData;
60
60
  };
61
+ /**
62
+ * Telemetry usage stats
63
+ */
64
+ export declare type QUEUED = 0;
65
+ export declare type DROPPED = 1;
66
+ export declare type DEDUPED = 2;
67
+ export declare type ImpressionDataType = QUEUED | DROPPED | DEDUPED;
68
+ export declare type EventDataType = QUEUED | DROPPED;
69
+ export declare type SPLITS = 'sp';
70
+ export declare type IMPRESSIONS = 'im';
71
+ export declare type IMPRESSIONS_COUNT = 'ic';
72
+ export declare type EVENTS = 'ev';
73
+ export declare type TELEMETRY = 'te';
74
+ export declare type TOKEN = 'to';
75
+ export declare type SEGMENT = 'se';
76
+ export declare type MY_SEGMENT = 'ms';
77
+ export declare type OperationType = SPLITS | IMPRESSIONS | IMPRESSIONS_COUNT | EVENTS | TELEMETRY | TOKEN | SEGMENT | MY_SEGMENT;
78
+ export declare type LastSync = Record<OperationType, number | undefined>;
79
+ export declare type HttpErrors = Record<OperationType, {
80
+ [statusCode: string]: number;
81
+ }>;
82
+ export declare type HttpLatencies = Record<OperationType, Array<number>>;
83
+ export declare type TREATMENT = 't';
84
+ export declare type TREATMENTS = 'ts';
85
+ export declare type TREATMENT_WITH_CONFIG = 'tc';
86
+ export declare type TREATMENTS_WITH_CONFIG = 'tcs';
87
+ export declare type TRACK = 'tr';
88
+ export declare type Method = TREATMENT | TREATMENTS | TREATMENT_WITH_CONFIG | TREATMENTS_WITH_CONFIG | TRACK;
89
+ export declare type MethodLatencies = Record<Method, Array<number>>;
90
+ export declare type MethodExceptions = Record<Method, number>;
91
+ export declare type CONNECTION_ESTABLISHED = 0;
92
+ export declare type OCCUPANCY_PRI = 10;
93
+ export declare type OCCUPANCY_SEC = 20;
94
+ export declare type STREAMING_STATUS = 30;
95
+ export declare type SSE_CONNECTION_ERROR = 40;
96
+ export declare type TOKEN_REFRESH = 50;
97
+ export declare type ABLY_ERROR = 60;
98
+ export declare type SYNC_MODE_UPDATE = 70;
99
+ export declare type StreamingEventType = CONNECTION_ESTABLISHED | OCCUPANCY_PRI | OCCUPANCY_SEC | STREAMING_STATUS | SSE_CONNECTION_ERROR | TOKEN_REFRESH | ABLY_ERROR | SYNC_MODE_UPDATE;
100
+ export declare type StreamingEvent = {
101
+ e: StreamingEventType;
102
+ d?: number;
103
+ t: number;
104
+ };
105
+ export declare type TelemetryUsageStatsPayload = {
106
+ lS: LastSync;
107
+ mL: MethodLatencies;
108
+ mE: MethodExceptions;
109
+ hE: HttpErrors;
110
+ hL: HttpLatencies;
111
+ tR: number;
112
+ aR: number;
113
+ iQ: number;
114
+ iDe: number;
115
+ iDr: number;
116
+ spC: number;
117
+ seC: number;
118
+ skC: number;
119
+ sL?: number;
120
+ eQ: number;
121
+ eD: number;
122
+ sE: Array<StreamingEvent>;
123
+ t?: Array<string>;
124
+ };
125
+ /**
126
+ * Telemetry config stats
127
+ */
128
+ export declare type STANDALONE_ENUM = 0;
129
+ export declare type CONSUMER_ENUM = 1;
130
+ export declare type CONSUMER_PARTIAL_ENUM = 2;
131
+ export declare type OperationMode = STANDALONE_ENUM | CONSUMER_ENUM | CONSUMER_PARTIAL_ENUM;
132
+ export declare type OPTIMIZED_ENUM = 0;
133
+ export declare type DEBUG_ENUM = 1;
134
+ export declare type ImpressionsMode = OPTIMIZED_ENUM | DEBUG_ENUM;
135
+ export declare type RefreshRates = {
136
+ sp: number;
137
+ se: number;
138
+ im: number;
139
+ ev: number;
140
+ te: number;
141
+ };
142
+ export declare type UrlOverrides = {
143
+ s: boolean;
144
+ e: boolean;
145
+ a: boolean;
146
+ st: boolean;
147
+ t: boolean;
148
+ };
149
+ export declare type TelemetryConfigStatsPayload = {
150
+ oM?: OperationMode;
151
+ st: 'memory' | 'redis' | 'pluggable' | 'localstorage';
152
+ sE: boolean;
153
+ rR: RefreshRates;
154
+ uO: UrlOverrides;
155
+ iQ: number;
156
+ eQ: number;
157
+ iM: ImpressionsMode;
158
+ iL: boolean;
159
+ hP: boolean;
160
+ aF: number;
161
+ rF: number;
162
+ tR: number;
163
+ tC?: number;
164
+ nR: number;
165
+ t?: Array<string>;
166
+ i?: Array<string>;
167
+ };
@@ -1,6 +1,7 @@
1
- import { ISyncManagerCS, ISyncManagerFactoryParams } from './types';
1
+ import { ISyncManagerCS } from './types';
2
2
  import { IPushManager } from './streaming/types';
3
3
  import { IPollingManager } from './polling/types';
4
+ import { ISdkFactoryContextSync } from '../sdkFactory/types';
4
5
  /**
5
6
  * Online SyncManager factory.
6
7
  * Can be used for server-side API, and client-side API with or without multiple clients.
@@ -9,4 +10,4 @@ import { IPollingManager } from './polling/types';
9
10
  * `pollingManagerSSFactory` or `pollingManagerCSFactory` respectively.
10
11
  * @param pushManagerFactory optional to build a SyncManager with or without streaming support
11
12
  */
12
- export declare function syncManagerOnlineFactory(pollingManagerFactory?: (params: ISyncManagerFactoryParams) => IPollingManager, pushManagerFactory?: (params: ISyncManagerFactoryParams, pollingManager: IPollingManager) => IPushManager | undefined): (params: ISyncManagerFactoryParams) => ISyncManagerCS;
13
+ export declare function syncManagerOnlineFactory(pollingManagerFactory?: (params: ISdkFactoryContextSync) => IPollingManager, pushManagerFactory?: (params: ISdkFactoryContextSync, pollingManager: IPollingManager) => IPushManager | undefined): (params: ISdkFactoryContextSync) => ISyncManagerCS;
@@ -1,8 +1,5 @@
1
1
  import { IReadinessManager } from '../readiness/types';
2
- import { IPlatform } from '../sdkFactory/types';
3
- import { ISplitApi } from '../services/types';
4
2
  import { IStorageSync } from '../storages/types';
5
- import { ISettings } from '../types';
6
3
  import { IPollingManager } from './polling/types';
7
4
  import { IPushManager } from './streaming/types';
8
5
  export interface ITask<Input extends any[] = []> {
@@ -33,9 +30,6 @@ export interface ISyncTask<Input extends any[] = [], Output = any> extends ITask
33
30
  */
34
31
  isExecuting(): boolean;
35
32
  }
36
- export interface ITimeTracker {
37
- start(): () => void;
38
- }
39
33
  /** SyncManager */
40
34
  export interface ISyncManager extends ITask {
41
35
  flush(): Promise<any>;
@@ -46,10 +40,3 @@ export interface ISyncManager extends ITask {
46
40
  export interface ISyncManagerCS extends ISyncManager {
47
41
  shared(matchingKey: string, readinessManager: IReadinessManager, storage: IStorageSync): ISyncManager | undefined;
48
42
  }
49
- export interface ISyncManagerFactoryParams {
50
- settings: ISettings;
51
- readiness: IReadinessManager;
52
- storage: IStorageSync;
53
- splitApi: ISplitApi;
54
- platform: IPlatform;
55
- }
@@ -1,4 +1,4 @@
1
- import { IEventsCacheBase } from '../storages/types';
1
+ import { IEventsCacheBase, ITelemetryCacheAsync, ITelemetryCacheSync } from '../storages/types';
2
2
  import { IEventsHandler, IEventTracker } from './types';
3
3
  import { ISettings } from '../types';
4
4
  /**
@@ -7,4 +7,4 @@ import { ISettings } from '../types';
7
7
  * @param eventsCache cache to save events
8
8
  * @param integrationsManager optional event handler used for integrations
9
9
  */
10
- export declare function eventTrackerFactory(settings: ISettings, eventsCache: IEventsCacheBase, integrationsManager?: IEventsHandler): IEventTracker;
10
+ export declare function eventTrackerFactory(settings: ISettings, eventsCache: IEventsCacheBase, integrationsManager?: IEventsHandler, telemetryCache?: ITelemetryCacheSync | ITelemetryCacheAsync): IEventTracker;
@@ -1,4 +1,4 @@
1
- import { IImpressionCountsCacheSync, IImpressionsCacheBase } from '../storages/types';
1
+ import { IImpressionCountsCacheSync, IImpressionsCacheBase, ITelemetryCacheSync, ITelemetryCacheAsync } from '../storages/types';
2
2
  import { IImpressionsHandler, IImpressionsTracker } from './types';
3
3
  import { ISettings } from '../types';
4
4
  import { IImpressionObserver } from './impressionObserver/types';
@@ -12,4 +12,4 @@ import { IImpressionObserver } from './impressionObserver/types';
12
12
  * @param observer optional impression observer. If provided, previous time (pt property) is included in impression instances
13
13
  * @param countsCache optional cache to save impressions count. If provided, impressions will be deduped (OPTIMIZED mode)
14
14
  */
15
- export declare function impressionsTrackerFactory(settings: ISettings, impressionsCache: IImpressionsCacheBase, integrationsManager?: IImpressionsHandler, observer?: IImpressionObserver, countsCache?: IImpressionCountsCacheSync): IImpressionsTracker;
15
+ export declare function impressionsTrackerFactory(settings: ISettings, impressionsCache: IImpressionsCacheBase, integrationsManager?: IImpressionsHandler, observer?: IImpressionObserver, countsCache?: IImpressionCountsCacheSync, telemetryCache?: ITelemetryCacheSync | ITelemetryCacheAsync): IImpressionsTracker;
@@ -1,4 +1,3 @@
1
- import { TelemetryCacheAsync, TelemetryCacheSync } from '../storages/types';
2
- import { ISettings } from '../types';
1
+ import { ITelemetryCacheSync, ITelemetryCacheAsync } from '../storages/types';
3
2
  import { ITelemetryTracker } from './types';
4
- export declare function telemetryTrackerFactory(settings: ISettings, telemetryCache?: TelemetryCacheAsync | TelemetryCacheSync, now?: () => number): ITelemetryTracker;
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/api'
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;