@splitsoftware/splitio-commons 2.0.0-rc.2 → 2.0.0-rc.3
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 +1 -3
- package/cjs/logger/constants.js +1 -2
- package/cjs/logger/messages/error.js +0 -1
- package/cjs/sdkFactory/index.js +1 -3
- package/cjs/storages/dataLoader.js +37 -99
- package/cjs/storages/inMemory/InMemoryStorageCS.js +4 -16
- package/cjs/sync/offline/LocalhostFromObject.js +3 -8
- package/cjs/utils/settingsValidation/index.js +1 -4
- package/esm/logger/constants.js +0 -1
- package/esm/logger/messages/error.js +0 -1
- package/esm/sdkFactory/index.js +2 -4
- package/esm/storages/dataLoader.js +35 -96
- package/esm/storages/inMemory/InMemoryStorageCS.js +4 -16
- package/esm/sync/offline/LocalhostFromObject.js +2 -6
- package/esm/utils/settingsValidation/index.js +1 -4
- package/package.json +1 -1
- package/src/logger/constants.ts +0 -1
- package/src/logger/messages/error.ts +0 -1
- package/src/sdkFactory/index.ts +3 -6
- package/src/storages/dataLoader.ts +38 -97
- package/src/storages/inMemory/InMemoryStorageCS.ts +4 -19
- package/src/storages/types.ts +2 -4
- package/src/sync/offline/LocalhostFromObject.ts +2 -8
- package/src/types.ts +14 -26
- package/src/utils/settingsValidation/index.ts +1 -4
- package/src/utils/settingsValidation/types.ts +0 -2
- package/types/logger/constants.d.ts +0 -1
- package/types/storages/dataLoader.d.ts +6 -17
- package/types/storages/types.d.ts +1 -4
- package/types/sync/offline/LocalhostFromObject.d.ts +1 -2
- package/types/types.d.ts +13 -23
- package/types/utils/settingsValidation/index.d.ts +0 -1
- package/types/utils/settingsValidation/types.d.ts +0 -2
- package/cjs/utils/settingsValidation/localhost/builtin.js +0 -18
- package/cjs/utils/settingsValidation/localhost/pluggable.js +0 -22
- package/esm/utils/settingsValidation/localhost/builtin.js +0 -14
- package/esm/utils/settingsValidation/localhost/pluggable.js +0 -18
- package/src/utils/settingsValidation/localhost/builtin.ts +0 -16
- package/src/utils/settingsValidation/localhost/pluggable.ts +0 -22
- package/types/evaluator/matchers/sember_inlist.d.ts +0 -3
- package/types/evaluator/matchersTransform/set.d.ts +0 -5
- package/types/evaluator/matchersTransform/string.d.ts +0 -7
- package/types/integrations/browser.d.ts +0 -12
- package/types/integrations/ga/GaToSplit.d.ts +0 -40
- package/types/integrations/ga/GoogleAnalyticsToSplit.d.ts +0 -3
- package/types/integrations/ga/SplitToGa.d.ts +0 -34
- package/types/integrations/ga/SplitToGoogleAnalytics.d.ts +0 -3
- package/types/integrations/ga/types.d.ts +0 -148
- package/types/sdkClient/sdkClientMethodCSWithTT.d.ts +0 -8
- package/types/storages/AbstractSegmentsCacheSync.d.ts +0 -54
- package/types/storages/AbstractSplitsCache.d.ts +0 -46
- package/types/sync/streaming/mySegmentsV2utils.d.ts +0 -27
- package/types/sync/streaming/pushManagerCS_Spec1_3.d.ts +0 -9
- package/types/sync/streaming/pushManager_Spec1_3.d.ts +0 -9
- package/types/trackers/impressionObserver/utils.d.ts +0 -5
- package/types/utils/inputValidation/sdkKey.d.ts +0 -7
- package/types/utils/inputValidation/splitExistance.d.ts +0 -7
- package/types/utils/inputValidation/trafficTypeExistance.d.ts +0 -9
- package/types/utils/lang/maps.d.ts +0 -59
- package/types/utils/redis/RedisMock.d.ts +0 -4
- package/types/utils/settingsValidation/localhost/builtin.d.ts +0 -16
- package/types/utils/settingsValidation/localhost/pluggable.d.ts +0 -16
- package/types/utils/settingsValidation/logger/globalLogLevel.d.ts +0 -8
- /package/types/utils/{semVer.d.ts → Semver.d.ts} +0 -0
package/CHANGES.txt
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
2.0.0 (October XX, 2024)
|
|
2
2
|
- Added support for targeting rules based on large segments.
|
|
3
3
|
- Added `factory.destroy()` method, which invokes the `destroy` method on all SDK clients created by the factory.
|
|
4
|
-
- Added `factory.getState()` method for standalone server-side SDKs, which returns the rollout plan snapshot from the storage.
|
|
5
|
-
- Added `preloadedData` configuration option for standalone client-side SDKs, which allows preloading the SDK storage with a snapshot of the rollout plan.
|
|
6
|
-
- Updated internal storage factory to emit the SDK_READY_FROM_CACHE event when it corresponds, to clean up the initialization flow.
|
|
7
4
|
- Updated the handling of timers and async operations inside an `init` factory method to enable lazy initialization of the SDK in standalone mode. This update is intended for the React SDK.
|
|
8
5
|
- Bugfixing - Fixed an issue with the server-side polling manager that caused dangling timers when the SDK was destroyed before it was ready.
|
|
9
6
|
- BREAKING CHANGES:
|
|
@@ -14,6 +11,7 @@
|
|
|
14
11
|
- Removed the migration logic for the old format of MySegments keys in LocalStorage introduced in JavaScript SDK v10.17.3.
|
|
15
12
|
- Removed the `sdkClientMethodCSWithTT` function, which handled the logic to bound an optional traffic type to SDK clients. Client-side SDK implementations must use `sdkClientMethodCS` module, which, unlike the previous function, does not allow passing a traffic type but simplifies the SDK API.
|
|
16
13
|
- Removed internal ponyfills for `Map` and `Set` global objects, dropping support for IE and other outdated browsers. The SDK now requires the runtime environment to support these features natively or to provide a polyfill.
|
|
14
|
+
- Removed the `sync.localhostMode` configuration option to plug the LocalhostMode module.
|
|
17
15
|
|
|
18
16
|
1.17.0 (September 6, 2024)
|
|
19
17
|
- Added `sync.requestOptions.getHeaderOverrides` configuration option to enhance SDK HTTP request Headers for Authorization Frameworks.
|
package/cjs/logger/constants.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ENGINE_VALUE_INVALID = exports.USER_CONSENT_INITIAL = exports.USER_CONSENT_NOT_UPDATED = exports.USER_CONSENT_UPDATED = exports.IMPRESSIONS_TRACKER_SUCCESS = exports.EVENTS_TRACKER_SUCCESS = exports.SYNC_STOP_POLLING = exports.SYNC_CONTINUE_POLLING = exports.SYNC_START_POLLING = exports.SUBMITTERS_PUSH = exports.SUBMITTERS_PUSH_FULL_QUEUE = exports.STREAMING_DISCONNECTING = exports.STREAMING_DISABLED = exports.STREAMING_CONNECTING = exports.STREAMING_RECONNECT = exports.STREAMING_REFRESH_TOKEN = exports.SYNC_SPLITS_FETCH_RETRY = exports.POLLING_STOP = exports.POLLING_START = exports.POLLING_SMART_PAUSING = exports.NEW_FACTORY = exports.NEW_SHARED_CLIENT = exports.IMPRESSION_QUEUEING = exports.IMPRESSION = exports.CLIENT_READY = exports.CLIENT_READY_FROM_CACHE = exports.ENGINE_MATCHER_RESULT = exports.SETTINGS_SPLITS_FILTER = exports.SYNC_TASK_STOP = exports.SYNC_TASK_EXECUTE = exports.SYNC_TASK_START = exports.STREAMING_NEW_MESSAGE = exports.SYNC_SPLITS_SEGMENTS = exports.SYNC_SPLITS_REMOVED = exports.SYNC_SPLITS_NEW = exports.SYNC_SPLITS_FETCH = exports.SYNC_OFFLINE_DATA = exports.RETRIEVE_MANAGER = exports.RETRIEVE_CLIENT_EXISTING = exports.RETRIEVE_CLIENT_DEFAULT = exports.CLEANUP_DEREGISTERING = exports.CLEANUP_REGISTERING = exports.ENGINE_SANITIZE = exports.ENGINE_VALUE = exports.ENGINE_MATCHER_DEPENDENCY_PRE = exports.ENGINE_MATCHER_DEPENDENCY = exports.ENGINE_BUCKET = exports.ENGINE_COMBINER_IFELSEIF_NO_TREATMENT = exports.ENGINE_COMBINER_IFELSEIF = exports.ENGINE_COMBINER_AND = void 0;
|
|
4
4
|
exports.ERROR_INVALID_CONFIG_PARAM = exports.ERROR_EMPTY_ARRAY = exports.ERROR_EMPTY = exports.ERROR_INVALID = exports.ERROR_INVALID_KEY_OBJECT = exports.ERROR_TOO_LONG = exports.ERROR_NULL = exports.ERROR_CLIENT_DESTROYED = exports.ERROR_NOT_FINITE = exports.ERROR_SIZE_EXCEEDED = exports.ERROR_NOT_PLAIN_OBJECT = exports.ERROR_EVENT_TYPE_FORMAT = exports.ERROR_EVENTS_TRACKER = exports.ERROR_IMPRESSIONS_LISTENER = exports.ERROR_IMPRESSIONS_TRACKER = exports.ERROR_STREAMING_AUTH = exports.ERROR_STREAMING_SSE = exports.ERROR_SYNC_OFFLINE_LOADING = exports.ERROR_CLIENT_CANNOT_GET_READY = exports.ERROR_CLIENT_LISTENER = exports.ERROR_LOGLEVEL_INVALID = exports.ERROR_ENGINE_COMBINER_IFELSEIF = exports.WARN_FLAGSET_WITHOUT_FLAGS = exports.WARN_FLAGSET_NOT_CONFIGURED = exports.WARN_LOWERCASE_FLAGSET = exports.WARN_INVALID_FLAGSET = exports.STREAMING_PARSING_SPLIT_UPDATE = exports.STREAMING_PARSING_MEMBERSHIPS_UPDATE = exports.WARN_SDK_KEY = exports.WARN_SPLITS_FILTER_EMPTY = exports.WARN_SPLITS_FILTER_INVALID = exports.WARN_SPLITS_FILTER_IGNORED = exports.WARN_INTEGRATION_INVALID = exports.WARN_NOT_EXISTENT_TT = exports.WARN_LOWERCASE_TRAFFIC_TYPE = exports.WARN_NOT_EXISTENT_SPLIT = exports.WARN_TRIMMING = exports.WARN_CONVERTING = exports.WARN_TRIMMING_PROPERTIES = exports.WARN_SETTING_NULL = exports.SUBMITTERS_PUSH_RETRY = exports.SUBMITTERS_PUSH_FAILS = exports.STREAMING_FALLBACK = exports.STREAMING_PARSING_MESSAGE_FAILS = exports.STREAMING_PARSING_ERROR_FAILS = exports.SYNC_SPLITS_FETCH_FAILS = exports.SYNC_MYSEGMENTS_FETCH_RETRY = exports.CLIENT_NOT_READY = exports.CLIENT_NO_LISTENER = exports.ENGINE_VALUE_NO_ATTRIBUTES = void 0;
|
|
5
|
-
exports.LOG_PREFIX_CLEANUP = exports.LOG_PREFIX_UNIQUE_KEYS_TRACKER = exports.LOG_PREFIX_EVENTS_TRACKER = exports.LOG_PREFIX_IMPRESSIONS_TRACKER = exports.LOG_PREFIX_SYNC_SUBMITTERS = exports.LOG_PREFIX_SYNC_POLLING = exports.LOG_PREFIX_SYNC_MYSEGMENTS = exports.LOG_PREFIX_SYNC_SEGMENTS = exports.LOG_PREFIX_SYNC_SPLITS = exports.LOG_PREFIX_SYNC_STREAMING = exports.LOG_PREFIX_SYNC_OFFLINE = exports.LOG_PREFIX_SYNC_MANAGER = exports.LOG_PREFIX_SYNC = exports.LOG_PREFIX_ENGINE_VALUE = exports.LOG_PREFIX_ENGINE_MATCHER = exports.LOG_PREFIX_ENGINE_COMBINER = exports.LOG_PREFIX_ENGINE = exports.LOG_PREFIX_CLIENT_INSTANTIATION = exports.LOG_PREFIX_INSTANTIATION = exports.LOG_PREFIX_SETTINGS = exports.ENGINE_MATCHER_ERROR = exports.ERROR_SETS_FILTER_EXCLUSIVE = exports.ERROR_TOO_MANY_SETS = exports.ERROR_MIN_CONFIG_PARAM = exports.ERROR_NOT_BOOLEAN = exports.ERROR_STORAGE_INVALID = exports.
|
|
5
|
+
exports.LOG_PREFIX_CLEANUP = exports.LOG_PREFIX_UNIQUE_KEYS_TRACKER = exports.LOG_PREFIX_EVENTS_TRACKER = exports.LOG_PREFIX_IMPRESSIONS_TRACKER = exports.LOG_PREFIX_SYNC_SUBMITTERS = exports.LOG_PREFIX_SYNC_POLLING = exports.LOG_PREFIX_SYNC_MYSEGMENTS = exports.LOG_PREFIX_SYNC_SEGMENTS = exports.LOG_PREFIX_SYNC_SPLITS = exports.LOG_PREFIX_SYNC_STREAMING = exports.LOG_PREFIX_SYNC_OFFLINE = exports.LOG_PREFIX_SYNC_MANAGER = exports.LOG_PREFIX_SYNC = exports.LOG_PREFIX_ENGINE_VALUE = exports.LOG_PREFIX_ENGINE_MATCHER = exports.LOG_PREFIX_ENGINE_COMBINER = exports.LOG_PREFIX_ENGINE = exports.LOG_PREFIX_CLIENT_INSTANTIATION = exports.LOG_PREFIX_INSTANTIATION = exports.LOG_PREFIX_SETTINGS = exports.ENGINE_MATCHER_ERROR = exports.ERROR_SETS_FILTER_EXCLUSIVE = exports.ERROR_TOO_MANY_SETS = exports.ERROR_MIN_CONFIG_PARAM = exports.ERROR_NOT_BOOLEAN = exports.ERROR_STORAGE_INVALID = exports.ERROR_HTTP = void 0;
|
|
6
6
|
/**
|
|
7
7
|
* Message codes used to trim string log messages from commons and client-side API modules,
|
|
8
8
|
* in order to reduce the minimal SDK size for Browser and eventually other client-side environments.
|
|
@@ -111,7 +111,6 @@ exports.ERROR_EMPTY = 319;
|
|
|
111
111
|
exports.ERROR_EMPTY_ARRAY = 320;
|
|
112
112
|
exports.ERROR_INVALID_CONFIG_PARAM = 321;
|
|
113
113
|
exports.ERROR_HTTP = 322;
|
|
114
|
-
exports.ERROR_LOCALHOST_MODULE_REQUIRED = 323;
|
|
115
114
|
exports.ERROR_STORAGE_INVALID = 324;
|
|
116
115
|
exports.ERROR_NOT_BOOLEAN = 325;
|
|
117
116
|
exports.ERROR_MIN_CONFIG_PARAM = 326;
|
|
@@ -35,7 +35,6 @@ exports.codesError = [
|
|
|
35
35
|
[c.ERROR_NOT_BOOLEAN, '%s: provided param must be a boolean value.'],
|
|
36
36
|
// initialization / settings validation
|
|
37
37
|
[c.ERROR_INVALID_CONFIG_PARAM, c.LOG_PREFIX_SETTINGS + ': you passed an invalid "%s" config param. It should be one of the following values: %s. Defaulting to "%s".'],
|
|
38
|
-
[c.ERROR_LOCALHOST_MODULE_REQUIRED, c.LOG_PREFIX_SETTINGS + ': an invalid value was received for "sync.localhostMode" config. A valid entity should be provided for localhost mode.'],
|
|
39
38
|
[c.ERROR_STORAGE_INVALID, c.LOG_PREFIX_SETTINGS + ': the provided storage is invalid.%s Falling back into default MEMORY storage'],
|
|
40
39
|
[c.ERROR_MIN_CONFIG_PARAM, c.LOG_PREFIX_SETTINGS + ': the provided "%s" config param is lower than allowed. Setting to the minimum value %s seconds'],
|
|
41
40
|
[c.ERROR_TOO_MANY_SETS, c.LOG_PREFIX_SETTINGS + ': the amount of flag sets provided are big causing uri length error.'],
|
package/cjs/sdkFactory/index.js
CHANGED
|
@@ -45,10 +45,8 @@ function sdkFactory(params) {
|
|
|
45
45
|
readiness.splits.emit(constants_2.SDK_SPLITS_ARRIVED);
|
|
46
46
|
readiness.segments.emit(constants_2.SDK_SEGMENTS_ARRIVED);
|
|
47
47
|
},
|
|
48
|
-
onReadyFromCacheCb: function () {
|
|
49
|
-
readiness.splits.emit(constants_2.SDK_SPLITS_CACHE_LOADED);
|
|
50
|
-
}
|
|
51
48
|
});
|
|
49
|
+
// @TODO add support for dataloader: `if (params.dataLoader) params.dataLoader(storage);`
|
|
52
50
|
var clients = {};
|
|
53
51
|
var telemetryTracker = (0, telemetryTracker_1.telemetryTrackerFactory)(storage.telemetry, platform.now);
|
|
54
52
|
var integrationsManager = integrationsManagerFactory && integrationsManagerFactory({ settings: settings, storage: storage, telemetryTracker: telemetryTracker });
|
|
@@ -1,113 +1,51 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
var
|
|
5
|
-
var key_1 = require("../utils/key");
|
|
3
|
+
exports.dataLoaderFactory = void 0;
|
|
4
|
+
var browser_1 = require("../utils/constants/browser");
|
|
6
5
|
/**
|
|
7
|
-
*
|
|
8
|
-
* (https://github.com/godaddy/split-javascript-data-loader/blob/master/src/load-data.js)
|
|
6
|
+
* Factory of client-side storage loader
|
|
9
7
|
*
|
|
10
|
-
* @param preloadedData validated data following the format proposed in https://github.com/godaddy/split-javascript-data-loader
|
|
11
|
-
*
|
|
12
|
-
* @
|
|
13
|
-
*
|
|
14
|
-
* @TODO extend to load largeSegments
|
|
15
|
-
* @TODO extend to load data on shared mySegments storages. Be specific when emitting SDK_READY_FROM_CACHE on shared clients. Maybe the serializer should provide the `useSegments` flag.
|
|
16
|
-
* @TODO add logs, and input validation in this module, in favor of size reduction.
|
|
17
|
-
* @TODO unit tests
|
|
8
|
+
* @param preloadedData validated data following the format proposed in https://github.com/godaddy/split-javascript-data-loader
|
|
9
|
+
* and extended with a `mySegmentsData` property.
|
|
10
|
+
* @returns function to preload the storage
|
|
18
11
|
*/
|
|
19
|
-
function
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
12
|
+
function dataLoaderFactory(preloadedData) {
|
|
13
|
+
/**
|
|
14
|
+
* Storage-agnostic adaptation of `loadDataIntoLocalStorage` function
|
|
15
|
+
* (https://github.com/godaddy/split-javascript-data-loader/blob/master/src/load-data.js)
|
|
16
|
+
*
|
|
17
|
+
* @param storage object containing `splits` and `segments` cache (client-side variant)
|
|
18
|
+
* @param userId user key string of the provided MySegmentsCache
|
|
19
|
+
*
|
|
20
|
+
* @TODO extend to support SegmentsCache (server-side variant) by making `userId` optional and adding the corresponding logic.
|
|
21
|
+
* @TODO extend to load data on shared mySegments storages. Be specific when emitting SDK_READY_FROM_CACHE on shared clients. Maybe the serializer should provide the `useSegments` flag.
|
|
22
|
+
*/
|
|
23
|
+
return function loadData(storage, userId) {
|
|
24
|
+
// Do not load data if current preloadedData is empty
|
|
25
|
+
if (Object.keys(preloadedData).length === 0)
|
|
26
|
+
return;
|
|
27
|
+
var _a = preloadedData.lastUpdated, lastUpdated = _a === void 0 ? -1 : _a, _b = preloadedData.segmentsData, segmentsData = _b === void 0 ? {} : _b, _c = preloadedData.since, since = _c === void 0 ? -1 : _c, _d = preloadedData.splitsData, splitsData = _d === void 0 ? {} : _d;
|
|
25
28
|
var storedSince = storage.splits.getChangeNumber();
|
|
26
|
-
|
|
27
|
-
if
|
|
29
|
+
var expirationTimestamp = Date.now() - browser_1.DEFAULT_CACHE_EXPIRATION_IN_MILLIS;
|
|
30
|
+
// Do not load data if current localStorage data is more recent,
|
|
31
|
+
// or if its `lastUpdated` timestamp is older than the given `expirationTimestamp`,
|
|
32
|
+
if (storedSince > since || lastUpdated < expirationTimestamp)
|
|
28
33
|
return;
|
|
29
34
|
// cleaning up the localStorage data, since some cached splits might need be part of the preloaded data
|
|
30
35
|
storage.splits.clear();
|
|
31
36
|
storage.splits.setChangeNumber(since);
|
|
32
37
|
// splitsData in an object where the property is the split name and the pertaining value is a stringified json of its data
|
|
33
|
-
storage.splits.addSplits(splitsData.map(function (
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
return segmentKeys.indexOf(matchingKey) > -1;
|
|
43
|
-
}).map(function (segmentName) { return ({ n: segmentName }); })
|
|
44
|
-
}
|
|
45
|
-
};
|
|
38
|
+
storage.splits.addSplits(Object.keys(splitsData).map(function (splitName) { return JSON.parse(splitsData[splitName]); }));
|
|
39
|
+
// add mySegments data
|
|
40
|
+
var mySegmentsData = preloadedData.mySegmentsData && preloadedData.mySegmentsData[userId];
|
|
41
|
+
if (!mySegmentsData) {
|
|
42
|
+
// segmentsData in an object where the property is the segment name and the pertaining value is a stringified object that contains the `added` array of userIds
|
|
43
|
+
mySegmentsData = Object.keys(segmentsData).filter(function (segmentName) {
|
|
44
|
+
var userIds = JSON.parse(segmentsData[segmentName]).added;
|
|
45
|
+
return Array.isArray(userIds) && userIds.indexOf(userId) > -1;
|
|
46
|
+
});
|
|
46
47
|
}
|
|
47
|
-
|
|
48
|
-
if (membershipsData.ms)
|
|
49
|
-
storage.segments.resetSegments(membershipsData.ms);
|
|
50
|
-
if (membershipsData.ls && storage.largeSegments)
|
|
51
|
-
storage.largeSegments.resetSegments(membershipsData.ls);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
else { // add segments data (server-side)
|
|
55
|
-
Object.keys(segmentsData).forEach(function (segmentName) {
|
|
56
|
-
var segmentKeys = segmentsData[segmentName];
|
|
57
|
-
storage.segments.update(segmentName, segmentKeys, [], -1);
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
exports.loadData = loadData;
|
|
62
|
-
function getSnapshot(storage, userKeys) {
|
|
63
|
-
return {
|
|
64
|
-
// lastUpdated: Date.now(),
|
|
65
|
-
since: storage.splits.getChangeNumber(),
|
|
66
|
-
splitsData: storage.splits.getAll(),
|
|
67
|
-
segmentsData: userKeys ?
|
|
68
|
-
undefined : // @ts-ignore accessing private prop
|
|
69
|
-
Object.keys(storage.segments.segmentCache).reduce(function (prev, cur) {
|
|
70
|
-
prev[cur] = (0, sets_1.setToArray)(storage.segments.segmentCache[cur]);
|
|
71
|
-
return prev;
|
|
72
|
-
}, {}),
|
|
73
|
-
membershipsData: userKeys ?
|
|
74
|
-
userKeys.reduce(function (prev, userKey) {
|
|
75
|
-
if (storage.shared) {
|
|
76
|
-
// Client-side segments
|
|
77
|
-
// @ts-ignore accessing private prop
|
|
78
|
-
var sharedStorage = storage.shared(userKey);
|
|
79
|
-
prev[(0, key_1.getMatching)(userKey)] = {
|
|
80
|
-
ms: {
|
|
81
|
-
// @ts-ignore accessing private prop
|
|
82
|
-
k: Object.keys(sharedStorage.segments.segmentCache).map(function (segmentName) { return ({ n: segmentName }); }),
|
|
83
|
-
// cn: sharedStorage.segments.getChangeNumber()
|
|
84
|
-
},
|
|
85
|
-
ls: sharedStorage.largeSegments ? {
|
|
86
|
-
// @ts-ignore accessing private prop
|
|
87
|
-
k: Object.keys(sharedStorage.largeSegments.segmentCache).map(function (segmentName) { return ({ n: segmentName }); }),
|
|
88
|
-
// cn: sharedStorage.largeSegments.getChangeNumber()
|
|
89
|
-
} : undefined
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
else {
|
|
93
|
-
prev[(0, key_1.getMatching)(userKey)] = {
|
|
94
|
-
ms: {
|
|
95
|
-
// Server-side segments
|
|
96
|
-
// @ts-ignore accessing private prop
|
|
97
|
-
k: Object.keys(storage.segments.segmentCache).reduce(function (prev, segmentName) {
|
|
98
|
-
return storage.segments.segmentCache[segmentName].has(userKey) ?
|
|
99
|
-
prev.concat({ n: segmentName }) :
|
|
100
|
-
prev;
|
|
101
|
-
}, [])
|
|
102
|
-
},
|
|
103
|
-
ls: {
|
|
104
|
-
k: []
|
|
105
|
-
}
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
return prev;
|
|
109
|
-
}, {}) :
|
|
110
|
-
undefined
|
|
48
|
+
storage.segments.resetSegments({ k: mySegmentsData.map(function (s) { return ({ n: s }); }) });
|
|
111
49
|
};
|
|
112
50
|
}
|
|
113
|
-
exports.
|
|
51
|
+
exports.dataLoaderFactory = dataLoaderFactory;
|
|
@@ -9,15 +9,13 @@ var ImpressionCountsCacheInMemory_1 = require("./ImpressionCountsCacheInMemory")
|
|
|
9
9
|
var constants_1 = require("../../utils/constants");
|
|
10
10
|
var TelemetryCacheInMemory_1 = require("./TelemetryCacheInMemory");
|
|
11
11
|
var UniqueKeysCacheInMemoryCS_1 = require("./UniqueKeysCacheInMemoryCS");
|
|
12
|
-
var key_1 = require("../../utils/key");
|
|
13
|
-
var dataLoader_1 = require("../dataLoader");
|
|
14
12
|
/**
|
|
15
13
|
* InMemory storage factory for standalone client-side SplitFactory
|
|
16
14
|
*
|
|
17
15
|
* @param params parameters required by EventsCacheSync
|
|
18
16
|
*/
|
|
19
17
|
function InMemoryStorageCSFactory(params) {
|
|
20
|
-
var _a = params.settings, _b = _a.scheduler, impressionsQueueSize = _b.impressionsQueueSize, eventsQueueSize = _b.eventsQueueSize, _c = _a.sync, impressionsMode = _c.impressionsMode, __splitFiltersValidation = _c.__splitFiltersValidation
|
|
18
|
+
var _a = params.settings, _b = _a.scheduler, impressionsQueueSize = _b.impressionsQueueSize, eventsQueueSize = _b.eventsQueueSize, _c = _a.sync, impressionsMode = _c.impressionsMode, __splitFiltersValidation = _c.__splitFiltersValidation;
|
|
21
19
|
var splits = new SplitsCacheInMemory_1.SplitsCacheInMemory(__splitFiltersValidation);
|
|
22
20
|
var segments = new MySegmentsCacheInMemory_1.MySegmentsCacheInMemory();
|
|
23
21
|
var largeSegments = new MySegmentsCacheInMemory_1.MySegmentsCacheInMemory();
|
|
@@ -41,16 +39,11 @@ function InMemoryStorageCSFactory(params) {
|
|
|
41
39
|
this.uniqueKeys && this.uniqueKeys.clear();
|
|
42
40
|
},
|
|
43
41
|
// When using shared instantiation with MEMORY we reuse everything but segments (they are unique per key)
|
|
44
|
-
shared: function (
|
|
45
|
-
var segments = new MySegmentsCacheInMemory_1.MySegmentsCacheInMemory();
|
|
46
|
-
var largeSegments = new MySegmentsCacheInMemory_1.MySegmentsCacheInMemory();
|
|
47
|
-
if (preloadedData) {
|
|
48
|
-
(0, dataLoader_1.loadData)(preloadedData, { segments: segments, largeSegments: largeSegments }, matchingKey);
|
|
49
|
-
}
|
|
42
|
+
shared: function () {
|
|
50
43
|
return {
|
|
51
44
|
splits: this.splits,
|
|
52
|
-
segments:
|
|
53
|
-
largeSegments:
|
|
45
|
+
segments: new MySegmentsCacheInMemory_1.MySegmentsCacheInMemory(),
|
|
46
|
+
largeSegments: new MySegmentsCacheInMemory_1.MySegmentsCacheInMemory(),
|
|
54
47
|
impressions: this.impressions,
|
|
55
48
|
impressionCounts: this.impressionCounts,
|
|
56
49
|
events: this.events,
|
|
@@ -75,11 +68,6 @@ function InMemoryStorageCSFactory(params) {
|
|
|
75
68
|
if (storage.uniqueKeys)
|
|
76
69
|
storage.uniqueKeys.track = noopTrack;
|
|
77
70
|
}
|
|
78
|
-
if (preloadedData) {
|
|
79
|
-
(0, dataLoader_1.loadData)(preloadedData, storage, (0, key_1.getMatching)(params.settings.core.key));
|
|
80
|
-
if (splits.getChangeNumber() > -1)
|
|
81
|
-
onReadyFromCacheCb();
|
|
82
|
-
}
|
|
83
71
|
return storage;
|
|
84
72
|
}
|
|
85
73
|
exports.InMemoryStorageCSFactory = InMemoryStorageCSFactory;
|
|
@@ -1,13 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.localhostFromObjectFactory = void 0;
|
|
4
4
|
var splitsParserFromSettings_1 = require("./splitsParser/splitsParserFromSettings");
|
|
5
5
|
var syncManagerOffline_1 = require("./syncManagerOffline");
|
|
6
|
-
// Singleton instance of the factory function for offline SyncManager from object
|
|
6
|
+
// Singleton instance of the factory function for offline SyncManager from object
|
|
7
7
|
// SDK instances instantiate their SyncManagers with the same factory
|
|
8
|
-
|
|
9
|
-
localhostFromObject.type = 'LocalhostFromObject';
|
|
10
|
-
function LocalhostFromObject() {
|
|
11
|
-
return localhostFromObject;
|
|
12
|
-
}
|
|
13
|
-
exports.LocalhostFromObject = LocalhostFromObject;
|
|
8
|
+
exports.localhostFromObjectFactory = (0, syncManagerOffline_1.syncManagerOfflineFactory)(splitsParserFromSettings_1.splitsParserFromSettingsFactory);
|
|
@@ -70,7 +70,6 @@ exports.base = {
|
|
|
70
70
|
splitFilters: undefined,
|
|
71
71
|
// impressions collection mode
|
|
72
72
|
impressionsMode: constants_1.OPTIMIZED,
|
|
73
|
-
localhostMode: undefined,
|
|
74
73
|
enabled: true,
|
|
75
74
|
flagSpecVersion: constants_1.FLAG_SPEC_VERSION
|
|
76
75
|
},
|
|
@@ -88,7 +87,7 @@ function fromSecondsToMillis(n) {
|
|
|
88
87
|
* @param validationParams defaults and fields validators used to validate and creates a settings object from a given config
|
|
89
88
|
*/
|
|
90
89
|
function settingsValidation(config, validationParams) {
|
|
91
|
-
var defaults = validationParams.defaults, runtime = validationParams.runtime, storage = validationParams.storage, integrations = validationParams.integrations, logger = validationParams.logger,
|
|
90
|
+
var defaults = validationParams.defaults, runtime = validationParams.runtime, storage = validationParams.storage, integrations = validationParams.integrations, logger = validationParams.logger, consent = validationParams.consent, flagSpec = validationParams.flagSpec;
|
|
92
91
|
// creates a settings object merging base, defaults and config objects.
|
|
93
92
|
var withDefaults = (0, lang_1.merge)({}, exports.base, defaults, config);
|
|
94
93
|
// Keeps reference to the `features` property
|
|
@@ -160,8 +159,6 @@ function settingsValidation(config, validationParams) {
|
|
|
160
159
|
// @ts-ignore, modify readonly prop
|
|
161
160
|
if (integrations)
|
|
162
161
|
withDefaults.integrations = integrations(withDefaults);
|
|
163
|
-
if (localhost)
|
|
164
|
-
sync.localhostMode = localhost(withDefaults);
|
|
165
162
|
// validate push options
|
|
166
163
|
if (withDefaults.streamingEnabled !== false) { // @ts-ignore, modify readonly prop
|
|
167
164
|
withDefaults.streamingEnabled = true;
|
package/esm/logger/constants.js
CHANGED
|
@@ -106,7 +106,6 @@ export var ERROR_EMPTY = 319;
|
|
|
106
106
|
export var ERROR_EMPTY_ARRAY = 320;
|
|
107
107
|
export var ERROR_INVALID_CONFIG_PARAM = 321;
|
|
108
108
|
export var ERROR_HTTP = 322;
|
|
109
|
-
export var ERROR_LOCALHOST_MODULE_REQUIRED = 323;
|
|
110
109
|
export var ERROR_STORAGE_INVALID = 324;
|
|
111
110
|
export var ERROR_NOT_BOOLEAN = 325;
|
|
112
111
|
export var ERROR_MIN_CONFIG_PARAM = 326;
|
|
@@ -31,7 +31,6 @@ export var codesError = [
|
|
|
31
31
|
[c.ERROR_NOT_BOOLEAN, '%s: provided param must be a boolean value.'],
|
|
32
32
|
// initialization / settings validation
|
|
33
33
|
[c.ERROR_INVALID_CONFIG_PARAM, c.LOG_PREFIX_SETTINGS + ': you passed an invalid "%s" config param. It should be one of the following values: %s. Defaulting to "%s".'],
|
|
34
|
-
[c.ERROR_LOCALHOST_MODULE_REQUIRED, c.LOG_PREFIX_SETTINGS + ': an invalid value was received for "sync.localhostMode" config. A valid entity should be provided for localhost mode.'],
|
|
35
34
|
[c.ERROR_STORAGE_INVALID, c.LOG_PREFIX_SETTINGS + ': the provided storage is invalid.%s Falling back into default MEMORY storage'],
|
|
36
35
|
[c.ERROR_MIN_CONFIG_PARAM, c.LOG_PREFIX_SETTINGS + ': the provided "%s" config param is lower than allowed. Setting to the minimum value %s seconds'],
|
|
37
36
|
[c.ERROR_TOO_MANY_SETS, c.LOG_PREFIX_SETTINGS + ': the amount of flag sets provided are big causing uri length error.'],
|
package/esm/sdkFactory/index.js
CHANGED
|
@@ -5,7 +5,7 @@ import { telemetryTrackerFactory } from '../trackers/telemetryTracker';
|
|
|
5
5
|
import { validateAndTrackApiKey } from '../utils/inputValidation/apiKey';
|
|
6
6
|
import { createLoggerAPI } from '../logger/sdkLogger';
|
|
7
7
|
import { NEW_FACTORY, RETRIEVE_MANAGER } from '../logger/constants';
|
|
8
|
-
import { SDK_SPLITS_ARRIVED, SDK_SEGMENTS_ARRIVED
|
|
8
|
+
import { SDK_SPLITS_ARRIVED, SDK_SEGMENTS_ARRIVED } from '../readiness/constants';
|
|
9
9
|
import { objectAssign } from '../utils/lang/objectAssign';
|
|
10
10
|
import { strategyDebugFactory } from '../trackers/strategy/strategyDebug';
|
|
11
11
|
import { strategyOptimizedFactory } from '../trackers/strategy/strategyOptimized';
|
|
@@ -42,10 +42,8 @@ export function sdkFactory(params) {
|
|
|
42
42
|
readiness.splits.emit(SDK_SPLITS_ARRIVED);
|
|
43
43
|
readiness.segments.emit(SDK_SEGMENTS_ARRIVED);
|
|
44
44
|
},
|
|
45
|
-
onReadyFromCacheCb: function () {
|
|
46
|
-
readiness.splits.emit(SDK_SPLITS_CACHE_LOADED);
|
|
47
|
-
}
|
|
48
45
|
});
|
|
46
|
+
// @TODO add support for dataloader: `if (params.dataLoader) params.dataLoader(storage);`
|
|
49
47
|
var clients = {};
|
|
50
48
|
var telemetryTracker = telemetryTrackerFactory(storage.telemetry, platform.now);
|
|
51
49
|
var integrationsManager = integrationsManagerFactory && integrationsManagerFactory({ settings: settings, storage: storage, telemetryTracker: telemetryTracker });
|
|
@@ -1,108 +1,47 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { getMatching } from '../utils/key';
|
|
1
|
+
import { DEFAULT_CACHE_EXPIRATION_IN_MILLIS } from '../utils/constants/browser';
|
|
3
2
|
/**
|
|
4
|
-
*
|
|
5
|
-
* (https://github.com/godaddy/split-javascript-data-loader/blob/master/src/load-data.js)
|
|
3
|
+
* Factory of client-side storage loader
|
|
6
4
|
*
|
|
7
|
-
* @param preloadedData validated data following the format proposed in https://github.com/godaddy/split-javascript-data-loader
|
|
8
|
-
*
|
|
9
|
-
* @
|
|
10
|
-
*
|
|
11
|
-
* @TODO extend to load largeSegments
|
|
12
|
-
* @TODO extend to load data on shared mySegments storages. Be specific when emitting SDK_READY_FROM_CACHE on shared clients. Maybe the serializer should provide the `useSegments` flag.
|
|
13
|
-
* @TODO add logs, and input validation in this module, in favor of size reduction.
|
|
14
|
-
* @TODO unit tests
|
|
5
|
+
* @param preloadedData validated data following the format proposed in https://github.com/godaddy/split-javascript-data-loader
|
|
6
|
+
* and extended with a `mySegmentsData` property.
|
|
7
|
+
* @returns function to preload the storage
|
|
15
8
|
*/
|
|
16
|
-
export function
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
9
|
+
export function dataLoaderFactory(preloadedData) {
|
|
10
|
+
/**
|
|
11
|
+
* Storage-agnostic adaptation of `loadDataIntoLocalStorage` function
|
|
12
|
+
* (https://github.com/godaddy/split-javascript-data-loader/blob/master/src/load-data.js)
|
|
13
|
+
*
|
|
14
|
+
* @param storage object containing `splits` and `segments` cache (client-side variant)
|
|
15
|
+
* @param userId user key string of the provided MySegmentsCache
|
|
16
|
+
*
|
|
17
|
+
* @TODO extend to support SegmentsCache (server-side variant) by making `userId` optional and adding the corresponding logic.
|
|
18
|
+
* @TODO extend to load data on shared mySegments storages. Be specific when emitting SDK_READY_FROM_CACHE on shared clients. Maybe the serializer should provide the `useSegments` flag.
|
|
19
|
+
*/
|
|
20
|
+
return function loadData(storage, userId) {
|
|
21
|
+
// Do not load data if current preloadedData is empty
|
|
22
|
+
if (Object.keys(preloadedData).length === 0)
|
|
23
|
+
return;
|
|
24
|
+
var _a = preloadedData.lastUpdated, lastUpdated = _a === void 0 ? -1 : _a, _b = preloadedData.segmentsData, segmentsData = _b === void 0 ? {} : _b, _c = preloadedData.since, since = _c === void 0 ? -1 : _c, _d = preloadedData.splitsData, splitsData = _d === void 0 ? {} : _d;
|
|
22
25
|
var storedSince = storage.splits.getChangeNumber();
|
|
23
|
-
|
|
24
|
-
if
|
|
26
|
+
var expirationTimestamp = Date.now() - DEFAULT_CACHE_EXPIRATION_IN_MILLIS;
|
|
27
|
+
// Do not load data if current localStorage data is more recent,
|
|
28
|
+
// or if its `lastUpdated` timestamp is older than the given `expirationTimestamp`,
|
|
29
|
+
if (storedSince > since || lastUpdated < expirationTimestamp)
|
|
25
30
|
return;
|
|
26
31
|
// cleaning up the localStorage data, since some cached splits might need be part of the preloaded data
|
|
27
32
|
storage.splits.clear();
|
|
28
33
|
storage.splits.setChangeNumber(since);
|
|
29
34
|
// splitsData in an object where the property is the split name and the pertaining value is a stringified json of its data
|
|
30
|
-
storage.splits.addSplits(splitsData.map(function (
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
return segmentKeys.indexOf(matchingKey) > -1;
|
|
40
|
-
}).map(function (segmentName) { return ({ n: segmentName }); })
|
|
41
|
-
}
|
|
42
|
-
};
|
|
35
|
+
storage.splits.addSplits(Object.keys(splitsData).map(function (splitName) { return JSON.parse(splitsData[splitName]); }));
|
|
36
|
+
// add mySegments data
|
|
37
|
+
var mySegmentsData = preloadedData.mySegmentsData && preloadedData.mySegmentsData[userId];
|
|
38
|
+
if (!mySegmentsData) {
|
|
39
|
+
// segmentsData in an object where the property is the segment name and the pertaining value is a stringified object that contains the `added` array of userIds
|
|
40
|
+
mySegmentsData = Object.keys(segmentsData).filter(function (segmentName) {
|
|
41
|
+
var userIds = JSON.parse(segmentsData[segmentName]).added;
|
|
42
|
+
return Array.isArray(userIds) && userIds.indexOf(userId) > -1;
|
|
43
|
+
});
|
|
43
44
|
}
|
|
44
|
-
|
|
45
|
-
if (membershipsData.ms)
|
|
46
|
-
storage.segments.resetSegments(membershipsData.ms);
|
|
47
|
-
if (membershipsData.ls && storage.largeSegments)
|
|
48
|
-
storage.largeSegments.resetSegments(membershipsData.ls);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
else { // add segments data (server-side)
|
|
52
|
-
Object.keys(segmentsData).forEach(function (segmentName) {
|
|
53
|
-
var segmentKeys = segmentsData[segmentName];
|
|
54
|
-
storage.segments.update(segmentName, segmentKeys, [], -1);
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
export function getSnapshot(storage, userKeys) {
|
|
59
|
-
return {
|
|
60
|
-
// lastUpdated: Date.now(),
|
|
61
|
-
since: storage.splits.getChangeNumber(),
|
|
62
|
-
splitsData: storage.splits.getAll(),
|
|
63
|
-
segmentsData: userKeys ?
|
|
64
|
-
undefined : // @ts-ignore accessing private prop
|
|
65
|
-
Object.keys(storage.segments.segmentCache).reduce(function (prev, cur) {
|
|
66
|
-
prev[cur] = setToArray(storage.segments.segmentCache[cur]);
|
|
67
|
-
return prev;
|
|
68
|
-
}, {}),
|
|
69
|
-
membershipsData: userKeys ?
|
|
70
|
-
userKeys.reduce(function (prev, userKey) {
|
|
71
|
-
if (storage.shared) {
|
|
72
|
-
// Client-side segments
|
|
73
|
-
// @ts-ignore accessing private prop
|
|
74
|
-
var sharedStorage = storage.shared(userKey);
|
|
75
|
-
prev[getMatching(userKey)] = {
|
|
76
|
-
ms: {
|
|
77
|
-
// @ts-ignore accessing private prop
|
|
78
|
-
k: Object.keys(sharedStorage.segments.segmentCache).map(function (segmentName) { return ({ n: segmentName }); }),
|
|
79
|
-
// cn: sharedStorage.segments.getChangeNumber()
|
|
80
|
-
},
|
|
81
|
-
ls: sharedStorage.largeSegments ? {
|
|
82
|
-
// @ts-ignore accessing private prop
|
|
83
|
-
k: Object.keys(sharedStorage.largeSegments.segmentCache).map(function (segmentName) { return ({ n: segmentName }); }),
|
|
84
|
-
// cn: sharedStorage.largeSegments.getChangeNumber()
|
|
85
|
-
} : undefined
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
else {
|
|
89
|
-
prev[getMatching(userKey)] = {
|
|
90
|
-
ms: {
|
|
91
|
-
// Server-side segments
|
|
92
|
-
// @ts-ignore accessing private prop
|
|
93
|
-
k: Object.keys(storage.segments.segmentCache).reduce(function (prev, segmentName) {
|
|
94
|
-
return storage.segments.segmentCache[segmentName].has(userKey) ?
|
|
95
|
-
prev.concat({ n: segmentName }) :
|
|
96
|
-
prev;
|
|
97
|
-
}, [])
|
|
98
|
-
},
|
|
99
|
-
ls: {
|
|
100
|
-
k: []
|
|
101
|
-
}
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
return prev;
|
|
105
|
-
}, {}) :
|
|
106
|
-
undefined
|
|
45
|
+
storage.segments.resetSegments({ k: mySegmentsData.map(function (s) { return ({ n: s }); }) });
|
|
107
46
|
};
|
|
108
47
|
}
|
|
@@ -6,15 +6,13 @@ import { ImpressionCountsCacheInMemory } from './ImpressionCountsCacheInMemory';
|
|
|
6
6
|
import { DEBUG, LOCALHOST_MODE, NONE, STORAGE_MEMORY } from '../../utils/constants';
|
|
7
7
|
import { shouldRecordTelemetry, TelemetryCacheInMemory } from './TelemetryCacheInMemory';
|
|
8
8
|
import { UniqueKeysCacheInMemoryCS } from './UniqueKeysCacheInMemoryCS';
|
|
9
|
-
import { getMatching } from '../../utils/key';
|
|
10
|
-
import { loadData } from '../dataLoader';
|
|
11
9
|
/**
|
|
12
10
|
* InMemory storage factory for standalone client-side SplitFactory
|
|
13
11
|
*
|
|
14
12
|
* @param params parameters required by EventsCacheSync
|
|
15
13
|
*/
|
|
16
14
|
export function InMemoryStorageCSFactory(params) {
|
|
17
|
-
var _a = params.settings, _b = _a.scheduler, impressionsQueueSize = _b.impressionsQueueSize, eventsQueueSize = _b.eventsQueueSize, _c = _a.sync, impressionsMode = _c.impressionsMode, __splitFiltersValidation = _c.__splitFiltersValidation
|
|
15
|
+
var _a = params.settings, _b = _a.scheduler, impressionsQueueSize = _b.impressionsQueueSize, eventsQueueSize = _b.eventsQueueSize, _c = _a.sync, impressionsMode = _c.impressionsMode, __splitFiltersValidation = _c.__splitFiltersValidation;
|
|
18
16
|
var splits = new SplitsCacheInMemory(__splitFiltersValidation);
|
|
19
17
|
var segments = new MySegmentsCacheInMemory();
|
|
20
18
|
var largeSegments = new MySegmentsCacheInMemory();
|
|
@@ -38,16 +36,11 @@ export function InMemoryStorageCSFactory(params) {
|
|
|
38
36
|
this.uniqueKeys && this.uniqueKeys.clear();
|
|
39
37
|
},
|
|
40
38
|
// When using shared instantiation with MEMORY we reuse everything but segments (they are unique per key)
|
|
41
|
-
shared: function (
|
|
42
|
-
var segments = new MySegmentsCacheInMemory();
|
|
43
|
-
var largeSegments = new MySegmentsCacheInMemory();
|
|
44
|
-
if (preloadedData) {
|
|
45
|
-
loadData(preloadedData, { segments: segments, largeSegments: largeSegments }, matchingKey);
|
|
46
|
-
}
|
|
39
|
+
shared: function () {
|
|
47
40
|
return {
|
|
48
41
|
splits: this.splits,
|
|
49
|
-
segments:
|
|
50
|
-
largeSegments:
|
|
42
|
+
segments: new MySegmentsCacheInMemory(),
|
|
43
|
+
largeSegments: new MySegmentsCacheInMemory(),
|
|
51
44
|
impressions: this.impressions,
|
|
52
45
|
impressionCounts: this.impressionCounts,
|
|
53
46
|
events: this.events,
|
|
@@ -72,11 +65,6 @@ export function InMemoryStorageCSFactory(params) {
|
|
|
72
65
|
if (storage.uniqueKeys)
|
|
73
66
|
storage.uniqueKeys.track = noopTrack;
|
|
74
67
|
}
|
|
75
|
-
if (preloadedData) {
|
|
76
|
-
loadData(preloadedData, storage, getMatching(params.settings.core.key));
|
|
77
|
-
if (splits.getChangeNumber() > -1)
|
|
78
|
-
onReadyFromCacheCb();
|
|
79
|
-
}
|
|
80
68
|
return storage;
|
|
81
69
|
}
|
|
82
70
|
InMemoryStorageCSFactory.type = STORAGE_MEMORY;
|
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
import { splitsParserFromSettingsFactory } from './splitsParser/splitsParserFromSettings';
|
|
2
2
|
import { syncManagerOfflineFactory } from './syncManagerOffline';
|
|
3
|
-
// Singleton instance of the factory function for offline SyncManager from object
|
|
3
|
+
// Singleton instance of the factory function for offline SyncManager from object
|
|
4
4
|
// SDK instances instantiate their SyncManagers with the same factory
|
|
5
|
-
var
|
|
6
|
-
localhostFromObject.type = 'LocalhostFromObject';
|
|
7
|
-
export function LocalhostFromObject() {
|
|
8
|
-
return localhostFromObject;
|
|
9
|
-
}
|
|
5
|
+
export var localhostFromObjectFactory = syncManagerOfflineFactory(splitsParserFromSettingsFactory);
|
|
@@ -67,7 +67,6 @@ export var base = {
|
|
|
67
67
|
splitFilters: undefined,
|
|
68
68
|
// impressions collection mode
|
|
69
69
|
impressionsMode: OPTIMIZED,
|
|
70
|
-
localhostMode: undefined,
|
|
71
70
|
enabled: true,
|
|
72
71
|
flagSpecVersion: FLAG_SPEC_VERSION
|
|
73
72
|
},
|
|
@@ -85,7 +84,7 @@ function fromSecondsToMillis(n) {
|
|
|
85
84
|
* @param validationParams defaults and fields validators used to validate and creates a settings object from a given config
|
|
86
85
|
*/
|
|
87
86
|
export function settingsValidation(config, validationParams) {
|
|
88
|
-
var defaults = validationParams.defaults, runtime = validationParams.runtime, storage = validationParams.storage, integrations = validationParams.integrations, logger = validationParams.logger,
|
|
87
|
+
var defaults = validationParams.defaults, runtime = validationParams.runtime, storage = validationParams.storage, integrations = validationParams.integrations, logger = validationParams.logger, consent = validationParams.consent, flagSpec = validationParams.flagSpec;
|
|
89
88
|
// creates a settings object merging base, defaults and config objects.
|
|
90
89
|
var withDefaults = merge({}, base, defaults, config);
|
|
91
90
|
// Keeps reference to the `features` property
|
|
@@ -157,8 +156,6 @@ export function settingsValidation(config, validationParams) {
|
|
|
157
156
|
// @ts-ignore, modify readonly prop
|
|
158
157
|
if (integrations)
|
|
159
158
|
withDefaults.integrations = integrations(withDefaults);
|
|
160
|
-
if (localhost)
|
|
161
|
-
sync.localhostMode = localhost(withDefaults);
|
|
162
159
|
// validate push options
|
|
163
160
|
if (withDefaults.streamingEnabled !== false) { // @ts-ignore, modify readonly prop
|
|
164
161
|
withDefaults.streamingEnabled = true;
|
package/package.json
CHANGED
package/src/logger/constants.ts
CHANGED
|
@@ -109,7 +109,6 @@ export const ERROR_EMPTY = 319;
|
|
|
109
109
|
export const ERROR_EMPTY_ARRAY = 320;
|
|
110
110
|
export const ERROR_INVALID_CONFIG_PARAM = 321;
|
|
111
111
|
export const ERROR_HTTP = 322;
|
|
112
|
-
export const ERROR_LOCALHOST_MODULE_REQUIRED = 323;
|
|
113
112
|
export const ERROR_STORAGE_INVALID = 324;
|
|
114
113
|
export const ERROR_NOT_BOOLEAN = 325;
|
|
115
114
|
export const ERROR_MIN_CONFIG_PARAM = 326;
|
|
@@ -32,7 +32,6 @@ export const codesError: [number, string][] = [
|
|
|
32
32
|
[c.ERROR_NOT_BOOLEAN, '%s: provided param must be a boolean value.'],
|
|
33
33
|
// initialization / settings validation
|
|
34
34
|
[c.ERROR_INVALID_CONFIG_PARAM, c.LOG_PREFIX_SETTINGS + ': you passed an invalid "%s" config param. It should be one of the following values: %s. Defaulting to "%s".'],
|
|
35
|
-
[c.ERROR_LOCALHOST_MODULE_REQUIRED, c.LOG_PREFIX_SETTINGS + ': an invalid value was received for "sync.localhostMode" config. A valid entity should be provided for localhost mode.'],
|
|
36
35
|
[c.ERROR_STORAGE_INVALID, c.LOG_PREFIX_SETTINGS+': the provided storage is invalid.%s Falling back into default MEMORY storage'],
|
|
37
36
|
[c.ERROR_MIN_CONFIG_PARAM, c.LOG_PREFIX_SETTINGS + ': the provided "%s" config param is lower than allowed. Setting to the minimum value %s seconds'],
|
|
38
37
|
[c.ERROR_TOO_MANY_SETS, c.LOG_PREFIX_SETTINGS + ': the amount of flag sets provided are big causing uri length error.'],
|