@splitsoftware/splitio-commons 2.1.0 → 2.1.1-rc.1

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 (77) hide show
  1. package/CHANGES.txt +3 -0
  2. package/cjs/logger/constants.js +4 -6
  3. package/cjs/logger/messages/debug.js +1 -3
  4. package/cjs/logger/messages/error.js +1 -1
  5. package/cjs/logger/messages/warn.js +1 -1
  6. package/cjs/sdkClient/client.js +29 -19
  7. package/cjs/sdkClient/clientAttributesDecoration.js +19 -25
  8. package/cjs/sdkClient/clientInputValidation.js +28 -26
  9. package/cjs/storages/AbstractSplitsCacheAsync.js +12 -1
  10. package/cjs/storages/AbstractSplitsCacheSync.js +5 -7
  11. package/cjs/storages/KeyBuilder.js +0 -16
  12. package/cjs/storages/KeyBuilderCS.js +8 -2
  13. package/cjs/storages/dataLoader.js +1 -2
  14. package/cjs/storages/inLocalStorage/SplitsCacheInLocal.js +5 -2
  15. package/cjs/storages/inMemory/SplitsCacheInMemory.js +24 -31
  16. package/cjs/storages/inRedis/SplitsCacheInRedis.js +4 -21
  17. package/cjs/storages/pluggable/SplitsCachePluggable.js +2 -19
  18. package/cjs/storages/utils.js +1 -0
  19. package/cjs/sync/offline/syncTasks/fromObjectSyncTask.js +12 -13
  20. package/cjs/sync/polling/syncTasks/splitsSyncTask.js +1 -1
  21. package/cjs/sync/polling/updaters/splitChangesUpdater.js +9 -23
  22. package/cjs/sync/submitters/impressionsSubmitter.js +3 -2
  23. package/cjs/trackers/strategy/strategyOptimized.js +3 -0
  24. package/cjs/utils/inputValidation/eventProperties.js +12 -1
  25. package/cjs/utils/inputValidation/index.js +3 -1
  26. package/esm/logger/constants.js +1 -3
  27. package/esm/logger/messages/debug.js +1 -3
  28. package/esm/logger/messages/error.js +1 -1
  29. package/esm/logger/messages/warn.js +1 -1
  30. package/esm/sdkClient/client.js +29 -19
  31. package/esm/sdkClient/clientAttributesDecoration.js +19 -25
  32. package/esm/sdkClient/clientInputValidation.js +29 -27
  33. package/esm/storages/AbstractSplitsCacheAsync.js +12 -1
  34. package/esm/storages/AbstractSplitsCacheSync.js +5 -7
  35. package/esm/storages/KeyBuilder.js +0 -16
  36. package/esm/storages/KeyBuilderCS.js +8 -2
  37. package/esm/storages/dataLoader.js +1 -2
  38. package/esm/storages/inLocalStorage/SplitsCacheInLocal.js +5 -2
  39. package/esm/storages/inMemory/SplitsCacheInMemory.js +24 -31
  40. package/esm/storages/inRedis/SplitsCacheInRedis.js +4 -21
  41. package/esm/storages/pluggable/SplitsCachePluggable.js +2 -19
  42. package/esm/storages/utils.js +1 -0
  43. package/esm/sync/offline/syncTasks/fromObjectSyncTask.js +12 -13
  44. package/esm/sync/polling/syncTasks/splitsSyncTask.js +1 -1
  45. package/esm/sync/polling/updaters/splitChangesUpdater.js +10 -24
  46. package/esm/sync/submitters/impressionsSubmitter.js +3 -2
  47. package/esm/trackers/strategy/strategyOptimized.js +3 -0
  48. package/esm/utils/inputValidation/eventProperties.js +10 -0
  49. package/esm/utils/inputValidation/index.js +1 -0
  50. package/package.json +1 -1
  51. package/src/logger/constants.ts +1 -3
  52. package/src/logger/messages/debug.ts +1 -3
  53. package/src/logger/messages/error.ts +1 -1
  54. package/src/logger/messages/warn.ts +1 -1
  55. package/src/sdkClient/client.ts +31 -21
  56. package/src/sdkClient/clientAttributesDecoration.ts +20 -27
  57. package/src/sdkClient/clientInputValidation.ts +30 -27
  58. package/src/storages/AbstractSplitsCacheAsync.ts +15 -5
  59. package/src/storages/AbstractSplitsCacheSync.ts +9 -13
  60. package/src/storages/KeyBuilder.ts +0 -20
  61. package/src/storages/KeyBuilderCS.ts +10 -3
  62. package/src/storages/dataLoader.ts +1 -2
  63. package/src/storages/inLocalStorage/SplitsCacheInLocal.ts +5 -2
  64. package/src/storages/inMemory/SplitsCacheInMemory.ts +22 -27
  65. package/src/storages/inRedis/SplitsCacheInRedis.ts +4 -21
  66. package/src/storages/pluggable/SplitsCachePluggable.ts +2 -19
  67. package/src/storages/types.ts +10 -16
  68. package/src/storages/utils.ts +1 -0
  69. package/src/sync/offline/syncTasks/fromObjectSyncTask.ts +14 -15
  70. package/src/sync/polling/syncTasks/splitsSyncTask.ts +1 -2
  71. package/src/sync/polling/updaters/splitChangesUpdater.ts +12 -27
  72. package/src/sync/submitters/impressionsSubmitter.ts +3 -2
  73. package/src/sync/submitters/types.ts +23 -33
  74. package/src/trackers/strategy/strategyOptimized.ts +3 -0
  75. package/src/utils/inputValidation/eventProperties.ts +10 -0
  76. package/src/utils/inputValidation/index.ts +1 -0
  77. package/types/splitio.d.ts +100 -35
package/CHANGES.txt CHANGED
@@ -1,3 +1,6 @@
1
+ 2.2.0 (March 28, 2025)
2
+ - Added new optional argument to the client `getTreatment` methods to allow passing additional evaluation options, such as a map of properties to append to the generated impression object sent to Split's backend. Read more in our docs.
3
+
1
4
  2.1.0 (January 17, 2025)
2
5
  - Added support for the new impressions tracking toggle available on feature flags, both respecting the setting and including the new field being returned on `SplitView` type objects. Read more in our docs.
