@splitsoftware/splitio-commons 1.2.1-rc.5 → 1.2.1-rc.8
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/logger/constants.js +3 -2
- package/cjs/logger/messages/debug.js +3 -3
- package/cjs/logger/messages/error.js +2 -2
- package/cjs/logger/messages/info.js +4 -3
- package/cjs/sdkClient/client.js +3 -8
- package/cjs/sdkClient/clientInputValidation.js +6 -8
- package/cjs/sdkClient/sdkClient.js +1 -4
- package/cjs/sdkFactory/index.js +3 -3
- package/cjs/sdkFactory/userConsentProps.js +11 -8
- package/cjs/storages/KeyBuilder.js +1 -5
- package/cjs/sync/streaming/SSEClient/index.js +2 -1
- package/cjs/sync/submitters/eventsSyncTask.js +8 -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/lang/index.js +8 -1
- package/cjs/utils/settingsValidation/consent.js +2 -2
- package/cjs/utils/settingsValidation/impressionsMode.js +2 -2
- package/esm/logger/constants.js +1 -0
- package/esm/logger/messages/debug.js +3 -3
- package/esm/logger/messages/error.js +2 -2
- package/esm/logger/messages/info.js +4 -3
- package/esm/sdkClient/client.js +4 -9
- package/esm/sdkClient/clientInputValidation.js +6 -8
- package/esm/sdkClient/sdkClient.js +1 -4
- package/esm/sdkFactory/index.js +3 -3
- package/esm/sdkFactory/userConsentProps.js +12 -9
- package/esm/storages/KeyBuilder.js +2 -6
- package/esm/sync/streaming/SSEClient/index.js +2 -1
- package/esm/sync/submitters/eventsSyncTask.js +8 -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/lang/index.js +6 -0
- package/esm/utils/settingsValidation/consent.js +2 -2
- package/esm/utils/settingsValidation/impressionsMode.js +2 -2
- package/package.json +1 -1
- package/src/logger/constants.ts +1 -0
- package/src/logger/messages/debug.ts +3 -3
- package/src/logger/messages/error.ts +2 -2
- package/src/logger/messages/info.ts +4 -3
- package/src/sdkClient/client.ts +4 -5
- package/src/sdkClient/clientInputValidation.ts +8 -7
- package/src/sdkClient/sdkClient.ts +2 -5
- package/src/sdkFactory/index.ts +3 -3
- package/src/sdkFactory/types.ts +0 -1
- package/src/sdkFactory/userConsentProps.ts +12 -9
- package/src/storages/KeyBuilder.ts +2 -6
- package/src/sync/streaming/SSEClient/index.ts +2 -1
- package/src/sync/submitters/eventsSyncTask.ts +8 -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/utils/lang/index.ts +8 -1
- package/src/utils/settingsValidation/consent.ts +4 -2
- package/src/utils/settingsValidation/impressionsMode.ts +2 -1
- package/types/logger/constants.d.ts +1 -0
- package/types/sdkClient/clientInputValidation.d.ts +2 -3
- package/types/sdkFactory/types.d.ts +0 -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/utils/lang/index.d.ts +4 -0
- package/types/utils/settingsValidation/consent.d.ts +3 -2
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 = void 0;
|
|
4
|
+
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.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_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 = 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.
|
|
@@ -73,6 +73,7 @@ exports.SYNC_STOP_POLLING = 119;
|
|
|
73
73
|
exports.EVENTS_TRACKER_SUCCESS = 120;
|
|
74
74
|
exports.IMPRESSIONS_TRACKER_SUCCESS = 121;
|
|
75
75
|
exports.USER_CONSENT_UPDATED = 122;
|
|
76
|
+
exports.USER_CONSENT_NOT_UPDATED = 123;
|
|
76
77
|
exports.ENGINE_VALUE_INVALID = 200;
|
|
77
78
|
exports.ENGINE_VALUE_NO_ATTRIBUTES = 201;
|
|
78
79
|
exports.CLIENT_NO_LISTENER = 202;
|
|
@@ -34,9 +34,9 @@ exports.codesDebug = info_1.codesInfo.concat([
|
|
|
34
34
|
// SDK
|
|
35
35
|
[c.CLEANUP_REGISTERING, c.LOG_PREFIX_CLEANUP + 'Registering cleanup handler %s'],
|
|
36
36
|
[c.CLEANUP_DEREGISTERING, c.LOG_PREFIX_CLEANUP + 'Deregistering cleanup handler %s'],
|
|
37
|
-
[c.RETRIEVE_CLIENT_DEFAULT, '
|
|
38
|
-
[c.RETRIEVE_CLIENT_EXISTING, '
|
|
39
|
-
[c.RETRIEVE_MANAGER, '
|
|
37
|
+
[c.RETRIEVE_CLIENT_DEFAULT, 'Retrieving default SDK client.'],
|
|
38
|
+
[c.RETRIEVE_CLIENT_EXISTING, 'Retrieving existing SDK client.'],
|
|
39
|
+
[c.RETRIEVE_MANAGER, 'Retrieving manager instance.'],
|
|
40
40
|
// synchronizer
|
|
41
41
|
[c.SYNC_OFFLINE_DATA, c.LOG_PREFIX_SYNC_OFFLINE + 'Splits data: \n%s'],
|
|
42
42
|
[c.SYNC_SPLITS_FETCH, c.LOG_PREFIX_SYNC_SPLITS + 'Spin up split update using since = %s'],
|
|
@@ -8,7 +8,7 @@ exports.codesError = [
|
|
|
8
8
|
[c.ERROR_ENGINE_COMBINER_IFELSEIF, c.LOG_PREFIX_ENGINE_COMBINER + 'Invalid Split, no valid rules found'],
|
|
9
9
|
// SDK
|
|
10
10
|
[c.ERROR_LOGLEVEL_INVALID, 'logger: Invalid Log Level - No changes to the logs will be applied.'],
|
|
11
|
-
[c.ERROR_CLIENT_CANNOT_GET_READY, '
|
|
11
|
+
[c.ERROR_CLIENT_CANNOT_GET_READY, 'The SDK will not get ready. Reason: %s'],
|
|
12
12
|
[c.ERROR_IMPRESSIONS_TRACKER, c.LOG_PREFIX_IMPRESSIONS_TRACKER + 'Could not store impressions bulk with %s impression(s). Error: %s'],
|
|
13
13
|
[c.ERROR_IMPRESSIONS_LISTENER, c.LOG_PREFIX_IMPRESSIONS_TRACKER + 'Impression listener logImpression method threw: %s.'],
|
|
14
14
|
[c.ERROR_EVENTS_TRACKER, c.LOG_PREFIX_EVENTS_TRACKER + 'Failed to queue %s'],
|
|
@@ -31,7 +31,7 @@ exports.codesError = [
|
|
|
31
31
|
[c.ERROR_INVALID, '%s: you passed an invalid %s. It must be a non-empty string.'],
|
|
32
32
|
[c.ERROR_EMPTY, '%s: you passed an empty %s. It must be a non-empty string.'],
|
|
33
33
|
[c.ERROR_EMPTY_ARRAY, '%s: %s must be a non-empty array.'],
|
|
34
|
-
[c.ERROR_NOT_BOOLEAN, '%s:
|
|
34
|
+
[c.ERROR_NOT_BOOLEAN, '%s: provided param must be a boolean value.'],
|
|
35
35
|
// initialization / settings validation
|
|
36
36
|
[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".'],
|
|
37
37
|
[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.'],
|
|
@@ -12,11 +12,12 @@ exports.codesInfo = warn_1.codesWarn.concat([
|
|
|
12
12
|
// SDK
|
|
13
13
|
[c.IMPRESSION, c.LOG_PREFIX_IMPRESSIONS_TRACKER + 'Split: %s. Key: %s. Evaluation: %s. Label: %s'],
|
|
14
14
|
[c.IMPRESSION_QUEUEING, c.LOG_PREFIX_IMPRESSIONS_TRACKER + 'Queueing corresponding impression.'],
|
|
15
|
-
[c.NEW_SHARED_CLIENT, '
|
|
16
|
-
[c.NEW_FACTORY, '
|
|
15
|
+
[c.NEW_SHARED_CLIENT, 'New shared client instance created.'],
|
|
16
|
+
[c.NEW_FACTORY, 'New Split SDK instance created.'],
|
|
17
17
|
[c.EVENTS_TRACKER_SUCCESS, c.LOG_PREFIX_EVENTS_TRACKER + 'Successfully queued %s'],
|
|
18
18
|
[c.IMPRESSIONS_TRACKER_SUCCESS, c.LOG_PREFIX_IMPRESSIONS_TRACKER + 'Successfully stored %s impression(s).'],
|
|
19
|
-
[c.USER_CONSENT_UPDATED, '
|
|
19
|
+
[c.USER_CONSENT_UPDATED, 'setUserConsent: consent status changed from %s to %s.'],
|
|
20
|
+
[c.USER_CONSENT_NOT_UPDATED, 'setUserConsent: call had no effect because it was the current consent status (%s).'],
|
|
20
21
|
// synchronizer
|
|
21
22
|
[c.POLLING_SMART_PAUSING, c.LOG_PREFIX_SYNC_POLLING + 'Turning segments data polling %s.'],
|
|
22
23
|
[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,
|
|
@@ -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,7 +2,6 @@
|
|
|
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");
|
|
@@ -15,9 +14,7 @@ function sdkClientFactory(params) {
|
|
|
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 () {
|
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,8 +59,8 @@ 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
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.userConsentProps = void 0;
|
|
4
4
|
var constants_1 = require("../logger/constants");
|
|
5
5
|
var constants_2 = require("../utils/constants");
|
|
6
|
+
var lang_1 = require("../utils/lang");
|
|
6
7
|
// Extend client-side factory instances with user consent getter/setter
|
|
7
8
|
function userConsentProps(settings, syncManager) {
|
|
8
9
|
var log = settings.log;
|
|
@@ -10,19 +11,21 @@ function userConsentProps(settings, syncManager) {
|
|
|
10
11
|
setUserConsent: function (consent) {
|
|
11
12
|
var _a, _b;
|
|
12
13
|
// validate input param
|
|
13
|
-
if (
|
|
14
|
-
log.
|
|
14
|
+
if (!(0, lang_1.isBoolean)(consent)) {
|
|
15
|
+
log.warn(constants_1.ERROR_NOT_BOOLEAN, ['setUserConsent']);
|
|
15
16
|
return false;
|
|
16
17
|
}
|
|
17
18
|
var newConsentStatus = consent ? constants_2.CONSENT_GRANTED : constants_2.CONSENT_DECLINED;
|
|
18
|
-
if (settings.userConsent !== newConsentStatus) {
|
|
19
|
-
|
|
19
|
+
if (settings.userConsent !== newConsentStatus) { // @ts-ignore, modify readonly prop
|
|
20
|
+
settings.userConsent = newConsentStatus;
|
|
20
21
|
if (consent)
|
|
21
|
-
(_a = syncManager === null || syncManager === void 0 ? void 0 : syncManager.submitter) === null || _a === void 0 ? void 0 : _a.start();
|
|
22
|
+
(_a = syncManager === null || syncManager === void 0 ? void 0 : syncManager.submitter) === null || _a === void 0 ? void 0 : _a.start(); // resumes submitters if transitioning to GRANTED
|
|
22
23
|
else
|
|
23
|
-
(_b = syncManager === null || syncManager === void 0 ? void 0 : syncManager.submitter) === null || _b === void 0 ? void 0 : _b.stop();
|
|
24
|
-
log.info(constants_1.USER_CONSENT_UPDATED, [settings.userConsent, newConsentStatus]);
|
|
25
|
-
|
|
24
|
+
(_b = syncManager === null || syncManager === void 0 ? void 0 : syncManager.submitter) === null || _b === void 0 ? void 0 : _b.stop(); // pauses submitters if transitioning to DECLINED
|
|
25
|
+
log.info(constants_1.USER_CONSENT_UPDATED, [settings.userConsent, newConsentStatus]);
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
log.info(constants_1.USER_CONSENT_NOT_UPDATED, [newConsentStatus]);
|
|
26
29
|
}
|
|
27
30
|
return true;
|
|
28
31
|
},
|
|
@@ -5,11 +5,7 @@ var lang_1 = require("../utils/lang");
|
|
|
5
5
|
var everythingAtTheEnd = /[^.]+$/;
|
|
6
6
|
var DEFAULT_PREFIX = 'SPLITIO';
|
|
7
7
|
function validatePrefix(prefix) {
|
|
8
|
-
return prefix
|
|
9
|
-
(0, lang_1.endsWith)(prefix, '.' + DEFAULT_PREFIX) ?
|
|
10
|
-
prefix : // suffix already appended
|
|
11
|
-
prefix + '.' + DEFAULT_PREFIX : // append suffix
|
|
12
|
-
DEFAULT_PREFIX; // use default prefix if none is provided
|
|
8
|
+
return prefix ? prefix + '.SPLITIO' : 'SPLITIO';
|
|
13
9
|
}
|
|
14
10
|
exports.validatePrefix = validatePrefix;
|
|
15
11
|
var KeyBuilder = /** @class */ (function () {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SSEClient = void 0;
|
|
4
|
+
var lang_1 = require("../../../utils/lang");
|
|
4
5
|
var VERSION = '1.1';
|
|
5
6
|
var CONTROL_CHANNEL_REGEX = /^control_/;
|
|
6
7
|
/**
|
|
@@ -11,7 +12,7 @@ var CONTROL_CHANNEL_REGEX = /^control_/;
|
|
|
11
12
|
*/
|
|
12
13
|
function buildSSEHeaders(settings) {
|
|
13
14
|
var headers = {
|
|
14
|
-
SplitSDKClientKey: settings.core.authorizationKey.slice(-4),
|
|
15
|
+
SplitSDKClientKey: (0, lang_1.isString)(settings.core.authorizationKey) ? settings.core.authorizationKey.slice(-4) : '',
|
|
15
16
|
SplitSDKVersion: settings.version,
|
|
16
17
|
};
|
|
17
18
|
// ip and hostname are false if IPAddressesEnabled is false
|
|
@@ -10,18 +10,25 @@ var DATA_NAME = 'events';
|
|
|
10
10
|
function eventsSyncTaskFactory(log, postEventsBulk, eventsCache, eventsPushRate, eventsFirstPushWindow, latencyTracker) {
|
|
11
11
|
// don't retry events.
|
|
12
12
|
var syncTask = (0, submitterSyncTask_1.submitterSyncTaskFactory)(log, postEventsBulk, eventsCache, eventsPushRate, DATA_NAME, latencyTracker);
|
|
13
|
-
// Set a timer for the first push of events
|
|
13
|
+
// Set a timer for the first push window of events.
|
|
14
|
+
// Not implemented in the base submitter or sync task, since this feature is only used by the events submitter.
|
|
14
15
|
if (eventsFirstPushWindow > 0) {
|
|
16
|
+
var running_1 = false;
|
|
15
17
|
var stopEventPublisherTimeout_1;
|
|
16
18
|
var originalStart_1 = syncTask.start;
|
|
17
19
|
syncTask.start = function () {
|
|
20
|
+
running_1 = true;
|
|
18
21
|
stopEventPublisherTimeout_1 = setTimeout(originalStart_1, eventsFirstPushWindow);
|
|
19
22
|
};
|
|
20
23
|
var originalStop_1 = syncTask.stop;
|
|
21
24
|
syncTask.stop = function () {
|
|
25
|
+
running_1 = false;
|
|
22
26
|
clearTimeout(stopEventPublisherTimeout_1);
|
|
23
27
|
originalStop_1();
|
|
24
28
|
};
|
|
29
|
+
syncTask.isRunning = function () {
|
|
30
|
+
return running_1;
|
|
31
|
+
};
|
|
25
32
|
}
|
|
26
33
|
// register events submitter to be executed when events cache is full
|
|
27
34
|
eventsCache.setOnFullQueueCb(function () {
|
|
@@ -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
|
}
|
package/cjs/utils/lang/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.uniqueId = exports.uniqAsStrings = exports.uniq = exports.toString = exports.toNumber = exports.startsWith = exports.merge = exports.isString = exports.isObject = exports.isNaNNumber = exports.isIntegerNumber = exports.isFiniteNumber = exports.isBoolean = exports.groupBy = exports.get = exports.forOwn = exports.findIndex = exports.find = exports.endsWith = void 0;
|
|
3
|
+
exports.uniqueId = exports.uniqAsStrings = exports.uniq = exports.toString = exports.toNumber = exports.startsWith = exports.merge = exports.stringToUpperCase = exports.isString = exports.isObject = exports.isNaNNumber = exports.isIntegerNumber = exports.isFiniteNumber = exports.isBoolean = exports.groupBy = exports.get = exports.forOwn = exports.findIndex = exports.find = exports.endsWith = void 0;
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
5
5
|
/**
|
|
6
6
|
* Checks if the target string ends with the sub string.
|
|
@@ -167,6 +167,13 @@ function isString(val) {
|
|
|
167
167
|
return typeof val === 'string' || val instanceof String;
|
|
168
168
|
}
|
|
169
169
|
exports.isString = isString;
|
|
170
|
+
/**
|
|
171
|
+
* String sanitizer. Returns the provided value converted to uppercase if it is a string.
|
|
172
|
+
*/
|
|
173
|
+
function stringToUpperCase(val) {
|
|
174
|
+
return isString(val) ? val.toUpperCase() : val;
|
|
175
|
+
}
|
|
176
|
+
exports.stringToUpperCase = stringToUpperCase;
|
|
170
177
|
/**
|
|
171
178
|
* Deep copy version of Object.assign using recursion.
|
|
172
179
|
* There are some assumptions here. It's for internal use and we don't need verbose errors
|
|
@@ -3,11 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.validateConsent = void 0;
|
|
4
4
|
var constants_1 = require("../../logger/constants");
|
|
5
5
|
var constants_2 = require("../constants");
|
|
6
|
+
var lang_1 = require("../lang");
|
|
6
7
|
var userConsentValues = [constants_2.CONSENT_DECLINED, constants_2.CONSENT_GRANTED, constants_2.CONSENT_UNKNOWN];
|
|
7
8
|
function validateConsent(_a) {
|
|
8
9
|
var userConsent = _a.userConsent, log = _a.log;
|
|
9
|
-
|
|
10
|
-
userConsent = userConsent.toUpperCase();
|
|
10
|
+
userConsent = (0, lang_1.stringToUpperCase)(userConsent);
|
|
11
11
|
if (userConsentValues.indexOf(userConsent) > -1)
|
|
12
12
|
return userConsent;
|
|
13
13
|
log.error(constants_1.ERROR_INVALID_CONFIG_PARAM, ['userConsent', userConsentValues, constants_2.CONSENT_GRANTED]);
|
|
@@ -3,9 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.validImpressionsMode = void 0;
|
|
4
4
|
var constants_1 = require("../../logger/constants");
|
|
5
5
|
var constants_2 = require("../constants");
|
|
6
|
+
var lang_1 = require("../lang");
|
|
6
7
|
function validImpressionsMode(log, impressionsMode) {
|
|
7
|
-
|
|
8
|
-
impressionsMode = impressionsMode.toUpperCase();
|
|
8
|
+
impressionsMode = (0, lang_1.stringToUpperCase)(impressionsMode);
|
|
9
9
|
if ([constants_2.DEBUG, constants_2.OPTIMIZED].indexOf(impressionsMode) > -1)
|
|
10
10
|
return impressionsMode;
|
|
11
11
|
log.error(constants_1.ERROR_INVALID_CONFIG_PARAM, ['impressionsMode', [constants_2.DEBUG, constants_2.OPTIMIZED], constants_2.OPTIMIZED]);
|
package/esm/logger/constants.js
CHANGED
|
@@ -68,6 +68,7 @@ export var SYNC_STOP_POLLING = 119;
|
|
|
68
68
|
export var EVENTS_TRACKER_SUCCESS = 120;
|
|
69
69
|
export var IMPRESSIONS_TRACKER_SUCCESS = 121;
|
|
70
70
|
export var USER_CONSENT_UPDATED = 122;
|
|
71
|
+
export var USER_CONSENT_NOT_UPDATED = 123;
|
|
71
72
|
export var ENGINE_VALUE_INVALID = 200;
|
|
72
73
|
export var ENGINE_VALUE_NO_ATTRIBUTES = 201;
|
|
73
74
|
export var CLIENT_NO_LISTENER = 202;
|
|
@@ -30,9 +30,9 @@ export var codesDebug = codesInfo.concat([
|
|
|
30
30
|
// SDK
|
|
31
31
|
[c.CLEANUP_REGISTERING, c.LOG_PREFIX_CLEANUP + 'Registering cleanup handler %s'],
|
|
32
32
|
[c.CLEANUP_DEREGISTERING, c.LOG_PREFIX_CLEANUP + 'Deregistering cleanup handler %s'],
|
|
33
|
-
[c.RETRIEVE_CLIENT_DEFAULT, '
|
|
34
|
-
[c.RETRIEVE_CLIENT_EXISTING, '
|
|
35
|
-
[c.RETRIEVE_MANAGER, '
|
|
33
|
+
[c.RETRIEVE_CLIENT_DEFAULT, 'Retrieving default SDK client.'],
|
|
34
|
+
[c.RETRIEVE_CLIENT_EXISTING, 'Retrieving existing SDK client.'],
|
|
35
|
+
[c.RETRIEVE_MANAGER, 'Retrieving manager instance.'],
|
|
36
36
|
// synchronizer
|
|
37
37
|
[c.SYNC_OFFLINE_DATA, c.LOG_PREFIX_SYNC_OFFLINE + 'Splits data: \n%s'],
|
|
38
38
|
[c.SYNC_SPLITS_FETCH, c.LOG_PREFIX_SYNC_SPLITS + 'Spin up split update using since = %s'],
|
|
@@ -4,7 +4,7 @@ export var codesError = [
|
|
|
4
4
|
[c.ERROR_ENGINE_COMBINER_IFELSEIF, c.LOG_PREFIX_ENGINE_COMBINER + 'Invalid Split, no valid rules found'],
|
|
5
5
|
// SDK
|
|
6
6
|
[c.ERROR_LOGLEVEL_INVALID, 'logger: Invalid Log Level - No changes to the logs will be applied.'],
|
|
7
|
-
[c.ERROR_CLIENT_CANNOT_GET_READY, '
|
|
7
|
+
[c.ERROR_CLIENT_CANNOT_GET_READY, 'The SDK will not get ready. Reason: %s'],
|
|
8
8
|
[c.ERROR_IMPRESSIONS_TRACKER, c.LOG_PREFIX_IMPRESSIONS_TRACKER + 'Could not store impressions bulk with %s impression(s). Error: %s'],
|
|
9
9
|
[c.ERROR_IMPRESSIONS_LISTENER, c.LOG_PREFIX_IMPRESSIONS_TRACKER + 'Impression listener logImpression method threw: %s.'],
|
|
10
10
|
[c.ERROR_EVENTS_TRACKER, c.LOG_PREFIX_EVENTS_TRACKER + 'Failed to queue %s'],
|
|
@@ -27,7 +27,7 @@ export var codesError = [
|
|
|
27
27
|
[c.ERROR_INVALID, '%s: you passed an invalid %s. It must be a non-empty string.'],
|
|
28
28
|
[c.ERROR_EMPTY, '%s: you passed an empty %s. It must be a non-empty string.'],
|
|
29
29
|
[c.ERROR_EMPTY_ARRAY, '%s: %s must be a non-empty array.'],
|
|
30
|
-
[c.ERROR_NOT_BOOLEAN, '%s:
|
|
30
|
+
[c.ERROR_NOT_BOOLEAN, '%s: provided param must be a boolean value.'],
|
|
31
31
|
// initialization / settings validation
|
|
32
32
|
[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".'],
|
|
33
33
|
[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.'],
|
|
@@ -8,11 +8,12 @@ export var codesInfo = codesWarn.concat([
|
|
|
8
8
|
// SDK
|
|
9
9
|
[c.IMPRESSION, c.LOG_PREFIX_IMPRESSIONS_TRACKER + 'Split: %s. Key: %s. Evaluation: %s. Label: %s'],
|
|
10
10
|
[c.IMPRESSION_QUEUEING, c.LOG_PREFIX_IMPRESSIONS_TRACKER + 'Queueing corresponding impression.'],
|
|
11
|
-
[c.NEW_SHARED_CLIENT, '
|
|
12
|
-
[c.NEW_FACTORY, '
|
|
11
|
+
[c.NEW_SHARED_CLIENT, 'New shared client instance created.'],
|
|
12
|
+
[c.NEW_FACTORY, 'New Split SDK instance created.'],
|
|
13
13
|
[c.EVENTS_TRACKER_SUCCESS, c.LOG_PREFIX_EVENTS_TRACKER + 'Successfully queued %s'],
|
|
14
14
|
[c.IMPRESSIONS_TRACKER_SUCCESS, c.LOG_PREFIX_IMPRESSIONS_TRACKER + 'Successfully stored %s impression(s).'],
|
|
15
|
-
[c.USER_CONSENT_UPDATED, '
|
|
15
|
+
[c.USER_CONSENT_UPDATED, 'setUserConsent: consent status changed from %s to %s.'],
|
|
16
|
+
[c.USER_CONSENT_NOT_UPDATED, 'setUserConsent: call had no effect because it was the current consent status (%s).'],
|
|
16
17
|
// synchronizer
|
|
17
18
|
[c.POLLING_SMART_PAUSING, c.LOG_PREFIX_SYNC_POLLING + 'Turning segments data polling %s.'],
|
|
18
19
|
[c.POLLING_START, c.LOG_PREFIX_SYNC_POLLING + 'Starting polling'],
|
package/esm/sdkClient/client.js
CHANGED
|
@@ -4,7 +4,7 @@ import { getMatching, getBucketing } from '../utils/key';
|
|
|
4
4
|
import { validateSplitExistance } from '../utils/inputValidation/splitExistance';
|
|
5
5
|
import { validateTrafficTypeExistance } from '../utils/inputValidation/trafficTypeExistance';
|
|
6
6
|
import { SDK_NOT_READY } from '../utils/labels';
|
|
7
|
-
import {
|
|
7
|
+
import { CONTROL } from '../utils/constants';
|
|
8
8
|
import { IMPRESSION, IMPRESSION_QUEUEING } from '../logger/constants';
|
|
9
9
|
/**
|
|
10
10
|
* Creator of base client with getTreatments and track methods.
|
|
@@ -18,8 +18,7 @@ export function clientFactory(params) {
|
|
|
18
18
|
var wrapUp = function (evaluationResult) {
|
|
19
19
|
var queue = [];
|
|
20
20
|
var treatment = processEvaluation(evaluationResult, splitName, key, attributes, withConfig, "getTreatment" + (withConfig ? 'withConfig' : ''), queue);
|
|
21
|
-
|
|
22
|
-
impressionsTracker.track(queue, attributes);
|
|
21
|
+
impressionsTracker.track(queue, attributes);
|
|
23
22
|
return treatment;
|
|
24
23
|
};
|
|
25
24
|
var evaluation = evaluateFeature(log, key, splitName, attributes, storage);
|
|
@@ -36,8 +35,7 @@ export function clientFactory(params) {
|
|
|
36
35
|
Object.keys(evaluationResults).forEach(function (splitName) {
|
|
37
36
|
treatments[splitName] = processEvaluation(evaluationResults[splitName], splitName, key, attributes, withConfig, "getTreatments" + (withConfig ? 'withConfig' : ''), queue);
|
|
38
37
|
});
|
|
39
|
-
|
|
40
|
-
impressionsTracker.track(queue, attributes);
|
|
38
|
+
impressionsTracker.track(queue, attributes);
|
|
41
39
|
return treatments;
|
|
42
40
|
};
|
|
43
41
|
var evaluations = evaluateFeatures(log, key, splitNames, attributes, storage);
|
|
@@ -91,10 +89,7 @@ export function clientFactory(params) {
|
|
|
91
89
|
};
|
|
92
90
|
// 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.
|
|
93
91
|
validateTrafficTypeExistance(log, readinessManager, storage.splits, mode, trafficTypeName, 'track');
|
|
94
|
-
|
|
95
|
-
return eventTracker.track(eventData, size);
|
|
96
|
-
else
|
|
97
|
-
return false;
|
|
92
|
+
return eventTracker.track(eventData, size);
|
|
98
93
|
}
|
|
99
94
|
return {
|
|
100
95
|
getTreatment: getTreatment,
|
|
@@ -2,12 +2,14 @@ import { objectAssign } from '../utils/lang/objectAssign';
|
|
|
2
2
|
import { validateAttributes, validateEvent, validateEventValue, validateEventProperties, validateKey, validateSplit, validateSplits, validateTrafficType, validateIfNotDestroyed, validateIfOperational } from '../utils/inputValidation';
|
|
3
3
|
import { startsWith } from '../utils/lang';
|
|
4
4
|
import { CONTROL, CONTROL_WITH_CONFIG } from '../utils/constants';
|
|
5
|
+
import { isStorageSync } from '../trackers/impressionObserver/utils';
|
|
5
6
|
/**
|
|
6
7
|
* Decorator that validates the input before actually executing the client methods.
|
|
7
8
|
* We should "guard" the client here, while not polluting the "real" implementation of those methods.
|
|
8
9
|
*/
|
|
9
|
-
export function clientInputValidationDecorator(
|
|
10
|
-
|
|
10
|
+
export function clientInputValidationDecorator(settings, client, readinessManager) {
|
|
11
|
+
var log = settings.log;
|
|
12
|
+
var isSync = isStorageSync(settings);
|
|
11
13
|
/**
|
|
12
14
|
* Avoid repeating this validations code
|
|
13
15
|
*/
|
|
@@ -27,9 +29,7 @@ export function clientInputValidationDecorator(log, client, readinessManager, is
|
|
|
27
29
|
};
|
|
28
30
|
}
|
|
29
31
|
function wrapResult(value) {
|
|
30
|
-
|
|
31
|
-
return value;
|
|
32
|
-
return Promise.resolve(value);
|
|
32
|
+
return isSync ? value : Promise.resolve(value);
|
|
33
33
|
}
|
|
34
34
|
function getTreatment(maybeKey, maybeSplit, maybeAttributes) {
|
|
35
35
|
var params = validateEvaluationParams(maybeKey, maybeSplit, maybeAttributes, 'getTreatment');
|
|
@@ -84,9 +84,7 @@ export function clientInputValidationDecorator(log, client, readinessManager, is
|
|
|
84
84
|
return client.track(key, tt, event, eventValue, properties, size);
|
|
85
85
|
}
|
|
86
86
|
else {
|
|
87
|
-
|
|
88
|
-
return false;
|
|
89
|
-
return Promise.resolve(false);
|
|
87
|
+
return isSync ? false : Promise.resolve(false);
|
|
90
88
|
}
|
|
91
89
|
}
|
|
92
90
|
return {
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { objectAssign } from '../utils/lang/objectAssign';
|
|
2
|
-
import { CONSUMER_MODE, CONSUMER_PARTIAL_MODE } from '../utils/constants';
|
|
3
2
|
import { releaseApiKey } from '../utils/inputValidation/apiKey';
|
|
4
3
|
import { clientFactory } from './client';
|
|
5
4
|
import { clientInputValidationDecorator } from './clientInputValidation';
|
|
@@ -12,9 +11,7 @@ export function sdkClientFactory(params) {
|
|
|
12
11
|
// Proto-linkage of the readiness Event Emitter
|
|
13
12
|
Object.create(sdkReadinessManager.sdkStatus),
|
|
14
13
|
// Client API (getTreatment* & track methods)
|
|
15
|
-
clientInputValidationDecorator(settings
|
|
16
|
-
// storage is async if and only if mode is consumer or partial consumer
|
|
17
|
-
[CONSUMER_MODE, CONSUMER_PARTIAL_MODE].indexOf(settings.mode) === -1 ? true : false),
|
|
14
|
+
clientInputValidationDecorator(settings, clientFactory(params), sdkReadinessManager.readinessManager),
|
|
18
15
|
// Sdk destroy
|
|
19
16
|
{
|
|
20
17
|
destroy: function () {
|
package/esm/sdkFactory/index.js
CHANGED
|
@@ -13,7 +13,7 @@ import { objectAssign } from '../utils/lang/objectAssign';
|
|
|
13
13
|
* Modular SDK factory
|
|
14
14
|
*/
|
|
15
15
|
export function sdkFactory(params) {
|
|
16
|
-
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,
|
|
16
|
+
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;
|
|
17
17
|
var log = settings.log;
|
|
18
18
|
// @TODO handle non-recoverable errors: not start sync, mark the SDK as destroyed, etc.
|
|
19
19
|
// We will just log and allow for the SDK to end up throwing an SDK_TIMEOUT event for devs to handle.
|
|
@@ -56,8 +56,8 @@ export function sdkFactory(params) {
|
|
|
56
56
|
var integrationsManager = integrationsManagerFactory && integrationsManagerFactory({ settings: settings, storage: storage });
|
|
57
57
|
// trackers
|
|
58
58
|
var observer = impressionsObserverFactory && impressionsObserverFactory();
|
|
59
|
-
var impressionsTracker = impressionsTrackerFactory(
|
|
60
|
-
var eventTracker = eventTrackerFactory(
|
|
59
|
+
var impressionsTracker = impressionsTrackerFactory(settings, storage.impressions, integrationsManager, observer, storage.impressionCounts);
|
|
60
|
+
var eventTracker = eventTrackerFactory(settings, storage.events, integrationsManager);
|
|
61
61
|
// signal listener
|
|
62
62
|
var signalListener = SignalListener && new SignalListener(syncManager, settings, storage, splitApi);
|
|
63
63
|
// Sdk client and manager
|