UNPKG

@fast-china/axios

Version:

Fast Axios 请求工具库.

1,474 lines 266 kB
var FastAxios = (function(exports, axios2) { "use strict"; "use strict"; function isAbsoluteURL(url) { return /^([a-z][a-z\d+\-.]*:)?\/\//i.test(url); } "use strict"; function combineURLs(baseURL, relativeURL) { return relativeURL ? baseURL.replace(/\/?\/$/, "") + "/" + relativeURL.replace(/^\/+/, "") : baseURL; } "use strict"; function buildFullPath(baseURL, requestedURL, allowAbsoluteUrls) { let isRelativeUrl = !isAbsoluteURL(requestedURL); if (baseURL && (isRelativeUrl || allowAbsoluteUrls == false)) { return combineURLs(baseURL, requestedURL); } return requestedURL; } "use strict"; function bind$1(fn, thisArg) { return function wrap2() { return fn.apply(thisArg, arguments); }; } "use strict"; const { toString: toString$1 } = Object.prototype; const { getPrototypeOf } = Object; const { iterator, toStringTag } = Symbol; const kindOf = /* @__PURE__ */ ((cache) => (thing) => { const str = toString$1.call(thing); return cache[str] || (cache[str] = str.slice(8, -1).toLowerCase()); })(/* @__PURE__ */ Object.create(null)); const kindOfTest = (type) => { type = type.toLowerCase(); return (thing) => kindOf(thing) === type; }; const typeOfTest = (type) => (thing) => typeof thing === type; const { isArray: isArray$1 } = Array; const isUndefined$1 = typeOfTest("undefined"); function isBuffer$1(val) { return val !== null && !isUndefined$1(val) && val.constructor !== null && !isUndefined$1(val.constructor) && isFunction$1(val.constructor.isBuffer) && val.constructor.isBuffer(val); } const isArrayBuffer$1 = kindOfTest("ArrayBuffer"); function isArrayBufferView(val) { let result2; if (typeof ArrayBuffer !== "undefined" && ArrayBuffer.isView) { result2 = ArrayBuffer.isView(val); } else { result2 = val && val.buffer && isArrayBuffer$1(val.buffer); } return result2; } const isString$1 = typeOfTest("string"); const isFunction$1 = typeOfTest("function"); const isNumber$1 = typeOfTest("number"); const isObject$1 = (thing) => thing !== null && typeof thing === "object"; const isBoolean$1 = (thing) => thing === true || thing === false; const isPlainObject$1 = (val) => { if (kindOf(val) !== "object") { return false; } const prototype2 = getPrototypeOf(val); return (prototype2 === null || prototype2 === Object.prototype || Object.getPrototypeOf(prototype2) === null) && !(toStringTag in val) && !(iterator in val); }; const isEmptyObject = (val) => { if (!isObject$1(val) || isBuffer$1(val)) { return false; } try { return Object.keys(val).length === 0 && Object.getPrototypeOf(val) === Object.prototype; } catch (e) { return false; } }; const isDate$1 = kindOfTest("Date"); const isFile = kindOfTest("File"); const isBlob = kindOfTest("Blob"); const isFileList = kindOfTest("FileList"); const isStream = (val) => isObject$1(val) && isFunction$1(val.pipe); const isFormData = (thing) => { let kind; return thing && (typeof FormData === "function" && thing instanceof FormData || isFunction$1(thing.append) && ((kind = kindOf(thing)) === "formdata" || // detect form-data instance kind === "object" && isFunction$1(thing.toString) && thing.toString() === "[object FormData]")); }; const isURLSearchParams = kindOfTest("URLSearchParams"); const [isReadableStream, isRequest, isResponse, isHeaders] = ["ReadableStream", "Request", "Response", "Headers"].map(kindOfTest); const trim$1 = (str) => str.trim ? str.trim() : str.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, ""); function forEach$1(obj, fn, { allOwnKeys = false } = {}) { if (obj === null || typeof obj === "undefined") { return; } let i; let l; if (typeof obj !== "object") { obj = [obj]; } if (isArray$1(obj)) { for (i = 0, l = obj.length; i < l; i++) { fn.call(null, obj[i], i, obj); } } else { if (isBuffer$1(obj)) { return; } const keys2 = allOwnKeys ? Object.getOwnPropertyNames(obj) : Object.keys(obj); const len = keys2.length; let key; for (i = 0; i < len; i++) { key = keys2[i]; fn.call(null, obj[key], key, obj); } } } function findKey$1(obj, key) { if (isBuffer$1(obj)) { return null; } key = key.toLowerCase(); const keys2 = Object.keys(obj); let i = keys2.length; let _key; while (i-- > 0) { _key = keys2[i]; if (key === _key.toLowerCase()) { return _key; } } return null; } const _global = (() => { if (typeof globalThis !== "undefined") return globalThis; return typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : global; })(); const isContextDefined = (context) => !isUndefined$1(context) && context !== _global; function merge$1() { const { caseless, skipUndefined } = isContextDefined(this) && this || {}; const result2 = {}; const assignValue2 = (val, key) => { const targetKey = caseless && findKey$1(result2, key) || key; if (isPlainObject$1(result2[targetKey]) && isPlainObject$1(val)) { result2[targetKey] = merge$1(result2[targetKey], val); } else if (isPlainObject$1(val)) { result2[targetKey] = merge$1({}, val); } else if (isArray$1(val)) { result2[targetKey] = val.slice(); } else if (!skipUndefined || !isUndefined$1(val)) { result2[targetKey] = val; } }; for (let i = 0, l = arguments.length; i < l; i++) { arguments[i] && forEach$1(arguments[i], assignValue2); } return result2; } const extend = (a, b, thisArg, { allOwnKeys } = {}) => { forEach$1(b, (val, key) => { if (thisArg && isFunction$1(val)) { a[key] = bind$1(val, thisArg); } else { a[key] = val; } }, { allOwnKeys }); return a; }; const stripBOM = (content) => { if (content.charCodeAt(0) === 65279) { content = content.slice(1); } return content; }; const inherits = (constructor, superConstructor, props, descriptors2) => { constructor.prototype = Object.create(superConstructor.prototype, descriptors2); constructor.prototype.constructor = constructor; Object.defineProperty(constructor, "super", { value: superConstructor.prototype }); props && Object.assign(constructor.prototype, props); }; const toFlatObject = (sourceObj, destObj, filter2, propFilter) => { let props; let i; let prop; const merged = {}; destObj = destObj || {}; if (sourceObj == null) return destObj; do { props = Object.getOwnPropertyNames(sourceObj); i = props.length; while (i-- > 0) { prop = props[i]; if ((!propFilter || propFilter(prop, sourceObj, destObj)) && !merged[prop]) { destObj[prop] = sourceObj[prop]; merged[prop] = true; } } sourceObj = filter2 !== false && getPrototypeOf(sourceObj); } while (sourceObj && (!filter2 || filter2(sourceObj, destObj)) && sourceObj !== Object.prototype); return destObj; }; const endsWith$1 = (str, searchString, position) => { str = String(str); if (position === void 0 || position > str.length) { position = str.length; } position -= searchString.length; const lastIndex = str.indexOf(searchString, position); return lastIndex !== -1 && lastIndex === position; }; const toArray$1 = (thing) => { if (!thing) return null; if (isArray$1(thing)) return thing; let i = thing.length; if (!isNumber$1(i)) return null; const arr = new Array(i); while (i-- > 0) { arr[i] = thing[i]; } return arr; }; const isTypedArray$1 = /* @__PURE__ */ ((TypedArray) => { return (thing) => { return TypedArray && thing instanceof TypedArray; }; })(typeof Uint8Array !== "undefined" && getPrototypeOf(Uint8Array)); const forEachEntry = (obj, fn) => { const generator = obj && obj[iterator]; const _iterator = generator.call(obj); let result2; while ((result2 = _iterator.next()) && !result2.done) { const pair = result2.value; fn.call(obj, pair[0], pair[1]); } }; const matchAll = (regExp, str) => { let matches2; const arr = []; while ((matches2 = regExp.exec(str)) !== null) { arr.push(matches2); } return arr; }; const isHTMLForm = kindOfTest("HTMLFormElement"); const toCamelCase = (str) => { return str.toLowerCase().replace( /[-_\s]([a-z\d])(\w*)/g, function replacer(m, p1, p2) { return p1.toUpperCase() + p2; } ); }; const hasOwnProperty$q = (({ hasOwnProperty: hasOwnProperty2 }) => (obj, prop) => hasOwnProperty2.call(obj, prop))(Object.prototype); const isRegExp$1 = kindOfTest("RegExp"); const reduceDescriptors = (obj, reducer) => { const descriptors2 = Object.getOwnPropertyDescriptors(obj); const reducedDescriptors = {}; forEach$1(descriptors2, (descriptor, name) => { let ret; if ((ret = reducer(descriptor, name, obj)) !== false) { reducedDescriptors[name] = ret || descriptor; } }); Object.defineProperties(obj, reducedDescriptors); }; const freezeMethods = (obj) => { reduceDescriptors(obj, (descriptor, name) => { if (isFunction$1(obj) && ["arguments", "caller", "callee"].indexOf(name) !== -1) { return false; } const value = obj[name]; if (!isFunction$1(value)) return; descriptor.enumerable = false; if ("writable" in descriptor) { descriptor.writable = false; return; } if (!descriptor.set) { descriptor.set = () => { throw Error("Can not rewrite read-only method '" + name + "'"); }; } }); }; const toObjectSet = (arrayOrString, delimiter) => { const obj = {}; const define = (arr) => { arr.forEach((value) => { obj[value] = true; }); }; isArray$1(arrayOrString) ? define(arrayOrString) : define(String(arrayOrString).split(delimiter)); return obj; }; const noop$1 = () => { }; const toFiniteNumber = (value, defaultValue) => { return value != null && Number.isFinite(value = +value) ? value : defaultValue; }; function isSpecCompliantForm(thing) { return !!(thing && isFunction$1(thing.append) && thing[toStringTag] === "FormData" && thing[iterator]); } const toJSONObject = (obj) => { const stack = new Array(10); const visit = (source, i) => { if (isObject$1(source)) { if (stack.indexOf(source) >= 0) { return; } if (isBuffer$1(source)) { return source; } if (!("toJSON" in source)) { stack[i] = source; const target = isArray$1(source) ? [] : {}; forEach$1(source, (value, key) => { const reducedValue = visit(value, i + 1); !isUndefined$1(reducedValue) && (target[key] = reducedValue); }); stack[i] = void 0; return target; } } return source; }; return visit(obj, 0); }; const isAsyncFn = kindOfTest("AsyncFunction"); const isThenable = (thing) => thing && (isObject$1(thing) || isFunction$1(thing)) && isFunction$1(thing.then) && isFunction$1(thing.catch); 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$1(_global.postMessage) ); const asap = typeof queueMicrotask !== "undefined" ? queueMicrotask.bind(_global) : typeof process !== "undefined" && process.nextTick || _setImmediate; const isIterable = (thing) => thing != null && isFunction$1(thing[iterator]); const utils = { isArray: isArray$1, isArrayBuffer: isArrayBuffer$1, isBuffer: isBuffer$1, isFormData, isArrayBufferView, isString: isString$1, isNumber: isNumber$1, isBoolean: isBoolean$1, isObject: isObject$1, isPlainObject: isPlainObject$1, isEmptyObject, isReadableStream, isRequest, isResponse, isHeaders, isUndefined: isUndefined$1, isDate: isDate$1, isFile, isBlob, isRegExp: isRegExp$1, isFunction: isFunction$1, isStream, isURLSearchParams, isTypedArray: isTypedArray$1, isFileList, forEach: forEach$1, merge: merge$1, extend, trim: trim$1, stripBOM, inherits, toFlatObject, kindOf, kindOfTest, endsWith: endsWith$1, toArray: toArray$1, forEachEntry, matchAll, isHTMLForm, hasOwnProperty: hasOwnProperty$q, hasOwnProp: hasOwnProperty$q, // an alias to avoid ESLint no-prototype-builtins detection reduceDescriptors, freezeMethods, toObjectSet, toCamelCase, noop: noop$1, toFiniteNumber, findKey: findKey$1, global: _global, isContextDefined, isSpecCompliantForm, toJSONObject, isAsyncFn, isThenable, setImmediate: _setImmediate, asap, isIterable }; "use strict"; function AxiosError(message, code, config, request2, response) { Error.call(this); if (Error.captureStackTrace) { Error.captureStackTrace(this, this.constructor); } else { this.stack = new Error().stack; } this.message = message; this.name = "AxiosError"; code && (this.code = code); config && (this.config = config); request2 && (this.request = request2); if (response) { this.response = response; this.status = response.status ? response.status : null; } } utils.inherits(AxiosError, Error, { toJSON: function toJSON() { return { // Standard message: this.message, name: this.name, // Microsoft description: this.description, number: this.number, // Mozilla fileName: this.fileName, lineNumber: this.lineNumber, columnNumber: this.columnNumber, stack: this.stack, // Axios config: utils.toJSONObject(this.config), code: this.code, status: this.status }; } }); const prototype$1 = AxiosError.prototype; const descriptors = {}; [ "ERR_BAD_OPTION_VALUE", "ERR_BAD_OPTION", "ECONNABORTED", "ETIMEDOUT", "ERR_NETWORK", "ERR_FR_TOO_MANY_REDIRECTS", "ERR_DEPRECATED", "ERR_BAD_RESPONSE", "ERR_BAD_REQUEST", "ERR_CANCELED", "ERR_NOT_SUPPORT", "ERR_INVALID_URL" // eslint-disable-next-line func-names ].forEach((code) => { descriptors[code] = { value: code }; }); Object.defineProperties(AxiosError, descriptors); Object.defineProperty(prototype$1, "isAxiosError", { value: true }); AxiosError.from = (error, code, config, request2, response, customProps) => { const axiosError = Object.create(prototype$1); utils.toFlatObject(error, axiosError, function filter2(obj) { return obj !== Error.prototype; }, (prop) => { return prop !== "isAxiosError"; }); const msg = error && error.message ? error.message : "Error"; const errCode = code == null && error ? error.code : code; AxiosError.call(axiosError, msg, errCode, config, request2, response); if (error && axiosError.cause == null) { Object.defineProperty(axiosError, "cause", { value: error, configurable: true }); } axiosError.name = error && error.name || "Error"; customProps && Object.assign(axiosError, customProps); return axiosError; }; const PlatformFormData = null; "use strict"; function isVisitable(thing) { return utils.isPlainObject(thing) || utils.isArray(thing); } function removeBrackets(key) { return utils.endsWith(key, "[]") ? key.slice(0, -2) : key; } function renderKey(path, key, dots) { if (!path) return key; return path.concat(key).map(function each(token, i) { token = removeBrackets(token); return !dots && i ? "[" + token + "]" : token; }).join(dots ? "." : ""); } function isFlatArray(arr) { return utils.isArray(arr) && !arr.some(isVisitable); } const predicates = utils.toFlatObject(utils, {}, null, function filter2(prop) { return /^is[A-Z]/.test(prop); }); function toFormData(obj, formData, options) { if (!utils.isObject(obj)) { throw new TypeError("target must be an object"); } formData = formData || new (PlatformFormData || FormData)(); options = utils.toFlatObject(options, { metaTokens: true, dots: false, indexes: false }, false, function defined(option, source) { return !utils.isUndefined(source[option]); }); const metaTokens = options.metaTokens; const visitor = options.visitor || defaultVisitor; const dots = options.dots; const indexes = options.indexes; const _Blob = options.Blob || typeof Blob !== "undefined" && Blob; const useBlob = _Blob && utils.isSpecCompliantForm(formData); if (!utils.isFunction(visitor)) { throw new TypeError("visitor must be a function"); } function convertValue(value) { if (value === null) return ""; if (utils.isDate(value)) { return value.toISOString(); } if (utils.isBoolean(value)) { return value.toString(); } if (!useBlob && utils.isBlob(value)) { throw new AxiosError("Blob is not supported. Use a Buffer instead."); } if (utils.isArrayBuffer(value) || utils.isTypedArray(value)) { return useBlob && typeof Blob === "function" ? new Blob([value]) : Buffer.from(value); } return value; } function defaultVisitor(value, key, path) { let arr = value; if (value && !path && typeof value === "object") { if (utils.endsWith(key, "{}")) { key = metaTokens ? key : key.slice(0, -2); value = JSON.stringify(value); } else if (utils.isArray(value) && isFlatArray(value) || (utils.isFileList(value) || utils.endsWith(key, "[]")) && (arr = utils.toArray(value))) { key = removeBrackets(key); arr.forEach(function each(el, index) { !(utils.isUndefined(el) || el === null) && formData.append( // eslint-disable-next-line no-nested-ternary indexes === true ? renderKey([key], index, dots) : indexes === null ? key : key + "[]", convertValue(el) ); }); return false; } } if (isVisitable(value)) { return true; } formData.append(renderKey(path, key, dots), convertValue(value)); return false; } const stack = []; const exposedHelpers = Object.assign(predicates, { defaultVisitor, convertValue, isVisitable }); function build(value, path) { if (utils.isUndefined(value)) return; if (stack.indexOf(value) !== -1) { throw Error("Circular reference detected in " + path.join(".")); } stack.push(value); utils.forEach(value, function each(el, key) { const result2 = !(utils.isUndefined(el) || el === null) && visitor.call( formData, el, utils.isString(key) ? key.trim() : key, path, exposedHelpers ); if (result2 === true) { build(el, path ? path.concat(key) : [key]); } }); stack.pop(); } if (!utils.isObject(obj)) { throw new TypeError("data must be an object"); } build(obj); return formData; } "use strict"; function encode$1(str) { const charMap = { "!": "%21", "'": "%27", "(": "%28", ")": "%29", "~": "%7E", "%20": "+", "%00": "\0" }; return encodeURIComponent(str).replace(/[!'()~]|%20|%00/g, function replacer(match) { return charMap[match]; }); } function AxiosURLSearchParams(params, options) { this._pairs = []; params && toFormData(params, this, options); } const prototype = AxiosURLSearchParams.prototype; prototype.append = function append(name, value) { this._pairs.push([name, value]); }; prototype.toString = function toString2(encoder) { const _encode = encoder ? function(value) { return encoder.call(this, value, encode$1); } : encode$1; return this._pairs.map(function each(pair) { return _encode(pair[0]) + "=" + _encode(pair[1]); }, "").join("&"); }; "use strict"; function encode(val) { return encodeURIComponent(val).replace(/%3A/gi, ":").replace(/%24/g, "$").replace(/%2C/gi, ",").replace(/%20/g, "+"); } function buildURL(url, params, options) { if (!params) { return url; } const _encode = options && options.encode || encode; if (utils.isFunction(options)) { options = { serialize: options }; } const serializeFn = options && options.serialize; let serializedParams; if (serializeFn) { serializedParams = serializeFn(params, options); } else { serializedParams = utils.isURLSearchParams(params) ? params.toString() : new AxiosURLSearchParams(params, options).toString(_encode); } if (serializedParams) { const hashmarkIndex = url.indexOf("#"); if (hashmarkIndex !== -1) { url = url.slice(0, hashmarkIndex); } url += (url.indexOf("?") === -1 ? "?" : "&") + serializedParams; } return url; } "use strict"; function speedometer(samplesCount, min2) { samplesCount = samplesCount || 10; const bytes = new Array(samplesCount); const timestamps = new Array(samplesCount); let head2 = 0; let tail2 = 0; let firstSampleTS; min2 = min2 !== void 0 ? min2 : 1e3; return function push(chunkLength) { const now2 = Date.now(); const startedAt = timestamps[tail2]; if (!firstSampleTS) { firstSampleTS = now2; } bytes[head2] = chunkLength; timestamps[head2] = now2; let i = tail2; let bytesCount = 0; while (i !== head2) { bytesCount += bytes[i++]; i = i % samplesCount; } head2 = (head2 + 1) % samplesCount; if (head2 === tail2) { tail2 = (tail2 + 1) % samplesCount; } if (now2 - firstSampleTS < min2) { return; } const passed = startedAt && now2 - startedAt; return passed ? Math.round(bytesCount * 1e3 / passed) : void 0; }; } const getMethodType = (config) => { const { method: rawMethod = "GET" } = config; const method2 = rawMethod.toLocaleLowerCase(); switch (method2) { case "download": return "download"; case "upload": return "upload"; default: return "request"; } }; const resolveUniAppRequestOptions = (config) => { const data = config.data; const responseType = config.responseType === "arraybuffer" ? "arraybuffer" : "text"; const dataType = responseType === "text" ? "json" : void 0; const { headers, baseURL, ...requestConfig } = config; const requestHeaders = axios2.AxiosHeaders.from(headers).normalize(false); if (config.auth) { const username = config.auth.username || ""; const password = config.auth.password ? decodeURIComponent(encodeURIComponent(config.auth.password)) : ""; requestHeaders.set("Authorization", `Basic ${btoa(`${username}:${password}`)}`); } const fullPath = buildFullPath(baseURL, config.url); const method2 = config?.method?.toUpperCase() ?? "GET"; const url = buildURL(fullPath, config.params, config.paramsSerializer); const timeout = config.timeout || 6e4; let formData = {}; if (data && typeof data === "string") { try { formData = JSON.parse(data); } catch { } } const header = requestHeaders.toJSON(); return { ...requestConfig, url, data, header, method: method2, responseType, dataType, timeout, formData }; }; const progressEventReducer = (listener, isDownloadStream) => { let bytesNotified = 0; const _speedometer = speedometer(50, 250); return (result2) => { const loaded = result2.totalBytesWritten; const total = result2.totalBytesExpectedToWrite; const progressBytes = loaded - bytesNotified; const rate = _speedometer(progressBytes); const inRange2 = loaded <= total; bytesNotified = loaded; const data = { loaded, total, progress: total ? loaded / total : void 0, bytes: progressBytes, rate: rate || void 0, estimated: rate && total && inRange2 ? (total - loaded) / rate : void 0, event: result2, lengthComputable: true }; data[isDownloadStream ? "download" : "upload"] = true; listener(data); }; }; "use strict"; function settle(resolve, reject2, response) { const validateStatus = response.config.validateStatus; if (!response.status || !validateStatus || validateStatus(response.status)) { resolve(response); } else { reject2(new AxiosError( "Request failed with status code " + response.status, [AxiosError.ERR_BAD_REQUEST, AxiosError.ERR_BAD_RESPONSE][Math.floor(response.status / 100) - 4], response.config, response.request, response )); } } class OnCanceled { config; onCanceled; constructor(config) { this.config = config; } subscribe(task, reject2) { if (this.config.cancelToken || this.config.signal) { this.onCanceled = (cancel) => { if (!task) return; reject2(!cancel || cancel.type ? new axios2.CanceledError(void 0, void 0, this.config, task) : cancel); task.abort(); task = null; }; if (this.config.cancelToken) { this.config.cancelToken.subscribe(this.onCanceled); } if (this.config.signal && this.config.signal.addEventListener) { this.config.signal.aborted ? this.onCanceled() : this.config.signal.addEventListener("abort", this.onCanceled); } } } unsubscribe() { if (this.config.cancelToken) { this.config.cancelToken.unsubscribe(this.onCanceled); } if (this.config.signal && this.config.signal.removeEventListener) this.config.signal.removeEventListener("abort", this.onCanceled); } } const download = (config) => { return new Promise((resolve, reject2) => { const requestOptions = resolveUniAppRequestOptions(config); const responseConfig = config; responseConfig.headers = new axios2.AxiosHeaders(requestOptions.header); const onCanceled = new OnCanceled(config); let task = uni.downloadFile({ ...requestOptions, success(result2) { if (!task) return; const response = { config: responseConfig, data: result2.tempFilePath, headers: {}, status: result2.statusCode, statusText: result2.errMsg ?? "OK", request: task }; settle(resolve, reject2, response); task = null; }, fail(error) { const { errMsg = "" } = error ?? {}; if (errMsg) { const isTimeoutError = errMsg === "downloadFile:fail timeout"; if (isTimeoutError) reject2(new axios2.AxiosError(errMsg, axios2.AxiosError.ETIMEDOUT, responseConfig, task)); const isNetworkError = errMsg === "downloadFile:fail" || errMsg === "downloadFile:fail "; if (isNetworkError) { reject2(new axios2.AxiosError(errMsg, axios2.AxiosError.ERR_NETWORK, responseConfig, task)); } } reject2(new axios2.AxiosError(error.errMsg, void 0, responseConfig, task)); task = null; }, complete() { onCanceled.unsubscribe(); } }); if (typeof config.onDownloadProgress === "function") { task.onProgressUpdate(progressEventReducer(config.onDownloadProgress, true)); } if (typeof config.onHeadersReceived === "function") task.onHeadersReceived(config.onHeadersReceived); onCanceled.subscribe(task, reject2); }); }; const request = (config) => { return new Promise((resolve, reject2) => { const requestOptions = resolveUniAppRequestOptions(config); const responseConfig = config; responseConfig.headers = new axios2.AxiosHeaders(requestOptions.header); const onCanceled = new OnCanceled(config); let task = uni.request({ ...requestOptions, success(result2) { if (!task) return; if (Array.isArray(result2.header)) { const dingHeader = {}; result2.header.forEach((h) => Object.assign(dingHeader, h)); result2.header = dingHeader; } const headers = new axios2.AxiosHeaders(result2.header); const response = { config: responseConfig, data: result2.data, headers, status: result2.statusCode, statusText: result2.errMsg ?? "OK", request: task, cookies: result2.cookies }; settle(resolve, reject2, response); task = null; }, fail(error) { const { errMsg = "" } = error ?? {}; if (errMsg) { const isTimeoutError = errMsg === "request:fail timeout"; const isEconnabortedError = errMsg === "request:fail abort"; const isSslError = errMsg === "request:fail ssl"; const isNetworkError = errMsg === "request:fail" || errMsg === "request:fail "; if (isTimeoutError) reject2(new axios2.AxiosError(errMsg, axios2.AxiosError.ETIMEDOUT, responseConfig, task)); if (isEconnabortedError) reject2(new axios2.AxiosError(errMsg, axios2.AxiosError.ECONNABORTED, responseConfig, task)); if (isSslError) reject2(new axios2.AxiosError(errMsg, axios2.AxiosError.ERR_NETWORK, responseConfig, task)); if (isNetworkError) reject2(new axios2.AxiosError(errMsg, axios2.AxiosError.ERR_NETWORK, responseConfig, task)); } reject2(new axios2.AxiosError(error.errMsg, void 0, responseConfig, task)); task = null; }, complete() { onCanceled.unsubscribe(); } }); if (typeof config.onHeadersReceived === "function") task.onHeadersReceived(config.onHeadersReceived); onCanceled.subscribe(task, reject2); }); }; const upload = (config) => { return new Promise((resolve, reject2) => { const requestOptions = resolveUniAppRequestOptions(config); const responseConfig = config; responseConfig.headers = new axios2.AxiosHeaders(requestOptions.header); const onCanceled = new OnCanceled(config); let task = uni.uploadFile({ ...requestOptions, success(result2) { if (!task) return; const headers = new axios2.AxiosHeaders(result2.header); const response = { config: responseConfig, data: result2.data, headers, status: result2.statusCode, statusText: result2.errMsg ?? "OK", request: task }; settle(resolve, reject2, response); task = null; }, fail(error) { const { errMsg = "" } = error ?? {}; if (errMsg) { const isTimeoutError = errMsg === "uploadFile:fail timeout"; const isNetworkError = errMsg === "uploadFile:fail file error"; if (isTimeoutError) reject2(new axios2.AxiosError(errMsg, axios2.AxiosError.ETIMEDOUT, responseConfig, task)); if (isNetworkError) { reject2(new axios2.AxiosError(errMsg, axios2.AxiosError.ERR_NETWORK, responseConfig, task)); } } reject2(new axios2.AxiosError(error.errMsg, void 0, responseConfig, task)); task = null; }, complete() { onCanceled.unsubscribe(); } }); if (typeof config.onHeadersReceived === "function") task.onHeadersReceived(config.onHeadersReceived); onCanceled.subscribe(task, reject2); }); }; const getMethod = (config) => { const methodType = getMethodType(config); switch (methodType) { case "download": return download; case "upload": return upload; default: return request; } }; const createUniAppAxiosAdapter = () => { axios2.Axios.prototype.download = function(url, config) { return this.request({ url, method: "download", ...config }); }; axios2.Axios.prototype.upload = function(url, data, config) { return this.request({ url, method: "upload", data, ...config }); }; const uniAppAdapter = (config) => { const method2 = getMethod(config); return method2(config); }; return uniAppAdapter; }; var freeGlobal = typeof global == "object" && global && global.Object === Object && global; var freeSelf = typeof self == "object" && self && self.Object === Object && self; var root = freeGlobal || freeSelf || Function("return this")(); var Symbol$1 = root.Symbol; var objectProto$t = Object.prototype; var hasOwnProperty$p = objectProto$t.hasOwnProperty; var nativeObjectToString$3 = objectProto$t.toString; var symToStringTag$1 = Symbol$1 ? Symbol$1.toStringTag : void 0; function getRawTag(value) { var isOwn = hasOwnProperty$p.call(value, symToStringTag$1), tag = value[symToStringTag$1]; try { value[symToStringTag$1] = void 0; var unmasked = true; } catch (e) { } var result2 = nativeObjectToString$3.call(value); if (unmasked) { if (isOwn) { value[symToStringTag$1] = tag; } else { delete value[symToStringTag$1]; } } return result2; } var objectProto$s = Object.prototype; var nativeObjectToString$2 = objectProto$s.toString; function objectToString(value) { return nativeObjectToString$2.call(value); } var nullTag = "[object Null]", undefinedTag = "[object Undefined]"; var symToStringTag = Symbol$1 ? Symbol$1.toStringTag : void 0; function baseGetTag(value) { if (value == null) { return value === void 0 ? undefinedTag : nullTag; } return symToStringTag && symToStringTag in Object(value) ? getRawTag(value) : objectToString(value); } function isObjectLike(value) { return value != null && typeof value == "object"; } var symbolTag$3 = "[object Symbol]"; function isSymbol(value) { return typeof value == "symbol" || isObjectLike(value) && baseGetTag(value) == symbolTag$3; } var NAN$2 = 0 / 0; function baseToNumber(value) { if (typeof value == "number") { return value; } if (isSymbol(value)) { return NAN$2; } return +value; } function arrayMap(array2, iteratee2) { var index = -1, length = array2 == null ? 0 : array2.length, result2 = Array(length); while (++index < length) { result2[index] = iteratee2(array2[index], index, array2); } return result2; } var isArray = Array.isArray; var INFINITY$5 = 1 / 0; var symbolProto$2 = Symbol$1 ? Symbol$1.prototype : void 0, symbolToString = symbolProto$2 ? symbolProto$2.toString : void 0; function baseToString(value) { if (typeof value == "string") { return value; } if (isArray(value)) { return arrayMap(value, baseToString) + ""; } if (isSymbol(value)) { return symbolToString ? symbolToString.call(value) : ""; } var result2 = value + ""; return result2 == "0" && 1 / value == -INFINITY$5 ? "-0" : result2; } function createMathOperation(operator, defaultValue) { return function(value, other) { var result2; if (value === void 0 && other === void 0) { return defaultValue; } if (value !== void 0) { result2 = value; } if (other !== void 0) { if (result2 === void 0) { return other; } if (typeof value == "string" || typeof other == "string") { value = baseToString(value); other = baseToString(other); } else { value = baseToNumber(value); other = baseToNumber(other); } result2 = operator(value, other); } return result2; }; } var add = createMathOperation(function(augend, addend) { return augend + addend; }, 0); var reWhitespace = /\s/; function trimmedEndIndex(string2) { var index = string2.length; while (index-- && reWhitespace.test(string2.charAt(index))) { } return index; } var reTrimStart$2 = /^\s+/; function baseTrim(string2) { return string2 ? string2.slice(0, trimmedEndIndex(string2) + 1).replace(reTrimStart$2, "") : string2; } function isObject(value) { var type = typeof value; return value != null && (type == "object" || type == "function"); } var NAN$1 = 0 / 0; var reIsBadHex = /^[-+]0x[0-9a-f]+$/i; var reIsBinary = /^0b[01]+$/i; var reIsOctal = /^0o[0-7]+$/i; var freeParseInt = parseInt; function toNumber(value) { if (typeof value == "number") { return value; } if (isSymbol(value)) { return NAN$1; } if (isObject(value)) { var other = typeof value.valueOf == "function" ? value.valueOf() : value; value = isObject(other) ? other + "" : other; } if (typeof value != "string") { return value === 0 ? value : +value; } value = baseTrim(value); var isBinary = reIsBinary.test(value); return isBinary || reIsOctal.test(value) ? freeParseInt(value.slice(2), isBinary ? 2 : 8) : reIsBadHex.test(value) ? NAN$1 : +value; } var INFINITY$4 = 1 / 0, MAX_INTEGER = 17976931348623157e292; function toFinite(value) { if (!value) { return value === 0 ? value : 0; } value = toNumber(value); if (value === INFINITY$4 || value === -INFINITY$4) { var sign = value < 0 ? -1 : 1; return sign * MAX_INTEGER; } return value === value ? value : 0; } function toInteger(value) { var result2 = toFinite(value), remainder = result2 % 1; return result2 === result2 ? remainder ? result2 - remainder : result2 : 0; } var FUNC_ERROR_TEXT$b = "Expected a function"; function after(n, func2) { if (typeof func2 != "function") { throw new TypeError(FUNC_ERROR_TEXT$b); } n = toInteger(n); return function() { if (--n < 1) { return func2.apply(this, arguments); } }; } function identity(value) { return value; } var asyncTag = "[object AsyncFunction]", funcTag$2 = "[object Function]", genTag$1 = "[object GeneratorFunction]", proxyTag = "[object Proxy]"; function isFunction(value) { if (!isObject(value)) { return false; } var tag = baseGetTag(value); return tag == funcTag$2 || tag == genTag$1 || tag == asyncTag || tag == proxyTag; } var coreJsData = root["__core-js_shared__"]; var maskSrcKey = (function() { var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || ""); return uid ? "Symbol(src)_1." + uid : ""; })(); function isMasked(func2) { return !!maskSrcKey && maskSrcKey in func2; } var funcProto$2 = Function.prototype; var funcToString$2 = funcProto$2.toString; function toSource(func2) { if (func2 != null) { try { return funcToString$2.call(func2); } catch (e) { } try { return func2 + ""; } catch (e) { } } return ""; } var reRegExpChar$1 = /[\\^$.*+?()[\]{}|]/g; var reIsHostCtor = /^\[object .+?Constructor\]$/; var funcProto$1 = Function.prototype, objectProto$r = Object.prototype; var funcToString$1 = funcProto$1.toString; var hasOwnProperty$o = objectProto$r.hasOwnProperty; var reIsNative = RegExp( "^" + funcToString$1.call(hasOwnProperty$o).replace(reRegExpChar$1, "\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, "$1.*?") + "$" ); function baseIsNative(value) { if (!isObject(value) || isMasked(value)) { return false; } var pattern = isFunction(value) ? reIsNative : reIsHostCtor; return pattern.test(toSource(value)); } function getValue(object2, key) { return object2 == null ? void 0 : object2[key]; } function getNative(object2, key) { var value = getValue(object2, key); return baseIsNative(value) ? value : void 0; } var WeakMap = getNative(root, "WeakMap"); var metaMap = WeakMap && new WeakMap(); var baseSetData = !metaMap ? identity : function(func2, data) { metaMap.set(func2, data); return func2; }; var objectCreate = Object.create; var baseCreate = /* @__PURE__ */ (function() { function object2() { } return function(proto) { if (!isObject(proto)) { return {}; } if (objectCreate) { return objectCreate(proto); } object2.prototype = proto; var result2 = new object2(); object2.prototype = void 0; return result2; }; })(); function createCtor(Ctor) { return function() { var args = arguments; switch (args.length) { case 0: return new Ctor(); case 1: return new Ctor(args[0]); case 2: return new Ctor(args[0], args[1]); case 3: return new Ctor(args[0], args[1], args[2]); case 4: return new Ctor(args[0], args[1], args[2], args[3]); case 5: return new Ctor(args[0], args[1], args[2], args[3], args[4]); case 6: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5]); case 7: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5], args[6]); } var thisBinding = baseCreate(Ctor.prototype), result2 = Ctor.apply(thisBinding, args); return isObject(result2) ? result2 : thisBinding; }; } var WRAP_BIND_FLAG$8 = 1; function createBind(func2, bitmask, thisArg) { var isBind = bitmask & WRAP_BIND_FLAG$8, Ctor = createCtor(func2); function wrapper() { var fn = this && this !== root && this instanceof wrapper ? Ctor : func2; return fn.apply(isBind ? thisArg : this, arguments); } return wrapper; } function apply(func2, thisArg, args) { switch (args.length) { case 0: return func2.call(thisArg); case 1: return func2.call(thisArg, args[0]); case 2: return func2.call(thisArg, args[0], args[1]); case 3: return func2.call(thisArg, args[0], args[1], args[2]); } return func2.apply(thisArg, args); } var nativeMax$g = Math.max; function composeArgs(args, partials, holders, isCurried) { var argsIndex = -1, argsLength = args.length, holdersLength = holders.length, leftIndex = -1, leftLength = partials.length, rangeLength = nativeMax$g(argsLength - holdersLength, 0), result2 = Array(leftLength + rangeLength), isUncurried = !isCurried; while (++leftIndex < leftLength) { result2[leftIndex] = partials[leftIndex]; } while (++argsIndex < holdersLength) { if (isUncurried || argsIndex < argsLength) { result2[holders[argsIndex]] = args[argsIndex]; } } while (rangeLength--) { result2[leftIndex++] = args[argsIndex++]; } return result2; } var nativeMax$f = Math.max; function composeArgsRight(args, partials, holders, isCurried) { var argsIndex = -1, argsLength = args.length, holdersIndex = -1, holdersLength = holders.length, rightIndex = -1, rightLength = partials.length, rangeLength = nativeMax$f(argsLength - holdersLength, 0), result2 = Array(rangeLength + rightLength), isUncurried = !isCurried; while (++argsIndex < rangeLength) { result2[argsIndex] = args[argsIndex]; } var offset = argsIndex; while (++rightIndex < rightLength) { result2[offset + rightIndex] = partials[rightIndex]; } while (++holdersIndex < holdersLength) { if (isUncurried || argsIndex < argsLength) { result2[offset + holders[holdersIndex]] = args[argsIndex++]; } } return result2; } function countHolders(array2, placeholder) { var length = array2.length, result2 = 0; while (length--) { if (array2[length] === placeholder) { ++result2; } } return result2; } function baseLodash() { } var MAX_ARRAY_LENGTH$6 = 4294967295; function LazyWrapper(value) { this.__wrapped__ = value; this.__actions__ = []; this.__dir__ = 1; this.__filtered__ = false; this.__iteratees__ = []; this.__takeCount__ = MAX_ARRAY_LENGTH$6; this.__views__ = []; } LazyWrapper.prototype = baseCreate(baseLodash.prototype); LazyWrapper.prototype.constructor = LazyWrapper; function noop() { } var getData = !metaMap ? noop : function(func2) { return metaMap.get(func2); }; var realNames = {}; var objectProto$q = Object.prototype; var hasOwnProperty$n = objectProto$q.hasOwnProperty; function getFuncName(func2) { var result2 = func2.name + "", array2 = realNames[result2], length = hasOwnProperty$n.call(realNames, result2) ? array2.length : 0; while (length--) { var data = array2[length], otherFunc = data.func; if (otherFunc == null || otherFunc == func2) { return data.name; } } return result2; } function LodashWrapper(value, chainAll) { this.__wrapped__ = value; this.__actions__ = []; this.__chain__ = !!chainAll; this.__index__ = 0; this.__values__ = void 0; } LodashWrapper.prototype = baseCreate(baseLodash.prototype); LodashWrapper.prototype.constructor = LodashWrapper; function copyArray(source, array2) { var index = -1, length = source.length; array2 || (array2 = Array(length)); while (++index < length) { array2[index] = source[index]; } return array2; } function wrapperClone(wrapper) { if (wrapper instanceof LazyWrapper) { return wrapper.clone(); } var result2 = new LodashWrapper(wrapper.__wrapped__, wrapper.__chain__); result2.__actions__ = copyArray(wrapper.__actions__); result2.__index__ = wrapper.__index__; result2.__values__ = wrapper.__values__; return result2; } var objectProto$p = Object.prototype; var hasOwnProperty$m = objectProto$p.hasOwnProperty; function lodash(value) { if (isObjectLike(value) && !isArray(value) && !(value instanceof LazyWrapper)) { if (value instanceof LodashWrapper) { return value; } if (hasOwnProperty$m.call(value, "__wrapped__")) { return wrapperClone(value); } } return new LodashWrapper(value); } lodash.prototype = baseLodash.prototype; lodash.prototype.constructor = lodash; function isLaziable(func2) { var funcName = getFuncName(func2), other = lodash[funcName]; if (typeof other != "function" || !(funcName in LazyWrapper.prototype)) { return false; } if (func2 === other) { return true; } var data = getData(other); return !!data && func2 === data[0]; } var HOT_COUNT = 800, HOT_SPAN = 16; var nativeNow = Date.now; function shortOut(func2) { var count = 0, lastCalled = 0; return function() { var stamp = nativeNow(), remaining = HOT_SPAN - (stamp - lastCalled); lastCalled = stamp; if (remaining > 0) { if (++count >= HOT_COUNT) { return arguments[0]; } } else { count = 0; } return func2.apply(void 0, arguments); }; } var setData = shortOut(baseSetData); var reWrapDetails = /\{\n\/\* \[wrapped with (.+)\] \*/, reSplitDetails = /,? & /; function getWrapDetails(source) { var match = source.match(reWrapDetails); return match ? match[1].split(reSplitDetails) : []; } var reWrapComment = /\{(?:\n\/\* \[wrapped with .+\] \*\/)?\n?/; function insertWrapDetails(source, details) { var length = details.length; if (!length) { return source; } var lastIndex = length - 1; details[lastIndex] = (length > 1 ? "& " : "") + details[lastIndex]; details = details.join(length > 2 ? ", " : " "); return source.replace(reWrapComment, "{\n/* [wrapped with " + details + "] */\n"); } function constant(value) { return function() { return value; }; } var defineProperty = (function() { try { var func2 = getNative(Object, "defineProperty"); func2({}, "", {}); return func2; } catch (e) { } })(); var baseSetToString = !defineProperty ? identity : function(func2, string2) { return defineProperty(func2, "toString", { "configurable": true, "enumerable": false, "value": constant(string2), "writable": true }); }; var setToString = shortOut(baseSetToString); function arrayEach(array2, iteratee2) { var index = -1, length = array2 == null ? 0 : array2.length; while (++index < length) { if (iteratee2(array2[index], index, array2) === false) { break; } } return array2; } function baseFindIndex(array2, predicate, fromIndex, fromRight) { var length = array2.length, index = fromIndex + (fromRight ? 1 : -1); while (fromRight ? index-- : ++index <