3
6
 
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ENGINE_VALUE_INVALID = exports.USER_CONSENT_INITIAL = exports.USER_CONSENT_NOT_UPDATED = exports.USER_CONSENT_UPDATED = exports.IMPRESSIONS_TRACKER_SUCCESS = exports.EVENTS_TRACKER_SUCCESS = exports.SYNC_STOP_POLLING = exports.SYNC_CONTINUE_POLLING = exports.SYNC_START_POLLING = exports.SUBMITTERS_PUSH = exports.SUBMITTERS_PUSH_FULL_QUEUE = exports.STREAMING_DISCONNECTING = exports.STREAMING_DISABLED = exports.STREAMING_CONNECTING = exports.STREAMING_RECONNECT = exports.STREAMING_REFRESH_TOKEN = exports.SYNC_SPLITS_FETCH_RETRY = exports.POLLING_STOP = exports.POLLING_START = exports.POLLING_SMART_PAUSING = exports.NEW_FACTORY = exports.NEW_SHARED_CLIENT = exports.IMPRESSION_QUEUEING = exports.IMPRESSION = exports.CLIENT_READY = exports.CLIENT_READY_FROM_CACHE = exports.ENGINE_MATCHER_RESULT = exports.SETTINGS_SPLITS_FILTER = exports.SYNC_TASK_STOP = exports.SYNC_TASK_EXECUTE = exports.SYNC_TASK_START = exports.STREAMING_NEW_MESSAGE = exports.SYNC_SPLITS_SEGMENTS = exports.SYNC_SPLITS_REMOVED = exports.SYNC_SPLITS_NEW = exports.SYNC_SPLITS_FETCH = exports.SYNC_OFFLINE_DATA = exports.RETRIEVE_MANAGER = exports.RETRIEVE_CLIENT_EXISTING = exports.RETRIEVE_CLIENT_DEFAULT = exports.CLEANUP_DEREGISTERING = exports.CLEANUP_REGISTERING = exports.ENGINE_SANITIZE = exports.ENGINE_VALUE = exports.ENGINE_MATCHER_DEPENDENCY_PRE = exports.ENGINE_MATCHER_DEPENDENCY = exports.ENGINE_BUCKET = exports.ENGINE_COMBINER_IFELSEIF_NO_TREATMENT = exports.ENGINE_COMBINER_IFELSEIF = exports.ENGINE_COMBINER_AND = void 0;
4
- exports.ERROR_INVALID_CONFIG_PARAM = exports.ERROR_EMPTY_ARRAY = exports.ERROR_EMPTY = exports.ERROR_INVALID = exports.ERROR_INVALID_KEY_OBJECT = exports.ERROR_TOO_LONG = exports.ERROR_NULL = exports.ERROR_CLIENT_DESTROYED = exports.ERROR_NOT_FINITE = exports.ERROR_SIZE_EXCEEDED = exports.ERROR_NOT_PLAIN_OBJECT = exports.ERROR_EVENT_TYPE_FORMAT = exports.ERROR_EVENTS_TRACKER = exports.ERROR_IMPRESSIONS_LISTENER = exports.ERROR_IMPRESSIONS_TRACKER = exports.ERROR_STREAMING_AUTH = exports.ERROR_STREAMING_SSE = exports.ERROR_SYNC_OFFLINE_LOADING = exports.ERROR_CLIENT_CANNOT_GET_READY = exports.ERROR_CLIENT_LISTENER = exports.ERROR_LOGLEVEL_INVALID = exports.ERROR_ENGINE_COMBINER_IFELSEIF = exports.WARN_FLAGSET_WITHOUT_FLAGS = exports.WARN_FLAGSET_NOT_CONFIGURED = exports.WARN_LOWERCASE_FLAGSET = exports.WARN_INVALID_FLAGSET = exports.STREAMING_PARSING_SPLIT_UPDATE = exports.STREAMING_PARSING_MEMBERSHIPS_UPDATE = exports.WARN_SDK_KEY = exports.WARN_SPLITS_FILTER_EMPTY = exports.WARN_SPLITS_FILTER_INVALID = exports.WARN_SPLITS_FILTER_IGNORED = exports.WARN_INTEGRATION_INVALID = exports.WARN_NOT_EXISTENT_TT = exports.WARN_LOWERCASE_TRAFFIC_TYPE = exports.WARN_NOT_EXISTENT_SPLIT = exports.WARN_TRIMMING = exports.WARN_CONVERTING = exports.WARN_TRIMMING_PROPERTIES = exports.WARN_SETTING_NULL = exports.SUBMITTERS_PUSH_RETRY = exports.SUBMITTERS_PUSH_FAILS = exports.STREAMING_FALLBACK = exports.STREAMING_PARSING_MESSAGE_FAILS = exports.STREAMING_PARSING_ERROR_FAILS = exports.SYNC_SPLITS_FETCH_FAILS = exports.SYNC_MYSEGMENTS_FETCH_RETRY = exports.CLIENT_NOT_READY = exports.CLIENT_NO_LISTENER = exports.ENGINE_VALUE_NO_ATTRIBUTES = void 0;
5
- exports.LOG_PREFIX_CLEANUP = exports.LOG_PREFIX_UNIQUE_KEYS_TRACKER = exports.LOG_PREFIX_EVENTS_TRACKER = exports.LOG_PREFIX_IMPRESSIONS_TRACKER = exports.LOG_PREFIX_SYNC_SUBMITTERS = exports.LOG_PREFIX_SYNC_POLLING = exports.LOG_PREFIX_SYNC_MYSEGMENTS = exports.LOG_PREFIX_SYNC_SEGMENTS = exports.LOG_PREFIX_SYNC_SPLITS = exports.LOG_PREFIX_SYNC_STREAMING = exports.LOG_PREFIX_SYNC_OFFLINE = exports.LOG_PREFIX_SYNC_MANAGER = exports.LOG_PREFIX_SYNC = exports.LOG_PREFIX_ENGINE_VALUE = exports.LOG_PREFIX_ENGINE_MATCHER = exports.LOG_PREFIX_ENGINE_COMBINER = exports.LOG_PREFIX_ENGINE = exports.LOG_PREFIX_CLIENT_INSTANTIATION = exports.LOG_PREFIX_INSTANTIATION = exports.LOG_PREFIX_SETTINGS = exports.ENGINE_MATCHER_ERROR = exports.ERROR_SETS_FILTER_EXCLUSIVE = exports.ERROR_TOO_MANY_SETS = exports.ERROR_MIN_CONFIG_PARAM = exports.ERROR_NOT_BOOLEAN = exports.ERROR_STORAGE_INVALID = exports.ERROR_HTTP = void 0;
3
+ exports.CLIENT_NO_LISTENER = exports.ENGINE_VALUE_NO_ATTRIBUTES = exports.ENGINE_VALUE_INVALID = exports.USER_CONSENT_INITIAL = exports.USER_CONSENT_NOT_UPDATED = exports.USER_CONSENT_UPDATED = exports.IMPRESSIONS_TRACKER_SUCCESS = exports.EVENTS_TRACKER_SUCCESS = exports.SYNC_STOP_POLLING = exports.SYNC_CONTINUE_POLLING = exports.SYNC_START_POLLING = exports.SUBMITTERS_PUSH = exports.SUBMITTERS_PUSH_FULL_QUEUE = exports.STREAMING_DISCONNECTING = exports.STREAMING_DISABLED = exports.STREAMING_CONNECTING = exports.STREAMING_RECONNECT = exports.STREAMING_REFRESH_TOKEN = exports.SYNC_SPLITS_FETCH_RETRY = exports.POLLING_STOP = exports.POLLING_START = exports.POLLING_SMART_PAUSING = exports.NEW_FACTORY = exports.NEW_SHARED_CLIENT = exports.IMPRESSION_QUEUEING = exports.IMPRESSION = exports.CLIENT_READY = exports.CLIENT_READY_FROM_CACHE = exports.ENGINE_MATCHER_RESULT = exports.SETTINGS_SPLITS_FILTER = exports.SYNC_TASK_STOP = exports.SYNC_TASK_EXECUTE = exports.SYNC_TASK_START = exports.STREAMING_NEW_MESSAGE = exports.SYNC_SPLITS_UPDATE = exports.SYNC_SPLITS_FETCH = exports.SYNC_OFFLINE_DATA = exports.RETRIEVE_MANAGER = exports.RETRIEVE_CLIENT_EXISTING = exports.RETRIEVE_CLIENT_DEFAULT = exports.CLEANUP_DEREGISTERING = exports.CLEANUP_REGISTERING = exports.ENGINE_SANITIZE = exports.ENGINE_VALUE = exports.ENGINE_MATCHER_DEPENDENCY_PRE = exports.ENGINE_MATCHER_DEPENDENCY = exports.ENGINE_BUCKET = exports.ENGINE_COMBINER_IFELSEIF_NO_TREATMENT = exports.ENGINE_COMBINER_IFELSEIF = exports.ENGINE_COMBINER_AND = void 0;
4
+ exports.ERROR_STORAGE_INVALID = exports.ERROR_HTTP = exports.ERROR_INVALID_CONFIG_PARAM = exports.ERROR_EMPTY_ARRAY = exports.ERROR_EMPTY = exports.ERROR_INVALID = exports.ERROR_INVALID_KEY_OBJECT = exports.ERROR_TOO_LONG = exports.ERROR_NULL = exports.ERROR_CLIENT_DESTROYED = exports.ERROR_NOT_FINITE = exports.ERROR_SIZE_EXCEEDED = exports.ERROR_NOT_PLAIN_OBJECT = exports.ERROR_EVENT_TYPE_FORMAT = exports.ERROR_EVENTS_TRACKER = exports.ERROR_IMPRESSIONS_LISTENER = exports.ERROR_IMPRESSIONS_TRACKER = exports.ERROR_STREAMING_AUTH = exports.ERROR_STREAMING_SSE = exports.ERROR_SYNC_OFFLINE_LOADING = exports.ERROR_CLIENT_CANNOT_GET_READY = exports.ERROR_CLIENT_LISTENER = exports.ERROR_LOGLEVEL_INVALID = exports.ERROR_ENGINE_COMBINER_IFELSEIF = exports.WARN_FLAGSET_WITHOUT_FLAGS = exports.WARN_FLAGSET_NOT_CONFIGURED = exports.WARN_LOWERCASE_FLAGSET = exports.WARN_INVALID_FLAGSET = exports.STREAMING_PARSING_SPLIT_UPDATE = exports.STREAMING_PARSING_MEMBERSHIPS_UPDATE = exports.WARN_SDK_KEY = exports.WARN_SPLITS_FILTER_EMPTY = exports.WARN_SPLITS_FILTER_INVALID = exports.WARN_SPLITS_FILTER_IGNORED = exports.WARN_INTEGRATION_INVALID = exports.WARN_NOT_EXISTENT_TT = exports.WARN_LOWERCASE_TRAFFIC_TYPE = exports.WARN_NOT_EXISTENT_SPLIT = exports.WARN_TRIMMING = exports.WARN_CONVERTING = exports.WARN_TRIMMING_PROPERTIES = exports.WARN_SETTING_NULL = exports.SUBMITTERS_PUSH_RETRY = exports.SUBMITTERS_PUSH_FAILS = exports.STREAMING_FALLBACK = exports.STREAMING_PARSING_MESSAGE_FAILS = exports.STREAMING_PARSING_ERROR_FAILS = exports.SYNC_SPLITS_FETCH_FAILS = exports.SYNC_MYSEGMENTS_FETCH_RETRY = exports.CLIENT_NOT_READY = void 0;
5
+ exports.LOG_PREFIX_CLEANUP = exports.LOG_PREFIX_UNIQUE_KEYS_TRACKER = exports.LOG_PREFIX_EVENTS_TRACKER = exports.LOG_PREFIX_IMPRESSIONS_TRACKER = exports.LOG_PREFIX_SYNC_SUBMITTERS = exports.LOG_PREFIX_SYNC_POLLING = exports.LOG_PREFIX_SYNC_MYSEGMENTS = exports.LOG_PREFIX_SYNC_SEGMENTS = exports.LOG_PREFIX_SYNC_SPLITS = exports.LOG_PREFIX_SYNC_STREAMING = exports.LOG_PREFIX_SYNC_OFFLINE = exports.LOG_PREFIX_SYNC_MANAGER = exports.LOG_PREFIX_SYNC = exports.LOG_PREFIX_ENGINE_VALUE = exports.LOG_PREFIX_ENGINE_MATCHER = exports.LOG_PREFIX_ENGINE_COMBINER = exports.LOG_PREFIX_ENGINE = exports.LOG_PREFIX_CLIENT_INSTANTIATION = exports.LOG_PREFIX_INSTANTIATION = exports.LOG_PREFIX_SETTINGS = exports.ENGINE_MATCHER_ERROR = exports.ERROR_SETS_FILTER_EXCLUSIVE = exports.ERROR_TOO_MANY_SETS = exports.ERROR_MIN_CONFIG_PARAM = exports.ERROR_NOT_BOOLEAN = 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.
@@ -25,9 +25,7 @@ exports.RETRIEVE_CLIENT_EXISTING = 28;
25
25
  exports.RETRIEVE_MANAGER = 29;
