@seayoo-web/request 3.4.0 → 3.4.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/dist/index.js +66 -66
- package/dist/node.js +7 -7
- package/dist/{request.fetch-B3ED8nRu.js → request.fetch-6HUu6_l5.js} +1 -1
- package/dist/retry-BjOxSyvC.js +614 -0
- package/dist/wx.js +12 -12
- package/package.json +6 -6
- package/types/inc/config.d.ts +1 -1
- package/types/inc/guard.d.ts +1 -1
- package/types/inc/jsonp.d.ts +1 -1
- package/types/inc/main.d.ts +1 -1
- package/types/inc/request.fetch.d.ts +1 -1
- package/types/inc/request.node.d.ts +1 -1
- package/types/inc/request.wx.d.ts +1 -1
- package/types/inc/request.xhr.d.ts +1 -1
- package/dist/retry-CdUkYrFw.js +0 -606
package/README.md
CHANGED
|
@@ -141,7 +141,7 @@ setConfig({ timeout: 10000 });
|
|
|
141
141
|
|
|
142
142
|
类型:string
|
|
143
143
|
|
|
144
|
-
说明:默认的类型守卫错误提示,仅支持全局配置,默认
|
|
144
|
+
说明:默认的类型守卫错误提示,仅支持全局配置,默认 “响应数据未能正确识别”,单个 api 可通过传入完整的类型守卫({ guard, message })来定制提示消息。
|
|
145
145
|
|
|
146
146
|
### message
|
|
147
147
|
|
|
@@ -180,11 +180,11 @@ defaultMessage: string
|
|
|
180
180
|
|
|
181
181
|
**statusField**: string
|
|
182
182
|
|
|
183
|
-
|
|
183
|
+
解析状态的字段,仅在 resolve 为 json 时有效,有值的话会替换 response 的 code
|
|
184
184
|
|
|
185
185
|
**messageField**: string | string[]
|
|
186
186
|
|
|
187
|
-
|
|
187
|
+
解析错误消息的字段,仅在 resolve 为 json 时有效,默认值 "message"
|
|
188
188
|
|
|
189
189
|
- **OKRule**: { resolve, converter?, statusField?, statusOKValue?, dataField?, messageField?, ignoreMessage? }
|
|
190
190
|
|
package/dist/index.js
CHANGED
|
@@ -1,78 +1,78 @@
|
|
|
1
|
-
import { h as m, r as q, R as T, c as x,
|
|
2
|
-
import { g as z } from "./retry-
|
|
3
|
-
import { f as
|
|
4
|
-
const
|
|
5
|
-
return m(await q(y,
|
|
1
|
+
import { h as m, r as q, R as T, c as x, Q as R, a as w, _ as H, l as C, N as E, Z as L } from "./retry-BjOxSyvC.js";
|
|
2
|
+
import { g as z } from "./retry-BjOxSyvC.js";
|
|
3
|
+
import { f as j } from "./request.fetch-6HUu6_l5.js";
|
|
4
|
+
const k = async function(t, s, e) {
|
|
5
|
+
return m(await q(y, t, s, e), t, s, e);
|
|
6
6
|
};
|
|
7
|
-
async function S(
|
|
8
|
-
const r =
|
|
9
|
-
if (
|
|
10
|
-
const i = new T(n), u = await y(
|
|
11
|
-
...
|
|
7
|
+
async function S(t, s, e, n) {
|
|
8
|
+
const r = e?.body, l = e?.method === "PUT" ? "PUT" : "POST";
|
|
9
|
+
if (s instanceof Blob) {
|
|
10
|
+
const i = new T(n), u = await y(t, i, {
|
|
11
|
+
...e,
|
|
12
12
|
method: l,
|
|
13
|
-
body:
|
|
13
|
+
body: s
|
|
14
14
|
});
|
|
15
|
-
return m(u,
|
|
15
|
+
return m(u, t, i, e);
|
|
16
16
|
}
|
|
17
|
-
const a = new FormData(), d = { ...
|
|
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((
|
|
20
|
-
a.append(`${i}[${g}]`, String(
|
|
19
|
+
u instanceof Blob ? d[i] = u : Array.isArray(u) ? u.forEach((o, g) => {
|
|
20
|
+
a.append(`${i}[${g}]`, 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),
|
|
26
|
-
...
|
|
25
|
+
const b = new T(n), h = await y(t, b, {
|
|
26
|
+
...e,
|
|
27
27
|
method: l,
|
|
28
28
|
body: a
|
|
29
29
|
});
|
|
30
|
-
return m(
|
|
30
|
+
return m(h, t, b, e);
|
|
31
31
|
}
|
|
32
|
-
const y = async function(
|
|
33
|
-
const n = await x(
|
|
32
|
+
const y = async function(t, s, e) {
|
|
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, h = !1;
|
|
36
36
|
const i = function() {
|
|
37
|
-
|
|
37
|
+
h || (o.abort(), h = !0);
|
|
38
38
|
};
|
|
39
39
|
function u() {
|
|
40
40
|
b !== null && clearTimeout(b), n.abort && n.abort.removeEventListener("abort", i);
|
|
41
41
|
}
|
|
42
|
-
const
|
|
42
|
+
const o = new XMLHttpRequest();
|
|
43
43
|
let g = !1;
|
|
44
|
-
if (
|
|
44
|
+
if (o.open(r, a, !0), l) {
|
|
45
45
|
let f = 1;
|
|
46
|
-
|
|
47
|
-
f =
|
|
48
|
-
}),
|
|
46
|
+
o.upload.addEventListener("progress", (p) => {
|
|
47
|
+
f = p.total, l({ total: p.total, loaded: p.loaded });
|
|
48
|
+
}), o.addEventListener("load", () => {
|
|
49
49
|
l({ loaded: f, total: f });
|
|
50
50
|
});
|
|
51
51
|
}
|
|
52
|
-
|
|
53
|
-
const f =
|
|
52
|
+
o.addEventListener("load", () => {
|
|
53
|
+
const f = o.status, p = o.responseType;
|
|
54
54
|
u(), d({
|
|
55
55
|
url: a,
|
|
56
56
|
method: r,
|
|
57
57
|
status: f,
|
|
58
|
-
statusText:
|
|
59
|
-
headers: U(
|
|
60
|
-
body: r === "HEAD" || f === 204 ? "" :
|
|
58
|
+
statusText: o.statusText,
|
|
59
|
+
headers: U(o),
|
|
60
|
+
body: r === "HEAD" || f === 204 ? "" : p === "" || p === "text" || p === "json" || p === "document" ? o.responseText : ""
|
|
61
61
|
});
|
|
62
|
-
}),
|
|
62
|
+
}), o.addEventListener(
|
|
63
63
|
"error",
|
|
64
64
|
(f) => {
|
|
65
65
|
u(), d({
|
|
66
66
|
url: a,
|
|
67
67
|
method: r,
|
|
68
|
-
status:
|
|
69
|
-
statusText:
|
|
68
|
+
status: o.status || -1,
|
|
69
|
+
statusText: o.statusText || w.NetworkError,
|
|
70
70
|
body: "",
|
|
71
71
|
rawError: f
|
|
72
72
|
});
|
|
73
73
|
},
|
|
74
74
|
!0
|
|
75
|
-
),
|
|
75
|
+
), o.addEventListener("abort", () => {
|
|
76
76
|
u(), d({
|
|
77
77
|
url: a,
|
|
78
78
|
method: r,
|
|
@@ -81,53 +81,53 @@ const y = async function(e, o, t) {
|
|
|
81
81
|
statusText: g ? w.Timeout : w.Aborted,
|
|
82
82
|
body: ""
|
|
83
83
|
});
|
|
84
|
-
}), Object.entries(n.headers).forEach(([f,
|
|
85
|
-
|
|
86
|
-
}), n.credentials === "include" && (
|
|
84
|
+
}), Object.entries(n.headers).forEach(([f, p]) => {
|
|
85
|
+
o.setRequestHeader(f, p);
|
|
86
|
+
}), 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
87
|
g = !0, i();
|
|
88
88
|
}, n.timeout));
|
|
89
89
|
});
|
|
90
90
|
};
|
|
91
|
-
function U(
|
|
92
|
-
const
|
|
93
|
-
if (!
|
|
94
|
-
return
|
|
95
|
-
const
|
|
96
|
-
return
|
|
91
|
+
function U(t) {
|
|
92
|
+
const s = {};
|
|
93
|
+
if (!t)
|
|
94
|
+
return s;
|
|
95
|
+
const e = t.getAllResponseHeaders();
|
|
96
|
+
return e && e !== "null" && e.replace(/\r/g, "").split(`
|
|
97
97
|
`).forEach((n) => {
|
|
98
98
|
const r = n.trim();
|
|
99
99
|
if (!r)
|
|
100
100
|
return;
|
|
101
101
|
const l = r.split(":"), a = l[0].trim();
|
|
102
|
-
a && (
|
|
103
|
-
}),
|
|
102
|
+
a && (s[a] = (l[1] || "").trim());
|
|
103
|
+
}), s;
|
|
104
104
|
}
|
|
105
|
-
async function
|
|
105
|
+
async function P(t, s, e = {}) {
|
|
106
106
|
const n = window;
|
|
107
|
-
"callback" in
|
|
108
|
-
const r =
|
|
109
|
-
if (!
|
|
107
|
+
"callback" in e || (e.callback = "jsonxData" + Math.random().toString(16).slice(2));
|
|
108
|
+
const r = e.callback + "";
|
|
109
|
+
if (!t)
|
|
110
110
|
return null;
|
|
111
|
-
const l = R(
|
|
111
|
+
const l = R(t, e, !0);
|
|
112
112
|
return new Promise((a) => {
|
|
113
113
|
n[r] = function(d) {
|
|
114
|
-
if (r in window && delete n[r],
|
|
114
|
+
if (r in window && delete n[r], s(d))
|
|
115
115
|
return d;
|
|
116
|
-
console.warn("response type check failed",
|
|
116
|
+
console.warn("response type check failed", t, d), a(null);
|
|
117
117
|
}, H(l).catch(function() {
|
|
118
118
|
a(null), delete n[r];
|
|
119
119
|
});
|
|
120
120
|
});
|
|
121
121
|
}
|
|
122
|
-
async function A(
|
|
122
|
+
async function A(t, s, e = {}) {
|
|
123
123
|
const n = window;
|
|
124
|
-
return "var" in
|
|
125
|
-
const r = n[
|
|
126
|
-
return
|
|
124
|
+
return "var" in e || (e.var = "jsonxData" + Math.random().toString(16).slice(2)), t ? await H(R(t, e, !0)).then(() => {
|
|
125
|
+
const r = n[e.var + ""];
|
|
126
|
+
return s(r) ? r : (console.warn("response type check failed", t, r), null);
|
|
127
127
|
}).catch(() => null) : null;
|
|
128
128
|
}
|
|
129
|
-
const M = async function(
|
|
130
|
-
return await S(
|
|
129
|
+
const M = async function(t, s, e) {
|
|
130
|
+
return await S(t, s, e, {
|
|
131
131
|
baseURL: c.getConfig("baseURL"),
|
|
132
132
|
logHandler: c.getConfig("logHandler"),
|
|
133
133
|
errorHandler: c.getConfig("errorHandler"),
|
|
@@ -136,22 +136,22 @@ const M = async function(e, o, t) {
|
|
|
136
136
|
responseHandler: c.getConfig("responseHandler")
|
|
137
137
|
});
|
|
138
138
|
};
|
|
139
|
-
function
|
|
139
|
+
function v(t) {
|
|
140
140
|
if (!C())
|
|
141
141
|
throw new Error("Default Module Only Support In Browser");
|
|
142
|
-
return L() ? new E(
|
|
142
|
+
return L() ? new E(j, t) : new E(k, t);
|
|
143
143
|
}
|
|
144
|
-
const c =
|
|
144
|
+
const c = v(), N = c.setConfig, B = c.request, X = c.head, F = c.get, G = c.post, I = c.del, Q = c.put, Z = c.patch;
|
|
145
145
|
export {
|
|
146
|
-
|
|
146
|
+
v as NetRequest,
|
|
147
147
|
w as RequestInternalError,
|
|
148
148
|
I as del,
|
|
149
149
|
F as get,
|
|
150
150
|
z as getResponseRulesDescription,
|
|
151
151
|
X as head,
|
|
152
|
-
|
|
152
|
+
P as jsonp,
|
|
153
153
|
A as jsonx,
|
|
154
|
-
|
|
154
|
+
Z as patch,
|
|
155
155
|
G as post,
|
|
156
156
|
Q as put,
|
|
157
157
|
B as request,
|
package/dist/node.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { h as
|
|
2
|
-
import { g as z } from "./retry-
|
|
3
|
-
import { f as C } from "./request.fetch-
|
|
1
|
+
import { h as y, r as q, c as w, b as g, a as d, f as E, N as f, Z as x } from "./retry-BjOxSyvC.js";
|
|
2
|
+
import { g as z } from "./retry-BjOxSyvC.js";
|
|
3
|
+
import { f as C } from "./request.fetch-6HUu6_l5.js";
|
|
4
4
|
import N from "node:http";
|
|
5
5
|
import T from "node:https";
|
|
6
6
|
const j = async function(o, a, u) {
|
|
7
|
-
return
|
|
7
|
+
return y(await q(L, o, a, u), o, a, u);
|
|
8
8
|
}, L = async function(o, a, u) {
|
|
9
9
|
const t = await w(o, a, u);
|
|
10
10
|
if (!g(t.url))
|
|
@@ -31,7 +31,7 @@ const j = async function(o, a, u) {
|
|
|
31
31
|
const p = [];
|
|
32
32
|
e.on("data", (m) => p.push(m)), e.on("end", () => {
|
|
33
33
|
const m = E(
|
|
34
|
-
Object.entries(e.headers).map(([
|
|
34
|
+
Object.entries(e.headers).map(([b, h]) => [b.toLowerCase(), Array.isArray(h) ? h.join(",") : h])
|
|
35
35
|
);
|
|
36
36
|
r({
|
|
37
37
|
url: n.toString(),
|
|
@@ -67,11 +67,11 @@ const j = async function(o, a, u) {
|
|
|
67
67
|
function O(o) {
|
|
68
68
|
return x() ? new f(C, o) : new f(j, o);
|
|
69
69
|
}
|
|
70
|
-
const s = O(), k = s.setConfig, B = s.head, D = s.get, P = s.post,
|
|
70
|
+
const s = O(), k = s.setConfig, B = s.head, D = s.get, P = s.post, Z = s.del, F = s.put, G = s.patch;
|
|
71
71
|
export {
|
|
72
72
|
O as NetRequest,
|
|
73
73
|
d as RequestInternalError,
|
|
74
|
-
|
|
74
|
+
Z as del,
|
|
75
75
|
D as get,
|
|
76
76
|
z as getResponseRulesDescription,
|
|
77
77
|
B as head,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { h as w, r as y, c as E,
|
|
1
|
+
import { h as w, r as y, c as E, u as T, f as R, a as c } from "./retry-BjOxSyvC.js";
|
|
2
2
|
const x = async function(a, s, n) {
|
|
3
3
|
return w(await y(g, a, s, n), a, s, n);
|
|
4
4
|
}, g = async function(a, s, n) {
|