@splitsoftware/splitio-commons 1.6.2-rc.0 → 1.6.2-rc.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGES.txt +4 -0
- package/cjs/consent/sdkUserConsent.js +2 -2
- package/cjs/evaluator/index.js +15 -16
- package/cjs/integrations/ga/GaToSplit.js +8 -5
- package/cjs/listeners/browser.js +2 -1
- package/cjs/logger/constants.js +2 -1
- package/cjs/sdkClient/client.js +19 -7
- package/cjs/sdkClient/sdkClient.js +3 -1
- package/cjs/sdkFactory/index.js +24 -7
- package/cjs/sdkManager/index.js +3 -11
- package/cjs/services/splitApi.js +24 -4
- package/cjs/storages/AbstractSplitsCacheAsync.js +8 -10
- package/cjs/storages/AbstractSplitsCacheSync.js +8 -10
- package/cjs/storages/KeyBuilderSS.js +54 -9
- package/cjs/storages/dataLoader.js +1 -1
- package/cjs/storages/inLocalStorage/SplitsCacheInLocal.js +5 -7
- package/cjs/storages/inLocalStorage/index.js +5 -1
- package/cjs/storages/inMemory/ImpressionCountsCacheInMemory.js +12 -1
- package/cjs/storages/inMemory/InMemoryStorage.js +6 -2
- package/cjs/storages/inMemory/InMemoryStorageCS.js +6 -2
- package/cjs/storages/inMemory/SplitsCacheInMemory.js +7 -10
- package/cjs/storages/inMemory/TelemetryCacheInMemory.js +10 -5
- package/cjs/storages/inMemory/UniqueKeysCacheInMemory.js +73 -0
- package/cjs/storages/inMemory/UniqueKeysCacheInMemoryCS.js +78 -0
- package/cjs/storages/inRedis/EventsCacheInRedis.js +1 -1
- package/cjs/storages/inRedis/ImpressionCountsCacheInRedis.js +50 -0
- package/cjs/storages/inRedis/SplitsCacheInRedis.js +15 -9
- package/cjs/storages/inRedis/TelemetryCacheInRedis.js +100 -0
- package/cjs/storages/inRedis/UniqueKeysCacheInRedis.js +59 -0
- package/cjs/storages/inRedis/constants.js +4 -1
- package/cjs/storages/inRedis/index.js +17 -2
- package/cjs/storages/pluggable/ImpressionCountsCachePluggable.js +43 -0
- package/cjs/storages/pluggable/SplitsCachePluggable.js +14 -9
- package/cjs/storages/pluggable/TelemetryCachePluggable.js +126 -0
- package/cjs/storages/pluggable/UniqueKeysCachePluggable.js +50 -0
- package/cjs/storages/pluggable/index.js +42 -17
- package/cjs/sync/offline/syncTasks/fromObjectSyncTask.js +2 -3
- package/cjs/sync/polling/updaters/splitChangesUpdater.js +1 -1
- package/cjs/sync/submitters/submitterManager.js +3 -0
- package/cjs/sync/submitters/telemetrySubmitter.js +8 -4
- package/cjs/sync/submitters/uniqueKeysSubmitter.js +27 -0
- package/cjs/trackers/impressionsTracker.js +22 -41
- package/cjs/trackers/strategy/strategyDebug.js +25 -0
- package/cjs/trackers/strategy/strategyNone.js +29 -0
- package/cjs/trackers/strategy/strategyOptimized.js +35 -0
- package/cjs/trackers/telemetryTracker.js +6 -0
- package/cjs/trackers/uniqueKeysTracker.js +38 -0
- package/cjs/utils/constants/index.js +4 -2
- package/cjs/utils/lang/maps.js +15 -7
- package/cjs/utils/redis/RedisMock.js +31 -0
- package/cjs/utils/settingsValidation/impressionsMode.js +2 -2
- package/esm/consent/sdkUserConsent.js +2 -2
- package/esm/evaluator/index.js +15 -16
- package/esm/integrations/ga/GaToSplit.js +8 -5
- package/esm/listeners/browser.js +3 -2
- package/esm/logger/constants.js +1 -0
- package/esm/sdkClient/client.js +19 -7
- package/esm/sdkClient/sdkClient.js +3 -1
- package/esm/sdkFactory/index.js +24 -7
- package/esm/sdkManager/index.js +3 -11
- package/esm/services/splitApi.js +24 -4
- package/esm/storages/AbstractSplitsCacheAsync.js +8 -10
- package/esm/storages/AbstractSplitsCacheSync.js +8 -10
- package/esm/storages/KeyBuilderSS.js +50 -8
- package/esm/storages/dataLoader.js +1 -1
- package/esm/storages/inLocalStorage/SplitsCacheInLocal.js +5 -7
- package/esm/storages/inLocalStorage/index.js +6 -2
- package/esm/storages/inMemory/ImpressionCountsCacheInMemory.js +12 -1
- package/esm/storages/inMemory/InMemoryStorage.js +8 -4
- package/esm/storages/inMemory/InMemoryStorageCS.js +7 -3
- package/esm/storages/inMemory/SplitsCacheInMemory.js +7 -10
- package/esm/storages/inMemory/TelemetryCacheInMemory.js +9 -5
- package/esm/storages/inMemory/UniqueKeysCacheInMemory.js +70 -0
- package/esm/storages/inMemory/UniqueKeysCacheInMemoryCS.js +75 -0
- package/esm/storages/inRedis/EventsCacheInRedis.js +1 -1
- package/esm/storages/inRedis/ImpressionCountsCacheInRedis.js +47 -0
- package/esm/storages/inRedis/SplitsCacheInRedis.js +15 -9
- package/esm/storages/inRedis/TelemetryCacheInRedis.js +100 -0
- package/esm/storages/inRedis/UniqueKeysCacheInRedis.js +56 -0
- package/esm/storages/inRedis/constants.js +3 -0
- package/esm/storages/inRedis/index.js +18 -3
- package/esm/storages/pluggable/ImpressionCountsCachePluggable.js +40 -0
- package/esm/storages/pluggable/SplitsCachePluggable.js +14 -9
- package/esm/storages/pluggable/TelemetryCachePluggable.js +126 -0
- package/esm/storages/pluggable/UniqueKeysCachePluggable.js +47 -0
- package/esm/storages/pluggable/index.js +43 -18
- package/esm/sync/offline/syncTasks/fromObjectSyncTask.js +2 -3
- package/esm/sync/polling/updaters/splitChangesUpdater.js +1 -1
- package/esm/sync/submitters/submitterManager.js +3 -0
- package/esm/sync/submitters/telemetrySubmitter.js +9 -5
- package/esm/sync/submitters/uniqueKeysSubmitter.js +23 -0
- package/esm/trackers/impressionsTracker.js +22 -41
- package/esm/trackers/strategy/strategyDebug.js +21 -0
- package/esm/trackers/strategy/strategyNone.js +25 -0
- package/esm/trackers/strategy/strategyOptimized.js +31 -0
- package/esm/trackers/telemetryTracker.js +6 -0
- package/esm/trackers/uniqueKeysTracker.js +34 -0
- package/esm/utils/constants/index.js +2 -0
- package/esm/utils/lang/maps.js +15 -7
- package/esm/utils/redis/RedisMock.js +28 -0
- package/esm/utils/settingsValidation/impressionsMode.js +3 -3
- package/package.json +1 -2
- package/src/consent/sdkUserConsent.ts +2 -2
- package/src/evaluator/index.ts +14 -15
- package/src/integrations/ga/GaToSplit.ts +9 -5
- package/src/integrations/types.ts +2 -1
- package/src/listeners/browser.ts +3 -2
- package/src/logger/constants.ts +1 -0
- package/src/sdkClient/client.ts +21 -8
- package/src/sdkClient/sdkClient.ts +3 -1
- package/src/sdkFactory/index.ts +28 -8
- package/src/sdkFactory/types.ts +7 -4
- package/src/sdkManager/index.ts +3 -12
- package/src/services/splitApi.ts +26 -4
- package/src/services/types.ts +8 -2
- package/src/storages/AbstractSplitsCacheAsync.ts +13 -15
- package/src/storages/AbstractSplitsCacheSync.ts +15 -17
- package/src/storages/KeyBuilderSS.ts +61 -9
- package/src/storages/dataLoader.ts +1 -1
- package/src/storages/inLocalStorage/SplitsCacheInLocal.ts +8 -11
- package/src/storages/inLocalStorage/index.ts +5 -2
- package/src/storages/inMemory/ImpressionCountsCacheInMemory.ts +16 -1
- package/src/storages/inMemory/InMemoryStorage.ts +7 -4
- package/src/storages/inMemory/InMemoryStorageCS.ts +6 -3
- package/src/storages/inMemory/SplitsCacheInMemory.ts +10 -14
- package/src/storages/inMemory/TelemetryCacheInMemory.ts +10 -6
- package/src/storages/inMemory/UniqueKeysCacheInMemory.ts +82 -0
- package/src/storages/inMemory/UniqueKeysCacheInMemoryCS.ts +88 -0
- package/src/storages/inRedis/EventsCacheInRedis.ts +1 -1
- package/src/storages/inRedis/ImpressionCountsCacheInRedis.ts +53 -0
- package/src/storages/inRedis/SplitsCacheInRedis.ts +21 -17
- package/src/storages/inRedis/TelemetryCacheInRedis.ts +122 -2
- package/src/storages/inRedis/UniqueKeysCacheInRedis.ts +65 -0
- package/src/storages/inRedis/constants.ts +3 -0
- package/src/storages/inRedis/index.ts +15 -5
- package/src/storages/pluggable/ImpressionCountsCachePluggable.ts +47 -0
- package/src/storages/pluggable/SplitsCachePluggable.ts +20 -17
- package/src/storages/pluggable/TelemetryCachePluggable.ts +147 -2
- package/src/storages/pluggable/UniqueKeysCachePluggable.ts +56 -0
- package/src/storages/pluggable/index.ts +44 -19
- package/src/storages/types.ts +50 -29
- package/src/sync/offline/syncTasks/fromObjectSyncTask.ts +5 -6
- package/src/sync/polling/updaters/splitChangesUpdater.ts +2 -2
- package/src/sync/submitters/submitterManager.ts +2 -0
- package/src/sync/submitters/telemetrySubmitter.ts +15 -8
- package/src/sync/submitters/types.ts +38 -7
- package/src/sync/submitters/uniqueKeysSubmitter.ts +36 -0
- package/src/trackers/impressionsTracker.ts +27 -48
- package/src/trackers/strategy/strategyDebug.ts +28 -0
- package/src/trackers/strategy/strategyNone.ts +34 -0
- package/src/trackers/strategy/strategyOptimized.ts +42 -0
- package/src/trackers/telemetryTracker.ts +7 -2
- package/src/trackers/types.ts +32 -0
- package/src/trackers/uniqueKeysTracker.ts +48 -0
- package/src/types.ts +1 -1
- package/src/utils/constants/index.ts +2 -0
- package/src/utils/lang/maps.ts +20 -8
- package/src/utils/redis/RedisMock.ts +33 -0
- package/src/utils/settingsValidation/impressionsMode.ts +3 -3
- package/src/utils/settingsValidation/index.ts +1 -0
- package/types/integrations/types.d.ts +2 -1
- package/types/logger/browser/{debugLogger.d.ts → DebugLogger.d.ts} +0 -0
- package/types/logger/browser/{errorLogger.d.ts → ErrorLogger.d.ts} +0 -0
- package/types/logger/browser/{infoLogger.d.ts → InfoLogger.d.ts} +0 -0
- package/types/logger/browser/{warnLogger.d.ts → WarnLogger.d.ts} +0 -0
- package/types/logger/constants.d.ts +1 -0
- package/types/sdkFactory/types.d.ts +4 -2
- package/types/services/types.d.ts +6 -2
- package/types/storages/AbstractSplitsCacheAsync.d.ts +7 -6
- package/types/storages/AbstractSplitsCacheSync.d.ts +6 -6
- package/types/storages/KeyBuilderSS.d.ts +9 -2
- package/types/storages/inLocalStorage/SplitsCacheInLocal.d.ts +3 -4
- package/types/storages/inMemory/ImpressionCountsCacheInMemory.d.ts +5 -1
- package/types/storages/inMemory/SplitsCacheInMemory.d.ts +3 -2
- package/types/storages/inMemory/TelemetryCacheInMemory.d.ts +6 -3
- package/types/storages/inMemory/uniqueKeysCacheInMemory.d.ts +35 -0
- package/types/storages/inMemory/uniqueKeysCacheInMemoryCS.d.ts +37 -0
- package/types/storages/inRedis/EventsCacheInRedis.d.ts +1 -1
- package/types/storages/inRedis/ImpressionCountsCacheInRedis.d.ts +14 -0
- package/types/storages/inRedis/SplitsCacheInRedis.d.ts +6 -5
- package/types/storages/inRedis/TelemetryCacheInRedis.d.ts +16 -1
- package/types/storages/inRedis/constants.d.ts +3 -0
- package/types/storages/inRedis/uniqueKeysCacheInRedis.d.ts +15 -0
- package/types/storages/pluggable/ImpressionCountsCachePluggable.d.ts +14 -0
- package/types/storages/pluggable/SplitsCachePluggable.d.ts +6 -5
- package/types/storages/pluggable/TelemetryCachePluggable.d.ts +17 -1
- package/types/storages/pluggable/UniqueKeysCachePluggable.d.ts +14 -0
- package/types/storages/types.d.ts +38 -25
- package/types/sync/polling/updaters/splitChangesUpdater.d.ts +1 -1
- package/types/sync/submitters/telemetrySubmitter.d.ts +1 -1
- package/types/sync/submitters/types.d.ts +30 -7
- package/types/sync/submitters/uniqueKeysSubmitter.d.ts +0 -8
- package/types/trackers/impressionsTracker.d.ts +4 -6
- package/types/trackers/types.d.ts +27 -0
- package/types/trackers/uniqueKeysTracker.d.ts +3 -3
- package/types/types.d.ts +1 -1
- package/types/utils/constants/index.d.ts +2 -0
- package/types/utils/lang/maps.d.ts +6 -2
- package/types/utils/redis/RedisMock.d.ts +4 -0
- package/src/splitio.d.ts +0 -1602
- package/types/integrations/ga/GaToSplitPlugin.d.ts +0 -3
- package/types/integrations/ga/SplitToGaPlugin.d.ts +0 -4
- package/types/integrations/ga/autoRequire.d.ts +0 -4
- package/types/logger/codes.d.ts +0 -2
- package/types/logger/codesConstants.d.ts +0 -117
- package/types/logger/codesConstantsBrowser.d.ts +0 -2
- package/types/logger/codesConstantsNode.d.ts +0 -14
- package/types/logger/codesDebug.d.ts +0 -1
- package/types/logger/codesDebugBrowser.d.ts +0 -1
- package/types/logger/codesDebugNode.d.ts +0 -1
- package/types/logger/codesError.d.ts +0 -1
- package/types/logger/codesErrorNode.d.ts +0 -1
- package/types/logger/codesInfo.d.ts +0 -1
- package/types/logger/codesWarn.d.ts +0 -1
- package/types/logger/codesWarnNode.d.ts +0 -1
- package/types/logger/debugLogger.d.ts +0 -2
- package/types/logger/errorLogger.d.ts +0 -2
- package/types/logger/infoLogger.d.ts +0 -2
- package/types/logger/messages/debugBrowser.d.ts +0 -1
- package/types/logger/messages/debugNode.d.ts +0 -1
- package/types/logger/messages/errorNode.d.ts +0 -1
- package/types/logger/messages/warnNode.d.ts +0 -1
- package/types/logger/noopLogger.d.ts +0 -2
- package/types/logger/warnLogger.d.ts +0 -2
- package/types/sdkClient/types.d.ts +0 -18
- package/types/sdkFactory/userConsentProps.d.ts +0 -6
- package/types/sdkManager/sdkManagerMethod.d.ts +0 -6
- package/types/storages/getRegisteredSegments.d.ts +0 -10
- package/types/storages/inMemory/CountsCacheInMemory.d.ts +0 -20
- package/types/storages/inMemory/LatenciesCacheInMemory.d.ts +0 -20
- package/types/storages/inMemory/index.d.ts +0 -10
- package/types/storages/inRedis/CountsCacheInRedis.d.ts +0 -9
- package/types/storages/inRedis/LatenciesCacheInRedis.d.ts +0 -9
- package/types/storages/parseSegments.d.ts +0 -6
- package/types/sync/offline/LocalhostFromFile.d.ts +0 -2
- package/types/sync/offline/splitsParser/splitsParserFromFile.d.ts +0 -2
- package/types/sync/polling/syncTasks/splitsSyncTask.copy.d.ts +0 -35
- package/types/sync/polling/syncTasks/splitsSyncTask.morelikeoriginal.d.ts +0 -35
- package/types/sync/streaming/AuthClient/indexV1.d.ts +0 -12
- package/types/sync/streaming/AuthClient/indexV2.d.ts +0 -8
- package/types/sync/streaming/pushManagerCS.d.ts +0 -1
- package/types/sync/streaming/pushManagerNoUsers.d.ts +0 -13
- package/types/sync/streaming/pushManagerSS.d.ts +0 -1
- package/types/sync/submitters/eventsSyncTask.d.ts +0 -8
- package/types/sync/submitters/impressionCountsSyncTask.d.ts +0 -13
- package/types/sync/submitters/impressionsSyncTask.d.ts +0 -14
- package/types/sync/submitters/metricsSyncTask.d.ts +0 -12
- package/types/sync/submitters/submitterSyncTask.d.ts +0 -10
- package/types/sync/submitters/telemetrySyncTask.d.ts +0 -0
- package/types/sync/syncManagerFromFile.d.ts +0 -2
- package/types/sync/syncManagerFromObject.d.ts +0 -2
- package/types/sync/syncManagerOffline.d.ts +0 -9
- package/types/sync/syncTaskComposite.d.ts +0 -5
- package/types/trackers/telemetryRecorder.d.ts +0 -0
- package/types/utils/EventEmitter.d.ts +0 -4
- package/types/utils/consent.d.ts +0 -2
- package/types/utils/lang/errors.d.ts +0 -10
- package/types/utils/murmur3/commons.d.ts +0 -12
- package/types/utils/settingsValidation/buildMetadata.d.ts +0 -3
- package/types/utils/settingsValidation/localhost/index.d.ts +0 -9
- package/types/utils/settingsValidation/logger.d.ts +0 -11
- package/types/utils/settingsValidation/runtime/browser.d.ts +0 -2
- package/types/utils/settingsValidation/runtime/node.d.ts +0 -2
- package/types/utils/settingsValidation/userConsent.d.ts +0 -5
- package/types/utils/timeTracker/index.d.ts +0 -1
|
@@ -13,6 +13,7 @@ export var SPLIT_EVENT = 'EVENT';
|
|
|
13
13
|
// Impression collection modes
|
|
14
14
|
export var DEBUG = 'DEBUG';
|
|
15
15
|
export var OPTIMIZED = 'OPTIMIZED';
|
|
16
|
+
export var NONE = 'NONE';
|
|
16
17
|
// SDK Modes
|
|
17
18
|
export var LOCALHOST_MODE = 'localhost';
|
|
18
19
|
export var STANDALONE_MODE = 'standalone';
|
|
@@ -37,6 +38,7 @@ export var CONSUMER_ENUM = 1;
|
|
|
37
38
|
export var CONSUMER_PARTIAL_ENUM = 2;
|
|
38
39
|
export var OPTIMIZED_ENUM = 0;
|
|
39
40
|
export var DEBUG_ENUM = 1;
|
|
41
|
+
export var NONE_ENUM = 2;
|
|
40
42
|
export var SPLITS = 'sp';
|
|
41
43
|
export var IMPRESSIONS = 'im';
|
|
42
44
|
export var IMPRESSIONS_COUNT = 'ic';
|
package/esm/utils/lang/maps.js
CHANGED
|
@@ -37,13 +37,6 @@ var MapPoly = /** @class */ (function () {
|
|
|
37
37
|
this.__mapKeysData__.length = 0;
|
|
38
38
|
this.__mapValuesData__.length = 0;
|
|
39
39
|
};
|
|
40
|
-
MapPoly.prototype.set = function (key, value) {
|
|
41
|
-
var index = this.__mapKeysData__.indexOf(key);
|
|
42
|
-
if (index === -1)
|
|
43
|
-
index = this.__mapKeysData__.push(key) - 1;
|
|
44
|
-
this.__mapValuesData__[index] = value;
|
|
45
|
-
return this;
|
|
46
|
-
};
|
|
47
40
|
MapPoly.prototype.delete = function (key) {
|
|
48
41
|
var index = this.__mapKeysData__.indexOf(key);
|
|
49
42
|
if (index === -1)
|
|
@@ -52,12 +45,27 @@ var MapPoly = /** @class */ (function () {
|
|
|
52
45
|
this.__mapValuesData__.splice(index, 1);
|
|
53
46
|
return true;
|
|
54
47
|
};
|
|
48
|
+
MapPoly.prototype.forEach = function (callbackfn, thisArg) {
|
|
49
|
+
for (var i = 0; i < this.__mapKeysData__.length; i++) {
|
|
50
|
+
callbackfn.call(thisArg, this.__mapValuesData__[i], this.__mapKeysData__[i], this);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
55
53
|
MapPoly.prototype.get = function (key) {
|
|
56
54
|
var index = this.__mapKeysData__.indexOf(key);
|
|
57
55
|
if (index === -1)
|
|
58
56
|
return;
|
|
59
57
|
return this.__mapValuesData__[index];
|
|
60
58
|
};
|
|
59
|
+
MapPoly.prototype.has = function (key) {
|
|
60
|
+
return this.__mapKeysData__.indexOf(key) !== -1;
|
|
61
|
+
};
|
|
62
|
+
MapPoly.prototype.set = function (key, value) {
|
|
63
|
+
var index = this.__mapKeysData__.indexOf(key);
|
|
64
|
+
if (index === -1)
|
|
65
|
+
index = this.__mapKeysData__.push(key) - 1;
|
|
66
|
+
this.__mapValuesData__[index] = value;
|
|
67
|
+
return this;
|
|
68
|
+
};
|
|
61
69
|
Object.defineProperty(MapPoly.prototype, "size", {
|
|
62
70
|
get: function () {
|
|
63
71
|
return this.__mapKeysData__.length;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
//@ts-nocheck
|
|
2
|
+
function identityFunction(data) {
|
|
3
|
+
return data;
|
|
4
|
+
}
|
|
5
|
+
function asyncFunction(data) {
|
|
6
|
+
return Promise.resolve(data);
|
|
7
|
+
}
|
|
8
|
+
var IDENTITY_METHODS = [];
|
|
9
|
+
var ASYNC_METHODS = ['rpush', 'hincrby'];
|
|
10
|
+
var PIPELINE_METHODS = ['rpush', 'hincrby'];
|
|
11
|
+
var RedisMock = /** @class */ (function () {
|
|
12
|
+
function RedisMock() {
|
|
13
|
+
var _this = this;
|
|
14
|
+
this.pipelineMethods = { exec: jest.fn(asyncFunction) };
|
|
15
|
+
IDENTITY_METHODS.forEach(function (method) {
|
|
16
|
+
_this[method] = jest.fn(identityFunction);
|
|
17
|
+
});
|
|
18
|
+
ASYNC_METHODS.forEach(function (method) {
|
|
19
|
+
_this[method] = jest.fn(asyncFunction);
|
|
20
|
+
});
|
|
21
|
+
PIPELINE_METHODS.forEach(function (method) {
|
|
22
|
+
_this.pipelineMethods[method] = _this[method];
|
|
23
|
+
});
|
|
24
|
+
this.pipeline = jest.fn(function () { return _this.pipelineMethods; });
|
|
25
|
+
}
|
|
26
|
+
return RedisMock;
|
|
27
|
+
}());
|
|
28
|
+
export { RedisMock };
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { ERROR_INVALID_CONFIG_PARAM } from '../../logger/constants';
|
|
2
|
-
import { DEBUG, OPTIMIZED } from '../constants';
|
|
2
|
+
import { DEBUG, OPTIMIZED, NONE } from '../constants';
|
|
3
3
|
import { stringToUpperCase } from '../lang';
|
|
4
4
|
export function validImpressionsMode(log, impressionsMode) {
|
|
5
5
|
impressionsMode = stringToUpperCase(impressionsMode);
|
|
6
|
-
if ([DEBUG, OPTIMIZED].indexOf(impressionsMode) > -1)
|
|
6
|
+
if ([DEBUG, OPTIMIZED, NONE].indexOf(impressionsMode) > -1)
|
|
7
7
|
return impressionsMode;
|
|
8
|
-
log.error(ERROR_INVALID_CONFIG_PARAM, ['impressionsMode', [DEBUG, OPTIMIZED], OPTIMIZED]);
|
|
8
|
+
log.error(ERROR_INVALID_CONFIG_PARAM, ['impressionsMode', [DEBUG, OPTIMIZED, NONE], OPTIMIZED]);
|
|
9
9
|
return OPTIMIZED;
|
|
10
10
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@splitsoftware/splitio-commons",
|
|
3
|
-
"version": "1.6.2-rc.
|
|
3
|
+
"version": "1.6.2-rc.10",
|
|
4
4
|
"description": "Split Javascript SDK common components",
|
|
5
5
|
"main": "cjs/index.js",
|
|
6
6
|
"module": "esm/index.js",
|
|
@@ -70,7 +70,6 @@
|
|
|
70
70
|
"ioredis": "^4.28.0",
|
|
71
71
|
"jest": "^27.2.3",
|
|
72
72
|
"jest-localstorage-mock": "^2.4.3",
|
|
73
|
-
"js-yaml": "^3.13.1",
|
|
74
73
|
"lodash": "^4.17.21",
|
|
75
74
|
"node-fetch": "^2.6.7",
|
|
76
75
|
"redis-server": "1.2.2",
|
|
@@ -40,8 +40,8 @@ export function createUserConsentAPI(params: ISdkFactoryContext) {
|
|
|
40
40
|
|
|
41
41
|
// @ts-ignore, clear method is present in storage for standalone and partial consumer mode
|
|
42
42
|
if (events.clear) events.clear(); // @ts-ignore
|
|
43
|
-
if (impressions.clear) impressions.clear()
|
|
44
|
-
if (impressionCounts) impressionCounts.clear();
|
|
43
|
+
if (impressions.clear) impressions.clear();// @ts-ignore
|
|
44
|
+
if (impressionCounts && impressionCounts.clear) impressionCounts.clear();
|
|
45
45
|
}
|
|
46
46
|
} else {
|
|
47
47
|
log.info(USER_CONSENT_NOT_UPDATED, [newConsentStatus]);
|
package/src/evaluator/index.ts
CHANGED
|
@@ -29,19 +29,19 @@ export function evaluateFeature(
|
|
|
29
29
|
attributes: SplitIO.Attributes | undefined,
|
|
30
30
|
storage: IStorageSync | IStorageAsync,
|
|
31
31
|
): MaybeThenable<IEvaluationResult> {
|
|
32
|
-
let
|
|
32
|
+
let parsedSplit;
|
|
33
33
|
|
|
34
34
|
try {
|
|
35
|
-
|
|
35
|
+
parsedSplit = storage.splits.getSplit(splitName);
|
|
36
36
|
} catch (e) {
|
|
37
37
|
// Exception on sync `getSplit` storage. Not possible ATM with InMemory and InLocal storages.
|
|
38
38
|
return treatmentException;
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
if (thenable(
|
|
42
|
-
return
|
|
41
|
+
if (thenable(parsedSplit)) {
|
|
42
|
+
return parsedSplit.then((split) => getEvaluation(
|
|
43
43
|
log,
|
|
44
|
-
|
|
44
|
+
split,
|
|
45
45
|
key,
|
|
46
46
|
attributes,
|
|
47
47
|
storage,
|
|
@@ -54,7 +54,7 @@ export function evaluateFeature(
|
|
|
54
54
|
|
|
55
55
|
return getEvaluation(
|
|
56
56
|
log,
|
|
57
|
-
|
|
57
|
+
parsedSplit,
|
|
58
58
|
key,
|
|
59
59
|
attributes,
|
|
60
60
|
storage,
|
|
@@ -68,28 +68,28 @@ export function evaluateFeatures(
|
|
|
68
68
|
attributes: SplitIO.Attributes | undefined,
|
|
69
69
|
storage: IStorageSync | IStorageAsync,
|
|
70
70
|
): MaybeThenable<Record<string, IEvaluationResult>> {
|
|
71
|
-
let
|
|
71
|
+
let parsedSplits;
|
|
72
72
|
|
|
73
73
|
try {
|
|
74
|
-
|
|
74
|
+
parsedSplits = storage.splits.getSplits(splitNames);
|
|
75
75
|
} catch (e) {
|
|
76
76
|
// Exception on sync `getSplits` storage. Not possible ATM with InMemory and InLocal storages.
|
|
77
77
|
return treatmentsException(splitNames);
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
-
return
|
|
81
|
-
|
|
80
|
+
return thenable(parsedSplits) ?
|
|
81
|
+
parsedSplits.then(splits => getEvaluations(log, splitNames, splits, key, attributes, storage))
|
|
82
82
|
.catch(() => {
|
|
83
83
|
// Exception on async `getSplits` storage. For example, when the storage is redis or
|
|
84
84
|
// pluggable and there is a connection issue and we can't retrieve the split to be evaluated
|
|
85
85
|
return treatmentsException(splitNames);
|
|
86
86
|
}) :
|
|
87
|
-
getEvaluations(log, splitNames,
|
|
87
|
+
getEvaluations(log, splitNames, parsedSplits, key, attributes, storage);
|
|
88
88
|
}
|
|
89
89
|
|
|
90
90
|
function getEvaluation(
|
|
91
91
|
log: ILogger,
|
|
92
|
-
|
|
92
|
+
splitJSON: ISplit | null,
|
|
93
93
|
key: SplitIO.SplitKey,
|
|
94
94
|
attributes: SplitIO.Attributes | undefined,
|
|
95
95
|
storage: IStorageSync | IStorageAsync,
|
|
@@ -100,8 +100,7 @@ function getEvaluation(
|
|
|
100
100
|
config: null
|
|
101
101
|
};
|
|
102
102
|
|
|
103
|
-
if (
|
|
104
|
-
const splitJSON: ISplit = JSON.parse(stringifiedSplit);
|
|
103
|
+
if (splitJSON) {
|
|
105
104
|
const split = Engine.parse(log, splitJSON, storage);
|
|
106
105
|
evaluation = split.getTreatment(key, attributes, evaluateFeature);
|
|
107
106
|
|
|
@@ -125,7 +124,7 @@ function getEvaluation(
|
|
|
125
124
|
function getEvaluations(
|
|
126
125
|
log: ILogger,
|
|
127
126
|
splitNames: string[],
|
|
128
|
-
splits: Record<string,
|
|
127
|
+
splits: Record<string, ISplit | null>,
|
|
129
128
|
key: SplitIO.SplitKey,
|
|
130
129
|
attributes: SplitIO.Attributes | undefined,
|
|
131
130
|
storage: IStorageSync | IStorageAsync,
|
|
@@ -12,6 +12,7 @@ import { SplitIO } from '../../types';
|
|
|
12
12
|
import { Identity, GoogleAnalyticsToSplitOptions } from './types';
|
|
13
13
|
import { ILogger } from '../../logger/types';
|
|
14
14
|
import { IIntegrationFactoryParams } from '../types';
|
|
15
|
+
import { ITelemetryTracker } from '../../trackers/types';
|
|
15
16
|
|
|
16
17
|
const logPrefix = 'ga-to-split: ';
|
|
17
18
|
const logNameMapper = 'ga-to-split:mapper';
|
|
@@ -25,7 +26,7 @@ const logNameMapper = 'ga-to-split:mapper';
|
|
|
25
26
|
* @param log Logger instance.
|
|
26
27
|
* @param autoRequire If true, log error when auto-require script is not detected
|
|
27
28
|
*/
|
|
28
|
-
function providePlugin(window: any, pluginName: string, pluginConstructor: Function, log: ILogger, autoRequire?:
|
|
29
|
+
function providePlugin(window: any, pluginName: string, pluginConstructor: Function, log: ILogger, autoRequire: boolean, telemetryTracker?: ITelemetryTracker) {
|
|
29
30
|
// get reference to global command queue. Init it if not defined yet.
|
|
30
31
|
const gaAlias = window.GoogleAnalyticsObject || 'ga';
|
|
31
32
|
window[gaAlias] = window[gaAlias] || function () {
|
|
@@ -35,10 +36,13 @@ function providePlugin(window: any, pluginName: string, pluginConstructor: Funct
|
|
|
35
36
|
// provides the plugin for use with analytics.js.
|
|
36
37
|
window[gaAlias]('provide', pluginName, pluginConstructor);
|
|
37
38
|
|
|
38
|
-
|
|
39
|
-
|
|
39
|
+
const hasAutoRequire = window[gaAlias].q && window[gaAlias].q.push !== [].push;
|
|
40
|
+
if (autoRequire && !hasAutoRequire) { // Expecting spy on ga.q push method but not found
|
|
40
41
|
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.');
|
|
41
42
|
}
|
|
43
|
+
if (telemetryTracker && hasAutoRequire) {
|
|
44
|
+
telemetryTracker.addTag('integration:ga-autorequire');
|
|
45
|
+
}
|
|
42
46
|
}
|
|
43
47
|
|
|
44
48
|
// Default mapping: object used for building the default mapper from hits to Split events
|
|
@@ -191,7 +195,7 @@ export function fixEventTypeId(log: ILogger, eventTypeId: any) {
|
|
|
191
195
|
*/
|
|
192
196
|
export function GaToSplit(sdkOptions: GoogleAnalyticsToSplitOptions, params: IIntegrationFactoryParams) {
|
|
193
197
|
|
|
194
|
-
const { storage, settings: { core: coreSettings, log } } = params;
|
|
198
|
+
const { storage, settings: { core: coreSettings, log }, telemetryTracker } = params;
|
|
195
199
|
|
|
196
200
|
const defaultOptions = {
|
|
197
201
|
prefix: defaultPrefix,
|
|
@@ -291,5 +295,5 @@ export function GaToSplit(sdkOptions: GoogleAnalyticsToSplitOptions, params: IIn
|
|
|
291
295
|
}
|
|
292
296
|
|
|
293
297
|
// Register the plugin, even if config is invalid, since, if not provided, it will block `ga` command queue.
|
|
294
|
-
providePlugin(window, 'splitTracker', SplitTracker, log, sdkOptions.autoRequire === true);
|
|
298
|
+
providePlugin(window, 'splitTracker', SplitTracker, log, sdkOptions.autoRequire === true, telemetryTracker);
|
|
295
299
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IEventsCacheBase } from '../storages/types';
|
|
2
|
-
import { IEventsHandler, IImpressionsHandler } from '../trackers/types';
|
|
2
|
+
import { IEventsHandler, IImpressionsHandler, ITelemetryTracker } from '../trackers/types';
|
|
3
3
|
import { ISettings, SplitIO } from '../types';
|
|
4
4
|
|
|
5
5
|
export interface IIntegration {
|
|
@@ -11,6 +11,7 @@ export type IIntegrationManager = IEventsHandler & IImpressionsHandler;
|
|
|
11
11
|
export interface IIntegrationFactoryParams {
|
|
12
12
|
storage: { events: IEventsCacheBase }
|
|
13
13
|
settings: ISettings
|
|
14
|
+
telemetryTracker: ITelemetryTracker
|
|
14
15
|
}
|
|
15
16
|
|
|
16
17
|
export type IntegrationFactory = {
|
package/src/listeners/browser.ts
CHANGED
|
@@ -7,7 +7,7 @@ import { fromImpressionCountsCollector } from '../sync/submitters/impressionCoun
|
|
|
7
7
|
import { IResponse, ISplitApi } from '../services/types';
|
|
8
8
|
import { ImpressionDTO, ISettings } from '../types';
|
|
9
9
|
import { ImpressionsPayload } from '../sync/submitters/types';
|
|
10
|
-
import { OPTIMIZED, DEBUG } from '../utils/constants';
|
|
10
|
+
import { OPTIMIZED, DEBUG, NONE } from '../utils/constants';
|
|
11
11
|
import { objectAssign } from '../utils/lang/objectAssign';
|
|
12
12
|
import { CLEANUP_REGISTERING, CLEANUP_DEREGISTERING } from '../logger/constants';
|
|
13
13
|
import { ISyncManager } from '../sync/types';
|
|
@@ -88,9 +88,10 @@ export class BrowserSignalListener implements ISignalListener {
|
|
|
88
88
|
// Flush impressions & events data if there is user consent
|
|
89
89
|
if (isConsentGranted(this.settings)) {
|
|
90
90
|
const eventsUrl = this.settings.urls.events;
|
|
91
|
+
const sim = this.settings.sync.impressionsMode;
|
|
91
92
|
const extraMetadata = {
|
|
92
93
|
// sim stands for Sync/Split Impressions Mode
|
|
93
|
-
sim:
|
|
94
|
+
sim: sim === OPTIMIZED ? OPTIMIZED : sim === DEBUG ? DEBUG : NONE
|
|
94
95
|
};
|
|
95
96
|
|
|
96
97
|
this._flushData(eventsUrl + '/testImpressions/beacon', this.storage.impressions, this.serviceApi.postTestImpressionsBulk, this.fromImpressionsCollector, extraMetadata);
|
package/src/logger/constants.ts
CHANGED
|
@@ -143,4 +143,5 @@ export const LOG_PREFIX_SYNC_POLLING = LOG_PREFIX_SYNC + ':polling-manager: ';
|
|
|
143
143
|
export const LOG_PREFIX_SYNC_SUBMITTERS = LOG_PREFIX_SYNC + ':submitter: ';
|
|
144
144
|
export const LOG_PREFIX_IMPRESSIONS_TRACKER = 'impressions-tracker: ';
|
|
145
145
|
export const LOG_PREFIX_EVENTS_TRACKER = 'events-tracker: ';
|
|
146
|
+
export const LOG_PREFIX_UNIQUE_KEYS_TRACKER = 'unique-keys-tracker: ';
|
|
146
147
|
export const LOG_PREFIX_CLEANUP = 'cleanup: ';
|
package/src/sdkClient/client.ts
CHANGED
|
@@ -9,6 +9,17 @@ import { IEvaluationResult } from '../evaluator/types';
|
|
|
9
9
|
import { SplitIO, ImpressionDTO } from '../types';
|
|
10
10
|
import { IMPRESSION, IMPRESSION_QUEUEING } from '../logger/constants';
|
|
11
11
|
import { ISdkFactoryContext } from '../sdkFactory/types';
|
|
12
|
+
import { isStorageSync } from '../trackers/impressionObserver/utils';
|
|
13
|
+
|
|
14
|
+
const treatmentNotReady = { treatment: CONTROL, label: SDK_NOT_READY };
|
|
15
|
+
|
|
16
|
+
function treatmentsNotReady(splitNames: string[]) {
|
|
17
|
+
const evaluations: Record<string, IEvaluationResult> = {};
|
|
18
|
+
splitNames.forEach(splitName => {
|
|
19
|
+
evaluations[splitName] = treatmentNotReady;
|
|
20
|
+
});
|
|
21
|
+
return evaluations;
|
|
22
|
+
}
|
|
12
23
|
|
|
13
24
|
/**
|
|
14
25
|
* Creator of base client with getTreatments and track methods.
|
|
@@ -29,7 +40,11 @@ export function clientFactory(params: ISdkFactoryContext): SplitIO.IClient | Spl
|
|
|
29
40
|
return treatment;
|
|
30
41
|
};
|
|
31
42
|
|
|
32
|
-
const evaluation =
|
|
43
|
+
const evaluation = readinessManager.isReady() || readinessManager.isReadyFromCache() ?
|
|
44
|
+
evaluateFeature(log, key, splitName, attributes, storage) :
|
|
45
|
+
isStorageSync(settings) ? // If the SDK is not ready, treatment may be incorrect due to having splits but not segments data, or storage is not connected
|
|
46
|
+
treatmentNotReady :
|
|
47
|
+
Promise.resolve(treatmentNotReady); // Promisify if async
|
|
33
48
|
|
|
34
49
|
return thenable(evaluation) ? evaluation.then((res) => wrapUp(res)) : wrapUp(evaluation);
|
|
35
50
|
}
|
|
@@ -53,7 +68,11 @@ export function clientFactory(params: ISdkFactoryContext): SplitIO.IClient | Spl
|
|
|
53
68
|
return treatments;
|
|
54
69
|
};
|
|
55
70
|
|
|
56
|
-
const evaluations =
|
|
71
|
+
const evaluations = readinessManager.isReady() || readinessManager.isReadyFromCache() ?
|
|
72
|
+
evaluateFeatures(log, key, splitNames, attributes, storage) :
|
|
73
|
+
isStorageSync(settings) ? // If the SDK is not ready, treatment may be incorrect due to having splits but not segments data, or storage is not connected
|
|
74
|
+
treatmentsNotReady(splitNames) :
|
|
75
|
+
Promise.resolve(treatmentsNotReady(splitNames)); // Promisify if async
|
|
57
76
|
|
|
58
77
|
return thenable(evaluations) ? evaluations.then((res) => wrapUp(res)) : wrapUp(evaluations);
|
|
59
78
|
}
|
|
@@ -72,15 +91,9 @@ export function clientFactory(params: ISdkFactoryContext): SplitIO.IClient | Spl
|
|
|
72
91
|
invokingMethodName: string,
|
|
73
92
|
queue: ImpressionDTO[]
|
|
74
93
|
): SplitIO.Treatment | SplitIO.TreatmentWithConfig {
|
|
75
|
-
const isSdkReady = readinessManager.isReady() || readinessManager.isReadyFromCache();
|
|
76
94
|
const matchingKey = getMatching(key);
|
|
77
95
|
const bucketingKey = getBucketing(key);
|
|
78
96
|
|
|
79
|
-
// If the SDK was not ready, treatment may be incorrect due to having Splits but not segments data.
|
|
80
|
-
if (!isSdkReady) {
|
|
81
|
-
evaluation = { treatment: CONTROL, label: SDK_NOT_READY };
|
|
82
|
-
}
|
|
83
|
-
|
|
84
97
|
const { treatment, label, changeNumber, config = null } = evaluation;
|
|
85
98
|
log.info(IMPRESSION, [splitName, matchingKey, treatment, label]);
|
|
86
99
|
|
|
@@ -9,7 +9,7 @@ import { ISdkFactoryContext } from '../sdkFactory/types';
|
|
|
9
9
|
* Creates an Sdk client, i.e., a base client with status and destroy interface
|
|
10
10
|
*/
|
|
11
11
|
export function sdkClientFactory(params: ISdkFactoryContext, isSharedClient?: boolean): SplitIO.IClient | SplitIO.IAsyncClient {
|
|
12
|
-
const { sdkReadinessManager, syncManager, storage, signalListener, settings, telemetryTracker } = params;
|
|
12
|
+
const { sdkReadinessManager, syncManager, storage, signalListener, settings, telemetryTracker, uniqueKeysTracker } = params;
|
|
13
13
|
|
|
14
14
|
return objectAssign(
|
|
15
15
|
// Proto-linkage of the readiness Event Emitter
|
|
@@ -39,6 +39,8 @@ export function sdkClientFactory(params: ISdkFactoryContext, isSharedClient?: bo
|
|
|
39
39
|
|
|
40
40
|
// Release the API Key if it is the main client
|
|
41
41
|
if (!isSharedClient) releaseApiKey(settings.core.authorizationKey);
|
|
42
|
+
|
|
43
|
+
if (uniqueKeysTracker) uniqueKeysTracker.stop();
|
|
42
44
|
|
|
43
45
|
// Cleanup storage
|
|
44
46
|
return storage.destroy();
|
package/src/sdkFactory/index.ts
CHANGED
|
@@ -13,6 +13,11 @@ import { NEW_FACTORY, RETRIEVE_MANAGER } from '../logger/constants';
|
|
|
13
13
|
import { metadataBuilder } from '../storages/metadataBuilder';
|
|
14
14
|
import { SDK_SPLITS_ARRIVED, SDK_SEGMENTS_ARRIVED } from '../readiness/constants';
|
|
15
15
|
import { objectAssign } from '../utils/lang/objectAssign';
|
|
16
|
+
import { strategyDebugFactory } from '../trackers/strategy/strategyDebug';
|
|
17
|
+
import { strategyOptimizedFactory } from '../trackers/strategy/strategyOptimized';
|
|
18
|
+
import { strategyNoneFactory } from '../trackers/strategy/strategyNone';
|
|
19
|
+
import { uniqueKeysTrackerFactory } from '../trackers/uniqueKeysTracker';
|
|
20
|
+
import { NONE, OPTIMIZED } from '../utils/constants';
|
|
16
21
|
|
|
17
22
|
/**
|
|
18
23
|
* Modular SDK factory
|
|
@@ -21,7 +26,8 @@ export function sdkFactory(params: ISdkFactoryParams): SplitIO.ICsSDK | SplitIO.
|
|
|
21
26
|
|
|
22
27
|
const { settings, platform, storageFactory, splitApiFactory, extraProps,
|
|
23
28
|
syncManagerFactory, SignalListener, impressionsObserverFactory,
|
|
24
|
-
integrationsManagerFactory, sdkManagerFactory, sdkClientMethodFactory
|
|
29
|
+
integrationsManagerFactory, sdkManagerFactory, sdkClientMethodFactory,
|
|
30
|
+
filterAdapterFactory } = params;
|
|
25
31
|
const log = settings.log;
|
|
26
32
|
|
|
27
33
|
// @TODO handle non-recoverable errors, such as, global `fetch` not available, invalid API Key, etc.
|
|
@@ -45,6 +51,7 @@ export function sdkFactory(params: ISdkFactoryParams): SplitIO.ICsSDK | SplitIO.
|
|
|
45
51
|
|
|
46
52
|
// ATM, only used by PluggableStorage
|
|
47
53
|
mode: settings.mode,
|
|
54
|
+
impressionsMode: settings.sync.impressionsMode,
|
|
48
55
|
|
|
49
56
|
// Callback used to emit SDK_READY in consumer mode, where `syncManagerFactory` is undefined,
|
|
50
57
|
// or partial consumer mode, where it only has submitters, and therefore it doesn't emit readiness events.
|
|
@@ -60,18 +67,31 @@ export function sdkFactory(params: ISdkFactoryParams): SplitIO.ICsSDK | SplitIO.
|
|
|
60
67
|
const storage = storageFactory(storageFactoryParams);
|
|
61
68
|
// @TODO add support for dataloader: `if (params.dataLoader) params.dataLoader(storage);`
|
|
62
69
|
|
|
63
|
-
const integrationsManager = integrationsManagerFactory && integrationsManagerFactory({ settings, storage });
|
|
64
|
-
|
|
65
|
-
// trackers
|
|
66
|
-
const observer = impressionsObserverFactory && impressionsObserverFactory();
|
|
67
|
-
const impressionsTracker = impressionsTrackerFactory(settings, storage.impressions, integrationsManager, observer, storage.impressionCounts, storage.telemetry);
|
|
68
|
-
const eventTracker = eventTrackerFactory(settings, storage.events, integrationsManager, storage.telemetry);
|
|
69
70
|
const telemetryTracker = telemetryTrackerFactory(storage.telemetry, platform.now);
|
|
71
|
+
const integrationsManager = integrationsManagerFactory && integrationsManagerFactory({ settings, storage, telemetryTracker });
|
|
72
|
+
|
|
73
|
+
const observer = impressionsObserverFactory();
|
|
74
|
+
const uniqueKeysTracker = storageFactoryParams.impressionsMode === NONE ? uniqueKeysTrackerFactory(log, storage.uniqueKeys!, filterAdapterFactory && filterAdapterFactory()) : undefined;
|
|
75
|
+
|
|
76
|
+
let strategy;
|
|
77
|
+
switch (storageFactoryParams.impressionsMode) {
|
|
78
|
+
case OPTIMIZED:
|
|
79
|
+
strategy = strategyOptimizedFactory(observer, storage.impressionCounts!);
|
|
80
|
+
break;
|
|
81
|
+
case NONE:
|
|
82
|
+
strategy = strategyNoneFactory(storage.impressionCounts!, uniqueKeysTracker!);
|
|
83
|
+
break;
|
|
84
|
+
default:
|
|
85
|
+
strategy = strategyDebugFactory(observer);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const impressionsTracker = impressionsTrackerFactory(settings, storage.impressions, strategy, integrationsManager, storage.telemetry);
|
|
89
|
+
const eventTracker = eventTrackerFactory(settings, storage.events, integrationsManager, storage.telemetry);
|
|
70
90
|
|
|
71
91
|
// splitApi is used by SyncManager and Browser signal listener
|
|
72
92
|
const splitApi = splitApiFactory && splitApiFactory(settings, platform, telemetryTracker);
|
|
73
93
|
|
|
74
|
-
const ctx: ISdkFactoryContext = { splitApi, eventTracker, impressionsTracker, telemetryTracker, sdkReadinessManager, readiness, settings, storage, platform };
|
|
94
|
+
const ctx: ISdkFactoryContext = { splitApi, eventTracker, impressionsTracker, telemetryTracker, uniqueKeysTracker, sdkReadinessManager, readiness, settings, storage, platform };
|
|
75
95
|
|
|
76
96
|
const syncManager = syncManagerFactory && syncManagerFactory(ctx as ISdkFactoryContextSync);
|
|
77
97
|
ctx.syncManager = syncManager;
|
package/src/sdkFactory/types.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { IFetch, ISplitApi, IEventSourceConstructor } from '../services/types';
|
|
|
6
6
|
import { IStorageAsync, IStorageSync, ISplitsCacheSync, ISplitsCacheAsync, IStorageFactoryParams } from '../storages/types';
|
|
7
7
|
import { ISyncManager } from '../sync/types';
|
|
8
8
|
import { IImpressionObserver } from '../trackers/impressionObserver/types';
|
|
9
|
-
import { IImpressionsTracker, IEventTracker, ITelemetryTracker } from '../trackers/types';
|
|
9
|
+
import { IImpressionsTracker, IEventTracker, ITelemetryTracker, IFilterAdapter, IUniqueKeysTracker } from '../trackers/types';
|
|
10
10
|
import { SplitIO, ISettings, IEventEmitter } from '../types';
|
|
11
11
|
|
|
12
12
|
/**
|
|
@@ -44,6 +44,7 @@ export interface ISdkFactoryContext {
|
|
|
44
44
|
eventTracker: IEventTracker,
|
|
45
45
|
telemetryTracker: ITelemetryTracker,
|
|
46
46
|
storage: IStorageSync | IStorageAsync,
|
|
47
|
+
uniqueKeysTracker?: IUniqueKeysTracker,
|
|
47
48
|
signalListener?: ISignalListener
|
|
48
49
|
splitApi?: ISplitApi
|
|
49
50
|
syncManager?: ISyncManager,
|
|
@@ -96,6 +97,11 @@ export interface ISdkFactoryParams {
|
|
|
96
97
|
// It Allows to distinguish SDK clients with the client-side API (`ICsSDK`) or server-side API (`ISDK` or `IAsyncSDK`).
|
|
97
98
|
sdkClientMethodFactory: (params: ISdkFactoryContext) => ({ (): SplitIO.ICsClient; (key: SplitIO.SplitKey, trafficType?: string | undefined): SplitIO.ICsClient; } | (() => SplitIO.IClient) | (() => SplitIO.IAsyncClient))
|
|
98
99
|
|
|
100
|
+
// Impression observer factory. If provided, will be used for impressions dedupe
|
|
101
|
+
impressionsObserverFactory: () => IImpressionObserver
|
|
102
|
+
|
|
103
|
+
filterAdapterFactory?: () => IFilterAdapter
|
|
104
|
+
|
|
99
105
|
// Optional signal listener constructor. Used to handle special app states, like shutdown, app paused or resumed.
|
|
100
106
|
// Pass only if `syncManager` (used by Node listener) and `splitApi` (used by Browser listener) are passed.
|
|
101
107
|
SignalListener?: new (
|
|
@@ -107,9 +113,6 @@ export interface ISdkFactoryParams {
|
|
|
107
113
|
// @TODO review impressionListener and integrations interfaces. What about handling impressionListener as an integration ?
|
|
108
114
|
integrationsManagerFactory?: (params: IIntegrationFactoryParams) => IIntegrationManager | undefined,
|
|
109
115
|
|
|
110
|
-
// Impression observer factory. If provided, will be used for impressions dedupe
|
|
111
|
-
impressionsObserverFactory?: () => IImpressionObserver
|
|
112
|
-
|
|
113
116
|
// Optional function to assign additional properties to the factory instance
|
|
114
117
|
extraProps?: (params: ISdkFactoryContext) => object
|
|
115
118
|
}
|
package/src/sdkManager/index.ts
CHANGED
|
@@ -18,16 +18,7 @@ function collectTreatments(splitObject: ISplit) {
|
|
|
18
18
|
return allTreatmentsCondition ? allTreatmentsCondition.partitions.map(v => v.treatment) : [];
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
function objectToView(
|
|
22
|
-
let splitObject: ISplit | null;
|
|
23
|
-
|
|
24
|
-
try {
|
|
25
|
-
// @ts-expect-error
|
|
26
|
-
splitObject = JSON.parse(json);
|
|
27
|
-
} catch (e) {
|
|
28
|
-
return null;
|
|
29
|
-
}
|
|
30
|
-
|
|
21
|
+
function objectToView(splitObject: ISplit | null): SplitIO.SplitView | null {
|
|
31
22
|
if (!splitObject) return null;
|
|
32
23
|
|
|
33
24
|
return {
|
|
@@ -40,10 +31,10 @@ function objectToView(json: string | null): SplitIO.SplitView | null {
|
|
|
40
31
|
};
|
|
41
32
|
}
|
|
42
33
|
|
|
43
|
-
function objectsToViews(
|
|
34
|
+
function objectsToViews(splitObjects: ISplit[]) {
|
|
44
35
|
let views: SplitIO.SplitView[] = [];
|
|
45
36
|
|
|
46
|
-
|
|
37
|
+
splitObjects.forEach(split => {
|
|
47
38
|
const view = objectToView(split);
|
|
48
39
|
if (view) views.push(view);
|
|
49
40
|
});
|
package/src/services/splitApi.ts
CHANGED
|
@@ -106,15 +106,37 @@ export function splitApiFactory(
|
|
|
106
106
|
const url = `${urls.events}/testImpressions/count`;
|
|
107
107
|
return splitHttpClient(url, { method: 'POST', body, headers }, telemetryTracker.trackHttp(IMPRESSIONS_COUNT));
|
|
108
108
|
},
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Post unique keys for client side.
|
|
112
|
+
*
|
|
113
|
+
* @param body unique keys payload
|
|
114
|
+
* @param headers Optionals headers to overwrite default ones. For example, it is used in producer mode to overwrite metadata headers.
|
|
115
|
+
*/
|
|
116
|
+
postUniqueKeysBulkCs(body: string, headers?: Record<string, string>) {
|
|
117
|
+
const url = `${urls.telemetry}/v1/keys/cs`;
|
|
118
|
+
return splitHttpClient(url, { method: 'POST', body, headers }, telemetryTracker.trackHttp(TELEMETRY));
|
|
119
|
+
},
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Post unique keys for server side.
|
|
123
|
+
*
|
|
124
|
+
* @param body unique keys payload
|
|
125
|
+
* @param headers Optionals headers to overwrite default ones. For example, it is used in producer mode to overwrite metadata headers.
|
|
126
|
+
*/
|
|
127
|
+
postUniqueKeysBulkSs(body: string, headers?: Record<string, string>) {
|
|
128
|
+
const url = `${urls.telemetry}/v1/keys/ss`;
|
|
129
|
+
return splitHttpClient(url, { method: 'POST', body, headers }, telemetryTracker.trackHttp(TELEMETRY));
|
|
130
|
+
},
|
|
109
131
|
|
|
110
|
-
postMetricsConfig(body: string) {
|
|
132
|
+
postMetricsConfig(body: string, headers?: Record<string, string>) {
|
|
111
133
|
const url = `${urls.telemetry}/v1/metrics/config`;
|
|
112
|
-
return splitHttpClient(url, { method: 'POST', body }, telemetryTracker.trackHttp(TELEMETRY), true);
|
|
134
|
+
return splitHttpClient(url, { method: 'POST', body, headers }, telemetryTracker.trackHttp(TELEMETRY), true);
|
|
113
135
|
},
|
|
114
136
|
|
|
115
|
-
postMetricsUsage(body: string) {
|
|
137
|
+
postMetricsUsage(body: string, headers?: Record<string, string>) {
|
|
116
138
|
const url = `${urls.telemetry}/v1/metrics/usage`;
|
|
117
|
-
return splitHttpClient(url, { method: 'POST', body }, telemetryTracker.trackHttp(TELEMETRY), true);
|
|
139
|
+
return splitHttpClient(url, { method: 'POST', body, headers }, telemetryTracker.trackHttp(TELEMETRY), true);
|
|
118
140
|
}
|
|
119
141
|
};
|
|
120
142
|
}
|
package/src/services/types.ts
CHANGED
|
@@ -43,13 +43,17 @@ export type IFetchMySegments = (userMatchingKey: string, noCache?: boolean) => P
|
|
|
43
43
|
|
|
44
44
|
export type IPostEventsBulk = (body: string, headers?: Record<string, string>) => Promise<IResponse>
|
|
45
45
|
|
|
46
|
+
export type IPostUniqueKeysBulkCs = (body: string, headers?: Record<string, string>) => Promise<IResponse>
|
|
47
|
+
|
|
48
|
+
export type IPostUniqueKeysBulkSs = (body: string, headers?: Record<string, string>) => Promise<IResponse>
|
|
49
|
+
|
|
46
50
|
export type IPostTestImpressionsBulk = (body: string, headers?: Record<string, string>) => Promise<IResponse>
|
|
47
51
|
|
|
48
52
|
export type IPostTestImpressionsCount = (body: string, headers?: Record<string, string>) => Promise<IResponse>
|
|
49
53
|
|
|
50
|
-
export type IPostMetricsConfig = (body: string) => Promise<IResponse>
|
|
54
|
+
export type IPostMetricsConfig = (body: string, headers?: Record<string, string>) => Promise<IResponse>
|
|
51
55
|
|
|
52
|
-
export type IPostMetricsUsage = (body: string) => Promise<IResponse>
|
|
56
|
+
export type IPostMetricsUsage = (body: string, headers?: Record<string, string>) => Promise<IResponse>
|
|
53
57
|
|
|
54
58
|
export interface ISplitApi {
|
|
55
59
|
getSdkAPIHealthCheck: IHealthCheckAPI
|
|
@@ -59,6 +63,8 @@ export interface ISplitApi {
|
|
|
59
63
|
fetchSegmentChanges: IFetchSegmentChanges
|
|
60
64
|
fetchMySegments: IFetchMySegments
|
|
61
65
|
postEventsBulk: IPostEventsBulk
|
|
66
|
+
postUniqueKeysBulkCs: IPostUniqueKeysBulkCs
|
|
67
|
+
postUniqueKeysBulkSs: IPostUniqueKeysBulkSs
|
|
62
68
|
postTestImpressionsBulk: IPostTestImpressionsBulk
|
|
63
69
|
postTestImpressionsCount: IPostTestImpressionsCount
|
|
64
70
|
postMetricsConfig: IPostMetricsConfig
|