@splitsoftware/splitio-commons 1.2.1-rc.6 → 1.2.1-rc.9

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.
Files changed (58) hide show
  1. package/cjs/sdkClient/client.js +4 -9
  2. package/cjs/sdkClient/clientCS.js +1 -1
  3. package/cjs/sdkClient/clientInputValidation.js +6 -8
  4. package/cjs/sdkClient/sdkClient.js +1 -4
  5. package/cjs/sdkClient/sdkClientMethodCS.js +1 -5
  6. package/cjs/sdkClient/sdkClientMethodCSWithTT.js +1 -9
  7. package/cjs/sdkFactory/index.js +3 -3
  8. package/cjs/storages/inRedis/RedisAdapter.js +9 -2
  9. package/cjs/sync/streaming/SSEClient/index.js +2 -1
  10. package/cjs/trackers/eventTracker.js +8 -1
  11. package/cjs/trackers/impressionObserver/utils.js +8 -1
  12. package/cjs/trackers/impressionsTracker.js +6 -5
  13. package/cjs/utils/lang/maps.js +16 -2
  14. package/cjs/utils/settingsValidation/index.js +20 -4
  15. package/esm/sdkClient/client.js +5 -10
  16. package/esm/sdkClient/clientCS.js +1 -1
  17. package/esm/sdkClient/clientInputValidation.js +6 -8
  18. package/esm/sdkClient/sdkClient.js +1 -4
  19. package/esm/sdkClient/sdkClientMethodCS.js +1 -5
  20. package/esm/sdkClient/sdkClientMethodCSWithTT.js +1 -9
  21. package/esm/sdkFactory/index.js +3 -3
  22. package/esm/storages/inRedis/RedisAdapter.js +9 -2
  23. package/esm/sync/streaming/SSEClient/index.js +2 -1
  24. package/esm/trackers/eventTracker.js +8 -1
  25. package/esm/trackers/impressionObserver/utils.js +7 -1
  26. package/esm/trackers/impressionsTracker.js +6 -5
  27. package/esm/utils/lang/maps.js +14 -1
  28. package/esm/utils/settingsValidation/index.js +20 -4
  29. package/package.json +1 -1
  30. package/src/integrations/pluggable.ts +2 -2
  31. package/src/sdkClient/client.ts +5 -6
  32. package/src/sdkClient/clientCS.ts +1 -1
  33. package/src/sdkClient/clientInputValidation.ts +8 -7
  34. package/src/sdkClient/sdkClient.ts +2 -5
  35. package/src/sdkClient/sdkClientMethodCS.ts +1 -6
  36. package/src/sdkClient/sdkClientMethodCSWithTT.ts +2 -11
  37. package/src/sdkFactory/index.ts +3 -3
  38. package/src/sdkFactory/types.ts +0 -1
  39. package/src/storages/inRedis/RedisAdapter.ts +8 -2
  40. package/src/sync/streaming/SSEClient/index.ts +2 -1
  41. package/src/trackers/eventTracker.ts +11 -3
  42. package/src/trackers/impressionObserver/utils.ts +8 -1
  43. package/src/trackers/impressionsTracker.ts +7 -8
  44. package/src/types.ts +1 -1
  45. package/src/utils/lang/maps.ts +15 -1
  46. package/src/utils/settingsValidation/consent.ts +2 -1
  47. package/src/utils/settingsValidation/index.ts +20 -4
  48. package/src/utils/settingsValidation/types.ts +3 -1
  49. package/types/sdkClient/clientInputValidation.d.ts +2 -3
  50. package/types/sdkFactory/types.d.ts +0 -1
  51. package/types/storages/inRedis/RedisAdapter.d.ts +1 -1
  52. package/types/trackers/eventTracker.d.ts +2 -2
  53. package/types/trackers/impressionObserver/utils.d.ts +4 -0
  54. package/types/trackers/impressionsTracker.d.ts +2 -3
  55. package/types/types.d.ts +1 -1
  56. package/types/utils/lang/maps.d.ts +7 -0
  57. package/types/utils/settingsValidation/consent.d.ts +3 -2
  58. package/types/utils/settingsValidation/types.d.ts +3 -1
