@becollective/utils 1.5.5 → 1.6.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.
- package/bundle.js +3600 -5
- package/index.js +8 -2
- package/jestconfig.json +11 -0
- package/package.json +18 -13
- package/rollup.config.js +6 -0
- package/setup.ts +7 -0
- package/src/featureDecision.ts +14 -0
- package/tests/featureDecision.test.ts +38 -0
- package/tsconfig.json +17 -0
- package/tslint.json +100 -0
- package/testUtils/setup.js +0 -21
- /package/{src → tests}/date-time.test.js +0 -0
- /package/{src → tests}/money.test.js +0 -0
- /package/{src → tests}/password.test.js +0 -0
package/bundle.js
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var http = require('http');
|
|
4
|
+
var https = require('https');
|
|
5
|
+
var url = require('url');
|
|
6
|
+
var require$$0 = require('stream');
|
|
7
|
+
var assert = require('assert');
|
|
8
|
+
var tty = require('tty');
|
|
9
|
+
var util$1 = require('util');
|
|
10
|
+
var os = require('os');
|
|
11
|
+
var zlib = require('zlib');
|
|
12
|
+
|
|
13
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
14
|
+
|
|
15
|
+
var http__default = /*#__PURE__*/_interopDefaultLegacy(http);
|
|
16
|
+
var https__default = /*#__PURE__*/_interopDefaultLegacy(https);
|
|
17
|
+
var url__default = /*#__PURE__*/_interopDefaultLegacy(url);
|
|
18
|
+
var require$$0__default = /*#__PURE__*/_interopDefaultLegacy(require$$0);
|
|
19
|
+
var assert__default = /*#__PURE__*/_interopDefaultLegacy(assert);
|
|
20
|
+
var tty__default = /*#__PURE__*/_interopDefaultLegacy(tty);
|
|
21
|
+
var util__default = /*#__PURE__*/_interopDefaultLegacy(util$1);
|
|
22
|
+
var os__default = /*#__PURE__*/_interopDefaultLegacy(os);
|
|
23
|
+
var zlib__default = /*#__PURE__*/_interopDefaultLegacy(zlib);
|
|
24
|
+
|
|
3
25
|
var password = {
|
|
4
26
|
hasUppercase: function hasUppercase(input) {
|
|
5
27
|
return !!input.match(/[A-Z]/);
|
|
@@ -98,8 +120,8 @@ var getShiftText = function getShiftText(from, to, timezone) {
|
|
|
98
120
|
}
|
|
99
121
|
};
|
|
100
122
|
|
|
101
|
-
var _require = require('@becollective/constants'),
|
|
102
|
-
currencies = _require.currencies; // We should probably throw and error on bad input instead of falling back to a default.
|
|
123
|
+
var _require$2 = require('@becollective/constants'),
|
|
124
|
+
currencies = _require$2.currencies; // We should probably throw and error on bad input instead of falling back to a default.
|
|
103
125
|
// We're making an assumption that whoever is calling this function can safely work
|
|
104
126
|
// with AUD. But this assumption removes a lot of error handling elsewhere.
|
|
105
127
|
|
|
@@ -164,8 +186,8 @@ var readableOpportunityType = function readableOpportunityType(type) {
|
|
|
164
186
|
return TYPE_MAP[type] || null;
|
|
165
187
|
};
|
|
166
188
|
|
|
167
|
-
var _require
|
|
168
|
-
pick = _require
|
|
189
|
+
var _require = require('lodash'),
|
|
190
|
+
pick = _require.pick;
|
|
169
191
|
/**
|
|
170
192
|
*
|
|
171
193
|
* @param {*} opportunityUser
|
|
@@ -198,6 +220,3578 @@ var getHomeLocalityFromLocationList = function getHomeLocalityFromLocationList(l
|
|
|
198
220
|
return null;
|
|
199
221
|
};
|
|
200
222
|
|
|
223
|
+
var bind = function bind(fn, thisArg) {
|
|
224
|
+
return function wrap() {
|
|
225
|
+
var args = new Array(arguments.length);
|
|
226
|
+
for (var i = 0; i < args.length; i++) {
|
|
227
|
+
args[i] = arguments[i];
|
|
228
|
+
}
|
|
229
|
+
return fn.apply(thisArg, args);
|
|
230
|
+
};
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
/*global toString:true*/
|
|
234
|
+
|
|
235
|
+
// utils is a library of generic helper functions non-specific to axios
|
|
236
|
+
|
|
237
|
+
var toString = Object.prototype.toString;
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* Determine if a value is an Array
|
|
241
|
+
*
|
|
242
|
+
* @param {Object} val The value to test
|
|
243
|
+
* @returns {boolean} True if value is an Array, otherwise false
|
|
244
|
+
*/
|
|
245
|
+
function isArray(val) {
|
|
246
|
+
return toString.call(val) === '[object Array]';
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* Determine if a value is undefined
|
|
251
|
+
*
|
|
252
|
+
* @param {Object} val The value to test
|
|
253
|
+
* @returns {boolean} True if the value is undefined, otherwise false
|
|
254
|
+
*/
|
|
255
|
+
function isUndefined(val) {
|
|
256
|
+
return typeof val === 'undefined';
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* Determine if a value is a Buffer
|
|
261
|
+
*
|
|
262
|
+
* @param {Object} val The value to test
|
|
263
|
+
* @returns {boolean} True if value is a Buffer, otherwise false
|
|
264
|
+
*/
|
|
265
|
+
function isBuffer(val) {
|
|
266
|
+
return val !== null && !isUndefined(val) && val.constructor !== null && !isUndefined(val.constructor)
|
|
267
|
+
&& typeof val.constructor.isBuffer === 'function' && val.constructor.isBuffer(val);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* Determine if a value is an ArrayBuffer
|
|
272
|
+
*
|
|
273
|
+
* @param {Object} val The value to test
|
|
274
|
+
* @returns {boolean} True if value is an ArrayBuffer, otherwise false
|
|
275
|
+
*/
|
|
276
|
+
function isArrayBuffer(val) {
|
|
277
|
+
return toString.call(val) === '[object ArrayBuffer]';
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* Determine if a value is a FormData
|
|
282
|
+
*
|
|
283
|
+
* @param {Object} val The value to test
|
|
284
|
+
* @returns {boolean} True if value is an FormData, otherwise false
|
|
285
|
+
*/
|
|
286
|
+
function isFormData(val) {
|
|
287
|
+
return (typeof FormData !== 'undefined') && (val instanceof FormData);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* Determine if a value is a view on an ArrayBuffer
|
|
292
|
+
*
|
|
293
|
+
* @param {Object} val The value to test
|
|
294
|
+
* @returns {boolean} True if value is a view on an ArrayBuffer, otherwise false
|
|
295
|
+
*/
|
|
296
|
+
function isArrayBufferView(val) {
|
|
297
|
+
var result;
|
|
298
|
+
if ((typeof ArrayBuffer !== 'undefined') && (ArrayBuffer.isView)) {
|
|
299
|
+
result = ArrayBuffer.isView(val);
|
|
300
|
+
} else {
|
|
301
|
+
result = (val) && (val.buffer) && (val.buffer instanceof ArrayBuffer);
|
|
302
|
+
}
|
|
303
|
+
return result;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* Determine if a value is a String
|
|
308
|
+
*
|
|
309
|
+
* @param {Object} val The value to test
|
|
310
|
+
* @returns {boolean} True if value is a String, otherwise false
|
|
311
|
+
*/
|
|
312
|
+
function isString(val) {
|
|
313
|
+
return typeof val === 'string';
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
/**
|
|
317
|
+
* Determine if a value is a Number
|
|
318
|
+
*
|
|
319
|
+
* @param {Object} val The value to test
|
|
320
|
+
* @returns {boolean} True if value is a Number, otherwise false
|
|
321
|
+
*/
|
|
322
|
+
function isNumber(val) {
|
|
323
|
+
return typeof val === 'number';
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* Determine if a value is an Object
|
|
328
|
+
*
|
|
329
|
+
* @param {Object} val The value to test
|
|
330
|
+
* @returns {boolean} True if value is an Object, otherwise false
|
|
331
|
+
*/
|
|
332
|
+
function isObject(val) {
|
|
333
|
+
return val !== null && typeof val === 'object';
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* Determine if a value is a plain Object
|
|
338
|
+
*
|
|
339
|
+
* @param {Object} val The value to test
|
|
340
|
+
* @return {boolean} True if value is a plain Object, otherwise false
|
|
341
|
+
*/
|
|
342
|
+
function isPlainObject(val) {
|
|
343
|
+
if (toString.call(val) !== '[object Object]') {
|
|
344
|
+
return false;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
var prototype = Object.getPrototypeOf(val);
|
|
348
|
+
return prototype === null || prototype === Object.prototype;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
/**
|
|
352
|
+
* Determine if a value is a Date
|
|
353
|
+
*
|
|
354
|
+
* @param {Object} val The value to test
|
|
355
|
+
* @returns {boolean} True if value is a Date, otherwise false
|
|
356
|
+
*/
|
|
357
|
+
function isDate(val) {
|
|
358
|
+
return toString.call(val) === '[object Date]';
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
/**
|
|
362
|
+
* Determine if a value is a File
|
|
363
|
+
*
|
|
364
|
+
* @param {Object} val The value to test
|
|
365
|
+
* @returns {boolean} True if value is a File, otherwise false
|
|
366
|
+
*/
|
|
367
|
+
function isFile(val) {
|
|
368
|
+
return toString.call(val) === '[object File]';
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
/**
|
|
372
|
+
* Determine if a value is a Blob
|
|
373
|
+
*
|
|
374
|
+
* @param {Object} val The value to test
|
|
375
|
+
* @returns {boolean} True if value is a Blob, otherwise false
|
|
376
|
+
*/
|
|
377
|
+
function isBlob(val) {
|
|
378
|
+
return toString.call(val) === '[object Blob]';
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
/**
|
|
382
|
+
* Determine if a value is a Function
|
|
383
|
+
*
|
|
384
|
+
* @param {Object} val The value to test
|
|
385
|
+
* @returns {boolean} True if value is a Function, otherwise false
|
|
386
|
+
*/
|
|
387
|
+
function isFunction(val) {
|
|
388
|
+
return toString.call(val) === '[object Function]';
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
/**
|
|
392
|
+
* Determine if a value is a Stream
|
|
393
|
+
*
|
|
394
|
+
* @param {Object} val The value to test
|
|
395
|
+
* @returns {boolean} True if value is a Stream, otherwise false
|
|
396
|
+
*/
|
|
397
|
+
function isStream(val) {
|
|
398
|
+
return isObject(val) && isFunction(val.pipe);
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
/**
|
|
402
|
+
* Determine if a value is a URLSearchParams object
|
|
403
|
+
*
|
|
404
|
+
* @param {Object} val The value to test
|
|
405
|
+
* @returns {boolean} True if value is a URLSearchParams object, otherwise false
|
|
406
|
+
*/
|
|
407
|
+
function isURLSearchParams(val) {
|
|
408
|
+
return typeof URLSearchParams !== 'undefined' && val instanceof URLSearchParams;
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
/**
|
|
412
|
+
* Trim excess whitespace off the beginning and end of a string
|
|
413
|
+
*
|
|
414
|
+
* @param {String} str The String to trim
|
|
415
|
+
* @returns {String} The String freed of excess whitespace
|
|
416
|
+
*/
|
|
417
|
+
function trim(str) {
|
|
418
|
+
return str.replace(/^\s*/, '').replace(/\s*$/, '');
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
/**
|
|
422
|
+
* Determine if we're running in a standard browser environment
|
|
423
|
+
*
|
|
424
|
+
* This allows axios to run in a web worker, and react-native.
|
|
425
|
+
* Both environments support XMLHttpRequest, but not fully standard globals.
|
|
426
|
+
*
|
|
427
|
+
* web workers:
|
|
428
|
+
* typeof window -> undefined
|
|
429
|
+
* typeof document -> undefined
|
|
430
|
+
*
|
|
431
|
+
* react-native:
|
|
432
|
+
* navigator.product -> 'ReactNative'
|
|
433
|
+
* nativescript
|
|
434
|
+
* navigator.product -> 'NativeScript' or 'NS'
|
|
435
|
+
*/
|
|
436
|
+
function isStandardBrowserEnv() {
|
|
437
|
+
if (typeof navigator !== 'undefined' && (navigator.product === 'ReactNative' ||
|
|
438
|
+
navigator.product === 'NativeScript' ||
|
|
439
|
+
navigator.product === 'NS')) {
|
|
440
|
+
return false;
|
|
441
|
+
}
|
|
442
|
+
return (
|
|
443
|
+
typeof window !== 'undefined' &&
|
|
444
|
+
typeof document !== 'undefined'
|
|
445
|
+
);
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
/**
|
|
449
|
+
* Iterate over an Array or an Object invoking a function for each item.
|
|
450
|
+
*
|
|
451
|
+
* If `obj` is an Array callback will be called passing
|
|
452
|
+
* the value, index, and complete array for each item.
|
|
453
|
+
*
|
|
454
|
+
* If 'obj' is an Object callback will be called passing
|
|
455
|
+
* the value, key, and complete object for each property.
|
|
456
|
+
*
|
|
457
|
+
* @param {Object|Array} obj The object to iterate
|
|
458
|
+
* @param {Function} fn The callback to invoke for each item
|
|
459
|
+
*/
|
|
460
|
+
function forEach(obj, fn) {
|
|
461
|
+
// Don't bother if no value provided
|
|
462
|
+
if (obj === null || typeof obj === 'undefined') {
|
|
463
|
+
return;
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
// Force an array if not already something iterable
|
|
467
|
+
if (typeof obj !== 'object') {
|
|
468
|
+
/*eslint no-param-reassign:0*/
|
|
469
|
+
obj = [obj];
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
if (isArray(obj)) {
|
|
473
|
+
// Iterate over array values
|
|
474
|
+
for (var i = 0, l = obj.length; i < l; i++) {
|
|
475
|
+
fn.call(null, obj[i], i, obj);
|
|
476
|
+
}
|
|
477
|
+
} else {
|
|
478
|
+
// Iterate over object keys
|
|
479
|
+
for (var key in obj) {
|
|
480
|
+
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
481
|
+
fn.call(null, obj[key], key, obj);
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
/**
|
|
488
|
+
* Accepts varargs expecting each argument to be an object, then
|
|
489
|
+
* immutably merges the properties of each object and returns result.
|
|
490
|
+
*
|
|
491
|
+
* When multiple objects contain the same key the later object in
|
|
492
|
+
* the arguments list will take precedence.
|
|
493
|
+
*
|
|
494
|
+
* Example:
|
|
495
|
+
*
|
|
496
|
+
* ```js
|
|
497
|
+
* var result = merge({foo: 123}, {foo: 456});
|
|
498
|
+
* console.log(result.foo); // outputs 456
|
|
499
|
+
* ```
|
|
500
|
+
*
|
|
501
|
+
* @param {Object} obj1 Object to merge
|
|
502
|
+
* @returns {Object} Result of all merge properties
|
|
503
|
+
*/
|
|
504
|
+
function merge(/* obj1, obj2, obj3, ... */) {
|
|
505
|
+
var result = {};
|
|
506
|
+
function assignValue(val, key) {
|
|
507
|
+
if (isPlainObject(result[key]) && isPlainObject(val)) {
|
|
508
|
+
result[key] = merge(result[key], val);
|
|
509
|
+
} else if (isPlainObject(val)) {
|
|
510
|
+
result[key] = merge({}, val);
|
|
511
|
+
} else if (isArray(val)) {
|
|
512
|
+
result[key] = val.slice();
|
|
513
|
+
} else {
|
|
514
|
+
result[key] = val;
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
for (var i = 0, l = arguments.length; i < l; i++) {
|
|
519
|
+
forEach(arguments[i], assignValue);
|
|
520
|
+
}
|
|
521
|
+
return result;
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
/**
|
|
525
|
+
* Extends object a by mutably adding to it the properties of object b.
|
|
526
|
+
*
|
|
527
|
+
* @param {Object} a The object to be extended
|
|
528
|
+
* @param {Object} b The object to copy properties from
|
|
529
|
+
* @param {Object} thisArg The object to bind function to
|
|
530
|
+
* @return {Object} The resulting value of object a
|
|
531
|
+
*/
|
|
532
|
+
function extend(a, b, thisArg) {
|
|
533
|
+
forEach(b, function assignValue(val, key) {
|
|
534
|
+
if (thisArg && typeof val === 'function') {
|
|
535
|
+
a[key] = bind(val, thisArg);
|
|
536
|
+
} else {
|
|
537
|
+
a[key] = val;
|
|
538
|
+
}
|
|
539
|
+
});
|
|
540
|
+
return a;
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
/**
|
|
544
|
+
* Remove byte order marker. This catches EF BB BF (the UTF-8 BOM)
|
|
545
|
+
*
|
|
546
|
+
* @param {string} content with BOM
|
|
547
|
+
* @return {string} content value without BOM
|
|
548
|
+
*/
|
|
549
|
+
function stripBOM(content) {
|
|
550
|
+
if (content.charCodeAt(0) === 0xFEFF) {
|
|
551
|
+
content = content.slice(1);
|
|
552
|
+
}
|
|
553
|
+
return content;
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
var utils = {
|
|
557
|
+
isArray: isArray,
|
|
558
|
+
isArrayBuffer: isArrayBuffer,
|
|
559
|
+
isBuffer: isBuffer,
|
|
560
|
+
isFormData: isFormData,
|
|
561
|
+
isArrayBufferView: isArrayBufferView,
|
|
562
|
+
isString: isString,
|
|
563
|
+
isNumber: isNumber,
|
|
564
|
+
isObject: isObject,
|
|
565
|
+
isPlainObject: isPlainObject,
|
|
566
|
+
isUndefined: isUndefined,
|
|
567
|
+
isDate: isDate,
|
|
568
|
+
isFile: isFile,
|
|
569
|
+
isBlob: isBlob,
|
|
570
|
+
isFunction: isFunction,
|
|
571
|
+
isStream: isStream,
|
|
572
|
+
isURLSearchParams: isURLSearchParams,
|
|
573
|
+
isStandardBrowserEnv: isStandardBrowserEnv,
|
|
574
|
+
forEach: forEach,
|
|
575
|
+
merge: merge,
|
|
576
|
+
extend: extend,
|
|
577
|
+
trim: trim,
|
|
578
|
+
stripBOM: stripBOM
|
|
579
|
+
};
|
|
580
|
+
|
|
581
|
+
function encode(val) {
|
|
582
|
+
return encodeURIComponent(val).
|
|
583
|
+
replace(/%3A/gi, ':').
|
|
584
|
+
replace(/%24/g, '$').
|
|
585
|
+
replace(/%2C/gi, ',').
|
|
586
|
+
replace(/%20/g, '+').
|
|
587
|
+
replace(/%5B/gi, '[').
|
|
588
|
+
replace(/%5D/gi, ']');
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
/**
|
|
592
|
+
* Build a URL by appending params to the end
|
|
593
|
+
*
|
|
594
|
+
* @param {string} url The base of the url (e.g., http://www.google.com)
|
|
595
|
+
* @param {object} [params] The params to be appended
|
|
596
|
+
* @returns {string} The formatted url
|
|
597
|
+
*/
|
|
598
|
+
var buildURL = function buildURL(url, params, paramsSerializer) {
|
|
599
|
+
/*eslint no-param-reassign:0*/
|
|
600
|
+
if (!params) {
|
|
601
|
+
return url;
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
var serializedParams;
|
|
605
|
+
if (paramsSerializer) {
|
|
606
|
+
serializedParams = paramsSerializer(params);
|
|
607
|
+
} else if (utils.isURLSearchParams(params)) {
|
|
608
|
+
serializedParams = params.toString();
|
|
609
|
+
} else {
|
|
610
|
+
var parts = [];
|
|
611
|
+
|
|
612
|
+
utils.forEach(params, function serialize(val, key) {
|
|
613
|
+
if (val === null || typeof val === 'undefined') {
|
|
614
|
+
return;
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
if (utils.isArray(val)) {
|
|
618
|
+
key = key + '[]';
|
|
619
|
+
} else {
|
|
620
|
+
val = [val];
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
utils.forEach(val, function parseValue(v) {
|
|
624
|
+
if (utils.isDate(v)) {
|
|
625
|
+
v = v.toISOString();
|
|
626
|
+
} else if (utils.isObject(v)) {
|
|
627
|
+
v = JSON.stringify(v);
|
|
628
|
+
}
|
|
629
|
+
parts.push(encode(key) + '=' + encode(v));
|
|
630
|
+
});
|
|
631
|
+
});
|
|
632
|
+
|
|
633
|
+
serializedParams = parts.join('&');
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
if (serializedParams) {
|
|
637
|
+
var hashmarkIndex = url.indexOf('#');
|
|
638
|
+
if (hashmarkIndex !== -1) {
|
|
639
|
+
url = url.slice(0, hashmarkIndex);
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
url += (url.indexOf('?') === -1 ? '?' : '&') + serializedParams;
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
return url;
|
|
646
|
+
};
|
|
647
|
+
|
|
648
|
+
function InterceptorManager() {
|
|
649
|
+
this.handlers = [];
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
/**
|
|
653
|
+
* Add a new interceptor to the stack
|
|
654
|
+
*
|
|
655
|
+
* @param {Function} fulfilled The function to handle `then` for a `Promise`
|
|
656
|
+
* @param {Function} rejected The function to handle `reject` for a `Promise`
|
|
657
|
+
*
|
|
658
|
+
* @return {Number} An ID used to remove interceptor later
|
|
659
|
+
*/
|
|
660
|
+
InterceptorManager.prototype.use = function use(fulfilled, rejected) {
|
|
661
|
+
this.handlers.push({
|
|
662
|
+
fulfilled: fulfilled,
|
|
663
|
+
rejected: rejected
|
|
664
|
+
});
|
|
665
|
+
return this.handlers.length - 1;
|
|
666
|
+
};
|
|
667
|
+
|
|
668
|
+
/**
|
|
669
|
+
* Remove an interceptor from the stack
|
|
670
|
+
*
|
|
671
|
+
* @param {Number} id The ID that was returned by `use`
|
|
672
|
+
*/
|
|
673
|
+
InterceptorManager.prototype.eject = function eject(id) {
|
|
674
|
+
if (this.handlers[id]) {
|
|
675
|
+
this.handlers[id] = null;
|
|
676
|
+
}
|
|
677
|
+
};
|
|
678
|
+
|
|
679
|
+
/**
|
|
680
|
+
* Iterate over all the registered interceptors
|
|
681
|
+
*
|
|
682
|
+
* This method is particularly useful for skipping over any
|
|
683
|
+
* interceptors that may have become `null` calling `eject`.
|
|
684
|
+
*
|
|
685
|
+
* @param {Function} fn The function to call for each interceptor
|
|
686
|
+
*/
|
|
687
|
+
InterceptorManager.prototype.forEach = function forEach(fn) {
|
|
688
|
+
utils.forEach(this.handlers, function forEachHandler(h) {
|
|
689
|
+
if (h !== null) {
|
|
690
|
+
fn(h);
|
|
691
|
+
}
|
|
692
|
+
});
|
|
693
|
+
};
|
|
694
|
+
|
|
695
|
+
var InterceptorManager_1 = InterceptorManager;
|
|
696
|
+
|
|
697
|
+
/**
|
|
698
|
+
* Transform the data for a request or a response
|
|
699
|
+
*
|
|
700
|
+
* @param {Object|String} data The data to be transformed
|
|
701
|
+
* @param {Array} headers The headers for the request or response
|
|
702
|
+
* @param {Array|Function} fns A single function or Array of functions
|
|
703
|
+
* @returns {*} The resulting transformed data
|
|
704
|
+
*/
|
|
705
|
+
var transformData = function transformData(data, headers, fns) {
|
|
706
|
+
/*eslint no-param-reassign:0*/
|
|
707
|
+
utils.forEach(fns, function transform(fn) {
|
|
708
|
+
data = fn(data, headers);
|
|
709
|
+
});
|
|
710
|
+
|
|
711
|
+
return data;
|
|
712
|
+
};
|
|
713
|
+
|
|
714
|
+
var isCancel = function isCancel(value) {
|
|
715
|
+
return !!(value && value.__CANCEL__);
|
|
716
|
+
};
|
|
717
|
+
|
|
718
|
+
var normalizeHeaderName = function normalizeHeaderName(headers, normalizedName) {
|
|
719
|
+
utils.forEach(headers, function processHeader(value, name) {
|
|
720
|
+
if (name !== normalizedName && name.toUpperCase() === normalizedName.toUpperCase()) {
|
|
721
|
+
headers[normalizedName] = value;
|
|
722
|
+
delete headers[name];
|
|
723
|
+
}
|
|
724
|
+
});
|
|
725
|
+
};
|
|
726
|
+
|
|
727
|
+
/**
|
|
728
|
+
* Update an Error with the specified config, error code, and response.
|
|
729
|
+
*
|
|
730
|
+
* @param {Error} error The error to update.
|
|
731
|
+
* @param {Object} config The config.
|
|
732
|
+
* @param {string} [code] The error code (for example, 'ECONNABORTED').
|
|
733
|
+
* @param {Object} [request] The request.
|
|
734
|
+
* @param {Object} [response] The response.
|
|
735
|
+
* @returns {Error} The error.
|
|
736
|
+
*/
|
|
737
|
+
var enhanceError = function enhanceError(error, config, code, request, response) {
|
|
738
|
+
error.config = config;
|
|
739
|
+
if (code) {
|
|
740
|
+
error.code = code;
|
|
741
|
+
}
|
|
742
|
+
|
|
743
|
+
error.request = request;
|
|
744
|
+
error.response = response;
|
|
745
|
+
error.isAxiosError = true;
|
|
746
|
+
|
|
747
|
+
error.toJSON = function toJSON() {
|
|
748
|
+
return {
|
|
749
|
+
// Standard
|
|
750
|
+
message: this.message,
|
|
751
|
+
name: this.name,
|
|
752
|
+
// Microsoft
|
|
753
|
+
description: this.description,
|
|
754
|
+
number: this.number,
|
|
755
|
+
// Mozilla
|
|
756
|
+
fileName: this.fileName,
|
|
757
|
+
lineNumber: this.lineNumber,
|
|
758
|
+
columnNumber: this.columnNumber,
|
|
759
|
+
stack: this.stack,
|
|
760
|
+
// Axios
|
|
761
|
+
config: this.config,
|
|
762
|
+
code: this.code
|
|
763
|
+
};
|
|
764
|
+
};
|
|
765
|
+
return error;
|
|
766
|
+
};
|
|
767
|
+
|
|
768
|
+
/**
|
|
769
|
+
* Create an Error with the specified message, config, error code, request and response.
|
|
770
|
+
*
|
|
771
|
+
* @param {string} message The error message.
|
|
772
|
+
* @param {Object} config The config.
|
|
773
|
+
* @param {string} [code] The error code (for example, 'ECONNABORTED').
|
|
774
|
+
* @param {Object} [request] The request.
|
|
775
|
+
* @param {Object} [response] The response.
|
|
776
|
+
* @returns {Error} The created error.
|
|
777
|
+
*/
|
|
778
|
+
var createError = function createError(message, config, code, request, response) {
|
|
779
|
+
var error = new Error(message);
|
|
780
|
+
return enhanceError(error, config, code, request, response);
|
|
781
|
+
};
|
|
782
|
+
|
|
783
|
+
/**
|
|
784
|
+
* Resolve or reject a Promise based on response status.
|
|
785
|
+
*
|
|
786
|
+
* @param {Function} resolve A function that resolves the promise.
|
|
787
|
+
* @param {Function} reject A function that rejects the promise.
|
|
788
|
+
* @param {object} response The response.
|
|
789
|
+
*/
|
|
790
|
+
var settle = function settle(resolve, reject, response) {
|
|
791
|
+
var validateStatus = response.config.validateStatus;
|
|
792
|
+
if (!response.status || !validateStatus || validateStatus(response.status)) {
|
|
793
|
+
resolve(response);
|
|
794
|
+
} else {
|
|
795
|
+
reject(createError(
|
|
796
|
+
'Request failed with status code ' + response.status,
|
|
797
|
+
response.config,
|
|
798
|
+
null,
|
|
799
|
+
response.request,
|
|
800
|
+
response
|
|
801
|
+
));
|
|
802
|
+
}
|
|
803
|
+
};
|
|
804
|
+
|
|
805
|
+
var cookies = (
|
|
806
|
+
utils.isStandardBrowserEnv() ?
|
|
807
|
+
|
|
808
|
+
// Standard browser envs support document.cookie
|
|
809
|
+
(function standardBrowserEnv() {
|
|
810
|
+
return {
|
|
811
|
+
write: function write(name, value, expires, path, domain, secure) {
|
|
812
|
+
var cookie = [];
|
|
813
|
+
cookie.push(name + '=' + encodeURIComponent(value));
|
|
814
|
+
|
|
815
|
+
if (utils.isNumber(expires)) {
|
|
816
|
+
cookie.push('expires=' + new Date(expires).toGMTString());
|
|
817
|
+
}
|
|
818
|
+
|
|
819
|
+
if (utils.isString(path)) {
|
|
820
|
+
cookie.push('path=' + path);
|
|
821
|
+
}
|
|
822
|
+
|
|
823
|
+
if (utils.isString(domain)) {
|
|
824
|
+
cookie.push('domain=' + domain);
|
|
825
|
+
}
|
|
826
|
+
|
|
827
|
+
if (secure === true) {
|
|
828
|
+
cookie.push('secure');
|
|
829
|
+
}
|
|
830
|
+
|
|
831
|
+
document.cookie = cookie.join('; ');
|
|
832
|
+
},
|
|
833
|
+
|
|
834
|
+
read: function read(name) {
|
|
835
|
+
var match = document.cookie.match(new RegExp('(^|;\\s*)(' + name + ')=([^;]*)'));
|
|
836
|
+
return (match ? decodeURIComponent(match[3]) : null);
|
|
837
|
+
},
|
|
838
|
+
|
|
839
|
+
remove: function remove(name) {
|
|
840
|
+
this.write(name, '', Date.now() - 86400000);
|
|
841
|
+
}
|
|
842
|
+
};
|
|
843
|
+
})() :
|
|
844
|
+
|
|
845
|
+
// Non standard browser env (web workers, react-native) lack needed support.
|
|
846
|
+
(function nonStandardBrowserEnv() {
|
|
847
|
+
return {
|
|
848
|
+
write: function write() {},
|
|
849
|
+
read: function read() { return null; },
|
|
850
|
+
remove: function remove() {}
|
|
851
|
+
};
|
|
852
|
+
})()
|
|
853
|
+
);
|
|
854
|
+
|
|
855
|
+
/**
|
|
856
|
+
* Determines whether the specified URL is absolute
|
|
857
|
+
*
|
|
858
|
+
* @param {string} url The URL to test
|
|
859
|
+
* @returns {boolean} True if the specified URL is absolute, otherwise false
|
|
860
|
+
*/
|
|
861
|
+
var isAbsoluteURL = function isAbsoluteURL(url) {
|
|
862
|
+
// A URL is considered absolute if it begins with "<scheme>://" or "//" (protocol-relative URL).
|
|
863
|
+
// RFC 3986 defines scheme name as a sequence of characters beginning with a letter and followed
|
|
864
|
+
// by any combination of letters, digits, plus, period, or hyphen.
|
|
865
|
+
return /^([a-z][a-z\d\+\-\.]*:)?\/\//i.test(url);
|
|
866
|
+
};
|
|
867
|
+
|
|
868
|
+
/**
|
|
869
|
+
* Creates a new URL by combining the specified URLs
|
|
870
|
+
*
|
|
871
|
+
* @param {string} baseURL The base URL
|
|
872
|
+
* @param {string} relativeURL The relative URL
|
|
873
|
+
* @returns {string} The combined URL
|
|
874
|
+
*/
|
|
875
|
+
var combineURLs = function combineURLs(baseURL, relativeURL) {
|
|
876
|
+
return relativeURL
|
|
877
|
+
? baseURL.replace(/\/+$/, '') + '/' + relativeURL.replace(/^\/+/, '')
|
|
878
|
+
: baseURL;
|
|
879
|
+
};
|
|
880
|
+
|
|
881
|
+
/**
|
|
882
|
+
* Creates a new URL by combining the baseURL with the requestedURL,
|
|
883
|
+
* only when the requestedURL is not already an absolute URL.
|
|
884
|
+
* If the requestURL is absolute, this function returns the requestedURL untouched.
|
|
885
|
+
*
|
|
886
|
+
* @param {string} baseURL The base URL
|
|
887
|
+
* @param {string} requestedURL Absolute or relative URL to combine
|
|
888
|
+
* @returns {string} The combined full path
|
|
889
|
+
*/
|
|
890
|
+
var buildFullPath = function buildFullPath(baseURL, requestedURL) {
|
|
891
|
+
if (baseURL && !isAbsoluteURL(requestedURL)) {
|
|
892
|
+
return combineURLs(baseURL, requestedURL);
|
|
893
|
+
}
|
|
894
|
+
return requestedURL;
|
|
895
|
+
};
|
|
896
|
+
|
|
897
|
+
// Headers whose duplicates are ignored by node
|
|
898
|
+
// c.f. https://nodejs.org/api/http.html#http_message_headers
|
|
899
|
+
var ignoreDuplicateOf = [
|
|
900
|
+
'age', 'authorization', 'content-length', 'content-type', 'etag',
|
|
901
|
+
'expires', 'from', 'host', 'if-modified-since', 'if-unmodified-since',
|
|
902
|
+
'last-modified', 'location', 'max-forwards', 'proxy-authorization',
|
|
903
|
+
'referer', 'retry-after', 'user-agent'
|
|
904
|
+
];
|
|
905
|
+
|
|
906
|
+
/**
|
|
907
|
+
* Parse headers into an object
|
|
908
|
+
*
|
|
909
|
+
* ```
|
|
910
|
+
* Date: Wed, 27 Aug 2014 08:58:49 GMT
|
|
911
|
+
* Content-Type: application/json
|
|
912
|
+
* Connection: keep-alive
|
|
913
|
+
* Transfer-Encoding: chunked
|
|
914
|
+
* ```
|
|
915
|
+
*
|
|
916
|
+
* @param {String} headers Headers needing to be parsed
|
|
917
|
+
* @returns {Object} Headers parsed into an object
|
|
918
|
+
*/
|
|
919
|
+
var parseHeaders = function parseHeaders(headers) {
|
|
920
|
+
var parsed = {};
|
|
921
|
+
var key;
|
|
922
|
+
var val;
|
|
923
|
+
var i;
|
|
924
|
+
|
|
925
|
+
if (!headers) { return parsed; }
|
|
926
|
+
|
|
927
|
+
utils.forEach(headers.split('\n'), function parser(line) {
|
|
928
|
+
i = line.indexOf(':');
|
|
929
|
+
key = utils.trim(line.substr(0, i)).toLowerCase();
|
|
930
|
+
val = utils.trim(line.substr(i + 1));
|
|
931
|
+
|
|
932
|
+
if (key) {
|
|
933
|
+
if (parsed[key] && ignoreDuplicateOf.indexOf(key) >= 0) {
|
|
934
|
+
return;
|
|
935
|
+
}
|
|
936
|
+
if (key === 'set-cookie') {
|
|
937
|
+
parsed[key] = (parsed[key] ? parsed[key] : []).concat([val]);
|
|
938
|
+
} else {
|
|
939
|
+
parsed[key] = parsed[key] ? parsed[key] + ', ' + val : val;
|
|
940
|
+
}
|
|
941
|
+
}
|
|
942
|
+
});
|
|
943
|
+
|
|
944
|
+
return parsed;
|
|
945
|
+
};
|
|
946
|
+
|
|
947
|
+
var isURLSameOrigin = (
|
|
948
|
+
utils.isStandardBrowserEnv() ?
|
|
949
|
+
|
|
950
|
+
// Standard browser envs have full support of the APIs needed to test
|
|
951
|
+
// whether the request URL is of the same origin as current location.
|
|
952
|
+
(function standardBrowserEnv() {
|
|
953
|
+
var msie = /(msie|trident)/i.test(navigator.userAgent);
|
|
954
|
+
var urlParsingNode = document.createElement('a');
|
|
955
|
+
var originURL;
|
|
956
|
+
|
|
957
|
+
/**
|
|
958
|
+
* Parse a URL to discover it's components
|
|
959
|
+
*
|
|
960
|
+
* @param {String} url The URL to be parsed
|
|
961
|
+
* @returns {Object}
|
|
962
|
+
*/
|
|
963
|
+
function resolveURL(url) {
|
|
964
|
+
var href = url;
|
|
965
|
+
|
|
966
|
+
if (msie) {
|
|
967
|
+
// IE needs attribute set twice to normalize properties
|
|
968
|
+
urlParsingNode.setAttribute('href', href);
|
|
969
|
+
href = urlParsingNode.href;
|
|
970
|
+
}
|
|
971
|
+
|
|
972
|
+
urlParsingNode.setAttribute('href', href);
|
|
973
|
+
|
|
974
|
+
// urlParsingNode provides the UrlUtils interface - http://url.spec.whatwg.org/#urlutils
|
|
975
|
+
return {
|
|
976
|
+
href: urlParsingNode.href,
|
|
977
|
+
protocol: urlParsingNode.protocol ? urlParsingNode.protocol.replace(/:$/, '') : '',
|
|
978
|
+
host: urlParsingNode.host,
|
|
979
|
+
search: urlParsingNode.search ? urlParsingNode.search.replace(/^\?/, '') : '',
|
|
980
|
+
hash: urlParsingNode.hash ? urlParsingNode.hash.replace(/^#/, '') : '',
|
|
981
|
+
hostname: urlParsingNode.hostname,
|
|
982
|
+
port: urlParsingNode.port,
|
|
983
|
+
pathname: (urlParsingNode.pathname.charAt(0) === '/') ?
|
|
984
|
+
urlParsingNode.pathname :
|
|
985
|
+
'/' + urlParsingNode.pathname
|
|
986
|
+
};
|
|
987
|
+
}
|
|
988
|
+
|
|
989
|
+
originURL = resolveURL(window.location.href);
|
|
990
|
+
|
|
991
|
+
/**
|
|
992
|
+
* Determine if a URL shares the same origin as the current location
|
|
993
|
+
*
|
|
994
|
+
* @param {String} requestURL The URL to test
|
|
995
|
+
* @returns {boolean} True if URL shares the same origin, otherwise false
|
|
996
|
+
*/
|
|
997
|
+
return function isURLSameOrigin(requestURL) {
|
|
998
|
+
var parsed = (utils.isString(requestURL)) ? resolveURL(requestURL) : requestURL;
|
|
999
|
+
return (parsed.protocol === originURL.protocol &&
|
|
1000
|
+
parsed.host === originURL.host);
|
|
1001
|
+
};
|
|
1002
|
+
})() :
|
|
1003
|
+
|
|
1004
|
+
// Non standard browser envs (web workers, react-native) lack needed support.
|
|
1005
|
+
(function nonStandardBrowserEnv() {
|
|
1006
|
+
return function isURLSameOrigin() {
|
|
1007
|
+
return true;
|
|
1008
|
+
};
|
|
1009
|
+
})()
|
|
1010
|
+
);
|
|
1011
|
+
|
|
1012
|
+
var xhr = function xhrAdapter(config) {
|
|
1013
|
+
return new Promise(function dispatchXhrRequest(resolve, reject) {
|
|
1014
|
+
var requestData = config.data;
|
|
1015
|
+
var requestHeaders = config.headers;
|
|
1016
|
+
|
|
1017
|
+
if (utils.isFormData(requestData)) {
|
|
1018
|
+
delete requestHeaders['Content-Type']; // Let the browser set it
|
|
1019
|
+
}
|
|
1020
|
+
|
|
1021
|
+
var request = new XMLHttpRequest();
|
|
1022
|
+
|
|
1023
|
+
// HTTP basic authentication
|
|
1024
|
+
if (config.auth) {
|
|
1025
|
+
var username = config.auth.username || '';
|
|
1026
|
+
var password = config.auth.password ? unescape(encodeURIComponent(config.auth.password)) : '';
|
|
1027
|
+
requestHeaders.Authorization = 'Basic ' + btoa(username + ':' + password);
|
|
1028
|
+
}
|
|
1029
|
+
|
|
1030
|
+
var fullPath = buildFullPath(config.baseURL, config.url);
|
|
1031
|
+
request.open(config.method.toUpperCase(), buildURL(fullPath, config.params, config.paramsSerializer), true);
|
|
1032
|
+
|
|
1033
|
+
// Set the request timeout in MS
|
|
1034
|
+
request.timeout = config.timeout;
|
|
1035
|
+
|
|
1036
|
+
// Listen for ready state
|
|
1037
|
+
request.onreadystatechange = function handleLoad() {
|
|
1038
|
+
if (!request || request.readyState !== 4) {
|
|
1039
|
+
return;
|
|
1040
|
+
}
|
|
1041
|
+
|
|
1042
|
+
// The request errored out and we didn't get a response, this will be
|
|
1043
|
+
// handled by onerror instead
|
|
1044
|
+
// With one exception: request that using file: protocol, most browsers
|
|
1045
|
+
// will return status as 0 even though it's a successful request
|
|
1046
|
+
if (request.status === 0 && !(request.responseURL && request.responseURL.indexOf('file:') === 0)) {
|
|
1047
|
+
return;
|
|
1048
|
+
}
|
|
1049
|
+
|
|
1050
|
+
// Prepare the response
|
|
1051
|
+
var responseHeaders = 'getAllResponseHeaders' in request ? parseHeaders(request.getAllResponseHeaders()) : null;
|
|
1052
|
+
var responseData = !config.responseType || config.responseType === 'text' ? request.responseText : request.response;
|
|
1053
|
+
var response = {
|
|
1054
|
+
data: responseData,
|
|
1055
|
+
status: request.status,
|
|
1056
|
+
statusText: request.statusText,
|
|
1057
|
+
headers: responseHeaders,
|
|
1058
|
+
config: config,
|
|
1059
|
+
request: request
|
|
1060
|
+
};
|
|
1061
|
+
|
|
1062
|
+
settle(resolve, reject, response);
|
|
1063
|
+
|
|
1064
|
+
// Clean up request
|
|
1065
|
+
request = null;
|
|
1066
|
+
};
|
|
1067
|
+
|
|
1068
|
+
// Handle browser request cancellation (as opposed to a manual cancellation)
|
|
1069
|
+
request.onabort = function handleAbort() {
|
|
1070
|
+
if (!request) {
|
|
1071
|
+
return;
|
|
1072
|
+
}
|
|
1073
|
+
|
|
1074
|
+
reject(createError('Request aborted', config, 'ECONNABORTED', request));
|
|
1075
|
+
|
|
1076
|
+
// Clean up request
|
|
1077
|
+
request = null;
|
|
1078
|
+
};
|
|
1079
|
+
|
|
1080
|
+
// Handle low level network errors
|
|
1081
|
+
request.onerror = function handleError() {
|
|
1082
|
+
// Real errors are hidden from us by the browser
|
|
1083
|
+
// onerror should only fire if it's a network error
|
|
1084
|
+
reject(createError('Network Error', config, null, request));
|
|
1085
|
+
|
|
1086
|
+
// Clean up request
|
|
1087
|
+
request = null;
|
|
1088
|
+
};
|
|
1089
|
+
|
|
1090
|
+
// Handle timeout
|
|
1091
|
+
request.ontimeout = function handleTimeout() {
|
|
1092
|
+
var timeoutErrorMessage = 'timeout of ' + config.timeout + 'ms exceeded';
|
|
1093
|
+
if (config.timeoutErrorMessage) {
|
|
1094
|
+
timeoutErrorMessage = config.timeoutErrorMessage;
|
|
1095
|
+
}
|
|
1096
|
+
reject(createError(timeoutErrorMessage, config, 'ECONNABORTED',
|
|
1097
|
+
request));
|
|
1098
|
+
|
|
1099
|
+
// Clean up request
|
|
1100
|
+
request = null;
|
|
1101
|
+
};
|
|
1102
|
+
|
|
1103
|
+
// Add xsrf header
|
|
1104
|
+
// This is only done if running in a standard browser environment.
|
|
1105
|
+
// Specifically not if we're in a web worker, or react-native.
|
|
1106
|
+
if (utils.isStandardBrowserEnv()) {
|
|
1107
|
+
// Add xsrf header
|
|
1108
|
+
var xsrfValue = (config.withCredentials || isURLSameOrigin(fullPath)) && config.xsrfCookieName ?
|
|
1109
|
+
cookies.read(config.xsrfCookieName) :
|
|
1110
|
+
undefined;
|
|
1111
|
+
|
|
1112
|
+
if (xsrfValue) {
|
|
1113
|
+
requestHeaders[config.xsrfHeaderName] = xsrfValue;
|
|
1114
|
+
}
|
|
1115
|
+
}
|
|
1116
|
+
|
|
1117
|
+
// Add headers to the request
|
|
1118
|
+
if ('setRequestHeader' in request) {
|
|
1119
|
+
utils.forEach(requestHeaders, function setRequestHeader(val, key) {
|
|
1120
|
+
if (typeof requestData === 'undefined' && key.toLowerCase() === 'content-type') {
|
|
1121
|
+
// Remove Content-Type if data is undefined
|
|
1122
|
+
delete requestHeaders[key];
|
|
1123
|
+
} else {
|
|
1124
|
+
// Otherwise add header to the request
|
|
1125
|
+
request.setRequestHeader(key, val);
|
|
1126
|
+
}
|
|
1127
|
+
});
|
|
1128
|
+
}
|
|
1129
|
+
|
|
1130
|
+
// Add withCredentials to request if needed
|
|
1131
|
+
if (!utils.isUndefined(config.withCredentials)) {
|
|
1132
|
+
request.withCredentials = !!config.withCredentials;
|
|
1133
|
+
}
|
|
1134
|
+
|
|
1135
|
+
// Add responseType to request if needed
|
|
1136
|
+
if (config.responseType) {
|
|
1137
|
+
try {
|
|
1138
|
+
request.responseType = config.responseType;
|
|
1139
|
+
} catch (e) {
|
|
1140
|
+
// Expected DOMException thrown by browsers not compatible XMLHttpRequest Level 2.
|
|
1141
|
+
// But, this can be suppressed for 'json' type as it can be parsed by default 'transformResponse' function.
|
|
1142
|
+
if (config.responseType !== 'json') {
|
|
1143
|
+
throw e;
|
|
1144
|
+
}
|
|
1145
|
+
}
|
|
1146
|
+
}
|
|
1147
|
+
|
|
1148
|
+
// Handle progress if needed
|
|
1149
|
+
if (typeof config.onDownloadProgress === 'function') {
|
|
1150
|
+
request.addEventListener('progress', config.onDownloadProgress);
|
|
1151
|
+
}
|
|
1152
|
+
|
|
1153
|
+
// Not all browsers support upload events
|
|
1154
|
+
if (typeof config.onUploadProgress === 'function' && request.upload) {
|
|
1155
|
+
request.upload.addEventListener('progress', config.onUploadProgress);
|
|
1156
|
+
}
|
|
1157
|
+
|
|
1158
|
+
if (config.cancelToken) {
|
|
1159
|
+
// Handle cancellation
|
|
1160
|
+
config.cancelToken.promise.then(function onCanceled(cancel) {
|
|
1161
|
+
if (!request) {
|
|
1162
|
+
return;
|
|
1163
|
+
}
|
|
1164
|
+
|
|
1165
|
+
request.abort();
|
|
1166
|
+
reject(cancel);
|
|
1167
|
+
// Clean up request
|
|
1168
|
+
request = null;
|
|
1169
|
+
});
|
|
1170
|
+
}
|
|
1171
|
+
|
|
1172
|
+
if (!requestData) {
|
|
1173
|
+
requestData = null;
|
|
1174
|
+
}
|
|
1175
|
+
|
|
1176
|
+
// Send the request
|
|
1177
|
+
request.send(requestData);
|
|
1178
|
+
});
|
|
1179
|
+
};
|
|
1180
|
+
|
|
1181
|
+
function createCommonjsModule(fn) {
|
|
1182
|
+
var module = { exports: {} };
|
|
1183
|
+
return fn(module, module.exports), module.exports;
|
|
1184
|
+
}
|
|
1185
|
+
|
|
1186
|
+
/**
|
|
1187
|
+
* Helpers.
|
|
1188
|
+
*/
|
|
1189
|
+
var s = 1000;
|
|
1190
|
+
var m = s * 60;
|
|
1191
|
+
var h = m * 60;
|
|
1192
|
+
var d = h * 24;
|
|
1193
|
+
var w = d * 7;
|
|
1194
|
+
var y = d * 365.25;
|
|
1195
|
+
|
|
1196
|
+
/**
|
|
1197
|
+
* Parse or format the given `val`.
|
|
1198
|
+
*
|
|
1199
|
+
* Options:
|
|
1200
|
+
*
|
|
1201
|
+
* - `long` verbose formatting [false]
|
|
1202
|
+
*
|
|
1203
|
+
* @param {String|Number} val
|
|
1204
|
+
* @param {Object} [options]
|
|
1205
|
+
* @throws {Error} throw an error if val is not a non-empty string or a number
|
|
1206
|
+
* @return {String|Number}
|
|
1207
|
+
* @api public
|
|
1208
|
+
*/
|
|
1209
|
+
|
|
1210
|
+
var ms = function(val, options) {
|
|
1211
|
+
options = options || {};
|
|
1212
|
+
var type = typeof val;
|
|
1213
|
+
if (type === 'string' && val.length > 0) {
|
|
1214
|
+
return parse(val);
|
|
1215
|
+
} else if (type === 'number' && isFinite(val)) {
|
|
1216
|
+
return options.long ? fmtLong(val) : fmtShort(val);
|
|
1217
|
+
}
|
|
1218
|
+
throw new Error(
|
|
1219
|
+
'val is not a non-empty string or a valid number. val=' +
|
|
1220
|
+
JSON.stringify(val)
|
|
1221
|
+
);
|
|
1222
|
+
};
|
|
1223
|
+
|
|
1224
|
+
/**
|
|
1225
|
+
* Parse the given `str` and return milliseconds.
|
|
1226
|
+
*
|
|
1227
|
+
* @param {String} str
|
|
1228
|
+
* @return {Number}
|
|
1229
|
+
* @api private
|
|
1230
|
+
*/
|
|
1231
|
+
|
|
1232
|
+
function parse(str) {
|
|
1233
|
+
str = String(str);
|
|
1234
|
+
if (str.length > 100) {
|
|
1235
|
+
return;
|
|
1236
|
+
}
|
|
1237
|
+
var match = /^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(
|
|
1238
|
+
str
|
|
1239
|
+
);
|
|
1240
|
+
if (!match) {
|
|
1241
|
+
return;
|
|
1242
|
+
}
|
|
1243
|
+
var n = parseFloat(match[1]);
|
|
1244
|
+
var type = (match[2] || 'ms').toLowerCase();
|
|
1245
|
+
switch (type) {
|
|
1246
|
+
case 'years':
|
|
1247
|
+
case 'year':
|
|
1248
|
+
case 'yrs':
|
|
1249
|
+
case 'yr':
|
|
1250
|
+
case 'y':
|
|
1251
|
+
return n * y;
|
|
1252
|
+
case 'weeks':
|
|
1253
|
+
case 'week':
|
|
1254
|
+
case 'w':
|
|
1255
|
+
return n * w;
|
|
1256
|
+
case 'days':
|
|
1257
|
+
case 'day':
|
|
1258
|
+
case 'd':
|
|
1259
|
+
return n * d;
|
|
1260
|
+
case 'hours':
|
|
1261
|
+
case 'hour':
|
|
1262
|
+
case 'hrs':
|
|
1263
|
+
case 'hr':
|
|
1264
|
+
case 'h':
|
|
1265
|
+
return n * h;
|
|
1266
|
+
case 'minutes':
|
|
1267
|
+
case 'minute':
|
|
1268
|
+
case 'mins':
|
|
1269
|
+
case 'min':
|
|
1270
|
+
case 'm':
|
|
1271
|
+
return n * m;
|
|
1272
|
+
case 'seconds':
|
|
1273
|
+
case 'second':
|
|
1274
|
+
case 'secs':
|
|
1275
|
+
case 'sec':
|
|
1276
|
+
case 's':
|
|
1277
|
+
return n * s;
|
|
1278
|
+
case 'milliseconds':
|
|
1279
|
+
case 'millisecond':
|
|
1280
|
+
case 'msecs':
|
|
1281
|
+
case 'msec':
|
|
1282
|
+
case 'ms':
|
|
1283
|
+
return n;
|
|
1284
|
+
default:
|
|
1285
|
+
return undefined;
|
|
1286
|
+
}
|
|
1287
|
+
}
|
|
1288
|
+
|
|
1289
|
+
/**
|
|
1290
|
+
* Short format for `ms`.
|
|
1291
|
+
*
|
|
1292
|
+
* @param {Number} ms
|
|
1293
|
+
* @return {String}
|
|
1294
|
+
* @api private
|
|
1295
|
+
*/
|
|
1296
|
+
|
|
1297
|
+
function fmtShort(ms) {
|
|
1298
|
+
var msAbs = Math.abs(ms);
|
|
1299
|
+
if (msAbs >= d) {
|
|
1300
|
+
return Math.round(ms / d) + 'd';
|
|
1301
|
+
}
|
|
1302
|
+
if (msAbs >= h) {
|
|
1303
|
+
return Math.round(ms / h) + 'h';
|
|
1304
|
+
}
|
|
1305
|
+
if (msAbs >= m) {
|
|
1306
|
+
return Math.round(ms / m) + 'm';
|
|
1307
|
+
}
|
|
1308
|
+
if (msAbs >= s) {
|
|
1309
|
+
return Math.round(ms / s) + 's';
|
|
1310
|
+
}
|
|
1311
|
+
return ms + 'ms';
|
|
1312
|
+
}
|
|
1313
|
+
|
|
1314
|
+
/**
|
|
1315
|
+
* Long format for `ms`.
|
|
1316
|
+
*
|
|
1317
|
+
* @param {Number} ms
|
|
1318
|
+
* @return {String}
|
|
1319
|
+
* @api private
|
|
1320
|
+
*/
|
|
1321
|
+
|
|
1322
|
+
function fmtLong(ms) {
|
|
1323
|
+
var msAbs = Math.abs(ms);
|
|
1324
|
+
if (msAbs >= d) {
|
|
1325
|
+
return plural(ms, msAbs, d, 'day');
|
|
1326
|
+
}
|
|
1327
|
+
if (msAbs >= h) {
|
|
1328
|
+
return plural(ms, msAbs, h, 'hour');
|
|
1329
|
+
}
|
|
1330
|
+
if (msAbs >= m) {
|
|
1331
|
+
return plural(ms, msAbs, m, 'minute');
|
|
1332
|
+
}
|
|
1333
|
+
if (msAbs >= s) {
|
|
1334
|
+
return plural(ms, msAbs, s, 'second');
|
|
1335
|
+
}
|
|
1336
|
+
return ms + ' ms';
|
|
1337
|
+
}
|
|
1338
|
+
|
|
1339
|
+
/**
|
|
1340
|
+
* Pluralization helper.
|
|
1341
|
+
*/
|
|
1342
|
+
|
|
1343
|
+
function plural(ms, msAbs, n, name) {
|
|
1344
|
+
var isPlural = msAbs >= n * 1.5;
|
|
1345
|
+
return Math.round(ms / n) + ' ' + name + (isPlural ? 's' : '');
|
|
1346
|
+
}
|
|
1347
|
+
|
|
1348
|
+
/**
|
|
1349
|
+
* This is the common logic for both the Node.js and web browser
|
|
1350
|
+
* implementations of `debug()`.
|
|
1351
|
+
*/
|
|
1352
|
+
|
|
1353
|
+
function setup(env) {
|
|
1354
|
+
createDebug.debug = createDebug;
|
|
1355
|
+
createDebug.default = createDebug;
|
|
1356
|
+
createDebug.coerce = coerce;
|
|
1357
|
+
createDebug.disable = disable;
|
|
1358
|
+
createDebug.enable = enable;
|
|
1359
|
+
createDebug.enabled = enabled;
|
|
1360
|
+
createDebug.humanize = ms;
|
|
1361
|
+
createDebug.destroy = destroy;
|
|
1362
|
+
|
|
1363
|
+
Object.keys(env).forEach(key => {
|
|
1364
|
+
createDebug[key] = env[key];
|
|
1365
|
+
});
|
|
1366
|
+
|
|
1367
|
+
/**
|
|
1368
|
+
* The currently active debug mode names, and names to skip.
|
|
1369
|
+
*/
|
|
1370
|
+
|
|
1371
|
+
createDebug.names = [];
|
|
1372
|
+
createDebug.skips = [];
|
|
1373
|
+
|
|
1374
|
+
/**
|
|
1375
|
+
* Map of special "%n" handling functions, for the debug "format" argument.
|
|
1376
|
+
*
|
|
1377
|
+
* Valid key names are a single, lower or upper-case letter, i.e. "n" and "N".
|
|
1378
|
+
*/
|
|
1379
|
+
createDebug.formatters = {};
|
|
1380
|
+
|
|
1381
|
+
/**
|
|
1382
|
+
* Selects a color for a debug namespace
|
|
1383
|
+
* @param {String} namespace The namespace string for the for the debug instance to be colored
|
|
1384
|
+
* @return {Number|String} An ANSI color code for the given namespace
|
|
1385
|
+
* @api private
|
|
1386
|
+
*/
|
|
1387
|
+
function selectColor(namespace) {
|
|
1388
|
+
let hash = 0;
|
|
1389
|
+
|
|
1390
|
+
for (let i = 0; i < namespace.length; i++) {
|
|
1391
|
+
hash = ((hash << 5) - hash) + namespace.charCodeAt(i);
|
|
1392
|
+
hash |= 0; // Convert to 32bit integer
|
|
1393
|
+
}
|
|
1394
|
+
|
|
1395
|
+
return createDebug.colors[Math.abs(hash) % createDebug.colors.length];
|
|
1396
|
+
}
|
|
1397
|
+
createDebug.selectColor = selectColor;
|
|
1398
|
+
|
|
1399
|
+
/**
|
|
1400
|
+
* Create a debugger with the given `namespace`.
|
|
1401
|
+
*
|
|
1402
|
+
* @param {String} namespace
|
|
1403
|
+
* @return {Function}
|
|
1404
|
+
* @api public
|
|
1405
|
+
*/
|
|
1406
|
+
function createDebug(namespace) {
|
|
1407
|
+
let prevTime;
|
|
1408
|
+
let enableOverride = null;
|
|
1409
|
+
|
|
1410
|
+
function debug(...args) {
|
|
1411
|
+
// Disabled?
|
|
1412
|
+
if (!debug.enabled) {
|
|
1413
|
+
return;
|
|
1414
|
+
}
|
|
1415
|
+
|
|
1416
|
+
const self = debug;
|
|
1417
|
+
|
|
1418
|
+
// Set `diff` timestamp
|
|
1419
|
+
const curr = Number(new Date());
|
|
1420
|
+
const ms = curr - (prevTime || curr);
|
|
1421
|
+
self.diff = ms;
|
|
1422
|
+
self.prev = prevTime;
|
|
1423
|
+
self.curr = curr;
|
|
1424
|
+
prevTime = curr;
|
|
1425
|
+
|
|
1426
|
+
args[0] = createDebug.coerce(args[0]);
|
|
1427
|
+
|
|
1428
|
+
if (typeof args[0] !== 'string') {
|
|
1429
|
+
// Anything else let's inspect with %O
|
|
1430
|
+
args.unshift('%O');
|
|
1431
|
+
}
|
|
1432
|
+
|
|
1433
|
+
// Apply any `formatters` transformations
|
|
1434
|
+
let index = 0;
|
|
1435
|
+
args[0] = args[0].replace(/%([a-zA-Z%])/g, (match, format) => {
|
|
1436
|
+
// If we encounter an escaped % then don't increase the array index
|
|
1437
|
+
if (match === '%%') {
|
|
1438
|
+
return '%';
|
|
1439
|
+
}
|
|
1440
|
+
index++;
|
|
1441
|
+
const formatter = createDebug.formatters[format];
|
|
1442
|
+
if (typeof formatter === 'function') {
|
|
1443
|
+
const val = args[index];
|
|
1444
|
+
match = formatter.call(self, val);
|
|
1445
|
+
|
|
1446
|
+
// Now we need to remove `args[index]` since it's inlined in the `format`
|
|
1447
|
+
args.splice(index, 1);
|
|
1448
|
+
index--;
|
|
1449
|
+
}
|
|
1450
|
+
return match;
|
|
1451
|
+
});
|
|
1452
|
+
|
|
1453
|
+
// Apply env-specific formatting (colors, etc.)
|
|
1454
|
+
createDebug.formatArgs.call(self, args);
|
|
1455
|
+
|
|
1456
|
+
const logFn = self.log || createDebug.log;
|
|
1457
|
+
logFn.apply(self, args);
|
|
1458
|
+
}
|
|
1459
|
+
|
|
1460
|
+
debug.namespace = namespace;
|
|
1461
|
+
debug.useColors = createDebug.useColors();
|
|
1462
|
+
debug.color = createDebug.selectColor(namespace);
|
|
1463
|
+
debug.extend = extend;
|
|
1464
|
+
debug.destroy = createDebug.destroy; // XXX Temporary. Will be removed in the next major release.
|
|
1465
|
+
|
|
1466
|
+
Object.defineProperty(debug, 'enabled', {
|
|
1467
|
+
enumerable: true,
|
|
1468
|
+
configurable: false,
|
|
1469
|
+
get: () => enableOverride === null ? createDebug.enabled(namespace) : enableOverride,
|
|
1470
|
+
set: v => {
|
|
1471
|
+
enableOverride = v;
|
|
1472
|
+
}
|
|
1473
|
+
});
|
|
1474
|
+
|
|
1475
|
+
// Env-specific initialization logic for debug instances
|
|
1476
|
+
if (typeof createDebug.init === 'function') {
|
|
1477
|
+
createDebug.init(debug);
|
|
1478
|
+
}
|
|
1479
|
+
|
|
1480
|
+
return debug;
|
|
1481
|
+
}
|
|
1482
|
+
|
|
1483
|
+
function extend(namespace, delimiter) {
|
|
1484
|
+
const newDebug = createDebug(this.namespace + (typeof delimiter === 'undefined' ? ':' : delimiter) + namespace);
|
|
1485
|
+
newDebug.log = this.log;
|
|
1486
|
+
return newDebug;
|
|
1487
|
+
}
|
|
1488
|
+
|
|
1489
|
+
/**
|
|
1490
|
+
* Enables a debug mode by namespaces. This can include modes
|
|
1491
|
+
* separated by a colon and wildcards.
|
|
1492
|
+
*
|
|
1493
|
+
* @param {String} namespaces
|
|
1494
|
+
* @api public
|
|
1495
|
+
*/
|
|
1496
|
+
function enable(namespaces) {
|
|
1497
|
+
createDebug.save(namespaces);
|
|
1498
|
+
|
|
1499
|
+
createDebug.names = [];
|
|
1500
|
+
createDebug.skips = [];
|
|
1501
|
+
|
|
1502
|
+
let i;
|
|
1503
|
+
const split = (typeof namespaces === 'string' ? namespaces : '').split(/[\s,]+/);
|
|
1504
|
+
const len = split.length;
|
|
1505
|
+
|
|
1506
|
+
for (i = 0; i < len; i++) {
|
|
1507
|
+
if (!split[i]) {
|
|
1508
|
+
// ignore empty strings
|
|
1509
|
+
continue;
|
|
1510
|
+
}
|
|
1511
|
+
|
|
1512
|
+
namespaces = split[i].replace(/\*/g, '.*?');
|
|
1513
|
+
|
|
1514
|
+
if (namespaces[0] === '-') {
|
|
1515
|
+
createDebug.skips.push(new RegExp('^' + namespaces.substr(1) + '$'));
|
|
1516
|
+
} else {
|
|
1517
|
+
createDebug.names.push(new RegExp('^' + namespaces + '$'));
|
|
1518
|
+
}
|
|
1519
|
+
}
|
|
1520
|
+
}
|
|
1521
|
+
|
|
1522
|
+
/**
|
|
1523
|
+
* Disable debug output.
|
|
1524
|
+
*
|
|
1525
|
+
* @return {String} namespaces
|
|
1526
|
+
* @api public
|
|
1527
|
+
*/
|
|
1528
|
+
function disable() {
|
|
1529
|
+
const namespaces = [
|
|
1530
|
+
...createDebug.names.map(toNamespace),
|
|
1531
|
+
...createDebug.skips.map(toNamespace).map(namespace => '-' + namespace)
|
|
1532
|
+
].join(',');
|
|
1533
|
+
createDebug.enable('');
|
|
1534
|
+
return namespaces;
|
|
1535
|
+
}
|
|
1536
|
+
|
|
1537
|
+
/**
|
|
1538
|
+
* Returns true if the given mode name is enabled, false otherwise.
|
|
1539
|
+
*
|
|
1540
|
+
* @param {String} name
|
|
1541
|
+
* @return {Boolean}
|
|
1542
|
+
* @api public
|
|
1543
|
+
*/
|
|
1544
|
+
function enabled(name) {
|
|
1545
|
+
if (name[name.length - 1] === '*') {
|
|
1546
|
+
return true;
|
|
1547
|
+
}
|
|
1548
|
+
|
|
1549
|
+
let i;
|
|
1550
|
+
let len;
|
|
1551
|
+
|
|
1552
|
+
for (i = 0, len = createDebug.skips.length; i < len; i++) {
|
|
1553
|
+
if (createDebug.skips[i].test(name)) {
|
|
1554
|
+
return false;
|
|
1555
|
+
}
|
|
1556
|
+
}
|
|
1557
|
+
|
|
1558
|
+
for (i = 0, len = createDebug.names.length; i < len; i++) {
|
|
1559
|
+
if (createDebug.names[i].test(name)) {
|
|
1560
|
+
return true;
|
|
1561
|
+
}
|
|
1562
|
+
}
|
|
1563
|
+
|
|
1564
|
+
return false;
|
|
1565
|
+
}
|
|
1566
|
+
|
|
1567
|
+
/**
|
|
1568
|
+
* Convert regexp to namespace
|
|
1569
|
+
*
|
|
1570
|
+
* @param {RegExp} regxep
|
|
1571
|
+
* @return {String} namespace
|
|
1572
|
+
* @api private
|
|
1573
|
+
*/
|
|
1574
|
+
function toNamespace(regexp) {
|
|
1575
|
+
return regexp.toString()
|
|
1576
|
+
.substring(2, regexp.toString().length - 2)
|
|
1577
|
+
.replace(/\.\*\?$/, '*');
|
|
1578
|
+
}
|
|
1579
|
+
|
|
1580
|
+
/**
|
|
1581
|
+
* Coerce `val`.
|
|
1582
|
+
*
|
|
1583
|
+
* @param {Mixed} val
|
|
1584
|
+
* @return {Mixed}
|
|
1585
|
+
* @api private
|
|
1586
|
+
*/
|
|
1587
|
+
function coerce(val) {
|
|
1588
|
+
if (val instanceof Error) {
|
|
1589
|
+
return val.stack || val.message;
|
|
1590
|
+
}
|
|
1591
|
+
return val;
|
|
1592
|
+
}
|
|
1593
|
+
|
|
1594
|
+
/**
|
|
1595
|
+
* XXX DO NOT USE. This is a temporary stub function.
|
|
1596
|
+
* XXX It WILL be removed in the next major release.
|
|
1597
|
+
*/
|
|
1598
|
+
function destroy() {
|
|
1599
|
+
console.warn('Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.');
|
|
1600
|
+
}
|
|
1601
|
+
|
|
1602
|
+
createDebug.enable(createDebug.load());
|
|
1603
|
+
|
|
1604
|
+
return createDebug;
|
|
1605
|
+
}
|
|
1606
|
+
|
|
1607
|
+
var common = setup;
|
|
1608
|
+
|
|
1609
|
+
/* eslint-env browser */
|
|
1610
|
+
|
|
1611
|
+
var browser$1 = createCommonjsModule(function (module, exports) {
|
|
1612
|
+
/**
|
|
1613
|
+
* This is the web browser implementation of `debug()`.
|
|
1614
|
+
*/
|
|
1615
|
+
|
|
1616
|
+
exports.formatArgs = formatArgs;
|
|
1617
|
+
exports.save = save;
|
|
1618
|
+
exports.load = load;
|
|
1619
|
+
exports.useColors = useColors;
|
|
1620
|
+
exports.storage = localstorage();
|
|
1621
|
+
exports.destroy = (() => {
|
|
1622
|
+
let warned = false;
|
|
1623
|
+
|
|
1624
|
+
return () => {
|
|
1625
|
+
if (!warned) {
|
|
1626
|
+
warned = true;
|
|
1627
|
+
console.warn('Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.');
|
|
1628
|
+
}
|
|
1629
|
+
};
|
|
1630
|
+
})();
|
|
1631
|
+
|
|
1632
|
+
/**
|
|
1633
|
+
* Colors.
|
|
1634
|
+
*/
|
|
1635
|
+
|
|
1636
|
+
exports.colors = [
|
|
1637
|
+
'#0000CC',
|
|
1638
|
+
'#0000FF',
|
|
1639
|
+
'#0033CC',
|
|
1640
|
+
'#0033FF',
|
|
1641
|
+
'#0066CC',
|
|
1642
|
+
'#0066FF',
|
|
1643
|
+
'#0099CC',
|
|
1644
|
+
'#0099FF',
|
|
1645
|
+
'#00CC00',
|
|
1646
|
+
'#00CC33',
|
|
1647
|
+
'#00CC66',
|
|
1648
|
+
'#00CC99',
|
|
1649
|
+
'#00CCCC',
|
|
1650
|
+
'#00CCFF',
|
|
1651
|
+
'#3300CC',
|
|
1652
|
+
'#3300FF',
|
|
1653
|
+
'#3333CC',
|
|
1654
|
+
'#3333FF',
|
|
1655
|
+
'#3366CC',
|
|
1656
|
+
'#3366FF',
|
|
1657
|
+
'#3399CC',
|
|
1658
|
+
'#3399FF',
|
|
1659
|
+
'#33CC00',
|
|
1660
|
+
'#33CC33',
|
|
1661
|
+
'#33CC66',
|
|
1662
|
+
'#33CC99',
|
|
1663
|
+
'#33CCCC',
|
|
1664
|
+
'#33CCFF',
|
|
1665
|
+
'#6600CC',
|
|
1666
|
+
'#6600FF',
|
|
1667
|
+
'#6633CC',
|
|
1668
|
+
'#6633FF',
|
|
1669
|
+
'#66CC00',
|
|
1670
|
+
'#66CC33',
|
|
1671
|
+
'#9900CC',
|
|
1672
|
+
'#9900FF',
|
|
1673
|
+
'#9933CC',
|
|
1674
|
+
'#9933FF',
|
|
1675
|
+
'#99CC00',
|
|
1676
|
+
'#99CC33',
|
|
1677
|
+
'#CC0000',
|
|
1678
|
+
'#CC0033',
|
|
1679
|
+
'#CC0066',
|
|
1680
|
+
'#CC0099',
|
|
1681
|
+
'#CC00CC',
|
|
1682
|
+
'#CC00FF',
|
|
1683
|
+
'#CC3300',
|
|
1684
|
+
'#CC3333',
|
|
1685
|
+
'#CC3366',
|
|
1686
|
+
'#CC3399',
|
|
1687
|
+
'#CC33CC',
|
|
1688
|
+
'#CC33FF',
|
|
1689
|
+
'#CC6600',
|
|
1690
|
+
'#CC6633',
|
|
1691
|
+
'#CC9900',
|
|
1692
|
+
'#CC9933',
|
|
1693
|
+
'#CCCC00',
|
|
1694
|
+
'#CCCC33',
|
|
1695
|
+
'#FF0000',
|
|
1696
|
+
'#FF0033',
|
|
1697
|
+
'#FF0066',
|
|
1698
|
+
'#FF0099',
|
|
1699
|
+
'#FF00CC',
|
|
1700
|
+
'#FF00FF',
|
|
1701
|
+
'#FF3300',
|
|
1702
|
+
'#FF3333',
|
|
1703
|
+
'#FF3366',
|
|
1704
|
+
'#FF3399',
|
|
1705
|
+
'#FF33CC',
|
|
1706
|
+
'#FF33FF',
|
|
1707
|
+
'#FF6600',
|
|
1708
|
+
'#FF6633',
|
|
1709
|
+
'#FF9900',
|
|
1710
|
+
'#FF9933',
|
|
1711
|
+
'#FFCC00',
|
|
1712
|
+
'#FFCC33'
|
|
1713
|
+
];
|
|
1714
|
+
|
|
1715
|
+
/**
|
|
1716
|
+
* Currently only WebKit-based Web Inspectors, Firefox >= v31,
|
|
1717
|
+
* and the Firebug extension (any Firefox version) are known
|
|
1718
|
+
* to support "%c" CSS customizations.
|
|
1719
|
+
*
|
|
1720
|
+
* TODO: add a `localStorage` variable to explicitly enable/disable colors
|
|
1721
|
+
*/
|
|
1722
|
+
|
|
1723
|
+
// eslint-disable-next-line complexity
|
|
1724
|
+
function useColors() {
|
|
1725
|
+
// NB: In an Electron preload script, document will be defined but not fully
|
|
1726
|
+
// initialized. Since we know we're in Chrome, we'll just detect this case
|
|
1727
|
+
// explicitly
|
|
1728
|
+
if (typeof window !== 'undefined' && window.process && (window.process.type === 'renderer' || window.process.__nwjs)) {
|
|
1729
|
+
return true;
|
|
1730
|
+
}
|
|
1731
|
+
|
|
1732
|
+
// Internet Explorer and Edge do not support colors.
|
|
1733
|
+
if (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)) {
|
|
1734
|
+
return false;
|
|
1735
|
+
}
|
|
1736
|
+
|
|
1737
|
+
// Is webkit? http://stackoverflow.com/a/16459606/376773
|
|
1738
|
+
// document is undefined in react-native: https://github.com/facebook/react-native/pull/1632
|
|
1739
|
+
return (typeof document !== 'undefined' && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance) ||
|
|
1740
|
+
// Is firebug? http://stackoverflow.com/a/398120/376773
|
|
1741
|
+
(typeof window !== 'undefined' && window.console && (window.console.firebug || (window.console.exception && window.console.table))) ||
|
|
1742
|
+
// Is firefox >= v31?
|
|
1743
|
+
// https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages
|
|
1744
|
+
(typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/) && parseInt(RegExp.$1, 10) >= 31) ||
|
|
1745
|
+
// Double check webkit in userAgent just in case we are in a worker
|
|
1746
|
+
(typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/));
|
|
1747
|
+
}
|
|
1748
|
+
|
|
1749
|
+
/**
|
|
1750
|
+
* Colorize log arguments if enabled.
|
|
1751
|
+
*
|
|
1752
|
+
* @api public
|
|
1753
|
+
*/
|
|
1754
|
+
|
|
1755
|
+
function formatArgs(args) {
|
|
1756
|
+
args[0] = (this.useColors ? '%c' : '') +
|
|
1757
|
+
this.namespace +
|
|
1758
|
+
(this.useColors ? ' %c' : ' ') +
|
|
1759
|
+
args[0] +
|
|
1760
|
+
(this.useColors ? '%c ' : ' ') +
|
|
1761
|
+
'+' + module.exports.humanize(this.diff);
|
|
1762
|
+
|
|
1763
|
+
if (!this.useColors) {
|
|
1764
|
+
return;
|
|
1765
|
+
}
|
|
1766
|
+
|
|
1767
|
+
const c = 'color: ' + this.color;
|
|
1768
|
+
args.splice(1, 0, c, 'color: inherit');
|
|
1769
|
+
|
|
1770
|
+
// The final "%c" is somewhat tricky, because there could be other
|
|
1771
|
+
// arguments passed either before or after the %c, so we need to
|
|
1772
|
+
// figure out the correct index to insert the CSS into
|
|
1773
|
+
let index = 0;
|
|
1774
|
+
let lastC = 0;
|
|
1775
|
+
args[0].replace(/%[a-zA-Z%]/g, match => {
|
|
1776
|
+
if (match === '%%') {
|
|
1777
|
+
return;
|
|
1778
|
+
}
|
|
1779
|
+
index++;
|
|
1780
|
+
if (match === '%c') {
|
|
1781
|
+
// We only are interested in the *last* %c
|
|
1782
|
+
// (the user may have provided their own)
|
|
1783
|
+
lastC = index;
|
|
1784
|
+
}
|
|
1785
|
+
});
|
|
1786
|
+
|
|
1787
|
+
args.splice(lastC, 0, c);
|
|
1788
|
+
}
|
|
1789
|
+
|
|
1790
|
+
/**
|
|
1791
|
+
* Invokes `console.debug()` when available.
|
|
1792
|
+
* No-op when `console.debug` is not a "function".
|
|
1793
|
+
* If `console.debug` is not available, falls back
|
|
1794
|
+
* to `console.log`.
|
|
1795
|
+
*
|
|
1796
|
+
* @api public
|
|
1797
|
+
*/
|
|
1798
|
+
exports.log = console.debug || console.log || (() => {});
|
|
1799
|
+
|
|
1800
|
+
/**
|
|
1801
|
+
* Save `namespaces`.
|
|
1802
|
+
*
|
|
1803
|
+
* @param {String} namespaces
|
|
1804
|
+
* @api private
|
|
1805
|
+
*/
|
|
1806
|
+
function save(namespaces) {
|
|
1807
|
+
try {
|
|
1808
|
+
if (namespaces) {
|
|
1809
|
+
exports.storage.setItem('debug', namespaces);
|
|
1810
|
+
} else {
|
|
1811
|
+
exports.storage.removeItem('debug');
|
|
1812
|
+
}
|
|
1813
|
+
} catch (error) {
|
|
1814
|
+
// Swallow
|
|
1815
|
+
// XXX (@Qix-) should we be logging these?
|
|
1816
|
+
}
|
|
1817
|
+
}
|
|
1818
|
+
|
|
1819
|
+
/**
|
|
1820
|
+
* Load `namespaces`.
|
|
1821
|
+
*
|
|
1822
|
+
* @return {String} returns the previously persisted debug modes
|
|
1823
|
+
* @api private
|
|
1824
|
+
*/
|
|
1825
|
+
function load() {
|
|
1826
|
+
let r;
|
|
1827
|
+
try {
|
|
1828
|
+
r = exports.storage.getItem('debug');
|
|
1829
|
+
} catch (error) {
|
|
1830
|
+
// Swallow
|
|
1831
|
+
// XXX (@Qix-) should we be logging these?
|
|
1832
|
+
}
|
|
1833
|
+
|
|
1834
|
+
// If debug isn't set in LS, and we're in Electron, try to load $DEBUG
|
|
1835
|
+
if (!r && typeof process !== 'undefined' && 'env' in process) {
|
|
1836
|
+
r = process.env.DEBUG;
|
|
1837
|
+
}
|
|
1838
|
+
|
|
1839
|
+
return r;
|
|
1840
|
+
}
|
|
1841
|
+
|
|
1842
|
+
/**
|
|
1843
|
+
* Localstorage attempts to return the localstorage.
|
|
1844
|
+
*
|
|
1845
|
+
* This is necessary because safari throws
|
|
1846
|
+
* when a user disables cookies/localstorage
|
|
1847
|
+
* and you attempt to access it.
|
|
1848
|
+
*
|
|
1849
|
+
* @return {LocalStorage}
|
|
1850
|
+
* @api private
|
|
1851
|
+
*/
|
|
1852
|
+
|
|
1853
|
+
function localstorage() {
|
|
1854
|
+
try {
|
|
1855
|
+
// TVMLKit (Apple TV JS Runtime) does not have a window object, just localStorage in the global context
|
|
1856
|
+
// The Browser also has localStorage in the global context.
|
|
1857
|
+
return localStorage;
|
|
1858
|
+
} catch (error) {
|
|
1859
|
+
// Swallow
|
|
1860
|
+
// XXX (@Qix-) should we be logging these?
|
|
1861
|
+
}
|
|
1862
|
+
}
|
|
1863
|
+
|
|
1864
|
+
module.exports = common(exports);
|
|
1865
|
+
|
|
1866
|
+
const {formatters} = module.exports;
|
|
1867
|
+
|
|
1868
|
+
/**
|
|
1869
|
+
* Map %j to `JSON.stringify()`, since no Web Inspectors do that by default.
|
|
1870
|
+
*/
|
|
1871
|
+
|
|
1872
|
+
formatters.j = function (v) {
|
|
1873
|
+
try {
|
|
1874
|
+
return JSON.stringify(v);
|
|
1875
|
+
} catch (error) {
|
|
1876
|
+
return '[UnexpectedJSONParseError]: ' + error.message;
|
|
1877
|
+
}
|
|
1878
|
+
};
|
|
1879
|
+
});
|
|
1880
|
+
|
|
1881
|
+
var hasFlag = (flag, argv) => {
|
|
1882
|
+
argv = argv || process.argv;
|
|
1883
|
+
const prefix = flag.startsWith('-') ? '' : (flag.length === 1 ? '-' : '--');
|
|
1884
|
+
const pos = argv.indexOf(prefix + flag);
|
|
1885
|
+
const terminatorPos = argv.indexOf('--');
|
|
1886
|
+
return pos !== -1 && (terminatorPos === -1 ? true : pos < terminatorPos);
|
|
1887
|
+
};
|
|
1888
|
+
|
|
1889
|
+
const env = process.env;
|
|
1890
|
+
|
|
1891
|
+
let forceColor;
|
|
1892
|
+
if (hasFlag('no-color') ||
|
|
1893
|
+
hasFlag('no-colors') ||
|
|
1894
|
+
hasFlag('color=false')) {
|
|
1895
|
+
forceColor = false;
|
|
1896
|
+
} else if (hasFlag('color') ||
|
|
1897
|
+
hasFlag('colors') ||
|
|
1898
|
+
hasFlag('color=true') ||
|
|
1899
|
+
hasFlag('color=always')) {
|
|
1900
|
+
forceColor = true;
|
|
1901
|
+
}
|
|
1902
|
+
if ('FORCE_COLOR' in env) {
|
|
1903
|
+
forceColor = env.FORCE_COLOR.length === 0 || parseInt(env.FORCE_COLOR, 10) !== 0;
|
|
1904
|
+
}
|
|
1905
|
+
|
|
1906
|
+
function translateLevel(level) {
|
|
1907
|
+
if (level === 0) {
|
|
1908
|
+
return false;
|
|
1909
|
+
}
|
|
1910
|
+
|
|
1911
|
+
return {
|
|
1912
|
+
level,
|
|
1913
|
+
hasBasic: true,
|
|
1914
|
+
has256: level >= 2,
|
|
1915
|
+
has16m: level >= 3
|
|
1916
|
+
};
|
|
1917
|
+
}
|
|
1918
|
+
|
|
1919
|
+
function supportsColor(stream) {
|
|
1920
|
+
if (forceColor === false) {
|
|
1921
|
+
return 0;
|
|
1922
|
+
}
|
|
1923
|
+
|
|
1924
|
+
if (hasFlag('color=16m') ||
|
|
1925
|
+
hasFlag('color=full') ||
|
|
1926
|
+
hasFlag('color=truecolor')) {
|
|
1927
|
+
return 3;
|
|
1928
|
+
}
|
|
1929
|
+
|
|
1930
|
+
if (hasFlag('color=256')) {
|
|
1931
|
+
return 2;
|
|
1932
|
+
}
|
|
1933
|
+
|
|
1934
|
+
if (stream && !stream.isTTY && forceColor !== true) {
|
|
1935
|
+
return 0;
|
|
1936
|
+
}
|
|
1937
|
+
|
|
1938
|
+
const min = forceColor ? 1 : 0;
|
|
1939
|
+
|
|
1940
|
+
if (process.platform === 'win32') {
|
|
1941
|
+
// Node.js 7.5.0 is the first version of Node.js to include a patch to
|
|
1942
|
+
// libuv that enables 256 color output on Windows. Anything earlier and it
|
|
1943
|
+
// won't work. However, here we target Node.js 8 at minimum as it is an LTS
|
|
1944
|
+
// release, and Node.js 7 is not. Windows 10 build 10586 is the first Windows
|
|
1945
|
+
// release that supports 256 colors. Windows 10 build 14931 is the first release
|
|
1946
|
+
// that supports 16m/TrueColor.
|
|
1947
|
+
const osRelease = os__default['default'].release().split('.');
|
|
1948
|
+
if (
|
|
1949
|
+
Number(process.versions.node.split('.')[0]) >= 8 &&
|
|
1950
|
+
Number(osRelease[0]) >= 10 &&
|
|
1951
|
+
Number(osRelease[2]) >= 10586
|
|
1952
|
+
) {
|
|
1953
|
+
return Number(osRelease[2]) >= 14931 ? 3 : 2;
|
|
1954
|
+
}
|
|
1955
|
+
|
|
1956
|
+
return 1;
|
|
1957
|
+
}
|
|
1958
|
+
|
|
1959
|
+
if ('CI' in env) {
|
|
1960
|
+
if (['TRAVIS', 'CIRCLECI', 'APPVEYOR', 'GITLAB_CI'].some(sign => sign in env) || env.CI_NAME === 'codeship') {
|
|
1961
|
+
return 1;
|
|
1962
|
+
}
|
|
1963
|
+
|
|
1964
|
+
return min;
|
|
1965
|
+
}
|
|
1966
|
+
|
|
1967
|
+
if ('TEAMCITY_VERSION' in env) {
|
|
1968
|
+
return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
|
|
1969
|
+
}
|
|
1970
|
+
|
|
1971
|
+
if (env.COLORTERM === 'truecolor') {
|
|
1972
|
+
return 3;
|
|
1973
|
+
}
|
|
1974
|
+
|
|
1975
|
+
if ('TERM_PROGRAM' in env) {
|
|
1976
|
+
const version = parseInt((env.TERM_PROGRAM_VERSION || '').split('.')[0], 10);
|
|
1977
|
+
|
|
1978
|
+
switch (env.TERM_PROGRAM) {
|
|
1979
|
+
case 'iTerm.app':
|
|
1980
|
+
return version >= 3 ? 3 : 2;
|
|
1981
|
+
case 'Apple_Terminal':
|
|
1982
|
+
return 2;
|
|
1983
|
+
// No default
|
|
1984
|
+
}
|
|
1985
|
+
}
|
|
1986
|
+
|
|
1987
|
+
if (/-256(color)?$/i.test(env.TERM)) {
|
|
1988
|
+
return 2;
|
|
1989
|
+
}
|
|
1990
|
+
|
|
1991
|
+
if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) {
|
|
1992
|
+
return 1;
|
|
1993
|
+
}
|
|
1994
|
+
|
|
1995
|
+
if ('COLORTERM' in env) {
|
|
1996
|
+
return 1;
|
|
1997
|
+
}
|
|
1998
|
+
|
|
1999
|
+
if (env.TERM === 'dumb') {
|
|
2000
|
+
return min;
|
|
2001
|
+
}
|
|
2002
|
+
|
|
2003
|
+
return min;
|
|
2004
|
+
}
|
|
2005
|
+
|
|
2006
|
+
function getSupportLevel(stream) {
|
|
2007
|
+
const level = supportsColor(stream);
|
|
2008
|
+
return translateLevel(level);
|
|
2009
|
+
}
|
|
2010
|
+
|
|
2011
|
+
var supportsColor_1 = {
|
|
2012
|
+
supportsColor: getSupportLevel,
|
|
2013
|
+
stdout: getSupportLevel(process.stdout),
|
|
2014
|
+
stderr: getSupportLevel(process.stderr)
|
|
2015
|
+
};
|
|
2016
|
+
|
|
2017
|
+
/**
|
|
2018
|
+
* Module dependencies.
|
|
2019
|
+
*/
|
|
2020
|
+
|
|
2021
|
+
var node = createCommonjsModule(function (module, exports) {
|
|
2022
|
+
/**
|
|
2023
|
+
* This is the Node.js implementation of `debug()`.
|
|
2024
|
+
*/
|
|
2025
|
+
|
|
2026
|
+
exports.init = init;
|
|
2027
|
+
exports.log = log;
|
|
2028
|
+
exports.formatArgs = formatArgs;
|
|
2029
|
+
exports.save = save;
|
|
2030
|
+
exports.load = load;
|
|
2031
|
+
exports.useColors = useColors;
|
|
2032
|
+
exports.destroy = util__default['default'].deprecate(
|
|
2033
|
+
() => {},
|
|
2034
|
+
'Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.'
|
|
2035
|
+
);
|
|
2036
|
+
|
|
2037
|
+
/**
|
|
2038
|
+
* Colors.
|
|
2039
|
+
*/
|
|
2040
|
+
|
|
2041
|
+
exports.colors = [6, 2, 3, 4, 5, 1];
|
|
2042
|
+
|
|
2043
|
+
try {
|
|
2044
|
+
// Optional dependency (as in, doesn't need to be installed, NOT like optionalDependencies in package.json)
|
|
2045
|
+
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
2046
|
+
const supportsColor = supportsColor_1;
|
|
2047
|
+
|
|
2048
|
+
if (supportsColor && (supportsColor.stderr || supportsColor).level >= 2) {
|
|
2049
|
+
exports.colors = [
|
|
2050
|
+
20,
|
|
2051
|
+
21,
|
|
2052
|
+
26,
|
|
2053
|
+
27,
|
|
2054
|
+
32,
|
|
2055
|
+
33,
|
|
2056
|
+
38,
|
|
2057
|
+
39,
|
|
2058
|
+
40,
|
|
2059
|
+
41,
|
|
2060
|
+
42,
|
|
2061
|
+
43,
|
|
2062
|
+
44,
|
|
2063
|
+
45,
|
|
2064
|
+
56,
|
|
2065
|
+
57,
|
|
2066
|
+
62,
|
|
2067
|
+
63,
|
|
2068
|
+
68,
|
|
2069
|
+
69,
|
|
2070
|
+
74,
|
|
2071
|
+
75,
|
|
2072
|
+
76,
|
|
2073
|
+
77,
|
|
2074
|
+
78,
|
|
2075
|
+
79,
|
|
2076
|
+
80,
|
|
2077
|
+
81,
|
|
2078
|
+
92,
|
|
2079
|
+
93,
|
|
2080
|
+
98,
|
|
2081
|
+
99,
|
|
2082
|
+
112,
|
|
2083
|
+
113,
|
|
2084
|
+
128,
|
|
2085
|
+
129,
|
|
2086
|
+
134,
|
|
2087
|
+
135,
|
|
2088
|
+
148,
|
|
2089
|
+
149,
|
|
2090
|
+
160,
|
|
2091
|
+
161,
|
|
2092
|
+
162,
|
|
2093
|
+
163,
|
|
2094
|
+
164,
|
|
2095
|
+
165,
|
|
2096
|
+
166,
|
|
2097
|
+
167,
|
|
2098
|
+
168,
|
|
2099
|
+
169,
|
|
2100
|
+
170,
|
|
2101
|
+
171,
|
|
2102
|
+
172,
|
|
2103
|
+
173,
|
|
2104
|
+
178,
|
|
2105
|
+
179,
|
|
2106
|
+
184,
|
|
2107
|
+
185,
|
|
2108
|
+
196,
|
|
2109
|
+
197,
|
|
2110
|
+
198,
|
|
2111
|
+
199,
|
|
2112
|
+
200,
|
|
2113
|
+
201,
|
|
2114
|
+
202,
|
|
2115
|
+
203,
|
|
2116
|
+
204,
|
|
2117
|
+
205,
|
|
2118
|
+
206,
|
|
2119
|
+
207,
|
|
2120
|
+
208,
|
|
2121
|
+
209,
|
|
2122
|
+
214,
|
|
2123
|
+
215,
|
|
2124
|
+
220,
|
|
2125
|
+
221
|
|
2126
|
+
];
|
|
2127
|
+
}
|
|
2128
|
+
} catch (error) {
|
|
2129
|
+
// Swallow - we only care if `supports-color` is available; it doesn't have to be.
|
|
2130
|
+
}
|
|
2131
|
+
|
|
2132
|
+
/**
|
|
2133
|
+
* Build up the default `inspectOpts` object from the environment variables.
|
|
2134
|
+
*
|
|
2135
|
+
* $ DEBUG_COLORS=no DEBUG_DEPTH=10 DEBUG_SHOW_HIDDEN=enabled node script.js
|
|
2136
|
+
*/
|
|
2137
|
+
|
|
2138
|
+
exports.inspectOpts = Object.keys(process.env).filter(key => {
|
|
2139
|
+
return /^debug_/i.test(key);
|
|
2140
|
+
}).reduce((obj, key) => {
|
|
2141
|
+
// Camel-case
|
|
2142
|
+
const prop = key
|
|
2143
|
+
.substring(6)
|
|
2144
|
+
.toLowerCase()
|
|
2145
|
+
.replace(/_([a-z])/g, (_, k) => {
|
|
2146
|
+
return k.toUpperCase();
|
|
2147
|
+
});
|
|
2148
|
+
|
|
2149
|
+
// Coerce string value into JS value
|
|
2150
|
+
let val = process.env[key];
|
|
2151
|
+
if (/^(yes|on|true|enabled)$/i.test(val)) {
|
|
2152
|
+
val = true;
|
|
2153
|
+
} else if (/^(no|off|false|disabled)$/i.test(val)) {
|
|
2154
|
+
val = false;
|
|
2155
|
+
} else if (val === 'null') {
|
|
2156
|
+
val = null;
|
|
2157
|
+
} else {
|
|
2158
|
+
val = Number(val);
|
|
2159
|
+
}
|
|
2160
|
+
|
|
2161
|
+
obj[prop] = val;
|
|
2162
|
+
return obj;
|
|
2163
|
+
}, {});
|
|
2164
|
+
|
|
2165
|
+
/**
|
|
2166
|
+
* Is stdout a TTY? Colored output is enabled when `true`.
|
|
2167
|
+
*/
|
|
2168
|
+
|
|
2169
|
+
function useColors() {
|
|
2170
|
+
return 'colors' in exports.inspectOpts ?
|
|
2171
|
+
Boolean(exports.inspectOpts.colors) :
|
|
2172
|
+
tty__default['default'].isatty(process.stderr.fd);
|
|
2173
|
+
}
|
|
2174
|
+
|
|
2175
|
+
/**
|
|
2176
|
+
* Adds ANSI color escape codes if enabled.
|
|
2177
|
+
*
|
|
2178
|
+
* @api public
|
|
2179
|
+
*/
|
|
2180
|
+
|
|
2181
|
+
function formatArgs(args) {
|
|
2182
|
+
const {namespace: name, useColors} = this;
|
|
2183
|
+
|
|
2184
|
+
if (useColors) {
|
|
2185
|
+
const c = this.color;
|
|
2186
|
+
const colorCode = '\u001B[3' + (c < 8 ? c : '8;5;' + c);
|
|
2187
|
+
const prefix = ` ${colorCode};1m${name} \u001B[0m`;
|
|
2188
|
+
|
|
2189
|
+
args[0] = prefix + args[0].split('\n').join('\n' + prefix);
|
|
2190
|
+
args.push(colorCode + 'm+' + module.exports.humanize(this.diff) + '\u001B[0m');
|
|
2191
|
+
} else {
|
|
2192
|
+
args[0] = getDate() + name + ' ' + args[0];
|
|
2193
|
+
}
|
|
2194
|
+
}
|
|
2195
|
+
|
|
2196
|
+
function getDate() {
|
|
2197
|
+
if (exports.inspectOpts.hideDate) {
|
|
2198
|
+
return '';
|
|
2199
|
+
}
|
|
2200
|
+
return new Date().toISOString() + ' ';
|
|
2201
|
+
}
|
|
2202
|
+
|
|
2203
|
+
/**
|
|
2204
|
+
* Invokes `util.format()` with the specified arguments and writes to stderr.
|
|
2205
|
+
*/
|
|
2206
|
+
|
|
2207
|
+
function log(...args) {
|
|
2208
|
+
return process.stderr.write(util__default['default'].format(...args) + '\n');
|
|
2209
|
+
}
|
|
2210
|
+
|
|
2211
|
+
/**
|
|
2212
|
+
* Save `namespaces`.
|
|
2213
|
+
*
|
|
2214
|
+
* @param {String} namespaces
|
|
2215
|
+
* @api private
|
|
2216
|
+
*/
|
|
2217
|
+
function save(namespaces) {
|
|
2218
|
+
if (namespaces) {
|
|
2219
|
+
process.env.DEBUG = namespaces;
|
|
2220
|
+
} else {
|
|
2221
|
+
// If you set a process.env field to null or undefined, it gets cast to the
|
|
2222
|
+
// string 'null' or 'undefined'. Just delete instead.
|
|
2223
|
+
delete process.env.DEBUG;
|
|
2224
|
+
}
|
|
2225
|
+
}
|
|
2226
|
+
|
|
2227
|
+
/**
|
|
2228
|
+
* Load `namespaces`.
|
|
2229
|
+
*
|
|
2230
|
+
* @return {String} returns the previously persisted debug modes
|
|
2231
|
+
* @api private
|
|
2232
|
+
*/
|
|
2233
|
+
|
|
2234
|
+
function load() {
|
|
2235
|
+
return process.env.DEBUG;
|
|
2236
|
+
}
|
|
2237
|
+
|
|
2238
|
+
/**
|
|
2239
|
+
* Init logic for `debug` instances.
|
|
2240
|
+
*
|
|
2241
|
+
* Create a new `inspectOpts` object in case `useColors` is set
|
|
2242
|
+
* differently for a particular `debug` instance.
|
|
2243
|
+
*/
|
|
2244
|
+
|
|
2245
|
+
function init(debug) {
|
|
2246
|
+
debug.inspectOpts = {};
|
|
2247
|
+
|
|
2248
|
+
const keys = Object.keys(exports.inspectOpts);
|
|
2249
|
+
for (let i = 0; i < keys.length; i++) {
|
|
2250
|
+
debug.inspectOpts[keys[i]] = exports.inspectOpts[keys[i]];
|
|
2251
|
+
}
|
|
2252
|
+
}
|
|
2253
|
+
|
|
2254
|
+
module.exports = common(exports);
|
|
2255
|
+
|
|
2256
|
+
const {formatters} = module.exports;
|
|
2257
|
+
|
|
2258
|
+
/**
|
|
2259
|
+
* Map %o to `util.inspect()`, all on a single line.
|
|
2260
|
+
*/
|
|
2261
|
+
|
|
2262
|
+
formatters.o = function (v) {
|
|
2263
|
+
this.inspectOpts.colors = this.useColors;
|
|
2264
|
+
return util__default['default'].inspect(v, this.inspectOpts)
|
|
2265
|
+
.split('\n')
|
|
2266
|
+
.map(str => str.trim())
|
|
2267
|
+
.join(' ');
|
|
2268
|
+
};
|
|
2269
|
+
|
|
2270
|
+
/**
|
|
2271
|
+
* Map %O to `util.inspect()`, allowing multiple lines if needed.
|
|
2272
|
+
*/
|
|
2273
|
+
|
|
2274
|
+
formatters.O = function (v) {
|
|
2275
|
+
this.inspectOpts.colors = this.useColors;
|
|
2276
|
+
return util__default['default'].inspect(v, this.inspectOpts);
|
|
2277
|
+
};
|
|
2278
|
+
});
|
|
2279
|
+
|
|
2280
|
+
/**
|
|
2281
|
+
* Detect Electron renderer / nwjs process, which is node, but we should
|
|
2282
|
+
* treat as a browser.
|
|
2283
|
+
*/
|
|
2284
|
+
|
|
2285
|
+
var src = createCommonjsModule(function (module) {
|
|
2286
|
+
if (typeof process === 'undefined' || process.type === 'renderer' || process.browser === true || process.__nwjs) {
|
|
2287
|
+
module.exports = browser$1;
|
|
2288
|
+
} else {
|
|
2289
|
+
module.exports = node;
|
|
2290
|
+
}
|
|
2291
|
+
});
|
|
2292
|
+
|
|
2293
|
+
var debug;
|
|
2294
|
+
|
|
2295
|
+
var debug_1 = function () {
|
|
2296
|
+
if (!debug) {
|
|
2297
|
+
try {
|
|
2298
|
+
/* eslint global-require: off */
|
|
2299
|
+
debug = src("follow-redirects");
|
|
2300
|
+
}
|
|
2301
|
+
catch (error) {
|
|
2302
|
+
debug = function () { /* */ };
|
|
2303
|
+
}
|
|
2304
|
+
}
|
|
2305
|
+
debug.apply(null, arguments);
|
|
2306
|
+
};
|
|
2307
|
+
|
|
2308
|
+
var URL = url__default['default'].URL;
|
|
2309
|
+
|
|
2310
|
+
|
|
2311
|
+
var Writable = require$$0__default['default'].Writable;
|
|
2312
|
+
|
|
2313
|
+
|
|
2314
|
+
|
|
2315
|
+
// Create handlers that pass events from native requests
|
|
2316
|
+
var events = ["abort", "aborted", "connect", "error", "socket", "timeout"];
|
|
2317
|
+
var eventHandlers = Object.create(null);
|
|
2318
|
+
events.forEach(function (event) {
|
|
2319
|
+
eventHandlers[event] = function (arg1, arg2, arg3) {
|
|
2320
|
+
this._redirectable.emit(event, arg1, arg2, arg3);
|
|
2321
|
+
};
|
|
2322
|
+
});
|
|
2323
|
+
|
|
2324
|
+
// Error types with codes
|
|
2325
|
+
var RedirectionError = createErrorType(
|
|
2326
|
+
"ERR_FR_REDIRECTION_FAILURE",
|
|
2327
|
+
""
|
|
2328
|
+
);
|
|
2329
|
+
var TooManyRedirectsError = createErrorType(
|
|
2330
|
+
"ERR_FR_TOO_MANY_REDIRECTS",
|
|
2331
|
+
"Maximum number of redirects exceeded"
|
|
2332
|
+
);
|
|
2333
|
+
var MaxBodyLengthExceededError = createErrorType(
|
|
2334
|
+
"ERR_FR_MAX_BODY_LENGTH_EXCEEDED",
|
|
2335
|
+
"Request body larger than maxBodyLength limit"
|
|
2336
|
+
);
|
|
2337
|
+
var WriteAfterEndError = createErrorType(
|
|
2338
|
+
"ERR_STREAM_WRITE_AFTER_END",
|
|
2339
|
+
"write after end"
|
|
2340
|
+
);
|
|
2341
|
+
|
|
2342
|
+
// An HTTP(S) request that can be redirected
|
|
2343
|
+
function RedirectableRequest(options, responseCallback) {
|
|
2344
|
+
// Initialize the request
|
|
2345
|
+
Writable.call(this);
|
|
2346
|
+
this._sanitizeOptions(options);
|
|
2347
|
+
this._options = options;
|
|
2348
|
+
this._ended = false;
|
|
2349
|
+
this._ending = false;
|
|
2350
|
+
this._redirectCount = 0;
|
|
2351
|
+
this._redirects = [];
|
|
2352
|
+
this._requestBodyLength = 0;
|
|
2353
|
+
this._requestBodyBuffers = [];
|
|
2354
|
+
|
|
2355
|
+
// Attach a callback if passed
|
|
2356
|
+
if (responseCallback) {
|
|
2357
|
+
this.on("response", responseCallback);
|
|
2358
|
+
}
|
|
2359
|
+
|
|
2360
|
+
// React to responses of native requests
|
|
2361
|
+
var self = this;
|
|
2362
|
+
this._onNativeResponse = function (response) {
|
|
2363
|
+
self._processResponse(response);
|
|
2364
|
+
};
|
|
2365
|
+
|
|
2366
|
+
// Perform the first request
|
|
2367
|
+
this._performRequest();
|
|
2368
|
+
}
|
|
2369
|
+
RedirectableRequest.prototype = Object.create(Writable.prototype);
|
|
2370
|
+
|
|
2371
|
+
RedirectableRequest.prototype.abort = function () {
|
|
2372
|
+
// Abort the internal request
|
|
2373
|
+
abortRequest(this._currentRequest);
|
|
2374
|
+
|
|
2375
|
+
// Abort this request
|
|
2376
|
+
this.emit("abort");
|
|
2377
|
+
this.removeAllListeners();
|
|
2378
|
+
};
|
|
2379
|
+
|
|
2380
|
+
// Writes buffered data to the current native request
|
|
2381
|
+
RedirectableRequest.prototype.write = function (data, encoding, callback) {
|
|
2382
|
+
// Writing is not allowed if end has been called
|
|
2383
|
+
if (this._ending) {
|
|
2384
|
+
throw new WriteAfterEndError();
|
|
2385
|
+
}
|
|
2386
|
+
|
|
2387
|
+
// Validate input and shift parameters if necessary
|
|
2388
|
+
if (!(typeof data === "string" || typeof data === "object" && ("length" in data))) {
|
|
2389
|
+
throw new TypeError("data should be a string, Buffer or Uint8Array");
|
|
2390
|
+
}
|
|
2391
|
+
if (typeof encoding === "function") {
|
|
2392
|
+
callback = encoding;
|
|
2393
|
+
encoding = null;
|
|
2394
|
+
}
|
|
2395
|
+
|
|
2396
|
+
// Ignore empty buffers, since writing them doesn't invoke the callback
|
|
2397
|
+
// https://github.com/nodejs/node/issues/22066
|
|
2398
|
+
if (data.length === 0) {
|
|
2399
|
+
if (callback) {
|
|
2400
|
+
callback();
|
|
2401
|
+
}
|
|
2402
|
+
return;
|
|
2403
|
+
}
|
|
2404
|
+
// Only write when we don't exceed the maximum body length
|
|
2405
|
+
if (this._requestBodyLength + data.length <= this._options.maxBodyLength) {
|
|
2406
|
+
this._requestBodyLength += data.length;
|
|
2407
|
+
this._requestBodyBuffers.push({ data: data, encoding: encoding });
|
|
2408
|
+
this._currentRequest.write(data, encoding, callback);
|
|
2409
|
+
}
|
|
2410
|
+
// Error when we exceed the maximum body length
|
|
2411
|
+
else {
|
|
2412
|
+
this.emit("error", new MaxBodyLengthExceededError());
|
|
2413
|
+
this.abort();
|
|
2414
|
+
}
|
|
2415
|
+
};
|
|
2416
|
+
|
|
2417
|
+
// Ends the current native request
|
|
2418
|
+
RedirectableRequest.prototype.end = function (data, encoding, callback) {
|
|
2419
|
+
// Shift parameters if necessary
|
|
2420
|
+
if (typeof data === "function") {
|
|
2421
|
+
callback = data;
|
|
2422
|
+
data = encoding = null;
|
|
2423
|
+
}
|
|
2424
|
+
else if (typeof encoding === "function") {
|
|
2425
|
+
callback = encoding;
|
|
2426
|
+
encoding = null;
|
|
2427
|
+
}
|
|
2428
|
+
|
|
2429
|
+
// Write data if needed and end
|
|
2430
|
+
if (!data) {
|
|
2431
|
+
this._ended = this._ending = true;
|
|
2432
|
+
this._currentRequest.end(null, null, callback);
|
|
2433
|
+
}
|
|
2434
|
+
else {
|
|
2435
|
+
var self = this;
|
|
2436
|
+
var currentRequest = this._currentRequest;
|
|
2437
|
+
this.write(data, encoding, function () {
|
|
2438
|
+
self._ended = true;
|
|
2439
|
+
currentRequest.end(null, null, callback);
|
|
2440
|
+
});
|
|
2441
|
+
this._ending = true;
|
|
2442
|
+
}
|
|
2443
|
+
};
|
|
2444
|
+
|
|
2445
|
+
// Sets a header value on the current native request
|
|
2446
|
+
RedirectableRequest.prototype.setHeader = function (name, value) {
|
|
2447
|
+
this._options.headers[name] = value;
|
|
2448
|
+
this._currentRequest.setHeader(name, value);
|
|
2449
|
+
};
|
|
2450
|
+
|
|
2451
|
+
// Clears a header value on the current native request
|
|
2452
|
+
RedirectableRequest.prototype.removeHeader = function (name) {
|
|
2453
|
+
delete this._options.headers[name];
|
|
2454
|
+
this._currentRequest.removeHeader(name);
|
|
2455
|
+
};
|
|
2456
|
+
|
|
2457
|
+
// Global timeout for all underlying requests
|
|
2458
|
+
RedirectableRequest.prototype.setTimeout = function (msecs, callback) {
|
|
2459
|
+
var self = this;
|
|
2460
|
+
if (callback) {
|
|
2461
|
+
this.on("timeout", callback);
|
|
2462
|
+
}
|
|
2463
|
+
|
|
2464
|
+
function destroyOnTimeout(socket) {
|
|
2465
|
+
socket.setTimeout(msecs);
|
|
2466
|
+
socket.removeListener("timeout", socket.destroy);
|
|
2467
|
+
socket.addListener("timeout", socket.destroy);
|
|
2468
|
+
}
|
|
2469
|
+
|
|
2470
|
+
// Sets up a timer to trigger a timeout event
|
|
2471
|
+
function startTimer(socket) {
|
|
2472
|
+
if (self._timeout) {
|
|
2473
|
+
clearTimeout(self._timeout);
|
|
2474
|
+
}
|
|
2475
|
+
self._timeout = setTimeout(function () {
|
|
2476
|
+
self.emit("timeout");
|
|
2477
|
+
clearTimer();
|
|
2478
|
+
}, msecs);
|
|
2479
|
+
destroyOnTimeout(socket);
|
|
2480
|
+
}
|
|
2481
|
+
|
|
2482
|
+
// Prevent a timeout from triggering
|
|
2483
|
+
function clearTimer() {
|
|
2484
|
+
clearTimeout(this._timeout);
|
|
2485
|
+
if (callback) {
|
|
2486
|
+
self.removeListener("timeout", callback);
|
|
2487
|
+
}
|
|
2488
|
+
if (!this.socket) {
|
|
2489
|
+
self._currentRequest.removeListener("socket", startTimer);
|
|
2490
|
+
}
|
|
2491
|
+
}
|
|
2492
|
+
|
|
2493
|
+
// Start the timer when the socket is opened
|
|
2494
|
+
if (this.socket) {
|
|
2495
|
+
startTimer(this.socket);
|
|
2496
|
+
}
|
|
2497
|
+
else {
|
|
2498
|
+
this._currentRequest.once("socket", startTimer);
|
|
2499
|
+
}
|
|
2500
|
+
|
|
2501
|
+
this.on("socket", destroyOnTimeout);
|
|
2502
|
+
this.once("response", clearTimer);
|
|
2503
|
+
this.once("error", clearTimer);
|
|
2504
|
+
|
|
2505
|
+
return this;
|
|
2506
|
+
};
|
|
2507
|
+
|
|
2508
|
+
// Proxy all other public ClientRequest methods
|
|
2509
|
+
[
|
|
2510
|
+
"flushHeaders", "getHeader",
|
|
2511
|
+
"setNoDelay", "setSocketKeepAlive",
|
|
2512
|
+
].forEach(function (method) {
|
|
2513
|
+
RedirectableRequest.prototype[method] = function (a, b) {
|
|
2514
|
+
return this._currentRequest[method](a, b);
|
|
2515
|
+
};
|
|
2516
|
+
});
|
|
2517
|
+
|
|
2518
|
+
// Proxy all public ClientRequest properties
|
|
2519
|
+
["aborted", "connection", "socket"].forEach(function (property) {
|
|
2520
|
+
Object.defineProperty(RedirectableRequest.prototype, property, {
|
|
2521
|
+
get: function () { return this._currentRequest[property]; },
|
|
2522
|
+
});
|
|
2523
|
+
});
|
|
2524
|
+
|
|
2525
|
+
RedirectableRequest.prototype._sanitizeOptions = function (options) {
|
|
2526
|
+
// Ensure headers are always present
|
|
2527
|
+
if (!options.headers) {
|
|
2528
|
+
options.headers = {};
|
|
2529
|
+
}
|
|
2530
|
+
|
|
2531
|
+
// Since http.request treats host as an alias of hostname,
|
|
2532
|
+
// but the url module interprets host as hostname plus port,
|
|
2533
|
+
// eliminate the host property to avoid confusion.
|
|
2534
|
+
if (options.host) {
|
|
2535
|
+
// Use hostname if set, because it has precedence
|
|
2536
|
+
if (!options.hostname) {
|
|
2537
|
+
options.hostname = options.host;
|
|
2538
|
+
}
|
|
2539
|
+
delete options.host;
|
|
2540
|
+
}
|
|
2541
|
+
|
|
2542
|
+
// Complete the URL object when necessary
|
|
2543
|
+
if (!options.pathname && options.path) {
|
|
2544
|
+
var searchPos = options.path.indexOf("?");
|
|
2545
|
+
if (searchPos < 0) {
|
|
2546
|
+
options.pathname = options.path;
|
|
2547
|
+
}
|
|
2548
|
+
else {
|
|
2549
|
+
options.pathname = options.path.substring(0, searchPos);
|
|
2550
|
+
options.search = options.path.substring(searchPos);
|
|
2551
|
+
}
|
|
2552
|
+
}
|
|
2553
|
+
};
|
|
2554
|
+
|
|
2555
|
+
|
|
2556
|
+
// Executes the next native request (initial or redirect)
|
|
2557
|
+
RedirectableRequest.prototype._performRequest = function () {
|
|
2558
|
+
// Load the native protocol
|
|
2559
|
+
var protocol = this._options.protocol;
|
|
2560
|
+
var nativeProtocol = this._options.nativeProtocols[protocol];
|
|
2561
|
+
if (!nativeProtocol) {
|
|
2562
|
+
this.emit("error", new TypeError("Unsupported protocol " + protocol));
|
|
2563
|
+
return;
|
|
2564
|
+
}
|
|
2565
|
+
|
|
2566
|
+
// If specified, use the agent corresponding to the protocol
|
|
2567
|
+
// (HTTP and HTTPS use different types of agents)
|
|
2568
|
+
if (this._options.agents) {
|
|
2569
|
+
var scheme = protocol.substr(0, protocol.length - 1);
|
|
2570
|
+
this._options.agent = this._options.agents[scheme];
|
|
2571
|
+
}
|
|
2572
|
+
|
|
2573
|
+
// Create the native request
|
|
2574
|
+
var request = this._currentRequest =
|
|
2575
|
+
nativeProtocol.request(this._options, this._onNativeResponse);
|
|
2576
|
+
this._currentUrl = url__default['default'].format(this._options);
|
|
2577
|
+
|
|
2578
|
+
// Set up event handlers
|
|
2579
|
+
request._redirectable = this;
|
|
2580
|
+
for (var e = 0; e < events.length; e++) {
|
|
2581
|
+
request.on(events[e], eventHandlers[events[e]]);
|
|
2582
|
+
}
|
|
2583
|
+
|
|
2584
|
+
// End a redirected request
|
|
2585
|
+
// (The first request must be ended explicitly with RedirectableRequest#end)
|
|
2586
|
+
if (this._isRedirect) {
|
|
2587
|
+
// Write the request entity and end.
|
|
2588
|
+
var i = 0;
|
|
2589
|
+
var self = this;
|
|
2590
|
+
var buffers = this._requestBodyBuffers;
|
|
2591
|
+
(function writeNext(error) {
|
|
2592
|
+
// Only write if this request has not been redirected yet
|
|
2593
|
+
/* istanbul ignore else */
|
|
2594
|
+
if (request === self._currentRequest) {
|
|
2595
|
+
// Report any write errors
|
|
2596
|
+
/* istanbul ignore if */
|
|
2597
|
+
if (error) {
|
|
2598
|
+
self.emit("error", error);
|
|
2599
|
+
}
|
|
2600
|
+
// Write the next buffer if there are still left
|
|
2601
|
+
else if (i < buffers.length) {
|
|
2602
|
+
var buffer = buffers[i++];
|
|
2603
|
+
/* istanbul ignore else */
|
|
2604
|
+
if (!request.finished) {
|
|
2605
|
+
request.write(buffer.data, buffer.encoding, writeNext);
|
|
2606
|
+
}
|
|
2607
|
+
}
|
|
2608
|
+
// End the request if `end` has been called on us
|
|
2609
|
+
else if (self._ended) {
|
|
2610
|
+
request.end();
|
|
2611
|
+
}
|
|
2612
|
+
}
|
|
2613
|
+
}());
|
|
2614
|
+
}
|
|
2615
|
+
};
|
|
2616
|
+
|
|
2617
|
+
// Processes a response from the current native request
|
|
2618
|
+
RedirectableRequest.prototype._processResponse = function (response) {
|
|
2619
|
+
// Store the redirected response
|
|
2620
|
+
var statusCode = response.statusCode;
|
|
2621
|
+
if (this._options.trackRedirects) {
|
|
2622
|
+
this._redirects.push({
|
|
2623
|
+
url: this._currentUrl,
|
|
2624
|
+
headers: response.headers,
|
|
2625
|
+
statusCode: statusCode,
|
|
2626
|
+
});
|
|
2627
|
+
}
|
|
2628
|
+
|
|
2629
|
+
// RFC7231§6.4: The 3xx (Redirection) class of status code indicates
|
|
2630
|
+
// that further action needs to be taken by the user agent in order to
|
|
2631
|
+
// fulfill the request. If a Location header field is provided,
|
|
2632
|
+
// the user agent MAY automatically redirect its request to the URI
|
|
2633
|
+
// referenced by the Location field value,
|
|
2634
|
+
// even if the specific status code is not understood.
|
|
2635
|
+
var location = response.headers.location;
|
|
2636
|
+
if (location && this._options.followRedirects !== false &&
|
|
2637
|
+
statusCode >= 300 && statusCode < 400) {
|
|
2638
|
+
// Abort the current request
|
|
2639
|
+
abortRequest(this._currentRequest);
|
|
2640
|
+
// Discard the remainder of the response to avoid waiting for data
|
|
2641
|
+
response.destroy();
|
|
2642
|
+
|
|
2643
|
+
// RFC7231§6.4: A client SHOULD detect and intervene
|
|
2644
|
+
// in cyclical redirections (i.e., "infinite" redirection loops).
|
|
2645
|
+
if (++this._redirectCount > this._options.maxRedirects) {
|
|
2646
|
+
this.emit("error", new TooManyRedirectsError());
|
|
2647
|
+
return;
|
|
2648
|
+
}
|
|
2649
|
+
|
|
2650
|
+
// RFC7231§6.4: Automatic redirection needs to done with
|
|
2651
|
+
// care for methods not known to be safe, […]
|
|
2652
|
+
// RFC7231§6.4.2–3: For historical reasons, a user agent MAY change
|
|
2653
|
+
// the request method from POST to GET for the subsequent request.
|
|
2654
|
+
if ((statusCode === 301 || statusCode === 302) && this._options.method === "POST" ||
|
|
2655
|
+
// RFC7231§6.4.4: The 303 (See Other) status code indicates that
|
|
2656
|
+
// the server is redirecting the user agent to a different resource […]
|
|
2657
|
+
// A user agent can perform a retrieval request targeting that URI
|
|
2658
|
+
// (a GET or HEAD request if using HTTP) […]
|
|
2659
|
+
(statusCode === 303) && !/^(?:GET|HEAD)$/.test(this._options.method)) {
|
|
2660
|
+
this._options.method = "GET";
|
|
2661
|
+
// Drop a possible entity and headers related to it
|
|
2662
|
+
this._requestBodyBuffers = [];
|
|
2663
|
+
removeMatchingHeaders(/^content-/i, this._options.headers);
|
|
2664
|
+
}
|
|
2665
|
+
|
|
2666
|
+
// Drop the Host header, as the redirect might lead to a different host
|
|
2667
|
+
var previousHostName = removeMatchingHeaders(/^host$/i, this._options.headers) ||
|
|
2668
|
+
url__default['default'].parse(this._currentUrl).hostname;
|
|
2669
|
+
|
|
2670
|
+
// Create the redirected request
|
|
2671
|
+
var redirectUrl = url__default['default'].resolve(this._currentUrl, location);
|
|
2672
|
+
debug_1("redirecting to", redirectUrl);
|
|
2673
|
+
this._isRedirect = true;
|
|
2674
|
+
var redirectUrlParts = url__default['default'].parse(redirectUrl);
|
|
2675
|
+
Object.assign(this._options, redirectUrlParts);
|
|
2676
|
+
|
|
2677
|
+
// Drop the Authorization header if redirecting to another host
|
|
2678
|
+
if (redirectUrlParts.hostname !== previousHostName) {
|
|
2679
|
+
removeMatchingHeaders(/^authorization$/i, this._options.headers);
|
|
2680
|
+
}
|
|
2681
|
+
|
|
2682
|
+
// Evaluate the beforeRedirect callback
|
|
2683
|
+
if (typeof this._options.beforeRedirect === "function") {
|
|
2684
|
+
var responseDetails = { headers: response.headers };
|
|
2685
|
+
try {
|
|
2686
|
+
this._options.beforeRedirect.call(null, this._options, responseDetails);
|
|
2687
|
+
}
|
|
2688
|
+
catch (err) {
|
|
2689
|
+
this.emit("error", err);
|
|
2690
|
+
return;
|
|
2691
|
+
}
|
|
2692
|
+
this._sanitizeOptions(this._options);
|
|
2693
|
+
}
|
|
2694
|
+
|
|
2695
|
+
// Perform the redirected request
|
|
2696
|
+
try {
|
|
2697
|
+
this._performRequest();
|
|
2698
|
+
}
|
|
2699
|
+
catch (cause) {
|
|
2700
|
+
var error = new RedirectionError("Redirected request failed: " + cause.message);
|
|
2701
|
+
error.cause = cause;
|
|
2702
|
+
this.emit("error", error);
|
|
2703
|
+
}
|
|
2704
|
+
}
|
|
2705
|
+
else {
|
|
2706
|
+
// The response is not a redirect; return it as-is
|
|
2707
|
+
response.responseUrl = this._currentUrl;
|
|
2708
|
+
response.redirects = this._redirects;
|
|
2709
|
+
this.emit("response", response);
|
|
2710
|
+
|
|
2711
|
+
// Clean up
|
|
2712
|
+
this._requestBodyBuffers = [];
|
|
2713
|
+
}
|
|
2714
|
+
};
|
|
2715
|
+
|
|
2716
|
+
// Wraps the key/value object of protocols with redirect functionality
|
|
2717
|
+
function wrap(protocols) {
|
|
2718
|
+
// Default settings
|
|
2719
|
+
var exports = {
|
|
2720
|
+
maxRedirects: 21,
|
|
2721
|
+
maxBodyLength: 10 * 1024 * 1024,
|
|
2722
|
+
};
|
|
2723
|
+
|
|
2724
|
+
// Wrap each protocol
|
|
2725
|
+
var nativeProtocols = {};
|
|
2726
|
+
Object.keys(protocols).forEach(function (scheme) {
|
|
2727
|
+
var protocol = scheme + ":";
|
|
2728
|
+
var nativeProtocol = nativeProtocols[protocol] = protocols[scheme];
|
|
2729
|
+
var wrappedProtocol = exports[scheme] = Object.create(nativeProtocol);
|
|
2730
|
+
|
|
2731
|
+
// Executes a request, following redirects
|
|
2732
|
+
function request(input, options, callback) {
|
|
2733
|
+
// Parse parameters
|
|
2734
|
+
if (typeof input === "string") {
|
|
2735
|
+
var urlStr = input;
|
|
2736
|
+
try {
|
|
2737
|
+
input = urlToOptions(new URL(urlStr));
|
|
2738
|
+
}
|
|
2739
|
+
catch (err) {
|
|
2740
|
+
/* istanbul ignore next */
|
|
2741
|
+
input = url__default['default'].parse(urlStr);
|
|
2742
|
+
}
|
|
2743
|
+
}
|
|
2744
|
+
else if (URL && (input instanceof URL)) {
|
|
2745
|
+
input = urlToOptions(input);
|
|
2746
|
+
}
|
|
2747
|
+
else {
|
|
2748
|
+
callback = options;
|
|
2749
|
+
options = input;
|
|
2750
|
+
input = { protocol: protocol };
|
|
2751
|
+
}
|
|
2752
|
+
if (typeof options === "function") {
|
|
2753
|
+
callback = options;
|
|
2754
|
+
options = null;
|
|
2755
|
+
}
|
|
2756
|
+
|
|
2757
|
+
// Set defaults
|
|
2758
|
+
options = Object.assign({
|
|
2759
|
+
maxRedirects: exports.maxRedirects,
|
|
2760
|
+
maxBodyLength: exports.maxBodyLength,
|
|
2761
|
+
}, input, options);
|
|
2762
|
+
options.nativeProtocols = nativeProtocols;
|
|
2763
|
+
|
|
2764
|
+
assert__default['default'].equal(options.protocol, protocol, "protocol mismatch");
|
|
2765
|
+
debug_1("options", options);
|
|
2766
|
+
return new RedirectableRequest(options, callback);
|
|
2767
|
+
}
|
|
2768
|
+
|
|
2769
|
+
// Executes a GET request, following redirects
|
|
2770
|
+
function get(input, options, callback) {
|
|
2771
|
+
var wrappedRequest = wrappedProtocol.request(input, options, callback);
|
|
2772
|
+
wrappedRequest.end();
|
|
2773
|
+
return wrappedRequest;
|
|
2774
|
+
}
|
|
2775
|
+
|
|
2776
|
+
// Expose the properties on the wrapped protocol
|
|
2777
|
+
Object.defineProperties(wrappedProtocol, {
|
|
2778
|
+
request: { value: request, configurable: true, enumerable: true, writable: true },
|
|
2779
|
+
get: { value: get, configurable: true, enumerable: true, writable: true },
|
|
2780
|
+
});
|
|
2781
|
+
});
|
|
2782
|
+
return exports;
|
|
2783
|
+
}
|
|
2784
|
+
|
|
2785
|
+
/* istanbul ignore next */
|
|
2786
|
+
function noop() { /* empty */ }
|
|
2787
|
+
|
|
2788
|
+
// from https://github.com/nodejs/node/blob/master/lib/internal/url.js
|
|
2789
|
+
function urlToOptions(urlObject) {
|
|
2790
|
+
var options = {
|
|
2791
|
+
protocol: urlObject.protocol,
|
|
2792
|
+
hostname: urlObject.hostname.startsWith("[") ?
|
|
2793
|
+
/* istanbul ignore next */
|
|
2794
|
+
urlObject.hostname.slice(1, -1) :
|
|
2795
|
+
urlObject.hostname,
|
|
2796
|
+
hash: urlObject.hash,
|
|
2797
|
+
search: urlObject.search,
|
|
2798
|
+
pathname: urlObject.pathname,
|
|
2799
|
+
path: urlObject.pathname + urlObject.search,
|
|
2800
|
+
href: urlObject.href,
|
|
2801
|
+
};
|
|
2802
|
+
if (urlObject.port !== "") {
|
|
2803
|
+
options.port = Number(urlObject.port);
|
|
2804
|
+
}
|
|
2805
|
+
return options;
|
|
2806
|
+
}
|
|
2807
|
+
|
|
2808
|
+
function removeMatchingHeaders(regex, headers) {
|
|
2809
|
+
var lastValue;
|
|
2810
|
+
for (var header in headers) {
|
|
2811
|
+
if (regex.test(header)) {
|
|
2812
|
+
lastValue = headers[header];
|
|
2813
|
+
delete headers[header];
|
|
2814
|
+
}
|
|
2815
|
+
}
|
|
2816
|
+
return lastValue;
|
|
2817
|
+
}
|
|
2818
|
+
|
|
2819
|
+
function createErrorType(code, defaultMessage) {
|
|
2820
|
+
function CustomError(message) {
|
|
2821
|
+
Error.captureStackTrace(this, this.constructor);
|
|
2822
|
+
this.message = message || defaultMessage;
|
|
2823
|
+
}
|
|
2824
|
+
CustomError.prototype = new Error();
|
|
2825
|
+
CustomError.prototype.constructor = CustomError;
|
|
2826
|
+
CustomError.prototype.name = "Error [" + code + "]";
|
|
2827
|
+
CustomError.prototype.code = code;
|
|
2828
|
+
return CustomError;
|
|
2829
|
+
}
|
|
2830
|
+
|
|
2831
|
+
function abortRequest(request) {
|
|
2832
|
+
for (var e = 0; e < events.length; e++) {
|
|
2833
|
+
request.removeListener(events[e], eventHandlers[events[e]]);
|
|
2834
|
+
}
|
|
2835
|
+
request.on("error", noop);
|
|
2836
|
+
request.abort();
|
|
2837
|
+
}
|
|
2838
|
+
|
|
2839
|
+
// Exports
|
|
2840
|
+
var followRedirects = wrap({ http: http__default['default'], https: https__default['default'] });
|
|
2841
|
+
var wrap_1 = wrap;
|
|
2842
|
+
followRedirects.wrap = wrap_1;
|
|
2843
|
+
|
|
2844
|
+
var _args = [
|
|
2845
|
+
[
|
|
2846
|
+
"axios@0.21.1",
|
|
2847
|
+
"/codefresh/volume/becollective-npm/packages/utils"
|
|
2848
|
+
]
|
|
2849
|
+
];
|
|
2850
|
+
var _from = "axios@0.21.1";
|
|
2851
|
+
var _id = "axios@0.21.1";
|
|
2852
|
+
var _inBundle = false;
|
|
2853
|
+
var _integrity = "sha512-dKQiRHxGD9PPRIUNIWvZhPTPpl1rf/OxTYKsqKUDjBwYylTvV7SjSHJb9ratfyzM6wCdLCOYLzs73qpg5c4iGA==";
|
|
2854
|
+
var _location = "/axios";
|
|
2855
|
+
var _phantomChildren = {
|
|
2856
|
+
};
|
|
2857
|
+
var _requested = {
|
|
2858
|
+
type: "version",
|
|
2859
|
+
registry: true,
|
|
2860
|
+
raw: "axios@0.21.1",
|
|
2861
|
+
name: "axios",
|
|
2862
|
+
escapedName: "axios",
|
|
2863
|
+
rawSpec: "0.21.1",
|
|
2864
|
+
saveSpec: null,
|
|
2865
|
+
fetchSpec: "0.21.1"
|
|
2866
|
+
};
|
|
2867
|
+
var _requiredBy = [
|
|
2868
|
+
"/"
|
|
2869
|
+
];
|
|
2870
|
+
var _resolved = "https://registry.npmjs.org/axios/-/axios-0.21.1.tgz";
|
|
2871
|
+
var _spec = "0.21.1";
|
|
2872
|
+
var _where = "/codefresh/volume/becollective-npm/packages/utils";
|
|
2873
|
+
var author = {
|
|
2874
|
+
name: "Matt Zabriskie"
|
|
2875
|
+
};
|
|
2876
|
+
var browser = {
|
|
2877
|
+
"./lib/adapters/http.js": "./lib/adapters/xhr.js"
|
|
2878
|
+
};
|
|
2879
|
+
var bugs = {
|
|
2880
|
+
url: "https://github.com/axios/axios/issues"
|
|
2881
|
+
};
|
|
2882
|
+
var bundlesize = [
|
|
2883
|
+
{
|
|
2884
|
+
path: "./dist/axios.min.js",
|
|
2885
|
+
threshold: "5kB"
|
|
2886
|
+
}
|
|
2887
|
+
];
|
|
2888
|
+
var dependencies = {
|
|
2889
|
+
"follow-redirects": "^1.10.0"
|
|
2890
|
+
};
|
|
2891
|
+
var description = "Promise based HTTP client for the browser and node.js";
|
|
2892
|
+
var devDependencies = {
|
|
2893
|
+
bundlesize: "^0.17.0",
|
|
2894
|
+
coveralls: "^3.0.0",
|
|
2895
|
+
"es6-promise": "^4.2.4",
|
|
2896
|
+
grunt: "^1.0.2",
|
|
2897
|
+
"grunt-banner": "^0.6.0",
|
|
2898
|
+
"grunt-cli": "^1.2.0",
|
|
2899
|
+
"grunt-contrib-clean": "^1.1.0",
|
|
2900
|
+
"grunt-contrib-watch": "^1.0.0",
|
|
2901
|
+
"grunt-eslint": "^20.1.0",
|
|
2902
|
+
"grunt-karma": "^2.0.0",
|
|
2903
|
+
"grunt-mocha-test": "^0.13.3",
|
|
2904
|
+
"grunt-ts": "^6.0.0-beta.19",
|
|
2905
|
+
"grunt-webpack": "^1.0.18",
|
|
2906
|
+
"istanbul-instrumenter-loader": "^1.0.0",
|
|
2907
|
+
"jasmine-core": "^2.4.1",
|
|
2908
|
+
karma: "^1.3.0",
|
|
2909
|
+
"karma-chrome-launcher": "^2.2.0",
|
|
2910
|
+
"karma-coverage": "^1.1.1",
|
|
2911
|
+
"karma-firefox-launcher": "^1.1.0",
|
|
2912
|
+
"karma-jasmine": "^1.1.1",
|
|
2913
|
+
"karma-jasmine-ajax": "^0.1.13",
|
|
2914
|
+
"karma-opera-launcher": "^1.0.0",
|
|
2915
|
+
"karma-safari-launcher": "^1.0.0",
|
|
2916
|
+
"karma-sauce-launcher": "^1.2.0",
|
|
2917
|
+
"karma-sinon": "^1.0.5",
|
|
2918
|
+
"karma-sourcemap-loader": "^0.3.7",
|
|
2919
|
+
"karma-webpack": "^1.7.0",
|
|
2920
|
+
"load-grunt-tasks": "^3.5.2",
|
|
2921
|
+
minimist: "^1.2.0",
|
|
2922
|
+
mocha: "^5.2.0",
|
|
2923
|
+
sinon: "^4.5.0",
|
|
2924
|
+
typescript: "^2.8.1",
|
|
2925
|
+
"url-search-params": "^0.10.0",
|
|
2926
|
+
webpack: "^1.13.1",
|
|
2927
|
+
"webpack-dev-server": "^1.14.1"
|
|
2928
|
+
};
|
|
2929
|
+
var homepage = "https://github.com/axios/axios";
|
|
2930
|
+
var jsdelivr = "dist/axios.min.js";
|
|
2931
|
+
var keywords = [
|
|
2932
|
+
"xhr",
|
|
2933
|
+
"http",
|
|
2934
|
+
"ajax",
|
|
2935
|
+
"promise",
|
|
2936
|
+
"node"
|
|
2937
|
+
];
|
|
2938
|
+
var license = "MIT";
|
|
2939
|
+
var main = "index.js";
|
|
2940
|
+
var name = "axios";
|
|
2941
|
+
var repository = {
|
|
2942
|
+
type: "git",
|
|
2943
|
+
url: "git+https://github.com/axios/axios.git"
|
|
2944
|
+
};
|
|
2945
|
+
var scripts = {
|
|
2946
|
+
build: "NODE_ENV=production grunt build",
|
|
2947
|
+
coveralls: "cat coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js",
|
|
2948
|
+
examples: "node ./examples/server.js",
|
|
2949
|
+
fix: "eslint --fix lib/**/*.js",
|
|
2950
|
+
postversion: "git push && git push --tags",
|
|
2951
|
+
preversion: "npm test",
|
|
2952
|
+
start: "node ./sandbox/server.js",
|
|
2953
|
+
test: "grunt test && bundlesize",
|
|
2954
|
+
version: "npm run build && grunt version && git add -A dist && git add CHANGELOG.md bower.json package.json"
|
|
2955
|
+
};
|
|
2956
|
+
var typings = "./index.d.ts";
|
|
2957
|
+
var unpkg = "dist/axios.min.js";
|
|
2958
|
+
var version = "0.21.1";
|
|
2959
|
+
var pkg = {
|
|
2960
|
+
_args: _args,
|
|
2961
|
+
_from: _from,
|
|
2962
|
+
_id: _id,
|
|
2963
|
+
_inBundle: _inBundle,
|
|
2964
|
+
_integrity: _integrity,
|
|
2965
|
+
_location: _location,
|
|
2966
|
+
_phantomChildren: _phantomChildren,
|
|
2967
|
+
_requested: _requested,
|
|
2968
|
+
_requiredBy: _requiredBy,
|
|
2969
|
+
_resolved: _resolved,
|
|
2970
|
+
_spec: _spec,
|
|
2971
|
+
_where: _where,
|
|
2972
|
+
author: author,
|
|
2973
|
+
browser: browser,
|
|
2974
|
+
bugs: bugs,
|
|
2975
|
+
bundlesize: bundlesize,
|
|
2976
|
+
dependencies: dependencies,
|
|
2977
|
+
description: description,
|
|
2978
|
+
devDependencies: devDependencies,
|
|
2979
|
+
homepage: homepage,
|
|
2980
|
+
jsdelivr: jsdelivr,
|
|
2981
|
+
keywords: keywords,
|
|
2982
|
+
license: license,
|
|
2983
|
+
main: main,
|
|
2984
|
+
name: name,
|
|
2985
|
+
repository: repository,
|
|
2986
|
+
scripts: scripts,
|
|
2987
|
+
typings: typings,
|
|
2988
|
+
unpkg: unpkg,
|
|
2989
|
+
version: version
|
|
2990
|
+
};
|
|
2991
|
+
|
|
2992
|
+
var httpFollow = followRedirects.http;
|
|
2993
|
+
var httpsFollow = followRedirects.https;
|
|
2994
|
+
|
|
2995
|
+
|
|
2996
|
+
|
|
2997
|
+
|
|
2998
|
+
|
|
2999
|
+
|
|
3000
|
+
var isHttps = /https:?/;
|
|
3001
|
+
|
|
3002
|
+
/**
|
|
3003
|
+
*
|
|
3004
|
+
* @param {http.ClientRequestArgs} options
|
|
3005
|
+
* @param {AxiosProxyConfig} proxy
|
|
3006
|
+
* @param {string} location
|
|
3007
|
+
*/
|
|
3008
|
+
function setProxy(options, proxy, location) {
|
|
3009
|
+
options.hostname = proxy.host;
|
|
3010
|
+
options.host = proxy.host;
|
|
3011
|
+
options.port = proxy.port;
|
|
3012
|
+
options.path = location;
|
|
3013
|
+
|
|
3014
|
+
// Basic proxy authorization
|
|
3015
|
+
if (proxy.auth) {
|
|
3016
|
+
var base64 = Buffer.from(proxy.auth.username + ':' + proxy.auth.password, 'utf8').toString('base64');
|
|
3017
|
+
options.headers['Proxy-Authorization'] = 'Basic ' + base64;
|
|
3018
|
+
}
|
|
3019
|
+
|
|
3020
|
+
// If a proxy is used, any redirects must also pass through the proxy
|
|
3021
|
+
options.beforeRedirect = function beforeRedirect(redirection) {
|
|
3022
|
+
redirection.headers.host = redirection.host;
|
|
3023
|
+
setProxy(redirection, proxy, redirection.href);
|
|
3024
|
+
};
|
|
3025
|
+
}
|
|
3026
|
+
|
|
3027
|
+
/*eslint consistent-return:0*/
|
|
3028
|
+
var http_1 = function httpAdapter(config) {
|
|
3029
|
+
return new Promise(function dispatchHttpRequest(resolvePromise, rejectPromise) {
|
|
3030
|
+
var resolve = function resolve(value) {
|
|
3031
|
+
resolvePromise(value);
|
|
3032
|
+
};
|
|
3033
|
+
var reject = function reject(value) {
|
|
3034
|
+
rejectPromise(value);
|
|
3035
|
+
};
|
|
3036
|
+
var data = config.data;
|
|
3037
|
+
var headers = config.headers;
|
|
3038
|
+
|
|
3039
|
+
// Set User-Agent (required by some servers)
|
|
3040
|
+
// Only set header if it hasn't been set in config
|
|
3041
|
+
// See https://github.com/axios/axios/issues/69
|
|
3042
|
+
if (!headers['User-Agent'] && !headers['user-agent']) {
|
|
3043
|
+
headers['User-Agent'] = 'axios/' + pkg.version;
|
|
3044
|
+
}
|
|
3045
|
+
|
|
3046
|
+
if (data && !utils.isStream(data)) {
|
|
3047
|
+
if (Buffer.isBuffer(data)) ; else if (utils.isArrayBuffer(data)) {
|
|
3048
|
+
data = Buffer.from(new Uint8Array(data));
|
|
3049
|
+
} else if (utils.isString(data)) {
|
|
3050
|
+
data = Buffer.from(data, 'utf-8');
|
|
3051
|
+
} else {
|
|
3052
|
+
return reject(createError(
|
|
3053
|
+
'Data after transformation must be a string, an ArrayBuffer, a Buffer, or a Stream',
|
|
3054
|
+
config
|
|
3055
|
+
));
|
|
3056
|
+
}
|
|
3057
|
+
|
|
3058
|
+
// Add Content-Length header if data exists
|
|
3059
|
+
headers['Content-Length'] = data.length;
|
|
3060
|
+
}
|
|
3061
|
+
|
|
3062
|
+
// HTTP basic authentication
|
|
3063
|
+
var auth = undefined;
|
|
3064
|
+
if (config.auth) {
|
|
3065
|
+
var username = config.auth.username || '';
|
|
3066
|
+
var password = config.auth.password || '';
|
|
3067
|
+
auth = username + ':' + password;
|
|
3068
|
+
}
|
|
3069
|
+
|
|
3070
|
+
// Parse url
|
|
3071
|
+
var fullPath = buildFullPath(config.baseURL, config.url);
|
|
3072
|
+
var parsed = url__default['default'].parse(fullPath);
|
|
3073
|
+
var protocol = parsed.protocol || 'http:';
|
|
3074
|
+
|
|
3075
|
+
if (!auth && parsed.auth) {
|
|
3076
|
+
var urlAuth = parsed.auth.split(':');
|
|
3077
|
+
var urlUsername = urlAuth[0] || '';
|
|
3078
|
+
var urlPassword = urlAuth[1] || '';
|
|
3079
|
+
auth = urlUsername + ':' + urlPassword;
|
|
3080
|
+
}
|
|
3081
|
+
|
|
3082
|
+
if (auth) {
|
|
3083
|
+
delete headers.Authorization;
|
|
3084
|
+
}
|
|
3085
|
+
|
|
3086
|
+
var isHttpsRequest = isHttps.test(protocol);
|
|
3087
|
+
var agent = isHttpsRequest ? config.httpsAgent : config.httpAgent;
|
|
3088
|
+
|
|
3089
|
+
var options = {
|
|
3090
|
+
path: buildURL(parsed.path, config.params, config.paramsSerializer).replace(/^\?/, ''),
|
|
3091
|
+
method: config.method.toUpperCase(),
|
|
3092
|
+
headers: headers,
|
|
3093
|
+
agent: agent,
|
|
3094
|
+
agents: { http: config.httpAgent, https: config.httpsAgent },
|
|
3095
|
+
auth: auth
|
|
3096
|
+
};
|
|
3097
|
+
|
|
3098
|
+
if (config.socketPath) {
|
|
3099
|
+
options.socketPath = config.socketPath;
|
|
3100
|
+
} else {
|
|
3101
|
+
options.hostname = parsed.hostname;
|
|
3102
|
+
options.port = parsed.port;
|
|
3103
|
+
}
|
|
3104
|
+
|
|
3105
|
+
var proxy = config.proxy;
|
|
3106
|
+
if (!proxy && proxy !== false) {
|
|
3107
|
+
var proxyEnv = protocol.slice(0, -1) + '_proxy';
|
|
3108
|
+
var proxyUrl = process.env[proxyEnv] || process.env[proxyEnv.toUpperCase()];
|
|
3109
|
+
if (proxyUrl) {
|
|
3110
|
+
var parsedProxyUrl = url__default['default'].parse(proxyUrl);
|
|
3111
|
+
var noProxyEnv = process.env.no_proxy || process.env.NO_PROXY;
|
|
3112
|
+
var shouldProxy = true;
|
|
3113
|
+
|
|
3114
|
+
if (noProxyEnv) {
|
|
3115
|
+
var noProxy = noProxyEnv.split(',').map(function trim(s) {
|
|
3116
|
+
return s.trim();
|
|
3117
|
+
});
|
|
3118
|
+
|
|
3119
|
+
shouldProxy = !noProxy.some(function proxyMatch(proxyElement) {
|
|
3120
|
+
if (!proxyElement) {
|
|
3121
|
+
return false;
|
|
3122
|
+
}
|
|
3123
|
+
if (proxyElement === '*') {
|
|
3124
|
+
return true;
|
|
3125
|
+
}
|
|
3126
|
+
if (proxyElement[0] === '.' &&
|
|
3127
|
+
parsed.hostname.substr(parsed.hostname.length - proxyElement.length) === proxyElement) {
|
|
3128
|
+
return true;
|
|
3129
|
+
}
|
|
3130
|
+
|
|
3131
|
+
return parsed.hostname === proxyElement;
|
|
3132
|
+
});
|
|
3133
|
+
}
|
|
3134
|
+
|
|
3135
|
+
if (shouldProxy) {
|
|
3136
|
+
proxy = {
|
|
3137
|
+
host: parsedProxyUrl.hostname,
|
|
3138
|
+
port: parsedProxyUrl.port,
|
|
3139
|
+
protocol: parsedProxyUrl.protocol
|
|
3140
|
+
};
|
|
3141
|
+
|
|
3142
|
+
if (parsedProxyUrl.auth) {
|
|
3143
|
+
var proxyUrlAuth = parsedProxyUrl.auth.split(':');
|
|
3144
|
+
proxy.auth = {
|
|
3145
|
+
username: proxyUrlAuth[0],
|
|
3146
|
+
password: proxyUrlAuth[1]
|
|
3147
|
+
};
|
|
3148
|
+
}
|
|
3149
|
+
}
|
|
3150
|
+
}
|
|
3151
|
+
}
|
|
3152
|
+
|
|
3153
|
+
if (proxy) {
|
|
3154
|
+
options.headers.host = parsed.hostname + (parsed.port ? ':' + parsed.port : '');
|
|
3155
|
+
setProxy(options, proxy, protocol + '//' + parsed.hostname + (parsed.port ? ':' + parsed.port : '') + options.path);
|
|
3156
|
+
}
|
|
3157
|
+
|
|
3158
|
+
var transport;
|
|
3159
|
+
var isHttpsProxy = isHttpsRequest && (proxy ? isHttps.test(proxy.protocol) : true);
|
|
3160
|
+
if (config.transport) {
|
|
3161
|
+
transport = config.transport;
|
|
3162
|
+
} else if (config.maxRedirects === 0) {
|
|
3163
|
+
transport = isHttpsProxy ? https__default['default'] : http__default['default'];
|
|
3164
|
+
} else {
|
|
3165
|
+
if (config.maxRedirects) {
|
|
3166
|
+
options.maxRedirects = config.maxRedirects;
|
|
3167
|
+
}
|
|
3168
|
+
transport = isHttpsProxy ? httpsFollow : httpFollow;
|
|
3169
|
+
}
|
|
3170
|
+
|
|
3171
|
+
if (config.maxBodyLength > -1) {
|
|
3172
|
+
options.maxBodyLength = config.maxBodyLength;
|
|
3173
|
+
}
|
|
3174
|
+
|
|
3175
|
+
// Create the request
|
|
3176
|
+
var req = transport.request(options, function handleResponse(res) {
|
|
3177
|
+
if (req.aborted) return;
|
|
3178
|
+
|
|
3179
|
+
// uncompress the response body transparently if required
|
|
3180
|
+
var stream = res;
|
|
3181
|
+
|
|
3182
|
+
// return the last request in case of redirects
|
|
3183
|
+
var lastRequest = res.req || req;
|
|
3184
|
+
|
|
3185
|
+
|
|
3186
|
+
// if no content, is HEAD request or decompress disabled we should not decompress
|
|
3187
|
+
if (res.statusCode !== 204 && lastRequest.method !== 'HEAD' && config.decompress !== false) {
|
|
3188
|
+
switch (res.headers['content-encoding']) {
|
|
3189
|
+
/*eslint default-case:0*/
|
|
3190
|
+
case 'gzip':
|
|
3191
|
+
case 'compress':
|
|
3192
|
+
case 'deflate':
|
|
3193
|
+
// add the unzipper to the body stream processing pipeline
|
|
3194
|
+
stream = stream.pipe(zlib__default['default'].createUnzip());
|
|
3195
|
+
|
|
3196
|
+
// remove the content-encoding in order to not confuse downstream operations
|
|
3197
|
+
delete res.headers['content-encoding'];
|
|
3198
|
+
break;
|
|
3199
|
+
}
|
|
3200
|
+
}
|
|
3201
|
+
|
|
3202
|
+
var response = {
|
|
3203
|
+
status: res.statusCode,
|
|
3204
|
+
statusText: res.statusMessage,
|
|
3205
|
+
headers: res.headers,
|
|
3206
|
+
config: config,
|
|
3207
|
+
request: lastRequest
|
|
3208
|
+
};
|
|
3209
|
+
|
|
3210
|
+
if (config.responseType === 'stream') {
|
|
3211
|
+
response.data = stream;
|
|
3212
|
+
settle(resolve, reject, response);
|
|
3213
|
+
} else {
|
|
3214
|
+
var responseBuffer = [];
|
|
3215
|
+
stream.on('data', function handleStreamData(chunk) {
|
|
3216
|
+
responseBuffer.push(chunk);
|
|
3217
|
+
|
|
3218
|
+
// make sure the content length is not over the maxContentLength if specified
|
|
3219
|
+
if (config.maxContentLength > -1 && Buffer.concat(responseBuffer).length > config.maxContentLength) {
|
|
3220
|
+
stream.destroy();
|
|
3221
|
+
reject(createError('maxContentLength size of ' + config.maxContentLength + ' exceeded',
|
|
3222
|
+
config, null, lastRequest));
|
|
3223
|
+
}
|
|
3224
|
+
});
|
|
3225
|
+
|
|
3226
|
+
stream.on('error', function handleStreamError(err) {
|
|
3227
|
+
if (req.aborted) return;
|
|
3228
|
+
reject(enhanceError(err, config, null, lastRequest));
|
|
3229
|
+
});
|
|
3230
|
+
|
|
3231
|
+
stream.on('end', function handleStreamEnd() {
|
|
3232
|
+
var responseData = Buffer.concat(responseBuffer);
|
|
3233
|
+
if (config.responseType !== 'arraybuffer') {
|
|
3234
|
+
responseData = responseData.toString(config.responseEncoding);
|
|
3235
|
+
if (!config.responseEncoding || config.responseEncoding === 'utf8') {
|
|
3236
|
+
responseData = utils.stripBOM(responseData);
|
|
3237
|
+
}
|
|
3238
|
+
}
|
|
3239
|
+
|
|
3240
|
+
response.data = responseData;
|
|
3241
|
+
settle(resolve, reject, response);
|
|
3242
|
+
});
|
|
3243
|
+
}
|
|
3244
|
+
});
|
|
3245
|
+
|
|
3246
|
+
// Handle errors
|
|
3247
|
+
req.on('error', function handleRequestError(err) {
|
|
3248
|
+
if (req.aborted && err.code !== 'ERR_FR_TOO_MANY_REDIRECTS') return;
|
|
3249
|
+
reject(enhanceError(err, config, null, req));
|
|
3250
|
+
});
|
|
3251
|
+
|
|
3252
|
+
// Handle request timeout
|
|
3253
|
+
if (config.timeout) {
|
|
3254
|
+
// Sometime, the response will be very slow, and does not respond, the connect event will be block by event loop system.
|
|
3255
|
+
// And timer callback will be fired, and abort() will be invoked before connection, then get "socket hang up" and code ECONNRESET.
|
|
3256
|
+
// At this time, if we have a large number of request, nodejs will hang up some socket on background. and the number will up and up.
|
|
3257
|
+
// And then these socket which be hang up will devoring CPU little by little.
|
|
3258
|
+
// ClientRequest.setTimeout will be fired on the specify milliseconds, and can make sure that abort() will be fired after connect.
|
|
3259
|
+
req.setTimeout(config.timeout, function handleRequestTimeout() {
|
|
3260
|
+
req.abort();
|
|
3261
|
+
reject(createError('timeout of ' + config.timeout + 'ms exceeded', config, 'ECONNABORTED', req));
|
|
3262
|
+
});
|
|
3263
|
+
}
|
|
3264
|
+
|
|
3265
|
+
if (config.cancelToken) {
|
|
3266
|
+
// Handle cancellation
|
|
3267
|
+
config.cancelToken.promise.then(function onCanceled(cancel) {
|
|
3268
|
+
if (req.aborted) return;
|
|
3269
|
+
|
|
3270
|
+
req.abort();
|
|
3271
|
+
reject(cancel);
|
|
3272
|
+
});
|
|
3273
|
+
}
|
|
3274
|
+
|
|
3275
|
+
// Send the request
|
|
3276
|
+
if (utils.isStream(data)) {
|
|
3277
|
+
data.on('error', function handleStreamError(err) {
|
|
3278
|
+
reject(enhanceError(err, config, null, req));
|
|
3279
|
+
}).pipe(req);
|
|
3280
|
+
} else {
|
|
3281
|
+
req.end(data);
|
|
3282
|
+
}
|
|
3283
|
+
});
|
|
3284
|
+
};
|
|
3285
|
+
|
|
3286
|
+
var DEFAULT_CONTENT_TYPE = {
|
|
3287
|
+
'Content-Type': 'application/x-www-form-urlencoded'
|
|
3288
|
+
};
|
|
3289
|
+
|
|
3290
|
+
function setContentTypeIfUnset(headers, value) {
|
|
3291
|
+
if (!utils.isUndefined(headers) && utils.isUndefined(headers['Content-Type'])) {
|
|
3292
|
+
headers['Content-Type'] = value;
|
|
3293
|
+
}
|
|
3294
|
+
}
|
|
3295
|
+
|
|
3296
|
+
function getDefaultAdapter() {
|
|
3297
|
+
var adapter;
|
|
3298
|
+
if (typeof XMLHttpRequest !== 'undefined') {
|
|
3299
|
+
// For browsers use XHR adapter
|
|
3300
|
+
adapter = xhr;
|
|
3301
|
+
} else if (typeof process !== 'undefined' && Object.prototype.toString.call(process) === '[object process]') {
|
|
3302
|
+
// For node use HTTP adapter
|
|
3303
|
+
adapter = http_1;
|
|
3304
|
+
}
|
|
3305
|
+
return adapter;
|
|
3306
|
+
}
|
|
3307
|
+
|
|
3308
|
+
var defaults = {
|
|
3309
|
+
adapter: getDefaultAdapter(),
|
|
3310
|
+
|
|
3311
|
+
transformRequest: [function transformRequest(data, headers) {
|
|
3312
|
+
normalizeHeaderName(headers, 'Accept');
|
|
3313
|
+
normalizeHeaderName(headers, 'Content-Type');
|
|
3314
|
+
if (utils.isFormData(data) ||
|
|
3315
|
+
utils.isArrayBuffer(data) ||
|
|
3316
|
+
utils.isBuffer(data) ||
|
|
3317
|
+
utils.isStream(data) ||
|
|
3318
|
+
utils.isFile(data) ||
|
|
3319
|
+
utils.isBlob(data)
|
|
3320
|
+
) {
|
|
3321
|
+
return data;
|
|
3322
|
+
}
|
|
3323
|
+
if (utils.isArrayBufferView(data)) {
|
|
3324
|
+
return data.buffer;
|
|
3325
|
+
}
|
|
3326
|
+
if (utils.isURLSearchParams(data)) {
|
|
3327
|
+
setContentTypeIfUnset(headers, 'application/x-www-form-urlencoded;charset=utf-8');
|
|
3328
|
+
return data.toString();
|
|
3329
|
+
}
|
|
3330
|
+
if (utils.isObject(data)) {
|
|
3331
|
+
setContentTypeIfUnset(headers, 'application/json;charset=utf-8');
|
|
3332
|
+
return JSON.stringify(data);
|
|
3333
|
+
}
|
|
3334
|
+
return data;
|
|
3335
|
+
}],
|
|
3336
|
+
|
|
3337
|
+
transformResponse: [function transformResponse(data) {
|
|
3338
|
+
/*eslint no-param-reassign:0*/
|
|
3339
|
+
if (typeof data === 'string') {
|
|
3340
|
+
try {
|
|
3341
|
+
data = JSON.parse(data);
|
|
3342
|
+
} catch (e) { /* Ignore */ }
|
|
3343
|
+
}
|
|
3344
|
+
return data;
|
|
3345
|
+
}],
|
|
3346
|
+
|
|
3347
|
+
/**
|
|
3348
|
+
* A timeout in milliseconds to abort a request. If set to 0 (default) a
|
|
3349
|
+
* timeout is not created.
|
|
3350
|
+
*/
|
|
3351
|
+
timeout: 0,
|
|
3352
|
+
|
|
3353
|
+
xsrfCookieName: 'XSRF-TOKEN',
|
|
3354
|
+
xsrfHeaderName: 'X-XSRF-TOKEN',
|
|
3355
|
+
|
|
3356
|
+
maxContentLength: -1,
|
|
3357
|
+
maxBodyLength: -1,
|
|
3358
|
+
|
|
3359
|
+
validateStatus: function validateStatus(status) {
|
|
3360
|
+
return status >= 200 && status < 300;
|
|
3361
|
+
}
|
|
3362
|
+
};
|
|
3363
|
+
|
|
3364
|
+
defaults.headers = {
|
|
3365
|
+
common: {
|
|
3366
|
+
'Accept': 'application/json, text/plain, */*'
|
|
3367
|
+
}
|
|
3368
|
+
};
|
|
3369
|
+
|
|
3370
|
+
utils.forEach(['delete', 'get', 'head'], function forEachMethodNoData(method) {
|
|
3371
|
+
defaults.headers[method] = {};
|
|
3372
|
+
});
|
|
3373
|
+
|
|
3374
|
+
utils.forEach(['post', 'put', 'patch'], function forEachMethodWithData(method) {
|
|
3375
|
+
defaults.headers[method] = utils.merge(DEFAULT_CONTENT_TYPE);
|
|
3376
|
+
});
|
|
3377
|
+
|
|
3378
|
+
var defaults_1 = defaults;
|
|
3379
|
+
|
|
3380
|
+
/**
|
|
3381
|
+
* Throws a `Cancel` if cancellation has been requested.
|
|
3382
|
+
*/
|
|
3383
|
+
function throwIfCancellationRequested(config) {
|
|
3384
|
+
if (config.cancelToken) {
|
|
3385
|
+
config.cancelToken.throwIfRequested();
|
|
3386
|
+
}
|
|
3387
|
+
}
|
|
3388
|
+
|
|
3389
|
+
/**
|
|
3390
|
+
* Dispatch a request to the server using the configured adapter.
|
|
3391
|
+
*
|
|
3392
|
+
* @param {object} config The config that is to be used for the request
|
|
3393
|
+
* @returns {Promise} The Promise to be fulfilled
|
|
3394
|
+
*/
|
|
3395
|
+
var dispatchRequest = function dispatchRequest(config) {
|
|
3396
|
+
throwIfCancellationRequested(config);
|
|
3397
|
+
|
|
3398
|
+
// Ensure headers exist
|
|
3399
|
+
config.headers = config.headers || {};
|
|
3400
|
+
|
|
3401
|
+
// Transform request data
|
|
3402
|
+
config.data = transformData(
|
|
3403
|
+
config.data,
|
|
3404
|
+
config.headers,
|
|
3405
|
+
config.transformRequest
|
|
3406
|
+
);
|
|
3407
|
+
|
|
3408
|
+
// Flatten headers
|
|
3409
|
+
config.headers = utils.merge(
|
|
3410
|
+
config.headers.common || {},
|
|
3411
|
+
config.headers[config.method] || {},
|
|
3412
|
+
config.headers
|
|
3413
|
+
);
|
|
3414
|
+
|
|
3415
|
+
utils.forEach(
|
|
3416
|
+
['delete', 'get', 'head', 'post', 'put', 'patch', 'common'],
|
|
3417
|
+
function cleanHeaderConfig(method) {
|
|
3418
|
+
delete config.headers[method];
|
|
3419
|
+
}
|
|
3420
|
+
);
|
|
3421
|
+
|
|
3422
|
+
var adapter = config.adapter || defaults_1.adapter;
|
|
3423
|
+
|
|
3424
|
+
return adapter(config).then(function onAdapterResolution(response) {
|
|
3425
|
+
throwIfCancellationRequested(config);
|
|
3426
|
+
|
|
3427
|
+
// Transform response data
|
|
3428
|
+
response.data = transformData(
|
|
3429
|
+
response.data,
|
|
3430
|
+
response.headers,
|
|
3431
|
+
config.transformResponse
|
|
3432
|
+
);
|
|
3433
|
+
|
|
3434
|
+
return response;
|
|
3435
|
+
}, function onAdapterRejection(reason) {
|
|
3436
|
+
if (!isCancel(reason)) {
|
|
3437
|
+
throwIfCancellationRequested(config);
|
|
3438
|
+
|
|
3439
|
+
// Transform response data
|
|
3440
|
+
if (reason && reason.response) {
|
|
3441
|
+
reason.response.data = transformData(
|
|
3442
|
+
reason.response.data,
|
|
3443
|
+
reason.response.headers,
|
|
3444
|
+
config.transformResponse
|
|
3445
|
+
);
|
|
3446
|
+
}
|
|
3447
|
+
}
|
|
3448
|
+
|
|
3449
|
+
return Promise.reject(reason);
|
|
3450
|
+
});
|
|
3451
|
+
};
|
|
3452
|
+
|
|
3453
|
+
/**
|
|
3454
|
+
* Config-specific merge-function which creates a new config-object
|
|
3455
|
+
* by merging two configuration objects together.
|
|
3456
|
+
*
|
|
3457
|
+
* @param {Object} config1
|
|
3458
|
+
* @param {Object} config2
|
|
3459
|
+
* @returns {Object} New object resulting from merging config2 to config1
|
|
3460
|
+
*/
|
|
3461
|
+
var mergeConfig = function mergeConfig(config1, config2) {
|
|
3462
|
+
// eslint-disable-next-line no-param-reassign
|
|
3463
|
+
config2 = config2 || {};
|
|
3464
|
+
var config = {};
|
|
3465
|
+
|
|
3466
|
+
var valueFromConfig2Keys = ['url', 'method', 'data'];
|
|
3467
|
+
var mergeDeepPropertiesKeys = ['headers', 'auth', 'proxy', 'params'];
|
|
3468
|
+
var defaultToConfig2Keys = [
|
|
3469
|
+
'baseURL', 'transformRequest', 'transformResponse', 'paramsSerializer',
|
|
3470
|
+
'timeout', 'timeoutMessage', 'withCredentials', 'adapter', 'responseType', 'xsrfCookieName',
|
|
3471
|
+
'xsrfHeaderName', 'onUploadProgress', 'onDownloadProgress', 'decompress',
|
|
3472
|
+
'maxContentLength', 'maxBodyLength', 'maxRedirects', 'transport', 'httpAgent',
|
|
3473
|
+
'httpsAgent', 'cancelToken', 'socketPath', 'responseEncoding'
|
|
3474
|
+
];
|
|
3475
|
+
var directMergeKeys = ['validateStatus'];
|
|
3476
|
+
|
|
3477
|
+
function getMergedValue(target, source) {
|
|
3478
|
+
if (utils.isPlainObject(target) && utils.isPlainObject(source)) {
|
|
3479
|
+
return utils.merge(target, source);
|
|
3480
|
+
} else if (utils.isPlainObject(source)) {
|
|
3481
|
+
return utils.merge({}, source);
|
|
3482
|
+
} else if (utils.isArray(source)) {
|
|
3483
|
+
return source.slice();
|
|
3484
|
+
}
|
|
3485
|
+
return source;
|
|
3486
|
+
}
|
|
3487
|
+
|
|
3488
|
+
function mergeDeepProperties(prop) {
|
|
3489
|
+
if (!utils.isUndefined(config2[prop])) {
|
|
3490
|
+
config[prop] = getMergedValue(config1[prop], config2[prop]);
|
|
3491
|
+
} else if (!utils.isUndefined(config1[prop])) {
|
|
3492
|
+
config[prop] = getMergedValue(undefined, config1[prop]);
|
|
3493
|
+
}
|
|
3494
|
+
}
|
|
3495
|
+
|
|
3496
|
+
utils.forEach(valueFromConfig2Keys, function valueFromConfig2(prop) {
|
|
3497
|
+
if (!utils.isUndefined(config2[prop])) {
|
|
3498
|
+
config[prop] = getMergedValue(undefined, config2[prop]);
|
|
3499
|
+
}
|
|
3500
|
+
});
|
|
3501
|
+
|
|
3502
|
+
utils.forEach(mergeDeepPropertiesKeys, mergeDeepProperties);
|
|
3503
|
+
|
|
3504
|
+
utils.forEach(defaultToConfig2Keys, function defaultToConfig2(prop) {
|
|
3505
|
+
if (!utils.isUndefined(config2[prop])) {
|
|
3506
|
+
config[prop] = getMergedValue(undefined, config2[prop]);
|
|
3507
|
+
} else if (!utils.isUndefined(config1[prop])) {
|
|
3508
|
+
config[prop] = getMergedValue(undefined, config1[prop]);
|
|
3509
|
+
}
|
|
3510
|
+
});
|
|
3511
|
+
|
|
3512
|
+
utils.forEach(directMergeKeys, function merge(prop) {
|
|
3513
|
+
if (prop in config2) {
|
|
3514
|
+
config[prop] = getMergedValue(config1[prop], config2[prop]);
|
|
3515
|
+
} else if (prop in config1) {
|
|
3516
|
+
config[prop] = getMergedValue(undefined, config1[prop]);
|
|
3517
|
+
}
|
|
3518
|
+
});
|
|
3519
|
+
|
|
3520
|
+
var axiosKeys = valueFromConfig2Keys
|
|
3521
|
+
.concat(mergeDeepPropertiesKeys)
|
|
3522
|
+
.concat(defaultToConfig2Keys)
|
|
3523
|
+
.concat(directMergeKeys);
|
|
3524
|
+
|
|
3525
|
+
var otherKeys = Object
|
|
3526
|
+
.keys(config1)
|
|
3527
|
+
.concat(Object.keys(config2))
|
|
3528
|
+
.filter(function filterAxiosKeys(key) {
|
|
3529
|
+
return axiosKeys.indexOf(key) === -1;
|
|
3530
|
+
});
|
|
3531
|
+
|
|
3532
|
+
utils.forEach(otherKeys, mergeDeepProperties);
|
|
3533
|
+
|
|
3534
|
+
return config;
|
|
3535
|
+
};
|
|
3536
|
+
|
|
3537
|
+
/**
|
|
3538
|
+
* Create a new instance of Axios
|
|
3539
|
+
*
|
|
3540
|
+
* @param {Object} instanceConfig The default config for the instance
|
|
3541
|
+
*/
|
|
3542
|
+
function Axios(instanceConfig) {
|
|
3543
|
+
this.defaults = instanceConfig;
|
|
3544
|
+
this.interceptors = {
|
|
3545
|
+
request: new InterceptorManager_1(),
|
|
3546
|
+
response: new InterceptorManager_1()
|
|
3547
|
+
};
|
|
3548
|
+
}
|
|
3549
|
+
|
|
3550
|
+
/**
|
|
3551
|
+
* Dispatch a request
|
|
3552
|
+
*
|
|
3553
|
+
* @param {Object} config The config specific for this request (merged with this.defaults)
|
|
3554
|
+
*/
|
|
3555
|
+
Axios.prototype.request = function request(config) {
|
|
3556
|
+
/*eslint no-param-reassign:0*/
|
|
3557
|
+
// Allow for axios('example/url'[, config]) a la fetch API
|
|
3558
|
+
if (typeof config === 'string') {
|
|
3559
|
+
config = arguments[1] || {};
|
|
3560
|
+
config.url = arguments[0];
|
|
3561
|
+
} else {
|
|
3562
|
+
config = config || {};
|
|
3563
|
+
}
|
|
3564
|
+
|
|
3565
|
+
config = mergeConfig(this.defaults, config);
|
|
3566
|
+
|
|
3567
|
+
// Set config.method
|
|
3568
|
+
if (config.method) {
|
|
3569
|
+
config.method = config.method.toLowerCase();
|
|
3570
|
+
} else if (this.defaults.method) {
|
|
3571
|
+
config.method = this.defaults.method.toLowerCase();
|
|
3572
|
+
} else {
|
|
3573
|
+
config.method = 'get';
|
|
3574
|
+
}
|
|
3575
|
+
|
|
3576
|
+
// Hook up interceptors middleware
|
|
3577
|
+
var chain = [dispatchRequest, undefined];
|
|
3578
|
+
var promise = Promise.resolve(config);
|
|
3579
|
+
|
|
3580
|
+
this.interceptors.request.forEach(function unshiftRequestInterceptors(interceptor) {
|
|
3581
|
+
chain.unshift(interceptor.fulfilled, interceptor.rejected);
|
|
3582
|
+
});
|
|
3583
|
+
|
|
3584
|
+
this.interceptors.response.forEach(function pushResponseInterceptors(interceptor) {
|
|
3585
|
+
chain.push(interceptor.fulfilled, interceptor.rejected);
|
|
3586
|
+
});
|
|
3587
|
+
|
|
3588
|
+
while (chain.length) {
|
|
3589
|
+
promise = promise.then(chain.shift(), chain.shift());
|
|
3590
|
+
}
|
|
3591
|
+
|
|
3592
|
+
return promise;
|
|
3593
|
+
};
|
|
3594
|
+
|
|
3595
|
+
Axios.prototype.getUri = function getUri(config) {
|
|
3596
|
+
config = mergeConfig(this.defaults, config);
|
|
3597
|
+
return buildURL(config.url, config.params, config.paramsSerializer).replace(/^\?/, '');
|
|
3598
|
+
};
|
|
3599
|
+
|
|
3600
|
+
// Provide aliases for supported request methods
|
|
3601
|
+
utils.forEach(['delete', 'get', 'head', 'options'], function forEachMethodNoData(method) {
|
|
3602
|
+
/*eslint func-names:0*/
|
|
3603
|
+
Axios.prototype[method] = function(url, config) {
|
|
3604
|
+
return this.request(mergeConfig(config || {}, {
|
|
3605
|
+
method: method,
|
|
3606
|
+
url: url,
|
|
3607
|
+
data: (config || {}).data
|
|
3608
|
+
}));
|
|
3609
|
+
};
|
|
3610
|
+
});
|
|
3611
|
+
|
|
3612
|
+
utils.forEach(['post', 'put', 'patch'], function forEachMethodWithData(method) {
|
|
3613
|
+
/*eslint func-names:0*/
|
|
3614
|
+
Axios.prototype[method] = function(url, data, config) {
|
|
3615
|
+
return this.request(mergeConfig(config || {}, {
|
|
3616
|
+
method: method,
|
|
3617
|
+
url: url,
|
|
3618
|
+
data: data
|
|
3619
|
+
}));
|
|
3620
|
+
};
|
|
3621
|
+
});
|
|
3622
|
+
|
|
3623
|
+
var Axios_1 = Axios;
|
|
3624
|
+
|
|
3625
|
+
/**
|
|
3626
|
+
* A `Cancel` is an object that is thrown when an operation is canceled.
|
|
3627
|
+
*
|
|
3628
|
+
* @class
|
|
3629
|
+
* @param {string=} message The message.
|
|
3630
|
+
*/
|
|
3631
|
+
function Cancel(message) {
|
|
3632
|
+
this.message = message;
|
|
3633
|
+
}
|
|
3634
|
+
|
|
3635
|
+
Cancel.prototype.toString = function toString() {
|
|
3636
|
+
return 'Cancel' + (this.message ? ': ' + this.message : '');
|
|
3637
|
+
};
|
|
3638
|
+
|
|
3639
|
+
Cancel.prototype.__CANCEL__ = true;
|
|
3640
|
+
|
|
3641
|
+
var Cancel_1 = Cancel;
|
|
3642
|
+
|
|
3643
|
+
/**
|
|
3644
|
+
* A `CancelToken` is an object that can be used to request cancellation of an operation.
|
|
3645
|
+
*
|
|
3646
|
+
* @class
|
|
3647
|
+
* @param {Function} executor The executor function.
|
|
3648
|
+
*/
|
|
3649
|
+
function CancelToken(executor) {
|
|
3650
|
+
if (typeof executor !== 'function') {
|
|
3651
|
+
throw new TypeError('executor must be a function.');
|
|
3652
|
+
}
|
|
3653
|
+
|
|
3654
|
+
var resolvePromise;
|
|
3655
|
+
this.promise = new Promise(function promiseExecutor(resolve) {
|
|
3656
|
+
resolvePromise = resolve;
|
|
3657
|
+
});
|
|
3658
|
+
|
|
3659
|
+
var token = this;
|
|
3660
|
+
executor(function cancel(message) {
|
|
3661
|
+
if (token.reason) {
|
|
3662
|
+
// Cancellation has already been requested
|
|
3663
|
+
return;
|
|
3664
|
+
}
|
|
3665
|
+
|
|
3666
|
+
token.reason = new Cancel_1(message);
|
|
3667
|
+
resolvePromise(token.reason);
|
|
3668
|
+
});
|
|
3669
|
+
}
|
|
3670
|
+
|
|
3671
|
+
/**
|
|
3672
|
+
* Throws a `Cancel` if cancellation has been requested.
|
|
3673
|
+
*/
|
|
3674
|
+
CancelToken.prototype.throwIfRequested = function throwIfRequested() {
|
|
3675
|
+
if (this.reason) {
|
|
3676
|
+
throw this.reason;
|
|
3677
|
+
}
|
|
3678
|
+
};
|
|
3679
|
+
|
|
3680
|
+
/**
|
|
3681
|
+
* Returns an object that contains a new `CancelToken` and a function that, when called,
|
|
3682
|
+
* cancels the `CancelToken`.
|
|
3683
|
+
*/
|
|
3684
|
+
CancelToken.source = function source() {
|
|
3685
|
+
var cancel;
|
|
3686
|
+
var token = new CancelToken(function executor(c) {
|
|
3687
|
+
cancel = c;
|
|
3688
|
+
});
|
|
3689
|
+
return {
|
|
3690
|
+
token: token,
|
|
3691
|
+
cancel: cancel
|
|
3692
|
+
};
|
|
3693
|
+
};
|
|
3694
|
+
|
|
3695
|
+
var CancelToken_1 = CancelToken;
|
|
3696
|
+
|
|
3697
|
+
/**
|
|
3698
|
+
* Syntactic sugar for invoking a function and expanding an array for arguments.
|
|
3699
|
+
*
|
|
3700
|
+
* Common use case would be to use `Function.prototype.apply`.
|
|
3701
|
+
*
|
|
3702
|
+
* ```js
|
|
3703
|
+
* function f(x, y, z) {}
|
|
3704
|
+
* var args = [1, 2, 3];
|
|
3705
|
+
* f.apply(null, args);
|
|
3706
|
+
* ```
|
|
3707
|
+
*
|
|
3708
|
+
* With `spread` this example can be re-written.
|
|
3709
|
+
*
|
|
3710
|
+
* ```js
|
|
3711
|
+
* spread(function(x, y, z) {})([1, 2, 3]);
|
|
3712
|
+
* ```
|
|
3713
|
+
*
|
|
3714
|
+
* @param {Function} callback
|
|
3715
|
+
* @returns {Function}
|
|
3716
|
+
*/
|
|
3717
|
+
var spread = function spread(callback) {
|
|
3718
|
+
return function wrap(arr) {
|
|
3719
|
+
return callback.apply(null, arr);
|
|
3720
|
+
};
|
|
3721
|
+
};
|
|
3722
|
+
|
|
3723
|
+
/**
|
|
3724
|
+
* Determines whether the payload is an error thrown by Axios
|
|
3725
|
+
*
|
|
3726
|
+
* @param {*} payload The value to test
|
|
3727
|
+
* @returns {boolean} True if the payload is an error thrown by Axios, otherwise false
|
|
3728
|
+
*/
|
|
3729
|
+
var isAxiosError = function isAxiosError(payload) {
|
|
3730
|
+
return (typeof payload === 'object') && (payload.isAxiosError === true);
|
|
3731
|
+
};
|
|
3732
|
+
|
|
3733
|
+
/**
|
|
3734
|
+
* Create an instance of Axios
|
|
3735
|
+
*
|
|
3736
|
+
* @param {Object} defaultConfig The default config for the instance
|
|
3737
|
+
* @return {Axios} A new instance of Axios
|
|
3738
|
+
*/
|
|
3739
|
+
function createInstance(defaultConfig) {
|
|
3740
|
+
var context = new Axios_1(defaultConfig);
|
|
3741
|
+
var instance = bind(Axios_1.prototype.request, context);
|
|
3742
|
+
|
|
3743
|
+
// Copy axios.prototype to instance
|
|
3744
|
+
utils.extend(instance, Axios_1.prototype, context);
|
|
3745
|
+
|
|
3746
|
+
// Copy context to instance
|
|
3747
|
+
utils.extend(instance, context);
|
|
3748
|
+
|
|
3749
|
+
return instance;
|
|
3750
|
+
}
|
|
3751
|
+
|
|
3752
|
+
// Create the default instance to be exported
|
|
3753
|
+
var axios$1 = createInstance(defaults_1);
|
|
3754
|
+
|
|
3755
|
+
// Expose Axios class to allow class inheritance
|
|
3756
|
+
axios$1.Axios = Axios_1;
|
|
3757
|
+
|
|
3758
|
+
// Factory for creating new instances
|
|
3759
|
+
axios$1.create = function create(instanceConfig) {
|
|
3760
|
+
return createInstance(mergeConfig(axios$1.defaults, instanceConfig));
|
|
3761
|
+
};
|
|
3762
|
+
|
|
3763
|
+
// Expose Cancel & CancelToken
|
|
3764
|
+
axios$1.Cancel = Cancel_1;
|
|
3765
|
+
axios$1.CancelToken = CancelToken_1;
|
|
3766
|
+
axios$1.isCancel = isCancel;
|
|
3767
|
+
|
|
3768
|
+
// Expose all/spread
|
|
3769
|
+
axios$1.all = function all(promises) {
|
|
3770
|
+
return Promise.all(promises);
|
|
3771
|
+
};
|
|
3772
|
+
axios$1.spread = spread;
|
|
3773
|
+
|
|
3774
|
+
// Expose isAxiosError
|
|
3775
|
+
axios$1.isAxiosError = isAxiosError;
|
|
3776
|
+
|
|
3777
|
+
var axios_1 = axios$1;
|
|
3778
|
+
|
|
3779
|
+
// Allow use of default import syntax in TypeScript
|
|
3780
|
+
var _default = axios$1;
|
|
3781
|
+
axios_1.default = _default;
|
|
3782
|
+
|
|
3783
|
+
var axios = axios_1;
|
|
3784
|
+
|
|
3785
|
+
const isFeatureActive = async (feature, options) => {
|
|
3786
|
+
const getFlagByFeatureUrl = `https://lb-central.becollective.com/api/v2/feature-flags/${feature}`;
|
|
3787
|
+
let isFeatureActive = false;
|
|
3788
|
+
const featureFlags = await axios.get(getFlagByFeatureUrl);
|
|
3789
|
+
if (featureFlags && featureFlags.data && featureFlags.data.Environments) {
|
|
3790
|
+
isFeatureActive = featureFlags.data.Environments.includes(options.env);
|
|
3791
|
+
}
|
|
3792
|
+
return isFeatureActive;
|
|
3793
|
+
};
|
|
3794
|
+
|
|
201
3795
|
var util = {
|
|
202
3796
|
getAge: getAge,
|
|
203
3797
|
getCurrencyFromCurrencyCode: getCurrencyFromCurrencyCode,
|
|
@@ -210,6 +3804,7 @@ var util = {
|
|
|
210
3804
|
readableOpportunityType: readableOpportunityType,
|
|
211
3805
|
getTimeInfo: getTimeInfo,
|
|
212
3806
|
getHomeLocalityFromLocationList: getHomeLocalityFromLocationList,
|
|
213
|
-
getShiftText: getShiftText
|
|
3807
|
+
getShiftText: getShiftText,
|
|
3808
|
+
isFeatureActive: isFeatureActive
|
|
214
3809
|
};
|
|
215
3810
|
module.exports = util;
|