@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
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { groupBy, forOwn } from '../../utils/lang';
|
|
2
2
|
import { submitterSyncTaskFactory } from './submitterSyncTask';
|
|
3
|
+
import { SUBMITTERS_PUSH_FULL_QUEUE } from '../../logger/constants';
|
|
4
|
+
var DATA_NAME = 'impressions';
|
|
3
5
|
/**
|
|
4
6
|
* Converts `impressions` data from cache into request payload.
|
|
5
7
|
*/
|
|
@@ -32,5 +34,15 @@ export function fromImpressionsCollector(sendLabels, data) {
|
|
|
32
34
|
export function impressionsSyncTaskFactory(log, postTestImpressionsBulk, impressionsCache, impressionsRefreshRate, sendLabels, latencyTracker) {
|
|
33
35
|
if (sendLabels === void 0) { sendLabels = false; }
|
|
34
36
|
// retry impressions only once.
|
|
35
|
-
|
|
37
|
+
var syncTask = submitterSyncTaskFactory(log, postTestImpressionsBulk, impressionsCache, impressionsRefreshRate, DATA_NAME, latencyTracker, fromImpressionsCollector.bind(undefined, sendLabels), 1);
|
|
38
|
+
// register impressions submitter to be executed when impressions cache is full
|
|
39
|
+
impressionsCache.setOnFullQueueCb(function () {
|
|
40
|
+
if (syncTask.isRunning()) {
|
|
41
|
+
log.info(SUBMITTERS_PUSH_FULL_QUEUE, [DATA_NAME]);
|
|
42
|
+
syncTask.execute();
|
|
43
|
+
}
|
|
44
|
+
// If submitter is stopped (e.g., user consent declined or unknown, or app state offline), we don't send the data.
|
|
45
|
+
// Data will be sent when submitter is resumed.
|
|
46
|
+
});
|
|
47
|
+
return syncTask;
|
|
36
48
|
}
|
|
@@ -2,7 +2,8 @@ import { syncTaskComposite } from '../syncTaskComposite';
|
|
|
2
2
|
import { eventsSyncTaskFactory } from './eventsSyncTask';
|
|
3
3
|
import { impressionsSyncTaskFactory } from './impressionsSyncTask';
|
|
4
4
|
import { impressionCountsSyncTaskFactory } from './impressionCountsSyncTask';
|
|
5
|
-
export function submitterManagerFactory(
|
|
5
|
+
export function submitterManagerFactory(params) {
|
|
6
|
+
var settings = params.settings, storage = params.storage, splitApi = params.splitApi;
|
|
6
7
|
var log = settings.log;
|
|
7
8
|
var submitters = [
|
|
8
9
|
impressionsSyncTaskFactory(log, splitApi.postTestImpressionsBulk, storage.impressions, settings.scheduler.impressionsRefreshRate, settings.core.labelsEnabled),
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { submitterManagerFactory } from './submitters/submitterManager';
|
|
2
2
|
import { PUSH_SUBSYSTEM_UP, PUSH_SUBSYSTEM_DOWN } from './streaming/constants';
|
|
3
3
|
import { SYNC_START_POLLING, SYNC_CONTINUE_POLLING, SYNC_STOP_POLLING } from '../logger/constants';
|
|
4
|
+
import { isConsentGranted } from '../utils/consent';
|
|
4
5
|
/**
|
|
5
6
|
* Online SyncManager factory.
|
|
6
7
|
* Can be used for server-side API, and client-side API with or without multiple clients.
|
|
@@ -13,18 +14,17 @@ export function syncManagerOnlineFactory(pollingManagerFactory, pushManagerFacto
|
|
|
13
14
|
/**
|
|
14
15
|
* SyncManager factory for modular SDK
|
|
15
16
|
*/
|
|
16
|
-
return function (
|
|
17
|
-
var settings =
|
|
18
|
-
var log = settings.log;
|
|
17
|
+
return function (params) {
|
|
18
|
+
var settings = params.settings, _a = params.settings, log = _a.log, streamingEnabled = _a.streamingEnabled;
|
|
19
19
|
/** Polling Manager */
|
|
20
|
-
var pollingManager = pollingManagerFactory && pollingManagerFactory(
|
|
20
|
+
var pollingManager = pollingManagerFactory && pollingManagerFactory(params);
|
|
21
21
|
/** Push Manager */
|
|
22
|
-
var pushManager =
|
|
23
|
-
pushManagerFactory(
|
|
22
|
+
var pushManager = streamingEnabled && pollingManager && pushManagerFactory ?
|
|
23
|
+
pushManagerFactory(params, pollingManager) :
|
|
24
24
|
undefined;
|
|
25
25
|
/** Submitter Manager */
|
|
26
26
|
// It is not inyected as push and polling managers, because at the moment it is required
|
|
27
|
-
var submitter = submitterManagerFactory(
|
|
27
|
+
var submitter = submitterManagerFactory(params);
|
|
28
28
|
/** Sync Manager logic */
|
|
29
29
|
function startPolling() {
|
|
30
30
|
if (pollingManager.isRunning()) {
|
|
@@ -50,13 +50,15 @@ export function syncManagerOnlineFactory(pollingManagerFactory, pushManagerFacto
|
|
|
50
50
|
var running = false; // flag that indicates whether the syncManager has been started (true) or stopped (false)
|
|
51
51
|
var startFirstTime = true; // flag to distinguish calling the `start` method for the first time, to support pausing and resuming the synchronization
|
|
52
52
|
return {
|
|
53
|
+
// Exposed for fine-grained control of synchronization.
|
|
54
|
+
// E.g.: user consent, app state changes (Page hide, Foreground/Background, Online/Offline).
|
|
55
|
+
pollingManager: pollingManager,
|
|
53
56
|
pushManager: pushManager,
|
|
57
|
+
submitter: submitter,
|
|
54
58
|
/**
|
|
55
59
|
* Method used to start the syncManager for the first time, or resume it after being stopped.
|
|
56
60
|
*/
|
|
57
61
|
start: function () {
|
|
58
|
-
if (running)
|
|
59
|
-
return;
|
|
60
62
|
running = true;
|
|
61
63
|
// start syncing splits and segments
|
|
62
64
|
if (pollingManager) {
|
|
@@ -73,15 +75,13 @@ export function syncManagerOnlineFactory(pollingManagerFactory, pushManagerFacto
|
|
|
73
75
|
}
|
|
74
76
|
}
|
|
75
77
|
// start periodic data recording (events, impressions, telemetry).
|
|
76
|
-
if (
|
|
78
|
+
if (isConsentGranted(settings))
|
|
77
79
|
submitter.start();
|
|
78
80
|
},
|
|
79
81
|
/**
|
|
80
82
|
* Method used to stop/pause the syncManager.
|
|
81
83
|
*/
|
|
82
84
|
stop: function () {
|
|
83
|
-
if (!running)
|
|
84
|
-
return;
|
|
85
85
|
running = false;
|
|
86
86
|
// stop syncing
|
|
87
87
|
if (pushManager)
|
|
@@ -89,14 +89,13 @@ export function syncManagerOnlineFactory(pollingManagerFactory, pushManagerFacto
|
|
|
89
89
|
if (pollingManager && pollingManager.isRunning())
|
|
90
90
|
pollingManager.stop();
|
|
91
91
|
// stop periodic data recording (events, impressions, telemetry).
|
|
92
|
-
|
|
93
|
-
submitter.stop();
|
|
92
|
+
submitter.stop();
|
|
94
93
|
},
|
|
95
94
|
isRunning: function () {
|
|
96
95
|
return running;
|
|
97
96
|
},
|
|
98
97
|
flush: function () {
|
|
99
|
-
if (
|
|
98
|
+
if (isConsentGranted(settings))
|
|
100
99
|
return submitter.execute();
|
|
101
100
|
else
|
|
102
101
|
return Promise.resolve();
|
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
import { objectAssign } from '../utils/lang/objectAssign';
|
|
2
2
|
import { thenable } from '../utils/promise/thenable';
|
|
3
3
|
import { EVENTS_TRACKER_SUCCESS, ERROR_EVENTS_TRACKER } from '../logger/constants';
|
|
4
|
+
import { CONSENT_DECLINED } from '../utils/constants';
|
|
5
|
+
import { isStorageSync } from './impressionObserver/utils';
|
|
4
6
|
/**
|
|
5
7
|
* Event tracker stores events in cache and pass them to the integrations manager if provided.
|
|
6
8
|
*
|
|
7
9
|
* @param eventsCache cache to save events
|
|
8
10
|
* @param integrationsManager optional event handler used for integrations
|
|
9
11
|
*/
|
|
10
|
-
export function eventTrackerFactory(
|
|
12
|
+
export function eventTrackerFactory(settings, eventsCache, integrationsManager) {
|
|
13
|
+
var log = settings.log;
|
|
14
|
+
var isSync = isStorageSync(settings);
|
|
11
15
|
function queueEventsCallback(eventData, tracked) {
|
|
12
16
|
var eventTypeId = eventData.eventTypeId, trafficTypeName = eventData.trafficTypeName, key = eventData.key, value = eventData.value, timestamp = eventData.timestamp, properties = eventData.properties;
|
|
13
17
|
// Logging every prop would be too much.
|
|
@@ -33,6 +37,9 @@ export function eventTrackerFactory(log, eventsCache, integrationsManager) {
|
|
|
33
37
|
}
|
|
34
38
|
return {
|
|
35
39
|
track: function (eventData, size) {
|
|
40
|
+
if (settings.userConsent === CONSENT_DECLINED) {
|
|
41
|
+
return isSync ? false : Promise.resolve(false);
|
|
42
|
+
}
|
|
36
43
|
var tracked = eventsCache.track(eventData, size);
|
|
37
44
|
if (thenable(tracked)) {
|
|
38
45
|
return tracked.then(queueEventsCallback.bind(null, eventData));
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CONSUMER_PARTIAL_MODE, OPTIMIZED, PRODUCER_MODE, STANDALONE_MODE } from '../../utils/constants';
|
|
1
|
+
import { CONSUMER_MODE, CONSUMER_PARTIAL_MODE, OPTIMIZED, PRODUCER_MODE, STANDALONE_MODE } from '../../utils/constants';
|
|
2
2
|
/**
|
|
3
3
|
* Checks if impressions previous time should be added or not.
|
|
4
4
|
*/
|
|
@@ -13,3 +13,9 @@ export function shouldBeOptimized(settings) {
|
|
|
13
13
|
return false;
|
|
14
14
|
return settings.sync.impressionsMode === OPTIMIZED ? true : false;
|
|
15
15
|
}
|
|
16
|
+
/**
|
|
17
|
+
* Storage is async if mode is consumer or partial consumer
|
|
18
|
+
*/
|
|
19
|
+
export function isStorageSync(settings) {
|
|
20
|
+
return [CONSUMER_MODE, CONSUMER_PARTIAL_MODE].indexOf(settings.mode) === -1 ? true : false;
|
|
21
|
+
}
|
|
@@ -2,6 +2,7 @@ import { objectAssign } from '../utils/lang/objectAssign';
|
|
|
2
2
|
import { thenable } from '../utils/promise/thenable';
|
|
3
3
|
import { truncateTimeFrame } from '../utils/time';
|
|
4
4
|
import { IMPRESSIONS_TRACKER_SUCCESS, ERROR_IMPRESSIONS_TRACKER, ERROR_IMPRESSIONS_LISTENER } from '../logger/constants';
|
|
5
|
+
import { CONSENT_DECLINED } from '../utils/constants';
|
|
5
6
|
/**
|
|
6
7
|
* Impressions tracker stores impressions in cache and pass them to the listener and integrations manager if provided.
|
|
7
8
|
*
|
|
@@ -12,16 +13,16 @@ import { IMPRESSIONS_TRACKER_SUCCESS, ERROR_IMPRESSIONS_TRACKER, ERROR_IMPRESSIO
|
|
|
12
13
|
* @param observer optional impression observer. If provided, previous time (pt property) is included in impression instances
|
|
13
14
|
* @param countsCache optional cache to save impressions count. If provided, impressions will be deduped (OPTIMIZED mode)
|
|
14
15
|
*/
|
|
15
|
-
export function impressionsTrackerFactory(
|
|
16
|
-
// @TODO consider passing only an optional integrationsManager to handle impressions
|
|
17
|
-
_a, impressionListener, integrationsManager,
|
|
16
|
+
export function impressionsTrackerFactory(settings, impressionsCache, integrationsManager,
|
|
18
17
|
// if observer is provided, it implies `shouldAddPreviousTime` flag (i.e., if impressions previous time should be added or not)
|
|
19
18
|
observer,
|
|
20
19
|
// if countsCache is provided, it implies `isOptimized` flag (i.e., if impressions should be deduped or not)
|
|
21
20
|
countsCache) {
|
|
22
|
-
var
|
|
21
|
+
var log = settings.log, impressionListener = settings.impressionListener, _a = settings.runtime, ip = _a.ip, hostname = _a.hostname, version = settings.version;
|
|
23
22
|
return {
|
|
24
23
|
track: function (impressions, attributes) {
|
|
24
|
+
if (settings.userConsent === CONSENT_DECLINED)
|
|
25
|
+
return;
|
|
25
26
|
var impressionsCount = impressions.length;
|
|
26
27
|
var impressionsToStore = []; // Track only the impressions that are going to be stored
|
|
27
28
|
// Wraps impressions to store and adds previousTime if it corresponds
|
|
@@ -65,7 +66,7 @@ countsCache) {
|
|
|
65
66
|
// integrationsManager.handleImpression does not throw errors
|
|
66
67
|
if (integrationsManager)
|
|
67
68
|
integrationsManager.handleImpression(impressionData);
|
|
68
|
-
try { // An exception on the listeners should not break the SDK.
|
|
69
|
+
try { // @ts-ignore. An exception on the listeners should not break the SDK.
|
|
69
70
|
if (impressionListener)
|
|
70
71
|
impressionListener.logImpression(impressionData);
|
|
71
72
|
}
|
|
@@ -24,3 +24,7 @@ export var STORAGE_MEMORY = 'MEMORY';
|
|
|
24
24
|
export var STORAGE_LOCALSTORAGE = 'LOCALSTORAGE';
|
|
25
25
|
export var STORAGE_REDIS = 'REDIS';
|
|
26
26
|
export var STORAGE_PLUGGABLE = 'PLUGGABLE';
|
|
27
|
+
// User consent
|
|
28
|
+
export var CONSENT_GRANTED = 'GRANTED'; // The user has granted consent for tracking events and impressions
|
|
29
|
+
export var CONSENT_DECLINED = 'DECLINED'; // The user has declined consent for tracking events and impressions
|
|
30
|
+
export var CONSENT_UNKNOWN = 'UNKNOWN'; // The user has neither granted nor declined consent for tracking events and impressions
|
|
@@ -3,7 +3,7 @@ import { validateAttribute } from './attribute';
|
|
|
3
3
|
import { ERROR_NOT_PLAIN_OBJECT } from '../../logger/constants';
|
|
4
4
|
export function validateAttributes(log, maybeAttrs, method) {
|
|
5
5
|
// Attributes are optional
|
|
6
|
-
if (
|
|
6
|
+
if (maybeAttrs == undefined || isObject(maybeAttrs)) // eslint-disable-line eqeqeq
|
|
7
7
|
return maybeAttrs;
|
|
8
8
|
log.error(ERROR_NOT_PLAIN_OBJECT, [method, 'attributes']);
|
|
9
9
|
return false;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { isObject,
|
|
1
|
+
import { isObject, isString, isFiniteNumber, isBoolean } from '../lang';
|
|
2
|
+
import { objectAssign } from '../lang/objectAssign';
|
|
2
3
|
import { ERROR_NOT_PLAIN_OBJECT, ERROR_SIZE_EXCEEDED, WARN_SETTING_NULL, WARN_TRIMMING_PROPERTIES } from '../../logger/constants';
|
|
3
4
|
var ECMA_SIZES = {
|
|
4
5
|
NULL: 0,
|
|
@@ -17,7 +18,8 @@ export function validateEventProperties(log, maybeProperties, method) {
|
|
|
17
18
|
return { properties: false, size: BASE_EVENT_SIZE };
|
|
18
19
|
}
|
|
19
20
|
var keys = Object.keys(maybeProperties);
|
|
20
|
-
|
|
21
|
+
// Shallow clone
|
|
22
|
+
var clone = objectAssign({}, maybeProperties);
|
|
21
23
|
// To avoid calculating the size twice we'll return it from here.
|
|
22
24
|
var output = {
|
|
23
25
|
properties: clone,
|
|
@@ -35,7 +35,8 @@ export function validateKey(log, maybeKey, method) {
|
|
|
35
35
|
var bucketingKey = validateKeyValue(log, maybeKey.bucketingKey, method, 'bucketingKey');
|
|
36
36
|
if (matchingKey && bucketingKey)
|
|
37
37
|
return {
|
|
38
|
-
matchingKey: matchingKey,
|
|
38
|
+
matchingKey: matchingKey,
|
|
39
|
+
bucketingKey: bucketingKey
|
|
39
40
|
};
|
|
40
41
|
log.error(ERROR_INVALID_KEY_OBJECT, [method]);
|
|
41
42
|
return false;
|
package/esm/utils/lang/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { __spreadArray } from "tslib";
|
|
2
2
|
/**
|
|
3
3
|
* Checks if the target string ends with the sub string.
|
|
4
4
|
*/
|
|
@@ -141,10 +141,12 @@ export function isNaNNumber(val) {
|
|
|
141
141
|
return val !== val;
|
|
142
142
|
}
|
|
143
143
|
/**
|
|
144
|
-
* Validates if a value is an object
|
|
144
|
+
* Validates if a value is an object created by the Object constructor (plain object).
|
|
145
|
+
* It checks `constructor.name` to avoid false negatives when validating values on a separate VM context, which has its own global built-ins.
|
|
145
146
|
*/
|
|
146
147
|
export function isObject(obj) {
|
|
147
|
-
return obj !== null && typeof obj === 'object' && obj.constructor === Object
|
|
148
|
+
return obj !== null && typeof obj === 'object' && (obj.constructor === Object ||
|
|
149
|
+
(obj.constructor != null && obj.constructor.name === 'Object'));
|
|
148
150
|
}
|
|
149
151
|
/**
|
|
150
152
|
* Checks if a given value is a string.
|
|
@@ -152,6 +154,12 @@ export function isObject(obj) {
|
|
|
152
154
|
export function isString(val) {
|
|
153
155
|
return typeof val === 'string' || val instanceof String;
|
|
154
156
|
}
|
|
157
|
+
/**
|
|
158
|
+
* String sanitizer. Returns the provided value converted to uppercase if it is a string.
|
|
159
|
+
*/
|
|
160
|
+
export function stringToUpperCase(val) {
|
|
161
|
+
return isString(val) ? val.toUpperCase() : val;
|
|
162
|
+
}
|
|
155
163
|
/**
|
|
156
164
|
* Deep copy version of Object.assign using recursion.
|
|
157
165
|
* There are some assumptions here. It's for internal use and we don't need verbose errors
|
|
@@ -179,21 +187,10 @@ export function merge(target, source) {
|
|
|
179
187
|
});
|
|
180
188
|
if (rest && rest.length) {
|
|
181
189
|
var nextSource = rest.splice(0, 1)[0];
|
|
182
|
-
res = merge.apply(void 0,
|
|
190
|
+
res = merge.apply(void 0, __spreadArray([res, nextSource], rest, false));
|
|
183
191
|
}
|
|
184
192
|
return res;
|
|
185
193
|
}
|
|
186
|
-
/**
|
|
187
|
-
* Shallow clone an object
|
|
188
|
-
*/
|
|
189
|
-
export function shallowClone(obj) {
|
|
190
|
-
var keys = Object.keys(obj);
|
|
191
|
-
var output = {};
|
|
192
|
-
for (var i = 0; i < keys.length; i++) {
|
|
193
|
-
output[keys[i]] = obj[keys[i]];
|
|
194
|
-
}
|
|
195
|
-
return output;
|
|
196
|
-
}
|
|
197
194
|
/**
|
|
198
195
|
* Checks if the target string starts with the sub string.
|
|
199
196
|
*/
|
package/esm/utils/lang/maps.js
CHANGED
|
@@ -68,4 +68,17 @@ var MapPoly = /** @class */ (function () {
|
|
|
68
68
|
return MapPoly;
|
|
69
69
|
}());
|
|
70
70
|
export { MapPoly };
|
|
71
|
-
|
|
71
|
+
/**
|
|
72
|
+
* return the Map constructor to use. If native Map is not available or it doesn't support the required features (e.g., IE11),
|
|
73
|
+
* a ponyfill with minimal features is returned instead.
|
|
74
|
+
*
|
|
75
|
+
* Exported for testing purposes only.
|
|
76
|
+
*/
|
|
77
|
+
export function __getMapConstructor() {
|
|
78
|
+
// eslint-disable-next-line compat/compat
|
|
79
|
+
if (typeof Array.from === 'function' && typeof Map === 'function' && Map.prototype && Map.prototype.values) {
|
|
80
|
+
return Map;
|
|
81
|
+
}
|
|
82
|
+
return MapPoly;
|
|
83
|
+
}
|
|
84
|
+
export var _Map = __getMapConstructor();
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ERROR_INVALID_CONFIG_PARAM } from '../../logger/constants';
|
|
2
|
+
import { CONSENT_DECLINED, CONSENT_GRANTED, CONSENT_UNKNOWN } from '../constants';
|
|
3
|
+
import { stringToUpperCase } from '../lang';
|
|
4
|
+
var userConsentValues = [CONSENT_DECLINED, CONSENT_GRANTED, CONSENT_UNKNOWN];
|
|
5
|
+
export function validateConsent(_a) {
|
|
6
|
+
var userConsent = _a.userConsent, log = _a.log;
|
|
7
|
+
userConsent = stringToUpperCase(userConsent);
|
|
8
|
+
if (userConsentValues.indexOf(userConsent) > -1)
|
|
9
|
+
return userConsent;
|
|
10
|
+
log.error(ERROR_INVALID_CONFIG_PARAM, ['userConsent', userConsentValues, CONSENT_GRANTED]);
|
|
11
|
+
return CONSENT_GRANTED;
|
|
12
|
+
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ERROR_INVALID_CONFIG_PARAM } from '../../logger/constants';
|
|
2
2
|
import { DEBUG, OPTIMIZED } from '../constants';
|
|
3
|
+
import { stringToUpperCase } from '../lang';
|
|
3
4
|
export function validImpressionsMode(log, impressionsMode) {
|
|
4
|
-
impressionsMode = impressionsMode
|
|
5
|
-
if ([DEBUG, OPTIMIZED].indexOf(impressionsMode)
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
return impressionsMode;
|
|
5
|
+
impressionsMode = stringToUpperCase(impressionsMode);
|
|
6
|
+
if ([DEBUG, OPTIMIZED].indexOf(impressionsMode) > -1)
|
|
7
|
+
return impressionsMode;
|
|
8
|
+
log.error(ERROR_INVALID_CONFIG_PARAM, ['impressionsMode', [DEBUG, OPTIMIZED], OPTIMIZED]);
|
|
9
|
+
return OPTIMIZED;
|
|
10
10
|
}
|
|
@@ -3,6 +3,8 @@ import { mode } from './mode';
|
|
|
3
3
|
import { validateSplitFilters } from './splitFilters';
|
|
4
4
|
import { STANDALONE_MODE, OPTIMIZED, LOCALHOST_MODE } from '../constants';
|
|
5
5
|
import { validImpressionsMode } from './impressionsMode';
|
|
6
|
+
import { validateKey } from '../inputValidation/key';
|
|
7
|
+
import { validateTrafficType } from '../inputValidation/trafficType';
|
|
6
8
|
var base = {
|
|
7
9
|
// Define which kind of object you want to retrieve from SplitFactory
|
|
8
10
|
mode: STANDALONE_MODE,
|
|
@@ -33,6 +35,8 @@ var base = {
|
|
|
33
35
|
eventsPushRate: 60,
|
|
34
36
|
// how many events will be queued before flushing
|
|
35
37
|
eventsQueueSize: 500,
|
|
38
|
+
// how many impressions will be queued before flushing
|
|
39
|
+
impressionsQueueSize: 30000,
|
|
36
40
|
// backoff base seconds to wait before re attempting to connect to push notifications
|
|
37
41
|
pushRetryBackoffBase: 1,
|
|
38
42
|
},
|
|
@@ -64,10 +68,6 @@ var base = {
|
|
|
64
68
|
impressionsMode: OPTIMIZED,
|
|
65
69
|
localhostMode: undefined
|
|
66
70
|
},
|
|
67
|
-
runtime: {
|
|
68
|
-
ip: false,
|
|
69
|
-
hostname: false
|
|
70
|
-
},
|
|
71
71
|
// Logger
|
|
72
72
|
log: undefined
|
|
73
73
|
};
|
|
@@ -82,7 +82,7 @@ function fromSecondsToMillis(n) {
|
|
|
82
82
|
* @param validationParams defaults and fields validators used to validate and creates a settings object from a given config
|
|
83
83
|
*/
|
|
84
84
|
export function settingsValidation(config, validationParams) {
|
|
85
|
-
var defaults = validationParams.defaults, runtime = validationParams.runtime, storage = validationParams.storage, integrations = validationParams.integrations, logger = validationParams.logger, localhost = validationParams.localhost;
|
|
85
|
+
var defaults = validationParams.defaults, runtime = validationParams.runtime, storage = validationParams.storage, integrations = validationParams.integrations, logger = validationParams.logger, localhost = validationParams.localhost, consent = validationParams.consent;
|
|
86
86
|
// creates a settings object merging base, defaults and config objects.
|
|
87
87
|
var withDefaults = merge({}, base, defaults, config);
|
|
88
88
|
// ensure a valid logger.
|
|
@@ -108,14 +108,29 @@ export function settingsValidation(config, validationParams) {
|
|
|
108
108
|
// @ts-ignore, modify readonly prop
|
|
109
109
|
if (storage)
|
|
110
110
|
withDefaults.storage = storage(withDefaults);
|
|
111
|
-
//
|
|
112
|
-
if (
|
|
113
|
-
withDefaults.core.key
|
|
111
|
+
// Validate key and TT (for client-side)
|
|
112
|
+
if (validationParams.acceptKey) {
|
|
113
|
+
var maybeKey = withDefaults.core.key;
|
|
114
|
+
// Although `key` is required in client-side, it can be omitted in LOCALHOST mode. In that case, the value `localhost_key` is used.
|
|
115
|
+
if (withDefaults.mode === LOCALHOST_MODE && maybeKey === undefined) {
|
|
116
|
+
withDefaults.core.key = 'localhost_key';
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
// Keeping same behaviour than JS SDK: if settings key or TT are invalid,
|
|
120
|
+
// `false` value is used as binded key/TT of the default client, which leads to some issues.
|
|
121
|
+
// @ts-ignore, @TODO handle invalid keys as a non-recoverable error?
|
|
122
|
+
withDefaults.core.key = validateKey(log, maybeKey, 'Client instantiation');
|
|
123
|
+
}
|
|
124
|
+
if (validationParams.acceptTT) {
|
|
125
|
+
var maybeTT = withDefaults.core.trafficType;
|
|
126
|
+
if (maybeTT !== undefined) { // @ts-ignore
|
|
127
|
+
withDefaults.core.trafficType = validateTrafficType(log, maybeTT, 'Client instantiation');
|
|
128
|
+
}
|
|
129
|
+
}
|
|
114
130
|
}
|
|
115
131
|
// Current ip/hostname information
|
|
116
132
|
// @ts-ignore, modify readonly prop
|
|
117
|
-
|
|
118
|
-
withDefaults.runtime = runtime(withDefaults);
|
|
133
|
+
withDefaults.runtime = runtime(withDefaults);
|
|
119
134
|
// ensure a valid list of integrations.
|
|
120
135
|
// `integrations` returns an array of valid integration items.
|
|
121
136
|
// @ts-ignore, modify readonly prop
|
|
@@ -136,5 +151,8 @@ export function settingsValidation(config, validationParams) {
|
|
|
136
151
|
withDefaults.sync.__splitFiltersValidation = splitFiltersValidation;
|
|
137
152
|
// ensure a valid impressionsMode
|
|
138
153
|
withDefaults.sync.impressionsMode = validImpressionsMode(log, withDefaults.sync.impressionsMode);
|
|
154
|
+
// ensure a valid user consent value
|
|
155
|
+
// @ts-ignore, modify readonly prop
|
|
156
|
+
withDefaults.userConsent = consent(withDefaults);
|
|
139
157
|
return withDefaults;
|
|
140
158
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@splitsoftware/splitio-commons",
|
|
3
|
-
"version": "1.2.1-rc.
|
|
3
|
+
"version": "1.2.1-rc.11",
|
|
4
4
|
"description": "Split Javascript SDK common components",
|
|
5
5
|
"main": "cjs/index.js",
|
|
6
6
|
"module": "esm/index.js",
|
|
@@ -20,8 +20,8 @@
|
|
|
20
20
|
"check:lint": "eslint src --ext .js,.ts",
|
|
21
21
|
"check:types": "tsc --noEmit",
|
|
22
22
|
"build": "npm run build:cjs && npm run build:esm",
|
|
23
|
-
"build:esm": "rimraf esm && tsc -m es2015 --outDir esm -d true --declarationDir types
|
|
24
|
-
"build:cjs": "rimraf cjs && tsc -m CommonJS --outDir cjs
|
|
23
|
+
"build:esm": "rimraf esm && tsc -m es2015 --outDir esm -d true --declarationDir types",
|
|
24
|
+
"build:cjs": "rimraf cjs && tsc -m CommonJS --outDir cjs",
|
|
25
25
|
"test": "jest",
|
|
26
26
|
"test:coverage": "jest --coverage",
|
|
27
27
|
"publish:rc": "npm run check && npm run test && npm run build && npm publish --tag rc",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"bugs": "https://github.com/splitio/javascript-commons/issues",
|
|
45
45
|
"homepage": "https://github.com/splitio/javascript-commons#readme",
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"tslib": "^2.1
|
|
47
|
+
"tslib": "^2.3.1"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
50
|
"@types/google.analytics": "0.0.40",
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
"eslint": "^7.32.0",
|
|
59
59
|
"eslint-plugin-compat": "3.7.0",
|
|
60
60
|
"eslint-plugin-import": "^2.25.3",
|
|
61
|
-
"fetch-mock": "^9.
|
|
61
|
+
"fetch-mock": "^9.11.0",
|
|
62
62
|
"ioredis": "^4.28.0",
|
|
63
63
|
"jest": "^27.2.3",
|
|
64
64
|
"jest-localstorage-mock": "^2.4.3",
|
|
@@ -68,7 +68,7 @@
|
|
|
68
68
|
"redis-server": "1.2.2",
|
|
69
69
|
"rimraf": "^3.0.2",
|
|
70
70
|
"ts-jest": "^27.0.5",
|
|
71
|
-
"typescript": "
|
|
71
|
+
"typescript": "4.4.4"
|
|
72
72
|
},
|
|
73
73
|
"sideEffects": false
|
|
74
74
|
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { ENGINE_MATCHER_ENDS_WITH } from '../../logger/constants';
|
|
2
2
|
import { ILogger } from '../../logger/types';
|
|
3
|
-
import { endsWith
|
|
3
|
+
import { endsWith } from '../../utils/lang';
|
|
4
4
|
|
|
5
5
|
export function endsWithMatcherContext(log: ILogger, ruleAttr: string[]) /*: Function */ {
|
|
6
6
|
return function endsWithMatcher(runtimeAttr: string): boolean {
|
|
7
|
-
let
|
|
7
|
+
let strEndsWith = ruleAttr.some(e => endsWith(runtimeAttr, e));
|
|
8
8
|
|
|
9
|
-
log.debug(ENGINE_MATCHER_ENDS_WITH, [runtimeAttr, ruleAttr,
|
|
9
|
+
log.debug(ENGINE_MATCHER_ENDS_WITH, [runtimeAttr, ruleAttr, strEndsWith]);
|
|
10
10
|
|
|
11
|
-
return
|
|
11
|
+
return strEndsWith;
|
|
12
12
|
};
|
|
13
13
|
}
|
|
@@ -31,7 +31,7 @@ export function parser(log: ILogger, conditions: ISplitCondition[], storage: ISt
|
|
|
31
31
|
const matcher = matcherFactory(log, matcherDto, storage);
|
|
32
32
|
|
|
33
33
|
// Evaluator function.
|
|
34
|
-
return (key: string, attributes: SplitIO.Attributes, splitEvaluator: ISplitEvaluator) => {
|
|
34
|
+
return (key: string, attributes: SplitIO.Attributes | undefined, splitEvaluator: ISplitEvaluator) => {
|
|
35
35
|
const value = sanitizeValue(log, key, matcherDto, attributes);
|
|
36
36
|
const result = value !== undefined && matcher ? matcher(value, splitEvaluator) : false;
|
|
37
37
|
|
package/src/evaluator/types.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { ILogger } from '../logger/types';
|
|
|
6
6
|
|
|
7
7
|
export interface IDependencyMatcherValue {
|
|
8
8
|
key: SplitIO.SplitKey,
|
|
9
|
-
attributes
|
|
9
|
+
attributes?: SplitIO.Attributes
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
export interface IMatcherDto {
|
|
@@ -27,7 +27,7 @@ export interface IEvaluation {
|
|
|
27
27
|
|
|
28
28
|
export type IEvaluationResult = IEvaluation & { treatment: string }
|
|
29
29
|
|
|
30
|
-
export type ISplitEvaluator = (log: ILogger, key: SplitIO.SplitKey, splitName: string, attributes: SplitIO.Attributes, storage: IStorageSync | IStorageAsync) => MaybeThenable<IEvaluation>
|
|
30
|
+
export type ISplitEvaluator = (log: ILogger, key: SplitIO.SplitKey, splitName: string, attributes: SplitIO.Attributes | undefined, storage: IStorageSync | IStorageAsync) => MaybeThenable<IEvaluation>
|
|
31
31
|
|
|
32
32
|
export type IEvaluator = (key: SplitIO.SplitKey, seed: number, trafficAllocation?: number, trafficAllocationSeed?: number, attributes?: SplitIO.Attributes, splitEvaluator?: ISplitEvaluator) => MaybeThenable<IEvaluation | undefined>
|
|
33
33
|
|
|
@@ -4,7 +4,7 @@ import { ILogger } from '../../logger/types';
|
|
|
4
4
|
import { sanitize } from './sanitize';
|
|
5
5
|
import { ENGINE_VALUE, ENGINE_VALUE_NO_ATTRIBUTES, ENGINE_VALUE_INVALID } from '../../logger/constants';
|
|
6
6
|
|
|
7
|
-
function parseValue(log: ILogger, key: string, attributeName: string | null, attributes
|
|
7
|
+
function parseValue(log: ILogger, key: string, attributeName: string | null, attributes?: SplitIO.Attributes) {
|
|
8
8
|
let value = undefined;
|
|
9
9
|
if (attributeName) {
|
|
10
10
|
if (attributes) {
|
|
@@ -23,7 +23,7 @@ function parseValue(log: ILogger, key: string, attributeName: string | null, att
|
|
|
23
23
|
/**
|
|
24
24
|
* Defines value to be matched (key / attribute).
|
|
25
25
|
*/
|
|
26
|
-
export function sanitizeValue(log: ILogger, key: string, matcherDto: IMatcherDto, attributes
|
|
26
|
+
export function sanitizeValue(log: ILogger, key: string, matcherDto: IMatcherDto, attributes?: SplitIO.Attributes) {
|
|
27
27
|
const attributeName = matcherDto.attribute;
|
|
28
28
|
const valueToMatch = parseValue(log, key, attributeName, attributes);
|
|
29
29
|
const sanitizedValue = sanitize(log, matcherDto.type, valueToMatch, matcherDto.dataType, attributes);
|
|
@@ -41,7 +41,7 @@ function sanitizeBoolean(val: any): boolean | undefined {
|
|
|
41
41
|
return undefined;
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
function dependencyProcessor(sanitizedValue: string, attributes
|
|
44
|
+
function dependencyProcessor(sanitizedValue: string, attributes?: SplitIO.Attributes): IDependencyMatcherValue {
|
|
45
45
|
return {
|
|
46
46
|
key: sanitizedValue,
|
|
47
47
|
attributes
|
|
@@ -69,7 +69,7 @@ function getProcessingFunction(matcherTypeID: number, dataType: string) {
|
|
|
69
69
|
/**
|
|
70
70
|
* Sanitize matcher value
|
|
71
71
|
*/
|
|
72
|
-
export function sanitize(log: ILogger, matcherTypeID: number, value: string | number | boolean | Array<string | number> | undefined, dataType: string, attributes
|
|
72
|
+
export function sanitize(log: ILogger, matcherTypeID: number, value: string | number | boolean | Array<string | number> | undefined, dataType: string, attributes?: SplitIO.Attributes) {
|
|
73
73
|
const processor = getProcessingFunction(matcherTypeID, dataType);
|
|
74
74
|
let sanitizedValue: string | number | boolean | Array<string | number> | IDependencyMatcherValue | undefined;
|
|
75
75
|
|
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
import { IIntegrationFactoryParams } from '../types';
|
|
1
|
+
import { IIntegrationFactoryParams, IntegrationFactory } from '../types';
|
|
2
2
|
import { GaToSplit } from './GaToSplit';
|
|
3
3
|
import { GoogleAnalyticsToSplitOptions } from './types';
|
|
4
4
|
|
|
5
|
-
export function GoogleAnalyticsToSplit(options: GoogleAnalyticsToSplitOptions) {
|
|
5
|
+
export function GoogleAnalyticsToSplit(options: GoogleAnalyticsToSplitOptions): IntegrationFactory {
|
|
6
6
|
|
|
7
7
|
// GaToSplit integration factory
|
|
8
|
-
|
|
8
|
+
function GoogleAnalyticsToSplitFactory(params: IIntegrationFactoryParams) {
|
|
9
9
|
return GaToSplit(options, params);
|
|
10
|
-
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
GoogleAnalyticsToSplitFactory.type = 'GOOGLE_ANALYTICS_TO_SPLIT';
|
|
13
|
+
return GoogleAnalyticsToSplitFactory;
|
|
11
14
|
}
|
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
import { IIntegrationFactoryParams } from '../types';
|
|
1
|
+
import { IIntegrationFactoryParams, IntegrationFactory } from '../types';
|
|
2
2
|
import { SplitToGa } from './SplitToGa';
|
|
3
3
|
import { SplitToGoogleAnalyticsOptions } from './types';
|
|
4
4
|
|
|
5
|
-
export function SplitToGoogleAnalytics(options: SplitToGoogleAnalyticsOptions = {}) {
|
|
5
|
+
export function SplitToGoogleAnalytics(options: SplitToGoogleAnalyticsOptions = {}): IntegrationFactory {
|
|
6
6
|
|
|
7
7
|
// SplitToGa integration factory
|
|
8
|
-
|
|
8
|
+
function SplitToGoogleAnalyticsFactory(params: IIntegrationFactoryParams) {
|
|
9
9
|
return new SplitToGa(params.settings.log, options);
|
|
10
|
-
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
SplitToGoogleAnalyticsFactory.type = 'SPLIT_TO_GOOGLE_ANALYTICS';
|
|
13
|
+
return SplitToGoogleAnalyticsFactory;
|
|
11
14
|
}
|