@seayoo-web/request 4.0.5 → 4.1.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/dist/index.js +143 -166
- package/dist/node.js +61 -81
- package/dist/request.fetch-CY3SKtx7.js +48 -0
- package/dist/retry-x0AqZ13h.js +635 -0
- package/dist/uni.js +61 -0
- package/dist/wx.js +62 -68
- package/package.json +30 -25
- package/types/inc/request.uni.d.ts +5 -0
- package/types/index.d.ts +25 -25
- package/types/node.d.ts +21 -21
- package/types/uni.d.ts +60 -0
- package/types/wx.d.ts +17 -17
- package/dist/request.fetch-zzHMZXfR.js +0 -54
- package/dist/retry-LYfsjIVg.js +0 -655
package/dist/index.js
CHANGED
|
@@ -1,174 +1,151 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { _ as e, a as t, d as n, f as r, h as i, i as a, m as o, n as s, o as c, p as l, r as u, s as d, t as f, u as p } from "./retry-x0AqZ13h.js";
|
|
2
|
+
import { t as m } from "./request.fetch-CY3SKtx7.js";
|
|
3
|
+
//#region src/inc/request.xhr.ts
|
|
4
|
+
var h = async function(e, t, n) {
|
|
5
|
+
return u(await f(_, e, t, n), e, t, n);
|
|
6
6
|
};
|
|
7
|
-
async function
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
return h(p, n, f, t);
|
|
7
|
+
async function g(e, t, n, i) {
|
|
8
|
+
let a = n?.body, o = n?.method === "PUT" ? "PUT" : "POST";
|
|
9
|
+
if (t instanceof Blob) {
|
|
10
|
+
let a = new r(i);
|
|
11
|
+
return u(await _(e, a, {
|
|
12
|
+
...n,
|
|
13
|
+
method: o,
|
|
14
|
+
body: t
|
|
15
|
+
}), e, a, n);
|
|
16
|
+
}
|
|
17
|
+
let s = new FormData(), c = { ...t };
|
|
18
|
+
a instanceof Object && Object.entries(a).forEach(([e, t]) => {
|
|
19
|
+
t instanceof Blob ? c[e] = t : Array.isArray(t) ? t.forEach((t, n) => {
|
|
20
|
+
s.append(`${e}[${n}]`, String(t));
|
|
21
|
+
}) : s.append(e, String(t));
|
|
22
|
+
});
|
|
23
|
+
for (let e in c) s.append(e, c[e]);
|
|
24
|
+
let l = new r(i);
|
|
25
|
+
return u(await _(e, l, {
|
|
26
|
+
...n,
|
|
27
|
+
method: o,
|
|
28
|
+
body: s
|
|
29
|
+
}), e, l, n);
|
|
31
30
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
e.setRequestHeader(s, b);
|
|
99
|
-
}), r.credentials === "include" && (e.withCredentials = !0), e.send(r.body || void 0), r.abort && r.abort.addEventListener("abort", p), r.timeout > 0 && (d = setTimeout(function() {
|
|
100
|
-
g = !0, p();
|
|
101
|
-
}, r.timeout));
|
|
102
|
-
});
|
|
31
|
+
var _ = async function(e, r, i) {
|
|
32
|
+
let a = await t(e, r, i), o = a.method, c = i?.onUploadProgress;
|
|
33
|
+
return await new Promise((e) => {
|
|
34
|
+
let t = null, r = !1, i = function() {
|
|
35
|
+
r ||= (u.abort(), !0);
|
|
36
|
+
};
|
|
37
|
+
function l() {
|
|
38
|
+
t !== null && clearTimeout(t), a.abort && a.abort.removeEventListener("abort", i);
|
|
39
|
+
}
|
|
40
|
+
let u = new XMLHttpRequest(), f = !1;
|
|
41
|
+
if (u.open(o, a.url, !0), c) {
|
|
42
|
+
let e = 1;
|
|
43
|
+
u.upload.addEventListener("progress", (t) => {
|
|
44
|
+
e = t.total, c({
|
|
45
|
+
total: t.total,
|
|
46
|
+
loaded: t.loaded
|
|
47
|
+
});
|
|
48
|
+
}), u.addEventListener("load", () => {
|
|
49
|
+
c({
|
|
50
|
+
loaded: e,
|
|
51
|
+
total: e
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
u.addEventListener("load", async () => {
|
|
56
|
+
l();
|
|
57
|
+
let t = u.responseType;
|
|
58
|
+
e(await s({
|
|
59
|
+
url: a.url,
|
|
60
|
+
method: o,
|
|
61
|
+
status: u.status,
|
|
62
|
+
statusText: u.statusText,
|
|
63
|
+
headers: v(u),
|
|
64
|
+
body: null
|
|
65
|
+
}, {
|
|
66
|
+
asBuffer: a.asBuffer,
|
|
67
|
+
text: () => t === "" || t === "text" || t === "json" || t === "document" ? u.responseText : "",
|
|
68
|
+
buffer: async () => t === "arraybuffer" ? u.response : t === "blob" ? await u.response.arrayBuffer() : await d(u.responseText)
|
|
69
|
+
}));
|
|
70
|
+
}), u.addEventListener("error", (t) => {
|
|
71
|
+
l(), e({
|
|
72
|
+
url: a.url,
|
|
73
|
+
method: o,
|
|
74
|
+
status: u.status || -1,
|
|
75
|
+
error: u.status ? void 0 : n.NetworkError,
|
|
76
|
+
statusText: u.statusText || n.NetworkError,
|
|
77
|
+
body: null,
|
|
78
|
+
rawError: t
|
|
79
|
+
});
|
|
80
|
+
}, !0), u.addEventListener("abort", () => {
|
|
81
|
+
l();
|
|
82
|
+
let t = f ? n.Timeout : n.Aborted;
|
|
83
|
+
e({
|
|
84
|
+
url: a.url,
|
|
85
|
+
method: o,
|
|
86
|
+
status: -1,
|
|
87
|
+
error: t,
|
|
88
|
+
statusText: t,
|
|
89
|
+
body: null
|
|
90
|
+
});
|
|
91
|
+
}), Object.entries(a.headers).forEach(([e, t]) => {
|
|
92
|
+
u.setRequestHeader(e, t);
|
|
93
|
+
}), a.credentials === "include" && (u.withCredentials = !0), u.send(a.body || void 0), a.abort && a.abort.addEventListener("abort", i), a.timeout > 0 && (t = setTimeout(function() {
|
|
94
|
+
f = !0, i();
|
|
95
|
+
}, a.timeout));
|
|
96
|
+
});
|
|
103
97
|
};
|
|
104
|
-
function
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
const u = o.split(":"), c = u[0].trim();
|
|
115
|
-
c && (a[c] = (u[1] || "").trim());
|
|
116
|
-
}), a;
|
|
98
|
+
function v(e) {
|
|
99
|
+
let t = {};
|
|
100
|
+
if (!e) return t;
|
|
101
|
+
let n = e.getAllResponseHeaders();
|
|
102
|
+
return n && n !== "null" && n.replace(/\r/g, "").split("\n").forEach((e) => {
|
|
103
|
+
let n = e.trim();
|
|
104
|
+
if (!n) return;
|
|
105
|
+
let r = n.split(":"), i = r[0].trim();
|
|
106
|
+
i && (t[i] = (r[1] || "").trim());
|
|
107
|
+
}), t;
|
|
117
108
|
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
109
|
+
//#endregion
|
|
110
|
+
//#region src/inc/jsonp.ts
|
|
111
|
+
async function y(e, t, n = {}) {
|
|
112
|
+
let r = window;
|
|
113
|
+
"callback" in n || (n.callback = "jsonxData" + Math.random().toString(16).slice(2));
|
|
114
|
+
let a = n.callback + "";
|
|
115
|
+
if (!e) return null;
|
|
116
|
+
let o = l(e, c(n), !0);
|
|
117
|
+
return new Promise((n) => {
|
|
118
|
+
r[a] = function(i) {
|
|
119
|
+
if (a in window && delete r[a], t(i)) return i;
|
|
120
|
+
console.warn("response type check failed", e, i), n(null);
|
|
121
|
+
}, i(o).catch(function() {
|
|
122
|
+
n(null), delete r[a];
|
|
123
|
+
});
|
|
124
|
+
});
|
|
134
125
|
}
|
|
135
|
-
async function
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
126
|
+
async function b(e, t, n = {}) {
|
|
127
|
+
let r = window;
|
|
128
|
+
return "var" in n || (n.var = "jsonxData" + Math.random().toString(16).slice(2)), e ? await i(l(e, c(n), !0)).then(() => {
|
|
129
|
+
let i = r[n.var + ""];
|
|
130
|
+
return t(i) ? i : (console.warn("response type check failed", e, i), null);
|
|
131
|
+
}).catch(() => null) : null;
|
|
141
132
|
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
133
|
+
//#endregion
|
|
134
|
+
//#region src/index.ts
|
|
135
|
+
var x = async function(e, t, n) {
|
|
136
|
+
return await g(e, t, n, {
|
|
137
|
+
baseURL: C.getConfig("baseURL"),
|
|
138
|
+
logHandler: C.getConfig("logHandler"),
|
|
139
|
+
errorHandler: C.getConfig("errorHandler"),
|
|
140
|
+
requestTransformer: C.getConfig("requestTransformer"),
|
|
141
|
+
messageHandler: C.getConfig("messageHandler"),
|
|
142
|
+
responseHandler: C.getConfig("responseHandler")
|
|
143
|
+
});
|
|
151
144
|
};
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
throw new Error("Default Module Only Support In Browser");
|
|
156
|
-
return k() ? new T(S, n) : new T(j, n);
|
|
145
|
+
function S(t) {
|
|
146
|
+
if (!e()) throw Error("Default Module Only Support In Browser");
|
|
147
|
+
return o() ? new p(m, t) : new p(h, t);
|
|
157
148
|
}
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
w as RequestInternalError,
|
|
162
|
-
z as del,
|
|
163
|
-
I as get,
|
|
164
|
-
W as getResponseRulesDescription,
|
|
165
|
-
F as head,
|
|
166
|
-
O as jsonp,
|
|
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
|
-
};
|
|
149
|
+
var C = S(), w = C.setConfig, T = C.request, E = C.head, D = C.get, O = C.post, k = C.del, A = C.put, j = C.patch;
|
|
150
|
+
//#endregion
|
|
151
|
+
export { S as NetRequest, n as RequestInternalError, k as del, D as get, a as getResponseRulesDescription, E as head, y as jsonp, b as jsonx, j as patch, O as post, A as put, T as request, w as setGlobalConfig, x as upload };
|
package/dist/node.js
CHANGED
|
@@ -1,83 +1,63 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
},
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}), u.on("timeout", () => {
|
|
56
|
-
d({
|
|
57
|
-
url: t.url,
|
|
58
|
-
method: t.method,
|
|
59
|
-
status: -1,
|
|
60
|
-
error: s.Timeout,
|
|
61
|
-
statusText: s.Timeout,
|
|
62
|
-
body: null
|
|
63
|
-
});
|
|
64
|
-
}), t.body && u.write(t.body), u.end();
|
|
65
|
-
});
|
|
1
|
+
import { a as e, c as t, d as n, i as r, m as i, n as a, r as o, t as s, u as c } from "./retry-x0AqZ13h.js";
|
|
2
|
+
import { t as l } from "./request.fetch-CY3SKtx7.js";
|
|
3
|
+
import u from "node:http";
|
|
4
|
+
import d from "node:https";
|
|
5
|
+
//#region src/inc/request.node.ts
|
|
6
|
+
var f = async function(e, t, n) {
|
|
7
|
+
return o(await s(p, e, t, n), e, t, n);
|
|
8
|
+
}, p = async function(r, i, o) {
|
|
9
|
+
let s = await e(r, i, o), c = /^https:\/\//i.test(s.url) ? d : u;
|
|
10
|
+
return new Promise((e) => {
|
|
11
|
+
let r = c.request(s.url, {
|
|
12
|
+
headers: s.headers,
|
|
13
|
+
method: s.method,
|
|
14
|
+
timeout: s.timeout > 0 ? s.timeout : void 0
|
|
15
|
+
}, function(r) {
|
|
16
|
+
let i = [];
|
|
17
|
+
r.on("data", (e) => i.push(e)), r.on("end", async () => {
|
|
18
|
+
let o = t(Object.entries(r.headers).map(([e, t]) => [e.toLowerCase(), Array.isArray(t) ? t.join(",") : t])), c = Buffer.concat(i);
|
|
19
|
+
e(await a({
|
|
20
|
+
url: s.url,
|
|
21
|
+
method: s.method,
|
|
22
|
+
status: r.statusCode || -1,
|
|
23
|
+
error: r.statusCode ? void 0 : n.Unknown,
|
|
24
|
+
statusText: r.statusMessage || n.Unknown,
|
|
25
|
+
headers: o,
|
|
26
|
+
body: null
|
|
27
|
+
}, {
|
|
28
|
+
asBuffer: s.asBuffer,
|
|
29
|
+
text: () => c.toString("utf-8"),
|
|
30
|
+
buffer: () => c.buffer
|
|
31
|
+
}));
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
r.on("error", (t) => {
|
|
35
|
+
e({
|
|
36
|
+
url: s.url,
|
|
37
|
+
method: s.method,
|
|
38
|
+
status: -1,
|
|
39
|
+
error: n.NetworkError,
|
|
40
|
+
statusText: n.NetworkError,
|
|
41
|
+
body: null,
|
|
42
|
+
rawError: t
|
|
43
|
+
});
|
|
44
|
+
}), r.on("timeout", () => {
|
|
45
|
+
e({
|
|
46
|
+
url: s.url,
|
|
47
|
+
method: s.method,
|
|
48
|
+
status: -1,
|
|
49
|
+
error: n.Timeout,
|
|
50
|
+
statusText: n.Timeout,
|
|
51
|
+
body: null
|
|
52
|
+
});
|
|
53
|
+
}), s.body && r.write(s.body), r.end();
|
|
54
|
+
});
|
|
66
55
|
};
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
56
|
+
//#endregion
|
|
57
|
+
//#region src/node.ts
|
|
58
|
+
function m(e) {
|
|
59
|
+
return i() ? new c(l, e) : new c(f, e);
|
|
70
60
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
s as RequestInternalError,
|
|
75
|
-
H as del,
|
|
76
|
-
D as get,
|
|
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
|
-
};
|
|
61
|
+
var h = m(), g = h.setConfig, _ = h.head, v = h.get, y = h.post, b = h.del, x = h.put, S = h.patch;
|
|
62
|
+
//#endregion
|
|
63
|
+
export { m as NetRequest, n as RequestInternalError, b as del, v as get, r as getResponseRulesDescription, _ as head, S as patch, y as post, x as put, g as setGlobalConfig };
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { a as e, c as t, d as n, n as r, r as i, t as a, v as o } from "./retry-x0AqZ13h.js";
|
|
2
|
+
//#region src/inc/request.fetch.ts
|
|
3
|
+
var s = async function(e, t, n) {
|
|
4
|
+
return i(await a(c, e, t, n), e, t, n);
|
|
5
|
+
}, c = async function(i, a, s) {
|
|
6
|
+
let c = await e(i, a, s), l = o() ? new AbortController() : null;
|
|
7
|
+
function u(e) {
|
|
8
|
+
l && !l.signal.aborted && l.abort(e);
|
|
9
|
+
}
|
|
10
|
+
c.abort?.addEventListener("abort", u);
|
|
11
|
+
let d = !1, f = c.timeout > 0 ? setTimeout(function() {
|
|
12
|
+
d = !0, u("TimeoutTriggered");
|
|
13
|
+
}, c.timeout) : null;
|
|
14
|
+
return await fetch(c.url, {
|
|
15
|
+
method: c.method,
|
|
16
|
+
headers: Object.keys(c.headers).length > 0 ? new Headers(c.headers) : void 0,
|
|
17
|
+
body: c.body,
|
|
18
|
+
credentials: c.credentials,
|
|
19
|
+
signal: l?.signal,
|
|
20
|
+
redirect: "follow"
|
|
21
|
+
}).then(async (e) => r({
|
|
22
|
+
url: c.url,
|
|
23
|
+
method: c.method,
|
|
24
|
+
status: e.status,
|
|
25
|
+
statusText: e.statusText,
|
|
26
|
+
headers: t([...e.headers.entries()]),
|
|
27
|
+
body: null
|
|
28
|
+
}, {
|
|
29
|
+
asBuffer: c.asBuffer,
|
|
30
|
+
text: () => e.text(),
|
|
31
|
+
buffer: () => e.arrayBuffer()
|
|
32
|
+
})).catch((e) => {
|
|
33
|
+
let t = l?.signal.aborted, r = d ? n.Timeout : t ? n.Aborted : n.NetworkError;
|
|
34
|
+
return {
|
|
35
|
+
url: c.url,
|
|
36
|
+
method: c.method,
|
|
37
|
+
status: -1,
|
|
38
|
+
error: r,
|
|
39
|
+
statusText: r,
|
|
40
|
+
body: null,
|
|
41
|
+
rawError: e
|
|
42
|
+
};
|
|
43
|
+
}).finally(() => {
|
|
44
|
+
f !== null && clearTimeout(f), c.abort && c.abort.removeEventListener("abort", u);
|
|
45
|
+
});
|
|
46
|
+
};
|
|
47
|
+
//#endregion
|
|
48
|
+
export { s as t };
|