@splitsoftware/splitio-commons 1.16.1-rc.11 → 1.16.1-rc.12
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.
- package/cjs/logger/constants.js +2 -2
- package/cjs/logger/messages/warn.js +1 -1
- package/cjs/services/splitApi.js +2 -2
- package/cjs/storages/inMemory/TelemetryCacheInMemory.js +1 -1
- package/cjs/sync/polling/fetchers/mySegmentsFetcher.js +2 -2
- package/cjs/sync/polling/updaters/mySegmentsUpdater.js +6 -5
- package/cjs/sync/streaming/SSEHandler/index.js +2 -2
- package/cjs/sync/streaming/UpdateWorkers/MySegmentsUpdateWorker.js +104 -63
- package/cjs/sync/streaming/constants.js +3 -3
- package/cjs/sync/streaming/pushManager.js +17 -20
- package/esm/logger/constants.js +1 -1
- package/esm/logger/messages/warn.js +1 -1
- package/esm/services/splitApi.js +2 -2
- package/esm/storages/inMemory/TelemetryCacheInMemory.js +1 -1
- package/esm/sync/polling/fetchers/mySegmentsFetcher.js +2 -2
- package/esm/sync/polling/updaters/mySegmentsUpdater.js +7 -6
- package/esm/sync/streaming/SSEHandler/index.js +3 -3
- package/esm/sync/streaming/UpdateWorkers/MySegmentsUpdateWorker.js +104 -63
- package/esm/sync/streaming/constants.js +2 -2
- package/esm/sync/streaming/pushManager.js +19 -22
- package/package.json +1 -1
- package/src/logger/constants.ts +1 -1
- package/src/logger/messages/warn.ts +1 -1
- package/src/services/splitApi.ts +2 -2
- package/src/services/types.ts +1 -1
- package/src/storages/inMemory/TelemetryCacheInMemory.ts +1 -1
- package/src/storages/types.ts +1 -1
- package/src/sync/polling/fetchers/mySegmentsFetcher.ts +2 -1
- package/src/sync/polling/fetchers/types.ts +1 -0
- package/src/sync/polling/types.ts +3 -3
- package/src/sync/polling/updaters/mySegmentsUpdater.ts +8 -7
- package/src/sync/streaming/SSEHandler/index.ts +3 -3
- package/src/sync/streaming/SSEHandler/types.ts +3 -3
- package/src/sync/streaming/UpdateWorkers/MySegmentsUpdateWorker.ts +112 -64
- package/src/sync/streaming/constants.ts +2 -2
- package/src/sync/streaming/pushManager.ts +19 -25
- package/src/sync/streaming/types.ts +5 -5
- package/src/sync/submitters/types.ts +1 -1
- package/types/logger/constants.d.ts +1 -1
- package/types/services/types.d.ts +1 -1
- package/types/storages/types.d.ts +1 -1
- package/types/sync/polling/fetchers/types.d.ts +1 -1
- package/types/sync/polling/types.d.ts +3 -3
- package/types/sync/polling/updaters/mySegmentsUpdater.d.ts +1 -1
- package/types/sync/streaming/SSEHandler/types.d.ts +3 -3
- package/types/sync/streaming/UpdateWorkers/MySegmentsUpdateWorker.d.ts +3 -1
- package/types/sync/streaming/constants.d.ts +2 -2
- package/types/sync/streaming/types.d.ts +4 -4
- package/types/sync/submitters/types.d.ts +1 -1
|
@@ -1,77 +1,118 @@
|
|
|
1
1
|
import { Backoff } from '../../../utils/Backoff';
|
|
2
2
|
import { MEMBERSHIPS } from '../../../utils/constants';
|
|
3
|
+
import { FETCH_BACKOFF_MAX_RETRIES } from './constants';
|
|
4
|
+
import { MEMBERSHIPS_LS_UPDATE, MEMBERSHIPS_MS_UPDATE } from '../constants';
|
|
3
5
|
/**
|
|
4
6
|
* MySegmentsUpdateWorker factory
|
|
5
7
|
*/
|
|
6
|
-
export function MySegmentsUpdateWorker(mySegmentsSyncTask, telemetryTracker) {
|
|
7
|
-
var
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
if (
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
8
|
+
export function MySegmentsUpdateWorker(log, storage, mySegmentsSyncTask, telemetryTracker) {
|
|
9
|
+
var _a;
|
|
10
|
+
function createUpdateWorker(mySegmentsCache) {
|
|
11
|
+
var maxChangeNumber = 0; // keeps the maximum changeNumber among queued events
|
|
12
|
+
var currentChangeNumber = -1;
|
|
13
|
+
var handleNewEvent = false;
|
|
14
|
+
var isHandlingEvent;
|
|
15
|
+
var cdnBypass;
|
|
16
|
+
var _segmentsData; // keeps the segmentsData (if included in notification payload) from the queued event with maximum changeNumber
|
|
17
|
+
var _delay;
|
|
18
|
+
var _delayTimeoutID;
|
|
19
|
+
var backoff = new Backoff(__handleMySegmentsUpdateCall);
|
|
20
|
+
function __handleMySegmentsUpdateCall() {
|
|
21
|
+
isHandlingEvent = true;
|
|
22
|
+
if (maxChangeNumber > Math.max(currentChangeNumber, mySegmentsCache.getChangeNumber())) {
|
|
23
|
+
handleNewEvent = false;
|
|
24
|
+
var currentMaxChangeNumber_1 = maxChangeNumber;
|
|
25
|
+
// fetch mySegments revalidating data if cached
|
|
26
|
+
var syncTask = _delay ?
|
|
27
|
+
new Promise(function (res) {
|
|
28
|
+
_delayTimeoutID = setTimeout(function () {
|
|
29
|
+
_delay = undefined;
|
|
30
|
+
mySegmentsSyncTask.execute(_segmentsData, true, cdnBypass ? maxChangeNumber : undefined).then(res);
|
|
31
|
+
}, _delay);
|
|
32
|
+
}) :
|
|
33
|
+
mySegmentsSyncTask.execute(_segmentsData, true, cdnBypass ? maxChangeNumber : undefined);
|
|
34
|
+
syncTask.then(function (result) {
|
|
35
|
+
if (!isHandlingEvent)
|
|
36
|
+
return; // halt if `stop` has been called
|
|
37
|
+
if (result !== false) { // Unlike `Splits|SegmentsUpdateWorker`, `mySegmentsCache.getChangeNumber` can be -1, since `/memberships` change number is optional
|
|
38
|
+
var storageChangeNumber = mySegmentsCache.getChangeNumber();
|
|
39
|
+
currentChangeNumber = storageChangeNumber > -1 ?
|
|
40
|
+
storageChangeNumber :
|
|
41
|
+
Math.max(currentChangeNumber, currentMaxChangeNumber_1); // use `currentMaxChangeNumber`, in case that `maxChangeNumber` was updated during fetch.
|
|
42
|
+
}
|
|
43
|
+
if (handleNewEvent) {
|
|
44
|
+
__handleMySegmentsUpdateCall();
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
if (_segmentsData)
|
|
48
|
+
telemetryTracker.trackUpdatesFromSSE(MEMBERSHIPS);
|
|
49
|
+
var attempts = backoff.attempts + 1;
|
|
50
|
+
if (maxChangeNumber <= currentChangeNumber) {
|
|
51
|
+
log.debug("Refresh completed" + (cdnBypass ? ' bypassing the CDN' : '') + " in " + attempts + " attempts.");
|
|
52
|
+
isHandlingEvent = false;
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
if (attempts < FETCH_BACKOFF_MAX_RETRIES) {
|
|
56
|
+
backoff.scheduleCall();
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
if (cdnBypass) {
|
|
60
|
+
log.debug("No changes fetched after " + attempts + " attempts with CDN bypassed.");
|
|
61
|
+
isHandlingEvent = false;
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
backoff.reset();
|
|
65
|
+
cdnBypass = true;
|
|
66
|
+
__handleMySegmentsUpdateCall();
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
isHandlingEvent = false;
|
|
73
|
+
}
|
|
47
74
|
}
|
|
75
|
+
return {
|
|
76
|
+
/**
|
|
77
|
+
* Invoked by NotificationProcessor on MY_(LARGE)_SEGMENTS_UPDATE notifications
|
|
78
|
+
*
|
|
79
|
+
* @param changeNumber change number of the notification
|
|
80
|
+
* @param segmentsData data for KeyList or SegmentRemoval instant updates
|
|
81
|
+
* @param delay optional time to wait for BoundedFetchRequest or BoundedFetchRequest updates
|
|
82
|
+
*/
|
|
83
|
+
put: function (mySegmentsData, payload, delay) {
|
|
84
|
+
var type = mySegmentsData.type, cn = mySegmentsData.cn;
|
|
85
|
+
// Ignore event if it is outdated or if there is a pending fetch request (_delay is set)
|
|
86
|
+
if (cn <= Math.max(currentChangeNumber, mySegmentsCache.getChangeNumber()) || cn <= maxChangeNumber || _delay)
|
|
87
|
+
return;
|
|
88
|
+
maxChangeNumber = cn;
|
|
89
|
+
handleNewEvent = true;
|
|
90
|
+
cdnBypass = false;
|
|
91
|
+
_segmentsData = payload && { type: type, cn: cn, added: payload.added, removed: payload.removed };
|
|
92
|
+
_delay = delay;
|
|
93
|
+
if (backoff.timeoutID || !isHandlingEvent)
|
|
94
|
+
__handleMySegmentsUpdateCall();
|
|
95
|
+
backoff.reset();
|
|
96
|
+
},
|
|
97
|
+
stop: function () {
|
|
98
|
+
clearTimeout(_delayTimeoutID);
|
|
99
|
+
_delay = undefined;
|
|
100
|
+
isHandlingEvent = false;
|
|
101
|
+
backoff.reset();
|
|
102
|
+
}
|
|
103
|
+
};
|
|
48
104
|
}
|
|
105
|
+
var updateWorkers = (_a = {},
|
|
106
|
+
_a[MEMBERSHIPS_MS_UPDATE] = createUpdateWorker(storage.segments),
|
|
107
|
+
_a[MEMBERSHIPS_LS_UPDATE] = createUpdateWorker(storage.largeSegments),
|
|
108
|
+
_a);
|
|
49
109
|
return {
|
|
50
|
-
/**
|
|
51
|
-
* Invoked by NotificationProcessor on MY_(LARGE)_SEGMENTS_UPDATE notifications
|
|
52
|
-
*
|
|
53
|
-
* @param changeNumber change number of the notification
|
|
54
|
-
* @param segmentsData data for KeyList or SegmentRemoval instant updates
|
|
55
|
-
* @param delay optional time to wait for BoundedFetchRequest or BoundedFetchRequest updates
|
|
56
|
-
*/
|
|
57
110
|
put: function (mySegmentsData, payload, delay) {
|
|
58
|
-
|
|
59
|
-
// Ignore event if it is outdated or if there is a pending fetch request (_delay is set)
|
|
60
|
-
if (cn <= currentChangeNumber || cn <= maxChangeNumber || _delay)
|
|
61
|
-
return;
|
|
62
|
-
maxChangeNumber = cn;
|
|
63
|
-
handleNewEvent = true;
|
|
64
|
-
_segmentsData = payload && { type: type, cn: cn, added: payload.added, removed: payload.removed };
|
|
65
|
-
_delay = delay;
|
|
66
|
-
if (backoff.timeoutID || !isHandlingEvent)
|
|
67
|
-
__handleMySegmentsUpdateCall();
|
|
68
|
-
backoff.reset();
|
|
111
|
+
updateWorkers[mySegmentsData.type].put(mySegmentsData, payload, delay);
|
|
69
112
|
},
|
|
70
113
|
stop: function () {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
isHandlingEvent = false;
|
|
74
|
-
backoff.reset();
|
|
114
|
+
updateWorkers[MEMBERSHIPS_MS_UPDATE].stop();
|
|
115
|
+
updateWorkers[MEMBERSHIPS_LS_UPDATE].stop();
|
|
75
116
|
}
|
|
76
117
|
};
|
|
77
118
|
}
|
|
@@ -22,8 +22,8 @@ export var PUSH_SUBSYSTEM_UP = 'PUSH_SUBSYSTEM_UP';
|
|
|
22
22
|
*/
|
|
23
23
|
export var PUSH_SUBSYSTEM_DOWN = 'PUSH_SUBSYSTEM_DOWN';
|
|
24
24
|
// Update-type push notifications, handled by NotificationProcessor
|
|
25
|
-
export var
|
|
26
|
-
export var
|
|
25
|
+
export var MEMBERSHIPS_MS_UPDATE = 'MEMBERSHIPS_MS_UPDATE';
|
|
26
|
+
export var MEMBERSHIPS_LS_UPDATE = 'MEMBERSHIPS_LS_UPDATE';
|
|
27
27
|
export var SEGMENT_UPDATE = 'SEGMENT_UPDATE';
|
|
28
28
|
export var SPLIT_KILL = 'SPLIT_KILL';
|
|
29
29
|
export var SPLIT_UPDATE = 'SPLIT_UPDATE';
|
|
@@ -8,8 +8,8 @@ import { authenticateFactory, hashUserKey } from './AuthClient';
|
|
|
8
8
|
import { forOwn } from '../../utils/lang';
|
|
9
9
|
import { SSEClient } from './SSEClient';
|
|
10
10
|
import { getMatching } from '../../utils/key';
|
|
11
|
-
import {
|
|
12
|
-
import { STREAMING_FALLBACK, STREAMING_REFRESH_TOKEN, STREAMING_CONNECTING, STREAMING_DISABLED, ERROR_STREAMING_AUTH, STREAMING_DISCONNECTING, STREAMING_RECONNECT,
|
|
11
|
+
import { MEMBERSHIPS_MS_UPDATE, MEMBERSHIPS_LS_UPDATE, PUSH_NONRETRYABLE_ERROR, PUSH_SUBSYSTEM_DOWN, SECONDS_BEFORE_EXPIRATION, SEGMENT_UPDATE, SPLIT_KILL, SPLIT_UPDATE, PUSH_RETRYABLE_ERROR, PUSH_SUBSYSTEM_UP, ControlType } from './constants';
|
|
12
|
+
import { STREAMING_FALLBACK, STREAMING_REFRESH_TOKEN, STREAMING_CONNECTING, STREAMING_DISABLED, ERROR_STREAMING_AUTH, STREAMING_DISCONNECTING, STREAMING_RECONNECT, STREAMING_PARSING_MEMBERSHIPS_UPDATE, STREAMING_PARSING_SPLIT_UPDATE } from '../../logger/constants';
|
|
13
13
|
import { UpdateStrategy } from './SSEHandler/types';
|
|
14
14
|
import { getDelay, isInBitmap, parseBitmap, parseFFUpdatePayload, parseKeyList } from './parseUtils';
|
|
15
15
|
import { _Set } from '../../utils/lang/sets';
|
|
@@ -140,9 +140,8 @@ export function pushManagerFactory(params, pollingManager) {
|
|
|
140
140
|
splitsUpdateWorker.stop();
|
|
141
141
|
if (userKey)
|
|
142
142
|
forOwn(clients, function (_a) {
|
|
143
|
-
var worker = _a.worker
|
|
144
|
-
worker.stop();
|
|
145
|
-
workerLarge.stop();
|
|
143
|
+
var worker = _a.worker;
|
|
144
|
+
return worker.stop();
|
|
146
145
|
});
|
|
147
146
|
else
|
|
148
147
|
segmentsUpdateWorker.stop();
|
|
@@ -197,7 +196,6 @@ export function pushManagerFactory(params, pollingManager) {
|
|
|
197
196
|
splitsUpdateWorker.put(parsedData);
|
|
198
197
|
});
|
|
199
198
|
function handleMySegmentsUpdate(parsedData) {
|
|
200
|
-
var isLS = parsedData.type === MEMBERSHIP_LS_UPDATE;
|
|
201
199
|
switch (parsedData.u) {
|
|
202
200
|
case UpdateStrategy.BoundedFetchRequest: {
|
|
203
201
|
var bitmap_1;
|
|
@@ -205,13 +203,13 @@ export function pushManagerFactory(params, pollingManager) {
|
|
|
205
203
|
bitmap_1 = parseBitmap(parsedData.d, parsedData.c);
|
|
206
204
|
}
|
|
207
205
|
catch (e) {
|
|
208
|
-
log.warn(
|
|
206
|
+
log.warn(STREAMING_PARSING_MEMBERSHIPS_UPDATE, ['BoundedFetchRequest', e]);
|
|
209
207
|
break;
|
|
210
208
|
}
|
|
211
209
|
forOwn(clients, function (_a, matchingKey) {
|
|
212
|
-
var hash64 = _a.hash64, worker = _a.worker
|
|
210
|
+
var hash64 = _a.hash64, worker = _a.worker;
|
|
213
211
|
if (isInBitmap(bitmap_1, hash64.hex)) {
|
|
214
|
-
|
|
212
|
+
worker.put(parsedData, undefined, getDelay(parsedData, matchingKey));
|
|
215
213
|
}
|
|
216
214
|
});
|
|
217
215
|
return;
|
|
@@ -224,18 +222,18 @@ export function pushManagerFactory(params, pollingManager) {
|
|
|
224
222
|
removed_1 = new _Set(keyList.r);
|
|
225
223
|
}
|
|
226
224
|
catch (e) {
|
|
227
|
-
log.warn(
|
|
225
|
+
log.warn(STREAMING_PARSING_MEMBERSHIPS_UPDATE, ['KeyList', e]);
|
|
228
226
|
break;
|
|
229
227
|
}
|
|
230
228
|
if (!parsedData.n || !parsedData.n.length) {
|
|
231
|
-
log.warn(
|
|
229
|
+
log.warn(STREAMING_PARSING_MEMBERSHIPS_UPDATE, ['KeyList', 'No segment name was provided']);
|
|
232
230
|
break;
|
|
233
231
|
}
|
|
234
232
|
forOwn(clients, function (_a) {
|
|
235
|
-
var hash64 = _a.hash64, worker = _a.worker
|
|
233
|
+
var hash64 = _a.hash64, worker = _a.worker;
|
|
236
234
|
var add = added_1.has(hash64.dec) ? true : removed_1.has(hash64.dec) ? false : undefined;
|
|
237
235
|
if (add !== undefined) {
|
|
238
|
-
|
|
236
|
+
worker.put(parsedData, {
|
|
239
237
|
added: add ? [parsedData.n[0]] : [],
|
|
240
238
|
removed: add ? [] : [parsedData.n[0]]
|
|
241
239
|
});
|
|
@@ -245,12 +243,12 @@ export function pushManagerFactory(params, pollingManager) {
|
|
|
245
243
|
}
|
|
246
244
|
case UpdateStrategy.SegmentRemoval:
|
|
247
245
|
if (!parsedData.n || !parsedData.n.length) {
|
|
248
|
-
log.warn(
|
|
246
|
+
log.warn(STREAMING_PARSING_MEMBERSHIPS_UPDATE, ['SegmentRemoval', 'No segment name was provided']);
|
|
249
247
|
break;
|
|
250
248
|
}
|
|
251
249
|
forOwn(clients, function (_a) {
|
|
252
|
-
var worker = _a.worker
|
|
253
|
-
|
|
250
|
+
var worker = _a.worker;
|
|
251
|
+
worker.put(parsedData, {
|
|
254
252
|
added: [],
|
|
255
253
|
removed: parsedData.n
|
|
256
254
|
});
|
|
@@ -259,13 +257,13 @@ export function pushManagerFactory(params, pollingManager) {
|
|
|
259
257
|
}
|
|
260
258
|
// `UpdateStrategy.UnboundedFetchRequest` and fallbacks of other cases
|
|
261
259
|
forOwn(clients, function (_a, matchingKey) {
|
|
262
|
-
var worker = _a.worker
|
|
263
|
-
|
|
260
|
+
var worker = _a.worker;
|
|
261
|
+
worker.put(parsedData, undefined, getDelay(parsedData, matchingKey));
|
|
264
262
|
});
|
|
265
263
|
}
|
|
266
264
|
if (userKey) {
|
|
267
|
-
pushEmitter.on(
|
|
268
|
-
pushEmitter.on(
|
|
265
|
+
pushEmitter.on(MEMBERSHIPS_MS_UPDATE, handleMySegmentsUpdate);
|
|
266
|
+
pushEmitter.on(MEMBERSHIPS_LS_UPDATE, handleMySegmentsUpdate);
|
|
269
267
|
}
|
|
270
268
|
else {
|
|
271
269
|
pushEmitter.on(SEGMENT_UPDATE, segmentsUpdateWorker.put);
|
|
@@ -303,8 +301,7 @@ export function pushManagerFactory(params, pollingManager) {
|
|
|
303
301
|
userKeyHashes[hash] = userKey;
|
|
304
302
|
clients[userKey] = {
|
|
305
303
|
hash64: hash64(userKey),
|
|
306
|
-
worker: MySegmentsUpdateWorker(mySegmentsSyncTask, telemetryTracker)
|
|
307
|
-
workerLarge: MySegmentsUpdateWorker(mySegmentsSyncTask, telemetryTracker)
|
|
304
|
+
worker: MySegmentsUpdateWorker(log, storage, mySegmentsSyncTask, telemetryTracker)
|
|
308
305
|
};
|
|
309
306
|
connectForNewClient = true; // we must reconnect on start, to listen the channel for the new user key
|
|
310
307
|
// Reconnects in case of a new client.
|
package/package.json
CHANGED
package/src/logger/constants.ts
CHANGED
|
@@ -79,7 +79,7 @@ export const WARN_SPLITS_FILTER_IGNORED = 219;
|
|
|
79
79
|
export const WARN_SPLITS_FILTER_INVALID = 220;
|
|
80
80
|
export const WARN_SPLITS_FILTER_EMPTY = 221;
|
|
81
81
|
export const WARN_SDK_KEY = 222;
|
|
82
|
-
export const
|
|
82
|
+
export const STREAMING_PARSING_MEMBERSHIPS_UPDATE = 223;
|
|
83
83
|
export const STREAMING_PARSING_SPLIT_UPDATE = 224;
|
|
84
84
|
export const WARN_INVALID_FLAGSET = 225;
|
|
85
85
|
export const WARN_LOWERCASE_FLAGSET = 226;
|
|
@@ -32,7 +32,7 @@ export const codesWarn: [number, string][] = codesError.concat([
|
|
|
32
32
|
[c.WARN_SPLITS_FILTER_EMPTY, c.LOG_PREFIX_SETTINGS + ': feature flag filter configuration must be a non-empty array of filter objects.'],
|
|
33
33
|
[c.WARN_SDK_KEY, c.LOG_PREFIX_SETTINGS + ': You already have %s. We recommend keeping only one instance of the factory at all times (Singleton pattern) and reusing it throughout your application'],
|
|
34
34
|
|
|
35
|
-
[c.
|
|
35
|
+
[c.STREAMING_PARSING_MEMBERSHIPS_UPDATE, c.LOG_PREFIX_SYNC_STREAMING + 'Fetching Memberships due to an error processing %s notification: %s'],
|
|
36
36
|
[c.STREAMING_PARSING_SPLIT_UPDATE, c.LOG_PREFIX_SYNC_STREAMING + 'Fetching SplitChanges due to an error processing SPLIT_UPDATE notification: %s'],
|
|
37
37
|
[c.WARN_INVALID_FLAGSET, '%s: you passed %s, flag set must adhere to the regular expressions %s. This means a flag set must start with a letter or number, be in lowercase, alphanumeric and have a max length of 50 characters. %s was discarded.'],
|
|
38
38
|
[c.WARN_LOWERCASE_FLAGSET, '%s: flag set %s should be all lowercase - converting string to lowercase.'],
|
package/src/services/splitApi.ts
CHANGED
|
@@ -67,14 +67,14 @@ export function splitApiFactory(
|
|
|
67
67
|
return splitHttpClient(url, noCache ? noCacheHeaderOptions : undefined, telemetryTracker.trackHttp(SEGMENT));
|
|
68
68
|
},
|
|
69
69
|
|
|
70
|
-
fetchMemberships(userMatchingKey: string, noCache?: boolean) {
|
|
70
|
+
fetchMemberships(userMatchingKey: string, noCache?: boolean, till?: number) {
|
|
71
71
|
/**
|
|
72
72
|
* URI encoding of user keys in order to:
|
|
73
73
|
* - avoid 400 responses (due to URI malformed). E.g.: '/api/memberships/%'
|
|
74
74
|
* - avoid 404 responses. E.g.: '/api/memberships/foo/bar'
|
|
75
75
|
* - match user keys with special characters. E.g.: 'foo%bar', 'foo/bar'
|
|
76
76
|
*/
|
|
77
|
-
const url = `${urls.sdk}/memberships/${encodeURIComponent(userMatchingKey)}`;
|
|
77
|
+
const url = `${urls.sdk}/memberships/${encodeURIComponent(userMatchingKey)}${till ? '?till=' + till : ''}`;
|
|
78
78
|
return splitHttpClient(url, noCache ? noCacheHeaderOptions : undefined, telemetryTracker.trackHttp(MEMBERSHIPS));
|
|
79
79
|
},
|
|
80
80
|
|
package/src/services/types.ts
CHANGED
|
@@ -39,7 +39,7 @@ export type IFetchSplitChanges = (since: number, noCache?: boolean, till?: numbe
|
|
|
39
39
|
|
|
40
40
|
export type IFetchSegmentChanges = (since: number, segmentName: string, noCache?: boolean, till?: number) => Promise<IResponse>
|
|
41
41
|
|
|
42
|
-
export type IFetchMemberships = (userMatchingKey: string, noCache?: boolean) => Promise<IResponse>
|
|
42
|
+
export type IFetchMemberships = (userMatchingKey: string, noCache?: boolean, till?: number) => Promise<IResponse>
|
|
43
43
|
|
|
44
44
|
export type IPostEventsBulk = (body: string, headers?: Record<string, string>) => Promise<IResponse>
|
|
45
45
|
|
|
@@ -51,7 +51,7 @@ export class TelemetryCacheInMemory implements ITelemetryCacheSync {
|
|
|
51
51
|
spC: this.splits && this.splits.getSplitNames().length,
|
|
52
52
|
seC: this.segments && this.segments.getRegisteredSegments().length,
|
|
53
53
|
skC: this.segments && this.segments.getKeysCount(),
|
|
54
|
-
|
|
54
|
+
lsC: this.largeSegments && this.largeSegments.getRegisteredSegments().length,
|
|
55
55
|
lskC: this.largeSegments && this.largeSegments.getKeysCount(),
|
|
56
56
|
sL: this.getSessionLength(),
|
|
57
57
|
eQ: this.getEventStats(QUEUED),
|
package/src/storages/types.ts
CHANGED
|
@@ -270,7 +270,7 @@ export interface ISegmentsCacheSync extends ISegmentsCacheBase {
|
|
|
270
270
|
getRegisteredSegments(): string[]
|
|
271
271
|
getKeysCount(): number // only used for telemetry
|
|
272
272
|
setChangeNumber(name: string, changeNumber: number): boolean | void
|
|
273
|
-
getChangeNumber(name
|
|
273
|
+
getChangeNumber(name?: string): number
|
|
274
274
|
resetSegments(segmentsData: MySegmentsData | IMySegmentsResponse): boolean // only for Sync Client-Side
|
|
275
275
|
clear(): void
|
|
276
276
|
}
|
|
@@ -11,11 +11,12 @@ export function mySegmentsFetcherFactory(fetchMemberships: IFetchMemberships): I
|
|
|
11
11
|
return function mySegmentsFetcher(
|
|
12
12
|
userMatchingKey: string,
|
|
13
13
|
noCache?: boolean,
|
|
14
|
+
till?: number,
|
|
14
15
|
// Optional decorator for `fetchMemberships` promise, such as timeout or time tracker
|
|
15
16
|
decorator?: (promise: Promise<IResponse>) => Promise<IResponse>
|
|
16
17
|
): Promise<IMembershipsResponse> {
|
|
17
18
|
|
|
18
|
-
let mySegmentsPromise = fetchMemberships(userMatchingKey, noCache);
|
|
19
|
+
let mySegmentsPromise = fetchMemberships(userMatchingKey, noCache, till);
|
|
19
20
|
if (decorator) mySegmentsPromise = decorator(mySegmentsPromise);
|
|
20
21
|
|
|
21
22
|
return mySegmentsPromise.then(resp => resp.json());
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ISplit } from '../../dtos/types';
|
|
2
2
|
import { IReadinessManager } from '../../readiness/types';
|
|
3
3
|
import { IStorageSync } from '../../storages/types';
|
|
4
|
-
import {
|
|
4
|
+
import { MEMBERSHIPS_LS_UPDATE, MEMBERSHIPS_MS_UPDATE } from '../streaming/types';
|
|
5
5
|
import { ITask, ISyncTask } from '../types';
|
|
6
6
|
|
|
7
7
|
export interface ISplitsSyncTask extends ISyncTask<[noCache?: boolean, till?: number, splitUpdateNotification?: { payload: ISplit, changeNumber: number }], boolean> { }
|
|
@@ -9,13 +9,13 @@ export interface ISplitsSyncTask extends ISyncTask<[noCache?: boolean, till?: nu
|
|
|
9
9
|
export interface ISegmentsSyncTask extends ISyncTask<[fetchOnlyNew?: boolean, segmentName?: string, noCache?: boolean, till?: number], boolean> { }
|
|
10
10
|
|
|
11
11
|
export type MySegmentsData = {
|
|
12
|
-
type:
|
|
12
|
+
type: MEMBERSHIPS_MS_UPDATE | MEMBERSHIPS_LS_UPDATE
|
|
13
13
|
cn: number
|
|
14
14
|
added: string[]
|
|
15
15
|
removed: string[]
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
export interface IMySegmentsSyncTask extends ISyncTask<[segmentsData?: MySegmentsData, noCache?: boolean], boolean> { }
|
|
18
|
+
export interface IMySegmentsSyncTask extends ISyncTask<[segmentsData?: MySegmentsData, noCache?: boolean, till?: number], boolean> { }
|
|
19
19
|
|
|
20
20
|
export interface IPollingManager extends ITask {
|
|
21
21
|
syncAll(): Promise<any>
|
|
@@ -7,9 +7,9 @@ import { ILogger } from '../../../logger/types';
|
|
|
7
7
|
import { SYNC_MYSEGMENTS_FETCH_RETRY } from '../../../logger/constants';
|
|
8
8
|
import { MySegmentsData } from '../types';
|
|
9
9
|
import { IMembershipsResponse } from '../../../dtos/types';
|
|
10
|
-
import {
|
|
10
|
+
import { MEMBERSHIPS_LS_UPDATE } from '../../streaming/constants';
|
|
11
11
|
|
|
12
|
-
type IMySegmentsUpdater = (
|
|
12
|
+
type IMySegmentsUpdater = (segmentsData?: MySegmentsData, noCache?: boolean, till?: number) => Promise<boolean>
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* factory of MySegments updater, a task that:
|
|
@@ -42,7 +42,7 @@ export function mySegmentsUpdaterFactory(
|
|
|
42
42
|
|
|
43
43
|
let shouldNotifyUpdate;
|
|
44
44
|
if ((segmentsData as MySegmentsData).type !== undefined) {
|
|
45
|
-
shouldNotifyUpdate = (segmentsData as MySegmentsData).type ===
|
|
45
|
+
shouldNotifyUpdate = (segmentsData as MySegmentsData).type === MEMBERSHIPS_LS_UPDATE ?
|
|
46
46
|
largeSegments!.resetSegments(segmentsData as MySegmentsData) :
|
|
47
47
|
segments.resetSegments(segmentsData as MySegmentsData);
|
|
48
48
|
} else {
|
|
@@ -57,12 +57,12 @@ export function mySegmentsUpdaterFactory(
|
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
-
function _mySegmentsUpdater(retry: number, segmentsData?: MySegmentsData, noCache?: boolean): Promise<boolean> {
|
|
60
|
+
function _mySegmentsUpdater(retry: number, segmentsData?: MySegmentsData, noCache?: boolean, till?: number): Promise<boolean> {
|
|
61
61
|
const updaterPromise: Promise<boolean> = segmentsData ?
|
|
62
62
|
// If segmentsData is provided, there is no need to fetch mySegments
|
|
63
63
|
new Promise((res) => { updateSegments(segmentsData); res(true); }) :
|
|
64
64
|
// If not provided, fetch mySegments
|
|
65
|
-
mySegmentsFetcher(matchingKey, noCache, _promiseDecorator).then(segments => {
|
|
65
|
+
mySegmentsFetcher(matchingKey, noCache, till, _promiseDecorator).then(segments => {
|
|
66
66
|
// Only when we have downloaded segments completely, we should not keep retrying anymore
|
|
67
67
|
startingUp = false;
|
|
68
68
|
|
|
@@ -92,9 +92,10 @@ export function mySegmentsUpdaterFactory(
|
|
|
92
92
|
* (2) an object with a segment name and action (true: add, or false: delete) to update the storage,
|
|
93
93
|
* (3) or `undefined`, for which the updater will fetch mySegments in order to sync the storage.
|
|
94
94
|
* @param {boolean | undefined} noCache true to revalidate data to fetch
|
|
95
|
+
* @param {boolean | undefined} till query param to bypass CDN requests
|
|
95
96
|
*/
|
|
96
|
-
return function mySegmentsUpdater(segmentsData?: MySegmentsData, noCache?: boolean) {
|
|
97
|
-
return _mySegmentsUpdater(0, segmentsData, noCache);
|
|
97
|
+
return function mySegmentsUpdater(segmentsData?: MySegmentsData, noCache?: boolean, till?: number) {
|
|
98
|
+
return _mySegmentsUpdater(0, segmentsData, noCache, till);
|
|
98
99
|
};
|
|
99
100
|
|
|
100
101
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { errorParser, messageParser } from './NotificationParser';
|
|
2
2
|
import { notificationKeeperFactory } from './NotificationKeeper';
|
|
3
|
-
import { PUSH_RETRYABLE_ERROR, PUSH_NONRETRYABLE_ERROR, OCCUPANCY, CONTROL, SEGMENT_UPDATE, SPLIT_KILL, SPLIT_UPDATE,
|
|
3
|
+
import { PUSH_RETRYABLE_ERROR, PUSH_NONRETRYABLE_ERROR, OCCUPANCY, CONTROL, SEGMENT_UPDATE, SPLIT_KILL, SPLIT_UPDATE, MEMBERSHIPS_MS_UPDATE, MEMBERSHIPS_LS_UPDATE } from '../constants';
|
|
4
4
|
import { IPushEventEmitter } from '../types';
|
|
5
5
|
import { ISseEventHandler } from '../SSEClient/types';
|
|
6
6
|
import { INotificationError, INotificationMessage } from './types';
|
|
@@ -81,8 +81,8 @@ export function SSEHandlerFactory(log: ILogger, pushEmitter: IPushEventEmitter,
|
|
|
81
81
|
/* update events */
|
|
82
82
|
case SPLIT_UPDATE:
|
|
83
83
|
case SEGMENT_UPDATE:
|
|
84
|
-
case
|
|
85
|
-
case
|
|
84
|
+
case MEMBERSHIPS_MS_UPDATE:
|
|
85
|
+
case MEMBERSHIPS_LS_UPDATE:
|
|
86
86
|
case SPLIT_KILL:
|
|
87
87
|
pushEmitter.emit(parsedData.type, parsedData);
|
|
88
88
|
break;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ControlType } from '../constants';
|
|
2
|
-
import { SEGMENT_UPDATE, SPLIT_UPDATE, SPLIT_KILL, CONTROL, OCCUPANCY,
|
|
2
|
+
import { SEGMENT_UPDATE, SPLIT_UPDATE, SPLIT_KILL, CONTROL, OCCUPANCY, MEMBERSHIPS_LS_UPDATE, MEMBERSHIPS_MS_UPDATE } from '../types';
|
|
3
3
|
|
|
4
4
|
export enum Compression {
|
|
5
5
|
None = 0,
|
|
@@ -31,9 +31,9 @@ interface IMembershipUpdateData<T extends string> {
|
|
|
31
31
|
s?: number, // seed for hash function
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
export interface IMembershipMSUpdateData extends IMembershipUpdateData<
|
|
34
|
+
export interface IMembershipMSUpdateData extends IMembershipUpdateData<MEMBERSHIPS_MS_UPDATE> { }
|
|
35
35
|
|
|
36
|
-
export interface IMembershipLSUpdateData extends IMembershipUpdateData<
|
|
36
|
+
export interface IMembershipLSUpdateData extends IMembershipUpdateData<MEMBERSHIPS_LS_UPDATE> { }
|
|
37
37
|
|
|
38
38
|
export interface ISegmentUpdateData {
|
|
39
39
|
type: SEGMENT_UPDATE,
|