@splitsoftware/splitio-commons 3.1.1-rc.10 → 3.1.1-rc.11

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 (208) hide show
  1. package/CHANGES.txt +2 -0
  2. package/cjs/evaluator/condition/index.js +2 -2
  3. package/cjs/evaluator/fallbackTreatmentsCalculator/fallbackSanitizer/index.js +5 -8
  4. package/cjs/evaluator/index.js +81 -71
  5. package/cjs/listeners/browser.js +2 -1
  6. package/cjs/listeners/node.js +4 -4
  7. package/cjs/logger/constants.js +15 -20
  8. package/cjs/logger/messages/debug.js +5 -6
  9. package/cjs/logger/messages/error.js +3 -3
  10. package/cjs/logger/messages/info.js +3 -4
  11. package/cjs/logger/messages/warn.js +6 -7
  12. package/cjs/platform/browser.js +15 -0
  13. package/cjs/platform/getEventSource/browser.js +8 -0
  14. package/cjs/platform/getEventSource/eventsource.js +480 -0
  15. package/cjs/platform/getEventSource/node.js +26 -0
  16. package/cjs/platform/getFetch/browser.js +9 -0
  17. package/cjs/platform/getFetch/node.js +27 -0
  18. package/cjs/platform/getOptions/node.js +25 -0
  19. package/cjs/platform/node.js +17 -0
  20. package/cjs/presets/serverSide.js +2 -2
  21. package/cjs/readiness/constants.js +5 -4
  22. package/cjs/readiness/readinessManager.js +23 -23
  23. package/cjs/readiness/sdkReadinessManager.js +1 -17
  24. package/cjs/sdkClient/client.js +24 -50
  25. package/cjs/sdkClient/clientInputValidation.js +6 -17
  26. package/cjs/sdkClient/sdkClient.js +3 -60
  27. package/cjs/sdkClient/sdkLifecycle.js +74 -0
  28. package/cjs/sdkClient/trackMethod.js +56 -0
  29. package/cjs/sdkFactory/index.js +11 -15
  30. package/cjs/sdkManager/index.js +5 -5
  31. package/cjs/services/authProvider.js +80 -0
  32. package/cjs/services/decorateHeaders.js +2 -1
  33. package/cjs/services/secureSplitHttpClient.js +36 -0
  34. package/cjs/services/serviceApi.js +147 -0
  35. package/cjs/services/splitApi.js +24 -10
  36. package/cjs/services/splitHttpClient.js +3 -5
  37. package/cjs/storages/AbstractDefinitionsCacheAsync.js +51 -0
  38. package/cjs/storages/AbstractDefinitionsCacheSync.js +76 -0
  39. package/cjs/storages/KeyBuilder.js +6 -6
  40. package/cjs/storages/KeyBuilderCS.js +5 -5
  41. package/cjs/storages/KeyBuilderSS.js +2 -2
  42. package/cjs/storages/getRolloutPlan.js +3 -3
  43. package/cjs/storages/inLocalStorage/DefinitionsCacheInLocal.js +194 -0
  44. package/cjs/storages/inLocalStorage/MySegmentsCacheInLocal.js +1 -2
  45. package/cjs/storages/inLocalStorage/RBSegmentsCacheInLocal.js +10 -10
  46. package/cjs/storages/inLocalStorage/index.js +6 -6
  47. package/cjs/storages/inLocalStorage/validateCache.js +3 -3
  48. package/cjs/storages/inMemory/DefinitionsCacheInMemory.js +121 -0
  49. package/cjs/storages/inMemory/InMemoryStorage.js +4 -4
  50. package/cjs/storages/inMemory/InMemoryStorageCS.js +5 -5
  51. package/cjs/storages/inMemory/RBSegmentsCacheInMemory.js +5 -5
  52. package/cjs/storages/inMemory/SegmentsCacheInMemory.js +1 -1
  53. package/cjs/storages/inMemory/TelemetryCacheInMemory.js +5 -5
  54. package/cjs/storages/inRedis/{SplitsCacheInRedis.js → DefinitionsCacheInRedis.js} +77 -77
  55. package/cjs/storages/inRedis/RBSegmentsCacheInRedis.js +1 -1
  56. package/cjs/storages/inRedis/index.js +2 -2
  57. package/cjs/storages/pluggable/DefinitionsCachePluggable.js +212 -0
  58. package/cjs/storages/pluggable/RBSegmentsCachePluggable.js +1 -1
  59. package/cjs/storages/pluggable/index.js +2 -2
  60. package/cjs/storages/setRolloutPlan.js +4 -4
  61. package/cjs/storages/utils.js +1 -0
  62. package/cjs/sync/offline/syncTasks/fromObjectSyncTask.js +5 -5
  63. package/cjs/sync/polling/fetchers/splitChangesFetcher.js +24 -15
  64. package/cjs/sync/polling/pollingManagerCS.js +86 -81
  65. package/cjs/sync/polling/pollingManagerSS.js +44 -36
  66. package/cjs/sync/polling/syncTasks/definitionsSyncTask.js +13 -0
  67. package/cjs/sync/polling/syncTasks/segmentsSyncTask.js +2 -3
  68. package/cjs/sync/polling/updaters/{splitChangesUpdater.js → definitionChangesUpdater.js} +66 -69
  69. package/cjs/sync/polling/updaters/mySegmentsUpdater.js +3 -3
  70. package/cjs/sync/polling/updaters/segmentChangesUpdater.js +6 -6
  71. package/cjs/sync/streaming/AuthClient/index.js +13 -14
  72. package/cjs/sync/streaming/SSEHandler/NotificationKeeper.js +1 -1
  73. package/cjs/sync/streaming/SSEHandler/index.js +2 -1
  74. package/cjs/sync/streaming/UpdateWorkers/{SplitsUpdateWorker.js → DefinitionsUpdateWorker.js} +16 -19
  75. package/cjs/sync/streaming/constants.js +4 -3
  76. package/cjs/sync/streaming/parseUtils.js +11 -11
  77. package/cjs/sync/streaming/pushManager.js +20 -25
  78. package/cjs/sync/submitters/eventsSubmitter.js +1 -1
  79. package/cjs/sync/submitters/impressionCountsSubmitter.js +1 -1
  80. package/cjs/sync/submitters/impressionsSubmitter.js +5 -4
  81. package/cjs/sync/submitters/telemetrySubmitter.js +3 -4
  82. package/cjs/sync/submitters/uniqueKeysSubmitter.js +1 -1
  83. package/cjs/sync/syncManagerOnline.js +5 -5
  84. package/cjs/utils/Backoff.js +35 -3
  85. package/cjs/utils/EventEmitter.js +391 -0
  86. package/cjs/utils/filter/bloomFilter.js +37 -0
  87. package/cjs/utils/inputValidation/{split.js → definition.js} +10 -10
  88. package/cjs/utils/inputValidation/{splitExistence.js → definitionExistence.js} +6 -6
  89. package/cjs/utils/inputValidation/definitions.js +25 -0
  90. package/cjs/utils/inputValidation/index.js +7 -7
  91. package/cjs/utils/inputValidation/isOperational.js +4 -4
  92. package/cjs/utils/inputValidation/target.js +22 -0
  93. package/cjs/utils/labels/index.js +3 -3
  94. package/cjs/utils/settingsValidation/index.js +2 -0
  95. package/cjs/utils/settingsValidation/splitFilters.js +3 -3
  96. package/cjs/utils/settingsValidation/url.js +6 -2
  97. package/esm/evaluator/condition/index.js +2 -2
  98. package/esm/evaluator/fallbackTreatmentsCalculator/fallbackSanitizer/index.js +5 -8
  99. package/esm/evaluator/index.js +80 -71
  100. package/esm/listeners/browser.js +2 -1
  101. package/esm/listeners/node.js +4 -4
  102. package/esm/logger/constants.js +12 -17
  103. package/esm/logger/messages/debug.js +5 -6
  104. package/esm/logger/messages/error.js +3 -3
  105. package/esm/logger/messages/info.js +3 -4
  106. package/esm/logger/messages/warn.js +6 -7
  107. package/esm/platform/browser.js +12 -0
  108. package/esm/platform/getEventSource/browser.js +4 -0
  109. package/esm/platform/getEventSource/eventsource.js +480 -0
  110. package/esm/platform/getEventSource/node.js +20 -0
  111. package/esm/platform/getFetch/browser.js +5 -0
  112. package/esm/platform/getFetch/node.js +22 -0
  113. package/esm/platform/getOptions/node.js +20 -0
  114. package/esm/platform/node.js +14 -0
  115. package/esm/presets/serverSide.js +2 -2
  116. package/esm/readiness/constants.js +4 -3
  117. package/esm/readiness/readinessManager.js +24 -24
  118. package/esm/readiness/sdkReadinessManager.js +2 -18
  119. package/esm/sdkClient/client.js +23 -50
  120. package/esm/sdkClient/clientInputValidation.js +8 -19
  121. package/esm/sdkClient/sdkClient.js +3 -60
  122. package/esm/sdkClient/sdkLifecycle.js +70 -0
  123. package/esm/sdkClient/trackMethod.js +52 -0
  124. package/esm/sdkFactory/index.js +12 -16
  125. package/esm/sdkManager/index.js +6 -6
  126. package/esm/services/authProvider.js +76 -0
  127. package/esm/services/decorateHeaders.js +2 -1
  128. package/esm/services/secureSplitHttpClient.js +32 -0
  129. package/esm/services/serviceApi.js +143 -0
  130. package/esm/services/splitApi.js +24 -10
  131. package/esm/services/splitHttpClient.js +3 -5
  132. package/esm/storages/AbstractDefinitionsCacheAsync.js +48 -0
  133. package/esm/storages/AbstractDefinitionsCacheSync.js +71 -0
  134. package/esm/storages/KeyBuilder.js +6 -6
  135. package/esm/storages/KeyBuilderCS.js +5 -5
  136. package/esm/storages/KeyBuilderSS.js +2 -2
  137. package/esm/storages/getRolloutPlan.js +3 -3
  138. package/esm/storages/inLocalStorage/DefinitionsCacheInLocal.js +191 -0
  139. package/esm/storages/inLocalStorage/MySegmentsCacheInLocal.js +1 -2
  140. package/esm/storages/inLocalStorage/RBSegmentsCacheInLocal.js +7 -7
  141. package/esm/storages/inLocalStorage/index.js +6 -6
  142. package/esm/storages/inLocalStorage/validateCache.js +3 -3
  143. package/esm/storages/inMemory/DefinitionsCacheInMemory.js +118 -0
  144. package/esm/storages/inMemory/InMemoryStorage.js +4 -4
  145. package/esm/storages/inMemory/InMemoryStorageCS.js +5 -5
  146. package/esm/storages/inMemory/RBSegmentsCacheInMemory.js +2 -2
  147. package/esm/storages/inMemory/SegmentsCacheInMemory.js +1 -1
  148. package/esm/storages/inMemory/TelemetryCacheInMemory.js +5 -5
  149. package/esm/storages/inRedis/{SplitsCacheInRedis.js → DefinitionsCacheInRedis.js} +76 -76
  150. package/esm/storages/inRedis/RBSegmentsCacheInRedis.js +1 -1
  151. package/esm/storages/inRedis/index.js +2 -2
  152. package/esm/storages/pluggable/DefinitionsCachePluggable.js +209 -0
  153. package/esm/storages/pluggable/RBSegmentsCachePluggable.js +1 -1
  154. package/esm/storages/pluggable/index.js +2 -2
  155. package/esm/storages/setRolloutPlan.js +4 -4
  156. package/esm/storages/utils.js +1 -0
  157. package/esm/sync/offline/syncTasks/fromObjectSyncTask.js +6 -6
  158. package/esm/sync/polling/fetchers/splitChangesFetcher.js +25 -16
  159. package/esm/sync/polling/pollingManagerCS.js +87 -82
  160. package/esm/sync/polling/pollingManagerSS.js +44 -36
  161. package/esm/sync/polling/syncTasks/definitionsSyncTask.js +9 -0
  162. package/esm/sync/polling/syncTasks/segmentsSyncTask.js +2 -3
  163. package/esm/sync/polling/updaters/definitionChangesUpdater.js +191 -0
  164. package/esm/sync/polling/updaters/mySegmentsUpdater.js +3 -3
  165. package/esm/sync/polling/updaters/segmentChangesUpdater.js +7 -7
  166. package/esm/sync/streaming/AuthClient/index.js +11 -11
  167. package/esm/sync/streaming/SSEHandler/NotificationKeeper.js +2 -2
  168. package/esm/sync/streaming/SSEHandler/index.js +3 -2
  169. package/esm/sync/streaming/UpdateWorkers/{SplitsUpdateWorker.js → DefinitionsUpdateWorker.js} +15 -18
  170. package/esm/sync/streaming/constants.js +3 -2
  171. package/esm/sync/streaming/parseUtils.js +9 -9
  172. package/esm/sync/streaming/pushManager.js +22 -27
  173. package/esm/sync/submitters/eventsSubmitter.js +1 -1
  174. package/esm/sync/submitters/impressionCountsSubmitter.js +1 -1
  175. package/esm/sync/submitters/impressionsSubmitter.js +5 -4
  176. package/esm/sync/submitters/telemetrySubmitter.js +3 -4
  177. package/esm/sync/submitters/uniqueKeysSubmitter.js +1 -1
  178. package/esm/sync/syncManagerOnline.js +4 -4
  179. package/esm/utils/Backoff.js +35 -3
  180. package/esm/utils/EventEmitter.js +387 -0
  181. package/esm/utils/filter/bloomFilter.js +33 -0
  182. package/esm/utils/inputValidation/{split.js → definition.js} +8 -8
  183. package/esm/utils/inputValidation/definitionExistence.js +15 -0
  184. package/esm/utils/inputValidation/definitions.js +21 -0
  185. package/esm/utils/inputValidation/index.js +3 -3
  186. package/esm/utils/inputValidation/isOperational.js +4 -4
  187. package/esm/utils/inputValidation/target.js +18 -0
  188. package/esm/utils/labels/index.js +2 -2
  189. package/esm/utils/settingsValidation/index.js +2 -0
  190. package/esm/utils/settingsValidation/splitFilters.js +3 -3
  191. package/esm/utils/settingsValidation/url.js +6 -2
  192. package/package.json +1 -1
  193. package/cjs/storages/AbstractSplitsCacheAsync.js +0 -51
  194. package/cjs/storages/AbstractSplitsCacheSync.js +0 -76
  195. package/cjs/storages/inLocalStorage/SplitsCacheInLocal.js +0 -194
  196. package/cjs/storages/inMemory/SplitsCacheInMemory.js +0 -121
  197. package/cjs/storages/pluggable/SplitsCachePluggable.js +0 -212
  198. package/cjs/sync/polling/syncTasks/splitsSyncTask.js +0 -13
  199. package/cjs/utils/inputValidation/splits.js +0 -25
  200. package/esm/storages/AbstractSplitsCacheAsync.js +0 -48
  201. package/esm/storages/AbstractSplitsCacheSync.js +0 -71
  202. package/esm/storages/inLocalStorage/SplitsCacheInLocal.js +0 -191
  203. package/esm/storages/inMemory/SplitsCacheInMemory.js +0 -118
  204. package/esm/storages/pluggable/SplitsCachePluggable.js +0 -209
  205. package/esm/sync/polling/syncTasks/splitsSyncTask.js +0 -9
  206. package/esm/sync/polling/updaters/splitChangesUpdater.js +0 -194
  207. package/esm/utils/inputValidation/splitExistence.js +0 -15
  208. package/esm/utils/inputValidation/splits.js +0 -21
