@splitsoftware/splitio-commons 1.2.1-rc.0 → 1.2.1-rc.11
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/evaluator/Engine.js +6 -6
- package/cjs/evaluator/combiners/and.js +1 -1
- package/cjs/evaluator/combiners/ifelseif.js +2 -2
- package/cjs/evaluator/condition/engineUtils.js +2 -2
- package/cjs/evaluator/condition/index.js +4 -4
- package/cjs/evaluator/index.js +5 -5
- package/cjs/evaluator/matchers/cont_all.js +1 -1
- package/cjs/evaluator/matchers/cont_any.js +1 -1
- package/cjs/evaluator/matchers/cont_str.js +1 -1
- package/cjs/evaluator/matchers/dependency.js +1 -1
- package/cjs/evaluator/matchers/eq_set.js +1 -1
- package/cjs/evaluator/matchers/ew.js +3 -3
- package/cjs/evaluator/matchers/part_of.js +1 -1
- package/cjs/evaluator/matchers/segment.js +1 -1
- package/cjs/evaluator/matchers/sw.js +1 -1
- package/cjs/evaluator/matchers/whitelist.js +1 -1
- package/cjs/evaluator/matchersTransform/index.js +12 -12
- package/cjs/evaluator/parser/index.js +6 -6
- package/cjs/evaluator/treatments/index.js +1 -1
- package/cjs/evaluator/value/index.js +1 -1
- package/cjs/evaluator/value/sanitize.js +4 -4
- package/cjs/integrations/browser.js +3 -3
- package/cjs/integrations/ga/GaToSplit.js +14 -14
- package/cjs/integrations/ga/GoogleAnalyticsToSplit.js +5 -3
- package/cjs/integrations/ga/SplitToGa.js +1 -1
- package/cjs/integrations/ga/SplitToGoogleAnalytics.js +4 -2
- package/cjs/listeners/browser.js +15 -11
- package/cjs/listeners/node.js +1 -1
- package/cjs/logger/constants.js +9 -3
- package/cjs/logger/index.js +2 -2
- package/cjs/logger/messages/debug.js +4 -4
- package/cjs/logger/messages/error.js +5 -4
- package/cjs/logger/messages/info.js +8 -5
- package/cjs/logger/messages/warn.js +1 -1
- package/cjs/logger/sdkLogger.js +1 -1
- package/cjs/readiness/readinessManager.js +2 -2
- package/cjs/readiness/sdkReadinessManager.js +4 -4
- package/cjs/sdkClient/client.js +12 -11
- package/cjs/sdkClient/clientAttributesDecoration.js +4 -4
- package/cjs/sdkClient/clientCS.js +3 -3
- package/cjs/sdkClient/clientInputValidation.js +20 -22
- package/cjs/sdkClient/sdkClient.js +3 -6
- package/cjs/sdkClient/sdkClientMethod.js +1 -1
- package/cjs/sdkClient/sdkClientMethodCS.js +6 -10
- package/cjs/sdkClient/sdkClientMethodCSWithTT.js +7 -15
- package/cjs/sdkFactory/index.js +14 -12
- package/cjs/sdkFactory/userConsentProps.js +40 -0
- package/cjs/sdkManager/index.js +11 -11
- package/cjs/services/splitApi.js +3 -2
- package/cjs/services/splitHttpClient.js +2 -2
- package/cjs/storages/KeyBuilder.js +2 -6
- package/cjs/storages/KeyBuilderCS.js +13 -3
- package/cjs/storages/KeyBuilderSS.js +1 -1
- package/cjs/storages/findLatencyIndex.js +1 -1
- package/cjs/storages/inLocalStorage/MySegmentsCacheInLocal.js +24 -4
- package/cjs/storages/inLocalStorage/SplitsCacheInLocal.js +12 -12
- package/cjs/storages/inLocalStorage/index.js +4 -4
- package/cjs/storages/inMemory/AttributesCacheInMemory.js +1 -1
- package/cjs/storages/inMemory/ImpressionCountsCacheInMemory.js +1 -1
- package/cjs/storages/inMemory/ImpressionsCacheInMemory.js +15 -1
- package/cjs/storages/inMemory/InMemoryStorage.js +1 -1
- package/cjs/storages/inMemory/InMemoryStorageCS.js +1 -1
- package/cjs/storages/inMemory/LatenciesCacheInMemory.js +1 -1
- package/cjs/storages/inMemory/MySegmentsCacheInMemory.js +1 -1
- package/cjs/storages/inMemory/SegmentsCacheInMemory.js +2 -2
- package/cjs/storages/inMemory/SplitsCacheInMemory.js +5 -5
- package/cjs/storages/inRedis/LatenciesCacheInRedis.js +1 -1
- package/cjs/storages/inRedis/RedisAdapter.js +24 -11
- package/cjs/storages/inRedis/SegmentsCacheInRedis.js +1 -1
- package/cjs/storages/inRedis/SplitsCacheInRedis.js +3 -3
- package/cjs/storages/inRedis/index.js +1 -1
- package/cjs/storages/pluggable/SegmentsCachePluggable.js +1 -1
- package/cjs/storages/pluggable/SplitsCachePluggable.js +3 -3
- package/cjs/storages/pluggable/inMemoryWrapper.js +4 -4
- package/cjs/storages/pluggable/index.js +6 -6
- package/cjs/sync/offline/LocalhostFromFile.js +1 -1
- package/cjs/sync/offline/LocalhostFromObject.js +1 -1
- package/cjs/sync/offline/splitsParser/parseCondition.js +1 -1
- package/cjs/sync/offline/splitsParser/splitsParserFromFile.js +13 -13
- package/cjs/sync/offline/splitsParser/splitsParserFromSettings.js +3 -3
- package/cjs/sync/offline/syncManagerOffline.js +1 -1
- package/cjs/sync/offline/syncTasks/fromObjectSyncTask.js +2 -2
- package/cjs/sync/polling/fetchers/mySegmentsFetcher.js +2 -2
- package/cjs/sync/polling/fetchers/segmentChangesFetcher.js +1 -1
- package/cjs/sync/polling/pollingManagerCS.js +8 -7
- package/cjs/sync/polling/pollingManagerSS.js +5 -4
- package/cjs/sync/polling/syncTasks/mySegmentsSyncTask.js +1 -1
- package/cjs/sync/polling/syncTasks/segmentsSyncTask.js +1 -1
- package/cjs/sync/polling/syncTasks/splitsSyncTask.js +1 -1
- package/cjs/sync/polling/updaters/mySegmentsUpdater.js +3 -3
- package/cjs/sync/polling/updaters/segmentChangesUpdater.js +2 -2
- package/cjs/sync/polling/updaters/splitChangesUpdater.js +2 -2
- package/cjs/sync/streaming/AuthClient/index.js +3 -3
- package/cjs/sync/streaming/SSEClient/index.js +2 -1
- package/cjs/sync/streaming/SSEHandler/NotificationParser.js +1 -1
- package/cjs/sync/streaming/SSEHandler/index.js +3 -3
- package/cjs/sync/streaming/UpdateWorkers/SegmentsUpdateWorker.js +1 -1
- package/cjs/sync/streaming/mySegmentsV2utils.js +1 -1
- package/cjs/sync/streaming/pushManager.js +27 -19
- package/cjs/sync/submitters/eventsSyncTask.js +17 -5
- package/cjs/sync/submitters/impressionCountsSyncTask.js +1 -1
- package/cjs/sync/submitters/impressionsSyncTask.js +15 -3
- package/cjs/sync/submitters/metricsSyncTask.js +3 -3
- package/cjs/sync/submitters/submitterManager.js +6 -5
- package/cjs/sync/submitters/submitterSyncTask.js +1 -1
- package/cjs/sync/syncManagerOnline.js +14 -15
- package/cjs/trackers/eventTracker.js +11 -4
- package/cjs/trackers/impressionObserver/impressionObserverCS.js +1 -1
- package/cjs/trackers/impressionObserver/impressionObserverSS.js +1 -1
- package/cjs/trackers/impressionObserver/utils.js +8 -1
- package/cjs/trackers/impressionsTracker.js +9 -8
- package/cjs/utils/MinEvents.js +2 -1
- package/cjs/utils/consent.js +10 -0
- package/cjs/utils/constants/index.js +5 -1
- package/cjs/utils/inputValidation/apiKey.js +1 -1
- package/cjs/utils/inputValidation/attribute.js +4 -4
- package/cjs/utils/inputValidation/attributes.js +2 -2
- package/cjs/utils/inputValidation/event.js +1 -1
- package/cjs/utils/inputValidation/eventProperties.js +7 -5
- package/cjs/utils/inputValidation/eventValue.js +1 -1
- package/cjs/utils/inputValidation/key.js +6 -5
- package/cjs/utils/inputValidation/preloadedData.js +8 -8
- package/cjs/utils/inputValidation/split.js +1 -1
- package/cjs/utils/inputValidation/splits.js +2 -2
- package/cjs/utils/inputValidation/trafficType.js +1 -1
- package/cjs/utils/inputValidation/trafficTypeExistance.js +1 -1
- package/cjs/utils/jwt/index.js +1 -1
- package/cjs/utils/key/index.js +3 -3
- package/cjs/utils/lang/index.js +13 -16
- package/cjs/utils/lang/maps.js +16 -2
- package/cjs/utils/murmur3/common.js +1 -1
- package/cjs/utils/murmur3/murmur3.js +10 -10
- package/cjs/utils/murmur3/murmur3_128.js +1 -1
- package/cjs/utils/murmur3/murmur3_128_x86.js +37 -37
- package/cjs/utils/murmur3/murmur3_64.js +1 -1
- package/cjs/utils/settingsValidation/consent.js +16 -0
- package/cjs/utils/settingsValidation/impressionsMode.js +6 -6
- package/cjs/utils/settingsValidation/index.js +32 -14
- package/cjs/utils/settingsValidation/integrations/configurable.js +1 -1
- package/cjs/utils/settingsValidation/integrations/pluggable.js +1 -1
- package/cjs/utils/settingsValidation/localhost/builtin.js +2 -2
- package/cjs/utils/settingsValidation/logger/builtinLogger.js +3 -3
- package/cjs/utils/settingsValidation/logger/commons.js +1 -1
- package/cjs/utils/settingsValidation/logger/pluggableLogger.js +1 -1
- package/cjs/utils/settingsValidation/runtime.js +11 -0
- package/cjs/utils/settingsValidation/splitFilters.js +1 -1
- package/cjs/utils/settingsValidation/storage/storageCS.js +1 -1
- package/cjs/utils/timeTracker/index.js +3 -3
- package/esm/evaluator/matchers/ew.js +4 -4
- package/esm/integrations/ga/GoogleAnalyticsToSplit.js +4 -2
- package/esm/integrations/ga/SplitToGoogleAnalytics.js +4 -2
- package/esm/listeners/browser.js +14 -10
- package/esm/logger/constants.js +6 -2
- package/esm/logger/messages/debug.js +3 -3
- package/esm/logger/messages/error.js +4 -3
- package/esm/logger/messages/info.js +7 -4
- package/esm/sdkClient/client.js +3 -2
- package/esm/sdkClient/clientCS.js +1 -1
- package/esm/sdkClient/clientInputValidation.js +6 -8
- package/esm/sdkClient/sdkClient.js +1 -4
- package/esm/sdkClient/sdkClientMethodCS.js +1 -5
- package/esm/sdkClient/sdkClientMethodCSWithTT.js +1 -9
- package/esm/sdkFactory/index.js +8 -6
- package/esm/sdkFactory/userConsentProps.js +36 -0
- package/esm/services/splitApi.js +2 -1
- package/esm/storages/KeyBuilder.js +2 -6
- package/esm/storages/KeyBuilderCS.js +11 -1
- package/esm/storages/inLocalStorage/MySegmentsCacheInLocal.js +23 -3
- package/esm/storages/inLocalStorage/index.js +1 -1
- package/esm/storages/inMemory/ImpressionsCacheInMemory.js +15 -1
- package/esm/storages/inMemory/InMemoryStorage.js +1 -1
- package/esm/storages/inMemory/InMemoryStorageCS.js +1 -1
- package/esm/storages/inRedis/RedisAdapter.js +15 -2
- package/esm/storages/pluggable/index.js +2 -2
- package/esm/sync/offline/splitsParser/splitsParserFromFile.js +1 -1
- package/esm/sync/polling/fetchers/mySegmentsFetcher.js +2 -2
- package/esm/sync/polling/fetchers/segmentChangesFetcher.js +2 -2
- package/esm/sync/polling/pollingManagerCS.js +2 -1
- package/esm/sync/polling/pollingManagerSS.js +2 -1
- package/esm/sync/polling/syncTasks/mySegmentsSyncTask.js +1 -1
- package/esm/sync/polling/updaters/mySegmentsUpdater.js +2 -2
- package/esm/sync/streaming/SSEClient/index.js +2 -1
- package/esm/sync/streaming/UpdateWorkers/SegmentsUpdateWorker.js +1 -1
- package/esm/sync/streaming/pushManager.js +13 -5
- package/esm/sync/submitters/eventsSyncTask.js +18 -6
- package/esm/sync/submitters/impressionsSyncTask.js +13 -1
- package/esm/sync/submitters/submitterManager.js +2 -1
- package/esm/sync/syncManagerOnline.js +14 -15
- package/esm/trackers/eventTracker.js +8 -1
- package/esm/trackers/impressionObserver/utils.js +7 -1
- package/esm/trackers/impressionsTracker.js +6 -5
- package/esm/utils/consent.js +6 -0
- package/esm/utils/constants/index.js +4 -0
- package/esm/utils/inputValidation/attributes.js +1 -1
- package/esm/utils/inputValidation/eventProperties.js +4 -2
- package/esm/utils/inputValidation/key.js +2 -1
- package/esm/utils/lang/index.js +12 -15
- package/esm/utils/lang/maps.js +14 -1
- package/esm/utils/settingsValidation/consent.js +12 -0
- package/esm/utils/settingsValidation/impressionsMode.js +7 -7
- package/esm/utils/settingsValidation/index.js +28 -10
- package/esm/utils/settingsValidation/runtime.js +7 -0
- package/package.json +6 -6
- package/src/evaluator/matchers/ew.ts +4 -4
- package/src/evaluator/parser/index.ts +1 -1
- package/src/evaluator/types.ts +2 -2
- package/src/evaluator/value/index.ts +2 -2
- package/src/evaluator/value/sanitize.ts +2 -2
- package/src/integrations/ga/GoogleAnalyticsToSplit.ts +7 -4
- package/src/integrations/ga/SplitToGoogleAnalytics.ts +7 -4
- package/src/integrations/pluggable.ts +2 -2
- package/src/integrations/types.ts +5 -0
- package/src/listeners/browser.ts +13 -9
- package/src/logger/constants.ts +6 -2
- package/src/logger/messages/debug.ts +3 -3
- package/src/logger/messages/error.ts +4 -3
- package/src/logger/messages/info.ts +7 -4
- package/src/logger/types.ts +4 -0
- package/src/sdkClient/client.ts +3 -2
- package/src/sdkClient/clientCS.ts +1 -1
- package/src/sdkClient/clientInputValidation.ts +8 -7
- package/src/sdkClient/sdkClient.ts +2 -5
- package/src/sdkClient/sdkClientMethodCS.ts +1 -6
- package/src/sdkClient/sdkClientMethodCSWithTT.ts +2 -11
- package/src/sdkFactory/index.ts +9 -7
- package/src/sdkFactory/types.ts +2 -1
- package/src/sdkFactory/userConsentProps.ts +42 -0
- package/src/storages/KeyBuilder.ts +2 -6
- package/src/storages/KeyBuilderCS.ts +13 -1
- package/src/storages/inLocalStorage/MySegmentsCacheInLocal.ts +23 -3
- package/src/storages/inLocalStorage/index.ts +1 -1
- package/src/storages/inMemory/ImpressionsCacheInMemory.ts +22 -1
- package/src/storages/inMemory/InMemoryStorage.ts +1 -1
- package/src/storages/inMemory/InMemoryStorageCS.ts +1 -1
- package/src/storages/inRedis/RedisAdapter.ts +8 -2
- package/src/storages/pluggable/index.ts +2 -2
- package/src/storages/types.ts +6 -2
- package/src/sync/offline/splitsParser/splitsParserFromFile.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/pollingManagerCS.ts +3 -6
- package/src/sync/polling/pollingManagerSS.ts +3 -8
- package/src/sync/polling/syncTasks/mySegmentsSyncTask.ts +2 -1
- package/src/sync/polling/types.ts +0 -12
- package/src/sync/polling/updaters/mySegmentsUpdater.ts +2 -1
- package/src/sync/streaming/SSEClient/index.ts +2 -1
- package/src/sync/streaming/UpdateWorkers/SegmentsUpdateWorker.ts +1 -1
- package/src/sync/streaming/pushManager.ts +19 -16
- package/src/sync/streaming/types.ts +5 -25
- package/src/sync/submitters/eventsSyncTask.ts +19 -6
- package/src/sync/submitters/impressionsSyncTask.ts +16 -1
- package/src/sync/submitters/submitterManager.ts +4 -8
- package/src/sync/syncManagerOnline.ts +20 -24
- package/src/sync/types.ts +4 -1
- package/src/trackers/eventTracker.ts +11 -3
- package/src/trackers/impressionObserver/utils.ts +8 -1
- package/src/trackers/impressionsTracker.ts +7 -8
- package/src/types.ts +22 -1
- package/src/utils/consent.ts +8 -0
- package/src/utils/constants/index.ts +5 -0
- package/src/utils/inputValidation/attributes.ts +1 -2
- package/src/utils/inputValidation/eventProperties.ts +4 -2
- package/src/utils/lang/index.ts +15 -18
- package/src/utils/lang/maps.ts +15 -1
- package/src/utils/settingsValidation/consent.ts +16 -0
- package/src/utils/settingsValidation/impressionsMode.ts +8 -8
- package/src/utils/settingsValidation/index.ts +29 -10
- package/src/utils/settingsValidation/runtime.ts +9 -0
- package/src/utils/settingsValidation/types.ts +12 -6
- package/types/evaluator/types.d.ts +2 -2
- package/types/evaluator/value/index.d.ts +1 -1
- package/types/evaluator/value/sanitize.d.ts +1 -1
- package/types/integrations/ga/GoogleAnalyticsToSplit.d.ts +2 -2
- package/types/integrations/ga/SplitToGoogleAnalytics.d.ts +2 -3
- package/types/integrations/types.d.ts +4 -0
- package/types/logger/constants.d.ts +6 -2
- package/types/logger/types.d.ts +4 -0
- package/types/sdkClient/clientAttributesDecoration.d.ts +1 -1
- package/types/sdkClient/clientInputValidation.d.ts +2 -3
- package/types/sdkFactory/types.d.ts +1 -1
- package/types/sdkFactory/userConsentProps.d.ts +6 -0
- package/types/storages/KeyBuilderCS.d.ts +2 -0
- package/types/storages/inMemory/ImpressionsCacheInMemory.d.ts +9 -0
- package/types/storages/inMemory/index.d.ts +10 -0
- package/types/storages/inRedis/RedisAdapter.d.ts +1 -1
- package/types/storages/parseSegments.d.ts +6 -0
- package/types/storages/types.d.ts +3 -1
- package/types/sync/polling/fetchers/mySegmentsFetcher.d.ts +1 -1
- package/types/sync/polling/fetchers/types.d.ts +1 -1
- package/types/sync/polling/pollingManagerCS.d.ts +2 -5
- package/types/sync/polling/pollingManagerSS.d.ts +2 -5
- package/types/sync/polling/types.d.ts +0 -11
- package/types/sync/polling/updaters/mySegmentsUpdater.d.ts +1 -1
- package/types/sync/streaming/UpdateWorkers/SegmentsUpdateWorker.d.ts +1 -1
- package/types/sync/streaming/pushManager.d.ts +3 -7
- package/types/sync/streaming/pushManagerCS.d.ts +1 -12
- package/types/sync/streaming/pushManagerSS.d.ts +1 -11
- package/types/sync/streaming/types.d.ts +3 -23
- package/types/sync/submitters/submitterManager.d.ts +2 -4
- package/types/sync/syncManagerOnline.d.ts +3 -3
- package/types/sync/types.d.ts +3 -0
- package/types/trackers/eventTracker.d.ts +2 -2
- package/types/trackers/impressionObserver/utils.d.ts +4 -0
- package/types/trackers/impressionsTracker.d.ts +2 -3
- package/types/types.d.ts +22 -1
- package/types/utils/consent.d.ts +2 -0
- package/types/utils/constants/index.d.ts +3 -0
- package/types/utils/lang/index.d.ts +6 -5
- package/types/utils/lang/maps.d.ts +7 -0
- package/types/utils/settingsValidation/consent.d.ts +6 -0
- package/types/utils/settingsValidation/impressionsMode.d.ts +1 -1
- package/types/utils/settingsValidation/runtime/browser.d.ts +2 -0
- package/types/utils/settingsValidation/runtime/node.d.ts +2 -0
- package/types/utils/settingsValidation/runtime.d.ts +2 -0
- package/types/utils/settingsValidation/types.d.ts +12 -6
- package/types/utils/settingsValidation/userConsent.d.ts +5 -0
|
@@ -17,6 +17,6 @@ export function clientCSDecorator(log, client, key, trafficType) {
|
|
|
17
17
|
getTreatmentsWithConfig: clientCS.getTreatmentsWithConfig.bind(clientCS, key),
|
|
18
18
|
// Key is bound to the `track` method. Same thing happens with trafficType but only if provided
|
|
19
19
|
track: trafficType ? clientCS.track.bind(clientCS, key, trafficType) : clientCS.track.bind(clientCS, key),
|
|
20
|
-
|
|
20
|
+
isClientSide: true
|
|
21
21
|
});
|
|
22
22
|
}
|
|
@@ -2,12 +2,14 @@ import { objectAssign } from '../utils/lang/objectAssign';
|
|
|
2
2
|
import { validateAttributes, validateEvent, validateEventValue, validateEventProperties, validateKey, validateSplit, validateSplits, validateTrafficType, validateIfNotDestroyed, validateIfOperational } from '../utils/inputValidation';
|
|
3
3
|
import { startsWith } from '../utils/lang';
|
|
4
4
|
import { CONTROL, CONTROL_WITH_CONFIG } from '../utils/constants';
|
|
5
|
+
import { isStorageSync } from '../trackers/impressionObserver/utils';
|
|
5
6
|
/**
|
|
6
7
|
* Decorator that validates the input before actually executing the client methods.
|
|
7
8
|
* We should "guard" the client here, while not polluting the "real" implementation of those methods.
|
|
8
9
|
*/
|
|
9
|
-
export function clientInputValidationDecorator(
|
|
10
|
-
|
|
10
|
+
export function clientInputValidationDecorator(settings, client, readinessManager) {
|
|
11
|
+
var log = settings.log;
|
|
12
|
+
var isSync = isStorageSync(settings);
|
|
11
13
|
/**
|
|
12
14
|
* Avoid repeating this validations code
|
|
13
15
|
*/
|
|
@@ -27,9 +29,7 @@ export function clientInputValidationDecorator(log, client, readinessManager, is
|
|
|
27
29
|
};
|
|
28
30
|
}
|
|
29
31
|
function wrapResult(value) {
|
|
30
|
-
|
|
31
|
-
return value;
|
|
32
|
-
return Promise.resolve(value);
|
|
32
|
+
return isSync ? value : Promise.resolve(value);
|
|
33
33
|
}
|
|
34
34
|
function getTreatment(maybeKey, maybeSplit, maybeAttributes) {
|
|
35
35
|
var params = validateEvaluationParams(maybeKey, maybeSplit, maybeAttributes, 'getTreatment');
|
|
@@ -84,9 +84,7 @@ export function clientInputValidationDecorator(log, client, readinessManager, is
|
|
|
84
84
|
return client.track(key, tt, event, eventValue, properties, size);
|
|
85
85
|
}
|
|
86
86
|
else {
|
|
87
|
-
|
|
88
|
-
return false;
|
|
89
|
-
return Promise.resolve(false);
|
|
87
|
+
return isSync ? false : Promise.resolve(false);
|
|
90
88
|
}
|
|
91
89
|
}
|
|
92
90
|
return {
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { objectAssign } from '../utils/lang/objectAssign';
|
|
2
|
-
import { CONSUMER_MODE, CONSUMER_PARTIAL_MODE } from '../utils/constants';
|
|
3
2
|
import { releaseApiKey } from '../utils/inputValidation/apiKey';
|
|
4
3
|
import { clientFactory } from './client';
|
|
5
4
|
import { clientInputValidationDecorator } from './clientInputValidation';
|
|
@@ -12,9 +11,7 @@ export function sdkClientFactory(params) {
|
|
|
12
11
|
// Proto-linkage of the readiness Event Emitter
|
|
13
12
|
Object.create(sdkReadinessManager.sdkStatus),
|
|
14
13
|
// Client API (getTreatment* & track methods)
|
|
15
|
-
clientInputValidationDecorator(settings
|
|
16
|
-
// storage is async if and only if mode is consumer or partial consumer
|
|
17
|
-
[CONSUMER_MODE, CONSUMER_PARTIAL_MODE].indexOf(settings.mode) === -1 ? true : false),
|
|
14
|
+
clientInputValidationDecorator(settings, clientFactory(params), sdkReadinessManager.readinessManager),
|
|
18
15
|
// Sdk destroy
|
|
19
16
|
{
|
|
20
17
|
destroy: function () {
|
|
@@ -16,12 +16,8 @@ var method = 'Client instantiation';
|
|
|
16
16
|
*/
|
|
17
17
|
export function sdkClientMethodCSFactory(params) {
|
|
18
18
|
var storage = params.storage, syncManager = params.syncManager, sdkReadinessManager = params.sdkReadinessManager, _a = params.settings, key = _a.core.key, readyTimeout = _a.startup.readyTimeout, log = _a.log;
|
|
19
|
-
// Keeping similar behaviour as in the isomorphic JS SDK: if settings key is invalid,
|
|
20
|
-
// `false` value is used as binded key of the default client, but trafficType is ignored
|
|
21
|
-
// @TODO handle as a non-recoverable error
|
|
22
|
-
var validKey = validateKey(log, key, method);
|
|
23
19
|
var mainClientInstance = clientCSDecorator(log, sdkClientFactory(params), // @ts-ignore
|
|
24
|
-
|
|
20
|
+
key);
|
|
25
21
|
var parsedDefaultKey = keyParser(key);
|
|
26
22
|
var defaultInstanceId = buildInstanceId(parsedDefaultKey);
|
|
27
23
|
// Cache instances created per factory.
|
|
@@ -18,16 +18,8 @@ var method = 'Client instantiation';
|
|
|
18
18
|
*/
|
|
19
19
|
export function sdkClientMethodCSFactory(params) {
|
|
20
20
|
var storage = params.storage, syncManager = params.syncManager, sdkReadinessManager = params.sdkReadinessManager, _a = params.settings, _b = _a.core, key = _b.key, trafficType = _b.trafficType, readyTimeout = _a.startup.readyTimeout, log = _a.log;
|
|
21
|
-
// Keeping the behaviour as in the isomorphic JS SDK: if settings key or TT are invalid,
|
|
22
|
-
// `false` value is used as binded key/TT of the default client, which leads to several issues.
|
|
23
|
-
// @TODO update when supporting non-recoverable errors
|
|
24
|
-
var validKey = validateKey(log, key, method);
|
|
25
|
-
var validTrafficType;
|
|
26
|
-
if (trafficType !== undefined) {
|
|
27
|
-
validTrafficType = validateTrafficType(log, trafficType, method);
|
|
28
|
-
}
|
|
29
21
|
var mainClientInstance = clientCSDecorator(log, sdkClientFactory(params), // @ts-ignore
|
|
30
|
-
|
|
22
|
+
key, trafficType);
|
|
31
23
|
var parsedDefaultKey = keyParser(key);
|
|
32
24
|
var defaultInstanceId = buildInstanceId(parsedDefaultKey, trafficType);
|
|
33
25
|
// Cache instances created per factory.
|
package/esm/sdkFactory/index.js
CHANGED
|
@@ -8,11 +8,12 @@ import { createLoggerAPI } from '../logger/sdkLogger';
|
|
|
8
8
|
import { NEW_FACTORY, RETRIEVE_MANAGER } from '../logger/constants';
|
|
9
9
|
import { metadataBuilder } from '../storages/metadataBuilder';
|
|
10
10
|
import { SDK_SPLITS_ARRIVED, SDK_SEGMENTS_ARRIVED } from '../readiness/constants';
|
|
11
|
+
import { objectAssign } from '../utils/lang/objectAssign';
|
|
11
12
|
/**
|
|
12
13
|
* Modular SDK factory
|
|
13
14
|
*/
|
|
14
15
|
export function sdkFactory(params) {
|
|
15
|
-
var settings = params.settings, platform = params.platform, storageFactory = params.storageFactory, splitApiFactory = params.splitApiFactory,
|
|
16
|
+
var settings = params.settings, platform = params.platform, storageFactory = params.storageFactory, splitApiFactory = params.splitApiFactory, extraProps = params.extraProps, syncManagerFactory = params.syncManagerFactory, SignalListener = params.SignalListener, impressionsObserverFactory = params.impressionsObserverFactory, integrationsManagerFactory = params.integrationsManagerFactory, sdkManagerFactory = params.sdkManagerFactory, sdkClientMethodFactory = params.sdkClientMethodFactory;
|
|
16
17
|
var log = settings.log;
|
|
17
18
|
// @TODO handle non-recoverable errors: not start sync, mark the SDK as destroyed, etc.
|
|
18
19
|
// We will just log and allow for the SDK to end up throwing an SDK_TIMEOUT event for devs to handle.
|
|
@@ -22,6 +23,7 @@ export function sdkFactory(params) {
|
|
|
22
23
|
var readinessManager = sdkReadinessManager.readinessManager;
|
|
23
24
|
// @TODO consider passing the settings object, so that each storage access only what it needs
|
|
24
25
|
var storageFactoryParams = {
|
|
26
|
+
impressionsQueueSize: settings.scheduler.impressionsQueueSize,
|
|
25
27
|
eventsQueueSize: settings.scheduler.eventsQueueSize,
|
|
26
28
|
optimize: shouldBeOptimized(settings),
|
|
27
29
|
// ATM, only used by InLocalStorage
|
|
@@ -54,8 +56,8 @@ export function sdkFactory(params) {
|
|
|
54
56
|
var integrationsManager = integrationsManagerFactory && integrationsManagerFactory({ settings: settings, storage: storage });
|
|
55
57
|
// trackers
|
|
56
58
|
var observer = impressionsObserverFactory && impressionsObserverFactory();
|
|
57
|
-
var impressionsTracker = impressionsTrackerFactory(
|
|
58
|
-
var eventTracker = eventTrackerFactory(
|
|
59
|
+
var impressionsTracker = impressionsTrackerFactory(settings, storage.impressions, integrationsManager, observer, storage.impressionCounts);
|
|
60
|
+
var eventTracker = eventTrackerFactory(settings, storage.events, integrationsManager);
|
|
59
61
|
// signal listener
|
|
60
62
|
var signalListener = SignalListener && new SignalListener(syncManager, settings, storage, splitApi);
|
|
61
63
|
// Sdk client and manager
|
|
@@ -64,11 +66,11 @@ export function sdkFactory(params) {
|
|
|
64
66
|
syncManager && syncManager.start();
|
|
65
67
|
signalListener && signalListener.start();
|
|
66
68
|
log.info(NEW_FACTORY);
|
|
67
|
-
|
|
69
|
+
// @ts-ignore
|
|
70
|
+
return objectAssign({
|
|
68
71
|
// Split evaluation and event tracking engine
|
|
69
72
|
client: clientMethod,
|
|
70
73
|
// Manager API to explore available information
|
|
71
|
-
// @ts-ignore
|
|
72
74
|
manager: function () {
|
|
73
75
|
log.debug(RETRIEVE_MANAGER);
|
|
74
76
|
return managerInstance;
|
|
@@ -76,5 +78,5 @@ export function sdkFactory(params) {
|
|
|
76
78
|
// Logger wrapper API
|
|
77
79
|
Logger: createLoggerAPI(settings.log),
|
|
78
80
|
settings: settings,
|
|
79
|
-
};
|
|
81
|
+
}, extraProps && extraProps(settings, syncManager));
|
|
80
82
|
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { ERROR_NOT_BOOLEAN, USER_CONSENT_UPDATED, USER_CONSENT_NOT_UPDATED, USER_CONSENT_INITIAL } from '../logger/constants';
|
|
2
|
+
import { isConsentGranted } from '../utils/consent';
|
|
3
|
+
import { CONSENT_GRANTED, CONSENT_DECLINED } from '../utils/constants';
|
|
4
|
+
import { isBoolean } from '../utils/lang';
|
|
5
|
+
// Extend client-side factory instances with user consent getter/setter
|
|
6
|
+
export function userConsentProps(settings, syncManager) {
|
|
7
|
+
var log = settings.log;
|
|
8
|
+
if (!isConsentGranted(settings))
|
|
9
|
+
log.info(USER_CONSENT_INITIAL, [settings.userConsent]);
|
|
10
|
+
return {
|
|
11
|
+
setUserConsent: function (consent) {
|
|
12
|
+
var _a, _b;
|
|
13
|
+
// validate input param
|
|
14
|
+
if (!isBoolean(consent)) {
|
|
15
|
+
log.warn(ERROR_NOT_BOOLEAN, ['setUserConsent']);
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
var newConsentStatus = consent ? CONSENT_GRANTED : CONSENT_DECLINED;
|
|
19
|
+
if (settings.userConsent !== newConsentStatus) {
|
|
20
|
+
log.info(USER_CONSENT_UPDATED, [settings.userConsent, newConsentStatus]); // @ts-ignore, modify readonly prop
|
|
21
|
+
settings.userConsent = newConsentStatus;
|
|
22
|
+
if (consent)
|
|
23
|
+
(_a = syncManager === null || syncManager === void 0 ? void 0 : syncManager.submitter) === null || _a === void 0 ? void 0 : _a.start(); // resumes submitters if transitioning to GRANTED
|
|
24
|
+
else
|
|
25
|
+
(_b = syncManager === null || syncManager === void 0 ? void 0 : syncManager.submitter) === null || _b === void 0 ? void 0 : _b.stop(); // pauses submitters if transitioning to DECLINED
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
log.info(USER_CONSENT_NOT_UPDATED, [newConsentStatus]);
|
|
29
|
+
}
|
|
30
|
+
return true;
|
|
31
|
+
},
|
|
32
|
+
getUserConsent: function () {
|
|
33
|
+
return settings.userConsent;
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
}
|
package/esm/services/splitApi.js
CHANGED
|
@@ -72,7 +72,8 @@ export function splitApiFactory(settings, platform) {
|
|
|
72
72
|
return splitHttpClient(url, {
|
|
73
73
|
// Adding extra headers to send impressions in OPTIMIZED or DEBUG modes.
|
|
74
74
|
method: 'POST',
|
|
75
|
-
body: body,
|
|
75
|
+
body: body,
|
|
76
|
+
headers: objectAssign({ SplitSDKImpressionsMode: SplitSDKImpressionsMode }, headers)
|
|
76
77
|
});
|
|
77
78
|
},
|
|
78
79
|
/**
|
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { startsWith } from '../utils/lang';
|
|
2
2
|
var everythingAtTheEnd = /[^.]+$/;
|
|
3
3
|
var DEFAULT_PREFIX = 'SPLITIO';
|
|
4
4
|
export function validatePrefix(prefix) {
|
|
5
|
-
return prefix
|
|
6
|
-
endsWith(prefix, '.' + DEFAULT_PREFIX) ?
|
|
7
|
-
prefix : // suffix already appended
|
|
8
|
-
prefix + '.' + DEFAULT_PREFIX : // append suffix
|
|
9
|
-
DEFAULT_PREFIX; // use default prefix if none is provided
|
|
5
|
+
return prefix ? prefix + '.SPLITIO' : 'SPLITIO';
|
|
10
6
|
}
|
|
11
7
|
var KeyBuilder = /** @class */ (function () {
|
|
12
8
|
function KeyBuilder(prefix) {
|
|
@@ -13,9 +13,19 @@ var KeyBuilderCS = /** @class */ (function (_super) {
|
|
|
13
13
|
* @override
|
|
14
14
|
*/
|
|
15
15
|
KeyBuilderCS.prototype.buildSegmentNameKey = function (segmentName) {
|
|
16
|
-
return this.
|
|
16
|
+
return this.prefix + "." + this.matchingKey + ".segment." + segmentName;
|
|
17
17
|
};
|
|
18
18
|
KeyBuilderCS.prototype.extractSegmentName = function (builtSegmentKeyName) {
|
|
19
|
+
var prefix = this.prefix + "." + this.matchingKey + ".segment.";
|
|
20
|
+
if (startsWith(builtSegmentKeyName, prefix))
|
|
21
|
+
return builtSegmentKeyName.substr(prefix.length);
|
|
22
|
+
};
|
|
23
|
+
// @BREAKING: The key used to start with the matching key instead of the prefix, this was changed on version 10.17.3
|
|
24
|
+
KeyBuilderCS.prototype.buildOldSegmentNameKey = function (segmentName) {
|
|
25
|
+
return this.matchingKey + "." + this.prefix + ".segment." + segmentName;
|
|
26
|
+
};
|
|
27
|
+
// @BREAKING: The key used to start with the matching key instead of the prefix, this was changed on version 10.17.3
|
|
28
|
+
KeyBuilderCS.prototype.extractOldSegmentKey = function (builtSegmentKeyName) {
|
|
19
29
|
var prefix = this.matchingKey + "." + this.prefix + ".segment.";
|
|
20
30
|
if (startsWith(builtSegmentKeyName, prefix))
|
|
21
31
|
return builtSegmentKeyName.substr(prefix.length);
|
|
@@ -57,9 +57,29 @@ var MySegmentsCacheInLocal = /** @class */ (function (_super) {
|
|
|
57
57
|
var index;
|
|
58
58
|
// Scan current values from localStorage
|
|
59
59
|
var storedSegmentNames = Object.keys(localStorage).reduce(function (accum, key) {
|
|
60
|
-
var
|
|
61
|
-
if (
|
|
62
|
-
accum.push(
|
|
60
|
+
var segmentName = _this.keys.extractSegmentName(key);
|
|
61
|
+
if (segmentName) {
|
|
62
|
+
accum.push(segmentName);
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
// @BREAKING: This is only to clean up "old" keys. Remove this whole else code block.
|
|
66
|
+
segmentName = _this.keys.extractOldSegmentKey(key);
|
|
67
|
+
if (segmentName) { // this was an old segment key, let's clean up.
|
|
68
|
+
var newSegmentKey = _this.keys.buildSegmentNameKey(segmentName);
|
|
69
|
+
try {
|
|
70
|
+
// If the new format key is not there, create it.
|
|
71
|
+
if (!localStorage.getItem(newSegmentKey) && names.indexOf(segmentName) > -1) {
|
|
72
|
+
localStorage.setItem(newSegmentKey, DEFINED);
|
|
73
|
+
// we are migrating a segment, let's track it.
|
|
74
|
+
accum.push(segmentName);
|
|
75
|
+
}
|
|
76
|
+
localStorage.removeItem(key); // we migrated the current key, let's delete it.
|
|
77
|
+
}
|
|
78
|
+
catch (e) {
|
|
79
|
+
_this.log.error(e);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
63
83
|
return accum;
|
|
64
84
|
}, []);
|
|
65
85
|
// Extreme fast => everything is empty
|
|
@@ -30,7 +30,7 @@ export function InLocalStorage(options) {
|
|
|
30
30
|
return {
|
|
31
31
|
splits: new SplitsCacheInLocal(log, keys, expirationTimestamp, params.splitFiltersValidation),
|
|
32
32
|
segments: new MySegmentsCacheInLocal(log, keys),
|
|
33
|
-
impressions: new ImpressionsCacheInMemory(),
|
|
33
|
+
impressions: new ImpressionsCacheInMemory(params.impressionsQueueSize),
|
|
34
34
|
impressionCounts: params.optimize ? new ImpressionCountsCacheInMemory() : undefined,
|
|
35
35
|
events: new EventsCacheInMemory(params.eventsQueueSize),
|
|
36
36
|
destroy: function () {
|
|
@@ -1,13 +1,27 @@
|
|
|
1
1
|
var ImpressionsCacheInMemory = /** @class */ (function () {
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
*
|
|
4
|
+
* @param impressionsQueueSize number of queued impressions to call onFullQueueCb.
|
|
5
|
+
* Default value is 0, that means no maximum value, in case we want to avoid this being triggered.
|
|
6
|
+
*/
|
|
7
|
+
function ImpressionsCacheInMemory(impressionsQueueSize) {
|
|
8
|
+
if (impressionsQueueSize === void 0) { impressionsQueueSize = 0; }
|
|
9
|
+
this.maxQueue = impressionsQueueSize;
|
|
3
10
|
this.queue = [];
|
|
4
11
|
}
|
|
12
|
+
ImpressionsCacheInMemory.prototype.setOnFullQueueCb = function (cb) {
|
|
13
|
+
this.onFullQueue = cb;
|
|
14
|
+
};
|
|
5
15
|
/**
|
|
6
16
|
* Store impressions in sequential order
|
|
7
17
|
*/
|
|
8
18
|
ImpressionsCacheInMemory.prototype.track = function (data) {
|
|
9
19
|
var _a;
|
|
10
20
|
(_a = this.queue).push.apply(_a, data);
|
|
21
|
+
// Check if the cache queue is full and we need to flush it.
|
|
22
|
+
if (this.maxQueue > 0 && this.queue.length >= this.maxQueue && this.onFullQueue) {
|
|
23
|
+
this.onFullQueue();
|
|
24
|
+
}
|
|
11
25
|
};
|
|
12
26
|
/**
|
|
13
27
|
* Clear the data stored on the cache.
|
|
@@ -13,7 +13,7 @@ export function InMemoryStorageFactory(params) {
|
|
|
13
13
|
return {
|
|
14
14
|
splits: new SplitsCacheInMemory(),
|
|
15
15
|
segments: new SegmentsCacheInMemory(),
|
|
16
|
-
impressions: new ImpressionsCacheInMemory(),
|
|
16
|
+
impressions: new ImpressionsCacheInMemory(params.impressionsQueueSize),
|
|
17
17
|
impressionCounts: params.optimize ? new ImpressionCountsCacheInMemory() : undefined,
|
|
18
18
|
events: new EventsCacheInMemory(params.eventsQueueSize),
|
|
19
19
|
// When using MEMORY we should clean all the caches to leave them empty
|
|
@@ -13,7 +13,7 @@ export function InMemoryStorageCSFactory(params) {
|
|
|
13
13
|
return {
|
|
14
14
|
splits: new SplitsCacheInMemory(),
|
|
15
15
|
segments: new MySegmentsCacheInMemory(),
|
|
16
|
-
impressions: new ImpressionsCacheInMemory(),
|
|
16
|
+
impressions: new ImpressionsCacheInMemory(params.impressionsQueueSize),
|
|
17
17
|
impressionCounts: params.optimize ? new ImpressionCountsCacheInMemory() : undefined,
|
|
18
18
|
events: new EventsCacheInMemory(params.eventsQueueSize),
|
|
19
19
|
// When using MEMORY we should clean all the caches to leave them empty
|
|
@@ -143,15 +143,28 @@ var RedisAdapter = /** @class */ (function (_super) {
|
|
|
143
143
|
else { // If it IS the string URL, that'll be the first param for ioredis.
|
|
144
144
|
result.unshift(options.url);
|
|
145
145
|
}
|
|
146
|
+
if (options.connectionTimeout) {
|
|
147
|
+
merge(opts, { connectTimeout: options.connectionTimeout });
|
|
148
|
+
}
|
|
149
|
+
if (options.tls) {
|
|
150
|
+
merge(opts, { tls: options.tls });
|
|
151
|
+
}
|
|
146
152
|
return result;
|
|
147
153
|
};
|
|
148
154
|
/**
|
|
149
155
|
* Parses the options into what we care about.
|
|
150
156
|
*/
|
|
151
157
|
RedisAdapter._defineOptions = function (_a) {
|
|
152
|
-
var connectionTimeout = _a.connectionTimeout, operationTimeout = _a.operationTimeout, url = _a.url, host = _a.host, port = _a.port, db = _a.db, pass = _a.pass;
|
|
158
|
+
var connectionTimeout = _a.connectionTimeout, operationTimeout = _a.operationTimeout, url = _a.url, host = _a.host, port = _a.port, db = _a.db, pass = _a.pass, tls = _a.tls;
|
|
153
159
|
var parsedOptions = {
|
|
154
|
-
connectionTimeout: connectionTimeout,
|
|
160
|
+
connectionTimeout: connectionTimeout,
|
|
161
|
+
operationTimeout: operationTimeout,
|
|
162
|
+
url: url,
|
|
163
|
+
host: host,
|
|
164
|
+
port: port,
|
|
165
|
+
db: db,
|
|
166
|
+
pass: pass,
|
|
167
|
+
tls: tls
|
|
155
168
|
};
|
|
156
169
|
return merge({}, DEFAULT_OPTIONS, parsedOptions);
|
|
157
170
|
};
|
|
@@ -51,7 +51,7 @@ export function PluggableStorage(options) {
|
|
|
51
51
|
validatePluggableStorageOptions(options);
|
|
52
52
|
var prefix = validatePrefix(options.prefix);
|
|
53
53
|
function PluggableStorageFactory(_a) {
|
|
54
|
-
var log = _a.log, metadata = _a.metadata, onReadyCb = _a.onReadyCb, mode = _a.mode, eventsQueueSize = _a.eventsQueueSize, optimize = _a.optimize;
|
|
54
|
+
var log = _a.log, metadata = _a.metadata, onReadyCb = _a.onReadyCb, mode = _a.mode, eventsQueueSize = _a.eventsQueueSize, impressionsQueueSize = _a.impressionsQueueSize, optimize = _a.optimize;
|
|
55
55
|
var keys = new KeyBuilderSS(prefix, metadata);
|
|
56
56
|
var wrapper = wrapperAdapter(log, options.wrapper);
|
|
57
57
|
var isPartialConsumer = mode === CONSUMER_PARTIAL_MODE;
|
|
@@ -60,7 +60,7 @@ export function PluggableStorage(options) {
|
|
|
60
60
|
return {
|
|
61
61
|
splits: new SplitsCachePluggable(log, keys, wrapper),
|
|
62
62
|
segments: new SegmentsCachePluggable(log, keys, wrapper),
|
|
63
|
-
impressions: isPartialConsumer ? new ImpressionsCacheInMemory() : new ImpressionsCachePluggable(log, keys.buildImpressionsKey(), wrapper, metadata),
|
|
63
|
+
impressions: isPartialConsumer ? new ImpressionsCacheInMemory(impressionsQueueSize) : new ImpressionsCachePluggable(log, keys.buildImpressionsKey(), wrapper, metadata),
|
|
64
64
|
impressionCounts: optimize ? new ImpressionCountsCacheInMemory() : undefined,
|
|
65
65
|
events: isPartialConsumer ? promisifyEventsTrack(new EventsCacheInMemory(eventsQueueSize)) : new EventsCachePluggable(log, keys.buildEventsKey(), wrapper, metadata),
|
|
66
66
|
// @TODO add telemetry cache when required
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
* Factory of MySegments fetcher.
|
|
3
3
|
* MySegments fetcher is a wrapper around `mySegments` API service that parses the response and handle errors.
|
|
4
4
|
*/
|
|
5
|
-
export function mySegmentsFetcherFactory(fetchMySegments
|
|
6
|
-
return function mySegmentsFetcher(noCache,
|
|
5
|
+
export function mySegmentsFetcherFactory(fetchMySegments) {
|
|
6
|
+
return function mySegmentsFetcher(userMatchingKey, noCache,
|
|
7
7
|
// Optional decorator for `fetchMySegments` promise, such as timeout or time tracker
|
|
8
8
|
decorator) {
|
|
9
9
|
var mySegmentsPromise = fetchMySegments(userMatchingKey, noCache);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { __spreadArray } from "tslib";
|
|
2
2
|
function greedyFetch(fetchSegmentChanges, since, segmentName, noCache) {
|
|
3
3
|
return fetchSegmentChanges(since, segmentName, noCache)
|
|
4
4
|
.then(function (resp) { return resp.json(); })
|
|
@@ -9,7 +9,7 @@ function greedyFetch(fetchSegmentChanges, since, segmentName, noCache) {
|
|
|
9
9
|
}
|
|
10
10
|
else {
|
|
11
11
|
return Promise.all([json, greedyFetch(fetchSegmentChanges, till, segmentName, noCache)]).then(function (flatMe) {
|
|
12
|
-
return
|
|
12
|
+
return __spreadArray([flatMe[0]], flatMe[1], true);
|
|
13
13
|
});
|
|
14
14
|
}
|
|
15
15
|
});
|
|
@@ -8,7 +8,8 @@ import { POLLING_SMART_PAUSING, POLLING_START, POLLING_STOP } from '../../logger
|
|
|
8
8
|
* Expose start / stop mechanism for polling data from services.
|
|
9
9
|
* For client-side API with multiple clients.
|
|
10
10
|
*/
|
|
11
|
-
export function pollingManagerCSFactory(
|
|
11
|
+
export function pollingManagerCSFactory(params) {
|
|
12
|
+
var splitApi = params.splitApi, storage = params.storage, readiness = params.readiness, settings = params.settings;
|
|
12
13
|
var log = settings.log;
|
|
13
14
|
var splitsSyncTask = splitsSyncTaskFactory(splitApi.fetchSplitChanges, storage, readiness, settings);
|
|
14
15
|
// Map of matching keys to their corresponding MySegmentsSyncTask.
|
|
@@ -5,7 +5,8 @@ import { POLLING_START, POLLING_STOP, LOG_PREFIX_SYNC_POLLING } from '../../logg
|
|
|
5
5
|
/**
|
|
6
6
|
* Expose start / stop mechanism for pulling data from services.
|
|
7
7
|
*/
|
|
8
|
-
export function pollingManagerSSFactory(
|
|
8
|
+
export function pollingManagerSSFactory(params) {
|
|
9
|
+
var splitApi = params.splitApi, storage = params.storage, readiness = params.readiness, settings = params.settings;
|
|
9
10
|
var log = settings.log;
|
|
10
11
|
var splitsSyncTask = splitsSyncTaskFactory(splitApi.fetchSplitChanges, storage, readiness, settings);
|
|
11
12
|
var segmentsSyncTask = segmentsSyncTaskFactory(splitApi.fetchSegmentChanges, storage, readiness, settings);
|
|
@@ -5,5 +5,5 @@ import { mySegmentsUpdaterFactory } from '../updaters/mySegmentsUpdater';
|
|
|
5
5
|
* Creates a sync task that periodically executes a `mySegmentsUpdater` task
|
|
6
6
|
*/
|
|
7
7
|
export function mySegmentsSyncTaskFactory(fetchMySegments, storage, readiness, settings, matchingKey) {
|
|
8
|
-
return syncTaskFactory(settings.log, mySegmentsUpdaterFactory(settings.log, mySegmentsFetcherFactory(fetchMySegments
|
|
8
|
+
return syncTaskFactory(settings.log, mySegmentsUpdaterFactory(settings.log, mySegmentsFetcherFactory(fetchMySegments), storage.splits, storage.segments, readiness.segments, settings.startup.requestTimeoutBeforeReady, settings.startup.retriesOnFailureBeforeReady, matchingKey), settings.scheduler.segmentsRefreshRate, 'mySegmentsUpdater');
|
|
9
9
|
}
|
|
@@ -7,7 +7,7 @@ import { SYNC_MYSEGMENTS_FETCH_RETRY } from '../../../logger/constants';
|
|
|
7
7
|
* - updates `mySegmentsCache`
|
|
8
8
|
* - uses `segmentsEventEmitter` to emit events related to segments data updates
|
|
9
9
|
*/
|
|
10
|
-
export function mySegmentsUpdaterFactory(log, mySegmentsFetcher, splitsCache, mySegmentsCache, segmentsEventEmitter, requestTimeoutBeforeReady, retriesOnFailureBeforeReady) {
|
|
10
|
+
export function mySegmentsUpdaterFactory(log, mySegmentsFetcher, splitsCache, mySegmentsCache, segmentsEventEmitter, requestTimeoutBeforeReady, retriesOnFailureBeforeReady, matchingKey) {
|
|
11
11
|
var readyOnAlreadyExistentState = true;
|
|
12
12
|
var startingUp = true;
|
|
13
13
|
/** timeout and telemetry decorator for `splitChangesFetcher` promise */
|
|
@@ -51,7 +51,7 @@ export function mySegmentsUpdaterFactory(log, mySegmentsFetcher, splitsCache, my
|
|
|
51
51
|
// If segmentsData is provided, there is no need to fetch mySegments
|
|
52
52
|
new Promise(function (res) { updateSegments(segmentsData); res(true); }) :
|
|
53
53
|
// If not provided, fetch mySegments
|
|
54
|
-
mySegmentsFetcher(noCache, _promiseDecorator).then(function (segments) {
|
|
54
|
+
mySegmentsFetcher(matchingKey, noCache, _promiseDecorator).then(function (segments) {
|
|
55
55
|
// Only when we have downloaded segments completely, we should not keep retrying anymore
|
|
56
56
|
startingUp = false;
|
|
57
57
|
updateSegments(segments);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isString } from '../../../utils/lang';
|
|
1
2
|
var VERSION = '1.1';
|
|
2
3
|
var CONTROL_CHANNEL_REGEX = /^control_/;
|
|
3
4
|
/**
|
|
@@ -8,7 +9,7 @@ var CONTROL_CHANNEL_REGEX = /^control_/;
|
|
|
8
9
|
*/
|
|
9
10
|
function buildSSEHeaders(settings) {
|
|
10
11
|
var headers = {
|
|
11
|
-
SplitSDKClientKey: settings.core.authorizationKey.slice(-4),
|
|
12
|
+
SplitSDKClientKey: isString(settings.core.authorizationKey) ? settings.core.authorizationKey.slice(-4) : '',
|
|
12
13
|
SplitSDKVersion: settings.version,
|
|
13
14
|
};
|
|
14
15
|
// ip and hostname are false if IPAddressesEnabled is false
|
|
@@ -7,7 +7,7 @@ var SegmentsUpdateWorker = /** @class */ (function () {
|
|
|
7
7
|
* @param {Object} segmentsCache segments data cache
|
|
8
8
|
* @param {Object} segmentsSyncTask task for syncing segments data
|
|
9
9
|
*/
|
|
10
|
-
function SegmentsUpdateWorker(
|
|
10
|
+
function SegmentsUpdateWorker(segmentsSyncTask, segmentsCache) {
|
|
11
11
|
this.segmentsCache = segmentsCache;
|
|
12
12
|
this.segmentsSyncTask = segmentsSyncTask;
|
|
13
13
|
this.maxChangeNumbers = {};
|
|
@@ -19,7 +19,8 @@ import { hash64 } from '../../utils/murmur3/murmur3_64';
|
|
|
19
19
|
* - for server-side if key is not provided in settings.
|
|
20
20
|
* - for client-side, with support for multiple clients, if key is provided in settings
|
|
21
21
|
*/
|
|
22
|
-
export function pushManagerFactory(
|
|
22
|
+
export function pushManagerFactory(params, pollingManager) {
|
|
23
|
+
var settings = params.settings, storage = params.storage, splitApi = params.splitApi, readiness = params.readiness, platform = params.platform;
|
|
23
24
|
// `userKey` is the matching key of main client in client-side SDK.
|
|
24
25
|
// It can be used to check if running on client-side or server-side SDK.
|
|
25
26
|
var userKey = settings.core.key ? getMatching(settings.core.key) : undefined;
|
|
@@ -33,14 +34,14 @@ export function pushManagerFactory(pollingManager, storage, readiness, fetchAuth
|
|
|
33
34
|
log.warn(STREAMING_FALLBACK, [e]);
|
|
34
35
|
return;
|
|
35
36
|
}
|
|
36
|
-
var authenticate = authenticateFactory(fetchAuth);
|
|
37
|
+
var authenticate = authenticateFactory(splitApi.fetchAuth);
|
|
37
38
|
// init feedback loop
|
|
38
39
|
var pushEmitter = new platform.EventEmitter();
|
|
39
40
|
var sseHandler = SSEHandlerFactory(log, pushEmitter);
|
|
40
41
|
sseClient.setEventHandler(sseHandler);
|
|
41
42
|
// init workers
|
|
42
43
|
// MySegmentsUpdateWorker (client-side) are initiated in `add` method
|
|
43
|
-
var segmentsUpdateWorker = userKey ? undefined : new SegmentsUpdateWorker(
|
|
44
|
+
var segmentsUpdateWorker = userKey ? undefined : new SegmentsUpdateWorker(pollingManager.segmentsSyncTask, storage.segments);
|
|
44
45
|
// For server-side we pass the segmentsSyncTask, used by SplitsUpdateWorker to fetch new segments
|
|
45
46
|
var splitsUpdateWorker = new SplitsUpdateWorker(storage.splits, pollingManager.splitsSyncTask, readiness.splits, userKey ? undefined : pollingManager.segmentsSyncTask);
|
|
46
47
|
// [Only for client-side] map of hashes to user keys, to dispatch MY_SEGMENTS_UPDATE events to the corresponding MySegmentsUpdateWorker
|
|
@@ -54,6 +55,7 @@ export function pushManagerFactory(pollingManager, storage, readiness, fetchAuth
|
|
|
54
55
|
// It is used to halt the `connectPush` process if it was in progress.
|
|
55
56
|
var disconnected;
|
|
56
57
|
// flag that indicates a PUSH_NONRETRYABLE_ERROR, condition with which starting pushManager again is ignored.
|
|
58
|
+
// true if STREAMING_DISABLED control event, or 'pushEnabled: false', or non-recoverable SSE or Auth errors.
|
|
57
59
|
var disabled; // `disabled` implies `disconnected === true`
|
|
58
60
|
/** PushManager functions related to initialization */
|
|
59
61
|
var connectPushRetryBackoff = new Backoff(connectPush, settings.scheduler.pushRetryBackoffBase);
|
|
@@ -254,13 +256,15 @@ export function pushManagerFactory(pollingManager, storage, readiness, fetchAuth
|
|
|
254
256
|
return objectAssign(
|
|
255
257
|
// Expose Event Emitter functionality and Event constants
|
|
256
258
|
Object.create(pushEmitter), {
|
|
257
|
-
// Stop/pause push mode
|
|
259
|
+
// Stop/pause push mode.
|
|
260
|
+
// It doesn't emit events. Neither PUSH_SUBSYSTEM_DOWN to start polling.
|
|
258
261
|
stop: function () {
|
|
259
262
|
disconnectPush(); // `handleNonRetryableError` cannot be used as `stop`, because it emits PUSH_SUBSYSTEM_DOWN event, which starts polling.
|
|
260
263
|
if (userKey)
|
|
261
264
|
this.remove(userKey); // Necessary to properly resume streaming in client-side (e.g., RN SDK transition to foreground).
|
|
262
265
|
},
|
|
263
|
-
// Start/resume push mode
|
|
266
|
+
// Start/resume push mode.
|
|
267
|
+
// It eventually emits PUSH_SUBSYSTEM_DOWN, that starts polling, or PUSH_SUBSYSTEM_UP, that executes a syncAll
|
|
264
268
|
start: function () {
|
|
265
269
|
// Guard condition to avoid calling `connectPush` again if the `start` method is called multiple times or if push has been disabled.
|
|
266
270
|
if (disabled || disconnected === false)
|
|
@@ -271,6 +275,10 @@ export function pushManagerFactory(pollingManager, storage, readiness, fetchAuth
|
|
|
271
275
|
else
|
|
272
276
|
setTimeout(connectPush); // server-side runs in next cycle as in client-side, for consistency with client-side
|
|
273
277
|
},
|
|
278
|
+
// true/false if start or stop was called last respectively
|
|
279
|
+
isRunning: function () {
|
|
280
|
+
return disconnected === false;
|
|
281
|
+
},
|
|
274
282
|
// [Only for client-side]
|
|
275
283
|
add: function (userKey, mySegmentsSyncTask) {
|
|
276
284
|
var hash = hashUserKey(userKey);
|
|
@@ -1,28 +1,40 @@
|
|
|
1
1
|
import { submitterSyncTaskFactory } from './submitterSyncTask';
|
|
2
|
-
import {
|
|
2
|
+
import { SUBMITTERS_PUSH_FULL_QUEUE } from '../../logger/constants';
|
|
3
|
+
var DATA_NAME = 'events';
|
|
3
4
|
/**
|
|
4
5
|
* Sync task that periodically posts tracked events
|
|
5
6
|
*/
|
|
6
7
|
export function eventsSyncTaskFactory(log, postEventsBulk, eventsCache, eventsPushRate, eventsFirstPushWindow, latencyTracker) {
|
|
7
8
|
// don't retry events.
|
|
8
|
-
var syncTask = submitterSyncTaskFactory(log, postEventsBulk, eventsCache, eventsPushRate,
|
|
9
|
-
// Set a timer for the first push of events
|
|
9
|
+
var syncTask = submitterSyncTaskFactory(log, postEventsBulk, eventsCache, eventsPushRate, DATA_NAME, latencyTracker);
|
|
10
|
+
// Set a timer for the first push window of events.
|
|
11
|
+
// Not implemented in the base submitter or sync task, since this feature is only used by the events submitter.
|
|
10
12
|
if (eventsFirstPushWindow > 0) {
|
|
13
|
+
var running_1 = false;
|
|
11
14
|
var stopEventPublisherTimeout_1;
|
|
12
15
|
var originalStart_1 = syncTask.start;
|
|
13
16
|
syncTask.start = function () {
|
|
17
|
+
running_1 = true;
|
|
14
18
|
stopEventPublisherTimeout_1 = setTimeout(originalStart_1, eventsFirstPushWindow);
|
|
15
19
|
};
|
|
16
20
|
var originalStop_1 = syncTask.stop;
|
|
17
21
|
syncTask.stop = function () {
|
|
22
|
+
running_1 = false;
|
|
18
23
|
clearTimeout(stopEventPublisherTimeout_1);
|
|
19
24
|
originalStop_1();
|
|
20
25
|
};
|
|
26
|
+
syncTask.isRunning = function () {
|
|
27
|
+
return running_1;
|
|
28
|
+
};
|
|
21
29
|
}
|
|
22
|
-
// register
|
|
30
|
+
// register events submitter to be executed when events cache is full
|
|
23
31
|
eventsCache.setOnFullQueueCb(function () {
|
|
24
|
-
|
|
25
|
-
|
|
32
|
+
if (syncTask.isRunning()) {
|
|
33
|
+
log.info(SUBMITTERS_PUSH_FULL_QUEUE, [DATA_NAME]);
|
|
34
|
+
syncTask.execute();
|
|
35
|
+
}
|
|
36
|
+
// If submitter is stopped (e.g., user consent declined or unknown, or app state offline), we don't send the data.
|
|
37
|
+
// Data will be sent when submitter is resumed.
|
|
26
38
|
});
|
|
27
39
|
return syncTask;
|
|
28
40
|
}
|