@seayoo-web/request 3.0.2 → 3.0.4
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 +2 -2
- package/dist/index.js +12 -12
- package/dist/node.cjs +1 -1
- package/dist/node.js +14 -14
- package/dist/{request.fetch-CO0NyBFt.cjs → request.fetch-BvueP7FG.cjs} +1 -1
- package/dist/{request.fetch-D3jWQQuh.js → request.fetch-Dizdj2Zf.js} +1 -1
- package/dist/{retry-DjjIq-kG.js → retry-BdpLadtU.js} +88 -87
- package/dist/retry-DsG4xDrA.cjs +3 -0
- package/dist/wx.cjs +1 -1
- package/dist/wx.js +18 -18
- package/package.json +4 -3
- package/dist/retry-BhqDL0mQ.cjs +0 -3
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("./retry-
|
|
2
|
-
`).forEach(n=>{const r=n.trim();if(!r)return;const d=r.split(":"),c=d[0].trim();c&&(s[c]=(d[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 r=e.callback+"";if(!t)return null;const d=o.
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("./retry-DsG4xDrA.cjs"),q=require("./request.fetch-BvueP7FG.cjs"),y=async function(t,s,e){return o.handleResponse(await o.retryRequest(R,t,s,e),t,s,e)};async function m(t,s,e,n){const r=e==null?void 0:e.body,d=(e==null?void 0:e.method)==="PUT"?"PUT":"POST";if(s instanceof Blob){const u=new o.RequestGlobalConfig(n),g=await R(t,u,{...e,method:d,body:s});return o.handleResponse(g,t,u,e)}const c=new FormData,f={...s};r instanceof Object&&Object.entries(r).forEach(([u,g])=>{g instanceof Blob?f[u]=g:Array.isArray(g)?g.forEach((a,i)=>{c.append(`${u}[${i}]`,String(a))}):c.append(u,String(g))});for(const u in f)c.append(u,f[u]);const b=new o.RequestGlobalConfig(n),w=await R(t,b,{...e,method:d,body:c});return o.handleResponse(w,t,b,e)}const R=async function(t,s,e){const n=await o.convertOptions(t,s,e),r=n.method,d=e==null?void 0:e.onUploadProgress,c=o.ge(n.url,n.params);return await new Promise(f=>{let b=null,w=!1;const u=function(){w||(a.abort(),w=!0)};function g(){b!==null&&clearTimeout(b),n.abort&&n.abort.removeEventListener("abort",u)}const a=new XMLHttpRequest;if(a.open(r,c,!0),d){let i=1;a.upload.addEventListener("progress",h=>{i=h.total,d({total:h.total,loaded:h.loaded})}),a.addEventListener("load",()=>{d({loaded:i,total:i})})}a.addEventListener("load",()=>{const i=a.status;g(),f({url:c,method:r,status:i,statusText:a.statusText,headers:E(a),body:r==="HEAD"||i===204?"":a.responseText})}),a.addEventListener("error",i=>{g(),f({url:c,method:r,status:a.status||-1,statusText:a.statusText||o.RequestInternalError.NetworkError,body:"",rawError:i})},!0),a.addEventListener("abort",()=>{g(),f({url:c,method:r,status:0,statusText:o.RequestInternalError.Aborted,body:""})}),Object.entries(n.headers).forEach(([i,h])=>{a.setRequestHeader(i,h)}),n.credentials==="include"&&(a.withCredentials=!0),a.send(n.body||void 0),n.abort&&n.abort.addEventListener("abort",u),n.timeout>0&&(b=setTimeout(u,n.timeout))})};function E(t){const s={};if(!t)return s;const e=t.getAllResponseHeaders();return e&&e!=="null"&&e.replace(/\r/g,"").split(`
|
|
2
|
+
`).forEach(n=>{const r=n.trim();if(!r)return;const d=r.split(":"),c=d[0].trim();c&&(s[c]=(d[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 r=e.callback+"";if(!t)return null;const d=o.ge(t,e,!0);return new Promise(c=>{n[r]=function(f){if(r in window&&delete n[r],s(f))return f;console.warn("response type check failed",t,f),c(null)},o.ce(d).catch(function(){c(null),delete n[r]})})}async function T(t,s,e={}){const n=window;return"var"in e||(e.var="jsonxData"+Math.random().toString(16).slice(2)),t?await o.ce(o.ge(t,e,!0)).then(()=>{const r=n[e.var+""];return s(r)?r:(console.warn("response type check failed",t,r),null)}).catch(()=>null):null}const j=async function(t,s,e){return await m(t,s,e,{baseURL:l.getConfig("baseURL"),logHandler:l.getConfig("logHandler"),errorHandler:l.getConfig("errorHandler"),requestTransformer:l.getConfig("requestTransformer"),messageHandler:l.getConfig("messageHandler"),responseHandler:l.getConfig("responseHandler")})};function p(t){if(!o.jt.window)throw new Error("Default Module Only Support In Browser");return o.jt.fetch?new o.NetRequestHandler(q.fetchRequest,t):new o.NetRequestHandler(y,t)}const l=p(),x=l.setConfig,C=l.request,L=l.head,S=l.get,k=l.post,v=l.del,D=l.put,U=l.patch;exports.RequestInternalError=o.RequestInternalError;exports.getResponseRulesDescription=o.getResponseRulesDescription;exports.NetRequest=p;exports.del=v;exports.get=S;exports.head=L;exports.jsonp=H;exports.jsonx=T;exports.patch=U;exports.post=k;exports.put=D;exports.request=C;exports.setGlobalConfig=x;exports.upload=j;
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { h as w, r as T, R as y, c as x,
|
|
2
|
-
import {
|
|
3
|
-
import { f as C } from "./request.fetch-
|
|
1
|
+
import { h as w, r as T, R as y, c as x, g as p, a as R, b as q, j as E, N as H } from "./retry-BdpLadtU.js";
|
|
2
|
+
import { d as J } from "./retry-BdpLadtU.js";
|
|
3
|
+
import { f as C } from "./request.fetch-Dizdj2Zf.js";
|
|
4
4
|
const L = async function(t, a, e) {
|
|
5
5
|
return w(await T(m, t, a, e), t, a, e);
|
|
6
6
|
};
|
|
7
|
-
async function
|
|
7
|
+
async function j(t, a, e, n) {
|
|
8
8
|
const r = e == null ? void 0 : e.body, d = (e == null ? void 0 : e.method) === "PUT" ? "PUT" : "POST";
|
|
9
9
|
if (a instanceof Blob) {
|
|
10
10
|
const l = new y(n), f = await m(t, l, {
|
|
@@ -55,7 +55,7 @@ const m = async function(t, a, e) {
|
|
|
55
55
|
method: r,
|
|
56
56
|
status: i,
|
|
57
57
|
statusText: o.statusText,
|
|
58
|
-
headers:
|
|
58
|
+
headers: k(o),
|
|
59
59
|
body: r === "HEAD" || i === 204 ? "" : o.responseText
|
|
60
60
|
});
|
|
61
61
|
}), o.addEventListener(
|
|
@@ -85,7 +85,7 @@ const m = async function(t, a, e) {
|
|
|
85
85
|
}), n.credentials === "include" && (o.withCredentials = !0), o.send(n.body || void 0), n.abort && n.abort.addEventListener("abort", l), n.timeout > 0 && (b = setTimeout(l, n.timeout));
|
|
86
86
|
});
|
|
87
87
|
};
|
|
88
|
-
function
|
|
88
|
+
function k(t) {
|
|
89
89
|
const a = {};
|
|
90
90
|
if (!t)
|
|
91
91
|
return a;
|
|
@@ -99,7 +99,7 @@ function O(t) {
|
|
|
99
99
|
s && (a[s] = (d[1] || "").trim());
|
|
100
100
|
}), a;
|
|
101
101
|
}
|
|
102
|
-
async function
|
|
102
|
+
async function D(t, a, e = {}) {
|
|
103
103
|
const n = window;
|
|
104
104
|
"callback" in e || (e.callback = "jsonxData" + Math.random().toString(16).slice(2));
|
|
105
105
|
const r = e.callback + "";
|
|
@@ -116,7 +116,7 @@ async function v(t, a, e = {}) {
|
|
|
116
116
|
});
|
|
117
117
|
});
|
|
118
118
|
}
|
|
119
|
-
async function
|
|
119
|
+
async function O(t, a, e = {}) {
|
|
120
120
|
const n = window;
|
|
121
121
|
return "var" in e || (e.var = "jsonxData" + Math.random().toString(16).slice(2)), t ? await q(p(t, e, !0)).then(() => {
|
|
122
122
|
const r = n[e.var + ""];
|
|
@@ -124,7 +124,7 @@ async function D(t, a, e = {}) {
|
|
|
124
124
|
}).catch(() => null) : null;
|
|
125
125
|
}
|
|
126
126
|
const P = async function(t, a, e) {
|
|
127
|
-
return await
|
|
127
|
+
return await j(t, a, e, {
|
|
128
128
|
baseURL: c.getConfig("baseURL"),
|
|
129
129
|
logHandler: c.getConfig("logHandler"),
|
|
130
130
|
errorHandler: c.getConfig("errorHandler"),
|
|
@@ -144,10 +144,10 @@ export {
|
|
|
144
144
|
R as RequestInternalError,
|
|
145
145
|
F as del,
|
|
146
146
|
B as get,
|
|
147
|
-
|
|
147
|
+
J as getResponseRulesDescription,
|
|
148
148
|
N as head,
|
|
149
|
-
|
|
150
|
-
|
|
149
|
+
D as jsonp,
|
|
150
|
+
O as jsonx,
|
|
151
151
|
I as patch,
|
|
152
152
|
X as post,
|
|
153
153
|
G as put,
|
package/dist/node.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./retry-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./retry-DsG4xDrA.cjs"),y=require("./request.fetch-BvueP7FG.cjs"),b=require("node:http"),g=require("node:https"),w=async function(r,u,c){return e.handleResponse(await e.retryRequest(E,r,u,c),r,u,c)},E=async function(r,u,c){const t=await e.convertOptions(r,u,c);if(!e.At(t.url))return{url:t.url,method:t.method,status:-1,statusText:e.RequestInternalError.URLFormatError,headers:{},body:""};const p=/^https:\/\//i.test(t.url)?g:b,a=new URL(t.url),i=t.params;i instanceof Object&&Object.keys(i).forEach(n=>a.searchParams.set(n,i[n]));const f=t.method==="HEAD";return new Promise(n=>{const d=p.request(a,{headers:t.headers,method:t.method,timeout:t.timeout>0?t.timeout:void 0},function(o){const l=[];o.on("data",h=>l.push(h)),o.on("end",()=>{const h=e.fromEntries(Object.entries(o.headers).map(([R,m])=>[R.toLowerCase(),Array.isArray(m)?m.join(","):m]));n({url:a.toString(),method:t.method,status:o.statusCode||-1,statusText:o.statusMessage||e.RequestInternalError.Unknown,headers:h,body:f||o.statusCode===204?"":Buffer.concat(l).toString("utf-8")})})});d.on("error",o=>{n({url:a.toString(),method:t.method,status:-1,statusText:e.RequestInternalError.NetworkError,body:"",rawError:o})}),d.on("timeout",()=>{n({url:a.toString(),method:t.method,status:-1,statusText:e.RequestInternalError.Timeout,body:""})}),t.body&&d.write(t.body),d.end()})};function q(r){return e.jt.fetch?new e.NetRequestHandler(y.fetchRequest,r):new e.NetRequestHandler(w,r)}const s=q(),j=s.setConfig,C=s.head,N=s.get,S=s.post,T=s.del,O=s.put,x=s.patch;exports.NetRequest=q;exports.del=T;exports.get=N;exports.head=C;exports.patch=x;exports.post=S;exports.put=O;exports.setGlobalConfig=j;
|
package/dist/node.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { h as b, r as q, c as w,
|
|
2
|
-
import { f as x } from "./request.fetch-
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
const
|
|
6
|
-
return b(await q(
|
|
7
|
-
},
|
|
1
|
+
import { h as b, r as q, c as w, A as g, a as d, f as E, N as p, j } from "./retry-BdpLadtU.js";
|
|
2
|
+
import { f as x } from "./request.fetch-Dizdj2Zf.js";
|
|
3
|
+
import A from "node:http";
|
|
4
|
+
import C from "node:https";
|
|
5
|
+
const N = async function(o, a, u) {
|
|
6
|
+
return b(await q(T, o, a, u), o, a, u);
|
|
7
|
+
}, T = async function(o, a, u) {
|
|
8
8
|
const t = await w(o, a, u);
|
|
9
9
|
if (!g(t.url))
|
|
10
10
|
return {
|
|
@@ -15,7 +15,7 @@ const T = async function(o, a, u) {
|
|
|
15
15
|
headers: {},
|
|
16
16
|
body: ""
|
|
17
17
|
};
|
|
18
|
-
const l = /^https:\/\//i.test(t.url) ?
|
|
18
|
+
const l = /^https:\/\//i.test(t.url) ? C : A, n = new URL(t.url), i = t.params;
|
|
19
19
|
i instanceof Object && Object.keys(i).forEach((r) => n.searchParams.set(r, i[r]));
|
|
20
20
|
const R = t.method === "HEAD";
|
|
21
21
|
return new Promise((r) => {
|
|
@@ -64,16 +64,16 @@ const T = async function(o, a, u) {
|
|
|
64
64
|
});
|
|
65
65
|
};
|
|
66
66
|
function L(o) {
|
|
67
|
-
return
|
|
67
|
+
return j.fetch ? new p(x, o) : new p(N, o);
|
|
68
68
|
}
|
|
69
|
-
const s = L(), k = s.setConfig, B = s.head, P = s.get,
|
|
69
|
+
const s = L(), k = s.setConfig, B = s.head, P = s.get, D = s.post, F = s.del, G = s.put, I = s.patch;
|
|
70
70
|
export {
|
|
71
71
|
L as NetRequest,
|
|
72
|
-
|
|
72
|
+
F as del,
|
|
73
73
|
P as get,
|
|
74
74
|
B as head,
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
75
|
+
I as patch,
|
|
76
|
+
D as post,
|
|
77
|
+
G as put,
|
|
78
78
|
k as setGlobalConfig
|
|
79
79
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const s=require("./retry-
|
|
1
|
+
"use strict";const s=require("./retry-DsG4xDrA.cjs"),m=async function(a,n,i){return s.handleResponse(await s.retryRequest(w,a,n,i),a,n,i)},w=async function(a,n,i){const t=await s.convertOptions(a,n,i),c=new URL(t.url),u=t.params;u instanceof Object&&Object.keys(u).forEach(e=>c.searchParams.set(e,u[e]));const r=s.jt.AbortController?new AbortController:null;function d(){r&&!r.signal.aborted&&r.abort()}t.abort&&t.abort.addEventListener("abort",d);const h=t.timeout>0?setTimeout(d,t.timeout):null,l=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:r==null?void 0:r.signal,redirect:"follow"}).then(async e=>{const o={url:c.toString(),method:t.method,status:e.status,statusText:e.statusText,headers:s.fromEntries([...e.headers.entries()])},b=l||e.status===204?"":await e.text().catch(f=>f);return b instanceof Error?{...o,body:"",statusText:s.RequestInternalError.Unknown,rawError:b}:{...o,body:b}}).catch(e=>{const o=r==null?void 0:r.signal.aborted;return{url:c.toString(),method:t.method,status:o?0:-1,statusText:o?s.RequestInternalError.Aborted:s.RequestInternalError.NetworkError,body:"",rawError:e}}).finally(()=>{h!==null&&clearTimeout(h),t.abort&&t.abort.removeEventListener("abort",d)})};exports.fetchRequest=m;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { h as m, r as w, c as y,
|
|
1
|
+
import { h as m, r as w, c as y, j as E, f as R, a as b } from "./retry-BdpLadtU.js";
|
|
2
2
|
const x = async function(s, o, n) {
|
|
3
3
|
return m(await w(g, s, o, n), s, o, n);
|
|
4
4
|
}, g = async function(s, o, n) {
|
|
@@ -16,7 +16,8 @@ const u = typeof globalThis < "u" ? globalThis : typeof self < "u" ? self : type
|
|
|
16
16
|
FormData: "FormData" in u && _(u.FormData),
|
|
17
17
|
TextDecoder: "TextDecoder" in u && _(u.TextDecoder),
|
|
18
18
|
ResizeObserver: "ResizeObserver" in u && _(u.ResizeObserver),
|
|
19
|
-
AbortController: "AbortController" in u && _(u.AbortController)
|
|
19
|
+
AbortController: "AbortController" in u && _(u.AbortController),
|
|
20
|
+
URLSearchParams: "URLSearchParams" in u && _(u.URLSearchParams)
|
|
20
21
|
};
|
|
21
22
|
function _(e) {
|
|
22
23
|
return typeof e == "function";
|
|
@@ -75,7 +76,7 @@ function b(e, ...t) {
|
|
|
75
76
|
function B(e, t) {
|
|
76
77
|
return Array.isArray(e) && e.every((s) => t(s));
|
|
77
78
|
}
|
|
78
|
-
function
|
|
79
|
+
function U(e) {
|
|
79
80
|
if (typeof e != "number" || Number.isNaN(e) || !Number.isFinite(e) || Number.isInteger(e) && !Number.isSafeInteger(e))
|
|
80
81
|
return !1;
|
|
81
82
|
if (e === 0)
|
|
@@ -86,20 +87,20 @@ function T(e) {
|
|
|
86
87
|
function ot(e) {
|
|
87
88
|
return bt.test(e) || yt.test(e);
|
|
88
89
|
}
|
|
89
|
-
function
|
|
90
|
+
function vt(e, t = 20) {
|
|
91
|
+
const s = Math.max(t, 10), r = [...e];
|
|
92
|
+
return r.length <= s ? e : r.slice(0, s - 3).join("") + "...";
|
|
93
|
+
}
|
|
94
|
+
function E(e) {
|
|
90
95
|
return e ? e[0].toLowerCase() + e.slice(1) : "";
|
|
91
96
|
}
|
|
92
97
|
const at = /_\w*/, lt = /-\w*/;
|
|
93
|
-
function Z(e) {
|
|
94
|
-
const t = at.test(e) ? e.replace(/(?:^_*|_*$)/g, "").replace(/_+([^_])/g, (s, r) => r.toUpperCase()) : lt.test(e) ? e.replace(/(?:^-*|-*$)/g, "").replace(/-+(\w)/g, (s, r) => r.toUpperCase()) : e;
|
|
95
|
-
return R(t);
|
|
96
|
-
}
|
|
97
98
|
function Y(e) {
|
|
98
|
-
|
|
99
|
+
const t = at.test(e) ? e.replace(/(?:^_*|_*$)/g, "").replace(/_+([^_])/g, (s, r) => r.toUpperCase()) : lt.test(e) ? e.replace(/(?:^-*|-*$)/g, "").replace(/-+(\w)/g, (s, r) => r.toUpperCase()) : e;
|
|
100
|
+
return E(t);
|
|
99
101
|
}
|
|
100
|
-
function
|
|
101
|
-
|
|
102
|
-
return e.length <= s ? e : e.slice(0, s - 3) + "...";
|
|
102
|
+
function Q(e) {
|
|
103
|
+
return at.test(e) ? E(e).replace(/(?:^_*|_*$)/g, "").replace(/_+([^_])/g, (t, s) => "_" + s.toLowerCase()) : lt.test(e) ? E(e.replace(/(?:^-*|-*$)/g, "")).replace(/-+(\w)/g, (t, s) => "_" + s.toLowerCase()) : E(e).replace(/[A-Z]/g, (t) => `_${t.toLowerCase()}`);
|
|
103
104
|
}
|
|
104
105
|
function M(e, t) {
|
|
105
106
|
try {
|
|
@@ -111,25 +112,25 @@ function M(e, t) {
|
|
|
111
112
|
}
|
|
112
113
|
"" + Math.random().toString(32).slice(2);
|
|
113
114
|
function A(e, t = !1) {
|
|
114
|
-
return typeof e == "string" ?
|
|
115
|
+
return typeof e == "string" ? Y(e) : Array.isArray(e) ? e.map((s) => !t || typeof s == "string" ? A(s) : typeof s == "object" && s ? A(s, !0) : s) : b(e) ? Object.keys(e).reduce(
|
|
115
116
|
(s, r) => {
|
|
116
|
-
const n =
|
|
117
|
+
const n = Y(String(r)), i = n.charAt(0).toLowerCase() + n.slice(1);
|
|
117
118
|
return s[i] = t ? e[r] : A(e[r]), s;
|
|
118
119
|
},
|
|
119
120
|
{}
|
|
120
121
|
) : e;
|
|
121
122
|
}
|
|
122
123
|
function F(e, t = !1) {
|
|
123
|
-
return typeof e == "string" ?
|
|
124
|
+
return typeof e == "string" ? Q(e) : Array.isArray(e) ? e.map((s) => !t || typeof s == "string" ? F(s) : typeof s == "object" && s ? F(s, t) : s) : b(e) ? Object.keys(e).reduce(
|
|
124
125
|
(s, r) => {
|
|
125
|
-
const n =
|
|
126
|
+
const n = Q(String(r));
|
|
126
127
|
return s[n] = t ? e[r] : F(e[r]), s;
|
|
127
128
|
},
|
|
128
129
|
{}
|
|
129
130
|
) : e;
|
|
130
131
|
}
|
|
131
132
|
nt("LoadUtils");
|
|
132
|
-
async function
|
|
133
|
+
async function Vt(e) {
|
|
133
134
|
return await new Promise(function(t) {
|
|
134
135
|
const s = document.getElementsByTagName("head")[0], r = document.createElement("script");
|
|
135
136
|
r.setAttribute("type", "text/javascript"), r.setAttribute("charset", "utf-8"), r.onload = function() {
|
|
@@ -145,13 +146,13 @@ function tt(e) {
|
|
|
145
146
|
}), e;
|
|
146
147
|
}
|
|
147
148
|
const g = nt("Validator");
|
|
148
|
-
function
|
|
149
|
+
function R(e) {
|
|
149
150
|
return e ? `"${vt(e).replace(/"/g, '\\"')}"` : "empty string";
|
|
150
151
|
}
|
|
151
152
|
function C(e) {
|
|
152
153
|
return typeof e == "object" && e && "constructor" in e && typeof e.constructor == "function" ? e.constructor.name || "ClassInstance" : Object.prototype.toString.call(e).replace(/(?:.+ |]$)/g, "");
|
|
153
154
|
}
|
|
154
|
-
function
|
|
155
|
+
function T(e) {
|
|
155
156
|
return typeof e == "bigint";
|
|
156
157
|
}
|
|
157
158
|
function l(e) {
|
|
@@ -213,14 +214,14 @@ class q {
|
|
|
213
214
|
if (typeof t != "string")
|
|
214
215
|
return s(`should be a string, but got ${typeof t}`), !1;
|
|
215
216
|
if (this._allow.length > 0)
|
|
216
|
-
return this._allow.includes(t) || (s(`${
|
|
217
|
+
return this._allow.includes(t) || (s(`${R(t)} is not allowed, just support ${this._allow.map(R).join(", ")}`), !1);
|
|
217
218
|
if (this._reject.length > 0 && this._reject.some((n) => typeof n == "string" ? n === t : n.test(t)))
|
|
218
|
-
return s(`${
|
|
219
|
+
return s(`${R(t)} is not allowed`), !1;
|
|
219
220
|
const r = Object.keys(this._ps);
|
|
220
221
|
return r.length > 0 && !r.some((n) => {
|
|
221
222
|
const i = this._ps[n];
|
|
222
223
|
return i instanceof RegExp ? i.test(t) : i(t);
|
|
223
|
-
}) ? (s(`${
|
|
224
|
+
}) ? (s(`${R(t)} is not match pattern ${r.join(" | ")}`), !1) : !0;
|
|
224
225
|
}
|
|
225
226
|
}
|
|
226
227
|
class H {
|
|
@@ -257,7 +258,7 @@ class H {
|
|
|
257
258
|
enum(...t) {
|
|
258
259
|
if (this._locked) throw l("enum");
|
|
259
260
|
const s = t[0];
|
|
260
|
-
return B(t,
|
|
261
|
+
return B(t, U) ? (this._allow = t, this._reject = []) : b(s) && (this._allow = Object.values(s).map((r) => U(r) ? r : null).filter((r) => r !== null), this._reject = []), this;
|
|
261
262
|
}
|
|
262
263
|
disallow(...t) {
|
|
263
264
|
if (this._locked) throw l("disallow");
|
|
@@ -279,10 +280,10 @@ class H {
|
|
|
279
280
|
return t._int = this._int, t._min = this._min, t._max = this._max, t._allow = [...this._allow], t._reject = [...this._reject], t._infinite = this._infinite, t._unsafe = this._unsafe, t._nan = this._nan, t._locked = !1, t;
|
|
280
281
|
}
|
|
281
282
|
validate(t, s = g.warn) {
|
|
282
|
-
return t === void 0 ? this._opt || (s("should be a number, but got undefined"), !1) : t === null ? this._null || (s("should be a number, but got null"), !1) : typeof t != "number" ? (s(`should be a number, but got ${typeof t}`), !1) : Number.isNaN(t) ? this._nan || (s("should be a number, but got NaN"), !1) : !Number.isFinite(t) && !this._infinite ? (s("should be a number, but got Infinity"), !1) : this._allow.length > 0 ? this._allow.includes(t) || (s(`${t} is not allowed, just support ${this._allow.join(", ")}`), !1) : this._reject.length > 0 && this._reject.includes(t) ? (s(`${t} is not allowed`), !1) : this._int && Math.ceil(t) !== t ? (s(`${t} is not an integer`), !1) : !
|
|
283
|
+
return t === void 0 ? this._opt || (s("should be a number, but got undefined"), !1) : t === null ? this._null || (s("should be a number, but got null"), !1) : typeof t != "number" ? (s(`should be a number, but got ${typeof t}`), !1) : Number.isNaN(t) ? this._nan || (s("should be a number, but got NaN"), !1) : !Number.isFinite(t) && !this._infinite ? (s("should be a number, but got Infinity"), !1) : this._allow.length > 0 ? this._allow.includes(t) || (s(`${t} is not allowed, just support ${this._allow.join(", ")}`), !1) : this._reject.length > 0 && this._reject.includes(t) ? (s(`${t} is not allowed`), !1) : this._int && Math.ceil(t) !== t ? (s(`${t} is not an integer`), !1) : !U(t) && !this._unsafe ? (s(`${t} is not a safe number`), !1) : t >= this._min && t <= this._max || (s(`${t} is not in range [${this._min}, ${this._max}]`), !1);
|
|
283
284
|
}
|
|
284
285
|
}
|
|
285
|
-
class
|
|
286
|
+
class z {
|
|
286
287
|
constructor() {
|
|
287
288
|
o(this, "_min", null), o(this, "_max", null), o(this, "_allow", []), o(this, "_reject", []), o(this, "_locked", !1), o(this, "_opt", !1), o(this, "_null", !1);
|
|
288
289
|
}
|
|
@@ -297,7 +298,7 @@ class G {
|
|
|
297
298
|
enum(...t) {
|
|
298
299
|
if (this._locked) throw l("enum");
|
|
299
300
|
const s = t[0];
|
|
300
|
-
return B(t,
|
|
301
|
+
return B(t, T) ? (this._allow = t, this._reject = []) : b(s) && (this._allow = Object.values(s).map((r) => T(r) ? r : null).filter((r) => r !== null), this._reject = []), this;
|
|
301
302
|
}
|
|
302
303
|
disallow(...t) {
|
|
303
304
|
if (this._locked) throw l("disallow");
|
|
@@ -315,16 +316,16 @@ class G {
|
|
|
315
316
|
return this._locked = !0, this;
|
|
316
317
|
}
|
|
317
318
|
clone() {
|
|
318
|
-
const t = new
|
|
319
|
+
const t = new z();
|
|
319
320
|
return t._min = this._min, t._max = this._max, t._allow = [...this._allow], t._reject = [...this._reject], t._locked = !1, t;
|
|
320
321
|
}
|
|
321
322
|
validate(t, s = g.warn) {
|
|
322
|
-
return t === void 0 ? this._opt || (s("should be a bigint, but got undefined"), !1) : t === null ? this._null || (s("should be a bigint, but got null"), !1) :
|
|
323
|
+
return t === void 0 ? this._opt || (s("should be a bigint, but got undefined"), !1) : t === null ? this._null || (s("should be a bigint, but got null"), !1) : T(t) ? this._allow.length > 0 ? this._allow.includes(t) || (s(`${t} is not allowed, just support ${this._allow.join(", ")}`), !1) : this._reject.length > 0 && this._reject.includes(t) ? (s(`${t} is not allowed`), !1) : (this._min !== null ? t >= this._min : !0) && (this._max !== null ? t <= this._max : !0) || (s(
|
|
323
324
|
`${t} is not in range [${this._min === null ? -1 / 0 : this._min}, ${this._max === null ? 1 / 0 : this._max}]`
|
|
324
325
|
), !1) : (s(`should be a bigint, but got ${typeof t}`), !1);
|
|
325
326
|
}
|
|
326
327
|
}
|
|
327
|
-
class
|
|
328
|
+
class G {
|
|
328
329
|
constructor() {
|
|
329
330
|
o(this, "_locked", !1), o(this, "_opt", !1), o(this, "_null", !1);
|
|
330
331
|
}
|
|
@@ -340,7 +341,7 @@ class K {
|
|
|
340
341
|
return this._locked = !0, this;
|
|
341
342
|
}
|
|
342
343
|
clone() {
|
|
343
|
-
return new
|
|
344
|
+
return new G();
|
|
344
345
|
}
|
|
345
346
|
validate(t, s = g.warn) {
|
|
346
347
|
return t === void 0 ? this._opt || (s("should be a boolean, but got undefined"), !1) : t === null ? this._null || (s("should be a boolean, but got null"), !1) : typeof t != "boolean" ? (s(`should be a boolean, but got ${typeof t}`), !1) : !0;
|
|
@@ -387,7 +388,7 @@ class N {
|
|
|
387
388
|
})) : (s(`should be a object, but got ${C(t)}`), !1);
|
|
388
389
|
}
|
|
389
390
|
}
|
|
390
|
-
class
|
|
391
|
+
class K {
|
|
391
392
|
constructor(t) {
|
|
392
393
|
o(this, "_val"), o(this, "_locked", !1), o(this, "_opt", !1), o(this, "_null", !1), this._val = t;
|
|
393
394
|
}
|
|
@@ -403,7 +404,7 @@ class z {
|
|
|
403
404
|
return this._locked = !0, this;
|
|
404
405
|
}
|
|
405
406
|
clone() {
|
|
406
|
-
return new
|
|
407
|
+
return new K(this._val);
|
|
407
408
|
}
|
|
408
409
|
validate(t, s = g.warn) {
|
|
409
410
|
return t === void 0 ? this._opt || (s("should be a record, but got undefined"), !1) : t === null ? this._null || (s("should be a record, but got null"), !1) : b(t) ? Object.keys(t).every(
|
|
@@ -413,7 +414,7 @@ class z {
|
|
|
413
414
|
) : (s(`should be a record, but got ${C(t)}`), !1);
|
|
414
415
|
}
|
|
415
416
|
}
|
|
416
|
-
class
|
|
417
|
+
class W {
|
|
417
418
|
constructor(t) {
|
|
418
419
|
o(this, "_val"), o(this, "_min", 0), o(this, "_max", 1 / 0), o(this, "_locked", !1), o(this, "_opt", !1), o(this, "_null", !1), this._val = t;
|
|
419
420
|
}
|
|
@@ -437,7 +438,7 @@ class V {
|
|
|
437
438
|
return this._locked = !0, this;
|
|
438
439
|
}
|
|
439
440
|
clone() {
|
|
440
|
-
const t = new
|
|
441
|
+
const t = new W(this._val);
|
|
441
442
|
return t._min = this._min, t._max = this._max, t._locked = !1, t;
|
|
442
443
|
}
|
|
443
444
|
validate(t, s = g.warn) {
|
|
@@ -448,7 +449,7 @@ class V {
|
|
|
448
449
|
) : (s(`should be a array, but got ${typeof t}`), !1);
|
|
449
450
|
}
|
|
450
451
|
}
|
|
451
|
-
class
|
|
452
|
+
class J {
|
|
452
453
|
constructor(...t) {
|
|
453
454
|
o(this, "_vs"), o(this, "_locked", !1), o(this, "_opt", !1), o(this, "_null", !1), this._vs = t;
|
|
454
455
|
}
|
|
@@ -464,7 +465,7 @@ class W {
|
|
|
464
465
|
return this._locked = !0, this;
|
|
465
466
|
}
|
|
466
467
|
clone() {
|
|
467
|
-
return new
|
|
468
|
+
return new J(...this._vs);
|
|
468
469
|
}
|
|
469
470
|
validate(t, s = g.warn) {
|
|
470
471
|
return t === void 0 ? this._opt || (s("should be a tuple, but got undefined"), !1) : t === null ? this._null || (s("should be a tuple, but got null"), !1) : Array.isArray(t) ? t.length !== this._vs.length ? (s(`should be a tuple with length ${this._vs.length}, but got ${t.length}`), !1) : this._vs.every(
|
|
@@ -474,7 +475,7 @@ class W {
|
|
|
474
475
|
) : (s(`should be a tuple, but got ${typeof t}`), !1);
|
|
475
476
|
}
|
|
476
477
|
}
|
|
477
|
-
class
|
|
478
|
+
class V {
|
|
478
479
|
constructor(...t) {
|
|
479
480
|
o(this, "_vs"), o(this, "_key", ""), o(this, "_locked", !1), o(this, "_opt", !1), o(this, "_null", !1), this._vs = t;
|
|
480
481
|
}
|
|
@@ -505,7 +506,7 @@ class J {
|
|
|
505
506
|
return [...this._vs];
|
|
506
507
|
}
|
|
507
508
|
clone() {
|
|
508
|
-
const t = new
|
|
509
|
+
const t = new V(...this._vs);
|
|
509
510
|
return t._key = this._key, t._locked = !1, t;
|
|
510
511
|
}
|
|
511
512
|
validate(t, s = g.warn) {
|
|
@@ -588,19 +589,19 @@ const jt = {
|
|
|
588
589
|
* 如果需要指定 key 类型,使用 define 辅助工具
|
|
589
590
|
*/
|
|
590
591
|
record(e) {
|
|
591
|
-
return new
|
|
592
|
+
return new K(e);
|
|
592
593
|
},
|
|
593
594
|
/** 数组类型验证 */
|
|
594
595
|
array(e) {
|
|
595
|
-
return new
|
|
596
|
+
return new W(e);
|
|
596
597
|
},
|
|
597
598
|
/** 元组类型验证 */
|
|
598
599
|
tuple(...e) {
|
|
599
|
-
return new
|
|
600
|
+
return new J(...e);
|
|
600
601
|
},
|
|
601
602
|
/** 联合类型验证 */
|
|
602
603
|
union(...e) {
|
|
603
|
-
return new
|
|
604
|
+
return new V(...e);
|
|
604
605
|
},
|
|
605
606
|
/** 字符串类型验证 */
|
|
606
607
|
string() {
|
|
@@ -608,7 +609,7 @@ const jt = {
|
|
|
608
609
|
},
|
|
609
610
|
/** 布尔型类型验证 */
|
|
610
611
|
bool() {
|
|
611
|
-
return new
|
|
612
|
+
return new G();
|
|
612
613
|
},
|
|
613
614
|
/** 数字验证 */
|
|
614
615
|
number() {
|
|
@@ -616,7 +617,7 @@ const jt = {
|
|
|
616
617
|
},
|
|
617
618
|
/** bigint 验证 */
|
|
618
619
|
bigint() {
|
|
619
|
-
return new
|
|
620
|
+
return new z();
|
|
620
621
|
},
|
|
621
622
|
/** 自定义验证 */
|
|
622
623
|
custom: $t,
|
|
@@ -657,14 +658,14 @@ function Ot(e, t = "") {
|
|
|
657
658
|
function et(e) {
|
|
658
659
|
return I(e, !0) ? e.startsWith("http") ? e : ("location" in globalThis ? location.protocol : "https:") + e : ("location" in globalThis ? location.origin : "http://127.0.0.1") + "/" + e.replace(/^\/+/, "");
|
|
659
660
|
}
|
|
660
|
-
function
|
|
661
|
+
function Rt(e, t) {
|
|
661
662
|
const s = {};
|
|
662
663
|
return (e.match(/([^=&#?]+)=[^&#]*/g) || []).forEach(function(r) {
|
|
663
664
|
const n = r.split("="), i = n[0], a = decodeURIComponent(n[1] || "");
|
|
664
665
|
s[i] !== void 0 ? s[i] += "," + a : s[i] = a;
|
|
665
666
|
}), t !== !0 ? s[t] || "" : s;
|
|
666
667
|
}
|
|
667
|
-
function
|
|
668
|
+
function Et(e, t) {
|
|
668
669
|
if (t) {
|
|
669
670
|
if (t === !0)
|
|
670
671
|
return e.replace(/\?[^#]*/, "");
|
|
@@ -672,12 +673,12 @@ function Rt(e, t) {
|
|
|
672
673
|
const s = e.split("#"), r = s[0].split("?"), n = r[0], i = r.length > 1 ? r[1] : "", a = s.length > 1 ? "#" + s[1] : "", h = typeof t == "string" ? [t] : Array.isArray(t) ? t : [];
|
|
673
674
|
return !h.length || !i ? s[0] + a : (h.map((c) => c.replace(/([\\(){}[\]^$+\-*?|])/g, "\\$1")), (n + "?" + i.replace(new RegExp("(?:^|&)(?:" + h.join("|") + ")=[^&$]+", "g"), "").replace(/^&/, "")).replace(/\?$/, "") + a);
|
|
674
675
|
}
|
|
675
|
-
function
|
|
676
|
+
function Zt(e, t, s = !1) {
|
|
676
677
|
const r = typeof t == "string" ? t : Object.keys(t).map((a) => `${a}=${encodeURIComponent(t[a])}`).join("&");
|
|
677
678
|
if (!r)
|
|
678
679
|
return e;
|
|
679
680
|
const n = e.split("#");
|
|
680
|
-
s && (n[0] =
|
|
681
|
+
s && (n[0] = Et(
|
|
681
682
|
n[0],
|
|
682
683
|
(r.match(/([^=&#?]+)=[^&#]+/g) || []).map((a) => a.replace(/=.+$/, ""))
|
|
683
684
|
));
|
|
@@ -695,7 +696,7 @@ class Ft {
|
|
|
695
696
|
this.cache = {}, this.ttl = Math.max(t, 0);
|
|
696
697
|
}
|
|
697
698
|
getKey(t, s) {
|
|
698
|
-
const r = t.replace(/#.+/, ""), n = r.replace(/\?.+/g, ""), i = Object.assign(
|
|
699
|
+
const r = t.replace(/#.+/, ""), n = r.replace(/\?.+/g, ""), i = Object.assign(Rt(r, !0), s), a = At(r), h = Object.keys(i).sort().map((c) => `${c}#${i[c]}`);
|
|
699
700
|
return `${n}_${h.join(",")}_${a.join(",")}`;
|
|
700
701
|
}
|
|
701
702
|
updateTTL(t) {
|
|
@@ -755,11 +756,11 @@ class St {
|
|
|
755
756
|
this.config.messageHandler && s && this.config.messageHandler(t, s, r, n);
|
|
756
757
|
}
|
|
757
758
|
}
|
|
758
|
-
var
|
|
759
|
-
function
|
|
759
|
+
var Z = /* @__PURE__ */ ((e) => (e.UnexpectResponse = "UnexpectResponse", e.Aborted = "Aborted", e.Unknown = "Unknown", e.NetworkError = "NetworkError", e.Timeout = "Timeout", e.NotSupport = "NotSupport", e.URLFormatError = "URLFormatError", e))(Z || {});
|
|
760
|
+
function Ut(e, t, s, r) {
|
|
760
761
|
if (t.ok && !kt(t.data) && r) {
|
|
761
762
|
const n = xt(r, s.get("defaultTypeGuardMessage"));
|
|
762
|
-
return n.guard(t.data) || (t.code =
|
|
763
|
+
return n.guard(t.data) || (t.code = Z.UnexpectResponse, s.showMessage(!0, `${e} ${n.message}`, t.code, t.status), console.error(t.code, e, t.data), t.data = null, t.message = n.message), t;
|
|
763
764
|
}
|
|
764
765
|
return t;
|
|
765
766
|
}
|
|
@@ -780,7 +781,7 @@ class Xt {
|
|
|
780
781
|
return console.error("RequestError", r), {
|
|
781
782
|
ok: !1,
|
|
782
783
|
status: -9,
|
|
783
|
-
code:
|
|
784
|
+
code: Z.Unknown,
|
|
784
785
|
message: r instanceof Error ? `${r.message}
|
|
785
786
|
${r.stack || ""}` : String(r),
|
|
786
787
|
headers: {},
|
|
@@ -792,7 +793,7 @@ ${r.stack || ""}` : String(r),
|
|
|
792
793
|
* 检查响应的数据类型
|
|
793
794
|
*/
|
|
794
795
|
async guard(t, s, r) {
|
|
795
|
-
return
|
|
796
|
+
return Ut(t, s, this.config, r);
|
|
796
797
|
}
|
|
797
798
|
/**
|
|
798
799
|
* 修改默认请求配置: baseURL / timeout / credentials / errorHandler / messageHandler / responseHandler / logHandler / responseRule
|
|
@@ -839,7 +840,7 @@ ${r.stack || ""}` : String(r),
|
|
|
839
840
|
return i.method = "PATCH", i.body = s || {}, this.guard(t, await this.request(t, i), r || null);
|
|
840
841
|
}
|
|
841
842
|
}
|
|
842
|
-
async function
|
|
843
|
+
async function Yt(e, t, s) {
|
|
843
844
|
var w;
|
|
844
845
|
const r = Object.assign({ method: "GET" }, s), n = j.FormData ? r.body instanceof FormData : !1, i = n && r.method !== "POST" && r.method !== "PUT" ? "POST" : r.method, a = i === "GET" || i === "HEAD" || i === "DELETE";
|
|
845
846
|
a && r.body !== void 0 && (console.warn("request body is invalid with method get, head, delete"), delete r.body);
|
|
@@ -850,7 +851,7 @@ async function Zt(e, t, s) {
|
|
|
850
851
|
r.headers
|
|
851
852
|
), c = r.params || {}, m = {};
|
|
852
853
|
Object.keys(c).forEach(($) => {
|
|
853
|
-
c[$] !== void 0 && (m[$] =
|
|
854
|
+
c[$] !== void 0 && (m[$] = Tt(c[$]));
|
|
854
855
|
});
|
|
855
856
|
const f = t.getFullUrl(e), d = Mt(r.body), p = r.timeout || t.get("timeout"), y = await async function() {
|
|
856
857
|
const $ = t.get("requestTransformer");
|
|
@@ -868,19 +869,19 @@ async function Zt(e, t, s) {
|
|
|
868
869
|
credentials: r.credentials || t.get("credentials")
|
|
869
870
|
};
|
|
870
871
|
}
|
|
871
|
-
function
|
|
872
|
+
function Tt(e) {
|
|
872
873
|
return typeof e == "string" ? e : Array.isArray(e) ? e.join(",") : e + "";
|
|
873
874
|
}
|
|
874
875
|
function Mt(e) {
|
|
875
876
|
if (e)
|
|
876
|
-
return typeof e == "string" || j.
|
|
877
|
+
return typeof e == "string" || j.URLSearchParams && e instanceof URLSearchParams || e instanceof ArrayBuffer || j.Blob && e instanceof Blob || j.FormData && e instanceof FormData ? e : JSON.stringify(e);
|
|
877
878
|
}
|
|
878
879
|
const ut = "data", x = "message";
|
|
879
880
|
function Ct(e, t, s, r, n) {
|
|
880
881
|
const i = n || r;
|
|
881
|
-
return X(e) ? qt(i.ok || r.ok, e, t, s) :
|
|
882
|
+
return X(e) ? qt(i.ok || r.ok, e, t, s) : Pt(i.failed || r.failed, t, s);
|
|
882
883
|
}
|
|
883
|
-
const
|
|
884
|
+
const Qt = function(e) {
|
|
884
885
|
const t = [], s = e.failed || { resolve: "json" };
|
|
885
886
|
switch (t.push("- 当http状态码 <200 或者 >=400 时"), s.resolve) {
|
|
886
887
|
case "body":
|
|
@@ -906,7 +907,7 @@ const Yt = function(e) {
|
|
|
906
907
|
return t.join(`
|
|
907
908
|
`);
|
|
908
909
|
};
|
|
909
|
-
function
|
|
910
|
+
function Pt(e, t, s) {
|
|
910
911
|
const r = e || { resolve: "json", messageField: x }, n = {
|
|
911
912
|
ok: !1,
|
|
912
913
|
code: t,
|
|
@@ -918,22 +919,22 @@ function Lt(e, t, s) {
|
|
|
918
919
|
n.message = st(s) || s;
|
|
919
920
|
break;
|
|
920
921
|
case "json":
|
|
921
|
-
const { code: i, message: a } =
|
|
922
|
+
const { code: i, message: a } = Lt(s, r.converter, r.statusField, r.messageField);
|
|
922
923
|
n.code = i || t, n.message = st(s) || a;
|
|
923
924
|
break;
|
|
924
925
|
}
|
|
925
926
|
return n;
|
|
926
927
|
}
|
|
927
|
-
function
|
|
928
|
+
function Lt(e, t, s, r = x) {
|
|
928
929
|
if (!ot(e))
|
|
929
930
|
return { message: "" };
|
|
930
|
-
const n =
|
|
931
|
+
const n = L(M(e), t);
|
|
931
932
|
return !n || !b(n) ? { message: e } : {
|
|
932
|
-
code: s ?
|
|
933
|
-
message:
|
|
933
|
+
code: s ? P(n, s) : "",
|
|
934
|
+
message: P(n, r) || e
|
|
934
935
|
};
|
|
935
936
|
}
|
|
936
|
-
function
|
|
937
|
+
function P(e, t) {
|
|
937
938
|
const s = Array.isArray(t) ? t : [t];
|
|
938
939
|
for (const r of s)
|
|
939
940
|
if (r in e)
|
|
@@ -961,24 +962,24 @@ function qt(e, t, s, r) {
|
|
|
961
962
|
if (t === 204 || !r)
|
|
962
963
|
return i;
|
|
963
964
|
if (n.resolve === "body")
|
|
964
|
-
return i.data = ot(r) ?
|
|
965
|
-
const a =
|
|
965
|
+
return i.data = ot(r) ? L(M(r), e.converter) : r, i;
|
|
966
|
+
const a = L(M(r), e.converter);
|
|
966
967
|
if (!a || !b(a))
|
|
967
968
|
return i.ok = !1, i.code = "ResponseFormatError", i.message = "响应内容无法格式化为 Object", i;
|
|
968
969
|
const h = n.statusField, c = n.statusOKValue || "", m = n.dataField || ut, f = n.messageField || x, d = n.ignoreMessage || "";
|
|
969
970
|
if (h && !(h in a))
|
|
970
971
|
return i.ok = !1, i.code = "ResponseFieldMissing", i.message = "响应内容找不到状态字段 " + h, i;
|
|
971
972
|
const p = h ? a[h] + "" : "";
|
|
972
|
-
return i.ok = h ? p === c : !0, i.code = p || s, i.data = m === !0 ? a : m in a ? a[m] : null, i.message =
|
|
973
|
+
return i.ok = h ? p === c : !0, i.code = p || s, i.data = m === !0 ? a : m in a ? a[m] : null, i.message = P(a, f), d && i.message && (Array.isArray(d) && d.includes(i.message) || typeof d == "string" && i.message === d) && (i.message = ""), i;
|
|
973
974
|
}
|
|
974
975
|
function X(e) {
|
|
975
976
|
return e >= 200 && e < 400;
|
|
976
977
|
}
|
|
977
|
-
function
|
|
978
|
+
function L(e, t) {
|
|
978
979
|
return t === "camelize" ? A(e) : t === "snakify" ? F(e) : e;
|
|
979
980
|
}
|
|
980
981
|
const Ht = mt("APIError");
|
|
981
|
-
function
|
|
982
|
+
function zt(e) {
|
|
982
983
|
const t = {};
|
|
983
984
|
for (const n in e.headers)
|
|
984
985
|
(n.startsWith("x-") || n.includes("trace") || n.includes("server") || /\b(?:id|uuid)\b/.test(n)) && (t[n] = e.headers[n]);
|
|
@@ -1000,7 +1001,7 @@ function Gt(e) {
|
|
|
1000
1001
|
}
|
|
1001
1002
|
};
|
|
1002
1003
|
}
|
|
1003
|
-
function
|
|
1004
|
+
function Gt(e) {
|
|
1004
1005
|
return e.reduce(
|
|
1005
1006
|
(t, [s, r]) => (s && (t[s] = r || ""), t),
|
|
1006
1007
|
{}
|
|
@@ -1008,7 +1009,7 @@ function Kt(e) {
|
|
|
1008
1009
|
}
|
|
1009
1010
|
function te(e, t, s, r) {
|
|
1010
1011
|
var y;
|
|
1011
|
-
const n = e.status, i = e.method, a =
|
|
1012
|
+
const n = e.status, i = e.method, a = Gt(
|
|
1012
1013
|
Object.entries(e.headers || {}).map(([k, w]) => [k.toLowerCase(), w])
|
|
1013
1014
|
), { ok: h, code: c, data: m, message: f } = Ct(
|
|
1014
1015
|
n,
|
|
@@ -1018,7 +1019,7 @@ function te(e, t, s, r) {
|
|
|
1018
1019
|
r == null ? void 0 : r.responseRule
|
|
1019
1020
|
);
|
|
1020
1021
|
if (!X(n)) {
|
|
1021
|
-
const k =
|
|
1022
|
+
const k = zt({
|
|
1022
1023
|
url: e.url,
|
|
1023
1024
|
method: e.method,
|
|
1024
1025
|
status: n,
|
|
@@ -1028,7 +1029,7 @@ function te(e, t, s, r) {
|
|
|
1028
1029
|
headers: a,
|
|
1029
1030
|
error: e.rawError
|
|
1030
1031
|
});
|
|
1031
|
-
(s.get("errorHandler") ||
|
|
1032
|
+
(s.get("errorHandler") || Kt)({
|
|
1032
1033
|
url: t,
|
|
1033
1034
|
method: i,
|
|
1034
1035
|
status: n,
|
|
@@ -1062,13 +1063,13 @@ function rt(e, t, s, r, n, i) {
|
|
|
1062
1063
|
}
|
|
1063
1064
|
return e;
|
|
1064
1065
|
}
|
|
1065
|
-
function
|
|
1066
|
+
function Kt(e) {
|
|
1066
1067
|
const t = {};
|
|
1067
1068
|
for (const s in e)
|
|
1068
1069
|
s.startsWith("sentry") || (t[s] = e[s]);
|
|
1069
1070
|
console.error("RequestError", t);
|
|
1070
1071
|
}
|
|
1071
|
-
async function
|
|
1072
|
+
async function Wt(e, t, s, r, n) {
|
|
1072
1073
|
const i = n || 0, a = Math.max(0, Math.min(10, (r == null ? void 0 : r.maxRetry) ?? s.get("maxRetry") ?? 0)), h = (r == null ? void 0 : r.retryResolve) ?? s.get("retryResolve"), c = s.get("logHandler") || D;
|
|
1073
1074
|
c({
|
|
1074
1075
|
type: "prepare",
|
|
@@ -1101,19 +1102,19 @@ async function Vt(e, t, s, r, n) {
|
|
|
1101
1102
|
100,
|
|
1102
1103
|
w === "2EB" ? Math.pow(2, i) * 100 : typeof w == "function" ? w(i + 1) || 0 : w
|
|
1103
1104
|
)
|
|
1104
|
-
), await
|
|
1105
|
+
), await Wt(e, t, s, r, i + 1);
|
|
1105
1106
|
}
|
|
1106
1107
|
export {
|
|
1107
|
-
I as
|
|
1108
|
+
I as A,
|
|
1108
1109
|
Xt as N,
|
|
1109
|
-
j as O,
|
|
1110
|
-
Jt as Q,
|
|
1111
1110
|
St as R,
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1111
|
+
Z as a,
|
|
1112
|
+
Vt as b,
|
|
1113
|
+
Yt as c,
|
|
1114
|
+
Qt as d,
|
|
1115
|
+
Gt as f,
|
|
1116
|
+
Zt as g,
|
|
1116
1117
|
te as h,
|
|
1117
|
-
|
|
1118
|
-
|
|
1118
|
+
j,
|
|
1119
|
+
Wt as r
|
|
1119
1120
|
};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
"use strict";var dt=Object.defineProperty;var _t=(e,t,s)=>t in e?dt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[t]=s;var v=(e,t,s)=>_t(e,typeof t!="symbol"?t+"":t,s);var mt=Object.defineProperty,gt=(e,t,s)=>t in e?mt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[t]=s,o=(e,t,s)=>gt(e,typeof t!="symbol"?t+"":t,s);const u=typeof globalThis<"u"?globalThis:typeof self<"u"?self:typeof window<"u"?window:Function("return this")(),j={wx:"wx"in u&&O(u.wx)&&"getSystemInfo"in u.wx&&_(u.wx.getSystemInfo),fetch:"fetch"in u&&_(u.fetch),window:"window"in u&&O(u.window),requestAnimationFrame:"requestAnimationFrame"in u&&_(u.requestAnimationFrame),localStorage:"localStorage"in u&&O(u.localStorage)&&"getItem"in u.localStorage&&_(u.localStorage.getItem),sessionStorage:"sessionStorage"in u&&O(u.sessionStorage)&&"getItem"in u.sessionStorage&&_(u.sessionStorage.getItem),File:"File"in u&&_(u.File),Blob:"Blob"in u&&_(u.Blob),Proxy:"Proxy"in u&&_(u.Proxy),Request:"Request"in u&&_(u.Request),FormData:"FormData"in u&&_(u.FormData),TextDecoder:"TextDecoder"in u&&_(u.TextDecoder),ResizeObserver:"ResizeObserver"in u&&_(u.ResizeObserver),AbortController:"AbortController"in u&&_(u.AbortController),URLSearchParams:"URLSearchParams"in u&&_(u.URLSearchParams)};function _(e){return typeof e=="function"}function O(e){return typeof e=="object"&&e!==null}function pt(e){return new Promise(t=>setTimeout(t,Math.max(0,e)))}function q(){}function nt(e,t){const s={log:console.log.bind(console),error:console.error.bind(console),warn:console.warn.bind(console)},r=`[${e}]`;return["log","error","warn"].forEach(n=>{const i=console[n];s[n]=(...a)=>{i.apply(console,[r,...a])}}),s}function bt(e){const t=e||"CustomError";return class extends Error{constructor(s){super(s),Object.defineProperty(this,"name",{value:t,enumerable:!1,configurable:!0}),"setPrototypeOf"in Object&&Object.setPrototypeOf(this,new.target.prototype),"captureStackTrace"in Error&&typeof Error.captureStackTrace=="function"&&Error.captureStackTrace(this,this.constructor)}}}const yt=/^(?:https?:)?\/\/.+$/i,wt=/^https?:\/\/.+$/i,kt=/^\{[\d\D]*\}$/,vt=/^\[[\d\D]*\]$/;function $t(e){return typeof e=="string"}function U(e,t=!1){return t?yt.test(e):wt.test(e)}function jt(e){return e==null}function it(e,...t){return e!==null&&typeof e=="object"&&!(e instanceof Map)&&!(e instanceof Set)&&!(e instanceof WeakMap)&&!(e instanceof WeakSet)&&!Array.isArray(e)&&t.every(s=>s in e)}function b(e,...t){if(!e||typeof e!="object")return!1;const s=Object.getPrototypeOf(e);return s!==Object.prototype&&s!==null?!1:t.every(r=>r in e)}function B(e,t){return Array.isArray(e)&&e.every(s=>t(s))}function C(e){if(typeof e!="number"||Number.isNaN(e)||!Number.isFinite(e)||Number.isInteger(e)&&!Number.isSafeInteger(e))return!1;if(e===0)return!0;const t=Math.abs(e);return t>=Number.EPSILON&&t<=Number.MAX_SAFE_INTEGER}function ot(e){return kt.test(e)||vt.test(e)}function Rt(e,t=20){const s=Math.max(t,10),r=[...e];return r.length<=s?e:r.slice(0,s-3).join("")+"..."}function E(e){return e?e[0].toLowerCase()+e.slice(1):""}const at=/_\w*/,lt=/-\w*/;function Y(e){const t=at.test(e)?e.replace(/(?:^_*|_*$)/g,"").replace(/_+([^_])/g,(s,r)=>r.toUpperCase()):lt.test(e)?e.replace(/(?:^-*|-*$)/g,"").replace(/-+(\w)/g,(s,r)=>r.toUpperCase()):e;return E(t)}function Q(e){return at.test(e)?E(e).replace(/(?:^_*|_*$)/g,"").replace(/_+([^_])/g,(t,s)=>"_"+s.toLowerCase()):lt.test(e)?E(e.replace(/(?:^-*|-*$)/g,"")).replace(/-+(\w)/g,(t,s)=>"_"+s.toLowerCase()):E(e).replace(/[A-Z]/g,t=>`_${t.toLowerCase()}`)}function P(e,t){try{const s=JSON.parse(e);return t?t(s)?s:null:s}catch{return null}}""+Math.random().toString(32).slice(2);function A(e,t=!1){return typeof e=="string"?Y(e):Array.isArray(e)?e.map(s=>!t||typeof s=="string"?A(s):typeof s=="object"&&s?A(s,!0):s):b(e)?Object.keys(e).reduce((s,r)=>{const n=Y(String(r)),i=n.charAt(0).toLowerCase()+n.slice(1);return s[i]=t?e[r]:A(e[r]),s},{}):e}function F(e,t=!1){return typeof e=="string"?Q(e):Array.isArray(e)?e.map(s=>!t||typeof s=="string"?F(s):typeof s=="object"&&s?F(s,t):s):b(e)?Object.keys(e).reduce((s,r)=>{const n=Q(String(r));return s[n]=t?e[r]:F(e[r]),s},{}):e}nt("LoadUtils");async function Nt(e){return await new Promise(function(t){const s=document.getElementsByTagName("head")[0],r=document.createElement("script");r.setAttribute("type","text/javascript"),r.setAttribute("charset","utf-8"),r.onload=function(){s.removeChild(r),t(!0)},r.onerror=function(){s.removeChild(r),t(!1)},r.setAttribute("src",e),s.appendChild(r)})}function tt(e){return Object.getOwnPropertyNames(e).forEach(function(t){delete e[t]}),e}const g=nt("Validator");function x(e){return e?`"${Rt(e).replace(/"/g,'\\"')}"`:"empty string"}function L(e){return typeof e=="object"&&e&&"constructor"in e&&typeof e.constructor=="function"?e.constructor.name||"ClassInstance":Object.prototype.toString.call(e).replace(/(?:.+ |]$)/g,"")}function M(e){return typeof e=="bigint"}function l(e){return new Error(`${e?`${e}()`:"method"} is not allowed after locked`)}class H{constructor(){o(this,"_ps",{}),o(this,"_allow",[]),o(this,"_reject",[]),o(this,"_locked",!1),o(this,"_opt",!1),o(this,"_null",!1)}pattern(t,s){if(this._locked)throw l("pattern");return this._ps[`#${t||"custom"}`]=s,this}url(t=!1){if(this._locked)throw l("url");return this._ps.url=t?/^(?:https?:)?\/\/.+$/i:/^https?:\/\/.+$/i,this}dataUri(){if(this._locked)throw l("dataUri");return this._ps.dataUri=/^data:[a-z]+\/[a-z]+;base64,[\w+/=]+$/,this}enum(...t){if(this._locked)throw l("enum");const s=t[0];return B(t,$t)?(this._allow=t,tt(this._ps)):b(s)&&(this._allow=Object.values(s).map(r=>`${r}`),tt(this._ps)),this}disallow(...t){return this._reject.push(...t),this}optional(){if(this._locked)throw l("optional");return this._opt=!0,this}maybeNull(){if(this._locked)throw l("maybeNull");return this._null=!0,this}lock(){return this._locked=!0,this}clone(){const t=new H;return t._ps={...this._ps},t._allow=[...this._allow],t._reject=[...this._reject],t._locked=!1,t}validate(t,s=g.warn){if(t===void 0)return this._opt||(s("should be a string, but got undefined"),!1);if(t===null)return this._null||(s("should be a string, but got null"),!1);if(typeof t!="string")return s(`should be a string, but got ${typeof t}`),!1;if(this._allow.length>0)return this._allow.includes(t)||(s(`${x(t)} is not allowed, just support ${this._allow.map(x).join(", ")}`),!1);if(this._reject.length>0&&this._reject.some(n=>typeof n=="string"?n===t:n.test(t)))return s(`${x(t)} is not allowed`),!1;const r=Object.keys(this._ps);return r.length>0&&!r.some(n=>{const i=this._ps[n];return i instanceof RegExp?i.test(t):i(t)})?(s(`${x(t)} is not match pattern ${r.join(" | ")}`),!1):!0}}class G{constructor(){o(this,"_int",!1),o(this,"_min",-1/0),o(this,"_max",1/0),o(this,"_allow",[]),o(this,"_reject",[]),o(this,"_infinite",!1),o(this,"_unsafe",!1),o(this,"_nan",!1),o(this,"_locked",!1),o(this,"_opt",!1),o(this,"_null",!1)}int(){if(this._locked)throw l("int");return this._int=!0,this}min(t){if(this._locked)throw l("min");return Number.isNaN(t)||(this._min=t),this}max(t){if(this._locked)throw l("max");return Number.isNaN(t)||(this._max=t),this}allowNaN(){if(this._locked)throw l("allowNaN");return this._nan=!0,this}allowInfinity(){if(this._locked)throw l("allowInfinity");return this._infinite=!0,this._unsafe=!0,this}unsafe(){if(this._locked)throw l("unsafe");return this._unsafe=!0,this}enum(...t){if(this._locked)throw l("enum");const s=t[0];return B(t,C)?(this._allow=t,this._reject=[]):b(s)&&(this._allow=Object.values(s).map(r=>C(r)?r:null).filter(r=>r!==null),this._reject=[]),this}disallow(...t){if(this._locked)throw l("disallow");return this._reject.push(...t),this}optional(){if(this._locked)throw l("optional");return this._opt=!0,this}maybeNull(){if(this._locked)throw l("maybeNull");return this._null=!0,this}lock(){return this._locked=!0,this}clone(){const t=new G;return t._int=this._int,t._min=this._min,t._max=this._max,t._allow=[...this._allow],t._reject=[...this._reject],t._infinite=this._infinite,t._unsafe=this._unsafe,t._nan=this._nan,t._locked=!1,t}validate(t,s=g.warn){return t===void 0?this._opt||(s("should be a number, but got undefined"),!1):t===null?this._null||(s("should be a number, but got null"),!1):typeof t!="number"?(s(`should be a number, but got ${typeof t}`),!1):Number.isNaN(t)?this._nan||(s("should be a number, but got NaN"),!1):!Number.isFinite(t)&&!this._infinite?(s("should be a number, but got Infinity"),!1):this._allow.length>0?this._allow.includes(t)||(s(`${t} is not allowed, just support ${this._allow.join(", ")}`),!1):this._reject.length>0&&this._reject.includes(t)?(s(`${t} is not allowed`),!1):this._int&&Math.ceil(t)!==t?(s(`${t} is not an integer`),!1):!C(t)&&!this._unsafe?(s(`${t} is not a safe number`),!1):t>=this._min&&t<=this._max||(s(`${t} is not in range [${this._min}, ${this._max}]`),!1)}}class z{constructor(){o(this,"_min",null),o(this,"_max",null),o(this,"_allow",[]),o(this,"_reject",[]),o(this,"_locked",!1),o(this,"_opt",!1),o(this,"_null",!1)}min(t){if(this._locked)throw l("min");return this._min=t,this}max(t){if(this._locked)throw l("max");return this._max=t,this}enum(...t){if(this._locked)throw l("enum");const s=t[0];return B(t,M)?(this._allow=t,this._reject=[]):b(s)&&(this._allow=Object.values(s).map(r=>M(r)?r:null).filter(r=>r!==null),this._reject=[]),this}disallow(...t){if(this._locked)throw l("disallow");return this._reject.push(...t),this}optional(){if(this._locked)throw l("optional");return this._opt=!0,this}maybeNull(){if(this._locked)throw l("maybeNull");return this._null=!0,this}lock(){return this._locked=!0,this}clone(){const t=new z;return t._min=this._min,t._max=this._max,t._allow=[...this._allow],t._reject=[...this._reject],t._locked=!1,t}validate(t,s=g.warn){return t===void 0?this._opt||(s("should be a bigint, but got undefined"),!1):t===null?this._null||(s("should be a bigint, but got null"),!1):M(t)?this._allow.length>0?this._allow.includes(t)||(s(`${t} is not allowed, just support ${this._allow.join(", ")}`),!1):this._reject.length>0&&this._reject.includes(t)?(s(`${t} is not allowed`),!1):(this._min!==null?t>=this._min:!0)&&(this._max!==null?t<=this._max:!0)||(s(`${t} 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 t}`),!1)}}class K{constructor(){o(this,"_locked",!1),o(this,"_opt",!1),o(this,"_null",!1)}optional(){if(this._locked)throw l("optional");return this._opt=!0,this}maybeNull(){if(this._locked)throw l("maybeNull");return this._null=!0,this}lock(){return this._locked=!0,this}clone(){return new K}validate(t,s=g.warn){return t===void 0?this._opt||(s("should be a boolean, but got undefined"),!1):t===null?this._null||(s("should be a boolean, but got null"),!1):typeof t!="boolean"?(s(`should be a boolean, but got ${typeof t}`),!1):!0}}class R{constructor(t){o(this,"_shape"),o(this,"_plain",!1),o(this,"_locked",!1),o(this,"_opt",!1),o(this,"_null",!1),this._shape=t}plain(){if(this._locked)throw l("plain");return this._plain=!0,this}optional(){if(this._locked)throw l("optional");return this._opt=!0,this}maybeNull(){if(this._locked)throw l("maybeNull");return this._null=!0,this}lock(){return this._locked=!0,this}get shape(){return{...this._shape}}clone(){const t=new R(this._shape);return t._plain=this._plain,t._locked=!1,t}match(t,s){return t in this._shape?this._shape[t].validate(s,q):!1}validate(t,s=g.warn){return t===void 0?this._opt||(s("should be a object, but got undefined"),!1):t===null?this._null||(s("should be a object, but got null"),!1):it(t)?this._plain&&!b(t)?(s(`should be a plain object, but got ${L(t)}`),!1):Object.keys(this._shape).every(r=>this._shape[r].validate(t[r],(...n)=>{s(`[.${String(r)}]`,...n)})):(s(`should be a object, but got ${L(t)}`),!1)}}class W{constructor(t){o(this,"_val"),o(this,"_locked",!1),o(this,"_opt",!1),o(this,"_null",!1),this._val=t}optional(){if(this._locked)throw l("optional");return this._opt=!0,this}maybeNull(){if(this._locked)throw l("maybeNull");return this._null=!0,this}lock(){return this._locked=!0,this}clone(){return new W(this._val)}validate(t,s=g.warn){return t===void 0?this._opt||(s("should be a record, but got undefined"),!1):t===null?this._null||(s("should be a record, but got null"),!1):b(t)?Object.keys(t).every(r=>this._val.validate(t[r],(...n)=>{s(`[:${r}]`,...n)})):(s(`should be a record, but got ${L(t)}`),!1)}}class J{constructor(t){o(this,"_val"),o(this,"_min",0),o(this,"_max",1/0),o(this,"_locked",!1),o(this,"_opt",!1),o(this,"_null",!1),this._val=t}min(t){if(this._locked)throw l("min");return this._min=t,this}max(t){if(this._locked)throw l("max");return this._max=t,this}optional(){if(this._locked)throw l("optional");return this._opt=!0,this}maybeNull(){if(this._locked)throw l("maybeNull");return this._null=!0,this}lock(){return this._locked=!0,this}clone(){const t=new J(this._val);return t._min=this._min,t._max=this._max,t._locked=!1,t}validate(t,s=g.warn){return t===void 0?this._opt||(s("should be a array, but got undefined"),!1):t===null?this._null||(s("should be a array, but got null"),!1):Array.isArray(t)?t.length<this._min||t.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):t.every((r,n)=>this._val.validate(r,(...i)=>{s(`[${n}]`,...i)})):(s(`should be a array, but got ${typeof t}`),!1)}}class V{constructor(...t){o(this,"_vs"),o(this,"_locked",!1),o(this,"_opt",!1),o(this,"_null",!1),this._vs=t}optional(){if(this._locked)throw l("optional");return this._opt=!0,this}maybeNull(){if(this._locked)throw l("maybeNull");return this._null=!0,this}lock(){return this._locked=!0,this}clone(){return new V(...this._vs)}validate(t,s=g.warn){return t===void 0?this._opt||(s("should be a tuple, but got undefined"),!1):t===null?this._null||(s("should be a tuple, but got null"),!1):Array.isArray(t)?t.length!==this._vs.length?(s(`should be a tuple with length ${this._vs.length}, but got ${t.length}`),!1):this._vs.every((r,n)=>r.validate(t[n],(...i)=>{s(`[idx:${n}]`,...i)})):(s(`should be a tuple, but got ${typeof t}`),!1)}}class Z{constructor(...t){o(this,"_vs"),o(this,"_key",""),o(this,"_locked",!1),o(this,"_opt",!1),o(this,"_null",!1),this._vs=t}optional(){if(this._locked)throw l("optional");return this._opt=!0,this}maybeNull(){if(this._locked)throw l("maybeNull");return this._null=!0,this}key(t){if(this._locked)throw l("key");return this._vs.every(s=>s instanceof R)?this._key=t: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 t=new Z(...this._vs);return t._key=this._key,t._locked=!1,t}validate(t,s=g.warn){if(t===void 0)return this._opt||(s("should be a union, but got undefined"),!1);if(t===null)return this._null||(s("should be a union, but got null"),!1);if(this._key&&it(t)&&t){const n=t[this._key];if(n===void 0)return s(`key field "${this._key}" is not found`,t),!1;const i=this._vs.find(a=>a instanceof R&&a.match(this._key,n));return i?i.validate(t,s):(s(`key field "${this._key}" value is match union definition`,n),!1)}const r=this._vs.some(n=>n.validate(t,q));return r||s("value is not match union definition",t),r}}class S{constructor(t,s){o(this,"_name",""),o(this,"_guard"),o(this,"_locked",!1),o(this,"_opt",!1),o(this,"_null",!1),this._name=t,this._guard=s}optional(){if(this._locked)throw l("optional");return this._opt=!0,this}maybeNull(){if(this._locked)throw l("maybeNull");return this._null=!0,this}lock(){return this._locked=!0,this}clone(){return new S(this._name,this._guard)}validate(t,s=g.warn){const r=this._name||"custom type";return t===void 0?this._opt||(s(`should be ${r}, but got undefined`),!1):t===null?this._null||(s(`should be ${r}, but got null`),!1):this._guard(t)||(s(`custom validation${this._name?`(${this._name})`:""} failed`),!1)}}function Ot(e,t){if(typeof e=="string"){if(!t)throw new Error("custom type guard must be defined");return new S(e,t)}return new S("",e)}const xt={shape(e){return e},define(e){return e},guard(e){return function(t){return e.validate(t)}},object(e){return new R(e)},record(e){return new W(e)},array(e){return new J(e)},tuple(...e){return new V(...e)},union(...e){return new Z(...e)},string(){return new H},bool(){return new K},number(){return new G},bigint(){return new z},custom:Ot,unknown(){return{validate(e){return!0}}},never(){return{validate(e){return!1}}}},Et=e=>b(e)&&Object.keys(e).length===0;xt.custom("EmptyObject",Et);function At(e,t="数据未能正确识别"){return typeof e=="function"?{guard:e,message:t}:{guard:e.guard,message:e.message||t}}function Ft(e,t=""){return!t||U(e,!0)?et(e):(et(t)+"/"+e).replace(/\/{2,}/g,"/").replace(/:\//,"://")}function et(e){return U(e,!0)?e.startsWith("http")?e:("location"in globalThis?location.protocol:"https:")+e:("location"in globalThis?location.origin:"http://127.0.0.1")+"/"+e.replace(/^\/+/,"")}function St(e,t){const s={};return(e.match(/([^=&#?]+)=[^&#]*/g)||[]).forEach(function(r){const n=r.split("="),i=n[0],a=decodeURIComponent(n[1]||"");s[i]!==void 0?s[i]+=","+a:s[i]=a}),t!==!0?s[t]||"":s}function Ut(e,t){if(t){if(t===!0)return e.replace(/\?[^#]*/,"")}else return e;const s=e.split("#"),r=s[0].split("?"),n=r[0],i=r.length>1?r[1]:"",a=s.length>1?"#"+s[1]:"",h=typeof t=="string"?[t]:Array.isArray(t)?t:[];return!h.length||!i?s[0]+a:(h.map(c=>c.replace(/([\\(){}[\]^$+\-*?|])/g,"\\$1")),(n+"?"+i.replace(new RegExp("(?:^|&)(?:"+h.join("|")+")=[^&$]+","g"),"").replace(/^&/,"")).replace(/\?$/,"")+a)}function Tt(e,t,s=!1){const r=typeof t=="string"?t:Object.keys(t).map(a=>`${a}=${encodeURIComponent(t[a])}`).join("&");if(!r)return e;const n=e.split("#");s&&(n[0]=Ut(n[0],(r.match(/([^=&#?]+)=[^&#]+/g)||[]).map(a=>a.replace(/=.+$/,""))));const i=n[0].indexOf("?")+1?"&":"?";return(n[0]+i+r+(n.length>1?"#"+n[1]:"")).replace(/\?&/,"?")}function Ct(e){const t=e.match(/(?:\?|&)([^=]+)(?:&|$)/g);return t?t.join("").replace(/(?:\?|^&+|&+$)/g,"").replace(/&{2}/g,"&").split("&").sort():[]}class Mt{constructor(t=500){v(this,"ttl");v(this,"cache");this.cache={},this.ttl=Math.max(t,0)}getKey(t,s){const r=t.replace(/#.+/,""),n=r.replace(/\?.+/g,""),i=Object.assign(St(r,!0),s),a=Ct(r),h=Object.keys(i).sort().map(c=>`${c}#${i[c]}`);return`${n}_${h.join(",")}_${a.join(",")}`}updateTTL(t){this.ttl=Math.max(t,0)}get(t){if(this.ttl===0)return null;const s=this.cache[t];return s?s.ttl<Date.now()?(delete this.cache[t],null):s.res:null}set(t,s){this.ttl!==0&&(this.cache[t]={ttl:Date.now()+this.ttl,res:s})}}class ut{constructor(t){v(this,"config",{baseURL:"/",maxRetry:0,retryInterval:100,retryResolve:"network",timeout:1e4,cacheTTL:500,credentials:"same-origin",defaultTypeGuardMessage:"响应数据未能正确识别",responseRule:{ok:{resolve:"body"},failed:{resolve:"json",messageField:"message"}}});t&&this.set(t)}set(t){if(t.baseURL&&!/^\/.+/.test(t.baseURL)&&!U(t.baseURL))throw console.warn("baseURL 需要以 / 开头,或者是完整的 url 地址"),new Error("BaseURLError");Object.assign(this.config,t)}get(t){return this.config[t]}getFullUrl(t){return Ft(t,this.config.baseURL)}showMessage(t,s,r,n){this.config.messageHandler&&s&&this.config.messageHandler(t,s,r,n)}}var T=(e=>(e.UnexpectResponse="UnexpectResponse",e.Aborted="Aborted",e.Unknown="Unknown",e.NetworkError="NetworkError",e.Timeout="Timeout",e.NotSupport="NotSupport",e.URLFormatError="URLFormatError",e))(T||{});function Pt(e,t,s,r){if(t.ok&&!jt(t.data)&&r){const n=At(r,s.get("defaultTypeGuardMessage"));return n.guard(t.data)||(t.code=T.UnexpectResponse,s.showMessage(!0,`${e} ${n.message}`,t.code,t.status),console.error(t.code,e,t.data),t.data=null,t.message=n.message),t}return t}class Lt{constructor(t,s){v(this,"agent");v(this,"config");v(this,"cache");this.config=new ut(s),this.agent=t,this.cache=new Mt(this.config.get("cacheTTL")),this.setConfig=this.setConfig.bind(this),this.getConfig=this.getConfig.bind(this),this.request=this.request.bind(this),this.get=this.get.bind(this),this.post=this.post.bind(this),this.del=this.del.bind(this),this.patch=this.patch.bind(this),this.put=this.put.bind(this),this.head=this.head.bind(this)}async request(t,s){try{return await this.agent(t,this.config,s)}catch(r){return console.error("RequestError",r),{ok:!1,status:-9,code:T.Unknown,message:r instanceof Error?`${r.message}
|
|
2
|
+
${r.stack||""}`:String(r),headers:{},data:null}}}async guard(t,s,r){return Pt(t,s,this.config,r)}setConfig(t){this.config.set(t),this.cache.updateTTL(this.config.get("cacheTTL"))}getConfig(t){return this.config.get(t)}async head(t,s){const r=Object.assign({},s||null);return r.method="HEAD",this.guard(t,await this.request(t,r),null)}async get(t,s,r){const n=Object.assign({},r||null);n.method="GET";const i=this.cache.getKey(t,n.params),a=this.cache.get(i);if(a)return this.guard(t,await a,s||null);const h=this.request(t,n);return this.cache.set(i,h),this.guard(t,await h,s||null)}async post(t,s,r,n){const i=Object.assign({},n||null);return i.method="POST",i.body=s||{},this.guard(t,await this.request(t,i),r||null)}async del(t,s,r){const n=Object.assign({},r||null);return n.method="DELETE",this.guard(t,await this.request(t,n),s||null)}async put(t,s,r,n){const i=Object.assign({},n||null);return i.method="PUT",i.body=s||{},this.guard(t,await this.request(t,i),r||null)}async patch(t,s,r,n){const i=Object.assign({},n||null);return i.method="PATCH",i.body=s||{},this.guard(t,await this.request(t,i),r||null)}}async function Dt(e,t,s){var w;const r=Object.assign({method:"GET"},s),n=j.FormData?r.body instanceof FormData:!1,i=n&&r.method!=="POST"&&r.method!=="PUT"?"POST":r.method,a=i==="GET"||i==="HEAD"||i==="DELETE";a&&r.body!==void 0&&(console.warn("request body is invalid with method get, head, delete"),delete r.body);const h=Object.assign(n||a?{}:{"Content-Type":j.Blob&&r.body instanceof Blob?r.body.type||"application/octet-stream":"application/json;charset=utf-8"},r.headers),c=r.params||{},m={};Object.keys(c).forEach($=>{c[$]!==void 0&&(m[$]=It(c[$]))});const f=t.getFullUrl(e),d=qt(r.body),p=r.timeout||t.get("timeout"),y=await async function(){const $=t.get("requestTransformer");if($)return await $({headers:h,params:m,method:i,url:f,body:d})}(),k=typeof y=="string"&&y?y:f;return(w=t.get("logHandler"))==null||w({type:"ready",url:k,method:i,headers:h,timeout:p,body:d}),{url:k,method:i,body:d,params:m,headers:h,timeout:p,abort:r.abort,credentials:r.credentials||t.get("credentials")}}function It(e){return typeof e=="string"?e:Array.isArray(e)?e.join(","):e+""}function qt(e){if(e)return typeof e=="string"||j.URLSearchParams&&e instanceof URLSearchParams||e instanceof ArrayBuffer||j.Blob&&e instanceof Blob||j.FormData&&e instanceof FormData?e:JSON.stringify(e)}const ht="data",N="message";function Bt(e,t,s,r,n){const i=n||r;return X(e)?Vt(i.ok||r.ok,e,t,s):Gt(i.failed||r.failed,t,s)}const Ht=function(e){const t=[],s=e.failed||{resolve:"json"};switch(t.push("- 当http状态码 <200 或者 >=400 时"),s.resolve){case"body":t.push(" 将响应内容格式化为字符串并作为错误消息");break;case"json":t.push(" 将响应解析为json,并读取 "+(s.messageField||N)+" 作为错误消息");break}const r=e.ok||{resolve:"body"};switch(t.push("- 当http状态码 >=200 并且 <400 时"),r.resolve){case"body":t.push(" 将响应尝试解析为 json,并作为数据内容返回");break;case"json":t.push(" 将响应解析为 json,读取 "+(r.dataField||ht)+" 作为响应数据,读取 "+(r.messageField||N)+" 作为提示消息"),r.statusField&&t.push(" 当 "+r.statusField+" 为 "+(r.statusOKValue||"空值")+" 时是成功提示,否则是错误消息"),r.ignoreMessage&&t.push(" 并忽略以下消息:"+r.ignoreMessage);break}return t.join(`
|
|
3
|
+
`)};function Gt(e,t,s){const r=e||{resolve:"json",messageField:N},n={ok:!1,code:t,message:s,data:null};switch(r.resolve){case"body":n.message=st(s)||s;break;case"json":const{code:i,message:a}=zt(s,r.converter,r.statusField,r.messageField);n.code=i||t,n.message=st(s)||a;break}return n}function zt(e,t,s,r=N){if(!ot(e))return{message:""};const n=I(P(e),t);return!n||!b(n)?{message:e}:{code:s?D(n,s):"",message:D(n,r)||e}}function D(e,t){const s=Array.isArray(t)?t:[t];for(const r of s)if(r in e)return Kt(e[r]);return""}function Kt(e){return e?typeof e=="string"?e:JSON.stringify(e):""}const Wt=/<title>([^<]+)<\/title>/i,Jt=/<message>([^<]+)<\/message>/i;function st(e){const t=e.match(Wt);if(t)return t[1];const s=e.match(Jt);return s?s[1]:""}function Vt(e,t,s,r){const n=e||{resolve:"body"},i={ok:!0,code:s,message:"",data:null};if(t===204||!r)return i;if(n.resolve==="body")return i.data=ot(r)?I(P(r),e.converter):r,i;const a=I(P(r),e.converter);if(!a||!b(a))return i.ok=!1,i.code="ResponseFormatError",i.message="响应内容无法格式化为 Object",i;const h=n.statusField,c=n.statusOKValue||"",m=n.dataField||ht,f=n.messageField||N,d=n.ignoreMessage||"";if(h&&!(h in a))return i.ok=!1,i.code="ResponseFieldMissing",i.message="响应内容找不到状态字段 "+h,i;const p=h?a[h]+"":"";return i.ok=h?p===c:!0,i.code=p||s,i.data=m===!0?a:m in a?a[m]:null,i.message=D(a,f),d&&i.message&&(Array.isArray(d)&&d.includes(i.message)||typeof d=="string"&&i.message===d)&&(i.message=""),i}function X(e){return e>=200&&e<400}function I(e,t){return t==="camelize"?A(e):t==="snakify"?F(e):e}const Zt=bt("APIError");function Xt(e){const t={};for(const n in e.headers)(n.startsWith("x-")||n.includes("trace")||n.includes("server")||/\b(?:id|uuid)\b/.test(n))&&(t[n]=e.headers[n]);const s=e.url.replace(/^(?:https?:)?\/*/i,"").replace(/\?.+/,""),r=e.status<0?"unknown":e.status;return{sentryError:new Zt(`${s} | ${r}${e.code?` | ${e.code}`:""}`),sentryTags:{...t,status:r,method:e.method,code:e.code||"unknown",message:e.message||"empty"},sentryExtra:{url:e.url,responseBody:e.body||"empty",responseHeaders:e.headers,rawError:e.error}}}function ct(e){return e.reduce((t,[s,r])=>(s&&(t[s]=r||""),t),{})}function Yt(e,t,s,r){var y;const n=e.status,i=e.method,a=ct(Object.entries(e.headers||{}).map(([k,w])=>[k.toLowerCase(),w])),{ok:h,code:c,data:m,message:f}=Bt(n,e.statusText,e.body,s.get("responseRule"),r==null?void 0:r.responseRule);if(!X(n)){const k=Xt({url:e.url,method:e.method,status:n,code:c,message:f,body:e.body,headers:a,error:e.rawError});(s.get("errorHandler")||Qt)({url:t,method:i,status:n,code:c,message:f,headers:a,rawError:e.rawError,responseBody:e.body,...k})}if(n<0)return rt({ok:!1,status:n,code:e.statusText,headers:{},message:"",data:null},`${i} ${t} ${e.statusText}`,i,t,s,r);const d={ok:h,data:m,code:c,message:f,status:n,headers:a};(y=s.get("responseHandler"))==null||y({...d},i,t);const p=h?f:f||e.statusText;return rt(d,p,i,t,s,r)}function rt(e,t,s,r,n,i){const a=n.get("message"),h=a===!1||(i==null?void 0:i.message)===!1?!1:(i==null?void 0:i.message)||a;if(h!==!1){const c=typeof h=="function"?h(e,s,r,t):t;c instanceof Error?n.showMessage(!0,c.message,e.code,e.status):c&&typeof c=="object"&&"message"in c?n.showMessage(!1,c.message,e.code,e.status):n.showMessage(!e.ok,c,e.code,e.status)}return e}function Qt(e){const t={};for(const s in e)s.startsWith("sentry")||(t[s]=e[s]);console.error("RequestError",t)}async function ft(e,t,s,r,n){const i=n||0,a=Math.max(0,Math.min(10,(r==null?void 0:r.maxRetry)??s.get("maxRetry")??0)),h=(r==null?void 0:r.retryResolve)??s.get("retryResolve"),c=s.get("logHandler")||q;c({type:"prepare",url:t,method:(r==null?void 0:r.method)||"GET",retry:i,maxRetry:a,message:i===0?"start":`retry ${i}/${a} start`,headers:r==null?void 0:r.headers,options:r});const m=Date.now(),f=await e(t,s,r),d=f.status,p=Date.now()-m,y=`[cost ${p}][${d}] ${d<0?f.body:""}`;c({type:"finished",url:t,method:f.method,retry:i,maxRetry:a,message:i===0?`finish ${y}`:`retry ${i}/${a} finish ${y}`,response:f,headers:f.headers,cost:p});const k=X(d);if(!a||h==="network"&&d>0||h==="status"&&k||Array.isArray(h)&&!h.includes(d)||typeof h=="function"&&h(f,i)!==!0||i>=a)return f;const w=(r==null?void 0:r.retryInterval)??s.get("retryInterval")??100;return await pt(Math.max(100,w==="2EB"?Math.pow(2,i)*100:typeof w=="function"?w(i+1)||0:w)),await ft(e,t,s,r,i+1)}exports.At=U;exports.NetRequestHandler=Lt;exports.RequestGlobalConfig=ut;exports.RequestInternalError=T;exports.ce=Nt;exports.convertOptions=Dt;exports.fromEntries=ct;exports.ge=Tt;exports.getResponseRulesDescription=Ht;exports.handleResponse=Yt;exports.jt=j;exports.retryRequest=ft;
|
package/dist/wx.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./retry-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./retry-DsG4xDrA.cjs"),l=async function(t,r,u){return e.handleResponse(await e.retryRequest(f,t,r,u),t,r,u)},f=async function(t,r,u){const s=await e.convertOptions(t,r,u),a=s.method==="PATCH"?"POST":s.method,c=e.ge(s.url,s.params);return e.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:e.RequestInternalError.Unknown,body:""})},success(n){d({url:c,method:a,status:n.statusCode,statusText:n.statusCode+"",headers:{...n.header},body:s.method==="HEAD"||n.statusCode===204?"":p(n.data)})}})}):{url:c,method:a,status:-1,statusText:e.RequestInternalError.NotSupport,body:""}};function p(t){return typeof t=="string"?t:t instanceof ArrayBuffer&&e.jt.TextDecoder?new TextDecoder().decode(t):JSON.stringify(t)}function i(t){return new e.NetRequestHandler(l,t)}const o=i(),y=o.setConfig,g=o.head,h=o.get,q=o.post,x=o.del,R=o.put;exports.NetRequest=i;exports.del=x;exports.get=h;exports.head=g;exports.post=q;exports.put=R;exports.setGlobalConfig=y;
|
package/dist/wx.js
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import { h as f, r as p, c as l,
|
|
1
|
+
import { h as f, r as p, c as l, g as h, j as i, a as d, N as y } from "./retry-BdpLadtU.js";
|
|
2
2
|
const x = async function(t, n, r) {
|
|
3
|
-
return f(await p(
|
|
4
|
-
},
|
|
5
|
-
const e = await l(t, n, r),
|
|
3
|
+
return f(await p(g, t, n, r), t, n, r);
|
|
4
|
+
}, g = async function(t, n, r) {
|
|
5
|
+
const e = await l(t, n, r), a = e.method === "PATCH" ? "POST" : e.method, u = h(e.url, e.params);
|
|
6
6
|
return i.wx ? new Promise((c) => {
|
|
7
7
|
wx.request({
|
|
8
|
-
url:
|
|
8
|
+
url: u,
|
|
9
9
|
data: e.body,
|
|
10
10
|
header: e.headers,
|
|
11
|
-
method:
|
|
11
|
+
method: a,
|
|
12
12
|
dataType: "string",
|
|
13
13
|
responseType: "text",
|
|
14
14
|
fail() {
|
|
15
15
|
c({
|
|
16
|
-
url:
|
|
17
|
-
method:
|
|
16
|
+
url: u,
|
|
17
|
+
method: a,
|
|
18
18
|
status: -1,
|
|
19
19
|
statusText: d.Unknown,
|
|
20
20
|
body: ""
|
|
@@ -22,36 +22,36 @@ const x = async function(t, n, r) {
|
|
|
22
22
|
},
|
|
23
23
|
success(o) {
|
|
24
24
|
c({
|
|
25
|
-
url:
|
|
26
|
-
method:
|
|
25
|
+
url: u,
|
|
26
|
+
method: a,
|
|
27
27
|
status: o.statusCode,
|
|
28
28
|
statusText: o.statusCode + "",
|
|
29
29
|
headers: { ...o.header },
|
|
30
|
-
body: e.method === "HEAD" || o.statusCode === 204 ? "" :
|
|
30
|
+
body: e.method === "HEAD" || o.statusCode === 204 ? "" : m(o.data)
|
|
31
31
|
});
|
|
32
32
|
}
|
|
33
33
|
});
|
|
34
34
|
}) : {
|
|
35
|
-
url:
|
|
36
|
-
method:
|
|
35
|
+
url: u,
|
|
36
|
+
method: a,
|
|
37
37
|
status: -1,
|
|
38
38
|
statusText: d.NotSupport,
|
|
39
39
|
body: ""
|
|
40
40
|
};
|
|
41
41
|
};
|
|
42
|
-
function
|
|
42
|
+
function m(t) {
|
|
43
43
|
return typeof t == "string" ? t : t instanceof ArrayBuffer && i.TextDecoder ? new TextDecoder().decode(t) : JSON.stringify(t);
|
|
44
44
|
}
|
|
45
|
-
function
|
|
45
|
+
function w(t) {
|
|
46
46
|
return new y(x, t);
|
|
47
47
|
}
|
|
48
|
-
const s =
|
|
48
|
+
const s = w(), q = s.setConfig, R = s.head, b = s.get, C = s.post, N = s.del, S = s.put;
|
|
49
49
|
export {
|
|
50
|
-
|
|
50
|
+
w as NetRequest,
|
|
51
51
|
N as del,
|
|
52
52
|
b as get,
|
|
53
53
|
R as head,
|
|
54
54
|
C as post,
|
|
55
|
-
|
|
55
|
+
S as put,
|
|
56
56
|
q as setGlobalConfig
|
|
57
57
|
};
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@seayoo-web/request",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.4",
|
|
4
4
|
"description": "request tools for seayoo web",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"source": "./src/index.ts",
|
|
7
7
|
"main": "./dist/index.js",
|
|
8
8
|
"module": "./dist/index.js",
|
|
9
9
|
"types": "./types/index.d.ts",
|
|
10
|
+
"sideEffects": false,
|
|
10
11
|
"exports": {
|
|
11
12
|
".": {
|
|
12
13
|
"types": "./types/index.d.ts",
|
|
@@ -44,7 +45,7 @@
|
|
|
44
45
|
"access": "public"
|
|
45
46
|
},
|
|
46
47
|
"engines": {
|
|
47
|
-
"node": ">=
|
|
48
|
+
"node": ">=22"
|
|
48
49
|
},
|
|
49
50
|
"keywords": [
|
|
50
51
|
"request",
|
|
@@ -59,7 +60,7 @@
|
|
|
59
60
|
"happy-dom": "^12.10.3",
|
|
60
61
|
"msw": "^2.7.0",
|
|
61
62
|
"vitest": "^3.0.5",
|
|
62
|
-
"@seayoo-web/utils": "^3.
|
|
63
|
+
"@seayoo-web/utils": "^3.5.1"
|
|
63
64
|
},
|
|
64
65
|
"scripts": {
|
|
65
66
|
"prebuild": "pnpm --F utils build",
|
package/dist/retry-BhqDL0mQ.cjs
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
"use strict";var dt=Object.defineProperty;var _t=(e,t,s)=>t in e?dt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[t]=s;var v=(e,t,s)=>_t(e,typeof t!="symbol"?t+"":t,s);var mt=Object.defineProperty,gt=(e,t,s)=>t in e?mt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[t]=s,o=(e,t,s)=>gt(e,typeof t!="symbol"?t+"":t,s);const u=typeof globalThis<"u"?globalThis:typeof self<"u"?self:typeof window<"u"?window:Function("return this")(),j={wx:"wx"in u&&x(u.wx)&&"getSystemInfo"in u.wx&&_(u.wx.getSystemInfo),fetch:"fetch"in u&&_(u.fetch),window:"window"in u&&x(u.window),requestAnimationFrame:"requestAnimationFrame"in u&&_(u.requestAnimationFrame),localStorage:"localStorage"in u&&x(u.localStorage)&&"getItem"in u.localStorage&&_(u.localStorage.getItem),sessionStorage:"sessionStorage"in u&&x(u.sessionStorage)&&"getItem"in u.sessionStorage&&_(u.sessionStorage.getItem),File:"File"in u&&_(u.File),Blob:"Blob"in u&&_(u.Blob),Proxy:"Proxy"in u&&_(u.Proxy),Request:"Request"in u&&_(u.Request),FormData:"FormData"in u&&_(u.FormData),TextDecoder:"TextDecoder"in u&&_(u.TextDecoder),ResizeObserver:"ResizeObserver"in u&&_(u.ResizeObserver),AbortController:"AbortController"in u&&_(u.AbortController)};function _(e){return typeof e=="function"}function x(e){return typeof e=="object"&&e!==null}function pt(e){return new Promise(t=>setTimeout(t,Math.max(0,e)))}function q(){}function nt(e,t){const s={log:console.log.bind(console),error:console.error.bind(console),warn:console.warn.bind(console)},r=`[${e}]`;return["log","error","warn"].forEach(n=>{const i=console[n];s[n]=(...a)=>{i.apply(console,[r,...a])}}),s}function bt(e){const t=e||"CustomError";return class extends Error{constructor(s){super(s),Object.defineProperty(this,"name",{value:t,enumerable:!1,configurable:!0}),"setPrototypeOf"in Object&&Object.setPrototypeOf(this,new.target.prototype),"captureStackTrace"in Error&&typeof Error.captureStackTrace=="function"&&Error.captureStackTrace(this,this.constructor)}}}const yt=/^(?:https?:)?\/\/.+$/i,wt=/^https?:\/\/.+$/i,kt=/^\{[\d\D]*\}$/,vt=/^\[[\d\D]*\]$/;function $t(e){return typeof e=="string"}function T(e,t=!1){return t?yt.test(e):wt.test(e)}function jt(e){return e==null}function it(e,...t){return e!==null&&typeof e=="object"&&!(e instanceof Map)&&!(e instanceof Set)&&!(e instanceof WeakMap)&&!(e instanceof WeakSet)&&!Array.isArray(e)&&t.every(s=>s in e)}function b(e,...t){if(!e||typeof e!="object")return!1;const s=Object.getPrototypeOf(e);return s!==Object.prototype&&s!==null?!1:t.every(r=>r in e)}function B(e,t){return Array.isArray(e)&&e.every(s=>t(s))}function M(e){if(typeof e!="number"||Number.isNaN(e)||!Number.isFinite(e)||Number.isInteger(e)&&!Number.isSafeInteger(e))return!1;if(e===0)return!0;const t=Math.abs(e);return t>=Number.EPSILON&&t<=Number.MAX_SAFE_INTEGER}function ot(e){return kt.test(e)||vt.test(e)}function E(e){return e?e[0].toLowerCase()+e.slice(1):""}const at=/_\w*/,lt=/-\w*/;function Z(e){const t=at.test(e)?e.replace(/(?:^_*|_*$)/g,"").replace(/_+([^_])/g,(s,r)=>r.toUpperCase()):lt.test(e)?e.replace(/(?:^-*|-*$)/g,"").replace(/-+(\w)/g,(s,r)=>r.toUpperCase()):e;return E(t)}function Y(e){return at.test(e)?E(e).replace(/(?:^_*|_*$)/g,"").replace(/_+([^_])/g,(t,s)=>"_"+s.toLowerCase()):lt.test(e)?E(e.replace(/(?:^-*|-*$)/g,"")).replace(/-+(\w)/g,(t,s)=>"_"+s.toLowerCase()):E(e).replace(/[A-Z]/g,t=>`_${t.toLowerCase()}`)}function Nt(e,t=20){const s=Math.max(t,10);return e.length<=s?e:e.slice(0,s-3)+"..."}function L(e,t){try{const s=JSON.parse(e);return t?t(s)?s:null:s}catch{return null}}""+Math.random().toString(32).slice(2);function A(e,t=!1){return typeof e=="string"?Z(e):Array.isArray(e)?e.map(s=>!t||typeof s=="string"?A(s):typeof s=="object"&&s?A(s,!0):s):b(e)?Object.keys(e).reduce((s,r)=>{const n=Z(String(r)),i=n.charAt(0).toLowerCase()+n.slice(1);return s[i]=t?e[r]:A(e[r]),s},{}):e}function F(e,t=!1){return typeof e=="string"?Y(e):Array.isArray(e)?e.map(s=>!t||typeof s=="string"?F(s):typeof s=="object"&&s?F(s,t):s):b(e)?Object.keys(e).reduce((s,r)=>{const n=Y(String(r));return s[n]=t?e[r]:F(e[r]),s},{}):e}nt("LoadUtils");async function Ot(e){return await new Promise(function(t){const s=document.getElementsByTagName("head")[0],r=document.createElement("script");r.setAttribute("type","text/javascript"),r.setAttribute("charset","utf-8"),r.onload=function(){s.removeChild(r),t(!0)},r.onerror=function(){s.removeChild(r),t(!1)},r.setAttribute("src",e),s.appendChild(r)})}function tt(e){return Object.getOwnPropertyNames(e).forEach(function(t){delete e[t]}),e}const g=nt("Validator");function R(e){return e?`"${Nt(e).replace(/"/g,'\\"')}"`:"empty string"}function P(e){return typeof e=="object"&&e&&"constructor"in e&&typeof e.constructor=="function"?e.constructor.name||"ClassInstance":Object.prototype.toString.call(e).replace(/(?:.+ |]$)/g,"")}function C(e){return typeof e=="bigint"}function l(e){return new Error(`${e?`${e}()`:"method"} is not allowed after locked`)}class H{constructor(){o(this,"_ps",{}),o(this,"_allow",[]),o(this,"_reject",[]),o(this,"_locked",!1),o(this,"_opt",!1),o(this,"_null",!1)}pattern(t,s){if(this._locked)throw l("pattern");return this._ps[`#${t||"custom"}`]=s,this}url(t=!1){if(this._locked)throw l("url");return this._ps.url=t?/^(?:https?:)?\/\/.+$/i:/^https?:\/\/.+$/i,this}dataUri(){if(this._locked)throw l("dataUri");return this._ps.dataUri=/^data:[a-z]+\/[a-z]+;base64,[\w+/=]+$/,this}enum(...t){if(this._locked)throw l("enum");const s=t[0];return B(t,$t)?(this._allow=t,tt(this._ps)):b(s)&&(this._allow=Object.values(s).map(r=>`${r}`),tt(this._ps)),this}disallow(...t){return this._reject.push(...t),this}optional(){if(this._locked)throw l("optional");return this._opt=!0,this}maybeNull(){if(this._locked)throw l("maybeNull");return this._null=!0,this}lock(){return this._locked=!0,this}clone(){const t=new H;return t._ps={...this._ps},t._allow=[...this._allow],t._reject=[...this._reject],t._locked=!1,t}validate(t,s=g.warn){if(t===void 0)return this._opt||(s("should be a string, but got undefined"),!1);if(t===null)return this._null||(s("should be a string, but got null"),!1);if(typeof t!="string")return s(`should be a string, but got ${typeof t}`),!1;if(this._allow.length>0)return this._allow.includes(t)||(s(`${R(t)} is not allowed, just support ${this._allow.map(R).join(", ")}`),!1);if(this._reject.length>0&&this._reject.some(n=>typeof n=="string"?n===t:n.test(t)))return s(`${R(t)} is not allowed`),!1;const r=Object.keys(this._ps);return r.length>0&&!r.some(n=>{const i=this._ps[n];return i instanceof RegExp?i.test(t):i(t)})?(s(`${R(t)} is not match pattern ${r.join(" | ")}`),!1):!0}}class G{constructor(){o(this,"_int",!1),o(this,"_min",-1/0),o(this,"_max",1/0),o(this,"_allow",[]),o(this,"_reject",[]),o(this,"_infinite",!1),o(this,"_unsafe",!1),o(this,"_nan",!1),o(this,"_locked",!1),o(this,"_opt",!1),o(this,"_null",!1)}int(){if(this._locked)throw l("int");return this._int=!0,this}min(t){if(this._locked)throw l("min");return Number.isNaN(t)||(this._min=t),this}max(t){if(this._locked)throw l("max");return Number.isNaN(t)||(this._max=t),this}allowNaN(){if(this._locked)throw l("allowNaN");return this._nan=!0,this}allowInfinity(){if(this._locked)throw l("allowInfinity");return this._infinite=!0,this._unsafe=!0,this}unsafe(){if(this._locked)throw l("unsafe");return this._unsafe=!0,this}enum(...t){if(this._locked)throw l("enum");const s=t[0];return B(t,M)?(this._allow=t,this._reject=[]):b(s)&&(this._allow=Object.values(s).map(r=>M(r)?r:null).filter(r=>r!==null),this._reject=[]),this}disallow(...t){if(this._locked)throw l("disallow");return this._reject.push(...t),this}optional(){if(this._locked)throw l("optional");return this._opt=!0,this}maybeNull(){if(this._locked)throw l("maybeNull");return this._null=!0,this}lock(){return this._locked=!0,this}clone(){const t=new G;return t._int=this._int,t._min=this._min,t._max=this._max,t._allow=[...this._allow],t._reject=[...this._reject],t._infinite=this._infinite,t._unsafe=this._unsafe,t._nan=this._nan,t._locked=!1,t}validate(t,s=g.warn){return t===void 0?this._opt||(s("should be a number, but got undefined"),!1):t===null?this._null||(s("should be a number, but got null"),!1):typeof t!="number"?(s(`should be a number, but got ${typeof t}`),!1):Number.isNaN(t)?this._nan||(s("should be a number, but got NaN"),!1):!Number.isFinite(t)&&!this._infinite?(s("should be a number, but got Infinity"),!1):this._allow.length>0?this._allow.includes(t)||(s(`${t} is not allowed, just support ${this._allow.join(", ")}`),!1):this._reject.length>0&&this._reject.includes(t)?(s(`${t} is not allowed`),!1):this._int&&Math.ceil(t)!==t?(s(`${t} is not an integer`),!1):!M(t)&&!this._unsafe?(s(`${t} is not a safe number`),!1):t>=this._min&&t<=this._max||(s(`${t} is not in range [${this._min}, ${this._max}]`),!1)}}class K{constructor(){o(this,"_min",null),o(this,"_max",null),o(this,"_allow",[]),o(this,"_reject",[]),o(this,"_locked",!1),o(this,"_opt",!1),o(this,"_null",!1)}min(t){if(this._locked)throw l("min");return this._min=t,this}max(t){if(this._locked)throw l("max");return this._max=t,this}enum(...t){if(this._locked)throw l("enum");const s=t[0];return B(t,C)?(this._allow=t,this._reject=[]):b(s)&&(this._allow=Object.values(s).map(r=>C(r)?r:null).filter(r=>r!==null),this._reject=[]),this}disallow(...t){if(this._locked)throw l("disallow");return this._reject.push(...t),this}optional(){if(this._locked)throw l("optional");return this._opt=!0,this}maybeNull(){if(this._locked)throw l("maybeNull");return this._null=!0,this}lock(){return this._locked=!0,this}clone(){const t=new K;return t._min=this._min,t._max=this._max,t._allow=[...this._allow],t._reject=[...this._reject],t._locked=!1,t}validate(t,s=g.warn){return t===void 0?this._opt||(s("should be a bigint, but got undefined"),!1):t===null?this._null||(s("should be a bigint, but got null"),!1):C(t)?this._allow.length>0?this._allow.includes(t)||(s(`${t} is not allowed, just support ${this._allow.join(", ")}`),!1):this._reject.length>0&&this._reject.includes(t)?(s(`${t} is not allowed`),!1):(this._min!==null?t>=this._min:!0)&&(this._max!==null?t<=this._max:!0)||(s(`${t} 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 t}`),!1)}}class z{constructor(){o(this,"_locked",!1),o(this,"_opt",!1),o(this,"_null",!1)}optional(){if(this._locked)throw l("optional");return this._opt=!0,this}maybeNull(){if(this._locked)throw l("maybeNull");return this._null=!0,this}lock(){return this._locked=!0,this}clone(){return new z}validate(t,s=g.warn){return t===void 0?this._opt||(s("should be a boolean, but got undefined"),!1):t===null?this._null||(s("should be a boolean, but got null"),!1):typeof t!="boolean"?(s(`should be a boolean, but got ${typeof t}`),!1):!0}}class N{constructor(t){o(this,"_shape"),o(this,"_plain",!1),o(this,"_locked",!1),o(this,"_opt",!1),o(this,"_null",!1),this._shape=t}plain(){if(this._locked)throw l("plain");return this._plain=!0,this}optional(){if(this._locked)throw l("optional");return this._opt=!0,this}maybeNull(){if(this._locked)throw l("maybeNull");return this._null=!0,this}lock(){return this._locked=!0,this}get shape(){return{...this._shape}}clone(){const t=new N(this._shape);return t._plain=this._plain,t._locked=!1,t}match(t,s){return t in this._shape?this._shape[t].validate(s,q):!1}validate(t,s=g.warn){return t===void 0?this._opt||(s("should be a object, but got undefined"),!1):t===null?this._null||(s("should be a object, but got null"),!1):it(t)?this._plain&&!b(t)?(s(`should be a plain object, but got ${P(t)}`),!1):Object.keys(this._shape).every(r=>this._shape[r].validate(t[r],(...n)=>{s(`[.${String(r)}]`,...n)})):(s(`should be a object, but got ${P(t)}`),!1)}}class V{constructor(t){o(this,"_val"),o(this,"_locked",!1),o(this,"_opt",!1),o(this,"_null",!1),this._val=t}optional(){if(this._locked)throw l("optional");return this._opt=!0,this}maybeNull(){if(this._locked)throw l("maybeNull");return this._null=!0,this}lock(){return this._locked=!0,this}clone(){return new V(this._val)}validate(t,s=g.warn){return t===void 0?this._opt||(s("should be a record, but got undefined"),!1):t===null?this._null||(s("should be a record, but got null"),!1):b(t)?Object.keys(t).every(r=>this._val.validate(t[r],(...n)=>{s(`[:${r}]`,...n)})):(s(`should be a record, but got ${P(t)}`),!1)}}class W{constructor(t){o(this,"_val"),o(this,"_min",0),o(this,"_max",1/0),o(this,"_locked",!1),o(this,"_opt",!1),o(this,"_null",!1),this._val=t}min(t){if(this._locked)throw l("min");return this._min=t,this}max(t){if(this._locked)throw l("max");return this._max=t,this}optional(){if(this._locked)throw l("optional");return this._opt=!0,this}maybeNull(){if(this._locked)throw l("maybeNull");return this._null=!0,this}lock(){return this._locked=!0,this}clone(){const t=new W(this._val);return t._min=this._min,t._max=this._max,t._locked=!1,t}validate(t,s=g.warn){return t===void 0?this._opt||(s("should be a array, but got undefined"),!1):t===null?this._null||(s("should be a array, but got null"),!1):Array.isArray(t)?t.length<this._min||t.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):t.every((r,n)=>this._val.validate(r,(...i)=>{s(`[${n}]`,...i)})):(s(`should be a array, but got ${typeof t}`),!1)}}class J{constructor(...t){o(this,"_vs"),o(this,"_locked",!1),o(this,"_opt",!1),o(this,"_null",!1),this._vs=t}optional(){if(this._locked)throw l("optional");return this._opt=!0,this}maybeNull(){if(this._locked)throw l("maybeNull");return this._null=!0,this}lock(){return this._locked=!0,this}clone(){return new J(...this._vs)}validate(t,s=g.warn){return t===void 0?this._opt||(s("should be a tuple, but got undefined"),!1):t===null?this._null||(s("should be a tuple, but got null"),!1):Array.isArray(t)?t.length!==this._vs.length?(s(`should be a tuple with length ${this._vs.length}, but got ${t.length}`),!1):this._vs.every((r,n)=>r.validate(t[n],(...i)=>{s(`[idx:${n}]`,...i)})):(s(`should be a tuple, but got ${typeof t}`),!1)}}class Q{constructor(...t){o(this,"_vs"),o(this,"_key",""),o(this,"_locked",!1),o(this,"_opt",!1),o(this,"_null",!1),this._vs=t}optional(){if(this._locked)throw l("optional");return this._opt=!0,this}maybeNull(){if(this._locked)throw l("maybeNull");return this._null=!0,this}key(t){if(this._locked)throw l("key");return this._vs.every(s=>s instanceof N)?this._key=t: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 t=new Q(...this._vs);return t._key=this._key,t._locked=!1,t}validate(t,s=g.warn){if(t===void 0)return this._opt||(s("should be a union, but got undefined"),!1);if(t===null)return this._null||(s("should be a union, but got null"),!1);if(this._key&&it(t)&&t){const n=t[this._key];if(n===void 0)return s(`key field "${this._key}" is not found`,t),!1;const i=this._vs.find(a=>a instanceof N&&a.match(this._key,n));return i?i.validate(t,s):(s(`key field "${this._key}" value is match union definition`,n),!1)}const r=this._vs.some(n=>n.validate(t,q));return r||s("value is not match union definition",t),r}}class S{constructor(t,s){o(this,"_name",""),o(this,"_guard"),o(this,"_locked",!1),o(this,"_opt",!1),o(this,"_null",!1),this._name=t,this._guard=s}optional(){if(this._locked)throw l("optional");return this._opt=!0,this}maybeNull(){if(this._locked)throw l("maybeNull");return this._null=!0,this}lock(){return this._locked=!0,this}clone(){return new S(this._name,this._guard)}validate(t,s=g.warn){const r=this._name||"custom type";return t===void 0?this._opt||(s(`should be ${r}, but got undefined`),!1):t===null?this._null||(s(`should be ${r}, but got null`),!1):this._guard(t)||(s(`custom validation${this._name?`(${this._name})`:""} failed`),!1)}}function xt(e,t){if(typeof e=="string"){if(!t)throw new Error("custom type guard must be defined");return new S(e,t)}return new S("",e)}const Rt={shape(e){return e},define(e){return e},guard(e){return function(t){return e.validate(t)}},object(e){return new N(e)},record(e){return new V(e)},array(e){return new W(e)},tuple(...e){return new J(...e)},union(...e){return new Q(...e)},string(){return new H},bool(){return new z},number(){return new G},bigint(){return new K},custom:xt,unknown(){return{validate(e){return!0}}},never(){return{validate(e){return!1}}}},Et=e=>b(e)&&Object.keys(e).length===0;Rt.custom("EmptyObject",Et);function At(e,t="数据未能正确识别"){return typeof e=="function"?{guard:e,message:t}:{guard:e.guard,message:e.message||t}}function Ft(e,t=""){return!t||T(e,!0)?et(e):(et(t)+"/"+e).replace(/\/{2,}/g,"/").replace(/:\//,"://")}function et(e){return T(e,!0)?e.startsWith("http")?e:("location"in globalThis?location.protocol:"https:")+e:("location"in globalThis?location.origin:"http://127.0.0.1")+"/"+e.replace(/^\/+/,"")}function St(e,t){const s={};return(e.match(/([^=&#?]+)=[^&#]*/g)||[]).forEach(function(r){const n=r.split("="),i=n[0],a=decodeURIComponent(n[1]||"");s[i]!==void 0?s[i]+=","+a:s[i]=a}),t!==!0?s[t]||"":s}function Tt(e,t){if(t){if(t===!0)return e.replace(/\?[^#]*/,"")}else return e;const s=e.split("#"),r=s[0].split("?"),n=r[0],i=r.length>1?r[1]:"",a=s.length>1?"#"+s[1]:"",h=typeof t=="string"?[t]:Array.isArray(t)?t:[];return!h.length||!i?s[0]+a:(h.map(c=>c.replace(/([\\(){}[\]^$+\-*?|])/g,"\\$1")),(n+"?"+i.replace(new RegExp("(?:^|&)(?:"+h.join("|")+")=[^&$]+","g"),"").replace(/^&/,"")).replace(/\?$/,"")+a)}function Ut(e,t,s=!1){const r=typeof t=="string"?t:Object.keys(t).map(a=>`${a}=${encodeURIComponent(t[a])}`).join("&");if(!r)return e;const n=e.split("#");s&&(n[0]=Tt(n[0],(r.match(/([^=&#?]+)=[^&#]+/g)||[]).map(a=>a.replace(/=.+$/,""))));const i=n[0].indexOf("?")+1?"&":"?";return(n[0]+i+r+(n.length>1?"#"+n[1]:"")).replace(/\?&/,"?")}function Mt(e){const t=e.match(/(?:\?|&)([^=]+)(?:&|$)/g);return t?t.join("").replace(/(?:\?|^&+|&+$)/g,"").replace(/&{2}/g,"&").split("&").sort():[]}class Ct{constructor(t=500){v(this,"ttl");v(this,"cache");this.cache={},this.ttl=Math.max(t,0)}getKey(t,s){const r=t.replace(/#.+/,""),n=r.replace(/\?.+/g,""),i=Object.assign(St(r,!0),s),a=Mt(r),h=Object.keys(i).sort().map(c=>`${c}#${i[c]}`);return`${n}_${h.join(",")}_${a.join(",")}`}updateTTL(t){this.ttl=Math.max(t,0)}get(t){if(this.ttl===0)return null;const s=this.cache[t];return s?s.ttl<Date.now()?(delete this.cache[t],null):s.res:null}set(t,s){this.ttl!==0&&(this.cache[t]={ttl:Date.now()+this.ttl,res:s})}}class ut{constructor(t){v(this,"config",{baseURL:"/",maxRetry:0,retryInterval:100,retryResolve:"network",timeout:1e4,cacheTTL:500,credentials:"same-origin",defaultTypeGuardMessage:"响应数据未能正确识别",responseRule:{ok:{resolve:"body"},failed:{resolve:"json",messageField:"message"}}});t&&this.set(t)}set(t){if(t.baseURL&&!/^\/.+/.test(t.baseURL)&&!T(t.baseURL))throw console.warn("baseURL 需要以 / 开头,或者是完整的 url 地址"),new Error("BaseURLError");Object.assign(this.config,t)}get(t){return this.config[t]}getFullUrl(t){return Ft(t,this.config.baseURL)}showMessage(t,s,r,n){this.config.messageHandler&&s&&this.config.messageHandler(t,s,r,n)}}var U=(e=>(e.UnexpectResponse="UnexpectResponse",e.Aborted="Aborted",e.Unknown="Unknown",e.NetworkError="NetworkError",e.Timeout="Timeout",e.NotSupport="NotSupport",e.URLFormatError="URLFormatError",e))(U||{});function Lt(e,t,s,r){if(t.ok&&!jt(t.data)&&r){const n=At(r,s.get("defaultTypeGuardMessage"));return n.guard(t.data)||(t.code=U.UnexpectResponse,s.showMessage(!0,`${e} ${n.message}`,t.code,t.status),console.error(t.code,e,t.data),t.data=null,t.message=n.message),t}return t}class Pt{constructor(t,s){v(this,"agent");v(this,"config");v(this,"cache");this.config=new ut(s),this.agent=t,this.cache=new Ct(this.config.get("cacheTTL")),this.setConfig=this.setConfig.bind(this),this.getConfig=this.getConfig.bind(this),this.request=this.request.bind(this),this.get=this.get.bind(this),this.post=this.post.bind(this),this.del=this.del.bind(this),this.patch=this.patch.bind(this),this.put=this.put.bind(this),this.head=this.head.bind(this)}async request(t,s){try{return await this.agent(t,this.config,s)}catch(r){return console.error("RequestError",r),{ok:!1,status:-9,code:U.Unknown,message:r instanceof Error?`${r.message}
|
|
2
|
-
${r.stack||""}`:String(r),headers:{},data:null}}}async guard(t,s,r){return Lt(t,s,this.config,r)}setConfig(t){this.config.set(t),this.cache.updateTTL(this.config.get("cacheTTL"))}getConfig(t){return this.config.get(t)}async head(t,s){const r=Object.assign({},s||null);return r.method="HEAD",this.guard(t,await this.request(t,r),null)}async get(t,s,r){const n=Object.assign({},r||null);n.method="GET";const i=this.cache.getKey(t,n.params),a=this.cache.get(i);if(a)return this.guard(t,await a,s||null);const h=this.request(t,n);return this.cache.set(i,h),this.guard(t,await h,s||null)}async post(t,s,r,n){const i=Object.assign({},n||null);return i.method="POST",i.body=s||{},this.guard(t,await this.request(t,i),r||null)}async del(t,s,r){const n=Object.assign({},r||null);return n.method="DELETE",this.guard(t,await this.request(t,n),s||null)}async put(t,s,r,n){const i=Object.assign({},n||null);return i.method="PUT",i.body=s||{},this.guard(t,await this.request(t,i),r||null)}async patch(t,s,r,n){const i=Object.assign({},n||null);return i.method="PATCH",i.body=s||{},this.guard(t,await this.request(t,i),r||null)}}async function Dt(e,t,s){var w;const r=Object.assign({method:"GET"},s),n=j.FormData?r.body instanceof FormData:!1,i=n&&r.method!=="POST"&&r.method!=="PUT"?"POST":r.method,a=i==="GET"||i==="HEAD"||i==="DELETE";a&&r.body!==void 0&&(console.warn("request body is invalid with method get, head, delete"),delete r.body);const h=Object.assign(n||a?{}:{"Content-Type":j.Blob&&r.body instanceof Blob?r.body.type||"application/octet-stream":"application/json;charset=utf-8"},r.headers),c=r.params||{},m={};Object.keys(c).forEach($=>{c[$]!==void 0&&(m[$]=It(c[$]))});const f=t.getFullUrl(e),d=qt(r.body),p=r.timeout||t.get("timeout"),y=await async function(){const $=t.get("requestTransformer");if($)return await $({headers:h,params:m,method:i,url:f,body:d})}(),k=typeof y=="string"&&y?y:f;return(w=t.get("logHandler"))==null||w({type:"ready",url:k,method:i,headers:h,timeout:p,body:d}),{url:k,method:i,body:d,params:m,headers:h,timeout:p,abort:r.abort,credentials:r.credentials||t.get("credentials")}}function It(e){return typeof e=="string"?e:Array.isArray(e)?e.join(","):e+""}function qt(e){if(e)return typeof e=="string"||j.window&&e instanceof URLSearchParams||e instanceof ArrayBuffer||j.Blob&&e instanceof Blob||j.FormData&&e instanceof FormData?e:JSON.stringify(e)}const ht="data",O="message";function Bt(e,t,s,r,n){const i=n||r;return X(e)?Jt(i.ok||r.ok,e,t,s):Gt(i.failed||r.failed,t,s)}const Ht=function(e){const t=[],s=e.failed||{resolve:"json"};switch(t.push("- 当http状态码 <200 或者 >=400 时"),s.resolve){case"body":t.push(" 将响应内容格式化为字符串并作为错误消息");break;case"json":t.push(" 将响应解析为json,并读取 "+(s.messageField||O)+" 作为错误消息");break}const r=e.ok||{resolve:"body"};switch(t.push("- 当http状态码 >=200 并且 <400 时"),r.resolve){case"body":t.push(" 将响应尝试解析为 json,并作为数据内容返回");break;case"json":t.push(" 将响应解析为 json,读取 "+(r.dataField||ht)+" 作为响应数据,读取 "+(r.messageField||O)+" 作为提示消息"),r.statusField&&t.push(" 当 "+r.statusField+" 为 "+(r.statusOKValue||"空值")+" 时是成功提示,否则是错误消息"),r.ignoreMessage&&t.push(" 并忽略以下消息:"+r.ignoreMessage);break}return t.join(`
|
|
3
|
-
`)};function Gt(e,t,s){const r=e||{resolve:"json",messageField:O},n={ok:!1,code:t,message:s,data:null};switch(r.resolve){case"body":n.message=st(s)||s;break;case"json":const{code:i,message:a}=Kt(s,r.converter,r.statusField,r.messageField);n.code=i||t,n.message=st(s)||a;break}return n}function Kt(e,t,s,r=O){if(!ot(e))return{message:""};const n=I(L(e),t);return!n||!b(n)?{message:e}:{code:s?D(n,s):"",message:D(n,r)||e}}function D(e,t){const s=Array.isArray(t)?t:[t];for(const r of s)if(r in e)return zt(e[r]);return""}function zt(e){return e?typeof e=="string"?e:JSON.stringify(e):""}const Vt=/<title>([^<]+)<\/title>/i,Wt=/<message>([^<]+)<\/message>/i;function st(e){const t=e.match(Vt);if(t)return t[1];const s=e.match(Wt);return s?s[1]:""}function Jt(e,t,s,r){const n=e||{resolve:"body"},i={ok:!0,code:s,message:"",data:null};if(t===204||!r)return i;if(n.resolve==="body")return i.data=ot(r)?I(L(r),e.converter):r,i;const a=I(L(r),e.converter);if(!a||!b(a))return i.ok=!1,i.code="ResponseFormatError",i.message="响应内容无法格式化为 Object",i;const h=n.statusField,c=n.statusOKValue||"",m=n.dataField||ht,f=n.messageField||O,d=n.ignoreMessage||"";if(h&&!(h in a))return i.ok=!1,i.code="ResponseFieldMissing",i.message="响应内容找不到状态字段 "+h,i;const p=h?a[h]+"":"";return i.ok=h?p===c:!0,i.code=p||s,i.data=m===!0?a:m in a?a[m]:null,i.message=D(a,f),d&&i.message&&(Array.isArray(d)&&d.includes(i.message)||typeof d=="string"&&i.message===d)&&(i.message=""),i}function X(e){return e>=200&&e<400}function I(e,t){return t==="camelize"?A(e):t==="snakify"?F(e):e}const Qt=bt("APIError");function Xt(e){const t={};for(const n in e.headers)(n.startsWith("x-")||n.includes("trace")||n.includes("server")||/\b(?:id|uuid)\b/.test(n))&&(t[n]=e.headers[n]);const s=e.url.replace(/^(?:https?:)?\/*/i,"").replace(/\?.+/,""),r=e.status<0?"unknown":e.status;return{sentryError:new Qt(`${s} | ${r}${e.code?` | ${e.code}`:""}`),sentryTags:{...t,status:r,method:e.method,code:e.code||"unknown",message:e.message||"empty"},sentryExtra:{url:e.url,responseBody:e.body||"empty",responseHeaders:e.headers,rawError:e.error}}}function ct(e){return e.reduce((t,[s,r])=>(s&&(t[s]=r||""),t),{})}function Zt(e,t,s,r){var y;const n=e.status,i=e.method,a=ct(Object.entries(e.headers||{}).map(([k,w])=>[k.toLowerCase(),w])),{ok:h,code:c,data:m,message:f}=Bt(n,e.statusText,e.body,s.get("responseRule"),r==null?void 0:r.responseRule);if(!X(n)){const k=Xt({url:e.url,method:e.method,status:n,code:c,message:f,body:e.body,headers:a,error:e.rawError});(s.get("errorHandler")||Yt)({url:t,method:i,status:n,code:c,message:f,headers:a,rawError:e.rawError,responseBody:e.body,...k})}if(n<0)return rt({ok:!1,status:n,code:e.statusText,headers:{},message:"",data:null},`${i} ${t} ${e.statusText}`,i,t,s,r);const d={ok:h,data:m,code:c,message:f,status:n,headers:a};(y=s.get("responseHandler"))==null||y({...d},i,t);const p=h?f:f||e.statusText;return rt(d,p,i,t,s,r)}function rt(e,t,s,r,n,i){const a=n.get("message"),h=a===!1||(i==null?void 0:i.message)===!1?!1:(i==null?void 0:i.message)||a;if(h!==!1){const c=typeof h=="function"?h(e,s,r,t):t;c instanceof Error?n.showMessage(!0,c.message,e.code,e.status):c&&typeof c=="object"&&"message"in c?n.showMessage(!1,c.message,e.code,e.status):n.showMessage(!e.ok,c,e.code,e.status)}return e}function Yt(e){const t={};for(const s in e)s.startsWith("sentry")||(t[s]=e[s]);console.error("RequestError",t)}async function ft(e,t,s,r,n){const i=n||0,a=Math.max(0,Math.min(10,(r==null?void 0:r.maxRetry)??s.get("maxRetry")??0)),h=(r==null?void 0:r.retryResolve)??s.get("retryResolve"),c=s.get("logHandler")||q;c({type:"prepare",url:t,method:(r==null?void 0:r.method)||"GET",retry:i,maxRetry:a,message:i===0?"start":`retry ${i}/${a} start`,headers:r==null?void 0:r.headers,options:r});const m=Date.now(),f=await e(t,s,r),d=f.status,p=Date.now()-m,y=`[cost ${p}][${d}] ${d<0?f.body:""}`;c({type:"finished",url:t,method:f.method,retry:i,maxRetry:a,message:i===0?`finish ${y}`:`retry ${i}/${a} finish ${y}`,response:f,headers:f.headers,cost:p});const k=X(d);if(!a||h==="network"&&d>0||h==="status"&&k||Array.isArray(h)&&!h.includes(d)||typeof h=="function"&&h(f,i)!==!0||i>=a)return f;const w=(r==null?void 0:r.retryInterval)??s.get("retryInterval")??100;return await pt(Math.max(100,w==="2EB"?Math.pow(2,i)*100:typeof w=="function"?w(i+1)||0:w)),await ft(e,t,s,r,i+1)}exports.$t=T;exports.NetRequestHandler=Pt;exports.Ot=j;exports.Qe=Ot;exports.RequestGlobalConfig=ut;exports.RequestInternalError=U;exports.convertOptions=Dt;exports.fromEntries=ct;exports.getResponseRulesDescription=Ht;exports.handleResponse=Zt;exports.retryRequest=ft;exports.ue=Ut;
|