scratch-storage 1.3.4 → 2.0.0

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.
@@ -0,0 +1,1906 @@
1
+ /******/ (function(modules) { // webpackBootstrap
2
+ /******/ // The module cache
3
+ /******/ var installedModules = {};
4
+ /******/
5
+ /******/ // The require function
6
+ /******/ function __webpack_require__(moduleId) {
7
+ /******/
8
+ /******/ // Check if module is in cache
9
+ /******/ if(installedModules[moduleId]) {
10
+ /******/ return installedModules[moduleId].exports;
11
+ /******/ }
12
+ /******/ // Create a new module (and put it into the cache)
13
+ /******/ var module = installedModules[moduleId] = {
14
+ /******/ i: moduleId,
15
+ /******/ l: false,
16
+ /******/ exports: {}
17
+ /******/ };
18
+ /******/
19
+ /******/ // Execute the module function
20
+ /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
21
+ /******/
22
+ /******/ // Flag the module as loaded
23
+ /******/ module.l = true;
24
+ /******/
25
+ /******/ // Return the exports of the module
26
+ /******/ return module.exports;
27
+ /******/ }
28
+ /******/
29
+ /******/
30
+ /******/ // expose the modules object (__webpack_modules__)
31
+ /******/ __webpack_require__.m = modules;
32
+ /******/
33
+ /******/ // expose the module cache
34
+ /******/ __webpack_require__.c = installedModules;
35
+ /******/
36
+ /******/ // define getter function for harmony exports
37
+ /******/ __webpack_require__.d = function(exports, name, getter) {
38
+ /******/ if(!__webpack_require__.o(exports, name)) {
39
+ /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
40
+ /******/ }
41
+ /******/ };
42
+ /******/
43
+ /******/ // define __esModule on exports
44
+ /******/ __webpack_require__.r = function(exports) {
45
+ /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
46
+ /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
47
+ /******/ }
48
+ /******/ Object.defineProperty(exports, '__esModule', { value: true });
49
+ /******/ };
50
+ /******/
51
+ /******/ // create a fake namespace object
52
+ /******/ // mode & 1: value is a module id, require it
53
+ /******/ // mode & 2: merge all properties of value into the ns
54
+ /******/ // mode & 4: return value when already ns object
55
+ /******/ // mode & 8|1: behave like require
56
+ /******/ __webpack_require__.t = function(value, mode) {
57
+ /******/ if(mode & 1) value = __webpack_require__(value);
58
+ /******/ if(mode & 8) return value;
59
+ /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
60
+ /******/ var ns = Object.create(null);
61
+ /******/ __webpack_require__.r(ns);
62
+ /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
63
+ /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
64
+ /******/ return ns;
65
+ /******/ };
66
+ /******/
67
+ /******/ // getDefaultExport function for compatibility with non-harmony modules
68
+ /******/ __webpack_require__.n = function(module) {
69
+ /******/ var getter = module && module.__esModule ?
70
+ /******/ function getDefault() { return module['default']; } :
71
+ /******/ function getModuleExports() { return module; };
72
+ /******/ __webpack_require__.d(getter, 'a', getter);
73
+ /******/ return getter;
74
+ /******/ };
75
+ /******/
76
+ /******/ // Object.prototype.hasOwnProperty.call
77
+ /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
78
+ /******/
79
+ /******/ // __webpack_public_path__
80
+ /******/ __webpack_require__.p = "";
81
+ /******/
82
+ /******/
83
+ /******/ // Load entry module and return exports
84
+ /******/ return __webpack_require__(__webpack_require__.s = "./node_modules/babel-loader/lib/index.js?!./src/FetchWorkerTool.worker.js");
85
+ /******/ })
86
+ /************************************************************************/
87
+ /******/ ({
88
+
89
+ /***/ "./node_modules/babel-loader/lib/index.js?!./src/FetchWorkerTool.worker.js":
90
+ /*!*******************************************************************************!*\
91
+ !*** ./node_modules/babel-loader/lib??ref--4!./src/FetchWorkerTool.worker.js ***!
92
+ \*******************************************************************************/
93
+ /*! no static exports found */
94
+ /***/ (function(module, exports, __webpack_require__) {
95
+
96
+ /* WEBPACK VAR INJECTION */(function(fetch) {/* eslint-env worker */
97
+ var jobsActive = 0;
98
+ var complete = [];
99
+ var intervalId = null;
100
+ /**
101
+ * Register a step function.
102
+ *
103
+ * Step checks if there are completed jobs and if there are sends them to the
104
+ * parent. Then it checks the jobs count. If there are no further jobs, clear
105
+ * the step.
106
+ */
107
+
108
+ var registerStep = function registerStep() {
109
+ intervalId = setInterval(function () {
110
+ if (complete.length) {
111
+ // Send our chunk of completed requests and instruct postMessage to
112
+ // transfer the buffers instead of copying them.
113
+ postMessage(complete.slice(), // Instruct postMessage that these buffers in the sent message
114
+ // should use their Transferable trait. After the postMessage
115
+ // call the "buffers" will still be in complete if you looked,
116
+ // but they will all be length 0 as the data they reference has
117
+ // been sent to the window. This lets us send a lot of data
118
+ // without the normal postMessage behaviour of making a copy of
119
+ // all of the data for the window.
120
+ complete.map(function (response) {
121
+ return response.buffer;
122
+ }).filter(Boolean));
123
+ complete.length = 0;
124
+ }
125
+
126
+ if (jobsActive === 0) {
127
+ clearInterval(intervalId);
128
+ intervalId = null;
129
+ }
130
+ }, 1);
131
+ };
132
+ /**
133
+ * Receive a job from the parent and fetch the requested data.
134
+ * @param {object} options.job A job id, url, and options descriptor to perform.
135
+ */
136
+
137
+
138
+ var onMessage = function onMessage(_ref) {
139
+ var job = _ref.data;
140
+
141
+ if (jobsActive === 0 && !intervalId) {
142
+ registerStep();
143
+ }
144
+
145
+ jobsActive++;
146
+ fetch(job.url, job.options).then(function (result) {
147
+ if (result.ok) return result.arrayBuffer();
148
+ if (result.status === 404) return null;
149
+ return Promise.reject(result.status);
150
+ }).then(function (buffer) {
151
+ return complete.push({
152
+ id: job.id,
153
+ buffer: buffer
154
+ });
155
+ }).catch(function (error) {
156
+ return complete.push({
157
+ id: job.id,
158
+ error: error
159
+ });
160
+ }).then(function () {
161
+ return jobsActive--;
162
+ });
163
+ };
164
+
165
+ if (self.fetch) {
166
+ postMessage({
167
+ support: {
168
+ fetch: true
169
+ }
170
+ });
171
+ self.addEventListener('message', onMessage);
172
+ } else {
173
+ postMessage({
174
+ support: {
175
+ fetch: false
176
+ }
177
+ });
178
+ self.addEventListener('message', function (_ref2) {
179
+ var job = _ref2.data;
180
+ postMessage([{
181
+ id: job.id,
182
+ error: new Error('fetch is unavailable')
183
+ }]);
184
+ });
185
+ }
186
+ /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! node-fetch */ "./node_modules/node-fetch/lib/index.mjs")["default"]))
187
+
188
+ /***/ }),
189
+
190
+ /***/ "./node_modules/node-fetch/lib/index.mjs":
191
+ /*!***********************************************!*\
192
+ !*** ./node_modules/node-fetch/lib/index.mjs ***!
193
+ \***********************************************/
194
+ /*! exports provided: default, Headers, Request, Response, FetchError */
195
+ /***/ (function(__webpack_module__, __webpack_exports__, __webpack_require__) {
196
+
197
+ "use strict";
198
+ __webpack_require__.r(__webpack_exports__);
199
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "Headers", function() { return Headers; });
200
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "Request", function() { return Request; });
201
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "Response", function() { return Response; });
202
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "FetchError", function() { return FetchError; });
203
+ /* harmony import */ var stream__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! stream */ "stream");
204
+ /* harmony import */ var http__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! http */ "http");
205
+ /* harmony import */ var url__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! url */ "url");
206
+ /* harmony import */ var https__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! https */ "https");
207
+ /* harmony import */ var zlib__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! zlib */ "zlib");
208
+
209
+
210
+
211
+
212
+
213
+
214
+ // Based on https://github.com/tmpvar/jsdom/blob/aa85b2abf07766ff7bf5c1f6daafb3726f2f2db5/lib/jsdom/living/blob.js
215
+
216
+ // fix for "Readable" isn't a named export issue
217
+ const Readable = stream__WEBPACK_IMPORTED_MODULE_0__.Readable;
218
+
219
+ const BUFFER = Symbol('buffer');
220
+ const TYPE = Symbol('type');
221
+
222
+ class Blob {
223
+ constructor() {
224
+ this[TYPE] = '';
225
+
226
+ const blobParts = arguments[0];
227
+ const options = arguments[1];
228
+
229
+ const buffers = [];
230
+ let size = 0;
231
+
232
+ if (blobParts) {
233
+ const a = blobParts;
234
+ const length = Number(a.length);
235
+ for (let i = 0; i < length; i++) {
236
+ const element = a[i];
237
+ let buffer;
238
+ if (element instanceof Buffer) {
239
+ buffer = element;
240
+ } else if (ArrayBuffer.isView(element)) {
241
+ buffer = Buffer.from(element.buffer, element.byteOffset, element.byteLength);
242
+ } else if (element instanceof ArrayBuffer) {
243
+ buffer = Buffer.from(element);
244
+ } else if (element instanceof Blob) {
245
+ buffer = element[BUFFER];
246
+ } else {
247
+ buffer = Buffer.from(typeof element === 'string' ? element : String(element));
248
+ }
249
+ size += buffer.length;
250
+ buffers.push(buffer);
251
+ }
252
+ }
253
+
254
+ this[BUFFER] = Buffer.concat(buffers);
255
+
256
+ let type = options && options.type !== undefined && String(options.type).toLowerCase();
257
+ if (type && !/[^\u0020-\u007E]/.test(type)) {
258
+ this[TYPE] = type;
259
+ }
260
+ }
261
+ get size() {
262
+ return this[BUFFER].length;
263
+ }
264
+ get type() {
265
+ return this[TYPE];
266
+ }
267
+ text() {
268
+ return Promise.resolve(this[BUFFER].toString());
269
+ }
270
+ arrayBuffer() {
271
+ const buf = this[BUFFER];
272
+ const ab = buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength);
273
+ return Promise.resolve(ab);
274
+ }
275
+ stream() {
276
+ const readable = new Readable();
277
+ readable._read = function () {};
278
+ readable.push(this[BUFFER]);
279
+ readable.push(null);
280
+ return readable;
281
+ }
282
+ toString() {
283
+ return '[object Blob]';
284
+ }
285
+ slice() {
286
+ const size = this.size;
287
+
288
+ const start = arguments[0];
289
+ const end = arguments[1];
290
+ let relativeStart, relativeEnd;
291
+ if (start === undefined) {
292
+ relativeStart = 0;
293
+ } else if (start < 0) {
294
+ relativeStart = Math.max(size + start, 0);
295
+ } else {
296
+ relativeStart = Math.min(start, size);
297
+ }
298
+ if (end === undefined) {
299
+ relativeEnd = size;
300
+ } else if (end < 0) {
301
+ relativeEnd = Math.max(size + end, 0);
302
+ } else {
303
+ relativeEnd = Math.min(end, size);
304
+ }
305
+ const span = Math.max(relativeEnd - relativeStart, 0);
306
+
307
+ const buffer = this[BUFFER];
308
+ const slicedBuffer = buffer.slice(relativeStart, relativeStart + span);
309
+ const blob = new Blob([], { type: arguments[2] });
310
+ blob[BUFFER] = slicedBuffer;
311
+ return blob;
312
+ }
313
+ }
314
+
315
+ Object.defineProperties(Blob.prototype, {
316
+ size: { enumerable: true },
317
+ type: { enumerable: true },
318
+ slice: { enumerable: true }
319
+ });
320
+
321
+ Object.defineProperty(Blob.prototype, Symbol.toStringTag, {
322
+ value: 'Blob',
323
+ writable: false,
324
+ enumerable: false,
325
+ configurable: true
326
+ });
327
+
328
+ /**
329
+ * fetch-error.js
330
+ *
331
+ * FetchError interface for operational errors
332
+ */
333
+
334
+ /**
335
+ * Create FetchError instance
336
+ *
337
+ * @param String message Error message for human
338
+ * @param String type Error type for machine
339
+ * @param String systemError For Node.js system error
340
+ * @return FetchError
341
+ */
342
+ function FetchError(message, type, systemError) {
343
+ Error.call(this, message);
344
+
345
+ this.message = message;
346
+ this.type = type;
347
+
348
+ // when err.type is `system`, err.code contains system error code
349
+ if (systemError) {
350
+ this.code = this.errno = systemError.code;
351
+ }
352
+
353
+ // hide custom error implementation details from end-users
354
+ Error.captureStackTrace(this, this.constructor);
355
+ }
356
+
357
+ FetchError.prototype = Object.create(Error.prototype);
358
+ FetchError.prototype.constructor = FetchError;
359
+ FetchError.prototype.name = 'FetchError';
360
+
361
+ let convert;
362
+ try {
363
+ convert = require('encoding').convert;
364
+ } catch (e) {}
365
+
366
+ const INTERNALS = Symbol('Body internals');
367
+
368
+ // fix an issue where "PassThrough" isn't a named export for node <10
369
+ const PassThrough = stream__WEBPACK_IMPORTED_MODULE_0__.PassThrough;
370
+
371
+ /**
372
+ * Body mixin
373
+ *
374
+ * Ref: https://fetch.spec.whatwg.org/#body
375
+ *
376
+ * @param Stream body Readable stream
377
+ * @param Object opts Response options
378
+ * @return Void
379
+ */
380
+ function Body(body) {
381
+ var _this = this;
382
+
383
+ var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
384
+ _ref$size = _ref.size;
385
+
386
+ let size = _ref$size === undefined ? 0 : _ref$size;
387
+ var _ref$timeout = _ref.timeout;
388
+ let timeout = _ref$timeout === undefined ? 0 : _ref$timeout;
389
+
390
+ if (body == null) {
391
+ // body is undefined or null
392
+ body = null;
393
+ } else if (isURLSearchParams(body)) {
394
+ // body is a URLSearchParams
395
+ body = Buffer.from(body.toString());
396
+ } else if (isBlob(body)) ; else if (Buffer.isBuffer(body)) ; else if (Object.prototype.toString.call(body) === '[object ArrayBuffer]') {
397
+ // body is ArrayBuffer
398
+ body = Buffer.from(body);
399
+ } else if (ArrayBuffer.isView(body)) {
400
+ // body is ArrayBufferView
401
+ body = Buffer.from(body.buffer, body.byteOffset, body.byteLength);
402
+ } else if (body instanceof stream__WEBPACK_IMPORTED_MODULE_0__) ; else {
403
+ // none of the above
404
+ // coerce to string then buffer
405
+ body = Buffer.from(String(body));
406
+ }
407
+ this[INTERNALS] = {
408
+ body,
409
+ disturbed: false,
410
+ error: null
411
+ };
412
+ this.size = size;
413
+ this.timeout = timeout;
414
+
415
+ if (body instanceof stream__WEBPACK_IMPORTED_MODULE_0__) {
416
+ body.on('error', function (err) {
417
+ const error = err.name === 'AbortError' ? err : new FetchError(`Invalid response body while trying to fetch ${_this.url}: ${err.message}`, 'system', err);
418
+ _this[INTERNALS].error = error;
419
+ });
420
+ }
421
+ }
422
+
423
+ Body.prototype = {
424
+ get body() {
425
+ return this[INTERNALS].body;
426
+ },
427
+
428
+ get bodyUsed() {
429
+ return this[INTERNALS].disturbed;
430
+ },
431
+
432
+ /**
433
+ * Decode response as ArrayBuffer
434
+ *
435
+ * @return Promise
436
+ */
437
+ arrayBuffer() {
438
+ return consumeBody.call(this).then(function (buf) {
439
+ return buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength);
440
+ });
441
+ },
442
+
443
+ /**
444
+ * Return raw response as Blob
445
+ *
446
+ * @return Promise
447
+ */
448
+ blob() {
449
+ let ct = this.headers && this.headers.get('content-type') || '';
450
+ return consumeBody.call(this).then(function (buf) {
451
+ return Object.assign(
452
+ // Prevent copying
453
+ new Blob([], {
454
+ type: ct.toLowerCase()
455
+ }), {
456
+ [BUFFER]: buf
457
+ });
458
+ });
459
+ },
460
+
461
+ /**
462
+ * Decode response as json
463
+ *
464
+ * @return Promise
465
+ */
466
+ json() {
467
+ var _this2 = this;
468
+
469
+ return consumeBody.call(this).then(function (buffer) {
470
+ try {
471
+ return JSON.parse(buffer.toString());
472
+ } catch (err) {
473
+ return Body.Promise.reject(new FetchError(`invalid json response body at ${_this2.url} reason: ${err.message}`, 'invalid-json'));
474
+ }
475
+ });
476
+ },
477
+
478
+ /**
479
+ * Decode response as text
480
+ *
481
+ * @return Promise
482
+ */
483
+ text() {
484
+ return consumeBody.call(this).then(function (buffer) {
485
+ return buffer.toString();
486
+ });
487
+ },
488
+
489
+ /**
490
+ * Decode response as buffer (non-spec api)
491
+ *
492
+ * @return Promise
493
+ */
494
+ buffer() {
495
+ return consumeBody.call(this);
496
+ },
497
+
498
+ /**
499
+ * Decode response as text, while automatically detecting the encoding and
500
+ * trying to decode to UTF-8 (non-spec api)
501
+ *
502
+ * @return Promise
503
+ */
504
+ textConverted() {
505
+ var _this3 = this;
506
+
507
+ return consumeBody.call(this).then(function (buffer) {
508
+ return convertBody(buffer, _this3.headers);
509
+ });
510
+ }
511
+ };
512
+
513
+ // In browsers, all properties are enumerable.
514
+ Object.defineProperties(Body.prototype, {
515
+ body: { enumerable: true },
516
+ bodyUsed: { enumerable: true },
517
+ arrayBuffer: { enumerable: true },
518
+ blob: { enumerable: true },
519
+ json: { enumerable: true },
520
+ text: { enumerable: true }
521
+ });
522
+
523
+ Body.mixIn = function (proto) {
524
+ for (const name of Object.getOwnPropertyNames(Body.prototype)) {
525
+ // istanbul ignore else: future proof
526
+ if (!(name in proto)) {
527
+ const desc = Object.getOwnPropertyDescriptor(Body.prototype, name);
528
+ Object.defineProperty(proto, name, desc);
529
+ }
530
+ }
531
+ };
532
+
533
+ /**
534
+ * Consume and convert an entire Body to a Buffer.
535
+ *
536
+ * Ref: https://fetch.spec.whatwg.org/#concept-body-consume-body
537
+ *
538
+ * @return Promise
539
+ */
540
+ function consumeBody() {
541
+ var _this4 = this;
542
+
543
+ if (this[INTERNALS].disturbed) {
544
+ return Body.Promise.reject(new TypeError(`body used already for: ${this.url}`));
545
+ }
546
+
547
+ this[INTERNALS].disturbed = true;
548
+
549
+ if (this[INTERNALS].error) {
550
+ return Body.Promise.reject(this[INTERNALS].error);
551
+ }
552
+
553
+ let body = this.body;
554
+
555
+ // body is null
556
+ if (body === null) {
557
+ return Body.Promise.resolve(Buffer.alloc(0));
558
+ }
559
+
560
+ // body is blob
561
+ if (isBlob(body)) {
562
+ body = body.stream();
563
+ }
564
+
565
+ // body is buffer
566
+ if (Buffer.isBuffer(body)) {
567
+ return Body.Promise.resolve(body);
568
+ }
569
+
570
+ // istanbul ignore if: should never happen
571
+ if (!(body instanceof stream__WEBPACK_IMPORTED_MODULE_0__)) {
572
+ return Body.Promise.resolve(Buffer.alloc(0));
573
+ }
574
+
575
+ // body is stream
576
+ // get ready to actually consume the body
577
+ let accum = [];
578
+ let accumBytes = 0;
579
+ let abort = false;
580
+
581
+ return new Body.Promise(function (resolve, reject) {
582
+ let resTimeout;
583
+
584
+ // allow timeout on slow response body
585
+ if (_this4.timeout) {
586
+ resTimeout = setTimeout(function () {
587
+ abort = true;
588
+ reject(new FetchError(`Response timeout while trying to fetch ${_this4.url} (over ${_this4.timeout}ms)`, 'body-timeout'));
589
+ }, _this4.timeout);
590
+ }
591
+
592
+ // handle stream errors
593
+ body.on('error', function (err) {
594
+ if (err.name === 'AbortError') {
595
+ // if the request was aborted, reject with this Error
596
+ abort = true;
597
+ reject(err);
598
+ } else {
599
+ // other errors, such as incorrect content-encoding
600
+ reject(new FetchError(`Invalid response body while trying to fetch ${_this4.url}: ${err.message}`, 'system', err));
601
+ }
602
+ });
603
+
604
+ body.on('data', function (chunk) {
605
+ if (abort || chunk === null) {
606
+ return;
607
+ }
608
+
609
+ if (_this4.size && accumBytes + chunk.length > _this4.size) {
610
+ abort = true;
611
+ reject(new FetchError(`content size at ${_this4.url} over limit: ${_this4.size}`, 'max-size'));
612
+ return;
613
+ }
614
+
615
+ accumBytes += chunk.length;
616
+ accum.push(chunk);
617
+ });
618
+
619
+ body.on('end', function () {
620
+ if (abort) {
621
+ return;
622
+ }
623
+
624
+ clearTimeout(resTimeout);
625
+
626
+ try {
627
+ resolve(Buffer.concat(accum, accumBytes));
628
+ } catch (err) {
629
+ // handle streams that have accumulated too much data (issue #414)
630
+ reject(new FetchError(`Could not create Buffer from response body for ${_this4.url}: ${err.message}`, 'system', err));
631
+ }
632
+ });
633
+ });
634
+ }
635
+
636
+ /**
637
+ * Detect buffer encoding and convert to target encoding
638
+ * ref: http://www.w3.org/TR/2011/WD-html5-20110113/parsing.html#determining-the-character-encoding
639
+ *
640
+ * @param Buffer buffer Incoming buffer
641
+ * @param String encoding Target encoding
642
+ * @return String
643
+ */
644
+ function convertBody(buffer, headers) {
645
+ if (typeof convert !== 'function') {
646
+ throw new Error('The package `encoding` must be installed to use the textConverted() function');
647
+ }
648
+
649
+ const ct = headers.get('content-type');
650
+ let charset = 'utf-8';
651
+ let res, str;
652
+
653
+ // header
654
+ if (ct) {
655
+ res = /charset=([^;]*)/i.exec(ct);
656
+ }
657
+
658
+ // no charset in content type, peek at response body for at most 1024 bytes
659
+ str = buffer.slice(0, 1024).toString();
660
+
661
+ // html5
662
+ if (!res && str) {
663
+ res = /<meta.+?charset=(['"])(.+?)\1/i.exec(str);
664
+ }
665
+
666
+ // html4
667
+ if (!res && str) {
668
+ res = /<meta[\s]+?http-equiv=(['"])content-type\1[\s]+?content=(['"])(.+?)\2/i.exec(str);
669
+ if (!res) {
670
+ res = /<meta[\s]+?content=(['"])(.+?)\1[\s]+?http-equiv=(['"])content-type\3/i.exec(str);
671
+ if (res) {
672
+ res.pop(); // drop last quote
673
+ }
674
+ }
675
+
676
+ if (res) {
677
+ res = /charset=(.*)/i.exec(res.pop());
678
+ }
679
+ }
680
+
681
+ // xml
682
+ if (!res && str) {
683
+ res = /<\?xml.+?encoding=(['"])(.+?)\1/i.exec(str);
684
+ }
685
+
686
+ // found charset
687
+ if (res) {
688
+ charset = res.pop();
689
+
690
+ // prevent decode issues when sites use incorrect encoding
691
+ // ref: https://hsivonen.fi/encoding-menu/
692
+ if (charset === 'gb2312' || charset === 'gbk') {
693
+ charset = 'gb18030';
694
+ }
695
+ }
696
+
697
+ // turn raw buffers into a single utf-8 buffer
698
+ return convert(buffer, 'UTF-8', charset).toString();
699
+ }
700
+
701
+ /**
702
+ * Detect a URLSearchParams object
703
+ * ref: https://github.com/bitinn/node-fetch/issues/296#issuecomment-307598143
704
+ *
705
+ * @param Object obj Object to detect by type or brand
706
+ * @return String
707
+ */
708
+ function isURLSearchParams(obj) {
709
+ // Duck-typing as a necessary condition.
710
+ if (typeof obj !== 'object' || typeof obj.append !== 'function' || typeof obj.delete !== 'function' || typeof obj.get !== 'function' || typeof obj.getAll !== 'function' || typeof obj.has !== 'function' || typeof obj.set !== 'function') {
711
+ return false;
712
+ }
713
+
714
+ // Brand-checking and more duck-typing as optional condition.
715
+ return obj.constructor.name === 'URLSearchParams' || Object.prototype.toString.call(obj) === '[object URLSearchParams]' || typeof obj.sort === 'function';
716
+ }
717
+
718
+ /**
719
+ * Check if `obj` is a W3C `Blob` object (which `File` inherits from)
720
+ * @param {*} obj
721
+ * @return {boolean}
722
+ */
723
+ function isBlob(obj) {
724
+ return typeof obj === 'object' && typeof obj.arrayBuffer === 'function' && typeof obj.type === 'string' && typeof obj.stream === 'function' && typeof obj.constructor === 'function' && typeof obj.constructor.name === 'string' && /^(Blob|File)$/.test(obj.constructor.name) && /^(Blob|File)$/.test(obj[Symbol.toStringTag]);
725
+ }
726
+
727
+ /**
728
+ * Clone body given Res/Req instance
729
+ *
730
+ * @param Mixed instance Response or Request instance
731
+ * @return Mixed
732
+ */
733
+ function clone(instance) {
734
+ let p1, p2;
735
+ let body = instance.body;
736
+
737
+ // don't allow cloning a used body
738
+ if (instance.bodyUsed) {
739
+ throw new Error('cannot clone body after it is used');
740
+ }
741
+
742
+ // check that body is a stream and not form-data object
743
+ // note: we can't clone the form-data object without having it as a dependency
744
+ if (body instanceof stream__WEBPACK_IMPORTED_MODULE_0__ && typeof body.getBoundary !== 'function') {
745
+ // tee instance body
746
+ p1 = new PassThrough();
747
+ p2 = new PassThrough();
748
+ body.pipe(p1);
749
+ body.pipe(p2);
750
+ // set instance body to teed body and return the other teed body
751
+ instance[INTERNALS].body = p1;
752
+ body = p2;
753
+ }
754
+
755
+ return body;
756
+ }
757
+
758
+ /**
759
+ * Performs the operation "extract a `Content-Type` value from |object|" as
760
+ * specified in the specification:
761
+ * https://fetch.spec.whatwg.org/#concept-bodyinit-extract
762
+ *
763
+ * This function assumes that instance.body is present.
764
+ *
765
+ * @param Mixed instance Any options.body input
766
+ */
767
+ function extractContentType(body) {
768
+ if (body === null) {
769
+ // body is null
770
+ return null;
771
+ } else if (typeof body === 'string') {
772
+ // body is string
773
+ return 'text/plain;charset=UTF-8';
774
+ } else if (isURLSearchParams(body)) {
775
+ // body is a URLSearchParams
776
+ return 'application/x-www-form-urlencoded;charset=UTF-8';
777
+ } else if (isBlob(body)) {
778
+ // body is blob
779
+ return body.type || null;
780
+ } else if (Buffer.isBuffer(body)) {
781
+ // body is buffer
782
+ return null;
783
+ } else if (Object.prototype.toString.call(body) === '[object ArrayBuffer]') {
784
+ // body is ArrayBuffer
785
+ return null;
786
+ } else if (ArrayBuffer.isView(body)) {
787
+ // body is ArrayBufferView
788
+ return null;
789
+ } else if (typeof body.getBoundary === 'function') {
790
+ // detect form data input from form-data module
791
+ return `multipart/form-data;boundary=${body.getBoundary()}`;
792
+ } else if (body instanceof stream__WEBPACK_IMPORTED_MODULE_0__) {
793
+ // body is stream
794
+ // can't really do much about this
795
+ return null;
796
+ } else {
797
+ // Body constructor defaults other things to string
798
+ return 'text/plain;charset=UTF-8';
799
+ }
800
+ }
801
+
802
+ /**
803
+ * The Fetch Standard treats this as if "total bytes" is a property on the body.
804
+ * For us, we have to explicitly get it with a function.
805
+ *
806
+ * ref: https://fetch.spec.whatwg.org/#concept-body-total-bytes
807
+ *
808
+ * @param Body instance Instance of Body
809
+ * @return Number? Number of bytes, or null if not possible
810
+ */
811
+ function getTotalBytes(instance) {
812
+ const body = instance.body;
813
+
814
+
815
+ if (body === null) {
816
+ // body is null
817
+ return 0;
818
+ } else if (isBlob(body)) {
819
+ return body.size;
820
+ } else if (Buffer.isBuffer(body)) {
821
+ // body is buffer
822
+ return body.length;
823
+ } else if (body && typeof body.getLengthSync === 'function') {
824
+ // detect form data input from form-data module
825
+ if (body._lengthRetrievers && body._lengthRetrievers.length == 0 || // 1.x
826
+ body.hasKnownLength && body.hasKnownLength()) {
827
+ // 2.x
828
+ return body.getLengthSync();
829
+ }
830
+ return null;
831
+ } else {
832
+ // body is stream
833
+ return null;
834
+ }
835
+ }
836
+
837
+ /**
838
+ * Write a Body to a Node.js WritableStream (e.g. http.Request) object.
839
+ *
840
+ * @param Body instance Instance of Body
841
+ * @return Void
842
+ */
843
+ function writeToStream(dest, instance) {
844
+ const body = instance.body;
845
+
846
+
847
+ if (body === null) {
848
+ // body is null
849
+ dest.end();
850
+ } else if (isBlob(body)) {
851
+ body.stream().pipe(dest);
852
+ } else if (Buffer.isBuffer(body)) {
853
+ // body is buffer
854
+ dest.write(body);
855
+ dest.end();
856
+ } else {
857
+ // body is stream
858
+ body.pipe(dest);
859
+ }
860
+ }
861
+
862
+ // expose Promise
863
+ Body.Promise = global.Promise;
864
+
865
+ /**
866
+ * headers.js
867
+ *
868
+ * Headers class offers convenient helpers
869
+ */
870
+
871
+ const invalidTokenRegex = /[^\^_`a-zA-Z\-0-9!#$%&'*+.|~]/;
872
+ const invalidHeaderCharRegex = /[^\t\x20-\x7e\x80-\xff]/;
873
+
874
+ function validateName(name) {
875
+ name = `${name}`;
876
+ if (invalidTokenRegex.test(name) || name === '') {
877
+ throw new TypeError(`${name} is not a legal HTTP header name`);
878
+ }
879
+ }
880
+
881
+ function validateValue(value) {
882
+ value = `${value}`;
883
+ if (invalidHeaderCharRegex.test(value)) {
884
+ throw new TypeError(`${value} is not a legal HTTP header value`);
885
+ }
886
+ }
887
+
888
+ /**
889
+ * Find the key in the map object given a header name.
890
+ *
891
+ * Returns undefined if not found.
892
+ *
893
+ * @param String name Header name
894
+ * @return String|Undefined
895
+ */
896
+ function find(map, name) {
897
+ name = name.toLowerCase();
898
+ for (const key in map) {
899
+ if (key.toLowerCase() === name) {
900
+ return key;
901
+ }
902
+ }
903
+ return undefined;
904
+ }
905
+
906
+ const MAP = Symbol('map');
907
+ class Headers {
908
+ /**
909
+ * Headers class
910
+ *
911
+ * @param Object headers Response headers
912
+ * @return Void
913
+ */
914
+ constructor() {
915
+ let init = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : undefined;
916
+
917
+ this[MAP] = Object.create(null);
918
+
919
+ if (init instanceof Headers) {
920
+ const rawHeaders = init.raw();
921
+ const headerNames = Object.keys(rawHeaders);
922
+
923
+ for (const headerName of headerNames) {
924
+ for (const value of rawHeaders[headerName]) {
925
+ this.append(headerName, value);
926
+ }
927
+ }
928
+
929
+ return;
930
+ }
931
+
932
+ // We don't worry about converting prop to ByteString here as append()
933
+ // will handle it.
934
+ if (init == null) ; else if (typeof init === 'object') {
935
+ const method = init[Symbol.iterator];
936
+ if (method != null) {
937
+ if (typeof method !== 'function') {
938
+ throw new TypeError('Header pairs must be iterable');
939
+ }
940
+
941
+ // sequence<sequence<ByteString>>
942
+ // Note: per spec we have to first exhaust the lists then process them
943
+ const pairs = [];
944
+ for (const pair of init) {
945
+ if (typeof pair !== 'object' || typeof pair[Symbol.iterator] !== 'function') {
946
+ throw new TypeError('Each header pair must be iterable');
947
+ }
948
+ pairs.push(Array.from(pair));
949
+ }
950
+
951
+ for (const pair of pairs) {
952
+ if (pair.length !== 2) {
953
+ throw new TypeError('Each header pair must be a name/value tuple');
954
+ }
955
+ this.append(pair[0], pair[1]);
956
+ }
957
+ } else {
958
+ // record<ByteString, ByteString>
959
+ for (const key of Object.keys(init)) {
960
+ const value = init[key];
961
+ this.append(key, value);
962
+ }
963
+ }
964
+ } else {
965
+ throw new TypeError('Provided initializer must be an object');
966
+ }
967
+ }
968
+
969
+ /**
970
+ * Return combined header value given name
971
+ *
972
+ * @param String name Header name
973
+ * @return Mixed
974
+ */
975
+ get(name) {
976
+ name = `${name}`;
977
+ validateName(name);
978
+ const key = find(this[MAP], name);
979
+ if (key === undefined) {
980
+ return null;
981
+ }
982
+
983
+ return this[MAP][key].join(', ');
984
+ }
985
+
986
+ /**
987
+ * Iterate over all headers
988
+ *
989
+ * @param Function callback Executed for each item with parameters (value, name, thisArg)
990
+ * @param Boolean thisArg `this` context for callback function
991
+ * @return Void
992
+ */
993
+ forEach(callback) {
994
+ let thisArg = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined;
995
+
996
+ let pairs = getHeaders(this);
997
+ let i = 0;
998
+ while (i < pairs.length) {
999
+ var _pairs$i = pairs[i];
1000
+ const name = _pairs$i[0],
1001
+ value = _pairs$i[1];
1002
+
1003
+ callback.call(thisArg, value, name, this);
1004
+ pairs = getHeaders(this);
1005
+ i++;
1006
+ }
1007
+ }
1008
+
1009
+ /**
1010
+ * Overwrite header values given name
1011
+ *
1012
+ * @param String name Header name
1013
+ * @param String value Header value
1014
+ * @return Void
1015
+ */
1016
+ set(name, value) {
1017
+ name = `${name}`;
1018
+ value = `${value}`;
1019
+ validateName(name);
1020
+ validateValue(value);
1021
+ const key = find(this[MAP], name);
1022
+ this[MAP][key !== undefined ? key : name] = [value];
1023
+ }
1024
+
1025
+ /**
1026
+ * Append a value onto existing header
1027
+ *
1028
+ * @param String name Header name
1029
+ * @param String value Header value
1030
+ * @return Void
1031
+ */
1032
+ append(name, value) {
1033
+ name = `${name}`;
1034
+ value = `${value}`;
1035
+ validateName(name);
1036
+ validateValue(value);
1037
+ const key = find(this[MAP], name);
1038
+ if (key !== undefined) {
1039
+ this[MAP][key].push(value);
1040
+ } else {
1041
+ this[MAP][name] = [value];
1042
+ }
1043
+ }
1044
+
1045
+ /**
1046
+ * Check for header name existence
1047
+ *
1048
+ * @param String name Header name
1049
+ * @return Boolean
1050
+ */
1051
+ has(name) {
1052
+ name = `${name}`;
1053
+ validateName(name);
1054
+ return find(this[MAP], name) !== undefined;
1055
+ }
1056
+
1057
+ /**
1058
+ * Delete all header values given name
1059
+ *
1060
+ * @param String name Header name
1061
+ * @return Void
1062
+ */
1063
+ delete(name) {
1064
+ name = `${name}`;
1065
+ validateName(name);
1066
+ const key = find(this[MAP], name);
1067
+ if (key !== undefined) {
1068
+ delete this[MAP][key];
1069
+ }
1070
+ }
1071
+
1072
+ /**
1073
+ * Return raw headers (non-spec api)
1074
+ *
1075
+ * @return Object
1076
+ */
1077
+ raw() {
1078
+ return this[MAP];
1079
+ }
1080
+
1081
+ /**
1082
+ * Get an iterator on keys.
1083
+ *
1084
+ * @return Iterator
1085
+ */
1086
+ keys() {
1087
+ return createHeadersIterator(this, 'key');
1088
+ }
1089
+
1090
+ /**
1091
+ * Get an iterator on values.
1092
+ *
1093
+ * @return Iterator
1094
+ */
1095
+ values() {
1096
+ return createHeadersIterator(this, 'value');
1097
+ }
1098
+
1099
+ /**
1100
+ * Get an iterator on entries.
1101
+ *
1102
+ * This is the default iterator of the Headers object.
1103
+ *
1104
+ * @return Iterator
1105
+ */
1106
+ [Symbol.iterator]() {
1107
+ return createHeadersIterator(this, 'key+value');
1108
+ }
1109
+ }
1110
+ Headers.prototype.entries = Headers.prototype[Symbol.iterator];
1111
+
1112
+ Object.defineProperty(Headers.prototype, Symbol.toStringTag, {
1113
+ value: 'Headers',
1114
+ writable: false,
1115
+ enumerable: false,
1116
+ configurable: true
1117
+ });
1118
+
1119
+ Object.defineProperties(Headers.prototype, {
1120
+ get: { enumerable: true },
1121
+ forEach: { enumerable: true },
1122
+ set: { enumerable: true },
1123
+ append: { enumerable: true },
1124
+ has: { enumerable: true },
1125
+ delete: { enumerable: true },
1126
+ keys: { enumerable: true },
1127
+ values: { enumerable: true },
1128
+ entries: { enumerable: true }
1129
+ });
1130
+
1131
+ function getHeaders(headers) {
1132
+ let kind = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'key+value';
1133
+
1134
+ const keys = Object.keys(headers[MAP]).sort();
1135
+ return keys.map(kind === 'key' ? function (k) {
1136
+ return k.toLowerCase();
1137
+ } : kind === 'value' ? function (k) {
1138
+ return headers[MAP][k].join(', ');
1139
+ } : function (k) {
1140
+ return [k.toLowerCase(), headers[MAP][k].join(', ')];
1141
+ });
1142
+ }
1143
+
1144
+ const INTERNAL = Symbol('internal');
1145
+
1146
+ function createHeadersIterator(target, kind) {
1147
+ const iterator = Object.create(HeadersIteratorPrototype);
1148
+ iterator[INTERNAL] = {
1149
+ target,
1150
+ kind,
1151
+ index: 0
1152
+ };
1153
+ return iterator;
1154
+ }
1155
+
1156
+ const HeadersIteratorPrototype = Object.setPrototypeOf({
1157
+ next() {
1158
+ // istanbul ignore if
1159
+ if (!this || Object.getPrototypeOf(this) !== HeadersIteratorPrototype) {
1160
+ throw new TypeError('Value of `this` is not a HeadersIterator');
1161
+ }
1162
+
1163
+ var _INTERNAL = this[INTERNAL];
1164
+ const target = _INTERNAL.target,
1165
+ kind = _INTERNAL.kind,
1166
+ index = _INTERNAL.index;
1167
+
1168
+ const values = getHeaders(target, kind);
1169
+ const len = values.length;
1170
+ if (index >= len) {
1171
+ return {
1172
+ value: undefined,
1173
+ done: true
1174
+ };
1175
+ }
1176
+
1177
+ this[INTERNAL].index = index + 1;
1178
+
1179
+ return {
1180
+ value: values[index],
1181
+ done: false
1182
+ };
1183
+ }
1184
+ }, Object.getPrototypeOf(Object.getPrototypeOf([][Symbol.iterator]())));
1185
+
1186
+ Object.defineProperty(HeadersIteratorPrototype, Symbol.toStringTag, {
1187
+ value: 'HeadersIterator',
1188
+ writable: false,
1189
+ enumerable: false,
1190
+ configurable: true
1191
+ });
1192
+
1193
+ /**
1194
+ * Export the Headers object in a form that Node.js can consume.
1195
+ *
1196
+ * @param Headers headers
1197
+ * @return Object
1198
+ */
1199
+ function exportNodeCompatibleHeaders(headers) {
1200
+ const obj = Object.assign({ __proto__: null }, headers[MAP]);
1201
+
1202
+ // http.request() only supports string as Host header. This hack makes
1203
+ // specifying custom Host header possible.
1204
+ const hostHeaderKey = find(headers[MAP], 'Host');
1205
+ if (hostHeaderKey !== undefined) {
1206
+ obj[hostHeaderKey] = obj[hostHeaderKey][0];
1207
+ }
1208
+
1209
+ return obj;
1210
+ }
1211
+
1212
+ /**
1213
+ * Create a Headers object from an object of headers, ignoring those that do
1214
+ * not conform to HTTP grammar productions.
1215
+ *
1216
+ * @param Object obj Object of headers
1217
+ * @return Headers
1218
+ */
1219
+ function createHeadersLenient(obj) {
1220
+ const headers = new Headers();
1221
+ for (const name of Object.keys(obj)) {
1222
+ if (invalidTokenRegex.test(name)) {
1223
+ continue;
1224
+ }
1225
+ if (Array.isArray(obj[name])) {
1226
+ for (const val of obj[name]) {
1227
+ if (invalidHeaderCharRegex.test(val)) {
1228
+ continue;
1229
+ }
1230
+ if (headers[MAP][name] === undefined) {
1231
+ headers[MAP][name] = [val];
1232
+ } else {
1233
+ headers[MAP][name].push(val);
1234
+ }
1235
+ }
1236
+ } else if (!invalidHeaderCharRegex.test(obj[name])) {
1237
+ headers[MAP][name] = [obj[name]];
1238
+ }
1239
+ }
1240
+ return headers;
1241
+ }
1242
+
1243
+ const INTERNALS$1 = Symbol('Response internals');
1244
+
1245
+ // fix an issue where "STATUS_CODES" aren't a named export for node <10
1246
+ const STATUS_CODES = http__WEBPACK_IMPORTED_MODULE_1__.STATUS_CODES;
1247
+
1248
+ /**
1249
+ * Response class
1250
+ *
1251
+ * @param Stream body Readable stream
1252
+ * @param Object opts Response options
1253
+ * @return Void
1254
+ */
1255
+ class Response {
1256
+ constructor() {
1257
+ let body = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
1258
+ let opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1259
+
1260
+ Body.call(this, body, opts);
1261
+
1262
+ const status = opts.status || 200;
1263
+ const headers = new Headers(opts.headers);
1264
+
1265
+ if (body != null && !headers.has('Content-Type')) {
1266
+ const contentType = extractContentType(body);
1267
+ if (contentType) {
1268
+ headers.append('Content-Type', contentType);
1269
+ }
1270
+ }
1271
+
1272
+ this[INTERNALS$1] = {
1273
+ url: opts.url,
1274
+ status,
1275
+ statusText: opts.statusText || STATUS_CODES[status],
1276
+ headers,
1277
+ counter: opts.counter
1278
+ };
1279
+ }
1280
+
1281
+ get url() {
1282
+ return this[INTERNALS$1].url || '';
1283
+ }
1284
+
1285
+ get status() {
1286
+ return this[INTERNALS$1].status;
1287
+ }
1288
+
1289
+ /**
1290
+ * Convenience property representing if the request ended normally
1291
+ */
1292
+ get ok() {
1293
+ return this[INTERNALS$1].status >= 200 && this[INTERNALS$1].status < 300;
1294
+ }
1295
+
1296
+ get redirected() {
1297
+ return this[INTERNALS$1].counter > 0;
1298
+ }
1299
+
1300
+ get statusText() {
1301
+ return this[INTERNALS$1].statusText;
1302
+ }
1303
+
1304
+ get headers() {
1305
+ return this[INTERNALS$1].headers;
1306
+ }
1307
+
1308
+ /**
1309
+ * Clone this response
1310
+ *
1311
+ * @return Response
1312
+ */
1313
+ clone() {
1314
+ return new Response(clone(this), {
1315
+ url: this.url,
1316
+ status: this.status,
1317
+ statusText: this.statusText,
1318
+ headers: this.headers,
1319
+ ok: this.ok,
1320
+ redirected: this.redirected
1321
+ });
1322
+ }
1323
+ }
1324
+
1325
+ Body.mixIn(Response.prototype);
1326
+
1327
+ Object.defineProperties(Response.prototype, {
1328
+ url: { enumerable: true },
1329
+ status: { enumerable: true },
1330
+ ok: { enumerable: true },
1331
+ redirected: { enumerable: true },
1332
+ statusText: { enumerable: true },
1333
+ headers: { enumerable: true },
1334
+ clone: { enumerable: true }
1335
+ });
1336
+
1337
+ Object.defineProperty(Response.prototype, Symbol.toStringTag, {
1338
+ value: 'Response',
1339
+ writable: false,
1340
+ enumerable: false,
1341
+ configurable: true
1342
+ });
1343
+
1344
+ const INTERNALS$2 = Symbol('Request internals');
1345
+
1346
+ // fix an issue where "format", "parse" aren't a named export for node <10
1347
+ const parse_url = url__WEBPACK_IMPORTED_MODULE_2__.parse;
1348
+ const format_url = url__WEBPACK_IMPORTED_MODULE_2__.format;
1349
+
1350
+ const streamDestructionSupported = 'destroy' in stream__WEBPACK_IMPORTED_MODULE_0__.Readable.prototype;
1351
+
1352
+ /**
1353
+ * Check if a value is an instance of Request.
1354
+ *
1355
+ * @param Mixed input
1356
+ * @return Boolean
1357
+ */
1358
+ function isRequest(input) {
1359
+ return typeof input === 'object' && typeof input[INTERNALS$2] === 'object';
1360
+ }
1361
+
1362
+ function isAbortSignal(signal) {
1363
+ const proto = signal && typeof signal === 'object' && Object.getPrototypeOf(signal);
1364
+ return !!(proto && proto.constructor.name === 'AbortSignal');
1365
+ }
1366
+
1367
+ /**
1368
+ * Request class
1369
+ *
1370
+ * @param Mixed input Url or Request instance
1371
+ * @param Object init Custom options
1372
+ * @return Void
1373
+ */
1374
+ class Request {
1375
+ constructor(input) {
1376
+ let init = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1377
+
1378
+ let parsedURL;
1379
+
1380
+ // normalize input
1381
+ if (!isRequest(input)) {
1382
+ if (input && input.href) {
1383
+ // in order to support Node.js' Url objects; though WHATWG's URL objects
1384
+ // will fall into this branch also (since their `toString()` will return
1385
+ // `href` property anyway)
1386
+ parsedURL = parse_url(input.href);
1387
+ } else {
1388
+ // coerce input to a string before attempting to parse
1389
+ parsedURL = parse_url(`${input}`);
1390
+ }
1391
+ input = {};
1392
+ } else {
1393
+ parsedURL = parse_url(input.url);
1394
+ }
1395
+
1396
+ let method = init.method || input.method || 'GET';
1397
+ method = method.toUpperCase();
1398
+
1399
+ if ((init.body != null || isRequest(input) && input.body !== null) && (method === 'GET' || method === 'HEAD')) {
1400
+ throw new TypeError('Request with GET/HEAD method cannot have body');
1401
+ }
1402
+
1403
+ let inputBody = init.body != null ? init.body : isRequest(input) && input.body !== null ? clone(input) : null;
1404
+
1405
+ Body.call(this, inputBody, {
1406
+ timeout: init.timeout || input.timeout || 0,
1407
+ size: init.size || input.size || 0
1408
+ });
1409
+
1410
+ const headers = new Headers(init.headers || input.headers || {});
1411
+
1412
+ if (inputBody != null && !headers.has('Content-Type')) {
1413
+ const contentType = extractContentType(inputBody);
1414
+ if (contentType) {
1415
+ headers.append('Content-Type', contentType);
1416
+ }
1417
+ }
1418
+
1419
+ let signal = isRequest(input) ? input.signal : null;
1420
+ if ('signal' in init) signal = init.signal;
1421
+
1422
+ if (signal != null && !isAbortSignal(signal)) {
1423
+ throw new TypeError('Expected signal to be an instanceof AbortSignal');
1424
+ }
1425
+
1426
+ this[INTERNALS$2] = {
1427
+ method,
1428
+ redirect: init.redirect || input.redirect || 'follow',
1429
+ headers,
1430
+ parsedURL,
1431
+ signal
1432
+ };
1433
+
1434
+ // node-fetch-only options
1435
+ this.follow = init.follow !== undefined ? init.follow : input.follow !== undefined ? input.follow : 20;
1436
+ this.compress = init.compress !== undefined ? init.compress : input.compress !== undefined ? input.compress : true;
1437
+ this.counter = init.counter || input.counter || 0;
1438
+ this.agent = init.agent || input.agent;
1439
+ }
1440
+
1441
+ get method() {
1442
+ return this[INTERNALS$2].method;
1443
+ }
1444
+
1445
+ get url() {
1446
+ return format_url(this[INTERNALS$2].parsedURL);
1447
+ }
1448
+
1449
+ get headers() {
1450
+ return this[INTERNALS$2].headers;
1451
+ }
1452
+
1453
+ get redirect() {
1454
+ return this[INTERNALS$2].redirect;
1455
+ }
1456
+
1457
+ get signal() {
1458
+ return this[INTERNALS$2].signal;
1459
+ }
1460
+
1461
+ /**
1462
+ * Clone this request
1463
+ *
1464
+ * @return Request
1465
+ */
1466
+ clone() {
1467
+ return new Request(this);
1468
+ }
1469
+ }
1470
+
1471
+ Body.mixIn(Request.prototype);
1472
+
1473
+ Object.defineProperty(Request.prototype, Symbol.toStringTag, {
1474
+ value: 'Request',
1475
+ writable: false,
1476
+ enumerable: false,
1477
+ configurable: true
1478
+ });
1479
+
1480
+ Object.defineProperties(Request.prototype, {
1481
+ method: { enumerable: true },
1482
+ url: { enumerable: true },
1483
+ headers: { enumerable: true },
1484
+ redirect: { enumerable: true },
1485
+ clone: { enumerable: true },
1486
+ signal: { enumerable: true }
1487
+ });
1488
+
1489
+ /**
1490
+ * Convert a Request to Node.js http request options.
1491
+ *
1492
+ * @param Request A Request instance
1493
+ * @return Object The options object to be passed to http.request
1494
+ */
1495
+ function getNodeRequestOptions(request) {
1496
+ const parsedURL = request[INTERNALS$2].parsedURL;
1497
+ const headers = new Headers(request[INTERNALS$2].headers);
1498
+
1499
+ // fetch step 1.3
1500
+ if (!headers.has('Accept')) {
1501
+ headers.set('Accept', '*/*');
1502
+ }
1503
+
1504
+ // Basic fetch
1505
+ if (!parsedURL.protocol || !parsedURL.hostname) {
1506
+ throw new TypeError('Only absolute URLs are supported');
1507
+ }
1508
+
1509
+ if (!/^https?:$/.test(parsedURL.protocol)) {
1510
+ throw new TypeError('Only HTTP(S) protocols are supported');
1511
+ }
1512
+
1513
+ if (request.signal && request.body instanceof stream__WEBPACK_IMPORTED_MODULE_0__.Readable && !streamDestructionSupported) {
1514
+ throw new Error('Cancellation of streamed requests with AbortSignal is not supported in node < 8');
1515
+ }
1516
+
1517
+ // HTTP-network-or-cache fetch steps 2.4-2.7
1518
+ let contentLengthValue = null;
1519
+ if (request.body == null && /^(POST|PUT)$/i.test(request.method)) {
1520
+ contentLengthValue = '0';
1521
+ }
1522
+ if (request.body != null) {
1523
+ const totalBytes = getTotalBytes(request);
1524
+ if (typeof totalBytes === 'number') {
1525
+ contentLengthValue = String(totalBytes);
1526
+ }
1527
+ }
1528
+ if (contentLengthValue) {
1529
+ headers.set('Content-Length', contentLengthValue);
1530
+ }
1531
+
1532
+ // HTTP-network-or-cache fetch step 2.11
1533
+ if (!headers.has('User-Agent')) {
1534
+ headers.set('User-Agent', 'node-fetch/1.0 (+https://github.com/bitinn/node-fetch)');
1535
+ }
1536
+
1537
+ // HTTP-network-or-cache fetch step 2.15
1538
+ if (request.compress && !headers.has('Accept-Encoding')) {
1539
+ headers.set('Accept-Encoding', 'gzip,deflate');
1540
+ }
1541
+
1542
+ let agent = request.agent;
1543
+ if (typeof agent === 'function') {
1544
+ agent = agent(parsedURL);
1545
+ }
1546
+
1547
+ if (!headers.has('Connection') && !agent) {
1548
+ headers.set('Connection', 'close');
1549
+ }
1550
+
1551
+ // HTTP-network fetch step 4.2
1552
+ // chunked encoding is handled by Node.js
1553
+
1554
+ return Object.assign({}, parsedURL, {
1555
+ method: request.method,
1556
+ headers: exportNodeCompatibleHeaders(headers),
1557
+ agent
1558
+ });
1559
+ }
1560
+
1561
+ /**
1562
+ * abort-error.js
1563
+ *
1564
+ * AbortError interface for cancelled requests
1565
+ */
1566
+
1567
+ /**
1568
+ * Create AbortError instance
1569
+ *
1570
+ * @param String message Error message for human
1571
+ * @return AbortError
1572
+ */
1573
+ function AbortError(message) {
1574
+ Error.call(this, message);
1575
+
1576
+ this.type = 'aborted';
1577
+ this.message = message;
1578
+
1579
+ // hide custom error implementation details from end-users
1580
+ Error.captureStackTrace(this, this.constructor);
1581
+ }
1582
+
1583
+ AbortError.prototype = Object.create(Error.prototype);
1584
+ AbortError.prototype.constructor = AbortError;
1585
+ AbortError.prototype.name = 'AbortError';
1586
+
1587
+ // fix an issue where "PassThrough", "resolve" aren't a named export for node <10
1588
+ const PassThrough$1 = stream__WEBPACK_IMPORTED_MODULE_0__.PassThrough;
1589
+ const resolve_url = url__WEBPACK_IMPORTED_MODULE_2__.resolve;
1590
+
1591
+ /**
1592
+ * Fetch function
1593
+ *
1594
+ * @param Mixed url Absolute url or Request instance
1595
+ * @param Object opts Fetch options
1596
+ * @return Promise
1597
+ */
1598
+ function fetch(url, opts) {
1599
+
1600
+ // allow custom promise
1601
+ if (!fetch.Promise) {
1602
+ throw new Error('native promise missing, set fetch.Promise to your favorite alternative');
1603
+ }
1604
+
1605
+ Body.Promise = fetch.Promise;
1606
+
1607
+ // wrap http.request into fetch
1608
+ return new fetch.Promise(function (resolve, reject) {
1609
+ // build request object
1610
+ const request = new Request(url, opts);
1611
+ const options = getNodeRequestOptions(request);
1612
+
1613
+ const send = (options.protocol === 'https:' ? https__WEBPACK_IMPORTED_MODULE_3__ : http__WEBPACK_IMPORTED_MODULE_1__).request;
1614
+ const signal = request.signal;
1615
+
1616
+ let response = null;
1617
+
1618
+ const abort = function abort() {
1619
+ let error = new AbortError('The user aborted a request.');
1620
+ reject(error);
1621
+ if (request.body && request.body instanceof stream__WEBPACK_IMPORTED_MODULE_0__.Readable) {
1622
+ request.body.destroy(error);
1623
+ }
1624
+ if (!response || !response.body) return;
1625
+ response.body.emit('error', error);
1626
+ };
1627
+
1628
+ if (signal && signal.aborted) {
1629
+ abort();
1630
+ return;
1631
+ }
1632
+
1633
+ const abortAndFinalize = function abortAndFinalize() {
1634
+ abort();
1635
+ finalize();
1636
+ };
1637
+
1638
+ // send request
1639
+ const req = send(options);
1640
+ let reqTimeout;
1641
+
1642
+ if (signal) {
1643
+ signal.addEventListener('abort', abortAndFinalize);
1644
+ }
1645
+
1646
+ function finalize() {
1647
+ req.abort();
1648
+ if (signal) signal.removeEventListener('abort', abortAndFinalize);
1649
+ clearTimeout(reqTimeout);
1650
+ }
1651
+
1652
+ if (request.timeout) {
1653
+ req.once('socket', function (socket) {
1654
+ reqTimeout = setTimeout(function () {
1655
+ reject(new FetchError(`network timeout at: ${request.url}`, 'request-timeout'));
1656
+ finalize();
1657
+ }, request.timeout);
1658
+ });
1659
+ }
1660
+
1661
+ req.on('error', function (err) {
1662
+ reject(new FetchError(`request to ${request.url} failed, reason: ${err.message}`, 'system', err));
1663
+ finalize();
1664
+ });
1665
+
1666
+ req.on('response', function (res) {
1667
+ clearTimeout(reqTimeout);
1668
+
1669
+ const headers = createHeadersLenient(res.headers);
1670
+
1671
+ // HTTP fetch step 5
1672
+ if (fetch.isRedirect(res.statusCode)) {
1673
+ // HTTP fetch step 5.2
1674
+ const location = headers.get('Location');
1675
+
1676
+ // HTTP fetch step 5.3
1677
+ const locationURL = location === null ? null : resolve_url(request.url, location);
1678
+
1679
+ // HTTP fetch step 5.5
1680
+ switch (request.redirect) {
1681
+ case 'error':
1682
+ reject(new FetchError(`uri requested responds with a redirect, redirect mode is set to error: ${request.url}`, 'no-redirect'));
1683
+ finalize();
1684
+ return;
1685
+ case 'manual':
1686
+ // node-fetch-specific step: make manual redirect a bit easier to use by setting the Location header value to the resolved URL.
1687
+ if (locationURL !== null) {
1688
+ // handle corrupted header
1689
+ try {
1690
+ headers.set('Location', locationURL);
1691
+ } catch (err) {
1692
+ // istanbul ignore next: nodejs server prevent invalid response headers, we can't test this through normal request
1693
+ reject(err);
1694
+ }
1695
+ }
1696
+ break;
1697
+ case 'follow':
1698
+ // HTTP-redirect fetch step 2
1699
+ if (locationURL === null) {
1700
+ break;
1701
+ }
1702
+
1703
+ // HTTP-redirect fetch step 5
1704
+ if (request.counter >= request.follow) {
1705
+ reject(new FetchError(`maximum redirect reached at: ${request.url}`, 'max-redirect'));
1706
+ finalize();
1707
+ return;
1708
+ }
1709
+
1710
+ // HTTP-redirect fetch step 6 (counter increment)
1711
+ // Create a new Request object.
1712
+ const requestOpts = {
1713
+ headers: new Headers(request.headers),
1714
+ follow: request.follow,
1715
+ counter: request.counter + 1,
1716
+ agent: request.agent,
1717
+ compress: request.compress,
1718
+ method: request.method,
1719
+ body: request.body,
1720
+ signal: request.signal,
1721
+ timeout: request.timeout,
1722
+ size: request.size
1723
+ };
1724
+
1725
+ // HTTP-redirect fetch step 9
1726
+ if (res.statusCode !== 303 && request.body && getTotalBytes(request) === null) {
1727
+ reject(new FetchError('Cannot follow redirect with body being a readable stream', 'unsupported-redirect'));
1728
+ finalize();
1729
+ return;
1730
+ }
1731
+
1732
+ // HTTP-redirect fetch step 11
1733
+ if (res.statusCode === 303 || (res.statusCode === 301 || res.statusCode === 302) && request.method === 'POST') {
1734
+ requestOpts.method = 'GET';
1735
+ requestOpts.body = undefined;
1736
+ requestOpts.headers.delete('content-length');
1737
+ }
1738
+
1739
+ // HTTP-redirect fetch step 15
1740
+ resolve(fetch(new Request(locationURL, requestOpts)));
1741
+ finalize();
1742
+ return;
1743
+ }
1744
+ }
1745
+
1746
+ // prepare response
1747
+ res.once('end', function () {
1748
+ if (signal) signal.removeEventListener('abort', abortAndFinalize);
1749
+ });
1750
+ let body = res.pipe(new PassThrough$1());
1751
+
1752
+ const response_options = {
1753
+ url: request.url,
1754
+ status: res.statusCode,
1755
+ statusText: res.statusMessage,
1756
+ headers: headers,
1757
+ size: request.size,
1758
+ timeout: request.timeout,
1759
+ counter: request.counter
1760
+ };
1761
+
1762
+ // HTTP-network fetch step 12.1.1.3
1763
+ const codings = headers.get('Content-Encoding');
1764
+
1765
+ // HTTP-network fetch step 12.1.1.4: handle content codings
1766
+
1767
+ // in following scenarios we ignore compression support
1768
+ // 1. compression support is disabled
1769
+ // 2. HEAD request
1770
+ // 3. no Content-Encoding header
1771
+ // 4. no content response (204)
1772
+ // 5. content not modified response (304)
1773
+ if (!request.compress || request.method === 'HEAD' || codings === null || res.statusCode === 204 || res.statusCode === 304) {
1774
+ response = new Response(body, response_options);
1775
+ resolve(response);
1776
+ return;
1777
+ }
1778
+
1779
+ // For Node v6+
1780
+ // Be less strict when decoding compressed responses, since sometimes
1781
+ // servers send slightly invalid responses that are still accepted
1782
+ // by common browsers.
1783
+ // Always using Z_SYNC_FLUSH is what cURL does.
1784
+ const zlibOptions = {
1785
+ flush: zlib__WEBPACK_IMPORTED_MODULE_4__.Z_SYNC_FLUSH,
1786
+ finishFlush: zlib__WEBPACK_IMPORTED_MODULE_4__.Z_SYNC_FLUSH
1787
+ };
1788
+
1789
+ // for gzip
1790
+ if (codings == 'gzip' || codings == 'x-gzip') {
1791
+ body = body.pipe(zlib__WEBPACK_IMPORTED_MODULE_4__.createGunzip(zlibOptions));
1792
+ response = new Response(body, response_options);
1793
+ resolve(response);
1794
+ return;
1795
+ }
1796
+
1797
+ // for deflate
1798
+ if (codings == 'deflate' || codings == 'x-deflate') {
1799
+ // handle the infamous raw deflate response from old servers
1800
+ // a hack for old IIS and Apache servers
1801
+ const raw = res.pipe(new PassThrough$1());
1802
+ raw.once('data', function (chunk) {
1803
+ // see http://stackoverflow.com/questions/37519828
1804
+ if ((chunk[0] & 0x0F) === 0x08) {
1805
+ body = body.pipe(zlib__WEBPACK_IMPORTED_MODULE_4__.createInflate());
1806
+ } else {
1807
+ body = body.pipe(zlib__WEBPACK_IMPORTED_MODULE_4__.createInflateRaw());
1808
+ }
1809
+ response = new Response(body, response_options);
1810
+ resolve(response);
1811
+ });
1812
+ return;
1813
+ }
1814
+
1815
+ // for br
1816
+ if (codings == 'br' && typeof zlib__WEBPACK_IMPORTED_MODULE_4__.createBrotliDecompress === 'function') {
1817
+ body = body.pipe(zlib__WEBPACK_IMPORTED_MODULE_4__.createBrotliDecompress());
1818
+ response = new Response(body, response_options);
1819
+ resolve(response);
1820
+ return;
1821
+ }
1822
+
1823
+ // otherwise, use response as-is
1824
+ response = new Response(body, response_options);
1825
+ resolve(response);
1826
+ });
1827
+
1828
+ writeToStream(req, request);
1829
+ });
1830
+ }
1831
+ /**
1832
+ * Redirect code matching
1833
+ *
1834
+ * @param Number code Status code
1835
+ * @return Boolean
1836
+ */
1837
+ fetch.isRedirect = function (code) {
1838
+ return code === 301 || code === 302 || code === 303 || code === 307 || code === 308;
1839
+ };
1840
+
1841
+ // expose Promise
1842
+ fetch.Promise = global.Promise;
1843
+
1844
+ /* harmony default export */ __webpack_exports__["default"] = (fetch);
1845
+
1846
+
1847
+
1848
+ /***/ }),
1849
+
1850
+ /***/ "http":
1851
+ /*!***********************!*\
1852
+ !*** external "http" ***!
1853
+ \***********************/
1854
+ /*! no static exports found */
1855
+ /***/ (function(module, exports) {
1856
+
1857
+ module.exports = require("http");
1858
+
1859
+ /***/ }),
1860
+
1861
+ /***/ "https":
1862
+ /*!************************!*\
1863
+ !*** external "https" ***!
1864
+ \************************/
1865
+ /*! no static exports found */
1866
+ /***/ (function(module, exports) {
1867
+
1868
+ module.exports = require("https");
1869
+
1870
+ /***/ }),
1871
+
1872
+ /***/ "stream":
1873
+ /*!*************************!*\
1874
+ !*** external "stream" ***!
1875
+ \*************************/
1876
+ /*! no static exports found */
1877
+ /***/ (function(module, exports) {
1878
+
1879
+ module.exports = require("stream");
1880
+
1881
+ /***/ }),
1882
+
1883
+ /***/ "url":
1884
+ /*!**********************!*\
1885
+ !*** external "url" ***!
1886
+ \**********************/
1887
+ /*! no static exports found */
1888
+ /***/ (function(module, exports) {
1889
+
1890
+ module.exports = require("url");
1891
+
1892
+ /***/ }),
1893
+
1894
+ /***/ "zlib":
1895
+ /*!***********************!*\
1896
+ !*** external "zlib" ***!
1897
+ \***********************/
1898
+ /*! no static exports found */
1899
+ /***/ (function(module, exports) {
1900
+
1901
+ module.exports = require("zlib");
1902
+
1903
+ /***/ })
1904
+
1905
+ /******/ });
1906
+ //# sourceMappingURL=50604be620465cc30dd8.worker.js.map