@seayoo-web/request 3.3.0 → 3.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/index.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("./retry-BltIjZ1L.cjs"),m=require("./request.fetch-BqSnA_jT.cjs"),y=async function(t,s,e){return r.handleResponse(await r.retryRequest(R,t,s,e),t,s,e)};async function E(t,s,e,n){const o=e?.body,u=e?.method==="PUT"?"PUT":"POST";if(s instanceof Blob){const i=new r.RequestGlobalConfig(n),f=await R(t,i,{...e,method:u,body:s});return r.handleResponse(f,t,i,e)}const l=new FormData,d={...s};o instanceof Object&&Object.entries(o).forEach(([i,f])=>{f instanceof Blob?d[i]=f:Array.isArray(f)?f.forEach((a,p)=>{l.append(`${i}[${p}]`,String(a))}):l.append(i,String(f))});for(const i in d)l.append(i,d[i]);const b=new r.RequestGlobalConfig(n),w=await R(t,b,{...e,method:u,body:l});return r.handleResponse(w,t,b,e)}const R=async function(t,s,e){const n=await r.convertOptions(t,s,e),o=n.method,u=e?.onUploadProgress,l=r._e(n.url,n.params);return await new Promise(d=>{let b=null,w=!1;const i=function(){w||(a.abort(),w=!0)};function f(){b!==null&&clearTimeout(b),n.abort&&n.abort.removeEventListener("abort",i)}const a=new XMLHttpRequest;let p=!1;if(a.open(o,l,!0),u){let g=1;a.upload.addEventListener("progress",h=>{g=h.total,u({total:h.total,loaded:h.loaded})}),a.addEventListener("load",()=>{u({loaded:g,total:g})})}a.addEventListener("load",()=>{const g=a.status;f(),d({url:l,method:o,status:g,statusText:a.statusText,headers:T(a),body:o==="HEAD"||g===204?"":a.responseText})}),a.addEventListener("error",g=>{f(),d({url:l,method:o,status:a.status||-1,statusText:a.statusText||r.RequestInternalError.NetworkError,body:"",rawError:g})},!0),a.addEventListener("abort",()=>{f(),d({url:l,method:o,status:p?-1:0,statusText:p?r.RequestInternalError.Timeout:r.RequestInternalError.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",i),n.timeout>0&&(b=setTimeout(function(){p=!0,i()},n.timeout))})};function T(t){const s={};if(!t)return s;const e=t.getAllResponseHeaders();return e&&e!=="null"&&e.replace(/\r/g,"").split(`
2
- `).forEach(n=>{const o=n.trim();if(!o)return;const u=o.split(":"),l=u[0].trim();l&&(s[l]=(u[1]||"").trim())}),s}async function H(t,s,e={}){const n=window;"callback"in e||(e.callback="jsonxData"+Math.random().toString(16).slice(2));const o=e.callback+"";if(!t)return null;const u=r._e(t,e,!0);return new Promise(l=>{n[o]=function(d){if(o in window&&delete n[o],s(d))return d;console.warn("response type check failed",t,d),l(null)},r.le(u).catch(function(){l(null),delete n[o]})})}async function j(t,s,e={}){const n=window;return"var"in e||(e.var="jsonxData"+Math.random().toString(16).slice(2)),t?await r.le(r._e(t,e,!0)).then(()=>{const o=n[e.var+""];return s(o)?o:(console.warn("response type check failed",t,o),null)}).catch(()=>null):null}const x=async function(t,s,e){return await E(t,s,e,{baseURL:c.getConfig("baseURL"),logHandler:c.getConfig("logHandler"),errorHandler:c.getConfig("errorHandler"),requestTransformer:c.getConfig("requestTransformer"),messageHandler:c.getConfig("messageHandler"),responseHandler:c.getConfig("responseHandler")})};function q(t){if(!r.jt.window)throw new Error("Default Module Only Support In Browser");return r.jt.fetch?new r.NetRequestHandler(m.fetchRequest,t):new r.NetRequestHandler(y,t)}const c=q(),C=c.setConfig,L=c.request,S=c.head,k=c.get,v=c.post,D=c.del,U=c.put,O=c.patch;exports.RequestInternalError=r.RequestInternalError;exports.getResponseRulesDescription=r.getResponseRulesDescription;exports.NetRequest=q;exports.del=D;exports.get=k;exports.head=S;exports.jsonp=H;exports.jsonx=j;exports.patch=O;exports.post=v;exports.put=U;exports.request=L;exports.setGlobalConfig=C;exports.upload=x;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("./retry-sL4_1f7S.cjs"),y=require("./request.fetch-0OA7qu9S.cjs"),m=async function(t,s,e){return r.handleResponse(await r.retryRequest(R,t,s,e),t,s,e)};async function E(t,s,e,n){const o=e?.body,u=e?.method==="PUT"?"PUT":"POST";if(s instanceof Blob){const l=new r.RequestGlobalConfig(n),f=await R(t,l,{...e,method:u,body:s});return r.handleResponse(f,t,l,e)}const c=new FormData,d={...s};o instanceof Object&&Object.entries(o).forEach(([l,f])=>{f instanceof Blob?d[l]=f:Array.isArray(f)?f.forEach((a,p)=>{c.append(`${l}[${p}]`,String(a))}):c.append(l,String(f))});for(const l in d)c.append(l,d[l]);const b=new r.RequestGlobalConfig(n),w=await R(t,b,{...e,method:u,body:c});return r.handleResponse(w,t,b,e)}const R=async function(t,s,e){const n=await r.convertOptions(t,s,e),o=n.method,u=e?.onUploadProgress,c=r.ye(n.url,n.params);return await new Promise(d=>{let b=null,w=!1;const l=function(){w||(a.abort(),w=!0)};function f(){b!==null&&clearTimeout(b),n.abort&&n.abort.removeEventListener("abort",l)}const a=new XMLHttpRequest;let p=!1;if(a.open(o,c,!0),u){let g=1;a.upload.addEventListener("progress",h=>{g=h.total,u({total:h.total,loaded:h.loaded})}),a.addEventListener("load",()=>{u({loaded:g,total:g})})}a.addEventListener("load",()=>{const g=a.status;f(),d({url:c,method:o,status:g,statusText:a.statusText,headers:T(a),body:o==="HEAD"||g===204?"":a.responseText})}),a.addEventListener("error",g=>{f(),d({url:c,method:o,status:a.status||-1,statusText:a.statusText||r.RequestInternalError.NetworkError,body:"",rawError:g})},!0),a.addEventListener("abort",()=>{f(),d({url:c,method:o,status:p?-1:0,statusText:p?r.RequestInternalError.Timeout:r.RequestInternalError.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",l),n.timeout>0&&(b=setTimeout(function(){p=!0,l()},n.timeout))})};function T(t){const s={};if(!t)return s;const e=t.getAllResponseHeaders();return e&&e!=="null"&&e.replace(/\r/g,"").split(`
2
+ `).forEach(n=>{const o=n.trim();if(!o)return;const u=o.split(":"),c=u[0].trim();c&&(s[c]=(u[1]||"").trim())}),s}async function H(t,s,e={}){const n=window;"callback"in e||(e.callback="jsonxData"+Math.random().toString(16).slice(2));const o=e.callback+"";if(!t)return null;const u=r.ye(t,e,!0);return new Promise(c=>{n[o]=function(d){if(o in window&&delete n[o],s(d))return d;console.warn("response type check failed",t,d),c(null)},r.ue(u).catch(function(){c(null),delete n[o]})})}async function C(t,s,e={}){const n=window;return"var"in e||(e.var="jsonxData"+Math.random().toString(16).slice(2)),t?await r.ue(r.ye(t,e,!0)).then(()=>{const o=n[e.var+""];return s(o)?o:(console.warn("response type check failed",t,o),null)}).catch(()=>null):null}const x=async function(t,s,e){return await E(t,s,e,{baseURL:i.getConfig("baseURL"),logHandler:i.getConfig("logHandler"),errorHandler:i.getConfig("errorHandler"),requestTransformer:i.getConfig("requestTransformer"),messageHandler:i.getConfig("messageHandler"),responseHandler:i.getConfig("responseHandler")})};function q(t){if(!r.Ct.window)throw new Error("Default Module Only Support In Browser");return r.Ct.fetch?new r.NetRequestHandler(y.fetchRequest,t):new r.NetRequestHandler(m,t)}const i=q(),j=i.setConfig,L=i.request,S=i.head,k=i.get,v=i.post,D=i.del,U=i.put,O=i.patch;exports.RequestInternalError=r.RequestInternalError;exports.getResponseRulesDescription=r.getResponseRulesDescription;exports.NetRequest=q;exports.del=D;exports.get=k;exports.head=S;exports.jsonp=H;exports.jsonx=C;exports.patch=O;exports.post=v;exports.put=U;exports.request=L;exports.setGlobalConfig=j;exports.upload=x;
package/dist/index.js CHANGED
@@ -1,27 +1,27 @@
1
- import { h as m, r as x, R as T, c as C, _ as R, a as w, l as q, j as E, N as H } from "./retry-D8V8lDdS.js";
2
- import { g as J } from "./retry-D8V8lDdS.js";
3
- import { f as L } from "./request.fetch-CLcd8XUK.js";
4
- const j = async function(t, o, e) {
1
+ import { h as m, r as x, R as T, c as C, y as R, a as w, u as q, C as E, N as H } from "./retry-vMhW20_a.js";
2
+ import { g as K } from "./retry-vMhW20_a.js";
3
+ import { f as L } from "./request.fetch-BJaP3VPV.js";
4
+ const k = async function(t, o, e) {
5
5
  return m(await x(y, t, o, e), t, o, e);
6
6
  };
7
- async function k(t, o, e, n) {
7
+ async function S(t, o, e, n) {
8
8
  const r = e?.body, l = e?.method === "PUT" ? "PUT" : "POST";
9
9
  if (o instanceof Blob) {
10
- const i = new T(n), u = await y(t, i, {
10
+ const i = new T(n), d = await y(t, i, {
11
11
  ...e,
12
12
  method: l,
13
13
  body: o
14
14
  });
15
- return m(u, t, i, e);
15
+ return m(d, t, i, e);
16
16
  }
17
- const a = new FormData(), d = { ...o };
18
- r instanceof Object && Object.entries(r).forEach(([i, u]) => {
19
- u instanceof Blob ? d[i] = u : Array.isArray(u) ? u.forEach((s, g) => {
17
+ const a = new FormData(), u = { ...o };
18
+ r instanceof Object && Object.entries(r).forEach(([i, d]) => {
19
+ d instanceof Blob ? u[i] = d : Array.isArray(d) ? d.forEach((s, g) => {
20
20
  a.append(`${i}[${g}]`, String(s));
21
- }) : a.append(i, String(u));
21
+ }) : a.append(i, String(d));
22
22
  });
23
- for (const i in d)
24
- a.append(i, d[i]);
23
+ for (const i in u)
24
+ a.append(i, u[i]);
25
25
  const b = new T(n), p = await y(t, b, {
26
26
  ...e,
27
27
  method: l,
@@ -31,12 +31,12 @@ async function k(t, o, e, n) {
31
31
  }
32
32
  const y = async function(t, o, e) {
33
33
  const n = await C(t, o, e), r = n.method, l = e?.onUploadProgress, a = R(n.url, n.params);
34
- return await new Promise((d) => {
34
+ return await new Promise((u) => {
35
35
  let b = null, p = !1;
36
36
  const i = function() {
37
37
  p || (s.abort(), p = !0);
38
38
  };
39
- function u() {
39
+ function d() {
40
40
  b !== null && clearTimeout(b), n.abort && n.abort.removeEventListener("abort", i);
41
41
  }
42
42
  const s = new XMLHttpRequest();
@@ -51,18 +51,18 @@ const y = async function(t, o, e) {
51
51
  }
52
52
  s.addEventListener("load", () => {
53
53
  const f = s.status;
54
- u(), d({
54
+ d(), u({
55
55
  url: a,
56
56
  method: r,
57
57
  status: f,
58
58
  statusText: s.statusText,
59
- headers: S(s),
59
+ headers: U(s),
60
60
  body: r === "HEAD" || f === 204 ? "" : s.responseText
61
61
  });
62
62
  }), s.addEventListener(
63
63
  "error",
64
64
  (f) => {
65
- u(), d({
65
+ d(), u({
66
66
  url: a,
67
67
  method: r,
68
68
  status: s.status || -1,
@@ -73,7 +73,7 @@ const y = async function(t, o, e) {
73
73
  },
74
74
  !0
75
75
  ), s.addEventListener("abort", () => {
76
- u(), d({
76
+ d(), u({
77
77
  url: a,
78
78
  method: r,
79
79
  status: g ? -1 : 0,
@@ -88,7 +88,7 @@ const y = async function(t, o, e) {
88
88
  }, n.timeout));
89
89
  });
90
90
  };
91
- function S(t) {
91
+ function U(t) {
92
92
  const o = {};
93
93
  if (!t)
94
94
  return o;
@@ -110,10 +110,10 @@ async function O(t, o, e = {}) {
110
110
  return null;
111
111
  const l = R(t, e, !0);
112
112
  return new Promise((a) => {
113
- n[r] = function(d) {
114
- if (r in window && delete n[r], o(d))
115
- return d;
116
- console.warn("response type check failed", t, d), a(null);
113
+ n[r] = function(u) {
114
+ if (r in window && delete n[r], o(u))
115
+ return u;
116
+ console.warn("response type check failed", t, u), a(null);
117
117
  }, q(l).catch(function() {
118
118
  a(null), delete n[r];
119
119
  });
@@ -127,7 +127,7 @@ async function P(t, o, e = {}) {
127
127
  }).catch(() => null) : null;
128
128
  }
129
129
  const A = async function(t, o, e) {
130
- return await k(t, o, e, {
130
+ return await S(t, o, e, {
131
131
  baseURL: c.getConfig("baseURL"),
132
132
  logHandler: c.getConfig("logHandler"),
133
133
  errorHandler: c.getConfig("errorHandler"),
@@ -136,22 +136,22 @@ const A = async function(t, o, e) {
136
136
  responseHandler: c.getConfig("responseHandler")
137
137
  });
138
138
  };
139
- function U(t) {
139
+ function j(t) {
140
140
  if (!E.window)
141
141
  throw new Error("Default Module Only Support In Browser");
142
- return E.fetch ? new H(L, t) : new H(j, t);
142
+ return E.fetch ? new H(L, t) : new H(k, t);
143
143
  }
144
- const c = U(), M = c.setConfig, N = c.request, B = c.head, X = c.get, F = c.post, G = c.del, I = c.put, _ = c.patch;
144
+ const c = j(), M = c.setConfig, N = c.request, B = c.head, X = c.get, F = c.post, G = c.del, I = c.put, $ = c.patch;
145
145
  export {
146
- U as NetRequest,
146
+ j as NetRequest,
147
147
  w as RequestInternalError,
148
148
  G as del,
149
149
  X as get,
150
- J as getResponseRulesDescription,
150
+ K as getResponseRulesDescription,
151
151
  B as head,
152
152
  O as jsonp,
153
153
  P as jsonx,
154
- _ as patch,
154
+ $ as patch,
155
155
  F as post,
156
156
  I as put,
157
157
  N as request,
package/dist/node.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./retry-BltIjZ1L.cjs"),y=require("./request.fetch-BqSnA_jT.cjs"),b=require("node:http"),g=require("node:https"),E=async function(r,a,c){return e.handleResponse(await e.retryRequest(w,r,a,c),r,a,c)},w=async function(r,a,c){const t=await e.convertOptions(r,a,c);if(!e.Nt(t.url))return{url:t.url,method:t.method,status:-1,statusText:e.RequestInternalError.URLFormatError,headers:{},body:""};const R=/^https:\/\//i.test(t.url)?g:b,u=new URL(t.url),i=t.params;i instanceof Object&&Object.keys(i).forEach(n=>u.searchParams.set(n,i[n]));const q=t.method==="HEAD";return new Promise(n=>{const d=R.request(u,{headers:t.headers,method:t.method,timeout:t.timeout>0?t.timeout:void 0},function(o){const m=[];o.on("data",h=>m.push(h)),o.on("end",()=>{const h=e.fromEntries(Object.entries(o.headers).map(([f,l])=>[f.toLowerCase(),Array.isArray(l)?l.join(","):l]));n({url:u.toString(),method:t.method,status:o.statusCode||-1,statusText:o.statusMessage||e.RequestInternalError.Unknown,headers:h,body:q||o.statusCode===204?"":Buffer.concat(m).toString("utf-8")})})});d.on("error",o=>{n({url:u.toString(),method:t.method,status:-1,statusText:e.RequestInternalError.NetworkError,body:"",rawError:o})}),d.on("timeout",()=>{n({url:u.toString(),method:t.method,status:-1,statusText:e.RequestInternalError.Timeout,body:""})}),t.body&&d.write(t.body),d.end()})};function p(r){return e.jt.fetch?new e.NetRequestHandler(y.fetchRequest,r):new e.NetRequestHandler(E,r)}const s=p(),N=s.setConfig,j=s.head,C=s.get,I=s.post,S=s.del,T=s.put,O=s.patch;exports.RequestInternalError=e.RequestInternalError;exports.getResponseRulesDescription=e.getResponseRulesDescription;exports.NetRequest=p;exports.del=S;exports.get=C;exports.head=j;exports.patch=O;exports.post=I;exports.put=T;exports.setGlobalConfig=N;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./retry-sL4_1f7S.cjs"),y=require("./request.fetch-0OA7qu9S.cjs"),b=require("node:http"),g=require("node:https"),E=async function(r,a,c){return e.handleResponse(await e.retryRequest(w,r,a,c),r,a,c)},w=async function(r,a,c){const t=await e.convertOptions(r,a,c);if(!e.Et(t.url))return{url:t.url,method:t.method,status:-1,statusText:e.RequestInternalError.URLFormatError,headers:{},body:""};const R=/^https:\/\//i.test(t.url)?g:b,u=new URL(t.url),i=t.params;i instanceof Object&&Object.keys(i).forEach(n=>u.searchParams.set(n,i[n]));const q=t.method==="HEAD";return new Promise(n=>{const d=R.request(u,{headers:t.headers,method:t.method,timeout:t.timeout>0?t.timeout:void 0},function(o){const m=[];o.on("data",h=>m.push(h)),o.on("end",()=>{const h=e.fromEntries(Object.entries(o.headers).map(([f,l])=>[f.toLowerCase(),Array.isArray(l)?l.join(","):l]));n({url:u.toString(),method:t.method,status:o.statusCode||-1,statusText:o.statusMessage||e.RequestInternalError.Unknown,headers:h,body:q||o.statusCode===204?"":Buffer.concat(m).toString("utf-8")})})});d.on("error",o=>{n({url:u.toString(),method:t.method,status:-1,statusText:e.RequestInternalError.NetworkError,body:"",rawError:o})}),d.on("timeout",()=>{n({url:u.toString(),method:t.method,status:-1,statusText:e.RequestInternalError.Timeout,body:""})}),t.body&&d.write(t.body),d.end()})};function p(r){return e.Ct.fetch?new e.NetRequestHandler(y.fetchRequest,r):new e.NetRequestHandler(E,r)}const s=p(),C=s.setConfig,I=s.head,N=s.get,S=s.post,T=s.del,j=s.put,O=s.patch;exports.RequestInternalError=e.RequestInternalError;exports.getResponseRulesDescription=e.getResponseRulesDescription;exports.NetRequest=p;exports.del=T;exports.get=N;exports.head=I;exports.patch=O;exports.post=S;exports.put=j;exports.setGlobalConfig=C;
package/dist/node.js CHANGED
@@ -1,10 +1,10 @@
1
- import { h as y, r as q, c as w, b as g, a as d, f as E, N as f, j } from "./retry-D8V8lDdS.js";
2
- import { g as J } from "./retry-D8V8lDdS.js";
3
- import { f as x } from "./request.fetch-CLcd8XUK.js";
1
+ import { h as b, r as q, c as w, E as g, a as d, f as E, N as f, C } from "./retry-vMhW20_a.js";
2
+ import { g as J } from "./retry-vMhW20_a.js";
3
+ import { f as x } from "./request.fetch-BJaP3VPV.js";
4
4
  import N from "node:http";
5
- import C from "node:https";
6
- const T = async function(o, a, u) {
7
- return y(await q(L, o, a, u), o, a, u);
5
+ import T from "node:https";
6
+ const j = async function(o, a, u) {
7
+ return b(await q(L, o, a, u), o, a, u);
8
8
  }, L = async function(o, a, u) {
9
9
  const t = await w(o, a, u);
10
10
  if (!g(t.url))
@@ -16,7 +16,7 @@ const T = async function(o, a, u) {
16
16
  headers: {},
17
17
  body: ""
18
18
  };
19
- const R = /^https:\/\//i.test(t.url) ? C : N, n = new URL(t.url), i = t.params;
19
+ const R = /^https:\/\//i.test(t.url) ? T : N, n = new URL(t.url), i = t.params;
20
20
  i instanceof Object && Object.keys(i).forEach((r) => n.searchParams.set(r, i[r]));
21
21
  const l = t.method === "HEAD";
22
22
  return new Promise((r) => {
@@ -31,7 +31,7 @@ const T = async function(o, a, u) {
31
31
  const p = [];
32
32
  e.on("data", (m) => p.push(m)), e.on("end", () => {
33
33
  const m = E(
34
- Object.entries(e.headers).map(([b, h]) => [b.toLowerCase(), Array.isArray(h) ? h.join(",") : h])
34
+ Object.entries(e.headers).map(([y, h]) => [y.toLowerCase(), Array.isArray(h) ? h.join(",") : h])
35
35
  );
36
36
  r({
37
37
  url: n.toString(),
@@ -65,7 +65,7 @@ const T = async function(o, a, u) {
65
65
  });
66
66
  };
67
67
  function O(o) {
68
- return j.fetch ? new f(x, o) : new f(T, o);
68
+ return C.fetch ? new f(x, o) : new f(j, o);
69
69
  }
70
70
  const s = O(), k = s.setConfig, B = s.head, D = s.get, P = s.post, F = s.del, G = s.put, I = s.patch;
71
71
  export {
@@ -1 +1 @@
1
- "use strict";const r=require("./retry-BltIjZ1L.cjs"),E=async function(s,a,i){return r.handleResponse(await r.retryRequest(w,s,a,i),s,a,i)},w=async function(s,a,i){const t=await r.convertOptions(s,a,i),c=new URL(t.url),u=t.params;u instanceof Object&&Object.keys(u).forEach(e=>c.searchParams.set(e,u[e]));const o=r.jt.AbortController?new AbortController:null;function l(){o&&!o.signal.aborted&&o.abort()}t.abort&&t.abort.addEventListener("abort",l);let d=!1;const h=t.timeout>0?setTimeout(function(){d=!0,l()},t.timeout):null,f=t.method==="HEAD";return await fetch(c,{method:t.method,headers:Object.keys(t.headers).length>0?new Headers(t.headers):void 0,body:t.body,credentials:t.credentials,signal:o?.signal,redirect:"follow"}).then(async e=>{const n={url:c.toString(),method:t.method,status:e.status,statusText:e.statusText,headers:r.fromEntries([...e.headers.entries()])},b=f||e.status===204?"":await e.text().catch(m=>m);return b instanceof Error?{...n,body:"",statusText:r.RequestInternalError.Unknown,rawError:b}:{...n,body:b}}).catch(e=>{const n=o?.signal.aborted;return{url:c.toString(),method:t.method,status:n&&!d?0:-1,statusText:d?r.RequestInternalError.Timeout:n?r.RequestInternalError.Aborted:r.RequestInternalError.NetworkError,body:"",rawError:e}}).finally(()=>{h!==null&&clearTimeout(h),t.abort&&t.abort.removeEventListener("abort",l)})};exports.fetchRequest=E;
1
+ "use strict";const r=require("./retry-sL4_1f7S.cjs"),E=async function(s,a,i){return r.handleResponse(await r.retryRequest(w,s,a,i),s,a,i)},w=async function(s,a,i){const t=await r.convertOptions(s,a,i),c=new URL(t.url),u=t.params;u instanceof Object&&Object.keys(u).forEach(e=>c.searchParams.set(e,u[e]));const o=r.Ct.AbortController?new AbortController:null;function l(){o&&!o.signal.aborted&&o.abort()}t.abort&&t.abort.addEventListener("abort",l);let d=!1;const h=t.timeout>0?setTimeout(function(){d=!0,l()},t.timeout):null,f=t.method==="HEAD";return await fetch(c,{method:t.method,headers:Object.keys(t.headers).length>0?new Headers(t.headers):void 0,body:t.body,credentials:t.credentials,signal:o?.signal,redirect:"follow"}).then(async e=>{const n={url:c.toString(),method:t.method,status:e.status,statusText:e.statusText,headers:r.fromEntries([...e.headers.entries()])},b=f||e.status===204?"":await e.text().catch(m=>m);return b instanceof Error?{...n,body:"",statusText:r.RequestInternalError.Unknown,rawError:b}:{...n,body:b}}).catch(e=>{const n=o?.signal.aborted;return{url:c.toString(),method:t.method,status:n&&!d?0:-1,statusText:d?r.RequestInternalError.Timeout:n?r.RequestInternalError.Aborted:r.RequestInternalError.NetworkError,body:"",rawError:e}}).finally(()=>{h!==null&&clearTimeout(h),t.abort&&t.abort.removeEventListener("abort",l)})};exports.fetchRequest=E;
@@ -1,4 +1,4 @@
1
- import { h as w, r as y, c as E, j as T, f as R, a as c } from "./retry-D8V8lDdS.js";
1
+ import { h as w, r as y, c as E, C as T, f as R, a as c } from "./retry-vMhW20_a.js";
2
2
  const x = async function(a, s, n) {
3
3
  return w(await y(g, a, s, n), a, s, n);
4
4
  }, g = async function(a, s, n) {
@@ -1,3 +1,3 @@
1
- "use strict";const l=typeof globalThis<"u"?globalThis:typeof self<"u"?self:typeof window<"u"?window:Function("return this")(),K="wx"in l&&R(l.wx)&&"getSystemInfo"in l.wx&&d(l.wx.getSystemInfo),k={wx:K,fetch:"fetch"in l&&d(l.fetch),window:"window"in l&&R(l.window)&&!K,requestAnimationFrame:"requestAnimationFrame"in l&&d(l.requestAnimationFrame),localStorage:"localStorage"in l&&R(l.localStorage)&&"getItem"in l.localStorage&&d(l.localStorage.getItem),sessionStorage:"sessionStorage"in l&&R(l.sessionStorage)&&"getItem"in l.sessionStorage&&d(l.sessionStorage.getItem),File:"File"in l&&d(l.File),Blob:"Blob"in l&&d(l.Blob),Proxy:"Proxy"in l&&d(l.Proxy),Request:"Request"in l&&d(l.Request),FormData:"FormData"in l&&d(l.FormData),TextDecoder:"TextDecoder"in l&&d(l.TextDecoder),ResizeObserver:"ResizeObserver"in l&&d(l.ResizeObserver),AbortController:"AbortController"in l&&d(l.AbortController),URLSearchParams:"URLSearchParams"in l&&d(l.URLSearchParams),EventSource:"EventSource"in l&&d(l.EventSource)};function d(t){return typeof t=="function"}function R(t){return typeof t=="object"&&t!==null}function re(t){return new Promise(e=>setTimeout(e,Math.max(0,t)))}function X(){}function Q(t,e){const s={log:console.log.bind(console),error:console.error.bind(console),warn:console.warn.bind(console)},n=`[${t}]`;return["log","error","warn"].forEach(r=>{const o=console[r];s[r]=(...i)=>{o.apply(console,[n,...i])}}),s}function oe(t){const e=t||"CustomError";return class extends Error{constructor(s){super(s),Object.defineProperty(this,"name",{value:e,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 ie=/^(?:https?:)?\/\/.+$/i,ae=/^https?:\/\/.+$/i,le=/^\{[\d\D]*\}$/,ue=/^\[[\d\D]*\]$/;function ce(t){return typeof t=="string"}function N(t,e=!1){return e?ie.test(t):ae.test(t)}function he(t){return t==null}function Y(t,...e){return t!==null&&typeof t=="object"&&!(t instanceof Map)&&!(t instanceof Set)&&!(t instanceof WeakMap)&&!(t instanceof WeakSet)&&!Array.isArray(t)&&e.every(s=>s in t)}function y(t,...e){if(!t||typeof t!="object")return!1;const s=Object.getPrototypeOf(t);return s!==Object.prototype&&s!==null?!1:e.every(n=>n in t)}function U(t,e){return Array.isArray(t)&&t.every(s=>e(s))}function x(t){if(typeof t!="number"||Number.isNaN(t)||!Number.isFinite(t))return!1;if(Number.isInteger(t))return Number.isSafeInteger(t);if(t===0)return!0;const e=Math.abs(t);return e>=Number.EPSILON&&e<=Number.MAX_SAFE_INTEGER}function Z(t){return le.test(t)||ue.test(t)}function fe(t,e=20){const s=Math.max(e,10),n=[...t];return n.length<=s?t:n.slice(0,s-3).join("")+"..."}function F(t,e){try{const s=JSON.parse(t);return e?e(s)?s:null:s}catch{return null}}""+Math.random().toString(32).slice(2);Q("LoadUtils");async function de(t){return await new Promise(function(e){const s=document.getElementsByTagName("head")[0],n=document.createElement("script");n.setAttribute("type","text/javascript"),n.setAttribute("charset","utf-8"),n.onload=function(){s.removeChild(n),e(!0)},n.onerror=function(){s.removeChild(n),e(!1)},n.setAttribute("src",t),s.appendChild(n)})}function z(t){return Object.getOwnPropertyNames(t).forEach(function(e){delete t[e]}),t}const g=Q("Validator");function j(t){return t?`"${fe(t).replace(/"/g,'\\"')}"`:"empty string"}function S(t){return typeof t=="object"&&t&&"constructor"in t&&typeof t.constructor=="function"?t.constructor.name||"ClassInstance":Object.prototype.toString.call(t).replace(/(?:.+ |]$)/g,"")}function O(t){return typeof t=="bigint"}function a(t){return new Error(`${t?`${t}()`:"method"} is not allowed after locked`)}class M{_ps={};_allow=[];_reject=[];_locked=!1;_opt=!1;_null=!1;pattern(e,s){if(this._locked)throw a("pattern");return this._ps[`#${e||"custom"}`]=s,this}url(e=!1){if(this._locked)throw a("url");return this._ps.url=e?/^(?:https?:)?\/\/.+$/i:/^https?:\/\/.+$/i,this}dataUri(){if(this._locked)throw a("dataUri");return this._ps.dataUri=/^data:[a-z]+\/[a-z]+;base64,[\w+/=]+$/,this}enum(...e){if(this._locked)throw a("enum");const s=e[0];return U(e,ce)?(this._allow=e,z(this._ps)):y(s)&&(this._allow=Object.values(s).map(n=>`${n}`),z(this._ps)),this}disallow(...e){return this._reject.push(...e),this}optional(){if(this._locked)throw a("optional");return this._opt=!0,this}maybeNull(){if(this._locked)throw a("maybeNull");return this._null=!0,this}lock(){return this._locked=!0,this}clone(){const e=new M;return e._ps={...this._ps},e._allow=[...this._allow],e._reject=[...this._reject],e._locked=!1,e}validate(e,s=g.warn){if(e===void 0)return this._opt||(s("should be a string, but got undefined"),!1);if(e===null)return this._null||(s("should be a string, but got null"),!1);if(typeof e!="string")return s(`should be a string, but got ${typeof e}`),!1;if(this._allow.length>0)return this._allow.includes(e)||(s(`${j(e)} is not allowed, just support ${this._allow.map(j).join(", ")}`),!1);if(this._reject.length>0&&this._reject.some(r=>typeof r=="string"?r===e:r.test(e)))return s(`${j(e)} is not allowed`),!1;const n=Object.keys(this._ps);return n.length>0&&!n.some(r=>{const o=this._ps[r];return o instanceof RegExp?o.test(e):o(e)})?(s(`${j(e)} is not match pattern ${n.join(" | ")}`),!1):!0}}class P{_int=!1;_min=-1/0;_max=1/0;_allow=[];_reject=[];_infinite=!1;_unsafe=!1;_nan=!1;_locked=!1;_opt=!1;_null=!1;int(){if(this._locked)throw a("int");return this._int=!0,this}min(e){if(this._locked)throw a("min");return Number.isNaN(e)||(this._min=e),this}max(e){if(this._locked)throw a("max");return Number.isNaN(e)||(this._max=e),this}allowNaN(){if(this._locked)throw a("allowNaN");return this._nan=!0,this}allowInfinity(){if(this._locked)throw a("allowInfinity");return this._infinite=!0,this._unsafe=!0,this}unsafe(){if(this._locked)throw a("unsafe");return this._unsafe=!0,this}enum(...e){if(this._locked)throw a("enum");const s=e[0];return U(e,x)?(this._allow=e,this._reject=[]):y(s)&&(this._allow=Object.values(s).map(n=>x(n)?n:null).filter(n=>n!==null),this._reject=[]),this}disallow(...e){if(this._locked)throw a("disallow");return this._reject.push(...e),this}optional(){if(this._locked)throw a("optional");return this._opt=!0,this}maybeNull(){if(this._locked)throw a("maybeNull");return this._null=!0,this}lock(){return this._locked=!0,this}clone(){const e=new P;return e._int=this._int,e._min=this._min,e._max=this._max,e._allow=[...this._allow],e._reject=[...this._reject],e._infinite=this._infinite,e._unsafe=this._unsafe,e._nan=this._nan,e._locked=!1,e}validate(e,s=g.warn){return e===void 0?this._opt||(s("should be a number, but got undefined"),!1):e===null?this._null||(s("should be a number, but got null"),!1):typeof e!="number"?(s(`should be a number, but got ${typeof e}`),!1):Number.isNaN(e)?this._nan||(s("should be a number, but got NaN"),!1):!Number.isFinite(e)&&!this._infinite?(s("should be a number, but got Infinity"),!1):this._allow.length>0?this._allow.includes(e)||(s(`${e} is not allowed, just support ${this._allow.join(", ")}`),!1):this._reject.length>0&&this._reject.includes(e)?(s(`${e} is not allowed`),!1):this._int&&Math.ceil(e)!==e?(s(`${e} is not an integer`),!1):!x(e)&&!this._unsafe?(s(`${e} is not a safe number`),!1):e>=this._min&&e<=this._max||(s(`${e} is not in range [${this._min}, ${this._max}]`),!1)}}class C{_min=null;_max=null;_allow=[];_reject=[];_locked=!1;_opt=!1;_null=!1;min(e){if(this._locked)throw a("min");return this._min=e,this}max(e){if(this._locked)throw a("max");return this._max=e,this}enum(...e){if(this._locked)throw a("enum");const s=e[0];return U(e,O)?(this._allow=e,this._reject=[]):y(s)&&(this._allow=Object.values(s).map(n=>O(n)?n:null).filter(n=>n!==null),this._reject=[]),this}disallow(...e){if(this._locked)throw a("disallow");return this._reject.push(...e),this}optional(){if(this._locked)throw a("optional");return this._opt=!0,this}maybeNull(){if(this._locked)throw a("maybeNull");return this._null=!0,this}lock(){return this._locked=!0,this}clone(){const e=new C;return e._min=this._min,e._max=this._max,e._allow=[...this._allow],e._reject=[...this._reject],e._locked=!1,e}validate(e,s=g.warn){return e===void 0?this._opt||(s("should be a bigint, but got undefined"),!1):e===null?this._null||(s("should be a bigint, but got null"),!1):O(e)?this._allow.length>0?this._allow.includes(e)||(s(`${e} is not allowed, just support ${this._allow.join(", ")}`),!1):this._reject.length>0&&this._reject.includes(e)?(s(`${e} is not allowed`),!1):(this._min!==null?e>=this._min:!0)&&(this._max!==null?e<=this._max:!0)||(s(`${e} is not in range [${this._min===null?-1/0:this._min}, ${this._max===null?1/0:this._max}]`),!1):(s(`should be a bigint, but got ${typeof e}`),!1)}}class I{_locked=!1;_opt=!1;_null=!1;optional(){if(this._locked)throw a("optional");return this._opt=!0,this}maybeNull(){if(this._locked)throw a("maybeNull");return this._null=!0,this}lock(){return this._locked=!0,this}clone(){return new I}validate(e,s=g.warn){return e===void 0?this._opt||(s("should be a boolean, but got undefined"),!1):e===null?this._null||(s("should be a boolean, but got null"),!1):typeof e!="boolean"?(s(`should be a boolean, but got ${typeof e}`),!1):!0}}class v{_shape;_plain=!1;_locked=!1;_opt=!1;_null=!1;constructor(e){this._shape=e}plain(){if(this._locked)throw a("plain");return this._plain=!0,this}optional(){if(this._locked)throw a("optional");return this._opt=!0,this}maybeNull(){if(this._locked)throw a("maybeNull");return this._null=!0,this}lock(){return this._locked=!0,this}get shape(){return{...this._shape}}clone(){const e=new v(this._shape);return e._plain=this._plain,e._locked=!1,e}match(e,s){return e in this._shape?this._shape[e].validate(s,X):!1}validate(e,s=g.warn){return e===void 0?this._opt||(s("should be a object, but got undefined"),!1):e===null?this._null||(s("should be a object, but got null"),!1):Y(e)?this._plain&&!y(e)?(s(`should be a plain object, but got ${S(e)}`),!1):Object.keys(this._shape).every(n=>this._shape[n].validate(e[n],(...r)=>{s(`[.${String(n)}]`,...r)})):(s(`should be a object, but got ${S(e)}`),!1)}}class q{_val;_locked=!1;_opt=!1;_null=!1;constructor(e){this._val=e}optional(){if(this._locked)throw a("optional");return this._opt=!0,this}maybeNull(){if(this._locked)throw a("maybeNull");return this._null=!0,this}lock(){return this._locked=!0,this}clone(){return new q(this._val)}validate(e,s=g.warn){return e===void 0?this._opt||(s("should be a record, but got undefined"),!1):e===null?this._null||(s("should be a record, but got null"),!1):y(e)?Object.keys(e).every(n=>this._val.validate(e[n],(...r)=>{s(`[:${n}]`,...r)})):(s(`should be a record, but got ${S(e)}`),!1)}}class D{_val;_min=0;_max=1/0;_locked=!1;_opt=!1;_null=!1;constructor(e){this._val=e}min(e){if(this._locked)throw a("min");return this._min=e,this}max(e){if(this._locked)throw a("max");return this._max=e,this}optional(){if(this._locked)throw a("optional");return this._opt=!0,this}maybeNull(){if(this._locked)throw a("maybeNull");return this._null=!0,this}lock(){return this._locked=!0,this}clone(){const e=new D(this._val);return e._min=this._min,e._max=this._max,e._locked=!1,e}validate(e,s=g.warn){return e===void 0?this._opt||(s("should be a array, but got undefined"),!1):e===null?this._null||(s("should be a array, but got null"),!1):Array.isArray(e)?e.length<this._min||e.length>this._max?(this._min===this._max?s(`should be a array with length ${this._min}`):s(`should be a array with length between ${this._min} and ${this._max}`),!1):e.every((n,r)=>this._val.validate(n,(...o)=>{s(`[${r}]`,...o)})):(s(`should be a array, but got ${typeof e}`),!1)}}class L{_vs;_locked=!1;_opt=!1;_null=!1;constructor(...e){this._vs=e}optional(){if(this._locked)throw a("optional");return this._opt=!0,this}maybeNull(){if(this._locked)throw a("maybeNull");return this._null=!0,this}lock(){return this._locked=!0,this}clone(){return new L(...this._vs)}validate(e,s=g.warn){return e===void 0?this._opt||(s("should be a tuple, but got undefined"),!1):e===null?this._null||(s("should be a tuple, but got null"),!1):Array.isArray(e)?e.length!==this._vs.length?(s(`should be a tuple with length ${this._vs.length}, but got ${e.length}`),!1):this._vs.every((n,r)=>n.validate(e[r],(...o)=>{s(`[idx:${r}]`,...o)})):(s(`should be a tuple, but got ${typeof e}`),!1)}}class B{_vs;_key="";_locked=!1;_opt=!1;_null=!1;constructor(...e){this._vs=e}optional(){if(this._locked)throw a("optional");return this._opt=!0,this}maybeNull(){if(this._locked)throw a("maybeNull");return this._null=!0,this}key(e){if(this._locked)throw a("key");return this._vs.every(s=>s instanceof v)?this._key=e:g.warn("union type key can only be used when all validators are ObjectValidator"),this}satisfies(){return this}lock(){return this._locked=!0,this}get validators(){return[...this._vs]}clone(){const e=new B(...this._vs);return e._key=this._key,e._locked=!1,e}validate(e,s=g.warn){if(e===void 0)return this._opt||(s("should be a union, but got undefined"),!1);if(e===null)return this._null||(s("should be a union, but got null"),!1);if(this._key&&Y(e)&&e){const r=e[this._key];if(r===void 0)return s(`key field "${this._key}" is not found`,e),!1;const o=this._vs.find(i=>i instanceof v&&i.match(this._key,r));return o?o.validate(e,s):(s(`key field "${this._key}" value is match union definition`,r),!1)}const n=this._vs.some(r=>r.validate(e,X));return n||s("value is not match union definition",e),n}}class E{_name="";_guard;_locked=!1;_opt=!1;_null=!1;constructor(e,s){this._name=e,this._guard=s}optional(){if(this._locked)throw a("optional");return this._opt=!0,this}maybeNull(){if(this._locked)throw a("maybeNull");return this._null=!0,this}lock(){return this._locked=!0,this}clone(){return new E(this._name,this._guard)}validate(e,s=g.warn){const n=this._name||"custom type";return e===void 0?this._opt||(s(`should be ${n}, but got undefined`),!1):e===null?this._null||(s(`should be ${n}, but got null`),!1):this._guard(e)||(s(`custom validation${this._name?`(${this._name})`:""} failed`),!1)}}function _e(t,e){if(typeof t=="string"){if(!e)throw new Error("custom type guard must be defined");return new E(t,e)}return new E("",t)}const me={shape(t){return t},define(t){return t},guard(t){return function(e){return t.validate(e)}},object(t){return new v(t)},record(t){return new q(t)},array(t){return new D(t)},tuple(...t){return new L(...t)},union(...t){return new B(...t)},string(){return new M},bool(){return new I},number(){return new P},bigint(){return new C},custom:_e,unknown(){return{validate(t){return!0}}},never(){return{validate(t){return!1}}}},ge=t=>y(t)&&Object.keys(t).length===0;me.custom("EmptyObject",ge);function pe(t,e="数据未能正确识别"){return typeof t=="function"?{guard:t,message:e}:{guard:t.guard,message:t.message||e}}function be(t,e=""){return!e||N(t,!0)?W(t):(W(e)+"/"+t).replace(/\/{2,}/g,"/").replace(/:\//,"://")}function W(t){return N(t,!0)?t.startsWith("http")?t:("location"in globalThis?location.protocol:"https:")+t:("location"in globalThis?location.origin:"http://127.0.0.1")+"/"+t.replace(/^\/+/,"")}function ye(t,e){const s={};return(t.match(/([^=&#?]+)=[^&#]*/g)||[]).forEach(function(n){const r=n.split("="),o=r[0],i=decodeURIComponent(r[1]||"");s[o]!==void 0?s[o]+=","+i:s[o]=i}),e!==!0?s[e]||"":s}function we(t,e){if(e){if(e===!0)return t.replace(/\?[^#]*/,"")}else return t;const s=t.split("#"),n=s[0].split("?"),r=n[0],o=n.length>1?n[1]:"",i=s.length>1?"#"+s[1]:"",u=typeof e=="string"?[e]:Array.isArray(e)?e:[];return!u.length||!o?s[0]+i:(u.map(c=>c.replace(/([\\(){}[\]^$+\-*?|])/g,"\\$1")),(r+"?"+o.replace(new RegExp("(?:^|&)(?:"+u.join("|")+")=[^&$]+","g"),"").replace(/^&/,"")).replace(/\?$/,"")+i)}function ke(t,e,s=!1){const n=typeof e=="string"?e:Object.keys(e).map(i=>`${i}=${encodeURIComponent(e[i])}`).join("&");if(!n)return t;const r=t.split("#");s&&(r[0]=we(r[0],(n.match(/([^=&#?]+)=[^&#]+/g)||[]).map(i=>i.replace(/=.+$/,""))));const o=r[0].indexOf("?")+1?"&":"?";return(r[0]+o+n+(r.length>1?"#"+r[1]:"")).replace(/\?&/,"?")}function ve(t){const e=t.match(/(?:\?|&)([^=]+)(?:&|$)/g);return e?e.join("").replace(/(?:\?|^&+|&+$)/g,"").replace(/&{2}/g,"&").split("&").sort():[]}class $e{ttl;cache;constructor(e=500){this.cache={},this.ttl=Math.max(e,0)}getKey(e,s,n,r){if(e.toLowerCase()!=="get"&&!r)return"";const o=e.toLowerCase(),i=s.replace(/#.+/,""),u=i.replace(/\?.+/g,"");if(r){const h=r()||"";return h?`${u}_${o}_${h}`:""}const c=Object.assign(ye(i,!0),n),_=ve(i),f=Object.keys(c).sort().map(h=>`${h}#${c[h]}`);return`${u}_${o}_${f.join(",")}_${_.join(",")}`}updateTTL(e){this.ttl=Math.max(e,0)}get(e){if(this.ttl===0)return null;const s=this.cache[e];return s?s.ttl<Date.now()?(delete this.cache[e],null):s.res:null}set(e,s,n){const r=n??this.ttl;r<=0||(this.cache[e]={ttl:Date.now()+r,res:s})}}class ee{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"}}};constructor(e){e&&this.set(e)}set(e){if(e.baseURL&&!/^\/.+/.test(e.baseURL)&&!N(e.baseURL))throw console.warn("baseURL 需要以 / 开头,或者是完整的 url 地址"),new Error("BaseURLError");Object.assign(this.config,e)}get(e){return this.config[e]}getFullUrl(e){return be(e,this.config.baseURL)}showMessage(e,s,n,r){this.config.messageHandler&&s&&this.config.messageHandler(e,s,n,r)}}const H={UnexpectResponse:"UnexpectResponse",Aborted:"Aborted",Unknown:"Unknown",NetworkError:"NetworkError",Timeout:"Timeout",NotSupport:"NotSupport",URLFormatError:"URLFormatError"};function je(t,e,s,n){if(e.ok&&!he(e.data)&&n){const r=pe(n,s.get("defaultTypeGuardMessage"));return r.guard(e.data)||(e.code=H.UnexpectResponse,s.showMessage(!0,`${t} ${r.message}`,e.code,e.status),console.error(e.code,t,e.data),e.data=null,e.message=r.message),e}return e}class Re{agent;config;cache;constructor(e,s){this.config=new ee(s),this.agent=e,this.cache=new $e(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(e,s){const n=this.cache.getKey(s?.method||"GET",e,s?.params,s?.cacheResolve);if(n){const r=this.cache.get(n);if(r)return await r}try{const r=this.agent(e,this.config,s);return n&&this.cache.set(n,r),await r}catch(r){return console.error("RequestError",r),{ok:!1,status:-9,code:H.Unknown,message:r instanceof Error?`${r.message}
2
- ${r.stack||""}`:String(r),headers:{},data:null}}}async guard(e,s,n){return je(e,s,this.config,n)}setConfig(e){this.config.set(e),this.cache.updateTTL(this.config.get("cacheTTL"))}getConfig(e){return this.config.get(e)}async head(e,s){const n=Object.assign({},s||null);return n.method="HEAD",this.guard(e,await this.request(e,n),null)}async get(e,s,n){const r=Object.assign({},n||null);r.method="GET";const o=this.request(e,r);return this.guard(e,await o,s||null)}async post(e,s,n,r){const o=Object.assign({},r||null);return o.method="POST",o.body=s||{},this.guard(e,await this.request(e,o),n||null)}async del(e,s,n){const r=Object.assign({},n||null);return r.method="DELETE",this.guard(e,await this.request(e,r),s||null)}async put(e,s,n,r){const o=Object.assign({},r||null);return o.method="PUT",o.body=s||{},this.guard(e,await this.request(e,o),n||null)}async patch(e,s,n,r){const o=Object.assign({},r||null);return o.method="PATCH",o.body=s||{},this.guard(e,await this.request(e,o),n||null)}}async function Ee(t,e,s){const n=Object.assign({method:"GET"},s),r=k.FormData?n.body instanceof FormData:!1,o=r&&n.method!=="POST"&&n.method!=="PUT"?"POST":n.method,i=o==="GET"||o==="HEAD"||o==="DELETE";i&&n.body!==void 0&&(console.warn("request body is invalid with method get, head, delete"),delete n.body);const u=Object.assign(r||i?{}:{"Content-Type":k.Blob&&n.body instanceof Blob?n.body.type||"application/octet-stream":"application/json;charset=utf-8"},n.headers),c=n.params||{},_={};Object.keys(c).forEach(m=>{c[m]!==void 0&&(_[m]=Ne(c[m]))});const f=e.getFullUrl(t),h=xe(n.body),p=n.timeout||e.get("timeout"),b=await async function(){const m=e.get("requestTransformer");if(m)return await m({headers:u,params:_,method:o,url:f,body:h})}(),w=typeof b=="string"&&b?b:f;return e.get("logHandler")?.({type:"ready",url:w,method:o,headers:u,timeout:p,body:h}),{url:w,method:o,body:h,params:_,headers:u,timeout:p,abort:n.abort,credentials:n.credentials||e.get("credentials")}}function Ne(t){return typeof t=="string"?t:Array.isArray(t)?t.join(","):t+""}function xe(t){if(t)return typeof t=="string"||k.URLSearchParams&&t instanceof URLSearchParams||t instanceof ArrayBuffer||k.Blob&&t instanceof Blob||k.FormData&&t instanceof FormData?t:JSON.stringify(t)}const te="data",$="message";function Oe(t,e,s,n,r){const o=r||n;return G(t)?Pe(o.ok||n.ok,t,e,s):Se(o.failed||n.failed,e,s)}const Fe=function(t){const e=[],s=t.failed||{resolve:"json"};switch(e.push("- 当http状态码 <200 或者 >=400 时"),s.resolve){case"body":e.push(" 将响应内容格式化为字符串并作为错误消息");break;case"json":e.push(" 将响应解析为json,并读取 "+(s.messageField||$)+" 作为错误消息");break}const n=t.ok||{resolve:"body"};switch(e.push("- 当http状态码 >=200 并且 <400 时"),n.resolve){case"body":e.push(" 将响应尝试解析为 json,并作为数据内容返回");break;case"json":e.push(" 将响应解析为 json,读取 "+(n.dataField||te)+" 作为响应数据,读取 "+(n.messageField||$)+" 作为提示消息"),n.statusField&&e.push(" 当 "+n.statusField+" 为 "+(n.statusOKValue||"空值")+" 时是成功提示,否则是错误消息"),n.ignoreMessage&&e.push(" 并忽略以下消息:"+n.ignoreMessage);break}return e.join(`
3
- `)};function Se(t,e,s){const n=t||{resolve:"json",messageField:$},r={ok:!1,code:e,message:s,data:null};switch(n.resolve){case"body":r.message=V(s)||s;break;case"json":const{code:o,message:i}=Ae(s,n.converter,n.statusField,n.messageField);r.code=o||e,r.message=V(s)||i;break}return r}function Ae(t,e,s,n=$){if(!Z(t))return{message:""};const r=T(F(t),e);return!r||!y(r)?{message:t}:{code:s?A(r,s):"",message:A(r,n)||t}}function A(t,e){const s=Array.isArray(e)?e:[e];for(const n of s)if(n in t)return Te(t[n]);return""}function Te(t){return t?typeof t=="string"?t:JSON.stringify(t):""}const Ue=/<title>([^<]+)<\/title>/i,Me=/<message>([^<]+)<\/message>/i;function V(t){const e=t.match(Ue);if(e)return e[1];const s=t.match(Me);return s?s[1]:""}function Pe(t,e,s,n){const r=t||{resolve:"body"},o={ok:!0,code:s,message:"",data:null};if(e===204||!n)return o;if(r.resolve==="body")return o.data=Z(n)?T(F(n),t.converter):n,o;const i=T(F(n),t.converter);if(!i||!y(i))return o.ok=!1,o.code="ResponseFormatError",o.message="响应内容无法格式化为 Object",o;const u=r.statusField,c=r.statusOKValue||"",_=r.dataField||te,f=r.messageField||$,h=r.ignoreMessage||"";if(u&&!(u in i))return o.ok=!1,o.code="ResponseFieldMissing",o.message="响应内容找不到状态字段 "+u,o;const p=u?i[u]+"":"";return o.ok=u?p===c:!0,o.code=p||s,o.data=_===!0?i:_ in i?i[_]:null,o.message=A(i,f),h&&o.message&&(Array.isArray(h)&&h.includes(o.message)||typeof h=="string"&&o.message===h)&&(o.message=""),o}function G(t){return t>=200&&t<400}function T(t,e){return e?typeof e=="function"?e(t):(console.warn('工具不再支持 "camelize", "snakify" 参数,请自行提供函数来转化 body 内容'),t):t}const Ce=oe("APIError");function Ie(t){const e={};for(const r in t.headers)(r.startsWith("x-")||r.includes("trace")||r.includes("server")||/\b(?:id|uuid)\b/.test(r))&&(e[r]=t.headers[r]);const s=t.url.replace(/^(?:https?:)?\/*/i,"").replace(/\?.+/,""),n=t.status<0?"unknown":t.status;return{sentryError:new Ce(`${s} | ${n}${t.code?` | ${t.code}`:""}`),sentryTags:{...e,status:n,method:t.method,code:t.code||"unknown",message:t.message||"empty"},sentryExtra:{url:t.url,responseBody:t.body||"empty",responseHeaders:t.headers,rawError:t.error}}}function se(t){return t.reduce((e,[s,n])=>(s&&(e[s]=n||""),e),{})}function qe(t,e,s,n){const r=t.status,o=t.method,i=se(Object.entries(t.headers||{}).map(([b,w])=>[b.toLowerCase(),w])),{ok:u,code:c,data:_,message:f}=Oe(r,t.statusText,t.body,s.get("responseRule"),n?.responseRule);if(!G(r)){const b=Ie({url:t.url,method:t.method,status:r,code:c,message:f,body:t.body,headers:i,error:t.rawError});(s.get("errorHandler")||De)({url:e,method:o,status:r,code:c,message:f,headers:i,rawError:t.rawError,responseBody:t.body,...b})}if(r<0)return J({ok:!1,status:r,code:t.statusText,headers:{},message:"",data:null},`${o} ${e} ${t.statusText}`,o,e,s,n);const h={ok:u,data:_,code:c,message:f,status:r,headers:i};s.get("responseHandler")?.({...h},o,e);const p=u?f:f||t.statusText;return J(h,p,o,e,s,n)}function J(t,e,s,n,r,o){const i=r.get("message"),u=i===!1||o?.message===!1?!1:o?.message||i;if(u!==!1){const c=typeof u=="function"?u(t,s,n,e):e;c instanceof Error?r.showMessage(!0,c.message,t.code,t.status):c&&typeof c=="object"&&"message"in c?r.showMessage(!1,c.message,t.code,t.status):r.showMessage(!t.ok,c,t.code,t.status)}return t}function De(t){const e={};for(const s in t)s.startsWith("sentry")||(e[s]=t[s]);console.error("RequestError",e)}async function ne(t,e,s,n,r){const o=r||0,i=Math.max(0,Math.min(10,n?.maxRetry??s.get("maxRetry")??0)),u=n?.retryResolve??s.get("retryResolve"),c=s.get("logHandler");c?.({type:"prepare",url:e,method:n?.method||"GET",retry:o,maxRetry:i,message:o===0?"start":`retry ${o}/${i} start`,headers:n?.headers,options:n});const _=Date.now(),f=await t(e,s,n),h=f.status,p=Date.now()-_,b=`[cost ${p}][${h}] ${h<0?f.body:""}`;c?.({type:"finished",url:e,method:f.method,retry:o,maxRetry:i,message:o===0?`finish ${b}`:`retry ${o}/${i} finish ${b}`,response:f,headers:f.headers,cost:p});const w=G(h);if(!i||o>=i||u==="network"&&h>0||u==="status"&&w||Array.isArray(u)&&!u.includes(h)||typeof u=="function"&&u(f,o)!==!0)return f;const m=n?.retryInterval??s.get("retryInterval")??100;return await re(Math.max(100,m==="2EB"?Math.pow(2,o)*100:typeof m=="function"?m(o+1,{url:e,status:h,method:f.method})||0:m)),await ne(t,e,s,n,o+1)}exports.NetRequestHandler=Re;exports.Nt=N;exports.RequestGlobalConfig=ee;exports.RequestInternalError=H;exports._e=ke;exports.convertOptions=Ee;exports.fromEntries=se;exports.getResponseRulesDescription=Fe;exports.handleResponse=qe;exports.jt=k;exports.le=de;exports.retryRequest=ne;
1
+ "use strict";const l=typeof globalThis<"u"?globalThis:typeof self<"u"?self:typeof window<"u"?window:Function("return this")(),K="wx"in l&&R(l.wx)&&"getSystemInfo"in l.wx&&d(l.wx.getSystemInfo),k={wx:K,fetch:"fetch"in l&&d(l.fetch),window:"window"in l&&R(l.window)&&!K,requestAnimationFrame:"requestAnimationFrame"in l&&d(l.requestAnimationFrame),localStorage:"localStorage"in l&&R(l.localStorage)&&"getItem"in l.localStorage&&d(l.localStorage.getItem),sessionStorage:"sessionStorage"in l&&R(l.sessionStorage)&&"getItem"in l.sessionStorage&&d(l.sessionStorage.getItem),File:"File"in l&&d(l.File),Blob:"Blob"in l&&d(l.Blob),Proxy:"Proxy"in l&&d(l.Proxy),Request:"Request"in l&&d(l.Request),FormData:"FormData"in l&&d(l.FormData),TextDecoder:"TextDecoder"in l&&d(l.TextDecoder),ResizeObserver:"ResizeObserver"in l&&d(l.ResizeObserver),AbortController:"AbortController"in l&&d(l.AbortController),URLSearchParams:"URLSearchParams"in l&&d(l.URLSearchParams),EventSource:"EventSource"in l&&d(l.EventSource)};function d(t){return typeof t=="function"}function R(t){return typeof t=="object"&&t!==null}function re(t){return new Promise(e=>setTimeout(e,Math.max(0,t)))}function X(){}function Y(t,e){const s={log:console.log.bind(console),error:console.error.bind(console),warn:console.warn.bind(console)},n=`[${t}]`;return["log","error","warn"].forEach(r=>{const o=console[r];s[r]=(...i)=>{o.apply(console,[n,...i])}}),s}function oe(t){const e=t||"CustomError";return class extends Error{constructor(s){super(s),Object.defineProperty(this,"name",{value:e,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 ie=/^(?:https?:)?\/\/.+$/i,ae=/^https?:\/\/.+$/i,le=/^\{[\d\D]*\}$/,ue=/^\[[\d\D]*\]$/;function ce(t){return typeof t=="string"}function N(t,e=!1){return e?ie.test(t):ae.test(t)}function he(t){return t==null}function Q(t,...e){return t!==null&&typeof t=="object"&&!(t instanceof Map)&&!(t instanceof Set)&&!(t instanceof WeakMap)&&!(t instanceof WeakSet)&&!Array.isArray(t)&&e.every(s=>s in t)}function y(t,...e){if(!t||typeof t!="object")return!1;const s=Object.getPrototypeOf(t);return s!==Object.prototype&&s!==null?!1:e.every(n=>n in t)}function U(t,e){return Array.isArray(t)&&t.every(s=>e(s))}function x(t){if(typeof t!="number"||Number.isNaN(t)||!Number.isFinite(t))return!1;if(Number.isInteger(t))return Number.isSafeInteger(t);if(t===0)return!0;const e=Math.abs(t);return e>=Number.EPSILON&&e<=Number.MAX_SAFE_INTEGER}function Z(t){return le.test(t)||ue.test(t)}function fe(t,e=20){const s=Math.max(e,10),n=[...t];return n.length<=s?t:n.slice(0,s-3).join("")+"..."}function F(t,e){try{const s=JSON.parse(t);return e?e(s)?s:null:s}catch{return null}}""+Math.random().toString(32).slice(2);Y("LoadUtils");async function de(t){return await new Promise(function(e){const s=document.getElementsByTagName("head")[0],n=document.createElement("script");n.setAttribute("type","text/javascript"),n.setAttribute("charset","utf-8"),n.onload=function(){s.removeChild(n),e(!0)},n.onerror=function(){s.removeChild(n),e(!1)},n.setAttribute("src",t),s.appendChild(n)})}function z(t){return Object.getOwnPropertyNames(t).forEach(function(e){delete t[e]}),t}const g=Y("Validator");function j(t){return t?`"${fe(t).replace(/"/g,'\\"')}"`:"empty string"}function T(t){return typeof t=="object"&&t&&"constructor"in t&&typeof t.constructor=="function"?t.constructor.name||"ClassInstance":Object.prototype.toString.call(t).replace(/(?:.+ |]$)/g,"")}function O(t){return typeof t=="bigint"}function a(t){return new Error(`${t?`${t}()`:"method"} is not allowed after locked`)}class M{_ps={};_allow=[];_reject=[];_locked=!1;_opt=!1;_null=!1;pattern(e,s){if(this._locked)throw a("pattern");return this._ps[`#${e||"custom"}`]=s,this}url(e=!1){if(this._locked)throw a("url");return this._ps.url=e?/^(?:https?:)?\/\/.+$/i:/^https?:\/\/.+$/i,this}dataUri(){if(this._locked)throw a("dataUri");return this._ps.dataUri=/^data:[a-z]+\/[a-z]+;base64,[\w+/=]+$/,this}enum(...e){if(this._locked)throw a("enum");const s=e[0];return U(e,ce)?(this._allow=e,z(this._ps)):y(s)&&(this._allow=Object.values(s).map(n=>`${n}`),z(this._ps)),this}disallow(...e){return this._reject.push(...e),this}optional(){if(this._locked)throw a("optional");return this._opt=!0,this}maybeNull(){if(this._locked)throw a("maybeNull");return this._null=!0,this}lock(){return this._locked=!0,this}clone(){const e=new M;return e._ps={...this._ps},e._allow=[...this._allow],e._reject=[...this._reject],e._locked=!1,e}validate(e,s=g.warn){if(e===void 0)return this._opt||(s("should be a string, but got undefined"),!1);if(e===null)return this._null||(s("should be a string, but got null"),!1);if(typeof e!="string")return s(`should be a string, but got ${typeof e}`),!1;if(this._allow.length>0)return this._allow.includes(e)||(s(`${j(e)} is not allowed, just support ${this._allow.map(j).join(", ")}`),!1);if(this._reject.length>0&&this._reject.some(r=>typeof r=="string"?r===e:r.test(e)))return s(`${j(e)} is not allowed`),!1;const n=Object.keys(this._ps);return n.length>0&&!n.some(r=>{const o=this._ps[r];return o instanceof RegExp?o.test(e):o(e)})?(s(`${j(e)} is not match pattern ${n.join(" | ")}`),!1):!0}}class L{_int=!1;_min=-1/0;_max=1/0;_allow=[];_reject=[];_infinite=!1;_unsafe=!1;_nan=!1;_locked=!1;_opt=!1;_null=!1;int(){if(this._locked)throw a("int");return this._int=!0,this}min(e){if(this._locked)throw a("min");return Number.isNaN(e)||(this._min=e),this}max(e){if(this._locked)throw a("max");return Number.isNaN(e)||(this._max=e),this}allowNaN(){if(this._locked)throw a("allowNaN");return this._nan=!0,this}allowInfinity(){if(this._locked)throw a("allowInfinity");return this._infinite=!0,this._unsafe=!0,this}unsafe(){if(this._locked)throw a("unsafe");return this._unsafe=!0,this}enum(...e){if(this._locked)throw a("enum");const s=e[0];return U(e,x)?(this._allow=e,this._reject=[]):y(s)&&(this._allow=Object.values(s).map(n=>x(n)?n:null).filter(n=>n!==null),this._reject=[]),this}disallow(...e){if(this._locked)throw a("disallow");return this._reject.push(...e),this}optional(){if(this._locked)throw a("optional");return this._opt=!0,this}maybeNull(){if(this._locked)throw a("maybeNull");return this._null=!0,this}lock(){return this._locked=!0,this}clone(){const e=new L;return e._int=this._int,e._min=this._min,e._max=this._max,e._allow=[...this._allow],e._reject=[...this._reject],e._infinite=this._infinite,e._unsafe=this._unsafe,e._nan=this._nan,e._locked=!1,e}validate(e,s=g.warn){return e===void 0?this._opt||(s("should be a number, but got undefined"),!1):e===null?this._null||(s("should be a number, but got null"),!1):typeof e!="number"?(s(`should be a number, but got ${typeof e}`),!1):Number.isNaN(e)?this._nan||(s("should be a number, but got NaN"),!1):!Number.isFinite(e)&&!this._infinite?(s("should be a number, but got Infinity"),!1):this._allow.length>0?this._allow.includes(e)||(s(`${e} is not allowed, just support ${this._allow.join(", ")}`),!1):this._reject.length>0&&this._reject.includes(e)?(s(`${e} is not allowed`),!1):this._int&&Math.ceil(e)!==e?(s(`${e} is not an integer`),!1):!x(e)&&!this._unsafe?(s(`${e} is not a safe number`),!1):e>=this._min&&e<=this._max||(s(`${e} is not in range [${this._min}, ${this._max}]`),!1)}}class P{_min=null;_max=null;_allow=[];_reject=[];_locked=!1;_opt=!1;_null=!1;min(e){if(this._locked)throw a("min");return this._min=e,this}max(e){if(this._locked)throw a("max");return this._max=e,this}enum(...e){if(this._locked)throw a("enum");const s=e[0];return U(e,O)?(this._allow=e,this._reject=[]):y(s)&&(this._allow=Object.values(s).map(n=>O(n)?n:null).filter(n=>n!==null),this._reject=[]),this}disallow(...e){if(this._locked)throw a("disallow");return this._reject.push(...e),this}optional(){if(this._locked)throw a("optional");return this._opt=!0,this}maybeNull(){if(this._locked)throw a("maybeNull");return this._null=!0,this}lock(){return this._locked=!0,this}clone(){const e=new P;return e._min=this._min,e._max=this._max,e._allow=[...this._allow],e._reject=[...this._reject],e._locked=!1,e}validate(e,s=g.warn){return e===void 0?this._opt||(s("should be a bigint, but got undefined"),!1):e===null?this._null||(s("should be a bigint, but got null"),!1):O(e)?this._allow.length>0?this._allow.includes(e)||(s(`${e} is not allowed, just support ${this._allow.join(", ")}`),!1):this._reject.length>0&&this._reject.includes(e)?(s(`${e} is not allowed`),!1):(this._min!==null?e>=this._min:!0)&&(this._max!==null?e<=this._max:!0)||(s(`${e} is not in range [${this._min===null?-1/0:this._min}, ${this._max===null?1/0:this._max}]`),!1):(s(`should be a bigint, but got ${typeof e}`),!1)}}class C{_locked=!1;_opt=!1;_null=!1;optional(){if(this._locked)throw a("optional");return this._opt=!0,this}maybeNull(){if(this._locked)throw a("maybeNull");return this._null=!0,this}lock(){return this._locked=!0,this}clone(){return new C}validate(e,s=g.warn){return e===void 0?this._opt||(s("should be a boolean, but got undefined"),!1):e===null?this._null||(s("should be a boolean, but got null"),!1):typeof e!="boolean"?(s(`should be a boolean, but got ${typeof e}`),!1):!0}}class v{_shape;_plain=!1;_locked=!1;_opt=!1;_null=!1;constructor(e){this._shape=e}plain(){if(this._locked)throw a("plain");return this._plain=!0,this}optional(){if(this._locked)throw a("optional");return this._opt=!0,this}maybeNull(){if(this._locked)throw a("maybeNull");return this._null=!0,this}lock(){return this._locked=!0,this}get shape(){return{...this._shape}}clone(){const e=new v(this._shape);return e._plain=this._plain,e._locked=!1,e}match(e,s){return e in this._shape?this._shape[e].validate(s,X):!1}validate(e,s=g.warn){return e===void 0?this._opt||(s("should be a object, but got undefined"),!1):e===null?this._null||(s("should be a object, but got null"),!1):Q(e)?this._plain&&!y(e)?(s(`should be a plain object, but got ${T(e)}`),!1):Object.keys(this._shape).every(n=>this._shape[n].validate(e[n],(...r)=>{s(`[.${String(n)}]`,...r)})):(s(`should be a object, but got ${T(e)}`),!1)}}class I{_val;_locked=!1;_opt=!1;_null=!1;constructor(e){this._val=e}optional(){if(this._locked)throw a("optional");return this._opt=!0,this}maybeNull(){if(this._locked)throw a("maybeNull");return this._null=!0,this}lock(){return this._locked=!0,this}clone(){return new I(this._val)}validate(e,s=g.warn){return e===void 0?this._opt||(s("should be a record, but got undefined"),!1):e===null?this._null||(s("should be a record, but got null"),!1):y(e)?Object.keys(e).every(n=>this._val.validate(e[n],(...r)=>{s(`[:${n}]`,...r)})):(s(`should be a record, but got ${T(e)}`),!1)}}class q{_val;_min=0;_max=1/0;_locked=!1;_opt=!1;_null=!1;constructor(e){this._val=e}min(e){if(this._locked)throw a("min");return this._min=e,this}max(e){if(this._locked)throw a("max");return this._max=e,this}optional(){if(this._locked)throw a("optional");return this._opt=!0,this}maybeNull(){if(this._locked)throw a("maybeNull");return this._null=!0,this}lock(){return this._locked=!0,this}clone(){const e=new q(this._val);return e._min=this._min,e._max=this._max,e._locked=!1,e}validate(e,s=g.warn){return e===void 0?this._opt||(s("should be a array, but got undefined"),!1):e===null?this._null||(s("should be a array, but got null"),!1):Array.isArray(e)?e.length<this._min||e.length>this._max?(this._min===this._max?s(`should be a array with length ${this._min}`):s(`should be a array with length between ${this._min} and ${this._max}`),!1):e.every((n,r)=>this._val.validate(n,(...o)=>{s(`[${r}]`,...o)})):(s(`should be a array, but got ${typeof e}`),!1)}}class D{_vs;_locked=!1;_opt=!1;_null=!1;constructor(...e){this._vs=e}optional(){if(this._locked)throw a("optional");return this._opt=!0,this}maybeNull(){if(this._locked)throw a("maybeNull");return this._null=!0,this}lock(){return this._locked=!0,this}clone(){return new D(...this._vs)}validate(e,s=g.warn){return e===void 0?this._opt||(s("should be a tuple, but got undefined"),!1):e===null?this._null||(s("should be a tuple, but got null"),!1):Array.isArray(e)?e.length!==this._vs.length?(s(`should be a tuple with length ${this._vs.length}, but got ${e.length}`),!1):this._vs.every((n,r)=>n.validate(e[r],(...o)=>{s(`[idx:${r}]`,...o)})):(s(`should be a tuple, but got ${typeof e}`),!1)}}class B{_vs;_key="";_locked=!1;_opt=!1;_null=!1;constructor(...e){this._vs=e}optional(){if(this._locked)throw a("optional");return this._opt=!0,this}maybeNull(){if(this._locked)throw a("maybeNull");return this._null=!0,this}key(e){if(this._locked)throw a("key");return this._vs.every(s=>s instanceof v)?this._key=e:g.warn("union type key can only be used when all validators are ObjectValidator"),this}satisfies(){return this}lock(){return this._locked=!0,this}get validators(){return[...this._vs]}clone(){const e=new B(...this._vs);return e._key=this._key,e._locked=!1,e}validate(e,s=g.warn){if(e===void 0)return this._opt||(s("should be a union, but got undefined"),!1);if(e===null)return this._null||(s("should be a union, but got null"),!1);if(this._key&&Q(e)&&e){const r=e[this._key];if(r===void 0)return s(`key field "${this._key}" is not found`,e),!1;const o=this._vs.find(i=>i instanceof v&&i.match(this._key,r));return o?o.validate(e,s):(s(`key field "${this._key}" value is match union definition`,r),!1)}const n=this._vs.some(r=>r.validate(e,X));return n||s("value is not match union definition",e),n}}class E{_name="";_guard;_locked=!1;_opt=!1;_null=!1;constructor(e,s){this._name=e,this._guard=s}optional(){if(this._locked)throw a("optional");return this._opt=!0,this}maybeNull(){if(this._locked)throw a("maybeNull");return this._null=!0,this}lock(){return this._locked=!0,this}clone(){return new E(this._name,this._guard)}validate(e,s=g.warn){const n=this._name||"custom type";return e===void 0?this._opt||(s(`should be ${n}, but got undefined`),!1):e===null?this._null||(s(`should be ${n}, but got null`),!1):this._guard(e)||(s(`custom validation${this._name?`(${this._name})`:""} failed`),!1)}}function me(t,e){if(typeof t=="string"){if(!e)throw new Error("custom type guard must be defined");return new E(t,e)}return new E("",t)}const _e={shape(t){return t},define(t){return t},guard(t){return function(e){return t.validate(e)}},object(t){return new v(t)},record(t){return new I(t)},array(t){return new q(t)},tuple(...t){return new D(...t)},union(...t){return new B(...t)},string(){return new M},bool(){return new C},number(){return new L},bigint(){return new P},custom:me,unknown(){return{validate(t){return!0}}},never(){return{validate(t){return!1}}}},ge=t=>y(t)&&Object.keys(t).length===0;_e.custom("EmptyObject",ge);function pe(t,e="数据未能正确识别"){return typeof t=="function"?{guard:t,message:e}:{guard:t.guard,message:t.message||e}}function be(t,e=""){return!e||N(t,!0)?V(t):(V(e)+"/"+t).replace(/\/{2,}/g,"/").replace(/:\//,"://")}function V(t){return N(t,!0)?t.startsWith("http")?t:("location"in globalThis?location.protocol:"https:")+t:("location"in globalThis?location.origin:"http://127.0.0.1")+"/"+t.replace(/^\/+/,"")}function ye(t,e){const s={};return(t.match(/([^=&#?]+)=[^&#]*/g)||[]).forEach(function(n){const r=n.split("="),o=r[0],i=decodeURIComponent(r[1]||"");s[o]!==void 0?s[o]+=","+i:s[o]=i}),e!==!0?s[e]||"":s}function we(t,e){if(e){if(e===!0)return t.replace(/\?[^#]*/,"")}else return t;const s=t.split("#"),n=s[0].split("?"),r=n[0],o=n.length>1?n[1]:"",i=s.length>1?"#"+s[1]:"",u=typeof e=="string"?[e]:Array.isArray(e)?e:[];return!u.length||!o?s[0]+i:(u.map(c=>c.replace(/([\\(){}[\]^$+\-*?|])/g,"\\$1")),(r+"?"+o.replace(new RegExp("(?:^|&)(?:"+u.join("|")+")=[^&$]+","g"),"").replace(/^&/,"")).replace(/\?$/,"")+i)}function ke(t,e,s=!1){const n=typeof e=="string"?e:Object.keys(e).map(i=>`${i}=${encodeURIComponent(e[i])}`).join("&");if(!n)return t;const r=t.split("#");s&&(r[0]=we(r[0],(n.match(/([^=&#?]+)=[^&#]+/g)||[]).map(i=>i.replace(/=.+$/,""))));const o=r[0].indexOf("?")+1?"&":"?";return(r[0]+o+n+(r.length>1?"#"+r[1]:"")).replace(/\?&/,"?")}function ve(t){const e=t.match(/(?:\?|&)([^=]+)(?:&|$)/g);return e?e.join("").replace(/(?:\?|^&+|&+$)/g,"").replace(/&{2}/g,"&").split("&").sort():[]}class $e{ttl;cache;constructor(e=500){this.cache={},this.ttl=Math.max(e,0)}getKey(e,s,n,r){if(e.toLowerCase()!=="get"&&!r)return"";const o=e.toLowerCase(),i=s.replace(/#.+/,""),u=i.replace(/\?.+/g,"");if(r){const h=r()||"";return h?`${u}_${o}_${h}`:""}const c=Object.assign(ye(i,!0),n),m=ve(i),f=Object.keys(c).sort().map(h=>`${h}#${c[h]}`);return`${u}_${o}_${f.join(",")}_${m.join(",")}`}updateTTL(e){this.ttl=Math.max(e,0)}get(e,s){if(Math.max(s??this.ttl,0)===0)return null;const r=this.cache[e];return r?r.ttl<Date.now()?(delete this.cache[e],null):r.res:null}set(e,s,n){const r=Math.max(n??this.ttl,0);r!==0&&(this.cache[e]={ttl:Date.now()+r,res:s})}}class ee{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"}}};constructor(e){e&&this.set(e)}set(e){if(e.baseURL&&!/^\/.+/.test(e.baseURL)&&!N(e.baseURL))throw console.warn("baseURL 需要以 / 开头,或者是完整的 url 地址"),new Error("BaseURLError");Object.assign(this.config,e)}get(e){return this.config[e]}getFullUrl(e){return be(e,this.config.baseURL)}showMessage(e,s,n,r){this.config.messageHandler&&s&&this.config.messageHandler(e,s,n,r)}}const H={UnexpectResponse:"UnexpectResponse",Aborted:"Aborted",Unknown:"Unknown",NetworkError:"NetworkError",Timeout:"Timeout",NotSupport:"NotSupport",URLFormatError:"URLFormatError"};function je(t,e,s,n){if(e.ok&&!he(e.data)&&n){const r=pe(n,s.get("defaultTypeGuardMessage"));return r.guard(e.data)||(e.code=H.UnexpectResponse,s.showMessage(!0,`${t} ${r.message}`,e.code,e.status),console.error(e.code,t,e.data),e.data=null,e.message=r.message),e}return e}class Re{agent;config;cache;constructor(e,s){this.config=new ee(s),this.agent=e,this.cache=new $e(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(e,s){const n=this.cache.getKey(s?.method||"GET",e,s?.params,s?.cacheResolve);if(n){const r=this.cache.get(n,s?.cacheTTL);if(r)return await r}try{const r=this.agent(e,this.config,s);return n&&this.cache.set(n,r,s?.cacheTTL),await r}catch(r){return console.error("RequestError",r),{ok:!1,status:-9,code:H.Unknown,message:r instanceof Error?`${r.message}
2
+ ${r.stack||""}`:String(r),headers:{},data:null}}}async guard(e,s,n){return je(e,s,this.config,n)}setConfig(e){this.config.set(e),this.cache.updateTTL(this.config.get("cacheTTL"))}getConfig(e){return this.config.get(e)}async head(e,s){const n=Object.assign({},s||null);return n.method="HEAD",this.guard(e,await this.request(e,n),null)}async get(e,s,n){const r=Object.assign({},n||null);r.method="GET";const o=this.request(e,r);return this.guard(e,await o,s||null)}async post(e,s,n,r){const o=Object.assign({},r||null);return o.method="POST",o.body=s||{},this.guard(e,await this.request(e,o),n||null)}async del(e,s,n){const r=Object.assign({},n||null);return r.method="DELETE",this.guard(e,await this.request(e,r),s||null)}async put(e,s,n,r){const o=Object.assign({},r||null);return o.method="PUT",o.body=s||{},this.guard(e,await this.request(e,o),n||null)}async patch(e,s,n,r){const o=Object.assign({},r||null);return o.method="PATCH",o.body=s||{},this.guard(e,await this.request(e,o),n||null)}}async function Ee(t,e,s){const n=Object.assign({method:"GET"},s),r=k.FormData?n.body instanceof FormData:!1,o=r&&n.method!=="POST"&&n.method!=="PUT"?"POST":n.method,i=o==="GET"||o==="HEAD"||o==="DELETE";i&&n.body!==void 0&&(console.warn("request body is invalid with method get, head, delete"),delete n.body);const u=Object.assign(r||i?{}:{"Content-Type":k.Blob&&n.body instanceof Blob?n.body.type||"application/octet-stream":"application/json;charset=utf-8"},n.headers),c=n.params||{},m={};Object.keys(c).forEach(_=>{c[_]!==void 0&&(m[_]=Ne(c[_]))});const f=e.getFullUrl(t),h=xe(n.body),p=n.timeout||e.get("timeout"),b=await async function(){const _=e.get("requestTransformer");if(_)return await _({headers:u,params:m,method:o,url:f,body:h})}(),w=typeof b=="string"&&b?b:f;return e.get("logHandler")?.({type:"ready",url:w,method:o,headers:u,timeout:p,body:h}),{url:w,method:o,body:h,params:m,headers:u,timeout:p,abort:n.abort,credentials:n.credentials||e.get("credentials")}}function Ne(t){return typeof t=="string"?t:Array.isArray(t)?t.join(","):t+""}function xe(t){if(t)return typeof t=="string"||k.URLSearchParams&&t instanceof URLSearchParams||t instanceof ArrayBuffer||k.Blob&&t instanceof Blob||k.FormData&&t instanceof FormData?t:JSON.stringify(t)}const te="data",$="message";function Oe(t,e,s,n,r){const o=r||n;return G(t)?Le(o.ok||n.ok,t,e,s):Te(o.failed||n.failed,e,s)}const Fe=function(t){const e=[],s=t.failed||{resolve:"json"};switch(e.push("- 当http状态码 <200 或者 >=400 时"),s.resolve){case"body":e.push(" 将响应内容格式化为字符串并作为错误消息");break;case"json":e.push(" 将响应解析为json,并读取 "+(s.messageField||$)+" 作为错误消息");break}const n=t.ok||{resolve:"body"};switch(e.push("- 当http状态码 >=200 并且 <400 时"),n.resolve){case"body":e.push(" 将响应尝试解析为 json,并作为数据内容返回");break;case"json":e.push(" 将响应解析为 json,读取 "+(n.dataField||te)+" 作为响应数据,读取 "+(n.messageField||$)+" 作为提示消息"),n.statusField&&e.push(" 当 "+n.statusField+" 为 "+(n.statusOKValue||"空值")+" 时是成功提示,否则是错误消息"),n.ignoreMessage&&e.push(" 并忽略以下消息:"+n.ignoreMessage);break}return e.join(`
3
+ `)};function Te(t,e,s){const n=t||{resolve:"json",messageField:$},r={ok:!1,code:e,message:s,data:null};switch(n.resolve){case"body":r.message=W(s)||s;break;case"json":const{code:o,message:i}=Se(s,n.converter,n.statusField,n.messageField);r.code=o||e,r.message=W(s)||i;break}return r}function Se(t,e,s,n=$){if(!Z(t))return{message:""};const r=A(F(t),e);return!r||!y(r)?{message:t}:{code:s?S(r,s):"",message:S(r,n)||t}}function S(t,e){const s=Array.isArray(e)?e:[e];for(const n of s)if(n in t)return Ae(t[n]);return""}function Ae(t){return t?typeof t=="string"?t:JSON.stringify(t):""}const Ue=/<title>([^<]+)<\/title>/i,Me=/<message>([^<]+)<\/message>/i;function W(t){const e=t.match(Ue);if(e)return e[1];const s=t.match(Me);return s?s[1]:""}function Le(t,e,s,n){const r=t||{resolve:"body"},o={ok:!0,code:s,message:"",data:null};if(e===204||!n)return o;if(r.resolve==="body")return o.data=Z(n)?A(F(n),t.converter):n,o;const i=A(F(n),t.converter);if(!i||!y(i))return o.ok=!1,o.code="ResponseFormatError",o.message="响应内容无法格式化为 Object",o;const u=r.statusField,c=r.statusOKValue||"",m=r.dataField||te,f=r.messageField||$,h=r.ignoreMessage||"";if(u&&!(u in i))return o.ok=!1,o.code="ResponseFieldMissing",o.message="响应内容找不到状态字段 "+u,o;const p=u?i[u]+"":"";return o.ok=u?p===c:!0,o.code=p||s,o.data=m===!0?i:m in i?i[m]:null,o.message=S(i,f),h&&o.message&&(Array.isArray(h)&&h.includes(o.message)||typeof h=="string"&&o.message===h)&&(o.message=""),o}function G(t){return t>=200&&t<400}function A(t,e){return e?typeof e=="function"?e(t):(console.warn('工具不再支持 "camelize", "snakify" 参数,请自行提供函数来转化 body 内容'),t):t}const Pe=oe("APIError");function Ce(t){const e={};for(const r in t.headers)(r.startsWith("x-")||r.includes("trace")||r.includes("server")||/\b(?:id|uuid)\b/.test(r))&&(e[r]=t.headers[r]);const s=t.url.replace(/^(?:https?:)?\/*/i,"").replace(/\?.+/,""),n=t.status<0?"unknown":t.status;return{sentryError:new Pe(`${s} | ${n}${t.code?` | ${t.code}`:""}`),sentryTags:{...e,status:n,method:t.method,code:t.code||"unknown",message:t.message||"empty"},sentryExtra:{url:t.url,responseBody:t.body||"empty",responseHeaders:t.headers,rawError:t.error}}}function se(t){return t.reduce((e,[s,n])=>(s&&(e[s]=n||""),e),{})}function Ie(t,e,s,n){const r=t.status,o=t.method,i=se(Object.entries(t.headers||{}).map(([b,w])=>[b.toLowerCase(),w])),{ok:u,code:c,data:m,message:f}=Oe(r,t.statusText,t.body,s.get("responseRule"),n?.responseRule);if(!G(r)){const b=Ce({url:t.url,method:t.method,status:r,code:c,message:f,body:t.body,headers:i,error:t.rawError});(s.get("errorHandler")||qe)({url:e,method:o,status:r,code:c,message:f,headers:i,rawError:t.rawError,responseBody:t.body,...b})}if(r<0)return J({ok:!1,status:r,code:t.statusText,headers:{},message:"",data:null},`${o} ${e} ${t.statusText}`,o,e,s,n);const h={ok:u,data:m,code:c,message:f,status:r,headers:i};s.get("responseHandler")?.({...h},o,e);const p=u?f:f||t.statusText;return J(h,p,o,e,s,n)}function J(t,e,s,n,r,o){const i=r.get("message"),u=i===!1||o?.message===!1?!1:o?.message||i;if(u!==!1){const c=typeof u=="function"?u(t,s,n,e):e;c instanceof Error?r.showMessage(!0,c.message,t.code,t.status):c&&typeof c=="object"&&"message"in c?r.showMessage(!1,c.message,t.code,t.status):r.showMessage(!t.ok,c,t.code,t.status)}return t}function qe(t){const e={};for(const s in t)s.startsWith("sentry")||(e[s]=t[s]);console.error("RequestError",e)}async function ne(t,e,s,n,r){const o=r||0,i=Math.max(0,Math.min(10,n?.maxRetry??s.get("maxRetry")??0)),u=n?.retryResolve??s.get("retryResolve"),c=s.get("logHandler");c?.({type:"prepare",url:e,method:n?.method||"GET",retry:o,maxRetry:i,message:o===0?"start":`retry ${o}/${i} start`,headers:n?.headers,options:n});const m=Date.now(),f=await t(e,s,n),h=f.status,p=Date.now()-m,b=`[cost ${p}][${h}] ${h<0?f.body:""}`;c?.({type:"finished",url:e,method:f.method,retry:o,maxRetry:i,message:o===0?`finish ${b}`:`retry ${o}/${i} finish ${b}`,response:f,headers:f.headers,cost:p});const w=G(h);if(!i||o>=i||u==="network"&&h>0||u==="status"&&w||Array.isArray(u)&&!u.includes(h)||typeof u=="function"&&u(f,o)!==!0)return f;const _=n?.retryInterval??s.get("retryInterval")??100;return await re(Math.max(100,_==="2EB"?Math.pow(2,o)*100:typeof _=="function"?_(o+1,{url:e,status:h,method:f.method})||0:_)),await ne(t,e,s,n,o+1)}exports.Ct=k;exports.Et=N;exports.NetRequestHandler=Re;exports.RequestGlobalConfig=ee;exports.RequestInternalError=H;exports.convertOptions=Ee;exports.fromEntries=se;exports.getResponseRulesDescription=Fe;exports.handleResponse=Ie;exports.retryRequest=ne;exports.ue=de;exports.ye=ke;
@@ -56,13 +56,13 @@ const ne = /^(?:https?:)?\/\/.+$/i, re = /^https?:\/\/.+$/i, oe = /^\{[\d\D]*\}$
56
56
  function ae(t) {
57
57
  return typeof t == "string";
58
58
  }
59
- function T(t, e = !1) {
59
+ function A(t, e = !1) {
60
60
  return e ? ne.test(t) : re.test(t);
61
61
  }
62
62
  function le(t) {
63
63
  return t == null;
64
64
  }
65
- function Q(t, ...e) {
65
+ function Y(t, ...e) {
66
66
  return t !== null && typeof t == "object" && !(t instanceof Map) && !(t instanceof Set) && !(t instanceof WeakMap) && !(t instanceof WeakSet) && !Array.isArray(t) && e.every((s) => s in t);
67
67
  }
68
68
  function y(t, ...e) {
@@ -73,7 +73,7 @@ function y(t, ...e) {
73
73
  function U(t, e) {
74
74
  return Array.isArray(t) && t.every((s) => e(s));
75
75
  }
76
- function N(t) {
76
+ function x(t) {
77
77
  if (typeof t != "number" || Number.isNaN(t) || !Number.isFinite(t))
78
78
  return !1;
79
79
  if (Number.isInteger(t))
@@ -83,7 +83,7 @@ function N(t) {
83
83
  const e = Math.abs(t);
84
84
  return e >= Number.EPSILON && e <= Number.MAX_SAFE_INTEGER;
85
85
  }
86
- function Y(t) {
86
+ function Q(t) {
87
87
  return oe.test(t) || ie.test(t);
88
88
  }
89
89
  function ue(t, e = 20) {
@@ -122,7 +122,7 @@ function j(t) {
122
122
  function F(t) {
123
123
  return typeof t == "object" && t && "constructor" in t && typeof t.constructor == "function" ? t.constructor.name || "ClassInstance" : Object.prototype.toString.call(t).replace(/(?:.+ |]$)/g, "");
124
124
  }
125
- function x(t) {
125
+ function N(t) {
126
126
  return typeof t == "bigint";
127
127
  }
128
128
  function a(t) {
@@ -197,7 +197,7 @@ class M {
197
197
  }) ? (s(`${j(e)} is not match pattern ${n.join(" | ")}`), !1) : !0;
198
198
  }
199
199
  }
200
- class P {
200
+ class L {
201
201
  _int = !1;
202
202
  _min = -1 / 0;
203
203
  _max = 1 / 0;
@@ -239,7 +239,7 @@ class P {
239
239
  enum(...e) {
240
240
  if (this._locked) throw a("enum");
241
241
  const s = e[0];
242
- return U(e, N) ? (this._allow = e, this._reject = []) : y(s) && (this._allow = Object.values(s).map((n) => N(n) ? n : null).filter((n) => n !== null), this._reject = []), this;
242
+ return U(e, x) ? (this._allow = e, this._reject = []) : y(s) && (this._allow = Object.values(s).map((n) => x(n) ? n : null).filter((n) => n !== null), this._reject = []), this;
243
243
  }
244
244
  disallow(...e) {
245
245
  if (this._locked) throw a("disallow");
@@ -257,14 +257,14 @@ class P {
257
257
  return this._locked = !0, this;
258
258
  }
259
259
  clone() {
260
- const e = new P();
260
+ const e = new L();
261
261
  return e._int = this._int, e._min = this._min, e._max = this._max, e._allow = [...this._allow], e._reject = [...this._reject], e._infinite = this._infinite, e._unsafe = this._unsafe, e._nan = this._nan, e._locked = !1, e;
262
262
  }
263
263
  validate(e, s = g.warn) {
264
- return e === void 0 ? this._opt || (s("should be a number, but got undefined"), !1) : e === null ? this._null || (s("should be a number, but got null"), !1) : typeof e != "number" ? (s(`should be a number, but got ${typeof e}`), !1) : Number.isNaN(e) ? this._nan || (s("should be a number, but got NaN"), !1) : !Number.isFinite(e) && !this._infinite ? (s("should be a number, but got Infinity"), !1) : this._allow.length > 0 ? this._allow.includes(e) || (s(`${e} is not allowed, just support ${this._allow.join(", ")}`), !1) : this._reject.length > 0 && this._reject.includes(e) ? (s(`${e} is not allowed`), !1) : this._int && Math.ceil(e) !== e ? (s(`${e} is not an integer`), !1) : !N(e) && !this._unsafe ? (s(`${e} is not a safe number`), !1) : e >= this._min && e <= this._max || (s(`${e} is not in range [${this._min}, ${this._max}]`), !1);
264
+ return e === void 0 ? this._opt || (s("should be a number, but got undefined"), !1) : e === null ? this._null || (s("should be a number, but got null"), !1) : typeof e != "number" ? (s(`should be a number, but got ${typeof e}`), !1) : Number.isNaN(e) ? this._nan || (s("should be a number, but got NaN"), !1) : !Number.isFinite(e) && !this._infinite ? (s("should be a number, but got Infinity"), !1) : this._allow.length > 0 ? this._allow.includes(e) || (s(`${e} is not allowed, just support ${this._allow.join(", ")}`), !1) : this._reject.length > 0 && this._reject.includes(e) ? (s(`${e} is not allowed`), !1) : this._int && Math.ceil(e) !== e ? (s(`${e} is not an integer`), !1) : !x(e) && !this._unsafe ? (s(`${e} is not a safe number`), !1) : e >= this._min && e <= this._max || (s(`${e} is not in range [${this._min}, ${this._max}]`), !1);
265
265
  }
266
266
  }
267
- class C {
267
+ class P {
268
268
  _min = null;
269
269
  _max = null;
270
270
  _allow = [];
@@ -283,7 +283,7 @@ class C {
283
283
  enum(...e) {
284
284
  if (this._locked) throw a("enum");
285
285
  const s = e[0];
286
- return U(e, x) ? (this._allow = e, this._reject = []) : y(s) && (this._allow = Object.values(s).map((n) => x(n) ? n : null).filter((n) => n !== null), this._reject = []), this;
286
+ return U(e, N) ? (this._allow = e, this._reject = []) : y(s) && (this._allow = Object.values(s).map((n) => N(n) ? n : null).filter((n) => n !== null), this._reject = []), this;
287
287
  }
288
288
  disallow(...e) {
289
289
  if (this._locked) throw a("disallow");
@@ -301,16 +301,16 @@ class C {
301
301
  return this._locked = !0, this;
302
302
  }
303
303
  clone() {
304
- const e = new C();
304
+ const e = new P();
305
305
  return e._min = this._min, e._max = this._max, e._allow = [...this._allow], e._reject = [...this._reject], e._locked = !1, e;
306
306
  }
307
307
  validate(e, s = g.warn) {
308
- return e === void 0 ? this._opt || (s("should be a bigint, but got undefined"), !1) : e === null ? this._null || (s("should be a bigint, but got null"), !1) : x(e) ? this._allow.length > 0 ? this._allow.includes(e) || (s(`${e} is not allowed, just support ${this._allow.join(", ")}`), !1) : this._reject.length > 0 && this._reject.includes(e) ? (s(`${e} is not allowed`), !1) : (this._min !== null ? e >= this._min : !0) && (this._max !== null ? e <= this._max : !0) || (s(
308
+ return e === void 0 ? this._opt || (s("should be a bigint, but got undefined"), !1) : e === null ? this._null || (s("should be a bigint, but got null"), !1) : N(e) ? this._allow.length > 0 ? this._allow.includes(e) || (s(`${e} is not allowed, just support ${this._allow.join(", ")}`), !1) : this._reject.length > 0 && this._reject.includes(e) ? (s(`${e} is not allowed`), !1) : (this._min !== null ? e >= this._min : !0) && (this._max !== null ? e <= this._max : !0) || (s(
309
309
  `${e} is not in range [${this._min === null ? -1 / 0 : this._min}, ${this._max === null ? 1 / 0 : this._max}]`
310
310
  ), !1) : (s(`should be a bigint, but got ${typeof e}`), !1);
311
311
  }
312
312
  }
313
- class I {
313
+ class C {
314
314
  _locked = !1;
315
315
  _opt = !1;
316
316
  _null = !1;
@@ -326,7 +326,7 @@ class I {
326
326
  return this._locked = !0, this;
327
327
  }
328
328
  clone() {
329
- return new I();
329
+ return new C();
330
330
  }
331
331
  validate(e, s = g.warn) {
332
332
  return e === void 0 ? this._opt || (s("should be a boolean, but got undefined"), !1) : e === null ? this._null || (s("should be a boolean, but got null"), !1) : typeof e != "boolean" ? (s(`should be a boolean, but got ${typeof e}`), !1) : !0;
@@ -373,12 +373,12 @@ class v {
373
373
  return e in this._shape ? this._shape[e].validate(s, J) : !1;
374
374
  }
375
375
  validate(e, s = g.warn) {
376
- return e === void 0 ? this._opt || (s("should be a object, but got undefined"), !1) : e === null ? this._null || (s("should be a object, but got null"), !1) : Q(e) ? this._plain && !y(e) ? (s(`should be a plain object, but got ${F(e)}`), !1) : Object.keys(this._shape).every((n) => this._shape[n].validate(e[n], (...r) => {
376
+ return e === void 0 ? this._opt || (s("should be a object, but got undefined"), !1) : e === null ? this._null || (s("should be a object, but got null"), !1) : Y(e) ? this._plain && !y(e) ? (s(`should be a plain object, but got ${F(e)}`), !1) : Object.keys(this._shape).every((n) => this._shape[n].validate(e[n], (...r) => {
377
377
  s(`[.${String(n)}]`, ...r);
378
378
  })) : (s(`should be a object, but got ${F(e)}`), !1);
379
379
  }
380
380
  }
381
- class L {
381
+ class I {
382
382
  _val;
383
383
  _locked = !1;
384
384
  _opt = !1;
@@ -398,7 +398,7 @@ class L {
398
398
  return this._locked = !0, this;
399
399
  }
400
400
  clone() {
401
- return new L(this._val);
401
+ return new I(this._val);
402
402
  }
403
403
  validate(e, s = g.warn) {
404
404
  return e === void 0 ? this._opt || (s("should be a record, but got undefined"), !1) : e === null ? this._null || (s("should be a record, but got null"), !1) : y(e) ? Object.keys(e).every(
@@ -523,7 +523,7 @@ class B {
523
523
  return this._opt || (s("should be a union, but got undefined"), !1);
524
524
  if (e === null)
525
525
  return this._null || (s("should be a union, but got null"), !1);
526
- if (this._key && Q(e) && e) {
526
+ if (this._key && Y(e) && e) {
527
527
  const r = e[this._key];
528
528
  if (r === void 0)
529
529
  return s(`key field "${this._key}" is not found`, e), !1;
@@ -603,7 +603,7 @@ const he = {
603
603
  * 如果需要指定 key 类型,使用 define 辅助工具
604
604
  */
605
605
  record(t) {
606
- return new L(t);
606
+ return new I(t);
607
607
  },
608
608
  /** 数组类型验证 */
609
609
  array(t) {
@@ -623,15 +623,15 @@ const he = {
623
623
  },
624
624
  /** 布尔型类型验证 */
625
625
  bool() {
626
- return new I();
626
+ return new C();
627
627
  },
628
628
  /** 数字验证 */
629
629
  number() {
630
- return new P();
630
+ return new L();
631
631
  },
632
632
  /** bigint 验证 */
633
633
  bigint() {
634
- return new C();
634
+ return new P();
635
635
  },
636
636
  /** 自定义验证 */
637
637
  custom: ce,
@@ -666,13 +666,13 @@ function de(t, e = "数据未能正确识别") {
666
666
  message: t.message || e
667
667
  };
668
668
  }
669
- function _e(t, e = "") {
670
- return !e || T(t, !0) ? z(t) : (z(e) + "/" + t).replace(/\/{2,}/g, "/").replace(/:\//, "://");
669
+ function me(t, e = "") {
670
+ return !e || A(t, !0) ? z(t) : (z(e) + "/" + t).replace(/\/{2,}/g, "/").replace(/:\//, "://");
671
671
  }
672
672
  function z(t) {
673
- return T(t, !0) ? t.startsWith("http") ? t : ("location" in globalThis ? location.protocol : "https:") + t : ("location" in globalThis ? location.origin : "http://127.0.0.1") + "/" + t.replace(/^\/+/, "");
673
+ return A(t, !0) ? t.startsWith("http") ? t : ("location" in globalThis ? location.protocol : "https:") + t : ("location" in globalThis ? location.origin : "http://127.0.0.1") + "/" + t.replace(/^\/+/, "");
674
674
  }
675
- function me(t, e) {
675
+ function _e(t, e) {
676
676
  const s = {};
677
677
  return (t.match(/([^=&#?]+)=[^&#]*/g) || []).forEach(function(n) {
678
678
  const r = n.split("="), o = r[0], i = decodeURIComponent(r[1] || "");
@@ -687,7 +687,7 @@ function ge(t, e) {
687
687
  const s = t.split("#"), n = s[0].split("?"), r = n[0], o = n.length > 1 ? n[1] : "", i = s.length > 1 ? "#" + s[1] : "", u = typeof e == "string" ? [e] : Array.isArray(e) ? e : [];
688
688
  return !u.length || !o ? s[0] + i : (u.map((c) => c.replace(/([\\(){}[\]^$+\-*?|])/g, "\\$1")), (r + "?" + o.replace(new RegExp("(?:^|&)(?:" + u.join("|") + ")=[^&$]+", "g"), "").replace(/^&/, "")).replace(/\?$/, "") + i);
689
689
  }
690
- function Pe(t, e, s = !1) {
690
+ function Le(t, e, s = !1) {
691
691
  const n = typeof e == "string" ? e : Object.keys(e).map((i) => `${i}=${encodeURIComponent(e[i])}`).join("&");
692
692
  if (!n)
693
693
  return t;
@@ -717,21 +717,21 @@ class be {
717
717
  const h = r() || "";
718
718
  return h ? `${u}_${o}_${h}` : "";
719
719
  }
720
- const c = Object.assign(me(i, !0), n), _ = pe(i), f = Object.keys(c).sort().map((h) => `${h}#${c[h]}`);
721
- return `${u}_${o}_${f.join(",")}_${_.join(",")}`;
720
+ const c = Object.assign(_e(i, !0), n), m = pe(i), f = Object.keys(c).sort().map((h) => `${h}#${c[h]}`);
721
+ return `${u}_${o}_${f.join(",")}_${m.join(",")}`;
722
722
  }
723
723
  updateTTL(e) {
724
724
  this.ttl = Math.max(e, 0);
725
725
  }
726
- get(e) {
727
- if (this.ttl === 0)
726
+ get(e, s) {
727
+ if (Math.max(s ?? this.ttl, 0) === 0)
728
728
  return null;
729
- const s = this.cache[e];
730
- return s ? s.ttl < Date.now() ? (delete this.cache[e], null) : s.res : null;
729
+ const r = this.cache[e];
730
+ return r ? r.ttl < Date.now() ? (delete this.cache[e], null) : r.res : null;
731
731
  }
732
732
  set(e, s, n) {
733
- const r = n ?? this.ttl;
734
- r <= 0 || (this.cache[e] = {
733
+ const r = Math.max(n ?? this.ttl, 0);
734
+ r !== 0 && (this.cache[e] = {
735
735
  ttl: Date.now() + r,
736
736
  res: s
737
737
  });
@@ -762,7 +762,7 @@ class ye {
762
762
  e && this.set(e);
763
763
  }
764
764
  set(e) {
765
- if (e.baseURL && !/^\/.+/.test(e.baseURL) && !T(e.baseURL))
765
+ if (e.baseURL && !/^\/.+/.test(e.baseURL) && !A(e.baseURL))
766
766
  throw console.warn("baseURL 需要以 / 开头,或者是完整的 url 地址"), new Error("BaseURLError");
767
767
  Object.assign(this.config, e);
768
768
  }
@@ -771,7 +771,7 @@ class ye {
771
771
  }
772
772
  /** 基于 baseURL 返回完整的 url 地址 */
773
773
  getFullUrl(e) {
774
- return _e(e, this.config.baseURL);
774
+ return me(e, this.config.baseURL);
775
775
  }
776
776
  /** 提示消息 */
777
777
  showMessage(e, s, n, r) {
@@ -801,7 +801,7 @@ function we(t, e, s, n) {
801
801
  }
802
802
  return e;
803
803
  }
804
- class Ce {
804
+ class Pe {
805
805
  agent;
806
806
  config;
807
807
  cache;
@@ -814,13 +814,13 @@ class Ce {
814
814
  async request(e, s) {
815
815
  const n = this.cache.getKey(s?.method || "GET", e, s?.params, s?.cacheResolve);
816
816
  if (n) {
817
- const r = this.cache.get(n);
817
+ const r = this.cache.get(n, s?.cacheTTL);
818
818
  if (r)
819
819
  return await r;
820
820
  }
821
821
  try {
822
822
  const r = this.agent(e, this.config, s);
823
- return n && this.cache.set(n, r), await r;
823
+ return n && this.cache.set(n, r, s?.cacheTTL), await r;
824
824
  } catch (r) {
825
825
  return console.error("RequestError", r), {
826
826
  ok: !1,
@@ -881,7 +881,7 @@ ${r.stack || ""}` : String(r),
881
881
  return o.method = "PATCH", o.body = s || {}, this.guard(e, await this.request(e, o), n || null);
882
882
  }
883
883
  }
884
- async function Ie(t, e, s) {
884
+ async function Ce(t, e, s) {
885
885
  const n = Object.assign({ method: "GET" }, s), r = k.FormData ? n.body instanceof FormData : !1, o = r && n.method !== "POST" && n.method !== "PUT" ? "POST" : n.method, i = o === "GET" || o === "HEAD" || o === "DELETE";
886
886
  i && n.body !== void 0 && (console.warn("request body is invalid with method get, head, delete"), delete n.body);
887
887
  const u = Object.assign(
@@ -889,20 +889,20 @@ async function Ie(t, e, s) {
889
889
  "Content-Type": k.Blob && n.body instanceof Blob ? n.body.type || "application/octet-stream" : "application/json;charset=utf-8"
890
890
  },
891
891
  n.headers
892
- ), c = n.params || {}, _ = {};
893
- Object.keys(c).forEach((m) => {
894
- c[m] !== void 0 && (_[m] = ke(c[m]));
892
+ ), c = n.params || {}, m = {};
893
+ Object.keys(c).forEach((_) => {
894
+ c[_] !== void 0 && (m[_] = ke(c[_]));
895
895
  });
896
896
  const f = e.getFullUrl(t), h = ve(n.body), p = n.timeout || e.get("timeout"), b = await async function() {
897
- const m = e.get("requestTransformer");
898
- if (m)
899
- return await m({ headers: u, params: _, method: o, url: f, body: h });
897
+ const _ = e.get("requestTransformer");
898
+ if (_)
899
+ return await _({ headers: u, params: m, method: o, url: f, body: h });
900
900
  }(), w = typeof b == "string" && b ? b : f;
901
901
  return e.get("logHandler")?.({ type: "ready", url: w, method: o, headers: u, timeout: p, body: h }), {
902
902
  url: w,
903
903
  method: o,
904
904
  body: h,
905
- params: _,
905
+ params: m,
906
906
  headers: u,
907
907
  timeout: p,
908
908
  abort: n.abort,
@@ -921,7 +921,7 @@ function $e(t, e, s, n, r) {
921
921
  const o = r || n;
922
922
  return H(t) ? Oe(o.ok || n.ok, t, e, s) : je(o.failed || n.failed, e, s);
923
923
  }
924
- const Le = function(t) {
924
+ const Ie = function(t) {
925
925
  const e = [], s = t.failed || { resolve: "json" };
926
926
  switch (e.push("- 当http状态码 <200 或者 >=400 时"), s.resolve) {
927
927
  case "body":
@@ -956,25 +956,25 @@ function je(t, e, s) {
956
956
  };
957
957
  switch (n.resolve) {
958
958
  case "body":
959
- r.message = W(s) || s;
959
+ r.message = V(s) || s;
960
960
  break;
961
961
  case "json":
962
962
  const { code: o, message: i } = Ee(s, n.converter, n.statusField, n.messageField);
963
- r.code = o || e, r.message = W(s) || i;
963
+ r.code = o || e, r.message = V(s) || i;
964
964
  break;
965
965
  }
966
966
  return r;
967
967
  }
968
968
  function Ee(t, e, s, n = $) {
969
- if (!Y(t))
969
+ if (!Q(t))
970
970
  return { message: "" };
971
- const r = A(O(t), e);
971
+ const r = S(O(t), e);
972
972
  return !r || !y(r) ? { message: t } : {
973
- code: s ? S(r, s) : "",
974
- message: S(r, n) || t
973
+ code: s ? T(r, s) : "",
974
+ message: T(r, n) || t
975
975
  };
976
976
  }
977
- function S(t, e) {
977
+ function T(t, e) {
978
978
  const s = Array.isArray(e) ? e : [e];
979
979
  for (const n of s)
980
980
  if (n in t)
@@ -984,12 +984,12 @@ function S(t, e) {
984
984
  function Re(t) {
985
985
  return t ? typeof t == "string" ? t : JSON.stringify(t) : "";
986
986
  }
987
- const Ne = /<title>([^<]+)<\/title>/i, xe = /<message>([^<]+)<\/message>/i;
988
- function W(t) {
989
- const e = t.match(Ne);
987
+ const xe = /<title>([^<]+)<\/title>/i, Ne = /<message>([^<]+)<\/message>/i;
988
+ function V(t) {
989
+ const e = t.match(xe);
990
990
  if (e)
991
991
  return e[1];
992
- const s = t.match(xe);
992
+ const s = t.match(Ne);
993
993
  return s ? s[1] : "";
994
994
  }
995
995
  function Oe(t, e, s, n) {
@@ -1002,24 +1002,24 @@ function Oe(t, e, s, n) {
1002
1002
  if (e === 204 || !n)
1003
1003
  return o;
1004
1004
  if (r.resolve === "body")
1005
- return o.data = Y(n) ? A(O(n), t.converter) : n, o;
1006
- const i = A(O(n), t.converter);
1005
+ return o.data = Q(n) ? S(O(n), t.converter) : n, o;
1006
+ const i = S(O(n), t.converter);
1007
1007
  if (!i || !y(i))
1008
1008
  return o.ok = !1, o.code = "ResponseFormatError", o.message = "响应内容无法格式化为 Object", o;
1009
- const u = r.statusField, c = r.statusOKValue || "", _ = r.dataField || ee, f = r.messageField || $, h = r.ignoreMessage || "";
1009
+ const u = r.statusField, c = r.statusOKValue || "", m = r.dataField || ee, f = r.messageField || $, h = r.ignoreMessage || "";
1010
1010
  if (u && !(u in i))
1011
1011
  return o.ok = !1, o.code = "ResponseFieldMissing", o.message = "响应内容找不到状态字段 " + u, o;
1012
1012
  const p = u ? i[u] + "" : "";
1013
- return o.ok = u ? p === c : !0, o.code = p || s, o.data = _ === !0 ? i : _ in i ? i[_] : null, o.message = S(i, f), h && o.message && (Array.isArray(h) && h.includes(o.message) || typeof h == "string" && o.message === h) && (o.message = ""), o;
1013
+ return o.ok = u ? p === c : !0, o.code = p || s, o.data = m === !0 ? i : m in i ? i[m] : null, o.message = T(i, f), h && o.message && (Array.isArray(h) && h.includes(o.message) || typeof h == "string" && o.message === h) && (o.message = ""), o;
1014
1014
  }
1015
1015
  function H(t) {
1016
1016
  return t >= 200 && t < 400;
1017
1017
  }
1018
- function A(t, e) {
1018
+ function S(t, e) {
1019
1019
  return e ? typeof e == "function" ? e(t) : (console.warn('工具不再支持 "camelize", "snakify" 参数,请自行提供函数来转化 body 内容'), t) : t;
1020
1020
  }
1021
1021
  const Fe = se("APIError");
1022
- function Se(t) {
1022
+ function Te(t) {
1023
1023
  const e = {};
1024
1024
  for (const r in t.headers)
1025
1025
  (r.startsWith("x-") || r.includes("trace") || r.includes("server") || /\b(?:id|uuid)\b/.test(r)) && (e[r] = t.headers[r]);
@@ -1041,16 +1041,16 @@ function Se(t) {
1041
1041
  }
1042
1042
  };
1043
1043
  }
1044
- function Ae(t) {
1044
+ function Se(t) {
1045
1045
  return t.reduce(
1046
1046
  (e, [s, n]) => (s && (e[s] = n || ""), e),
1047
1047
  {}
1048
1048
  );
1049
1049
  }
1050
1050
  function De(t, e, s, n) {
1051
- const r = t.status, o = t.method, i = Ae(
1051
+ const r = t.status, o = t.method, i = Se(
1052
1052
  Object.entries(t.headers || {}).map(([b, w]) => [b.toLowerCase(), w])
1053
- ), { ok: u, code: c, data: _, message: f } = $e(
1053
+ ), { ok: u, code: c, data: m, message: f } = $e(
1054
1054
  r,
1055
1055
  t.statusText,
1056
1056
  t.body,
@@ -1058,7 +1058,7 @@ function De(t, e, s, n) {
1058
1058
  n?.responseRule
1059
1059
  );
1060
1060
  if (!H(r)) {
1061
- const b = Se({
1061
+ const b = Te({
1062
1062
  url: t.url,
1063
1063
  method: t.method,
1064
1064
  status: r,
@@ -1068,7 +1068,7 @@ function De(t, e, s, n) {
1068
1068
  headers: i,
1069
1069
  error: t.rawError
1070
1070
  });
1071
- (s.get("errorHandler") || Te)({
1071
+ (s.get("errorHandler") || Ae)({
1072
1072
  url: e,
1073
1073
  method: o,
1074
1074
  status: r,
@@ -1081,7 +1081,7 @@ function De(t, e, s, n) {
1081
1081
  });
1082
1082
  }
1083
1083
  if (r < 0)
1084
- return V(
1084
+ return W(
1085
1085
  { ok: !1, status: r, code: t.statusText, headers: {}, message: "", data: null },
1086
1086
  `${o} ${e} ${t.statusText}`,
1087
1087
  o,
@@ -1089,12 +1089,12 @@ function De(t, e, s, n) {
1089
1089
  s,
1090
1090
  n
1091
1091
  );
1092
- const h = { ok: u, data: _, code: c, message: f, status: r, headers: i };
1092
+ const h = { ok: u, data: m, code: c, message: f, status: r, headers: i };
1093
1093
  s.get("responseHandler")?.({ ...h }, o, e);
1094
1094
  const p = u ? f : f || t.statusText;
1095
- return V(h, p, o, e, s, n);
1095
+ return W(h, p, o, e, s, n);
1096
1096
  }
1097
- function V(t, e, s, n, r, o) {
1097
+ function W(t, e, s, n, r, o) {
1098
1098
  const i = r.get("message"), u = i === !1 || o?.message === !1 ? !1 : o?.message || i;
1099
1099
  if (u !== !1) {
1100
1100
  const c = typeof u == "function" ? u(t, s, n, e) : e;
@@ -1102,7 +1102,7 @@ function V(t, e, s, n, r, o) {
1102
1102
  }
1103
1103
  return t;
1104
1104
  }
1105
- function Te(t) {
1105
+ function Ae(t) {
1106
1106
  const e = {};
1107
1107
  for (const s in t)
1108
1108
  s.startsWith("sentry") || (e[s] = t[s]);
@@ -1120,7 +1120,7 @@ async function Ue(t, e, s, n, r) {
1120
1120
  headers: n?.headers,
1121
1121
  options: n
1122
1122
  });
1123
- const _ = Date.now(), f = await t(e, s, n), h = f.status, p = Date.now() - _, b = `[cost ${p}][${h}] ${h < 0 ? f.body : ""}`;
1123
+ const m = Date.now(), f = await t(e, s, n), h = f.status, p = Date.now() - m, b = `[cost ${p}][${h}] ${h < 0 ? f.body : ""}`;
1124
1124
  c?.({
1125
1125
  type: "finished",
1126
1126
  url: e,
@@ -1135,25 +1135,25 @@ async function Ue(t, e, s, n, r) {
1135
1135
  const w = H(h);
1136
1136
  if (!i || o >= i || u === "network" && h > 0 || u === "status" && w || Array.isArray(u) && !u.includes(h) || typeof u == "function" && u(f, o) !== !0)
1137
1137
  return f;
1138
- const m = n?.retryInterval ?? s.get("retryInterval") ?? 100;
1138
+ const _ = n?.retryInterval ?? s.get("retryInterval") ?? 100;
1139
1139
  return await te(
1140
1140
  Math.max(
1141
1141
  100,
1142
- m === "2EB" ? Math.pow(2, o) * 100 : typeof m == "function" ? m(o + 1, { url: e, status: h, method: f.method }) || 0 : m
1142
+ _ === "2EB" ? Math.pow(2, o) * 100 : typeof _ == "function" ? _(o + 1, { url: e, status: h, method: f.method }) || 0 : _
1143
1143
  )
1144
1144
  ), await Ue(t, e, s, n, o + 1);
1145
1145
  }
1146
1146
  export {
1147
- Ce as N,
1147
+ k as C,
1148
+ A as E,
1149
+ Pe as N,
1148
1150
  ye as R,
1149
- Pe as _,
1150
1151
  Z as a,
1151
- T as b,
1152
- Ie as c,
1153
- Ae as f,
1154
- Le as g,
1152
+ Ce as c,
1153
+ Se as f,
1154
+ Ie as g,
1155
1155
  De as h,
1156
- k as j,
1157
- Me as l,
1158
- Ue as r
1156
+ Ue as r,
1157
+ Me as u,
1158
+ Le as y
1159
1159
  };
package/dist/wx.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("./retry-BltIjZ1L.cjs"),l=async function(e,o,u){return t.handleResponse(await t.retryRequest(p,e,o,u),e,o,u)},p=async function(e,o,u){const s=await t.convertOptions(e,o,u),a=s.method==="PATCH"?"POST":s.method,c=t._e(s.url,s.params);return t.jt.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:t.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?"":f(n.data)})}})}):{url:c,method:a,status:-1,statusText:t.RequestInternalError.NotSupport,body:""}};function f(e){return typeof e=="string"?e:e instanceof ArrayBuffer&&t.jt.TextDecoder?new TextDecoder().decode(e):JSON.stringify(e)}function i(e){return new t.NetRequestHandler(l,e)}const r=i(),R=r.setConfig,y=r.head,g=r.get,q=r.post,h=r.del,x=r.put;exports.RequestInternalError=t.RequestInternalError;exports.getResponseRulesDescription=t.getResponseRulesDescription;exports.NetRequest=i;exports.del=h;exports.get=g;exports.head=y;exports.post=q;exports.put=x;exports.setGlobalConfig=R;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("./retry-sL4_1f7S.cjs"),l=async function(e,o,u){return t.handleResponse(await t.retryRequest(p,e,o,u),e,o,u)},p=async function(e,o,u){const s=await t.convertOptions(e,o,u),a=s.method==="PATCH"?"POST":s.method,c=t.ye(s.url,s.params);return t.Ct.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:t.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?"":f(n.data)})}})}):{url:c,method:a,status:-1,statusText:t.RequestInternalError.NotSupport,body:""}};function f(e){return typeof e=="string"?e:e instanceof ArrayBuffer&&t.Ct.TextDecoder?new TextDecoder().decode(e):JSON.stringify(e)}function i(e){return new t.NetRequestHandler(l,e)}const r=i(),y=r.setConfig,R=r.head,g=r.get,q=r.post,h=r.del,x=r.put;exports.RequestInternalError=t.RequestInternalError;exports.getResponseRulesDescription=t.getResponseRulesDescription;exports.NetRequest=i;exports.del=h;exports.get=g;exports.head=R;exports.post=q;exports.put=x;exports.setGlobalConfig=y;
package/dist/wx.js CHANGED
@@ -1,9 +1,9 @@
1
- import { h as p, r as f, c as l, _ as h, j as i, a as d, N as x } from "./retry-D8V8lDdS.js";
2
- import { g as H } from "./retry-D8V8lDdS.js";
3
- const y = async function(t, n, r) {
1
+ import { h as p, r as f, c as l, y, C as i, a as d, N as h } from "./retry-vMhW20_a.js";
2
+ import { g as H } from "./retry-vMhW20_a.js";
3
+ const x = async function(t, n, r) {
4
4
  return p(await f(g, t, n, r), t, n, r);
5
5
  }, g = async function(t, n, r) {
6
- const e = await l(t, n, r), a = e.method === "PATCH" ? "POST" : e.method, u = h(e.url, e.params);
6
+ const e = await l(t, n, r), a = e.method === "PATCH" ? "POST" : e.method, u = y(e.url, e.params);
7
7
  return i.wx ? new Promise((c) => {
8
8
  wx.request({
9
9
  url: u,
@@ -44,17 +44,17 @@ function m(t) {
44
44
  return typeof t == "string" ? t : t instanceof ArrayBuffer && i.TextDecoder ? new TextDecoder().decode(t) : JSON.stringify(t);
45
45
  }
46
46
  function R(t) {
47
- return new x(y, t);
47
+ return new h(x, t);
48
48
  }
49
- const s = R(), T = s.setConfig, q = s.head, b = s.get, C = s.post, N = s.del, D = s.put;
49
+ const s = R(), T = s.setConfig, q = s.head, C = s.get, b = s.post, N = s.del, D = s.put;
50
50
  export {
51
51
  R as NetRequest,
52
52
  d as RequestInternalError,
53
53
  N as del,
54
- b as get,
54
+ C as get,
55
55
  H as getResponseRulesDescription,
56
56
  q as head,
57
- C as post,
57
+ b as post,
58
58
  D as put,
59
59
  T as setGlobalConfig
60
60
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seayoo-web/request",
3
- "version": "3.3.0",
3
+ "version": "3.3.1",
4
4
  "description": "request tools for seayoo web",
5
5
  "type": "module",
6
6
  "source": "./src/index.ts",
@@ -60,7 +60,7 @@
60
60
  "happy-dom": "^12.10.3",
61
61
  "msw": "^2.7.0",
62
62
  "vitest": "^3.0.5",
63
- "@seayoo-web/utils": "^3.6.2"
63
+ "@seayoo-web/utils": "^3.7.1"
64
64
  },
65
65
  "scripts": {
66
66
  "prebuild": "pnpm --F utils build",
@@ -6,6 +6,6 @@ export declare class Cache<T = unknown> {
6
6
  constructor(ttl?: number);
7
7
  getKey(method: string, url: string, param?: Record<string, unknown>, resolve?: RequestCacheResolve): string;
8
8
  updateTTL(ttl: number): void;
9
- get(key: string): Promise<T> | null;
9
+ get(key: string, ttl?: number): Promise<T> | null;
10
10
  set(key: string, action: Promise<T>, ttl?: number): void;
11
11
  }