@splitsoftware/splitio-commons 0.1.1-rc.20 → 1.0.1-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.
- package/CHANGES.txt +9 -0
- package/README.md +3 -2
- package/cjs/listeners/browser.js +3 -1
- package/cjs/logger/constants.js +4 -4
- package/cjs/logger/messages/error.js +2 -1
- package/cjs/logger/messages/warn.js +0 -1
- package/cjs/sdkClient/sdkClient.js +4 -4
- package/cjs/sdkClient/sdkClientMethodCS.js +16 -5
- package/cjs/sdkClient/sdkClientMethodCSWithTT.js +17 -6
- package/cjs/sdkFactory/index.js +6 -3
- package/cjs/storages/inMemory/InMemoryStorage.js +0 -3
- package/cjs/storages/inRedis/index.js +1 -2
- package/cjs/storages/pluggable/SplitsCachePluggable.js +1 -1
- package/cjs/storages/pluggable/inMemoryWrapper.js +19 -5
- package/cjs/storages/pluggable/index.js +38 -15
- package/cjs/storages/pluggable/wrapperAdapter.js +3 -3
- package/cjs/sync/polling/updaters/mySegmentsUpdater.js +1 -1
- package/cjs/sync/streaming/UpdateWorkers/SplitsUpdateWorker.js +0 -1
- package/cjs/sync/submitters/submitterManager.js +19 -0
- package/cjs/sync/syncManagerOnline.js +20 -26
- package/cjs/trackers/impressionObserver/utils.js +1 -1
- package/cjs/utils/constants/index.js +3 -2
- package/cjs/utils/settingsValidation/mode.js +1 -1
- package/cjs/utils/settingsValidation/storage/storageCS.js +17 -3
- package/esm/listeners/browser.js +3 -1
- package/esm/logger/constants.js +3 -3
- package/esm/logger/messages/error.js +2 -1
- package/esm/logger/messages/warn.js +0 -1
- package/esm/sdkClient/sdkClient.js +5 -5
- package/esm/sdkClient/sdkClientMethodCS.js +16 -5
- package/esm/sdkClient/sdkClientMethodCSWithTT.js +17 -6
- package/esm/sdkFactory/index.js +6 -3
- package/esm/storages/inMemory/InMemoryStorage.js +0 -3
- package/esm/storages/inRedis/index.js +1 -2
- package/esm/storages/pluggable/SplitsCachePluggable.js +1 -1
- package/esm/storages/pluggable/inMemoryWrapper.js +19 -5
- package/esm/storages/pluggable/index.js +40 -16
- package/esm/storages/pluggable/wrapperAdapter.js +3 -3
- package/esm/sync/polling/updaters/mySegmentsUpdater.js +1 -1
- package/esm/sync/streaming/UpdateWorkers/SplitsUpdateWorker.js +0 -1
- package/esm/sync/submitters/submitterManager.js +15 -0
- package/esm/sync/syncManagerOnline.js +20 -26
- package/esm/trackers/impressionObserver/utils.js +2 -2
- package/esm/utils/constants/index.js +2 -1
- package/esm/utils/settingsValidation/mode.js +2 -2
- package/esm/utils/settingsValidation/storage/storageCS.js +19 -5
- package/package.json +1 -1
- package/src/listeners/browser.ts +3 -1
- package/src/logger/constants.ts +3 -3
- package/src/logger/messages/error.ts +2 -1
- package/src/logger/messages/warn.ts +0 -1
- package/src/sdkClient/sdkClient.ts +6 -6
- package/src/sdkClient/sdkClientMethodCS.ts +14 -4
- package/src/sdkClient/sdkClientMethodCSWithTT.ts +15 -5
- package/src/sdkFactory/index.ts +7 -3
- package/src/services/splitApi.ts +4 -1
- package/src/storages/inLocalStorage/index.ts +2 -2
- package/src/storages/inMemory/InMemoryStorage.ts +0 -3
- package/src/storages/inMemory/InMemoryStorageCS.ts +2 -2
- package/src/storages/inRedis/index.ts +1 -1
- package/src/storages/pluggable/EventsCachePluggable.ts +3 -3
- package/src/storages/pluggable/ImpressionsCachePluggable.ts +3 -3
- package/src/storages/pluggable/SegmentsCachePluggable.ts +3 -3
- package/src/storages/pluggable/SplitsCachePluggable.ts +4 -4
- package/src/storages/pluggable/inMemoryWrapper.ts +20 -6
- package/src/storages/pluggable/index.ts +46 -16
- package/src/storages/pluggable/wrapperAdapter.ts +5 -5
- package/src/storages/types.ts +24 -24
- package/src/sync/polling/updaters/mySegmentsUpdater.ts +1 -1
- package/src/sync/streaming/UpdateWorkers/SplitsUpdateWorker.ts +0 -1
- package/src/sync/submitters/submitterManager.ts +22 -0
- package/src/sync/syncManagerOnline.ts +26 -32
- package/src/sync/types.ts +1 -1
- package/src/trackers/impressionObserver/ImpressionObserver.ts +1 -1
- package/src/trackers/impressionObserver/utils.ts +2 -2
- package/src/types.ts +5 -5
- package/src/utils/constants/index.ts +6 -4
- package/src/utils/settingsValidation/mode.ts +2 -2
- package/src/utils/settingsValidation/storage/storageCS.ts +21 -8
- package/types/logger/constants.d.ts +3 -3
- package/types/services/splitApi.d.ts +1 -1
- package/types/storages/inMemory/InMemoryStorageCS.d.ts +2 -2
- package/types/storages/pluggable/EventsCachePluggable.d.ts +2 -2
- package/types/storages/pluggable/ImpressionsCachePluggable.d.ts +2 -2
- package/types/storages/pluggable/SegmentsCachePluggable.d.ts +5 -5
- package/types/storages/pluggable/SplitsCachePluggable.d.ts +3 -3
- package/types/storages/pluggable/inMemoryWrapper.d.ts +6 -3
- package/types/storages/pluggable/index.d.ts +2 -2
- package/types/storages/pluggable/wrapperAdapter.d.ts +4 -4
- package/types/storages/types.d.ts +21 -22
- package/types/sync/submitters/submitterManager.d.ts +4 -0
- package/types/sync/syncManagerOnline.d.ts +1 -1
- package/types/sync/types.d.ts +1 -1
- package/types/trackers/impressionObserver/ImpressionObserver.d.ts +1 -1
- package/types/types.d.ts +5 -5
- package/types/utils/constants/index.d.ts +6 -4
- package/types/utils/settingsValidation/storage/storageCS.d.ts +6 -4
package/CHANGES.txt
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
1.0.0 (October 20, 2021)
|
|
2
|
+
- BREAKING CHANGE on multiple modules due to general polishing, improvements and bug fixes. In most cases the change is to use named exports. This affected mostly modules related with synchronization and storages.
|
|
3
|
+
- Updated streaming logic to use the newest version of our streaming service, including:
|
|
4
|
+
- Integration with Auth service V2, connecting to the new channels and applying the received connection delay.
|
|
5
|
+
- Implemented handling of the new MySegmentsV2 notification types (SegmentRemoval, KeyList, Bounded and Unbounded)
|
|
6
|
+
- New control notification for environment scoped streaming reset.
|
|
7
|
+
- Updated localhost mode to emit SDK_READY_FROM_CACHE event in Browser when using localStorage (Related to issue https://github.com/splitio/react-client/issues/34).
|
|
8
|
+
- Updated dependencies for vulnerability fixes.
|
|
9
|
+
|
|
1
10
|
0.1.0 (March 30, 2021)
|
|
2
11
|
- Initial public release. It includes common modules to be consumed by the different Split implementations written in JavaScript. Based on the original JS SDK in the `javascript-client` repository.
|
|
3
12
|
- It's designed with a modular approach, with the following goals in mind:
|
package/README.md
CHANGED
|
@@ -24,17 +24,18 @@ To learn more about Split, contact hello@split.io, or get started with feature f
|
|
|
24
24
|
|
|
25
25
|
Split has built and maintains SDKs for:
|
|
26
26
|
|
|
27
|
-
* .NET [Github](https://github.com/splitio
|
|
27
|
+
* .NET [Github](https://github.com/splitio/dotnet-client) [Docs](https://help.split.io/hc/en-us/articles/360020240172--NET-SDK)
|
|
28
28
|
* Android [Github](https://github.com/splitio/android-client) [Docs](https://help.split.io/hc/en-us/articles/360020343291-Android-SDK)
|
|
29
29
|
* GO [Github](https://github.com/splitio/go-client) [Docs](https://help.split.io/hc/en-us/articles/360020093652-Go-SDK)
|
|
30
30
|
* iOS [Github](https://github.com/splitio/ios-client) [Docs](https://help.split.io/hc/en-us/articles/360020401491-iOS-SDK)
|
|
31
31
|
* Java [Github](https://github.com/splitio/java-client) [Docs](https://help.split.io/hc/en-us/articles/360020405151-Java-SDK)
|
|
32
32
|
* Javascript [Github](https://github.com/splitio/javascript-client) [Docs](https://help.split.io/hc/en-us/articles/360020448791-JavaScript-SDK)
|
|
33
|
+
* Javascript for Browser [Github](https://github.com/splitio/javascript-browser-client) [Docs](https://help.split.io/hc/en-us/articles/360058730852-Browser-SDK)
|
|
33
34
|
* Node [Github](https://github.com/splitio/javascript-client) [Docs](https://help.split.io/hc/en-us/articles/360020564931-Node-js-SDK)
|
|
34
|
-
* Javascript for Browser [Github](https://github.com/splitio/javascript-browser-client) [Docs](https://help.split.io/hc/en-us/articles/360058730852)
|
|
35
35
|
* PHP [Github](https://github.com/splitio/php-client) [Docs](https://help.split.io/hc/en-us/articles/360020350372-PHP-SDK)
|
|
36
36
|
* Python [Github](https://github.com/splitio/python-client) [Docs](https://help.split.io/hc/en-us/articles/360020359652-Python-SDK)
|
|
37
37
|
* React [Github](https://github.com/splitio/react-client) [Docs](https://help.split.io/hc/en-us/articles/360038825091-React-SDK)
|
|
38
|
+
* React Native [Github](https://github.com/splitio/react-native-client) [Docs](https://help.split.io/hc/en-us/articles/4406066357901-React-Native-SDK)
|
|
38
39
|
* Redux [Github](https://github.com/splitio/redux-client) [Docs](https://help.split.io/hc/en-us/articles/360038851551-Redux-SDK)
|
|
39
40
|
* Ruby [Github](https://github.com/splitio/ruby-client) [Docs](https://help.split.io/hc/en-us/articles/360020673251-Ruby-SDK)
|
|
40
41
|
|
package/cjs/listeners/browser.js
CHANGED
|
@@ -49,6 +49,8 @@ var BrowserSignalListener = /** @class */ (function () {
|
|
|
49
49
|
* using beacon API if possible, or falling back to regular post transport.
|
|
50
50
|
*/
|
|
51
51
|
BrowserSignalListener.prototype.flushData = function () {
|
|
52
|
+
if (!this.syncManager)
|
|
53
|
+
return; // In consumer mode there is not sync manager and data to flush
|
|
52
54
|
var eventsUrl = this.settings.urls.events;
|
|
53
55
|
var extraMetadata = {
|
|
54
56
|
// sim stands for Sync/Split Impressions Mode
|
|
@@ -59,7 +61,7 @@ var BrowserSignalListener = /** @class */ (function () {
|
|
|
59
61
|
if (this.storage.impressionCounts)
|
|
60
62
|
this._flushData(eventsUrl + '/testImpressions/count/beacon', this.storage.impressionCounts, this.serviceApi.postTestImpressionsCount, impressionCountsSyncTask_1.fromImpressionCountsCollector);
|
|
61
63
|
// Close streaming connection
|
|
62
|
-
if (this.syncManager
|
|
64
|
+
if (this.syncManager.pushManager)
|
|
63
65
|
this.syncManager.pushManager.stop();
|
|
64
66
|
};
|
|
65
67
|
BrowserSignalListener.prototype._flushData = function (url, cache, postService, fromCacheToPayload, extraMetadata) {
|
package/cjs/logger/constants.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.LOG_PREFIX_CLEANUP = exports.LOG_PREFIX_EVENTS_TRACKER = exports.LOG_PREFIX_IMPRESSIONS_TRACKER = exports.LOG_PREFIX_SYNC_SUBMITTERS = exports.LOG_PREFIX_SYNC_POLLING = exports.LOG_PREFIX_SYNC_MYSEGMENTS = exports.LOG_PREFIX_SYNC_SEGMENTS = exports.LOG_PREFIX_SYNC_SPLITS = exports.LOG_PREFIX_SYNC_STREAMING = exports.LOG_PREFIX_SYNC_OFFLINE = exports.LOG_PREFIX_SYNC_MANAGER = exports.LOG_PREFIX_SYNC = exports.LOG_PREFIX_ENGINE_VALUE = exports.LOG_PREFIX_ENGINE_MATCHER = exports.LOG_PREFIX_ENGINE_COMBINER = exports.LOG_PREFIX_ENGINE = exports.LOG_PREFIX_INSTANTIATION = exports.LOG_PREFIX_SETTINGS = exports.ERROR_LOCALHOST_MODULE_REQUIRED = exports.ERROR_HTTP = exports.ERROR_INVALID_IMPRESSIONS_MODE = exports.ERROR_EMPTY_ARRAY = exports.ERROR_EMPTY = exports.ERROR_INVALID = exports.ERROR_INVALID_KEY_OBJECT = exports.ERROR_TOO_LONG = exports.ERROR_NULL = exports.ERROR_CLIENT_DESTROYED = exports.ERROR_NOT_FINITE = exports.ERROR_SIZE_EXCEEDED = exports.ERROR_NOT_PLAIN_OBJECT = exports.ERROR_EVENT_TYPE_FORMAT = exports.ERROR_EVENTS_TRACKER = exports.ERROR_IMPRESSIONS_LISTENER = exports.ERROR_IMPRESSIONS_TRACKER = exports.ERROR_STREAMING_AUTH = exports.ERROR_STREAMING_SSE = exports.ERROR_SYNC_OFFLINE_LOADING = exports.ERROR_CLIENT_CANNOT_GET_READY = exports.ERROR_CLIENT_LISTENER = exports.ERROR_LOGLEVEL_INVALID = exports.ERROR_ENGINE_COMBINER_IFELSEIF = exports.STREAMING_PARSING_MY_SEGMENTS_UPDATE_V2 = exports.WARN_API_KEY = exports.
|
|
3
|
+
exports.LOG_PREFIX_CLEANUP = exports.LOG_PREFIX_EVENTS_TRACKER = exports.LOG_PREFIX_IMPRESSIONS_TRACKER = exports.LOG_PREFIX_SYNC_SUBMITTERS = exports.LOG_PREFIX_SYNC_POLLING = exports.LOG_PREFIX_SYNC_MYSEGMENTS = exports.LOG_PREFIX_SYNC_SEGMENTS = exports.LOG_PREFIX_SYNC_SPLITS = exports.LOG_PREFIX_SYNC_STREAMING = exports.LOG_PREFIX_SYNC_OFFLINE = exports.LOG_PREFIX_SYNC_MANAGER = exports.LOG_PREFIX_SYNC = exports.LOG_PREFIX_ENGINE_VALUE = exports.LOG_PREFIX_ENGINE_MATCHER = exports.LOG_PREFIX_ENGINE_COMBINER = exports.LOG_PREFIX_ENGINE = exports.LOG_PREFIX_INSTANTIATION = exports.LOG_PREFIX_SETTINGS = exports.ERROR_STORAGE_INVALID = exports.ERROR_LOCALHOST_MODULE_REQUIRED = exports.ERROR_HTTP = exports.ERROR_INVALID_IMPRESSIONS_MODE = exports.ERROR_EMPTY_ARRAY = exports.ERROR_EMPTY = exports.ERROR_INVALID = exports.ERROR_INVALID_KEY_OBJECT = exports.ERROR_TOO_LONG = exports.ERROR_NULL = exports.ERROR_CLIENT_DESTROYED = exports.ERROR_NOT_FINITE = exports.ERROR_SIZE_EXCEEDED = exports.ERROR_NOT_PLAIN_OBJECT = exports.ERROR_EVENT_TYPE_FORMAT = exports.ERROR_EVENTS_TRACKER = exports.ERROR_IMPRESSIONS_LISTENER = exports.ERROR_IMPRESSIONS_TRACKER = exports.ERROR_STREAMING_AUTH = exports.ERROR_STREAMING_SSE = exports.ERROR_SYNC_OFFLINE_LOADING = exports.ERROR_CLIENT_CANNOT_GET_READY = exports.ERROR_CLIENT_LISTENER = exports.ERROR_LOGLEVEL_INVALID = exports.ERROR_ENGINE_COMBINER_IFELSEIF = exports.STREAMING_PARSING_MY_SEGMENTS_UPDATE_V2 = exports.WARN_API_KEY = exports.WARN_SPLITS_FILTER_EMPTY = exports.WARN_SPLITS_FILTER_INVALID = exports.WARN_SPLITS_FILTER_IGNORED = exports.WARN_INTEGRATION_INVALID = exports.WARN_NOT_EXISTENT_TT = exports.WARN_LOWERCASE_TRAFFIC_TYPE = exports.WARN_NOT_EXISTENT_SPLIT = exports.WARN_TRIMMING = exports.WARN_CONVERTING = exports.WARN_TRIMMING_PROPERTIES = exports.WARN_SETTING_NULL = exports.SUBMITTERS_PUSH_RETRY = exports.SUBMITTERS_PUSH_FAILS = exports.STREAMING_FALLBACK = exports.STREAMING_PARSING_MESSAGE_FAILS = exports.STREAMING_PARSING_ERROR_FAILS = exports.SYNC_SPLITS_FETCH_FAILS = exports.SYNC_MYSEGMENTS_FETCH_RETRY = exports.CLIENT_NOT_READY = exports.CLIENT_NO_LISTENER = exports.ENGINE_VALUE_NO_ATTRIBUTES = exports.ENGINE_VALUE_INVALID = exports.IMPRESSIONS_TRACKER_SUCCESS = exports.EVENTS_TRACKER_SUCCESS = exports.SYNC_STOP_POLLING = exports.SYNC_CONTINUE_POLLING = exports.SYNC_START_POLLING = exports.SUBMITTERS_PUSH = exports.SUBMITTERS_PUSH_FULL_EVENTS_QUEUE = exports.STREAMING_DISCONNECTING = exports.STREAMING_DISABLED = exports.STREAMING_CONNECTING = exports.STREAMING_RECONNECT = exports.STREAMING_REFRESH_TOKEN = exports.SYNC_SPLITS_FETCH_RETRY = exports.POLLING_STOP = exports.POLLING_START = exports.POLLING_SMART_PAUSING = exports.NEW_FACTORY = exports.NEW_SHARED_CLIENT = exports.IMPRESSION_QUEUEING = exports.IMPRESSION = exports.CLIENT_READY = exports.CLIENT_READY_FROM_CACHE = exports.SETTINGS_SPLITS_FILTER = exports.SYNC_TASK_STOP = exports.SYNC_TASK_EXECUTE = exports.SYNC_TASK_START = exports.STREAMING_NEW_MESSAGE = exports.SYNC_SPLITS_SEGMENTS = exports.SYNC_SPLITS_REMOVED = exports.SYNC_SPLITS_NEW = exports.SYNC_SPLITS_FETCH = exports.SYNC_OFFLINE_DATA = exports.RETRIEVE_MANAGER = exports.RETRIEVE_CLIENT_EXISTING = exports.RETRIEVE_CLIENT_DEFAULT = exports.CLEANUP_DEREGISTERING = exports.CLEANUP_REGISTERING = exports.ENGINE_SANITIZE = exports.ENGINE_VALUE = exports.ENGINE_MATCHER_WHITELIST = exports.ENGINE_MATCHER_STARTS_WITH = exports.ENGINE_MATCHER_STRING_INVALID = exports.ENGINE_MATCHER_STRING = exports.ENGINE_MATCHER_SEGMENT = exports.ENGINE_MATCHER_PART_OF = exports.ENGINE_MATCHER_LESS = exports.ENGINE_MATCHER_GREATER = exports.ENGINE_MATCHER_ENDS_WITH = exports.ENGINE_MATCHER_EQUAL_TO_SET = exports.ENGINE_MATCHER_EQUAL = exports.ENGINE_MATCHER_DEPENDENCY_PRE = exports.ENGINE_MATCHER_DEPENDENCY = exports.ENGINE_MATCHER_CONTAINS_STRING = exports.ENGINE_MATCHER_CONTAINS_ANY = exports.ENGINE_MATCHER_CONTAINS_ALL = exports.ENGINE_MATCHER_BOOLEAN = exports.ENGINE_MATCHER_BETWEEN = exports.ENGINE_MATCHER_ALL = exports.ENGINE_BUCKET = exports.ENGINE_COMBINER_IFELSEIF_NO_TREATMENT = exports.ENGINE_COMBINER_IFELSEIF = exports.ENGINE_COMBINER_AND = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* Message codes used to trim string log messages from commons and client-side API modules,
|
|
6
6
|
* in order to reduce the minimal SDK size for Browser and eventually other client-side environments.
|
|
@@ -92,9 +92,8 @@ exports.WARN_INTEGRATION_INVALID = 218;
|
|
|
92
92
|
exports.WARN_SPLITS_FILTER_IGNORED = 219;
|
|
93
93
|
exports.WARN_SPLITS_FILTER_INVALID = 220;
|
|
94
94
|
exports.WARN_SPLITS_FILTER_EMPTY = 221;
|
|
95
|
-
exports.
|
|
96
|
-
exports.
|
|
97
|
-
exports.STREAMING_PARSING_MY_SEGMENTS_UPDATE_V2 = 224;
|
|
95
|
+
exports.WARN_API_KEY = 222;
|
|
96
|
+
exports.STREAMING_PARSING_MY_SEGMENTS_UPDATE_V2 = 223;
|
|
98
97
|
exports.ERROR_ENGINE_COMBINER_IFELSEIF = 300;
|
|
99
98
|
exports.ERROR_LOGLEVEL_INVALID = 301;
|
|
100
99
|
exports.ERROR_CLIENT_LISTENER = 302;
|
|
@@ -119,6 +118,7 @@ exports.ERROR_EMPTY_ARRAY = 320;
|
|
|
119
118
|
exports.ERROR_INVALID_IMPRESSIONS_MODE = 321;
|
|
120
119
|
exports.ERROR_HTTP = 322;
|
|
121
120
|
exports.ERROR_LOCALHOST_MODULE_REQUIRED = 323;
|
|
121
|
+
exports.ERROR_STORAGE_INVALID = 324;
|
|
122
122
|
// Log prefixes (a.k.a. tags or categories)
|
|
123
123
|
exports.LOG_PREFIX_SETTINGS = 'settings';
|
|
124
124
|
exports.LOG_PREFIX_INSTANTIATION = 'Factory instantiation';
|
|
@@ -33,5 +33,6 @@ exports.codesError = [
|
|
|
33
33
|
[c.ERROR_EMPTY_ARRAY, '%s: %s must be a non-empty array.'],
|
|
34
34
|
// initialization / settings validation
|
|
35
35
|
[c.ERROR_INVALID_IMPRESSIONS_MODE, c.LOG_PREFIX_SETTINGS + ': you passed an invalid "impressionsMode". It should be one of the following values: %s. Defaulting to "%s" mode.'],
|
|
36
|
-
[c.ERROR_LOCALHOST_MODULE_REQUIRED, c.LOG_PREFIX_SETTINGS + ': an invalid value was received for "sync.localhostMode" config. A valid entity should be provided for localhost mode.']
|
|
36
|
+
[c.ERROR_LOCALHOST_MODULE_REQUIRED, c.LOG_PREFIX_SETTINGS + ': an invalid value was received for "sync.localhostMode" config. A valid entity should be provided for localhost mode.'],
|
|
37
|
+
[c.ERROR_STORAGE_INVALID, c.LOG_PREFIX_SETTINGS + ': The provided storage is invalid.%s Fallbacking into default MEMORY storage'],
|
|
37
38
|
];
|
|
@@ -32,7 +32,6 @@ exports.codesWarn = error_1.codesError.concat([
|
|
|
32
32
|
[c.WARN_SPLITS_FILTER_IGNORED, c.LOG_PREFIX_SETTINGS + ': split filters have been configured but will have no effect if mode is not "%s", since synchronization is being deferred to an external tool.'],
|
|
33
33
|
[c.WARN_SPLITS_FILTER_INVALID, c.LOG_PREFIX_SETTINGS + ': split filter at position %s is invalid. It must be an object with a valid filter type ("byName" or "byPrefix") and a list of "values".'],
|
|
34
34
|
[c.WARN_SPLITS_FILTER_EMPTY, c.LOG_PREFIX_SETTINGS + ': splitFilters configuration must be a non-empty array of filter objects.'],
|
|
35
|
-
[c.WARN_STORAGE_INVALID, c.LOG_PREFIX_SETTINGS + ': The provided storage is invalid. Fallbacking into default MEMORY storage'],
|
|
36
35
|
[c.WARN_API_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'],
|
|
37
36
|
[c.STREAMING_PARSING_MY_SEGMENTS_UPDATE_V2, c.LOG_PREFIX_SYNC_STREAMING + 'Fetching MySegments due to an error processing %s notification: %s'],
|
|
38
37
|
]);
|
|
@@ -17,8 +17,8 @@ function sdkClientFactory(params) {
|
|
|
17
17
|
Object.create(sdkReadinessManager.sdkStatus),
|
|
18
18
|
// Client API (getTreatment* & track methods)
|
|
19
19
|
clientInputValidation_1.default(settings.log, client_1.default(params), sdkReadinessManager.readinessManager,
|
|
20
|
-
//
|
|
21
|
-
settings.mode ===
|
|
20
|
+
// storage is async if and only if mode is consumer or partial consumer
|
|
21
|
+
[constants_1.CONSUMER_MODE, constants_1.CONSUMER_PARTIAL_MODE].indexOf(settings.mode) === -1 ? true : false),
|
|
22
22
|
// Sdk destroy
|
|
23
23
|
{
|
|
24
24
|
destroy: function () {
|
|
@@ -29,11 +29,11 @@ function sdkClientFactory(params) {
|
|
|
29
29
|
// Cleanup event listeners
|
|
30
30
|
sdkReadinessManager.readinessManager.destroy();
|
|
31
31
|
signalListener && signalListener.stop();
|
|
32
|
-
// Cleanup storage
|
|
33
|
-
storage.destroy();
|
|
34
32
|
// Release the API Key if it is the main client
|
|
35
33
|
if (!sharedClient)
|
|
36
34
|
apiKey_1.releaseApiKey(settings.core.authorizationKey);
|
|
35
|
+
// Cleanup storage
|
|
36
|
+
return storage.destroy();
|
|
37
37
|
});
|
|
38
38
|
}
|
|
39
39
|
});
|
|
@@ -8,6 +8,7 @@ var key_2 = require("../utils/key");
|
|
|
8
8
|
var sdkClient_1 = require("./sdkClient");
|
|
9
9
|
var object_assign_1 = tslib_1.__importDefault(require("object-assign"));
|
|
10
10
|
var constants_1 = require("../logger/constants");
|
|
11
|
+
var constants_2 = require("../readiness/constants");
|
|
11
12
|
function buildInstanceId(key) {
|
|
12
13
|
// @ts-ignore
|
|
13
14
|
return (key.matchingKey ? key.matchingKey : key) + "-" + (key.bucketingKey ? key.bucketingKey : key) + "-";
|
|
@@ -43,14 +44,24 @@ function sdkClientMethodCSFactory(params) {
|
|
|
43
44
|
var instanceId = buildInstanceId(validKey);
|
|
44
45
|
if (!clientInstances[instanceId]) {
|
|
45
46
|
var matchingKey = key_2.getMatching(validKey);
|
|
46
|
-
var
|
|
47
|
-
var sharedStorage = storage.shared(matchingKey)
|
|
48
|
-
|
|
47
|
+
var sharedSdkReadiness_1 = sdkReadinessManager.shared(readyTimeout);
|
|
48
|
+
var sharedStorage = storage.shared && storage.shared(matchingKey, function (err) {
|
|
49
|
+
if (err)
|
|
50
|
+
return;
|
|
51
|
+
// Emit SDK_READY in consumer mode for shared clients
|
|
52
|
+
sharedSdkReadiness_1.readinessManager.segments.emit(constants_2.SDK_SEGMENTS_ARRIVED);
|
|
53
|
+
});
|
|
54
|
+
// 3 possibilities:
|
|
55
|
+
// - Standalone mode: both syncManager and sharedSyncManager are defined
|
|
56
|
+
// - Consumer mode: both syncManager and sharedSyncManager are undefined
|
|
57
|
+
// - Consumer partial mode: syncManager is defined (only for submitters) but sharedSyncManager is undefined
|
|
58
|
+
// @ts-ignore
|
|
59
|
+
var sharedSyncManager = syncManager && sharedStorage && syncManager.shared(matchingKey, sharedSdkReadiness_1.readinessManager, sharedStorage);
|
|
49
60
|
// As shared clients reuse all the storage information, we don't need to check here if we
|
|
50
61
|
// will use offline or online mode. We should stick with the original decision.
|
|
51
62
|
clientInstances[instanceId] = clientCS_1.default(sdkClient_1.sdkClientFactory(object_assign_1.default({}, params, {
|
|
52
|
-
sdkReadinessManager:
|
|
53
|
-
storage: sharedStorage,
|
|
63
|
+
sdkReadinessManager: sharedSdkReadiness_1,
|
|
64
|
+
storage: sharedStorage || storage,
|
|
54
65
|
syncManager: sharedSyncManager,
|
|
55
66
|
signalListener: undefined,
|
|
56
67
|
sharedClient: true
|
|
@@ -9,6 +9,7 @@ var key_2 = require("../utils/key");
|
|
|
9
9
|
var sdkClient_1 = require("./sdkClient");
|
|
10
10
|
var object_assign_1 = tslib_1.__importDefault(require("object-assign"));
|
|
11
11
|
var constants_1 = require("../logger/constants");
|
|
12
|
+
var constants_2 = require("../readiness/constants");
|
|
12
13
|
function buildInstanceId(key, trafficType) {
|
|
13
14
|
// @ts-ignore
|
|
14
15
|
return (key.matchingKey ? key.matchingKey : key) + "-" + (key.bucketingKey ? key.bucketingKey : key) + "-" + (trafficType !== undefined ? trafficType : '');
|
|
@@ -56,19 +57,29 @@ function sdkClientMethodCSFactory(params) {
|
|
|
56
57
|
var instanceId = buildInstanceId(validKey, validTrafficType);
|
|
57
58
|
if (!clientInstances[instanceId]) {
|
|
58
59
|
var matchingKey = key_2.getMatching(validKey);
|
|
59
|
-
var
|
|
60
|
-
var sharedStorage = storage.shared(matchingKey)
|
|
61
|
-
|
|
60
|
+
var sharedSdkReadiness_1 = sdkReadinessManager.shared(readyTimeout);
|
|
61
|
+
var sharedStorage = storage.shared && storage.shared(matchingKey, function (err) {
|
|
62
|
+
if (err)
|
|
63
|
+
return;
|
|
64
|
+
// Emit SDK_READY in consumer mode for shared clients
|
|
65
|
+
sharedSdkReadiness_1.readinessManager.segments.emit(constants_2.SDK_SEGMENTS_ARRIVED);
|
|
66
|
+
});
|
|
67
|
+
// 3 possibilities:
|
|
68
|
+
// - Standalone mode: both syncManager and sharedSyncManager are defined
|
|
69
|
+
// - Consumer mode: both syncManager and sharedSyncManager are undefined
|
|
70
|
+
// - Consumer partial mode: syncManager is defined (only for submitters) but sharedSyncManager is undefined
|
|
71
|
+
// @ts-ignore
|
|
72
|
+
var sharedSyncManager = syncManager && sharedStorage && syncManager.shared(matchingKey, sharedSdkReadiness_1.readinessManager, sharedStorage);
|
|
62
73
|
// As shared clients reuse all the storage information, we don't need to check here if we
|
|
63
74
|
// will use offline or online mode. We should stick with the original decision.
|
|
64
75
|
clientInstances[instanceId] = clientCS_1.default(sdkClient_1.sdkClientFactory(object_assign_1.default({}, params, {
|
|
65
|
-
sdkReadinessManager:
|
|
66
|
-
storage: sharedStorage,
|
|
76
|
+
sdkReadinessManager: sharedSdkReadiness_1,
|
|
77
|
+
storage: sharedStorage || storage,
|
|
67
78
|
syncManager: sharedSyncManager,
|
|
68
79
|
signalListener: undefined,
|
|
69
80
|
sharedClient: true
|
|
70
81
|
})), validKey, validTrafficType);
|
|
71
|
-
sharedSyncManager.start();
|
|
82
|
+
sharedSyncManager && sharedSyncManager.start();
|
|
72
83
|
log.info(constants_1.NEW_SHARED_CLIENT);
|
|
73
84
|
}
|
|
74
85
|
else {
|
package/cjs/sdkFactory/index.js
CHANGED
|
@@ -31,13 +31,16 @@ function sdkFactory(params) {
|
|
|
31
31
|
// ATM, only used by InLocalStorage
|
|
32
32
|
matchingKey: key_1.getMatching(settings.core.key),
|
|
33
33
|
splitFiltersValidation: settings.sync.__splitFiltersValidation,
|
|
34
|
-
//
|
|
35
|
-
|
|
34
|
+
// ATM, only used by PluggableStorage
|
|
35
|
+
mode: settings.mode,
|
|
36
|
+
// Callback used to emit SDK_READY in consumer mode, where `syncManagerFactory` is undefined
|
|
37
|
+
// or only instantiates submitters, and therefore it is not able to emit readiness events.
|
|
38
|
+
onReadyCb: function (error) {
|
|
36
39
|
if (error)
|
|
37
40
|
return; // don't emit SDK_READY if storage failed to connect.
|
|
38
41
|
readinessManager.splits.emit(constants_2.SDK_SPLITS_ARRIVED);
|
|
39
42
|
readinessManager.segments.emit(constants_2.SDK_SEGMENTS_ARRIVED);
|
|
40
|
-
}
|
|
43
|
+
},
|
|
41
44
|
metadata: metadataBuilder_1.metadataBuilder(settings),
|
|
42
45
|
log: log
|
|
43
46
|
};
|
|
@@ -14,9 +14,6 @@ var constants_1 = require("../../utils/constants");
|
|
|
14
14
|
* @param params parameters required by EventsCacheSync
|
|
15
15
|
*/
|
|
16
16
|
function InMemoryStorageFactory(params) {
|
|
17
|
-
// InMemory storage is always ready
|
|
18
|
-
if (params.onReadyCb)
|
|
19
|
-
setTimeout(params.onReadyCb);
|
|
20
17
|
return {
|
|
21
18
|
splits: new SplitsCacheInMemory_1.default(),
|
|
22
19
|
segments: new SegmentsCacheInMemory_1.default(),
|
|
@@ -25,8 +25,7 @@ function InRedisStorage(options) {
|
|
|
25
25
|
var redisClient = new RedisAdapter_1.default(log, options.options || {});
|
|
26
26
|
// subscription to Redis connect event in order to emit SDK_READY event on consumer mode
|
|
27
27
|
redisClient.on('connect', function () {
|
|
28
|
-
|
|
29
|
-
onReadyCb();
|
|
28
|
+
onReadyCb();
|
|
30
29
|
});
|
|
31
30
|
return {
|
|
32
31
|
splits: new SplitsCacheInRedis_1.default(log, keys, redisClient),
|
|
@@ -11,7 +11,7 @@ var AbstractSplitsCacheAsync_1 = tslib_1.__importDefault(require("../AbstractSpl
|
|
|
11
11
|
var SplitsCachePluggable = /** @class */ (function (_super) {
|
|
12
12
|
tslib_1.__extends(SplitsCachePluggable, _super);
|
|
13
13
|
/**
|
|
14
|
-
* Create a SplitsCache that uses a
|
|
14
|
+
* Create a SplitsCache that uses a storage wrapper.
|
|
15
15
|
* @param log Logger instance.
|
|
16
16
|
* @param keys Key builder.
|
|
17
17
|
* @param wrapper Adapted wrapper storage.
|
|
@@ -4,12 +4,15 @@ exports.inMemoryWrapperFactory = void 0;
|
|
|
4
4
|
var lang_1 = require("../../utils/lang");
|
|
5
5
|
var sets_1 = require("../../utils/lang/sets");
|
|
6
6
|
/**
|
|
7
|
-
* Creates a
|
|
7
|
+
* Creates a IPluggableStorageWrapper implementation that stores items in memory.
|
|
8
8
|
* The `_cache` property is the object were items are stored.
|
|
9
9
|
* Intended for testing purposes.
|
|
10
|
+
*
|
|
11
|
+
* @param connDelay delay in millis for `connect` resolve. If not provided, `connect` resolves inmediatelly.
|
|
10
12
|
*/
|
|
11
|
-
function inMemoryWrapperFactory() {
|
|
13
|
+
function inMemoryWrapperFactory(connDelay) {
|
|
12
14
|
var _cache = {};
|
|
15
|
+
var _connDelay = connDelay;
|
|
13
16
|
return {
|
|
14
17
|
/** Holds items (for key-value operations), list of items (for list operations) and set of items (for set operations) */
|
|
15
18
|
_cache: _cache,
|
|
@@ -117,9 +120,20 @@ function inMemoryWrapperFactory() {
|
|
|
117
120
|
return Promise.resolve(sets_1.setToArray(set));
|
|
118
121
|
return Promise.reject('key is not a set');
|
|
119
122
|
},
|
|
120
|
-
// always connects and
|
|
121
|
-
connect: function () {
|
|
122
|
-
|
|
123
|
+
// always connects and disconnects
|
|
124
|
+
connect: function () {
|
|
125
|
+
if (typeof _connDelay === 'number') {
|
|
126
|
+
return new Promise(function (res) { return setTimeout(res, _connDelay); });
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
return Promise.resolve();
|
|
130
|
+
}
|
|
131
|
+
},
|
|
132
|
+
disconnect: function () { return Promise.resolve(); },
|
|
133
|
+
// for testing
|
|
134
|
+
_setConnDelay: function (connDelay) {
|
|
135
|
+
_connDelay = connDelay;
|
|
136
|
+
}
|
|
123
137
|
};
|
|
124
138
|
}
|
|
125
139
|
exports.inMemoryWrapperFactory = inMemoryWrapperFactory;
|
|
@@ -11,7 +11,10 @@ var wrapperAdapter_1 = require("./wrapperAdapter");
|
|
|
11
11
|
var lang_1 = require("../../utils/lang");
|
|
12
12
|
var KeyBuilder_1 = require("../KeyBuilder");
|
|
13
13
|
var constants_1 = require("../../utils/constants");
|
|
14
|
-
var
|
|
14
|
+
var ImpressionsCacheInMemory_1 = tslib_1.__importDefault(require("../inMemory/ImpressionsCacheInMemory"));
|
|
15
|
+
var EventsCacheInMemory_1 = tslib_1.__importDefault(require("../inMemory/EventsCacheInMemory"));
|
|
16
|
+
var ImpressionCountsCacheInMemory_1 = tslib_1.__importDefault(require("../inMemory/ImpressionCountsCacheInMemory"));
|
|
17
|
+
var NO_VALID_WRAPPER = 'Expecting pluggable storage `wrapper` in options, but no valid wrapper instance was provided.';
|
|
15
18
|
var NO_VALID_WRAPPER_INTERFACE = 'The provided wrapper instance doesn’t follow the expected interface. Check our docs.';
|
|
16
19
|
/**
|
|
17
20
|
* Validate pluggable storage factory options.
|
|
@@ -27,6 +30,23 @@ function validatePluggableStorageOptions(options) {
|
|
|
27
30
|
if (missingMethods.length)
|
|
28
31
|
throw new Error(NO_VALID_WRAPPER_INTERFACE + " The following methods are missing or invalid: " + missingMethods);
|
|
29
32
|
}
|
|
33
|
+
// subscription to wrapper connect event in order to emit SDK_READY event
|
|
34
|
+
function wrapperConnect(wrapper, onReadyCb) {
|
|
35
|
+
wrapper.connect().then(function () {
|
|
36
|
+
onReadyCb();
|
|
37
|
+
}).catch(function (e) {
|
|
38
|
+
onReadyCb(e || new Error('Error connecting wrapper'));
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
// Async return type in `client.track` method on consumer partial mode
|
|
42
|
+
// No need to promisify impressions cache
|
|
43
|
+
function promisifyEventsTrack(events) {
|
|
44
|
+
var origTrack = events.track;
|
|
45
|
+
events.track = function () {
|
|
46
|
+
return Promise.resolve(origTrack.apply(this, arguments));
|
|
47
|
+
};
|
|
48
|
+
return events;
|
|
49
|
+
}
|
|
30
50
|
/**
|
|
31
51
|
* Pluggable storage factory for consumer server-side & client-side SplitFactory.
|
|
32
52
|
*/
|
|
@@ -34,30 +54,33 @@ function PluggableStorage(options) {
|
|
|
34
54
|
validatePluggableStorageOptions(options);
|
|
35
55
|
var prefix = KeyBuilder_1.validatePrefix(options.prefix);
|
|
36
56
|
function PluggableStorageFactory(_a) {
|
|
37
|
-
var log = _a.log, metadata = _a.metadata, onReadyCb = _a.onReadyCb;
|
|
57
|
+
var log = _a.log, metadata = _a.metadata, onReadyCb = _a.onReadyCb, mode = _a.mode, eventsQueueSize = _a.eventsQueueSize, optimize = _a.optimize;
|
|
38
58
|
var keys = new KeyBuilderSS_1.default(prefix, metadata);
|
|
39
59
|
var wrapper = wrapperAdapter_1.wrapperAdapter(log, options.wrapper);
|
|
40
|
-
|
|
41
|
-
wrapper
|
|
42
|
-
|
|
43
|
-
onReadyCb();
|
|
44
|
-
}).catch(function (e) {
|
|
45
|
-
if (onReadyCb)
|
|
46
|
-
onReadyCb(e || new Error('Error connecting wrapper'));
|
|
47
|
-
});
|
|
60
|
+
var isPartialConsumer = mode === constants_1.CONSUMER_PARTIAL_MODE;
|
|
61
|
+
// Connects to wrapper and emits SDK_READY event on main client
|
|
62
|
+
wrapperConnect(wrapper, onReadyCb);
|
|
48
63
|
return {
|
|
49
64
|
splits: new SplitsCachePluggable_1.SplitsCachePluggable(log, keys, wrapper),
|
|
50
65
|
segments: new SegmentsCachePluggable_1.SegmentsCachePluggable(log, keys, wrapper),
|
|
51
|
-
impressions: new ImpressionsCachePluggable_1.ImpressionsCachePluggable(log, keys.buildImpressionsKey(), wrapper, metadata),
|
|
52
|
-
|
|
66
|
+
impressions: isPartialConsumer ? new ImpressionsCacheInMemory_1.default() : new ImpressionsCachePluggable_1.ImpressionsCachePluggable(log, keys.buildImpressionsKey(), wrapper, metadata),
|
|
67
|
+
impressionCounts: optimize ? new ImpressionCountsCacheInMemory_1.default() : undefined,
|
|
68
|
+
events: isPartialConsumer ? promisifyEventsTrack(new EventsCacheInMemory_1.default(eventsQueueSize)) : new EventsCachePluggable_1.EventsCachePluggable(log, keys.buildEventsKey(), wrapper, metadata),
|
|
53
69
|
// @TODO add telemetry cache when required
|
|
54
|
-
// Disconnect the underlying storage
|
|
70
|
+
// Disconnect the underlying storage
|
|
55
71
|
destroy: function () {
|
|
56
|
-
return wrapper.
|
|
72
|
+
return wrapper.disconnect();
|
|
73
|
+
},
|
|
74
|
+
// emits SDK_READY event on shared clients and returns a reference to the storage
|
|
75
|
+
shared: function (_, onReadyCb) {
|
|
76
|
+
wrapperConnect(wrapper, onReadyCb);
|
|
77
|
+
return tslib_1.__assign(tslib_1.__assign({}, this), {
|
|
78
|
+
// no-op destroy, to disconnect the wrapper only when the main client is destroyed
|
|
79
|
+
destroy: function () { } });
|
|
57
80
|
}
|
|
58
81
|
};
|
|
59
82
|
}
|
|
60
|
-
PluggableStorageFactory.type = constants_1.
|
|
83
|
+
PluggableStorageFactory.type = constants_1.STORAGE_PLUGGABLE;
|
|
61
84
|
return PluggableStorageFactory;
|
|
62
85
|
}
|
|
63
86
|
exports.PluggableStorage = PluggableStorage;
|
|
@@ -19,14 +19,14 @@ exports.METHODS_TO_PROMISE_WRAP = [
|
|
|
19
19
|
'removeItems',
|
|
20
20
|
'getItems',
|
|
21
21
|
'connect',
|
|
22
|
-
'
|
|
22
|
+
'disconnect'
|
|
23
23
|
];
|
|
24
24
|
/**
|
|
25
|
-
* Adapter of the
|
|
25
|
+
* Adapter of the Pluggable Storage Wrapper.
|
|
26
26
|
* Used to handle exceptions as rejected promises, in order to simplify the error handling on storages.
|
|
27
27
|
*
|
|
28
28
|
* @param log logger instance
|
|
29
|
-
* @param wrapper
|
|
29
|
+
* @param wrapper storage wrapper to adapt
|
|
30
30
|
* @returns an adapted version of the given storage wrapper
|
|
31
31
|
*/
|
|
32
32
|
function wrapperAdapter(log, wrapper) {
|
|
@@ -23,7 +23,7 @@ function mySegmentsUpdaterFactory(log, mySegmentsFetcher, splitsCache, mySegment
|
|
|
23
23
|
// NOTE: We only collect metrics on startup.
|
|
24
24
|
// mySegmentsPromise = tracker.start(tracker.TaskNames.MY_SEGMENTS_FETCH, startingUp ? metricCollectors : false, mySegmentsPromise);
|
|
25
25
|
}
|
|
26
|
-
// @TODO if allowing
|
|
26
|
+
// @TODO if allowing pluggable storages, handle async execution
|
|
27
27
|
function updateSegments(segmentsData) {
|
|
28
28
|
var shouldNotifyUpdate;
|
|
29
29
|
if (Array.isArray(segmentsData)) {
|
|
@@ -70,7 +70,6 @@ var SplitsUpdateWorker = /** @class */ (function () {
|
|
|
70
70
|
*/
|
|
71
71
|
SplitsUpdateWorker.prototype.killSplit = function (_a) {
|
|
72
72
|
var changeNumber = _a.changeNumber, splitName = _a.splitName, defaultTreatment = _a.defaultTreatment;
|
|
73
|
-
// @TODO handle retry due to errors in storage, once we allow the definition of custom async storages
|
|
74
73
|
if (this.splitsCache.killLocally(splitName, defaultTreatment, changeNumber)) {
|
|
75
74
|
// trigger an SDK_UPDATE if Split was killed locally
|
|
76
75
|
this.splitsEventEmitter.emit(constants_1.SDK_SPLITS_ARRIVED, true);
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.submitterManagerFactory = void 0;
|
|
4
|
+
var syncTaskComposite_1 = require("../syncTaskComposite");
|
|
5
|
+
var eventsSyncTask_1 = require("./eventsSyncTask");
|
|
6
|
+
var impressionsSyncTask_1 = require("./impressionsSyncTask");
|
|
7
|
+
var impressionCountsSyncTask_1 = require("./impressionCountsSyncTask");
|
|
8
|
+
function submitterManagerFactory(settings, storage, splitApi) {
|
|
9
|
+
var log = settings.log;
|
|
10
|
+
var submitters = [
|
|
11
|
+
impressionsSyncTask_1.impressionsSyncTaskFactory(log, splitApi.postTestImpressionsBulk, storage.impressions, settings.scheduler.impressionsRefreshRate, settings.core.labelsEnabled),
|
|
12
|
+
eventsSyncTask_1.eventsSyncTaskFactory(log, splitApi.postEventsBulk, storage.events, settings.scheduler.eventsPushRate, settings.startup.eventsFirstPushWindow)
|
|
13
|
+
// @TODO add telemetry submitter
|
|
14
|
+
];
|
|
15
|
+
if (storage.impressionCounts)
|
|
16
|
+
submitters.push(impressionCountsSyncTask_1.impressionCountsSyncTaskFactory(log, splitApi.postTestImpressionsCount, storage.impressionCounts));
|
|
17
|
+
return syncTaskComposite_1.syncTaskComposite(submitters);
|
|
18
|
+
}
|
|
19
|
+
exports.submitterManagerFactory = submitterManagerFactory;
|
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.syncManagerOnlineFactory = void 0;
|
|
4
|
-
var
|
|
5
|
-
var eventsSyncTask_1 = require("./submitters/eventsSyncTask");
|
|
6
|
-
var impressionsSyncTask_1 = require("./submitters/impressionsSyncTask");
|
|
7
|
-
var impressionCountsSyncTask_1 = require("./submitters/impressionCountsSyncTask");
|
|
4
|
+
var submitterManager_1 = require("./submitters/submitterManager");
|
|
8
5
|
var constants_1 = require("./streaming/constants");
|
|
9
6
|
var constants_2 = require("../logger/constants");
|
|
10
7
|
/**
|
|
@@ -23,21 +20,14 @@ function syncManagerOnlineFactory(pollingManagerFactory, pushManagerFactory) {
|
|
|
23
20
|
var settings = _a.settings, platform = _a.platform, splitApi = _a.splitApi, storage = _a.storage, readiness = _a.readiness;
|
|
24
21
|
var log = settings.log;
|
|
25
22
|
/** Polling Manager */
|
|
26
|
-
var pollingManager = pollingManagerFactory(splitApi, storage, readiness, settings);
|
|
23
|
+
var pollingManager = pollingManagerFactory && pollingManagerFactory(splitApi, storage, readiness, settings);
|
|
27
24
|
/** Push Manager */
|
|
28
|
-
var pushManager = settings.streamingEnabled && pushManagerFactory ?
|
|
25
|
+
var pushManager = settings.streamingEnabled && pollingManager && pushManagerFactory ?
|
|
29
26
|
pushManagerFactory(pollingManager, storage, readiness, splitApi.fetchAuth, platform, settings) :
|
|
30
27
|
undefined;
|
|
31
28
|
/** Submitter Manager */
|
|
32
|
-
// It is not inyected
|
|
33
|
-
var
|
|
34
|
-
impressionsSyncTask_1.impressionsSyncTaskFactory(log, splitApi.postTestImpressionsBulk, storage.impressions, settings.scheduler.impressionsRefreshRate, settings.core.labelsEnabled),
|
|
35
|
-
eventsSyncTask_1.eventsSyncTaskFactory(log, splitApi.postEventsBulk, storage.events, settings.scheduler.eventsPushRate, settings.startup.eventsFirstPushWindow)
|
|
36
|
-
// @TODO add telemetry submitter
|
|
37
|
-
];
|
|
38
|
-
if (storage.impressionCounts)
|
|
39
|
-
submitters.push(impressionCountsSyncTask_1.impressionCountsSyncTaskFactory(log, splitApi.postTestImpressionsCount, storage.impressionCounts));
|
|
40
|
-
var submitter = syncTaskComposite_1.syncTaskComposite(submitters);
|
|
29
|
+
// It is not inyected as push and polling managers, because at the moment it is required
|
|
30
|
+
var submitter = submitterManager_1.submitterManagerFactory(settings, storage, splitApi);
|
|
41
31
|
/** Sync Manager logic */
|
|
42
32
|
function startPolling() {
|
|
43
33
|
if (!pollingManager.isRunning()) {
|
|
@@ -69,16 +59,18 @@ function syncManagerOnlineFactory(pollingManagerFactory, pushManagerFactory) {
|
|
|
69
59
|
*/
|
|
70
60
|
start: function () {
|
|
71
61
|
// start syncing splits and segments
|
|
72
|
-
if (
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
62
|
+
if (pollingManager) {
|
|
63
|
+
if (pushManager) {
|
|
64
|
+
// Doesn't call `syncAll` when the syncManager is resuming
|
|
65
|
+
if (startFirstTime) {
|
|
66
|
+
pollingManager.syncAll();
|
|
67
|
+
startFirstTime = false;
|
|
68
|
+
}
|
|
69
|
+
pushManager.start();
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
pollingManager.start();
|
|
77
73
|
}
|
|
78
|
-
pushManager.start();
|
|
79
|
-
}
|
|
80
|
-
else {
|
|
81
|
-
pollingManager.start();
|
|
82
74
|
}
|
|
83
75
|
// start periodic data recording (events, impressions, telemetry).
|
|
84
76
|
submitter && submitter.start();
|
|
@@ -91,7 +83,7 @@ function syncManagerOnlineFactory(pollingManagerFactory, pushManagerFactory) {
|
|
|
91
83
|
// stop syncing
|
|
92
84
|
if (pushManager)
|
|
93
85
|
pushManager.stop();
|
|
94
|
-
if (pollingManager.isRunning())
|
|
86
|
+
if (pollingManager && pollingManager.isRunning())
|
|
95
87
|
pollingManager.stop();
|
|
96
88
|
// stop periodic data recording (events, impressions, telemetry).
|
|
97
89
|
if (submitter)
|
|
@@ -108,8 +100,10 @@ function syncManagerOnlineFactory(pollingManagerFactory, pushManagerFactory) {
|
|
|
108
100
|
return Promise.resolve();
|
|
109
101
|
},
|
|
110
102
|
// [Only used for client-side]
|
|
111
|
-
//
|
|
103
|
+
// If polling and push managers are defined (standalone mode), they implement the interfaces for client-side
|
|
112
104
|
shared: function (matchingKey, readinessManager, storage) {
|
|
105
|
+
if (!pollingManager)
|
|
106
|
+
return;
|
|
113
107
|
var mySegmentsSyncTask = pollingManager.add(matchingKey, readinessManager, storage);
|
|
114
108
|
return {
|
|
115
109
|
isRunning: mySegmentsSyncTask.isRunning,
|
|
@@ -6,7 +6,7 @@ var constants_1 = require("../../utils/constants");
|
|
|
6
6
|
* Checks if impressions previous time should be added or not.
|
|
7
7
|
*/
|
|
8
8
|
function shouldAddPt(settings) {
|
|
9
|
-
return [constants_1.PRODUCER_MODE, constants_1.STANDALONE_MODE].indexOf(settings.mode) > -1 ? true : false;
|
|
9
|
+
return [constants_1.PRODUCER_MODE, constants_1.STANDALONE_MODE, constants_1.CONSUMER_PARTIAL_MODE].indexOf(settings.mode) > -1 ? true : false;
|
|
10
10
|
}
|
|
11
11
|
exports.shouldAddPt = shouldAddPt;
|
|
12
12
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.STORAGE_PLUGGABLE = exports.STORAGE_REDIS = exports.STORAGE_LOCALSTORAGE = exports.STORAGE_MEMORY = exports.CONSUMER_PARTIAL_MODE = exports.CONSUMER_MODE = exports.PRODUCER_MODE = exports.STANDALONE_MODE = exports.LOCALHOST_MODE = exports.OPTIMIZED = exports.DEBUG = exports.SPLIT_EVENT = exports.SPLIT_IMPRESSION = exports.NA = exports.UNKNOWN = exports.CONTROL_WITH_CONFIG = exports.CONTROL = void 0;
|
|
4
4
|
// Special treatments
|
|
5
5
|
exports.CONTROL = 'control';
|
|
6
6
|
exports.CONTROL_WITH_CONFIG = {
|
|
@@ -21,8 +21,9 @@ exports.LOCALHOST_MODE = 'localhost';
|
|
|
21
21
|
exports.STANDALONE_MODE = 'standalone';
|
|
22
22
|
exports.PRODUCER_MODE = 'producer';
|
|
23
23
|
exports.CONSUMER_MODE = 'consumer';
|
|
24
|
+
exports.CONSUMER_PARTIAL_MODE = 'consumer_partial';
|
|
24
25
|
// Storage types
|
|
25
26
|
exports.STORAGE_MEMORY = 'MEMORY';
|
|
26
27
|
exports.STORAGE_LOCALSTORAGE = 'LOCALSTORAGE';
|
|
27
28
|
exports.STORAGE_REDIS = 'REDIS';
|
|
28
|
-
exports.
|
|
29
|
+
exports.STORAGE_PLUGGABLE = 'PLUGGABLE';
|
|
@@ -5,7 +5,7 @@ function mode(key, mode) {
|
|
|
5
5
|
// Leaving the comparison as is, in case we change the mode name but not the setting.
|
|
6
6
|
if (key === 'localhost')
|
|
7
7
|
return constants_1.LOCALHOST_MODE;
|
|
8
|
-
if ([constants_1.STANDALONE_MODE, constants_1.PRODUCER_MODE, constants_1.CONSUMER_MODE].indexOf(mode) === -1)
|
|
8
|
+
if ([constants_1.STANDALONE_MODE, constants_1.PRODUCER_MODE, constants_1.CONSUMER_MODE, constants_1.CONSUMER_PARTIAL_MODE].indexOf(mode) === -1)
|
|
9
9
|
throw Error('Invalid mode provided');
|
|
10
10
|
return mode;
|
|
11
11
|
}
|