@seayoo-web/request 3.4.0 → 3.4.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 +21 -21
- package/dist/node.js +22 -22
- package/dist/{request.fetch-B3ED8nRu.js → request.fetch-Cbt_az4v.js} +7 -7
- package/dist/retry-FiwuCZIu.js +630 -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/types/inc/utils.d.ts +5 -0
- package/dist/retry-CdUkYrFw.js +0 -606
package/dist/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { h as m, r as q, R as T, c as x,
|
|
2
|
-
import { g as
|
|
3
|
-
import { f as k } from "./request.fetch-
|
|
4
|
-
const
|
|
1
|
+
import { h as m, r as q, R as T, c as x, B as R, a as w, N as H, f as C, b as E, X as L } from "./retry-FiwuCZIu.js";
|
|
2
|
+
import { g as Q } from "./retry-FiwuCZIu.js";
|
|
3
|
+
import { f as k } from "./request.fetch-Cbt_az4v.js";
|
|
4
|
+
const S = async function(e, o, t) {
|
|
5
5
|
return m(await q(y, e, o, t), e, o, t);
|
|
6
6
|
};
|
|
7
|
-
async function
|
|
7
|
+
async function U(e, o, t, n) {
|
|
8
8
|
const r = t?.body, l = t?.method === "PUT" ? "PUT" : "POST";
|
|
9
9
|
if (o instanceof Blob) {
|
|
10
10
|
const i = new T(n), u = await y(e, i, {
|
|
@@ -56,7 +56,7 @@ const y = async function(e, o, t) {
|
|
|
56
56
|
method: r,
|
|
57
57
|
status: f,
|
|
58
58
|
statusText: s.statusText,
|
|
59
|
-
headers:
|
|
59
|
+
headers: j(s),
|
|
60
60
|
body: r === "HEAD" || f === 204 ? "" : s.responseText
|
|
61
61
|
});
|
|
62
62
|
}), s.addEventListener(
|
|
@@ -88,7 +88,7 @@ const y = async function(e, o, t) {
|
|
|
88
88
|
}, n.timeout));
|
|
89
89
|
});
|
|
90
90
|
};
|
|
91
|
-
function
|
|
91
|
+
function j(e) {
|
|
92
92
|
const o = {};
|
|
93
93
|
if (!e)
|
|
94
94
|
return o;
|
|
@@ -119,15 +119,15 @@ async function O(e, o, t = {}) {
|
|
|
119
119
|
});
|
|
120
120
|
});
|
|
121
121
|
}
|
|
122
|
-
async function
|
|
122
|
+
async function P(e, o, t = {}) {
|
|
123
123
|
const n = window;
|
|
124
124
|
return "var" in t || (t.var = "jsonxData" + Math.random().toString(16).slice(2)), e ? await H(R(e, t, !0)).then(() => {
|
|
125
125
|
const r = n[t.var + ""];
|
|
126
126
|
return o(r) ? r : (console.warn("response type check failed", e, r), null);
|
|
127
127
|
}).catch(() => null) : null;
|
|
128
128
|
}
|
|
129
|
-
const
|
|
130
|
-
return await
|
|
129
|
+
const A = async function(e, o, t) {
|
|
130
|
+
return await U(e, o, t, {
|
|
131
131
|
baseURL: c.getConfig("baseURL"),
|
|
132
132
|
logHandler: c.getConfig("logHandler"),
|
|
133
133
|
errorHandler: c.getConfig("errorHandler"),
|
|
@@ -136,25 +136,25 @@ const M = async function(e, o, t) {
|
|
|
136
136
|
responseHandler: c.getConfig("responseHandler")
|
|
137
137
|
});
|
|
138
138
|
};
|
|
139
|
-
function
|
|
139
|
+
function v(e) {
|
|
140
140
|
if (!C())
|
|
141
141
|
throw new Error("Default Module Only Support In Browser");
|
|
142
|
-
return L() ? new E(k, e) : new E(
|
|
142
|
+
return L() ? new E(k, e) : new E(S, e);
|
|
143
143
|
}
|
|
144
|
-
const c =
|
|
144
|
+
const c = v(), B = c.setConfig, M = c.request, X = c.head, F = c.get, G = c.post, I = c.del, $ = 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
|
+
Q as getResponseRulesDescription,
|
|
151
151
|
X as head,
|
|
152
152
|
O as jsonp,
|
|
153
|
-
|
|
154
|
-
|
|
153
|
+
P as jsonx,
|
|
154
|
+
z as patch,
|
|
155
155
|
G as post,
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
156
|
+
$ as put,
|
|
157
|
+
M as request,
|
|
158
|
+
B as setGlobalConfig,
|
|
159
|
+
A as upload
|
|
160
160
|
};
|
package/dist/node.js
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
import { h as
|
|
2
|
-
import { g as z } from "./retry-
|
|
3
|
-
import { f as C } from "./request.fetch-
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
const
|
|
7
|
-
return
|
|
8
|
-
},
|
|
1
|
+
import { h as y, r as q, c as w, e as g, a as c, d as E, b as f, X as x } from "./retry-FiwuCZIu.js";
|
|
2
|
+
import { g as z } from "./retry-FiwuCZIu.js";
|
|
3
|
+
import { f as C } from "./request.fetch-Cbt_az4v.js";
|
|
4
|
+
import T from "node:http";
|
|
5
|
+
import j from "node:https";
|
|
6
|
+
const L = async function(o, a, u) {
|
|
7
|
+
return y(await q(N, o, a, u), o, a, u);
|
|
8
|
+
}, N = async function(o, a, u) {
|
|
9
9
|
const t = await w(o, a, u);
|
|
10
10
|
if (!g(t.url))
|
|
11
11
|
return {
|
|
12
12
|
url: t.url,
|
|
13
13
|
method: t.method,
|
|
14
14
|
status: -1,
|
|
15
|
-
statusText:
|
|
15
|
+
statusText: c.URLFormatError,
|
|
16
16
|
headers: {},
|
|
17
17
|
body: ""
|
|
18
18
|
};
|
|
19
|
-
const R = /^https:\/\//i.test(t.url) ?
|
|
19
|
+
const R = /^https:\/\//i.test(t.url) ? j : T, n = new URL(t.url), i = t.params;
|
|
20
20
|
i instanceof Object && Object.keys(i).forEach((r) => n.searchParams.set(r, i[r]));
|
|
21
21
|
const l = t.method === "HEAD";
|
|
22
22
|
return new Promise((r) => {
|
|
23
|
-
const
|
|
23
|
+
const d = R.request(
|
|
24
24
|
n,
|
|
25
25
|
{
|
|
26
26
|
headers: t.headers,
|
|
@@ -31,47 +31,47 @@ 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(),
|
|
38
38
|
method: t.method,
|
|
39
39
|
status: e.statusCode || -1,
|
|
40
|
-
statusText: e.statusMessage ||
|
|
40
|
+
statusText: e.statusMessage || c.Unknown,
|
|
41
41
|
headers: m,
|
|
42
42
|
body: l || e.statusCode === 204 ? "" : Buffer.concat(p).toString("utf-8")
|
|
43
43
|
});
|
|
44
44
|
});
|
|
45
45
|
}
|
|
46
46
|
);
|
|
47
|
-
|
|
47
|
+
d.on("error", (e) => {
|
|
48
48
|
r({
|
|
49
49
|
url: n.toString(),
|
|
50
50
|
method: t.method,
|
|
51
51
|
status: -1,
|
|
52
|
-
statusText:
|
|
52
|
+
statusText: c.NetworkError,
|
|
53
53
|
body: "",
|
|
54
54
|
rawError: e
|
|
55
55
|
});
|
|
56
|
-
}),
|
|
56
|
+
}), d.on("timeout", () => {
|
|
57
57
|
r({
|
|
58
58
|
url: n.toString(),
|
|
59
59
|
method: t.method,
|
|
60
60
|
status: -1,
|
|
61
|
-
statusText:
|
|
61
|
+
statusText: c.Timeout,
|
|
62
62
|
body: ""
|
|
63
63
|
});
|
|
64
|
-
}), t.body &&
|
|
64
|
+
}), t.body && d.write(t.body), d.end();
|
|
65
65
|
});
|
|
66
66
|
};
|
|
67
67
|
function O(o) {
|
|
68
|
-
return x() ? new f(C, o) : new f(
|
|
68
|
+
return x() ? new f(C, o) : new f(L, 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, X = s.del, F = s.put, G = s.patch;
|
|
71
71
|
export {
|
|
72
72
|
O as NetRequest,
|
|
73
|
-
|
|
74
|
-
|
|
73
|
+
c as RequestInternalError,
|
|
74
|
+
X as del,
|
|
75
75
|
D as get,
|
|
76
76
|
z as getResponseRulesDescription,
|
|
77
77
|
B as head,
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { h as w, r as y, c as E,
|
|
2
|
-
const x = async function(
|
|
3
|
-
return w(await y(g,
|
|
4
|
-
}, g = async function(
|
|
5
|
-
const t = await E(
|
|
1
|
+
import { h as w, r as y, c as E, s as T, d as R, a as c } from "./retry-FiwuCZIu.js";
|
|
2
|
+
const x = async function(s, a, n) {
|
|
3
|
+
return w(await y(g, s, a, n), s, a, n);
|
|
4
|
+
}, g = async function(s, a, n) {
|
|
5
|
+
const t = await E(s, a, n), i = new URL(t.url), u = t.params;
|
|
6
6
|
u instanceof Object && Object.keys(u).forEach((e) => i.searchParams.set(e, u[e]));
|
|
7
7
|
const r = T() ? new AbortController() : null;
|
|
8
8
|
function d() {
|
|
@@ -12,7 +12,7 @@ const x = async function(a, s, n) {
|
|
|
12
12
|
let l = !1;
|
|
13
13
|
const b = t.timeout > 0 ? setTimeout(function() {
|
|
14
14
|
l = !0, d();
|
|
15
|
-
}, t.timeout) : null,
|
|
15
|
+
}, t.timeout) : null, m = t.method === "HEAD";
|
|
16
16
|
return await fetch(i, {
|
|
17
17
|
method: t.method,
|
|
18
18
|
headers: Object.keys(t.headers).length > 0 ? new Headers(t.headers) : void 0,
|
|
@@ -27,7 +27,7 @@ const x = async function(a, s, n) {
|
|
|
27
27
|
status: e.status,
|
|
28
28
|
statusText: e.statusText,
|
|
29
29
|
headers: R([...e.headers.entries()])
|
|
30
|
-
}, h =
|
|
30
|
+
}, h = m || e.status === 204 ? "" : await e.text().catch((f) => f);
|
|
31
31
|
return h instanceof Error ? { ...o, body: "", statusText: c.Unknown, rawError: h } : { ...o, body: h };
|
|
32
32
|
}).catch((e) => {
|
|
33
33
|
const o = r?.signal.aborted;
|