@splitsoftware/splitio 10.26.1-rc.1 → 10.26.1-rc.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGES.txt +3 -0
- package/es/platform/getEventSource/eventsource.js +480 -0
- package/es/platform/getEventSource/node.js +1 -1
- package/es/platform/getFetch/node.js +1 -15
- package/es/platform/getOptions/node.js +17 -0
- package/es/platform/node.js +2 -0
- package/es/settings/defaults/version.js +1 -1
- package/lib/platform/getEventSource/eventsource.js +480 -0
- package/lib/platform/getEventSource/node.js +1 -1
- package/lib/platform/getFetch/node.js +1 -16
- package/lib/platform/getOptions/node.js +22 -0
- package/lib/platform/node.js +6 -4
- package/lib/settings/defaults/version.js +1 -1
- package/package.json +2 -5
- package/src/platform/getEventSource/eventsource.js +519 -0
- package/src/platform/getEventSource/node.js +1 -1
- package/src/platform/getFetch/node.js +1 -17
- package/src/platform/getOptions/node.js +20 -0
- package/src/platform/node.js +2 -0
- package/src/settings/defaults/version.js +1 -1
package/CHANGES.txt
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
10.27.0
|
|
2
|
+
- it must return an object that adheres to the NodeJS http/s request options object (https://nodejs.org/api/https.html#httpsrequesturl-options-callback)
|
|
3
|
+
|
|
1
4
|
10.26.1 (June XX, 2024)
|
|
2
5
|
- Updated the internal imports of 'os' and 'ioredis' modules for NodeJS to use EcmaScript 'import' rather than CommonJS 'require' for the ES modules build, avoiding runtime errors when bundling or importing the SDK in a .mjs file.
|
|
3
6
|
- Updated @splitsoftware/splitio-commons package to version 1.15.1 that includes updates on input validation logs.
|
|
@@ -0,0 +1,480 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* eslint-disable no-prototype-builtins */
|
|
3
|
+
/* eslint-disable no-restricted-syntax */
|
|
4
|
+
/*
|
|
5
|
+
Modified version of "eventsource" v1.1.2 package (https://www.npmjs.com/package/eventsource/v/1.1.2)
|
|
6
|
+
that accepts a custom agent.
|
|
7
|
+
|
|
8
|
+
The MIT License
|
|
9
|
+
|
|
10
|
+
Copyright (c) EventSource GitHub organisation
|
|
11
|
+
|
|
12
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
13
|
+
a copy of this software and associated documentation files (the
|
|
14
|
+
"Software"), to deal in the Software without restriction, including
|
|
15
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
16
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
17
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
18
|
+
the following conditions:
|
|
19
|
+
|
|
20
|
+
The above copyright notice and this permission notice shall be
|
|
21
|
+
included in all copies or substantial portions of the Software.
|
|
22
|
+
|
|
23
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
24
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
25
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
26
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
27
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
28
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
29
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
30
|
+
*/
|
|
31
|
+
var parse = require('url').parse;
|
|
32
|
+
var events = require('events');
|
|
33
|
+
var https = require('https');
|
|
34
|
+
var http = require('http');
|
|
35
|
+
var util = require('util');
|
|
36
|
+
var httpsOptions = [
|
|
37
|
+
'pfx', 'key', 'passphrase', 'cert', 'ca', 'ciphers',
|
|
38
|
+
'rejectUnauthorized', 'secureProtocol', 'servername', 'checkServerIdentity'
|
|
39
|
+
];
|
|
40
|
+
var bom = [239, 187, 191];
|
|
41
|
+
var colon = 58;
|
|
42
|
+
var space = 32;
|
|
43
|
+
var lineFeed = 10;
|
|
44
|
+
var carriageReturn = 13;
|
|
45
|
+
function hasBom(buf) {
|
|
46
|
+
return bom.every(function (charCode, index) {
|
|
47
|
+
return buf[index] === charCode;
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Creates a new EventSource object
|
|
52
|
+
*
|
|
53
|
+
* @param {String} url the URL to which to connect
|
|
54
|
+
* @param {Object} [eventSourceInitDict] extra init params. See README for details.
|
|
55
|
+
* @api public
|
|
56
|
+
**/
|
|
57
|
+
function EventSource(url, eventSourceInitDict) {
|
|
58
|
+
var readyState = EventSource.CONNECTING;
|
|
59
|
+
var headers = eventSourceInitDict && eventSourceInitDict.headers;
|
|
60
|
+
var hasNewOrigin = false;
|
|
61
|
+
Object.defineProperty(this, 'readyState', {
|
|
62
|
+
get: function () {
|
|
63
|
+
return readyState;
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
Object.defineProperty(this, 'url', {
|
|
67
|
+
get: function () {
|
|
68
|
+
return url;
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
var self = this;
|
|
72
|
+
self.reconnectInterval = 1000;
|
|
73
|
+
self.connectionInProgress = false;
|
|
74
|
+
var reconnectUrl = null;
|
|
75
|
+
function onConnectionClosed(message) {
|
|
76
|
+
if (readyState === EventSource.CLOSED)
|
|
77
|
+
return;
|
|
78
|
+
readyState = EventSource.CONNECTING;
|
|
79
|
+
_emit('error', new Event('error', { message: message }));
|
|
80
|
+
// The url may have been changed by a temporary redirect. If that's the case,
|
|
81
|
+
// revert it now, and flag that we are no longer pointing to a new origin
|
|
82
|
+
if (reconnectUrl) {
|
|
83
|
+
url = reconnectUrl;
|
|
84
|
+
reconnectUrl = null;
|
|
85
|
+
hasNewOrigin = false;
|
|
86
|
+
}
|
|
87
|
+
setTimeout(function () {
|
|
88
|
+
if (readyState !== EventSource.CONNECTING || self.connectionInProgress) {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
self.connectionInProgress = true;
|
|
92
|
+
connect();
|
|
93
|
+
}, self.reconnectInterval);
|
|
94
|
+
}
|
|
95
|
+
var req;
|
|
96
|
+
var lastEventId = '';
|
|
97
|
+
if (headers && headers['Last-Event-ID']) {
|
|
98
|
+
lastEventId = headers['Last-Event-ID'];
|
|
99
|
+
delete headers['Last-Event-ID'];
|
|
100
|
+
}
|
|
101
|
+
var discardTrailingNewline = false;
|
|
102
|
+
var data = '';
|
|
103
|
+
var eventName = '';
|
|
104
|
+
function connect() {
|
|
105
|
+
var options = parse(url);
|
|
106
|
+
var isSecure = options.protocol === 'https:';
|
|
107
|
+
options.headers = { 'Cache-Control': 'no-cache', 'Accept': 'text/event-stream' };
|
|
108
|
+
if (lastEventId)
|
|
109
|
+
options.headers['Last-Event-ID'] = lastEventId;
|
|
110
|
+
if (headers) {
|
|
111
|
+
var reqHeaders = hasNewOrigin ? removeUnsafeHeaders(headers) : headers;
|
|
112
|
+
for (var i in reqHeaders) {
|
|
113
|
+
var header = reqHeaders[i];
|
|
114
|
+
if (header) {
|
|
115
|
+
options.headers[i] = header;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
// Legacy: this should be specified as `eventSourceInitDict.https.rejectUnauthorized`,
|
|
120
|
+
// but for now exists as a backwards-compatibility layer
|
|
121
|
+
options.rejectUnauthorized = !(eventSourceInitDict && !eventSourceInitDict.rejectUnauthorized);
|
|
122
|
+
if (eventSourceInitDict && eventSourceInitDict.createConnection !== undefined) {
|
|
123
|
+
options.createConnection = eventSourceInitDict.createConnection;
|
|
124
|
+
}
|
|
125
|
+
// If specify agent, use it.
|
|
126
|
+
if (eventSourceInitDict && eventSourceInitDict.agent !== undefined) {
|
|
127
|
+
options.agent = eventSourceInitDict.agent;
|
|
128
|
+
}
|
|
129
|
+
// If specify http proxy, make the request to sent to the proxy server,
|
|
130
|
+
// and include the original url in path and Host headers
|
|
131
|
+
var useProxy = eventSourceInitDict && eventSourceInitDict.proxy;
|
|
132
|
+
if (useProxy) {
|
|
133
|
+
var proxy = parse(eventSourceInitDict.proxy);
|
|
134
|
+
isSecure = proxy.protocol === 'https:';
|
|
135
|
+
options.protocol = isSecure ? 'https:' : 'http:';
|
|
136
|
+
options.path = url;
|
|
137
|
+
options.headers.Host = options.host;
|
|
138
|
+
options.hostname = proxy.hostname;
|
|
139
|
+
options.host = proxy.host;
|
|
140
|
+
options.port = proxy.port;
|
|
141
|
+
}
|
|
142
|
+
// If https options are specified, merge them into the request options
|
|
143
|
+
if (eventSourceInitDict && eventSourceInitDict.https) {
|
|
144
|
+
for (var optName in eventSourceInitDict.https) {
|
|
145
|
+
if (httpsOptions.indexOf(optName) === -1) {
|
|
146
|
+
continue;
|
|
147
|
+
}
|
|
148
|
+
var option = eventSourceInitDict.https[optName];
|
|
149
|
+
if (option !== undefined) {
|
|
150
|
+
options[optName] = option;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
// Pass this on to the XHR
|
|
155
|
+
if (eventSourceInitDict && eventSourceInitDict.withCredentials !== undefined) {
|
|
156
|
+
options.withCredentials = eventSourceInitDict.withCredentials;
|
|
157
|
+
}
|
|
158
|
+
req = (isSecure ? https : http).request(options, function (res) {
|
|
159
|
+
self.connectionInProgress = false;
|
|
160
|
+
// Handle HTTP errors
|
|
161
|
+
if (res.statusCode === 500 || res.statusCode === 502 || res.statusCode === 503 || res.statusCode === 504) {
|
|
162
|
+
_emit('error', new Event('error', { status: res.statusCode, message: res.statusMessage }));
|
|
163
|
+
onConnectionClosed();
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
// Handle HTTP redirects
|
|
167
|
+
if (res.statusCode === 301 || res.statusCode === 302 || res.statusCode === 307) {
|
|
168
|
+
var location = res.headers.location;
|
|
169
|
+
if (!location) {
|
|
170
|
+
// Server sent redirect response without Location header.
|
|
171
|
+
_emit('error', new Event('error', { status: res.statusCode, message: res.statusMessage }));
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
var prevOrigin = getOrigin(url);
|
|
175
|
+
var nextOrigin = getOrigin(location);
|
|
176
|
+
hasNewOrigin = prevOrigin !== nextOrigin;
|
|
177
|
+
if (res.statusCode === 307)
|
|
178
|
+
reconnectUrl = url;
|
|
179
|
+
url = location;
|
|
180
|
+
process.nextTick(connect);
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
if (res.statusCode !== 200) {
|
|
184
|
+
_emit('error', new Event('error', { status: res.statusCode, message: res.statusMessage }));
|
|
185
|
+
return self.close();
|
|
186
|
+
}
|
|
187
|
+
readyState = EventSource.OPEN;
|
|
188
|
+
res.on('close', function () {
|
|
189
|
+
res.removeAllListeners('close');
|
|
190
|
+
res.removeAllListeners('end');
|
|
191
|
+
onConnectionClosed();
|
|
192
|
+
});
|
|
193
|
+
res.on('end', function () {
|
|
194
|
+
res.removeAllListeners('close');
|
|
195
|
+
res.removeAllListeners('end');
|
|
196
|
+
onConnectionClosed();
|
|
197
|
+
});
|
|
198
|
+
_emit('open', new Event('open'));
|
|
199
|
+
// text/event-stream parser adapted from webkit's
|
|
200
|
+
// Source/WebCore/page/EventSource.cpp
|
|
201
|
+
var isFirst = true;
|
|
202
|
+
var buf;
|
|
203
|
+
var startingPos = 0;
|
|
204
|
+
var startingFieldLength = -1;
|
|
205
|
+
res.on('data', function (chunk) {
|
|
206
|
+
buf = buf ? Buffer.concat([buf, chunk]) : chunk;
|
|
207
|
+
if (isFirst && hasBom(buf)) {
|
|
208
|
+
buf = buf.slice(bom.length);
|
|
209
|
+
}
|
|
210
|
+
isFirst = false;
|
|
211
|
+
var pos = 0;
|
|
212
|
+
var length = buf.length;
|
|
213
|
+
while (pos < length) {
|
|
214
|
+
if (discardTrailingNewline) {
|
|
215
|
+
if (buf[pos] === lineFeed) {
|
|
216
|
+
++pos;
|
|
217
|
+
}
|
|
218
|
+
discardTrailingNewline = false;
|
|
219
|
+
}
|
|
220
|
+
var lineLength = -1;
|
|
221
|
+
var fieldLength = startingFieldLength;
|
|
222
|
+
var c;
|
|
223
|
+
for (var i = startingPos; lineLength < 0 && i < length; ++i) {
|
|
224
|
+
c = buf[i];
|
|
225
|
+
if (c === colon) {
|
|
226
|
+
if (fieldLength < 0) {
|
|
227
|
+
fieldLength = i - pos;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
else if (c === carriageReturn) {
|
|
231
|
+
discardTrailingNewline = true;
|
|
232
|
+
lineLength = i - pos;
|
|
233
|
+
}
|
|
234
|
+
else if (c === lineFeed) {
|
|
235
|
+
lineLength = i - pos;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
if (lineLength < 0) {
|
|
239
|
+
startingPos = length - pos;
|
|
240
|
+
startingFieldLength = fieldLength;
|
|
241
|
+
break;
|
|
242
|
+
}
|
|
243
|
+
else {
|
|
244
|
+
startingPos = 0;
|
|
245
|
+
startingFieldLength = -1;
|
|
246
|
+
}
|
|
247
|
+
parseEventStreamLine(buf, pos, fieldLength, lineLength);
|
|
248
|
+
pos += lineLength + 1;
|
|
249
|
+
}
|
|
250
|
+
if (pos === length) {
|
|
251
|
+
buf = void 0;
|
|
252
|
+
}
|
|
253
|
+
else if (pos > 0) {
|
|
254
|
+
buf = buf.slice(pos);
|
|
255
|
+
}
|
|
256
|
+
});
|
|
257
|
+
});
|
|
258
|
+
req.on('error', function (err) {
|
|
259
|
+
self.connectionInProgress = false;
|
|
260
|
+
onConnectionClosed(err.message);
|
|
261
|
+
});
|
|
262
|
+
if (req.setNoDelay)
|
|
263
|
+
req.setNoDelay(true);
|
|
264
|
+
req.end();
|
|
265
|
+
}
|
|
266
|
+
connect();
|
|
267
|
+
function _emit() {
|
|
268
|
+
if (self.listeners(arguments[0]).length > 0) {
|
|
269
|
+
self.emit.apply(self, arguments);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
this._close = function () {
|
|
273
|
+
if (readyState === EventSource.CLOSED)
|
|
274
|
+
return;
|
|
275
|
+
readyState = EventSource.CLOSED;
|
|
276
|
+
if (req.abort)
|
|
277
|
+
req.abort();
|
|
278
|
+
if (req.xhr && req.xhr.abort)
|
|
279
|
+
req.xhr.abort();
|
|
280
|
+
};
|
|
281
|
+
function parseEventStreamLine(buf, pos, fieldLength, lineLength) {
|
|
282
|
+
if (lineLength === 0) {
|
|
283
|
+
if (data.length > 0) {
|
|
284
|
+
var type = eventName || 'message';
|
|
285
|
+
_emit(type, new MessageEvent(type, {
|
|
286
|
+
data: data.slice(0, -1),
|
|
287
|
+
lastEventId: lastEventId,
|
|
288
|
+
origin: getOrigin(url)
|
|
289
|
+
}));
|
|
290
|
+
data = '';
|
|
291
|
+
}
|
|
292
|
+
eventName = void 0;
|
|
293
|
+
}
|
|
294
|
+
else if (fieldLength > 0) {
|
|
295
|
+
var noValue = fieldLength < 0;
|
|
296
|
+
var step = 0;
|
|
297
|
+
var field = buf.slice(pos, pos + (noValue ? lineLength : fieldLength)).toString();
|
|
298
|
+
if (noValue) {
|
|
299
|
+
step = lineLength;
|
|
300
|
+
}
|
|
301
|
+
else if (buf[pos + fieldLength + 1] !== space) {
|
|
302
|
+
step = fieldLength + 1;
|
|
303
|
+
}
|
|
304
|
+
else {
|
|
305
|
+
step = fieldLength + 2;
|
|
306
|
+
}
|
|
307
|
+
pos += step;
|
|
308
|
+
var valueLength = lineLength - step;
|
|
309
|
+
var value = buf.slice(pos, pos + valueLength).toString();
|
|
310
|
+
if (field === 'data') {
|
|
311
|
+
data += value + '\n';
|
|
312
|
+
}
|
|
313
|
+
else if (field === 'event') {
|
|
314
|
+
eventName = value;
|
|
315
|
+
}
|
|
316
|
+
else if (field === 'id') {
|
|
317
|
+
lastEventId = value;
|
|
318
|
+
}
|
|
319
|
+
else if (field === 'retry') {
|
|
320
|
+
var retry = parseInt(value, 10);
|
|
321
|
+
if (!Number.isNaN(retry)) {
|
|
322
|
+
self.reconnectInterval = retry;
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
module.exports = EventSource;
|
|
329
|
+
util.inherits(EventSource, events.EventEmitter);
|
|
330
|
+
EventSource.prototype.constructor = EventSource; // make stacktraces readable
|
|
331
|
+
['open', 'error', 'message'].forEach(function (method) {
|
|
332
|
+
Object.defineProperty(EventSource.prototype, 'on' + method, {
|
|
333
|
+
/**
|
|
334
|
+
* Returns the current listener
|
|
335
|
+
*
|
|
336
|
+
* @return {Mixed} the set function or undefined
|
|
337
|
+
* @api private
|
|
338
|
+
*/
|
|
339
|
+
get: function get() {
|
|
340
|
+
var listener = this.listeners(method)[0];
|
|
341
|
+
return listener ? (listener._listener ? listener._listener : listener) : undefined;
|
|
342
|
+
},
|
|
343
|
+
/**
|
|
344
|
+
* Start listening for events
|
|
345
|
+
*
|
|
346
|
+
* @param {Function} listener the listener
|
|
347
|
+
* @return {Mixed} the set function or undefined
|
|
348
|
+
* @api private
|
|
349
|
+
*/
|
|
350
|
+
set: function set(listener) {
|
|
351
|
+
this.removeAllListeners(method);
|
|
352
|
+
this.addEventListener(method, listener);
|
|
353
|
+
}
|
|
354
|
+
});
|
|
355
|
+
});
|
|
356
|
+
/**
|
|
357
|
+
* Ready states
|
|
358
|
+
*/
|
|
359
|
+
Object.defineProperty(EventSource, 'CONNECTING', { enumerable: true, value: 0 });
|
|
360
|
+
Object.defineProperty(EventSource, 'OPEN', { enumerable: true, value: 1 });
|
|
361
|
+
Object.defineProperty(EventSource, 'CLOSED', { enumerable: true, value: 2 });
|
|
362
|
+
EventSource.prototype.CONNECTING = 0;
|
|
363
|
+
EventSource.prototype.OPEN = 1;
|
|
364
|
+
EventSource.prototype.CLOSED = 2;
|
|
365
|
+
/**
|
|
366
|
+
* Closes the connection, if one is made, and sets the readyState attribute to 2 (closed)
|
|
367
|
+
*
|
|
368
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/EventSource/close
|
|
369
|
+
* @api public
|
|
370
|
+
*/
|
|
371
|
+
EventSource.prototype.close = function () {
|
|
372
|
+
this._close();
|
|
373
|
+
};
|
|
374
|
+
/**
|
|
375
|
+
* Emulates the W3C Browser based WebSocket interface using addEventListener.
|
|
376
|
+
*
|
|
377
|
+
* @param {String} type A string representing the event type to listen out for
|
|
378
|
+
* @param {Function} listener callback
|
|
379
|
+
* @see https://developer.mozilla.org/en/DOM/element.addEventListener
|
|
380
|
+
* @see http://dev.w3.org/html5/websockets/#the-websocket-interface
|
|
381
|
+
* @api public
|
|
382
|
+
*/
|
|
383
|
+
EventSource.prototype.addEventListener = function addEventListener(type, listener) {
|
|
384
|
+
if (typeof listener === 'function') {
|
|
385
|
+
// store a reference so we can return the original function again
|
|
386
|
+
listener._listener = listener;
|
|
387
|
+
this.on(type, listener);
|
|
388
|
+
}
|
|
389
|
+
};
|
|
390
|
+
/**
|
|
391
|
+
* Emulates the W3C Browser based WebSocket interface using dispatchEvent.
|
|
392
|
+
*
|
|
393
|
+
* @param {Event} event An event to be dispatched
|
|
394
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/dispatchEvent
|
|
395
|
+
* @api public
|
|
396
|
+
*/
|
|
397
|
+
EventSource.prototype.dispatchEvent = function dispatchEvent(event) {
|
|
398
|
+
if (!event.type) {
|
|
399
|
+
throw new Error('UNSPECIFIED_EVENT_TYPE_ERR');
|
|
400
|
+
}
|
|
401
|
+
// if event is instance of an CustomEvent (or has 'details' property),
|
|
402
|
+
// send the detail object as the payload for the event
|
|
403
|
+
this.emit(event.type, event.detail);
|
|
404
|
+
};
|
|
405
|
+
/**
|
|
406
|
+
* Emulates the W3C Browser based WebSocket interface using removeEventListener.
|
|
407
|
+
*
|
|
408
|
+
* @param {String} type A string representing the event type to remove
|
|
409
|
+
* @param {Function} listener callback
|
|
410
|
+
* @see https://developer.mozilla.org/en/DOM/element.removeEventListener
|
|
411
|
+
* @see http://dev.w3.org/html5/websockets/#the-websocket-interface
|
|
412
|
+
* @api public
|
|
413
|
+
*/
|
|
414
|
+
EventSource.prototype.removeEventListener = function removeEventListener(type, listener) {
|
|
415
|
+
if (typeof listener === 'function') {
|
|
416
|
+
listener._listener = undefined;
|
|
417
|
+
this.removeListener(type, listener);
|
|
418
|
+
}
|
|
419
|
+
};
|
|
420
|
+
/**
|
|
421
|
+
* W3C Event
|
|
422
|
+
*
|
|
423
|
+
* @see http://www.w3.org/TR/DOM-Level-3-Events/#interface-Event
|
|
424
|
+
* @api private
|
|
425
|
+
*/
|
|
426
|
+
function Event(type, optionalProperties) {
|
|
427
|
+
Object.defineProperty(this, 'type', { writable: false, value: type, enumerable: true });
|
|
428
|
+
if (optionalProperties) {
|
|
429
|
+
for (var f in optionalProperties) {
|
|
430
|
+
if (optionalProperties.hasOwnProperty(f)) {
|
|
431
|
+
Object.defineProperty(this, f, { writable: false, value: optionalProperties[f], enumerable: true });
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
/**
|
|
437
|
+
* W3C MessageEvent
|
|
438
|
+
*
|
|
439
|
+
* @see http://www.w3.org/TR/webmessaging/#event-definitions
|
|
440
|
+
* @api private
|
|
441
|
+
*/
|
|
442
|
+
function MessageEvent(type, eventInitDict) {
|
|
443
|
+
Object.defineProperty(this, 'type', { writable: false, value: type, enumerable: true });
|
|
444
|
+
for (var f in eventInitDict) {
|
|
445
|
+
if (eventInitDict.hasOwnProperty(f)) {
|
|
446
|
+
Object.defineProperty(this, f, { writable: false, value: eventInitDict[f], enumerable: true });
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
/**
|
|
451
|
+
* Returns a new object of headers that does not include any authorization and cookie headers
|
|
452
|
+
*
|
|
453
|
+
* @param {Object} headers An object of headers ({[headerName]: headerValue})
|
|
454
|
+
* @return {Object} a new object of headers
|
|
455
|
+
* @api private
|
|
456
|
+
*/
|
|
457
|
+
function removeUnsafeHeaders(headers) {
|
|
458
|
+
var safe = {};
|
|
459
|
+
for (var key in headers) {
|
|
460
|
+
if (/^(cookie|authorization)$/i.test(key)) {
|
|
461
|
+
continue;
|
|
462
|
+
}
|
|
463
|
+
safe[key] = headers[key];
|
|
464
|
+
}
|
|
465
|
+
return safe;
|
|
466
|
+
}
|
|
467
|
+
/**
|
|
468
|
+
* Transform an URL to a valid origin value.
|
|
469
|
+
*
|
|
470
|
+
* @param {String|Object} url URL to transform to it's origin.
|
|
471
|
+
* @returns {String} The origin.
|
|
472
|
+
* @api private
|
|
473
|
+
*/
|
|
474
|
+
function getOrigin(url) {
|
|
475
|
+
if (typeof url === 'string')
|
|
476
|
+
url = parse(url);
|
|
477
|
+
if (!url.protocol || !url.hostname)
|
|
478
|
+
return 'null';
|
|
479
|
+
return (url.protocol + '//' + url.host).toLowerCase();
|
|
480
|
+
}
|
|
@@ -11,7 +11,7 @@ export function __restore() {
|
|
|
11
11
|
export function getEventSource() {
|
|
12
12
|
// returns EventSource at `eventsource` package. If not available, return global EventSource or undefined
|
|
13
13
|
try {
|
|
14
|
-
return __isCustom ? __eventSource : require('eventsource');
|
|
14
|
+
return __isCustom ? __eventSource : require('./eventsource');
|
|
15
15
|
}
|
|
16
16
|
catch (error) {
|
|
17
17
|
return typeof EventSource === 'function' ? EventSource : undefined;
|
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
/* eslint-disable compat/compat */
|
|
2
|
-
import https from 'https';
|
|
3
|
-
// @TODO
|
|
4
|
-
// 1- handle multiple protocols automatically
|
|
5
|
-
// 2- destroy it once the sdk is destroyed
|
|
6
|
-
var agent = new https.Agent({
|
|
7
|
-
keepAlive: true,
|
|
8
|
-
keepAliveMsecs: 1500
|
|
9
|
-
});
|
|
10
1
|
var nodeFetch;
|
|
11
2
|
try {
|
|
12
3
|
nodeFetch = require('node-fetch');
|
|
@@ -24,12 +15,7 @@ export function __setFetch(fetch) {
|
|
|
24
15
|
}
|
|
25
16
|
/**
|
|
26
17
|
* Retrieves 'node-fetch', a Fetch API polyfill for NodeJS, with fallback to global 'fetch' if available.
|
|
27
|
-
* It passes an https agent with keepAlive enabled if URL is https.
|
|
28
18
|
*/
|
|
29
19
|
export function getFetch() {
|
|
30
|
-
|
|
31
|
-
return function (url, options) {
|
|
32
|
-
return nodeFetch(url, Object.assign({ agent: url.startsWith('https:') ? agent : undefined }, options));
|
|
33
|
-
};
|
|
34
|
-
}
|
|
20
|
+
return nodeFetch;
|
|
35
21
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// @TODO
|
|
2
|
+
// 1- handle multiple protocols automatically
|
|
3
|
+
// 2- destroy it once the sdk is destroyed
|
|
4
|
+
import https from 'https';
|
|
5
|
+
import { find } from '@splitsoftware/splitio-commons/esm/utils/lang';
|
|
6
|
+
var agent = new https.Agent({
|
|
7
|
+
keepAlive: true,
|
|
8
|
+
keepAliveMsecs: 1500
|
|
9
|
+
});
|
|
10
|
+
export function getOptions(settings) {
|
|
11
|
+
// If some URL is not HTTPS, we don't use the agent, to let the SDK connect to HTTP endpoints
|
|
12
|
+
if (find(settings.urls, function (url) { return !url.startsWith('https:'); }))
|
|
13
|
+
return;
|
|
14
|
+
return {
|
|
15
|
+
agent: agent
|
|
16
|
+
};
|
|
17
|
+
}
|
package/es/platform/node.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import EventEmitter from 'events';
|
|
2
2
|
import { getFetch } from '../platform/getFetch/node';
|
|
3
3
|
import { getEventSource } from '../platform/getEventSource/node';
|
|
4
|
+
import { getOptions } from '../platform/getOptions/node';
|
|
4
5
|
import { NodeSignalListener } from '@splitsoftware/splitio-commons/esm/listeners/node';
|
|
5
6
|
import { now } from '@splitsoftware/splitio-commons/esm/utils/timeTracker/now/node';
|
|
6
7
|
export var platform = {
|
|
7
8
|
getFetch: getFetch,
|
|
8
9
|
getEventSource: getEventSource,
|
|
10
|
+
getOptions: getOptions,
|
|
9
11
|
EventEmitter: EventEmitter,
|
|
10
12
|
now: now
|
|
11
13
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export var packageVersion = '10.26.1-rc.
|
|
1
|
+
export var packageVersion = '10.26.1-rc.2';
|