@@ -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
- if (settings.userConsent !== constants_1.CONSENT_DECLINED)
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
- if (settings.userConsent !== constants_1.CONSENT_DECLINED)
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
- if (settings.userConsent !== constants_1.CONSENT_DECLINED)
98
- return eventTracker.track(eventData, size);
99
- else
100
- return false;
95
+ return eventTracker.track(eventData, size);
101
96
  }
102
97
  return {
103
98
  getTreatment: getTreatment,
@@ -105,7 +100,7 @@ function clientFactory(params) {
105
100
  getTreatments: getTreatments,
106
101
  getTreatmentsWithConfig: getTreatmentsWithConfig,
107
102
  track: track,
108
- isBrowserClient: false
103
+ isClientSide: false
109
104
  };
110
105
  }
111
106
  exports.clientFactory = clientFactory;
@@ -20,7 +20,7 @@ function clientCSDecorator(log, client, key, trafficType) {
20
20
  getTreatmentsWithConfig: clientCS.getTreatmentsWithConfig.bind(clientCS, key),
21
21
  // Key is bound to the `track` method. Same thing happens with trafficType but only if provided
22
22
  track: trafficType ? clientCS.track.bind(clientCS, key, trafficType) : clientCS.track.bind(clientCS, key),
23
- isBrowserClient: true
23
+ isClientSide: true
24
24
  });
25
25
  }
26
26
  exports.clientCSDecorator = clientCSDecorator;
@@ -5,12 +5,14 @@ var objectAssign_1 = require("../utils/lang/objectAssign");
5
5
  var inputValidation_1 = require("../utils/inputValidation");
6
6
  var lang_1 = require("../utils/lang");
7
7
  var constants_1 = require("../utils/constants");
8
+ var utils_1 = require("../trackers/impressionObserver/utils");
8
9
  /**
9
10
  * Decorator that validates the input before actually executing the client methods.
10
11
  * We should "guard" the client here, while not polluting the "real" implementation of those methods.
11
12
  */