@@ -0,0 +1,387 @@
1
+ // Copyright Joyent, Inc. and other Node contributors.
2
+ //
3
+ // Permission is hereby granted, free of charge, to any person obtaining a
4
+ // copy of this software and associated documentation files (the
5
+ // "Software"), to deal in the Software without restriction, including
6
+ // without limitation the rights to use, copy, modify, merge, publish,
7
+ // distribute, sublicense, and/or sell copies of the Software, and to permit
8
+ // persons to whom the Software is furnished to do so, subject to the
9
+ // following conditions:
10
+ //
11
+ // The above copyright notice and this permission notice shall be included
12
+ // in all copies or substantial portions of the Software.
13
+ //
14
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15
+ // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17
+ // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18
+ // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19
+ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20
+ // USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+ // Adaptation of "events" library (https://www.npmjs.com/package/events)
22
+ // exported as an ES module instead of CommonJS, to avoid extra configuration steps when using
23
+ // the ESM build of the SDK with tools that doesn't support CommonJS by default (e.g. Rollup).
24
+ var R = typeof Reflect === 'object' ? Reflect : null;
25
+ var ReflectApply = R && typeof R.apply === 'function'
26
+ ? R.apply
27
+ : function ReflectApply(target, receiver, args) {
28
+ return Function.prototype.apply.call(target, receiver, args);
29
+ };
30
+ var ReflectOwnKeys;
31
+ if (R && typeof R.ownKeys === 'function') {
32
+ ReflectOwnKeys = R.ownKeys;
33
+ }
34
+ else if (Object.getOwnPropertySymbols) {
35
+ ReflectOwnKeys = function ReflectOwnKeys(target) {
36
+ return Object.getOwnPropertyNames(target)
37
+ .concat(Object.getOwnPropertySymbols(target));
38
+ };
39
+ }
40
+ else {
41
+ ReflectOwnKeys = function ReflectOwnKeys(target) {
42
+ return Object.getOwnPropertyNames(target);
43
+ };
44
+ }
45
+ function ProcessEmitWarning(warning) {
46
+ if (console && console.warn)
47
+ console.warn(warning);
48
+ }
49
+ // eslint-disable-next-line compat/compat
50
+ var NumberIsNaN = Number.isNaN || function NumberIsNaN(value) {
51
+ return value !== value;
52
+ };
53
+ export function EventEmitter() {
54
+ EventEmitter.init.call(this);
55
+ }
56
+ EventEmitter.prototype._events = undefined;
57
+ EventEmitter.prototype._eventsCount = 0;
58
+ EventEmitter.prototype._maxListeners = undefined;
59
+ // By default EventEmitters will print a warning if more than 10 listeners are
60
+ // added to it. This is a useful default which helps finding memory leaks.
61
+ var defaultMaxListeners = 10;
62
+ function checkListener(listener) {
63
+ if (typeof listener !== 'function') {
64
+ throw new TypeError('The "listener" argument must be of type Function. Received type ' + typeof listener);
65
+ }
66
+ }
67
+ Object.defineProperty(EventEmitter, 'defaultMaxListeners', {
68
+ enumerable: true,
69
+ get: function () {
70
+ return defaultMaxListeners;
71
+ },
72
+ set: function (arg) {
73
+ if (typeof arg !== 'number' || arg < 0 || NumberIsNaN(arg)) {
74
+ throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received ' + arg + '.');
75
+ }
76
+ defaultMaxListeners = arg;
77
+ }
78
+ });
79
+ EventEmitter.init = function () {
80
+ if (this._events === undefined ||
81
+ this._events === Object.getPrototypeOf(this)._events) {
82
+ this._events = Object.create(null);
83
+ this._eventsCount = 0;
84
+ }
85
+ this._maxListeners = this._maxListeners || undefined;
86
+ };
87
+ // Obviously not all Emitters should be limited to 10. This function allows
88
+ // that to be increased. Set to zero for unlimited.
89
+ EventEmitter.prototype.setMaxListeners = function setMaxListeners(n) {
90
+ if (typeof n !== 'number' || n < 0 || NumberIsNaN(n)) {
91
+ throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received ' + n + '.');
92
+ }
93
+ this._maxListeners = n;
94
+ return this;
95
+ };
96
+ function _getMaxListeners(that) {
97
+ if (that._maxListeners === undefined)
98
+ return EventEmitter.defaultMaxListeners;
99
+ return that._maxListeners;
100
+ }
101
+ EventEmitter.prototype.getMaxListeners = function getMaxListeners() {
102
+ return _getMaxListeners(this);
103
+ };
104
+ EventEmitter.prototype.emit = function emit(type) {
105
+ var args = [];
106
+ for (var i = 1; i < arguments.length; i++)
107
+ args.push(arguments[i]);
108
+ var doError = (type === 'error');
109
+ var events = this._events;
110
+ if (events !== undefined)
111
+ doError = (doError && events.error === undefined);
112
+ else if (!doError)
113
+ return false;
114
+ // If there is no 'error' event listener then throw.
115
+ if (doError) {
116
+ var er;
117
+ if (args.length > 0)
118
+ er = args[0];
119
+ if (er instanceof Error) {
120
+ // Note: The comments on the `throw` lines are intentional, they show
121
+ // up in Node.js output if this results in an unhandled exception.
122
+ throw er; // Unhandled 'error' event
123
+ }
124
+ // At least give some kind of context to the user
125
+ var err = new Error('Unhandled error.' + (er ? ' (' + er.message + ')' : ''));
126
+ err.context = er;
127
+ throw err; // Unhandled 'error' event
128
+ }
129
+ var handler = events[type];
130
+ if (handler === undefined)
131
+ return false;
132
+ if (typeof handler === 'function') {
133
+ ReflectApply(handler, this, args);
134
+ }
135
+ else {
136
+ var len = handler.length;
137
+ var listeners = arrayClone(handler, len); // eslint-disable-next-line no-redeclare
138
+ for (var i = 0; i < len; ++i)
139
+ ReflectApply(listeners[i], this, args);
140
+ }
141
+ return true;
142
+ };
143
+ function _addListener(target, type, listener, prepend) {
144
+ var m;
145
+ var events;
146
+ var existing;
147
+ checkListener(listener);
148
+ events = target._events;
149
+ if (events === undefined) {
150
+ events = target._events = Object.create(null);
151
+ target._eventsCount = 0;
152
+ }
153
+ else {
154
+ // To avoid recursion in the case that type === "newListener"! Before
155
+ // adding it to the listeners, first emit "newListener".
156
+ if (events.newListener !== undefined) {
157
+ target.emit('newListener', type, listener.listener ? listener.listener : listener);
158
+ // Re-assign `events` because a newListener handler could have caused the
159
+ // this._events to be assigned to a new object
160
+ events = target._events;
161
+ }
162
+ existing = events[type];
163
+ }
164
+ if (existing === undefined) {
165
+ // Optimize the case of one listener. Don't need the extra array object.
166
+ existing = events[type] = listener;
167
+ ++target._eventsCount;
168
+ }
169
+ else {
170
+ if (typeof existing === 'function') {
171
+ // Adding the second element, need to change to array.
172
+ existing = events[type] =
173
+ prepend ? [listener, existing] : [existing, listener];
174
+ // If we've already got an array, just append.
175
+ }
176
+ else if (prepend) {
177
+ existing.unshift(listener);
178
+ }
179
+ else {
180
+ existing.push(listener);
181
+ }
182
+ // Check for listener leak
183
+ m = _getMaxListeners(target);
184
+ if (m > 0 && existing.length > m && !existing.warned) {
185
+ existing.warned = true;
186
+ // No error code for this since it is a Warning
187
+ // eslint-disable-next-line no-restricted-syntax
188
+ var w = new Error('Possible EventEmitter memory leak detected. ' +
189
+ existing.length + ' ' + String(type) + ' listeners ' +
190
+ 'added. Use emitter.setMaxListeners() to ' +
191
+ 'increase limit');
192
+ w.name = 'MaxListenersExceededWarning';
193
+ w.emitter = target;
194
+ w.type = type;
195
+ w.count = existing.length;
196
+ ProcessEmitWarning(w);
197
+ }
198
+ }
199
+ return target;
200
+ }
201
+ EventEmitter.prototype.addListener = function addListener(type, listener) {
202
+ return _addListener(this, type, listener, false);
203
+ };
204
+ EventEmitter.prototype.on = EventEmitter.prototype.addListener;
205
+ EventEmitter.prototype.prependListener =
206
+ function prependListener(type, listener) {
207
+ return _addListener(this, type, listener, true);
208
+ };
209
+ function onceWrapper() {
210
+ if (!this.fired) {
211
+ this.target.removeListener(this.type, this.wrapFn);
212
+ this.fired = true;
213
+ if (arguments.length === 0)
214
+ return this.listener.call(this.target);
215
+ return this.listener.apply(this.target, arguments);
216
+ }
217
+ }
218
+ function _onceWrap(target, type, listener) {
219
+ var state = { fired: false, wrapFn: undefined, target: target, type: type, listener: listener };
220
+ var wrapped = onceWrapper.bind(state);
221
+ wrapped.listener = listener;
222
+ state.wrapFn = wrapped;
223
+ return wrapped;
224
+ }
225
+ EventEmitter.prototype.once = function once(type, listener) {
226
+ checkListener(listener);
227
+ this.on(type, _onceWrap(this, type, listener));
228
+ return this;
229
+ };
230
+ EventEmitter.prototype.prependOnceListener =
231
+ function prependOnceListener(type, listener) {
232
+ checkListener(listener);
233
+ this.prependListener(type, _onceWrap(this, type, listener));
234
+ return this;
235
+ };
236
+ // Emits a 'removeListener' event if and only if the listener was removed.
237
+ EventEmitter.prototype.removeListener =
238
+ function removeListener(type, listener) {
239
+ var list, events, position, i, originalListener;
240
+ checkListener(listener);
241
+ events = this._events;
242
+ if (events === undefined)
243
+ return this;
244
+ list = events[type];
245
+ if (list === undefined)
246
+ return this;
247
+ if (list === listener || list.listener === listener) {
248
+ if (--this._eventsCount === 0)
249
+ this._events = Object.create(null);
250
+ else {
251
+ delete events[type];
252
+ if (events.removeListener)
253
+ this.emit('removeListener', type, list.listener || listener);
254
+ }
255
+ }
256
+ else if (typeof list !== 'function') {
257
+ position = -1;
258
+ for (i = list.length - 1; i >= 0; i--) {
259
+ if (list[i] === listener || list[i].listener === listener) {
260
+ originalListener = list[i].listener;
261
+ position = i;
262
+ break;
263
+ }
264
+ }
265
+ if (position < 0)
266
+ return this;
267
+ if (position === 0)
268
+ list.shift();
269
+ else {
270
+ spliceOne(list, position);
271
+ }
272
+ if (list.length === 1)
273
+ events[type] = list[0];
274
+ if (events.removeListener !== undefined)
275
+ this.emit('removeListener', type, originalListener || listener);
276
+ }
277
+ return this;
278
+ };
279
+ EventEmitter.prototype.off = EventEmitter.prototype.removeListener;
280
+ EventEmitter.prototype.removeAllListeners =
281
+ function removeAllListeners(type) {
282
+ var listeners, events, i;
283
+ events = this._events;
284
+ if (events === undefined)
285
+ return this;
286
+ // not listening for removeListener, no need to emit
287
+ if (events.removeListener === undefined) {
288
+ if (arguments.length === 0) {
289
+ this._events = Object.create(null);
290
+ this._eventsCount = 0;
291
+ }
292
+ else if (events[type] !== undefined) {
293
+ if (--this._eventsCount === 0)
294
+ this._events = Object.create(null);
295
+ else
296
+ delete events[type];
297
+ }
298
+ return this;
299
+ }
300
+ // emit removeListener for all listeners on all events
301
+ if (arguments.length === 0) {
302
+ var keys = Object.keys(events);
303
+ var key;
304
+ for (i = 0; i < keys.length; ++i) {
305
+ key = keys[i];
306
+ if (key === 'removeListener')
307
+ continue;
308
+ this.removeAllListeners(key);
309
+ }
310
+ this.removeAllListeners('removeListener');
311
+ this._events = Object.create(null);
312
+ this._eventsCount = 0;
313
+ return this;
314
+ }
315
+ listeners = events[type];
316
+ if (typeof listeners === 'function') {
317
+ this.removeListener(type, listeners);
318
+ }
319
+ else if (listeners !== undefined) {
320
+ // LIFO order
321
+ for (i = listeners.length - 1; i >= 0; i--) {
322
+ this.removeListener(type, listeners[i]);
323
+ }
324
+ }
325
+ return this;
326
+ };
327
+ function _listeners(target, type, unwrap) {
328
+ var events = target._events;
329
+ if (events === undefined)
330
+ return [];
331
+ var evlistener = events[type];
332
+ if (evlistener === undefined)
333
+ return [];
334
+ if (typeof evlistener === 'function')
335
+ return unwrap ? [evlistener.listener || evlistener] : [evlistener];
336
+ return unwrap ?
337
+ unwrapListeners(evlistener) : arrayClone(evlistener, evlistener.length);
338
+ }
339
+ EventEmitter.prototype.listeners = function listeners(type) {
340
+ return _listeners(this, type, true);
341
+ };
342
+ EventEmitter.prototype.rawListeners = function rawListeners(type) {
343
+ return _listeners(this, type, false);
344
+ };
345
+ EventEmitter.listenerCount = function (emitter, type) {
346
+ if (typeof emitter.listenerCount === 'function') {
347
+ return emitter.listenerCount(type);
348
+ }
349
+ else {
350
+ return listenerCount.call(emitter, type);
351
+ }
352
+ };
353
+ EventEmitter.prototype.listenerCount = listenerCount;
354
+ function listenerCount(type) {
355
+ var events = this._events;
356
+ if (events !== undefined) {
357
+ var evlistener = events[type];
358
+ if (typeof evlistener === 'function') {
359
+ return 1;
360
+ }
361
+ else if (evlistener !== undefined) {
362
+ return evlistener.length;
363
+ }
364
+ }
365
+ return 0;
366
+ }
367
+ EventEmitter.prototype.eventNames = function eventNames() {
368
+ return this._eventsCount > 0 ? ReflectOwnKeys(this._events) : [];
369
+ };
370
+ function arrayClone(arr, n) {
371
+ var copy = new Array(n);
372
+ for (var i = 0; i < n; ++i)
373
+ copy[i] = arr[i];
374
+ return copy;
375
+ }
376
+ function spliceOne(list, index) {
377
+ for (; index + 1 < list.length; index++)
378
+ list[index] = list[index + 1];
379
+ list.pop();
380
+ }
381
+ function unwrapListeners(arr) {
382
+ var ret = new Array(arr.length);
383
+ for (var i = 0; i < ret.length; ++i) {
384
+ ret[i] = arr[i].listener || arr[i];
385
+ }
386
+ return ret;
387
+ }
@@ -0,0 +1,33 @@
1
+ // bloom-filters is supported on the following platforms:
2
+ // - Node.js: v4.0.0 or higher
3
+ // - Google Chrome: v41 or higher
4
+ // - Mozilla Firefox: v34 or higher
5
+ // - Microsoft Edge: v12 or higher
6
+ import { BloomFilter } from 'bloom-filters';
7
+ var EXPECTED_INSERTIONS = 10000000;
8
+ var ERROR_RATE = 0.01;
9
+ var REFRESH_RATE = 24 * 60 * 60000; // 24HS
10
+ export function bloomFilterFactory(expectedInsertions, errorRate, refreshRate) {
11
+ if (expectedInsertions === void 0) { expectedInsertions = EXPECTED_INSERTIONS; }
12
+ if (errorRate === void 0) { errorRate = ERROR_RATE; }
13
+ if (refreshRate === void 0) { refreshRate = REFRESH_RATE; }
14
+ var filter = BloomFilter.create(expectedInsertions, errorRate);
15
+ return {
16
+ refreshRate: refreshRate,
17
+ add: function (key, value) {
18
+ var data = "".concat(key, ":").concat(value);
19
+ if (filter.has(data)) {
20
+ return false;
21
+ }
22
+ filter.add(data);
23
+ return true;
24
+ },
25
+ contains: function (key, value) {
26
+ var data = "".concat(key, ":").concat(value);
27
+ return filter.has(data);
28
+ },
29
+ clear: function () {
30
+ filter = BloomFilter.create(expectedInsertions, errorRate);
31
+ }
32
+ };
33
+ }
@@ -2,21 +2,21 @@ import { ERROR_NULL, ERROR_INVALID, WARN_TRIMMING, ERROR_EMPTY } from '../../log
2
2
  import { isString } from '../lang';
