@seayoo-web/request 1.2.2 → 1.3.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/dist/wx.js CHANGED
@@ -1 +1 @@
1
- import{isJsonLike as e,parseJSON as t,isStringRecord as r,noop as n,sleep as s,addParamsToString as o,isEmpty as a,getTypeGuard as i,isFullURL as u,getFullURL as c}from"@seayoo-web/utils";function l(){return l=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},l.apply(this,arguments)}function h(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}var d="message";function f(e,t){for(var r,n=function(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(r)return(r=r.call(e)).next.bind(r);if(Array.isArray(e)||(r=function(e,t){if(e){if("string"==typeof e)return h(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?h(e,t):void 0}}(e))){r&&(e=r);var n=0;return function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}(Array.isArray(t)?t:[t]);!(r=n()).done;){var s=r.value;if(s in e)return(o=e[s])?"string"==typeof o?o:JSON.stringify(o):""}var o;return""}var m=/<title>([^<]+)<\/title>/i,g=/<message>([^<]+)<\/message>/i;function v(e){var t=e.match(m);if(t)return t[1];var r=e.match(g);return r?r[1]:""}function y(e){return e>=200&&e<400}var p=function e(t,r,o,a,i){try{var u,c,l,h=i||0,d=Math.max(0,Math.min(10,null!=(u=null!=(c=null==a?void 0:a.maxRetry)?c:o.get("maxRetry"))?u:0)),f=null!=(l=null==a?void 0:a.retryResolve)?l:o.get("retryResolve"),m=o.get("logHandler")||n;m({type:"prepear",url:r,method:(null==a?void 0:a.method)||"GET",retry:h,maxRetry:d,message:0===h?"start":"retry "+h+"/"+d+" start",headers:null==a?void 0:a.headers,options:a});var g=Date.now();return Promise.resolve(t(r,o,a)).then(function(n){var i,u,c=n.status,l=Date.now()-g,v="[cost "+l+"]["+c+"] "+(c<0?n.body:"");m({type:"finished",url:r,method:n.method,retry:h,maxRetry:d,message:0===h?"finish "+v:"retry "+h+"/"+d+" finish "+v,response:n,headers:n.headers,cost:l});var p=y(c);if(!d||"network"===f&&c>0||"status"===f&&p||h>=d)return n;var b=null!=(i=null!=(u=null==a?void 0:a.retryInterval)?u:o.get("retryInterval"))?i:0;return Promise.resolve(s(Math.max(100,"function"==typeof b?b(h+1)||0:b))).then(function(){return Promise.resolve(e(t,r,o,a,h+1))})})}catch(e){return Promise.reject(e)}};function b(e,t,r,n,s,o){var a=s.get("message"),i=!1!==a&&!1!==(null==o?void 0:o.message)&&((null==o?void 0:o.message)||a);return!1!==i&&s.showMessage(!e.ok,"function"==typeof i?i(e,r,n,t):t),e}var P=function(n,s,o){try{return Promise.resolve(p(j,n,s,o)).then(function(a){return function(n,s,o,a){var i,u;if(n.status<0)return b({ok:!1,status:n.status,code:n.statusText,headers:{},message:"",data:null},n.method+" "+s+" "+n.statusText,n.method,s,o,a);y(n.status)||null==(u=o.get("errorHandler"))||u(n.status,n.method,s);var c,h,m,g,p,P=l({},(c=n.status,h=n.statusText,m=n.body,g=o.get("responseRule"),p=(null==a?void 0:a.responseRule)||g,y(c)?function(n,s,o,a){var i=n||{resolve:"body"},u={ok:!0,code:o,message:"",data:null};if(202===s||204===s||!a)return u;if("body"===i.resolve)return u.data=e(a)?t(a):a,u;var c=t(a);if(!c||!r(c))return u.ok=!1,u.code="ResponseFormatError",u.message="响应内容无法格式化为 Object",u;var l=i.statusField,h=i.statusOKValue||"",m=i.dataField||"data",g=i.messageField||d,v=i.ignoreMessage||"";if(l&&!(l in c))return u.ok=!1,u.code="ResponseFieldMissing",u.message="响应内容找不到状态字段 "+l,u;var y=l?c[l]+"":"";return u.ok=!l||y===h,u.code=y||o,u.data=m in c?c[m]:null,u.message=f(c,g),v&&u.message&&(Array.isArray(v)&&v.includes(u.message)||"string"==typeof v&&u.message===v)&&(u.message=""),u}(p.ok||g.ok,c,h,m):function(n,s,o){var a=n||{resolve:"json",messageField:d},i={ok:!1,code:s,message:o,data:null};switch(a.resolve){case"body":i.message=v(o)||o;break;case"json":i.message=v(o)||function(n,s){if(void 0===s&&(s=d),!e(n))return"";var o=t(n);return o&&r(o)&&f(o,s)||n}(o,a.messageField)}return i}(p.failed||g.failed,h,m)),{status:n.status,headers:Object.fromEntries(Object.entries(n.headers||{}).map(function(e){var t=e[1];return[e[0].toLowerCase(),t]}))});return null==(i=o.get("responseHandler"))||i(l({},P),n.method,s),b(P,P.ok?P.message:n.method+" "+s+" ["+(P.code||n.statusText)+"] "+(P.message||n.statusText),n.method,s,o,a)}(a,n,s,o)})}catch(e){return Promise.reject(e)}},j=function(e,t,r){try{return Promise.resolve(function(e,t,r){try{var n=Object.assign({method:"GET"},r),s=n.body instanceof FormData,o=s?"POST":n.method;"GET"!==o&&"HEAD"!==o&&"DELETE"!==o||void 0!==n.body&&(console.warn("request body is invalid with method get, head, delete"),delete n.body);var a=Object.assign(s?{}:{"Content-Type":"application/json;charset=utf-8"},n.headers),i=n.params||{},u={};Object.keys(i).forEach(function(e){var t;void 0!==i[e]&&(u[e]="string"==typeof(t=i[e])?t:Array.isArray(t)?t.join(","):t+"")});var c=t.getFullUrl(e),l=function(e){if(e)return e instanceof Blob||e instanceof ArrayBuffer||e instanceof FormData||e instanceof URLSearchParams||"string"==typeof e?e:JSON.stringify(e)}(n.body),h=n.timeout||t.get("timeout");return Promise.resolve(function(r){try{var n=function(n){var s;return r?n:Promise.resolve(null==(s=t.get("requestHandler"))?void 0:s(a,u,o,e))},s=t.get("requestTransformer"),i=function(){if(s)return Promise.resolve(s({headers:a,params:u,method:o,url:c,body:l})).then(function(e){return r=1,e})}();return Promise.resolve(i&&i.then?i.then(n):n(i))}catch(e){return Promise.reject(e)}}()).then(function(e){var r,s="string"==typeof e&&e?e:c;return null==(r=t.get("logHandler"))||r({type:"ready",url:s,method:o,headers:a,timeout:h,body:l}),{url:s,method:o,body:l,params:u,headers:a,timeout:h,credentials:n.credentials||t.get("credentials")}})}catch(e){return Promise.reject(e)}}(e,t,r)).then(function(e){var t="PATCH"===e.method?"POST":e.method,r=o(e.url,e.params);return globalThis.wx?new Promise(function(n){wx.request({url:r,data:e.body,header:e.headers,method:t,dataType:"string",responseType:"text",fail:function(){n({url:r,method:t,status:-1,statusText:"NetworkError",body:""})},success:function(s){var o;n({url:r,method:t,status:s.statusCode,statusText:s.statusCode+"",headers:l({},s.header),body:"HEAD"===e.method?"":(o=s.data,"string"==typeof o?o:o instanceof ArrayBuffer&&"TextDecoder"in globalThis?(new TextDecoder).decode(o):JSON.stringify(o))})}})}):{url:r,method:t,status:-2,statusText:"NotSupport",body:"NotFound namespace of wx"}})}catch(e){return Promise.reject(e)}},T=/*#__PURE__*/function(){function e(e){void 0===e&&(e=500),this.ttl=void 0,this.cache=void 0,this.cache={},this.ttl=Math.max(e,0)}var t=e.prototype;return t.getKey=function(e,t){return e+Object.keys(t||{}).sort().map(function(e){return e+"#"+(null==t?void 0:t[e])}).join(",")},t.updateTTL=function(e){this.ttl=Math.max(e,0)},t.get=function(e){if(0===this.ttl)return null;var t=this.cache[e];return t?t.ttl<Date.now()?(delete this.cache[e],null):t.res:null},t.set=function(e,t){0!==this.ttl&&(this.cache[e]={ttl:Date.now()+this.ttl,res:t})},e}(),x=/*#__PURE__*/function(){function e(e){this.config={baseURL:"",maxRetry:0,retryInterval:1e3,retryResolve:"network",timeout:5e3,cacheTTL:500,credentials:"same-origin",responseRule:{ok:{resolve:"body"},failed:{resolve:"json",messageField:"message"}}},e&&this.set(e)}var t=e.prototype;return t.set=function(e){if(e.baseURL&&!/^\/.+/.test(e.baseURL)&&!u(e.baseURL))throw console.warn("baseURL 需要以 / 开头,或者是完整的 url 地址"),new Error("BaseURLError");Object.assign(this.config,e)},t.get=function(e){return this.config[e]},t.getFullUrl=function(e){return e.startsWith("/")?c(e):c(e,this.config.baseURL)},t.showMessage=function(e,t){this.config.messageHandler&&t&&this.config.messageHandler(e,t)},e}(),w=/*#__PURE__*/function(){function e(e,t){this.agent=void 0,this.config=void 0,this.cache=void 0,this.config=new x(t),this.agent=e,this.cache=new T(this.config.get("cacheTTL")),this.setConfig=this.setConfig.bind(this),this.getConfig=this.getConfig.bind(this),this.get=this.get.bind(this),this.post=this.post.bind(this),this.del=this.del.bind(this),this.patch=this.patch.bind(this),this.put=this.put.bind(this),this.head=this.head.bind(this)}var t=e.prototype;return t.exec=function(e,t){try{return Promise.resolve(this.agent(e,this.config,t))}catch(e){return Promise.reject(e)}},t.guard=function(e,t,r){try{return Promise.resolve(function(e,t,r,n){if(t.ok&&!a(t.data)&&n){var s=i(n,"响应数据未能正确识别");return s.guard(t.data)||(console.error("ResponseCheckFaild",e,t.data),r.showMessage(!0,e+" "+s.message),t.data=null),t}return t}(e,t,this.config,r))}catch(e){return Promise.reject(e)}},t.setConfig=function(e){this.config.set(e),this.cache.updateTTL(this.config.get("cacheTTL"))},t.getConfig=function(e){return this.config.get(e)},t.head=function(e,t){try{var r=this,n=Object.assign({},t||null);n.method="HEAD";var s=r.guard;return Promise.resolve(r.exec(e,n)).then(function(t){return s.call(r,e,t,null)})}catch(e){return Promise.reject(e)}},t.get=function(e,t,r){try{var n,s=function(r){if(n)return r;var s=o.exec(e,a);o.cache.set(i,s);var u=o.guard;return Promise.resolve(s).then(function(r){return u.call(o,e,r,t||null)})},o=this,a=Object.assign({},r||null);a.method="GET";var i=o.cache.getKey(e,a.params),u=o.cache.get(i),c=function(){if(u){var r=o.guard;return Promise.resolve(u).then(function(s){var a=r.call(o,e,s,t||null);return n=1,a})}}();return Promise.resolve(c&&c.then?c.then(s):s(c))}catch(e){return Promise.reject(e)}},t.post=function(e,t,r,n){try{var s=this,o=Object.assign({},n||null);o.method="POST",o.body=t;var a=s.guard;return Promise.resolve(s.exec(e,o)).then(function(t){return a.call(s,e,t,r||null)})}catch(e){return Promise.reject(e)}},t.del=function(e,t,r){try{var n=this,s=Object.assign({},r||null);s.method="DELETE";var o=n.guard;return Promise.resolve(n.exec(e,s)).then(function(r){return o.call(n,e,r,t||null)})}catch(e){return Promise.reject(e)}},t.put=function(e,t,r,n){try{var s=this,o=Object.assign({},n||null);o.method="PUT",o.body=t;var a=s.guard;return Promise.resolve(s.exec(e,o)).then(function(t){return a.call(s,e,t,r||null)})}catch(e){return Promise.reject(e)}},t.patch=function(e,t,r,n){try{var s=this,o=Object.assign({},n||null);o.method="PATCH",o.body=t;var a=s.guard;return Promise.resolve(s.exec(e,o)).then(function(t){return a.call(s,e,t,r||null)})}catch(e){return Promise.reject(e)}},e}();function O(e){return new w(P,e)}var R=O(),E=R.setConfig,k=R.head,A=R.get,L=R.post,C=R.del,F=R.put;export{O as NetRequest,C as del,A as get,k as head,L as post,F as put,E as setGlobalConfig};
1
+ import{isJsonLike as e,parseJSON as t,isStringRecord as r,noop as n,sleep as s,addParamsToString as o,isEmpty as a,getTypeGuard as i,isFullURL as u,getFullURL as c}from"@seayoo-web/utils";function l(){return l=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},l.apply(this,arguments)}function h(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}var d="message";function f(e,t){for(var r,n=function(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(r)return(r=r.call(e)).next.bind(r);if(Array.isArray(e)||(r=function(e,t){if(e){if("string"==typeof e)return h(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?h(e,t):void 0}}(e))){r&&(e=r);var n=0;return function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}(Array.isArray(t)?t:[t]);!(r=n()).done;){var s=r.value;if(s in e)return(o=e[s])?"string"==typeof o?o:JSON.stringify(o):""}var o;return""}var m=/<title>([^<]+)<\/title>/i,g=/<message>([^<]+)<\/message>/i;function v(e){var t=e.match(m);if(t)return t[1];var r=e.match(g);return r?r[1]:""}function y(e){return e>=200&&e<400}var p=function e(t,r,o,a,i){try{var u,c,l,h=i||0,d=Math.max(0,Math.min(10,null!=(u=null!=(c=null==a?void 0:a.maxRetry)?c:o.get("maxRetry"))?u:0)),f=null!=(l=null==a?void 0:a.retryResolve)?l:o.get("retryResolve"),m=o.get("logHandler")||n;m({type:"prepear",url:r,method:(null==a?void 0:a.method)||"GET",retry:h,maxRetry:d,message:0===h?"start":"retry "+h+"/"+d+" start",headers:null==a?void 0:a.headers,options:a});var g=Date.now();return Promise.resolve(t(r,o,a)).then(function(n){var i,u,c=n.status,l=Date.now()-g,v="[cost "+l+"]["+c+"] "+(c<0?n.body:"");m({type:"finished",url:r,method:n.method,retry:h,maxRetry:d,message:0===h?"finish "+v:"retry "+h+"/"+d+" finish "+v,response:n,headers:n.headers,cost:l});var p=y(c);if(!d||"network"===f&&c>0||"status"===f&&p||Array.isArray(f)&&!f.includes(c)||"function"==typeof f&&!0!==f(n,h)||h>=d)return n;var b=null!=(i=null!=(u=null==a?void 0:a.retryInterval)?u:o.get("retryInterval"))?i:1e3;return Promise.resolve(s(Math.max(100,"2EB"===b?1e3*Math.pow(2,h):"function"==typeof b?b(h+1)||0:b))).then(function(){return Promise.resolve(e(t,r,o,a,h+1))})})}catch(e){return Promise.reject(e)}};function b(e,t,r,n,s,o){var a=s.get("message"),i=!1!==a&&!1!==(null==o?void 0:o.message)&&((null==o?void 0:o.message)||a);return!1!==i&&s.showMessage(!e.ok,"function"==typeof i?i(e,r,n,t):t),e}var P=function(n,s,o){try{return Promise.resolve(p(j,n,s,o)).then(function(a){return function(n,s,o,a){var i,u;if(n.status<0)return b({ok:!1,status:n.status,code:n.statusText,headers:{},message:"",data:null},n.method+" "+s+" "+n.statusText,n.method,s,o,a);y(n.status)||null==(u=o.get("errorHandler"))||u(n.status,n.method,s);var c,h,m,g,p,P=l({},(c=n.status,h=n.statusText,m=n.body,g=o.get("responseRule"),p=(null==a?void 0:a.responseRule)||g,y(c)?function(n,s,o,a){var i=n||{resolve:"body"},u={ok:!0,code:o,message:"",data:null};if(202===s||204===s||!a)return u;if("body"===i.resolve)return u.data=e(a)?t(a):a,u;var c=t(a);if(!c||!r(c))return u.ok=!1,u.code="ResponseFormatError",u.message="响应内容无法格式化为 Object",u;var l=i.statusField,h=i.statusOKValue||"",m=i.dataField||"data",g=i.messageField||d,v=i.ignoreMessage||"";if(l&&!(l in c))return u.ok=!1,u.code="ResponseFieldMissing",u.message="响应内容找不到状态字段 "+l,u;var y=l?c[l]+"":"";return u.ok=!l||y===h,u.code=y||o,u.data=!0===m?c:m in c?c[m]:null,u.message=f(c,g),v&&u.message&&(Array.isArray(v)&&v.includes(u.message)||"string"==typeof v&&u.message===v)&&(u.message=""),u}(p.ok||g.ok,c,h,m):function(n,s,o){var a=n||{resolve:"json",messageField:d},i={ok:!1,code:s,message:o,data:null};switch(a.resolve){case"body":i.message=v(o)||o;break;case"json":var u=function(n,s,o){if(void 0===o&&(o=d),!e(n))return{message:""};var a=t(n);return a&&r(a)?{code:s?f(a,s):"",message:f(a,o)||n}:{message:n}}(o,a.statusField,a.messageField),c=u.message;i.code=u.code||s,i.message=v(o)||c}return i}(p.failed||g.failed,h,m)),{status:n.status,headers:Object.fromEntries(Object.entries(n.headers||{}).map(function(e){var t=e[1];return[e[0].toLowerCase(),t]}))});return null==(i=o.get("responseHandler"))||i(l({},P),n.method,s),b(P,P.ok?P.message:n.method+" "+s+" ["+(P.code||n.statusText)+"] "+(P.message||n.statusText),n.method,s,o,a)}(a,n,s,o)})}catch(e){return Promise.reject(e)}},j=function(e,t,r){try{return Promise.resolve(function(e,t,r){try{var n=Object.assign({method:"GET"},r),s=n.body instanceof FormData,o=s?"POST":n.method;"GET"!==o&&"HEAD"!==o&&"DELETE"!==o||void 0!==n.body&&(console.warn("request body is invalid with method get, head, delete"),delete n.body);var a=Object.assign(s?{}:{"Content-Type":"application/json;charset=utf-8"},n.headers),i=n.params||{},u={};Object.keys(i).forEach(function(e){var t;void 0!==i[e]&&(u[e]="string"==typeof(t=i[e])?t:Array.isArray(t)?t.join(","):t+"")});var c=t.getFullUrl(e),l=function(e){if(e)return e instanceof Blob||e instanceof ArrayBuffer||e instanceof FormData||e instanceof URLSearchParams||"string"==typeof e?e:JSON.stringify(e)}(n.body),h=n.timeout||t.get("timeout");return Promise.resolve(function(r){try{var n=function(n){var s;return r?n:Promise.resolve(null==(s=t.get("requestHandler"))?void 0:s(a,u,o,e))},s=t.get("requestTransformer"),i=function(){if(s)return Promise.resolve(s({headers:a,params:u,method:o,url:c,body:l})).then(function(e){return r=1,e})}();return Promise.resolve(i&&i.then?i.then(n):n(i))}catch(e){return Promise.reject(e)}}()).then(function(e){var r,s="string"==typeof e&&e?e:c;return null==(r=t.get("logHandler"))||r({type:"ready",url:s,method:o,headers:a,timeout:h,body:l}),{url:s,method:o,body:l,params:u,headers:a,timeout:h,credentials:n.credentials||t.get("credentials")}})}catch(e){return Promise.reject(e)}}(e,t,r)).then(function(e){var t="PATCH"===e.method?"POST":e.method,r=o(e.url,e.params);return globalThis.wx?new Promise(function(n){wx.request({url:r,data:e.body,header:e.headers,method:t,dataType:"string",responseType:"text",fail:function(){n({url:r,method:t,status:-1,statusText:"NetworkError",body:""})},success:function(s){var o;n({url:r,method:t,status:s.statusCode,statusText:s.statusCode+"",headers:l({},s.header),body:"HEAD"===e.method?"":(o=s.data,"string"==typeof o?o:o instanceof ArrayBuffer&&"TextDecoder"in globalThis?(new TextDecoder).decode(o):JSON.stringify(o))})}})}):{url:r,method:t,status:-1,statusText:"NotSupport",body:"NotFound namespace of wx"}})}catch(e){return Promise.reject(e)}},T=/*#__PURE__*/function(){function e(e){void 0===e&&(e=500),this.ttl=void 0,this.cache=void 0,this.cache={},this.ttl=Math.max(e,0)}var t=e.prototype;return t.getKey=function(e,t){return e+Object.keys(t||{}).sort().map(function(e){return e+"#"+(null==t?void 0:t[e])}).join(",")},t.updateTTL=function(e){this.ttl=Math.max(e,0)},t.get=function(e){if(0===this.ttl)return null;var t=this.cache[e];return t?t.ttl<Date.now()?(delete this.cache[e],null):t.res:null},t.set=function(e,t){0!==this.ttl&&(this.cache[e]={ttl:Date.now()+this.ttl,res:t})},e}(),x=/*#__PURE__*/function(){function e(e){this.config={baseURL:"",maxRetry:0,retryInterval:1e3,retryResolve:"network",timeout:5e3,cacheTTL:500,credentials:"same-origin",responseRule:{ok:{resolve:"body"},failed:{resolve:"json",messageField:"message"}}},e&&this.set(e)}var t=e.prototype;return t.set=function(e){if(e.baseURL&&!/^\/.+/.test(e.baseURL)&&!u(e.baseURL))throw console.warn("baseURL 需要以 / 开头,或者是完整的 url 地址"),new Error("BaseURLError");Object.assign(this.config,e)},t.get=function(e){return this.config[e]},t.getFullUrl=function(e){return e.startsWith("/")?c(e):c(e,this.config.baseURL)},t.showMessage=function(e,t){this.config.messageHandler&&t&&this.config.messageHandler(e,t)},e}(),w=/*#__PURE__*/function(){function e(e,t){this.agent=void 0,this.config=void 0,this.cache=void 0,this.config=new x(t),this.agent=e,this.cache=new T(this.config.get("cacheTTL")),this.setConfig=this.setConfig.bind(this),this.getConfig=this.getConfig.bind(this),this.get=this.get.bind(this),this.post=this.post.bind(this),this.del=this.del.bind(this),this.patch=this.patch.bind(this),this.put=this.put.bind(this),this.head=this.head.bind(this)}var t=e.prototype;return t.exec=function(e,t){try{return Promise.resolve(this.agent(e,this.config,t))}catch(e){return Promise.reject(e)}},t.guard=function(e,t,r){try{return Promise.resolve(function(e,t,r,n){if(t.ok&&!a(t.data)&&n){var s=i(n,"响应数据未能正确识别");return s.guard(t.data)||(console.error("ResponseCheckFaild",e,t.data),r.showMessage(!0,e+" "+s.message),t.data=null),t}return t}(e,t,this.config,r))}catch(e){return Promise.reject(e)}},t.setConfig=function(e){this.config.set(e),this.cache.updateTTL(this.config.get("cacheTTL"))},t.getConfig=function(e){return this.config.get(e)},t.head=function(e,t){try{var r=this,n=Object.assign({},t||null);n.method="HEAD";var s=r.guard;return Promise.resolve(r.exec(e,n)).then(function(t){return s.call(r,e,t,null)})}catch(e){return Promise.reject(e)}},t.get=function(e,t,r){try{var n,s=function(r){if(n)return r;var s=o.exec(e,a);o.cache.set(i,s);var u=o.guard;return Promise.resolve(s).then(function(r){return u.call(o,e,r,t||null)})},o=this,a=Object.assign({},r||null);a.method="GET";var i=o.cache.getKey(e,a.params),u=o.cache.get(i),c=function(){if(u){var r=o.guard;return Promise.resolve(u).then(function(s){var a=r.call(o,e,s,t||null);return n=1,a})}}();return Promise.resolve(c&&c.then?c.then(s):s(c))}catch(e){return Promise.reject(e)}},t.post=function(e,t,r,n){try{var s=this,o=Object.assign({},n||null);o.method="POST",o.body=t;var a=s.guard;return Promise.resolve(s.exec(e,o)).then(function(t){return a.call(s,e,t,r||null)})}catch(e){return Promise.reject(e)}},t.del=function(e,t,r){try{var n=this,s=Object.assign({},r||null);s.method="DELETE";var o=n.guard;return Promise.resolve(n.exec(e,s)).then(function(r){return o.call(n,e,r,t||null)})}catch(e){return Promise.reject(e)}},t.put=function(e,t,r,n){try{var s=this,o=Object.assign({},n||null);o.method="PUT",o.body=t;var a=s.guard;return Promise.resolve(s.exec(e,o)).then(function(t){return a.call(s,e,t,r||null)})}catch(e){return Promise.reject(e)}},t.patch=function(e,t,r,n){try{var s=this,o=Object.assign({},n||null);o.method="PATCH",o.body=t;var a=s.guard;return Promise.resolve(s.exec(e,o)).then(function(t){return a.call(s,e,t,r||null)})}catch(e){return Promise.reject(e)}},e}();function O(e){return new w(P,e)}var R=O(),A=R.setConfig,E=R.head,k=R.get,L=R.post,C=R.del,F=R.put;export{O as NetRequest,C as del,k as get,E as head,L as post,F as put,A as setGlobalConfig};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seayoo-web/request",
3
- "version": "1.2.2",
3
+ "version": "1.3.1",
4
4
  "description": "requst tools for seayoo web",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -11,27 +11,36 @@
11
11
  ".": {
12
12
  "types": "./dist/index.d.ts",
13
13
  "import": "./dist/index.js",
14
- "require": "./dist/index.cjs"
14
+ "require": "./dist/index.cjs",
15
+ "default": "./dist/index.js"
15
16
  },
16
17
  "./node": {
18
+ "browser": null,
17
19
  "types": "./dist/node.d.ts",
18
20
  "import": "./dist/node.js",
19
- "require": "./dist/node.cjs"
21
+ "require": "./dist/node.cjs",
22
+ "default": "./dist/node.cjs"
20
23
  },
21
24
  "./dist/node": {
25
+ "browser": null,
22
26
  "types": "./dist/node.d.ts",
23
27
  "import": "./dist/node.js",
24
- "require": "./dist/node.cjs"
28
+ "require": "./dist/node.cjs",
29
+ "default": "./dist/node.cjs"
25
30
  },
26
31
  "./wx": {
27
32
  "types": "./dist/wx.d.ts",
28
33
  "import": "./dist/wx.js",
29
- "require": "./dist/wx.cjs"
34
+ "require": "./dist/wx.cjs",
35
+ "default": "./dist/wx.js"
30
36
  }
31
37
  },
32
38
  "publishConfig": {
33
39
  "access": "public"
34
40
  },
41
+ "engines": {
42
+ "node": ">=16"
43
+ },
35
44
  "scripts": {
36
45
  "build": "rimraf ./dist && microbundle src/*.ts --sourcemap false --format cjs,es",
37
46
  "dev": "microbundle watch",
@@ -54,9 +63,9 @@
54
63
  "commit-msg": "node scripts/verifyCommit.mjs $1"
55
64
  },
56
65
  "devDependencies": {
57
- "@types/node": "^20.10.5",
58
- "@typescript-eslint/eslint-plugin": "^6.16.0",
59
- "@typescript-eslint/parser": "^6.16.0",
66
+ "@types/node": "18.19.5",
67
+ "@typescript-eslint/eslint-plugin": "^6.18.1",
68
+ "@typescript-eslint/parser": "^6.18.1",
60
69
  "@vitest/browser": "^0.34.6",
61
70
  "@vitest/coverage-istanbul": "^0.34.6",
62
71
  "eslint": "^8.56.0",
@@ -65,7 +74,7 @@
65
74
  "happy-dom": "^12.10.3",
66
75
  "lint-staged": "^14.0.1",
67
76
  "microbundle": "^0.15.1",
68
- "msw": "^2.0.11",
77
+ "msw": "^2.0.13",
69
78
  "rimraf": "^5.0.5",
70
79
  "simple-git-hooks": "^2.9.0",
71
80
  "typescript": "~5.2.2",
@@ -73,6 +82,6 @@
73
82
  "webdriverio": "^8.27.0"
74
83
  },
75
84
  "dependencies": {
76
- "@seayoo-web/utils": "^1.12.6"
85
+ "@seayoo-web/utils": "^1.12.7"
77
86
  }
78
87
  }
package/vitest.config.ts DELETED
@@ -1,11 +0,0 @@
1
- import { defineConfig } from "vitest/config"
2
-
3
- export default defineConfig({
4
- test: {
5
- // ...
6
- environment: "happy-dom",
7
- coverage: {
8
- provider: "istanbul", // or 'v8'
9
- },
10
- },
11
- })