@seayoo-web/request 3.5.0 → 3.5.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 +13 -14
- package/dist/node.js +3 -3
- package/dist/request.fetch-Jj3A4PnG.js +48 -0
- package/dist/{retry-DodVI8cA.js → retry-Cxkf8ke1.js} +93 -96
- package/dist/wx.js +2 -2
- package/package.json +1 -1
- package/dist/request.fetch-U_igg1Ax.js +0 -49
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { h as m, r as q, R as T, c as x, H as R, a as w, v as E, b as C, N as H, X as L } from "./retry-
|
|
2
|
-
import { g as Q } from "./retry-
|
|
3
|
-
import { f as v } from "./request.fetch-
|
|
1
|
+
import { h as m, r as q, R as T, c as x, H as R, a as w, v as E, b as C, N as H, X as L } from "./retry-Cxkf8ke1.js";
|
|
2
|
+
import { g as Q } from "./retry-Cxkf8ke1.js";
|
|
3
|
+
import { f as v } from "./request.fetch-Jj3A4PnG.js";
|
|
4
4
|
const j = async function(t, s, e) {
|
|
5
5
|
return m(await q(y, t, s, e), t, s, e);
|
|
6
6
|
};
|
|
@@ -16,31 +16,31 @@ async function k(t, s, e, n) {
|
|
|
16
16
|
}
|
|
17
17
|
const a = new FormData(), d = { ...s };
|
|
18
18
|
r instanceof Object && Object.entries(r).forEach(([i, u]) => {
|
|
19
|
-
u instanceof Blob ? d[i] = u : Array.isArray(u) ? u.forEach((o,
|
|
20
|
-
a.append(`${i}[${
|
|
19
|
+
u instanceof Blob ? d[i] = u : Array.isArray(u) ? u.forEach((o, h) => {
|
|
20
|
+
a.append(`${i}[${h}]`, String(o));
|
|
21
21
|
}) : a.append(i, String(u));
|
|
22
22
|
});
|
|
23
23
|
for (const i in d)
|
|
24
24
|
a.append(i, d[i]);
|
|
25
|
-
const b = new T(n),
|
|
25
|
+
const b = new T(n), g = await y(t, b, {
|
|
26
26
|
...e,
|
|
27
27
|
method: l,
|
|
28
28
|
body: a
|
|
29
29
|
});
|
|
30
|
-
return m(
|
|
30
|
+
return m(g, t, b, e);
|
|
31
31
|
}
|
|
32
32
|
const y = async function(t, s, e) {
|
|
33
33
|
const n = await x(t, s, e), r = n.method, l = e?.onUploadProgress, a = R(n.url, n.params);
|
|
34
34
|
return await new Promise((d) => {
|
|
35
|
-
let b = null,
|
|
35
|
+
let b = null, g = !1;
|
|
36
36
|
const i = function() {
|
|
37
|
-
|
|
37
|
+
g || (o.abort(), g = !0);
|
|
38
38
|
};
|
|
39
39
|
function u() {
|
|
40
40
|
b !== null && clearTimeout(b), n.abort && n.abort.removeEventListener("abort", i);
|
|
41
41
|
}
|
|
42
42
|
const o = new XMLHttpRequest();
|
|
43
|
-
let
|
|
43
|
+
let h = !1;
|
|
44
44
|
if (o.open(r, a, !0), l) {
|
|
45
45
|
let f = 1;
|
|
46
46
|
o.upload.addEventListener("progress", (p) => {
|
|
@@ -76,15 +76,14 @@ const y = async function(t, s, e) {
|
|
|
76
76
|
u(), d({
|
|
77
77
|
url: a,
|
|
78
78
|
method: r,
|
|
79
|
-
status:
|
|
80
|
-
|
|
81
|
-
statusText: g ? w.Timeout : w.Aborted,
|
|
79
|
+
status: -1,
|
|
80
|
+
statusText: h ? w.Timeout : w.Aborted,
|
|
82
81
|
body: ""
|
|
83
82
|
});
|
|
84
83
|
}), Object.entries(n.headers).forEach(([f, p]) => {
|
|
85
84
|
o.setRequestHeader(f, p);
|
|
86
85
|
}), n.credentials === "include" && (o.withCredentials = !0), o.send(n.body || void 0), n.abort && n.abort.addEventListener("abort", i), n.timeout > 0 && (b = setTimeout(function() {
|
|
87
|
-
|
|
86
|
+
h = !0, i();
|
|
88
87
|
}, n.timeout));
|
|
89
88
|
});
|
|
90
89
|
};
|
package/dist/node.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { h as b, r as q, c as w, n as g, a as d, f as E, N as f, X as x } from "./retry-
|
|
2
|
-
import { g as z } from "./retry-
|
|
3
|
-
import { f as C } from "./request.fetch-
|
|
1
|
+
import { h as b, r as q, c as w, n as g, a as d, f as E, N as f, X as x } from "./retry-Cxkf8ke1.js";
|
|
2
|
+
import { g as z } from "./retry-Cxkf8ke1.js";
|
|
3
|
+
import { f as C } from "./request.fetch-Jj3A4PnG.js";
|
|
4
4
|
import N from "node:http";
|
|
5
5
|
import T from "node:https";
|
|
6
6
|
const j = async function(o, a, u) {
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { h as w, r as y, c as E, d as T, f as g, a as c } from "./retry-Cxkf8ke1.js";
|
|
2
|
+
const x = async function(o, a, s) {
|
|
3
|
+
return w(await y(R, o, a, s), o, a, s);
|
|
4
|
+
}, R = async function(o, a, s) {
|
|
5
|
+
const t = await E(o, a, s), n = new URL(t.url), u = t.params;
|
|
6
|
+
u instanceof Object && Object.keys(u).forEach((e) => n.searchParams.set(e, u[e]));
|
|
7
|
+
const r = T() ? new AbortController() : null;
|
|
8
|
+
function d(e) {
|
|
9
|
+
r && !r.signal.aborted && r.abort(e);
|
|
10
|
+
}
|
|
11
|
+
t.abort && t.abort.addEventListener("abort", d);
|
|
12
|
+
let h = !1;
|
|
13
|
+
const b = t.timeout > 0 ? setTimeout(function() {
|
|
14
|
+
h = !0, d("TimeoutTriggered");
|
|
15
|
+
}, t.timeout) : null, m = t.method === "HEAD";
|
|
16
|
+
return await fetch(n, {
|
|
17
|
+
method: t.method,
|
|
18
|
+
headers: Object.keys(t.headers).length > 0 ? new Headers(t.headers) : void 0,
|
|
19
|
+
body: t.body,
|
|
20
|
+
credentials: t.credentials,
|
|
21
|
+
signal: r?.signal,
|
|
22
|
+
redirect: "follow"
|
|
23
|
+
}).then(async (e) => {
|
|
24
|
+
const i = {
|
|
25
|
+
url: n.toString(),
|
|
26
|
+
method: t.method,
|
|
27
|
+
status: e.status,
|
|
28
|
+
statusText: e.statusText,
|
|
29
|
+
headers: g([...e.headers.entries()])
|
|
30
|
+
}, l = m || e.status === 204 ? "" : await e.text().catch((f) => f);
|
|
31
|
+
return l instanceof Error ? { ...i, body: "", statusText: c.Unknown, rawError: l } : { ...i, body: l };
|
|
32
|
+
}).catch((e) => {
|
|
33
|
+
const i = r?.signal.aborted;
|
|
34
|
+
return {
|
|
35
|
+
url: n.toString(),
|
|
36
|
+
method: t.method,
|
|
37
|
+
status: -1,
|
|
38
|
+
statusText: h ? c.Timeout : i ? c.Aborted : c.NetworkError,
|
|
39
|
+
body: "",
|
|
40
|
+
rawError: e
|
|
41
|
+
};
|
|
42
|
+
}).finally(() => {
|
|
43
|
+
b !== null && clearTimeout(b), t.abort && t.abort.removeEventListener("abort", d);
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
export {
|
|
47
|
+
x as f
|
|
48
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const l = typeof globalThis < "u" ? globalThis : typeof self < "u" ? self : typeof window < "u" ? window : Function("return this")();
|
|
2
|
-
function
|
|
2
|
+
function x() {
|
|
3
3
|
return l;
|
|
4
4
|
}
|
|
5
5
|
function p(t) {
|
|
@@ -8,14 +8,14 @@ function p(t) {
|
|
|
8
8
|
function F(t) {
|
|
9
9
|
return typeof t == "object" && t !== null;
|
|
10
10
|
}
|
|
11
|
-
function
|
|
11
|
+
function D() {
|
|
12
12
|
return "wx" in l && F(l.wx) && "getSystemInfo" in l.wx && p(l.wx.getSystemInfo);
|
|
13
13
|
}
|
|
14
14
|
function pe() {
|
|
15
15
|
return "fetch" in l && p(l.fetch);
|
|
16
16
|
}
|
|
17
17
|
function ye() {
|
|
18
|
-
return "window" in l && F(l.window) && !
|
|
18
|
+
return "window" in l && F(l.window) && !D();
|
|
19
19
|
}
|
|
20
20
|
function M() {
|
|
21
21
|
return "Blob" in l && p(l.Blob);
|
|
@@ -29,14 +29,14 @@ function be() {
|
|
|
29
29
|
function we() {
|
|
30
30
|
return "AbortController" in l && p(l.AbortController);
|
|
31
31
|
}
|
|
32
|
-
function
|
|
32
|
+
function P() {
|
|
33
33
|
return "URLSearchParams" in l && p(l.URLSearchParams);
|
|
34
34
|
}
|
|
35
|
-
function
|
|
35
|
+
function q(t) {
|
|
36
36
|
return new Promise((e) => setTimeout(e, Math.min(Number.MAX_SAFE_INTEGER, Math.max(0, t))));
|
|
37
37
|
}
|
|
38
38
|
// @__NO_SIDE_EFFECTS__
|
|
39
|
-
function
|
|
39
|
+
function H(t) {
|
|
40
40
|
const e = t || "CustomError";
|
|
41
41
|
return class extends Error {
|
|
42
42
|
constructor(s) {
|
|
@@ -48,22 +48,22 @@ function B(t) {
|
|
|
48
48
|
}
|
|
49
49
|
};
|
|
50
50
|
}
|
|
51
|
-
const
|
|
52
|
-
function
|
|
53
|
-
return e ?
|
|
51
|
+
const N = /^(?:https?:)?\/\/.+$/i, B = /^https?:\/\/.+$/i, I = /^\{[\d\D]*\}$/, G = /^\[[\d\D]*\]$/;
|
|
52
|
+
function $(t, e = !1) {
|
|
53
|
+
return e ? N.test(t) : B.test(t);
|
|
54
54
|
}
|
|
55
|
-
function
|
|
55
|
+
function K(t) {
|
|
56
56
|
return t == null;
|
|
57
57
|
}
|
|
58
|
-
function
|
|
58
|
+
function v(t, ...e) {
|
|
59
59
|
if (!t || typeof t != "object") return !1;
|
|
60
60
|
const s = Object.getPrototypeOf(t);
|
|
61
61
|
return s !== Object.prototype && s !== null ? !1 : e.every((n) => n in t);
|
|
62
62
|
}
|
|
63
|
-
function
|
|
64
|
-
return
|
|
63
|
+
function A(t) {
|
|
64
|
+
return I.test(t) || G.test(t);
|
|
65
65
|
}
|
|
66
|
-
function
|
|
66
|
+
function k(t, e) {
|
|
67
67
|
try {
|
|
68
68
|
const s = JSON.parse(t);
|
|
69
69
|
return e ? e(s) ? s : null : s;
|
|
@@ -81,7 +81,7 @@ async function Ee(t) {
|
|
|
81
81
|
}, n.setAttribute("src", t), s.appendChild(n);
|
|
82
82
|
});
|
|
83
83
|
}
|
|
84
|
-
function
|
|
84
|
+
function _(t, e = "数据未能正确识别") {
|
|
85
85
|
return typeof t == "function" ? {
|
|
86
86
|
guard: t,
|
|
87
87
|
message: e
|
|
@@ -90,21 +90,21 @@ function J(t, e = "数据未能正确识别") {
|
|
|
90
90
|
message: t.message || e
|
|
91
91
|
};
|
|
92
92
|
}
|
|
93
|
-
function
|
|
94
|
-
return !e ||
|
|
93
|
+
function J(t, e = "") {
|
|
94
|
+
return !e || $(t, !0) ? T(t) : (T(e) + "/" + t).replace(/\/{2,}/g, "/").replace(/:\//, "://");
|
|
95
95
|
}
|
|
96
|
-
function
|
|
97
|
-
const e =
|
|
98
|
-
return
|
|
96
|
+
function T(t) {
|
|
97
|
+
const e = x();
|
|
98
|
+
return $(t, !0) ? t.startsWith("http") ? t : ("location" in e ? location.protocol : "https:") + t : ("location" in e ? location.origin : "http://127.0.0.1") + "/" + t.replace(/^\/+/, "");
|
|
99
99
|
}
|
|
100
|
-
function
|
|
100
|
+
function V(t, e) {
|
|
101
101
|
const s = {};
|
|
102
102
|
return (t.match(/([^=&#?]+)=[^&#]*/g) || []).forEach(function(n) {
|
|
103
103
|
const r = n.split("="), o = r[0], a = decodeURIComponent(r[1] || "");
|
|
104
104
|
s[o] !== void 0 ? s[o] += "," + a : s[o] = a;
|
|
105
105
|
}), e !== !0 ? s[e] || "" : s;
|
|
106
106
|
}
|
|
107
|
-
function
|
|
107
|
+
function W(t, e) {
|
|
108
108
|
if (e) {
|
|
109
109
|
if (e === !0)
|
|
110
110
|
return t.replace(/\?[^#]*/, "");
|
|
@@ -112,23 +112,23 @@ function X(t, e) {
|
|
|
112
112
|
const s = t.split("#"), n = s[0].split("?"), r = n[0], o = n.length > 1 ? n[1] : "", a = s.length > 1 ? "#" + s[1] : "", i = typeof e == "string" ? [e] : Array.isArray(e) ? e : [];
|
|
113
113
|
return !i.length || !o ? s[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 ke(t, e, s = !1) {
|
|
116
116
|
const n = typeof e == "string" ? e : Object.keys(e).map((a) => `${a}=${encodeURIComponent(e[a])}`).join("&");
|
|
117
117
|
if (!n)
|
|
118
118
|
return t;
|
|
119
119
|
const r = t.split("#");
|
|
120
|
-
s && (r[0] =
|
|
120
|
+
s && (r[0] = W(
|
|
121
121
|
r[0],
|
|
122
122
|
(n.match(/([^=&#?]+)=[^&#]+/g) || []).map((a) => a.replace(/=.+$/, ""))
|
|
123
123
|
));
|
|
124
124
|
const o = r[0].indexOf("?") + 1 ? "&" : "?";
|
|
125
125
|
return (r[0] + o + n + (r.length > 1 ? "#" + r[1] : "")).replace(/\?&/, "?");
|
|
126
126
|
}
|
|
127
|
-
function
|
|
127
|
+
function X(t) {
|
|
128
128
|
const e = t.match(/(?:\?|&)([^=]+)(?:&|$)/g);
|
|
129
129
|
return e ? e.join("").replace(/(?:\?|^&+|&+$)/g, "").replace(/&{2}/g, "&").split("&").sort() : [];
|
|
130
130
|
}
|
|
131
|
-
class
|
|
131
|
+
class z {
|
|
132
132
|
ttl;
|
|
133
133
|
cache;
|
|
134
134
|
timer = null;
|
|
@@ -156,7 +156,7 @@ class Q {
|
|
|
156
156
|
} catch (h) {
|
|
157
157
|
return console.warn("[RequestCache] cacheResolve error", s, n, h), "";
|
|
158
158
|
}
|
|
159
|
-
const c = Object.assign(
|
|
159
|
+
const c = Object.assign(V(a, !0), n), g = X(a), u = Object.keys(c).sort().map((h) => `${h}#${c[h]}`);
|
|
160
160
|
return `${i}_${o}_${u.join(",")}_${g.join(",")}`;
|
|
161
161
|
}
|
|
162
162
|
updateTTL(e) {
|
|
@@ -179,7 +179,7 @@ class Q {
|
|
|
179
179
|
this.cache[e] && delete this.cache[e];
|
|
180
180
|
}
|
|
181
181
|
}
|
|
182
|
-
class
|
|
182
|
+
class Q {
|
|
183
183
|
// 保存的配置需要部分字段强制设置默认值
|
|
184
184
|
config = {
|
|
185
185
|
baseURL: "/",
|
|
@@ -204,7 +204,7 @@ class Y {
|
|
|
204
204
|
e && this.set(e);
|
|
205
205
|
}
|
|
206
206
|
set(e) {
|
|
207
|
-
if (e.baseURL && !/^\/.+/.test(e.baseURL) &&
|
|
207
|
+
if (e.baseURL && !/^\/.+/.test(e.baseURL) && !$(e.baseURL))
|
|
208
208
|
throw console.warn("baseURL 需要以 / 开头,或者是完整的 url 地址"), new Error("BaseURLError");
|
|
209
209
|
Object.assign(this.config, e);
|
|
210
210
|
}
|
|
@@ -213,7 +213,7 @@ class Y {
|
|
|
213
213
|
}
|
|
214
214
|
/** 基于 baseURL 返回完整的 url 地址 */
|
|
215
215
|
getFullUrl(e) {
|
|
216
|
-
return
|
|
216
|
+
return J(e, this.config.baseURL);
|
|
217
217
|
}
|
|
218
218
|
/** 提示消息 */
|
|
219
219
|
showMessage(e, s, n, r) {
|
|
@@ -236,19 +236,19 @@ const w = {
|
|
|
236
236
|
/** url 格式错误 */
|
|
237
237
|
URLFormatError: "URLFormatError"
|
|
238
238
|
};
|
|
239
|
-
function
|
|
240
|
-
if (e.ok && !
|
|
241
|
-
const r =
|
|
239
|
+
function Y(t, e, s, n) {
|
|
240
|
+
if (e.ok && !K(e.data) && n) {
|
|
241
|
+
const r = _(n, s.get("defaultTypeGuardMessage"));
|
|
242
242
|
return r.guard(e.data) || (e.code = w.UnexpectResponse, s.showMessage(!0, `${t} ${r.message}`, e.code, e.status), console.error(e.code, t, e.data), e.data = null, e.message = r.message), e;
|
|
243
243
|
}
|
|
244
244
|
return e;
|
|
245
245
|
}
|
|
246
|
-
class
|
|
246
|
+
class Re {
|
|
247
247
|
agent;
|
|
248
248
|
config;
|
|
249
249
|
cache;
|
|
250
250
|
constructor(e, s) {
|
|
251
|
-
this.config = new
|
|
251
|
+
this.config = new Q(s), this.agent = e, this.cache = new z(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);
|
|
252
252
|
}
|
|
253
253
|
/**
|
|
254
254
|
* 执行网络请求
|
|
@@ -281,7 +281,7 @@ ${r.stack || ""}` : String(r),
|
|
|
281
281
|
* 检查响应的数据类型
|
|
282
282
|
*/
|
|
283
283
|
async guard(e, s, n) {
|
|
284
|
-
return
|
|
284
|
+
return Y(e, s, this.config, n);
|
|
285
285
|
}
|
|
286
286
|
/**
|
|
287
287
|
* 修改默认请求配置: baseURL / timeout / credentials / errorHandler / messageHandler / responseHandler / logHandler / responseRule
|
|
@@ -335,9 +335,9 @@ async function je(t, e, s) {
|
|
|
335
335
|
n.headers
|
|
336
336
|
), c = n.params || {}, g = {};
|
|
337
337
|
Object.keys(c).forEach((y) => {
|
|
338
|
-
c[y] !== void 0 && (g[y] =
|
|
338
|
+
c[y] !== void 0 && (g[y] = Z(c[y]));
|
|
339
339
|
});
|
|
340
|
-
const u = e.getFullUrl(t), h =
|
|
340
|
+
const u = e.getFullUrl(t), h = ee(n.body), f = n.timeout || e.get("timeout"), d = await (async function() {
|
|
341
341
|
const y = e.get("requestTransformer");
|
|
342
342
|
if (y)
|
|
343
343
|
return await y({ headers: i, params: g, method: o, url: u, body: h });
|
|
@@ -353,21 +353,21 @@ async function je(t, e, s) {
|
|
|
353
353
|
credentials: n.credentials || e.get("credentials")
|
|
354
354
|
};
|
|
355
355
|
}
|
|
356
|
-
function
|
|
356
|
+
function Z(t) {
|
|
357
357
|
return t == null ? "" : typeof t == "string" ? t : typeof t == "number" || typeof t == "boolean" ? String(t) : Array.isArray(t) ? t.filter(
|
|
358
358
|
(s) => s != null && typeof s != "object" && typeof s != "function"
|
|
359
359
|
).join(",") : (console.warn("参数类型不支持,已被过滤", typeof t), "");
|
|
360
360
|
}
|
|
361
|
-
function
|
|
361
|
+
function ee(t) {
|
|
362
362
|
if (t)
|
|
363
|
-
return typeof t == "string" ||
|
|
363
|
+
return typeof t == "string" || P() && t instanceof URLSearchParams || t instanceof ArrayBuffer || M() && t instanceof Blob || U() && t instanceof FormData ? t : JSON.stringify(t);
|
|
364
364
|
}
|
|
365
|
-
const
|
|
366
|
-
function
|
|
365
|
+
const L = "data", b = "message";
|
|
366
|
+
function te(t, e, s, n, r) {
|
|
367
367
|
const o = r || n;
|
|
368
|
-
return
|
|
368
|
+
return S(t) ? ce(o.ok || n.ok, t, e, s) : se(o.failed || n.failed, e, s);
|
|
369
369
|
}
|
|
370
|
-
const
|
|
370
|
+
const $e = function(t) {
|
|
371
371
|
const e = [], s = t.failed || { resolve: "json" };
|
|
372
372
|
switch (e.push("- 当http状态码 <200 或者 >=400 时"), s.resolve) {
|
|
373
373
|
case "body":
|
|
@@ -384,7 +384,7 @@ const Te = function(t) {
|
|
|
384
384
|
break;
|
|
385
385
|
case "json":
|
|
386
386
|
e.push(
|
|
387
|
-
" 将响应解析为 json,读取 " + (n.dataField ||
|
|
387
|
+
" 将响应解析为 json,读取 " + (n.dataField || L) + " 作为响应数据,读取 " + (n.messageField || b) + " 作为提示消息"
|
|
388
388
|
), n.statusField && e.push(
|
|
389
389
|
" 当 " + n.statusField + " 为 " + (n.statusOKValue || "空值") + " 时是成功提示,否则是错误消息"
|
|
390
390
|
), n.ignoreMessage && e.push(" 并忽略以下消息:" + n.ignoreMessage);
|
|
@@ -393,7 +393,7 @@ const Te = function(t) {
|
|
|
393
393
|
return e.join(`
|
|
394
394
|
`);
|
|
395
395
|
};
|
|
396
|
-
function
|
|
396
|
+
function se(t, e, s) {
|
|
397
397
|
const n = t || { resolve: "json", messageField: b }, r = {
|
|
398
398
|
ok: !1,
|
|
399
399
|
code: e,
|
|
@@ -405,40 +405,40 @@ function ne(t, e, s) {
|
|
|
405
405
|
r.message = O(s) || s;
|
|
406
406
|
break;
|
|
407
407
|
case "json":
|
|
408
|
-
const { code: o, message: a } =
|
|
408
|
+
const { code: o, message: a } = ne(s, n.converter, n.statusField, n.messageField);
|
|
409
409
|
r.code = o || e, r.message = O(s) || a;
|
|
410
410
|
break;
|
|
411
411
|
}
|
|
412
412
|
return r;
|
|
413
413
|
}
|
|
414
|
-
function
|
|
415
|
-
if (!
|
|
414
|
+
function ne(t, e, s, n = b) {
|
|
415
|
+
if (!A(t))
|
|
416
416
|
return { message: "" };
|
|
417
|
-
const r = j(
|
|
418
|
-
return !r || !
|
|
419
|
-
code: s ?
|
|
420
|
-
message:
|
|
417
|
+
const r = j(k(t), e);
|
|
418
|
+
return !r || !v(r) ? { message: t } : {
|
|
419
|
+
code: s ? R(r, s) : "",
|
|
420
|
+
message: R(r, n) || t
|
|
421
421
|
};
|
|
422
422
|
}
|
|
423
|
-
function
|
|
423
|
+
function R(t, e) {
|
|
424
424
|
const s = Array.isArray(e) ? e : [e];
|
|
425
425
|
for (const n of s)
|
|
426
426
|
if (n in t)
|
|
427
|
-
return
|
|
427
|
+
return re(t[n]);
|
|
428
428
|
return "";
|
|
429
429
|
}
|
|
430
|
-
function
|
|
430
|
+
function re(t) {
|
|
431
431
|
return t ? typeof t == "string" ? t : JSON.stringify(t) : "";
|
|
432
432
|
}
|
|
433
|
-
const
|
|
433
|
+
const oe = /<title>([^<]+)<\/title>/i, ae = /<message>([^<]+)<\/message>/i;
|
|
434
434
|
function O(t) {
|
|
435
|
-
const e = t.match(
|
|
435
|
+
const e = t.match(oe);
|
|
436
436
|
if (e)
|
|
437
437
|
return e[1];
|
|
438
|
-
const s = t.match(
|
|
438
|
+
const s = t.match(ae);
|
|
439
439
|
return s ? s[1] : "";
|
|
440
440
|
}
|
|
441
|
-
function
|
|
441
|
+
function ce(t, e, s, n) {
|
|
442
442
|
const r = t || { resolve: "body" }, o = {
|
|
443
443
|
ok: !0,
|
|
444
444
|
code: s,
|
|
@@ -448,33 +448,33 @@ function ie(t, e, s, n) {
|
|
|
448
448
|
if (e === 204 || !n)
|
|
449
449
|
return o;
|
|
450
450
|
if (r.resolve === "body")
|
|
451
|
-
return o.data =
|
|
452
|
-
const a =
|
|
451
|
+
return o.data = A(n) ? j(k(n), t.converter) : n, o;
|
|
452
|
+
const a = k(n);
|
|
453
453
|
if (!a)
|
|
454
454
|
return o.ok = !1, o.code = "ResponseFormatError", o.message = "响应内容无法安全解析", o;
|
|
455
455
|
const i = j(a, t.converter);
|
|
456
|
-
if (!i || !
|
|
456
|
+
if (!i || !v(i))
|
|
457
457
|
return o.ok = !1, o.code = "ResponseFormatError", o.message = "响应内容无法格式化为 Object", o;
|
|
458
|
-
const c = r.statusField, g = r.statusOKValue || "", u = r.dataField ||
|
|
458
|
+
const c = r.statusField, g = r.statusOKValue || "", u = r.dataField || L, h = r.messageField || b, f = r.ignoreMessage || "";
|
|
459
459
|
if (c && !(c in i))
|
|
460
460
|
return o.ok = !1, o.code = "ResponseFieldMissing", o.message = "响应内容找不到状态字段 " + c, o;
|
|
461
|
-
const d = c ? i[c]
|
|
462
|
-
return o.ok = c ? d === g : !0, o.code = d || s, o.data = u === !0 ? i : u in i ? i[u] : null, o.message =
|
|
461
|
+
const d = c ? String(i[c] ?? "") : "";
|
|
462
|
+
return o.ok = c ? d === g : !0, o.code = d || s, o.data = u === !0 ? i : u in i ? i[u] : null, o.message = R(i, h), f && o.message && (Array.isArray(f) && f.includes(o.message) || typeof f == "string" && o.message === f) && (o.message = ""), o;
|
|
463
463
|
}
|
|
464
|
-
function
|
|
464
|
+
function S(t) {
|
|
465
465
|
return t >= 200 && t < 400;
|
|
466
466
|
}
|
|
467
467
|
function j(t, e) {
|
|
468
468
|
return e && typeof e == "function" ? e(t) : t;
|
|
469
469
|
}
|
|
470
|
-
const
|
|
471
|
-
function
|
|
470
|
+
const ie = /* @__PURE__ */ H("APIError");
|
|
471
|
+
function ue(t) {
|
|
472
472
|
const e = {};
|
|
473
473
|
for (const r in t.headers)
|
|
474
474
|
(r.startsWith("x-") || r.includes("trace") || r.includes("server") || /\b(?:id|uuid)\b/.test(r)) && (e[r] = t.headers[r]);
|
|
475
475
|
const s = t.url.replace(/^(?:https?:)?\/*/i, "").replace(/\?.+/, ""), n = t.status < 0 ? "unknown" : t.status;
|
|
476
476
|
return {
|
|
477
|
-
sentryError: new
|
|
477
|
+
sentryError: new ie(`${s} | ${n}${t.code ? ` | ${t.code}` : ""}`),
|
|
478
478
|
sentryTags: {
|
|
479
479
|
...e,
|
|
480
480
|
status: n,
|
|
@@ -490,38 +490,35 @@ function he(t) {
|
|
|
490
490
|
}
|
|
491
491
|
};
|
|
492
492
|
}
|
|
493
|
-
function
|
|
493
|
+
function he(t) {
|
|
494
494
|
const e = {};
|
|
495
495
|
for (const [s, n] of t)
|
|
496
496
|
s && typeof s == "string" && (e[s] = n || "");
|
|
497
497
|
return e;
|
|
498
498
|
}
|
|
499
|
-
function
|
|
499
|
+
function le(t) {
|
|
500
500
|
return typeof t == "function" ? t : Array.isArray(t) && t.length > 0 ? function(e) {
|
|
501
501
|
return t.includes(e.status);
|
|
502
|
-
} : t === "network" ?
|
|
502
|
+
} : t === "network" ? fe : de;
|
|
503
503
|
}
|
|
504
|
-
function
|
|
505
|
-
return t
|
|
504
|
+
function fe({ statusText: t }) {
|
|
505
|
+
return t == w.NetworkError;
|
|
506
506
|
}
|
|
507
|
-
function de(t) {
|
|
508
|
-
|
|
509
|
-
return !0;
|
|
510
|
-
const { status: e, headers: s } = t;
|
|
511
|
-
return s?.server === "TencentEdgeOne" ? e === 522 || e === 552 : !1;
|
|
507
|
+
function de({ status: t, headers: e, statusText: s }) {
|
|
508
|
+
return s == w.NetworkError ? !0 : e?.server === "TencentEdgeOne" ? t === 522 || t === 552 : !1;
|
|
512
509
|
}
|
|
513
|
-
function
|
|
514
|
-
const r = t.status, o = t.method, a =
|
|
510
|
+
function Te(t, e, s, n) {
|
|
511
|
+
const r = t.status, o = t.method, a = he(
|
|
515
512
|
Object.entries(t.headers || {}).map(([d, m]) => [d.toLowerCase(), m])
|
|
516
|
-
), { ok: i, code: c, data: g, message: u } =
|
|
513
|
+
), { ok: i, code: c, data: g, message: u } = te(
|
|
517
514
|
r,
|
|
518
515
|
t.statusText,
|
|
519
516
|
t.body,
|
|
520
517
|
s.get("responseRule"),
|
|
521
518
|
n?.responseRule
|
|
522
519
|
);
|
|
523
|
-
if (!
|
|
524
|
-
const d =
|
|
520
|
+
if (!S(r)) {
|
|
521
|
+
const d = ue({
|
|
525
522
|
url: t.url,
|
|
526
523
|
method: t.method,
|
|
527
524
|
status: r,
|
|
@@ -575,7 +572,7 @@ function E(t) {
|
|
|
575
572
|
return t.replace(/<script[\s\S]*?>[\s\S]*?<\/script>/gi, "").replace(/<[^>]+>/g, "").trim();
|
|
576
573
|
}
|
|
577
574
|
async function me(t, e, s, n, r) {
|
|
578
|
-
const o = r || 0, a = Math.max(0, Math.min(10, n?.maxRetry ?? s.get("maxRetry") ?? 0)), i =
|
|
575
|
+
const o = r || 0, a = Math.max(0, Math.min(10, n?.maxRetry ?? s.get("maxRetry") ?? 0)), i = le(n?.retryResolve ?? s.get("retryResolve")), c = s.get("logHandler");
|
|
579
576
|
c?.({
|
|
580
577
|
type: "prepare",
|
|
581
578
|
url: e,
|
|
@@ -600,7 +597,7 @@ async function me(t, e, s, n, r) {
|
|
|
600
597
|
}), !a || o >= a || i(u, o) !== !0)
|
|
601
598
|
return u;
|
|
602
599
|
const m = n?.retryInterval ?? s.get("retryInterval") ?? 100;
|
|
603
|
-
return await
|
|
600
|
+
return await q(
|
|
604
601
|
Math.max(
|
|
605
602
|
100,
|
|
606
603
|
m === "2EB" ? Math.pow(2, o) * 100 : typeof m == "function" ? m(o + 1, { url: e, status: h, method: u.method }) || 0 : m
|
|
@@ -608,20 +605,20 @@ async function me(t, e, s, n, r) {
|
|
|
608
605
|
), await me(t, e, s, n, o + 1);
|
|
609
606
|
}
|
|
610
607
|
export {
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
608
|
+
D as E,
|
|
609
|
+
ke as H,
|
|
610
|
+
Re as N,
|
|
611
|
+
Q as R,
|
|
615
612
|
pe as X,
|
|
616
613
|
w as a,
|
|
617
614
|
ye as b,
|
|
618
615
|
je as c,
|
|
619
616
|
we as d,
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
617
|
+
he as f,
|
|
618
|
+
$e as g,
|
|
619
|
+
Te as h,
|
|
623
620
|
be as i,
|
|
624
|
-
|
|
621
|
+
$ as n,
|
|
625
622
|
me as r,
|
|
626
623
|
Ee as v
|
|
627
624
|
};
|
package/dist/wx.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { h as i, r as p, c as f, H as l, E as h, a as d, i as y, N as g } from "./retry-
|
|
2
|
-
import { g as E } from "./retry-
|
|
1
|
+
import { h as i, r as p, c as f, H as l, E as h, a as d, i as y, N as g } from "./retry-Cxkf8ke1.js";
|
|
2
|
+
import { g as E } from "./retry-Cxkf8ke1.js";
|
|
3
3
|
const m = async function(t, n, r) {
|
|
4
4
|
return i(await p(x, t, n, r), t, n, r);
|
|
5
5
|
}, x = async function(t, n, r) {
|
package/package.json
CHANGED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { h as w, r as y, c as E, d as T, f as R, a as c } from "./retry-DodVI8cA.js";
|
|
2
|
-
const x = async function(a, s, n) {
|
|
3
|
-
return w(await y(g, a, s, n), a, s, n);
|
|
4
|
-
}, g = async function(a, s, n) {
|
|
5
|
-
const t = await E(a, s, n), i = new URL(t.url), u = t.params;
|
|
6
|
-
u instanceof Object && Object.keys(u).forEach((e) => i.searchParams.set(e, u[e]));
|
|
7
|
-
const r = T() ? new AbortController() : null;
|
|
8
|
-
function d() {
|
|
9
|
-
r && !r.signal.aborted && r.abort();
|
|
10
|
-
}
|
|
11
|
-
t.abort && t.abort.addEventListener("abort", d);
|
|
12
|
-
let l = !1;
|
|
13
|
-
const b = t.timeout > 0 ? setTimeout(function() {
|
|
14
|
-
l = !0, d();
|
|
15
|
-
}, t.timeout) : null, f = t.method === "HEAD";
|
|
16
|
-
return await fetch(i, {
|
|
17
|
-
method: t.method,
|
|
18
|
-
headers: Object.keys(t.headers).length > 0 ? new Headers(t.headers) : void 0,
|
|
19
|
-
body: t.body,
|
|
20
|
-
credentials: t.credentials,
|
|
21
|
-
signal: r?.signal,
|
|
22
|
-
redirect: "follow"
|
|
23
|
-
}).then(async (e) => {
|
|
24
|
-
const o = {
|
|
25
|
-
url: i.toString(),
|
|
26
|
-
method: t.method,
|
|
27
|
-
status: e.status,
|
|
28
|
-
statusText: e.statusText,
|
|
29
|
-
headers: R([...e.headers.entries()])
|
|
30
|
-
}, h = f || e.status === 204 ? "" : await e.text().catch((m) => m);
|
|
31
|
-
return h instanceof Error ? { ...o, body: "", statusText: c.Unknown, rawError: h } : { ...o, body: h };
|
|
32
|
-
}).catch((e) => {
|
|
33
|
-
const o = r?.signal.aborted;
|
|
34
|
-
return {
|
|
35
|
-
url: i.toString(),
|
|
36
|
-
method: t.method,
|
|
37
|
-
status: o && !l ? 0 : -1,
|
|
38
|
-
// 设置为 0 可以防止自动重试的默认策略
|
|
39
|
-
statusText: l ? c.Timeout : o ? c.Aborted : c.NetworkError,
|
|
40
|
-
body: "",
|
|
41
|
-
rawError: e
|
|
42
|
-
};
|
|
43
|
-
}).finally(() => {
|
|
44
|
-
b !== null && clearTimeout(b), t.abort && t.abort.removeEventListener("abort", d);
|
|
45
|
-
});
|
|
46
|
-
};
|
|
47
|
-
export {
|
|
48
|
-
x as f
|
|
49
|
-
};
|