@seayoo-web/request 3.5.2 → 4.0.0
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 +58 -56
- package/dist/index.js +135 -121
- package/dist/node.js +58 -58
- package/dist/request.fetch-BNCxK4Wq.js +54 -0
- package/dist/retry-DRbCcUt8.js +646 -0
- package/dist/wx.js +58 -49
- package/package.json +1 -1
- package/types/inc/cache.d.ts +2 -2
- package/types/inc/config.d.ts +5 -5
- package/types/inc/guard.d.ts +3 -3
- package/types/inc/jsonp.d.ts +3 -2
- package/types/inc/main.d.ts +51 -34
- package/types/inc/option.d.ts +6 -7
- package/types/inc/request.xhr.d.ts +4 -4
- package/types/inc/response.d.ts +8 -3
- package/types/inc/retry.d.ts +3 -3
- package/types/inc/rule.d.ts +5 -5
- package/types/inc/sentry.d.ts +4 -4
- package/types/inc/type.d.ts +55 -50
- package/types/inc/utils.d.ts +6 -2
- package/types/index.d.ts +37 -25
- package/types/node.d.ts +26 -24
- package/types/wx.d.ts +22 -20
- package/dist/request.fetch-Jj3A4PnG.js +0 -48
- package/dist/retry-Cxkf8ke1.js +0 -624
package/dist/node.js
CHANGED
|
@@ -1,83 +1,83 @@
|
|
|
1
|
-
import { h as
|
|
2
|
-
import { g as
|
|
3
|
-
import { f as
|
|
1
|
+
import { h as w, r as R, c as y, d as b, f as q, R as s, N as h, X as g } from "./retry-DRbCcUt8.js";
|
|
2
|
+
import { g as S } from "./retry-DRbCcUt8.js";
|
|
3
|
+
import { f as x } from "./request.fetch-BNCxK4Wq.js";
|
|
4
4
|
import N from "node:http";
|
|
5
|
-
import
|
|
6
|
-
const
|
|
7
|
-
return
|
|
8
|
-
},
|
|
9
|
-
const t = await
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
method: t.method,
|
|
14
|
-
status: -1,
|
|
15
|
-
statusText: d.URLFormatError,
|
|
16
|
-
headers: {},
|
|
17
|
-
body: ""
|
|
18
|
-
};
|
|
19
|
-
const R = /^https:\/\//i.test(t.url) ? T : N, n = new URL(t.url), i = t.params;
|
|
20
|
-
i instanceof Object && Object.keys(i).forEach((r) => n.searchParams.set(r, i[r]));
|
|
21
|
-
const l = t.method === "HEAD";
|
|
22
|
-
return new Promise((r) => {
|
|
23
|
-
const c = R.request(
|
|
24
|
-
n,
|
|
5
|
+
import C from "node:https";
|
|
6
|
+
const E = async function(o, n, a) {
|
|
7
|
+
return w(await R(T, o, n, a), o, n, a);
|
|
8
|
+
}, T = async function(o, n, a) {
|
|
9
|
+
const t = await y(o, n, a), p = /^https:\/\//i.test(t.url) ? C : N;
|
|
10
|
+
return new Promise((d) => {
|
|
11
|
+
const u = p.request(
|
|
12
|
+
t.url,
|
|
25
13
|
{
|
|
26
14
|
headers: t.headers,
|
|
27
15
|
method: t.method,
|
|
28
16
|
timeout: t.timeout > 0 ? t.timeout : void 0
|
|
29
17
|
},
|
|
30
18
|
function(e) {
|
|
31
|
-
const
|
|
32
|
-
e.on("data", (
|
|
33
|
-
const
|
|
34
|
-
Object.entries(e.headers).map(([
|
|
19
|
+
const f = [];
|
|
20
|
+
e.on("data", (c) => f.push(c)), e.on("end", async () => {
|
|
21
|
+
const c = b(
|
|
22
|
+
Object.entries(e.headers).map(([l, i]) => [l.toLowerCase(), Array.isArray(i) ? i.join(",") : i])
|
|
23
|
+
), m = Buffer.concat(f);
|
|
24
|
+
d(
|
|
25
|
+
await q(
|
|
26
|
+
{
|
|
27
|
+
url: t.url,
|
|
28
|
+
method: t.method,
|
|
29
|
+
status: e.statusCode || -1,
|
|
30
|
+
error: e.statusCode ? void 0 : s.Unknown,
|
|
31
|
+
statusText: e.statusMessage || s.Unknown,
|
|
32
|
+
headers: c,
|
|
33
|
+
body: null
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
asBuffer: t.asBuffer,
|
|
37
|
+
text: () => m.toString("utf-8"),
|
|
38
|
+
buffer: () => m.buffer
|
|
39
|
+
}
|
|
40
|
+
)
|
|
35
41
|
);
|
|
36
|
-
r({
|
|
37
|
-
url: n.toString(),
|
|
38
|
-
method: t.method,
|
|
39
|
-
status: e.statusCode || -1,
|
|
40
|
-
statusText: e.statusMessage || d.Unknown,
|
|
41
|
-
headers: m,
|
|
42
|
-
body: l || e.statusCode === 204 ? "" : Buffer.concat(p).toString("utf-8")
|
|
43
|
-
});
|
|
44
42
|
});
|
|
45
43
|
}
|
|
46
44
|
);
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
url:
|
|
45
|
+
u.on("error", (e) => {
|
|
46
|
+
d({
|
|
47
|
+
url: t.url,
|
|
50
48
|
method: t.method,
|
|
51
49
|
status: -1,
|
|
52
|
-
|
|
53
|
-
|
|
50
|
+
error: s.NetworkError,
|
|
51
|
+
statusText: s.NetworkError,
|
|
52
|
+
body: null,
|
|
54
53
|
rawError: e
|
|
55
54
|
});
|
|
56
|
-
}),
|
|
57
|
-
|
|
58
|
-
url:
|
|
55
|
+
}), u.on("timeout", () => {
|
|
56
|
+
d({
|
|
57
|
+
url: t.url,
|
|
59
58
|
method: t.method,
|
|
60
59
|
status: -1,
|
|
61
|
-
|
|
62
|
-
|
|
60
|
+
error: s.Timeout,
|
|
61
|
+
statusText: s.Timeout,
|
|
62
|
+
body: null
|
|
63
63
|
});
|
|
64
|
-
}), t.body &&
|
|
64
|
+
}), t.body && u.write(t.body), u.end();
|
|
65
65
|
});
|
|
66
66
|
};
|
|
67
67
|
// @__NO_SIDE_EFFECTS__
|
|
68
|
-
function
|
|
69
|
-
return
|
|
68
|
+
function k(o) {
|
|
69
|
+
return g() ? new h(x, o) : new h(E, o);
|
|
70
70
|
}
|
|
71
|
-
const
|
|
71
|
+
const r = /* @__PURE__ */ k(), U = r.setConfig, X = r.head, D = r.get, G = r.post, H = r.del, I = r.put, L = r.patch;
|
|
72
72
|
export {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
73
|
+
k as NetRequest,
|
|
74
|
+
s as RequestInternalError,
|
|
75
|
+
H as del,
|
|
76
76
|
D as get,
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
77
|
+
S as getResponseRulesDescription,
|
|
78
|
+
X as head,
|
|
79
|
+
L as patch,
|
|
80
|
+
G as post,
|
|
81
|
+
I as put,
|
|
82
|
+
U as setGlobalConfig
|
|
83
83
|
};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { h as f, r as h, c as m, e as b, f as y, d as T, R as u } from "./retry-DRbCcUt8.js";
|
|
2
|
+
const x = async function(o, a, s) {
|
|
3
|
+
return f(await h(w, o, a, s), o, a, s);
|
|
4
|
+
}, w = async function(o, a, s) {
|
|
5
|
+
const t = await m(o, a, s), r = b() ? new AbortController() : null;
|
|
6
|
+
function n(e) {
|
|
7
|
+
r && !r.signal.aborted && r.abort(e);
|
|
8
|
+
}
|
|
9
|
+
t.abort?.addEventListener("abort", n);
|
|
10
|
+
let i = !1;
|
|
11
|
+
const l = t.timeout > 0 ? setTimeout(function() {
|
|
12
|
+
i = !0, n("TimeoutTriggered");
|
|
13
|
+
}, t.timeout) : null;
|
|
14
|
+
return await fetch(t.url, {
|
|
15
|
+
method: t.method,
|
|
16
|
+
headers: Object.keys(t.headers).length > 0 ? new Headers(t.headers) : void 0,
|
|
17
|
+
body: t.body,
|
|
18
|
+
credentials: t.credentials,
|
|
19
|
+
signal: r?.signal,
|
|
20
|
+
redirect: "follow"
|
|
21
|
+
}).then(
|
|
22
|
+
async (e) => y(
|
|
23
|
+
{
|
|
24
|
+
url: t.url,
|
|
25
|
+
method: t.method,
|
|
26
|
+
status: e.status,
|
|
27
|
+
statusText: e.statusText,
|
|
28
|
+
headers: T([...e.headers.entries()]),
|
|
29
|
+
body: null
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
asBuffer: t.asBuffer,
|
|
33
|
+
text: () => e.text(),
|
|
34
|
+
buffer: () => e.arrayBuffer()
|
|
35
|
+
}
|
|
36
|
+
)
|
|
37
|
+
).catch((e) => {
|
|
38
|
+
const c = r?.signal.aborted, d = i ? u.Timeout : c ? u.Aborted : u.NetworkError;
|
|
39
|
+
return {
|
|
40
|
+
url: t.url,
|
|
41
|
+
method: t.method,
|
|
42
|
+
status: -1,
|
|
43
|
+
error: d,
|
|
44
|
+
statusText: d,
|
|
45
|
+
body: null,
|
|
46
|
+
rawError: e
|
|
47
|
+
};
|
|
48
|
+
}).finally(() => {
|
|
49
|
+
l !== null && clearTimeout(l), t.abort && t.abort.removeEventListener("abort", n);
|
|
50
|
+
});
|
|
51
|
+
};
|
|
52
|
+
export {
|
|
53
|
+
x as f
|
|
54
|
+
};
|