@seayoo-web/request 3.0.1 → 3.0.2

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.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./retry-C55r4dQg.cjs"),l=async function(t,r,u){return e.handleResponse(await e.retryRequest(f,t,r,u),t,r,u)},f=async function(t,r,u){const s=await e.convertOptions(t,r,u),a=s.method==="PATCH"?"POST":s.method,c=e.le(s.url,s.params);return e.Rt.wx?new Promise(d=>{wx.request({url:c,data:s.body,header:s.headers,method:a,dataType:"string",responseType:"text",fail(){d({url:c,method:a,status:-1,statusText:e.RequestInternalError.Unknown,body:""})},success(n){d({url:c,method:a,status:n.statusCode,statusText:n.statusCode+"",headers:{...n.header},body:s.method==="HEAD"||n.statusCode===204?"":p(n.data)})}})}):{url:c,method:a,status:-1,statusText:e.RequestInternalError.NotSupport,body:""}};function p(t){return typeof t=="string"?t:t instanceof ArrayBuffer&&e.Rt.TextDecoder?new TextDecoder().decode(t):JSON.stringify(t)}function i(t){return new e.NetRequestHandler(l,t)}const o=i(),y=o.setConfig,g=o.head,h=o.get,R=o.post,q=o.del,x=o.put;exports.NetRequest=i;exports.del=q;exports.get=h;exports.head=g;exports.post=R;exports.put=x;exports.setGlobalConfig=y;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./retry-BhqDL0mQ.cjs"),l=async function(t,r,u){return e.handleResponse(await e.retryRequest(f,t,r,u),t,r,u)},f=async function(t,r,u){const s=await e.convertOptions(t,r,u),a=s.method==="PATCH"?"POST":s.method,c=e.ue(s.url,s.params);return e.Ot.wx?new Promise(d=>{wx.request({url:c,data:s.body,header:s.headers,method:a,dataType:"string",responseType:"text",fail(){d({url:c,method:a,status:-1,statusText:e.RequestInternalError.Unknown,body:""})},success(n){d({url:c,method:a,status:n.statusCode,statusText:n.statusCode+"",headers:{...n.header},body:s.method==="HEAD"||n.statusCode===204?"":p(n.data)})}})}):{url:c,method:a,status:-1,statusText:e.RequestInternalError.NotSupport,body:""}};function p(t){return typeof t=="string"?t:t instanceof ArrayBuffer&&e.Ot.TextDecoder?new TextDecoder().decode(t):JSON.stringify(t)}function i(t){return new e.NetRequestHandler(l,t)}const o=i(),y=o.setConfig,g=o.head,h=o.get,q=o.post,x=o.del,R=o.put;exports.NetRequest=i;exports.del=x;exports.get=h;exports.head=g;exports.post=q;exports.put=R;exports.setGlobalConfig=y;
package/dist/wx.js CHANGED
@@ -1,20 +1,20 @@
1
- import { h as l, r as f, c as p, l as h, b as i, a as d, N as y } from "./retry-CiM_TrAz.js";
1
+ import { h as f, r as p, c as l, u as h, O as i, a as d, N as y } from "./retry-DjjIq-kG.js";
2
2
  const x = async function(t, n, r) {
3
- return l(await f(m, t, n, r), t, n, r);
3
+ return f(await p(m, t, n, r), t, n, r);
4
4
  }, m = async function(t, n, r) {
5
- const e = await p(t, n, r), a = e.method === "PATCH" ? "POST" : e.method, u = h(e.url, e.params);
5
+ const e = await l(t, n, r), u = e.method === "PATCH" ? "POST" : e.method, a = h(e.url, e.params);
6
6
  return i.wx ? new Promise((c) => {
7
7
  wx.request({
8
- url: u,
8
+ url: a,
9
9
  data: e.body,
10
10
  header: e.headers,
11
- method: a,
11
+ method: u,
12
12
  dataType: "string",
13
13
  responseType: "text",
14
14
  fail() {
15
15
  c({
16
- url: u,
17
- method: a,
16
+ url: a,
17
+ method: u,
18
18
  status: -1,
19
19
  statusText: d.Unknown,
20
20
  body: ""
@@ -22,8 +22,8 @@ const x = async function(t, n, r) {
22
22
  },
23
23
  success(o) {
24
24
  c({
25
- url: u,
26
- method: a,
25
+ url: a,
26
+ method: u,
27
27
  status: o.statusCode,
28
28
  statusText: o.statusCode + "",
29
29
  headers: { ...o.header },
@@ -32,8 +32,8 @@ const x = async function(t, n, r) {
32
32
  }
33
33
  });
34
34
  }) : {
35
- url: u,
36
- method: a,
35
+ url: a,
36
+ method: u,
37
37
  status: -1,
38
38
  statusText: d.NotSupport,
39
39
  body: ""
@@ -42,16 +42,16 @@ const x = async function(t, n, r) {
42
42
  function w(t) {
43
43
  return typeof t == "string" ? t : t instanceof ArrayBuffer && i.TextDecoder ? new TextDecoder().decode(t) : JSON.stringify(t);
44
44
  }
45
- function R(t) {
45
+ function T(t) {
46
46
  return new y(x, t);
47
47
  }
48
- const s = R(), g = s.setConfig, q = s.head, b = s.get, C = s.post, N = s.del, S = s.put;
48
+ const s = T(), q = s.setConfig, R = s.head, b = s.get, C = s.post, N = s.del, O = s.put;
49
49
  export {
50
- R as NetRequest,
50
+ T as NetRequest,
51
51
  N as del,
52
52
  b as get,
53
- q as head,
53
+ R as head,
54
54
  C as post,
55
- S as put,
56
- g as setGlobalConfig
55
+ O as put,
56
+ q as setGlobalConfig
57
57
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seayoo-web/request",
3
- "version": "3.0.1",
3
+ "version": "3.0.2",
4
4
  "description": "request tools for seayoo web",
5
5
  "type": "module",
6
6
  "source": "./src/index.ts",
@@ -59,13 +59,14 @@
59
59
  "happy-dom": "^12.10.3",
60
60
  "msw": "^2.7.0",
61
61
  "vitest": "^3.0.5",
62
- "@seayoo-web/utils": "^3.4.3"
62
+ "@seayoo-web/utils": "^3.4.4"
63
63
  },
64
64
  "scripts": {
65
+ "prebuild": "pnpm --F utils build",
65
66
  "build": "vite build && tsc --emitDeclarationOnly",
66
67
  "type-check": "tsc --noEmit",
67
68
  "lint": "eslint ./src/**/*.ts",
68
- "lint:fix": "eslint ./src/**/*.{ts,js} --fix",
69
+ "lint:fix": "eslint \"./src/**/*.{ts,js}\" --fix",
69
70
  "prepublish": "pnpm lint:fix && pnpm build",
70
71
  "test": "vitest --typecheck --dom",
71
72
  "coverage": "vitest run --coverage"
@@ -1,3 +0,0 @@
1
- "use strict";var J=Object.defineProperty;var z=(e,t,s)=>t in e?J(e,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[t]=s;var b=(e,t,s)=>z(e,typeof t!="symbol"?t+"":t,s);const c=typeof globalThis<"u"?globalThis:typeof self<"u"?self:typeof window<"u"?window:Function("return this")(),R={wx:"wx"in c&&j(c.wx)&&"getSystemInfo"in c.wx&&d(c.wx.getSystemInfo),fetch:"fetch"in c&&d(c.fetch),window:"window"in c&&j(c.window),requestAnimationFrame:"requestAnimationFrame"in c&&d(c.requestAnimationFrame),localStorage:"localStorage"in c&&j(c.localStorage)&&"getItem"in c.localStorage&&d(c.localStorage.getItem),sessionStorage:"sessionStorage"in c&&j(c.sessionStorage)&&"getItem"in c.sessionStorage&&d(c.sessionStorage.getItem),File:"File"in c&&d(c.File),Blob:"Blob"in c&&d(c.Blob),Proxy:"Proxy"in c&&d(c.Proxy),Request:"Request"in c&&d(c.Request),FormData:"FormData"in c&&d(c.FormData),TextDecoder:"TextDecoder"in c&&d(c.TextDecoder),ResizeObserver:"ResizeObserver"in c&&d(c.ResizeObserver),AbortController:"AbortController"in c&&d(c.AbortController)};function d(e){return typeof e=="function"}function j(e){return typeof e=="object"&&e!==null}function V(e){return new Promise(t=>setTimeout(t,Math.max(0,e)))}function W(){}function q(e,t){const s={log:console.log.bind(console),error:console.error.bind(console),warn:console.warn.bind(console)},r=`[${e}]`;return["log","error","warn"].forEach(o=>{const n=console[o];s[o]=(...a)=>{n.apply(console,[r,...a])}}),s}function Z(e){const t=e||"CustomError";return class extends Error{constructor(s){super(s),Object.defineProperty(this,"name",{value:t,enumerable:!1,configurable:!0}),"setPrototypeOf"in Object&&Object.setPrototypeOf(this,new.target.prototype),"captureStackTrace"in Error&&typeof Error.captureStackTrace=="function"&&Error.captureStackTrace(this,this.constructor)}}}const X=/^(?:https?:)?\/\/.+$/i,Q=/^https?:\/\/.+$/i,Y=/^\{[\d\D]*\}$/,ee=/^\[[\d\D]*\]$/;function F(e,t=!1){return t?X.test(e):Q.test(e)}function te(e){return e==null}function v(e,...t){if(!e||typeof e!="object")return!1;const s=Object.getPrototypeOf(e);return s!==Object.prototype&&s!==null?!1:t.every(r=>r in e)}function B(e){return Y.test(e)||ee.test(e)}function O(e){return e?e[0].toLowerCase()+e.slice(1):""}const _=/_\w*/,H=/-\w*/;function x(e){const t=_.test(e)?e.replace(/(?:^_*|_*$)/g,"").replace(/_+([^_])/g,(s,r)=>r.toUpperCase()):H.test(e)?e.replace(/(?:^-*|-*$)/g,"").replace(/-+(\w)/g,(s,r)=>r.toUpperCase()):e;return O(t)}function M(e){return _.test(e)?O(e).replace(/(?:^_*|_*$)/g,"").replace(/_+([^_])/g,(t,s)=>"_"+s.toLowerCase()):H.test(e)?O(e.replace(/(?:^-*|-*$)/g,"")).replace(/-+(\w)/g,(t,s)=>"_"+s.toLowerCase()):O(e).replace(/[A-Z]/g,t=>`_${t.toLowerCase()}`)}function A(e,t){try{const s=JSON.parse(e);return t?t(s)?s:null:s}catch{return null}}""+Math.random().toString(32).slice(2);function E(e,t=!1){return typeof e=="string"?x(e):Array.isArray(e)?e.map(s=>!t||typeof s=="string"?E(s):typeof s=="object"&&s?E(s,!0):s):v(e)?Object.keys(e).reduce((s,r)=>{const o=x(String(r)),n=o.charAt(0).toLowerCase()+o.slice(1);return s[n]=t?e[r]:E(e[r]),s},{}):e}function k(e,t=!1){return typeof e=="string"?M(e):Array.isArray(e)?e.map(s=>!t||typeof s=="string"?k(s):typeof s=="object"&&s?k(s,t):s):v(e)?Object.keys(e).reduce((s,r)=>{const o=M(String(r));return s[o]=t?e[r]:k(e[r]),s},{}):e}q("LoadUtils");async function se(e){return await new Promise(function(t){const s=document.getElementsByTagName("head")[0],r=document.createElement("script");r.setAttribute("type","text/javascript"),r.setAttribute("charset","utf-8"),r.onload=function(){s.removeChild(r),t(!0)},r.onerror=function(){s.removeChild(r),t(!1)},r.setAttribute("src",e),s.appendChild(r)})}q("Validator");function re(e,t="数据未能正确识别"){return typeof e=="function"?{guard:e,message:t}:{guard:e.guard,message:e.message||t}}function ne(e,t=""){return!t||F(e,!0)?D(e):(D(t)+"/"+e).replace(/\/{2,}/g,"/").replace(/:\//,"://")}function D(e){return F(e,!0)?e.startsWith("http")?e:("location"in globalThis?location.protocol:"https:")+e:("location"in globalThis?location.origin:"http://127.0.0.1")+"/"+e.replace(/^\/+/,"")}function oe(e,t){const s={};return(e.match(/([^=&#?]+)=[^&#]*/g)||[]).forEach(function(r){const o=r.split("="),n=o[0],a=decodeURIComponent(o[1]||"");s[n]!==void 0?s[n]+=","+a:s[n]=a}),t!==!0?s[t]||"":s}function ae(e,t){if(t){if(t===!0)return e.replace(/\?[^#]*/,"")}else return e;const s=e.split("#"),r=s[0].split("?"),o=r[0],n=r.length>1?r[1]:"",a=s.length>1?"#"+s[1]:"",i=typeof t=="string"?[t]:Array.isArray(t)?t:[];return!i.length||!n?s[0]+a:(i.map(u=>u.replace(/([\\(){}[\]^$+\-*?|])/g,"\\$1")),(o+"?"+n.replace(new RegExp("(?:^|&)(?:"+i.join("|")+")=[^&$]+","g"),"").replace(/^&/,"")).replace(/\?$/,"")+a)}function ce(e,t,s=!1){const r=typeof t=="string"?t:Object.keys(t).map(a=>`${a}=${encodeURIComponent(t[a])}`).join("&");if(!r)return e;const o=e.split("#");s&&(o[0]=ae(o[0],(r.match(/([^=&#?]+)=[^&#]+/g)||[]).map(a=>a.replace(/=.+$/,""))));const n=o[0].indexOf("?")+1?"&":"?";return(o[0]+n+r+(o.length>1?"#"+o[1]:"")).replace(/\?&/,"?")}function ie(e){const t=e.match(/(?:\?|&)([^=]+)(?:&|$)/g);return t?t.join("").replace(/(?:\?|^&+|&+$)/g,"").replace(/&{2}/g,"&").split("&").sort():[]}class ue{constructor(t=500){b(this,"ttl");b(this,"cache");this.cache={},this.ttl=Math.max(t,0)}getKey(t,s){const r=t.replace(/#.+/,""),o=r.replace(/\?.+/g,""),n=Object.assign(oe(r,!0),s),a=ie(r),i=Object.keys(n).sort().map(u=>`${u}#${n[u]}`);return`${o}_${i.join(",")}_${a.join(",")}`}updateTTL(t){this.ttl=Math.max(t,0)}get(t){if(this.ttl===0)return null;const s=this.cache[t];return s?s.ttl<Date.now()?(delete this.cache[t],null):s.res:null}set(t,s){this.ttl!==0&&(this.cache[t]={ttl:Date.now()+this.ttl,res:s})}}class I{constructor(t){b(this,"config",{baseURL:"/",maxRetry:0,retryInterval:100,retryResolve:"network",timeout:1e4,cacheTTL:500,credentials:"same-origin",defaultTypeGuardMessage:"响应数据未能正确识别",responseRule:{ok:{resolve:"body"},failed:{resolve:"json",messageField:"message"}}});t&&this.set(t)}set(t){if(t.baseURL&&!/^\/.+/.test(t.baseURL)&&!F(t.baseURL))throw console.warn("baseURL 需要以 / 开头,或者是完整的 url 地址"),new Error("BaseURLError");Object.assign(this.config,t)}get(t){return this.config[t]}getFullUrl(t){return ne(t,this.config.baseURL)}showMessage(t,s,r,o){this.config.messageHandler&&s&&this.config.messageHandler(t,s,r,o)}}var T=(e=>(e.UnexpectResponse="UnexpectResponse",e.Aborted="Aborted",e.Unknown="Unknown",e.NetworkError="NetworkError",e.Timeout="Timeout",e.NotSupport="NotSupport",e.URLFormatError="URLFormatError",e))(T||{});function le(e,t,s,r){if(t.ok&&!te(t.data)&&r){const o=re(r,s.get("defaultTypeGuardMessage"));return o.guard(t.data)||(t.code=T.UnexpectResponse,s.showMessage(!0,`${e} ${o.message}`,t.code,t.status),console.error(t.code,e,t.data),t.data=null,t.message=o.message),t}return t}class he{constructor(t,s){b(this,"agent");b(this,"config");b(this,"cache");this.config=new I(s),this.agent=t,this.cache=new ue(this.config.get("cacheTTL")),this.setConfig=this.setConfig.bind(this),this.getConfig=this.getConfig.bind(this),this.request=this.request.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)}async request(t,s){try{return await this.agent(t,this.config,s)}catch(r){return console.error("RequestError",r),{ok:!1,status:-9,code:T.Unknown,message:r instanceof Error?`${r.message}
2
- ${r.stack||""}`:String(r),headers:{},data:null}}}async guard(t,s,r){return le(t,s,this.config,r)}setConfig(t){this.config.set(t),this.cache.updateTTL(this.config.get("cacheTTL"))}getConfig(t){return this.config.get(t)}async head(t,s){const r=Object.assign({},s||null);return r.method="HEAD",this.guard(t,await this.request(t,r),null)}async get(t,s,r){const o=Object.assign({},r||null);o.method="GET";const n=this.cache.getKey(t,o.params),a=this.cache.get(n);if(a)return this.guard(t,await a,s||null);const i=this.request(t,o);return this.cache.set(n,i),this.guard(t,await i,s||null)}async post(t,s,r,o){const n=Object.assign({},o||null);return n.method="POST",n.body=s||{},this.guard(t,await this.request(t,n),r||null)}async del(t,s,r){const o=Object.assign({},r||null);return o.method="DELETE",this.guard(t,await this.request(t,o),s||null)}async put(t,s,r,o){const n=Object.assign({},o||null);return n.method="PUT",n.body=s||{},this.guard(t,await this.request(t,n),r||null)}async patch(t,s,r,o){const n=Object.assign({},o||null);return n.method="PATCH",n.body=s||{},this.guard(t,await this.request(t,n),r||null)}}async function de(e,t,s){var y;const r=Object.assign({method:"GET"},s),o=R.FormData?r.body instanceof FormData:!1,n=o&&r.method!=="POST"&&r.method!=="PUT"?"POST":r.method,a=n==="GET"||n==="HEAD"||n==="DELETE";a&&r.body!==void 0&&(console.warn("request body is invalid with method get, head, delete"),delete r.body);const i=Object.assign(o||a?{}:{"Content-Type":R.Blob&&r.body instanceof Blob?r.body.type||"application/octet-stream":"application/json;charset=utf-8"},r.headers),u=r.params||{},f={};Object.keys(u).forEach(w=>{u[w]!==void 0&&(f[w]=fe(u[w]))});const l=t.getFullUrl(e),h=ge(r.body),g=r.timeout||t.get("timeout"),m=await async function(){const w=t.get("requestTransformer");if(w)return await w({headers:i,params:f,method:n,url:l,body:h})}(),p=typeof m=="string"&&m?m:l;return(y=t.get("logHandler"))==null||y({type:"ready",url:p,method:n,headers:i,timeout:g,body:h}),{url:p,method:n,body:h,params:f,headers:i,timeout:g,abort:r.abort,credentials:r.credentials||t.get("credentials")}}function fe(e){return typeof e=="string"?e:Array.isArray(e)?e.join(","):e+""}function ge(e){if(e)return typeof e=="string"||e instanceof URLSearchParams||e instanceof ArrayBuffer||R.Blob&&e instanceof Blob||R.FormData&&e instanceof FormData?e:JSON.stringify(e)}const N="data",$="message";function me(e,t,s,r,o){const n=o||r;return S(e)?je(n.ok||r.ok,e,t,s):pe(n.failed||r.failed,t,s)}const ye=function(e){const t=[],s=e.failed||{resolve:"json"};switch(t.push("- 当http状态码 <200 或者 >=400 时"),s.resolve){case"body":t.push(" 将响应内容格式化为字符串并作为错误消息");break;case"json":t.push(" 将响应解析为json,并读取 "+(s.messageField||$)+" 作为错误消息");break}const r=e.ok||{resolve:"body"};switch(t.push("- 当http状态码 >=200 并且 <400 时"),r.resolve){case"body":t.push(" 将响应尝试解析为 json,并作为数据内容返回");break;case"json":t.push(" 将响应解析为 json,读取 "+(r.dataField||N)+" 作为响应数据,读取 "+(r.messageField||$)+" 作为提示消息"),r.statusField&&t.push(" 当 "+r.statusField+" 为 "+(r.statusOKValue||"空值")+" 时是成功提示,否则是错误消息"),r.ignoreMessage&&t.push(" 并忽略以下消息:"+r.ignoreMessage);break}return t.join(`
3
- `)};function pe(e,t,s){const r=e||{resolve:"json",messageField:$},o={ok:!1,code:t,message:s,data:null};switch(r.resolve){case"body":o.message=L(s)||s;break;case"json":const{code:n,message:a}=be(s,r.converter,r.statusField,r.messageField);o.code=n||t,o.message=L(s)||a;break}return o}function be(e,t,s,r=$){if(!B(e))return{message:""};const o=C(A(e),t);return!o||!v(o)?{message:e}:{code:s?U(o,s):"",message:U(o,r)||e}}function U(e,t){const s=Array.isArray(t)?t:[t];for(const r of s)if(r in e)return we(e[r]);return""}function we(e){return e?typeof e=="string"?e:JSON.stringify(e):""}const Re=/<title>([^<]+)<\/title>/i,$e=/<message>([^<]+)<\/message>/i;function L(e){const t=e.match(Re);if(t)return t[1];const s=e.match($e);return s?s[1]:""}function je(e,t,s,r){const o=e||{resolve:"body"},n={ok:!0,code:s,message:"",data:null};if(t===204||!r)return n;if(o.resolve==="body")return n.data=B(r)?C(A(r),e.converter):r,n;const a=C(A(r),e.converter);if(!a||!v(a))return n.ok=!1,n.code="ResponseFormatError",n.message="响应内容无法格式化为 Object",n;const i=o.statusField,u=o.statusOKValue||"",f=o.dataField||N,l=o.messageField||$,h=o.ignoreMessage||"";if(i&&!(i in a))return n.ok=!1,n.code="ResponseFieldMissing",n.message="响应内容找不到状态字段 "+i,n;const g=i?a[i]+"":"";return n.ok=i?g===u:!0,n.code=g||s,n.data=f===!0?a:f in a?a[f]:null,n.message=U(a,l),h&&n.message&&(Array.isArray(h)&&h.includes(n.message)||typeof h=="string"&&n.message===h)&&(n.message=""),n}function S(e){return e>=200&&e<400}function C(e,t){return t==="camelize"?E(e):t==="snakify"?k(e):e}const Oe=Z("APIError");function Ee(e){const t={};for(const o in e.headers)(o.startsWith("x-")||o.includes("trace")||o.includes("server")||/\b(?:id|uuid)\b/.test(o))&&(t[o]=e.headers[o]);const s=e.url.replace(/^(?:https?:)?\/*/i,"").replace(/\?.+/,""),r=e.status<0?"unknown":e.status;return{sentryError:new Oe(`${s} | ${r}${e.code?` | ${e.code}`:""}`),sentryTags:{...t,status:r,method:e.method,code:e.code||"unknown",message:e.message||"empty"},sentryExtra:{url:e.url,responseBody:e.body||"empty",responseHeaders:e.headers,rawError:e.error}}}function G(e){return e.reduce((t,[s,r])=>(s&&(t[s]=r||""),t),{})}function ke(e,t,s,r){var m;const o=e.status,n=e.method,a=G(Object.entries(e.headers||{}).map(([p,y])=>[p.toLowerCase(),y])),{ok:i,code:u,data:f,message:l}=me(o,e.statusText,e.body,s.get("responseRule"),r==null?void 0:r.responseRule);if(!S(o)){const p=Ee({url:e.url,method:e.method,status:o,code:u,message:l,body:e.body,headers:a,error:e.rawError});(s.get("errorHandler")||Fe)({url:t,method:n,status:o,code:u,message:l,headers:a,rawError:e.rawError,responseBody:e.body,...p})}if(o<0)return P({ok:!1,status:o,code:e.statusText,headers:{},message:"",data:null},`${n} ${t} ${e.statusText}`,n,t,s,r);const h={ok:i,data:f,code:u,message:l,status:o,headers:a};(m=s.get("responseHandler"))==null||m({...h},n,t);const g=i?l:l||e.statusText;return P(h,g,n,t,s,r)}function P(e,t,s,r,o,n){const a=o.get("message"),i=a===!1||(n==null?void 0:n.message)===!1?!1:(n==null?void 0:n.message)||a;if(i!==!1){const u=typeof i=="function"?i(e,s,r,t):t;u instanceof Error?o.showMessage(!0,u.message,e.code,e.status):u&&typeof u=="object"&&"message"in u?o.showMessage(!1,u.message,e.code,e.status):o.showMessage(!e.ok,u,e.code,e.status)}return e}function Fe(e){const t={};for(const s in e)s.startsWith("sentry")||(t[s]=e[s]);console.error("RequestError",t)}async function K(e,t,s,r,o){const n=o||0,a=Math.max(0,Math.min(10,(r==null?void 0:r.maxRetry)??s.get("maxRetry")??0)),i=(r==null?void 0:r.retryResolve)??s.get("retryResolve"),u=s.get("logHandler")||W;u({type:"prepare",url:t,method:(r==null?void 0:r.method)||"GET",retry:n,maxRetry:a,message:n===0?"start":`retry ${n}/${a} start`,headers:r==null?void 0:r.headers,options:r});const f=Date.now(),l=await e(t,s,r),h=l.status,g=Date.now()-f,m=`[cost ${g}][${h}] ${h<0?l.body:""}`;u({type:"finished",url:t,method:l.method,retry:n,maxRetry:a,message:n===0?`finish ${m}`:`retry ${n}/${a} finish ${m}`,response:l,headers:l.headers,cost:g});const p=S(h);if(!a||i==="network"&&h>0||i==="status"&&p||Array.isArray(i)&&!i.includes(h)||typeof i=="function"&&i(l,n)!==!0||n>=a)return l;const y=(r==null?void 0:r.retryInterval)??s.get("retryInterval")??100;return await V(Math.max(100,y==="2EB"?Math.pow(2,n)*100:typeof y=="function"?y(n+1)||0:y)),await K(e,t,s,r,n+1)}exports.$t=F;exports.Ge=se;exports.NetRequestHandler=he;exports.RequestGlobalConfig=I;exports.RequestInternalError=T;exports.Rt=R;exports.convertOptions=de;exports.fromEntries=G;exports.getResponseRulesDescription=ye;exports.handleResponse=ke;exports.le=ce;exports.retryRequest=K;