@flatfile/listener 0.4.1 → 1.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.
@@ -2,6 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
+ var fetch = require('cross-fetch');
5
6
  var pako = require('pako');
6
7
  var wildMatch = require('wildcard-match');
7
8
  var flat = require('flat');
@@ -120,667 +121,6 @@ CrossEnvConfig._overrides = /* @__PURE__ */ new Map();
120
121
  */
121
122
  CrossEnvConfig._aliases = /* @__PURE__ */ new Map();
122
123
 
123
- var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
124
-
125
- function getDefaultExportFromCjs (x) {
126
- return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
127
- }
128
-
129
- var browserPonyfill = {exports: {}};
130
-
131
- (function (module, exports) {
132
- // Save global object in a variable
133
- var __global__ =
134
- (typeof globalThis !== 'undefined' && globalThis) ||
135
- (typeof self !== 'undefined' && self) ||
136
- (typeof commonjsGlobal !== 'undefined' && commonjsGlobal);
137
- // Create an object that extends from __global__ without the fetch function
138
- var __globalThis__ = (function () {
139
- function F() {
140
- this.fetch = false;
141
- this.DOMException = __global__.DOMException;
142
- }
143
- F.prototype = __global__; // Needed for feature detection on whatwg-fetch's code
144
- return new F();
145
- })();
146
- // Wraps whatwg-fetch with a function scope to hijack the global object
147
- // "globalThis" that's going to be patched
148
- (function(globalThis) {
149
-
150
- ((function (exports) {
151
-
152
- var global =
153
- (typeof globalThis !== 'undefined' && globalThis) ||
154
- (typeof self !== 'undefined' && self) ||
155
- (typeof global !== 'undefined' && global);
156
-
157
- var support = {
158
- searchParams: 'URLSearchParams' in global,
159
- iterable: 'Symbol' in global && 'iterator' in Symbol,
160
- blob:
161
- 'FileReader' in global &&
162
- 'Blob' in global &&
163
- (function() {
164
- try {
165
- new Blob();
166
- return true
167
- } catch (e) {
168
- return false
169
- }
170
- })(),
171
- formData: 'FormData' in global,
172
- arrayBuffer: 'ArrayBuffer' in global
173
- };
174
-
175
- function isDataView(obj) {
176
- return obj && DataView.prototype.isPrototypeOf(obj)
177
- }
178
-
179
- if (support.arrayBuffer) {
180
- var viewClasses = [
181
- '[object Int8Array]',
182
- '[object Uint8Array]',
183
- '[object Uint8ClampedArray]',
184
- '[object Int16Array]',
185
- '[object Uint16Array]',
186
- '[object Int32Array]',
187
- '[object Uint32Array]',
188
- '[object Float32Array]',
189
- '[object Float64Array]'
190
- ];
191
-
192
- var isArrayBufferView =
193
- ArrayBuffer.isView ||
194
- function(obj) {
195
- return obj && viewClasses.indexOf(Object.prototype.toString.call(obj)) > -1
196
- };
197
- }
198
-
199
- function normalizeName(name) {
200
- if (typeof name !== 'string') {
201
- name = String(name);
202
- }
203
- if (/[^a-z0-9\-#$%&'*+.^_`|~!]/i.test(name) || name === '') {
204
- throw new TypeError('Invalid character in header field name: "' + name + '"')
205
- }
206
- return name.toLowerCase()
207
- }
208
-
209
- function normalizeValue(value) {
210
- if (typeof value !== 'string') {
211
- value = String(value);
212
- }
213
- return value
214
- }
215
-
216
- // Build a destructive iterator for the value list
217
- function iteratorFor(items) {
218
- var iterator = {
219
- next: function() {
220
- var value = items.shift();
221
- return {done: value === undefined, value: value}
222
- }
223
- };
224
-
225
- if (support.iterable) {
226
- iterator[Symbol.iterator] = function() {
227
- return iterator
228
- };
229
- }
230
-
231
- return iterator
232
- }
233
-
234
- function Headers(headers) {
235
- this.map = {};
236
-
237
- if (headers instanceof Headers) {
238
- headers.forEach(function(value, name) {
239
- this.append(name, value);
240
- }, this);
241
- } else if (Array.isArray(headers)) {
242
- headers.forEach(function(header) {
243
- this.append(header[0], header[1]);
244
- }, this);
245
- } else if (headers) {
246
- Object.getOwnPropertyNames(headers).forEach(function(name) {
247
- this.append(name, headers[name]);
248
- }, this);
249
- }
250
- }
251
-
252
- Headers.prototype.append = function(name, value) {
253
- name = normalizeName(name);
254
- value = normalizeValue(value);
255
- var oldValue = this.map[name];
256
- this.map[name] = oldValue ? oldValue + ', ' + value : value;
257
- };
258
-
259
- Headers.prototype['delete'] = function(name) {
260
- delete this.map[normalizeName(name)];
261
- };
262
-
263
- Headers.prototype.get = function(name) {
264
- name = normalizeName(name);
265
- return this.has(name) ? this.map[name] : null
266
- };
267
-
268
- Headers.prototype.has = function(name) {
269
- return this.map.hasOwnProperty(normalizeName(name))
270
- };
271
-
272
- Headers.prototype.set = function(name, value) {
273
- this.map[normalizeName(name)] = normalizeValue(value);
274
- };
275
-
276
- Headers.prototype.forEach = function(callback, thisArg) {
277
- for (var name in this.map) {
278
- if (this.map.hasOwnProperty(name)) {
279
- callback.call(thisArg, this.map[name], name, this);
280
- }
281
- }
282
- };
283
-
284
- Headers.prototype.keys = function() {
285
- var items = [];
286
- this.forEach(function(value, name) {
287
- items.push(name);
288
- });
289
- return iteratorFor(items)
290
- };
291
-
292
- Headers.prototype.values = function() {
293
- var items = [];
294
- this.forEach(function(value) {
295
- items.push(value);
296
- });
297
- return iteratorFor(items)
298
- };
299
-
300
- Headers.prototype.entries = function() {
301
- var items = [];
302
- this.forEach(function(value, name) {
303
- items.push([name, value]);
304
- });
305
- return iteratorFor(items)
306
- };
307
-
308
- if (support.iterable) {
309
- Headers.prototype[Symbol.iterator] = Headers.prototype.entries;
310
- }
311
-
312
- function consumed(body) {
313
- if (body.bodyUsed) {
314
- return Promise.reject(new TypeError('Already read'))
315
- }
316
- body.bodyUsed = true;
317
- }
318
-
319
- function fileReaderReady(reader) {
320
- return new Promise(function(resolve, reject) {
321
- reader.onload = function() {
322
- resolve(reader.result);
323
- };
324
- reader.onerror = function() {
325
- reject(reader.error);
326
- };
327
- })
328
- }
329
-
330
- function readBlobAsArrayBuffer(blob) {
331
- var reader = new FileReader();
332
- var promise = fileReaderReady(reader);
333
- reader.readAsArrayBuffer(blob);
334
- return promise
335
- }
336
-
337
- function readBlobAsText(blob) {
338
- var reader = new FileReader();
339
- var promise = fileReaderReady(reader);
340
- reader.readAsText(blob);
341
- return promise
342
- }
343
-
344
- function readArrayBufferAsText(buf) {
345
- var view = new Uint8Array(buf);
346
- var chars = new Array(view.length);
347
-
348
- for (var i = 0; i < view.length; i++) {
349
- chars[i] = String.fromCharCode(view[i]);
350
- }
351
- return chars.join('')
352
- }
353
-
354
- function bufferClone(buf) {
355
- if (buf.slice) {
356
- return buf.slice(0)
357
- } else {
358
- var view = new Uint8Array(buf.byteLength);
359
- view.set(new Uint8Array(buf));
360
- return view.buffer
361
- }
362
- }
363
-
364
- function Body() {
365
- this.bodyUsed = false;
366
-
367
- this._initBody = function(body) {
368
- /*
369
- fetch-mock wraps the Response object in an ES6 Proxy to
370
- provide useful test harness features such as flush. However, on
371
- ES5 browsers without fetch or Proxy support pollyfills must be used;
372
- the proxy-pollyfill is unable to proxy an attribute unless it exists
373
- on the object before the Proxy is created. This change ensures
374
- Response.bodyUsed exists on the instance, while maintaining the
375
- semantic of setting Request.bodyUsed in the constructor before
376
- _initBody is called.
377
- */
378
- this.bodyUsed = this.bodyUsed;
379
- this._bodyInit = body;
380
- if (!body) {
381
- this._bodyText = '';
382
- } else if (typeof body === 'string') {
383
- this._bodyText = body;
384
- } else if (support.blob && Blob.prototype.isPrototypeOf(body)) {
385
- this._bodyBlob = body;
386
- } else if (support.formData && FormData.prototype.isPrototypeOf(body)) {
387
- this._bodyFormData = body;
388
- } else if (support.searchParams && URLSearchParams.prototype.isPrototypeOf(body)) {
389
- this._bodyText = body.toString();
390
- } else if (support.arrayBuffer && support.blob && isDataView(body)) {
391
- this._bodyArrayBuffer = bufferClone(body.buffer);
392
- // IE 10-11 can't handle a DataView body.
393
- this._bodyInit = new Blob([this._bodyArrayBuffer]);
394
- } else if (support.arrayBuffer && (ArrayBuffer.prototype.isPrototypeOf(body) || isArrayBufferView(body))) {
395
- this._bodyArrayBuffer = bufferClone(body);
396
- } else {
397
- this._bodyText = body = Object.prototype.toString.call(body);
398
- }
399
-
400
- if (!this.headers.get('content-type')) {
401
- if (typeof body === 'string') {
402
- this.headers.set('content-type', 'text/plain;charset=UTF-8');
403
- } else if (this._bodyBlob && this._bodyBlob.type) {
404
- this.headers.set('content-type', this._bodyBlob.type);
405
- } else if (support.searchParams && URLSearchParams.prototype.isPrototypeOf(body)) {
406
- this.headers.set('content-type', 'application/x-www-form-urlencoded;charset=UTF-8');
407
- }
408
- }
409
- };
410
-
411
- if (support.blob) {
412
- this.blob = function() {
413
- var rejected = consumed(this);
414
- if (rejected) {
415
- return rejected
416
- }
417
-
418
- if (this._bodyBlob) {
419
- return Promise.resolve(this._bodyBlob)
420
- } else if (this._bodyArrayBuffer) {
421
- return Promise.resolve(new Blob([this._bodyArrayBuffer]))
422
- } else if (this._bodyFormData) {
423
- throw new Error('could not read FormData body as blob')
424
- } else {
425
- return Promise.resolve(new Blob([this._bodyText]))
426
- }
427
- };
428
-
429
- this.arrayBuffer = function() {
430
- if (this._bodyArrayBuffer) {
431
- var isConsumed = consumed(this);
432
- if (isConsumed) {
433
- return isConsumed
434
- }
435
- if (ArrayBuffer.isView(this._bodyArrayBuffer)) {
436
- return Promise.resolve(
437
- this._bodyArrayBuffer.buffer.slice(
438
- this._bodyArrayBuffer.byteOffset,
439
- this._bodyArrayBuffer.byteOffset + this._bodyArrayBuffer.byteLength
440
- )
441
- )
442
- } else {
443
- return Promise.resolve(this._bodyArrayBuffer)
444
- }
445
- } else {
446
- return this.blob().then(readBlobAsArrayBuffer)
447
- }
448
- };
449
- }
450
-
451
- this.text = function() {
452
- var rejected = consumed(this);
453
- if (rejected) {
454
- return rejected
455
- }
456
-
457
- if (this._bodyBlob) {
458
- return readBlobAsText(this._bodyBlob)
459
- } else if (this._bodyArrayBuffer) {
460
- return Promise.resolve(readArrayBufferAsText(this._bodyArrayBuffer))
461
- } else if (this._bodyFormData) {
462
- throw new Error('could not read FormData body as text')
463
- } else {
464
- return Promise.resolve(this._bodyText)
465
- }
466
- };
467
-
468
- if (support.formData) {
469
- this.formData = function() {
470
- return this.text().then(decode)
471
- };
472
- }
473
-
474
- this.json = function() {
475
- return this.text().then(JSON.parse)
476
- };
477
-
478
- return this
479
- }
480
-
481
- // HTTP methods whose capitalization should be normalized
482
- var methods = ['DELETE', 'GET', 'HEAD', 'OPTIONS', 'POST', 'PUT'];
483
-
484
- function normalizeMethod(method) {
485
- var upcased = method.toUpperCase();
486
- return methods.indexOf(upcased) > -1 ? upcased : method
487
- }
488
-
489
- function Request(input, options) {
490
- if (!(this instanceof Request)) {
491
- throw new TypeError('Please use the "new" operator, this DOM object constructor cannot be called as a function.')
492
- }
493
-
494
- options = options || {};
495
- var body = options.body;
496
-
497
- if (input instanceof Request) {
498
- if (input.bodyUsed) {
499
- throw new TypeError('Already read')
500
- }
501
- this.url = input.url;
502
- this.credentials = input.credentials;
503
- if (!options.headers) {
504
- this.headers = new Headers(input.headers);
505
- }
506
- this.method = input.method;
507
- this.mode = input.mode;
508
- this.signal = input.signal;
509
- if (!body && input._bodyInit != null) {
510
- body = input._bodyInit;
511
- input.bodyUsed = true;
512
- }
513
- } else {
514
- this.url = String(input);
515
- }
516
-
517
- this.credentials = options.credentials || this.credentials || 'same-origin';
518
- if (options.headers || !this.headers) {
519
- this.headers = new Headers(options.headers);
520
- }
521
- this.method = normalizeMethod(options.method || this.method || 'GET');
522
- this.mode = options.mode || this.mode || null;
523
- this.signal = options.signal || this.signal;
524
- this.referrer = null;
525
-
526
- if ((this.method === 'GET' || this.method === 'HEAD') && body) {
527
- throw new TypeError('Body not allowed for GET or HEAD requests')
528
- }
529
- this._initBody(body);
530
-
531
- if (this.method === 'GET' || this.method === 'HEAD') {
532
- if (options.cache === 'no-store' || options.cache === 'no-cache') {
533
- // Search for a '_' parameter in the query string
534
- var reParamSearch = /([?&])_=[^&]*/;
535
- if (reParamSearch.test(this.url)) {
536
- // If it already exists then set the value with the current time
537
- this.url = this.url.replace(reParamSearch, '$1_=' + new Date().getTime());
538
- } else {
539
- // Otherwise add a new '_' parameter to the end with the current time
540
- var reQueryString = /\?/;
541
- this.url += (reQueryString.test(this.url) ? '&' : '?') + '_=' + new Date().getTime();
542
- }
543
- }
544
- }
545
- }
546
-
547
- Request.prototype.clone = function() {
548
- return new Request(this, {body: this._bodyInit})
549
- };
550
-
551
- function decode(body) {
552
- var form = new FormData();
553
- body
554
- .trim()
555
- .split('&')
556
- .forEach(function(bytes) {
557
- if (bytes) {
558
- var split = bytes.split('=');
559
- var name = split.shift().replace(/\+/g, ' ');
560
- var value = split.join('=').replace(/\+/g, ' ');
561
- form.append(decodeURIComponent(name), decodeURIComponent(value));
562
- }
563
- });
564
- return form
565
- }
566
-
567
- function parseHeaders(rawHeaders) {
568
- var headers = new Headers();
569
- // Replace instances of \r\n and \n followed by at least one space or horizontal tab with a space
570
- // https://tools.ietf.org/html/rfc7230#section-3.2
571
- var preProcessedHeaders = rawHeaders.replace(/\r?\n[\t ]+/g, ' ');
572
- // Avoiding split via regex to work around a common IE11 bug with the core-js 3.6.0 regex polyfill
573
- // https://github.com/github/fetch/issues/748
574
- // https://github.com/zloirock/core-js/issues/751
575
- preProcessedHeaders
576
- .split('\r')
577
- .map(function(header) {
578
- return header.indexOf('\n') === 0 ? header.substr(1, header.length) : header
579
- })
580
- .forEach(function(line) {
581
- var parts = line.split(':');
582
- var key = parts.shift().trim();
583
- if (key) {
584
- var value = parts.join(':').trim();
585
- headers.append(key, value);
586
- }
587
- });
588
- return headers
589
- }
590
-
591
- Body.call(Request.prototype);
592
-
593
- function Response(bodyInit, options) {
594
- if (!(this instanceof Response)) {
595
- throw new TypeError('Please use the "new" operator, this DOM object constructor cannot be called as a function.')
596
- }
597
- if (!options) {
598
- options = {};
599
- }
600
-
601
- this.type = 'default';
602
- this.status = options.status === undefined ? 200 : options.status;
603
- this.ok = this.status >= 200 && this.status < 300;
604
- this.statusText = options.statusText === undefined ? '' : '' + options.statusText;
605
- this.headers = new Headers(options.headers);
606
- this.url = options.url || '';
607
- this._initBody(bodyInit);
608
- }
609
-
610
- Body.call(Response.prototype);
611
-
612
- Response.prototype.clone = function() {
613
- return new Response(this._bodyInit, {
614
- status: this.status,
615
- statusText: this.statusText,
616
- headers: new Headers(this.headers),
617
- url: this.url
618
- })
619
- };
620
-
621
- Response.error = function() {
622
- var response = new Response(null, {status: 0, statusText: ''});
623
- response.type = 'error';
624
- return response
625
- };
626
-
627
- var redirectStatuses = [301, 302, 303, 307, 308];
628
-
629
- Response.redirect = function(url, status) {
630
- if (redirectStatuses.indexOf(status) === -1) {
631
- throw new RangeError('Invalid status code')
632
- }
633
-
634
- return new Response(null, {status: status, headers: {location: url}})
635
- };
636
-
637
- exports.DOMException = global.DOMException;
638
- try {
639
- new exports.DOMException();
640
- } catch (err) {
641
- exports.DOMException = function(message, name) {
642
- this.message = message;
643
- this.name = name;
644
- var error = Error(message);
645
- this.stack = error.stack;
646
- };
647
- exports.DOMException.prototype = Object.create(Error.prototype);
648
- exports.DOMException.prototype.constructor = exports.DOMException;
649
- }
650
-
651
- function fetch(input, init) {
652
- return new Promise(function(resolve, reject) {
653
- var request = new Request(input, init);
654
-
655
- if (request.signal && request.signal.aborted) {
656
- return reject(new exports.DOMException('Aborted', 'AbortError'))
657
- }
658
-
659
- var xhr = new XMLHttpRequest();
660
-
661
- function abortXhr() {
662
- xhr.abort();
663
- }
664
-
665
- xhr.onload = function() {
666
- var options = {
667
- status: xhr.status,
668
- statusText: xhr.statusText,
669
- headers: parseHeaders(xhr.getAllResponseHeaders() || '')
670
- };
671
- options.url = 'responseURL' in xhr ? xhr.responseURL : options.headers.get('X-Request-URL');
672
- var body = 'response' in xhr ? xhr.response : xhr.responseText;
673
- setTimeout(function() {
674
- resolve(new Response(body, options));
675
- }, 0);
676
- };
677
-
678
- xhr.onerror = function() {
679
- setTimeout(function() {
680
- reject(new TypeError('Network request failed'));
681
- }, 0);
682
- };
683
-
684
- xhr.ontimeout = function() {
685
- setTimeout(function() {
686
- reject(new TypeError('Network request failed'));
687
- }, 0);
688
- };
689
-
690
- xhr.onabort = function() {
691
- setTimeout(function() {
692
- reject(new exports.DOMException('Aborted', 'AbortError'));
693
- }, 0);
694
- };
695
-
696
- function fixUrl(url) {
697
- try {
698
- return url === '' && global.location.href ? global.location.href : url
699
- } catch (e) {
700
- return url
701
- }
702
- }
703
-
704
- xhr.open(request.method, fixUrl(request.url), true);
705
-
706
- if (request.credentials === 'include') {
707
- xhr.withCredentials = true;
708
- } else if (request.credentials === 'omit') {
709
- xhr.withCredentials = false;
710
- }
711
-
712
- if ('responseType' in xhr) {
713
- if (support.blob) {
714
- xhr.responseType = 'blob';
715
- } else if (
716
- support.arrayBuffer &&
717
- request.headers.get('Content-Type') &&
718
- request.headers.get('Content-Type').indexOf('application/octet-stream') !== -1
719
- ) {
720
- xhr.responseType = 'arraybuffer';
721
- }
722
- }
723
-
724
- if (init && typeof init.headers === 'object' && !(init.headers instanceof Headers)) {
725
- Object.getOwnPropertyNames(init.headers).forEach(function(name) {
726
- xhr.setRequestHeader(name, normalizeValue(init.headers[name]));
727
- });
728
- } else {
729
- request.headers.forEach(function(value, name) {
730
- xhr.setRequestHeader(name, value);
731
- });
732
- }
733
-
734
- if (request.signal) {
735
- request.signal.addEventListener('abort', abortXhr);
736
-
737
- xhr.onreadystatechange = function() {
738
- // DONE (success or failure)
739
- if (xhr.readyState === 4) {
740
- request.signal.removeEventListener('abort', abortXhr);
741
- }
742
- };
743
- }
744
-
745
- xhr.send(typeof request._bodyInit === 'undefined' ? null : request._bodyInit);
746
- })
747
- }
748
-
749
- fetch.polyfill = true;
750
-
751
- if (!global.fetch) {
752
- global.fetch = fetch;
753
- global.Headers = Headers;
754
- global.Request = Request;
755
- global.Response = Response;
756
- }
757
-
758
- exports.Headers = Headers;
759
- exports.Request = Request;
760
- exports.Response = Response;
761
- exports.fetch = fetch;
762
-
763
- return exports;
764
-
765
- }))({});
766
- })(__globalThis__);
767
- // This is a ponyfill, so...
768
- __globalThis__.fetch.ponyfill = true;
769
- delete __globalThis__.fetch.polyfill;
770
- // Choose between native implementation (__global__) or custom implementation (__globalThis__)
771
- var ctx = __global__.fetch ? __global__ : __globalThis__;
772
- exports = ctx.fetch; // To enable: import fetch from 'cross-fetch'
773
- exports.default = ctx.fetch; // For TypeScript consumers without esModuleInterop.
774
- exports.fetch = ctx.fetch; // To enable: import {fetch} from 'cross-fetch'
775
- exports.Headers = ctx.Headers;
776
- exports.Request = ctx.Request;
777
- exports.Response = ctx.Response;
778
- module.exports = exports;
779
- } (browserPonyfill, browserPonyfill.exports));
780
-
781
- var browserPonyfillExports = browserPonyfill.exports;
782
- var fetch = /*@__PURE__*/getDefaultExportFromCjs(browserPonyfillExports);
783
-
784
124
  const ensureSingleTrailingSlash = (url) => {
785
125
  // Remove all trailing slashes
786
126
  while (url.endsWith('/')) {