@splitsoftware/splitio-commons 1.2.1-rc.7 → 1.3.0
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 +14 -0
- package/cjs/{utils/consent.js → consent/index.js} +1 -1
- package/cjs/consent/sdkUserConsent.js +58 -0
- package/cjs/listeners/browser.js +1 -1
- package/cjs/logger/constants.js +3 -2
- package/cjs/logger/messages/info.js +1 -0
- package/cjs/sdkClient/client.js +4 -9
- package/cjs/sdkClient/clientCS.js +1 -1
- package/cjs/sdkClient/clientInputValidation.js +6 -8
- package/cjs/sdkClient/sdkClient.js +4 -7
- package/cjs/sdkClient/sdkClientMethodCS.js +3 -9
- package/cjs/sdkClient/sdkClientMethodCSWithTT.js +3 -13
- package/cjs/sdkFactory/index.js +6 -5
- package/cjs/storages/inRedis/RedisAdapter.js +9 -2
- package/cjs/sync/syncManagerOnline.js +1 -1
- package/cjs/trackers/eventTracker.js +8 -1
- package/cjs/trackers/impressionObserver/utils.js +8 -1
- package/cjs/trackers/impressionsTracker.js +6 -5
- package/cjs/utils/inputValidation/attributes.js +1 -1
- package/cjs/utils/lang/index.js +4 -2
- package/cjs/utils/lang/maps.js +16 -2
- package/cjs/utils/settingsValidation/index.js +21 -3
- package/esm/{utils/consent.js → consent/index.js} +1 -1
- package/esm/consent/sdkUserConsent.js +54 -0
- package/esm/listeners/browser.js +1 -1
- package/esm/logger/constants.js +1 -0
- package/esm/logger/messages/info.js +1 -0
- package/esm/sdkClient/client.js +5 -10
- package/esm/sdkClient/clientCS.js +1 -1
- package/esm/sdkClient/clientInputValidation.js +6 -8
- package/esm/sdkClient/sdkClient.js +4 -7
- package/esm/sdkClient/sdkClientMethodCS.js +3 -9
- package/esm/sdkClient/sdkClientMethodCSWithTT.js +3 -13
- package/esm/sdkFactory/index.js +6 -5
- package/esm/storages/inRedis/RedisAdapter.js +9 -2
- package/esm/sync/syncManagerOnline.js +1 -1
- package/esm/trackers/eventTracker.js +8 -1
- package/esm/trackers/impressionObserver/utils.js +7 -1
- package/esm/trackers/impressionsTracker.js +6 -5
- package/esm/utils/inputValidation/attributes.js +1 -1
- package/esm/utils/lang/index.js +4 -2
- package/esm/utils/lang/maps.js +14 -1
- package/esm/utils/settingsValidation/index.js +21 -3
- package/package.json +1 -1
- package/src/{utils/consent.ts → consent/index.ts} +1 -1
- package/src/consent/sdkUserConsent.ts +58 -0
- package/src/evaluator/parser/index.ts +1 -1
- package/src/evaluator/types.ts +2 -2
- package/src/evaluator/value/index.ts +2 -2
- package/src/evaluator/value/sanitize.ts +2 -2
- package/src/integrations/pluggable.ts +2 -2
- package/src/listeners/browser.ts +1 -1
- package/src/logger/constants.ts +1 -0
- package/src/logger/messages/info.ts +1 -0
- package/src/sdkClient/client.ts +7 -9
- package/src/sdkClient/clientCS.ts +1 -1
- package/src/sdkClient/clientInputValidation.ts +8 -7
- package/src/sdkClient/sdkClient.ts +6 -9
- package/src/sdkClient/sdkClientMethod.ts +2 -2
- package/src/sdkClient/sdkClientMethodCS.ts +5 -11
- package/src/sdkClient/sdkClientMethodCSWithTT.ts +6 -16
- package/src/sdkFactory/index.ts +6 -5
- package/src/sdkFactory/types.ts +13 -4
- package/src/storages/inRedis/RedisAdapter.ts +8 -2
- package/src/sync/syncManagerOnline.ts +1 -1
- package/src/trackers/eventTracker.ts +11 -3
- package/src/trackers/impressionObserver/utils.ts +8 -1
- package/src/trackers/impressionsTracker.ts +7 -8
- package/src/types.ts +1 -1
- package/src/utils/inputValidation/attributes.ts +1 -2
- package/src/utils/lang/index.ts +7 -3
- package/src/utils/lang/maps.ts +15 -1
- package/src/utils/settingsValidation/index.ts +21 -3
- package/src/utils/settingsValidation/types.ts +5 -1
- package/types/consent/index.d.ts +2 -0
- package/types/consent/sdkUserConsent.d.ts +13 -0
- package/types/evaluator/types.d.ts +2 -2
- package/types/evaluator/value/index.d.ts +1 -1
- package/types/evaluator/value/sanitize.d.ts +1 -1
- package/types/logger/constants.d.ts +1 -0
- package/types/sdkClient/client.d.ts +2 -2
- package/types/sdkClient/clientInputValidation.d.ts +2 -3
- package/types/sdkClient/sdkClient.d.ts +2 -2
- package/types/sdkClient/sdkClientMethod.d.ts +2 -2
- package/types/sdkClient/sdkClientMethodCS.d.ts +2 -2
- package/types/sdkClient/sdkClientMethodCSWithTT.d.ts +2 -2
- package/types/sdkFactory/types.d.ts +12 -4
- package/types/storages/inRedis/RedisAdapter.d.ts +1 -1
- package/types/trackers/eventTracker.d.ts +2 -2
- package/types/trackers/impressionObserver/utils.d.ts +4 -0
- package/types/trackers/impressionsTracker.d.ts +2 -3
- package/types/types.d.ts +1 -1
- package/types/utils/lang/index.d.ts +2 -1
- package/types/utils/lang/maps.d.ts +7 -0
- package/types/utils/settingsValidation/types.d.ts +5 -1
- package/cjs/sdkClient/types.js +0 -2
- package/cjs/sdkFactory/userConsentProps.js +0 -37
- package/esm/sdkClient/types.js +0 -1
- package/esm/sdkFactory/userConsentProps.js +0 -33
- package/src/sdkClient/types.ts +0 -21
- package/src/sdkFactory/userConsentProps.ts +0 -40
package/CHANGES.txt
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
1.3.0 (April 6, 2022)
|
|
2
|
+
- Added user consent feature to allow delaying or disabling the data tracking from SDK until user consent is explicitly granted or declined. Read more in our docs.
|
|
3
|
+
- Added `scheduler.impressionsQueueSize` property to SDK configuration to limit the amount of impressions tracked in memory. Read more in our docs.
|
|
4
|
+
- Added support to accept TLS configuration options to the Redis storage in NodeJS. Read more in our docs.
|
|
5
|
+
- Updated format for MySegments keys in LocalStorage, keeping backwards compatibility (issue https://github.com/splitio/javascript-client/issues/638).
|
|
6
|
+
- Updated some modules due to general polishing and refactors, including updates in some log messages.
|
|
7
|
+
- Updated some dependencies for vulnerability fixes.
|
|
8
|
+
- Bugfixing - Updated internal isObject utility function, to avoid unexpected behaviors on frameworks and libraries that uses multiple VM contexts, like NuxtJS dev server.
|
|
9
|
+
- Bugfixing - Fixed validation of `core.key` SDK configuration param, to parse it into a string and log a warning when passing a number (Related to issue https://github.com/splitio/react-native-client/issues/19).
|
|
10
|
+
- Bugfixing - Fixed validation of `sync.impressionsMode` SDK configuration param, to avoid an exception on SplitFactory instantiation when passing a non-string value.
|
|
11
|
+
- Bugfixing - Fixed an issue with `connectionTimeout` options params of Redis storage, that was being ignored and not passed down to the underlying ioredis client.
|
|
12
|
+
- Bugfixing - Fixed streaming synchronization issue with multiple clients.
|
|
13
|
+
- Bugfixing - Fixed issue with internal Map ponyfill that results in logger not working properly on IE11 browser.
|
|
14
|
+
|
|
1
15
|
1.2.0 (January 19, 2022)
|
|
2
16
|
- Added support to SDK clients on browser to optionally bind attributes to the client, keeping these loaded within the SDK along with the user ID, for easier usage when requesting flag.
|
|
3
17
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isConsentGranted = void 0;
|
|
4
|
-
var constants_1 = require("
|
|
4
|
+
var constants_1 = require("../utils/constants");
|
|
5
5
|
function isConsentGranted(settings) {
|
|
6
6
|
var userConsent = settings.userConsent;
|
|
7
7
|
// undefined userConsent is handled as granted (default)
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createUserConsentAPI = void 0;
|
|
4
|
+
var constants_1 = require("../logger/constants");
|
|
5
|
+
var index_1 = require("./index");
|
|
6
|
+
var constants_2 = require("../utils/constants");
|
|
7
|
+
var lang_1 = require("../utils/lang");
|
|
8
|
+
// User consent enum
|
|
9
|
+
var ConsentStatus = {
|
|
10
|
+
GRANTED: constants_2.CONSENT_GRANTED,
|
|
11
|
+
DECLINED: constants_2.CONSENT_DECLINED,
|
|
12
|
+
UNKNOWN: constants_2.CONSENT_UNKNOWN,
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* The public user consent API exposed via SplitFactory, used to control if the SDK tracks and sends impressions and events or not.
|
|
16
|
+
*/
|
|
17
|
+
function createUserConsentAPI(params) {
|
|
18
|
+
var settings = params.settings, log = params.settings.log, syncManager = params.syncManager, _a = params.storage, events = _a.events, impressions = _a.impressions, impressionCounts = _a.impressionCounts;
|
|
19
|
+
if (!(0, index_1.isConsentGranted)(settings))
|
|
20
|
+
log.info(constants_1.USER_CONSENT_INITIAL, [settings.userConsent]);
|
|
21
|
+
return {
|
|
22
|
+
setStatus: function (consent) {
|
|
23
|
+
var _a, _b;
|
|
24
|
+
// validate input param
|
|
25
|
+
if (!(0, lang_1.isBoolean)(consent)) {
|
|
26
|
+
log.warn(constants_1.ERROR_NOT_BOOLEAN, ['setUserConsent']);
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
var newConsentStatus = consent ? constants_2.CONSENT_GRANTED : constants_2.CONSENT_DECLINED;
|
|
30
|
+
if (settings.userConsent !== newConsentStatus) {
|
|
31
|
+
log.info(constants_1.USER_CONSENT_UPDATED, [settings.userConsent, newConsentStatus]); // @ts-ignore, modify readonly prop
|
|
32
|
+
settings.userConsent = newConsentStatus;
|
|
33
|
+
if (consent) { // resumes submitters if transitioning to GRANTED
|
|
34
|
+
(_a = syncManager === null || syncManager === void 0 ? void 0 : syncManager.submitter) === null || _a === void 0 ? void 0 : _a.start();
|
|
35
|
+
}
|
|
36
|
+
else { // pauses submitters and drops tracked data if transitioning to DECLINED
|
|
37
|
+
(_b = syncManager === null || syncManager === void 0 ? void 0 : syncManager.submitter) === null || _b === void 0 ? void 0 : _b.stop();
|
|
38
|
+
// @ts-ignore, clear method is present in storage for standalone and partial consumer mode
|
|
39
|
+
if (events.clear)
|
|
40
|
+
events.clear(); // @ts-ignore
|
|
41
|
+
if (impressions.clear)
|
|
42
|
+
impressions.clear();
|
|
43
|
+
if (impressionCounts)
|
|
44
|
+
impressionCounts.clear();
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
log.info(constants_1.USER_CONSENT_NOT_UPDATED, [newConsentStatus]);
|
|
49
|
+
}
|
|
50
|
+
return true;
|
|
51
|
+
},
|
|
52
|
+
getStatus: function () {
|
|
53
|
+
return settings.userConsent;
|
|
54
|
+
},
|
|
55
|
+
Status: ConsentStatus
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
exports.createUserConsentAPI = createUserConsentAPI;
|
package/cjs/listeners/browser.js
CHANGED
|
@@ -6,7 +6,7 @@ var impressionCountsSyncTask_1 = require("../sync/submitters/impressionCountsSyn
|
|
|
6
6
|
var constants_1 = require("../utils/constants");
|
|
7
7
|
var objectAssign_1 = require("../utils/lang/objectAssign");
|
|
8
8
|
var constants_2 = require("../logger/constants");
|
|
9
|
-
var consent_1 = require("../
|
|
9
|
+
var consent_1 = require("../consent");
|
|
10
10
|
// 'unload' event is used instead of 'beforeunload', since 'unload' is not a cancelable event, so no other listeners can stop the event from occurring.
|
|
11
11
|
var UNLOAD_DOM_EVENT = 'unload';
|
|
12
12
|
var EVENT_NAME = 'for unload page event.';
|
package/cjs/logger/constants.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
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.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_WHITELIST = exports.ENGINE_MATCHER_STARTS_WITH = exports.ENGINE_MATCHER_STRING_INVALID = exports.ENGINE_MATCHER_STRING = exports.ENGINE_MATCHER_SEGMENT = exports.ENGINE_MATCHER_PART_OF = exports.ENGINE_MATCHER_LESS = exports.ENGINE_MATCHER_GREATER = exports.ENGINE_MATCHER_ENDS_WITH = exports.ENGINE_MATCHER_EQUAL_TO_SET = exports.ENGINE_MATCHER_EQUAL = exports.ENGINE_MATCHER_DEPENDENCY_PRE = exports.ENGINE_MATCHER_DEPENDENCY = exports.ENGINE_MATCHER_CONTAINS_STRING = exports.ENGINE_MATCHER_CONTAINS_ANY = exports.ENGINE_MATCHER_CONTAINS_ALL = exports.ENGINE_MATCHER_BOOLEAN = exports.ENGINE_MATCHER_BETWEEN = exports.ENGINE_MATCHER_ALL = exports.ENGINE_BUCKET = exports.ENGINE_COMBINER_IFELSEIF_NO_TREATMENT = exports.ENGINE_COMBINER_IFELSEIF = exports.ENGINE_COMBINER_AND = void 0;
|
|
4
|
-
exports.
|
|
5
|
-
exports.LOG_PREFIX_CLEANUP = 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_INSTANTIATION = exports.LOG_PREFIX_SETTINGS = exports.ERROR_NOT_BOOLEAN = exports.ERROR_STORAGE_INVALID = exports.ERROR_LOCALHOST_MODULE_REQUIRED = exports.ERROR_HTTP = 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 = void 0;
|
|
4
|
+
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.STREAMING_PARSING_MY_SEGMENTS_UPDATE_V2 = exports.WARN_API_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 = 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 = void 0;
|
|
5
|
+
exports.LOG_PREFIX_CLEANUP = 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_INSTANTIATION = exports.LOG_PREFIX_SETTINGS = exports.ERROR_NOT_BOOLEAN = exports.ERROR_STORAGE_INVALID = exports.ERROR_LOCALHOST_MODULE_REQUIRED = exports.ERROR_HTTP = 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 = 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.
|
|
@@ -74,6 +74,7 @@ exports.EVENTS_TRACKER_SUCCESS = 120;
|
|
|
74
74
|
exports.IMPRESSIONS_TRACKER_SUCCESS = 121;
|
|
75
75
|
exports.USER_CONSENT_UPDATED = 122;
|
|
76
76
|
exports.USER_CONSENT_NOT_UPDATED = 123;
|
|
77
|
+
exports.USER_CONSENT_INITIAL = 124;
|
|
77
78
|
exports.ENGINE_VALUE_INVALID = 200;
|
|
78
79
|
exports.ENGINE_VALUE_NO_ATTRIBUTES = 201;
|
|
79
80
|
exports.CLIENT_NO_LISTENER = 202;
|
|
@@ -18,6 +18,7 @@ exports.codesInfo = warn_1.codesWarn.concat([
|
|
|
18
18
|
[c.IMPRESSIONS_TRACKER_SUCCESS, c.LOG_PREFIX_IMPRESSIONS_TRACKER + 'Successfully stored %s impression(s).'],
|
|
19
19
|
[c.USER_CONSENT_UPDATED, 'setUserConsent: consent status changed from %s to %s.'],
|
|
20
20
|
[c.USER_CONSENT_NOT_UPDATED, 'setUserConsent: call had no effect because it was the current consent status (%s).'],
|
|
21
|
+
[c.USER_CONSENT_INITIAL, 'Starting the SDK with %s user consent. No data will be sent.'],
|
|
21
22
|
// synchronizer
|
|
22
23
|
[c.POLLING_SMART_PAUSING, c.LOG_PREFIX_SYNC_POLLING + 'Turning segments data polling %s.'],
|
|
23
24
|
[c.POLLING_START, c.LOG_PREFIX_SYNC_POLLING + 'Starting polling'],
|
package/cjs/sdkClient/client.js
CHANGED
|
@@ -21,8 +21,7 @@ function clientFactory(params) {
|
|
|
21
21
|
var wrapUp = function (evaluationResult) {
|
|
22
22
|
var queue = [];
|
|
23
23
|
var treatment = processEvaluation(evaluationResult, splitName, key, attributes, withConfig, "getTreatment" + (withConfig ? 'withConfig' : ''), queue);
|
|
24
|
-
|
|
25
|
-
impressionsTracker.track(queue, attributes);
|
|
24
|
+
impressionsTracker.track(queue, attributes);
|
|
26
25
|
return treatment;
|
|
27
26
|
};
|
|
28
27
|
var evaluation = (0, evaluator_1.evaluateFeature)(log, key, splitName, attributes, storage);
|
|
@@ -39,8 +38,7 @@ function clientFactory(params) {
|
|
|
39
38
|
Object.keys(evaluationResults).forEach(function (splitName) {
|
|
40
39
|
treatments[splitName] = processEvaluation(evaluationResults[splitName], splitName, key, attributes, withConfig, "getTreatments" + (withConfig ? 'withConfig' : ''), queue);
|
|
41
40
|
});
|
|
42
|
-
|
|
43
|
-
impressionsTracker.track(queue, attributes);
|
|
41
|
+
impressionsTracker.track(queue, attributes);
|
|
44
42
|
return treatments;
|
|
45
43
|
};
|
|
46
44
|
var evaluations = (0, evaluator_1.evaluateFeatures)(log, key, splitNames, attributes, storage);
|
|
@@ -94,10 +92,7 @@ function clientFactory(params) {
|
|
|
94
92
|
};
|
|
95
93
|
// This may be async but we only warn, we don't actually care if it is valid or not in terms of queueing the event.
|
|
96
94
|
(0, trafficTypeExistance_1.validateTrafficTypeExistance)(log, readinessManager, storage.splits, mode, trafficTypeName, 'track');
|
|
97
|
-
|
|
98
|
-
return eventTracker.track(eventData, size);
|
|
99
|
-
else
|
|
100
|
-
return false;
|
|
95
|
+
return eventTracker.track(eventData, size);
|
|
101
96
|
}
|
|
102
97
|
return {
|
|
103
98
|
getTreatment: getTreatment,
|
|
@@ -105,7 +100,7 @@ function clientFactory(params) {
|
|
|
105
100
|
getTreatments: getTreatments,
|
|
106
101
|
getTreatmentsWithConfig: getTreatmentsWithConfig,
|
|
107
102
|
track: track,
|
|
108
|
-
|
|
103
|
+
isClientSide: false
|
|
109
104
|
};
|
|
110
105
|
}
|
|
111
106
|
exports.clientFactory = clientFactory;
|
|
@@ -20,7 +20,7 @@ function clientCSDecorator(log, client, key, trafficType) {
|
|
|
20
20
|
getTreatmentsWithConfig: clientCS.getTreatmentsWithConfig.bind(clientCS, key),
|
|
21
21
|
// Key is bound to the `track` method. Same thing happens with trafficType but only if provided
|
|
22
22
|
track: trafficType ? clientCS.track.bind(clientCS, key, trafficType) : clientCS.track.bind(clientCS, key),
|
|
23
|
-
|
|
23
|
+
isClientSide: true
|
|
24
24
|
});
|
|
25
25
|
}
|
|
26
26
|
exports.clientCSDecorator = clientCSDecorator;
|
|
@@ -5,12 +5,14 @@ var objectAssign_1 = require("../utils/lang/objectAssign");
|
|
|
5
5
|
var inputValidation_1 = require("../utils/inputValidation");
|
|
6
6
|
var lang_1 = require("../utils/lang");
|
|
7
7
|
var constants_1 = require("../utils/constants");
|
|
8
|
+
var utils_1 = require("../trackers/impressionObserver/utils");
|
|
8
9
|
/**
|
|
9
10
|
* Decorator that validates the input before actually executing the client methods.
|
|
10
11
|
* We should "guard" the client here, while not polluting the "real" implementation of those methods.
|
|
11
12
|
*/
|
|
12
|
-
function clientInputValidationDecorator(
|
|
13
|
-
|
|
13
|
+
function clientInputValidationDecorator(settings, client, readinessManager) {
|
|
14
|
+
var log = settings.log;
|
|
15
|
+
var isSync = (0, utils_1.isStorageSync)(settings);
|
|
14
16
|
/**
|
|
15
17
|
* Avoid repeating this validations code
|
|
16
18
|
*/
|
|
@@ -30,9 +32,7 @@ function clientInputValidationDecorator(log, client, readinessManager, isStorage
|
|
|
30
32
|
};
|
|
31
33
|
}
|
|
32
34
|
function wrapResult(value) {
|
|
33
|
-
|
|
34
|
-
return value;
|
|
35
|
-
return Promise.resolve(value);
|
|
35
|
+
return isSync ? value : Promise.resolve(value);
|
|
36
36
|
}
|
|
37
37
|
function getTreatment(maybeKey, maybeSplit, maybeAttributes) {
|
|
38
38
|
var params = validateEvaluationParams(maybeKey, maybeSplit, maybeAttributes, 'getTreatment');
|
|
@@ -87,9 +87,7 @@ function clientInputValidationDecorator(log, client, readinessManager, isStorage
|
|
|
87
87
|
return client.track(key, tt, event, eventValue, properties, size);
|
|
88
88
|
}
|
|
89
89
|
else {
|
|
90
|
-
|
|
91
|
-
return false;
|
|
92
|
-
return Promise.resolve(false);
|
|
90
|
+
return isSync ? false : Promise.resolve(false);
|
|
93
91
|
}
|
|
94
92
|
}
|
|
95
93
|
return {
|
|
@@ -2,22 +2,19 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.sdkClientFactory = void 0;
|
|
4
4
|
var objectAssign_1 = require("../utils/lang/objectAssign");
|
|
5
|
-
var constants_1 = require("../utils/constants");
|
|
6
5
|
var apiKey_1 = require("../utils/inputValidation/apiKey");
|
|
7
6
|
var client_1 = require("./client");
|
|
8
7
|
var clientInputValidation_1 = require("./clientInputValidation");
|
|
9
8
|
/**
|
|
10
9
|
* Creates an Sdk client, i.e., a base client with status and destroy interface
|
|
11
10
|
*/
|
|
12
|
-
function sdkClientFactory(params) {
|
|
13
|
-
var sdkReadinessManager = params.sdkReadinessManager, syncManager = params.syncManager, storage = params.storage, signalListener = params.signalListener, settings = params.settings
|
|
11
|
+
function sdkClientFactory(params, isSharedClient) {
|
|
12
|
+
var sdkReadinessManager = params.sdkReadinessManager, syncManager = params.syncManager, storage = params.storage, signalListener = params.signalListener, settings = params.settings;
|
|
14
13
|
return (0, objectAssign_1.objectAssign)(
|
|
15
14
|
// Proto-linkage of the readiness Event Emitter
|
|
16
15
|
Object.create(sdkReadinessManager.sdkStatus),
|
|
17
16
|
// Client API (getTreatment* & track methods)
|
|
18
|
-
(0, clientInputValidation_1.clientInputValidationDecorator)(settings
|
|
19
|
-
// storage is async if and only if mode is consumer or partial consumer
|
|
20
|
-
[constants_1.CONSUMER_MODE, constants_1.CONSUMER_PARTIAL_MODE].indexOf(settings.mode) === -1 ? true : false),
|
|
17
|
+
(0, clientInputValidation_1.clientInputValidationDecorator)(settings, (0, client_1.clientFactory)(params), sdkReadinessManager.readinessManager),
|
|
21
18
|
// Sdk destroy
|
|
22
19
|
{
|
|
23
20
|
destroy: function () {
|
|
@@ -29,7 +26,7 @@ function sdkClientFactory(params) {
|
|
|
29
26
|
sdkReadinessManager.readinessManager.destroy();
|
|
30
27
|
signalListener && signalListener.stop();
|
|
31
28
|
// Release the API Key if it is the main client
|
|
32
|
-
if (!
|
|
29
|
+
if (!isSharedClient)
|
|
33
30
|
(0, apiKey_1.releaseApiKey)(settings.core.authorizationKey);
|
|
34
31
|
// Cleanup storage
|
|
35
32
|
return storage.destroy();
|
|
@@ -19,12 +19,7 @@ var method = 'Client instantiation';
|
|
|
19
19
|
*/
|
|
20
20
|
function sdkClientMethodCSFactory(params) {
|
|
21
21
|
var storage = params.storage, syncManager = params.syncManager, sdkReadinessManager = params.sdkReadinessManager, _a = params.settings, key = _a.core.key, readyTimeout = _a.startup.readyTimeout, log = _a.log;
|
|
22
|
-
|
|
23
|
-
// `false` value is used as binded key of the default client, but trafficType is ignored
|
|
24
|
-
// @TODO handle as a non-recoverable error
|
|
25
|
-
var validKey = (0, key_1.validateKey)(log, key, method);
|
|
26
|
-
var mainClientInstance = (0, clientCS_1.clientCSDecorator)(log, (0, sdkClient_1.sdkClientFactory)(params), // @ts-ignore
|
|
27
|
-
validKey);
|
|
22
|
+
var mainClientInstance = (0, clientCS_1.clientCSDecorator)(log, (0, sdkClient_1.sdkClientFactory)(params), key);
|
|
28
23
|
var parsedDefaultKey = (0, key_2.keyParser)(key);
|
|
29
24
|
var defaultInstanceId = buildInstanceId(parsedDefaultKey);
|
|
30
25
|
// Cache instances created per factory.
|
|
@@ -62,9 +57,8 @@ function sdkClientMethodCSFactory(params) {
|
|
|
62
57
|
sdkReadinessManager: sharedSdkReadiness_1,
|
|
63
58
|
storage: sharedStorage || storage,
|
|
64
59
|
syncManager: sharedSyncManager,
|
|
65
|
-
signalListener: undefined,
|
|
66
|
-
|
|
67
|
-
})), validKey);
|
|
60
|
+
signalListener: undefined, // only the main client "destroy" method stops the signal listener
|
|
61
|
+
}), true), validKey);
|
|
68
62
|
sharedSyncManager && sharedSyncManager.start();
|
|
69
63
|
log.info(constants_1.NEW_SHARED_CLIENT);
|
|
70
64
|
}
|
|
@@ -21,16 +21,7 @@ var method = 'Client instantiation';
|
|
|
21
21
|
*/
|
|
22
22
|
function sdkClientMethodCSFactory(params) {
|
|
23
23
|
var storage = params.storage, syncManager = params.syncManager, sdkReadinessManager = params.sdkReadinessManager, _a = params.settings, _b = _a.core, key = _b.key, trafficType = _b.trafficType, readyTimeout = _a.startup.readyTimeout, log = _a.log;
|
|
24
|
-
|
|
25
|
-
// `false` value is used as binded key/TT of the default client, which leads to several issues.
|
|
26
|
-
// @TODO update when supporting non-recoverable errors
|
|
27
|
-
var validKey = (0, key_1.validateKey)(log, key, method);
|
|
28
|
-
var validTrafficType;
|
|
29
|
-
if (trafficType !== undefined) {
|
|
30
|
-
validTrafficType = (0, trafficType_1.validateTrafficType)(log, trafficType, method);
|
|
31
|
-
}
|
|
32
|
-
var mainClientInstance = (0, clientCS_1.clientCSDecorator)(log, (0, sdkClient_1.sdkClientFactory)(params), // @ts-ignore
|
|
33
|
-
validKey, validTrafficType);
|
|
24
|
+
var mainClientInstance = (0, clientCS_1.clientCSDecorator)(log, (0, sdkClient_1.sdkClientFactory)(params), key, trafficType);
|
|
34
25
|
var parsedDefaultKey = (0, key_2.keyParser)(key);
|
|
35
26
|
var defaultInstanceId = buildInstanceId(parsedDefaultKey, trafficType);
|
|
36
27
|
// Cache instances created per factory.
|
|
@@ -75,9 +66,8 @@ function sdkClientMethodCSFactory(params) {
|
|
|
75
66
|
sdkReadinessManager: sharedSdkReadiness_1,
|
|
76
67
|
storage: sharedStorage || storage,
|
|
77
68
|
syncManager: sharedSyncManager,
|
|
78
|
-
signalListener: undefined,
|
|
79
|
-
|
|
80
|
-
})), validKey, validTrafficType);
|
|
69
|
+
signalListener: undefined, // only the main client "destroy" method stops the signal listener
|
|
70
|
+
}), true), validKey, validTrafficType);
|
|
81
71
|
sharedSyncManager && sharedSyncManager.start();
|
|
82
72
|
log.info(constants_1.NEW_SHARED_CLIENT);
|
|
83
73
|
}
|
package/cjs/sdkFactory/index.js
CHANGED
|
@@ -16,7 +16,7 @@ var objectAssign_1 = require("../utils/lang/objectAssign");
|
|
|
16
16
|
* Modular SDK factory
|
|
17
17
|
*/
|
|
18
18
|
function sdkFactory(params) {
|
|
19
|
-
var settings = params.settings, platform = params.platform, storageFactory = params.storageFactory, splitApiFactory = params.splitApiFactory, extraProps = params.extraProps, syncManagerFactory = params.syncManagerFactory, SignalListener = params.SignalListener, impressionsObserverFactory = params.impressionsObserverFactory,
|
|
19
|
+
var settings = params.settings, platform = params.platform, storageFactory = params.storageFactory, splitApiFactory = params.splitApiFactory, extraProps = params.extraProps, syncManagerFactory = params.syncManagerFactory, SignalListener = params.SignalListener, impressionsObserverFactory = params.impressionsObserverFactory, integrationsManagerFactory = params.integrationsManagerFactory, sdkManagerFactory = params.sdkManagerFactory, sdkClientMethodFactory = params.sdkClientMethodFactory;
|
|
20
20
|
var log = settings.log;
|
|
21
21
|
// @TODO handle non-recoverable errors: not start sync, mark the SDK as destroyed, etc.
|
|
22
22
|
// We will just log and allow for the SDK to end up throwing an SDK_TIMEOUT event for devs to handle.
|
|
@@ -59,12 +59,13 @@ function sdkFactory(params) {
|
|
|
59
59
|
var integrationsManager = integrationsManagerFactory && integrationsManagerFactory({ settings: settings, storage: storage });
|
|
60
60
|
// trackers
|
|
61
61
|
var observer = impressionsObserverFactory && impressionsObserverFactory();
|
|
62
|
-
var impressionsTracker = (0, impressionsTracker_1.impressionsTrackerFactory)(
|
|
63
|
-
var eventTracker = (0, eventTracker_1.eventTrackerFactory)(
|
|
62
|
+
var impressionsTracker = (0, impressionsTracker_1.impressionsTrackerFactory)(settings, storage.impressions, integrationsManager, observer, storage.impressionCounts);
|
|
63
|
+
var eventTracker = (0, eventTracker_1.eventTrackerFactory)(settings, storage.events, integrationsManager);
|
|
64
64
|
// signal listener
|
|
65
65
|
var signalListener = SignalListener && new SignalListener(syncManager, settings, storage, splitApi);
|
|
66
66
|
// Sdk client and manager
|
|
67
|
-
var
|
|
67
|
+
var ctx = { eventTracker: eventTracker, impressionsTracker: impressionsTracker, sdkReadinessManager: sdkReadinessManager, settings: settings, storage: storage, syncManager: syncManager, signalListener: signalListener };
|
|
68
|
+
var clientMethod = sdkClientMethodFactory(ctx);
|
|
68
69
|
var managerInstance = sdkManagerFactory(log, storage.splits, sdkReadinessManager);
|
|
69
70
|
syncManager && syncManager.start();
|
|
70
71
|
signalListener && signalListener.start();
|
|
@@ -81,6 +82,6 @@ function sdkFactory(params) {
|
|
|
81
82
|
// Logger wrapper API
|
|
82
83
|
Logger: (0, sdkLogger_1.createLoggerAPI)(settings.log),
|
|
83
84
|
settings: settings,
|
|
84
|
-
}, extraProps && extraProps(
|
|
85
|
+
}, extraProps && extraProps(ctx));
|
|
85
86
|
}
|
|
86
87
|
exports.sdkFactory = sdkFactory;
|
|
@@ -146,13 +146,19 @@ var RedisAdapter = /** @class */ (function (_super) {
|
|
|
146
146
|
else { // If it IS the string URL, that'll be the first param for ioredis.
|
|
147
147
|
result.unshift(options.url);
|
|
148
148
|
}
|
|
149
|
+
if (options.connectionTimeout) {
|
|
150
|
+
(0, lang_1.merge)(opts, { connectTimeout: options.connectionTimeout });
|
|
151
|
+
}
|
|
152
|
+
if (options.tls) {
|
|
153
|
+
(0, lang_1.merge)(opts, { tls: options.tls });
|
|
154
|
+
}
|
|
149
155
|
return result;
|
|
150
156
|
};
|
|
151
157
|
/**
|
|
152
158
|
* Parses the options into what we care about.
|
|
153
159
|
*/
|
|
154
160
|
RedisAdapter._defineOptions = function (_a) {
|
|
155
|
-
var connectionTimeout = _a.connectionTimeout, operationTimeout = _a.operationTimeout, url = _a.url, host = _a.host, port = _a.port, db = _a.db, pass = _a.pass;
|
|
161
|
+
var connectionTimeout = _a.connectionTimeout, operationTimeout = _a.operationTimeout, url = _a.url, host = _a.host, port = _a.port, db = _a.db, pass = _a.pass, tls = _a.tls;
|
|
156
162
|
var parsedOptions = {
|
|
157
163
|
connectionTimeout: connectionTimeout,
|
|
158
164
|
operationTimeout: operationTimeout,
|
|
@@ -160,7 +166,8 @@ var RedisAdapter = /** @class */ (function (_super) {
|
|
|
160
166
|
host: host,
|
|
161
167
|
port: port,
|
|
162
168
|
db: db,
|
|
163
|
-
pass: pass
|
|
169
|
+
pass: pass,
|
|
170
|
+
tls: tls
|
|
164
171
|
};
|
|
165
172
|
return (0, lang_1.merge)({}, DEFAULT_OPTIONS, parsedOptions);
|
|
166
173
|
};
|
|
@@ -4,7 +4,7 @@ exports.syncManagerOnlineFactory = void 0;
|
|
|
4
4
|
var submitterManager_1 = require("./submitters/submitterManager");
|
|
5
5
|
var constants_1 = require("./streaming/constants");
|
|
6
6
|
var constants_2 = require("../logger/constants");
|
|
7
|
-
var consent_1 = require("../
|
|
7
|
+
var consent_1 = require("../consent");
|
|
8
8
|
/**
|
|
9
9
|
* Online SyncManager factory.
|
|
10
10
|
* Can be used for server-side API, and client-side API with or without multiple clients.
|
|
@@ -4,13 +4,17 @@ exports.eventTrackerFactory = void 0;
|
|
|
4
4
|
var objectAssign_1 = require("../utils/lang/objectAssign");
|
|
5
5
|
var thenable_1 = require("../utils/promise/thenable");
|
|
6
6
|
var constants_1 = require("../logger/constants");
|
|
7
|
+
var constants_2 = require("../utils/constants");
|
|
8
|
+
var utils_1 = require("./impressionObserver/utils");
|
|
7
9
|
/**
|
|
8
10
|
* Event tracker stores events in cache and pass them to the integrations manager if provided.
|
|
9
11
|
*
|
|
10
12
|
* @param eventsCache cache to save events
|
|
11
13
|
* @param integrationsManager optional event handler used for integrations
|
|
12
14
|
*/
|
|
13
|
-
function eventTrackerFactory(
|
|
15
|
+
function eventTrackerFactory(settings, eventsCache, integrationsManager) {
|
|
16
|
+
var log = settings.log;
|
|
17
|
+
var isSync = (0, utils_1.isStorageSync)(settings);
|
|
14
18
|
function queueEventsCallback(eventData, tracked) {
|
|
15
19
|
var eventTypeId = eventData.eventTypeId, trafficTypeName = eventData.trafficTypeName, key = eventData.key, value = eventData.value, timestamp = eventData.timestamp, properties = eventData.properties;
|
|
16
20
|
// Logging every prop would be too much.
|
|
@@ -36,6 +40,9 @@ function eventTrackerFactory(log, eventsCache, integrationsManager) {
|
|
|
36
40
|
}
|
|
37
41
|
return {
|
|
38
42
|
track: function (eventData, size) {
|
|
43
|
+
if (settings.userConsent === constants_2.CONSENT_DECLINED) {
|
|
44
|
+
return isSync ? false : Promise.resolve(false);
|
|
45
|
+
}
|
|
39
46
|
var tracked = eventsCache.track(eventData, size);
|
|
40
47
|
if ((0, thenable_1.thenable)(tracked)) {
|
|
41
48
|
return tracked.then(queueEventsCallback.bind(null, eventData));
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.shouldBeOptimized = exports.shouldAddPt = void 0;
|
|
3
|
+
exports.isStorageSync = exports.shouldBeOptimized = exports.shouldAddPt = void 0;
|
|
4
4
|
var constants_1 = require("../../utils/constants");
|
|
5
5
|
/**
|
|
6
6
|
* Checks if impressions previous time should be added or not.
|
|
@@ -18,3 +18,10 @@ function shouldBeOptimized(settings) {
|
|
|
18
18
|
return settings.sync.impressionsMode === constants_1.OPTIMIZED ? true : false;
|
|
19
19
|
}
|
|
20
20
|
exports.shouldBeOptimized = shouldBeOptimized;
|
|
21
|
+
/**
|
|
22
|
+
* Storage is async if mode is consumer or partial consumer
|
|
23
|
+
*/
|
|
24
|
+
function isStorageSync(settings) {
|
|
25
|
+
return [constants_1.CONSUMER_MODE, constants_1.CONSUMER_PARTIAL_MODE].indexOf(settings.mode) === -1 ? true : false;
|
|
26
|
+
}
|
|
27
|
+
exports.isStorageSync = isStorageSync;
|
|
@@ -5,6 +5,7 @@ var objectAssign_1 = require("../utils/lang/objectAssign");
|
|
|
5
5
|
var thenable_1 = require("../utils/promise/thenable");
|
|
6
6
|
var time_1 = require("../utils/time");
|
|
7
7
|
var constants_1 = require("../logger/constants");
|
|
8
|
+
var constants_2 = require("../utils/constants");
|
|
8
9
|
/**
|
|
9
10
|
* Impressions tracker stores impressions in cache and pass them to the listener and integrations manager if provided.
|
|
10
11
|
*
|
|
@@ -15,16 +16,16 @@ var constants_1 = require("../logger/constants");
|
|
|
15
16
|
* @param observer optional impression observer. If provided, previous time (pt property) is included in impression instances
|
|
16
17
|
* @param countsCache optional cache to save impressions count. If provided, impressions will be deduped (OPTIMIZED mode)
|
|
17
18
|
*/
|
|
18
|
-
function impressionsTrackerFactory(
|
|
19
|
-
// @TODO consider passing only an optional integrationsManager to handle impressions
|
|
20
|
-
_a, impressionListener, integrationsManager,
|
|
19
|
+
function impressionsTrackerFactory(settings, impressionsCache, integrationsManager,
|
|
21
20
|
// if observer is provided, it implies `shouldAddPreviousTime` flag (i.e., if impressions previous time should be added or not)
|
|
22
21
|
observer,
|
|
23
22
|
// if countsCache is provided, it implies `isOptimized` flag (i.e., if impressions should be deduped or not)
|
|
24
23
|
countsCache) {
|
|
25
|
-
var
|
|
24
|
+
var log = settings.log, impressionListener = settings.impressionListener, _a = settings.runtime, ip = _a.ip, hostname = _a.hostname, version = settings.version;
|
|
26
25
|
return {
|
|
27
26
|
track: function (impressions, attributes) {
|
|
27
|
+
if (settings.userConsent === constants_2.CONSENT_DECLINED)
|
|
28
|
+
return;
|
|
28
29
|
var impressionsCount = impressions.length;
|
|
29
30
|
var impressionsToStore = []; // Track only the impressions that are going to be stored
|
|
30
31
|
// Wraps impressions to store and adds previousTime if it corresponds
|
|
@@ -68,7 +69,7 @@ countsCache) {
|
|
|
68
69
|
// integrationsManager.handleImpression does not throw errors
|
|
69
70
|
if (integrationsManager)
|
|
70
71
|
integrationsManager.handleImpression(impressionData);
|
|
71
|
-
try { // An exception on the listeners should not break the SDK.
|
|
72
|
+
try { // @ts-ignore. An exception on the listeners should not break the SDK.
|
|
72
73
|
if (impressionListener)
|
|
73
74
|
impressionListener.logImpression(impressionData);
|
|
74
75
|
}
|
|
@@ -6,7 +6,7 @@ var attribute_1 = require("./attribute");
|
|
|
6
6
|
var constants_1 = require("../../logger/constants");
|
|
7
7
|
function validateAttributes(log, maybeAttrs, method) {
|
|
8
8
|
// Attributes are optional
|
|
9
|
-
if ((0, lang_1.isObject)(maybeAttrs)
|
|
9
|
+
if (maybeAttrs == undefined || (0, lang_1.isObject)(maybeAttrs)) // eslint-disable-line eqeqeq
|
|
10
10
|
return maybeAttrs;
|
|
11
11
|
log.error(constants_1.ERROR_NOT_PLAIN_OBJECT, [method, 'attributes']);
|
|
12
12
|
return false;
|
package/cjs/utils/lang/index.js
CHANGED
|
@@ -154,10 +154,12 @@ function isNaNNumber(val) {
|
|
|
154
154
|
}
|
|
155
155
|
exports.isNaNNumber = isNaNNumber;
|
|
156
156
|
/**
|
|
157
|
-
* Validates if a value is an object
|
|
157
|
+
* Validates if a value is an object created by the Object constructor (plain object).
|
|
158
|
+
* It checks `constructor.name` to avoid false negatives when validating values on a separate VM context, which has its own global built-ins.
|
|
158
159
|
*/
|
|
159
160
|
function isObject(obj) {
|
|
160
|
-
return obj !== null && typeof obj === 'object' && obj.constructor === Object
|
|
161
|
+
return obj !== null && typeof obj === 'object' && (obj.constructor === Object ||
|
|
162
|
+
(obj.constructor != null && obj.constructor.name === 'Object'));
|
|
161
163
|
}
|
|
162
164
|
exports.isObject = isObject;
|
|
163
165
|
/**
|
package/cjs/utils/lang/maps.js
CHANGED
|
@@ -24,7 +24,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
24
24
|
THE SOFTWARE.
|
|
25
25
|
**/
|
|
26
26
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
-
exports._Map = exports.MapPoly = void 0;
|
|
27
|
+
exports._Map = exports.__getMapConstructor = exports.MapPoly = void 0;
|
|
28
28
|
var MapPoly = /** @class */ (function () {
|
|
29
29
|
// unlike ES6 `Map`, it only accepts an array as first argument iterable
|
|
30
30
|
function MapPoly(entries) {
|
|
@@ -71,4 +71,18 @@ var MapPoly = /** @class */ (function () {
|
|
|
71
71
|
return MapPoly;
|
|
72
72
|
}());
|
|
73
73
|
exports.MapPoly = MapPoly;
|
|
74
|
-
|
|
74
|
+
/**
|
|
75
|
+
* return the Map constructor to use. If native Map is not available or it doesn't support the required features (e.g., IE11),
|
|
76
|
+
* a ponyfill with minimal features is returned instead.
|
|
77
|
+
*
|
|
78
|
+
* Exported for testing purposes only.
|
|
79
|
+
*/
|
|
80
|
+
function __getMapConstructor() {
|
|
81
|
+
// eslint-disable-next-line compat/compat
|
|
82
|
+
if (typeof Array.from === 'function' && typeof Map === 'function' && Map.prototype && Map.prototype.values) {
|
|
83
|
+
return Map;
|
|
84
|
+
}
|
|
85
|
+
return MapPoly;
|
|
86
|
+
}
|
|
87
|
+
exports.__getMapConstructor = __getMapConstructor;
|
|
88
|
+
exports._Map = __getMapConstructor();
|
|
@@ -6,6 +6,8 @@ var mode_1 = require("./mode");
|
|
|
6
6
|
var splitFilters_1 = require("./splitFilters");
|
|
7
7
|
var constants_1 = require("../constants");
|
|
8
8
|
var impressionsMode_1 = require("./impressionsMode");
|
|
9
|
+
var key_1 = require("../inputValidation/key");
|
|
10
|
+
var trafficType_1 = require("../inputValidation/trafficType");
|
|
9
11
|
var base = {
|
|
10
12
|
// Define which kind of object you want to retrieve from SplitFactory
|
|
11
13
|
mode: constants_1.STANDALONE_MODE,
|
|
@@ -109,9 +111,25 @@ function settingsValidation(config, validationParams) {
|
|
|
109
111
|
// @ts-ignore, modify readonly prop
|
|
110
112
|
if (storage)
|
|
111
113
|
withDefaults.storage = storage(withDefaults);
|
|
112
|
-
//
|
|
113
|
-
if (
|
|
114
|
-
withDefaults.core.key
|
|
114
|
+
// Validate key and TT (for client-side)
|
|
115
|
+
if (validationParams.acceptKey) {
|
|
116
|
+
var maybeKey = withDefaults.core.key;
|
|
117
|
+
// Although `key` is required in client-side, it can be omitted in LOCALHOST mode. In that case, the value `localhost_key` is used.
|
|
118
|
+
if (withDefaults.mode === constants_1.LOCALHOST_MODE && maybeKey === undefined) {
|
|
119
|
+
withDefaults.core.key = 'localhost_key';
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
// Keeping same behaviour than JS SDK: if settings key or TT are invalid,
|
|
123
|
+
// `false` value is used as binded key/TT of the default client, which leads to some issues.
|
|
124
|
+
// @ts-ignore, @TODO handle invalid keys as a non-recoverable error?
|
|
125
|
+
withDefaults.core.key = (0, key_1.validateKey)(log, maybeKey, 'Client instantiation');
|
|
126
|
+
}
|
|
127
|
+
if (validationParams.acceptTT) {
|
|
128
|
+
var maybeTT = withDefaults.core.trafficType;
|
|
129
|
+
if (maybeTT !== undefined) { // @ts-ignore
|
|
130
|
+
withDefaults.core.trafficType = (0, trafficType_1.validateTrafficType)(log, maybeTT, 'Client instantiation');
|
|
131
|
+
}
|
|
132
|
+
}
|
|
115
133
|
}
|
|
116
134
|
// Current ip/hostname information
|
|
117
135
|
// @ts-ignore, modify readonly prop
|