@splitsoftware/splitio-commons 1.6.2-rc.5 → 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/consent/sdkUserConsent.js +2 -2
- package/cjs/evaluator/index.js +10 -11
- package/cjs/integrations/ga/GaToSplit.js +8 -5
- package/cjs/listeners/browser.js +1 -2
- package/cjs/logger/constants.js +1 -2
- package/cjs/sdkFactory/index.js +7 -25
- package/cjs/sdkManager/index.js +3 -11
- package/cjs/services/splitApi.js +0 -20
- package/cjs/storages/AbstractSplitsCacheAsync.js +7 -9
- package/cjs/storages/AbstractSplitsCacheSync.js +7 -9
- package/cjs/storages/KeyBuilderSS.js +0 -6
- package/cjs/storages/dataLoader.js +1 -1
- package/cjs/storages/inLocalStorage/SplitsCacheInLocal.js +5 -6
- package/cjs/storages/inLocalStorage/index.js +0 -4
- package/cjs/storages/inMemory/ImpressionCountsCacheInMemory.js +1 -12
- package/cjs/storages/inMemory/InMemoryStorage.js +1 -5
- package/cjs/storages/inMemory/InMemoryStorageCS.js +1 -5
- package/cjs/storages/inMemory/SplitsCacheInMemory.js +7 -10
- package/cjs/storages/inRedis/SplitsCacheInRedis.js +15 -9
- package/cjs/storages/inRedis/constants.js +1 -4
- package/cjs/storages/inRedis/index.js +1 -15
- 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/sync/submitters/submitterManager.js +0 -3
- package/cjs/sync/submitters/telemetrySubmitter.js +0 -1
- package/cjs/trackers/impressionsTracker.js +41 -22
- package/cjs/trackers/telemetryTracker.js +6 -0
- package/cjs/utils/constants/index.js +2 -4
- package/cjs/utils/settingsValidation/impressionsMode.js +2 -2
- package/cjs/utils/settingsValidation/index.js +0 -3
- package/esm/consent/sdkUserConsent.js +2 -2
- package/esm/evaluator/index.js +10 -11
- package/esm/integrations/ga/GaToSplit.js +8 -5
- package/esm/listeners/browser.js +2 -3
- package/esm/logger/constants.js +0 -1
- package/esm/sdkFactory/index.js +7 -25
- package/esm/sdkManager/index.js +3 -11
- package/esm/services/splitApi.js +0 -20
- package/esm/storages/AbstractSplitsCacheAsync.js +7 -9
- package/esm/storages/AbstractSplitsCacheSync.js +7 -9
- package/esm/storages/KeyBuilderSS.js +0 -6
- package/esm/storages/dataLoader.js +1 -1
- package/esm/storages/inLocalStorage/SplitsCacheInLocal.js +5 -6
- package/esm/storages/inLocalStorage/index.js +1 -5
- package/esm/storages/inMemory/ImpressionCountsCacheInMemory.js +1 -12
- package/esm/storages/inMemory/InMemoryStorage.js +2 -6
- package/esm/storages/inMemory/InMemoryStorageCS.js +2 -6
- package/esm/storages/inMemory/SplitsCacheInMemory.js +7 -10
- package/esm/storages/inRedis/SplitsCacheInRedis.js +15 -9
- package/esm/storages/inRedis/constants.js +0 -3
- package/esm/storages/inRedis/index.js +2 -16
- 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/sync/submitters/submitterManager.js +0 -3
- package/esm/sync/submitters/telemetrySubmitter.js +1 -2
- package/esm/trackers/impressionsTracker.js +41 -22
- package/esm/trackers/telemetryTracker.js +6 -0
- package/esm/utils/constants/index.js +0 -2
- package/esm/utils/settingsValidation/impressionsMode.js +3 -3
- package/esm/utils/settingsValidation/index.js +0 -3
- package/package.json +1 -1
- package/src/consent/sdkUserConsent.ts +2 -2
- package/src/evaluator/index.ts +8 -9
- package/src/integrations/ga/GaToSplit.ts +9 -5
- package/src/integrations/types.ts +2 -1
- package/src/listeners/browser.ts +2 -3
- package/src/logger/.DS_Store +0 -0
- package/src/logger/constants.ts +0 -1
- package/src/sdkFactory/index.ts +7 -28
- package/src/sdkFactory/types.ts +4 -7
- package/src/sdkManager/index.ts +3 -12
- package/src/services/splitApi.ts +0 -22
- package/src/services/types.ts +0 -6
- package/src/storages/AbstractSplitsCacheAsync.ts +13 -14
- package/src/storages/AbstractSplitsCacheSync.ts +14 -16
- package/src/storages/KeyBuilderSS.ts +0 -8
- package/src/storages/dataLoader.ts +1 -1
- package/src/storages/inLocalStorage/SplitsCacheInLocal.ts +8 -10
- package/src/storages/inLocalStorage/index.ts +1 -4
- package/src/storages/inMemory/ImpressionCountsCacheInMemory.ts +1 -16
- package/src/storages/inMemory/InMemoryStorage.ts +2 -5
- package/src/storages/inMemory/InMemoryStorageCS.ts +2 -6
- package/src/storages/inMemory/SplitsCacheInMemory.ts +10 -14
- package/src/storages/inRedis/SplitsCacheInRedis.ts +21 -17
- package/src/storages/inRedis/constants.ts +0 -3
- package/src/storages/inRedis/index.ts +3 -12
- package/src/storages/pluggable/SplitsCachePluggable.ts +20 -17
- package/src/storages/types.ts +21 -40
- package/src/sync/offline/syncTasks/fromObjectSyncTask.ts +5 -6
- package/src/sync/polling/updaters/splitChangesUpdater.ts +2 -2
- package/src/sync/submitters/submitterManager.ts +0 -2
- package/src/sync/submitters/telemetrySubmitter.ts +3 -4
- package/src/sync/submitters/types.ts +1 -20
- package/src/trackers/impressionsTracker.ts +48 -27
- package/src/trackers/telemetryTracker.ts +7 -2
- package/src/trackers/types.ts +4 -26
- package/src/types.ts +1 -3
- package/src/utils/constants/index.ts +0 -2
- package/src/utils/settingsValidation/impressionsMode.ts +3 -3
- package/src/utils/settingsValidation/index.ts +0 -4
- package/types/integrations/types.d.ts +2 -1
- package/types/logger/constants.d.ts +0 -1
- package/types/sdkFactory/types.d.ts +2 -4
- package/types/services/types.d.ts +0 -4
- package/types/storages/AbstractSplitsCacheAsync.d.ts +6 -5
- package/types/storages/AbstractSplitsCacheSync.d.ts +5 -5
- package/types/storages/KeyBuilderSS.d.ts +0 -2
- package/types/storages/inLocalStorage/SplitsCacheInLocal.d.ts +3 -3
- package/types/storages/inMemory/ImpressionCountsCacheInMemory.d.ts +1 -5
- package/types/storages/inMemory/SplitsCacheInMemory.d.ts +3 -2
- package/types/storages/inRedis/SplitsCacheInRedis.d.ts +6 -5
- package/types/storages/inRedis/constants.d.ts +0 -3
- package/types/storages/pluggable/SplitsCachePluggable.d.ts +6 -5
- package/types/storages/types.d.ts +18 -28
- package/types/sync/polling/updaters/splitChangesUpdater.d.ts +1 -1
- package/types/sync/submitters/types.d.ts +1 -18
- package/types/trackers/impressionsTracker.d.ts +6 -4
- package/types/trackers/types.d.ts +4 -21
- package/types/types.d.ts +1 -3
- package/types/utils/constants/index.d.ts +0 -2
- package/types/utils/settingsValidation/index.d.ts +0 -1
- package/cjs/storages/inMemory/uniqueKeysCacheInMemory.js +0 -73
- package/cjs/storages/inMemory/uniqueKeysCacheInMemoryCS.js +0 -78
- package/cjs/storages/inRedis/ImpressionCountsCacheInRedis.js +0 -46
- package/cjs/storages/inRedis/uniqueKeysCacheInRedis.js +0 -55
- package/cjs/sync/submitters/uniqueKeysSubmitter.js +0 -26
- package/cjs/trackers/strategy/strategyDebug.js +0 -25
- package/cjs/trackers/strategy/strategyNone.js +0 -29
- package/cjs/trackers/strategy/strategyOptimized.js +0 -34
- package/cjs/trackers/uniqueKeysTracker.js +0 -31
- package/esm/storages/inMemory/uniqueKeysCacheInMemory.js +0 -70
- package/esm/storages/inMemory/uniqueKeysCacheInMemoryCS.js +0 -75
- package/esm/storages/inRedis/ImpressionCountsCacheInRedis.js +0 -43
- package/esm/storages/inRedis/uniqueKeysCacheInRedis.js +0 -52
- package/esm/sync/submitters/uniqueKeysSubmitter.js +0 -22
- package/esm/trackers/strategy/strategyDebug.js +0 -21
- package/esm/trackers/strategy/strategyNone.js +0 -25
- package/esm/trackers/strategy/strategyOptimized.js +0 -30
- package/esm/trackers/uniqueKeysTracker.js +0 -27
- package/src/storages/inMemory/uniqueKeysCacheInMemory.ts +0 -82
- package/src/storages/inMemory/uniqueKeysCacheInMemoryCS.ts +0 -88
- package/src/storages/inRedis/ImpressionCountsCacheInRedis.ts +0 -48
- package/src/storages/inRedis/uniqueKeysCacheInRedis.ts +0 -61
- package/src/sync/submitters/uniqueKeysSubmitter.ts +0 -35
- package/src/trackers/strategy/strategyDebug.ts +0 -28
- package/src/trackers/strategy/strategyNone.ts +0 -34
- package/src/trackers/strategy/strategyOptimized.ts +0 -42
- package/src/trackers/uniqueKeysTracker.ts +0 -37
- package/types/sdkClient/types.d.ts +0 -18
- package/types/storages/inMemory/CountsCacheInMemory.d.ts +0 -20
- package/types/storages/inMemory/LatenciesCacheInMemory.d.ts +0 -20
- package/types/storages/inMemory/uniqueKeysCacheInMemory.d.ts +0 -35
- package/types/storages/inMemory/uniqueKeysCacheInMemoryCS.d.ts +0 -37
- package/types/storages/inRedis/CountsCacheInRedis.d.ts +0 -9
- package/types/storages/inRedis/ImpressionCountsCacheInRedis.d.ts +0 -13
- package/types/storages/inRedis/LatenciesCacheInRedis.d.ts +0 -9
- package/types/storages/inRedis/uniqueKeysCacheInRedis.d.ts +0 -14
- package/types/sync/offline/LocalhostFromFile.d.ts +0 -2
- package/types/sync/offline/splitsParser/splitsParserFromFile.d.ts +0 -2
- package/types/sync/submitters/eventsSyncTask.d.ts +0 -8
- package/types/sync/submitters/impressionCountsSubmitterInRedis.d.ts +0 -5
- 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/uniqueKeysSubmitter.d.ts +0 -5
- package/types/sync/submitters/uniqueKeysSubmitterInRedis.d.ts +0 -5
- package/types/sync/syncTaskComposite.d.ts +0 -5
- package/types/trackers/filter/bloomFilter.d.ts +0 -10
- package/types/trackers/filter/dictionaryFilter.d.ts +0 -8
- package/types/trackers/filter/types.d.ts +0 -5
- package/types/trackers/strategy/strategyDebug.d.ts +0 -9
- package/types/trackers/strategy/strategyNone.d.ts +0 -10
- package/types/trackers/strategy/strategyOptimized.d.ts +0 -11
- package/types/trackers/uniqueKeysTracker.d.ts +0 -13
- package/types/utils/timeTracker/index.d.ts +0 -70
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { objectAssign } from '../utils/lang/objectAssign';
|
|
1
2
|
/**
|
|
2
3
|
* This class provides a skeletal implementation of the ISplitsCacheAsync interface
|
|
3
4
|
* to minimize the effort required to implement this interface.
|
|
@@ -31,15 +32,12 @@ var AbstractSplitsCacheAsync = /** @class */ (function () {
|
|
|
31
32
|
AbstractSplitsCacheAsync.prototype.killLocally = function (name, defaultTreatment, changeNumber) {
|
|
32
33
|
var _this = this;
|
|
33
34
|
return this.getSplit(name).then(function (split) {
|
|
34
|
-
if (split) {
|
|
35
|
-
var
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
var newSplit = JSON.stringify(parsedSplit);
|
|
41
|
-
return _this.addSplit(name, newSplit);
|
|
42
|
-
}
|
|
35
|
+
if (split && (!split.changeNumber || split.changeNumber < changeNumber)) {
|
|
36
|
+
var newSplit = objectAssign({}, split);
|
|
37
|
+
newSplit.killed = true;
|
|
38
|
+
newSplit.defaultTreatment = defaultTreatment;
|
|
39
|
+
newSplit.changeNumber = changeNumber;
|
|
40
|
+
return _this.addSplit(name, newSplit);
|
|
43
41
|
}
|
|
44
42
|
return false;
|
|
45
43
|
}).catch(function () { return false; });
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { objectAssign } from '../utils/lang/objectAssign';
|
|
1
2
|
/**
|
|
2
3
|
* This class provides a skeletal implementation of the ISplitsCacheSync interface
|
|
3
4
|
* to minimize the effort required to implement this interface.
|
|
@@ -44,15 +45,12 @@ var AbstractSplitsCacheSync = /** @class */ (function () {
|
|
|
44
45
|
*/
|
|
45
46
|
AbstractSplitsCacheSync.prototype.killLocally = function (name, defaultTreatment, changeNumber) {
|
|
46
47
|
var split = this.getSplit(name);
|
|
47
|
-
if (split) {
|
|
48
|
-
var
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
var newSplit = JSON.stringify(parsedSplit);
|
|
54
|
-
return this.addSplit(name, newSplit);
|
|
55
|
-
}
|
|
48
|
+
if (split && (!split.changeNumber || split.changeNumber < changeNumber)) {
|
|
49
|
+
var newSplit = objectAssign({}, split);
|
|
50
|
+
newSplit.killed = true;
|
|
51
|
+
newSplit.defaultTreatment = defaultTreatment;
|
|
52
|
+
newSplit.changeNumber = changeNumber;
|
|
53
|
+
return this.addSplit(name, newSplit);
|
|
56
54
|
}
|
|
57
55
|
return false;
|
|
58
56
|
};
|
|
@@ -20,12 +20,6 @@ var KeyBuilderSS = /** @class */ (function (_super) {
|
|
|
20
20
|
KeyBuilderSS.prototype.buildImpressionsKey = function () {
|
|
21
21
|
return this.prefix + ".impressions";
|
|
22
22
|
};
|
|
23
|
-
KeyBuilderSS.prototype.buildImpressionsCountKey = function () {
|
|
24
|
-
return this.prefix + ".impressions.count";
|
|
25
|
-
};
|
|
26
|
-
KeyBuilderSS.prototype.buildUniqueKeysKey = function () {
|
|
27
|
-
return this.prefix + ".uniquekeys";
|
|
28
|
-
};
|
|
29
23
|
KeyBuilderSS.prototype.buildEventsKey = function () {
|
|
30
24
|
return this.prefix + ".events";
|
|
31
25
|
};
|
|
@@ -32,7 +32,7 @@ export function dataLoaderFactory(preloadedData) {
|
|
|
32
32
|
storage.splits.clear();
|
|
33
33
|
storage.splits.setChangeNumber(since);
|
|
34
34
|
// splitsData in an object where the property is the split name and the pertaining value is a stringified json of its data
|
|
35
|
-
storage.splits.addSplits(Object.keys(splitsData).map(function (splitName) { return
|
|
35
|
+
storage.splits.addSplits(Object.keys(splitsData).map(function (splitName) { return JSON.parse(splitsData[splitName]); }));
|
|
36
36
|
// add mySegments data
|
|
37
37
|
var mySegmentsData = preloadedData.mySegmentsData && preloadedData.mySegmentsData[userId];
|
|
38
38
|
if (!mySegmentsData) {
|
|
@@ -93,9 +93,8 @@ var SplitsCacheInLocal = /** @class */ (function (_super) {
|
|
|
93
93
|
var splitFromLocalStorage = localStorage.getItem(splitKey);
|
|
94
94
|
var previousSplit = splitFromLocalStorage ? JSON.parse(splitFromLocalStorage) : null;
|
|
95
95
|
this._decrementCounts(previousSplit);
|
|
96
|
-
localStorage.setItem(splitKey, split);
|
|
97
|
-
|
|
98
|
-
this._incrementCounts(parsedSplit);
|
|
96
|
+
localStorage.setItem(splitKey, JSON.stringify(split));
|
|
97
|
+
this._incrementCounts(split);
|
|
99
98
|
return true;
|
|
100
99
|
}
|
|
101
100
|
catch (e) {
|
|
@@ -107,8 +106,7 @@ var SplitsCacheInLocal = /** @class */ (function (_super) {
|
|
|
107
106
|
try {
|
|
108
107
|
var split = this.getSplit(name);
|
|
109
108
|
localStorage.removeItem(this.keys.buildSplitKey(name));
|
|
110
|
-
|
|
111
|
-
this._decrementCounts(parsedSplit);
|
|
109
|
+
this._decrementCounts(split);
|
|
112
110
|
return true;
|
|
113
111
|
}
|
|
114
112
|
catch (e) {
|
|
@@ -117,7 +115,8 @@ var SplitsCacheInLocal = /** @class */ (function (_super) {
|
|
|
117
115
|
}
|
|
118
116
|
};
|
|
119
117
|
SplitsCacheInLocal.prototype.getSplit = function (name) {
|
|
120
|
-
|
|
118
|
+
var item = localStorage.getItem(this.keys.buildSplitKey(name));
|
|
119
|
+
return item && JSON.parse(item);
|
|
121
120
|
};
|
|
122
121
|
SplitsCacheInLocal.prototype.setChangeNumber = function (changeNumber) {
|
|
123
122
|
// when cache is ready but using a new split query, we must clear all split data
|
|
@@ -11,9 +11,8 @@ import { SplitsCacheInMemory } from '../inMemory/SplitsCacheInMemory';
|
|
|
11
11
|
import { DEFAULT_CACHE_EXPIRATION_IN_MILLIS } from '../../utils/constants/browser';
|
|
12
12
|
import { InMemoryStorageCSFactory } from '../inMemory/InMemoryStorageCS';
|
|
13
13
|
import { LOG_PREFIX } from './constants';
|
|
14
|
-
import { LOCALHOST_MODE,
|
|
14
|
+
import { LOCALHOST_MODE, STORAGE_LOCALSTORAGE } from '../../utils/constants';
|
|
15
15
|
import { shouldRecordTelemetry, TelemetryCacheInMemory } from '../inMemory/TelemetryCacheInMemory';
|
|
16
|
-
import { UniqueKeysCacheInMemoryCS } from '../inMemory/uniqueKeysCacheInMemoryCS';
|
|
17
16
|
/**
|
|
18
17
|
* InLocal storage factory for standalone client-side SplitFactory
|
|
19
18
|
*/
|
|
@@ -36,15 +35,12 @@ export function InLocalStorage(options) {
|
|
|
36
35
|
impressionCounts: params.optimize ? new ImpressionCountsCacheInMemory() : undefined,
|
|
37
36
|
events: new EventsCacheInMemory(params.eventsQueueSize),
|
|
38
37
|
telemetry: params.mode !== LOCALHOST_MODE && shouldRecordTelemetry() ? new TelemetryCacheInMemory() : undefined,
|
|
39
|
-
uniqueKeys: params.impressionsMode === NONE ? new UniqueKeysCacheInMemoryCS() : undefined,
|
|
40
38
|
destroy: function () {
|
|
41
|
-
var _a;
|
|
42
39
|
this.splits = new SplitsCacheInMemory();
|
|
43
40
|
this.segments = new MySegmentsCacheInMemory();
|
|
44
41
|
this.impressions.clear();
|
|
45
42
|
this.impressionCounts && this.impressionCounts.clear();
|
|
46
43
|
this.events.clear();
|
|
47
|
-
(_a = this.uniqueKeys) === null || _a === void 0 ? void 0 : _a.clear();
|
|
48
44
|
},
|
|
49
45
|
// When using shared instanciation with MEMORY we reuse everything but segments (they are customer per key).
|
|
50
46
|
shared: function (matchingKey) {
|
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
import { truncateTimeFrame } from '../../utils/time';
|
|
2
|
-
import { DEFAULT_CACHE_SIZE } from '../inRedis/constants';
|
|
3
2
|
var ImpressionCountsCacheInMemory = /** @class */ (function () {
|
|
4
|
-
function ImpressionCountsCacheInMemory(
|
|
5
|
-
if (impressionCountsCacheSize === void 0) { impressionCountsCacheSize = DEFAULT_CACHE_SIZE; }
|
|
3
|
+
function ImpressionCountsCacheInMemory() {
|
|
6
4
|
this.cache = {};
|
|
7
|
-
this.cacheSize = 0;
|
|
8
|
-
this.maxStorage = impressionCountsCacheSize;
|
|
9
5
|
}
|
|
10
6
|
/**
|
|
11
7
|
* Builds key to be stored in the cache with the featureName and the timeFrame truncated.
|
|
@@ -20,13 +16,6 @@ var ImpressionCountsCacheInMemory = /** @class */ (function () {
|
|
|
20
16
|
var key = this._makeKey(featureName, timeFrame);
|
|
21
17
|
var currentAmount = this.cache[key];
|
|
22
18
|
this.cache[key] = currentAmount ? currentAmount + amount : amount;
|
|
23
|
-
if (this.onFullQueue) {
|
|
24
|
-
this.cacheSize = this.cacheSize + amount;
|
|
25
|
-
if (this.cacheSize >= this.maxStorage) {
|
|
26
|
-
this.onFullQueue();
|
|
27
|
-
this.cacheSize = 0;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
19
|
};
|
|
31
20
|
/**
|
|
32
21
|
* Pop the collected data, used as payload for posting.
|
|
@@ -3,9 +3,8 @@ import { SegmentsCacheInMemory } from './SegmentsCacheInMemory';
|
|
|
3
3
|
import { ImpressionsCacheInMemory } from './ImpressionsCacheInMemory';
|
|
4
4
|
import { EventsCacheInMemory } from './EventsCacheInMemory';
|
|
5
5
|
import { ImpressionCountsCacheInMemory } from './ImpressionCountsCacheInMemory';
|
|
6
|
-
import {
|
|
6
|
+
import { LOCALHOST_MODE, STORAGE_MEMORY } from '../../utils/constants';
|
|
7
7
|
import { TelemetryCacheInMemory } from './TelemetryCacheInMemory';
|
|
8
|
-
import { UniqueKeysCacheInMemory } from './uniqueKeysCacheInMemory';
|
|
9
8
|
/**
|
|
10
9
|
* InMemory storage factory for standalone server-side SplitFactory
|
|
11
10
|
*
|
|
@@ -16,19 +15,16 @@ export function InMemoryStorageFactory(params) {
|
|
|
16
15
|
splits: new SplitsCacheInMemory(),
|
|
17
16
|
segments: new SegmentsCacheInMemory(),
|
|
18
17
|
impressions: new ImpressionsCacheInMemory(params.impressionsQueueSize),
|
|
19
|
-
impressionCounts: params.
|
|
18
|
+
impressionCounts: params.optimize ? new ImpressionCountsCacheInMemory() : undefined,
|
|
20
19
|
events: new EventsCacheInMemory(params.eventsQueueSize),
|
|
21
20
|
telemetry: params.mode !== LOCALHOST_MODE ? new TelemetryCacheInMemory() : undefined,
|
|
22
|
-
uniqueKeys: params.impressionsMode === NONE ? new UniqueKeysCacheInMemory(params.uniqueKeysCacheSize) : undefined,
|
|
23
21
|
// When using MEMORY we should clean all the caches to leave them empty
|
|
24
22
|
destroy: function () {
|
|
25
|
-
var _a;
|
|
26
23
|
this.splits.clear();
|
|
27
24
|
this.segments.clear();
|
|
28
25
|
this.impressions.clear();
|
|
29
26
|
this.impressionCounts && this.impressionCounts.clear();
|
|
30
27
|
this.events.clear();
|
|
31
|
-
(_a = this.uniqueKeys) === null || _a === void 0 ? void 0 : _a.clear();
|
|
32
28
|
}
|
|
33
29
|
};
|
|
34
30
|
}
|
|
@@ -3,9 +3,8 @@ import { MySegmentsCacheInMemory } from './MySegmentsCacheInMemory';
|
|
|
3
3
|
import { ImpressionsCacheInMemory } from './ImpressionsCacheInMemory';
|
|
4
4
|
import { EventsCacheInMemory } from './EventsCacheInMemory';
|
|
5
5
|
import { ImpressionCountsCacheInMemory } from './ImpressionCountsCacheInMemory';
|
|
6
|
-
import {
|
|
6
|
+
import { LOCALHOST_MODE, STORAGE_MEMORY } from '../../utils/constants';
|
|
7
7
|
import { shouldRecordTelemetry, TelemetryCacheInMemory } from './TelemetryCacheInMemory';
|
|
8
|
-
import { UniqueKeysCacheInMemoryCS } from './uniqueKeysCacheInMemoryCS';
|
|
9
8
|
/**
|
|
10
9
|
* InMemory storage factory for standalone client-side SplitFactory
|
|
11
10
|
*
|
|
@@ -16,19 +15,16 @@ export function InMemoryStorageCSFactory(params) {
|
|
|
16
15
|
splits: new SplitsCacheInMemory(),
|
|
17
16
|
segments: new MySegmentsCacheInMemory(),
|
|
18
17
|
impressions: new ImpressionsCacheInMemory(params.impressionsQueueSize),
|
|
19
|
-
impressionCounts: params.
|
|
18
|
+
impressionCounts: params.optimize ? new ImpressionCountsCacheInMemory() : undefined,
|
|
20
19
|
events: new EventsCacheInMemory(params.eventsQueueSize),
|
|
21
20
|
telemetry: params.mode !== LOCALHOST_MODE && shouldRecordTelemetry() ? new TelemetryCacheInMemory() : undefined,
|
|
22
|
-
uniqueKeys: params.impressionsMode === NONE ? new UniqueKeysCacheInMemoryCS(params.uniqueKeysCacheSize) : undefined,
|
|
23
21
|
// When using MEMORY we should clean all the caches to leave them empty
|
|
24
22
|
destroy: function () {
|
|
25
|
-
var _a;
|
|
26
23
|
this.splits.clear();
|
|
27
24
|
this.segments.clear();
|
|
28
25
|
this.impressions.clear();
|
|
29
26
|
this.impressionCounts && this.impressionCounts.clear();
|
|
30
27
|
this.events.clear();
|
|
31
|
-
(_a = this.uniqueKeys) === null || _a === void 0 ? void 0 : _a.clear();
|
|
32
28
|
},
|
|
33
29
|
// When using shared instanciation with MEMORY we reuse everything but segments (they are unique per key)
|
|
34
30
|
shared: function () {
|
|
@@ -22,9 +22,8 @@ var SplitsCacheInMemory = /** @class */ (function (_super) {
|
|
|
22
22
|
this.splitsWithSegmentsCount = 0;
|
|
23
23
|
};
|
|
24
24
|
SplitsCacheInMemory.prototype.addSplit = function (name, split) {
|
|
25
|
-
var
|
|
26
|
-
if (
|
|
27
|
-
var previousSplit = JSON.parse(splitFromMemory);
|
|
25
|
+
var previousSplit = this.getSplit(name);
|
|
26
|
+
if (previousSplit) { // We had this Split already
|
|
28
27
|
if (previousSplit.trafficTypeName) {
|
|
29
28
|
var previousTtName = previousSplit.trafficTypeName;
|
|
30
29
|
this.ttCache[previousTtName]--;
|
|
@@ -35,19 +34,18 @@ var SplitsCacheInMemory = /** @class */ (function (_super) {
|
|
|
35
34
|
this.splitsWithSegmentsCount--;
|
|
36
35
|
}
|
|
37
36
|
}
|
|
38
|
-
|
|
39
|
-
if (parsedSplit) {
|
|
37
|
+
if (split) {
|
|
40
38
|
// Store the Split.
|
|
41
39
|
this.splitsCache[name] = split;
|
|
42
40
|
// Update TT cache
|
|
43
|
-
var ttName =
|
|
41
|
+
var ttName = split.trafficTypeName;
|
|
44
42
|
if (ttName) { // safeguard
|
|
45
43
|
if (!this.ttCache[ttName])
|
|
46
44
|
this.ttCache[ttName] = 0;
|
|
47
45
|
this.ttCache[ttName]++;
|
|
48
46
|
}
|
|
49
47
|
// Add to segments count for the new version of the Split
|
|
50
|
-
if (usesSegments(
|
|
48
|
+
if (usesSegments(split))
|
|
51
49
|
this.splitsWithSegmentsCount++;
|
|
52
50
|
return true;
|
|
53
51
|
}
|
|
@@ -60,15 +58,14 @@ var SplitsCacheInMemory = /** @class */ (function (_super) {
|
|
|
60
58
|
if (split) {
|
|
61
59
|
// Delete the Split
|
|
62
60
|
delete this.splitsCache[name];
|
|
63
|
-
var
|
|
64
|
-
var ttName = parsedSplit.trafficTypeName;
|
|
61
|
+
var ttName = split.trafficTypeName;
|
|
65
62
|
if (ttName) { // safeguard
|
|
66
63
|
this.ttCache[ttName]--; // Update tt cache
|
|
67
64
|
if (!this.ttCache[ttName])
|
|
68
65
|
delete this.ttCache[ttName];
|
|
69
66
|
}
|
|
70
67
|
// Update the segments count.
|
|
71
|
-
if (usesSegments(
|
|
68
|
+
if (usesSegments(split))
|
|
72
69
|
this.splitsWithSegmentsCount--;
|
|
73
70
|
return true;
|
|
74
71
|
}
|
|
@@ -59,17 +59,17 @@ var SplitsCacheInRedis = /** @class */ (function (_super) {
|
|
|
59
59
|
var splitKey = this.keys.buildSplitKey(name);
|
|
60
60
|
return this.redis.get(splitKey).then(function (splitFromStorage) {
|
|
61
61
|
// handling parsing errors
|
|
62
|
-
var parsedPreviousSplit,
|
|
62
|
+
var parsedPreviousSplit, newStringifiedSplit;
|
|
63
63
|
try {
|
|
64
64
|
parsedPreviousSplit = splitFromStorage ? JSON.parse(splitFromStorage) : undefined;
|
|
65
|
-
|
|
65
|
+
newStringifiedSplit = JSON.stringify(split);
|
|
66
66
|
}
|
|
67
67
|
catch (e) {
|
|
68
68
|
throw new Error('Error parsing split definition: ' + e);
|
|
69
69
|
}
|
|
70
70
|
return Promise.all([
|
|
71
|
-
_this.redis.set(splitKey,
|
|
72
|
-
_this._incrementCounts(
|
|
71
|
+
_this.redis.set(splitKey, newStringifiedSplit),
|
|
72
|
+
_this._incrementCounts(split),
|
|
73
73
|
// If it's an update, we decrement the traffic type of the existing split,
|
|
74
74
|
parsedPreviousSplit && _this._decrementCounts(parsedPreviousSplit)
|
|
75
75
|
]);
|
|
@@ -96,8 +96,7 @@ var SplitsCacheInRedis = /** @class */ (function (_super) {
|
|
|
96
96
|
var _this = this;
|
|
97
97
|
return this.getSplit(name).then(function (split) {
|
|
98
98
|
if (split) {
|
|
99
|
-
|
|
100
|
-
_this._decrementCounts(parsedSplit);
|
|
99
|
+
_this._decrementCounts(split);
|
|
101
100
|
}
|
|
102
101
|
return _this.redis.del(_this.keys.buildSplitKey(name));
|
|
103
102
|
});
|
|
@@ -120,7 +119,8 @@ var SplitsCacheInRedis = /** @class */ (function (_super) {
|
|
|
120
119
|
this.log.error(LOG_PREFIX + this.redisError);
|
|
121
120
|
return Promise.reject(this.redisError);
|
|
122
121
|
}
|
|
123
|
-
return this.redis.get(this.keys.buildSplitKey(name))
|
|
122
|
+
return this.redis.get(this.keys.buildSplitKey(name))
|
|
123
|
+
.then(function (maybeSplit) { return maybeSplit && JSON.parse(maybeSplit); });
|
|
124
124
|
};
|
|
125
125
|
/**
|
|
126
126
|
* Set till number.
|
|
@@ -155,7 +155,12 @@ var SplitsCacheInRedis = /** @class */ (function (_super) {
|
|
|
155
155
|
*/
|
|
156
156
|
SplitsCacheInRedis.prototype.getAll = function () {
|
|
157
157
|
var _this = this;
|
|
158
|
-
return this.redis.keys(this.keys.searchPatternForSplitKeys())
|
|
158
|
+
return this.redis.keys(this.keys.searchPatternForSplitKeys())
|
|
159
|
+
.then(function (listOfKeys) { return _this.redis.pipeline(listOfKeys.map(function (k) { return ['get', k]; })).exec(); })
|
|
160
|
+
.then(processPipelineAnswer)
|
|
161
|
+
.then(function (splitDefinitions) { return splitDefinitions.map(function (splitDefinition) {
|
|
162
|
+
return JSON.parse(splitDefinition);
|
|
163
|
+
}); });
|
|
159
164
|
};
|
|
160
165
|
/**
|
|
161
166
|
* Get list of split names.
|
|
@@ -215,7 +220,8 @@ var SplitsCacheInRedis = /** @class */ (function (_super) {
|
|
|
215
220
|
var keys = names.map(function (name) { return _this.keys.buildSplitKey(name); });
|
|
216
221
|
return (_a = this.redis).mget.apply(_a, keys).then(function (splitDefinitions) {
|
|
217
222
|
names.forEach(function (name, idx) {
|
|
218
|
-
|
|
223
|
+
var split = splitDefinitions[idx];
|
|
224
|
+
splits[name] = split && JSON.parse(split);
|
|
219
225
|
});
|
|
220
226
|
return Promise.resolve(splits);
|
|
221
227
|
})
|
|
@@ -5,10 +5,8 @@ import { SplitsCacheInRedis } from './SplitsCacheInRedis';
|
|
|
5
5
|
import { SegmentsCacheInRedis } from './SegmentsCacheInRedis';
|
|
6
6
|
import { ImpressionsCacheInRedis } from './ImpressionsCacheInRedis';
|
|
7
7
|
import { EventsCacheInRedis } from './EventsCacheInRedis';
|
|
8
|
-
import {
|
|
8
|
+
import { STORAGE_REDIS } from '../../utils/constants';
|
|
9
9
|
import { TelemetryCacheInRedis } from './TelemetryCacheInRedis';
|
|
10
|
-
import { UniqueKeysCacheInRedis } from './uniqueKeysCacheInRedis';
|
|
11
|
-
import { ImpressionCountsCacheInRedis } from './ImpressionCountsCacheInRedis';
|
|
12
10
|
/**
|
|
13
11
|
* InRedis storage factory for consumer server-side SplitFactory, that uses `Ioredis` Redis client for Node.
|
|
14
12
|
* @see {@link https://www.npmjs.com/package/ioredis}
|
|
@@ -17,19 +15,13 @@ export function InRedisStorage(options) {
|
|
|
17
15
|
if (options === void 0) { options = {}; }
|
|
18
16
|
var prefix = validatePrefix(options.prefix);
|
|
19
17
|
function InRedisStorageFactory(_a) {
|
|
20
|
-
var log = _a.log, metadata = _a.metadata, onReadyCb = _a.onReadyCb
|
|
18
|
+
var log = _a.log, metadata = _a.metadata, onReadyCb = _a.onReadyCb;
|
|
21
19
|
var keys = new KeyBuilderSS(prefix, metadata);
|
|
22
20
|
var redisClient = new RedisAdapter(log, options.options || {});
|
|
23
21
|
var telemetry = new TelemetryCacheInRedis(log, keys, redisClient);
|
|
24
|
-
var impressionCountsCache = impressionsMode !== DEBUG ? new ImpressionCountsCacheInRedis(log, keys.buildImpressionsCountKey(), redisClient) : undefined;
|
|
25
|
-
var uniqueKeysCache = impressionsMode === NONE ? new UniqueKeysCacheInRedis(log, keys.buildUniqueKeysKey(), redisClient) : undefined;
|
|
26
22
|
// subscription to Redis connect event in order to emit SDK_READY event on consumer mode
|
|
27
23
|
redisClient.on('connect', function () {
|
|
28
24
|
onReadyCb();
|
|
29
|
-
if (impressionCountsCache)
|
|
30
|
-
impressionCountsCache.start();
|
|
31
|
-
if (uniqueKeysCache)
|
|
32
|
-
uniqueKeysCache.start();
|
|
33
25
|
// Synchronize config
|
|
34
26
|
telemetry.recordConfig();
|
|
35
27
|
});
|
|
@@ -37,18 +29,12 @@ export function InRedisStorage(options) {
|
|
|
37
29
|
splits: new SplitsCacheInRedis(log, keys, redisClient),
|
|
38
30
|
segments: new SegmentsCacheInRedis(log, keys, redisClient),
|
|
39
31
|
impressions: new ImpressionsCacheInRedis(log, keys.buildImpressionsKey(), redisClient, metadata),
|
|
40
|
-
impressionCounts: impressionCountsCache,
|
|
41
32
|
events: new EventsCacheInRedis(log, keys.buildEventsKey(), redisClient, metadata),
|
|
42
33
|
telemetry: telemetry,
|
|
43
|
-
uniqueKeys: uniqueKeysCache,
|
|
44
34
|
// When using REDIS we should:
|
|
45
35
|
// 1- Disconnect from the storage
|
|
46
36
|
destroy: function () {
|
|
47
37
|
redisClient.disconnect();
|
|
48
|
-
if (impressionCountsCache)
|
|
49
|
-
impressionCountsCache.stop();
|
|
50
|
-
if (uniqueKeysCache)
|
|
51
|
-
uniqueKeysCache.stop();
|
|
52
38
|
// @TODO check that caches works as expected when redisClient is disconnected
|
|
53
39
|
}
|
|
54
40
|
};
|
|
@@ -46,17 +46,17 @@ var SplitsCachePluggable = /** @class */ (function (_super) {
|
|
|
46
46
|
var splitKey = this.keys.buildSplitKey(name);
|
|
47
47
|
return this.wrapper.get(splitKey).then(function (splitFromStorage) {
|
|
48
48
|
// handling parsing error
|
|
49
|
-
var parsedPreviousSplit,
|
|
49
|
+
var parsedPreviousSplit, stringifiedNewSplit;
|
|
50
50
|
try {
|
|
51
51
|
parsedPreviousSplit = splitFromStorage ? JSON.parse(splitFromStorage) : undefined;
|
|
52
|
-
|
|
52
|
+
stringifiedNewSplit = JSON.stringify(split);
|
|
53
53
|
}
|
|
54
54
|
catch (e) {
|
|
55
55
|
throw new Error('Error parsing split definition: ' + e);
|
|
56
56
|
}
|
|
57
57
|
return Promise.all([
|
|
58
|
-
_this.wrapper.set(splitKey,
|
|
59
|
-
_this._incrementCounts(
|
|
58
|
+
_this.wrapper.set(splitKey, stringifiedNewSplit),
|
|
59
|
+
_this._incrementCounts(split),
|
|
60
60
|
// If it's an update, we decrement the traffic type and segment count of the existing split,
|
|
61
61
|
parsedPreviousSplit && _this._decrementCounts(parsedPreviousSplit)
|
|
62
62
|
]);
|
|
@@ -80,8 +80,7 @@ var SplitsCachePluggable = /** @class */ (function (_super) {
|
|
|
80
80
|
var _this = this;
|
|
81
81
|
return this.getSplit(name).then(function (split) {
|
|
82
82
|
if (split) {
|
|
83
|
-
|
|
84
|
-
_this._decrementCounts(parsedSplit);
|
|
83
|
+
_this._decrementCounts(split);
|
|
85
84
|
}
|
|
86
85
|
return _this.wrapper.del(_this.keys.buildSplitKey(name));
|
|
87
86
|
});
|
|
@@ -101,7 +100,8 @@ var SplitsCachePluggable = /** @class */ (function (_super) {
|
|
|
101
100
|
* or rejected if wrapper operation fails.
|
|
102
101
|
*/
|
|
103
102
|
SplitsCachePluggable.prototype.getSplit = function (name) {
|
|
104
|
-
return this.wrapper.get(this.keys.buildSplitKey(name))
|
|
103
|
+
return this.wrapper.get(this.keys.buildSplitKey(name))
|
|
104
|
+
.then(function (maybeSplit) { return maybeSplit && JSON.parse(maybeSplit); });
|
|
105
105
|
};
|
|
106
106
|
/**
|
|
107
107
|
* Get list of splits.
|
|
@@ -114,7 +114,8 @@ var SplitsCachePluggable = /** @class */ (function (_super) {
|
|
|
114
114
|
return this.wrapper.getMany(keys).then(function (splitDefinitions) {
|
|
115
115
|
var splits = {};
|
|
116
116
|
names.forEach(function (name, idx) {
|
|
117
|
-
|
|
117
|
+
var split = splitDefinitions[idx];
|
|
118
|
+
splits[name] = split && JSON.parse(split);
|
|
118
119
|
});
|
|
119
120
|
return Promise.resolve(splits);
|
|
120
121
|
});
|
|
@@ -126,7 +127,11 @@ var SplitsCachePluggable = /** @class */ (function (_super) {
|
|
|
126
127
|
*/
|
|
127
128
|
SplitsCachePluggable.prototype.getAll = function () {
|
|
128
129
|
var _this = this;
|
|
129
|
-
return this.wrapper.getKeysByPrefix(this.keys.buildSplitKeyPrefix())
|
|
130
|
+
return this.wrapper.getKeysByPrefix(this.keys.buildSplitKeyPrefix())
|
|
131
|
+
.then(function (listOfKeys) { return _this.wrapper.getMany(listOfKeys); })
|
|
132
|
+
.then(function (splitDefinitions) { return splitDefinitions.map(function (splitDefinition) {
|
|
133
|
+
return JSON.parse(splitDefinition);
|
|
134
|
+
}); });
|
|
130
135
|
};
|
|
131
136
|
/**
|
|
132
137
|
* Get list of split names.
|
|
@@ -24,8 +24,7 @@ export function fromObjectUpdaterFactory(splitsParser, storage, readiness, setti
|
|
|
24
24
|
log.debug(SYNC_OFFLINE_DATA, [JSON.stringify(splitsMock)]);
|
|
25
25
|
forOwn(splitsMock, function (val, name) {
|
|
26
26
|
splits.push([
|
|
27
|
-
name,
|
|
28
|
-
JSON.stringify({
|
|
27
|
+
name, {
|
|
29
28
|
name: name,
|
|
30
29
|
status: 'ACTIVE',
|
|
31
30
|
killed: false,
|
|
@@ -34,7 +33,7 @@ export function fromObjectUpdaterFactory(splitsParser, storage, readiness, setti
|
|
|
34
33
|
conditions: val.conditions || [],
|
|
35
34
|
configurations: val.configurations,
|
|
36
35
|
trafficTypeName: val.trafficTypeName
|
|
37
|
-
}
|
|
36
|
+
}
|
|
38
37
|
]);
|
|
39
38
|
});
|
|
40
39
|
return Promise.all([
|
|
@@ -37,7 +37,7 @@ export function computeSplitsMutation(entries) {
|
|
|
37
37
|
var segments = new _Set();
|
|
38
38
|
var computed = entries.reduce(function (accum, split) {
|
|
39
39
|
if (split.status === 'ACTIVE') {
|
|
40
|
-
accum.added.push([split.name,
|
|
40
|
+
accum.added.push([split.name, split]);
|
|
41
41
|
parseSegments(split).forEach(function (segmentName) {
|
|
42
42
|
segments.add(segmentName);
|
|
43
43
|
});
|
|
@@ -2,7 +2,6 @@ import { eventsSubmitterFactory } from './eventsSubmitter';
|
|
|
2
2
|
import { impressionsSubmitterFactory } from './impressionsSubmitter';
|
|
3
3
|
import { impressionCountsSubmitterFactory } from './impressionCountsSubmitter';
|
|
4
4
|
import { telemetrySubmitterFactory } from './telemetrySubmitter';
|
|
5
|
-
import { uniqueKeysSubmitterFactory } from './uniqueKeysSubmitter';
|
|
6
5
|
export function submitterManagerFactory(params) {
|
|
7
6
|
var submitters = [
|
|
8
7
|
impressionsSubmitterFactory(params),
|
|
@@ -12,8 +11,6 @@ export function submitterManagerFactory(params) {
|
|
|
12
11
|
if (impressionCountsSubmitter)
|
|
13
12
|
submitters.push(impressionCountsSubmitter);
|
|
14
13
|
var telemetrySubmitter = telemetrySubmitterFactory(params);
|
|
15
|
-
if (params.uniqueKeysTracker)
|
|
16
|
-
submitters.push(uniqueKeysSubmitterFactory(params));
|
|
17
14
|
return {
|
|
18
15
|
// `onlyTelemetry` true if SDK is created with userConsent not GRANTED
|
|
19
16
|
start: function (onlyTelemetry) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
var _a, _b, _c;
|
|
2
2
|
import { submitterFactory, firstPushWindowDecorator } from './submitter';
|
|
3
|
-
import { QUEUED, DEDUPED, DROPPED, CONSUMER_MODE, CONSUMER_ENUM, STANDALONE_MODE, CONSUMER_PARTIAL_MODE, STANDALONE_ENUM, CONSUMER_PARTIAL_ENUM, OPTIMIZED, DEBUG,
|
|
3
|
+
import { QUEUED, DEDUPED, DROPPED, CONSUMER_MODE, CONSUMER_ENUM, STANDALONE_MODE, CONSUMER_PARTIAL_MODE, STANDALONE_ENUM, CONSUMER_PARTIAL_ENUM, OPTIMIZED, DEBUG, DEBUG_ENUM, OPTIMIZED_ENUM, CONSENT_GRANTED, CONSENT_DECLINED, CONSENT_UNKNOWN } from '../../utils/constants';
|
|
4
4
|
import { SDK_READY, SDK_READY_FROM_CACHE } from '../../readiness/constants';
|
|
5
5
|
import { base } from '../../utils/settingsValidation';
|
|
6
6
|
import { usedKeysMap } from '../../utils/inputValidation/apiKey';
|
|
@@ -46,7 +46,6 @@ var OPERATION_MODE_MAP = (_a = {},
|
|
|
46
46
|
var IMPRESSIONS_MODE_MAP = (_b = {},
|
|
47
47
|
_b[OPTIMIZED] = OPTIMIZED_ENUM,
|
|
48
48
|
_b[DEBUG] = DEBUG_ENUM,
|
|
49
|
-
_b[NONE] = NONE_ENUM,
|
|
50
49
|
_b);
|
|
51
50
|
var USER_CONSENT_MAP = (_c = {},
|
|
52
51
|
_c[CONSENT_UNKNOWN] = 1,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { objectAssign } from '../utils/lang/objectAssign';
|
|
2
2
|
import { thenable } from '../utils/promise/thenable';
|
|
3
|
+
import { truncateTimeFrame } from '../utils/time';
|
|
3
4
|
import { IMPRESSIONS_TRACKER_SUCCESS, ERROR_IMPRESSIONS_TRACKER, ERROR_IMPRESSIONS_LISTENER } from '../logger/constants';
|
|
4
5
|
import { CONSENT_DECLINED, DEDUPED, QUEUED } from '../utils/constants';
|
|
5
6
|
/**
|
|
@@ -9,34 +10,52 @@ import { CONSENT_DECLINED, DEDUPED, QUEUED } from '../utils/constants';
|
|
|
9
10
|
* @param metadata runtime metadata (ip, hostname and version)
|
|
10
11
|
* @param impressionListener optional impression listener
|
|
11
12
|
* @param integrationsManager optional integrations manager
|
|
12
|
-
* @param
|
|
13
|
+
* @param observer optional impression observer. If provided, previous time (pt property) is included in impression instances
|
|
14
|
+
* @param countsCache optional cache to save impressions count. If provided, impressions will be deduped (OPTIMIZED mode)
|
|
13
15
|
*/
|
|
14
|
-
export function impressionsTrackerFactory(settings, impressionsCache,
|
|
16
|
+
export function impressionsTrackerFactory(settings, impressionsCache, integrationsManager,
|
|
17
|
+
// if observer is provided, it implies `shouldAddPreviousTime` flag (i.e., if impressions previous time should be added or not)
|
|
18
|
+
observer,
|
|
19
|
+
// if countsCache is provided, it implies `isOptimized` flag (i.e., if impressions should be deduped or not)
|
|
20
|
+
countsCache, telemetryCache) {
|
|
15
21
|
var log = settings.log, impressionListener = settings.impressionListener, _a = settings.runtime, ip = _a.ip, hostname = _a.hostname, version = settings.version;
|
|
16
22
|
return {
|
|
17
23
|
track: function (impressions, attributes) {
|
|
18
24
|
if (settings.userConsent === CONSENT_DECLINED)
|
|
19
25
|
return;
|
|
20
26
|
var impressionsCount = impressions.length;
|
|
21
|
-
var
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
res.then(function () {
|
|
28
|
-
log.info(IMPRESSIONS_TRACKER_SUCCESS, [impressionsCount]);
|
|
29
|
-
}).catch(function (err) {
|
|
30
|
-
log.error(ERROR_IMPRESSIONS_TRACKER, [impressionsCount, err]);
|
|
31
|
-
});
|
|
27
|
+
var impressionsToStore = []; // Track only the impressions that are going to be stored
|
|
28
|
+
// Wraps impressions to store and adds previousTime if it corresponds
|
|
29
|
+
impressions.forEach(function (impression) {
|
|
30
|
+
if (observer) {
|
|
31
|
+
// Adds previous time if it is enabled
|
|
32
|
+
impression.pt = observer.testAndSet(impression);
|
|
32
33
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
//
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
34
|
+
var now = Date.now();
|
|
35
|
+
if (countsCache) {
|
|
36
|
+
// Increments impression counter per featureName
|
|
37
|
+
countsCache.track(impression.feature, now, 1);
|
|
38
|
+
}
|
|
39
|
+
// Checks if the impression should be added in queue to be sent
|
|
40
|
+
if (!countsCache || !impression.pt || impression.pt < truncateTimeFrame(now)) {
|
|
41
|
+
impressionsToStore.push(impression);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
var res = impressionsCache.track(impressionsToStore);
|
|
45
|
+
// If we're on an async storage, handle error and log it.
|
|
46
|
+
if (thenable(res)) {
|
|
47
|
+
res.then(function () {
|
|
48
|
+
log.info(IMPRESSIONS_TRACKER_SUCCESS, [impressionsCount]);
|
|
49
|
+
}).catch(function (err) {
|
|
50
|
+
log.error(ERROR_IMPRESSIONS_TRACKER, [impressionsCount, err]);
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
// Record when impressionsCache is sync only (standalone mode)
|
|
55
|
+
// @TODO we are not dropping impressions on full queue yet, so DROPPED stats are not recorded
|
|
56
|
+
if (telemetryCache) {
|
|
57
|
+
telemetryCache.recordImpressionStats(QUEUED, impressionsToStore.length);
|
|
58
|
+
telemetryCache.recordImpressionStats(DEDUPED, impressions.length - impressionsToStore.length);
|
|
40
59
|
}
|
|
41
60
|
}
|
|
42
61
|
// @TODO next block might be handled by the integration manager. In that case, the metadata object doesn't need to be passed in the constructor
|
|
@@ -44,7 +63,7 @@ export function impressionsTrackerFactory(settings, impressionsCache, strategy,
|
|
|
44
63
|
var _loop_1 = function (i) {
|
|
45
64
|
var impressionData = {
|
|
46
65
|
// copy of impression, to avoid unexpected behaviour if modified by integrations or impressionListener
|
|
47
|
-
impression: objectAssign({},
|
|
66
|
+
impression: objectAssign({}, impressions[i]),
|
|
48
67
|
attributes: attributes,
|
|
49
68
|
ip: ip,
|
|
50
69
|
hostname: hostname,
|
|
@@ -64,7 +83,7 @@ export function impressionsTrackerFactory(settings, impressionsCache, strategy,
|
|
|
64
83
|
}
|
|
65
84
|
}, 0);
|
|
66
85
|
};
|
|
67
|
-
for (var i = 0; i <
|
|
86
|
+
for (var i = 0; i < impressionsCount; i++) {
|
|
68
87
|
_loop_1(i);
|
|
69
88
|
}
|
|
70
89
|
}
|