@allkit/http-client 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/dist/README.md +1 -0
- package/dist/adapter/base.d.ts +2 -0
- package/dist/adapter/taro.d.ts +2 -0
- package/dist/constants.d.ts +13 -0
- package/dist/core/Http.d.ts +26 -0
- package/dist/core/config.d.ts +7 -0
- package/dist/core/index.d.ts +4 -0
- package/dist/core/interceptor.d.ts +17 -0
- package/dist/core/request.d.ts +73 -0
- package/dist/http-client.es.js +1864 -0
- package/dist/http-client.umd.js +6 -0
- package/dist/index.d.ts +11 -0
- package/dist/package.json +22 -0
- package/dist/types.d.ts +69 -0
- package/dist/utils/index.d.ts +15 -0
- package/package.json +33 -0
- package/scripts/build.mjs +94 -0
- package/skill/SKILL.md +37 -0
- package/skill/examples/api.ts +50 -0
- package/skill/references/delete.md +17 -0
- package/skill/references/get.md +28 -0
- package/skill/references/patch.md +18 -0
- package/skill/references/post.md +27 -0
- package/skill/references/put.md +18 -0
- package/src/adapter/base.ts +1 -0
- package/src/adapter/taro.ts +35 -0
- package/src/constants.ts +20 -0
- package/src/core/Http.ts +82 -0
- package/src/core/config.ts +51 -0
- package/src/core/index.ts +6 -0
- package/src/core/interceptor.ts +98 -0
- package/src/core/request.ts +75 -0
- package/src/index.ts +18 -0
- package/src/types.ts +82 -0
- package/src/utils/index.ts +36 -0
- package/tsconfig.json +26 -0
- package/types/global.d.ts +16 -0
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
(function(h,e){typeof exports=="object"&&typeof module!="undefined"?e(exports):typeof define=="function"&&define.amd?define(["exports"],e):(h=typeof globalThis!="undefined"?globalThis:h||self,e(h["http-client"]={}))})(this,(function(exports){"use strict";var _=Object.defineProperty,H=Object.defineProperties;var g=Object.getOwnPropertyDescriptors;var w=Object.getOwnPropertySymbols;var k=Object.prototype.hasOwnProperty,N=Object.prototype.propertyIsEnumerable;var $=(h,e,t)=>e in h?_(h,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):h[e]=t,b=(h,e)=>{for(var t in e||(e={}))k.call(e,t)&&$(h,t,e[t]);if(w)for(var t of w(e))N.call(e,t)&&$(h,t,e[t]);return h},O=(h,e)=>H(h,g(e));var S=(h,e,t)=>$(h,typeof e!="symbol"?e+"":e,t);var F=(h,e,t)=>new Promise((s,r)=>{var i=a=>{try{o(t.next(a))}catch(c){r(c)}},n=a=>{try{o(t.throw(a))}catch(c){r(c)}},o=a=>a.done?s(a.value):Promise.resolve(a.value).then(i,n);o((t=t.apply(h,e)).next())});const EnumMethod={POST:"post"};var EnumContentType=(e=>(e.URL_ENCODED="application/x-www-form-urlencoded",e.JSON="application/json",e.FORM="multipart/form-data",e.TEXT="text/html",e))(EnumContentType||{});function bind(e,t){return function(){return e.apply(t,arguments)}}const{toString:toString$1}=Object.prototype,{getPrototypeOf}=Object,kindOf=(e=>t=>{const s=toString$1.call(t);return e[s]||(e[s]=s.slice(8,-1).toLowerCase())})(Object.create(null)),kindOfTest=e=>(e=e.toLowerCase(),t=>kindOf(t)===e),typeOfTest=e=>t=>typeof t===e,{isArray}=Array,isUndefined=typeOfTest("undefined");function isBuffer(e){return e!==null&&!isUndefined(e)&&e.constructor!==null&&!isUndefined(e.constructor)&&isFunction$1(e.constructor.isBuffer)&&e.constructor.isBuffer(e)}const isArrayBuffer=kindOfTest("ArrayBuffer");function isArrayBufferView(e){let t;return typeof ArrayBuffer!="undefined"&&ArrayBuffer.isView?t=ArrayBuffer.isView(e):t=e&&e.buffer&&isArrayBuffer(e.buffer),t}const isString=typeOfTest("string"),isFunction$1=typeOfTest("function"),isNumber=typeOfTest("number"),isObject$1=e=>e!==null&&typeof e=="object",isBoolean=e=>e===!0||e===!1,isPlainObject=e=>{if(kindOf(e)!=="object")return!1;const t=getPrototypeOf(e);return(t===null||t===Object.prototype||Object.getPrototypeOf(t)===null)&&!(Symbol.toStringTag in e)&&!(Symbol.iterator in e)},isDate=kindOfTest("Date"),isFile=kindOfTest("File"),isBlob=kindOfTest("Blob"),isFileList=kindOfTest("FileList"),isStream=e=>isObject$1(e)&&isFunction$1(e.pipe),isFormData=e=>{let t;return e&&(typeof FormData=="function"&&e instanceof FormData||isFunction$1(e.append)&&((t=kindOf(e))==="formdata"||t==="object"&&isFunction$1(e.toString)&&e.toString()==="[object FormData]"))},isURLSearchParams=kindOfTest("URLSearchParams"),trim=e=>e.trim?e.trim():e.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"");function forEach(e,t,{allOwnKeys:s=!1}={}){if(e===null||typeof e=="undefined")return;let r,i;if(typeof e!="object"&&(e=[e]),isArray(e))for(r=0,i=e.length;r<i;r++)t.call(null,e[r],r,e);else{const n=s?Object.getOwnPropertyNames(e):Object.keys(e),o=n.length;let a;for(r=0;r<o;r++)a=n[r],t.call(null,e[a],a,e)}}function findKey(e,t){t=t.toLowerCase();const s=Object.keys(e);let r=s.length,i;for(;r-- >0;)if(i=s[r],t===i.toLowerCase())return i;return null}const _global=typeof globalThis!="undefined"?globalThis:typeof self!="undefined"?self:typeof window!="undefined"?window:global,isContextDefined=e=>!isUndefined(e)&&e!==_global;function merge(){const{caseless:e}=isContextDefined(this)&&this||{},t={},s=(r,i)=>{const n=e&&findKey(t,i)||i;isPlainObject(t[n])&&isPlainObject(r)?t[n]=merge(t[n],r):isPlainObject(r)?t[n]=merge({},r):isArray(r)?t[n]=r.slice():t[n]=r};for(let r=0,i=arguments.length;r<i;r++)arguments[r]&&forEach(arguments[r],s);return t}const extend=(e,t,s,{allOwnKeys:r}={})=>(forEach(t,(i,n)=>{s&&isFunction$1(i)?e[n]=bind(i,s):e[n]=i},{allOwnKeys:r}),e),stripBOM=e=>(e.charCodeAt(0)===65279&&(e=e.slice(1)),e),inherits=(e,t,s,r)=>{e.prototype=Object.create(t.prototype,r),e.prototype.constructor=e,Object.defineProperty(e,"super",{value:t.prototype}),s&&Object.assign(e.prototype,s)},toFlatObject=(e,t,s,r)=>{let i,n,o;const a={};if(t=t||{},e==null)return t;do{for(i=Object.getOwnPropertyNames(e),n=i.length;n-- >0;)o=i[n],(!r||r(o,e,t))&&!a[o]&&(t[o]=e[o],a[o]=!0);e=s!==!1&&getPrototypeOf(e)}while(e&&(!s||s(e,t))&&e!==Object.prototype);return t},endsWith=(e,t,s)=>{e=String(e),(s===void 0||s>e.length)&&(s=e.length),s-=t.length;const r=e.indexOf(t,s);return r!==-1&&r===s},toArray=e=>{if(!e)return null;if(isArray(e))return e;let t=e.length;if(!isNumber(t))return null;const s=new Array(t);for(;t-- >0;)s[t]=e[t];return s},isTypedArray=(e=>t=>e&&t instanceof e)(typeof Uint8Array!="undefined"&&getPrototypeOf(Uint8Array)),forEachEntry=(e,t)=>{const r=(e&&e[Symbol.iterator]).call(e);let i;for(;(i=r.next())&&!i.done;){const n=i.value;t.call(e,n[0],n[1])}},matchAll=(e,t)=>{let s;const r=[];for(;(s=e.exec(t))!==null;)r.push(s);return r},isHTMLForm=kindOfTest("HTMLFormElement"),toCamelCase=e=>e.toLowerCase().replace(/[-_\s]([a-z\d])(\w*)/g,function(s,r,i){return r.toUpperCase()+i}),hasOwnProperty=(({hasOwnProperty:e})=>(t,s)=>e.call(t,s))(Object.prototype),isRegExp=kindOfTest("RegExp"),reduceDescriptors=(e,t)=>{const s=Object.getOwnPropertyDescriptors(e),r={};forEach(s,(i,n)=>{let o;(o=t(i,n,e))!==!1&&(r[n]=o||i)}),Object.defineProperties(e,r)},freezeMethods=e=>{reduceDescriptors(e,(t,s)=>{if(isFunction$1(e)&&["arguments","caller","callee"].indexOf(s)!==-1)return!1;const r=e[s];if(isFunction$1(r)){if(t.enumerable=!1,"writable"in t){t.writable=!1;return}t.set||(t.set=()=>{throw Error("Can not rewrite read-only method '"+s+"'")})}})},toObjectSet=(e,t)=>{const s={},r=i=>{i.forEach(n=>{s[n]=!0})};return isArray(e)?r(e):r(String(e).split(t)),s},noop=()=>{},toFiniteNumber=(e,t)=>(e=+e,Number.isFinite(e)?e:t),ALPHA="abcdefghijklmnopqrstuvwxyz",DIGIT="0123456789",ALPHABET={DIGIT,ALPHA,ALPHA_DIGIT:ALPHA+ALPHA.toUpperCase()+DIGIT},generateString=(e=16,t=ALPHABET.ALPHA_DIGIT)=>{let s="";const{length:r}=t;for(;e--;)s+=t[Math.random()*r|0];return s};function isSpecCompliantForm(e){return!!(e&&isFunction$1(e.append)&&e[Symbol.toStringTag]==="FormData"&&e[Symbol.iterator])}const toJSONObject=e=>{const t=new Array(10),s=(r,i)=>{if(isObject$1(r)){if(t.indexOf(r)>=0)return;if(!("toJSON"in r)){t[i]=r;const n=isArray(r)?[]:{};return forEach(r,(o,a)=>{const c=s(o,i+1);!isUndefined(c)&&(n[a]=c)}),t[i]=void 0,n}}return r};return s(e,0)},isAsyncFn=kindOfTest("AsyncFunction"),isThenable=e=>e&&(isObject$1(e)||isFunction$1(e))&&isFunction$1(e.then)&&isFunction$1(e.catch),utils$1={isArray,isArrayBuffer,isBuffer,isFormData,isArrayBufferView,isString,isNumber,isBoolean,isObject:isObject$1,isPlainObject,isUndefined,isDate,isFile,isBlob,isRegExp,isFunction:isFunction$1,isStream,isURLSearchParams,isTypedArray,isFileList,forEach,merge,extend,trim,stripBOM,inherits,toFlatObject,kindOf,kindOfTest,endsWith,toArray,forEachEntry,matchAll,isHTMLForm,hasOwnProperty,hasOwnProp:hasOwnProperty,reduceDescriptors,freezeMethods,toObjectSet,toCamelCase,noop,toFiniteNumber,findKey,global:_global,isContextDefined,ALPHABET,generateString,isSpecCompliantForm,toJSONObject,isAsyncFn,isThenable};function AxiosError$1(e,t,s,r,i){Error.call(this),Error.captureStackTrace?Error.captureStackTrace(this,this.constructor):this.stack=new Error().stack,this.message=e,this.name="AxiosError",t&&(this.code=t),s&&(this.config=s),r&&(this.request=r),i&&(this.response=i)}utils$1.inherits(AxiosError$1,Error,{toJSON:function(){return{message:this.message,name:this.name,description:this.description,number:this.number,fileName:this.fileName,lineNumber:this.lineNumber,columnNumber:this.columnNumber,stack:this.stack,config:utils$1.toJSONObject(this.config),code:this.code,status:this.response&&this.response.status?this.response.status:null}}});const prototype$1=AxiosError$1.prototype,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"].forEach(e=>{descriptors[e]={value:e}}),Object.defineProperties(AxiosError$1,descriptors),Object.defineProperty(prototype$1,"isAxiosError",{value:!0}),AxiosError$1.from=(e,t,s,r,i,n)=>{const o=Object.create(prototype$1);return utils$1.toFlatObject(e,o,function(c){return c!==Error.prototype},a=>a!=="isAxiosError"),AxiosError$1.call(o,e.message,t,s,r,i),o.cause=e,o.name=e.name,n&&Object.assign(o,n),o};const httpAdapter=null;function isVisitable(e){return utils$1.isPlainObject(e)||utils$1.isArray(e)}function removeBrackets(e){return utils$1.endsWith(e,"[]")?e.slice(0,-2):e}function renderKey(e,t,s){return e?e.concat(t).map(function(i,n){return i=removeBrackets(i),!s&&n?"["+i+"]":i}).join(s?".":""):t}function isFlatArray(e){return utils$1.isArray(e)&&!e.some(isVisitable)}const predicates=utils$1.toFlatObject(utils$1,{},null,function(t){return/^is[A-Z]/.test(t)});function toFormData$1(e,t,s){if(!utils$1.isObject(e))throw new TypeError("target must be an object");t=t||new FormData,s=utils$1.toFlatObject(s,{metaTokens:!0,dots:!1,indexes:!1},!1,function(d,y){return!utils$1.isUndefined(y[d])});const r=s.metaTokens,i=s.visitor||l,n=s.dots,o=s.indexes,c=(s.Blob||typeof Blob!="undefined"&&Blob)&&utils$1.isSpecCompliantForm(t);if(!utils$1.isFunction(i))throw new TypeError("visitor must be a function");function p(f){if(f===null)return"";if(utils$1.isDate(f))return f.toISOString();if(!c&&utils$1.isBlob(f))throw new AxiosError$1("Blob is not supported. Use a Buffer instead.");return utils$1.isArrayBuffer(f)||utils$1.isTypedArray(f)?c&&typeof Blob=="function"?new Blob([f]):Buffer.from(f):f}function l(f,d,y){let A=f;if(f&&!y&&typeof f=="object"){if(utils$1.endsWith(d,"{}"))d=r?d:d.slice(0,-2),f=JSON.stringify(f);else if(utils$1.isArray(f)&&isFlatArray(f)||(utils$1.isFileList(f)||utils$1.endsWith(d,"[]"))&&(A=utils$1.toArray(f)))return d=removeBrackets(d),A.forEach(function(R,T){!(utils$1.isUndefined(R)||R===null)&&t.append(o===!0?renderKey([d],T,n):o===null?d:d+"[]",p(R))}),!1}return isVisitable(f)?!0:(t.append(renderKey(y,d,n),p(f)),!1)}const u=[],m=Object.assign(predicates,{defaultVisitor:l,convertValue:p,isVisitable});function E(f,d){if(!utils$1.isUndefined(f)){if(u.indexOf(f)!==-1)throw Error("Circular reference detected in "+d.join("."));u.push(f),utils$1.forEach(f,function(A,x){(!(utils$1.isUndefined(A)||A===null)&&i.call(t,A,utils$1.isString(x)?x.trim():x,d,m))===!0&&E(A,d?d.concat(x):[x])}),u.pop()}}if(!utils$1.isObject(e))throw new TypeError("data must be an object");return E(e),t}function encode$1(e){const t={"!":"%21","'":"%27","(":"%28",")":"%29","~":"%7E","%20":"+","%00":"\0"};return encodeURIComponent(e).replace(/[!'()~]|%20|%00/g,function(r){return t[r]})}function AxiosURLSearchParams(e,t){this._pairs=[],e&&toFormData$1(e,this,t)}const prototype=AxiosURLSearchParams.prototype;prototype.append=function(t,s){this._pairs.push([t,s])},prototype.toString=function(t){const s=t?function(r){return t.call(this,r,encode$1)}:encode$1;return this._pairs.map(function(i){return s(i[0])+"="+s(i[1])},"").join("&")};function encode(e){return encodeURIComponent(e).replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+").replace(/%5B/gi,"[").replace(/%5D/gi,"]")}function buildURL(e,t,s){if(!t)return e;const r=s&&s.encode||encode,i=s&&s.serialize;let n;if(i?n=i(t,s):n=utils$1.isURLSearchParams(t)?t.toString():new AxiosURLSearchParams(t,s).toString(r),n){const o=e.indexOf("#");o!==-1&&(e=e.slice(0,o)),e+=(e.indexOf("?")===-1?"?":"&")+n}return e}class InterceptorManager{constructor(){this.handlers=[]}use(t,s,r){return this.handlers.push({fulfilled:t,rejected:s,synchronous:r?r.synchronous:!1,runWhen:r?r.runWhen:null}),this.handlers.length-1}eject(t){this.handlers[t]&&(this.handlers[t]=null)}clear(){this.handlers&&(this.handlers=[])}forEach(t){utils$1.forEach(this.handlers,function(r){r!==null&&t(r)})}}const transitionalDefaults={silentJSONParsing:!0,forcedJSONParsing:!0,clarifyTimeoutError:!1},URLSearchParams$1=typeof URLSearchParams!="undefined"?URLSearchParams:AxiosURLSearchParams,FormData$1=typeof FormData!="undefined"?FormData:null,Blob$1=typeof Blob!="undefined"?Blob:null,platform$1={isBrowser:!0,classes:{URLSearchParams:URLSearchParams$1,FormData:FormData$1,Blob:Blob$1},protocols:["http","https","file","blob","url","data"]},hasBrowserEnv=typeof window!="undefined"&&typeof document!="undefined",hasStandardBrowserEnv=(e=>hasBrowserEnv&&["ReactNative","NativeScript","NS"].indexOf(e)<0)(typeof navigator!="undefined"&&navigator.product),hasStandardBrowserWebWorkerEnv=typeof WorkerGlobalScope!="undefined"&&self instanceof WorkerGlobalScope&&typeof self.importScripts=="function",utils=Object.freeze(Object.defineProperty({__proto__:null,hasBrowserEnv,hasStandardBrowserEnv,hasStandardBrowserWebWorkerEnv},Symbol.toStringTag,{value:"Module"})),platform=b(b({},utils),platform$1);function toURLEncodedForm(e,t){return toFormData$1(e,new platform.classes.URLSearchParams,Object.assign({visitor:function(s,r,i,n){return platform.isNode&&utils$1.isBuffer(s)?(this.append(r,s.toString("base64")),!1):n.defaultVisitor.apply(this,arguments)}},t))}function parsePropPath(e){return utils$1.matchAll(/\w+|\[(\w*)]/g,e).map(t=>t[0]==="[]"?"":t[1]||t[0])}function arrayToObject(e){const t={},s=Object.keys(e);let r;const i=s.length;let n;for(r=0;r<i;r++)n=s[r],t[n]=e[n];return t}function formDataToJSON(e){function t(s,r,i,n){let o=s[n++];if(o==="__proto__")return!0;const a=Number.isFinite(+o),c=n>=s.length;return o=!o&&utils$1.isArray(i)?i.length:o,c?(utils$1.hasOwnProp(i,o)?i[o]=[i[o],r]:i[o]=r,!a):((!i[o]||!utils$1.isObject(i[o]))&&(i[o]=[]),t(s,r,i[o],n)&&utils$1.isArray(i[o])&&(i[o]=arrayToObject(i[o])),!a)}if(utils$1.isFormData(e)&&utils$1.isFunction(e.entries)){const s={};return utils$1.forEachEntry(e,(r,i)=>{t(parsePropPath(r),i,s,0)}),s}return null}function stringifySafely(e,t,s){if(utils$1.isString(e))try{return(t||JSON.parse)(e),utils$1.trim(e)}catch(r){if(r.name!=="SyntaxError")throw r}return(s||JSON.stringify)(e)}const defaults={transitional:transitionalDefaults,adapter:["xhr","http"],transformRequest:[function(t,s){const r=s.getContentType()||"",i=r.indexOf("application/json")>-1,n=utils$1.isObject(t);if(n&&utils$1.isHTMLForm(t)&&(t=new FormData(t)),utils$1.isFormData(t))return i?JSON.stringify(formDataToJSON(t)):t;if(utils$1.isArrayBuffer(t)||utils$1.isBuffer(t)||utils$1.isStream(t)||utils$1.isFile(t)||utils$1.isBlob(t))return t;if(utils$1.isArrayBufferView(t))return t.buffer;if(utils$1.isURLSearchParams(t))return s.setContentType("application/x-www-form-urlencoded;charset=utf-8",!1),t.toString();let a;if(n){if(r.indexOf("application/x-www-form-urlencoded")>-1)return toURLEncodedForm(t,this.formSerializer).toString();if((a=utils$1.isFileList(t))||r.indexOf("multipart/form-data")>-1){const c=this.env&&this.env.FormData;return toFormData$1(a?{"files[]":t}:t,c&&new c,this.formSerializer)}}return n||i?(s.setContentType("application/json",!1),stringifySafely(t)):t}],transformResponse:[function(t){const s=this.transitional||defaults.transitional,r=s&&s.forcedJSONParsing,i=this.responseType==="json";if(t&&utils$1.isString(t)&&(r&&!this.responseType||i)){const o=!(s&&s.silentJSONParsing)&&i;try{return JSON.parse(t)}catch(a){if(o)throw a.name==="SyntaxError"?AxiosError$1.from(a,AxiosError$1.ERR_BAD_RESPONSE,this,null,this.response):a}}return t}],timeout:0,xsrfCookieName:"XSRF-TOKEN",xsrfHeaderName:"X-XSRF-TOKEN",maxContentLength:-1,maxBodyLength:-1,env:{FormData:platform.classes.FormData,Blob:platform.classes.Blob},validateStatus:function(t){return t>=200&&t<300},headers:{common:{Accept:"application/json, text/plain, */*","Content-Type":void 0}}};utils$1.forEach(["delete","get","head","post","put","patch"],e=>{defaults.headers[e]={}});const ignoreDuplicateOf=utils$1.toObjectSet(["age","authorization","content-length","content-type","etag","expires","from","host","if-modified-since","if-unmodified-since","last-modified","location","max-forwards","proxy-authorization","referer","retry-after","user-agent"]),parseHeaders$1=e=>{const t={};let s,r,i;return e&&e.split(`
|
|
2
|
+
`).forEach(function(o){i=o.indexOf(":"),s=o.substring(0,i).trim().toLowerCase(),r=o.substring(i+1).trim(),!(!s||t[s]&&ignoreDuplicateOf[s])&&(s==="set-cookie"?t[s]?t[s].push(r):t[s]=[r]:t[s]=t[s]?t[s]+", "+r:r)}),t},$internals=Symbol("internals");function normalizeHeader(e){return e&&String(e).trim().toLowerCase()}function normalizeValue(e){return e===!1||e==null?e:utils$1.isArray(e)?e.map(normalizeValue):String(e)}function parseTokens(e){const t=Object.create(null),s=/([^\s,;=]+)\s*(?:=\s*([^,;]+))?/g;let r;for(;r=s.exec(e);)t[r[1]]=r[2];return t}const isValidHeaderName=e=>/^[-_a-zA-Z0-9^`|~,!#$%&'*+.]+$/.test(e.trim());function matchHeaderValue(e,t,s,r,i){if(utils$1.isFunction(r))return r.call(this,t,s);if(i&&(t=s),!!utils$1.isString(t)){if(utils$1.isString(r))return t.indexOf(r)!==-1;if(utils$1.isRegExp(r))return r.test(t)}}function formatHeader(e){return e.trim().toLowerCase().replace(/([a-z\d])(\w*)/g,(t,s,r)=>s.toUpperCase()+r)}function buildAccessors(e,t){const s=utils$1.toCamelCase(" "+t);["get","set","has"].forEach(r=>{Object.defineProperty(e,r+s,{value:function(i,n,o){return this[r].call(this,t,i,n,o)},configurable:!0})})}let AxiosHeaders$1=class{constructor(t){t&&this.set(t)}set(t,s,r){const i=this;function n(a,c,p){const l=normalizeHeader(c);if(!l)throw new Error("header name must be a non-empty string");const u=utils$1.findKey(i,l);(!u||i[u]===void 0||p===!0||p===void 0&&i[u]!==!1)&&(i[u||c]=normalizeValue(a))}const o=(a,c)=>utils$1.forEach(a,(p,l)=>n(p,l,c));return utils$1.isPlainObject(t)||t instanceof this.constructor?o(t,s):utils$1.isString(t)&&(t=t.trim())&&!isValidHeaderName(t)?o(parseHeaders$1(t),s):t!=null&&n(s,t,r),this}get(t,s){if(t=normalizeHeader(t),t){const r=utils$1.findKey(this,t);if(r){const i=this[r];if(!s)return i;if(s===!0)return parseTokens(i);if(utils$1.isFunction(s))return s.call(this,i,r);if(utils$1.isRegExp(s))return s.exec(i);throw new TypeError("parser must be boolean|regexp|function")}}}has(t,s){if(t=normalizeHeader(t),t){const r=utils$1.findKey(this,t);return!!(r&&this[r]!==void 0&&(!s||matchHeaderValue(this,this[r],r,s)))}return!1}delete(t,s){const r=this;let i=!1;function n(o){if(o=normalizeHeader(o),o){const a=utils$1.findKey(r,o);a&&(!s||matchHeaderValue(r,r[a],a,s))&&(delete r[a],i=!0)}}return utils$1.isArray(t)?t.forEach(n):n(t),i}clear(t){const s=Object.keys(this);let r=s.length,i=!1;for(;r--;){const n=s[r];(!t||matchHeaderValue(this,this[n],n,t,!0))&&(delete this[n],i=!0)}return i}normalize(t){const s=this,r={};return utils$1.forEach(this,(i,n)=>{const o=utils$1.findKey(r,n);if(o){s[o]=normalizeValue(i),delete s[n];return}const a=t?formatHeader(n):String(n).trim();a!==n&&delete s[n],s[a]=normalizeValue(i),r[a]=!0}),this}concat(...t){return this.constructor.concat(this,...t)}toJSON(t){const s=Object.create(null);return utils$1.forEach(this,(r,i)=>{r!=null&&r!==!1&&(s[i]=t&&utils$1.isArray(r)?r.join(", "):r)}),s}[Symbol.iterator](){return Object.entries(this.toJSON())[Symbol.iterator]()}toString(){return Object.entries(this.toJSON()).map(([t,s])=>t+": "+s).join(`
|
|
3
|
+
`)}get[Symbol.toStringTag](){return"AxiosHeaders"}static from(t){return t instanceof this?t:new this(t)}static concat(t,...s){const r=new this(t);return s.forEach(i=>r.set(i)),r}static accessor(t){const r=(this[$internals]=this[$internals]={accessors:{}}).accessors,i=this.prototype;function n(o){const a=normalizeHeader(o);r[a]||(buildAccessors(i,o),r[a]=!0)}return utils$1.isArray(t)?t.forEach(n):n(t),this}};AxiosHeaders$1.accessor(["Content-Type","Content-Length","Accept","Accept-Encoding","User-Agent","Authorization"]),utils$1.reduceDescriptors(AxiosHeaders$1.prototype,({value:e},t)=>{let s=t[0].toUpperCase()+t.slice(1);return{get:()=>e,set(r){this[s]=r}}}),utils$1.freezeMethods(AxiosHeaders$1);function transformData(e,t){const s=this||defaults,r=t||s,i=AxiosHeaders$1.from(r.headers);let n=r.data;return utils$1.forEach(e,function(a){n=a.call(s,n,i.normalize(),t?t.status:void 0)}),i.normalize(),n}function isCancel$1(e){return!!(e&&e.__CANCEL__)}function CanceledError$1(e,t,s){AxiosError$1.call(this,e==null?"canceled":e,AxiosError$1.ERR_CANCELED,t,s),this.name="CanceledError"}utils$1.inherits(CanceledError$1,AxiosError$1,{__CANCEL__:!0});function settle(e,t,s){const r=s.config.validateStatus;!s.status||!r||r(s.status)?e(s):t(new AxiosError$1("Request failed with status code "+s.status,[AxiosError$1.ERR_BAD_REQUEST,AxiosError$1.ERR_BAD_RESPONSE][Math.floor(s.status/100)-4],s.config,s.request,s))}const cookies=platform.hasStandardBrowserEnv?{write(e,t,s,r,i,n){const o=[e+"="+encodeURIComponent(t)];utils$1.isNumber(s)&&o.push("expires="+new Date(s).toGMTString()),utils$1.isString(r)&&o.push("path="+r),utils$1.isString(i)&&o.push("domain="+i),n===!0&&o.push("secure"),document.cookie=o.join("; ")},read(e){const t=document.cookie.match(new RegExp("(^|;\\s*)("+e+")=([^;]*)"));return t?decodeURIComponent(t[3]):null},remove(e){this.write(e,"",Date.now()-864e5)}}:{write(){},read(){return null},remove(){}};function isAbsoluteURL(e){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)}function combineURLs(e,t){return t?e.replace(/\/?\/$/,"")+"/"+t.replace(/^\/+/,""):e}function buildFullPath(e,t){return e&&!isAbsoluteURL(t)?combineURLs(e,t):t}const isURLSameOrigin=platform.hasStandardBrowserEnv?(function(){const t=/(msie|trident)/i.test(navigator.userAgent),s=document.createElement("a");let r;function i(n){let o=n;return t&&(s.setAttribute("href",o),o=s.href),s.setAttribute("href",o),{href:s.href,protocol:s.protocol?s.protocol.replace(/:$/,""):"",host:s.host,search:s.search?s.search.replace(/^\?/,""):"",hash:s.hash?s.hash.replace(/^#/,""):"",hostname:s.hostname,port:s.port,pathname:s.pathname.charAt(0)==="/"?s.pathname:"/"+s.pathname}}return r=i(window.location.href),function(o){const a=utils$1.isString(o)?i(o):o;return a.protocol===r.protocol&&a.host===r.host}})():(function(){return function(){return!0}})();function parseProtocol(e){const t=/^([-+\w]{1,25})(:?\/\/|:)/.exec(e);return t&&t[1]||""}function speedometer(e,t){e=e||10;const s=new Array(e),r=new Array(e);let i=0,n=0,o;return t=t!==void 0?t:1e3,function(c){const p=Date.now(),l=r[n];o||(o=p),s[i]=c,r[i]=p;let u=n,m=0;for(;u!==i;)m+=s[u++],u=u%e;if(i=(i+1)%e,i===n&&(n=(n+1)%e),p-o<t)return;const E=l&&p-l;return E?Math.round(m*1e3/E):void 0}}function progressEventReducer(e,t){let s=0;const r=speedometer(50,250);return i=>{const n=i.loaded,o=i.lengthComputable?i.total:void 0,a=n-s,c=r(a),p=n<=o;s=n;const l={loaded:n,total:o,progress:o?n/o:void 0,bytes:a,rate:c||void 0,estimated:c&&o&&p?(o-n)/c:void 0,event:i};l[t?"download":"upload"]=!0,e(l)}}const isXHRAdapterSupported=typeof XMLHttpRequest!="undefined",xhrAdapter=isXHRAdapterSupported&&function(e){return new Promise(function(s,r){let i=e.data;const n=AxiosHeaders$1.from(e.headers).normalize();let{responseType:o,withXSRFToken:a}=e,c;function p(){e.cancelToken&&e.cancelToken.unsubscribe(c),e.signal&&e.signal.removeEventListener("abort",c)}let l;if(utils$1.isFormData(i)){if(platform.hasStandardBrowserEnv||platform.hasStandardBrowserWebWorkerEnv)n.setContentType(!1);else if((l=n.getContentType())!==!1){const[d,...y]=l?l.split(";").map(A=>A.trim()).filter(Boolean):[];n.setContentType([d||"multipart/form-data",...y].join("; "))}}let u=new XMLHttpRequest;if(e.auth){const d=e.auth.username||"",y=e.auth.password?unescape(encodeURIComponent(e.auth.password)):"";n.set("Authorization","Basic "+btoa(d+":"+y))}const m=buildFullPath(e.baseURL,e.url);u.open(e.method.toUpperCase(),buildURL(m,e.params,e.paramsSerializer),!0),u.timeout=e.timeout;function E(){if(!u)return;const d=AxiosHeaders$1.from("getAllResponseHeaders"in u&&u.getAllResponseHeaders()),A={data:!o||o==="text"||o==="json"?u.responseText:u.response,status:u.status,statusText:u.statusText,headers:d,config:e,request:u};settle(function(R){s(R),p()},function(R){r(R),p()},A),u=null}if("onloadend"in u?u.onloadend=E:u.onreadystatechange=function(){!u||u.readyState!==4||u.status===0&&!(u.responseURL&&u.responseURL.indexOf("file:")===0)||setTimeout(E)},u.onabort=function(){u&&(r(new AxiosError$1("Request aborted",AxiosError$1.ECONNABORTED,e,u)),u=null)},u.onerror=function(){r(new AxiosError$1("Network Error",AxiosError$1.ERR_NETWORK,e,u)),u=null},u.ontimeout=function(){let y=e.timeout?"timeout of "+e.timeout+"ms exceeded":"timeout exceeded";const A=e.transitional||transitionalDefaults;e.timeoutErrorMessage&&(y=e.timeoutErrorMessage),r(new AxiosError$1(y,A.clarifyTimeoutError?AxiosError$1.ETIMEDOUT:AxiosError$1.ECONNABORTED,e,u)),u=null},platform.hasStandardBrowserEnv&&(a&&utils$1.isFunction(a)&&(a=a(e)),a||a!==!1&&isURLSameOrigin(m))){const d=e.xsrfHeaderName&&e.xsrfCookieName&&cookies.read(e.xsrfCookieName);d&&n.set(e.xsrfHeaderName,d)}i===void 0&&n.setContentType(null),"setRequestHeader"in u&&utils$1.forEach(n.toJSON(),function(y,A){u.setRequestHeader(A,y)}),utils$1.isUndefined(e.withCredentials)||(u.withCredentials=!!e.withCredentials),o&&o!=="json"&&(u.responseType=e.responseType),typeof e.onDownloadProgress=="function"&&u.addEventListener("progress",progressEventReducer(e.onDownloadProgress,!0)),typeof e.onUploadProgress=="function"&&u.upload&&u.upload.addEventListener("progress",progressEventReducer(e.onUploadProgress)),(e.cancelToken||e.signal)&&(c=d=>{u&&(r(!d||d.type?new CanceledError$1(null,e,u):d),u.abort(),u=null)},e.cancelToken&&e.cancelToken.subscribe(c),e.signal&&(e.signal.aborted?c():e.signal.addEventListener("abort",c)));const f=parseProtocol(m);if(f&&platform.protocols.indexOf(f)===-1){r(new AxiosError$1("Unsupported protocol "+f+":",AxiosError$1.ERR_BAD_REQUEST,e));return}u.send(i||null)})},knownAdapters={http:httpAdapter,xhr:xhrAdapter};utils$1.forEach(knownAdapters,(e,t)=>{if(e){try{Object.defineProperty(e,"name",{value:t})}catch(s){}Object.defineProperty(e,"adapterName",{value:t})}});const renderReason=e=>`- ${e}`,isResolvedHandle=e=>utils$1.isFunction(e)||e===null||e===!1,adapters={getAdapter:e=>{e=utils$1.isArray(e)?e:[e];const{length:t}=e;let s,r;const i={};for(let n=0;n<t;n++){s=e[n];let o;if(r=s,!isResolvedHandle(s)&&(r=knownAdapters[(o=String(s)).toLowerCase()],r===void 0))throw new AxiosError$1(`Unknown adapter '${o}'`);if(r)break;i[o||"#"+n]=r}if(!r){const n=Object.entries(i).map(([a,c])=>`adapter ${a} `+(c===!1?"is not supported by the environment":"is not available in the build"));let o=t?n.length>1?`since :
|
|
4
|
+
`+n.map(renderReason).join(`
|
|
5
|
+
`):" "+renderReason(n[0]):"as no adapter specified";throw new AxiosError$1("There is no suitable adapter to dispatch the request "+o,"ERR_NOT_SUPPORT")}return r},adapters:knownAdapters};function throwIfCancellationRequested(e){if(e.cancelToken&&e.cancelToken.throwIfRequested(),e.signal&&e.signal.aborted)throw new CanceledError$1(null,e)}function dispatchRequest(e){return throwIfCancellationRequested(e),e.headers=AxiosHeaders$1.from(e.headers),e.data=transformData.call(e,e.transformRequest),["post","put","patch"].indexOf(e.method)!==-1&&e.headers.setContentType("application/x-www-form-urlencoded",!1),adapters.getAdapter(e.adapter||defaults.adapter)(e).then(function(r){return throwIfCancellationRequested(e),r.data=transformData.call(e,e.transformResponse,r),r.headers=AxiosHeaders$1.from(r.headers),r},function(r){return isCancel$1(r)||(throwIfCancellationRequested(e),r&&r.response&&(r.response.data=transformData.call(e,e.transformResponse,r.response),r.response.headers=AxiosHeaders$1.from(r.response.headers))),Promise.reject(r)})}const headersToObject=e=>e instanceof AxiosHeaders$1?b({},e):e;function mergeConfig$1(e,t){t=t||{};const s={};function r(p,l,u){return utils$1.isPlainObject(p)&&utils$1.isPlainObject(l)?utils$1.merge.call({caseless:u},p,l):utils$1.isPlainObject(l)?utils$1.merge({},l):utils$1.isArray(l)?l.slice():l}function i(p,l,u){if(utils$1.isUndefined(l)){if(!utils$1.isUndefined(p))return r(void 0,p,u)}else return r(p,l,u)}function n(p,l){if(!utils$1.isUndefined(l))return r(void 0,l)}function o(p,l){if(utils$1.isUndefined(l)){if(!utils$1.isUndefined(p))return r(void 0,p)}else return r(void 0,l)}function a(p,l,u){if(u in t)return r(p,l);if(u in e)return r(void 0,p)}const c={url:n,method:n,data:n,baseURL:o,transformRequest:o,transformResponse:o,paramsSerializer:o,timeout:o,timeoutMessage:o,withCredentials:o,withXSRFToken:o,adapter:o,responseType:o,xsrfCookieName:o,xsrfHeaderName:o,onUploadProgress:o,onDownloadProgress:o,decompress:o,maxContentLength:o,maxBodyLength:o,beforeRedirect:o,transport:o,httpAgent:o,httpsAgent:o,cancelToken:o,socketPath:o,responseEncoding:o,validateStatus:a,headers:(p,l)=>i(headersToObject(p),headersToObject(l),!0)};return utils$1.forEach(Object.keys(Object.assign({},e,t)),function(l){const u=c[l]||i,m=u(e[l],t[l],l);utils$1.isUndefined(m)&&u!==a||(s[l]=m)}),s}const VERSION$1="1.6.8",validators$1={};["object","boolean","number","function","string","symbol"].forEach((e,t)=>{validators$1[e]=function(r){return typeof r===e||"a"+(t<1?"n ":" ")+e}});const deprecatedWarnings={};validators$1.transitional=function(t,s,r){function i(n,o){return"[Axios v"+VERSION$1+"] Transitional option '"+n+"'"+o+(r?". "+r:"")}return(n,o,a)=>{if(t===!1)throw new AxiosError$1(i(o," has been removed"+(s?" in "+s:"")),AxiosError$1.ERR_DEPRECATED);return s&&!deprecatedWarnings[o]&&(deprecatedWarnings[o]=!0,console.warn(i(o," has been deprecated since v"+s+" and will be removed in the near future"))),t?t(n,o,a):!0}};function assertOptions(e,t,s){if(typeof e!="object")throw new AxiosError$1("options must be an object",AxiosError$1.ERR_BAD_OPTION_VALUE);const r=Object.keys(e);let i=r.length;for(;i-- >0;){const n=r[i],o=t[n];if(o){const a=e[n],c=a===void 0||o(a,n,e);if(c!==!0)throw new AxiosError$1("option "+n+" must be "+c,AxiosError$1.ERR_BAD_OPTION_VALUE);continue}if(s!==!0)throw new AxiosError$1("Unknown option "+n,AxiosError$1.ERR_BAD_OPTION)}}const validator={assertOptions,validators:validators$1},validators=validator.validators;let Axios$1=class{constructor(t){this.defaults=t,this.interceptors={request:new InterceptorManager,response:new InterceptorManager}}request(t,s){return F(this,null,function*(){try{return yield this._request(t,s)}catch(r){if(r instanceof Error){let i;Error.captureStackTrace?Error.captureStackTrace(i={}):i=new Error;const n=i.stack?i.stack.replace(/^.+\n/,""):"";r.stack?n&&!String(r.stack).endsWith(n.replace(/^.+\n.+\n/,""))&&(r.stack+=`
|
|
6
|
+
`+n):r.stack=n}throw r}})}_request(t,s){typeof t=="string"?(s=s||{},s.url=t):s=t||{},s=mergeConfig$1(this.defaults,s);const{transitional:r,paramsSerializer:i,headers:n}=s;r!==void 0&&validator.assertOptions(r,{silentJSONParsing:validators.transitional(validators.boolean),forcedJSONParsing:validators.transitional(validators.boolean),clarifyTimeoutError:validators.transitional(validators.boolean)},!1),i!=null&&(utils$1.isFunction(i)?s.paramsSerializer={serialize:i}:validator.assertOptions(i,{encode:validators.function,serialize:validators.function},!0)),s.method=(s.method||this.defaults.method||"get").toLowerCase();let o=n&&utils$1.merge(n.common,n[s.method]);n&&utils$1.forEach(["delete","get","head","post","put","patch","common"],f=>{delete n[f]}),s.headers=AxiosHeaders$1.concat(o,n);const a=[];let c=!0;this.interceptors.request.forEach(function(d){typeof d.runWhen=="function"&&d.runWhen(s)===!1||(c=c&&d.synchronous,a.unshift(d.fulfilled,d.rejected))});const p=[];this.interceptors.response.forEach(function(d){p.push(d.fulfilled,d.rejected)});let l,u=0,m;if(!c){const f=[dispatchRequest.bind(this),void 0];for(f.unshift.apply(f,a),f.push.apply(f,p),m=f.length,l=Promise.resolve(s);u<m;)l=l.then(f[u++],f[u++]);return l}m=a.length;let E=s;for(u=0;u<m;){const f=a[u++],d=a[u++];try{E=f(E)}catch(y){d.call(this,y);break}}try{l=dispatchRequest.call(this,E)}catch(f){return Promise.reject(f)}for(u=0,m=p.length;u<m;)l=l.then(p[u++],p[u++]);return l}getUri(t){t=mergeConfig$1(this.defaults,t);const s=buildFullPath(t.baseURL,t.url);return buildURL(s,t.params,t.paramsSerializer)}};utils$1.forEach(["delete","get","head","options"],function(t){Axios$1.prototype[t]=function(s,r){return this.request(mergeConfig$1(r||{},{method:t,url:s,data:(r||{}).data}))}}),utils$1.forEach(["post","put","patch"],function(t){function s(r){return function(n,o,a){return this.request(mergeConfig$1(a||{},{method:t,headers:r?{"Content-Type":"multipart/form-data"}:{},url:n,data:o}))}}Axios$1.prototype[t]=s(),Axios$1.prototype[t+"Form"]=s(!0)});let CancelToken$1=class C{constructor(t){if(typeof t!="function")throw new TypeError("executor must be a function.");let s;this.promise=new Promise(function(n){s=n});const r=this;this.promise.then(i=>{if(!r._listeners)return;let n=r._listeners.length;for(;n-- >0;)r._listeners[n](i);r._listeners=null}),this.promise.then=i=>{let n;const o=new Promise(a=>{r.subscribe(a),n=a}).then(i);return o.cancel=function(){r.unsubscribe(n)},o},t(function(n,o,a){r.reason||(r.reason=new CanceledError$1(n,o,a),s(r.reason))})}throwIfRequested(){if(this.reason)throw this.reason}subscribe(t){if(this.reason){t(this.reason);return}this._listeners?this._listeners.push(t):this._listeners=[t]}unsubscribe(t){if(!this._listeners)return;const s=this._listeners.indexOf(t);s!==-1&&this._listeners.splice(s,1)}static source(){let t;return{token:new C(function(i){t=i}),cancel:t}}};function spread$1(e){return function(s){return e.apply(null,s)}}function isAxiosError$1(e){return utils$1.isObject(e)&&e.isAxiosError===!0}const HttpStatusCode$1={Continue:100,SwitchingProtocols:101,Processing:102,EarlyHints:103,Ok:200,Created:201,Accepted:202,NonAuthoritativeInformation:203,NoContent:204,ResetContent:205,PartialContent:206,MultiStatus:207,AlreadyReported:208,ImUsed:226,MultipleChoices:300,MovedPermanently:301,Found:302,SeeOther:303,NotModified:304,UseProxy:305,Unused:306,TemporaryRedirect:307,PermanentRedirect:308,BadRequest:400,Unauthorized:401,PaymentRequired:402,Forbidden:403,NotFound:404,MethodNotAllowed:405,NotAcceptable:406,ProxyAuthenticationRequired:407,RequestTimeout:408,Conflict:409,Gone:410,LengthRequired:411,PreconditionFailed:412,PayloadTooLarge:413,UriTooLong:414,UnsupportedMediaType:415,RangeNotSatisfiable:416,ExpectationFailed:417,ImATeapot:418,MisdirectedRequest:421,UnprocessableEntity:422,Locked:423,FailedDependency:424,TooEarly:425,UpgradeRequired:426,PreconditionRequired:428,TooManyRequests:429,RequestHeaderFieldsTooLarge:431,UnavailableForLegalReasons:451,InternalServerError:500,NotImplemented:501,BadGateway:502,ServiceUnavailable:503,GatewayTimeout:504,HttpVersionNotSupported:505,VariantAlsoNegotiates:506,InsufficientStorage:507,LoopDetected:508,NotExtended:510,NetworkAuthenticationRequired:511};Object.entries(HttpStatusCode$1).forEach(([e,t])=>{HttpStatusCode$1[t]=e});function createInstance(e){const t=new Axios$1(e),s=bind(Axios$1.prototype.request,t);return utils$1.extend(s,Axios$1.prototype,t,{allOwnKeys:!0}),utils$1.extend(s,t,null,{allOwnKeys:!0}),s.create=function(i){return createInstance(mergeConfig$1(e,i))},s}const axios=createInstance(defaults);axios.Axios=Axios$1,axios.CanceledError=CanceledError$1,axios.CancelToken=CancelToken$1,axios.isCancel=isCancel$1,axios.VERSION=VERSION$1,axios.toFormData=toFormData$1,axios.AxiosError=AxiosError$1,axios.Cancel=axios.CanceledError,axios.all=function(t){return Promise.all(t)},axios.spread=spread$1,axios.isAxiosError=isAxiosError$1,axios.mergeConfig=mergeConfig$1,axios.AxiosHeaders=AxiosHeaders$1,axios.formToJSON=e=>formDataToJSON(utils$1.isHTMLForm(e)?new FormData(e):e),axios.getAdapter=adapters.getAdapter,axios.HttpStatusCode=HttpStatusCode$1,axios.default=axios;const{Axios,AxiosError,CanceledError,isCancel,CancelToken,VERSION,all,Cancel,isAxiosError,spread,toFormData,AxiosHeaders,HttpStatusCode,formToJSON,getAdapter,mergeConfig}=axios,toString=Object.prototype.toString;function is(e,t){return toString.call(e)===`[object ${t}]`}function isObject(e){return e!==null&&is(e,"Object")}function isFunction(e){return typeof e=="function"}const isEmptyObject=e=>isObject(e)&&Object.keys(e).length===0;navigator.userAgent.toLowerCase().indexOf("kuasheng-2.0")>=0;function mergeInterceptor(e){const t={request:[],response:[],rejectRequest:[],rejectResponse:[]};if(e&&!isEmptyObject(e))for(const r in t){const i=t[r],n=e[r]||[];t[r]=i.concat(n)}return[...t.request.map(r=>({callback:r,type:"request"})),...t.response.map(r=>({callback:r,type:"response"})),...t.rejectRequest.map(r=>({callback:r,type:"rejectRequest"})),...t.rejectResponse.map(r=>({callback:r,type:"rejectResponse"}))].filter(Boolean)}function handleInterceptor(e,t){mergeInterceptor(t.interceptors).forEach(r=>{var o,a,c,p,l,u,m,E;const{type:i,callback:n}=r;i==="request"&&((a=(o=e.interceptors)==null?void 0:o.request)==null||a.use(n)),i==="response"&&((p=(c=e.interceptors)==null?void 0:c.response)==null||p.use(n)),i==="rejectRequest"&&((u=(l=e.interceptors)==null?void 0:l.request)==null||u.use(void 0,n)),i==="rejectResponse"&&((E=(m=e.interceptors)==null?void 0:m.response)==null||E.use(void 0,n))})}function commonResponseErrorMsg(e){var r;const t=((r=e.data)==null?void 0:r.message)||e.msg;let s="";switch(e.status){case 401:s="401:"+t;break;case 403:s=t;break;case 404:s="404: "+t;break;case 422:s="请求参数错误"+t;break;case 426:s="426: "+t;break;case 428:s="428: "+t;break;case 500:{s="服务器错误: "+t;break}default:s="未知的情况";break}return s}function createWXAdapter(e){return new Promise(function(t,s){const r=b({},e.headers);wx.request({method:e.method,url:e.baseURL+e.url,data:e.data,header:r,enableHttp2:!0,success(i){const o={data:i.data,status:i.statusCode,statusText:"OK",headers:r,config:e,request:e};t(o)},fail(i){var o;const n=commonResponseErrorMsg(i);!e.ignoreToast&&((o=e.showErrorMsg)==null||o.call(e,n)),i._config=e,s(i)}})})}const defaultInterceptors=()=>({response:e=>new Promise((t,s)=>{const{showErrorMsg:r,ignoreToast:i}=e.config;if(e.status===200)return e.data.code===0?t(e.data.data):((Array.isArray(i)&&!i.includes(e.data.code)||!i)&&(r==null||r(e.data.msg||e.message||"接口错误")),s(e));const n=commonResponseErrorMsg(e);return r==null||r(n),s(e)}),rejectResponse:e=>{var r,i;const{showErrorMsg:t,ignoreToast:s}=e.config;if(Array.isArray(s)&&!s.includes(e.data.code)||!s){const n=((i=(r=e.response)==null?void 0:r.data)==null?void 0:i.message)||e.message||"接口错误";t==null||t(n)}return Promise.reject(e.response)}}),defaultConfig={baseURL:"",headers:{method:EnumMethod.POST,"Content-Type":EnumContentType.JSON},timeout:1e4,loading:!1,method:"POST",interceptors:defaultInterceptors()};var commonjsGlobal=typeof globalThis!="undefined"?globalThis:typeof window!="undefined"?window:typeof global!="undefined"?global:typeof self!="undefined"?self:{};function getDefaultExportFromCjs(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var md5$1={exports:{}};var hasRequiredMd5;function requireMd5(){return hasRequiredMd5||(hasRequiredMd5=1,(function(module){(function(){var ERROR="input is invalid type",WINDOW=typeof window=="object",root=WINDOW?window:{};root.JS_MD5_NO_WINDOW&&(WINDOW=!1);var WEB_WORKER=!WINDOW&&typeof self=="object",NODE_JS=!root.JS_MD5_NO_NODE_JS&&typeof process=="object"&&process.versions&&process.versions.node;NODE_JS?root=commonjsGlobal:WEB_WORKER&&(root=self);var COMMON_JS=!root.JS_MD5_NO_COMMON_JS&&!0&&module.exports,ARRAY_BUFFER=!root.JS_MD5_NO_ARRAY_BUFFER&&typeof ArrayBuffer!="undefined",HEX_CHARS="0123456789abcdef".split(""),EXTRA=[128,32768,8388608,-2147483648],SHIFT=[0,8,16,24],OUTPUT_TYPES=["hex","array","digest","buffer","arrayBuffer","base64"],BASE64_ENCODE_CHAR="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".split(""),blocks=[],buffer8;if(ARRAY_BUFFER){var buffer=new ArrayBuffer(68);buffer8=new Uint8Array(buffer),blocks=new Uint32Array(buffer)}(root.JS_MD5_NO_NODE_JS||!Array.isArray)&&(Array.isArray=function(e){return Object.prototype.toString.call(e)==="[object Array]"}),ARRAY_BUFFER&&(root.JS_MD5_NO_ARRAY_BUFFER_IS_VIEW||!ArrayBuffer.isView)&&(ArrayBuffer.isView=function(e){return typeof e=="object"&&e.buffer&&e.buffer.constructor===ArrayBuffer});var createOutputMethod=function(e){return function(t){return new Md5(!0).update(t)[e]()}},createMethod=function(){var e=createOutputMethod("hex");NODE_JS&&(e=nodeWrap(e)),e.create=function(){return new Md5},e.update=function(r){return e.create().update(r)};for(var t=0;t<OUTPUT_TYPES.length;++t){var s=OUTPUT_TYPES[t];e[s]=createOutputMethod(s)}return e},nodeWrap=function(method){var crypto=eval("require('crypto')"),Buffer=eval("require('buffer').Buffer"),nodeMethod=function(e){if(typeof e=="string")return crypto.createHash("md5").update(e,"utf8").digest("hex");if(e==null)throw ERROR;return e.constructor===ArrayBuffer&&(e=new Uint8Array(e)),Array.isArray(e)||ArrayBuffer.isView(e)||e.constructor===Buffer?crypto.createHash("md5").update(new Buffer(e)).digest("hex"):method(e)};return nodeMethod};function Md5(e){if(e)blocks[0]=blocks[16]=blocks[1]=blocks[2]=blocks[3]=blocks[4]=blocks[5]=blocks[6]=blocks[7]=blocks[8]=blocks[9]=blocks[10]=blocks[11]=blocks[12]=blocks[13]=blocks[14]=blocks[15]=0,this.blocks=blocks,this.buffer8=buffer8;else if(ARRAY_BUFFER){var t=new ArrayBuffer(68);this.buffer8=new Uint8Array(t),this.blocks=new Uint32Array(t)}else this.blocks=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];this.h0=this.h1=this.h2=this.h3=this.start=this.bytes=this.hBytes=0,this.finalized=this.hashed=!1,this.first=!0}Md5.prototype.update=function(e){if(!this.finalized){var t,s=typeof e;if(s!=="string"){if(s==="object"){if(e===null)throw ERROR;if(ARRAY_BUFFER&&e.constructor===ArrayBuffer)e=new Uint8Array(e);else if(!Array.isArray(e)&&(!ARRAY_BUFFER||!ArrayBuffer.isView(e)))throw ERROR}else throw ERROR;t=!0}for(var r,i=0,n,o=e.length,a=this.blocks,c=this.buffer8;i<o;){if(this.hashed&&(this.hashed=!1,a[0]=a[16],a[16]=a[1]=a[2]=a[3]=a[4]=a[5]=a[6]=a[7]=a[8]=a[9]=a[10]=a[11]=a[12]=a[13]=a[14]=a[15]=0),t)if(ARRAY_BUFFER)for(n=this.start;i<o&&n<64;++i)c[n++]=e[i];else for(n=this.start;i<o&&n<64;++i)a[n>>2]|=e[i]<<SHIFT[n++&3];else if(ARRAY_BUFFER)for(n=this.start;i<o&&n<64;++i)r=e.charCodeAt(i),r<128?c[n++]=r:r<2048?(c[n++]=192|r>>6,c[n++]=128|r&63):r<55296||r>=57344?(c[n++]=224|r>>12,c[n++]=128|r>>6&63,c[n++]=128|r&63):(r=65536+((r&1023)<<10|e.charCodeAt(++i)&1023),c[n++]=240|r>>18,c[n++]=128|r>>12&63,c[n++]=128|r>>6&63,c[n++]=128|r&63);else for(n=this.start;i<o&&n<64;++i)r=e.charCodeAt(i),r<128?a[n>>2]|=r<<SHIFT[n++&3]:r<2048?(a[n>>2]|=(192|r>>6)<<SHIFT[n++&3],a[n>>2]|=(128|r&63)<<SHIFT[n++&3]):r<55296||r>=57344?(a[n>>2]|=(224|r>>12)<<SHIFT[n++&3],a[n>>2]|=(128|r>>6&63)<<SHIFT[n++&3],a[n>>2]|=(128|r&63)<<SHIFT[n++&3]):(r=65536+((r&1023)<<10|e.charCodeAt(++i)&1023),a[n>>2]|=(240|r>>18)<<SHIFT[n++&3],a[n>>2]|=(128|r>>12&63)<<SHIFT[n++&3],a[n>>2]|=(128|r>>6&63)<<SHIFT[n++&3],a[n>>2]|=(128|r&63)<<SHIFT[n++&3]);this.lastByteIndex=n,this.bytes+=n-this.start,n>=64?(this.start=n-64,this.hash(),this.hashed=!0):this.start=n}return this.bytes>4294967295&&(this.hBytes+=this.bytes/4294967296<<0,this.bytes=this.bytes%4294967296),this}},Md5.prototype.finalize=function(){if(!this.finalized){this.finalized=!0;var e=this.blocks,t=this.lastByteIndex;e[t>>2]|=EXTRA[t&3],t>=56&&(this.hashed||this.hash(),e[0]=e[16],e[16]=e[1]=e[2]=e[3]=e[4]=e[5]=e[6]=e[7]=e[8]=e[9]=e[10]=e[11]=e[12]=e[13]=e[14]=e[15]=0),e[14]=this.bytes<<3,e[15]=this.hBytes<<3|this.bytes>>>29,this.hash()}},Md5.prototype.hash=function(){var e,t,s,r,i,n,o=this.blocks;this.first?(e=o[0]-680876937,e=(e<<7|e>>>25)-271733879<<0,r=(-1732584194^e&2004318071)+o[1]-117830708,r=(r<<12|r>>>20)+e<<0,s=(-271733879^r&(e^-271733879))+o[2]-1126478375,s=(s<<17|s>>>15)+r<<0,t=(e^s&(r^e))+o[3]-1316259209,t=(t<<22|t>>>10)+s<<0):(e=this.h0,t=this.h1,s=this.h2,r=this.h3,e+=(r^t&(s^r))+o[0]-680876936,e=(e<<7|e>>>25)+t<<0,r+=(s^e&(t^s))+o[1]-389564586,r=(r<<12|r>>>20)+e<<0,s+=(t^r&(e^t))+o[2]+606105819,s=(s<<17|s>>>15)+r<<0,t+=(e^s&(r^e))+o[3]-1044525330,t=(t<<22|t>>>10)+s<<0),e+=(r^t&(s^r))+o[4]-176418897,e=(e<<7|e>>>25)+t<<0,r+=(s^e&(t^s))+o[5]+1200080426,r=(r<<12|r>>>20)+e<<0,s+=(t^r&(e^t))+o[6]-1473231341,s=(s<<17|s>>>15)+r<<0,t+=(e^s&(r^e))+o[7]-45705983,t=(t<<22|t>>>10)+s<<0,e+=(r^t&(s^r))+o[8]+1770035416,e=(e<<7|e>>>25)+t<<0,r+=(s^e&(t^s))+o[9]-1958414417,r=(r<<12|r>>>20)+e<<0,s+=(t^r&(e^t))+o[10]-42063,s=(s<<17|s>>>15)+r<<0,t+=(e^s&(r^e))+o[11]-1990404162,t=(t<<22|t>>>10)+s<<0,e+=(r^t&(s^r))+o[12]+1804603682,e=(e<<7|e>>>25)+t<<0,r+=(s^e&(t^s))+o[13]-40341101,r=(r<<12|r>>>20)+e<<0,s+=(t^r&(e^t))+o[14]-1502002290,s=(s<<17|s>>>15)+r<<0,t+=(e^s&(r^e))+o[15]+1236535329,t=(t<<22|t>>>10)+s<<0,e+=(s^r&(t^s))+o[1]-165796510,e=(e<<5|e>>>27)+t<<0,r+=(t^s&(e^t))+o[6]-1069501632,r=(r<<9|r>>>23)+e<<0,s+=(e^t&(r^e))+o[11]+643717713,s=(s<<14|s>>>18)+r<<0,t+=(r^e&(s^r))+o[0]-373897302,t=(t<<20|t>>>12)+s<<0,e+=(s^r&(t^s))+o[5]-701558691,e=(e<<5|e>>>27)+t<<0,r+=(t^s&(e^t))+o[10]+38016083,r=(r<<9|r>>>23)+e<<0,s+=(e^t&(r^e))+o[15]-660478335,s=(s<<14|s>>>18)+r<<0,t+=(r^e&(s^r))+o[4]-405537848,t=(t<<20|t>>>12)+s<<0,e+=(s^r&(t^s))+o[9]+568446438,e=(e<<5|e>>>27)+t<<0,r+=(t^s&(e^t))+o[14]-1019803690,r=(r<<9|r>>>23)+e<<0,s+=(e^t&(r^e))+o[3]-187363961,s=(s<<14|s>>>18)+r<<0,t+=(r^e&(s^r))+o[8]+1163531501,t=(t<<20|t>>>12)+s<<0,e+=(s^r&(t^s))+o[13]-1444681467,e=(e<<5|e>>>27)+t<<0,r+=(t^s&(e^t))+o[2]-51403784,r=(r<<9|r>>>23)+e<<0,s+=(e^t&(r^e))+o[7]+1735328473,s=(s<<14|s>>>18)+r<<0,t+=(r^e&(s^r))+o[12]-1926607734,t=(t<<20|t>>>12)+s<<0,i=t^s,e+=(i^r)+o[5]-378558,e=(e<<4|e>>>28)+t<<0,r+=(i^e)+o[8]-2022574463,r=(r<<11|r>>>21)+e<<0,n=r^e,s+=(n^t)+o[11]+1839030562,s=(s<<16|s>>>16)+r<<0,t+=(n^s)+o[14]-35309556,t=(t<<23|t>>>9)+s<<0,i=t^s,e+=(i^r)+o[1]-1530992060,e=(e<<4|e>>>28)+t<<0,r+=(i^e)+o[4]+1272893353,r=(r<<11|r>>>21)+e<<0,n=r^e,s+=(n^t)+o[7]-155497632,s=(s<<16|s>>>16)+r<<0,t+=(n^s)+o[10]-1094730640,t=(t<<23|t>>>9)+s<<0,i=t^s,e+=(i^r)+o[13]+681279174,e=(e<<4|e>>>28)+t<<0,r+=(i^e)+o[0]-358537222,r=(r<<11|r>>>21)+e<<0,n=r^e,s+=(n^t)+o[3]-722521979,s=(s<<16|s>>>16)+r<<0,t+=(n^s)+o[6]+76029189,t=(t<<23|t>>>9)+s<<0,i=t^s,e+=(i^r)+o[9]-640364487,e=(e<<4|e>>>28)+t<<0,r+=(i^e)+o[12]-421815835,r=(r<<11|r>>>21)+e<<0,n=r^e,s+=(n^t)+o[15]+530742520,s=(s<<16|s>>>16)+r<<0,t+=(n^s)+o[2]-995338651,t=(t<<23|t>>>9)+s<<0,e+=(s^(t|~r))+o[0]-198630844,e=(e<<6|e>>>26)+t<<0,r+=(t^(e|~s))+o[7]+1126891415,r=(r<<10|r>>>22)+e<<0,s+=(e^(r|~t))+o[14]-1416354905,s=(s<<15|s>>>17)+r<<0,t+=(r^(s|~e))+o[5]-57434055,t=(t<<21|t>>>11)+s<<0,e+=(s^(t|~r))+o[12]+1700485571,e=(e<<6|e>>>26)+t<<0,r+=(t^(e|~s))+o[3]-1894986606,r=(r<<10|r>>>22)+e<<0,s+=(e^(r|~t))+o[10]-1051523,s=(s<<15|s>>>17)+r<<0,t+=(r^(s|~e))+o[1]-2054922799,t=(t<<21|t>>>11)+s<<0,e+=(s^(t|~r))+o[8]+1873313359,e=(e<<6|e>>>26)+t<<0,r+=(t^(e|~s))+o[15]-30611744,r=(r<<10|r>>>22)+e<<0,s+=(e^(r|~t))+o[6]-1560198380,s=(s<<15|s>>>17)+r<<0,t+=(r^(s|~e))+o[13]+1309151649,t=(t<<21|t>>>11)+s<<0,e+=(s^(t|~r))+o[4]-145523070,e=(e<<6|e>>>26)+t<<0,r+=(t^(e|~s))+o[11]-1120210379,r=(r<<10|r>>>22)+e<<0,s+=(e^(r|~t))+o[2]+718787259,s=(s<<15|s>>>17)+r<<0,t+=(r^(s|~e))+o[9]-343485551,t=(t<<21|t>>>11)+s<<0,this.first?(this.h0=e+1732584193<<0,this.h1=t-271733879<<0,this.h2=s-1732584194<<0,this.h3=r+271733878<<0,this.first=!1):(this.h0=this.h0+e<<0,this.h1=this.h1+t<<0,this.h2=this.h2+s<<0,this.h3=this.h3+r<<0)},Md5.prototype.hex=function(){this.finalize();var e=this.h0,t=this.h1,s=this.h2,r=this.h3;return HEX_CHARS[e>>4&15]+HEX_CHARS[e&15]+HEX_CHARS[e>>12&15]+HEX_CHARS[e>>8&15]+HEX_CHARS[e>>20&15]+HEX_CHARS[e>>16&15]+HEX_CHARS[e>>28&15]+HEX_CHARS[e>>24&15]+HEX_CHARS[t>>4&15]+HEX_CHARS[t&15]+HEX_CHARS[t>>12&15]+HEX_CHARS[t>>8&15]+HEX_CHARS[t>>20&15]+HEX_CHARS[t>>16&15]+HEX_CHARS[t>>28&15]+HEX_CHARS[t>>24&15]+HEX_CHARS[s>>4&15]+HEX_CHARS[s&15]+HEX_CHARS[s>>12&15]+HEX_CHARS[s>>8&15]+HEX_CHARS[s>>20&15]+HEX_CHARS[s>>16&15]+HEX_CHARS[s>>28&15]+HEX_CHARS[s>>24&15]+HEX_CHARS[r>>4&15]+HEX_CHARS[r&15]+HEX_CHARS[r>>12&15]+HEX_CHARS[r>>8&15]+HEX_CHARS[r>>20&15]+HEX_CHARS[r>>16&15]+HEX_CHARS[r>>28&15]+HEX_CHARS[r>>24&15]},Md5.prototype.toString=Md5.prototype.hex,Md5.prototype.digest=function(){this.finalize();var e=this.h0,t=this.h1,s=this.h2,r=this.h3;return[e&255,e>>8&255,e>>16&255,e>>24&255,t&255,t>>8&255,t>>16&255,t>>24&255,s&255,s>>8&255,s>>16&255,s>>24&255,r&255,r>>8&255,r>>16&255,r>>24&255]},Md5.prototype.array=Md5.prototype.digest,Md5.prototype.arrayBuffer=function(){this.finalize();var e=new ArrayBuffer(16),t=new Uint32Array(e);return t[0]=this.h0,t[1]=this.h1,t[2]=this.h2,t[3]=this.h3,e},Md5.prototype.buffer=Md5.prototype.arrayBuffer,Md5.prototype.base64=function(){for(var e,t,s,r="",i=this.array(),n=0;n<15;)e=i[n++],t=i[n++],s=i[n++],r+=BASE64_ENCODE_CHAR[e>>>2]+BASE64_ENCODE_CHAR[(e<<4|t>>>4)&63]+BASE64_ENCODE_CHAR[(t<<2|s>>>6)&63]+BASE64_ENCODE_CHAR[s&63];return e=i[n],r+=BASE64_ENCODE_CHAR[e>>>2]+BASE64_ENCODE_CHAR[e<<4&63]+"==",r};var exports$1=createMethod();COMMON_JS?module.exports=exports$1:root.md5=exports$1})()})(md5$1)),md5$1.exports}var md5Exports=requireMd5();const md5=getDefaultExportFromCjs(md5Exports);function parseHeaders(e){const{url:t,data:s}=e,r=isFunction(e.token)?e.token()||"":e.token||"",i=()=>md5(md5(r).toUpperCase()+JSON.stringify(s||{})).toUpperCase(),n=O(b({},e.headers),{method:t,sign:i()});return r&&(n.Authorization="Bearer "+r),n}function parseBody(e){var i,n;const{data:t={}}=e,s=((i=e.headers)==null?void 0:i["Content-Type"])||((n=e.headers)==null?void 0:n["content-type"]),r={data:{}};switch(s){case EnumContentType.URL_ENCODED:{const o=new window.URLSearchParams;for(const[a,c]of Object.entries(t))o.append(a,c);r.data=o;break}case EnumContentType.FORM:{const o=new FormData;for(const[a,c]of Object.entries(t))o.append(a,c);r.data=o;break}default:r.data=t;break}return r}function parseRequest(e){const t=parseBody(e),s=parseHeaders(e);return b(O(b({},e),{headers:s}),t)}const h=class h{constructor(t){S(this,"_client",null);S(this,"defaultReqConfig");this.defaultReqConfig=t,this.createHttp()}static get instance(){return h._instance}static init(t){if(!h._instance){const s=Object.assign({},defaultConfig,t);h._instance=new h(s)}return h._instance}createHttp(){const t=axios.create(defaultConfig);handleInterceptor(t,this.defaultReqConfig),this._client=t}setBaseURL(t){this.defaultReqConfig.baseURL=t}setAdapter(t){typeof wx=="object"&&wx&&(t.adapter=createWXAdapter)}get client(){return this._client}request(t){const s=Object.assign({},this.defaultReqConfig,t),r=parseRequest(s);return this.setAdapter(r),this.client.request(r)}static get(t){return h.init().request(b({method:"get"},t))}static post(t){return h.init().request(b({method:"post"},t))}static put(t){return h.init().request(b({method:"put"},t))}static delete(t){return h.init().request(b({method:"delete"},t))}};S(h,"_instance",null);let Http=h;const useHttp=e=>(e.method=e.method||EnumMethod.POST,Http.init().request(e));exports.Http=Http,exports.default=Http,exports.defaultConfig=defaultConfig,exports.defaultInterceptors=defaultInterceptors,exports.useHttp=useHttp,Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { default as Http } from './core';
|
|
2
|
+
import { HttpRequestConfigWrap } from './types';
|
|
3
|
+
export * from './core';
|
|
4
|
+
export * from './types';
|
|
5
|
+
/**
|
|
6
|
+
* 发送请求
|
|
7
|
+
* 默认post
|
|
8
|
+
*/
|
|
9
|
+
export declare const useHttp: <T = any>(config: HttpRequestConfigWrap) => Promise<T>;
|
|
10
|
+
export { Http };
|
|
11
|
+
export default Http;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@allkit/http-client",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "this is a http-client package",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./http-client.umd.js",
|
|
7
|
+
"module":"./http-client.es.js",
|
|
8
|
+
"types": "index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": "./http-client.es.js",
|
|
12
|
+
"require": "./http-client.umd.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"keywords": ["lodash", "dayjs", "big.js","@allkit/http-client"],
|
|
16
|
+
"license": "MIT",
|
|
17
|
+
"author": "SPig",
|
|
18
|
+
"publishConfig":{"access":"public"},
|
|
19
|
+
"dependencies":{"axios":"1.6.8","js-md5":"0.7.3","qs":"6.11.0"},
|
|
20
|
+
"peerDependencies": {}
|
|
21
|
+
}
|
|
22
|
+
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { AxiosInstance, AxiosRequestConfig } from 'axios';
|
|
2
|
+
import { EnumContentType, EnumMethod } from './constants';
|
|
3
|
+
export type MethodValueType = (typeof EnumMethod)[keyof typeof EnumMethod] | string;
|
|
4
|
+
export interface HttpRequestConfig<T = any> extends AxiosRequestConfig<T> {
|
|
5
|
+
/**
|
|
6
|
+
* token,可以是个函数
|
|
7
|
+
*/
|
|
8
|
+
token?: string | (() => string);
|
|
9
|
+
/** userId ,可以是函数 */
|
|
10
|
+
userId?: string | (() => string);
|
|
11
|
+
loading?: boolean;
|
|
12
|
+
/**
|
|
13
|
+
* loading配置
|
|
14
|
+
*/
|
|
15
|
+
loadingOption?: {
|
|
16
|
+
show: () => void;
|
|
17
|
+
hide: () => void;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* 是否忽略错误提示
|
|
21
|
+
*/
|
|
22
|
+
ignoreToast?: boolean | Array<number | string>;
|
|
23
|
+
/**
|
|
24
|
+
* 错误提示
|
|
25
|
+
* @param msg - 后台返回错误信息
|
|
26
|
+
*/
|
|
27
|
+
showErrorMsg?: (msg: string) => void;
|
|
28
|
+
casToken?: boolean;
|
|
29
|
+
headers: {
|
|
30
|
+
method: MethodValueType;
|
|
31
|
+
'Content-Type': EnumContentType;
|
|
32
|
+
'content-type'?: EnumContentType;
|
|
33
|
+
'X-menu-id'?: string;
|
|
34
|
+
'x-from'?: number | string;
|
|
35
|
+
'X-associated-system-code'?: string;
|
|
36
|
+
[key: string]: string | number | undefined;
|
|
37
|
+
};
|
|
38
|
+
interceptors?: Partial<HttpInterceptor>;
|
|
39
|
+
}
|
|
40
|
+
export type HttpRequestConfigWrap<T = any> = Omit<HttpRequestConfig<T>, 'headers'> & {
|
|
41
|
+
headers?: Partial<HttpRequestConfig['headers']>;
|
|
42
|
+
};
|
|
43
|
+
export interface HttpResponse<T = any> {
|
|
44
|
+
data: T;
|
|
45
|
+
code: number;
|
|
46
|
+
msg: string;
|
|
47
|
+
success: boolean;
|
|
48
|
+
headers: HttpRequestConfig['headers'];
|
|
49
|
+
config: HttpRequestConfigWrap<T>;
|
|
50
|
+
[key: string]: any;
|
|
51
|
+
}
|
|
52
|
+
export interface HttpClient extends AxiosInstance {
|
|
53
|
+
create?: (config: HttpRequestConfig) => any;
|
|
54
|
+
}
|
|
55
|
+
export type HttpInterceptorRequest = (value: AxiosRequestConfig) => Record<string, any>;
|
|
56
|
+
export type HttpInterceptorResponse = (value: HttpResponse) => Promise<any> | HttpResponse;
|
|
57
|
+
export type HttpInterceptorReject = (error: any) => any;
|
|
58
|
+
export interface HttpInterceptor {
|
|
59
|
+
request: HttpInterceptorRequest | Array<HttpInterceptorRequest>;
|
|
60
|
+
response: HttpInterceptorResponse | Array<HttpInterceptorResponse>;
|
|
61
|
+
rejectRequest: HttpInterceptorReject | Array<HttpInterceptorReject>;
|
|
62
|
+
rejectResponse: HttpInterceptorReject | Array<HttpInterceptorReject>;
|
|
63
|
+
}
|
|
64
|
+
export interface MultiInterceptor {
|
|
65
|
+
request: Array<HttpInterceptorRequest>;
|
|
66
|
+
rejectRequest: Array<HttpInterceptorReject>;
|
|
67
|
+
rejectResponse: Array<HttpInterceptorReject>;
|
|
68
|
+
response: Array<HttpInterceptorResponse>;
|
|
69
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare function is(val: unknown, type: string): boolean;
|
|
2
|
+
export declare function isObject(val: any): val is Record<any, any>;
|
|
3
|
+
export declare function isFunction(val: unknown): val is Function;
|
|
4
|
+
/**
|
|
5
|
+
* 检测当前类型是否是空对象
|
|
6
|
+
* @param obj - 检测当前类型
|
|
7
|
+
* @returns 如果为空的对象则返回true、否则返回false
|
|
8
|
+
*/
|
|
9
|
+
export declare const isEmptyObject: (obj: any) => boolean;
|
|
10
|
+
/**
|
|
11
|
+
* 随机数
|
|
12
|
+
* @param count - 位数
|
|
13
|
+
*/
|
|
14
|
+
export declare const random: (count: number) => string;
|
|
15
|
+
export declare const isKuaShengClient: boolean;
|
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@allkit/http-client",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "this is a http-client package",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./src/index.ts",
|
|
7
|
+
"module": "./src/index.ts",
|
|
8
|
+
"types": "./src/index.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": "./src/index.ts"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"author": {
|
|
15
|
+
"name": "SPig"
|
|
16
|
+
},
|
|
17
|
+
"publishConfig": {
|
|
18
|
+
"access": "public"
|
|
19
|
+
},
|
|
20
|
+
"scripts": {
|
|
21
|
+
"test": "vitest",
|
|
22
|
+
"build": "node ./scripts/build.mjs",
|
|
23
|
+
"coverage": "vitest run --coverage"
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"axios": "1.6.8",
|
|
27
|
+
"js-md5": "0.7.3",
|
|
28
|
+
"qs": "6.11.0"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@types/js-md5": "^0.7.2"
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { createReadStream, createWriteStream } from 'fs'
|
|
2
|
+
import { createRequire } from 'module'
|
|
3
|
+
import { dirname, resolve } from 'path'
|
|
4
|
+
import { fileURLToPath } from 'url'
|
|
5
|
+
import fse from 'fs-extra'
|
|
6
|
+
// 引入 vite 的 build 方法,进行编译构建
|
|
7
|
+
import { build } from 'vite'
|
|
8
|
+
import { viteLibConfig } from '@allkit/vite-config'
|
|
9
|
+
|
|
10
|
+
const { outputFile } = fse
|
|
11
|
+
|
|
12
|
+
const require = createRequire(import.meta.url)
|
|
13
|
+
|
|
14
|
+
const __filename = fileURLToPath(import.meta.url)
|
|
15
|
+
const __dirname = dirname(__filename)
|
|
16
|
+
|
|
17
|
+
// 输出目录
|
|
18
|
+
const outputDir = resolve(__dirname, '../dist')
|
|
19
|
+
|
|
20
|
+
const {
|
|
21
|
+
version,
|
|
22
|
+
peerDependencies,
|
|
23
|
+
name,
|
|
24
|
+
description,
|
|
25
|
+
publishConfig,
|
|
26
|
+
dependencies,
|
|
27
|
+
type,
|
|
28
|
+
} = require('../package.json')
|
|
29
|
+
// 生成 package.json
|
|
30
|
+
const createPackageJson = () => {
|
|
31
|
+
const pkgName = name
|
|
32
|
+
const pkgUMD = './http-client.umd.js'
|
|
33
|
+
const pkgESM = './http-client.es.js'
|
|
34
|
+
|
|
35
|
+
const fileStr = `{
|
|
36
|
+
"name": "${pkgName}",
|
|
37
|
+
"version": "${version}",
|
|
38
|
+
"description": "${description}",
|
|
39
|
+
"type": "${type}",
|
|
40
|
+
"main": "${pkgUMD}",
|
|
41
|
+
"module":"${pkgESM}",
|
|
42
|
+
"types": "index.d.ts",
|
|
43
|
+
"exports": {
|
|
44
|
+
".": {
|
|
45
|
+
"import": "${pkgESM}",
|
|
46
|
+
"require": "${pkgUMD}"
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
"keywords": ["lodash", "dayjs", "big.js","${name || ''}"],
|
|
50
|
+
"license": "MIT",
|
|
51
|
+
"author": "SPig",
|
|
52
|
+
"publishConfig":${JSON.stringify(publishConfig)},
|
|
53
|
+
"dependencies":${JSON.stringify(dependencies)},
|
|
54
|
+
"peerDependencies": ${peerDependencies ? JSON.stringify(peerDependencies) : '{}'}
|
|
55
|
+
}
|
|
56
|
+
`
|
|
57
|
+
// 单个组件 or 全量
|
|
58
|
+
const filePath = resolve(outputDir, 'package.json')
|
|
59
|
+
outputFile(filePath, fileStr, 'utf-8')
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** 全量构建 */
|
|
63
|
+
const buildAll = async () => {
|
|
64
|
+
const config = viteLibConfig({
|
|
65
|
+
mode: 'production',
|
|
66
|
+
build: {
|
|
67
|
+
target: 'es2015',
|
|
68
|
+
lib: {
|
|
69
|
+
entry: './src/index.ts',
|
|
70
|
+
name: 'http-client',
|
|
71
|
+
fileName: (format) => `http-client.${format}.js`,
|
|
72
|
+
},
|
|
73
|
+
rollupOptions: {},
|
|
74
|
+
},
|
|
75
|
+
})
|
|
76
|
+
await build(config)
|
|
77
|
+
|
|
78
|
+
createPackageJson()
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// copy文件
|
|
82
|
+
// README.md
|
|
83
|
+
// 样式 index.css
|
|
84
|
+
const copyFiles = () => {
|
|
85
|
+
const markdown = createReadStream(resolve(__dirname, '../README.md'))
|
|
86
|
+
markdown.pipe(createWriteStream(resolve(__dirname, '../dist/README.md')))
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const buildLib = async () => {
|
|
90
|
+
await buildAll()
|
|
91
|
+
copyFiles()
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
buildLib()
|
package/skill/SKILL.md
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: http-client
|
|
3
|
+
description: HTTP 客户端封装,统一处理 API 请求、响应和错误 / HTTP client wrapper for handling API requests
|
|
4
|
+
author: allkit
|
|
5
|
+
category: network
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# @allkit/http-client
|
|
9
|
+
|
|
10
|
+
HTTP 客户端,统一处理 API 请求、响应和错误。
|
|
11
|
+
|
|
12
|
+
## Install
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
pnpm add @allkit/http-client
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Methods
|
|
19
|
+
|
|
20
|
+
| Method | Description |
|
|
21
|
+
|--------|-------------|
|
|
22
|
+
| [Http.get](./references/get.md) | GET 请求 |
|
|
23
|
+
| [Http.post](./references/post.md) | POST 请求 |
|
|
24
|
+
| [Http.put](./references/put.md) | PUT 请求 |
|
|
25
|
+
| [Http.delete](./references/delete.md) | DELETE 请求 |
|
|
26
|
+
| [Http.patch](./references/patch.md) | PATCH 请求 |
|
|
27
|
+
|
|
28
|
+
## Usage
|
|
29
|
+
|
|
30
|
+
```ts
|
|
31
|
+
import Http from '@allkit/http-client'
|
|
32
|
+
|
|
33
|
+
const res = await Http.get({
|
|
34
|
+
url: '/api/user/list',
|
|
35
|
+
params: { page: 1, pageSize: 10 }
|
|
36
|
+
})
|
|
37
|
+
```
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import Http from '@allkit/http-client'
|
|
2
|
+
|
|
3
|
+
type UserInfo = {
|
|
4
|
+
id: number
|
|
5
|
+
name: string
|
|
6
|
+
email: string
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
type UserListParams = {
|
|
10
|
+
page: number
|
|
11
|
+
pageSize: number
|
|
12
|
+
keyword?: string
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const apiGetUserList = (params: UserListParams) => {
|
|
16
|
+
return Http.get<{ list: UserInfo[]; total: number }>({
|
|
17
|
+
url: '/user/list',
|
|
18
|
+
params,
|
|
19
|
+
})
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export const apiCreateUser = (data: Omit<UserInfo, 'id'>) => {
|
|
23
|
+
return Http.post<UserInfo>({
|
|
24
|
+
url: '/user',
|
|
25
|
+
data,
|
|
26
|
+
})
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export const apiUpdateUser = (id: number, data: Partial<UserInfo>) => {
|
|
30
|
+
return Http.put<UserInfo>({
|
|
31
|
+
url: `/user/${id}`,
|
|
32
|
+
data,
|
|
33
|
+
})
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export const apiDeleteUser = (id: number) => {
|
|
37
|
+
return Http.delete({
|
|
38
|
+
url: `/user/${id}`,
|
|
39
|
+
})
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export const apiUploadFile = (file: File) => {
|
|
43
|
+
const formData = new FormData()
|
|
44
|
+
formData.append('file', file)
|
|
45
|
+
return Http.post<{ url: string }>({
|
|
46
|
+
url: '/upload',
|
|
47
|
+
data: formData,
|
|
48
|
+
headers: { 'content-Type': 'multipart/form-data' },
|
|
49
|
+
})
|
|
50
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# Http.get
|
|
2
|
+
|
|
3
|
+
发送 GET 请求
|
|
4
|
+
|
|
5
|
+
## Signature
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
function get<T = any>(config: RequestConfig): Promise<T>
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Config
|
|
12
|
+
|
|
13
|
+
| Property | Type | Required | Description |
|
|
14
|
+
|-----------|------|----------|-------------|
|
|
15
|
+
| `url` | `string` | Yes | 请求地址 |
|
|
16
|
+
| `params` | `object` | No | URL 参数 |
|
|
17
|
+
| `headers` | `object` | No | 请求头 |
|
|
18
|
+
| `timeout` | `number` | No | 超时时间 |
|
|
19
|
+
| `responseType` | `string` | No | 响应类型 |
|
|
20
|
+
|
|
21
|
+
## Example
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
const res = await Http.get<{ list: User[]; total: number }>({
|
|
25
|
+
url: '/api/user/list',
|
|
26
|
+
params: { page: 1, pageSize: 10 }
|
|
27
|
+
})
|
|
28
|
+
```
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# Http.patch
|
|
2
|
+
|
|
3
|
+
发送 PATCH 请求
|
|
4
|
+
|
|
5
|
+
## Signature
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
function patch<T = any>(config: RequestConfig): Promise<T>
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Example
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
const res = await Http.patch<User>({
|
|
15
|
+
url: '/api/user/1',
|
|
16
|
+
data: { name: '王五' }
|
|
17
|
+
})
|
|
18
|
+
```
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# Http.post
|
|
2
|
+
|
|
3
|
+
发送 POST 请求
|
|
4
|
+
|
|
5
|
+
## Signature
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
function post<T = any>(config: RequestConfig): Promise<T>
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Config
|
|
12
|
+
|
|
13
|
+
| Property | Type | Required | Description |
|
|
14
|
+
|-----------|------|----------|-------------|
|
|
15
|
+
| `url` | `string` | Yes | 请求地址 |
|
|
16
|
+
| `data` | `object` | No | 请求体数据 |
|
|
17
|
+
| `headers` | `object` | No | 请求头 |
|
|
18
|
+
| `timeout` | `number` | No | 超时时间 |
|
|
19
|
+
|
|
20
|
+
## Example
|
|
21
|
+
|
|
22
|
+
```ts
|
|
23
|
+
const res = await Http.post<User>({
|
|
24
|
+
url: '/api/user',
|
|
25
|
+
data: { name: '张三', email: 'test@example.com' }
|
|
26
|
+
})
|
|
27
|
+
```
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default {}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { commonResponseErrorMsg } from '../core/interceptor'
|
|
2
|
+
import type { HttpRequestConfig } from '../types'
|
|
3
|
+
|
|
4
|
+
export function createWXAdapter(config: HttpRequestConfig): any {
|
|
5
|
+
return new Promise(function (resolve, reject) {
|
|
6
|
+
const header = { ...config.headers }
|
|
7
|
+
// @ts-ignore
|
|
8
|
+
;(wx as Wx).request({
|
|
9
|
+
method: config.method,
|
|
10
|
+
url: config.baseURL + config.url!,
|
|
11
|
+
data: config.data,
|
|
12
|
+
header,
|
|
13
|
+
enableHttp2: true,
|
|
14
|
+
success(res: Record<string, any>) {
|
|
15
|
+
const responseData = res.data
|
|
16
|
+
const response = {
|
|
17
|
+
data: responseData,
|
|
18
|
+
status: res.statusCode,
|
|
19
|
+
statusText: 'OK',
|
|
20
|
+
headers: header,
|
|
21
|
+
config: config,
|
|
22
|
+
request: config
|
|
23
|
+
}
|
|
24
|
+
resolve(response)
|
|
25
|
+
},
|
|
26
|
+
fail(error: any) {
|
|
27
|
+
const msg = commonResponseErrorMsg(error)
|
|
28
|
+
!config.ignoreToast && config.showErrorMsg?.(msg)
|
|
29
|
+
error._config = config
|
|
30
|
+
|
|
31
|
+
reject(error)
|
|
32
|
+
}
|
|
33
|
+
})
|
|
34
|
+
})
|
|
35
|
+
}
|
package/src/constants.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/*
|
|
2
|
+
*请求方法常量
|
|
3
|
+
*/
|
|
4
|
+
export const EnumMethod = {
|
|
5
|
+
GET: 'get',
|
|
6
|
+
POST: 'post',
|
|
7
|
+
put: 'put',
|
|
8
|
+
PATCH: 'patch',
|
|
9
|
+
DELETE: 'delete',
|
|
10
|
+
} as const
|
|
11
|
+
|
|
12
|
+
/*
|
|
13
|
+
*请求方法常量
|
|
14
|
+
*/
|
|
15
|
+
export enum EnumContentType {
|
|
16
|
+
URL_ENCODED = 'application/x-www-form-urlencoded',
|
|
17
|
+
JSON = 'application/json',
|
|
18
|
+
FORM = 'multipart/form-data',
|
|
19
|
+
TEXT = 'text/html',
|
|
20
|
+
}
|