@seayoo-web/request 4.0.0 → 4.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +31 -31
- package/dist/node.js +3 -3
- package/dist/{request.fetch-BNCxK4Wq.js → request.fetch-U42cahT4.js} +1 -1
- package/dist/{retry-DRbCcUt8.js → retry--akoKQtX.js} +248 -251
- package/dist/wx.js +2 -2
- package/package.json +1 -1
- package/types/inc/type.d.ts +1 -1
- package/types/inc/utils.d.ts +2 -1
package/dist/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { h, r as
|
|
2
|
-
import { g as
|
|
3
|
-
import { f as
|
|
4
|
-
const
|
|
5
|
-
return h(await
|
|
1
|
+
import { h, r as E, G as y, c as q, f as v, a as C, R as w, H as R, b as H, v as x, d as L, N as T, X as k } from "./retry--akoKQtX.js";
|
|
2
|
+
import { g as W } from "./retry--akoKQtX.js";
|
|
3
|
+
import { f as S } from "./request.fetch-U42cahT4.js";
|
|
4
|
+
const j = async function(n, a, t) {
|
|
5
|
+
return h(await E(m, n, a, t), n, a, t);
|
|
6
6
|
};
|
|
7
|
-
async function
|
|
7
|
+
async function B(n, a, t, r) {
|
|
8
8
|
const o = t?.body, u = t?.method === "PUT" ? "PUT" : "POST";
|
|
9
9
|
if (a instanceof Blob) {
|
|
10
10
|
const l = new y(r), e = await m(n, l, {
|
|
@@ -30,7 +30,7 @@ async function j(n, a, t, r) {
|
|
|
30
30
|
return h(p, n, f, t);
|
|
31
31
|
}
|
|
32
32
|
const m = async function(n, a, t) {
|
|
33
|
-
const r = await
|
|
33
|
+
const r = await q(n, a, t), o = r.method, u = t?.onUploadProgress;
|
|
34
34
|
return await new Promise((c) => {
|
|
35
35
|
let d = null, f = !1;
|
|
36
36
|
const p = function() {
|
|
@@ -53,19 +53,19 @@ const m = async function(n, a, t) {
|
|
|
53
53
|
l();
|
|
54
54
|
const s = e.responseType;
|
|
55
55
|
c(
|
|
56
|
-
await
|
|
56
|
+
await v(
|
|
57
57
|
{
|
|
58
58
|
url: r.url,
|
|
59
59
|
method: o,
|
|
60
60
|
status: e.status,
|
|
61
61
|
statusText: e.statusText,
|
|
62
|
-
headers:
|
|
62
|
+
headers: P(e),
|
|
63
63
|
body: null
|
|
64
64
|
},
|
|
65
65
|
{
|
|
66
66
|
asBuffer: r.asBuffer,
|
|
67
67
|
text: () => s === "" || s === "text" || s === "json" || s === "document" ? e.responseText : "",
|
|
68
|
-
buffer: async () => s === "arraybuffer" ? e.response : s === "blob" ? await e.response.arrayBuffer() : await
|
|
68
|
+
buffer: async () => s === "arraybuffer" ? e.response : s === "blob" ? await e.response.arrayBuffer() : await C(e.responseText)
|
|
69
69
|
}
|
|
70
70
|
)
|
|
71
71
|
);
|
|
@@ -101,7 +101,7 @@ const m = async function(n, a, t) {
|
|
|
101
101
|
}, r.timeout));
|
|
102
102
|
});
|
|
103
103
|
};
|
|
104
|
-
function
|
|
104
|
+
function P(n) {
|
|
105
105
|
const a = {};
|
|
106
106
|
if (!n)
|
|
107
107
|
return a;
|
|
@@ -121,26 +121,26 @@ async function O(n, a, t = {}) {
|
|
|
121
121
|
const o = t.callback + "";
|
|
122
122
|
if (!n)
|
|
123
123
|
return null;
|
|
124
|
-
const u = R(n, t, !0);
|
|
124
|
+
const u = R(n, H(t), !0);
|
|
125
125
|
return new Promise((c) => {
|
|
126
126
|
r[o] = function(d) {
|
|
127
127
|
if (o in window && delete r[o], a(d))
|
|
128
128
|
return d;
|
|
129
129
|
console.warn("response type check failed", n, d), c(null);
|
|
130
|
-
},
|
|
130
|
+
}, x(u).catch(function() {
|
|
131
131
|
c(null), delete r[o];
|
|
132
132
|
});
|
|
133
133
|
});
|
|
134
134
|
}
|
|
135
|
-
async function
|
|
135
|
+
async function A(n, a, t = {}) {
|
|
136
136
|
const r = window;
|
|
137
|
-
return "var" in t || (t.var = "jsonxData" + Math.random().toString(16).slice(2)), n ? await
|
|
137
|
+
return "var" in t || (t.var = "jsonxData" + Math.random().toString(16).slice(2)), n ? await x(R(n, H(t), !0)).then(() => {
|
|
138
138
|
const o = r[t.var + ""];
|
|
139
139
|
return a(o) ? o : (console.warn("response type check failed", n, o), null);
|
|
140
140
|
}).catch(() => null) : null;
|
|
141
141
|
}
|
|
142
|
-
const
|
|
143
|
-
return await
|
|
142
|
+
const M = async function(n, a, t) {
|
|
143
|
+
return await B(n, a, t, {
|
|
144
144
|
baseURL: i.getConfig("baseURL"),
|
|
145
145
|
logHandler: i.getConfig("logHandler"),
|
|
146
146
|
errorHandler: i.getConfig("errorHandler"),
|
|
@@ -151,24 +151,24 @@ const A = async function(n, a, t) {
|
|
|
151
151
|
};
|
|
152
152
|
// @__NO_SIDE_EFFECTS__
|
|
153
153
|
function U(n) {
|
|
154
|
-
if (!
|
|
154
|
+
if (!L())
|
|
155
155
|
throw new Error("Default Module Only Support In Browser");
|
|
156
|
-
return
|
|
156
|
+
return k() ? new T(S, n) : new T(j, n);
|
|
157
157
|
}
|
|
158
|
-
const i = /* @__PURE__ */ U(),
|
|
158
|
+
const i = /* @__PURE__ */ U(), X = i.setConfig, G = i.request, F = i.head, I = i.get, $ = i.post, z = i.del, J = i.put, K = i.patch;
|
|
159
159
|
export {
|
|
160
160
|
U as NetRequest,
|
|
161
161
|
w as RequestInternalError,
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
162
|
+
z as del,
|
|
163
|
+
I as get,
|
|
164
|
+
W as getResponseRulesDescription,
|
|
165
|
+
F as head,
|
|
166
166
|
O as jsonp,
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
167
|
+
A as jsonx,
|
|
168
|
+
K as patch,
|
|
169
|
+
$ as post,
|
|
170
|
+
J as put,
|
|
171
|
+
G as request,
|
|
172
|
+
X as setGlobalConfig,
|
|
173
|
+
M as upload
|
|
174
174
|
};
|
package/dist/node.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { h as w, r as R, c as y,
|
|
2
|
-
import { g as S } from "./retry
|
|
3
|
-
import { f as x } from "./request.fetch-
|
|
1
|
+
import { h as w, r as R, c as y, e as b, f as q, R as s, N as h, X as g } from "./retry--akoKQtX.js";
|
|
2
|
+
import { g as S } from "./retry--akoKQtX.js";
|
|
3
|
+
import { f as x } from "./request.fetch-U42cahT4.js";
|
|
4
4
|
import N from "node:http";
|
|
5
5
|
import C from "node:https";
|
|
6
6
|
const E = async function(o, n, a) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { h as f, r as h, c as m,
|
|
1
|
+
import { h as f, r as h, c as m, i as b, f as y, e as T, R as u } from "./retry--akoKQtX.js";
|
|
2
2
|
const x = async function(o, a, s) {
|
|
3
3
|
return f(await h(w, o, a, s), o, a, s);
|
|
4
4
|
}, w = async function(o, a, s) {
|
|
@@ -1,46 +1,46 @@
|
|
|
1
1
|
const f = typeof globalThis < "u" ? globalThis : typeof self < "u" ? self : typeof window < "u" ? window : Function("return this")();
|
|
2
|
-
function
|
|
2
|
+
function C() {
|
|
3
3
|
return f;
|
|
4
4
|
}
|
|
5
5
|
function m(e) {
|
|
6
6
|
return typeof e == "function";
|
|
7
7
|
}
|
|
8
|
-
function
|
|
8
|
+
function U(e) {
|
|
9
9
|
return typeof e == "object" && e !== null;
|
|
10
10
|
}
|
|
11
|
-
function
|
|
12
|
-
return "wx" in f &&
|
|
11
|
+
function P() {
|
|
12
|
+
return "wx" in f && U(f.wx) && "getSystemInfo" in f.wx && m(f.wx.getSystemInfo);
|
|
13
13
|
}
|
|
14
|
-
function
|
|
14
|
+
function we() {
|
|
15
15
|
return "fetch" in f && m(f.fetch);
|
|
16
16
|
}
|
|
17
|
-
function
|
|
18
|
-
return "window" in f &&
|
|
17
|
+
function be() {
|
|
18
|
+
return "window" in f && U(f.window) && !P();
|
|
19
19
|
}
|
|
20
|
-
function
|
|
20
|
+
function R() {
|
|
21
21
|
return "Blob" in f && m(f.Blob);
|
|
22
22
|
}
|
|
23
|
-
function
|
|
23
|
+
function M() {
|
|
24
24
|
return "FormData" in f && m(f.FormData);
|
|
25
25
|
}
|
|
26
|
-
function
|
|
26
|
+
function O() {
|
|
27
27
|
return "TextDecoder" in f && m(f.TextDecoder);
|
|
28
28
|
}
|
|
29
|
-
function
|
|
29
|
+
function Ee() {
|
|
30
30
|
return "AbortController" in f && m(f.AbortController);
|
|
31
31
|
}
|
|
32
|
-
function
|
|
32
|
+
function q() {
|
|
33
33
|
return "URLSearchParams" in f && m(f.URLSearchParams);
|
|
34
34
|
}
|
|
35
|
-
function
|
|
35
|
+
function H(e) {
|
|
36
36
|
return new Promise((t) => setTimeout(t, Math.min(Number.MAX_SAFE_INTEGER, Math.max(0, e))));
|
|
37
37
|
}
|
|
38
38
|
// @__NO_SIDE_EFFECTS__
|
|
39
|
-
function
|
|
39
|
+
function N(e) {
|
|
40
40
|
const t = e || "CustomError";
|
|
41
41
|
return class extends Error {
|
|
42
|
-
constructor(
|
|
43
|
-
super(
|
|
42
|
+
constructor(n) {
|
|
43
|
+
super(n), Object.defineProperty(this, "name", {
|
|
44
44
|
value: t,
|
|
45
45
|
enumerable: !1,
|
|
46
46
|
configurable: !0
|
|
@@ -48,40 +48,40 @@ function I(e) {
|
|
|
48
48
|
}
|
|
49
49
|
};
|
|
50
50
|
}
|
|
51
|
-
const
|
|
51
|
+
const I = /^(?:https?:)?\/\/.+$/i, G = /^https?:\/\/.+$/i, K = /^\{[\d\D]*\}$/, _ = /^\[[\d\D]*\]$/;
|
|
52
52
|
function $(e, t = !1) {
|
|
53
|
-
return t ?
|
|
53
|
+
return t ? I.test(e) : G.test(e);
|
|
54
54
|
}
|
|
55
|
-
function
|
|
55
|
+
function F(e) {
|
|
56
56
|
return e == null;
|
|
57
57
|
}
|
|
58
|
-
function
|
|
58
|
+
function A(e, ...t) {
|
|
59
59
|
if (!e || typeof e != "object") return !1;
|
|
60
|
-
const
|
|
61
|
-
return
|
|
60
|
+
const n = Object.getPrototypeOf(e);
|
|
61
|
+
return n !== Object.prototype && n !== null ? !1 : t.every((s) => s in e);
|
|
62
62
|
}
|
|
63
|
-
function
|
|
64
|
-
return
|
|
63
|
+
function S(e) {
|
|
64
|
+
return K.test(e) || _.test(e);
|
|
65
65
|
}
|
|
66
|
-
function
|
|
66
|
+
function E(e, t) {
|
|
67
67
|
try {
|
|
68
|
-
const
|
|
69
|
-
return t ? t(
|
|
68
|
+
const n = JSON.parse(e);
|
|
69
|
+
return t ? t(n) ? n : null : n;
|
|
70
70
|
} catch {
|
|
71
71
|
return null;
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
|
-
async function
|
|
74
|
+
async function Te(e) {
|
|
75
75
|
return await new Promise(function(t) {
|
|
76
|
-
const
|
|
76
|
+
const n = document.getElementsByTagName("head")[0], s = document.createElement("script");
|
|
77
77
|
s.setAttribute("type", "text/javascript"), s.setAttribute("charset", "utf-8"), s.onload = function() {
|
|
78
|
-
|
|
78
|
+
n.removeChild(s), t(!0);
|
|
79
79
|
}, s.onerror = function() {
|
|
80
|
-
|
|
81
|
-
}, s.setAttribute("src", e),
|
|
80
|
+
n.removeChild(s), t(!1);
|
|
81
|
+
}, s.setAttribute("src", e), n.appendChild(s);
|
|
82
82
|
});
|
|
83
83
|
}
|
|
84
|
-
function
|
|
84
|
+
function J(e, t = "数据未能正确识别") {
|
|
85
85
|
return typeof e == "function" ? {
|
|
86
86
|
guard: e,
|
|
87
87
|
message: t
|
|
@@ -90,52 +90,52 @@ function V(e, t = "数据未能正确识别") {
|
|
|
90
90
|
message: e.message || t
|
|
91
91
|
};
|
|
92
92
|
}
|
|
93
|
-
function
|
|
94
|
-
return !t || $(e, !0) ?
|
|
93
|
+
function V(e, t = "") {
|
|
94
|
+
return !t || $(e, !0) ? x(e) : (x(t) + "/" + e).replace(/\/{2,}/g, "/").replace(/:\//, "://");
|
|
95
95
|
}
|
|
96
|
-
function
|
|
97
|
-
const t =
|
|
96
|
+
function x(e) {
|
|
97
|
+
const t = C();
|
|
98
98
|
return $(e, !0) ? e.startsWith("http") ? e : ("location" in t ? location.protocol : "https:") + e : ("location" in t ? location.origin : "http://127.0.0.1") + "/" + e.replace(/^\/+/, "");
|
|
99
99
|
}
|
|
100
|
-
function
|
|
101
|
-
const
|
|
100
|
+
function W(e, t) {
|
|
101
|
+
const n = {};
|
|
102
102
|
return (e.match(/([^=&#?]+)=[^&#]*/g) || []).forEach(function(s) {
|
|
103
|
-
const
|
|
104
|
-
|
|
105
|
-
}), t !== !0 ?
|
|
103
|
+
const r = s.split("="), o = r[0], a = decodeURIComponent(r[1] || "");
|
|
104
|
+
n[o] !== void 0 ? n[o] += "," + a : n[o] = a;
|
|
105
|
+
}), t !== !0 ? n[t] || "" : n;
|
|
106
106
|
}
|
|
107
|
-
function
|
|
107
|
+
function X(e, t) {
|
|
108
108
|
if (t) {
|
|
109
109
|
if (t === !0)
|
|
110
110
|
return e.replace(/\?[^#]*/, "");
|
|
111
111
|
} else return e;
|
|
112
|
-
const
|
|
113
|
-
return !i.length || !o ?
|
|
112
|
+
const n = e.split("#"), s = n[0].split("?"), r = s[0], o = s.length > 1 ? s[1] : "", a = n.length > 1 ? "#" + n[1] : "", i = typeof t == "string" ? [t] : Array.isArray(t) ? t : [];
|
|
113
|
+
return !i.length || !o ? n[0] + a : (i.map((c) => c.replace(/([\\(){}[\]^$+\-*?|])/g, "\\$1")), (r + "?" + o.replace(new RegExp("(?:^|&)(?:" + i.join("|") + ")=[^&$]+", "g"), "").replace(/^&/, "")).replace(/\?$/, "") + a);
|
|
114
114
|
}
|
|
115
|
-
function
|
|
115
|
+
function z(e, t, n = !1) {
|
|
116
116
|
const s = typeof t == "string" ? t : Object.keys(t).map((a) => `${a}=${encodeURIComponent(t[a])}`).join("&");
|
|
117
117
|
if (!s)
|
|
118
118
|
return e;
|
|
119
|
-
const
|
|
120
|
-
|
|
121
|
-
|
|
119
|
+
const r = e.split("#");
|
|
120
|
+
n && (r[0] = X(
|
|
121
|
+
r[0],
|
|
122
122
|
(s.match(/([^=&#?]+)=[^&#]+/g) || []).map((a) => a.replace(/=.+$/, ""))
|
|
123
123
|
));
|
|
124
|
-
const o =
|
|
125
|
-
return (
|
|
124
|
+
const o = r[0].indexOf("?") + 1 ? "&" : "?";
|
|
125
|
+
return (r[0] + o + s + (r.length > 1 ? "#" + r[1] : "")).replace(/\?&/, "?");
|
|
126
126
|
}
|
|
127
|
-
function
|
|
127
|
+
function Q(e) {
|
|
128
128
|
const t = e.match(/(?:\?|&)([^=]+)(?:&|$)/g);
|
|
129
129
|
return t ? t.join("").replace(/(?:\?|^&+|&+$)/g, "").replace(/&{2}/g, "&").split("&").sort() : [];
|
|
130
130
|
}
|
|
131
|
-
class
|
|
131
|
+
class Y {
|
|
132
132
|
ttl;
|
|
133
133
|
cache;
|
|
134
134
|
timer = null;
|
|
135
135
|
// 定时循环以清理缓存
|
|
136
136
|
loopCheck() {
|
|
137
|
-
if (Object.keys(this.cache).forEach((
|
|
138
|
-
this.cache[
|
|
137
|
+
if (Object.keys(this.cache).forEach((n) => {
|
|
138
|
+
this.cache[n].ttl < Date.now() && delete this.cache[n];
|
|
139
139
|
}), Object.keys(this.cache).length === 0) {
|
|
140
140
|
this.timer = null;
|
|
141
141
|
return;
|
|
@@ -145,41 +145,41 @@ class Z {
|
|
|
145
145
|
constructor(t = 500) {
|
|
146
146
|
this.cache = {}, this.ttl = Math.max(t, 0), this.loopCheck = this.loopCheck.bind(this);
|
|
147
147
|
}
|
|
148
|
-
getKey(t,
|
|
149
|
-
if (t.toLowerCase() !== "get" && !
|
|
148
|
+
getKey(t, n, s, r) {
|
|
149
|
+
if (t.toLowerCase() !== "get" && !r)
|
|
150
150
|
return "";
|
|
151
|
-
const o = t.toLowerCase(), a =
|
|
152
|
-
if (
|
|
151
|
+
const o = t.toLowerCase(), a = n.replace(/#.+/, ""), i = a.replace(/\?.+/g, "");
|
|
152
|
+
if (r)
|
|
153
153
|
try {
|
|
154
|
-
const h =
|
|
154
|
+
const h = r() || "";
|
|
155
155
|
return h ? `${i}_${o}_${h}` : "";
|
|
156
156
|
} catch (h) {
|
|
157
|
-
return console.warn("[RequestCache] cacheResolve error",
|
|
157
|
+
return console.warn("[RequestCache] cacheResolve error", n, s, h), "";
|
|
158
158
|
}
|
|
159
|
-
const c = Object.assign(
|
|
159
|
+
const c = Object.assign(W(a, !0), s), l = Q(a), u = Object.keys(c).sort().map((h) => `${h}#${c[h]}`);
|
|
160
160
|
return `${i}_${o}_${u.join(",")}_${l.join(",")}`;
|
|
161
161
|
}
|
|
162
162
|
updateTTL(t) {
|
|
163
163
|
this.ttl = Math.max(t, 0);
|
|
164
164
|
}
|
|
165
|
-
get(t,
|
|
166
|
-
if (Math.max(
|
|
165
|
+
get(t, n) {
|
|
166
|
+
if (Math.max(n ?? this.ttl, 0) === 0)
|
|
167
167
|
return null;
|
|
168
|
-
const
|
|
169
|
-
return
|
|
170
|
-
}
|
|
171
|
-
set(t,
|
|
172
|
-
const
|
|
173
|
-
|
|
174
|
-
ttl: Date.now() +
|
|
175
|
-
res:
|
|
168
|
+
const r = this.cache[t];
|
|
169
|
+
return r ? r.ttl < Date.now() ? (delete this.cache[t], null) : r.res : null;
|
|
170
|
+
}
|
|
171
|
+
set(t, n, s) {
|
|
172
|
+
const r = Math.max(s ?? this.ttl, 0);
|
|
173
|
+
r !== 0 && (this.cache[t] = {
|
|
174
|
+
ttl: Date.now() + r,
|
|
175
|
+
res: n
|
|
176
176
|
}, this.timer === null && (this.timer = setTimeout(this.loopCheck, 5e3)));
|
|
177
177
|
}
|
|
178
178
|
del(t) {
|
|
179
179
|
this.cache[t] && delete this.cache[t];
|
|
180
180
|
}
|
|
181
181
|
}
|
|
182
|
-
class
|
|
182
|
+
class Z {
|
|
183
183
|
// 保存的配置需要部分字段强制设置默认值
|
|
184
184
|
config = {
|
|
185
185
|
baseURL: "/",
|
|
@@ -213,14 +213,14 @@ class ee {
|
|
|
213
213
|
}
|
|
214
214
|
/** 基于 baseURL 返回完整的 url 地址 */
|
|
215
215
|
getFullUrl(t) {
|
|
216
|
-
return
|
|
216
|
+
return V(t, this.config.baseURL);
|
|
217
217
|
}
|
|
218
218
|
/** 提示消息 */
|
|
219
|
-
showMessage(t,
|
|
220
|
-
this.config.messageHandler &&
|
|
219
|
+
showMessage(t, n, s, r) {
|
|
220
|
+
this.config.messageHandler && n && this.config.messageHandler(t, n, s, r);
|
|
221
221
|
}
|
|
222
222
|
}
|
|
223
|
-
const
|
|
223
|
+
const y = {
|
|
224
224
|
/** 响应数据校验失败 */
|
|
225
225
|
UnexpectResponse: "UnexpectResponse",
|
|
226
226
|
/** 请求被取消 */
|
|
@@ -234,53 +234,53 @@ const w = {
|
|
|
234
234
|
/** 请求方法不被支持,在微信小程序环境下有效 */
|
|
235
235
|
NotSupport: "NotSupport"
|
|
236
236
|
};
|
|
237
|
-
function
|
|
238
|
-
if (t.ok && !
|
|
239
|
-
const { guard:
|
|
240
|
-
return
|
|
237
|
+
function ee(e, t, n, s) {
|
|
238
|
+
if (t.ok && !F(t.data) && s) {
|
|
239
|
+
const { guard: r, message: o } = J(s, n.get("defaultTypeGuardMessage"));
|
|
240
|
+
return r(t.data) || (t.code = y.UnexpectResponse, n.showMessage(!0, `${e} ${o}`, t.code, t.status), console.error(t.code, e, t.data), t.data = null, t.message = o), t;
|
|
241
241
|
}
|
|
242
242
|
return t;
|
|
243
243
|
}
|
|
244
|
-
class
|
|
244
|
+
class ke {
|
|
245
245
|
agent;
|
|
246
246
|
config;
|
|
247
247
|
cache;
|
|
248
|
-
constructor(t,
|
|
249
|
-
this.config = new
|
|
248
|
+
constructor(t, n) {
|
|
249
|
+
this.config = new Z(n), this.agent = t, this.cache = new Y(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);
|
|
250
250
|
}
|
|
251
251
|
/** 发送网络请求,含有缓存控制逻辑,不含有 guard 逻辑 */
|
|
252
|
-
async send(t,
|
|
253
|
-
const s = this.cache.getKey(
|
|
252
|
+
async send(t, n) {
|
|
253
|
+
const s = this.cache.getKey(n?.method || "GET", t, n?.params, n?.cacheResolve);
|
|
254
254
|
if (s) {
|
|
255
|
-
const
|
|
256
|
-
if (
|
|
257
|
-
return await
|
|
255
|
+
const r = this.cache.get(s, n?.cacheTTL);
|
|
256
|
+
if (r)
|
|
257
|
+
return await r;
|
|
258
258
|
}
|
|
259
259
|
try {
|
|
260
|
-
const
|
|
261
|
-
s && this.cache.set(s,
|
|
262
|
-
const o = await
|
|
260
|
+
const r = this.agent(t, this.config, n);
|
|
261
|
+
s && this.cache.set(s, r, n?.cacheTTL);
|
|
262
|
+
const o = await r;
|
|
263
263
|
return (!o.ok || o.status < 0) && this.cache.del(s), o;
|
|
264
|
-
} catch (
|
|
265
|
-
return console.error("RequestError",
|
|
264
|
+
} catch (r) {
|
|
265
|
+
return console.error("RequestError", r), {
|
|
266
266
|
ok: !1,
|
|
267
267
|
status: -1,
|
|
268
|
-
code:
|
|
269
|
-
message:
|
|
268
|
+
code: y.Unknown,
|
|
269
|
+
message: r instanceof Error ? r.message : String(r),
|
|
270
270
|
headers: {},
|
|
271
271
|
data: null
|
|
272
272
|
};
|
|
273
273
|
}
|
|
274
274
|
}
|
|
275
275
|
async request(t) {
|
|
276
|
-
const
|
|
277
|
-
return
|
|
276
|
+
const n = await this.send(t.url, t.options);
|
|
277
|
+
return ee(t.url, n, this.config, t.guard ?? null);
|
|
278
278
|
}
|
|
279
279
|
/** 整理合并通用参数 */
|
|
280
|
-
gen(t,
|
|
280
|
+
gen(t, n, s, r, o) {
|
|
281
281
|
const a = Object.assign(
|
|
282
|
-
o ? { ...o, method:
|
|
283
|
-
|
|
282
|
+
o ? { ...o, method: n } : { method: n },
|
|
283
|
+
r ? { body: r } : null,
|
|
284
284
|
s ? { params: s } : null
|
|
285
285
|
);
|
|
286
286
|
return typeof t == "object" ? (a.params = t.params, { options: a, url: t.url }) : { options: a, url: t };
|
|
@@ -300,55 +300,62 @@ class Re {
|
|
|
300
300
|
/**
|
|
301
301
|
* 发送一个 HEAD 请求,并且不处理响应 body
|
|
302
302
|
*/
|
|
303
|
-
async head(t,
|
|
304
|
-
return this.request(this.gen(t, "HEAD",
|
|
303
|
+
async head(t, n, s) {
|
|
304
|
+
return this.request(this.gen(t, "HEAD", n, null, s));
|
|
305
305
|
}
|
|
306
|
-
async get(t,
|
|
307
|
-
const o = this.gen(t, "GET",
|
|
306
|
+
async get(t, n, s, r) {
|
|
307
|
+
const o = this.gen(t, "GET", n, null, r);
|
|
308
308
|
return s ? this.request({ ...o, guard: s }) : this.request(o);
|
|
309
309
|
}
|
|
310
|
-
async post(t,
|
|
311
|
-
const o = this.gen(t, "POST", null,
|
|
310
|
+
async post(t, n, s, r) {
|
|
311
|
+
const o = this.gen(t, "POST", null, n || {}, r);
|
|
312
312
|
return s ? this.request({ ...o, guard: s }) : this.request(o);
|
|
313
313
|
}
|
|
314
|
-
async del(t,
|
|
315
|
-
const o = this.gen(t, "DELETE",
|
|
314
|
+
async del(t, n, s, r) {
|
|
315
|
+
const o = this.gen(t, "DELETE", n, null, r);
|
|
316
316
|
return s ? this.request({ ...o, guard: s }) : this.request(o);
|
|
317
317
|
}
|
|
318
|
-
async put(t,
|
|
319
|
-
const o = this.gen(t, "PUT", null,
|
|
318
|
+
async put(t, n, s, r) {
|
|
319
|
+
const o = this.gen(t, "PUT", null, n || {}, r);
|
|
320
320
|
return s ? this.request({ ...o, guard: s }) : this.request(o);
|
|
321
321
|
}
|
|
322
|
-
async patch(t,
|
|
323
|
-
const o = this.gen(t, "PATCH", null,
|
|
322
|
+
async patch(t, n, s, r) {
|
|
323
|
+
const o = this.gen(t, "PATCH", null, n || {}, r);
|
|
324
324
|
return s ? this.request({ ...o, guard: s }) : this.request(o);
|
|
325
325
|
}
|
|
326
326
|
}
|
|
327
|
-
function
|
|
327
|
+
function te(e) {
|
|
328
328
|
const t = {};
|
|
329
|
-
for (const [
|
|
330
|
-
|
|
329
|
+
for (const [n, s] of e)
|
|
330
|
+
n && typeof n == "string" && (t[n] = s || "");
|
|
331
331
|
return t;
|
|
332
332
|
}
|
|
333
|
-
function
|
|
334
|
-
|
|
333
|
+
function se(e) {
|
|
334
|
+
const t = {};
|
|
335
|
+
return e && Object.keys(e).forEach((n) => {
|
|
336
|
+
const s = e[n], r = s == null ? "" : typeof s == "boolean" || typeof s == "number" ? String(s) : s;
|
|
337
|
+
r && (t[n] = r);
|
|
338
|
+
}), t;
|
|
335
339
|
}
|
|
336
|
-
function
|
|
337
|
-
return e
|
|
340
|
+
function L(e) {
|
|
341
|
+
return F(e) ? "" : typeof e == "string" ? e : e instanceof ArrayBuffer && O() ? new TextDecoder().decode(e) : JSON.stringify(e);
|
|
338
342
|
}
|
|
339
|
-
|
|
340
|
-
|
|
343
|
+
function ne(e) {
|
|
344
|
+
return e instanceof Error ? e : new Error(L(e));
|
|
345
|
+
}
|
|
346
|
+
async function Re(e) {
|
|
347
|
+
if (O())
|
|
341
348
|
return new TextEncoder().encode(e).buffer;
|
|
342
|
-
if (
|
|
349
|
+
if (R())
|
|
343
350
|
return await new Blob([e]).arrayBuffer();
|
|
344
351
|
throw new Error("cannot convert string to ArrayBuffer");
|
|
345
352
|
}
|
|
346
|
-
function
|
|
347
|
-
if ("URL" in
|
|
353
|
+
function re(e, t) {
|
|
354
|
+
if ("URL" in C()) {
|
|
348
355
|
const s = new URL(e);
|
|
349
|
-
return Object.keys(t).forEach((
|
|
356
|
+
return Object.keys(t).forEach((r) => s.searchParams.set(r, t[r])), s.toString();
|
|
350
357
|
}
|
|
351
|
-
return
|
|
358
|
+
return z(e, t);
|
|
352
359
|
}
|
|
353
360
|
function oe(e) {
|
|
354
361
|
return typeof e == "function" ? e : Array.isArray(e) && e.length > 0 ? function(t) {
|
|
@@ -356,109 +363,98 @@ function oe(e) {
|
|
|
356
363
|
} : e === "network" ? ae : ce;
|
|
357
364
|
}
|
|
358
365
|
function ae({ error: e }) {
|
|
359
|
-
return e ===
|
|
366
|
+
return e === y.NetworkError;
|
|
360
367
|
}
|
|
361
|
-
function ce({ status: e, headers: t, error:
|
|
362
|
-
return
|
|
368
|
+
function ce({ status: e, headers: t, error: n }) {
|
|
369
|
+
return n === y.NetworkError ? !0 : t?.server === "TencentEdgeOne" ? e === 522 || e === 552 : !1;
|
|
363
370
|
}
|
|
364
|
-
async function $e(e, t,
|
|
365
|
-
const s =
|
|
371
|
+
async function $e(e, t, n) {
|
|
372
|
+
const s = { ...n, method: n?.method || "GET" }, r = M() ? s.body instanceof FormData : !1, o = r && s.method !== "POST" && s.method !== "PUT" ? "POST" : s.method, a = o === "GET" || o === "HEAD" || o === "DELETE";
|
|
366
373
|
a && s.body !== void 0 && (console.warn("request body is invalid with method get, head, delete"), delete s.body);
|
|
367
|
-
const i =
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
})
|
|
376
|
-
|
|
377
|
-
const y = t.get("requestTransformer");
|
|
378
|
-
if (y)
|
|
379
|
-
return await y({ headers: i, params: l, method: o, url: u, body: h });
|
|
380
|
-
})(), g = ne(typeof d == "string" && d ? d : u, l);
|
|
381
|
-
return t.get("logHandler")?.({ type: "ready", url: g, method: o, headers: i, timeout: p, body: h }), {
|
|
382
|
-
url: g,
|
|
374
|
+
const i = r || a ? { ...s.headers } : {
|
|
375
|
+
"Content-Type": R() && s.body instanceof Blob ? s.body.type || "application/octet-stream" : "application/json;charset=utf-8",
|
|
376
|
+
...s.headers
|
|
377
|
+
}, c = t.getFullUrl(e), l = se(s.params), u = ie(s.body), h = s.timeout || t.get("timeout"), p = await (async function() {
|
|
378
|
+
const g = t.get("requestTransformer");
|
|
379
|
+
if (g)
|
|
380
|
+
return await g({ headers: i, params: l, method: o, url: c, body: u });
|
|
381
|
+
})(), d = re(typeof p == "string" && p ? p : c, l);
|
|
382
|
+
return t.get("logHandler")?.({ type: "ready", url: d, method: o, headers: i, timeout: h, body: u }), {
|
|
383
|
+
url: d,
|
|
383
384
|
method: o,
|
|
384
|
-
body:
|
|
385
|
+
body: u,
|
|
385
386
|
headers: i,
|
|
386
|
-
timeout:
|
|
387
|
+
timeout: h,
|
|
387
388
|
abort: s.abort,
|
|
388
389
|
asBuffer: !!s.asBuffer,
|
|
389
390
|
credentials: s.credentials || t.get("credentials")
|
|
390
391
|
};
|
|
391
392
|
}
|
|
392
393
|
function ie(e) {
|
|
393
|
-
return x(e) ? "" : typeof e == "string" ? e : typeof e == "number" || typeof e == "boolean" ? String(e) : Array.isArray(e) ? e.filter(
|
|
394
|
-
(r) => r != null && typeof r != "object" && typeof r != "function"
|
|
395
|
-
).join(",") : (console.warn("参数类型不支持,已被过滤", typeof e, e), "");
|
|
396
|
-
}
|
|
397
|
-
function ue(e) {
|
|
398
394
|
if (e)
|
|
399
|
-
return typeof e == "string" ||
|
|
395
|
+
return typeof e == "string" || q() && e instanceof URLSearchParams || e instanceof ArrayBuffer || R() && e instanceof Blob || M() && e instanceof FormData ? e : JSON.stringify(e);
|
|
400
396
|
}
|
|
401
|
-
const
|
|
402
|
-
function
|
|
403
|
-
return
|
|
397
|
+
const B = "data", w = "message";
|
|
398
|
+
function ue(e, t, n) {
|
|
399
|
+
return D(e.status) ? fe(n?.ok || t.ok, e) : he(n?.failed || t.failed, e);
|
|
404
400
|
}
|
|
405
|
-
function
|
|
401
|
+
function fe(e, { statusText: t, body: n }) {
|
|
406
402
|
const s = {
|
|
407
403
|
ok: !0,
|
|
408
404
|
code: t,
|
|
409
405
|
message: "",
|
|
410
406
|
data: null
|
|
411
407
|
};
|
|
412
|
-
if (!
|
|
408
|
+
if (!n)
|
|
413
409
|
return s;
|
|
414
|
-
if (typeof
|
|
415
|
-
return s.data =
|
|
410
|
+
if (typeof n != "string")
|
|
411
|
+
return s.data = n, s;
|
|
416
412
|
if (e.resolve === "body")
|
|
417
|
-
return s.data =
|
|
418
|
-
const
|
|
419
|
-
if (!
|
|
413
|
+
return s.data = S(n) ? T(E(n), e.converter) : n, s;
|
|
414
|
+
const r = E(n);
|
|
415
|
+
if (!r)
|
|
420
416
|
return s.ok = !1, s.code = "ResponseFormatError", s.message = "响应内容无法解析为 json", s;
|
|
421
|
-
const o =
|
|
422
|
-
if (!o || !
|
|
417
|
+
const o = T(r, e.converter);
|
|
418
|
+
if (!o || !A(o))
|
|
423
419
|
return s.ok = !1, s.code = "ResponseFormatError", s.message = "响应内容无法格式化为 object", s;
|
|
424
420
|
const a = e.statusField;
|
|
425
421
|
if (a && !(a in o))
|
|
426
422
|
return s.ok = !1, s.code = "ResponseFieldMissing", s.message = `响应内容找不到状态字段 ${a}`, s;
|
|
427
|
-
const i = e.statusOKValue || "", c = e.dataField ||
|
|
428
|
-
return s.ok = a ? u === i : !0, s.code = u || s.code, s.data = c === !0 ? o : c in o ? o[c] : null, s.message =
|
|
423
|
+
const i = e.statusOKValue || "", c = e.dataField || B, l = e.messageField || w, u = a ? String(o[a] ?? "") : "";
|
|
424
|
+
return s.ok = a ? u === i : !0, s.code = u || s.code, s.data = c === !0 ? o : c in o ? o[c] : null, s.message = k(o, l), e.ignoreMessage && s.message && (Array.isArray(e.ignoreMessage) ? e.ignoreMessage.includes(s.message) : e.ignoreMessage === s.message) && (s.message = ""), s;
|
|
429
425
|
}
|
|
430
|
-
function
|
|
431
|
-
const
|
|
426
|
+
function he(e, { statusText: t, body: n, error: s }) {
|
|
427
|
+
const r = typeof n == "string" ? n : "", o = {
|
|
432
428
|
ok: !1,
|
|
433
429
|
code: s || t,
|
|
434
|
-
message:
|
|
430
|
+
message: r,
|
|
435
431
|
data: null
|
|
436
432
|
};
|
|
437
433
|
switch (e.resolve) {
|
|
438
434
|
case "body":
|
|
439
|
-
o.message =
|
|
435
|
+
o.message = j(r) || r;
|
|
440
436
|
break;
|
|
441
437
|
case "json":
|
|
442
|
-
const { code: a, message: i } =
|
|
443
|
-
o.code = a || s || t, o.message =
|
|
438
|
+
const { code: a, message: i } = le(r, e.converter, e.statusField, e.messageField);
|
|
439
|
+
o.code = a || s || t, o.message = j(r) || i;
|
|
444
440
|
break;
|
|
445
441
|
}
|
|
446
442
|
return o;
|
|
447
443
|
}
|
|
448
|
-
function
|
|
444
|
+
function D(e) {
|
|
449
445
|
return e >= 200 && e < 400;
|
|
450
446
|
}
|
|
451
|
-
function
|
|
447
|
+
function T(e, t) {
|
|
452
448
|
return t && typeof t == "function" ? t(e) : e;
|
|
453
449
|
}
|
|
454
450
|
const xe = function(e) {
|
|
455
|
-
const t = [],
|
|
456
|
-
switch (t.push("- 当http状态码 <200 或者 >=400 时"),
|
|
451
|
+
const t = [], n = e.failed || { resolve: "json" };
|
|
452
|
+
switch (t.push("- 当http状态码 <200 或者 >=400 时"), n.resolve) {
|
|
457
453
|
case "body":
|
|
458
454
|
t.push(" 将响应内容格式化为字符串并作为错误消息");
|
|
459
455
|
break;
|
|
460
456
|
case "json":
|
|
461
|
-
t.push(" 将响应解析为json,并读取 " + (
|
|
457
|
+
t.push(" 将响应解析为json,并读取 " + (n.messageField || w) + " 作为错误消息");
|
|
462
458
|
break;
|
|
463
459
|
}
|
|
464
460
|
const s = e.ok || { resolve: "body" };
|
|
@@ -468,7 +464,7 @@ const xe = function(e) {
|
|
|
468
464
|
break;
|
|
469
465
|
case "json":
|
|
470
466
|
t.push(
|
|
471
|
-
" 将响应解析为 json,读取 " + (s.dataField ||
|
|
467
|
+
" 将响应解析为 json,读取 " + (s.dataField || B) + " 作为响应数据,读取 " + (s.messageField || w) + " 作为提示消息"
|
|
472
468
|
), s.statusField && t.push(
|
|
473
469
|
" 当 " + s.statusField + " 为 " + (s.statusOKValue || "空值") + " 时是成功提示,否则是错误消息"
|
|
474
470
|
), s.ignoreMessage && t.push(" 并忽略以下消息:" + s.ignoreMessage);
|
|
@@ -477,39 +473,39 @@ const xe = function(e) {
|
|
|
477
473
|
return t.join(`
|
|
478
474
|
`);
|
|
479
475
|
};
|
|
480
|
-
function
|
|
481
|
-
if (!
|
|
476
|
+
function le(e, t, n, s = w) {
|
|
477
|
+
if (!S(e))
|
|
482
478
|
return { message: "" };
|
|
483
|
-
const
|
|
484
|
-
return !
|
|
485
|
-
code:
|
|
486
|
-
message:
|
|
479
|
+
const r = T(E(e), t);
|
|
480
|
+
return !r || !A(r) ? { message: e } : {
|
|
481
|
+
code: n ? k(r, n) : "",
|
|
482
|
+
message: k(r, s) || e
|
|
487
483
|
};
|
|
488
484
|
}
|
|
489
|
-
function
|
|
490
|
-
const
|
|
491
|
-
for (const s of
|
|
485
|
+
function k(e, t) {
|
|
486
|
+
const n = Array.isArray(t) ? t : [t];
|
|
487
|
+
for (const s of n)
|
|
492
488
|
if (s in e)
|
|
493
|
-
return
|
|
489
|
+
return L(e[s]);
|
|
494
490
|
return "";
|
|
495
491
|
}
|
|
496
|
-
const
|
|
497
|
-
function
|
|
498
|
-
for (const t of
|
|
499
|
-
const
|
|
500
|
-
if (
|
|
501
|
-
return
|
|
492
|
+
const de = [/<title>([^<]+)<\/title>/i, /<message>([^<]+)<\/message>/i];
|
|
493
|
+
function j(e) {
|
|
494
|
+
for (const t of de) {
|
|
495
|
+
const n = e.match(t);
|
|
496
|
+
if (n)
|
|
497
|
+
return n[1];
|
|
502
498
|
}
|
|
503
499
|
return "";
|
|
504
500
|
}
|
|
505
|
-
const
|
|
506
|
-
function
|
|
501
|
+
const ge = /* @__PURE__ */ N("APIError");
|
|
502
|
+
function pe(e) {
|
|
507
503
|
const t = {};
|
|
508
|
-
for (const
|
|
509
|
-
(
|
|
510
|
-
const
|
|
504
|
+
for (const r in e.headers)
|
|
505
|
+
(r.startsWith("x-") || r.includes("trace") || r.includes("server") || r.includes("status") || /\b(?:id|uuid)\b/.test(r)) && (t[r] = e.headers[r]);
|
|
506
|
+
const n = e.url.replace(/^(?:https?:)?\/*/i, "").replace(/\?.+/, ""), s = e.status < 0 ? "unknown" : e.status;
|
|
511
507
|
return {
|
|
512
|
-
sentryError: new
|
|
508
|
+
sentryError: new ge(`${n}${s === "unknown" ? "" : ` | ${s}`} | ${e.code}`),
|
|
513
509
|
sentryTags: {
|
|
514
510
|
...t,
|
|
515
511
|
status: s,
|
|
@@ -525,35 +521,35 @@ function me(e) {
|
|
|
525
521
|
}
|
|
526
522
|
};
|
|
527
523
|
}
|
|
528
|
-
async function
|
|
524
|
+
async function je(e, t) {
|
|
529
525
|
if (e.method === "HEAD" || e.status === 204)
|
|
530
526
|
return e.body = null, e;
|
|
531
527
|
try {
|
|
532
528
|
e.body = t.asBuffer ? await t.buffer() : await t.text();
|
|
533
|
-
} catch (
|
|
534
|
-
e.body = null, e.error =
|
|
529
|
+
} catch (n) {
|
|
530
|
+
e.body = null, e.error = y.Unknown, e.rawError = ne(n);
|
|
535
531
|
}
|
|
536
532
|
return e;
|
|
537
533
|
}
|
|
538
|
-
function
|
|
539
|
-
const
|
|
534
|
+
function ve(e, t, n, s) {
|
|
535
|
+
const r = e.status, o = e.method, a = te(
|
|
540
536
|
Object.entries(e.headers || {}).map(([d, g]) => [d.toLowerCase(), g])
|
|
541
|
-
), { ok: i, code: c, data: l, message: u } =
|
|
542
|
-
if (!
|
|
543
|
-
const d =
|
|
537
|
+
), { ok: i, code: c, data: l, message: u } = ue(e, n.get("responseRule"), s?.responseRule);
|
|
538
|
+
if (!D(r)) {
|
|
539
|
+
const d = pe({
|
|
544
540
|
url: e.url,
|
|
545
541
|
method: e.method,
|
|
546
|
-
status:
|
|
542
|
+
status: r,
|
|
547
543
|
code: c,
|
|
548
544
|
message: u,
|
|
549
545
|
body: e.body,
|
|
550
546
|
headers: a,
|
|
551
547
|
error: e.rawError
|
|
552
548
|
});
|
|
553
|
-
(
|
|
549
|
+
(n.get("errorHandler") || me)({
|
|
554
550
|
url: t,
|
|
555
551
|
method: o,
|
|
556
|
-
status:
|
|
552
|
+
status: r,
|
|
557
553
|
code: c,
|
|
558
554
|
message: u,
|
|
559
555
|
headers: a,
|
|
@@ -561,39 +557,39 @@ function Oe(e, t, r, s) {
|
|
|
561
557
|
...d
|
|
562
558
|
});
|
|
563
559
|
}
|
|
564
|
-
if (
|
|
565
|
-
return
|
|
566
|
-
{ ok: !1, status:
|
|
560
|
+
if (r < 0)
|
|
561
|
+
return v(
|
|
562
|
+
{ ok: !1, status: r, code: e.statusText, headers: {}, message: "", data: null },
|
|
567
563
|
`${o} ${t} ${e.statusText}`,
|
|
568
564
|
o,
|
|
569
565
|
t,
|
|
570
|
-
|
|
566
|
+
n,
|
|
571
567
|
s
|
|
572
568
|
);
|
|
573
|
-
const h = { ok: i, data: l, code: c, message: u, status:
|
|
574
|
-
|
|
569
|
+
const h = { ok: i, data: l, code: c, message: u, status: r, headers: a };
|
|
570
|
+
n.get("responseHandler")?.({ ...h }, o, t);
|
|
575
571
|
const p = i ? u : u || e.statusText;
|
|
576
|
-
return
|
|
572
|
+
return v(h, p, o, t, n, s);
|
|
577
573
|
}
|
|
578
|
-
function
|
|
579
|
-
const a =
|
|
574
|
+
function v(e, t, n, s, r, o) {
|
|
575
|
+
const a = r.get("message"), i = a === !1 || o?.message === !1 ? !1 : o?.message || a;
|
|
580
576
|
if (i !== !1) {
|
|
581
|
-
const c = typeof i == "function" ? i(e,
|
|
582
|
-
c instanceof Error ?
|
|
577
|
+
const c = typeof i == "function" ? i(e, n, s, t) : t;
|
|
578
|
+
c instanceof Error ? r.showMessage(!0, b(c.message), e.code, e.status) : c && typeof c == "object" && "message" in c && typeof c.message == "string" ? r.showMessage(!1, b(c.message), e.code, e.status) : c && r.showMessage(!e.ok, b(String(c)), e.code, e.status);
|
|
583
579
|
}
|
|
584
580
|
return e;
|
|
585
581
|
}
|
|
586
|
-
function
|
|
582
|
+
function me(e) {
|
|
587
583
|
const t = {};
|
|
588
|
-
for (const
|
|
589
|
-
|
|
584
|
+
for (const n in e)
|
|
585
|
+
n.startsWith("sentry") || (t[n] = e[n]);
|
|
590
586
|
console.error("RequestError", t);
|
|
591
587
|
}
|
|
592
|
-
function
|
|
588
|
+
function b(e) {
|
|
593
589
|
return e.replace(/<script[\s\S]*?>[\s\S]*?<\/script>/gi, "").replace(/<[^>]+>/g, "").trim();
|
|
594
590
|
}
|
|
595
|
-
async function
|
|
596
|
-
const o =
|
|
591
|
+
async function ye(e, t, n, s, r) {
|
|
592
|
+
const o = r || 0, a = Math.max(0, Math.min(10, s?.maxRetry ?? n.get("maxRetry") ?? 0)), i = oe(s?.retryResolve ?? n.get("retryResolve")), c = n.get("logHandler");
|
|
597
593
|
c?.({
|
|
598
594
|
type: "prepare",
|
|
599
595
|
url: t,
|
|
@@ -604,7 +600,7 @@ async function we(e, t, r, s, n) {
|
|
|
604
600
|
headers: s?.headers,
|
|
605
601
|
options: s
|
|
606
602
|
});
|
|
607
|
-
const l = Date.now(), u = await e(t,
|
|
603
|
+
const l = Date.now(), u = await e(t, n, s), h = u.status, p = Date.now() - l, d = `[cost ${p}][${h}] ${h < 0 ? u.body : ""}`;
|
|
608
604
|
if (c?.({
|
|
609
605
|
type: "finished",
|
|
610
606
|
url: t,
|
|
@@ -617,30 +613,31 @@ async function we(e, t, r, s, n) {
|
|
|
617
613
|
cost: p
|
|
618
614
|
}), !a || o >= a || i(u, o) !== !0)
|
|
619
615
|
return u;
|
|
620
|
-
const g = s?.retryInterval ??
|
|
621
|
-
return await
|
|
616
|
+
const g = s?.retryInterval ?? n.get("retryInterval") ?? 100;
|
|
617
|
+
return await H(
|
|
622
618
|
Math.max(
|
|
623
619
|
100,
|
|
624
620
|
g === "2EB" ? Math.pow(2, o) * 100 : typeof g == "function" ? g(o + 1, { url: t, status: h, method: u.method }) || 0 : g
|
|
625
621
|
)
|
|
626
|
-
), await
|
|
622
|
+
), await ye(e, t, n, s, o + 1);
|
|
627
623
|
}
|
|
628
624
|
export {
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
625
|
+
P as E,
|
|
626
|
+
Z as G,
|
|
627
|
+
z as H,
|
|
628
|
+
ke as N,
|
|
629
|
+
y as R,
|
|
630
|
+
we as X,
|
|
631
|
+
Re as a,
|
|
632
|
+
se as b,
|
|
637
633
|
$e as c,
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
634
|
+
be as d,
|
|
635
|
+
te as e,
|
|
636
|
+
je as f,
|
|
641
637
|
xe as g,
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
638
|
+
ve as h,
|
|
639
|
+
Ee as i,
|
|
640
|
+
ye as r,
|
|
641
|
+
L as t,
|
|
642
|
+
Te as v
|
|
646
643
|
};
|
package/dist/wx.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { h as l, r as p, c as y, E as R, R as u, f as x, a as h, t as c, N as w } from "./retry
|
|
2
|
-
import { g as O } from "./retry
|
|
1
|
+
import { h as l, r as p, c as y, E as R, R as u, f as x, a as h, t as c, N as w } from "./retry--akoKQtX.js";
|
|
2
|
+
import { g as O } from "./retry--akoKQtX.js";
|
|
3
3
|
const m = async function(s, o, n) {
|
|
4
4
|
return l(await p(q, s, o, n), s, o, n);
|
|
5
5
|
}, q = async function(s, o, n) {
|
package/package.json
CHANGED
package/types/inc/type.d.ts
CHANGED
|
@@ -17,7 +17,7 @@ export declare const RequestInternalError: {
|
|
|
17
17
|
};
|
|
18
18
|
export type RequestInternalError = (typeof RequestInternalError)[keyof typeof RequestInternalError];
|
|
19
19
|
export type RequestMethod = "GET" | "POST" | "PUT" | "DELETE" | "PATCH" | "HEAD";
|
|
20
|
-
export type RequestQueryParams = Record<string, string | number | boolean>;
|
|
20
|
+
export type RequestQueryParams = Record<string, string | number | boolean | null | undefined>;
|
|
21
21
|
/** 通用网络请求工具的基本配置 */
|
|
22
22
|
export interface BaseRequestOptions {
|
|
23
23
|
/** 网络请求方法,默认 GET */
|
package/types/inc/utils.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { RetryResolve, RetryResolveFunc } from "./type";
|
|
1
|
+
import { RetryResolve, RetryResolveFunc, RequestQueryParams } from "./type";
|
|
2
2
|
/** 简版 Object.fromEntries 以处理某些低版本浏览器和 webview 的问题 */
|
|
3
3
|
export declare function fromEntries(kv: [string, string | undefined][]): Record<string, string>;
|
|
4
|
+
export declare function convertParams(params?: RequestQueryParams): Record<string, string>;
|
|
4
5
|
export declare function toString(data: unknown): string;
|
|
5
6
|
export declare function convertError(e: unknown): Error;
|
|
6
7
|
export declare function convertStringToArrayBuffer(content: string): Promise<ArrayBuffer>;
|