diff --git a/dist/index.js b/dist/index.js index 5196590..701710d 100644 --- a/dist/index.js +++ b/dist/index.js @@ -32819,6 +32819,36 @@ const isAsyncFn = kindOfTest('AsyncFunction'); const isThenable = (thing) => thing && (isObject(thing) || isFunction(thing)) && isFunction(thing.then) && isFunction(thing.catch); +// original code +// https://github.com/DigitalBrainJS/AxiosPromise/blob/16deab13710ec09779922131f3fa5954320f83ab/lib/utils.js#L11-L34 + +const _setImmediate = ((setImmediateSupported, postMessageSupported) => { + if (setImmediateSupported) { + return setImmediate; + } + + return postMessageSupported ? ((token, callbacks) => { + _global.addEventListener("message", ({source, data}) => { + if (source === _global && data === token) { + callbacks.length && callbacks.shift()(); + } + }, false); + + return (cb) => { + callbacks.push(cb); + _global.postMessage(token, "*"); + } + })(`axios@${Math.random()}`, []) : (cb) => setTimeout(cb); +})( + typeof setImmediate === 'function', + isFunction(_global.postMessage) +); + +const asap = typeof queueMicrotask !== 'undefined' ? + queueMicrotask.bind(_global) : ( typeof process !== 'undefined' && process.nextTick || _setImmediate); + +// ********************* + /* harmony default export */ const utils = ({ isArray, isArrayBuffer, @@ -32874,7 +32904,9 @@ const isThenable = (thing) => isSpecCompliantForm, toJSONObject, isAsyncFn, - isThenable + isThenable, + setImmediate: _setImmediate, + asap }); ;// CONCATENATED MODULE: ./node_modules/axios/lib/core/AxiosError.js @@ -34296,7 +34328,7 @@ var follow_redirects = __nccwpck_require__(7707); // EXTERNAL MODULE: external "zlib" var external_zlib_ = __nccwpck_require__(9796); ;// CONCATENATED MODULE: ./node_modules/axios/lib/env/data.js -const VERSION = "1.7.2"; +const VERSION = "1.7.4"; ;// CONCATENATED MODULE: ./node_modules/axios/lib/helpers/parseProtocol.js @@ -34362,108 +34394,12 @@ function fromDataURI(uri, asBlob, options) { // EXTERNAL MODULE: external "stream" var external_stream_ = __nccwpck_require__(2781); -;// CONCATENATED MODULE: ./node_modules/axios/lib/helpers/throttle.js - - -/** - * Throttle decorator - * @param {Function} fn - * @param {Number} freq - * @return {Function} - */ -function throttle(fn, freq) { - let timestamp = 0; - const threshold = 1000 / freq; - let timer = null; - return function throttled() { - const force = this === true; - - const now = Date.now(); - if (force || now - timestamp > threshold) { - if (timer) { - clearTimeout(timer); - timer = null; - } - timestamp = now; - return fn.apply(null, arguments); - } - if (!timer) { - timer = setTimeout(() => { - timer = null; - timestamp = Date.now(); - return fn.apply(null, arguments); - }, threshold - (now - timestamp)); - } - }; -} - -/* harmony default export */ const helpers_throttle = (throttle); - -;// CONCATENATED MODULE: ./node_modules/axios/lib/helpers/speedometer.js - - -/** - * Calculate data maxRate - * @param {Number} [samplesCount= 10] - * @param {Number} [min= 1000] - * @returns {Function} - */ -function speedometer(samplesCount, min) { - samplesCount = samplesCount || 10; - const bytes = new Array(samplesCount); - const timestamps = new Array(samplesCount); - let head = 0; - let tail = 0; - let firstSampleTS; - - min = min !== undefined ? min : 1000; - - return function push(chunkLength) { - const now = Date.now(); - - const startedAt = timestamps[tail]; - - if (!firstSampleTS) { - firstSampleTS = now; - } - - bytes[head] = chunkLength; - timestamps[head] = now; - - let i = tail; - let bytesCount = 0; - - while (i !== head) { - bytesCount += bytes[i++]; - i = i % samplesCount; - } - - head = (head + 1) % samplesCount; - - if (head === tail) { - tail = (tail + 1) % samplesCount; - } - - if (now - firstSampleTS < min) { - return; - } - - const passed = startedAt && now - startedAt; - - return passed ? Math.round(bytesCount * 1000 / passed) : undefined; - }; -} - -/* harmony default export */ const helpers_speedometer = (speedometer); - ;// CONCATENATED MODULE: ./node_modules/axios/lib/helpers/AxiosTransformStream.js - - const kInternals = Symbol('internals'); class AxiosTransformStream extends external_stream_.Transform{ @@ -34483,12 +34419,8 @@ class AxiosTransformStream extends external_stream_.Transform{ readableHighWaterMark: options.chunkSize }); - const self = this; - const internals = this[kInternals] = { - length: options.length, timeWindow: options.timeWindow, - ticksRate: options.ticksRate, chunkSize: options.chunkSize, maxRate: options.maxRate, minChunkSize: options.minChunkSize, @@ -34500,8 +34432,6 @@ class AxiosTransformStream extends external_stream_.Transform{ onReadCallback: null }; - const _speedometer = helpers_speedometer(internals.ticksRate * options.samplesCount, internals.timeWindow); - this.on('newListener', event => { if (event === 'progress') { if (!internals.isCaptured) { @@ -34509,39 +34439,6 @@ class AxiosTransformStream extends external_stream_.Transform{ } } }); - - let bytesNotified = 0; - - internals.updateProgress = helpers_throttle(function throttledHandler() { - const totalBytes = internals.length; - const bytesTransferred = internals.bytesSeen; - const progressBytes = bytesTransferred - bytesNotified; - if (!progressBytes || self.destroyed) return; - - const rate = _speedometer(progressBytes); - - bytesNotified = bytesTransferred; - - process.nextTick(() => { - self.emit('progress', { - loaded: bytesTransferred, - total: totalBytes, - progress: totalBytes ? (bytesTransferred / totalBytes) : undefined, - bytes: progressBytes, - rate: rate ? rate : undefined, - estimated: rate && totalBytes && bytesTransferred <= totalBytes ? - (totalBytes - bytesTransferred) / rate : undefined, - lengthComputable: totalBytes != null - }); - }); - }, internals.ticksRate); - - const onFinish = () => { - internals.updateProgress.call(true); - }; - - this.once('end', onFinish); - this.once('error', onFinish); } _read(size) { @@ -34555,7 +34452,6 @@ class AxiosTransformStream extends external_stream_.Transform{ } _transform(chunk, encoding, callback) { - const self = this; const internals = this[kInternals]; const maxRate = internals.maxRate; @@ -34567,16 +34463,14 @@ class AxiosTransformStream extends external_stream_.Transform{ const bytesThreshold = (maxRate / divider); const minChunkSize = internals.minChunkSize !== false ? Math.max(internals.minChunkSize, bytesThreshold * 0.01) : 0; - function pushChunk(_chunk, _callback) { + const pushChunk = (_chunk, _callback) => { const bytes = Buffer.byteLength(_chunk); internals.bytesSeen += bytes; internals.bytes += bytes; - if (internals.isCaptured) { - internals.updateProgress(); - } + internals.isCaptured && this.emit('progress', internals.bytesSeen); - if (self.push(_chunk)) { + if (this.push(_chunk)) { process.nextTick(_callback); } else { internals.onReadCallback = () => { @@ -34641,11 +34535,6 @@ class AxiosTransformStream extends external_stream_.Transform{ } }); } - - setLength(length) { - this[kInternals].length = +length; - return this; - } } /* harmony default export */ const helpers_AxiosTransformStream = (AxiosTransformStream); @@ -34830,6 +34719,155 @@ const callbackify = (fn, reducer) => { /* harmony default export */ const helpers_callbackify = (callbackify); +;// CONCATENATED MODULE: ./node_modules/axios/lib/helpers/speedometer.js + + +/** + * Calculate data maxRate + * @param {Number} [samplesCount= 10] + * @param {Number} [min= 1000] + * @returns {Function} + */ +function speedometer(samplesCount, min) { + samplesCount = samplesCount || 10; + const bytes = new Array(samplesCount); + const timestamps = new Array(samplesCount); + let head = 0; + let tail = 0; + let firstSampleTS; + + min = min !== undefined ? min : 1000; + + return function push(chunkLength) { + const now = Date.now(); + + const startedAt = timestamps[tail]; + + if (!firstSampleTS) { + firstSampleTS = now; + } + + bytes[head] = chunkLength; + timestamps[head] = now; + + let i = tail; + let bytesCount = 0; + + while (i !== head) { + bytesCount += bytes[i++]; + i = i % samplesCount; + } + + head = (head + 1) % samplesCount; + + if (head === tail) { + tail = (tail + 1) % samplesCount; + } + + if (now - firstSampleTS < min) { + return; + } + + const passed = startedAt && now - startedAt; + + return passed ? Math.round(bytesCount * 1000 / passed) : undefined; + }; +} + +/* harmony default export */ const helpers_speedometer = (speedometer); + +;// CONCATENATED MODULE: ./node_modules/axios/lib/helpers/throttle.js +/** + * Throttle decorator + * @param {Function} fn + * @param {Number} freq + * @return {Function} + */ +function throttle(fn, freq) { + let timestamp = 0; + let threshold = 1000 / freq; + let lastArgs; + let timer; + + const invoke = (args, now = Date.now()) => { + timestamp = now; + lastArgs = null; + if (timer) { + clearTimeout(timer); + timer = null; + } + fn.apply(null, args); + } + + const throttled = (...args) => { + const now = Date.now(); + const passed = now - timestamp; + if ( passed >= threshold) { + invoke(args, now); + } else { + lastArgs = args; + if (!timer) { + timer = setTimeout(() => { + timer = null; + invoke(lastArgs) + }, threshold - passed); + } + } + } + + const flush = () => lastArgs && invoke(lastArgs); + + return [throttled, flush]; +} + +/* harmony default export */ const helpers_throttle = (throttle); + +;// CONCATENATED MODULE: ./node_modules/axios/lib/helpers/progressEventReducer.js + + + + +const progressEventReducer = (listener, isDownloadStream, freq = 3) => { + let bytesNotified = 0; + const _speedometer = helpers_speedometer(50, 250); + + return helpers_throttle(e => { + const loaded = e.loaded; + const total = e.lengthComputable ? e.total : undefined; + const progressBytes = loaded - bytesNotified; + const rate = _speedometer(progressBytes); + const inRange = loaded <= total; + + bytesNotified = loaded; + + const data = { + loaded, + total, + progress: total ? (loaded / total) : undefined, + bytes: progressBytes, + rate: rate ? rate : undefined, + estimated: rate && total && inRange ? (total - loaded) / rate : undefined, + event: e, + lengthComputable: total != null, + [isDownloadStream ? 'download' : 'upload']: true + }; + + listener(data); + }, freq); +} + +const progressEventDecorator = (total, throttled) => { + const lengthComputable = total != null; + + return [(loaded) => throttled[0]({ + lengthComputable, + total, + loaded + }), throttled[1]]; +} + +const asyncDecorator = (fn) => (...args) => utils.asap(() => fn(...args)); + ;// CONCATENATED MODULE: ./node_modules/axios/lib/adapters/http.js @@ -34856,6 +34894,7 @@ const callbackify = (fn, reducer) => { + const zlibOptions = { @@ -34878,6 +34917,14 @@ const supportedProtocols = platform.protocols.map(protocol => { return protocol + ':'; }); +const flushOnFinish = (stream, [throttled, flush]) => { + stream + .on('end', flush) + .on('error', flush); + + return throttled; +} + /** * If the proxy or config beforeRedirects functions are defined, call them with the options * object. @@ -35053,7 +35100,7 @@ const buildAddressEntry = (address, family) => resolveFamily(utils.isObject(addr // Parse url const fullPath = buildFullPath(config.baseURL, config.url); - const parsed = new URL(fullPath, 'http://localhost'); + const parsed = new URL(fullPath, utils.hasBrowserEnv ? platform.origin : undefined); const protocol = parsed.protocol || supportedProtocols[0]; if (protocol === 'data:') { @@ -35111,8 +35158,7 @@ const buildAddressEntry = (address, family) => resolveFamily(utils.isObject(addr // Only set header if it hasn't been set in config headers.set('User-Agent', 'axios/' + VERSION, false); - const onDownloadProgress = config.onDownloadProgress; - const onUploadProgress = config.onUploadProgress; + const {onUploadProgress, onDownloadProgress} = config; const maxRate = config.maxRate; let maxUploadRate = undefined; let maxDownloadRate = undefined; @@ -35185,15 +35231,16 @@ const buildAddressEntry = (address, family) => resolveFamily(utils.isObject(addr } data = external_stream_.pipeline([data, new helpers_AxiosTransformStream({ - length: contentLength, maxRate: utils.toFiniteNumber(maxUploadRate) })], utils.noop); - onUploadProgress && data.on('progress', progress => { - onUploadProgress(Object.assign(progress, { - upload: true - })); - }); + onUploadProgress && data.on('progress', flushOnFinish( + data, + progressEventDecorator( + contentLength, + progressEventReducer(asyncDecorator(onUploadProgress), false, 3) + ) + )); } // HTTP basic authentication @@ -35292,17 +35339,18 @@ const buildAddressEntry = (address, family) => resolveFamily(utils.isObject(addr const responseLength = +res.headers['content-length']; - if (onDownloadProgress) { + if (onDownloadProgress || maxDownloadRate) { const transformStream = new helpers_AxiosTransformStream({ - length: utils.toFiniteNumber(responseLength), maxRate: utils.toFiniteNumber(maxDownloadRate) }); - onDownloadProgress && transformStream.on('progress', progress => { - onDownloadProgress(Object.assign(progress, { - download: true - })); - }); + onDownloadProgress && transformStream.on('progress', flushOnFinish( + transformStream, + progressEventDecorator( + responseLength, + progressEventReducer(asyncDecorator(onDownloadProgress), true, 3) + ) + )); streams.push(transformStream); } @@ -35517,40 +35565,6 @@ const buildAddressEntry = (address, family) => resolveFamily(utils.isObject(addr const __setProxy = (/* unused pure expression or super */ null && (setProxy)); -;// CONCATENATED MODULE: ./node_modules/axios/lib/helpers/progressEventReducer.js - - - -/* harmony default export */ const progressEventReducer = ((listener, isDownloadStream, freq = 3) => { - let bytesNotified = 0; - const _speedometer = helpers_speedometer(50, 250); - - return helpers_throttle(e => { - const loaded = e.loaded; - const total = e.lengthComputable ? e.total : undefined; - const progressBytes = loaded - bytesNotified; - const rate = _speedometer(progressBytes); - const inRange = loaded <= total; - - bytesNotified = loaded; - - const data = { - loaded, - total, - progress: total ? (loaded / total) : undefined, - bytes: progressBytes, - rate: rate ? rate : undefined, - estimated: rate && total && inRange ? (total - loaded) / rate : undefined, - event: e, - lengthComputable: total != null - }; - - data[isDownloadStream ? 'download' : 'upload'] = true; - - listener(data); - }, freq); -}); - ;// CONCATENATED MODULE: ./node_modules/axios/lib/helpers/isURLSameOrigin.js @@ -35850,16 +35864,18 @@ const isXHRAdapterSupported = typeof XMLHttpRequest !== 'undefined'; const _config = resolveConfig(config); let requestData = _config.data; const requestHeaders = core_AxiosHeaders.from(_config.headers).normalize(); - let {responseType} = _config; + let {responseType, onUploadProgress, onDownloadProgress} = _config; let onCanceled; + let uploadThrottled, downloadThrottled; + let flushUpload, flushDownload; + function done() { - if (_config.cancelToken) { - _config.cancelToken.unsubscribe(onCanceled); - } + flushUpload && flushUpload(); // flush events + flushDownload && flushDownload(); // flush events - if (_config.signal) { - _config.signal.removeEventListener('abort', onCanceled); - } + _config.cancelToken && _config.cancelToken.unsubscribe(onCanceled); + + _config.signal && _config.signal.removeEventListener('abort', onCanceled); } let request = new XMLHttpRequest(); @@ -35929,7 +35945,7 @@ const isXHRAdapterSupported = typeof XMLHttpRequest !== 'undefined'; return; } - reject(new core_AxiosError('Request aborted', core_AxiosError.ECONNABORTED, _config, request)); + reject(new core_AxiosError('Request aborted', core_AxiosError.ECONNABORTED, config, request)); // Clean up request request = null; @@ -35939,7 +35955,7 @@ const isXHRAdapterSupported = typeof XMLHttpRequest !== 'undefined'; request.onerror = function handleError() { // Real errors are hidden from us by the browser // onerror should only fire if it's a network error - reject(new core_AxiosError('Network Error', core_AxiosError.ERR_NETWORK, _config, request)); + reject(new core_AxiosError('Network Error', core_AxiosError.ERR_NETWORK, config, request)); // Clean up request request = null; @@ -35955,7 +35971,7 @@ const isXHRAdapterSupported = typeof XMLHttpRequest !== 'undefined'; reject(new core_AxiosError( timeoutErrorMessage, transitional.clarifyTimeoutError ? core_AxiosError.ETIMEDOUT : core_AxiosError.ECONNABORTED, - _config, + config, request)); // Clean up request @@ -35983,13 +35999,18 @@ const isXHRAdapterSupported = typeof XMLHttpRequest !== 'undefined'; } // Handle progress if needed - if (typeof _config.onDownloadProgress === 'function') { - request.addEventListener('progress', progressEventReducer(_config.onDownloadProgress, true)); + if (onDownloadProgress) { + ([downloadThrottled, flushDownload] = progressEventReducer(onDownloadProgress, true)); + request.addEventListener('progress', downloadThrottled); } // Not all browsers support upload events - if (typeof _config.onUploadProgress === 'function' && request.upload) { - request.upload.addEventListener('progress', progressEventReducer(_config.onUploadProgress)); + if (onUploadProgress && request.upload) { + ([uploadThrottled, flushUpload] = progressEventReducer(onUploadProgress)); + + request.upload.addEventListener('progress', uploadThrottled); + + request.upload.addEventListener('loadend', flushUpload); } if (_config.cancelToken || _config.signal) { @@ -36073,7 +36094,6 @@ const composeSignals = (signals, timeout) => { ;// CONCATENATED MODULE: ./node_modules/axios/lib/helpers/trackStream.js - const streamChunk = function* (chunk, chunkSize) { let len = chunk.byteLength; @@ -36102,25 +36122,38 @@ const trackStream = (stream, chunkSize, onProgress, onFinish, encode) => { const iterator = readBytes(stream, chunkSize, encode); let bytes = 0; + let done; + let _onFinish = (e) => { + if (!done) { + done = true; + onFinish && onFinish(e); + } + } return new ReadableStream({ - type: 'bytes', - async pull(controller) { - const {done, value} = await iterator.next(); + try { + const {done, value} = await iterator.next(); - if (done) { - controller.close(); - onFinish(); - return; - } + if (done) { + _onFinish(); + controller.close(); + return; + } - let len = value.byteLength; - onProgress && onProgress(bytes += len); - controller.enqueue(new Uint8Array(value)); + let len = value.byteLength; + if (onProgress) { + let loadedBytes = bytes += len; + onProgress(loadedBytes); + } + controller.enqueue(new Uint8Array(value)); + } catch (err) { + _onFinish(err); + throw err; + } }, cancel(reason) { - onFinish(reason); + _onFinish(reason); return iterator.return(); } }, { @@ -36139,15 +36172,6 @@ const trackStream = (stream, chunkSize, onProgress, onFinish, encode) => { -const fetchProgressDecorator = (total, fn) => { - const lengthComputable = total != null; - return (loaded) => setTimeout(() => fn({ - lengthComputable, - total, - loaded - })); -} - const isFetchSupported = typeof fetch === 'function' && typeof Request === 'function' && typeof Response === 'function'; const isReadableStreamSupported = isFetchSupported && typeof ReadableStream === 'function'; @@ -36157,7 +36181,15 @@ const encodeText = isFetchSupported && (typeof TextEncoder === 'function' ? async (str) => new Uint8Array(await new Response(str).arrayBuffer()) ); -const supportsRequestStream = isReadableStreamSupported && (() => { +const test = (fn, ...args) => { + try { + return !!fn(...args); + } catch (e) { + return false + } +} + +const supportsRequestStream = isReadableStreamSupported && test(() => { let duplexAccessed = false; const hasContentType = new Request(platform.origin, { @@ -36170,17 +36202,13 @@ const supportsRequestStream = isReadableStreamSupported && (() => { }).headers.has('Content-Type'); return duplexAccessed && !hasContentType; -})(); +}); const DEFAULT_CHUNK_SIZE = 64 * 1024; -const supportsResponseStream = isReadableStreamSupported && !!(()=> { - try { - return utils.isReadableStream(new Response('').body); - } catch(err) { - // return undefined - } -})(); +const supportsResponseStream = isReadableStreamSupported && + test(() => utils.isReadableStream(new Response('').body)); + const resolvers = { stream: supportsResponseStream && ((res) => res.body) @@ -36208,7 +36236,7 @@ const getBodyLength = async (body) => { return (await new Request(body).arrayBuffer()).byteLength; } - if(utils.isArrayBufferView(body)) { + if(utils.isArrayBufferView(body) || utils.isArrayBuffer(body)) { return body.byteLength; } @@ -36278,15 +36306,17 @@ const resolveBodyLength = async (headers, body) => { } if (_request.body) { - data = trackStream(_request.body, DEFAULT_CHUNK_SIZE, fetchProgressDecorator( + const [onProgress, flush] = progressEventDecorator( requestContentLength, - progressEventReducer(onUploadProgress) - ), null, encodeText); + progressEventReducer(asyncDecorator(onUploadProgress)) + ); + + data = trackStream(_request.body, DEFAULT_CHUNK_SIZE, onProgress, flush, encodeText); } } if (!utils.isString(withCredentials)) { - withCredentials = withCredentials ? 'cors' : 'omit'; + withCredentials = withCredentials ? 'include' : 'omit'; } request = new Request(url, { @@ -36296,7 +36326,7 @@ const resolveBodyLength = async (headers, body) => { headers: headers.normalize().toJSON(), body: data, duplex: "half", - withCredentials + credentials: withCredentials }); let response = await fetch(request); @@ -36312,11 +36342,16 @@ const resolveBodyLength = async (headers, body) => { const responseContentLength = utils.toFiniteNumber(response.headers.get('content-length')); + const [onProgress, flush] = onDownloadProgress && progressEventDecorator( + responseContentLength, + progressEventReducer(asyncDecorator(onDownloadProgress), true) + ) || []; + response = new Response( - trackStream(response.body, DEFAULT_CHUNK_SIZE, onDownloadProgress && fetchProgressDecorator( - responseContentLength, - progressEventReducer(onDownloadProgress, true) - ), isStreamResponse && onFinish, encodeText), + trackStream(response.body, DEFAULT_CHUNK_SIZE, onProgress, () => { + flush && flush(); + isStreamResponse && onFinish(); + }, encodeText), options ); }