@seayoo-web/request 4.0.0 → 4.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +31 -31
- package/dist/node.js +3 -3
- package/dist/{request.fetch-BNCxK4Wq.js → request.fetch-U2PiTmEn.js} +1 -1
- package/dist/{retry-DRbCcUt8.js → retry-b0Etywu_.js} +249 -250
- 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-b0Etywu_.js";
|
|
2
|
+
import { g as W } from "./retry-b0Etywu_.js";
|
|
3
|
+
import { f as S } from "./request.fetch-U2PiTmEn.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-b0Etywu_.js";
|
|
2
|
+
import { g as S } from "./retry-b0Etywu_.js";
|
|
3
|
+
import { f as x } from "./request.fetch-U2PiTmEn.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-b0Etywu_.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 O(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 && O(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 && O(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 U() {
|
|
24
24
|
return "FormData" in f && m(f.FormData);
|
|
25
25
|
}
|
|
26
|
-
function
|
|
26
|
+
function M() {
|
|
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) ? j(e) : (j(t) + "/" + e).replace(/\/{2,}/g, "/").replace(/:\//, "://");
|
|
95
95
|
}
|
|
96
|
-
function
|
|
97
|
-
const t =
|
|
96
|
+
function j(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;
|
|
339
|
+
}
|
|
340
|
+
function L(e) {
|
|
341
|
+
return F(e) ? "" : typeof e == "string" ? e : e instanceof ArrayBuffer && M() ? new TextDecoder().decode(e) : JSON.stringify(e);
|
|
335
342
|
}
|
|
336
|
-
function
|
|
337
|
-
return e instanceof Error ? e : new Error(
|
|
343
|
+
function ne(e) {
|
|
344
|
+
return e instanceof Error ? e : new Error(L(e));
|
|
338
345
|
}
|
|
339
|
-
async function
|
|
340
|
-
if (
|
|
346
|
+
async function Re(e) {
|
|
347
|
+
if (M())
|
|
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,100 @@ 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 = Object.assign({ method: "GET" },
|
|
371
|
+
async function $e(e, t, n) {
|
|
372
|
+
const s = Object.assign({ method: "GET" }, n), r = U() ? 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
374
|
const i = Object.assign(
|
|
368
|
-
|
|
369
|
-
"Content-Type":
|
|
375
|
+
r || a ? {} : {
|
|
376
|
+
"Content-Type": R() && s.body instanceof Blob ? s.body.type || "application/octet-stream" : "application/json;charset=utf-8"
|
|
370
377
|
},
|
|
371
378
|
s.headers
|
|
372
|
-
), c = s.params ||
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
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,
|
|
379
|
+
), c = t.getFullUrl(e), l = se(s.params), u = ie(s.body), h = s.timeout || t.get("timeout"), p = await (async function() {
|
|
380
|
+
const g = t.get("requestTransformer");
|
|
381
|
+
if (g)
|
|
382
|
+
return await g({ headers: i, params: l, method: o, url: c, body: u });
|
|
383
|
+
})(), d = re(typeof p == "string" && p ? p : c, l);
|
|
384
|
+
return t.get("logHandler")?.({ type: "ready", url: d, method: o, headers: i, timeout: h, body: u }), {
|
|
385
|
+
url: d,
|
|
383
386
|
method: o,
|
|
384
|
-
body:
|
|
387
|
+
body: u,
|
|
385
388
|
headers: i,
|
|
386
|
-
timeout:
|
|
389
|
+
timeout: h,
|
|
387
390
|
abort: s.abort,
|
|
388
391
|
asBuffer: !!s.asBuffer,
|
|
389
392
|
credentials: s.credentials || t.get("credentials")
|
|
390
393
|
};
|
|
391
394
|
}
|
|
392
395
|
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
396
|
if (e)
|
|
399
|
-
return typeof e == "string" ||
|
|
397
|
+
return typeof e == "string" || q() && e instanceof URLSearchParams || e instanceof ArrayBuffer || R() && e instanceof Blob || U() && e instanceof FormData ? e : JSON.stringify(e);
|
|
400
398
|
}
|
|
401
|
-
const
|
|
402
|
-
function
|
|
403
|
-
return
|
|
399
|
+
const B = "data", w = "message";
|
|
400
|
+
function ue(e, t, n) {
|
|
401
|
+
return D(e.status) ? fe(n?.ok || t.ok, e) : he(n?.failed || t.failed, e);
|
|
404
402
|
}
|
|
405
|
-
function
|
|
403
|
+
function fe(e, { statusText: t, body: n }) {
|
|
406
404
|
const s = {
|
|
407
405
|
ok: !0,
|
|
408
406
|
code: t,
|
|
409
407
|
message: "",
|
|
410
408
|
data: null
|
|
411
409
|
};
|
|
412
|
-
if (!
|
|
410
|
+
if (!n)
|
|
413
411
|
return s;
|
|
414
|
-
if (typeof
|
|
415
|
-
return s.data =
|
|
412
|
+
if (typeof n != "string")
|
|
413
|
+
return s.data = n, s;
|
|
416
414
|
if (e.resolve === "body")
|
|
417
|
-
return s.data =
|
|
418
|
-
const
|
|
419
|
-
if (!
|
|
415
|
+
return s.data = S(n) ? T(E(n), e.converter) : n, s;
|
|
416
|
+
const r = E(n);
|
|
417
|
+
if (!r)
|
|
420
418
|
return s.ok = !1, s.code = "ResponseFormatError", s.message = "响应内容无法解析为 json", s;
|
|
421
|
-
const o =
|
|
422
|
-
if (!o || !
|
|
419
|
+
const o = T(r, e.converter);
|
|
420
|
+
if (!o || !A(o))
|
|
423
421
|
return s.ok = !1, s.code = "ResponseFormatError", s.message = "响应内容无法格式化为 object", s;
|
|
424
422
|
const a = e.statusField;
|
|
425
423
|
if (a && !(a in o))
|
|
426
424
|
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 =
|
|
425
|
+
const i = e.statusOKValue || "", c = e.dataField || B, l = e.messageField || w, u = a ? String(o[a] ?? "") : "";
|
|
426
|
+
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
427
|
}
|
|
430
|
-
function
|
|
431
|
-
const
|
|
428
|
+
function he(e, { statusText: t, body: n, error: s }) {
|
|
429
|
+
const r = typeof n == "string" ? n : "", o = {
|
|
432
430
|
ok: !1,
|
|
433
431
|
code: s || t,
|
|
434
|
-
message:
|
|
432
|
+
message: r,
|
|
435
433
|
data: null
|
|
436
434
|
};
|
|
437
435
|
switch (e.resolve) {
|
|
438
436
|
case "body":
|
|
439
|
-
o.message =
|
|
437
|
+
o.message = x(r) || r;
|
|
440
438
|
break;
|
|
441
439
|
case "json":
|
|
442
|
-
const { code: a, message: i } =
|
|
443
|
-
o.code = a || s || t, o.message =
|
|
440
|
+
const { code: a, message: i } = le(r, e.converter, e.statusField, e.messageField);
|
|
441
|
+
o.code = a || s || t, o.message = x(r) || i;
|
|
444
442
|
break;
|
|
445
443
|
}
|
|
446
444
|
return o;
|
|
447
445
|
}
|
|
448
|
-
function
|
|
446
|
+
function D(e) {
|
|
449
447
|
return e >= 200 && e < 400;
|
|
450
448
|
}
|
|
451
|
-
function
|
|
449
|
+
function T(e, t) {
|
|
452
450
|
return t && typeof t == "function" ? t(e) : e;
|
|
453
451
|
}
|
|
454
|
-
const
|
|
455
|
-
const t = [],
|
|
456
|
-
switch (t.push("- 当http状态码 <200 或者 >=400 时"),
|
|
452
|
+
const je = function(e) {
|
|
453
|
+
const t = [], n = e.failed || { resolve: "json" };
|
|
454
|
+
switch (t.push("- 当http状态码 <200 或者 >=400 时"), n.resolve) {
|
|
457
455
|
case "body":
|
|
458
456
|
t.push(" 将响应内容格式化为字符串并作为错误消息");
|
|
459
457
|
break;
|
|
460
458
|
case "json":
|
|
461
|
-
t.push(" 将响应解析为json,并读取 " + (
|
|
459
|
+
t.push(" 将响应解析为json,并读取 " + (n.messageField || w) + " 作为错误消息");
|
|
462
460
|
break;
|
|
463
461
|
}
|
|
464
462
|
const s = e.ok || { resolve: "body" };
|
|
@@ -468,7 +466,7 @@ const xe = function(e) {
|
|
|
468
466
|
break;
|
|
469
467
|
case "json":
|
|
470
468
|
t.push(
|
|
471
|
-
" 将响应解析为 json,读取 " + (s.dataField ||
|
|
469
|
+
" 将响应解析为 json,读取 " + (s.dataField || B) + " 作为响应数据,读取 " + (s.messageField || w) + " 作为提示消息"
|
|
472
470
|
), s.statusField && t.push(
|
|
473
471
|
" 当 " + s.statusField + " 为 " + (s.statusOKValue || "空值") + " 时是成功提示,否则是错误消息"
|
|
474
472
|
), s.ignoreMessage && t.push(" 并忽略以下消息:" + s.ignoreMessage);
|
|
@@ -477,39 +475,39 @@ const xe = function(e) {
|
|
|
477
475
|
return t.join(`
|
|
478
476
|
`);
|
|
479
477
|
};
|
|
480
|
-
function
|
|
481
|
-
if (!
|
|
478
|
+
function le(e, t, n, s = w) {
|
|
479
|
+
if (!S(e))
|
|
482
480
|
return { message: "" };
|
|
483
|
-
const
|
|
484
|
-
return !
|
|
485
|
-
code:
|
|
486
|
-
message:
|
|
481
|
+
const r = T(E(e), t);
|
|
482
|
+
return !r || !A(r) ? { message: e } : {
|
|
483
|
+
code: n ? k(r, n) : "",
|
|
484
|
+
message: k(r, s) || e
|
|
487
485
|
};
|
|
488
486
|
}
|
|
489
|
-
function
|
|
490
|
-
const
|
|
491
|
-
for (const s of
|
|
487
|
+
function k(e, t) {
|
|
488
|
+
const n = Array.isArray(t) ? t : [t];
|
|
489
|
+
for (const s of n)
|
|
492
490
|
if (s in e)
|
|
493
|
-
return
|
|
491
|
+
return L(e[s]);
|
|
494
492
|
return "";
|
|
495
493
|
}
|
|
496
|
-
const
|
|
497
|
-
function
|
|
498
|
-
for (const t of
|
|
499
|
-
const
|
|
500
|
-
if (
|
|
501
|
-
return
|
|
494
|
+
const de = [/<title>([^<]+)<\/title>/i, /<message>([^<]+)<\/message>/i];
|
|
495
|
+
function x(e) {
|
|
496
|
+
for (const t of de) {
|
|
497
|
+
const n = e.match(t);
|
|
498
|
+
if (n)
|
|
499
|
+
return n[1];
|
|
502
500
|
}
|
|
503
501
|
return "";
|
|
504
502
|
}
|
|
505
|
-
const
|
|
506
|
-
function
|
|
503
|
+
const ge = /* @__PURE__ */ N("APIError");
|
|
504
|
+
function pe(e) {
|
|
507
505
|
const t = {};
|
|
508
|
-
for (const
|
|
509
|
-
(
|
|
510
|
-
const
|
|
506
|
+
for (const r in e.headers)
|
|
507
|
+
(r.startsWith("x-") || r.includes("trace") || r.includes("server") || r.includes("status") || /\b(?:id|uuid)\b/.test(r)) && (t[r] = e.headers[r]);
|
|
508
|
+
const n = e.url.replace(/^(?:https?:)?\/*/i, "").replace(/\?.+/, ""), s = e.status < 0 ? "unknown" : e.status;
|
|
511
509
|
return {
|
|
512
|
-
sentryError: new
|
|
510
|
+
sentryError: new ge(`${n}${s === "unknown" ? "" : ` | ${s}`} | ${e.code}`),
|
|
513
511
|
sentryTags: {
|
|
514
512
|
...t,
|
|
515
513
|
status: s,
|
|
@@ -525,35 +523,35 @@ function me(e) {
|
|
|
525
523
|
}
|
|
526
524
|
};
|
|
527
525
|
}
|
|
528
|
-
async function
|
|
526
|
+
async function xe(e, t) {
|
|
529
527
|
if (e.method === "HEAD" || e.status === 204)
|
|
530
528
|
return e.body = null, e;
|
|
531
529
|
try {
|
|
532
530
|
e.body = t.asBuffer ? await t.buffer() : await t.text();
|
|
533
|
-
} catch (
|
|
534
|
-
e.body = null, e.error =
|
|
531
|
+
} catch (n) {
|
|
532
|
+
e.body = null, e.error = y.Unknown, e.rawError = ne(n);
|
|
535
533
|
}
|
|
536
534
|
return e;
|
|
537
535
|
}
|
|
538
|
-
function
|
|
539
|
-
const
|
|
536
|
+
function ve(e, t, n, s) {
|
|
537
|
+
const r = e.status, o = e.method, a = te(
|
|
540
538
|
Object.entries(e.headers || {}).map(([d, g]) => [d.toLowerCase(), g])
|
|
541
|
-
), { ok: i, code: c, data: l, message: u } =
|
|
542
|
-
if (!
|
|
543
|
-
const d =
|
|
539
|
+
), { ok: i, code: c, data: l, message: u } = ue(e, n.get("responseRule"), s?.responseRule);
|
|
540
|
+
if (!D(r)) {
|
|
541
|
+
const d = pe({
|
|
544
542
|
url: e.url,
|
|
545
543
|
method: e.method,
|
|
546
|
-
status:
|
|
544
|
+
status: r,
|
|
547
545
|
code: c,
|
|
548
546
|
message: u,
|
|
549
547
|
body: e.body,
|
|
550
548
|
headers: a,
|
|
551
549
|
error: e.rawError
|
|
552
550
|
});
|
|
553
|
-
(
|
|
551
|
+
(n.get("errorHandler") || me)({
|
|
554
552
|
url: t,
|
|
555
553
|
method: o,
|
|
556
|
-
status:
|
|
554
|
+
status: r,
|
|
557
555
|
code: c,
|
|
558
556
|
message: u,
|
|
559
557
|
headers: a,
|
|
@@ -561,39 +559,39 @@ function Oe(e, t, r, s) {
|
|
|
561
559
|
...d
|
|
562
560
|
});
|
|
563
561
|
}
|
|
564
|
-
if (
|
|
565
|
-
return
|
|
566
|
-
{ ok: !1, status:
|
|
562
|
+
if (r < 0)
|
|
563
|
+
return v(
|
|
564
|
+
{ ok: !1, status: r, code: e.statusText, headers: {}, message: "", data: null },
|
|
567
565
|
`${o} ${t} ${e.statusText}`,
|
|
568
566
|
o,
|
|
569
567
|
t,
|
|
570
|
-
|
|
568
|
+
n,
|
|
571
569
|
s
|
|
572
570
|
);
|
|
573
|
-
const h = { ok: i, data: l, code: c, message: u, status:
|
|
574
|
-
|
|
571
|
+
const h = { ok: i, data: l, code: c, message: u, status: r, headers: a };
|
|
572
|
+
n.get("responseHandler")?.({ ...h }, o, t);
|
|
575
573
|
const p = i ? u : u || e.statusText;
|
|
576
|
-
return
|
|
574
|
+
return v(h, p, o, t, n, s);
|
|
577
575
|
}
|
|
578
|
-
function
|
|
579
|
-
const a =
|
|
576
|
+
function v(e, t, n, s, r, o) {
|
|
577
|
+
const a = r.get("message"), i = a === !1 || o?.message === !1 ? !1 : o?.message || a;
|
|
580
578
|
if (i !== !1) {
|
|
581
|
-
const c = typeof i == "function" ? i(e,
|
|
582
|
-
c instanceof Error ?
|
|
579
|
+
const c = typeof i == "function" ? i(e, n, s, t) : t;
|
|
580
|
+
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
581
|
}
|
|
584
582
|
return e;
|
|
585
583
|
}
|
|
586
|
-
function
|
|
584
|
+
function me(e) {
|
|
587
585
|
const t = {};
|
|
588
|
-
for (const
|
|
589
|
-
|
|
586
|
+
for (const n in e)
|
|
587
|
+
n.startsWith("sentry") || (t[n] = e[n]);
|
|
590
588
|
console.error("RequestError", t);
|
|
591
589
|
}
|
|
592
|
-
function
|
|
590
|
+
function b(e) {
|
|
593
591
|
return e.replace(/<script[\s\S]*?>[\s\S]*?<\/script>/gi, "").replace(/<[^>]+>/g, "").trim();
|
|
594
592
|
}
|
|
595
|
-
async function
|
|
596
|
-
const o =
|
|
593
|
+
async function ye(e, t, n, s, r) {
|
|
594
|
+
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
595
|
c?.({
|
|
598
596
|
type: "prepare",
|
|
599
597
|
url: t,
|
|
@@ -604,7 +602,7 @@ async function we(e, t, r, s, n) {
|
|
|
604
602
|
headers: s?.headers,
|
|
605
603
|
options: s
|
|
606
604
|
});
|
|
607
|
-
const l = Date.now(), u = await e(t,
|
|
605
|
+
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
606
|
if (c?.({
|
|
609
607
|
type: "finished",
|
|
610
608
|
url: t,
|
|
@@ -617,30 +615,31 @@ async function we(e, t, r, s, n) {
|
|
|
617
615
|
cost: p
|
|
618
616
|
}), !a || o >= a || i(u, o) !== !0)
|
|
619
617
|
return u;
|
|
620
|
-
const g = s?.retryInterval ??
|
|
621
|
-
return await
|
|
618
|
+
const g = s?.retryInterval ?? n.get("retryInterval") ?? 100;
|
|
619
|
+
return await H(
|
|
622
620
|
Math.max(
|
|
623
621
|
100,
|
|
624
622
|
g === "2EB" ? Math.pow(2, o) * 100 : typeof g == "function" ? g(o + 1, { url: t, status: h, method: u.method }) || 0 : g
|
|
625
623
|
)
|
|
626
|
-
), await
|
|
624
|
+
), await ye(e, t, n, s, o + 1);
|
|
627
625
|
}
|
|
628
626
|
export {
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
627
|
+
P as E,
|
|
628
|
+
Z as G,
|
|
629
|
+
z as H,
|
|
630
|
+
ke as N,
|
|
631
|
+
y as R,
|
|
632
|
+
we as X,
|
|
633
|
+
Re as a,
|
|
634
|
+
se as b,
|
|
637
635
|
$e as c,
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
636
|
+
be as d,
|
|
637
|
+
te as e,
|
|
638
|
+
xe as f,
|
|
639
|
+
je as g,
|
|
640
|
+
ve as h,
|
|
641
|
+
Ee as i,
|
|
642
|
+
ye as r,
|
|
643
|
+
L as t,
|
|
644
|
+
Te as v
|
|
646
645
|
};
|
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-b0Etywu_.js";
|
|
2
|
+
import { g as O } from "./retry-b0Etywu_.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>;
|