@splitsoftware/splitio-commons 1.2.1-rc.1 → 1.2.1-rc.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/consent/index.js +10 -0
- package/cjs/consent/sdkUserConsent.js +58 -0
- package/cjs/evaluator/Engine.js +6 -6
- package/cjs/evaluator/combiners/and.js +1 -1
- package/cjs/evaluator/combiners/ifelseif.js +2 -2
- package/cjs/evaluator/condition/engineUtils.js +2 -2
- package/cjs/evaluator/condition/index.js +4 -4
- package/cjs/evaluator/index.js +5 -5
- package/cjs/evaluator/matchers/cont_all.js +1 -1
- package/cjs/evaluator/matchers/cont_any.js +1 -1
- package/cjs/evaluator/matchers/cont_str.js +1 -1
- package/cjs/evaluator/matchers/dependency.js +1 -1
- package/cjs/evaluator/matchers/eq_set.js +1 -1
- package/cjs/evaluator/matchers/ew.js +1 -1
- package/cjs/evaluator/matchers/part_of.js +1 -1
- package/cjs/evaluator/matchers/segment.js +1 -1
- package/cjs/evaluator/matchers/sw.js +1 -1
- package/cjs/evaluator/matchers/whitelist.js +1 -1
- package/cjs/evaluator/matchersTransform/index.js +12 -12
- package/cjs/evaluator/parser/index.js +6 -6
- package/cjs/evaluator/treatments/index.js +1 -1
- package/cjs/evaluator/value/index.js +1 -1
- package/cjs/evaluator/value/sanitize.js +4 -4
- package/cjs/integrations/browser.js +3 -3
- package/cjs/integrations/ga/GaToSplit.js +14 -14
- package/cjs/integrations/ga/GoogleAnalyticsToSplit.js +5 -3
- package/cjs/integrations/ga/SplitToGa.js +1 -1
- package/cjs/integrations/ga/SplitToGoogleAnalytics.js +4 -2
- package/cjs/listeners/browser.js +15 -11
- package/cjs/listeners/node.js +1 -1
- package/cjs/logger/constants.js +9 -3
- package/cjs/logger/index.js +2 -2
- package/cjs/logger/messages/debug.js +4 -4
- package/cjs/logger/messages/error.js +5 -4
- package/cjs/logger/messages/info.js +8 -5
- package/cjs/logger/messages/warn.js +1 -1
- package/cjs/logger/sdkLogger.js +1 -1
- package/cjs/readiness/readinessManager.js +2 -2
- package/cjs/readiness/sdkReadinessManager.js +4 -4
- package/cjs/sdkClient/client.js +12 -11
- package/cjs/sdkClient/clientAttributesDecoration.js +4 -4
- package/cjs/sdkClient/clientCS.js +3 -3
- package/cjs/sdkClient/clientInputValidation.js +20 -22
- package/cjs/sdkClient/sdkClient.js +6 -9
- package/cjs/sdkClient/sdkClientMethod.js +1 -1
- package/cjs/sdkClient/sdkClientMethodCS.js +7 -13
- package/cjs/sdkClient/sdkClientMethodCSWithTT.js +8 -18
- package/cjs/sdkFactory/index.js +16 -13
- package/cjs/sdkManager/index.js +11 -11
- package/cjs/services/splitApi.js +3 -2
- package/cjs/services/splitHttpClient.js +2 -2
- package/cjs/storages/KeyBuilder.js +2 -6
- package/cjs/storages/KeyBuilderCS.js +13 -3
- package/cjs/storages/KeyBuilderSS.js +1 -1
- package/cjs/storages/findLatencyIndex.js +1 -1
- package/cjs/storages/inLocalStorage/MySegmentsCacheInLocal.js +24 -4
- package/cjs/storages/inLocalStorage/SplitsCacheInLocal.js +12 -12
- package/cjs/storages/inLocalStorage/index.js +4 -4
- package/cjs/storages/inMemory/AttributesCacheInMemory.js +1 -1
- package/cjs/storages/inMemory/ImpressionCountsCacheInMemory.js +1 -1
- package/cjs/storages/inMemory/ImpressionsCacheInMemory.js +15 -1
- package/cjs/storages/inMemory/InMemoryStorage.js +1 -1
- package/cjs/storages/inMemory/InMemoryStorageCS.js +1 -1
- package/cjs/storages/inMemory/LatenciesCacheInMemory.js +1 -1
- package/cjs/storages/inMemory/MySegmentsCacheInMemory.js +1 -1
- package/cjs/storages/inMemory/SegmentsCacheInMemory.js +2 -2
- package/cjs/storages/inMemory/SplitsCacheInMemory.js +5 -5
- package/cjs/storages/inRedis/LatenciesCacheInRedis.js +1 -1
- package/cjs/storages/inRedis/RedisAdapter.js +24 -11
- package/cjs/storages/inRedis/SegmentsCacheInRedis.js +1 -1
- package/cjs/storages/inRedis/SplitsCacheInRedis.js +3 -3
- package/cjs/storages/inRedis/index.js +1 -1
- package/cjs/storages/pluggable/SegmentsCachePluggable.js +1 -1
- package/cjs/storages/pluggable/SplitsCachePluggable.js +3 -3
- package/cjs/storages/pluggable/inMemoryWrapper.js +4 -4
- package/cjs/storages/pluggable/index.js +6 -6
- package/cjs/sync/offline/LocalhostFromFile.js +1 -1
- package/cjs/sync/offline/LocalhostFromObject.js +1 -1
- package/cjs/sync/offline/splitsParser/parseCondition.js +1 -1
- package/cjs/sync/offline/splitsParser/splitsParserFromFile.js +13 -13
- package/cjs/sync/offline/splitsParser/splitsParserFromSettings.js +3 -3
- package/cjs/sync/offline/syncManagerOffline.js +1 -1
- package/cjs/sync/offline/syncTasks/fromObjectSyncTask.js +2 -2
- package/cjs/sync/polling/fetchers/segmentChangesFetcher.js +1 -1
- package/cjs/sync/polling/pollingManagerCS.js +6 -6
- package/cjs/sync/polling/pollingManagerSS.js +3 -3
- package/cjs/sync/polling/syncTasks/mySegmentsSyncTask.js +1 -1
- package/cjs/sync/polling/syncTasks/segmentsSyncTask.js +1 -1
- package/cjs/sync/polling/syncTasks/splitsSyncTask.js +1 -1
- package/cjs/sync/polling/updaters/mySegmentsUpdater.js +1 -1
- package/cjs/sync/polling/updaters/segmentChangesUpdater.js +2 -2
- package/cjs/sync/polling/updaters/splitChangesUpdater.js +2 -2
- package/cjs/sync/streaming/AuthClient/index.js +3 -3
- package/cjs/sync/streaming/SSEClient/index.js +2 -1
- package/cjs/sync/streaming/SSEHandler/NotificationParser.js +1 -1
- package/cjs/sync/streaming/SSEHandler/index.js +3 -3
- package/cjs/sync/streaming/mySegmentsV2utils.js +1 -1
- package/cjs/sync/streaming/pushManager.js +24 -17
- package/cjs/sync/submitters/eventsSyncTask.js +17 -5
- package/cjs/sync/submitters/impressionCountsSyncTask.js +1 -1
- package/cjs/sync/submitters/impressionsSyncTask.js +15 -3
- package/cjs/sync/submitters/metricsSyncTask.js +3 -3
- package/cjs/sync/submitters/submitterManager.js +4 -4
- package/cjs/sync/submitters/submitterSyncTask.js +1 -1
- package/cjs/sync/syncManagerOnline.js +12 -8
- package/cjs/trackers/eventTracker.js +11 -4
- package/cjs/trackers/impressionObserver/impressionObserverCS.js +1 -1
- package/cjs/trackers/impressionObserver/impressionObserverSS.js +1 -1
- package/cjs/trackers/impressionObserver/utils.js +8 -1
- package/cjs/trackers/impressionsTracker.js +9 -8
- package/cjs/utils/MinEvents.js +2 -1
- package/cjs/utils/constants/index.js +5 -1
- package/cjs/utils/inputValidation/apiKey.js +1 -1
- package/cjs/utils/inputValidation/attribute.js +4 -4
- package/cjs/utils/inputValidation/attributes.js +2 -2
- package/cjs/utils/inputValidation/event.js +1 -1
- package/cjs/utils/inputValidation/eventProperties.js +5 -5
- package/cjs/utils/inputValidation/eventValue.js +1 -1
- package/cjs/utils/inputValidation/key.js +6 -5
- package/cjs/utils/inputValidation/preloadedData.js +8 -8
- package/cjs/utils/inputValidation/split.js +1 -1
- package/cjs/utils/inputValidation/splits.js +2 -2
- package/cjs/utils/inputValidation/trafficType.js +1 -1
- package/cjs/utils/inputValidation/trafficTypeExistance.js +1 -1
- package/cjs/utils/jwt/index.js +1 -1
- package/cjs/utils/key/index.js +3 -3
- package/cjs/utils/lang/index.js +13 -4
- package/cjs/utils/lang/maps.js +16 -2
- package/cjs/utils/murmur3/common.js +1 -1
- package/cjs/utils/murmur3/murmur3.js +10 -10
- package/cjs/utils/murmur3/murmur3_128.js +1 -1
- package/cjs/utils/murmur3/murmur3_128_x86.js +37 -37
- package/cjs/utils/murmur3/murmur3_64.js +1 -1
- package/cjs/utils/settingsValidation/consent.js +16 -0
- package/cjs/utils/settingsValidation/impressionsMode.js +6 -6
- package/cjs/utils/settingsValidation/index.js +32 -14
- package/cjs/utils/settingsValidation/integrations/configurable.js +1 -1
- package/cjs/utils/settingsValidation/integrations/pluggable.js +1 -1
- package/cjs/utils/settingsValidation/localhost/builtin.js +2 -2
- package/cjs/utils/settingsValidation/logger/builtinLogger.js +3 -3
- package/cjs/utils/settingsValidation/logger/commons.js +1 -1
- package/cjs/utils/settingsValidation/logger/pluggableLogger.js +1 -1
- package/cjs/utils/settingsValidation/runtime.js +11 -0
- package/cjs/utils/settingsValidation/splitFilters.js +1 -1
- package/cjs/utils/settingsValidation/storage/storageCS.js +1 -1
- package/cjs/utils/timeTracker/index.js +3 -3
- package/esm/consent/index.js +6 -0
- package/esm/consent/sdkUserConsent.js +54 -0
- package/esm/integrations/ga/GoogleAnalyticsToSplit.js +4 -2
- package/esm/integrations/ga/SplitToGoogleAnalytics.js +4 -2
- package/esm/listeners/browser.js +14 -10
- package/esm/logger/constants.js +6 -2
- package/esm/logger/messages/debug.js +3 -3
- package/esm/logger/messages/error.js +4 -3
- package/esm/logger/messages/info.js +7 -4
- package/esm/sdkClient/client.js +3 -2
- 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 +10 -7
- package/esm/services/splitApi.js +2 -1
- package/esm/storages/KeyBuilder.js +2 -6
- package/esm/storages/KeyBuilderCS.js +11 -1
- package/esm/storages/inLocalStorage/MySegmentsCacheInLocal.js +23 -3
- package/esm/storages/inLocalStorage/index.js +1 -1
- package/esm/storages/inMemory/ImpressionsCacheInMemory.js +15 -1
- package/esm/storages/inMemory/InMemoryStorage.js +1 -1
- package/esm/storages/inMemory/InMemoryStorageCS.js +1 -1
- package/esm/storages/inRedis/RedisAdapter.js +15 -2
- package/esm/storages/pluggable/index.js +2 -2
- package/esm/sync/offline/splitsParser/splitsParserFromFile.js +1 -1
- package/esm/sync/polling/fetchers/segmentChangesFetcher.js +2 -2
- package/esm/sync/streaming/SSEClient/index.js +2 -1
- package/esm/sync/streaming/pushManager.js +9 -2
- package/esm/sync/submitters/eventsSyncTask.js +18 -6
- package/esm/sync/submitters/impressionsSyncTask.js +13 -1
- package/esm/sync/syncManagerOnline.js +11 -7
- 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/constants/index.js +4 -0
- package/esm/utils/inputValidation/attributes.js +1 -1
- package/esm/utils/inputValidation/key.js +2 -1
- package/esm/utils/lang/index.js +12 -4
- package/esm/utils/lang/maps.js +14 -1
- package/esm/utils/settingsValidation/consent.js +12 -0
- package/esm/utils/settingsValidation/impressionsMode.js +7 -7
- package/esm/utils/settingsValidation/index.js +28 -10
- package/esm/utils/settingsValidation/runtime.js +7 -0
- package/package.json +8 -8
- package/src/consent/index.ts +8 -0
- 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/ga/GoogleAnalyticsToSplit.ts +7 -4
- package/src/integrations/ga/SplitToGoogleAnalytics.ts +7 -4
- package/src/integrations/pluggable.ts +2 -2
- package/src/integrations/types.ts +5 -0
- package/src/listeners/browser.ts +13 -9
- package/src/logger/constants.ts +6 -2
- package/src/logger/messages/debug.ts +3 -3
- package/src/logger/messages/error.ts +4 -3
- package/src/logger/messages/info.ts +7 -4
- package/src/logger/types.ts +4 -0
- package/src/sdkClient/client.ts +5 -5
- 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 +11 -8
- package/src/sdkFactory/types.ts +14 -3
- package/src/storages/KeyBuilder.ts +2 -6
- package/src/storages/KeyBuilderCS.ts +13 -1
- package/src/storages/inLocalStorage/MySegmentsCacheInLocal.ts +23 -3
- package/src/storages/inLocalStorage/index.ts +1 -1
- package/src/storages/inMemory/ImpressionsCacheInMemory.ts +22 -1
- package/src/storages/inMemory/InMemoryStorage.ts +1 -1
- package/src/storages/inMemory/InMemoryStorageCS.ts +1 -1
- package/src/storages/inRedis/RedisAdapter.ts +8 -2
- package/src/storages/pluggable/index.ts +2 -2
- package/src/storages/types.ts +6 -2
- package/src/sync/offline/splitsParser/splitsParserFromFile.ts +1 -1
- package/src/sync/streaming/SSEClient/index.ts +2 -1
- package/src/sync/streaming/pushManager.ts +11 -2
- package/src/sync/submitters/eventsSyncTask.ts +19 -6
- package/src/sync/submitters/impressionsSyncTask.ts +16 -1
- package/src/sync/syncManagerOnline.ts +13 -7
- package/src/sync/types.ts +4 -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 +22 -1
- package/src/utils/constants/index.ts +5 -0
- package/src/utils/inputValidation/attributes.ts +1 -2
- package/src/utils/lang/index.ts +15 -4
- package/src/utils/lang/maps.ts +15 -1
- package/src/utils/settingsValidation/consent.ts +16 -0
- package/src/utils/settingsValidation/impressionsMode.ts +8 -8
- package/src/utils/settingsValidation/index.ts +29 -10
- package/src/utils/settingsValidation/runtime.ts +9 -0
- package/src/utils/settingsValidation/types.ts +12 -6
- 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/integrations/ga/GoogleAnalyticsToSplit.d.ts +2 -2
- package/types/integrations/ga/SplitToGoogleAnalytics.d.ts +2 -3
- package/types/integrations/types.d.ts +4 -0
- package/types/logger/constants.d.ts +6 -2
- package/types/logger/types.d.ts +4 -0
- package/types/sdkClient/client.d.ts +2 -2
- package/types/sdkClient/clientAttributesDecoration.d.ts +1 -1
- 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 -3
- package/types/sdkFactory/userConsentProps.d.ts +6 -0
- package/types/storages/KeyBuilderCS.d.ts +2 -0
- package/types/storages/inMemory/ImpressionsCacheInMemory.d.ts +9 -0
- package/types/storages/inRedis/RedisAdapter.d.ts +1 -1
- package/types/storages/types.d.ts +3 -1
- package/types/sync/types.d.ts +3 -0
- 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 +22 -1
- package/types/utils/consent.d.ts +2 -0
- package/types/utils/constants/index.d.ts +3 -0
- package/types/utils/lang/index.d.ts +6 -1
- package/types/utils/lang/maps.d.ts +7 -0
- package/types/utils/settingsValidation/consent.d.ts +6 -0
- package/types/utils/settingsValidation/impressionsMode.d.ts +1 -1
- package/types/utils/settingsValidation/runtime/browser.d.ts +2 -0
- package/types/utils/settingsValidation/runtime/node.d.ts +2 -0
- package/types/utils/settingsValidation/runtime.d.ts +2 -0
- package/types/utils/settingsValidation/types.d.ts +12 -6
- package/types/utils/settingsValidation/userConsent.d.ts +5 -0
- package/cjs/sdkClient/types.js +0 -2
- package/esm/sdkClient/types.js +0 -1
- package/src/sdkClient/types.ts +0 -21
package/esm/utils/lang/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { __spreadArray } from "tslib";
|
|
2
2
|
/**
|
|
3
3
|
* Checks if the target string ends with the sub string.
|
|
4
4
|
*/
|
|
@@ -141,10 +141,12 @@ export function isNaNNumber(val) {
|
|
|
141
141
|
return val !== val;
|
|
142
142
|
}
|
|
143
143
|
/**
|
|
144
|
-
* Validates if a value is an object
|
|
144
|
+
* Validates if a value is an object created by the Object constructor (plain object).
|
|
145
|
+
* It checks `constructor.name` to avoid false negatives when validating values on a separate VM context, which has its own global built-ins.
|
|
145
146
|
*/
|
|
146
147
|
export function isObject(obj) {
|
|
147
|
-
return obj !== null && typeof obj === 'object' && obj.constructor === Object
|
|
148
|
+
return obj !== null && typeof obj === 'object' && (obj.constructor === Object ||
|
|
149
|
+
(obj.constructor != null && obj.constructor.name === 'Object'));
|
|
148
150
|
}
|
|
149
151
|
/**
|
|
150
152
|
* Checks if a given value is a string.
|
|
@@ -152,6 +154,12 @@ export function isObject(obj) {
|
|
|
152
154
|
export function isString(val) {
|
|
153
155
|
return typeof val === 'string' || val instanceof String;
|
|
154
156
|
}
|
|
157
|
+
/**
|
|
158
|
+
* String sanitizer. Returns the provided value converted to uppercase if it is a string.
|
|
159
|
+
*/
|
|
160
|
+
export function stringToUpperCase(val) {
|
|
161
|
+
return isString(val) ? val.toUpperCase() : val;
|
|
162
|
+
}
|
|
155
163
|
/**
|
|
156
164
|
* Deep copy version of Object.assign using recursion.
|
|
157
165
|
* There are some assumptions here. It's for internal use and we don't need verbose errors
|
|
@@ -179,7 +187,7 @@ export function merge(target, source) {
|
|
|
179
187
|
});
|
|
180
188
|
if (rest && rest.length) {
|
|
181
189
|
var nextSource = rest.splice(0, 1)[0];
|
|
182
|
-
res = merge.apply(void 0,
|
|
190
|
+
res = merge.apply(void 0, __spreadArray([res, nextSource], rest, false));
|
|
183
191
|
}
|
|
184
192
|
return res;
|
|
185
193
|
}
|
package/esm/utils/lang/maps.js
CHANGED
|
@@ -68,4 +68,17 @@ var MapPoly = /** @class */ (function () {
|
|
|
68
68
|
return MapPoly;
|
|
69
69
|
}());
|
|
70
70
|
export { MapPoly };
|
|
71
|
-
|
|
71
|
+
/**
|
|
72
|
+
* return the Map constructor to use. If native Map is not available or it doesn't support the required features (e.g., IE11),
|
|
73
|
+
* a ponyfill with minimal features is returned instead.
|
|
74
|
+
*
|
|
75
|
+
* Exported for testing purposes only.
|
|
76
|
+
*/
|
|
77
|
+
export function __getMapConstructor() {
|
|
78
|
+
// eslint-disable-next-line compat/compat
|
|
79
|
+
if (typeof Array.from === 'function' && typeof Map === 'function' && Map.prototype && Map.prototype.values) {
|
|
80
|
+
return Map;
|
|
81
|
+
}
|
|
82
|
+
return MapPoly;
|
|
83
|
+
}
|
|
84
|
+
export var _Map = __getMapConstructor();
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ERROR_INVALID_CONFIG_PARAM } from '../../logger/constants';
|
|
2
|
+
import { CONSENT_DECLINED, CONSENT_GRANTED, CONSENT_UNKNOWN } from '../constants';
|
|
3
|
+
import { stringToUpperCase } from '../lang';
|
|
4
|
+
var userConsentValues = [CONSENT_DECLINED, CONSENT_GRANTED, CONSENT_UNKNOWN];
|
|
5
|
+
export function validateConsent(_a) {
|
|
6
|
+
var userConsent = _a.userConsent, log = _a.log;
|
|
7
|
+
userConsent = stringToUpperCase(userConsent);
|
|
8
|
+
if (userConsentValues.indexOf(userConsent) > -1)
|
|
9
|
+
return userConsent;
|
|
10
|
+
log.error(ERROR_INVALID_CONFIG_PARAM, ['userConsent', userConsentValues, CONSENT_GRANTED]);
|
|
11
|
+
return CONSENT_GRANTED;
|
|
12
|
+
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ERROR_INVALID_CONFIG_PARAM } from '../../logger/constants';
|
|
2
2
|
import { DEBUG, OPTIMIZED } from '../constants';
|
|
3
|
+
import { stringToUpperCase } from '../lang';
|
|
3
4
|
export function validImpressionsMode(log, impressionsMode) {
|
|
4
|
-
impressionsMode = impressionsMode
|
|
5
|
-
if ([DEBUG, OPTIMIZED].indexOf(impressionsMode)
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
return impressionsMode;
|
|
5
|
+
impressionsMode = stringToUpperCase(impressionsMode);
|
|
6
|
+
if ([DEBUG, OPTIMIZED].indexOf(impressionsMode) > -1)
|
|
7
|
+
return impressionsMode;
|
|
8
|
+
log.error(ERROR_INVALID_CONFIG_PARAM, ['impressionsMode', [DEBUG, OPTIMIZED], OPTIMIZED]);
|
|
9
|
+
return OPTIMIZED;
|
|
10
10
|
}
|
|
@@ -3,6 +3,8 @@ import { mode } from './mode';
|
|
|
3
3
|
import { validateSplitFilters } from './splitFilters';
|
|
4
4
|
import { STANDALONE_MODE, OPTIMIZED, LOCALHOST_MODE } from '../constants';
|
|
5
5
|
import { validImpressionsMode } from './impressionsMode';
|
|
6
|
+
import { validateKey } from '../inputValidation/key';
|
|
7
|
+
import { validateTrafficType } from '../inputValidation/trafficType';
|
|
6
8
|
var base = {
|
|
7
9
|
// Define which kind of object you want to retrieve from SplitFactory
|
|
8
10
|
mode: STANDALONE_MODE,
|
|
@@ -33,6 +35,8 @@ var base = {
|
|
|
33
35
|
eventsPushRate: 60,
|
|
34
36
|
// how many events will be queued before flushing
|
|
35
37
|
eventsQueueSize: 500,
|
|
38
|
+
// how many impressions will be queued before flushing
|
|
39
|
+
impressionsQueueSize: 30000,
|
|
36
40
|
// backoff base seconds to wait before re attempting to connect to push notifications
|
|
37
41
|
pushRetryBackoffBase: 1,
|
|
38
42
|
},
|
|
@@ -64,10 +68,6 @@ var base = {
|
|
|
64
68
|
impressionsMode: OPTIMIZED,
|
|
65
69
|
localhostMode: undefined
|
|
66
70
|
},
|
|
67
|
-
runtime: {
|
|
68
|
-
ip: false,
|
|
69
|
-
hostname: false
|
|
70
|
-
},
|
|
71
71
|
// Logger
|
|
72
72
|
log: undefined
|
|
73
73
|
};
|
|
@@ -82,7 +82,7 @@ function fromSecondsToMillis(n) {
|
|
|
82
82
|
* @param validationParams defaults and fields validators used to validate and creates a settings object from a given config
|
|
83
83
|
*/
|
|
84
84
|
export function settingsValidation(config, validationParams) {
|
|
85
|
-
var defaults = validationParams.defaults, runtime = validationParams.runtime, storage = validationParams.storage, integrations = validationParams.integrations, logger = validationParams.logger, localhost = validationParams.localhost;
|
|
85
|
+
var defaults = validationParams.defaults, runtime = validationParams.runtime, storage = validationParams.storage, integrations = validationParams.integrations, logger = validationParams.logger, localhost = validationParams.localhost, consent = validationParams.consent;
|
|
86
86
|
// creates a settings object merging base, defaults and config objects.
|
|
87
87
|
var withDefaults = merge({}, base, defaults, config);
|
|
88
88
|
// ensure a valid logger.
|
|
@@ -108,14 +108,29 @@ export function settingsValidation(config, validationParams) {
|
|
|
108
108
|
// @ts-ignore, modify readonly prop
|
|
109
109
|
if (storage)
|
|
110
110
|
withDefaults.storage = storage(withDefaults);
|
|
111
|
-
//
|
|
112
|
-
if (
|
|
113
|
-
withDefaults.core.key
|
|
111
|
+
// Validate key and TT (for client-side)
|
|
112
|
+
if (validationParams.acceptKey) {
|
|
113
|
+
var maybeKey = withDefaults.core.key;
|
|
114
|
+
// Although `key` is required in client-side, it can be omitted in LOCALHOST mode. In that case, the value `localhost_key` is used.
|
|
115
|
+
if (withDefaults.mode === LOCALHOST_MODE && maybeKey === undefined) {
|
|
116
|
+
withDefaults.core.key = 'localhost_key';
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
// Keeping same behaviour than JS SDK: if settings key or TT are invalid,
|
|
120
|
+
// `false` value is used as binded key/TT of the default client, which leads to some issues.
|
|
121
|
+
// @ts-ignore, @TODO handle invalid keys as a non-recoverable error?
|
|
122
|
+
withDefaults.core.key = validateKey(log, maybeKey, 'Client instantiation');
|
|
123
|
+
}
|
|
124
|
+
if (validationParams.acceptTT) {
|
|
125
|
+
var maybeTT = withDefaults.core.trafficType;
|
|
126
|
+
if (maybeTT !== undefined) { // @ts-ignore
|
|
127
|
+
withDefaults.core.trafficType = validateTrafficType(log, maybeTT, 'Client instantiation');
|
|
128
|
+
}
|
|
129
|
+
}
|
|
114
130
|
}
|
|
115
131
|
// Current ip/hostname information
|
|
116
132
|
// @ts-ignore, modify readonly prop
|
|
117
|
-
|
|
118
|
-
withDefaults.runtime = runtime(withDefaults);
|
|
133
|
+
withDefaults.runtime = runtime(withDefaults);
|
|
119
134
|
// ensure a valid list of integrations.
|
|
120
135
|
// `integrations` returns an array of valid integration items.
|
|
121
136
|
// @ts-ignore, modify readonly prop
|
|
@@ -136,5 +151,8 @@ export function settingsValidation(config, validationParams) {
|
|
|
136
151
|
withDefaults.sync.__splitFiltersValidation = splitFiltersValidation;
|
|
137
152
|
// ensure a valid impressionsMode
|
|
138
153
|
withDefaults.sync.impressionsMode = validImpressionsMode(log, withDefaults.sync.impressionsMode);
|
|
154
|
+
// ensure a valid user consent value
|
|
155
|
+
// @ts-ignore, modify readonly prop
|
|
156
|
+
withDefaults.userConsent = consent(withDefaults);
|
|
139
157
|
return withDefaults;
|
|
140
158
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@splitsoftware/splitio-commons",
|
|
3
|
-
"version": "1.2.1-rc.
|
|
3
|
+
"version": "1.2.1-rc.12",
|
|
4
4
|
"description": "Split Javascript SDK common components",
|
|
5
5
|
"main": "cjs/index.js",
|
|
6
6
|
"module": "esm/index.js",
|
|
@@ -20,12 +20,12 @@
|
|
|
20
20
|
"check:lint": "eslint src --ext .js,.ts",
|
|
21
21
|
"check:types": "tsc --noEmit",
|
|
22
22
|
"build": "npm run build:cjs && npm run build:esm",
|
|
23
|
-
"build:esm": "rimraf esm && tsc -m es2015 --outDir esm -d true --declarationDir types
|
|
24
|
-
"build:cjs": "rimraf cjs && tsc -m CommonJS --outDir cjs
|
|
23
|
+
"build:esm": "rimraf esm && tsc -m es2015 --outDir esm -d true --declarationDir types",
|
|
24
|
+
"build:cjs": "rimraf cjs && tsc -m CommonJS --outDir cjs",
|
|
25
25
|
"test": "jest",
|
|
26
26
|
"test:coverage": "jest --coverage",
|
|
27
|
-
"publish:rc": "npm run check && npm run
|
|
28
|
-
"publish:stable": "npm run check && npm run
|
|
27
|
+
"publish:rc": "npm run check && npm run test && npm run build && npm publish --tag rc",
|
|
28
|
+
"publish:stable": "npm run check && npm run test && npm run build && npm publish"
|
|
29
29
|
},
|
|
30
30
|
"repository": {
|
|
31
31
|
"type": "git",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"bugs": "https://github.com/splitio/javascript-commons/issues",
|
|
45
45
|
"homepage": "https://github.com/splitio/javascript-commons#readme",
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"tslib": "^2.1
|
|
47
|
+
"tslib": "^2.3.1"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
50
|
"@types/google.analytics": "0.0.40",
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
"eslint": "^7.32.0",
|
|
59
59
|
"eslint-plugin-compat": "3.7.0",
|
|
60
60
|
"eslint-plugin-import": "^2.25.3",
|
|
61
|
-
"fetch-mock": "^9.
|
|
61
|
+
"fetch-mock": "^9.11.0",
|
|
62
62
|
"ioredis": "^4.28.0",
|
|
63
63
|
"jest": "^27.2.3",
|
|
64
64
|
"jest-localstorage-mock": "^2.4.3",
|
|
@@ -68,7 +68,7 @@
|
|
|
68
68
|
"redis-server": "1.2.2",
|
|
69
69
|
"rimraf": "^3.0.2",
|
|
70
70
|
"ts-jest": "^27.0.5",
|
|
71
|
-
"typescript": "
|
|
71
|
+
"typescript": "4.4.4"
|
|
72
72
|
},
|
|
73
73
|
"sideEffects": false
|
|
74
74
|
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ISettings } from '../types';
|
|
2
|
+
import { CONSENT_GRANTED } from '../utils/constants';
|
|
3
|
+
|
|
4
|
+
export function isConsentGranted(settings: ISettings) {
|
|
5
|
+
const userConsent = settings.userConsent;
|
|
6
|
+
// undefined userConsent is handled as granted (default)
|
|
7
|
+
return !userConsent || userConsent === CONSENT_GRANTED;
|
|
8
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { ERROR_NOT_BOOLEAN, USER_CONSENT_UPDATED, USER_CONSENT_NOT_UPDATED, USER_CONSENT_INITIAL } from '../logger/constants';
|
|
2
|
+
import { isConsentGranted } from './index';
|
|
3
|
+
import { CONSENT_GRANTED, CONSENT_DECLINED, CONSENT_UNKNOWN } from '../utils/constants';
|
|
4
|
+
import { isBoolean } from '../utils/lang';
|
|
5
|
+
import { ISdkFactoryContext } from '../sdkFactory/types';
|
|
6
|
+
|
|
7
|
+
// User consent enum
|
|
8
|
+
const ConsentStatus = {
|
|
9
|
+
GRANTED: CONSENT_GRANTED,
|
|
10
|
+
DECLINED: CONSENT_DECLINED,
|
|
11
|
+
UNKNOWN: CONSENT_UNKNOWN,
|
|
12
|
+
};
|
|
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
|
+
export function createUserConsentAPI(params: ISdkFactoryContext) {
|
|
18
|
+
const { settings, settings: { log }, syncManager, storage: { events, impressions, impressionCounts } } = params;
|
|
19
|
+
|
|
20
|
+
if (!isConsentGranted(settings)) log.info(USER_CONSENT_INITIAL, [settings.userConsent]);
|
|
21
|
+
|
|
22
|
+
return {
|
|
23
|
+
setStatus(consent: unknown) {
|
|
24
|
+
// validate input param
|
|
25
|
+
if (!isBoolean(consent)) {
|
|
26
|
+
log.warn(ERROR_NOT_BOOLEAN, ['setUserConsent']);
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const newConsentStatus = consent ? CONSENT_GRANTED : CONSENT_DECLINED;
|
|
31
|
+
|
|
32
|
+
if (settings.userConsent !== newConsentStatus) {
|
|
33
|
+
log.info(USER_CONSENT_UPDATED, [settings.userConsent, newConsentStatus]); // @ts-ignore, modify readonly prop
|
|
34
|
+
settings.userConsent = newConsentStatus;
|
|
35
|
+
|
|
36
|
+
if (consent) { // resumes submitters if transitioning to GRANTED
|
|
37
|
+
syncManager?.submitter?.start();
|
|
38
|
+
} else { // pauses submitters and drops tracked data if transitioning to DECLINED
|
|
39
|
+
syncManager?.submitter?.stop();
|
|
40
|
+
// @ts-ignore, clear method is present in storage for standalone and partial consumer mode
|
|
41
|
+
if (events.clear) events.clear(); // @ts-ignore
|
|
42
|
+
if (impressions.clear) impressions.clear();
|
|
43
|
+
if (impressionCounts) impressionCounts.clear();
|
|
44
|
+
}
|
|
45
|
+
} else {
|
|
46
|
+
log.info(USER_CONSENT_NOT_UPDATED, [newConsentStatus]);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return true;
|
|
50
|
+
},
|
|
51
|
+
|
|
52
|
+
getStatus() {
|
|
53
|
+
return settings.userConsent;
|
|
54
|
+
},
|
|
55
|
+
|
|
56
|
+
Status: ConsentStatus
|
|
57
|
+
};
|
|
58
|
+
}
|
|
@@ -31,7 +31,7 @@ export function parser(log: ILogger, conditions: ISplitCondition[], storage: ISt
|
|
|
31
31
|
const matcher = matcherFactory(log, matcherDto, storage);
|
|
32
32
|
|
|
33
33
|
// Evaluator function.
|
|
34
|
-
return (key: string, attributes: SplitIO.Attributes, splitEvaluator: ISplitEvaluator) => {
|
|
34
|
+
return (key: string, attributes: SplitIO.Attributes | undefined, splitEvaluator: ISplitEvaluator) => {
|
|
35
35
|
const value = sanitizeValue(log, key, matcherDto, attributes);
|
|
36
36
|
const result = value !== undefined && matcher ? matcher(value, splitEvaluator) : false;
|
|
37
37
|
|
package/src/evaluator/types.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { ILogger } from '../logger/types';
|
|
|
6
6
|
|
|
7
7
|
export interface IDependencyMatcherValue {
|
|
8
8
|
key: SplitIO.SplitKey,
|
|
9
|
-
attributes
|
|
9
|
+
attributes?: SplitIO.Attributes
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
export interface IMatcherDto {
|
|
@@ -27,7 +27,7 @@ export interface IEvaluation {
|
|
|
27
27
|
|
|
28
28
|
export type IEvaluationResult = IEvaluation & { treatment: string }
|
|
29
29
|
|
|
30
|
-
export type ISplitEvaluator = (log: ILogger, key: SplitIO.SplitKey, splitName: string, attributes: SplitIO.Attributes, storage: IStorageSync | IStorageAsync) => MaybeThenable<IEvaluation>
|
|
30
|
+
export type ISplitEvaluator = (log: ILogger, key: SplitIO.SplitKey, splitName: string, attributes: SplitIO.Attributes | undefined, storage: IStorageSync | IStorageAsync) => MaybeThenable<IEvaluation>
|
|
31
31
|
|
|
32
32
|
export type IEvaluator = (key: SplitIO.SplitKey, seed: number, trafficAllocation?: number, trafficAllocationSeed?: number, attributes?: SplitIO.Attributes, splitEvaluator?: ISplitEvaluator) => MaybeThenable<IEvaluation | undefined>
|
|
33
33
|
|
|
@@ -4,7 +4,7 @@ import { ILogger } from '../../logger/types';
|
|
|
4
4
|
import { sanitize } from './sanitize';
|
|
5
5
|
import { ENGINE_VALUE, ENGINE_VALUE_NO_ATTRIBUTES, ENGINE_VALUE_INVALID } from '../../logger/constants';
|
|
6
6
|
|
|
7
|
-
function parseValue(log: ILogger, key: string, attributeName: string | null, attributes
|
|
7
|
+
function parseValue(log: ILogger, key: string, attributeName: string | null, attributes?: SplitIO.Attributes) {
|
|
8
8
|
let value = undefined;
|
|
9
9
|
if (attributeName) {
|
|
10
10
|
if (attributes) {
|
|
@@ -23,7 +23,7 @@ function parseValue(log: ILogger, key: string, attributeName: string | null, att
|
|
|
23
23
|
/**
|
|
24
24
|
* Defines value to be matched (key / attribute).
|
|
25
25
|
*/
|
|
26
|
-
export function sanitizeValue(log: ILogger, key: string, matcherDto: IMatcherDto, attributes
|
|
26
|
+
export function sanitizeValue(log: ILogger, key: string, matcherDto: IMatcherDto, attributes?: SplitIO.Attributes) {
|
|
27
27
|
const attributeName = matcherDto.attribute;
|
|
28
28
|
const valueToMatch = parseValue(log, key, attributeName, attributes);
|
|
29
29
|
const sanitizedValue = sanitize(log, matcherDto.type, valueToMatch, matcherDto.dataType, attributes);
|
|
@@ -41,7 +41,7 @@ function sanitizeBoolean(val: any): boolean | undefined {
|
|
|
41
41
|
return undefined;
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
function dependencyProcessor(sanitizedValue: string, attributes
|
|
44
|
+
function dependencyProcessor(sanitizedValue: string, attributes?: SplitIO.Attributes): IDependencyMatcherValue {
|
|
45
45
|
return {
|
|
46
46
|
key: sanitizedValue,
|
|
47
47
|
attributes
|
|
@@ -69,7 +69,7 @@ function getProcessingFunction(matcherTypeID: number, dataType: string) {
|
|
|
69
69
|
/**
|
|
70
70
|
* Sanitize matcher value
|
|
71
71
|
*/
|
|
72
|
-
export function sanitize(log: ILogger, matcherTypeID: number, value: string | number | boolean | Array<string | number> | undefined, dataType: string, attributes
|
|
72
|
+
export function sanitize(log: ILogger, matcherTypeID: number, value: string | number | boolean | Array<string | number> | undefined, dataType: string, attributes?: SplitIO.Attributes) {
|
|
73
73
|
const processor = getProcessingFunction(matcherTypeID, dataType);
|
|
74
74
|
let sanitizedValue: string | number | boolean | Array<string | number> | IDependencyMatcherValue | undefined;
|
|
75
75
|
|
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
import { IIntegrationFactoryParams } from '../types';
|
|
1
|
+
import { IIntegrationFactoryParams, IntegrationFactory } from '../types';
|
|
2
2
|
import { GaToSplit } from './GaToSplit';
|
|
3
3
|
import { GoogleAnalyticsToSplitOptions } from './types';
|
|
4
4
|
|
|
5
|
-
export function GoogleAnalyticsToSplit(options: GoogleAnalyticsToSplitOptions) {
|
|
5
|
+
export function GoogleAnalyticsToSplit(options: GoogleAnalyticsToSplitOptions): IntegrationFactory {
|
|
6
6
|
|
|
7
7
|
// GaToSplit integration factory
|
|
8
|
-
|
|
8
|
+
function GoogleAnalyticsToSplitFactory(params: IIntegrationFactoryParams) {
|
|
9
9
|
return GaToSplit(options, params);
|
|
10
|
-
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
GoogleAnalyticsToSplitFactory.type = 'GOOGLE_ANALYTICS_TO_SPLIT';
|
|
13
|
+
return GoogleAnalyticsToSplitFactory;
|
|
11
14
|
}
|
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
import { IIntegrationFactoryParams } from '../types';
|
|
1
|
+
import { IIntegrationFactoryParams, IntegrationFactory } from '../types';
|
|
2
2
|
import { SplitToGa } from './SplitToGa';
|
|
3
3
|
import { SplitToGoogleAnalyticsOptions } from './types';
|
|
4
4
|
|
|
5
|
-
export function SplitToGoogleAnalytics(options: SplitToGoogleAnalyticsOptions = {}) {
|
|
5
|
+
export function SplitToGoogleAnalytics(options: SplitToGoogleAnalyticsOptions = {}): IntegrationFactory {
|
|
6
6
|
|
|
7
7
|
// SplitToGa integration factory
|
|
8
|
-
|
|
8
|
+
function SplitToGoogleAnalyticsFactory(params: IIntegrationFactoryParams) {
|
|
9
9
|
return new SplitToGa(params.settings.log, options);
|
|
10
|
-
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
SplitToGoogleAnalyticsFactory.type = 'SPLIT_TO_GOOGLE_ANALYTICS';
|
|
13
|
+
return SplitToGoogleAnalyticsFactory;
|
|
11
14
|
}
|
|
@@ -29,10 +29,10 @@ export function pluggableIntegrationsManagerFactory(
|
|
|
29
29
|
|
|
30
30
|
// Exception safe methods: each integration module is responsable for handling errors
|
|
31
31
|
return {
|
|
32
|
-
handleImpression
|
|
32
|
+
handleImpression(impressionData: SplitIO.ImpressionData) {
|
|
33
33
|
listeners.forEach(listener => listener.queue({ type: SPLIT_IMPRESSION, payload: impressionData }));
|
|
34
34
|
},
|
|
35
|
-
handleEvent
|
|
35
|
+
handleEvent(eventData: SplitIO.EventData) {
|
|
36
36
|
listeners.forEach(listener => listener.queue({ type: SPLIT_EVENT, payload: eventData }));
|
|
37
37
|
}
|
|
38
38
|
};
|
package/src/listeners/browser.ts
CHANGED
|
@@ -11,6 +11,7 @@ import { OPTIMIZED, DEBUG } from '../utils/constants';
|
|
|
11
11
|
import { objectAssign } from '../utils/lang/objectAssign';
|
|
12
12
|
import { CLEANUP_REGISTERING, CLEANUP_DEREGISTERING } from '../logger/constants';
|
|
13
13
|
import { ISyncManager } from '../sync/types';
|
|
14
|
+
import { isConsentGranted } from '../consent';
|
|
14
15
|
|
|
15
16
|
// 'unload' event is used instead of 'beforeunload', since 'unload' is not a cancelable event, so no other listeners can stop the event from occurring.
|
|
16
17
|
const UNLOAD_DOM_EVENT = 'unload';
|
|
@@ -65,15 +66,18 @@ export class BrowserSignalListener implements ISignalListener {
|
|
|
65
66
|
flushData() {
|
|
66
67
|
if (!this.syncManager) return; // In consumer mode there is not sync manager and data to flush
|
|
67
68
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
69
|
+
// Flush data if there is user consent
|
|
70
|
+
if (isConsentGranted(this.settings)) {
|
|
71
|
+
const eventsUrl = this.settings.urls.events;
|
|
72
|
+
const extraMetadata = {
|
|
73
|
+
// sim stands for Sync/Split Impressions Mode
|
|
74
|
+
sim: this.settings.sync.impressionsMode === OPTIMIZED ? OPTIMIZED : DEBUG
|
|
75
|
+
};
|
|
73
76
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
+
this._flushData(eventsUrl + '/testImpressions/beacon', this.storage.impressions, this.serviceApi.postTestImpressionsBulk, this.fromImpressionsCollector, extraMetadata);
|
|
78
|
+
this._flushData(eventsUrl + '/events/beacon', this.storage.events, this.serviceApi.postEventsBulk);
|
|
79
|
+
if (this.storage.impressionCounts) this._flushData(eventsUrl + '/testImpressions/count/beacon', this.storage.impressionCounts, this.serviceApi.postTestImpressionsCount, fromImpressionCountsCollector);
|
|
80
|
+
}
|
|
77
81
|
|
|
78
82
|
// Close streaming connection
|
|
79
83
|
if (this.syncManager.pushManager) this.syncManager.pushManager.stop();
|
|
@@ -84,7 +88,7 @@ export class BrowserSignalListener implements ISignalListener {
|
|
|
84
88
|
if (!cache.isEmpty()) {
|
|
85
89
|
const dataPayload = fromCacheToPayload ? fromCacheToPayload(cache.state()) : cache.state();
|
|
86
90
|
if (!this._sendBeacon(url, dataPayload, extraMetadata)) {
|
|
87
|
-
postService(JSON.stringify(dataPayload)).catch(() => { }); // no-op just to catch a possible
|
|
91
|
+
postService(JSON.stringify(dataPayload)).catch(() => { }); // no-op just to catch a possible exception
|
|
88
92
|
}
|
|
89
93
|
cache.clear();
|
|
90
94
|
}
|
package/src/logger/constants.ts
CHANGED
|
@@ -61,13 +61,16 @@ export const STREAMING_RECONNECT = 111;
|
|
|
61
61
|
export const STREAMING_CONNECTING = 112;
|
|
62
62
|
export const STREAMING_DISABLED = 113;
|
|
63
63
|
export const STREAMING_DISCONNECTING = 114;
|
|
64
|
-
export const
|
|
64
|
+
export const SUBMITTERS_PUSH_FULL_QUEUE = 115;
|
|
65
65
|
export const SUBMITTERS_PUSH = 116;
|
|
66
66
|
export const SYNC_START_POLLING = 117;
|
|
67
67
|
export const SYNC_CONTINUE_POLLING = 118;
|
|
68
68
|
export const SYNC_STOP_POLLING = 119;
|
|
69
69
|
export const EVENTS_TRACKER_SUCCESS = 120;
|
|
70
70
|
export const IMPRESSIONS_TRACKER_SUCCESS = 121;
|
|
71
|
+
export const USER_CONSENT_UPDATED = 122;
|
|
72
|
+
export const USER_CONSENT_NOT_UPDATED = 123;
|
|
73
|
+
export const USER_CONSENT_INITIAL = 124;
|
|
71
74
|
|
|
72
75
|
export const ENGINE_VALUE_INVALID = 200;
|
|
73
76
|
export const ENGINE_VALUE_NO_ATTRIBUTES = 201;
|
|
@@ -115,10 +118,11 @@ export const ERROR_INVALID_KEY_OBJECT = 317;
|
|
|
115
118
|
export const ERROR_INVALID = 318;
|
|
116
119
|
export const ERROR_EMPTY = 319;
|
|
117
120
|
export const ERROR_EMPTY_ARRAY = 320;
|
|
118
|
-
export const
|
|
121
|
+
export const ERROR_INVALID_CONFIG_PARAM = 321;
|
|
119
122
|
export const ERROR_HTTP = 322;
|
|
120
123
|
export const ERROR_LOCALHOST_MODULE_REQUIRED = 323;
|
|
121
124
|
export const ERROR_STORAGE_INVALID = 324;
|
|
125
|
+
export const ERROR_NOT_BOOLEAN = 325;
|
|
122
126
|
|
|
123
127
|
// Log prefixes (a.k.a. tags or categories)
|
|
124
128
|
export const LOG_PREFIX_SETTINGS = 'settings';
|
|
@@ -31,9 +31,9 @@ export const codesDebug: [number, string][] = codesInfo.concat([
|
|
|
31
31
|
// SDK
|
|
32
32
|
[c.CLEANUP_REGISTERING, c.LOG_PREFIX_CLEANUP + 'Registering cleanup handler %s'],
|
|
33
33
|
[c.CLEANUP_DEREGISTERING, c.LOG_PREFIX_CLEANUP + 'Deregistering cleanup handler %s'],
|
|
34
|
-
[c.RETRIEVE_CLIENT_DEFAULT, '
|
|
35
|
-
[c.RETRIEVE_CLIENT_EXISTING, '
|
|
36
|
-
[c.RETRIEVE_MANAGER, '
|
|
34
|
+
[c.RETRIEVE_CLIENT_DEFAULT, 'Retrieving default SDK client.'],
|
|
35
|
+
[c.RETRIEVE_CLIENT_EXISTING, 'Retrieving existing SDK client.'],
|
|
36
|
+
[c.RETRIEVE_MANAGER, 'Retrieving manager instance.'],
|
|
37
37
|
// synchronizer
|
|
38
38
|
[c.SYNC_OFFLINE_DATA, c.LOG_PREFIX_SYNC_OFFLINE + 'Splits data: \n%s'],
|
|
39
39
|
[c.SYNC_SPLITS_FETCH, c.LOG_PREFIX_SYNC_SPLITS + 'Spin up split update using since = %s'],
|
|
@@ -5,7 +5,7 @@ export const codesError: [number, string][] = [
|
|
|
5
5
|
[c.ERROR_ENGINE_COMBINER_IFELSEIF, c.LOG_PREFIX_ENGINE_COMBINER + 'Invalid Split, no valid rules found'],
|
|
6
6
|
// SDK
|
|
7
7
|
[c.ERROR_LOGLEVEL_INVALID, 'logger: Invalid Log Level - No changes to the logs will be applied.'],
|
|
8
|
-
[c.ERROR_CLIENT_CANNOT_GET_READY, '
|
|
8
|
+
[c.ERROR_CLIENT_CANNOT_GET_READY, 'The SDK will not get ready. Reason: %s'],
|
|
9
9
|
[c.ERROR_IMPRESSIONS_TRACKER, c.LOG_PREFIX_IMPRESSIONS_TRACKER + 'Could not store impressions bulk with %s impression(s). Error: %s'],
|
|
10
10
|
[c.ERROR_IMPRESSIONS_LISTENER, c.LOG_PREFIX_IMPRESSIONS_TRACKER + 'Impression listener logImpression method threw: %s.'],
|
|
11
11
|
[c.ERROR_EVENTS_TRACKER, c.LOG_PREFIX_EVENTS_TRACKER + 'Failed to queue %s'],
|
|
@@ -13,7 +13,7 @@ export const codesError: [number, string][] = [
|
|
|
13
13
|
[c.ERROR_SYNC_OFFLINE_LOADING, c.LOG_PREFIX_SYNC_OFFLINE + 'There was an issue loading the mock Splits data, no changes will be applied to the current cache. %s'],
|
|
14
14
|
[c.ERROR_STREAMING_SSE, c.LOG_PREFIX_SYNC_STREAMING + 'Failed to connect or error on streaming connection, with error message: %s'],
|
|
15
15
|
[c.ERROR_STREAMING_AUTH, c.LOG_PREFIX_SYNC_STREAMING + 'Failed to authenticate for streaming. Error: %s.'],
|
|
16
|
-
[c.ERROR_HTTP, '
|
|
16
|
+
[c.ERROR_HTTP, 'Response status is not OK. Status: %s. URL: %s. Message: %s'],
|
|
17
17
|
// client status
|
|
18
18
|
[c.ERROR_CLIENT_LISTENER, 'A listener was added for %s on the SDK, which has already fired and won\'t be emitted again. The callback won\'t be executed.'],
|
|
19
19
|
[c.ERROR_CLIENT_DESTROYED, '%s: Client has already been destroyed - no calls possible.'],
|
|
@@ -28,8 +28,9 @@ export const codesError: [number, string][] = [
|
|
|
28
28
|
[c.ERROR_INVALID, '%s: you passed an invalid %s. It must be a non-empty string.'],
|
|
29
29
|
[c.ERROR_EMPTY, '%s: you passed an empty %s. It must be a non-empty string.'],
|
|
30
30
|
[c.ERROR_EMPTY_ARRAY, '%s: %s must be a non-empty array.'],
|
|
31
|
+
[c.ERROR_NOT_BOOLEAN, '%s: provided param must be a boolean value.'],
|
|
31
32
|
// initialization / settings validation
|
|
32
|
-
[c.
|
|
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".'],
|
|
33
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.'],
|
|
34
35
|
[c.ERROR_STORAGE_INVALID, c.LOG_PREFIX_SETTINGS+': The provided storage is invalid.%s Fallbacking into default MEMORY storage'],
|
|
35
36
|
];
|
|
@@ -10,17 +10,20 @@ export const codesInfo: [number, string][] = codesWarn.concat([
|
|
|
10
10
|
// SDK
|
|
11
11
|
[c.IMPRESSION, c.LOG_PREFIX_IMPRESSIONS_TRACKER +'Split: %s. Key: %s. Evaluation: %s. Label: %s'],
|
|
12
12
|
[c.IMPRESSION_QUEUEING, c.LOG_PREFIX_IMPRESSIONS_TRACKER +'Queueing corresponding impression.'],
|
|
13
|
-
[c.NEW_SHARED_CLIENT, '
|
|
14
|
-
[c.NEW_FACTORY, '
|
|
13
|
+
[c.NEW_SHARED_CLIENT, 'New shared client instance created.'],
|
|
14
|
+
[c.NEW_FACTORY, 'New Split SDK instance created.'],
|
|
15
15
|
[c.EVENTS_TRACKER_SUCCESS, c.LOG_PREFIX_EVENTS_TRACKER + 'Successfully queued %s'],
|
|
16
16
|
[c.IMPRESSIONS_TRACKER_SUCCESS, c.LOG_PREFIX_IMPRESSIONS_TRACKER + 'Successfully stored %s impression(s).'],
|
|
17
|
+
[c.USER_CONSENT_UPDATED, 'setUserConsent: consent status changed from %s to %s.'],
|
|
18
|
+
[c.USER_CONSENT_NOT_UPDATED, 'setUserConsent: call had no effect because it was the current consent status (%s).'],
|
|
19
|
+
[c.USER_CONSENT_INITIAL, 'Starting the SDK with %s user consent. No data will be sent.'],
|
|
17
20
|
|
|
18
21
|
// synchronizer
|
|
19
22
|
[c.POLLING_SMART_PAUSING, c.LOG_PREFIX_SYNC_POLLING + 'Turning segments data polling %s.'],
|
|
20
23
|
[c.POLLING_START, c.LOG_PREFIX_SYNC_POLLING + 'Starting polling'],
|
|
21
24
|
[c.POLLING_STOP, c.LOG_PREFIX_SYNC_POLLING + 'Stopping polling'],
|
|
22
25
|
[c.SYNC_SPLITS_FETCH_RETRY, c.LOG_PREFIX_SYNC_SPLITS + 'Retrying download of splits #%s. Reason: %s'],
|
|
23
|
-
[c.
|
|
26
|
+
[c.SUBMITTERS_PUSH_FULL_QUEUE, c.LOG_PREFIX_SYNC_SUBMITTERS + 'Flushing full %s queue and reseting timer.'],
|
|
24
27
|
[c.SUBMITTERS_PUSH, c.LOG_PREFIX_SYNC_SUBMITTERS + 'Pushing %s %s.'],
|
|
25
28
|
[c.STREAMING_REFRESH_TOKEN, c.LOG_PREFIX_SYNC_STREAMING + 'Refreshing streaming token in %s seconds, and connecting streaming in %s seconds.'],
|
|
26
29
|
[c.STREAMING_RECONNECT, c.LOG_PREFIX_SYNC_STREAMING + 'Attempting to reconnect streaming in %s seconds.'],
|
|
@@ -29,5 +32,5 @@ export const codesInfo: [number, string][] = codesWarn.concat([
|
|
|
29
32
|
[c.STREAMING_DISCONNECTING, c.LOG_PREFIX_SYNC_STREAMING + 'Disconnecting streaming.'],
|
|
30
33
|
[c.SYNC_START_POLLING, c.LOG_PREFIX_SYNC_MANAGER + 'Streaming not available. Starting polling.'],
|
|
31
34
|
[c.SYNC_CONTINUE_POLLING, c.LOG_PREFIX_SYNC_MANAGER + 'Streaming couldn\'t connect. Continue polling.'],
|
|
32
|
-
[c.SYNC_STOP_POLLING, c.LOG_PREFIX_SYNC_MANAGER + 'Streaming
|
|
35
|
+
[c.SYNC_STOP_POLLING, c.LOG_PREFIX_SYNC_MANAGER + 'Streaming connected. Syncing and stopping polling.'],
|
|
33
36
|
]);
|
package/src/logger/types.ts
CHANGED
|
@@ -9,11 +9,15 @@ export interface ILoggerOptions {
|
|
|
9
9
|
export interface ILogger {
|
|
10
10
|
setLogLevel(logLevel: LogLevel): void
|
|
11
11
|
|
|
12
|
+
debug(msg: any): void
|
|
12
13
|
debug(msg: string | number, args?: any[]): void
|
|
13
14
|
|
|
15
|
+
info(msg: any): void
|
|
14
16
|
info(msg: string | number, args?: any[]): void
|
|
15
17
|
|
|
18
|
+
warn(msg: any): void
|
|
16
19
|
warn(msg: string | number, args?: any[]): void
|
|
17
20
|
|
|
21
|
+
error(msg: any): void
|
|
18
22
|
error(msg: string | number, args?: any[]): void
|
|
19
23
|
}
|
package/src/sdkClient/client.ts
CHANGED
|
@@ -5,18 +5,18 @@ import { validateSplitExistance } from '../utils/inputValidation/splitExistance'
|
|
|
5
5
|
import { validateTrafficTypeExistance } from '../utils/inputValidation/trafficTypeExistance';
|
|
6
6
|
import { SDK_NOT_READY } from '../utils/labels';
|
|
7
7
|
import { CONTROL } from '../utils/constants';
|
|
8
|
-
import { IClientFactoryParams } from './types';
|
|
9
8
|
import { IEvaluationResult } from '../evaluator/types';
|
|
10
9
|
import { SplitIO, ImpressionDTO } from '../types';
|
|
11
10
|
import { IMPRESSION, IMPRESSION_QUEUEING } from '../logger/constants';
|
|
12
|
-
|
|
11
|
+
import { ISdkFactoryContext } from '../sdkFactory/types';
|
|
13
12
|
|
|
14
13
|
/**
|
|
15
14
|
* Creator of base client with getTreatments and track methods.
|
|
16
15
|
*/
|
|
17
16
|
// @TODO missing time tracking to collect telemetry
|
|
18
|
-
export function clientFactory(params:
|
|
19
|
-
const { sdkReadinessManager: { readinessManager }, storage, settings
|
|
17
|
+
export function clientFactory(params: ISdkFactoryContext): SplitIO.IClient | SplitIO.IAsyncClient {
|
|
18
|
+
const { sdkReadinessManager: { readinessManager }, storage, settings, impressionsTracker, eventTracker } = params;
|
|
19
|
+
const { log, mode } = settings;
|
|
20
20
|
|
|
21
21
|
function getTreatment(key: SplitIO.SplitKey, splitName: string, attributes: SplitIO.Attributes | undefined, withConfig = false) {
|
|
22
22
|
const wrapUp = (evaluationResult: IEvaluationResult) => {
|
|
@@ -124,6 +124,6 @@ export function clientFactory(params: IClientFactoryParams): SplitIO.IClient | S
|
|
|
124
124
|
getTreatments,
|
|
125
125
|
getTreatmentsWithConfig,
|
|
126
126
|
track,
|
|
127
|
-
|
|
127
|
+
isClientSide: false
|
|
128
128
|
} as SplitIO.IClient | SplitIO.IAsyncClient;
|
|
129
129
|
}
|