@seayoo-web/request 2.0.3 → 2.0.5

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 CHANGED
@@ -380,7 +380,7 @@ status 表示网络错误或者http 状态码错误时重试;
380
380
 
381
381
  - http statusText 当请求完成且无自定义错误码时,可能为空字符串
382
382
  - responseRule 中自定义的错误码字段所传递的值
383
- - "NetworkError","Failed","Aborted" 或 "Unknown" 网络错误或取消等异常情况
383
+ - "Aborted" 或 "Unknown" 网络错误或取消等异常情况
384
384
 
385
385
  ### message
386
386
 
@@ -498,13 +498,13 @@ for(const key in data) {
498
498
  const { ok, data } = await post(url, formData, typeGuard);
499
499
  ```
500
500
 
501
- 修改默认的异常提示
501
+ 修改默认的异常提示(通常是不必要的)
502
502
 
503
503
  ```typescript
504
504
  setGlobalConfig({
505
505
  message: function({ code, status, message }, method, url, defaultMsg){
506
- if(code === "NetworkError" || code === "Failed" || code === "Aborted") {
507
- return "⚠️ 网络错误,请检查网络";
506
+ if(status === 401) {
507
+ return ""
508
508
  }
509
509
  if(status === 404) {
510
510
  return `${method} ${url} 接口未定义`;
@@ -512,7 +512,7 @@ setGlobalConfig({
512
512
  if(status >= 500 && status <= 599) {
513
513
  return "🚨 服务器错误,请稍候再试";
514
514
  }
515
- if(code === "Unknown") {
515
+ if(code === "Unknown" || code === "Aborted") {
516
516
  return `⛔ ${url} 出现未知错误,请稍候再试`;
517
517
  }
518
518
  return message;
@@ -1,4 +1,4 @@
1
- import { IRequestGlobalConfig } from "./type";
1
+ import type { ERequestRawError, IRequestGlobalConfig } from "./type";
2
2
  /** 根据响应组织整理 sentry 上报信息 */
3
3
  export declare function getSentryExceptionData(data: {
4
4
  url: string;
@@ -8,4 +8,5 @@ export declare function getSentryExceptionData(data: {
8
8
  message: string;
9
9
  body: string;
10
10
  headers: Record<string, string>;
11
+ error?: ERequestRawError;
11
12
  }): Pick<Parameters<NonNullable<IRequestGlobalConfig["errorHandler"]>>[0], "sentryError" | "sentryTags" | "sentryExtra">;
@@ -62,7 +62,7 @@ export interface IOtherRequestOptions {
62
62
  /** 对外工具接口的请求配置 */
63
63
  export type IRequestOptions = IBaseRequestOptions & IRetryRequestOptions & IOtherRequestOptions;
64
64
  /** 请求的原始错误信息 */
65
- type ERequestRawError = Error | ProgressEvent;
65
+ export type ERequestRawError = Error | ProgressEvent;
66
66
  /** 全局默认配置 */
67
67
  export type IRequestGlobalConfig = {
68
68
  /**
package/dist/index.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("./version-kPzj9ZQV.cjs"),y=require("./request.fetch-D8xMOauM.cjs"),m=async function(t,o,e){return s.handleResponse(await s.retryRequest(w,t,o,e),t,o,e)};async function q(t,o,e,n){const r=e==null?void 0:e.body,i=(e==null?void 0:e.method)==="PUT"?"PUT":"POST";if(o instanceof Blob){const d=new s.RequestGlobalConfig(n),f=await w(t,d,{...e,method:i,body:o});return s.handleResponse(f,t,d,e)}const c=new FormData,u={...o};r instanceof Object&&Object.entries(r).forEach(([d,f])=>{f instanceof Blob?u[d]=f:Array.isArray(f)?f.forEach((a,g)=>{c.append(`${d}[${g}]`,String(a))}):c.append(d,String(f))});for(const d in u)c.append(d,u[d]);const b=new s.RequestGlobalConfig(n),p=await w(t,b,{...e,method:i,body:c});return s.handleResponse(p,t,b,e)}const w=async function(t,o,e){const n=await s.convertOptions(t,o,e),r=n.method,i=e==null?void 0:e.onUploadProgress,c=s.vt(n.url,n.params);return await new Promise(u=>{let b=null,p=!1;const d=function(){p||(a.abort(),p=!0)};function f(){b!==null&&clearTimeout(b),n.abort&&n.abort.removeEventListener("abort",d)}const a=new XMLHttpRequest;if(a.open(r,c,!0),i){let g=1;a.upload.addEventListener("progress",h=>{g=h.total,i({total:h.total,loaded:h.loaded})}),a.addEventListener("load",()=>{i({loaded:g,total:g})})}a.addEventListener("load",()=>{f(),u({url:c,method:r,status:a.status,statusText:a.statusText,headers:H(a),body:r==="HEAD"?"":a.responseText})}),a.addEventListener("error",g=>{f(),u({url:c,method:r,status:-1,statusText:"Failed",body:"",rawError:g})},!0),a.addEventListener("abort",()=>{f(),u({url:c,method:r,status:-1,statusText:"Aborted",body:""})}),Object.entries(n.headers).forEach(([g,h])=>{a.setRequestHeader(g,h)}),n.credentials==="include"&&(a.withCredentials=!0),a.send(n.body||void 0),n.abort&&n.abort.addEventListener("abort",d),n.timeout>0&&(b=setTimeout(d,n.timeout))})};function H(t){const o={};if(!t)return o;const e=t.getAllResponseHeaders();return e&&e!=="null"&&e.replace(/\r/g,"").split(`
2
- `).forEach(n=>{const r=n.trim();if(!r)return;const i=r.split(":"),c=i[0].trim();c&&(o[c]=(i[1]||"").trim())}),o}async function E(t,o,e={}){const n=window;"callback"in e||(e.callback="jsonxData"+Math.random().toString(16).slice(2));const r=e.callback+"";if(!t)return null;const i=s.vt(t,e,!0);return new Promise(c=>{n[r]=function(u){if(r in window&&delete n[r],o(u))return u;console.warn("response type check faild",t,u),c(null)},s.Ee(i).catch(function(){c(null),delete n[r]})})}async function T(t,o,e={}){const n=window;return"var"in e||(e.var="jsonxData"+Math.random().toString(16).slice(2)),t?await s.Ee(s.vt(t,e,!0)).then(()=>{const r=n[e.var+""];return o(r)?r:(console.warn("response type check faild",t,r),null)}).catch(()=>null):null}const v=async function(t,o,e){return await q(t,o,e,{baseURL:l.getConfig("baseURL"),logHandler:l.getConfig("logHandler"),errorHandler:l.getConfig("errorHandler"),requestTransformer:l.getConfig("requestTransformer"),messageHandler:l.getConfig("messageHandler"),responseHandler:l.getConfig("responseHandler")})};function R(t){if(!s.Support.window)throw new Error("Default Module Only Support In Browser");return s.Support.fetch?new s.NetRequestHandler(y.fetchRequest,t):new s.NetRequestHandler(m,t)}const l=R(),C=l.setConfig,S=l.request,x=l.head,j=l.get,L=l.post,D=l.del,U=l.put,k=l.patch;exports.getResponseRulesDescription=s.getResponseRulesDescription;exports.version=s.version;exports.NetRequest=R;exports.del=D;exports.get=j;exports.head=x;exports.jsonp=E;exports.jsonx=T;exports.patch=k;exports.post=L;exports.put=U;exports.request=S;exports.setGlobalConfig=C;exports.upload=v;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("./version-otf8Cl2Z.cjs"),y=require("./request.fetch-D0LxU0UO.cjs"),m=async function(t,o,e){return s.handleResponse(await s.retryRequest(p,t,o,e),t,o,e)};async function q(t,o,e,n){const r=e==null?void 0:e.body,i=(e==null?void 0:e.method)==="PUT"?"PUT":"POST";if(o instanceof Blob){const d=new s.RequestGlobalConfig(n),f=await p(t,d,{...e,method:i,body:o});return s.handleResponse(f,t,d,e)}const c=new FormData,u={...o};r instanceof Object&&Object.entries(r).forEach(([d,f])=>{f instanceof Blob?u[d]=f:Array.isArray(f)?f.forEach((a,g)=>{c.append(`${d}[${g}]`,String(a))}):c.append(d,String(f))});for(const d in u)c.append(d,u[d]);const b=new s.RequestGlobalConfig(n),w=await p(t,b,{...e,method:i,body:c});return s.handleResponse(w,t,b,e)}const p=async function(t,o,e){const n=await s.convertOptions(t,o,e),r=n.method,i=e==null?void 0:e.onUploadProgress,c=s.vt(n.url,n.params);return await new Promise(u=>{let b=null,w=!1;const d=function(){w||(a.abort(),w=!0)};function f(){b!==null&&clearTimeout(b),n.abort&&n.abort.removeEventListener("abort",d)}const a=new XMLHttpRequest;if(a.open(r,c,!0),i){let g=1;a.upload.addEventListener("progress",h=>{g=h.total,i({total:h.total,loaded:h.loaded})}),a.addEventListener("load",()=>{i({loaded:g,total:g})})}a.addEventListener("load",()=>{f(),u({url:c,method:r,status:a.status,statusText:a.statusText,headers:H(a),body:r==="HEAD"?"":a.responseText})}),a.addEventListener("error",g=>{f(),u({url:c,method:r,status:-1,statusText:"Unknown",body:"",rawError:g})},!0),a.addEventListener("abort",()=>{f(),u({url:c,method:r,status:-1,statusText:"Aborted",body:""})}),Object.entries(n.headers).forEach(([g,h])=>{a.setRequestHeader(g,h)}),n.credentials==="include"&&(a.withCredentials=!0),a.send(n.body||void 0),n.abort&&n.abort.addEventListener("abort",d),n.timeout>0&&(b=setTimeout(d,n.timeout))})};function H(t){const o={};if(!t)return o;const e=t.getAllResponseHeaders();return e&&e!=="null"&&e.replace(/\r/g,"").split(`
2
+ `).forEach(n=>{const r=n.trim();if(!r)return;const i=r.split(":"),c=i[0].trim();c&&(o[c]=(i[1]||"").trim())}),o}async function E(t,o,e={}){const n=window;"callback"in e||(e.callback="jsonxData"+Math.random().toString(16).slice(2));const r=e.callback+"";if(!t)return null;const i=s.vt(t,e,!0);return new Promise(c=>{n[r]=function(u){if(r in window&&delete n[r],o(u))return u;console.warn("response type check faild",t,u),c(null)},s.Ee(i).catch(function(){c(null),delete n[r]})})}async function T(t,o,e={}){const n=window;return"var"in e||(e.var="jsonxData"+Math.random().toString(16).slice(2)),t?await s.Ee(s.vt(t,e,!0)).then(()=>{const r=n[e.var+""];return o(r)?r:(console.warn("response type check faild",t,r),null)}).catch(()=>null):null}const v=async function(t,o,e){return await q(t,o,e,{baseURL:l.getConfig("baseURL"),logHandler:l.getConfig("logHandler"),errorHandler:l.getConfig("errorHandler"),requestTransformer:l.getConfig("requestTransformer"),messageHandler:l.getConfig("messageHandler"),responseHandler:l.getConfig("responseHandler")})};function R(t){if(!s.Support.window)throw new Error("Default Module Only Support In Browser");return s.Support.fetch?new s.NetRequestHandler(y.fetchRequest,t):new s.NetRequestHandler(m,t)}const l=R(),C=l.setConfig,S=l.request,x=l.head,j=l.get,L=l.post,U=l.del,k=l.put,D=l.patch;exports.getResponseRulesDescription=s.getResponseRulesDescription;exports.version=s.version;exports.NetRequest=R;exports.del=U;exports.get=j;exports.head=x;exports.jsonp=E;exports.jsonx=T;exports.patch=D;exports.post=L;exports.put=k;exports.request=S;exports.setGlobalConfig=C;exports.upload=v;
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
- import { h as w, r as q, R as y, c as T, v as p, E as H, S as R, N as E } from "./version-CjW4Ddf0.js";
2
- import { g as I, a as J } from "./version-CjW4Ddf0.js";
3
- import { f as x } from "./request.fetch-njIlqfIR.js";
1
+ import { h as w, r as q, R as y, c as T, v as p, E as H, S as R, N as E } from "./version-BEDupKzt.js";
2
+ import { g as I, a as J } from "./version-BEDupKzt.js";
3
+ import { f as x } from "./request.fetch-49pAyky3.js";
4
4
  const v = async function(t, a, e) {
5
5
  return w(await q(m, t, a, e), t, a, e);
6
6
  };
@@ -64,7 +64,7 @@ const m = async function(t, a, e) {
64
64
  url: s,
65
65
  method: r,
66
66
  status: -1,
67
- statusText: "Failed",
67
+ statusText: "Unknown",
68
68
  body: "",
69
69
  rawError: f
70
70
  });
@@ -97,7 +97,7 @@ function L(t) {
97
97
  s && (a[s] = (d[1] || "").trim());
98
98
  }), a;
99
99
  }
100
- async function k(t, a, e = {}) {
100
+ async function j(t, a, e = {}) {
101
101
  const n = window;
102
102
  "callback" in e || (e.callback = "jsonxData" + Math.random().toString(16).slice(2));
103
103
  const r = e.callback + "";
@@ -136,18 +136,18 @@ function S(t) {
136
136
  throw new Error("Default Module Only Support In Browser");
137
137
  return R.fetch ? new E(x, t) : new E(v, t);
138
138
  }
139
- const c = S(), P = c.setConfig, A = c.request, M = c.head, N = c.get, B = c.post, F = c.del, X = c.put, G = c.patch;
139
+ const c = S(), P = c.setConfig, A = c.request, M = c.head, N = c.get, B = c.post, X = c.del, F = c.put, G = c.patch;
140
140
  export {
141
141
  S as NetRequest,
142
- F as del,
142
+ X as del,
143
143
  N as get,
144
144
  I as getResponseRulesDescription,
145
145
  M as head,
146
- k as jsonp,
146
+ j as jsonp,
147
147
  D as jsonx,
148
148
  G as patch,
149
149
  B as post,
150
- X as put,
150
+ F as put,
151
151
  A as request,
152
152
  P as setGlobalConfig,
153
153
  O as upload,
package/dist/node.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const y=require("node:http"),R=require("node:https"),o=require("./version-kPzj9ZQV.cjs"),g=require("./request.fetch-D8xMOauM.cjs"),w=async function(s,u,c){return o.handleResponse(await o.retryRequest(S,s,u,c),s,u,c)},S=async function(s,u,c){const t=await o.convertOptions(s,u,c);if(!o.K(t.url))return{url:t.url,method:t.method,status:-1,statusText:"URLFormatError",headers:{},body:""};const f=/^https:\/\//i.test(t.url)?R:y,a=new URL(t.url),i=t.params;i instanceof Object&&Object.keys(i).forEach(r=>a.searchParams.set(r,i[r]));const q=t.method==="HEAD";return new Promise(r=>{const d=f.request(a,{headers:t.headers,method:t.method,timeout:t.timeout>0?t.timeout:void 0},function(e){const p=[];e.on("data",h=>p.push(h)),e.on("end",()=>{const h=o.fromEntries(Object.entries(e.headers).map(([b,m])=>[b.toLowerCase(),Array.isArray(m)?m.join(","):m]));r({url:a.toString(),method:t.method,status:e.statusCode||-1,statusText:e.statusMessage||"Unknown",headers:h,body:q?"":Buffer.concat(p).toString("utf-8")})})});d.on("error",e=>{r({url:a.toString(),method:t.method,status:-1,statusText:e.name||"Unknown",body:e.message,rawError:e})}),d.on("timeout",()=>{r({url:a.toString(),method:t.method,status:-1,statusText:"Timeout",body:""})}),t.body&&d.write(t.body),d.end()})};function l(s){return o.Support.fetch?new o.NetRequestHandler(g.fetchRequest,s):new o.NetRequestHandler(w,s)}const n=l(),T=n.setConfig,j=n.head,C=n.get,E=n.post,N=n.del,O=n.put,U=n.patch;exports.version=o.version;exports.NetRequest=l;exports.del=N;exports.get=C;exports.head=j;exports.patch=U;exports.post=E;exports.put=O;exports.setGlobalConfig=T;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const y=require("node:http"),R=require("node:https"),e=require("./version-otf8Cl2Z.cjs"),g=require("./request.fetch-D0LxU0UO.cjs"),w=async function(o,a,c){return e.handleResponse(await e.retryRequest(S,o,a,c),o,a,c)},S=async function(o,a,c){const t=await e.convertOptions(o,a,c);if(!e.K(t.url))return{url:t.url,method:t.method,status:-1,statusText:"URLFormatError",headers:{},body:""};const f=/^https:\/\//i.test(t.url)?R:y,u=new URL(t.url),i=t.params;i instanceof Object&&Object.keys(i).forEach(r=>u.searchParams.set(r,i[r]));const q=t.method==="HEAD";return new Promise(r=>{const d=f.request(u,{headers:t.headers,method:t.method,timeout:t.timeout>0?t.timeout:void 0},function(s){const p=[];s.on("data",h=>p.push(h)),s.on("end",()=>{const h=e.fromEntries(Object.entries(s.headers).map(([b,m])=>[b.toLowerCase(),Array.isArray(m)?m.join(","):m]));r({url:u.toString(),method:t.method,status:s.statusCode||-1,statusText:s.statusMessage||"Unknown",headers:h,body:q?"":Buffer.concat(p).toString("utf-8")})})});d.on("error",s=>{r({url:u.toString(),method:t.method,status:-1,statusText:"Unknown",body:"",rawError:s})}),d.on("timeout",()=>{r({url:u.toString(),method:t.method,status:-1,statusText:"Timeout",body:""})}),t.body&&d.write(t.body),d.end()})};function l(o){return e.Support.fetch?new e.NetRequestHandler(g.fetchRequest,o):new e.NetRequestHandler(w,o)}const n=l(),T=n.setConfig,j=n.head,C=n.get,E=n.post,N=n.del,O=n.put,U=n.patch;exports.version=e.version;exports.NetRequest=l;exports.del=N;exports.get=C;exports.head=j;exports.patch=U;exports.post=E;exports.put=O;exports.setGlobalConfig=T;
package/dist/node.js CHANGED
@@ -1,12 +1,12 @@
1
1
  import y from "node:http";
2
2
  import R from "node:https";
3
- import { h as w, r as q, c as g, K as x, f as S, S as E, N as p } from "./version-CjW4Ddf0.js";
4
- import { a as z } from "./version-CjW4Ddf0.js";
5
- import { f as T } from "./request.fetch-njIlqfIR.js";
6
- const U = async function(o, a, u) {
7
- return w(await q(j, o, a, u), o, a, u);
8
- }, j = async function(o, a, u) {
9
- const t = await g(o, a, u);
3
+ import { h as w, r as q, c as g, K as x, f as S, S as E, N as p } from "./version-BEDupKzt.js";
4
+ import { a as z } from "./version-BEDupKzt.js";
5
+ import { f as T } from "./request.fetch-49pAyky3.js";
6
+ const U = async function(e, a, u) {
7
+ return w(await q(j, e, a, u), e, a, u);
8
+ }, j = async function(e, a, u) {
9
+ const t = await g(e, a, u);
10
10
  if (!x(t.url))
11
11
  return {
12
12
  url: t.url,
@@ -27,31 +27,31 @@ const U = async function(o, a, u) {
27
27
  method: t.method,
28
28
  timeout: t.timeout > 0 ? t.timeout : void 0
29
29
  },
30
- function(e) {
30
+ function(o) {
31
31
  const h = [];
32
- e.on("data", (i) => h.push(i)), e.on("end", () => {
32
+ o.on("data", (i) => h.push(i)), o.on("end", () => {
33
33
  const i = S(
34
- Object.entries(e.headers).map(([l, m]) => [l.toLowerCase(), Array.isArray(m) ? m.join(",") : m])
34
+ Object.entries(o.headers).map(([l, m]) => [l.toLowerCase(), Array.isArray(m) ? m.join(",") : m])
35
35
  );
36
36
  r({
37
37
  url: n.toString(),
38
38
  method: t.method,
39
- status: e.statusCode || -1,
40
- statusText: e.statusMessage || "Unknown",
39
+ status: o.statusCode || -1,
40
+ statusText: o.statusMessage || "Unknown",
41
41
  headers: i,
42
42
  body: b ? "" : Buffer.concat(h).toString("utf-8")
43
43
  });
44
44
  });
45
45
  }
46
46
  );
47
- c.on("error", (e) => {
47
+ c.on("error", (o) => {
48
48
  r({
49
49
  url: n.toString(),
50
50
  method: t.method,
51
51
  status: -1,
52
- statusText: e.name || "Unknown",
53
- body: e.message,
54
- rawError: e
52
+ statusText: "Unknown",
53
+ body: "",
54
+ rawError: o
55
55
  });
56
56
  }), c.on("timeout", () => {
57
57
  r({
@@ -64,8 +64,8 @@ const U = async function(o, a, u) {
64
64
  }), t.body && c.write(t.body), c.end();
65
65
  });
66
66
  };
67
- function C(o) {
68
- return E.fetch ? new p(T, o) : new p(U, o);
67
+ function C(e) {
68
+ return E.fetch ? new p(T, e) : new p(U, e);
69
69
  }
70
70
  const s = C(), H = s.setConfig, k = s.head, P = s.get, B = s.post, D = s.del, F = s.put, G = s.patch;
71
71
  export {
@@ -0,0 +1,40 @@
1
+ import { h as u, r as h, c as b, S as l, f as m } from "./version-BEDupKzt.js";
2
+ const y = async function(r, o, s) {
3
+ return u(await h(f, r, o, s), r, o, s);
4
+ }, f = async function(r, o, s) {
5
+ const t = await b(r, o, s), n = new URL(t.url), i = t.params;
6
+ i instanceof Object && Object.keys(i).forEach((a) => n.searchParams.set(a, i[a]));
7
+ const e = l.AbortController ? new AbortController() : null;
8
+ function c() {
9
+ e && !e.signal.aborted && e.abort();
10
+ }
11
+ t.abort && t.abort.addEventListener("abort", c);
12
+ const d = t.timeout > 0 ? setTimeout(c, t.timeout) : null;
13
+ return await fetch(n, {
14
+ method: t.method,
15
+ headers: Object.keys(t.headers).length > 0 ? new Headers(t.headers) : void 0,
16
+ body: t.body,
17
+ credentials: t.credentials,
18
+ signal: e == null ? void 0 : e.signal,
19
+ redirect: "follow"
20
+ }).then(async (a) => ({
21
+ url: n.toString(),
22
+ method: t.method,
23
+ status: a.status,
24
+ statusText: a.statusText,
25
+ headers: m([...a.headers.entries()]),
26
+ body: t.method === "HEAD" ? "" : await a.text().catch(() => "")
27
+ })).catch((a) => ({
28
+ url: n.toString(),
29
+ method: t.method,
30
+ status: -1,
31
+ statusText: e != null && e.signal.aborted ? "Aborted" : "Unknown",
32
+ body: "",
33
+ rawError: a
34
+ })).finally(() => {
35
+ d !== null && clearTimeout(d), t.abort && t.abort.removeEventListener("abort", c);
36
+ });
37
+ };
38
+ export {
39
+ y as f
40
+ };
@@ -0,0 +1 @@
1
+ "use strict";const r=require("./version-otf8Cl2Z.cjs"),h=async function(o,s,n){return r.handleResponse(await r.retryRequest(b,o,s,n),o,s,n)},b=async function(o,s,n){const t=await r.convertOptions(o,s,n),i=new URL(t.url),c=t.params;c instanceof Object&&Object.keys(c).forEach(a=>i.searchParams.set(a,c[a]));const e=r.Support.AbortController?new AbortController:null;function u(){e&&!e.signal.aborted&&e.abort()}t.abort&&t.abort.addEventListener("abort",u);const d=t.timeout>0?setTimeout(u,t.timeout):null;return await fetch(i,{method:t.method,headers:Object.keys(t.headers).length>0?new Headers(t.headers):void 0,body:t.body,credentials:t.credentials,signal:e==null?void 0:e.signal,redirect:"follow"}).then(async a=>({url:i.toString(),method:t.method,status:a.status,statusText:a.statusText,headers:r.fromEntries([...a.headers.entries()]),body:t.method==="HEAD"?"":await a.text().catch(()=>"")})).catch(a=>({url:i.toString(),method:t.method,status:-1,statusText:e!=null&&e.signal.aborted?"Aborted":"Unknown",body:"",rawError:a})).finally(()=>{d!==null&&clearTimeout(d),t.abort&&t.abort.removeEventListener("abort",u)})};exports.fetchRequest=h;
@@ -1,7 +1,7 @@
1
1
  var q = Object.defineProperty;
2
2
  var H = (e, t, s) => t in e ? q(e, t, { enumerable: !0, configurable: !0, writable: !0, value: s }) : e[t] = s;
3
3
  var y = (e, t, s) => (H(e, typeof t != "symbol" ? t + "" : t, s), s);
4
- const p = typeof globalThis < "u" ? globalThis : typeof global < "u" ? global : typeof window < "u" ? window : {}, E = {
4
+ const p = typeof globalThis < "u" ? globalThis : typeof global < "u" ? global : typeof window < "u" ? window : {}, $ = {
5
5
  fetch: "fetch" in p,
6
6
  window: "window" in p,
7
7
  FormData: "FormData" in p,
@@ -36,13 +36,13 @@ function G(e) {
36
36
  function j(e) {
37
37
  return e ? e[0].toLowerCase() + e.slice(1) : "";
38
38
  }
39
- const _ = /_\w*/, B = /-\w*/;
39
+ const x = /_\w*/, _ = /-\w*/;
40
40
  function A(e) {
41
- const t = _.test(e) ? e.replace(/(?:^_*|_*$)/g, "").replace(/_+([^_])/g, (s, r) => r.toUpperCase()) : B.test(e) ? e.replace(/(?:^-*|-*$)/g, "").replace(/-+(\w)/g, (s, r) => r.toUpperCase()) : e;
41
+ const t = x.test(e) ? e.replace(/(?:^_*|_*$)/g, "").replace(/_+([^_])/g, (s, r) => r.toUpperCase()) : _.test(e) ? e.replace(/(?:^-*|-*$)/g, "").replace(/-+(\w)/g, (s, r) => r.toUpperCase()) : e;
42
42
  return j(t);
43
43
  }
44
- function M(e) {
45
- return _.test(e) ? j(e).replace(/(?:^_*|_*$)/g, "").replace(/_+([^_])/g, (t, s) => "_" + s.toLowerCase()) : B.test(e) ? j(e.replace(/(?:^-*|-*$)/g, "")).replace(/-+(\w)/g, (t, s) => "_" + s.toLowerCase()) : j(e).replace(/[A-Z]/g, (t) => `_${t.toLowerCase()}`);
44
+ function U(e) {
45
+ return x.test(e) ? j(e).replace(/(?:^_*|_*$)/g, "").replace(/_+([^_])/g, (t, s) => "_" + s.toLowerCase()) : _.test(e) ? j(e.replace(/(?:^-*|-*$)/g, "")).replace(/-+(\w)/g, (t, s) => "_" + s.toLowerCase()) : j(e).replace(/[A-Z]/g, (t) => `_${t.toLowerCase()}`);
46
46
  }
47
47
  const J = /^(?:https?:)?\/\/.+$/i, V = /^https?:\/\/.+$/i, W = /^\{[\d\D]*\}$/, z = /^\[[\d\D]*\]$/;
48
48
  function F(e, t = !1) {
@@ -57,7 +57,7 @@ function O(e, ...t) {
57
57
  const s = Object.getPrototypeOf(e);
58
58
  return s !== Object.prototype && s !== null ? !1 : t.every((r) => r in e);
59
59
  }
60
- function x(e) {
60
+ function B(e) {
61
61
  return W.test(e) || z.test(e);
62
62
  }
63
63
  function v(e, t) {
@@ -69,20 +69,20 @@ function v(e, t) {
69
69
  }
70
70
  }
71
71
  "" + Math.random().toString(32).slice(2);
72
- function R(e, t = !1) {
73
- return typeof e == "string" ? A(e) : Array.isArray(e) ? e.map((s) => !t || typeof s == "string" ? R(s) : typeof s == "object" && s ? R(s, !0) : s) : O(e) ? Object.keys(e).reduce(
72
+ function E(e, t = !1) {
73
+ return typeof e == "string" ? A(e) : Array.isArray(e) ? e.map((s) => !t || typeof s == "string" ? E(s) : typeof s == "object" && s ? E(s, !0) : s) : O(e) ? Object.keys(e).reduce(
74
74
  (s, r) => {
75
75
  const a = A(String(r)), n = a.charAt(0).toLowerCase() + a.slice(1);
76
- return s[n] = t ? e[r] : R(e[r]), s;
76
+ return s[n] = t ? e[r] : E(e[r]), s;
77
77
  },
78
78
  {}
79
79
  ) : e;
80
80
  }
81
- function $(e, t = !1) {
82
- return typeof e == "string" ? M(e) : Array.isArray(e) ? e.map((s) => !t || typeof s == "string" ? $(s) : typeof s == "object" && s ? $(s, t) : s) : O(e) ? Object.keys(e).reduce(
81
+ function R(e, t = !1) {
82
+ return typeof e == "string" ? U(e) : Array.isArray(e) ? e.map((s) => !t || typeof s == "string" ? R(s) : typeof s == "object" && s ? R(s, t) : s) : O(e) ? Object.keys(e).reduce(
83
83
  (s, r) => {
84
- const a = M(String(r));
85
- return s[a] = t ? e[r] : $(e[r]), s;
84
+ const a = U(String(r));
85
+ return s[a] = t ? e[r] : R(e[r]), s;
86
86
  },
87
87
  {}
88
88
  ) : e;
@@ -107,9 +107,9 @@ function Z(e, t = "数据未能正确识别") {
107
107
  };
108
108
  }
109
109
  function X(e, t = "") {
110
- return !t || F(e, !0) ? U(e) : (U(t) + "/" + e).replace(/\/{2,}/g, "/").replace(/:\//, "://");
110
+ return !t || F(e, !0) ? M(e) : (M(t) + "/" + e).replace(/\/{2,}/g, "/").replace(/:\//, "://");
111
111
  }
112
- function U(e) {
112
+ function M(e) {
113
113
  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(/^\/+/, "");
114
114
  }
115
115
  function Y(e, t) {
@@ -218,7 +218,7 @@ class ne {
218
218
  this.config.messageHandler && s && this.config.messageHandler(t, s, r, a);
219
219
  }
220
220
  }
221
- class Re {
221
+ class Ee {
222
222
  constructor(t, s) {
223
223
  y(this, "agent");
224
224
  y(this, "config");
@@ -298,7 +298,7 @@ function ae(e, t, s, r, a) {
298
298
  const n = a || r;
299
299
  return T(e) ? he(n.ok || r.ok, e, t, s) : oe(n.failed || r.failed, t, s);
300
300
  }
301
- const $e = function(e) {
301
+ const Re = function(e) {
302
302
  const t = [], s = e.failed || { resolve: "json" };
303
303
  switch (t.push("- 当http状态码 <200 或者 >=400 时"), s.resolve) {
304
304
  case "body":
@@ -341,7 +341,7 @@ function oe(e, t, s) {
341
341
  return a;
342
342
  }
343
343
  function ce(e, t, s, r = w) {
344
- if (!x(e))
344
+ if (!B(e))
345
345
  return { message: "" };
346
346
  const a = C(v(e), t);
347
347
  return !a || !O(a) ? { message: e } : {
@@ -377,7 +377,7 @@ function he(e, t, s, r) {
377
377
  if (t === 204 || !r)
378
378
  return n;
379
379
  if (a.resolve === "body")
380
- return n.data = x(r) ? C(v(r), e.converter) : r, n;
380
+ return n.data = B(r) ? C(v(r), e.converter) : r, n;
381
381
  const o = C(v(r), e.converter);
382
382
  if (!o || !O(o))
383
383
  return n.ok = !1, n.code = "ResponseFormatError", n.message = "响应内容无法格式化为 Object", n;
@@ -391,7 +391,7 @@ function T(e) {
391
391
  return e >= 200 && e < 400;
392
392
  }
393
393
  function C(e, t) {
394
- return t === "camelize" ? R(e) : t === "snakify" ? $(e) : e;
394
+ return t === "camelize" ? E(e) : t === "snakify" ? R(e) : e;
395
395
  }
396
396
  async function de(e, t, s, r, a) {
397
397
  const n = a || 0, o = Math.max(0, Math.min(10, (r == null ? void 0 : r.maxRetry) ?? s.get("maxRetry") ?? 0)), c = (r == null ? void 0 : r.retryResolve) ?? s.get("retryResolve"), i = s.get("logHandler") || N;
@@ -428,13 +428,13 @@ async function de(e, t, s, r, a) {
428
428
  )
429
429
  ), await de(e, t, s, r, n + 1);
430
430
  }
431
- async function Ee(e, t, s) {
431
+ async function $e(e, t, s) {
432
432
  var f;
433
- const r = Object.assign({ method: "GET" }, s), a = E.FormData ? r.body instanceof FormData : !1, n = a && r.method !== "POST" && r.method !== "PUT" ? "POST" : r.method, o = n === "GET" || n === "HEAD" || n === "DELETE";
433
+ const r = Object.assign({ method: "GET" }, s), a = $.FormData ? r.body instanceof FormData : !1, n = a && r.method !== "POST" && r.method !== "PUT" ? "POST" : r.method, o = n === "GET" || n === "HEAD" || n === "DELETE";
434
434
  o && r.body !== void 0 && (console.warn("request body is invalid with method get, head, delete"), delete r.body);
435
435
  const c = Object.assign(
436
436
  a || o ? {} : {
437
- "Content-Type": E.Blob && r.body instanceof Blob ? r.body.type || "application/octet-stream" : "application/json;charset=utf-8"
437
+ "Content-Type": $.Blob && r.body instanceof Blob ? r.body.type || "application/octet-stream" : "application/json;charset=utf-8"
438
438
  },
439
439
  r.headers
440
440
  ), i = r.params || {}, h = {};
@@ -462,26 +462,28 @@ function ge(e) {
462
462
  }
463
463
  function fe(e) {
464
464
  if (e)
465
- return typeof e == "string" || e instanceof URLSearchParams || e instanceof ArrayBuffer || E.Blob && e instanceof Blob || E.FormData && e instanceof FormData ? e : JSON.stringify(e);
465
+ return typeof e == "string" || e instanceof URLSearchParams || e instanceof ArrayBuffer || $.Blob && e instanceof Blob || $.FormData && e instanceof FormData ? e : JSON.stringify(e);
466
466
  }
467
467
  const me = G("APIError");
468
468
  function ye(e) {
469
469
  const t = {};
470
- for (const s in e.headers)
471
- (s.startsWith("x-") || s.includes("trace") || s.includes("server") || /\b(?:id|uuid)\b/.test(s)) && (t[s] = e.headers[s]);
470
+ for (const a in e.headers)
471
+ (a.startsWith("x-") || a.includes("trace") || a.includes("server") || /\b(?:id|uuid)\b/.test(a)) && (t[a] = e.headers[a]);
472
+ const s = e.url.replace(/^(?:https?:)?\/*/i, "").replace(/\?.+/, ""), r = e.status < 0 ? "unknown" : e.status;
472
473
  return {
473
- sentryError: new me(`${e.url.replace(/^(?:https?:)?\/*/i, "")} | ${e.status}${e.code ? ` | ${e.code}` : ""}`),
474
+ sentryError: new me(`${s} | ${r}${e.code ? ` | ${e.code}` : ""}`),
474
475
  sentryTags: {
475
476
  ...t,
476
- status: e.status < 0 ? "unknown" : e.status,
477
+ status: r,
477
478
  method: e.method,
478
479
  code: e.code || "unknown",
479
480
  message: e.message || "empty"
480
481
  },
481
482
  sentryExtra: {
482
483
  url: e.url,
483
- responseBody: e.body,
484
- responseHeaders: e.headers
484
+ responseBody: e.body || "empty",
485
+ responseHeaders: e.headers,
486
+ rawError: e.error
485
487
  }
486
488
  };
487
489
  }
@@ -496,7 +498,8 @@ function Oe(e, t, s, r) {
496
498
  code: i,
497
499
  message: u,
498
500
  body: e.body,
499
- headers: o
501
+ headers: o,
502
+ error: e.rawError
500
503
  });
501
504
  (s.get("errorHandler") || pe)({
502
505
  url: t,
@@ -538,17 +541,17 @@ function pe(e) {
538
541
  s.startsWith("sentry") || (t[s] = e[s]);
539
542
  console.error("RequestError", t);
540
543
  }
541
- const ve = "2.0.3";
544
+ const ve = "2.0.5";
542
545
  export {
543
546
  we as E,
544
547
  F as K,
545
- Re as N,
548
+ Ee as N,
546
549
  ne as R,
547
- E as S,
550
+ $ as S,
548
551
  ve as a,
549
- Ee as c,
552
+ $e as c,
550
553
  I as f,
551
- $e as g,
554
+ Re as g,
552
555
  Oe as h,
553
556
  de as r,
554
557
  je as v
@@ -1,2 +1,2 @@
1
- "use strict";var K=Object.defineProperty;var N=(e,t,s)=>t in e?K(e,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[t]=s;var y=(e,t,s)=>(N(e,typeof t!="symbol"?t+"":t,s),s);const p=typeof globalThis<"u"?globalThis:typeof global<"u"?global:typeof window<"u"?window:{},w={fetch:"fetch"in p,window:"window"in p,FormData:"FormData"in p,Blob:"Blob"in p,wx:"wx"in p,TextDecoder:"TextDecoder"in p,AbortController:"AbortController"in p};function q(e){return e.reduce((t,[s,r])=>(s&&(t[s]=r||""),t),{})}function G(e){return new Promise(t=>setTimeout(t,Math.max(0,e)))}function J(){}function V(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&&Error.captureStackTrace(this,this.constructor)}}}function j(e){return e?e[0].toLowerCase()+e.slice(1):""}const _=/_\w*/,B=/-\w*/;function A(e){const t=_.test(e)?e.replace(/(?:^_*|_*$)/g,"").replace(/_+([^_])/g,(s,r)=>r.toUpperCase()):B.test(e)?e.replace(/(?:^-*|-*$)/g,"").replace(/-+(\w)/g,(s,r)=>r.toUpperCase()):e;return j(t)}function D(e){return _.test(e)?j(e).replace(/(?:^_*|_*$)/g,"").replace(/_+([^_])/g,(t,s)=>"_"+s.toLowerCase()):B.test(e)?j(e.replace(/(?:^-*|-*$)/g,"")).replace(/-+(\w)/g,(t,s)=>"_"+s.toLowerCase()):j(e).replace(/[A-Z]/g,t=>`_${t.toLowerCase()}`)}const W=/^(?:https?:)?\/\/.+$/i,z=/^https?:\/\/.+$/i,Q=/^\{[\d\D]*\}$/,Z=/^\[[\d\D]*\]$/;function O(e,t=!1){return t?W.test(e):z.test(e)}function X(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 S(e){return Q.test(e)||Z.test(e)}function k(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,t=!1){return typeof e=="string"?A(e):Array.isArray(e)?e.map(s=>!t||typeof s=="string"?$(s):typeof s=="object"&&s?$(s,!0):s):v(e)?Object.keys(e).reduce((s,r)=>{const a=A(String(r)),n=a.charAt(0).toLowerCase()+a.slice(1);return s[n]=t?e[r]:$(e[r]),s},{}):e}function E(e,t=!1){return typeof e=="string"?D(e):Array.isArray(e)?e.map(s=>!t||typeof s=="string"?E(s):typeof s=="object"&&s?E(s,t):s):v(e)?Object.keys(e).reduce((s,r)=>{const a=D(String(r));return s[a]=t?e[r]:E(e[r]),s},{}):e}async function Y(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)})}function ee(e,t="数据未能正确识别"){return typeof e=="function"?{guard:e,message:t}:{guard:e.guard,message:e.message||t}}function te(e,t=""){return!t||O(e,!0)?M(e):(M(t)+"/"+e).replace(/\/{2,}/g,"/").replace(/:\//,"://")}function M(e){return O(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 se(e,t){const s={};return(e.match(/([^=&#?]+)=[^&#]*/g)||[]).forEach(function(r){const a=r.split("="),n=a[0],o=decodeURIComponent(a[1]||"");s[n]!==void 0?s[n]+=","+o:s[n]=o}),t!==!0?s[t]||"":s}function re(e,t){if(t){if(t===!0)return e.replace(/\?[^#]*/,"")}else return e;const s=e.split("#"),r=s[0].split("?"),a=r[0],n=r.length>1?r[1]:"",o=s.length>1?"#"+s[1]:"",c=typeof t=="string"?[t]:Array.isArray(t)?t:[];return!c.length||!n?s[0]+o:(c.map(i=>i.replace(/([\\(){}[\]^$+\-*?|])/g,"\\$1")),(a+"?"+n.replace(new RegExp("(?:^|&)(?:"+c.join("|")+")=[^&$]+","g"),"").replace(/^&/,"")).replace(/\?$/,"")+o)}function ne(e,t,s=!1){const r=typeof t=="string"?t:Object.keys(t).map(o=>`${o}=${encodeURIComponent(t[o])}`).join("&");if(!r)return e;const a=e.split("#");s&&(a[0]=re(a[0],(r.match(/([^=&#?]+)=[^&#]+/g)||[]).map(o=>o.replace(/=.+$/,""))));const n=a[0].indexOf("?")+1?"&":"?";return(a[0]+n+r+(a.length>1?"#"+a[1]:"")).replace(/\?&/,"?")}function ae(e){const t=e.match(/(?:\?|&)([^=]+)(?:&|$)/g);return t?t.join("").replace(/(?:\?|^&+|&+$)/g,"").replace(/&{2}/g,"&").split("&").sort():[]}class oe{constructor(t=500){y(this,"ttl");y(this,"cache");this.cache={},this.ttl=Math.max(t,0)}getKey(t,s){const r=t.replace(/#.+/,""),a=r.replace(/\?.+/g,""),n=Object.assign(se(r,!0),s),o=ae(r),c=Object.keys(n).sort().map(i=>`${i}#${n[i]}`);return`${a}_${c.join(",")}_${o.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})}}const U="UnexpectResponse";function ce(e,t,s,r){if(t.ok&&!X(t.data)&&r){const a=ee(r,"响应数据未能正确识别");return a.guard(t.data)||(s.showMessage(!0,`${e} ${a.message}`,t.code,t.status),console.error(U,e,t.data),t.data=null,t.code=U,t.message=a.message),t}return t}class x{constructor(t){y(this,"config",{baseURL:"",maxRetry:0,retryInterval:1e3,retryResolve:"network",timeout:1e4,cacheTTL:500,credentials:"same-origin",responseRule:{ok:{resolve:"body"},failed:{resolve:"json",messageField:"message"}}});t&&this.set(t)}set(t){if(t.baseURL&&!/^\/.+/.test(t.baseURL)&&!O(t.baseURL))throw console.warn("baseURL 需要以 / 开头,或者是完整的 url 地址"),new Error("BaseURLError");Object.assign(this.config,t)}get(t){return this.config[t]}getFullUrl(t){return te(t,this.config.baseURL)}showMessage(t,s,r,a){this.config.messageHandler&&s&&this.config.messageHandler(t,s,r,a)}}class ie{constructor(t,s){y(this,"agent");y(this,"config");y(this,"cache");this.config=new x(s),this.agent=t,this.cache=new oe(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:"Unkonwn",message:String(r),headers:{},data:null}}}async guard(t,s,r){return ce(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 a=Object.assign({},r||null);a.method="GET";const n=this.cache.getKey(t,a.params),o=this.cache.get(n);if(o)return this.guard(t,await o,s||null);const c=this.request(t,a);return this.cache.set(n,c),this.guard(t,await c,s||null)}async post(t,s,r,a){const n=Object.assign({},a||null);return n.method="POST",n.body=s||{},this.guard(t,await this.request(t,n),r||null)}async del(t,s,r){const a=Object.assign({},r||null);return a.method="DELETE",this.guard(t,await this.request(t,a),s||null)}async put(t,s,r,a){const n=Object.assign({},a||null);return n.method="PUT",n.body=s||{},this.guard(t,await this.request(t,n),r||null)}async patch(t,s,r,a){const n=Object.assign({},a||null);return n.method="PATCH",n.body=s||{},this.guard(t,await this.request(t,n),r||null)}}const H="data",R="message";function ue(e,t,s,r,a){const n=a||r;return T(e)?ye(n.ok||r.ok,e,t,s):he(n.failed||r.failed,t,s)}const le=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||R)+" 作为错误消息");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||H)+" 作为响应数据,读取 "+(r.messageField||R)+" 作为提示消息"),r.statusField&&t.push(" 当 "+r.statusField+" 为 "+(r.statusOKValue||"空值")+" 时是成功提示,否则是错误消息"),r.ignoreMessage&&t.push(" 并忽略以下消息:"+r.ignoreMessage);break}return t.join(`
2
- `)};function he(e,t,s){const r=e||{resolve:"json",messageField:R},a={ok:!1,code:t,message:s,data:null};switch(r.resolve){case"body":a.message=L(s)||s;break;case"json":const{code:n,message:o}=de(s,r.converter,r.statusField,r.messageField);a.code=n||t,a.message=L(s)||o;break}return a}function de(e,t,s,r=R){if(!S(e))return{message:""};const a=F(k(e),t);return!a||!v(a)?{message:e}:{code:s?C(a,s):"",message:C(a,r)||e}}function C(e,t){const s=Array.isArray(t)?t:[t];for(const r of s)if(r in e)return ge(e[r]);return""}function ge(e){return e?typeof e=="string"?e:JSON.stringify(e):""}const fe=/<title>([^<]+)<\/title>/i,me=/<message>([^<]+)<\/message>/i;function L(e){const t=e.match(fe);if(t)return t[1];const s=e.match(me);return s?s[1]:""}function ye(e,t,s,r){const a=e||{resolve:"body"},n={ok:!0,code:s,message:"",data:null};if(t===204||!r)return n;if(a.resolve==="body")return n.data=S(r)?F(k(r),e.converter):r,n;const o=F(k(r),e.converter);if(!o||!v(o))return n.ok=!1,n.code="ResponseFormatError",n.message="响应内容无法格式化为 Object",n;const c=a.statusField,i=a.statusOKValue||"",h=a.dataField||H,u=a.messageField||R,l=a.ignoreMessage||"";if(c&&!(c in o))return n.ok=!1,n.code="ResponseFieldMissing",n.message="响应内容找不到状态字段 "+c,n;const d=c?o[c]+"":"";return n.ok=c?d===i:!0,n.code=d||s,n.data=h===!0?o:h in o?o[h]:null,n.message=C(o,u),l&&n.message&&(Array.isArray(l)&&l.includes(n.message)||typeof l=="string"&&n.message===l)&&(n.message=""),n}function T(e){return e>=200&&e<400}function F(e,t){return t==="camelize"?$(e):t==="snakify"?E(e):e}async function I(e,t,s,r,a){const n=a||0,o=Math.max(0,Math.min(10,(r==null?void 0:r.maxRetry)??s.get("maxRetry")??0)),c=(r==null?void 0:r.retryResolve)??s.get("retryResolve"),i=s.get("logHandler")||J;i({type:"prepear",url:t,method:(r==null?void 0:r.method)||"GET",retry:n,maxRetry:o,message:n===0?"start":`retry ${n}/${o} start`,headers:r==null?void 0:r.headers,options:r});const h=Date.now(),u=await e(t,s,r),l=u.status,d=Date.now()-h,g=`[cost ${d}][${l}] ${l<0?u.body:""}`;i({type:"finished",url:t,method:u.method,retry:n,maxRetry:o,message:n===0?`finish ${g}`:`retry ${n}/${o} finish ${g}`,response:u,headers:u.headers,cost:d});const m=T(l);if(!o||c==="network"&&l>0||c==="status"&&m||Array.isArray(c)&&!c.includes(l)||typeof c=="function"&&c(u,n)!==!0||n>=o)return u;const f=(r==null?void 0:r.retryInterval)??s.get("retryInterval")??1e3;return await G(Math.max(100,f==="2EB"?Math.pow(2,n)*1e3:typeof f=="function"?f(n+1)||0:f)),await I(e,t,s,r,n+1)}async function pe(e,t,s){var f;const r=Object.assign({method:"GET"},s),a=w.FormData?r.body instanceof FormData:!1,n=a&&r.method!=="POST"&&r.method!=="PUT"?"POST":r.method,o=n==="GET"||n==="HEAD"||n==="DELETE";o&&r.body!==void 0&&(console.warn("request body is invalid with method get, head, delete"),delete r.body);const c=Object.assign(a||o?{}:{"Content-Type":w.Blob&&r.body instanceof Blob?r.body.type||"application/octet-stream":"application/json;charset=utf-8"},r.headers),i=r.params||{},h={};Object.keys(i).forEach(b=>{i[b]!==void 0&&(h[b]=be(i[b]))});const u=t.getFullUrl(e),l=we(r.body),d=r.timeout||t.get("timeout"),g=await async function(){const b=t.get("requestTransformer");if(b)return await b({headers:c,params:h,method:n,url:u,body:l})}(),m=typeof g=="string"&&g?g:u;return(f=t.get("logHandler"))==null||f({type:"ready",url:m,method:n,headers:c,timeout:d,body:l}),{url:m,method:n,body:l,params:h,headers:c,timeout:d,abort:r.abort,credentials:r.credentials||t.get("credentials")}}function be(e){return typeof e=="string"?e:Array.isArray(e)?e.join(","):e+""}function we(e){if(e)return typeof e=="string"||e instanceof URLSearchParams||e instanceof ArrayBuffer||w.Blob&&e instanceof Blob||w.FormData&&e instanceof FormData?e:JSON.stringify(e)}const Re=V("APIError");function je(e){const t={};for(const s in e.headers)(s.startsWith("x-")||s.includes("trace")||s.includes("server")||/\b(?:id|uuid)\b/.test(s))&&(t[s]=e.headers[s]);return{sentryError:new Re(`${e.url.replace(/^(?:https?:)?\/*/i,"")} | ${e.status}${e.code?` | ${e.code}`:""}`),sentryTags:{...t,status:e.status<0?"unknown":e.status,method:e.method,code:e.code||"unknown",message:e.message||"empty"},sentryExtra:{url:e.url,responseBody:e.body,responseHeaders:e.headers}}}function $e(e,t,s,r){var g;const a=e.status,n=e.method,o=q(Object.entries(e.headers||{}).map(([m,f])=>[m.toLowerCase(),f])),{ok:c,code:i,data:h,message:u}=ue(a,e.statusText,e.body,s.get("responseRule"),r==null?void 0:r.responseRule);if(!T(a)){const m=je({url:e.url,method:e.method,status:a,code:i,message:u,body:e.body,headers:o});(s.get("errorHandler")||Ee)({url:t,method:n,status:a,code:i,message:u,headers:o,rawError:e.rawError,responseBody:e.body,...m})}if(a<0)return P({ok:!1,status:a,code:e.statusText,headers:{},message:"",data:null},`${n} ${t} ${e.statusText}`,n,t,s,r);const l={ok:c,data:h,code:i,message:u,status:a,headers:o};(g=s.get("responseHandler"))==null||g({...l},n,t);const d=c?u:u||e.statusText;return P(l,d,n,t,s,r)}function P(e,t,s,r,a,n){const o=a.get("message"),c=o===!1||(n==null?void 0:n.message)===!1?!1:(n==null?void 0:n.message)||o;if(c!==!1){const i=typeof c=="function"?c(e,s,r,t):t;i instanceof Error?a.showMessage(!0,i.message,e.code,e.status):i&&typeof i=="object"&&"message"in i?a.showMessage(!1,i.message,e.code,e.status):a.showMessage(!e.ok,i,e.code,e.status)}return e}function Ee(e){const t={};for(const s in e)s.startsWith("sentry")||(t[s]=e[s]);console.error("RequestError",t)}const Oe="2.0.3";exports.Ee=Y;exports.K=O;exports.NetRequestHandler=ie;exports.RequestGlobalConfig=x;exports.Support=w;exports.convertOptions=pe;exports.fromEntries=q;exports.getResponseRulesDescription=le;exports.handleResponse=$e;exports.retryRequest=I;exports.version=Oe;exports.vt=ne;
1
+ "use strict";var K=Object.defineProperty;var N=(e,t,s)=>t in e?K(e,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[t]=s;var y=(e,t,s)=>(N(e,typeof t!="symbol"?t+"":t,s),s);const p=typeof globalThis<"u"?globalThis:typeof global<"u"?global:typeof window<"u"?window:{},w={fetch:"fetch"in p,window:"window"in p,FormData:"FormData"in p,Blob:"Blob"in p,wx:"wx"in p,TextDecoder:"TextDecoder"in p,AbortController:"AbortController"in p};function q(e){return e.reduce((t,[s,r])=>(s&&(t[s]=r||""),t),{})}function G(e){return new Promise(t=>setTimeout(t,Math.max(0,e)))}function J(){}function V(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&&Error.captureStackTrace(this,this.constructor)}}}function j(e){return e?e[0].toLowerCase()+e.slice(1):""}const _=/_\w*/,x=/-\w*/;function A(e){const t=_.test(e)?e.replace(/(?:^_*|_*$)/g,"").replace(/_+([^_])/g,(s,r)=>r.toUpperCase()):x.test(e)?e.replace(/(?:^-*|-*$)/g,"").replace(/-+(\w)/g,(s,r)=>r.toUpperCase()):e;return j(t)}function U(e){return _.test(e)?j(e).replace(/(?:^_*|_*$)/g,"").replace(/_+([^_])/g,(t,s)=>"_"+s.toLowerCase()):x.test(e)?j(e.replace(/(?:^-*|-*$)/g,"")).replace(/-+(\w)/g,(t,s)=>"_"+s.toLowerCase()):j(e).replace(/[A-Z]/g,t=>`_${t.toLowerCase()}`)}const W=/^(?:https?:)?\/\/.+$/i,z=/^https?:\/\/.+$/i,Q=/^\{[\d\D]*\}$/,Z=/^\[[\d\D]*\]$/;function O(e,t=!1){return t?W.test(e):z.test(e)}function X(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 Q.test(e)||Z.test(e)}function k(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"?A(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 a=A(String(r)),n=a.charAt(0).toLowerCase()+a.slice(1);return s[n]=t?e[r]:E(e[r]),s},{}):e}function $(e,t=!1){return typeof e=="string"?U(e):Array.isArray(e)?e.map(s=>!t||typeof s=="string"?$(s):typeof s=="object"&&s?$(s,t):s):v(e)?Object.keys(e).reduce((s,r)=>{const a=U(String(r));return s[a]=t?e[r]:$(e[r]),s},{}):e}async function Y(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)})}function ee(e,t="数据未能正确识别"){return typeof e=="function"?{guard:e,message:t}:{guard:e.guard,message:e.message||t}}function te(e,t=""){return!t||O(e,!0)?D(e):(D(t)+"/"+e).replace(/\/{2,}/g,"/").replace(/:\//,"://")}function D(e){return O(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 se(e,t){const s={};return(e.match(/([^=&#?]+)=[^&#]*/g)||[]).forEach(function(r){const a=r.split("="),n=a[0],o=decodeURIComponent(a[1]||"");s[n]!==void 0?s[n]+=","+o:s[n]=o}),t!==!0?s[t]||"":s}function re(e,t){if(t){if(t===!0)return e.replace(/\?[^#]*/,"")}else return e;const s=e.split("#"),r=s[0].split("?"),a=r[0],n=r.length>1?r[1]:"",o=s.length>1?"#"+s[1]:"",c=typeof t=="string"?[t]:Array.isArray(t)?t:[];return!c.length||!n?s[0]+o:(c.map(i=>i.replace(/([\\(){}[\]^$+\-*?|])/g,"\\$1")),(a+"?"+n.replace(new RegExp("(?:^|&)(?:"+c.join("|")+")=[^&$]+","g"),"").replace(/^&/,"")).replace(/\?$/,"")+o)}function ne(e,t,s=!1){const r=typeof t=="string"?t:Object.keys(t).map(o=>`${o}=${encodeURIComponent(t[o])}`).join("&");if(!r)return e;const a=e.split("#");s&&(a[0]=re(a[0],(r.match(/([^=&#?]+)=[^&#]+/g)||[]).map(o=>o.replace(/=.+$/,""))));const n=a[0].indexOf("?")+1?"&":"?";return(a[0]+n+r+(a.length>1?"#"+a[1]:"")).replace(/\?&/,"?")}function ae(e){const t=e.match(/(?:\?|&)([^=]+)(?:&|$)/g);return t?t.join("").replace(/(?:\?|^&+|&+$)/g,"").replace(/&{2}/g,"&").split("&").sort():[]}class oe{constructor(t=500){y(this,"ttl");y(this,"cache");this.cache={},this.ttl=Math.max(t,0)}getKey(t,s){const r=t.replace(/#.+/,""),a=r.replace(/\?.+/g,""),n=Object.assign(se(r,!0),s),o=ae(r),c=Object.keys(n).sort().map(i=>`${i}#${n[i]}`);return`${a}_${c.join(",")}_${o.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})}}const M="UnexpectResponse";function ce(e,t,s,r){if(t.ok&&!X(t.data)&&r){const a=ee(r,"响应数据未能正确识别");return a.guard(t.data)||(s.showMessage(!0,`${e} ${a.message}`,t.code,t.status),console.error(M,e,t.data),t.data=null,t.code=M,t.message=a.message),t}return t}class S{constructor(t){y(this,"config",{baseURL:"",maxRetry:0,retryInterval:1e3,retryResolve:"network",timeout:1e4,cacheTTL:500,credentials:"same-origin",responseRule:{ok:{resolve:"body"},failed:{resolve:"json",messageField:"message"}}});t&&this.set(t)}set(t){if(t.baseURL&&!/^\/.+/.test(t.baseURL)&&!O(t.baseURL))throw console.warn("baseURL 需要以 / 开头,或者是完整的 url 地址"),new Error("BaseURLError");Object.assign(this.config,t)}get(t){return this.config[t]}getFullUrl(t){return te(t,this.config.baseURL)}showMessage(t,s,r,a){this.config.messageHandler&&s&&this.config.messageHandler(t,s,r,a)}}class ie{constructor(t,s){y(this,"agent");y(this,"config");y(this,"cache");this.config=new S(s),this.agent=t,this.cache=new oe(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:"Unkonwn",message:String(r),headers:{},data:null}}}async guard(t,s,r){return ce(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 a=Object.assign({},r||null);a.method="GET";const n=this.cache.getKey(t,a.params),o=this.cache.get(n);if(o)return this.guard(t,await o,s||null);const c=this.request(t,a);return this.cache.set(n,c),this.guard(t,await c,s||null)}async post(t,s,r,a){const n=Object.assign({},a||null);return n.method="POST",n.body=s||{},this.guard(t,await this.request(t,n),r||null)}async del(t,s,r){const a=Object.assign({},r||null);return a.method="DELETE",this.guard(t,await this.request(t,a),s||null)}async put(t,s,r,a){const n=Object.assign({},a||null);return n.method="PUT",n.body=s||{},this.guard(t,await this.request(t,n),r||null)}async patch(t,s,r,a){const n=Object.assign({},a||null);return n.method="PATCH",n.body=s||{},this.guard(t,await this.request(t,n),r||null)}}const H="data",R="message";function ue(e,t,s,r,a){const n=a||r;return T(e)?ye(n.ok||r.ok,e,t,s):he(n.failed||r.failed,t,s)}const le=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||R)+" 作为错误消息");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||H)+" 作为响应数据,读取 "+(r.messageField||R)+" 作为提示消息"),r.statusField&&t.push(" 当 "+r.statusField+" 为 "+(r.statusOKValue||"空值")+" 时是成功提示,否则是错误消息"),r.ignoreMessage&&t.push(" 并忽略以下消息:"+r.ignoreMessage);break}return t.join(`
2
+ `)};function he(e,t,s){const r=e||{resolve:"json",messageField:R},a={ok:!1,code:t,message:s,data:null};switch(r.resolve){case"body":a.message=L(s)||s;break;case"json":const{code:n,message:o}=de(s,r.converter,r.statusField,r.messageField);a.code=n||t,a.message=L(s)||o;break}return a}function de(e,t,s,r=R){if(!B(e))return{message:""};const a=F(k(e),t);return!a||!v(a)?{message:e}:{code:s?C(a,s):"",message:C(a,r)||e}}function C(e,t){const s=Array.isArray(t)?t:[t];for(const r of s)if(r in e)return ge(e[r]);return""}function ge(e){return e?typeof e=="string"?e:JSON.stringify(e):""}const fe=/<title>([^<]+)<\/title>/i,me=/<message>([^<]+)<\/message>/i;function L(e){const t=e.match(fe);if(t)return t[1];const s=e.match(me);return s?s[1]:""}function ye(e,t,s,r){const a=e||{resolve:"body"},n={ok:!0,code:s,message:"",data:null};if(t===204||!r)return n;if(a.resolve==="body")return n.data=B(r)?F(k(r),e.converter):r,n;const o=F(k(r),e.converter);if(!o||!v(o))return n.ok=!1,n.code="ResponseFormatError",n.message="响应内容无法格式化为 Object",n;const c=a.statusField,i=a.statusOKValue||"",h=a.dataField||H,u=a.messageField||R,l=a.ignoreMessage||"";if(c&&!(c in o))return n.ok=!1,n.code="ResponseFieldMissing",n.message="响应内容找不到状态字段 "+c,n;const d=c?o[c]+"":"";return n.ok=c?d===i:!0,n.code=d||s,n.data=h===!0?o:h in o?o[h]:null,n.message=C(o,u),l&&n.message&&(Array.isArray(l)&&l.includes(n.message)||typeof l=="string"&&n.message===l)&&(n.message=""),n}function T(e){return e>=200&&e<400}function F(e,t){return t==="camelize"?E(e):t==="snakify"?$(e):e}async function I(e,t,s,r,a){const n=a||0,o=Math.max(0,Math.min(10,(r==null?void 0:r.maxRetry)??s.get("maxRetry")??0)),c=(r==null?void 0:r.retryResolve)??s.get("retryResolve"),i=s.get("logHandler")||J;i({type:"prepear",url:t,method:(r==null?void 0:r.method)||"GET",retry:n,maxRetry:o,message:n===0?"start":`retry ${n}/${o} start`,headers:r==null?void 0:r.headers,options:r});const h=Date.now(),u=await e(t,s,r),l=u.status,d=Date.now()-h,g=`[cost ${d}][${l}] ${l<0?u.body:""}`;i({type:"finished",url:t,method:u.method,retry:n,maxRetry:o,message:n===0?`finish ${g}`:`retry ${n}/${o} finish ${g}`,response:u,headers:u.headers,cost:d});const m=T(l);if(!o||c==="network"&&l>0||c==="status"&&m||Array.isArray(c)&&!c.includes(l)||typeof c=="function"&&c(u,n)!==!0||n>=o)return u;const f=(r==null?void 0:r.retryInterval)??s.get("retryInterval")??1e3;return await G(Math.max(100,f==="2EB"?Math.pow(2,n)*1e3:typeof f=="function"?f(n+1)||0:f)),await I(e,t,s,r,n+1)}async function pe(e,t,s){var f;const r=Object.assign({method:"GET"},s),a=w.FormData?r.body instanceof FormData:!1,n=a&&r.method!=="POST"&&r.method!=="PUT"?"POST":r.method,o=n==="GET"||n==="HEAD"||n==="DELETE";o&&r.body!==void 0&&(console.warn("request body is invalid with method get, head, delete"),delete r.body);const c=Object.assign(a||o?{}:{"Content-Type":w.Blob&&r.body instanceof Blob?r.body.type||"application/octet-stream":"application/json;charset=utf-8"},r.headers),i=r.params||{},h={};Object.keys(i).forEach(b=>{i[b]!==void 0&&(h[b]=be(i[b]))});const u=t.getFullUrl(e),l=we(r.body),d=r.timeout||t.get("timeout"),g=await async function(){const b=t.get("requestTransformer");if(b)return await b({headers:c,params:h,method:n,url:u,body:l})}(),m=typeof g=="string"&&g?g:u;return(f=t.get("logHandler"))==null||f({type:"ready",url:m,method:n,headers:c,timeout:d,body:l}),{url:m,method:n,body:l,params:h,headers:c,timeout:d,abort:r.abort,credentials:r.credentials||t.get("credentials")}}function be(e){return typeof e=="string"?e:Array.isArray(e)?e.join(","):e+""}function we(e){if(e)return typeof e=="string"||e instanceof URLSearchParams||e instanceof ArrayBuffer||w.Blob&&e instanceof Blob||w.FormData&&e instanceof FormData?e:JSON.stringify(e)}const Re=V("APIError");function je(e){const t={};for(const a in e.headers)(a.startsWith("x-")||a.includes("trace")||a.includes("server")||/\b(?:id|uuid)\b/.test(a))&&(t[a]=e.headers[a]);const s=e.url.replace(/^(?:https?:)?\/*/i,"").replace(/\?.+/,""),r=e.status<0?"unknown":e.status;return{sentryError:new Re(`${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 Ee(e,t,s,r){var g;const a=e.status,n=e.method,o=q(Object.entries(e.headers||{}).map(([m,f])=>[m.toLowerCase(),f])),{ok:c,code:i,data:h,message:u}=ue(a,e.statusText,e.body,s.get("responseRule"),r==null?void 0:r.responseRule);if(!T(a)){const m=je({url:e.url,method:e.method,status:a,code:i,message:u,body:e.body,headers:o,error:e.rawError});(s.get("errorHandler")||$e)({url:t,method:n,status:a,code:i,message:u,headers:o,rawError:e.rawError,responseBody:e.body,...m})}if(a<0)return P({ok:!1,status:a,code:e.statusText,headers:{},message:"",data:null},`${n} ${t} ${e.statusText}`,n,t,s,r);const l={ok:c,data:h,code:i,message:u,status:a,headers:o};(g=s.get("responseHandler"))==null||g({...l},n,t);const d=c?u:u||e.statusText;return P(l,d,n,t,s,r)}function P(e,t,s,r,a,n){const o=a.get("message"),c=o===!1||(n==null?void 0:n.message)===!1?!1:(n==null?void 0:n.message)||o;if(c!==!1){const i=typeof c=="function"?c(e,s,r,t):t;i instanceof Error?a.showMessage(!0,i.message,e.code,e.status):i&&typeof i=="object"&&"message"in i?a.showMessage(!1,i.message,e.code,e.status):a.showMessage(!e.ok,i,e.code,e.status)}return e}function $e(e){const t={};for(const s in e)s.startsWith("sentry")||(t[s]=e[s]);console.error("RequestError",t)}const Oe="2.0.5";exports.Ee=Y;exports.K=O;exports.NetRequestHandler=ie;exports.RequestGlobalConfig=S;exports.Support=w;exports.convertOptions=pe;exports.fromEntries=q;exports.getResponseRulesDescription=le;exports.handleResponse=Ee;exports.retryRequest=I;exports.version=Oe;exports.vt=ne;
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const version = "2.0.3";
1
+ export declare const version = "2.0.5";
package/dist/wx.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./version-kPzj9ZQV.cjs"),p=async function(t,r,n){return e.handleResponse(await e.retryRequest(l,t,r,n),t,r,n)},l=async function(t,r,n){const o=await e.convertOptions(t,r,n),u=o.method==="PATCH"?"POST":o.method,a=e.vt(o.url,o.params);return e.Support.wx?new Promise(d=>{wx.request({url:a,data:o.body,header:o.headers,method:u,dataType:"string",responseType:"text",fail(){d({url:a,method:u,status:-1,statusText:"NetworkError",body:""})},success(c){d({url:a,method:u,status:c.statusCode,statusText:c.statusCode+"",headers:{...c.header},body:o.method==="HEAD"?"":f(c.data)})}})}):{url:a,method:u,status:-1,statusText:"NotSupport",body:"NotFound namespace of wx"}};function f(t){return typeof t=="string"?t:t instanceof ArrayBuffer&&e.Support.TextDecoder?new TextDecoder().decode(t):JSON.stringify(t)}function i(t){return new e.NetRequestHandler(p,t)}const s=i(),y=s.setConfig,g=s.head,h=s.get,x=s.post,w=s.del,T=s.put;exports.version=e.version;exports.NetRequest=i;exports.del=w;exports.get=h;exports.head=g;exports.post=x;exports.put=T;exports.setGlobalConfig=y;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./version-otf8Cl2Z.cjs"),p=async function(t,n,r){return e.handleResponse(await e.retryRequest(l,t,n,r),t,n,r)},l=async function(t,n,r){const s=await e.convertOptions(t,n,r),u=s.method==="PATCH"?"POST":s.method,a=e.vt(s.url,s.params);return e.Support.wx?new Promise(d=>{wx.request({url:a,data:s.body,header:s.headers,method:u,dataType:"string",responseType:"text",fail(){d({url:a,method:u,status:-1,statusText:"Unknown",body:""})},success(c){d({url:a,method:u,status:c.statusCode,statusText:c.statusCode+"",headers:{...c.header},body:s.method==="HEAD"?"":f(c.data)})}})}):{url:a,method:u,status:-1,statusText:"NotSupport",body:""}};function f(t){return typeof t=="string"?t:t instanceof ArrayBuffer&&e.Support.TextDecoder?new TextDecoder().decode(t):JSON.stringify(t)}function i(t){return new e.NetRequestHandler(p,t)}const o=i(),y=o.setConfig,g=o.head,h=o.get,x=o.post,T=o.del,b=o.put;exports.version=e.version;exports.NetRequest=i;exports.del=T;exports.get=h;exports.head=g;exports.post=x;exports.put=b;exports.setGlobalConfig=y;
package/dist/wx.js CHANGED
@@ -1,30 +1,30 @@
1
- import { h as i, r as p, c as f, v as l, S as d, N as x } from "./version-CjW4Ddf0.js";
2
- import { a as A } from "./version-CjW4Ddf0.js";
3
- const h = async function(t, o, r) {
4
- return i(await p(y, t, o, r), t, o, r);
5
- }, y = async function(t, o, r) {
6
- const e = await f(t, o, r), n = e.method === "PATCH" ? "POST" : e.method, a = l(e.url, e.params);
1
+ import { h as i, r as p, c as f, v as l, S as d, N as h } from "./version-BEDupKzt.js";
2
+ import { a as A } from "./version-BEDupKzt.js";
3
+ const x = async function(t, o, n) {
4
+ return i(await p(y, t, o, n), t, o, n);
5
+ }, y = async function(t, o, n) {
6
+ const e = await f(t, o, n), r = e.method === "PATCH" ? "POST" : e.method, a = l(e.url, e.params);
7
7
  return d.wx ? new Promise((c) => {
8
8
  wx.request({
9
9
  url: a,
10
10
  data: e.body,
11
11
  header: e.headers,
12
- method: n,
12
+ method: r,
13
13
  dataType: "string",
14
14
  responseType: "text",
15
15
  fail() {
16
16
  c({
17
17
  url: a,
18
- method: n,
18
+ method: r,
19
19
  status: -1,
20
- statusText: "NetworkError",
20
+ statusText: "Unknown",
21
21
  body: ""
22
22
  });
23
23
  },
24
24
  success(u) {
25
25
  c({
26
26
  url: a,
27
- method: n,
27
+ method: r,
28
28
  status: u.statusCode,
29
29
  statusText: u.statusCode + "",
30
30
  headers: { ...u.header },
@@ -34,26 +34,26 @@ const h = async function(t, o, r) {
34
34
  });
35
35
  }) : {
36
36
  url: a,
37
- method: n,
37
+ method: r,
38
38
  status: -1,
39
39
  statusText: "NotSupport",
40
- body: "NotFound namespace of wx"
40
+ body: ""
41
41
  };
42
42
  };
43
43
  function m(t) {
44
44
  return typeof t == "string" ? t : t instanceof ArrayBuffer && d.TextDecoder ? new TextDecoder().decode(t) : JSON.stringify(t);
45
45
  }
46
46
  function w(t) {
47
- return new x(h, t);
47
+ return new h(x, t);
48
48
  }
49
- const s = w(), g = s.setConfig, q = s.head, N = s.get, R = s.post, b = s.del, S = s.put;
49
+ const s = w(), g = s.setConfig, q = s.head, R = s.get, b = s.post, S = s.del, C = s.put;
50
50
  export {
51
51
  w as NetRequest,
52
- b as del,
53
- N as get,
52
+ S as del,
53
+ R as get,
54
54
  q as head,
55
- R as post,
56
- S as put,
55
+ b as post,
56
+ C as put,
57
57
  g as setGlobalConfig,
58
58
  A as version
59
59
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seayoo-web/request",
3
- "version": "2.0.3",
3
+ "version": "2.0.5",
4
4
  "description": "requst tools for seayoo web",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -1 +0,0 @@
1
- "use strict";const r=require("./version-kPzj9ZQV.cjs"),h=async function(s,o,n){return r.handleResponse(await r.retryRequest(b,s,o,n),s,o,n)},b=async function(s,o,n){const t=await r.convertOptions(s,o,n),i=new URL(t.url),d=t.params;d instanceof Object&&Object.keys(d).forEach(a=>i.searchParams.set(a,d[a]));const e=r.Support.AbortController?new AbortController:null;function u(){e&&!e.signal.aborted&&e.abort()}t.abort&&t.abort.addEventListener("abort",u);const c=t.timeout>0?setTimeout(u,t.timeout):null;return await fetch(i,{method:t.method,headers:Object.keys(t.headers).length>0?new Headers(t.headers):void 0,body:t.body,credentials:t.credentials,signal:e==null?void 0:e.signal,redirect:"follow"}).then(async a=>({url:i.toString(),method:t.method,status:a.status,statusText:a.statusText,headers:r.fromEntries([...a.headers.entries()]),body:t.method==="HEAD"?"":await a.text()})).catch(a=>({url:i.toString(),method:t.method,status:-1,statusText:e!=null&&e.signal.aborted?"Aborted":"NetworkError",body:String(a),rawError:e!=null&&e.signal.aborted?void 0:a})).finally(()=>{c!==null&&clearTimeout(c),t.abort&&t.abort.removeEventListener("abort",u)})};exports.fetchRequest=h;
@@ -1,40 +0,0 @@
1
- import { h as c, r as h, c as b, S as m, f as l } from "./version-CjW4Ddf0.js";
2
- const y = async function(s, r, o) {
3
- return c(await h(f, s, r, o), s, r, o);
4
- }, f = async function(s, r, o) {
5
- const t = await b(s, r, o), n = new URL(t.url), i = t.params;
6
- i instanceof Object && Object.keys(i).forEach((a) => n.searchParams.set(a, i[a]));
7
- const e = m.AbortController ? new AbortController() : null;
8
- function d() {
9
- e && !e.signal.aborted && e.abort();
10
- }
11
- t.abort && t.abort.addEventListener("abort", d);
12
- const u = t.timeout > 0 ? setTimeout(d, t.timeout) : null;
13
- return await fetch(n, {
14
- method: t.method,
15
- headers: Object.keys(t.headers).length > 0 ? new Headers(t.headers) : void 0,
16
- body: t.body,
17
- credentials: t.credentials,
18
- signal: e == null ? void 0 : e.signal,
19
- redirect: "follow"
20
- }).then(async (a) => ({
21
- url: n.toString(),
22
- method: t.method,
23
- status: a.status,
24
- statusText: a.statusText,
25
- headers: l([...a.headers.entries()]),
26
- body: t.method === "HEAD" ? "" : await a.text()
27
- })).catch((a) => ({
28
- url: n.toString(),
29
- method: t.method,
30
- status: -1,
31
- statusText: e != null && e.signal.aborted ? "Aborted" : "NetworkError",
32
- body: String(a),
33
- rawError: e != null && e.signal.aborted ? void 0 : a
34
- })).finally(() => {
35
- u !== null && clearTimeout(u), t.abort && t.abort.removeEventListener("abort", d);
36
- });
37
- };
38
- export {
39
- y as f
40
- };