12
- function clientInputValidationDecorator(log, client, readinessManager, isStorageSync) {
13
- if (isStorageSync === void 0) { isStorageSync = false; }
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
- if (isStorageSync)
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
- if (isStorageSync)
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.log, (0, client_1.clientFactory)(params), sdkReadinessManager.readinessManager,
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 () {
@@ -19,12 +19,8 @@ var method = 'Client instantiation';
19
19
  */
20
20
  function sdkClientMethodCSFactory(params) {
21
21
  var storage = params.storage, syncManager = params.syncManager, sdkReadinessManager = params.sdkReadinessManager, _a = params.settings, key = _a.core.key, readyTimeout = _a.startup.readyTimeout, log = _a.log;
22
- // Keeping similar behaviour as in the isomorphic JS SDK: if settings key is invalid,
23
- // `false` value is used as binded key of the default client, but trafficType is ignored
24
- // @TODO handle as a non-recoverable error
25
- var validKey = (0, key_1.validateKey)(log, key, method);
26
22
  var mainClientInstance = (0, clientCS_1.clientCSDecorator)(log, (0, sdkClient_1.sdkClientFactory)(params), // @ts-ignore
27
- validKey);
23
+ key);
28
24
  var parsedDefaultKey = (0, key_2.keyParser)(key);
29
25
  var defaultInstanceId = buildInstanceId(parsedDefaultKey);
30
26
  // Cache instances created per factory.
@@ -21,16 +21,8 @@ var method = 'Client instantiation';
21
21
  */
22
22
  function sdkClientMethodCSFactory(params) {
23
23
  var storage = params.storage, syncManager = params.syncManager, sdkReadinessManager = params.sdkReadinessManager, _a = params.settings, _b = _a.core, key = _b.key, trafficType = _b.trafficType, readyTimeout = _a.startup.readyTimeout, log = _a.log;
24
- // Keeping the behaviour as in the isomorphic JS SDK: if settings key or TT are invalid,
25
- // `false` value is used as binded key/TT of the default client, which leads to several issues.
26
- // @TODO update when supporting non-recoverable errors
27
- var validKey = (0, key_1.validateKey)(log, key, method);
28
- var validTrafficType;
29
- if (trafficType !== undefined) {
30
- validTrafficType = (0, trafficType_1.validateTrafficType)(log, trafficType, method);
31
- }
32
24
  var mainClientInstance = (0, clientCS_1.clientCSDecorator)(log, (0, sdkClient_1.sdkClientFactory)(params), // @ts-ignore
33
- validKey, validTrafficType);
25
+ key, trafficType);
34
26
  var parsedDefaultKey = (0, key_2.keyParser)(key);
35
27
  var defaultInstanceId = buildInstanceId(parsedDefaultKey, trafficType);
36
28
  // Cache instances created per factory.
@@ -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, impressionListener = params.impressionListener, integrationsManagerFactory = params.integrationsManagerFactory, sdkManagerFactory = params.sdkManagerFactory, sdkClientMethodFactory = params.sdkClientMethodFactory;
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)(log, storage.impressions, settings, impressionListener, integrationsManager, observer, storage.impressionCounts);
63
- var eventTracker = (0, eventTracker_1.eventTrackerFactory)(log, storage.events, integrationsManager);
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
@@ -146,13 +146,19 @@ var RedisAdapter = /** @class */ (function (_super) {
146
146
  else { // If it IS the string URL, that'll be the first param for ioredis.
147
147
  result.unshift(options.url);
148
148
  }
149
+ if (options.connectionTimeout) {
150
+ (0, lang_1.merge)(opts, { connectTimeout: options.connectionTimeout });
151
+ }
152
+ if (options.tls) {
153
+ (0, lang_1.merge)(opts, { tls: options.tls });
154
+ }
149
155
  return result;
150
156
  };
151
157
  /**
152
158
  * Parses the options into what we care about.
153
159
  */
154
160
  RedisAdapter._defineOptions = function (_a) {
155
- var connectionTimeout = _a.connectionTimeout, operationTimeout = _a.operationTimeout, url = _a.url, host = _a.host, port = _a.port, db = _a.db, pass = _a.pass;
161
+ var connectionTimeout = _a.connectionTimeout, operationTimeout = _a.operationTimeout, url = _a.url, host = _a.host, port = _a.port, db = _a.db, pass = _a.pass, tls = _a.tls;
156
162
  var parsedOptions = {
157
163
  connectionTimeout: connectionTimeout,
158
164
  operationTimeout: operationTimeout,
@@ -160,7 +166,8 @@ var RedisAdapter = /** @class */ (function (_super) {
160
166
  host: host,
161
167
  port: port,
162
168
  db: db,
163
- pass: pass
169
+ pass: pass,
170
+ tls: tls
164
171
  };
165
172
  return (0, lang_1.merge)({}, DEFAULT_OPTIONS, parsedOptions);
166
173
  };
@@ -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
@@ -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(log, eventsCache, integrationsManager) {
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(log, impressionsCache,
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 _b = _a.runtime, ip = _b.ip, hostname = _b.hostname, version = _a.version;
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
  }
@@ -24,7 +24,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
24
  THE SOFTWARE.
25
25
  **/
26
26
  Object.defineProperty(exports, "__esModule", { value: true });
27
- exports._Map = exports.MapPoly = void 0;
27
+ exports._Map = exports.__getMapConstructor = exports.MapPoly = void 0;
28
28
  var MapPoly = /** @class */ (function () {
29
29
  // unlike ES6 `Map`, it only accepts an array as first argument iterable
30
30
  function MapPoly(entries) {
@@ -71,4 +71,18 @@ var MapPoly = /** @class */ (function () {
71
71
  return MapPoly;
72
72
  }());
73
73
  exports.MapPoly = MapPoly;
74
- exports._Map = typeof Map !== 'undefined' ? Map : MapPoly;
74
+ /**
75
+ * return the Map constructor to use. If native Map is not available or it doesn't support the required features (e.g., IE11),
76
+ * a ponyfill with minimal features is returned instead.
77
+ *
78
+ * Exported for testing purposes only.
79
+ */
80
+ function __getMapConstructor() {
81
+ // eslint-disable-next-line compat/compat
82
+ if (typeof Array.from === 'function' && typeof Map === 'function' && Map.prototype && Map.prototype.values) {
83
+ return Map;
84
+ }
85
+ return MapPoly;
86
+ }
87
+ exports.__getMapConstructor = __getMapConstructor;
88
+ exports._Map = __getMapConstructor();
@@ -6,6 +6,8 @@ var mode_1 = require("./mode");
6
6
  var splitFilters_1 = require("./splitFilters");
7
7
  var constants_1 = require("../constants");
8
8
  var impressionsMode_1 = require("./impressionsMode");
9
+ var key_1 = require("../inputValidation/key");
10
+ var trafficType_1 = require("../inputValidation/trafficType");
9
11
  var base = {
10
12
  // Define which kind of object you want to retrieve from SplitFactory
11
13
  mode: constants_1.STANDALONE_MODE,
@@ -83,7 +85,7 @@ function fromSecondsToMillis(n) {
83
85
  * @param validationParams defaults and fields validators used to validate and creates a settings object from a given config
84
86
  */
85
87
  function settingsValidation(config, validationParams) {
86
- var defaults = validationParams.defaults, runtime = validationParams.runtime, storage = validationParams.storage, integrations = validationParams.integrations, logger = validationParams.logger, localhost = validationParams.localhost, consent = validationParams.consent;
88
+ var defaults = validationParams.defaults, isClientSide = validationParams.isClientSide, runtime = validationParams.runtime, storage = validationParams.storage, integrations = validationParams.integrations, logger = validationParams.logger, localhost = validationParams.localhost, consent = validationParams.consent;
87
89
  // creates a settings object merging base, defaults and config objects.
88
90
  var withDefaults = (0, lang_1.merge)({}, base, defaults, config);
89
91
  // ensure a valid logger.
@@ -109,9 +111,23 @@ function settingsValidation(config, validationParams) {
109
111
  // @ts-ignore, modify readonly prop
110
112
  if (storage)
111
113
  withDefaults.storage = storage(withDefaults);
112
- // Although `key` is mandatory according to TS declaration files, it can be omitted in LOCALHOST mode. In that case, the value `localhost_key` is used.
113
- if (withDefaults.mode === constants_1.LOCALHOST_MODE && withDefaults.core.key === undefined) {
114
- withDefaults.core.key = 'localhost_key';
114
+ // In client-side, validate key and TT
115
+ if (isClientSide) {
116
+ var maybeKey = withDefaults.core.key;
117
+ // Although `key` is required in client-side, it can be omitted in LOCALHOST mode. In that case, the value `localhost_key` is used.
118
+ if (withDefaults.mode === constants_1.LOCALHOST_MODE && maybeKey === undefined) {
119
+ withDefaults.core.key = 'localhost_key';
120
+ }
121
+ else {
122
+ // Keeping same behaviour than JS SDK: if settings key or TT are invalid,
123
+ // `false` value is used as binded key/TT of the default client, which leads to some issues.
124
+ // @ts-ignore, @TODO handle invalid keys as a non-recoverable error?
125
+ withDefaults.core.key = (0, key_1.validateKey)(log, maybeKey, 'Client instantiation');
126
+ }
127
+ var maybeTT = withDefaults.core.trafficType;
128
+ if (maybeTT !== undefined) { // @ts-ignore, assigning false
129
+ withDefaults.core.trafficType = (0, trafficType_1.validateTrafficType)(log, maybeTT, 'Client instantiation');
130
+ }
115
131
  }
116
132
  // Current ip/hostname information
117
133
  // @ts-ignore, modify readonly prop
@@ -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 { CONSENT_DECLINED, CONTROL } from '../utils/constants';
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
- if (settings.userConsent !== CONSENT_DECLINED)
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
- if (settings.userConsent !== CONSENT_DECLINED)
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
- if (settings.userConsent !== CONSENT_DECLINED)
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,
@@ -102,6 +97,6 @@ export function clientFactory(params) {
102
97
  getTreatments: getTreatments,
103
98
  getTreatmentsWithConfig: getTreatmentsWithConfig,
104
99
  track: track,
105
- isBrowserClient: false
100
+ isClientSide: false
106
101
  };
107
102
  }
@@ -17,6 +17,6 @@ export function clientCSDecorator(log, client, key, trafficType) {
17
17
  getTreatmentsWithConfig: clientCS.getTreatmentsWithConfig.bind(clientCS, key),
18
18
  // Key is bound to the `track` method. Same thing happens with trafficType but only if provided
19
19
  track: trafficType ? clientCS.track.bind(clientCS, key, trafficType) : clientCS.track.bind(clientCS, key),
20
- isBrowserClient: true
20
+ isClientSide: true
21
21
  });
22
22
  }
@@ -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(log, client, readinessManager, isStorageSync) {
10
- if (isStorageSync === void 0) { isStorageSync = false; }
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
- if (isStorageSync)
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
- if (isStorageSync)
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.log, clientFactory(params), sdkReadinessManager.readinessManager,
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 () {
@@ -16,12 +16,8 @@ var method = 'Client instantiation';
16
16
  */
17
17
  export function sdkClientMethodCSFactory(params) {
18
18
  var storage = params.storage, syncManager = params.syncManager, sdkReadinessManager = params.sdkReadinessManager, _a = params.settings, key = _a.core.key, readyTimeout = _a.startup.readyTimeout, log = _a.log;
19
- // Keeping similar behaviour as in the isomorphic JS SDK: if settings key is invalid,
20
- // `false` value is used as binded key of the default client, but trafficType is ignored
21
- // @TODO handle as a non-recoverable error
22
- var validKey = validateKey(log, key, method);
23
19
  var mainClientInstance = clientCSDecorator(log, sdkClientFactory(params), // @ts-ignore
24
- validKey);
20
+ key);
25
21
  var parsedDefaultKey = keyParser(key);
26
22
  var defaultInstanceId = buildInstanceId(parsedDefaultKey);
27
23
  // Cache instances created per factory.
@@ -18,16 +18,8 @@ var method = 'Client instantiation';
18
18
  */
19
19
  export function sdkClientMethodCSFactory(params) {
20
20
  var storage = params.storage, syncManager = params.syncManager, sdkReadinessManager = params.sdkReadinessManager, _a = params.settings, _b = _a.core, key = _b.key, trafficType = _b.trafficType, readyTimeout = _a.startup.readyTimeout, log = _a.log;
21
- // Keeping the behaviour as in the isomorphic JS SDK: if settings key or TT are invalid,
22
- // `false` value is used as binded key/TT of the default client, which leads to several issues.
23
- // @TODO update when supporting non-recoverable errors
24
- var validKey = validateKey(log, key, method);
25
- var validTrafficType;
26
- if (trafficType !== undefined) {
27
- validTrafficType = validateTrafficType(log, trafficType, method);
28
- }
29
21
  var mainClientInstance = clientCSDecorator(log, sdkClientFactory(params), // @ts-ignore
30
- validKey, validTrafficType);
22
+ key, trafficType);
31
23
  var parsedDefaultKey = keyParser(key);
32
24
  var defaultInstanceId = buildInstanceId(parsedDefaultKey, trafficType);
33
25
  // Cache instances created per factory.
@@ -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, impressionListener = params.impressionListener, integrationsManagerFactory = params.integrationsManagerFactory, sdkManagerFactory = params.sdkManagerFactory, sdkClientMethodFactory = params.sdkClientMethodFactory;
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(log, storage.impressions, settings, impressionListener, integrationsManager, observer, storage.impressionCounts);
60
- var eventTracker = eventTrackerFactory(log, storage.events, integrationsManager);
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
@@ -143,13 +143,19 @@ var RedisAdapter = /** @class */ (function (_super) {
143
143
  else { // If it IS the string URL, that'll be the first param for ioredis.
144
144
  result.unshift(options.url);
145
145
  }
146
+ if (options.connectionTimeout) {
147
+ merge(opts, { connectTimeout: options.connectionTimeout });
148
+ }
149
+ if (options.tls) {
150
+ merge(opts, { tls: options.tls });
151
+ }
146
152
  return result;
147
153
  };
148
154
  /**
149
155
  * Parses the options into what we care about.
150
156
  */
151
157
  RedisAdapter._defineOptions = function (_a) {
152
- var connectionTimeout = _a.connectionTimeout, operationTimeout = _a.operationTimeout, url = _a.url, host = _a.host, port = _a.port, db = _a.db, pass = _a.pass;
158
+ var connectionTimeout = _a.connectionTimeout, operationTimeout = _a.operationTimeout, url = _a.url, host = _a.host, port = _a.port, db = _a.db, pass = _a.pass, tls = _a.tls;
153
159
  var parsedOptions = {
154
160
  connectionTimeout: connectionTimeout,
155
161
  operationTimeout: operationTimeout,
@@ -157,7 +163,8 @@ var RedisAdapter = /** @class */ (function (_super) {
157
163
  host: host,
158
164
  port: port,
159
165
  db: db,
160
- pass: pass
166
+ pass: pass,
167
+ tls: tls
161
168
  };
162
169
  return merge({}, DEFAULT_OPTIONS, parsedOptions);
163
170
  };
@@ -1,3 +1,4 @@
1
+ import { isString } from '../../../utils/lang';
1
2
  var VERSION = '1.1';
2
3
  var CONTROL_CHANNEL_REGEX = /^control_/;
3
4
  /**
@@ -8,7 +9,7 @@ var CONTROL_CHANNEL_REGEX = /^control_/;
8
9
  */
9
10
  function buildSSEHeaders(settings) {
10
11
  var headers = {
11
- SplitSDKClientKey: settings.core.authorizationKey.slice(-4),
12
+ SplitSDKClientKey: isString(settings.core.authorizationKey) ? settings.core.authorizationKey.slice(-4) : '',
12
13
  SplitSDKVersion: settings.version,
13
14
  };
14
15
  // ip and hostname are false if IPAddressesEnabled is false
@@ -1,13 +1,17 @@
1
1
  import { objectAssign } from '../utils/lang/objectAssign';
2
2
  import { thenable } from '../utils/promise/thenable';
3
3
  import { EVENTS_TRACKER_SUCCESS, ERROR_EVENTS_TRACKER } from '../logger/constants';
4
+ import { CONSENT_DECLINED } from '../utils/constants';
5
+ import { isStorageSync } from './impressionObserver/utils';
4
6
  /**
5
7
  * Event tracker stores events in cache and pass them to the integrations manager if provided.
6
8
  *
7
9
  * @param eventsCache cache to save events
8
10
  * @param integrationsManager optional event handler used for integrations
9
11
  */
10
- export function eventTrackerFactory(log, eventsCache, integrationsManager) {
12
+ export function eventTrackerFactory(settings, eventsCache, integrationsManager) {
13
+ var log = settings.log;
14
+ var isSync = isStorageSync(settings);
11
15
  function queueEventsCallback(eventData, tracked) {
12
16
  var eventTypeId = eventData.eventTypeId, trafficTypeName = eventData.trafficTypeName, key = eventData.key, value = eventData.value, timestamp = eventData.timestamp, properties = eventData.properties;
13
17
  // Logging every prop would be too much.
@@ -33,6 +37,9 @@ export function eventTrackerFactory(log, eventsCache, integrationsManager) {
33
37
  }
34
38
  return {
35
39
  track: function (eventData, size) {
40
+ if (settings.userConsent === CONSENT_DECLINED) {
41
+ return isSync ? false : Promise.resolve(false);
42
+ }
36
43
  var tracked = eventsCache.track(eventData, size);
37
44
  if (thenable(tracked)) {
38
45
  return tracked.then(queueEventsCallback.bind(null, eventData));