@splitsoftware/splitio-commons 1.6.2-rc.3 → 1.6.2-rc.6
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/index.js +10 -11
- package/cjs/integrations/ga/GaToSplit.js +8 -5
- package/cjs/sdkFactory/index.js +2 -3
- package/cjs/sdkManager/index.js +3 -11
- package/cjs/services/splitApi.js +0 -1
- package/cjs/storages/AbstractSplitsCacheAsync.js +7 -9
- package/cjs/storages/AbstractSplitsCacheSync.js +7 -9
- package/cjs/storages/dataLoader.js +1 -1
- package/cjs/storages/inLocalStorage/SplitsCacheInLocal.js +5 -6
- package/cjs/storages/inMemory/SplitsCacheInMemory.js +7 -10
- package/cjs/storages/inRedis/SplitsCacheInRedis.js +15 -9
- package/cjs/storages/pluggable/SplitsCachePluggable.js +14 -9
- package/cjs/sync/offline/syncTasks/fromObjectSyncTask.js +2 -3
- package/cjs/sync/polling/updaters/splitChangesUpdater.js +1 -1
- package/cjs/trackers/telemetryTracker.js +6 -0
- package/cjs/types.js +2 -0
- package/cjs/utils/key/index.js +1 -1
- package/cjs/utils/settingsValidation/index.js +0 -1
- package/esm/evaluator/index.js +10 -11
- package/esm/integrations/ga/GaToSplit.js +8 -5
- package/esm/sdkFactory/index.js +2 -3
- package/esm/sdkManager/index.js +3 -11
- package/esm/services/splitApi.js +0 -1
- package/esm/storages/AbstractSplitsCacheAsync.js +7 -9
- package/esm/storages/AbstractSplitsCacheSync.js +7 -9
- package/esm/storages/dataLoader.js +1 -1
- package/esm/storages/inLocalStorage/SplitsCacheInLocal.js +5 -6
- package/esm/storages/inMemory/SplitsCacheInMemory.js +7 -10
- package/esm/storages/inRedis/SplitsCacheInRedis.js +15 -9
- package/esm/storages/pluggable/SplitsCachePluggable.js +14 -9
- package/esm/sync/offline/syncTasks/fromObjectSyncTask.js +2 -3
- package/esm/sync/polling/updaters/splitChangesUpdater.js +1 -1
- package/esm/trackers/telemetryTracker.js +6 -0
- package/esm/types.js +1 -0
- package/esm/utils/key/index.js +1 -1
- package/esm/utils/settingsValidation/index.js +0 -1
- package/package.json +2 -2
- package/src/consent/sdkUserConsent.ts +3 -4
- package/src/dtos/types.ts +8 -0
- package/src/evaluator/Engine.ts +3 -3
- package/src/evaluator/combiners/and.ts +1 -1
- package/src/evaluator/combiners/ifelseif.ts +3 -3
- package/src/evaluator/condition/engineUtils.ts +1 -1
- package/src/evaluator/condition/index.ts +6 -6
- package/src/evaluator/index.ts +18 -19
- package/src/evaluator/matchers/all.ts +1 -1
- package/src/evaluator/matchers/between.ts +1 -1
- package/src/evaluator/matchers/boolean.ts +1 -1
- package/src/evaluator/matchers/cont_all.ts +1 -1
- package/src/evaluator/matchers/cont_any.ts +1 -1
- package/src/evaluator/matchers/cont_str.ts +1 -1
- package/src/evaluator/matchers/dependency.ts +1 -1
- package/src/evaluator/matchers/eq.ts +1 -1
- package/src/evaluator/matchers/eq_set.ts +1 -1
- package/src/evaluator/matchers/ew.ts +1 -1
- package/src/evaluator/matchers/gte.ts +1 -1
- package/src/evaluator/matchers/index.ts +1 -1
- package/src/evaluator/matchers/lte.ts +1 -1
- package/src/evaluator/matchers/part_of.ts +1 -1
- package/src/evaluator/matchers/segment.ts +1 -1
- package/src/evaluator/matchers/string.ts +1 -1
- package/src/evaluator/matchers/sw.ts +1 -1
- package/src/evaluator/matchers/whitelist.ts +1 -1
- package/src/evaluator/parser/index.ts +3 -3
- package/src/evaluator/types.ts +6 -6
- package/src/evaluator/value/index.ts +4 -4
- package/src/evaluator/value/sanitize.ts +4 -4
- package/src/integrations/ga/GaToSplit.ts +15 -11
- package/src/integrations/ga/SplitToGa.ts +10 -10
- package/src/integrations/ga/types.ts +4 -4
- package/src/integrations/pluggable.ts +3 -3
- package/src/integrations/types.ts +4 -3
- package/src/logger/index.ts +3 -3
- package/src/logger/sdkLogger.ts +2 -1
- package/src/logger/types.ts +16 -0
- package/src/readiness/sdkReadinessManager.ts +1 -1
- package/src/readiness/types.ts +9 -2
- package/src/sdkClient/client.ts +13 -13
- package/src/sdkClient/clientAttributesDecoration.ts +9 -9
- package/src/sdkClient/clientCS.ts +4 -3
- package/src/sdkClient/clientInputValidation.ts +15 -15
- package/src/sdkClient/sdkClient.ts +2 -2
- package/src/sdkClient/sdkClientMethod.ts +2 -2
- package/src/sdkClient/sdkClientMethodCS.ts +9 -9
- package/src/sdkClient/sdkClientMethodCSWithTT.ts +9 -9
- package/src/sdkFactory/index.ts +4 -5
- package/src/sdkFactory/types.ts +4 -4
- package/src/sdkManager/index.ts +7 -16
- package/src/services/splitApi.ts +0 -1
- package/src/storages/AbstractSplitsCacheAsync.ts +13 -14
- package/src/storages/AbstractSplitsCacheSync.ts +14 -16
- package/src/storages/dataLoader.ts +3 -3
- package/src/storages/inLocalStorage/MySegmentsCacheInLocal.ts +1 -1
- package/src/storages/inLocalStorage/SplitsCacheInLocal.ts +10 -12
- package/src/storages/inLocalStorage/index.ts +2 -3
- package/src/storages/inMemory/EventsCacheInMemory.ts +4 -4
- package/src/storages/inMemory/SplitsCacheInMemory.ts +10 -14
- package/src/storages/inRedis/EventsCacheInRedis.ts +4 -4
- package/src/storages/inRedis/ImpressionsCacheInRedis.ts +1 -1
- package/src/storages/inRedis/RedisAdapter.ts +1 -1
- package/src/storages/inRedis/SegmentsCacheInRedis.ts +1 -1
- package/src/storages/inRedis/SplitsCacheInRedis.ts +22 -18
- package/src/storages/inRedis/TelemetryCacheInRedis.ts +1 -1
- package/src/storages/inRedis/index.ts +2 -3
- package/src/storages/pluggable/EventsCachePluggable.ts +4 -4
- package/src/storages/pluggable/ImpressionsCachePluggable.ts +1 -1
- package/src/storages/pluggable/SegmentsCachePluggable.ts +1 -1
- package/src/storages/pluggable/SplitsCachePluggable.ts +21 -18
- package/src/storages/pluggable/TelemetryCachePluggable.ts +1 -1
- package/src/storages/pluggable/index.ts +3 -3
- package/src/storages/pluggable/wrapperAdapter.ts +1 -1
- package/src/storages/types.ts +30 -54
- package/src/sync/offline/LocalhostFromObject.ts +4 -4
- package/src/sync/offline/splitsParser/splitsParserFromSettings.ts +8 -8
- package/src/sync/offline/syncTasks/fromObjectSyncTask.ts +5 -6
- package/src/sync/polling/updaters/mySegmentsUpdater.ts +1 -1
- package/src/sync/polling/updaters/segmentChangesUpdater.ts +1 -1
- package/src/sync/polling/updaters/splitChangesUpdater.ts +3 -3
- package/src/sync/streaming/SSEHandler/index.ts +1 -1
- package/src/sync/streaming/UpdateWorkers/SegmentsUpdateWorker.ts +1 -1
- package/src/sync/streaming/UpdateWorkers/SplitsUpdateWorker.ts +1 -1
- package/src/sync/submitters/submitter.ts +1 -1
- package/src/sync/submitters/types.ts +2 -2
- package/src/sync/syncTask.ts +1 -1
- package/src/trackers/eventTracker.ts +3 -3
- package/src/trackers/impressionsTracker.ts +3 -3
- package/src/trackers/telemetryTracker.ts +7 -2
- package/src/trackers/types.ts +8 -4
- package/src/types.ts +1263 -0
- package/src/utils/constants/index.ts +1 -1
- package/src/utils/inputValidation/apiKey.ts +1 -1
- package/src/utils/inputValidation/attribute.ts +1 -1
- package/src/utils/inputValidation/attributes.ts +3 -3
- package/src/utils/inputValidation/event.ts +1 -1
- package/src/utils/inputValidation/eventProperties.ts +3 -3
- package/src/utils/inputValidation/eventValue.ts +1 -1
- package/src/utils/inputValidation/isOperational.ts +1 -1
- package/src/utils/inputValidation/key.ts +3 -3
- package/src/utils/inputValidation/preloadedData.ts +3 -3
- package/src/utils/inputValidation/split.ts +1 -1
- package/src/utils/inputValidation/splitExistance.ts +1 -1
- package/src/utils/inputValidation/splits.ts +1 -1
- package/src/utils/inputValidation/trafficType.ts +1 -1
- package/src/utils/inputValidation/trafficTypeExistance.ts +1 -1
- package/src/utils/key/index.ts +9 -9
- package/src/utils/settingsValidation/consent.ts +2 -1
- package/src/utils/settingsValidation/impressionsMode.ts +3 -3
- package/src/utils/settingsValidation/index.ts +0 -1
- package/src/utils/settingsValidation/integrations/common.ts +1 -1
- package/src/utils/settingsValidation/integrations/configurable.ts +1 -1
- package/src/utils/settingsValidation/integrations/pluggable.ts +2 -1
- package/src/utils/settingsValidation/localhost/builtin.ts +2 -1
- package/src/utils/settingsValidation/localhost/pluggable.ts +2 -1
- package/src/utils/settingsValidation/logger/builtinLogger.ts +2 -1
- package/src/utils/settingsValidation/logger/pluggableLogger.ts +2 -1
- package/src/utils/settingsValidation/splitFilters.ts +9 -7
- package/src/utils/settingsValidation/storage/storageCS.ts +2 -1
- package/types/consent/sdkUserConsent.d.ts +9 -2
- package/types/dtos/types.d.ts +6 -0
- package/types/evaluator/Engine.d.ts +3 -3
- package/types/evaluator/combiners/and.d.ts +1 -1
- package/types/evaluator/combiners/ifelseif.d.ts +1 -1
- package/types/evaluator/condition/engineUtils.d.ts +1 -1
- package/types/evaluator/condition/index.d.ts +1 -1
- package/types/evaluator/index.d.ts +4 -4
- package/types/evaluator/matchers/all.d.ts +1 -1
- package/types/evaluator/matchers/between.d.ts +1 -1
- package/types/evaluator/matchers/boolean.d.ts +1 -1
- package/types/evaluator/matchers/cont_all.d.ts +1 -1
- package/types/evaluator/matchers/cont_any.d.ts +1 -1
- package/types/evaluator/matchers/cont_str.d.ts +1 -1
- package/types/evaluator/matchers/dependency.d.ts +1 -1
- package/types/evaluator/matchers/eq.d.ts +1 -1
- package/types/evaluator/matchers/eq_set.d.ts +1 -1
- package/types/evaluator/matchers/ew.d.ts +1 -1
- package/types/evaluator/matchers/gte.d.ts +1 -1
- package/types/evaluator/matchers/index.d.ts +1 -1
- package/types/evaluator/matchers/lte.d.ts +1 -1
- package/types/evaluator/matchers/part_of.d.ts +1 -1
- package/types/evaluator/matchers/segment.d.ts +1 -1
- package/types/evaluator/matchers/string.d.ts +1 -1
- package/types/evaluator/matchers/sw.d.ts +1 -1
- package/types/evaluator/matchers/whitelist.d.ts +1 -1
- package/types/evaluator/parser/index.d.ts +1 -1
- package/types/evaluator/types.d.ts +6 -6
- package/types/evaluator/value/index.d.ts +3 -3
- package/types/evaluator/value/sanitize.d.ts +3 -3
- package/types/integrations/ga/GaToSplit.d.ts +4 -4
- package/types/integrations/ga/SplitToGa.d.ts +4 -4
- package/types/integrations/ga/types.d.ts +4 -4
- package/types/integrations/types.d.ts +4 -3
- package/types/logger/index.d.ts +5 -3
- package/types/logger/sdkLogger.d.ts +2 -1
- package/types/logger/types.d.ts +11 -0
- package/types/readiness/sdkReadinessManager.d.ts +1 -1
- package/types/readiness/types.d.ts +8 -2
- package/types/sdkClient/client.d.ts +2 -2
- package/types/sdkClient/clientAttributesDecoration.d.ts +8 -8
- package/types/sdkClient/clientCS.d.ts +3 -2
- package/types/sdkClient/clientInputValidation.d.ts +2 -2
- package/types/sdkClient/sdkClient.d.ts +2 -2
- package/types/sdkClient/sdkClientMethod.d.ts +2 -2
- package/types/sdkClient/sdkClientMethodCS.d.ts +2 -2
- package/types/sdkClient/sdkClientMethodCSWithTT.d.ts +2 -2
- package/types/sdkFactory/index.d.ts +2 -2
- package/types/sdkFactory/types.d.ts +6 -6
- package/types/sdkManager/index.d.ts +3 -3
- package/types/storages/AbstractSplitsCacheAsync.d.ts +6 -5
- package/types/storages/AbstractSplitsCacheSync.d.ts +5 -5
- package/types/storages/dataLoader.d.ts +2 -2
- package/types/storages/inLocalStorage/MySegmentsCacheInLocal.d.ts +1 -1
- package/types/storages/inLocalStorage/SplitsCacheInLocal.d.ts +4 -3
- package/types/storages/inLocalStorage/index.d.ts +2 -2
- package/types/storages/inMemory/EventsCacheInMemory.d.ts +3 -3
- package/types/storages/inMemory/InMemoryStorage.d.ts +1 -1
- package/types/storages/inMemory/InMemoryStorageCS.d.ts +1 -1
- package/types/storages/inMemory/SplitsCacheInMemory.d.ts +3 -2
- package/types/storages/inRedis/EventsCacheInRedis.d.ts +3 -3
- package/types/storages/inRedis/ImpressionsCacheInRedis.d.ts +1 -1
- package/types/storages/inRedis/RedisAdapter.d.ts +1 -1
- package/types/storages/inRedis/SegmentsCacheInRedis.d.ts +1 -1
- package/types/storages/inRedis/SplitsCacheInRedis.d.ts +7 -6
- package/types/storages/inRedis/TelemetryCacheInRedis.d.ts +1 -1
- package/types/storages/inRedis/index.d.ts +2 -2
- package/types/storages/pluggable/EventsCachePluggable.d.ts +3 -3
- package/types/storages/pluggable/ImpressionsCachePluggable.d.ts +1 -1
- package/types/storages/pluggable/SegmentsCachePluggable.d.ts +1 -1
- package/types/storages/pluggable/SplitsCachePluggable.d.ts +7 -6
- package/types/storages/pluggable/TelemetryCachePluggable.d.ts +1 -1
- package/types/storages/pluggable/index.d.ts +2 -3
- package/types/storages/pluggable/wrapperAdapter.d.ts +1 -1
- package/types/storages/types.d.ts +28 -54
- package/types/sync/offline/LocalhostFromObject.d.ts +2 -2
- package/types/sync/polling/updaters/mySegmentsUpdater.d.ts +1 -1
- package/types/sync/polling/updaters/segmentChangesUpdater.d.ts +1 -1
- package/types/sync/polling/updaters/splitChangesUpdater.d.ts +2 -2
- package/types/sync/streaming/SSEHandler/index.d.ts +1 -1
- package/types/sync/streaming/UpdateWorkers/SegmentsUpdateWorker.d.ts +1 -1
- package/types/sync/streaming/UpdateWorkers/SplitsUpdateWorker.d.ts +1 -1
- package/types/sync/submitters/submitter.d.ts +1 -1
- package/types/sync/submitters/types.d.ts +2 -2
- package/types/sync/syncTask.d.ts +1 -1
- package/types/trackers/types.d.ts +8 -4
- package/types/types.d.ts +1261 -0
- package/types/utils/constants/index.d.ts +1 -1
- package/types/utils/inputValidation/apiKey.d.ts +1 -1
- package/types/utils/inputValidation/attribute.d.ts +1 -1
- package/types/utils/inputValidation/attributes.d.ts +3 -3
- package/types/utils/inputValidation/event.d.ts +1 -1
- package/types/utils/inputValidation/eventProperties.d.ts +3 -3
- package/types/utils/inputValidation/eventValue.d.ts +1 -1
- package/types/utils/inputValidation/isOperational.d.ts +1 -1
- package/types/utils/inputValidation/key.d.ts +3 -3
- package/types/utils/inputValidation/preloadedData.d.ts +3 -3
- package/types/utils/inputValidation/split.d.ts +1 -1
- package/types/utils/inputValidation/splitExistance.d.ts +1 -1
- package/types/utils/inputValidation/splits.d.ts +1 -1
- package/types/utils/inputValidation/trafficType.d.ts +1 -1
- package/types/utils/inputValidation/trafficTypeExistance.d.ts +1 -1
- package/types/utils/key/index.d.ts +4 -4
- package/types/utils/settingsValidation/consent.d.ts +2 -1
- package/types/utils/settingsValidation/impressionsMode.d.ts +3 -3
- package/types/utils/settingsValidation/integrations/common.d.ts +1 -1
- package/types/utils/settingsValidation/integrations/configurable.d.ts +1 -1
- package/types/utils/settingsValidation/integrations/pluggable.d.ts +2 -1
- package/types/utils/settingsValidation/localhost/builtin.d.ts +2 -1
- package/types/utils/settingsValidation/localhost/pluggable.d.ts +2 -1
- package/types/utils/settingsValidation/logger/builtinLogger.d.ts +1 -1
- package/types/utils/settingsValidation/logger/pluggableLogger.d.ts +1 -1
- package/types/utils/settingsValidation/splitFilters.d.ts +2 -1
- package/types/utils/settingsValidation/storage/storageCS.d.ts +3 -2
- package/src/types.d.ts +0 -1646
package/cjs/evaluator/index.js
CHANGED
|
@@ -37,45 +37,44 @@ function evaluateFeature(log, key, splitName, attributes, storage) {
|
|
|
37
37
|
}
|
|
38
38
|
exports.evaluateFeature = evaluateFeature;
|
|
39
39
|
function evaluateFeatures(log, key, splitNames, attributes, storage) {
|
|
40
|
-
var
|
|
40
|
+
var parsedSplits;
|
|
41
41
|
try {
|
|
42
|
-
|
|
42
|
+
parsedSplits = storage.splits.getSplits(splitNames);
|
|
43
43
|
}
|
|
44
44
|
catch (e) {
|
|
45
45
|
// Exception on sync `getSplits` storage. Not possible ATM with InMemory and InLocal storages.
|
|
46
46
|
return treatmentsException(splitNames);
|
|
47
47
|
}
|
|
48
|
-
return (
|
|
49
|
-
|
|
48
|
+
return (0, thenable_1.thenable)(parsedSplits) ?
|
|
49
|
+
parsedSplits.then(function (splits) { return getEvaluations(log, splitNames, splits, key, attributes, storage); })
|
|
50
50
|
.catch(function () {
|
|
51
51
|
// Exception on async `getSplits` storage. For example, when the storage is redis or
|
|
52
52
|
// pluggable and there is a connection issue and we can't retrieve the split to be evaluated
|
|
53
53
|
return treatmentsException(splitNames);
|
|
54
54
|
}) :
|
|
55
|
-
getEvaluations(log, splitNames,
|
|
55
|
+
getEvaluations(log, splitNames, parsedSplits, key, attributes, storage);
|
|
56
56
|
}
|
|
57
57
|
exports.evaluateFeatures = evaluateFeatures;
|
|
58
|
-
function getEvaluation(log,
|
|
58
|
+
function getEvaluation(log, splitJSON, key, attributes, storage) {
|
|
59
59
|
var evaluation = {
|
|
60
60
|
treatment: constants_1.CONTROL,
|
|
61
61
|
label: LabelsConstants.SPLIT_NOT_FOUND,
|
|
62
62
|
config: null
|
|
63
63
|
};
|
|
64
|
-
if (
|
|
65
|
-
var
|
|
66
|
-
var split_1 = Engine_1.Engine.parse(log, splitJSON_1, storage);
|
|
64
|
+
if (splitJSON) {
|
|
65
|
+
var split_1 = Engine_1.Engine.parse(log, splitJSON, storage);
|
|
67
66
|
evaluation = split_1.getTreatment(key, attributes, evaluateFeature);
|
|
68
67
|
// If the storage is async and the evaluated split uses segment, evaluation is thenable
|
|
69
68
|
if ((0, thenable_1.thenable)(evaluation)) {
|
|
70
69
|
return evaluation.then(function (result) {
|
|
71
70
|
result.changeNumber = split_1.getChangeNumber();
|
|
72
|
-
result.config =
|
|
71
|
+
result.config = splitJSON.configurations && splitJSON.configurations[result.treatment] || null;
|
|
73
72
|
return result;
|
|
74
73
|
});
|
|
75
74
|
}
|
|
76
75
|
else {
|
|
77
76
|
evaluation.changeNumber = split_1.getChangeNumber(); // Always sync and optional
|
|
78
|
-
evaluation.config =
|
|
77
|
+
evaluation.config = splitJSON.configurations && splitJSON.configurations[evaluation.treatment] || null;
|
|
79
78
|
}
|
|
80
79
|
}
|
|
81
80
|
return evaluation;
|
|
@@ -16,7 +16,7 @@ var logNameMapper = 'ga-to-split:mapper';
|
|
|
16
16
|
* @param log Logger instance.
|
|
17
17
|
* @param autoRequire If true, log error when auto-require script is not detected
|
|
18
18
|
*/
|
|
19
|
-
function providePlugin(window, pluginName, pluginConstructor, log, autoRequire) {
|
|
19
|
+
function providePlugin(window, pluginName, pluginConstructor, log, autoRequire, telemetryTracker) {
|
|
20
20
|
// get reference to global command queue. Init it if not defined yet.
|
|
21
21
|
var gaAlias = window.GoogleAnalyticsObject || 'ga';
|
|
22
22
|
window[gaAlias] = window[gaAlias] || function () {
|
|
@@ -24,10 +24,13 @@ function providePlugin(window, pluginName, pluginConstructor, log, autoRequire)
|
|
|
24
24
|
};
|
|
25
25
|
// provides the plugin for use with analytics.js.
|
|
26
26
|
window[gaAlias]('provide', pluginName, pluginConstructor);
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
var hasAutoRequire = window[gaAlias].q && window[gaAlias].q.push !== [].push;
|
|
28
|
+
if (autoRequire && !hasAutoRequire) { // Expecting spy on ga.q push method but not found
|
|
29
29
|
log.error(logPrefix + 'integration is configured to autorequire the splitTracker plugin, but the necessary script does not seem to have run. Please check the docs.');
|
|
30
30
|
}
|
|
31
|
+
if (telemetryTracker && hasAutoRequire) {
|
|
32
|
+
telemetryTracker.addTag('integration:ga-autorequire');
|
|
33
|
+
}
|
|
31
34
|
}
|
|
32
35
|
// Default mapping: object used for building the default mapper from hits to Split events
|
|
33
36
|
var defaultMapping = {
|
|
@@ -163,7 +166,7 @@ exports.fixEventTypeId = fixEventTypeId;
|
|
|
163
166
|
* @param {object} log factory logger
|
|
164
167
|
*/
|
|
165
168
|
function GaToSplit(sdkOptions, params) {
|
|
166
|
-
var storage = params.storage, _a = params.settings, coreSettings = _a.core, log = _a.log;
|
|
169
|
+
var storage = params.storage, _a = params.settings, coreSettings = _a.core, log = _a.log, telemetryTracker = params.telemetryTracker;
|
|
167
170
|
var defaultOptions = {
|
|
168
171
|
prefix: exports.defaultPrefix,
|
|
169
172
|
// We set default identities if key and TT are present in settings.core
|
|
@@ -249,6 +252,6 @@ function GaToSplit(sdkOptions, params) {
|
|
|
249
252
|
return SplitTracker;
|
|
250
253
|
}());
|
|
251
254
|
// Register the plugin, even if config is invalid, since, if not provided, it will block `ga` command queue.
|
|
252
|
-
providePlugin(window, 'splitTracker', SplitTracker, log, sdkOptions.autoRequire === true);
|
|
255
|
+
providePlugin(window, 'splitTracker', SplitTracker, log, sdkOptions.autoRequire === true, telemetryTracker);
|
|
253
256
|
}
|
|
254
257
|
exports.GaToSplit = GaToSplit;
|
package/cjs/sdkFactory/index.js
CHANGED
|
@@ -32,7 +32,6 @@ function sdkFactory(params) {
|
|
|
32
32
|
optimize: (0, utils_1.shouldBeOptimized)(settings),
|
|
33
33
|
// ATM, only used by InLocalStorage
|
|
34
34
|
matchingKey: (0, key_1.getMatching)(settings.core.key),
|
|
35
|
-
// @ts-ignore
|
|
36
35
|
splitFiltersValidation: settings.sync.__splitFiltersValidation,
|
|
37
36
|
// ATM, only used by PluggableStorage
|
|
38
37
|
mode: settings.mode,
|
|
@@ -49,12 +48,12 @@ function sdkFactory(params) {
|
|
|
49
48
|
};
|
|
50
49
|
var storage = storageFactory(storageFactoryParams);
|
|
51
50
|
// @TODO add support for dataloader: `if (params.dataLoader) params.dataLoader(storage);`
|
|
52
|
-
var
|
|
51
|
+
var telemetryTracker = (0, telemetryTracker_1.telemetryTrackerFactory)(storage.telemetry, platform.now);
|
|
52
|
+
var integrationsManager = integrationsManagerFactory && integrationsManagerFactory({ settings: settings, storage: storage, telemetryTracker: telemetryTracker });
|
|
53
53
|
// trackers
|
|
54
54
|
var observer = impressionsObserverFactory && impressionsObserverFactory();
|
|
55
55
|
var impressionsTracker = (0, impressionsTracker_1.impressionsTrackerFactory)(settings, storage.impressions, integrationsManager, observer, storage.impressionCounts, storage.telemetry);
|
|
56
56
|
var eventTracker = (0, eventTracker_1.eventTrackerFactory)(settings, storage.events, integrationsManager, storage.telemetry);
|
|
57
|
-
var telemetryTracker = (0, telemetryTracker_1.telemetryTrackerFactory)(storage.telemetry, platform.now);
|
|
58
57
|
// splitApi is used by SyncManager and Browser signal listener
|
|
59
58
|
var splitApi = splitApiFactory && splitApiFactory(settings, platform, telemetryTracker);
|
|
60
59
|
var ctx = { splitApi: splitApi, eventTracker: eventTracker, impressionsTracker: impressionsTracker, telemetryTracker: telemetryTracker, sdkReadinessManager: sdkReadinessManager, readiness: readiness, settings: settings, storage: storage, platform: platform };
|
package/cjs/sdkManager/index.js
CHANGED
|
@@ -15,15 +15,7 @@ function collectTreatments(splitObject) {
|
|
|
15
15
|
// Then extract the treatments from the partitions
|
|
16
16
|
return allTreatmentsCondition ? allTreatmentsCondition.partitions.map(function (v) { return v.treatment; }) : [];
|
|
17
17
|
}
|
|
18
|
-
function objectToView(
|
|
19
|
-
var splitObject;
|
|
20
|
-
try {
|
|
21
|
-
// @ts-expect-error
|
|
22
|
-
splitObject = JSON.parse(json);
|
|
23
|
-
}
|
|
24
|
-
catch (e) {
|
|
25
|
-
return null;
|
|
26
|
-
}
|
|
18
|
+
function objectToView(splitObject) {
|
|
27
19
|
if (!splitObject)
|
|
28
20
|
return null;
|
|
29
21
|
return {
|
|
@@ -35,9 +27,9 @@ function objectToView(json) {
|
|
|
35
27
|
configs: splitObject.configurations || {}
|
|
36
28
|
};
|
|
37
29
|
}
|
|
38
|
-
function objectsToViews(
|
|
30
|
+
function objectsToViews(splitObjects) {
|
|
39
31
|
var views = [];
|
|
40
|
-
|
|
32
|
+
splitObjects.forEach(function (split) {
|
|
41
33
|
var view = objectToView(split);
|
|
42
34
|
if (view)
|
|
43
35
|
views.push(view);
|
package/cjs/services/splitApi.js
CHANGED
|
@@ -16,7 +16,6 @@ function userKeyToQueryParam(userKey) {
|
|
|
16
16
|
*/
|
|
17
17
|
function splitApiFactory(settings, platform, telemetryTracker) {
|
|
18
18
|
var urls = settings.urls;
|
|
19
|
-
// @ts-ignore
|
|
20
19
|
var filterQueryString = settings.sync.__splitFiltersValidation && settings.sync.__splitFiltersValidation.queryString;
|
|
21
20
|
var SplitSDKImpressionsMode = settings.sync.impressionsMode;
|
|
22
21
|
var splitHttpClient = (0, splitHttpClient_1.splitHttpClientFactory)(settings, platform.getFetch, platform.getOptions);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AbstractSplitsCacheAsync = void 0;
|
|
4
|
+
var objectAssign_1 = require("../utils/lang/objectAssign");
|
|
4
5
|
/**
|
|
5
6
|
* This class provides a skeletal implementation of the ISplitsCacheAsync interface
|
|
6
7
|
* to minimize the effort required to implement this interface.
|
|
@@ -34,15 +35,12 @@ var AbstractSplitsCacheAsync = /** @class */ (function () {
|
|
|
34
35
|
AbstractSplitsCacheAsync.prototype.killLocally = function (name, defaultTreatment, changeNumber) {
|
|
35
36
|
var _this = this;
|
|
36
37
|
return this.getSplit(name).then(function (split) {
|
|
37
|
-
if (split) {
|
|
38
|
-
var
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
var newSplit = JSON.stringify(parsedSplit);
|
|
44
|
-
return _this.addSplit(name, newSplit);
|
|
45
|
-
}
|
|
38
|
+
if (split && (!split.changeNumber || split.changeNumber < changeNumber)) {
|
|
39
|
+
var newSplit = (0, objectAssign_1.objectAssign)({}, split);
|
|
40
|
+
newSplit.killed = true;
|
|
41
|
+
newSplit.defaultTreatment = defaultTreatment;
|
|
42
|
+
newSplit.changeNumber = changeNumber;
|
|
43
|
+
return _this.addSplit(name, newSplit);
|
|
46
44
|
}
|
|
47
45
|
return false;
|
|
48
46
|
}).catch(function () { return false; });
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.usesSegments = exports.AbstractSplitsCacheSync = void 0;
|
|
4
|
+
var objectAssign_1 = require("../utils/lang/objectAssign");
|
|
4
5
|
/**
|
|
5
6
|
* This class provides a skeletal implementation of the ISplitsCacheSync interface
|
|
6
7
|
* to minimize the effort required to implement this interface.
|
|
@@ -47,15 +48,12 @@ var AbstractSplitsCacheSync = /** @class */ (function () {
|
|
|
47
48
|
*/
|
|
48
49
|
AbstractSplitsCacheSync.prototype.killLocally = function (name, defaultTreatment, changeNumber) {
|
|
49
50
|
var split = this.getSplit(name);
|
|
50
|
-
if (split) {
|
|
51
|
-
var
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
var newSplit = JSON.stringify(parsedSplit);
|
|
57
|
-
return this.addSplit(name, newSplit);
|
|
58
|
-
}
|
|
51
|
+
if (split && (!split.changeNumber || split.changeNumber < changeNumber)) {
|
|
52
|
+
var newSplit = (0, objectAssign_1.objectAssign)({}, split);
|
|
53
|
+
newSplit.killed = true;
|
|
54
|
+
newSplit.defaultTreatment = defaultTreatment;
|
|
55
|
+
newSplit.changeNumber = changeNumber;
|
|
56
|
+
return this.addSplit(name, newSplit);
|
|
59
57
|
}
|
|
60
58
|
return false;
|
|
61
59
|
};
|
|
@@ -35,7 +35,7 @@ function dataLoaderFactory(preloadedData) {
|
|
|
35
35
|
storage.splits.clear();
|
|
36
36
|
storage.splits.setChangeNumber(since);
|
|
37
37
|
// splitsData in an object where the property is the split name and the pertaining value is a stringified json of its data
|
|
38
|
-
storage.splits.addSplits(Object.keys(splitsData).map(function (splitName) { return
|
|
38
|
+
storage.splits.addSplits(Object.keys(splitsData).map(function (splitName) { return JSON.parse(splitsData[splitName]); }));
|
|
39
39
|
// add mySegments data
|
|
40
40
|
var mySegmentsData = preloadedData.mySegmentsData && preloadedData.mySegmentsData[userId];
|
|
41
41
|
if (!mySegmentsData) {
|
|
@@ -96,9 +96,8 @@ var SplitsCacheInLocal = /** @class */ (function (_super) {
|
|
|
96
96
|
var splitFromLocalStorage = localStorage.getItem(splitKey);
|
|
97
97
|
var previousSplit = splitFromLocalStorage ? JSON.parse(splitFromLocalStorage) : null;
|
|
98
98
|
this._decrementCounts(previousSplit);
|
|
99
|
-
localStorage.setItem(splitKey, split);
|
|
100
|
-
|
|
101
|
-
this._incrementCounts(parsedSplit);
|
|
99
|
+
localStorage.setItem(splitKey, JSON.stringify(split));
|
|
100
|
+
this._incrementCounts(split);
|
|
102
101
|
return true;
|
|
103
102
|
}
|
|
104
103
|
catch (e) {
|
|
@@ -110,8 +109,7 @@ var SplitsCacheInLocal = /** @class */ (function (_super) {
|
|
|
110
109
|
try {
|
|
111
110
|
var split = this.getSplit(name);
|
|
112
111
|
localStorage.removeItem(this.keys.buildSplitKey(name));
|
|
113
|
-
|
|
114
|
-
this._decrementCounts(parsedSplit);
|
|
112
|
+
this._decrementCounts(split);
|
|
115
113
|
return true;
|
|
116
114
|
}
|
|
117
115
|
catch (e) {
|
|
@@ -120,7 +118,8 @@ var SplitsCacheInLocal = /** @class */ (function (_super) {
|
|
|
120
118
|
}
|
|
121
119
|
};
|
|
122
120
|
SplitsCacheInLocal.prototype.getSplit = function (name) {
|
|
123
|
-
|
|
121
|
+
var item = localStorage.getItem(this.keys.buildSplitKey(name));
|
|
122
|
+
return item && JSON.parse(item);
|
|
124
123
|
};
|
|
125
124
|
SplitsCacheInLocal.prototype.setChangeNumber = function (changeNumber) {
|
|
126
125
|
// when cache is ready but using a new split query, we must clear all split data
|
|
@@ -25,9 +25,8 @@ var SplitsCacheInMemory = /** @class */ (function (_super) {
|
|
|
25
25
|
this.splitsWithSegmentsCount = 0;
|
|
26
26
|
};
|
|
27
27
|
SplitsCacheInMemory.prototype.addSplit = function (name, split) {
|
|
28
|
-
var
|
|
29
|
-
if (
|
|
30
|
-
var previousSplit = JSON.parse(splitFromMemory);
|
|
28
|
+
var previousSplit = this.getSplit(name);
|
|
29
|
+
if (previousSplit) { // We had this Split already
|
|
31
30
|
if (previousSplit.trafficTypeName) {
|
|
32
31
|
var previousTtName = previousSplit.trafficTypeName;
|
|
33
32
|
this.ttCache[previousTtName]--;
|
|
@@ -38,19 +37,18 @@ var SplitsCacheInMemory = /** @class */ (function (_super) {
|
|
|
38
37
|
this.splitsWithSegmentsCount--;
|
|
39
38
|
}
|
|
40
39
|
}
|
|
41
|
-
|
|
42
|
-
if (parsedSplit) {
|
|
40
|
+
if (split) {
|
|
43
41
|
// Store the Split.
|
|
44
42
|
this.splitsCache[name] = split;
|
|
45
43
|
// Update TT cache
|
|
46
|
-
var ttName =
|
|
44
|
+
var ttName = split.trafficTypeName;
|
|
47
45
|
if (ttName) { // safeguard
|
|
48
46
|
if (!this.ttCache[ttName])
|
|
49
47
|
this.ttCache[ttName] = 0;
|
|
50
48
|
this.ttCache[ttName]++;
|
|
51
49
|
}
|
|
52
50
|
// Add to segments count for the new version of the Split
|
|
53
|
-
if ((0, AbstractSplitsCacheSync_1.usesSegments)(
|
|
51
|
+
if ((0, AbstractSplitsCacheSync_1.usesSegments)(split))
|
|
54
52
|
this.splitsWithSegmentsCount++;
|
|
55
53
|
return true;
|
|
56
54
|
}
|
|
@@ -63,15 +61,14 @@ var SplitsCacheInMemory = /** @class */ (function (_super) {
|
|
|
63
61
|
if (split) {
|
|
64
62
|
// Delete the Split
|
|
65
63
|
delete this.splitsCache[name];
|
|
66
|
-
var
|
|
67
|
-
var ttName = parsedSplit.trafficTypeName;
|
|
64
|
+
var ttName = split.trafficTypeName;
|
|
68
65
|
if (ttName) { // safeguard
|
|
69
66
|
this.ttCache[ttName]--; // Update tt cache
|
|
70
67
|
if (!this.ttCache[ttName])
|
|
71
68
|
delete this.ttCache[ttName];
|
|
72
69
|
}
|
|
73
70
|
// Update the segments count.
|
|
74
|
-
if ((0, AbstractSplitsCacheSync_1.usesSegments)(
|
|
71
|
+
if ((0, AbstractSplitsCacheSync_1.usesSegments)(split))
|
|
75
72
|
this.splitsWithSegmentsCount--;
|
|
76
73
|
return true;
|
|
77
74
|
}
|
|
@@ -62,17 +62,17 @@ var SplitsCacheInRedis = /** @class */ (function (_super) {
|
|
|
62
62
|
var splitKey = this.keys.buildSplitKey(name);
|
|
63
63
|
return this.redis.get(splitKey).then(function (splitFromStorage) {
|
|
64
64
|
// handling parsing errors
|
|
65
|
-
var parsedPreviousSplit,
|
|
65
|
+
var parsedPreviousSplit, newStringifiedSplit;
|
|
66
66
|
try {
|
|
67
67
|
parsedPreviousSplit = splitFromStorage ? JSON.parse(splitFromStorage) : undefined;
|
|
68
|
-
|
|
68
|
+
newStringifiedSplit = JSON.stringify(split);
|
|
69
69
|
}
|
|
70
70
|
catch (e) {
|
|
71
71
|
throw new Error('Error parsing split definition: ' + e);
|
|
72
72
|
}
|
|
73
73
|
return Promise.all([
|
|
74
|
-
_this.redis.set(splitKey,
|
|
75
|
-
_this._incrementCounts(
|
|
74
|
+
_this.redis.set(splitKey, newStringifiedSplit),
|
|
75
|
+
_this._incrementCounts(split),
|
|
76
76
|
// If it's an update, we decrement the traffic type of the existing split,
|
|
77
77
|
parsedPreviousSplit && _this._decrementCounts(parsedPreviousSplit)
|
|
78
78
|
]);
|
|
@@ -99,8 +99,7 @@ var SplitsCacheInRedis = /** @class */ (function (_super) {
|
|
|
99
99
|
var _this = this;
|
|
100
100
|
return this.getSplit(name).then(function (split) {
|
|
101
101
|
if (split) {
|
|
102
|
-
|
|
103
|
-
_this._decrementCounts(parsedSplit);
|
|
102
|
+
_this._decrementCounts(split);
|
|
104
103
|
}
|
|
105
104
|
return _this.redis.del(_this.keys.buildSplitKey(name));
|
|
106
105
|
});
|
|
@@ -123,7 +122,8 @@ var SplitsCacheInRedis = /** @class */ (function (_super) {
|
|
|
123
122
|
this.log.error(constants_1.LOG_PREFIX + this.redisError);
|
|
124
123
|
return Promise.reject(this.redisError);
|
|
125
124
|
}
|
|
126
|
-
return this.redis.get(this.keys.buildSplitKey(name))
|
|
125
|
+
return this.redis.get(this.keys.buildSplitKey(name))
|
|
126
|
+
.then(function (maybeSplit) { return maybeSplit && JSON.parse(maybeSplit); });
|
|
127
127
|
};
|
|
128
128
|
/**
|
|
129
129
|
* Set till number.
|
|
@@ -158,7 +158,12 @@ var SplitsCacheInRedis = /** @class */ (function (_super) {
|
|
|
158
158
|
*/
|
|
159
159
|
SplitsCacheInRedis.prototype.getAll = function () {
|
|
160
160
|
var _this = this;
|
|
161
|
-
return this.redis.keys(this.keys.searchPatternForSplitKeys())
|
|
161
|
+
return this.redis.keys(this.keys.searchPatternForSplitKeys())
|
|
162
|
+
.then(function (listOfKeys) { return _this.redis.pipeline(listOfKeys.map(function (k) { return ['get', k]; })).exec(); })
|
|
163
|
+
.then(processPipelineAnswer)
|
|
164
|
+
.then(function (splitDefinitions) { return splitDefinitions.map(function (splitDefinition) {
|
|
165
|
+
return JSON.parse(splitDefinition);
|
|
166
|
+
}); });
|
|
162
167
|
};
|
|
163
168
|
/**
|
|
164
169
|
* Get list of split names.
|
|
@@ -218,7 +223,8 @@ var SplitsCacheInRedis = /** @class */ (function (_super) {
|
|
|
218
223
|
var keys = names.map(function (name) { return _this.keys.buildSplitKey(name); });
|
|
219
224
|
return (_a = this.redis).mget.apply(_a, keys).then(function (splitDefinitions) {
|
|
220
225
|
names.forEach(function (name, idx) {
|
|
221
|
-
|
|
226
|
+
var split = splitDefinitions[idx];
|
|
227
|
+
splits[name] = split && JSON.parse(split);
|
|
222
228
|
});
|
|
223
229
|
return Promise.resolve(splits);
|
|
224
230
|
})
|
|
@@ -49,17 +49,17 @@ var SplitsCachePluggable = /** @class */ (function (_super) {
|
|
|
49
49
|
var splitKey = this.keys.buildSplitKey(name);
|
|
50
50
|
return this.wrapper.get(splitKey).then(function (splitFromStorage) {
|
|
51
51
|
// handling parsing error
|
|
52
|
-
var parsedPreviousSplit,
|
|
52
|
+
var parsedPreviousSplit, stringifiedNewSplit;
|
|
53
53
|
try {
|
|
54
54
|
parsedPreviousSplit = splitFromStorage ? JSON.parse(splitFromStorage) : undefined;
|
|
55
|
-
|
|
55
|
+
stringifiedNewSplit = JSON.stringify(split);
|
|
56
56
|
}
|
|
57
57
|
catch (e) {
|
|
58
58
|
throw new Error('Error parsing split definition: ' + e);
|
|
59
59
|
}
|
|
60
60
|
return Promise.all([
|
|
61
|
-
_this.wrapper.set(splitKey,
|
|
62
|
-
_this._incrementCounts(
|
|
61
|
+
_this.wrapper.set(splitKey, stringifiedNewSplit),
|
|
62
|
+
_this._incrementCounts(split),
|
|
63
63
|
// If it's an update, we decrement the traffic type and segment count of the existing split,
|
|
64
64
|
parsedPreviousSplit && _this._decrementCounts(parsedPreviousSplit)
|
|
65
65
|
]);
|
|
@@ -83,8 +83,7 @@ var SplitsCachePluggable = /** @class */ (function (_super) {
|
|
|
83
83
|
var _this = this;
|
|
84
84
|
return this.getSplit(name).then(function (split) {
|
|
85
85
|
if (split) {
|
|
86
|
-
|
|
87
|
-
_this._decrementCounts(parsedSplit);
|
|
86
|
+
_this._decrementCounts(split);
|
|
88
87
|
}
|
|
89
88
|
return _this.wrapper.del(_this.keys.buildSplitKey(name));
|
|
90
89
|
});
|
|
@@ -104,7 +103,8 @@ var SplitsCachePluggable = /** @class */ (function (_super) {
|
|
|
104
103
|
* or rejected if wrapper operation fails.
|
|
105
104
|
*/
|
|
106
105
|
SplitsCachePluggable.prototype.getSplit = function (name) {
|
|
107
|
-
return this.wrapper.get(this.keys.buildSplitKey(name))
|
|
106
|
+
return this.wrapper.get(this.keys.buildSplitKey(name))
|
|
107
|
+
.then(function (maybeSplit) { return maybeSplit && JSON.parse(maybeSplit); });
|
|
108
108
|
};
|
|
109
109
|
/**
|
|
110
110
|
* Get list of splits.
|
|
@@ -117,7 +117,8 @@ var SplitsCachePluggable = /** @class */ (function (_super) {
|
|
|
117
117
|
return this.wrapper.getMany(keys).then(function (splitDefinitions) {
|
|
118
118
|
var splits = {};
|
|
119
119
|
names.forEach(function (name, idx) {
|
|
120
|
-
|
|
120
|
+
var split = splitDefinitions[idx];
|
|
121
|
+
splits[name] = split && JSON.parse(split);
|
|
121
122
|
});
|
|
122
123
|
return Promise.resolve(splits);
|
|
123
124
|
});
|
|
@@ -129,7 +130,11 @@ var SplitsCachePluggable = /** @class */ (function (_super) {
|
|
|
129
130
|
*/
|
|
130
131
|
SplitsCachePluggable.prototype.getAll = function () {
|
|
131
132
|
var _this = this;
|
|
132
|
-
return this.wrapper.getKeysByPrefix(this.keys.buildSplitKeyPrefix())
|
|
133
|
+
return this.wrapper.getKeysByPrefix(this.keys.buildSplitKeyPrefix())
|
|
134
|
+
.then(function (listOfKeys) { return _this.wrapper.getMany(listOfKeys); })
|
|
135
|
+
.then(function (splitDefinitions) { return splitDefinitions.map(function (splitDefinition) {
|
|
136
|
+
return JSON.parse(splitDefinition);
|
|
137
|
+
}); });
|
|
133
138
|
};
|
|
134
139
|
/**
|
|
135
140
|
* Get list of split names.
|
|
@@ -27,8 +27,7 @@ function fromObjectUpdaterFactory(splitsParser, storage, readiness, settings) {
|
|
|
27
27
|
log.debug(constants_3.SYNC_OFFLINE_DATA, [JSON.stringify(splitsMock)]);
|
|
28
28
|
(0, lang_1.forOwn)(splitsMock, function (val, name) {
|
|
29
29
|
splits.push([
|
|
30
|
-
name,
|
|
31
|
-
JSON.stringify({
|
|
30
|
+
name, {
|
|
32
31
|
name: name,
|
|
33
32
|
status: 'ACTIVE',
|
|
34
33
|
killed: false,
|
|
@@ -37,7 +36,7 @@ function fromObjectUpdaterFactory(splitsParser, storage, readiness, settings) {
|
|
|
37
36
|
conditions: val.conditions || [],
|
|
38
37
|
configurations: val.configurations,
|
|
39
38
|
trafficTypeName: val.trafficTypeName
|
|
40
|
-
}
|
|
39
|
+
}
|
|
41
40
|
]);
|
|
42
41
|
});
|
|
43
42
|
return Promise.all([
|
|
@@ -41,7 +41,7 @@ function computeSplitsMutation(entries) {
|
|
|
41
41
|
var segments = new sets_1._Set();
|
|
42
42
|
var computed = entries.reduce(function (accum, split) {
|
|
43
43
|
if (split.status === 'ACTIVE') {
|
|
44
|
-
accum.added.push([split.name,
|
|
44
|
+
accum.added.push([split.name, split]);
|
|
45
45
|
parseSegments(split).forEach(function (segmentName) {
|
|
46
46
|
segments.add(segmentName);
|
|
47
47
|
});
|
|
@@ -49,6 +49,11 @@ function telemetryTrackerFactory(telemetryCache, now) {
|
|
|
49
49
|
if (e === constants_1.TOKEN_REFRESH)
|
|
50
50
|
telemetryCache.recordTokenRefreshes();
|
|
51
51
|
}
|
|
52
|
+
},
|
|
53
|
+
addTag: function (tag) {
|
|
54
|
+
// @ts-ignore
|
|
55
|
+
if (telemetryCache.addTag)
|
|
56
|
+
telemetryCache.addTag(tag);
|
|
52
57
|
}
|
|
53
58
|
};
|
|
54
59
|
}
|
|
@@ -59,6 +64,7 @@ function telemetryTrackerFactory(telemetryCache, now) {
|
|
|
59
64
|
trackHttp: noopTrack,
|
|
60
65
|
sessionLength: function () { },
|
|
61
66
|
streamingEvent: function () { },
|
|
67
|
+
addTag: function () { }
|
|
62
68
|
};
|
|
63
69
|
}
|
|
64
70
|
}
|
package/cjs/types.js
ADDED
package/cjs/utils/key/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.keyParser = exports.getBucketing = exports.getMatching = void 0;
|
|
4
4
|
var lang_1 = require("../lang");
|
|
5
|
-
// function isSplitKeyObject(key: any): key is SplitKeyObject {
|
|
5
|
+
// function isSplitKeyObject(key: any): key is SplitIO.SplitKeyObject {
|
|
6
6
|
// return key !== undefined && key !== null && typeof key.matchingKey === 'string';
|
|
7
7
|
// }
|
|
8
8
|
// returns the matchingKey if the Key is defined as an object or the key itself if it is a string
|
|
@@ -175,7 +175,6 @@ function settingsValidation(config, validationParams) {
|
|
|
175
175
|
// validate the `splitFilters` settings and parse splits query
|
|
176
176
|
var splitFiltersValidation = (0, splitFilters_1.validateSplitFilters)(log, withDefaults.sync.splitFilters, withDefaults.mode);
|
|
177
177
|
withDefaults.sync.splitFilters = splitFiltersValidation.validFilters;
|
|
178
|
-
// @ts-ignore
|
|
179
178
|
withDefaults.sync.__splitFiltersValidation = splitFiltersValidation;
|
|
180
179
|
// ensure a valid user consent value
|
|
181
180
|
// @ts-ignore, modify readonly prop
|
package/esm/evaluator/index.js
CHANGED
|
@@ -32,44 +32,43 @@ export function evaluateFeature(log, key, splitName, attributes, storage) {
|
|
|
32
32
|
return getEvaluation(log, stringifiedSplit, key, attributes, storage);
|
|
33
33
|
}
|
|
34
34
|
export function evaluateFeatures(log, key, splitNames, attributes, storage) {
|
|
35
|
-
var
|
|
35
|
+
var parsedSplits;
|
|
36
36
|
try {
|
|
37
|
-
|
|
37
|
+
parsedSplits = storage.splits.getSplits(splitNames);
|
|
38
38
|
}
|
|
39
39
|
catch (e) {
|
|
40
40
|
// Exception on sync `getSplits` storage. Not possible ATM with InMemory and InLocal storages.
|
|
41
41
|
return treatmentsException(splitNames);
|
|
42
42
|
}
|
|
43
|
-
return
|
|
44
|
-
|
|
43
|
+
return thenable(parsedSplits) ?
|
|
44
|
+
parsedSplits.then(function (splits) { return getEvaluations(log, splitNames, splits, key, attributes, storage); })
|
|
45
45
|
.catch(function () {
|
|
46
46
|
// Exception on async `getSplits` storage. For example, when the storage is redis or
|
|
47
47
|
// pluggable and there is a connection issue and we can't retrieve the split to be evaluated
|
|
48
48
|
return treatmentsException(splitNames);
|
|
49
49
|
}) :
|
|
50
|
-
getEvaluations(log, splitNames,
|
|
50
|
+
getEvaluations(log, splitNames, parsedSplits, key, attributes, storage);
|
|
51
51
|
}
|
|
52
|
-
function getEvaluation(log,
|
|
52
|
+
function getEvaluation(log, splitJSON, key, attributes, storage) {
|
|
53
53
|
var evaluation = {
|
|
54
54
|
treatment: CONTROL,
|
|
55
55
|
label: LabelsConstants.SPLIT_NOT_FOUND,
|
|
56
56
|
config: null
|
|
57
57
|
};
|
|
58
|
-
if (
|
|
59
|
-
var
|
|
60
|
-
var split_1 = Engine.parse(log, splitJSON_1, storage);
|
|
58
|
+
if (splitJSON) {
|
|
59
|
+
var split_1 = Engine.parse(log, splitJSON, storage);
|
|
61
60
|
evaluation = split_1.getTreatment(key, attributes, evaluateFeature);
|
|
62
61
|
// If the storage is async and the evaluated split uses segment, evaluation is thenable
|
|
63
62
|
if (thenable(evaluation)) {
|
|
64
63
|
return evaluation.then(function (result) {
|
|
65
64
|
result.changeNumber = split_1.getChangeNumber();
|
|
66
|
-
result.config =
|
|
65
|
+
result.config = splitJSON.configurations && splitJSON.configurations[result.treatment] || null;
|
|
67
66
|
return result;
|
|
68
67
|
});
|
|
69
68
|
}
|
|
70
69
|
else {
|
|
71
70
|
evaluation.changeNumber = split_1.getChangeNumber(); // Always sync and optional
|
|
72
|
-
evaluation.config =
|
|
71
|
+
evaluation.config = splitJSON.configurations && splitJSON.configurations[evaluation.treatment] || null;
|
|
73
72
|
}
|
|
74
73
|
}
|
|
75
74
|
return evaluation;
|
|
@@ -13,7 +13,7 @@ var logNameMapper = 'ga-to-split:mapper';
|
|
|
13
13
|
* @param log Logger instance.
|
|
14
14
|
* @param autoRequire If true, log error when auto-require script is not detected
|
|
15
15
|
*/
|
|
16
|
-
function providePlugin(window, pluginName, pluginConstructor, log, autoRequire) {
|
|
16
|
+
function providePlugin(window, pluginName, pluginConstructor, log, autoRequire, telemetryTracker) {
|
|
17
17
|
// get reference to global command queue. Init it if not defined yet.
|
|
18
18
|
var gaAlias = window.GoogleAnalyticsObject || 'ga';
|
|
19
19
|
window[gaAlias] = window[gaAlias] || function () {
|
|
@@ -21,10 +21,13 @@ function providePlugin(window, pluginName, pluginConstructor, log, autoRequire)
|
|
|
21
21
|
};
|
|
22
22
|
// provides the plugin for use with analytics.js.
|
|
23
23
|
window[gaAlias]('provide', pluginName, pluginConstructor);
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
var hasAutoRequire = window[gaAlias].q && window[gaAlias].q.push !== [].push;
|
|
25
|
+
if (autoRequire && !hasAutoRequire) { // Expecting spy on ga.q push method but not found
|
|
26
26
|
log.error(logPrefix + 'integration is configured to autorequire the splitTracker plugin, but the necessary script does not seem to have run. Please check the docs.');
|
|
27
27
|
}
|
|
28
|
+
if (telemetryTracker && hasAutoRequire) {
|
|
29
|
+
telemetryTracker.addTag('integration:ga-autorequire');
|
|
30
|
+
}
|
|
28
31
|
}
|
|
29
32
|
// Default mapping: object used for building the default mapper from hits to Split events
|
|
30
33
|
var defaultMapping = {
|
|
@@ -157,7 +160,7 @@ export function fixEventTypeId(log, eventTypeId) {
|
|
|
157
160
|
* @param {object} log factory logger
|
|
158
161
|
*/
|
|
159
162
|
export function GaToSplit(sdkOptions, params) {
|
|
160
|
-
var storage = params.storage, _a = params.settings, coreSettings = _a.core, log = _a.log;
|
|
163
|
+
var storage = params.storage, _a = params.settings, coreSettings = _a.core, log = _a.log, telemetryTracker = params.telemetryTracker;
|
|
161
164
|
var defaultOptions = {
|
|
162
165
|
prefix: defaultPrefix,
|
|
163
166
|
// We set default identities if key and TT are present in settings.core
|
|
@@ -243,5 +246,5 @@ export function GaToSplit(sdkOptions, params) {
|
|
|
243
246
|
return SplitTracker;
|
|
244
247
|
}());
|
|
245
248
|
// Register the plugin, even if config is invalid, since, if not provided, it will block `ga` command queue.
|
|
246
|
-
providePlugin(window, 'splitTracker', SplitTracker, log, sdkOptions.autoRequire === true);
|
|
249
|
+
providePlugin(window, 'splitTracker', SplitTracker, log, sdkOptions.autoRequire === true, telemetryTracker);
|
|
247
250
|
}
|