26
26
  exports.SYNC_OFFLINE_DATA = 30;
27
27
  exports.SYNC_SPLITS_FETCH = 31;
28
- exports.SYNC_SPLITS_NEW = 32;
29
- exports.SYNC_SPLITS_REMOVED = 33;
30
- exports.SYNC_SPLITS_SEGMENTS = 34;
28
+ exports.SYNC_SPLITS_UPDATE = 32;
31
29
  exports.STREAMING_NEW_MESSAGE = 35;
32
30
  exports.SYNC_TASK_START = 36;
33
31
  exports.SYNC_TASK_EXECUTE = 37;
@@ -24,9 +24,7 @@ exports.codesDebug = info_1.codesInfo.concat([
24
24
  // synchronizer
25
25
  [c.SYNC_OFFLINE_DATA, c.LOG_PREFIX_SYNC_OFFLINE + 'Feature flags data: \n%s'],
26
26
  [c.SYNC_SPLITS_FETCH, c.LOG_PREFIX_SYNC_SPLITS + 'Spin up feature flags update using since = %s'],
27
- [c.SYNC_SPLITS_NEW, c.LOG_PREFIX_SYNC_SPLITS + 'New feature flags %s'],
28
- [c.SYNC_SPLITS_REMOVED, c.LOG_PREFIX_SYNC_SPLITS + 'Removed feature flags %s'],
29
- [c.SYNC_SPLITS_SEGMENTS, c.LOG_PREFIX_SYNC_SPLITS + 'Segment names collected %s'],
27
+ [c.SYNC_SPLITS_UPDATE, c.LOG_PREFIX_SYNC_SPLITS + 'New feature flags %s. Removed feature flags %s. Segment names collected %s'],
30
28
  [c.STREAMING_NEW_MESSAGE, c.LOG_PREFIX_SYNC_STREAMING + 'New SSE message received, with data: %s.'],
31
29
  [c.SYNC_TASK_START, c.LOG_PREFIX_SYNC + ': Starting %s. Running each %s millis'],
32
30
  [c.SYNC_TASK_EXECUTE, c.LOG_PREFIX_SYNC + ': Running %s'],
@@ -24,7 +24,7 @@ exports.codesError = [
24
24
  // input validation
25
25
  [c.ERROR_EVENT_TYPE_FORMAT, '%s: you passed "%s", event_type must adhere to the regular expression /^[a-zA-Z0-9][-_.:a-zA-Z0-9]{0,79}$/g. This means an event_type must be alphanumeric, cannot be more than 80 characters long, and can only include a dash, underscore, period, or colon as separators of alphanumeric characters.'],
26
26
  [c.ERROR_NOT_PLAIN_OBJECT, '%s: %s must be a plain object.'],
27
- [c.ERROR_SIZE_EXCEEDED, '%s: the maximum size allowed for the properties is 32768 bytes, which was exceeded. Event not queued.'],
27
+ [c.ERROR_SIZE_EXCEEDED, '%s: the maximum size allowed for the properties is 32768 bytes, which was exceeded.'],
28
28
  [c.ERROR_NOT_FINITE, '%s: value must be a finite number.'],
29
29
  [c.ERROR_NULL, '%s: you passed a null or undefined %s. It must be a non-empty string.'],
30
30
  [c.ERROR_TOO_LONG, '%s: %s too long. It must have 250 characters or less.'],
@@ -21,7 +21,7 @@ exports.codesWarn = error_1.codesError.concat([
21
21
  [c.CLIENT_NO_LISTENER, 'No listeners for SDK Readiness detected. Incorrect control treatments could have been logged if you called getTreatment/s while the SDK was not yet ready.'],
22
22
  // input validation
23
23
  [c.WARN_SETTING_NULL, '%s: Property "%s" is of invalid type. Setting value to null.'],
24
- [c.WARN_TRIMMING_PROPERTIES, '%s: Event has more than 300 properties. Some of them will be trimmed when processed.'],
24
+ [c.WARN_TRIMMING_PROPERTIES, '%s: more than 300 properties were provided. Some of them will be trimmed when processed.'],
25
25
  [c.WARN_CONVERTING, '%s: %s "%s" is not of type string, converting.'],
26
26
  [c.WARN_TRIMMING, '%s: %s "%s" has extra whitespace, trimming.'],
27
27
  [c.WARN_NOT_EXISTENT_SPLIT, '%s: feature flag "%s" does not exist in this environment. Please double check what feature flags exist in the Split user interface.'],
@@ -18,6 +18,14 @@ function treatmentsNotReady(featureFlagNames) {
18
18
  });
19
19
  return evaluations;
20
20
  }
21
+ function stringify(options) {
22
+ if (options && options.properties) {
23
+ try {
24
+ return JSON.stringify(options.properties);
25
+ }
26
+ catch ( /* JSON.stringify should never throw with validated options, but handling just in case */_a) { /* JSON.stringify should never throw with validated options, but handling just in case */ }
27
+ }
28
+ }
21
29
  /**
22
30
  * Creator of base client with getTreatments and track methods.
23
31
  */
@@ -25,13 +33,13 @@ function clientFactory(params) {
25
33
  var readinessManager = params.sdkReadinessManager.readinessManager, storage = params.storage, settings = params.settings, impressionsTracker = params.impressionsTracker, eventTracker = params.eventTracker, telemetryTracker = params.telemetryTracker;
26
34
  var log = settings.log, mode = settings.mode;
27
35
  var isAsync = (0, mode_1.isConsumerMode)(mode);
28
- function getTreatment(key, featureFlagName, attributes, withConfig, methodName) {
36
+ function getTreatment(key, featureFlagName, attributes, options, withConfig, methodName) {
29
37
  if (withConfig === void 0) { withConfig = false; }
30
38
  if (methodName === void 0) { methodName = constants_1.GET_TREATMENT; }
31
39
  var stopTelemetryTracker = telemetryTracker.trackEval(withConfig ? constants_1.TREATMENT_WITH_CONFIG : constants_1.TREATMENT);
32
40
  var wrapUp = function (evaluationResult) {
33
41
  var queue = [];
34
- var treatment = processEvaluation(evaluationResult, featureFlagName, key, attributes, withConfig, methodName, queue);
42
+ var treatment = processEvaluation(evaluationResult, featureFlagName, key, stringify(options), withConfig, methodName, queue);
35
43
  impressionsTracker.track(queue, attributes);
36
44
  stopTelemetryTracker(queue[0] && queue[0].imp.label);
37
45
  return treatment;
@@ -43,18 +51,19 @@ function clientFactory(params) {
43
51
  treatmentNotReady;
44
52
  return (0, thenable_1.thenable)(evaluation) ? evaluation.then(function (res) { return wrapUp(res); }) : wrapUp(evaluation);
45
53
  }
46
- function getTreatmentWithConfig(key, featureFlagName, attributes) {
47
- return getTreatment(key, featureFlagName, attributes, true, constants_1.GET_TREATMENT_WITH_CONFIG);
54
+ function getTreatmentWithConfig(key, featureFlagName, attributes, options) {
55
+ return getTreatment(key, featureFlagName, attributes, options, true, constants_1.GET_TREATMENT_WITH_CONFIG);
48
56
  }
49
- function getTreatments(key, featureFlagNames, attributes, withConfig, methodName) {
57
+ function getTreatments(key, featureFlagNames, attributes, options, withConfig, methodName) {
50
58
  if (withConfig === void 0) { withConfig = false; }
51
59
  if (methodName === void 0) { methodName = constants_1.GET_TREATMENTS; }
52
60
  var stopTelemetryTracker = telemetryTracker.trackEval(withConfig ? constants_1.TREATMENTS_WITH_CONFIG : constants_1.TREATMENTS);
53
61
  var wrapUp = function (evaluationResults) {
54
62
  var queue = [];
55
63
  var treatments = {};
64
+ var properties = stringify(options);
56
65
  Object.keys(evaluationResults).forEach(function (featureFlagName) {
57
- treatments[featureFlagName] = processEvaluation(evaluationResults[featureFlagName], featureFlagName, key, attributes, withConfig, methodName, queue);
66
+ treatments[featureFlagName] = processEvaluation(evaluationResults[featureFlagName], featureFlagName, key, properties, withConfig, methodName, queue);
58
67
  });
59
68
  impressionsTracker.track(queue, attributes);
60
69
  stopTelemetryTracker(queue[0] && queue[0].imp.label);
@@ -67,10 +76,10 @@ function clientFactory(params) {
67
76
  treatmentsNotReady(featureFlagNames);
68
77
  return (0, thenable_1.thenable)(evaluations) ? evaluations.then(function (res) { return wrapUp(res); }) : wrapUp(evaluations);
69
78
  }
70
- function getTreatmentsWithConfig(key, featureFlagNames, attributes) {
71
- return getTreatments(key, featureFlagNames, attributes, true, constants_1.GET_TREATMENTS_WITH_CONFIG);
79
+ function getTreatmentsWithConfig(key, featureFlagNames, attributes, options) {
80
+ return getTreatments(key, featureFlagNames, attributes, options, true, constants_1.GET_TREATMENTS_WITH_CONFIG);
72
81
  }
73
- function getTreatmentsByFlagSets(key, flagSetNames, attributes, withConfig, method, methodName) {
82
+ function getTreatmentsByFlagSets(key, flagSetNames, attributes, options, withConfig, method, methodName) {
74
83
  if (withConfig === void 0) { withConfig = false; }
75
84
  if (method === void 0) { method = constants_1.TREATMENTS_BY_FLAGSETS; }
76
85
  if (methodName === void 0) { methodName = constants_1.GET_TREATMENTS_BY_FLAG_SETS; }
@@ -78,9 +87,9 @@ function clientFactory(params) {
78
87
  var wrapUp = function (evaluationResults) {
79
88
  var queue = [];
80
89
  var treatments = {};
81
- var evaluations = evaluationResults;
82
- Object.keys(evaluations).forEach(function (featureFlagName) {
83
- treatments[featureFlagName] = processEvaluation(evaluations[featureFlagName], featureFlagName, key, attributes, withConfig, methodName, queue);
90
+ var properties = stringify(options);
91
+ Object.keys(evaluationResults).forEach(function (featureFlagName) {
92
+ treatments[featureFlagName] = processEvaluation(evaluationResults[featureFlagName], featureFlagName, key, properties, withConfig, methodName, queue);
84
93
  });
85
94
  impressionsTracker.track(queue, attributes);
86
95
  stopTelemetryTracker(queue[0] && queue[0].imp.label);
@@ -93,17 +102,17 @@ function clientFactory(params) {
93
102
  {};
94
103
  return (0, thenable_1.thenable)(evaluations) ? evaluations.then(function (res) { return wrapUp(res); }) : wrapUp(evaluations);
95
104
  }
96
- function getTreatmentsWithConfigByFlagSets(key, flagSetNames, attributes) {
97
- return getTreatmentsByFlagSets(key, flagSetNames, attributes, true, constants_1.TREATMENTS_WITH_CONFIG_BY_FLAGSETS, constants_1.GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SETS);
105
+ function getTreatmentsWithConfigByFlagSets(key, flagSetNames, attributes, options) {
106
+ return getTreatmentsByFlagSets(key, flagSetNames, attributes, options, true, constants_1.TREATMENTS_WITH_CONFIG_BY_FLAGSETS, constants_1.GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SETS);
98
107
  }
99
- function getTreatmentsByFlagSet(key, flagSetName, attributes) {
100
- return getTreatmentsByFlagSets(key, [flagSetName], attributes, false, constants_1.TREATMENTS_BY_FLAGSET, constants_1.GET_TREATMENTS_BY_FLAG_SET);
108
+ function getTreatmentsByFlagSet(key, flagSetName, attributes, options) {
109
+ return getTreatmentsByFlagSets(key, [flagSetName], attributes, options, false, constants_1.TREATMENTS_BY_FLAGSET, constants_1.GET_TREATMENTS_BY_FLAG_SET);
101
110
  }
102
- function getTreatmentsWithConfigByFlagSet(key, flagSetName, attributes) {
103
- return getTreatmentsByFlagSets(key, [flagSetName], attributes, true, constants_1.TREATMENTS_WITH_CONFIG_BY_FLAGSET, constants_1.GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SET);
111
+ function getTreatmentsWithConfigByFlagSet(key, flagSetName, attributes, options) {
112
+ return getTreatmentsByFlagSets(key, [flagSetName], attributes, options, true, constants_1.TREATMENTS_WITH_CONFIG_BY_FLAGSET, constants_1.GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SET);
104
113
  }
105
114
  // Internal function
106
- function processEvaluation(evaluation, featureFlagName, key, attributes, withConfig, invokingMethodName, queue) {
115
+ function processEvaluation(evaluation, featureFlagName, key, properties, withConfig, invokingMethodName, queue) {
107
116
  var matchingKey = (0, key_1.getMatching)(key);
108
117
  var bucketingKey = (0, key_1.getBucketing)(key);
109
118
  var treatment = evaluation.treatment, label = evaluation.label, changeNumber = evaluation.changeNumber, _a = evaluation.config, config = _a === void 0 ? null : _a, impressionsDisabled = evaluation.impressionsDisabled;
@@ -119,6 +128,7 @@ function clientFactory(params) {
119
128
  bucketingKey: bucketingKey,
120
129
  label: label,
121
130
  changeNumber: changeNumber,
131
+ properties: properties
122
132
  },
123
133
  disabled: impressionsDisabled
124
134
  });
@@ -18,40 +18,35 @@ function clientAttributesDecoration(log, client) {
18
18
  var clientGetTreatmentsWithConfigByFlagSets = client.getTreatmentsWithConfigByFlagSets;
19
19
  var clientGetTreatmentsByFlagSet = client.getTreatmentsByFlagSet;
20
20
  var clientGetTreatmentsWithConfigByFlagSet = client.getTreatmentsWithConfigByFlagSet;
21
- var clientTrack = client.track;
22
- function getTreatment(maybeKey, maybeFeatureFlagName, maybeAttributes) {
23
- return clientGetTreatment(maybeKey, maybeFeatureFlagName, combineAttributes(maybeAttributes));
21
+ function getTreatment(maybeKey, maybeFeatureFlagName, maybeAttributes, maybeOptions) {
22
+ return clientGetTreatment(maybeKey, maybeFeatureFlagName, combineAttributes(maybeAttributes), maybeOptions);
24
23
  }
25
- function getTreatmentWithConfig(maybeKey, maybeFeatureFlagName, maybeAttributes) {
26
- return clientGetTreatmentWithConfig(maybeKey, maybeFeatureFlagName, combineAttributes(maybeAttributes));
24
+ function getTreatmentWithConfig(maybeKey, maybeFeatureFlagName, maybeAttributes, maybeOptions) {
25
+ return clientGetTreatmentWithConfig(maybeKey, maybeFeatureFlagName, combineAttributes(maybeAttributes), maybeOptions);
27
26
  }
28
- function getTreatments(maybeKey, maybeFeatureFlagNames, maybeAttributes) {
29
- return clientGetTreatments(maybeKey, maybeFeatureFlagNames, combineAttributes(maybeAttributes));
27
+ function getTreatments(maybeKey, maybeFeatureFlagNames, maybeAttributes, maybeOptions) {
28
+ return clientGetTreatments(maybeKey, maybeFeatureFlagNames, combineAttributes(maybeAttributes), maybeOptions);
30
29
  }
31
- function getTreatmentsWithConfig(maybeKey, maybeFeatureFlagNames, maybeAttributes) {
32
- return clientGetTreatmentsWithConfig(maybeKey, maybeFeatureFlagNames, combineAttributes(maybeAttributes));
30
+ function getTreatmentsWithConfig(maybeKey, maybeFeatureFlagNames, maybeAttributes, maybeOptions) {
31
+ return clientGetTreatmentsWithConfig(maybeKey, maybeFeatureFlagNames, combineAttributes(maybeAttributes), maybeOptions);
33
32
  }
34
- function getTreatmentsByFlagSets(maybeKey, maybeFlagSets, maybeAttributes) {
35
- return clientGetTreatmentsByFlagSets(maybeKey, maybeFlagSets, combineAttributes(maybeAttributes));
33
+ function getTreatmentsByFlagSets(maybeKey, maybeFlagSets, maybeAttributes, maybeOptions) {
34
+ return clientGetTreatmentsByFlagSets(maybeKey, maybeFlagSets, combineAttributes(maybeAttributes), maybeOptions);
36
35
  }
37
- function getTreatmentsWithConfigByFlagSets(maybeKey, maybeFlagSets, maybeAttributes) {
38
- return clientGetTreatmentsWithConfigByFlagSets(maybeKey, maybeFlagSets, combineAttributes(maybeAttributes));
36
+ function getTreatmentsWithConfigByFlagSets(maybeKey, maybeFlagSets, maybeAttributes, maybeOptions) {
37
+ return clientGetTreatmentsWithConfigByFlagSets(maybeKey, maybeFlagSets, combineAttributes(maybeAttributes), maybeOptions);
39
38
  }
40
- function getTreatmentsByFlagSet(maybeKey, maybeFlagSet, maybeAttributes) {
41
- return clientGetTreatmentsByFlagSet(maybeKey, maybeFlagSet, combineAttributes(maybeAttributes));
39
+ function getTreatmentsByFlagSet(maybeKey, maybeFlagSet, maybeAttributes, maybeOptions) {
40
+ return clientGetTreatmentsByFlagSet(maybeKey, maybeFlagSet, combineAttributes(maybeAttributes), maybeOptions);
42
41
  }
43
- function getTreatmentsWithConfigByFlagSet(maybeKey, maybeFlagSet, maybeAttributes) {
44
- return clientGetTreatmentsWithConfigByFlagSet(maybeKey, maybeFlagSet, combineAttributes(maybeAttributes));
45
- }
46
- function track(maybeKey, maybeTT, maybeEvent, maybeEventValue, maybeProperties) {
47
- return clientTrack(maybeKey, maybeTT, maybeEvent, maybeEventValue, maybeProperties);
42
+ function getTreatmentsWithConfigByFlagSet(maybeKey, maybeFlagSet, maybeAttributes, maybeOptions) {
43
+ return clientGetTreatmentsWithConfigByFlagSet(maybeKey, maybeFlagSet, combineAttributes(maybeAttributes), maybeOptions);
48
44
  }
49
45
  function combineAttributes(maybeAttributes) {
50
46
  var storedAttributes = attributeStorage.getAll();
51
- if (Object.keys(storedAttributes).length > 0) {
52
- return (0, objectAssign_1.objectAssign)({}, storedAttributes, maybeAttributes);
53
- }
54
- return maybeAttributes;
47
+ return Object.keys(storedAttributes).length > 0 ?
48
+ (0, objectAssign_1.objectAssign)({}, storedAttributes, maybeAttributes) :
49
+ maybeAttributes;
55
50
  }
56
51
  return (0, objectAssign_1.objectAssign)(client, {
57
52
  getTreatment: getTreatment,
@@ -62,7 +57,6 @@ function clientAttributesDecoration(log, client) {
62
57
  getTreatmentsWithConfigByFlagSets: getTreatmentsWithConfigByFlagSets,
63
58
  getTreatmentsByFlagSet: getTreatmentsByFlagSet,
64
59
  getTreatmentsWithConfigByFlagSet: getTreatmentsWithConfigByFlagSet,
65
- track: track,
66
60
  /**
67
61
  * Add an attribute to client's in memory attributes storage
68
62
  *
@@ -17,7 +17,7 @@ function clientInputValidationDecorator(settings, client, readinessManager) {
17
17
  /**
18
18
  * Avoid repeating this validations code
19
19
  */
20
- function validateEvaluationParams(maybeKey, maybeNameOrNames, maybeAttributes, methodName) {
20
+ function validateEvaluationParams(methodName, maybeKey, maybeNameOrNames, maybeAttributes, maybeOptions) {
21
21
  var key = (0, inputValidation_1.validateKey)(log, maybeKey, methodName);
22
22
  var nameOrNames = methodName.indexOf('ByFlagSet') > -1 ?
23
23
  (0, splitFilters_1.validateFlagSets)(log, methodName, maybeNameOrNames, settings.sync.__splitFiltersValidation.groupedFilters.bySet) :
@@ -26,40 +26,42 @@ function clientInputValidationDecorator(settings, client, readinessManager) {
26
26
  (0, inputValidation_1.validateSplit)(log, maybeNameOrNames, methodName);
27
27
  var attributes = (0, inputValidation_1.validateAttributes)(log, maybeAttributes, methodName);
28
28
  var isNotDestroyed = (0, inputValidation_1.validateIfNotDestroyed)(log, readinessManager, methodName);
29
+ var options = (0, inputValidation_1.validateEvaluationOptions)(log, maybeOptions, methodName);
29
30
  (0, inputValidation_1.validateIfOperational)(log, readinessManager, methodName, nameOrNames);
30
31
  var valid = isNotDestroyed && key && nameOrNames && attributes !== false;
31
32
  return {
32
33
  valid: valid,
33
34
  key: key,
34
35
  nameOrNames: nameOrNames,
35
- attributes: attributes
36
+ attributes: attributes,
37
+ options: options
36
38
  };
37
39
  }
38
40
  function wrapResult(value) {
39
41
  return isAsync ? Promise.resolve(value) : value;
40
42
  }
41
- function getTreatment(maybeKey, maybeFeatureFlagName, maybeAttributes) {
42
- var params = validateEvaluationParams(maybeKey, maybeFeatureFlagName, maybeAttributes, constants_1.GET_TREATMENT);
43
+ function getTreatment(maybeKey, maybeFeatureFlagName, maybeAttributes, maybeOptions) {
44
+ var params = validateEvaluationParams(constants_1.GET_TREATMENT, maybeKey, maybeFeatureFlagName, maybeAttributes, maybeOptions);
43
45
  if (params.valid) {
44
- return client.getTreatment(params.key, params.nameOrNames, params.attributes);
46
+ return client.getTreatment(params.key, params.nameOrNames, params.attributes, params.options);
45
47
  }
46
48
  else {
47
49
  return wrapResult(constants_1.CONTROL);
48
50
  }
49
51
  }
50
- function getTreatmentWithConfig(maybeKey, maybeFeatureFlagName, maybeAttributes) {
51
- var params = validateEvaluationParams(maybeKey, maybeFeatureFlagName, maybeAttributes, constants_1.GET_TREATMENT_WITH_CONFIG);
52
+ function getTreatmentWithConfig(maybeKey, maybeFeatureFlagName, maybeAttributes, maybeOptions) {
53
+ var params = validateEvaluationParams(constants_1.GET_TREATMENT_WITH_CONFIG, maybeKey, maybeFeatureFlagName, maybeAttributes, maybeOptions);
52
54
  if (params.valid) {
53
- return client.getTreatmentWithConfig(params.key, params.nameOrNames, params.attributes);
55
+ return client.getTreatmentWithConfig(params.key, params.nameOrNames, params.attributes, params.options);
54
56
  }
55
57
  else {
56
58
  return wrapResult((0, objectAssign_1.objectAssign)({}, constants_1.CONTROL_WITH_CONFIG));
57
59
  }
58
60
  }
59
- function getTreatments(maybeKey, maybeFeatureFlagNames, maybeAttributes) {
60
- var params = validateEvaluationParams(maybeKey, maybeFeatureFlagNames, maybeAttributes, constants_1.GET_TREATMENTS);
61
+ function getTreatments(maybeKey, maybeFeatureFlagNames, maybeAttributes, maybeOptions) {
62
+ var params = validateEvaluationParams(constants_1.GET_TREATMENTS, maybeKey, maybeFeatureFlagNames, maybeAttributes, maybeOptions);
61
63
  if (params.valid) {
62
- return client.getTreatments(params.key, params.nameOrNames, params.attributes);
64
+ return client.getTreatments(params.key, params.nameOrNames, params.attributes, params.options);
63
65
  }
64
66
  else {
65
67
  var res_1 = {};
@@ -68,10 +70,10 @@ function clientInputValidationDecorator(settings, client, readinessManager) {
68
70
  return wrapResult(res_1);
69
71
  }
70
72
  }
71
- function getTreatmentsWithConfig(maybeKey, maybeFeatureFlagNames, maybeAttributes) {
72
- var params = validateEvaluationParams(maybeKey, maybeFeatureFlagNames, maybeAttributes, constants_1.GET_TREATMENTS_WITH_CONFIG);
73
+ function getTreatmentsWithConfig(maybeKey, maybeFeatureFlagNames, maybeAttributes, maybeOptions) {
74
+ var params = validateEvaluationParams(constants_1.GET_TREATMENTS_WITH_CONFIG, maybeKey, maybeFeatureFlagNames, maybeAttributes, maybeOptions);
73
75
  if (params.valid) {
74
- return client.getTreatmentsWithConfig(params.key, params.nameOrNames, params.attributes);
76
+ return client.getTreatmentsWithConfig(params.key, params.nameOrNames, params.attributes, params.options);
75
77
  }
76
78
  else {
77
79
  var res_2 = {};
@@ -80,37 +82,37 @@ function clientInputValidationDecorator(settings, client, readinessManager) {
80
82
  return wrapResult(res_2);
81
83
  }
82
84
  }
83
- function getTreatmentsByFlagSets(maybeKey, maybeFlagSets, maybeAttributes) {
84
- var params = validateEvaluationParams(maybeKey, maybeFlagSets, maybeAttributes, constants_1.GET_TREATMENTS_BY_FLAG_SETS);
85
+ function getTreatmentsByFlagSets(maybeKey, maybeFlagSets, maybeAttributes, maybeOptions) {
86
+ var params = validateEvaluationParams(constants_1.GET_TREATMENTS_BY_FLAG_SETS, maybeKey, maybeFlagSets, maybeAttributes, maybeOptions);
85
87
  if (params.valid) {
86
- return client.getTreatmentsByFlagSets(params.key, params.nameOrNames, params.attributes);
88
+ return client.getTreatmentsByFlagSets(params.key, params.nameOrNames, params.attributes, params.options);
87
89
  }
88
90
  else {
89
91
  return wrapResult({});
90
92
  }
91
93
  }
92
- function getTreatmentsWithConfigByFlagSets(maybeKey, maybeFlagSets, maybeAttributes) {
93
- var params = validateEvaluationParams(maybeKey, maybeFlagSets, maybeAttributes, constants_1.GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SETS);
94
+ function getTreatmentsWithConfigByFlagSets(maybeKey, maybeFlagSets, maybeAttributes, maybeOptions) {
95
+ var params = validateEvaluationParams(constants_1.GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SETS, maybeKey, maybeFlagSets, maybeAttributes, maybeOptions);
94
96
  if (params.valid) {
95
- return client.getTreatmentsWithConfigByFlagSets(params.key, params.nameOrNames, params.attributes);
97
+ return client.getTreatmentsWithConfigByFlagSets(params.key, params.nameOrNames, params.attributes, params.options);
96
98
  }
97
99
  else {
98
100
  return wrapResult({});
99
101
  }
100
102
  }
101
- function getTreatmentsByFlagSet(maybeKey, maybeFlagSet, maybeAttributes) {
102
- var params = validateEvaluationParams(maybeKey, [maybeFlagSet], maybeAttributes, constants_1.GET_TREATMENTS_BY_FLAG_SET);
103
+ function getTreatmentsByFlagSet(maybeKey, maybeFlagSet, maybeAttributes, maybeOptions) {
104
+ var params = validateEvaluationParams(constants_1.GET_TREATMENTS_BY_FLAG_SET, maybeKey, [maybeFlagSet], maybeAttributes, maybeOptions);
103
105
  if (params.valid) {
104
- return client.getTreatmentsByFlagSet(params.key, params.nameOrNames[0], params.attributes);
106
+ return client.getTreatmentsByFlagSet(params.key, params.nameOrNames[0], params.attributes, params.options);
105
107
  }
106
108
  else {
107
109
  return wrapResult({});
108
110
  }
109
111
  }
110
- function getTreatmentsWithConfigByFlagSet(maybeKey, maybeFlagSet, maybeAttributes) {
111
- var params = validateEvaluationParams(maybeKey, [maybeFlagSet], maybeAttributes, constants_1.GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SET);
112
+ function getTreatmentsWithConfigByFlagSet(maybeKey, maybeFlagSet, maybeAttributes, maybeOptions) {
113
+ var params = validateEvaluationParams(constants_1.GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SET, maybeKey, [maybeFlagSet], maybeAttributes, maybeOptions);
112
114
  if (params.valid) {
113
- return client.getTreatmentsWithConfigByFlagSet(params.key, params.nameOrNames[0], params.attributes);
115
+ return client.getTreatmentsWithConfigByFlagSet(params.key, params.nameOrNames[0], params.attributes, params.options);
114
116
  }
115
117
  else {
116
118
  return wrapResult({});
@@ -9,6 +9,17 @@ var objectAssign_1 = require("../utils/lang/objectAssign");
9
9
  var AbstractSplitsCacheAsync = /** @class */ (function () {
10
10
  function AbstractSplitsCacheAsync() {
11
11
  }
12
+ AbstractSplitsCacheAsync.prototype.update = function (toAdd, toRemove, changeNumber) {
13
+ var _this = this;
14
+ return Promise.all([
15
+ this.setChangeNumber(changeNumber),
16
+ Promise.all(toAdd.map(function (addedFF) { return _this.addSplit(addedFF); })),
17
+ Promise.all(toRemove.map(function (removedFF) { return _this.removeSplit(removedFF.name); }))
18
+ ]).then(function (_a) {
19
+ var added = _a[1], removed = _a[2];
20
+ return added.some(function (result) { return result; }) || removed.some(function (result) { return result; });
21
+ });
22
+ };
12
23
  // @TODO revisit segment-related methods ('usesSegments', 'getRegisteredSegments', 'registerSegments')
13
24
  // noop, just keeping the interface. This is used by standalone client-side API only, and so only implemented by InMemory and InLocalStorage.
14
25
  AbstractSplitsCacheAsync.prototype.usesSegments = function () {
@@ -37,7 +48,7 @@ var AbstractSplitsCacheAsync = /** @class */ (function () {
37
48
  newSplit.killed = true;
38
49
  newSplit.defaultTreatment = defaultTreatment;
39
50
  newSplit.changeNumber = changeNumber;
40
- return _this.addSplit(name, newSplit);
51
+ return _this.addSplit(newSplit);
41
52
  }
42
53
  return false;
43
54
  }).catch(function () { return false; });
@@ -10,13 +10,11 @@ var constants_1 = require("../utils/constants");
10
10
  var AbstractSplitsCacheSync = /** @class */ (function () {
11
11
  function AbstractSplitsCacheSync() {
12
12
  }
13
- AbstractSplitsCacheSync.prototype.addSplits = function (entries) {
13
+ AbstractSplitsCacheSync.prototype.update = function (toAdd, toRemove, changeNumber) {
14
14
  var _this = this;
15
- return entries.map(function (keyValuePair) { return _this.addSplit(keyValuePair[0], keyValuePair[1]); });
16
- };
17
- AbstractSplitsCacheSync.prototype.removeSplits = function (names) {
18
- var _this = this;
19
- return names.map(function (name) { return _this.removeSplit(name); });
15
+ this.setChangeNumber(changeNumber);
16
+ var updated = toAdd.map(function (addedFF) { return _this.addSplit(addedFF); }).some(function (result) { return result; });
17
+ return toRemove.map(function (removedFF) { return _this.removeSplit(removedFF.name); }).some(function (result) { return result; }) || updated;
20
18
  };
21
19
  AbstractSplitsCacheSync.prototype.getSplits = function (names) {
22
20
  var _this = this;
@@ -51,7 +49,7 @@ var AbstractSplitsCacheSync = /** @class */ (function () {
51
49
  newSplit.killed = true;
52
50
  newSplit.defaultTreatment = defaultTreatment;
53
51
  newSplit.changeNumber = changeNumber;
54
- return this.addSplit(name, newSplit);
52
+ return this.addSplit(newSplit);
55
53
  }
56
54
  return false;
57
55
  };
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getStorageHash = exports.KeyBuilder = exports.validatePrefix = void 0;
4
- var lang_1 = require("../utils/lang");
5
4
  var murmur3_1 = require("../utils/murmur3/murmur3");
6
5
  var everythingAtTheEnd = /[^.]+$/;
7
6
  var DEFAULT_PREFIX = 'SPLITIO';
@@ -26,30 +25,15 @@ var KeyBuilder = /** @class */ (function () {
26
25
  KeyBuilder.prototype.buildSplitsTillKey = function () {
27
26
  return this.prefix + ".splits.till";
28
27
  };
29
- // NOT USED
30
- // buildSplitsReady() {
31
- // return `${this.prefix}.splits.ready`;
32
- // }
33
- KeyBuilder.prototype.isSplitKey = function (key) {
34
- return (0, lang_1.startsWith)(key, this.prefix + ".split.");
35
- };
36
28
  KeyBuilder.prototype.buildSplitKeyPrefix = function () {
37
29
  return this.prefix + ".split.";
38
30
  };
39
- // Only used by InLocalStorage.
40
- KeyBuilder.prototype.buildSplitsWithSegmentCountKey = function () {
41
- return this.prefix + ".splits.usingSegments";
42
- };
43
31
  KeyBuilder.prototype.buildSegmentNameKey = function (segmentName) {
44
32
  return this.prefix + ".segment." + segmentName;
45
33
  };
46
34
  KeyBuilder.prototype.buildSegmentTillKey = function (segmentName) {
47
35
  return this.prefix + ".segment." + segmentName + ".till";
48
36
  };
49
- // NOT USED
50
- // buildSegmentsReady() {
51
- // return `${this.prefix}.segments.ready`;
52
- // }
53
37
  KeyBuilder.prototype.extractKey = function (builtKey) {
54
38
  var s = builtKey.match(everythingAtTheEnd);
55
39
  if (s && s.length) {
@@ -21,7 +21,7 @@ var KeyBuilderCS = /** @class */ (function (_super) {
21
21
  KeyBuilderCS.prototype.extractSegmentName = function (builtSegmentKeyName) {
22
22
  var prefix = this.prefix + "." + this.matchingKey + ".segment.";
23
23
  if ((0, lang_1.startsWith)(builtSegmentKeyName, prefix))
24
- return builtSegmentKeyName.substr(prefix.length);
24
+ return builtSegmentKeyName.slice(prefix.length);
25
25
  };
26
26
  KeyBuilderCS.prototype.buildLastUpdatedKey = function () {
27
27
  return this.prefix + ".splits.lastUpdated";
@@ -32,6 +32,12 @@ var KeyBuilderCS = /** @class */ (function (_super) {
32
32
  KeyBuilderCS.prototype.buildTillKey = function () {
33
33
  return this.prefix + "." + this.matchingKey + ".segments.till";
34
34
  };
35
+ KeyBuilderCS.prototype.isSplitKey = function (key) {
36
+ return (0, lang_1.startsWith)(key, this.prefix + ".split.");
37
+ };
38
+ KeyBuilderCS.prototype.buildSplitsWithSegmentCountKey = function () {
39
+ return this.prefix + ".splits.usingSegments";
40
+ };
35
41
  return KeyBuilderCS;
36
42
  }(KeyBuilder_1.KeyBuilder));
37
43
  exports.KeyBuilderCS = KeyBuilderCS;
@@ -43,7 +49,7 @@ function myLargeSegmentsKeyBuilder(prefix, matchingKey) {
43
49
  extractSegmentName: function (builtSegmentKeyName) {
44
50
  var p = prefix + "." + matchingKey + ".largeSegment.";
45
51
  if ((0, lang_1.startsWith)(builtSegmentKeyName, p))
46
- return builtSegmentKeyName.substr(p.length);
52
+ return builtSegmentKeyName.slice(p.length);
47
53
  },
48
54
  buildTillKey: function () {
49
55
  return prefix + "." + matchingKey + ".largeSegments.till";
@@ -32,9 +32,8 @@ function dataLoaderFactory(preloadedData) {
32
32
  return;
33
33
  // cleaning up the localStorage data, since some cached splits might need be part of the preloaded data
34
34
  storage.splits.clear();
35
- storage.splits.setChangeNumber(since);
36
35
  // splitsData in an object where the property is the split name and the pertaining value is a stringified json of its data
37
- storage.splits.addSplits(Object.keys(splitsData).map(function (splitName) { return JSON.parse(splitsData[splitName]); }));
36
+ storage.splits.update(Object.keys(splitsData).map(function (splitName) { return JSON.parse(splitsData[splitName]); }), [], since);
38
37
  // add mySegments data
39
38
  var mySegmentsData = preloadedData.mySegmentsData && preloadedData.mySegmentsData[userId];
40
39
  if (!mySegmentsData) {
@@ -82,9 +82,10 @@ var SplitsCacheInLocal = /** @class */ (function (_super) {
82
82
  });
83
83
  this.hasSync = false;
84
84
  };
85
- SplitsCacheInLocal.prototype.addSplit = function (name, split) {
85
+ SplitsCacheInLocal.prototype.addSplit = function (split) {
86
86
  try {
87
- var splitKey = this.keys.buildSplitKey(name);
87
+ var name_1 = split.name;
88
+ var splitKey = this.keys.buildSplitKey(name_1);
88
89
  var splitFromLocalStorage = localStorage.getItem(splitKey);
89
90
  var previousSplit = splitFromLocalStorage ? JSON.parse(splitFromLocalStorage) : null;
90
91
  localStorage.setItem(splitKey, JSON.stringify(split));
@@ -103,6 +104,8 @@ var SplitsCacheInLocal = /** @class */ (function (_super) {
103
104
  SplitsCacheInLocal.prototype.removeSplit = function (name) {
104
105
  try {
105
106
  var split = this.getSplit(name);
107
+ if (!split)
108
+ return false;
106
109
  localStorage.removeItem(this.keys.buildSplitKey(name));
107
110
  this._decrementCounts(split);
108
111
  if (split)
@@ -25,7 +25,8 @@ var SplitsCacheInMemory = /** @class */ (function (_super) {
25
25
  this.changeNumber = -1;
26
26
  this.segmentsCount = 0;
27
27
  };
28
- SplitsCacheInMemory.prototype.addSplit = function (name, split) {
28
+ SplitsCacheInMemory.prototype.addSplit = function (split) {
29
+ var name = split.name;
29
30
  var previousSplit = this.getSplit(name);
30
31
  if (previousSplit) { // We had this Split already
31
32
  var previousTtName = previousSplit.trafficTypeName;
@@ -37,40 +38,32 @@ var SplitsCacheInMemory = /** @class */ (function (_super) {
37
38
  if ((0, AbstractSplitsCacheSync_1.usesSegments)(previousSplit))
38
39
  this.segmentsCount--;
39
40
  }
40
- if (split) {
41
- // Store the Split.
42
- this.splitsCache[name] = split;
43
- // Update TT cache
44
- var ttName = split.trafficTypeName;
45
- this.ttCache[ttName] = (this.ttCache[ttName] || 0) + 1;
46
- this.addToFlagSets(split);
47
- // Add to segments count for the new version of the Split
48
- if ((0, AbstractSplitsCacheSync_1.usesSegments)(split))
49
- this.segmentsCount++;
50
- return true;
51
- }
52
- else {
53
- return false;
54
- }
41
+ // Store the Split.
42
+ this.splitsCache[name] = split;
43
+ // Update TT cache
44
+ var ttName = split.trafficTypeName;
45
+ this.ttCache[ttName] = (this.ttCache[ttName] || 0) + 1;
46
+ this.addToFlagSets(split);
47
+ // Add to segments count for the new version of the Split
48
+ if ((0, AbstractSplitsCacheSync_1.usesSegments)(split))
49
+ this.segmentsCount++;
50
+ return true;
55
51
  };
56
52
  SplitsCacheInMemory.prototype.removeSplit = function (name) {
57
53
  var split = this.getSplit(name);
58
- if (split) {
59
- // Delete the Split
60
- delete this.splitsCache[name];
61
- var ttName = split.trafficTypeName;
62
- this.ttCache[ttName]--; // Update tt cache
63
- if (!this.ttCache[ttName])
64
- delete this.ttCache[ttName];
65
- this.removeFromFlagSets(split.name, split.sets);
66
- // Update the segments count.
67
- if ((0, AbstractSplitsCacheSync_1.usesSegments)(split))
68
- this.segmentsCount--;
69
- return true;
70
- }
71
- else {
54
+ if (!split)
72
55
  return false;
73
- }
56
+ // Delete the Split
57
+ delete this.splitsCache[name];
58
+ var ttName = split.trafficTypeName;
59
+ this.ttCache[ttName]--; // Update tt cache
60
+ if (!this.ttCache[ttName])
61
+ delete this.ttCache[ttName];
62
+ this.removeFromFlagSets(split.name, split.sets);
63
+ // Update the segments count.
64
+ if ((0, AbstractSplitsCacheSync_1.usesSegments)(split))
65
+ this.segmentsCount--;
66
+ return true;
74
67
  };
75
68
  SplitsCacheInMemory.prototype.getSplit = function (name) {
76
69
  return this.splitsCache[name] || null;