3
3
  // include BOM and nbsp
4
4
  var TRIMMABLE_SPACES_REGEX = /^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/;
5
- export function validateSplit(log, maybeSplit, method, item) {
5
+ export function validateDefinition(log, maybeDefinition, method, item) {
6
6
  if (item === void 0) { item = 'feature flag name'; }
7
- if (maybeSplit == undefined) { // eslint-disable-line eqeqeq
7
+ if (maybeDefinition == undefined) { // eslint-disable-line eqeqeq
8
8
  log.error(ERROR_NULL, [method, item]);
9
9
  }
10
- else if (!isString(maybeSplit)) {
10
+ else if (!isString(maybeDefinition)) {
11
11
  log.error(ERROR_INVALID, [method, item]);
12
12
  }
13
13
  else {
14
- if (TRIMMABLE_SPACES_REGEX.test(maybeSplit)) {
15
- log.warn(WARN_TRIMMING, [method, item, maybeSplit]);
16
- maybeSplit = maybeSplit.trim();
14
+ if (TRIMMABLE_SPACES_REGEX.test(maybeDefinition)) {
15
+ log.warn(WARN_TRIMMING, [method, item, maybeDefinition]);
16
+ maybeDefinition = maybeDefinition.trim();
17
17
  }
18
- if (maybeSplit.length > 0) {
19
- return maybeSplit;
18
+ if (maybeDefinition.length > 0) {
19
+ return maybeDefinition;
20
20
  }
21
21
  else {
22
22
  log.error(ERROR_EMPTY, [method, item]);
@@ -0,0 +1,15 @@
1
+ import { FALLBACK_DEFINITION_NOT_FOUND, DEFINITION_NOT_FOUND } from '../labels';
2
+ import { WARN_NOT_EXISTENT_DEFINITION } from '../../logger/constants';
3
+ /**
4
+ * This is defined here and in this format mostly because of the logger and the fact that it's considered a validation at product level.
5
+ * But it's not going to run on the input validation layer. In any case, the most compelling reason to use it as we do is to avoid going to Redis and get a definition twice.
6
+ */
7
+ export function validateDefinitionExistence(log, readinessManager, definitionName, labelOrDefinitionObj, method) {
8
+ if (readinessManager.isReady()) { // Only if it's ready (synced with BE) we validate this, otherwise it may just be that the SDK is still syncing
9
+ if (labelOrDefinitionObj === DEFINITION_NOT_FOUND || labelOrDefinitionObj === FALLBACK_DEFINITION_NOT_FOUND || labelOrDefinitionObj == null) {
10
+ log.warn(WARN_NOT_EXISTENT_DEFINITION, [method, definitionName]);
11
+ return false;
12
+ }
13
+ }
14
+ return true;
15
+ }
@@ -0,0 +1,21 @@
1
+ import { ERROR_EMPTY_ARRAY } from '../../logger/constants';
2
+ import { uniq } from '../lang';
3
+ import { validateDefinition } from './definition';
4
+ export function validateDefinitions(log, maybeDefinitions, method, listName, item) {
5
+ if (listName === void 0) { listName = 'feature flag names'; }
6
+ if (item === void 0) { item = 'feature flag name'; }
7
+ if (Array.isArray(maybeDefinitions) && maybeDefinitions.length > 0) {
8
+ var validatedArray_1 = [];
9
+ // Remove invalid values
10
+ maybeDefinitions.forEach(function (maybeDefinition) {
11
+ var definitionName = validateDefinition(log, maybeDefinition, method, item);
12
+ if (definitionName)
13
+ validatedArray_1.push(definitionName);
14
+ });
15
+ // Strip off duplicated values if we have valid definition names then return
16
+ if (validatedArray_1.length)
17
+ return uniq(validatedArray_1);
18
+ }
19
+ log.error(ERROR_EMPTY_ARRAY, [method, listName]);
20
+ return false;
21
+ }
@@ -4,10 +4,10 @@ export { validateEvent } from './event';
4
4
  export { validateEventValue } from './eventValue';
5
5
  export { validateEventProperties } from './eventProperties';
6
6
  export { validateKey } from './key';
7
- export { validateSplit } from './split';
8
- export { validateSplits } from './splits';
7
+ export { validateDefinition } from './definition';
8
+ export { validateDefinitions } from './definitions';
9
9
  export { validateTrafficType } from './trafficType';
10
10
  export { validateIfNotDestroyed, validateIfReadyFromCache, validateIfOperational } from './isOperational';
11
- export { validateSplitExistence } from './splitExistence';
11
+ export { validateDefinitionExistence } from './definitionExistence';
12
12
  export { validateTrafficTypeExistence } from './trafficTypeExistence';
13
13
  export { validateEvaluationOptions } from './eventProperties';
@@ -5,13 +5,13 @@ export function validateIfNotDestroyed(log, readinessManager, method) {
5
5
  log.error(ERROR_CLIENT_DESTROYED, [method]);
6
6
  return false;
7
7
  }
8
- export function validateIfReadyFromCache(log, readinessManager, method, featureFlagNameOrNames) {
8
+ export function validateIfReadyFromCache(log, readinessManager, method) {
9
9
  if (readinessManager.isReadyFromCache())
10
10
  return true;
11
- log.warn(CLIENT_NOT_READY_FROM_CACHE, [method, featureFlagNameOrNames ? " for feature flag ".concat(featureFlagNameOrNames.toString()) : '']);
11
+ log.warn(CLIENT_NOT_READY_FROM_CACHE, [method]);
12
12
  return false;
13
13
  }
14
14
  // Operational means that the SDK is ready to evaluate (not destroyed and ready from cache)
15
- export function validateIfOperational(log, readinessManager, method, featureFlagNameOrNames) {
16
- return validateIfNotDestroyed(log, readinessManager, method) && validateIfReadyFromCache(log, readinessManager, method, featureFlagNameOrNames);
15
+ export function validateIfOperational(log, readinessManager, method) {
16
+ return validateIfNotDestroyed(log, readinessManager, method) && validateIfReadyFromCache(log, readinessManager, method);
17
17
  }
@@ -0,0 +1,18 @@
1
+ import { __assign } from "tslib";
2
+ import { isObject } from '../lang';
3
+ import { validateKey } from './key';
4
+ import { validateAttributes } from './attributes';
5
+ import { ERROR_NOT_PLAIN_OBJECT } from '../../logger/constants';
6
+ export function validateTarget(log, maybeTarget, method) {
7
+ if (!isObject(maybeTarget)) {
8
+ log.error(ERROR_NOT_PLAIN_OBJECT, [method, 'target']);
9
+ return false;
10
+ }
11
+ var key = validateKey(log, maybeTarget.key, method);
12
+ if (key === false)
13
+ return false;
14
+ var attributes = validateAttributes(log, maybeTarget.attributes, method);
15
+ if (attributes === false)
16
+ return false;
17
+ return __assign(__assign({}, maybeTarget), { key: key, attributes: attributes });
18
+ }
@@ -1,11 +1,11 @@
1
1
  import { FALLBACK_PREFIX } from '../../evaluator/fallbackTreatmentsCalculator';
2
2
  export var SPLIT_KILLED = 'killed';
3
3
  export var NO_CONDITION_MATCH = 'default rule';
4
- export var SPLIT_NOT_FOUND = 'definition not found';
4
+ export var DEFINITION_NOT_FOUND = 'definition not found';
5
5
  export var SDK_NOT_READY = 'not ready';
6
6
  export var EXCEPTION = 'exception';
7
7
  export var SPLIT_ARCHIVED = 'archived';
8
8
  export var NOT_IN_SPLIT = 'not in split';
9
9
  export var UNSUPPORTED_MATCHER_TYPE = 'targeting rule type unsupported by sdk';
10
10
  export var PREREQUISITES_NOT_MET = 'prerequisites not met';
11
- export var FALLBACK_SPLIT_NOT_FOUND = FALLBACK_PREFIX + SPLIT_NOT_FOUND;
11
+ export var FALLBACK_DEFINITION_NOT_FOUND = FALLBACK_PREFIX + DEFINITION_NOT_FOUND;
@@ -52,6 +52,8 @@ export var base = {
52
52
  streaming: 'https://streaming.split.io',
53
53
  // Telemetry Server
54
54
  telemetry: 'https://telemetry.split.io/api',
55
+ // Configs Server
56
+ configs: 'https://configs.split.io',
55
57
  },
56
58
  // Defines which kind of storage we should instantiate.
57
59
  storage: undefined,
@@ -1,4 +1,4 @@
1
- import { validateSplits } from '../inputValidation/splits';
1
+ import { validateDefinitions } from '../inputValidation/definitions';
2
2
  import { WARN_SPLITS_FILTER_IGNORED, WARN_SPLITS_FILTER_EMPTY, WARN_SPLITS_FILTER_INVALID, SETTINGS_SPLITS_FILTER, LOG_PREFIX_SETTINGS, ERROR_SETS_FILTER_EXCLUSIVE, WARN_LOWERCASE_FLAGSET, WARN_INVALID_FLAGSET, WARN_FLAGSET_NOT_CONFIGURED } from '../../logger/constants';
3
3
  import { objectAssign } from '../lang/objectAssign';
4
4
  import { find, uniq } from '../lang';
@@ -42,7 +42,7 @@ function validateFilterType(maybeFilterType) {
42
42
  */
43
43
  function validateSplitFilter(log, type, values, maxLength) {
44
44
  // validate and remove invalid and duplicated values
45
- var result = validateSplits(log, values, LOG_PREFIX_SETTINGS, "".concat(type, " filter"), "".concat(type, " filter value"));
45
+ var result = validateDefinitions(log, values, LOG_PREFIX_SETTINGS, "".concat(type, " filter"), "".concat(type, " filter value"));
46
46
  if (result) {
47
47
  if (type === 'bySet') {
48
48
  result = sanitizeFlagSets(log, result, LOG_PREFIX_SETTINGS);
@@ -168,7 +168,7 @@ export function validateSplitFilters(log, maybeSplitFilters, mode) {
168
168
  return res;
169
169
  }
170
170
  export function validateFlagSets(log, method, flagSets, flagSetsInConfig) {
171
- var sets = validateSplits(log, flagSets, method, 'flag sets', 'flag set');
171
+ var sets = validateDefinitions(log, flagSets, method, 'flag sets', 'flag set');
172
172
  var toReturn = sets ? sanitizeFlagSets(log, sets, method) : [];
173
173
  if (flagSetsInConfig.length > 0) {
174
174
  toReturn = toReturn.filter(function (flagSet) {
@@ -1,7 +1,8 @@
1
- var telemetryEndpointMatcher = /^\/v1\/metrics\/(config|usage)/;
1
+ var telemetryEndpointMatcher = /^\/v1\/(metrics|keys)\/(config|usage|ss|cs)/;
2
2
  var eventsEndpointMatcher = /^\/(testImpressions|metrics|events)/;
3
- var authEndpointMatcher = /^\/v2\/auth/;
3
+ var authEndpointMatcher = /^\/(v2|v3)\/auth/;
4
4
  var streamingEndpointMatcher = /^\/(sse|event-stream)/;
5
+ var configsEndpointMatcher = /^\/v1\/(configs|segmentChanges)/;
5
6
  /**
6
7
  * Get URL based on a given target (path).
7
8
  * ATM, it is only used for testing purposes.
@@ -23,5 +24,8 @@ export function url(settings, target) {
23
24
  if (streamingEndpointMatcher.test(target)) {
24
25
  return "".concat(settings.urls.streaming).concat(target);
25
26
  }
27
+ if (configsEndpointMatcher.test(target)) {
28
+ return "".concat(settings.urls.configs).concat(target);
29
+ }
26
30
  return "".concat(settings.urls.sdk).concat(target);
27
31
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@splitsoftware/splitio-commons",
3
- "version": "3.1.1-rc.10",
3
+ "version": "3.1.1-rc.11",
4
4
  "description": "Split JavaScript SDK common components",
5
5
  "main": "cjs/index.js",
6
6
  "module": "esm/index.js",