@seayoo-web/request 1.5.6 → 1.6.1
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/inc/detect.d.ts +8 -0
- package/dist/inc/request.browser.d.ts +2 -1
- package/dist/index.cjs +2 -2
- package/dist/index.js +98 -89
- package/dist/node.cjs +1 -1
- package/dist/node.js +9 -9
- package/dist/version-D5ZPd9sj.js +436 -0
- package/dist/version-yl6932gU.cjs +2 -0
- package/dist/version.d.ts +1 -1
- package/dist/wx.cjs +1 -1
- package/dist/wx.js +17 -17
- package/package.json +8 -8
- package/dist/version-DCu7OI8o.js +0 -427
- package/dist/version-nbk4F2gf.cjs +0 -2
|
@@ -15,8 +15,9 @@ export declare const xhRequest: NetRequestAgent;
|
|
|
15
15
|
/**
|
|
16
16
|
* 上传文件,支持进度信息和多文件上传,不抛错,限制在浏览器中使用,不支持重试
|
|
17
17
|
*/
|
|
18
|
-
export declare function xhrUpload(url: string, files: Record<string, Blob
|
|
18
|
+
export declare function xhrUpload(url: string, files: Record<string, Blob> | Blob, options?: Omit<IRequestOptions, keyof XHRequestOptions | keyof IRetryRequestOptions> & Omit<XHRequestOptions, "body" | "method"> & {
|
|
19
19
|
body?: Record<string, unknown>;
|
|
20
|
+
method?: "POST" | "PUT";
|
|
20
21
|
},
|
|
21
22
|
/** 全局配置中独有的配置,以受全局配置控制 */
|
|
22
23
|
config?: Omit<IRequestGlobalConfig, keyof IRequestOptions>): Promise<IResponseResult>;
|
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
2
|
-
`).forEach(e=>{const r=e.trim();if(!r)return;const i=r.split(":"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("./version-yl6932gU.cjs"),E=async function(n,o,t){const e=await a.convertOptions(n,o,t),r=new URL(e.url),i=e.params;i instanceof Object&&Object.keys(i).forEach(s=>r.searchParams.set(s,i[s]));const c=new AbortController;function l(){c.signal.aborted||c.abort()}e.abort&&e.abort.addEventListener("abort",l);const b=e.timeout>0?setTimeout(l,e.timeout):null,h=new Request(r,{method:e.method,headers:new Headers(e.headers),body:e.body,credentials:e.credentials,signal:c.signal,redirect:"follow"});return await fetch(h).then(async s=>({url:r.toString(),method:e.method,status:s.status,statusText:s.statusText,headers:Object.fromEntries(s.headers.entries()),body:e.method==="HEAD"?"":await s.text()})).catch(s=>({url:r.toString(),method:e.method,status:-1,statusText:c.signal.aborted?"Aborted":"NetworkError",body:String(s)})).finally(()=>{b!==null&&clearTimeout(b),e.abort&&e.abort.removeEventListener("abort",l)})},p=async function(n,o,t){const e={...await a.convertOptions(n,o,t),onUploadProgress:t==null?void 0:t.onUploadProgress},r=e.method,i=e.onUploadProgress||a.Vt,c=a.Et(e.url,e.params);return await new Promise(l=>{let b=1;function h(m){b=m.total,i({total:m.total,loaded:m.loaded})}let s=null,f=!1;const g=function(){f||(d.abort(),f=!0)};function w(){s!==null&&clearTimeout(s),e.abort&&e.abort.removeEventListener("abort",g)}const d=new XMLHttpRequest;d.open(r,c,!0),d.upload.addEventListener("progress",h),d.addEventListener("load",()=>{w(),i({loaded:b,total:b}),l({url:c,method:r,status:d.status,statusText:d.statusText,headers:T(d),body:r==="HEAD"?"":d.responseText})}),d.addEventListener("error",()=>{w(),l({url:c,method:r,status:-1,statusText:"Failed",body:""})}),d.addEventListener("abort",()=>{w(),l({url:c,method:r,status:-1,statusText:"Aborted",body:""})}),Object.entries(e.headers).forEach(([m,R])=>{d.setRequestHeader(m,R)}),e.credentials==="include"&&(d.withCredentials=!0),d.send(e.body||void 0),e.abort&&e.abort.addEventListener("abort",g),e.timeout>0&&(s=setTimeout(g,e.timeout))})};function T(n){const o={};if(!n)return o;const t=n.getAllResponseHeaders();return t&&t!=="null"&&t.replace(/\r/g,"").split(`
|
|
2
|
+
`).forEach(e=>{const r=e.trim();if(!r)return;const i=r.split(":"),c=i[0].trim();c&&(o[c]=(i[1]||"").trim())}),o}const q=async function(n,o,t){return a.handleResponse(await a.retryRequest(E,n,o,t),n,o,t)},H=async function(n,o,t){return a.handleResponse(await a.retryRequest(p,n,o,t),n,o,t)};async function x(n,o,t,e){const r=t==null?void 0:t.body,i=(t==null?void 0:t.method)==="PUT"?"PUT":"POST";if(o instanceof Blob){const s=new a.RequestGlobalConfig(e),f=await p(n,s,{...t,method:i,body:o});return a.handleResponse(f,n,s,t)}const c=new FormData,l={...o};r instanceof Object&&Object.entries(r).forEach(([s,f])=>{f instanceof Blob?l[s]=f:Array.isArray(f)?f.forEach((g,w)=>{c.append(`${s}[${w}]`,String(g))}):c.append(s,String(f))});for(const s in l)c.append(s,l[s]);const b=new a.RequestGlobalConfig(e),h=await p(n,b,{...t,method:i,body:c});return a.handleResponse(h,n,b,t)}async function S(n,o,t={}){const e=window;"callback"in t||(t.callback="jsonxData"+Math.random().toString(16).slice(2));const r=t.callback+"";if(!n)return null;const i=a.Et(n,t,!0);return new Promise(c=>{e[r]=function(l){if(r in window&&delete e[r],o(l))return l;console.warn("response type check faild",n,l),c(null)},a.he(i).catch(function(){c(null),delete e[r]})})}async function v(n,o,t={}){const e=window;return"var"in t||(t.var="jsonxData"+Math.random().toString(16).slice(2)),n?await a.he(a.Et(n,t,!0)).then(()=>{const r=e[t.var+""];return o(r)?r:(console.warn("response type check faild",n,r),null)}).catch(()=>null):null}const j=async function(n,o,t){return await x(n,o,t,{baseURL:u.getConfig("baseURL"),logHandler:u.getConfig("logHandler"),errorHandler:u.getConfig("errorHandler"),requestTransformer:u.getConfig("requestTransformer"),messageHandler:u.getConfig("messageHandler"),responseHandler:u.getConfig("responseHandler")})};function y(n){if(!a.Support.window)throw new Error("Default Module Only Support In Browser");return a.Support.fetch?new a.NetRequestHandler(q,n):new a.NetRequestHandler(H,n)}const u=y(),C=u.setConfig,L=u.head,U=u.get,O=u.post,P=u.del,D=u.put,k=u.patch;exports.getResponseRulesDescription=a.getResponseRulesDescription;exports.version=a.version;exports.NetRequest=y;exports.del=P;exports.get=U;exports.head=L;exports.jsonp=S;exports.jsonx=v;exports.patch=k;exports.post=O;exports.put=D;exports.setGlobalConfig=C;exports.upload=j;
|
package/dist/index.js
CHANGED
|
@@ -1,83 +1,83 @@
|
|
|
1
|
-
import { c as
|
|
2
|
-
import { g as J, v as K } from "./version-
|
|
3
|
-
const
|
|
4
|
-
const t = await
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
function
|
|
8
|
-
|
|
1
|
+
import { c as H, E as p, V as S, h as w, r as x, R, a as q, S as E, N as T } from "./version-D5ZPd9sj.js";
|
|
2
|
+
import { g as J, v as K } from "./version-D5ZPd9sj.js";
|
|
3
|
+
const U = async function(n, o, e) {
|
|
4
|
+
const t = await H(n, o, e), r = new URL(t.url), l = t.params;
|
|
5
|
+
l instanceof Object && Object.keys(l).forEach((a) => r.searchParams.set(a, l[a]));
|
|
6
|
+
const s = new AbortController();
|
|
7
|
+
function c() {
|
|
8
|
+
s.signal.aborted || s.abort();
|
|
9
9
|
}
|
|
10
|
-
t.abort && t.abort.addEventListener("abort",
|
|
11
|
-
const f = t.timeout > 0 ? setTimeout(
|
|
10
|
+
t.abort && t.abort.addEventListener("abort", c);
|
|
11
|
+
const f = t.timeout > 0 ? setTimeout(c, t.timeout) : null, b = new Request(r, {
|
|
12
12
|
method: t.method,
|
|
13
13
|
headers: new Headers(t.headers),
|
|
14
14
|
body: t.body,
|
|
15
15
|
credentials: t.credentials,
|
|
16
|
-
signal:
|
|
16
|
+
signal: s.signal,
|
|
17
17
|
redirect: "follow"
|
|
18
18
|
});
|
|
19
|
-
return await fetch(
|
|
19
|
+
return await fetch(b).then(async (a) => ({
|
|
20
20
|
url: r.toString(),
|
|
21
21
|
method: t.method,
|
|
22
|
-
status:
|
|
23
|
-
statusText:
|
|
24
|
-
headers: Object.fromEntries(
|
|
25
|
-
body: t.method === "HEAD" ? "" : await
|
|
26
|
-
})).catch((
|
|
22
|
+
status: a.status,
|
|
23
|
+
statusText: a.statusText,
|
|
24
|
+
headers: Object.fromEntries(a.headers.entries()),
|
|
25
|
+
body: t.method === "HEAD" ? "" : await a.text()
|
|
26
|
+
})).catch((a) => ({
|
|
27
27
|
url: r.toString(),
|
|
28
28
|
method: t.method,
|
|
29
29
|
status: -1,
|
|
30
|
-
statusText:
|
|
31
|
-
body: String(
|
|
30
|
+
statusText: s.signal.aborted ? "Aborted" : "NetworkError",
|
|
31
|
+
body: String(a)
|
|
32
32
|
})).finally(() => {
|
|
33
|
-
f !== null && clearTimeout(f), t.abort && t.abort.removeEventListener("abort",
|
|
33
|
+
f !== null && clearTimeout(f), t.abort && t.abort.removeEventListener("abort", c);
|
|
34
34
|
});
|
|
35
|
-
},
|
|
35
|
+
}, y = async function(n, o, e) {
|
|
36
36
|
const t = {
|
|
37
|
-
...await
|
|
37
|
+
...await H(n, o, e),
|
|
38
38
|
onUploadProgress: e == null ? void 0 : e.onUploadProgress
|
|
39
|
-
}, r = t.method,
|
|
40
|
-
return await new Promise((
|
|
39
|
+
}, r = t.method, l = t.onUploadProgress || S, s = p(t.url, t.params);
|
|
40
|
+
return await new Promise((c) => {
|
|
41
41
|
let f = 1;
|
|
42
|
-
function
|
|
43
|
-
f =
|
|
42
|
+
function b(m) {
|
|
43
|
+
f = m.total, l({ total: m.total, loaded: m.loaded });
|
|
44
44
|
}
|
|
45
|
-
let
|
|
46
|
-
const
|
|
47
|
-
|
|
45
|
+
let a = null, u = !1;
|
|
46
|
+
const h = function() {
|
|
47
|
+
u || (i.abort(), u = !0);
|
|
48
48
|
};
|
|
49
|
-
function
|
|
50
|
-
|
|
49
|
+
function g() {
|
|
50
|
+
a !== null && clearTimeout(a), t.abort && t.abort.removeEventListener("abort", h);
|
|
51
51
|
}
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
url:
|
|
52
|
+
const i = new XMLHttpRequest();
|
|
53
|
+
i.open(r, s, !0), i.upload.addEventListener("progress", b), i.addEventListener("load", () => {
|
|
54
|
+
g(), l({ loaded: f, total: f }), c({
|
|
55
|
+
url: s,
|
|
56
56
|
method: r,
|
|
57
|
-
status:
|
|
58
|
-
statusText:
|
|
59
|
-
headers: v(
|
|
60
|
-
body: r === "HEAD" ? "" :
|
|
57
|
+
status: i.status,
|
|
58
|
+
statusText: i.statusText,
|
|
59
|
+
headers: v(i),
|
|
60
|
+
body: r === "HEAD" ? "" : i.responseText
|
|
61
61
|
});
|
|
62
|
-
}),
|
|
63
|
-
|
|
64
|
-
url:
|
|
62
|
+
}), i.addEventListener("error", () => {
|
|
63
|
+
g(), c({
|
|
64
|
+
url: s,
|
|
65
65
|
method: r,
|
|
66
66
|
status: -1,
|
|
67
67
|
statusText: "Failed",
|
|
68
68
|
body: ""
|
|
69
69
|
});
|
|
70
|
-
}),
|
|
71
|
-
|
|
72
|
-
url:
|
|
70
|
+
}), i.addEventListener("abort", () => {
|
|
71
|
+
g(), c({
|
|
72
|
+
url: s,
|
|
73
73
|
method: r,
|
|
74
74
|
status: -1,
|
|
75
75
|
statusText: "Aborted",
|
|
76
76
|
body: ""
|
|
77
77
|
});
|
|
78
|
-
}), Object.entries(t.headers).forEach(([
|
|
79
|
-
|
|
80
|
-
}), t.credentials === "include" && (
|
|
78
|
+
}), Object.entries(t.headers).forEach(([m, L]) => {
|
|
79
|
+
i.setRequestHeader(m, L);
|
|
80
|
+
}), t.credentials === "include" && (i.withCredentials = !0), i.send(t.body || void 0), t.abort && t.abort.addEventListener("abort", h), t.timeout > 0 && (a = setTimeout(h, t.timeout));
|
|
81
81
|
});
|
|
82
82
|
};
|
|
83
83
|
function v(n) {
|
|
@@ -90,30 +90,39 @@ function v(n) {
|
|
|
90
90
|
const r = t.trim();
|
|
91
91
|
if (!r)
|
|
92
92
|
return;
|
|
93
|
-
const
|
|
94
|
-
|
|
93
|
+
const l = r.split(":"), s = l[0].trim();
|
|
94
|
+
s && (o[s] = (l[1] || "").trim());
|
|
95
95
|
}), o;
|
|
96
96
|
}
|
|
97
|
-
const
|
|
98
|
-
return
|
|
97
|
+
const C = async function(n, o, e) {
|
|
98
|
+
return w(await x(U, n, o, e), n, o, e);
|
|
99
99
|
}, j = async function(n, o, e) {
|
|
100
|
-
return
|
|
100
|
+
return w(await x(y, n, o, e), n, o, e);
|
|
101
101
|
};
|
|
102
|
-
async function
|
|
103
|
-
const r =
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
102
|
+
async function O(n, o, e, t) {
|
|
103
|
+
const r = e == null ? void 0 : e.body, l = (e == null ? void 0 : e.method) === "PUT" ? "PUT" : "POST";
|
|
104
|
+
if (o instanceof Blob) {
|
|
105
|
+
const a = new R(t), u = await y(n, a, {
|
|
106
|
+
...e,
|
|
107
|
+
method: l,
|
|
108
|
+
body: o
|
|
109
|
+
});
|
|
110
|
+
return w(u, n, a, e);
|
|
111
|
+
}
|
|
112
|
+
const s = new FormData(), c = { ...o };
|
|
113
|
+
r instanceof Object && Object.entries(r).forEach(([a, u]) => {
|
|
114
|
+
u instanceof Blob ? c[a] = u : Array.isArray(u) ? u.forEach((h, g) => {
|
|
115
|
+
s.append(`${a}[${g}]`, String(h));
|
|
116
|
+
}) : s.append(a, String(u));
|
|
108
117
|
});
|
|
109
|
-
for (const
|
|
110
|
-
|
|
111
|
-
const
|
|
118
|
+
for (const a in c)
|
|
119
|
+
s.append(a, c[a]);
|
|
120
|
+
const f = new R(t), b = await y(n, f, {
|
|
112
121
|
...e,
|
|
113
|
-
method:
|
|
114
|
-
body:
|
|
122
|
+
method: l,
|
|
123
|
+
body: s
|
|
115
124
|
});
|
|
116
|
-
return
|
|
125
|
+
return w(b, n, f, e);
|
|
117
126
|
}
|
|
118
127
|
async function A(n, o, e = {}) {
|
|
119
128
|
const t = window;
|
|
@@ -121,26 +130,26 @@ async function A(n, o, e = {}) {
|
|
|
121
130
|
const r = e.callback + "";
|
|
122
131
|
if (!n)
|
|
123
132
|
return null;
|
|
124
|
-
const
|
|
125
|
-
return new Promise((
|
|
126
|
-
t[r] = function(
|
|
127
|
-
if (r in window && delete t[r], o(
|
|
128
|
-
return
|
|
129
|
-
console.warn("response type check faild", n,
|
|
130
|
-
},
|
|
131
|
-
|
|
133
|
+
const l = p(n, e, !0);
|
|
134
|
+
return new Promise((s) => {
|
|
135
|
+
t[r] = function(c) {
|
|
136
|
+
if (r in window && delete t[r], o(c))
|
|
137
|
+
return c;
|
|
138
|
+
console.warn("response type check faild", n, c), s(null);
|
|
139
|
+
}, q(l).catch(function() {
|
|
140
|
+
s(null), delete t[r];
|
|
132
141
|
});
|
|
133
142
|
});
|
|
134
143
|
}
|
|
135
144
|
async function D(n, o, e = {}) {
|
|
136
145
|
const t = window;
|
|
137
|
-
return "var" in e || (e.var = "jsonxData" + Math.random().toString(16).slice(2)), n ? await
|
|
146
|
+
return "var" in e || (e.var = "jsonxData" + Math.random().toString(16).slice(2)), n ? await q(p(n, e, !0)).then(() => {
|
|
138
147
|
const r = t[e.var + ""];
|
|
139
148
|
return o(r) ? r : (console.warn("response type check faild", n, r), null);
|
|
140
149
|
}).catch(() => null) : null;
|
|
141
150
|
}
|
|
142
|
-
const
|
|
143
|
-
return await
|
|
151
|
+
const M = async function(n, o, e) {
|
|
152
|
+
return await O(n, o, e, {
|
|
144
153
|
baseURL: d.getConfig("baseURL"),
|
|
145
154
|
logHandler: d.getConfig("logHandler"),
|
|
146
155
|
errorHandler: d.getConfig("errorHandler"),
|
|
@@ -149,24 +158,24 @@ const P = async function(n, o, e) {
|
|
|
149
158
|
responseHandler: d.getConfig("responseHandler")
|
|
150
159
|
});
|
|
151
160
|
};
|
|
152
|
-
function
|
|
153
|
-
if (
|
|
154
|
-
|
|
155
|
-
|
|
161
|
+
function P(n) {
|
|
162
|
+
if (!E.window)
|
|
163
|
+
throw new Error("Default Module Only Support In Browser");
|
|
164
|
+
return E.fetch ? new T(C, n) : new T(j, n);
|
|
156
165
|
}
|
|
157
|
-
const d =
|
|
166
|
+
const d = P(), N = d.setConfig, F = d.head, B = d.get, X = d.post, G = d.del, I = d.put, V = d.patch;
|
|
158
167
|
export {
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
168
|
+
P as NetRequest,
|
|
169
|
+
G as del,
|
|
170
|
+
B as get,
|
|
162
171
|
J as getResponseRulesDescription,
|
|
163
|
-
|
|
172
|
+
F as head,
|
|
164
173
|
A as jsonp,
|
|
165
174
|
D as jsonx,
|
|
166
|
-
|
|
175
|
+
V as patch,
|
|
167
176
|
X as post,
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
177
|
+
I as put,
|
|
178
|
+
N as setGlobalConfig,
|
|
179
|
+
M as upload,
|
|
171
180
|
K as version
|
|
172
181
|
};
|
package/dist/node.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const y=require("node:http"),q=require("node:https"),r=require("./version-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const y=require("node:http"),q=require("node:https"),r=require("./version-yl6932gU.cjs"),R=async function(s,u,c){return r.handleResponse(await r.retryRequest(w,s,u,c),s,u,c)},w=async function(s,u,c){const t=await r.convertOptions(s,u,c);if(!r.U(t.url))return{url:t.url,method:t.method,status:-1,statusText:"URLFormatError",headers:{},body:""};const b=/^https:\/\//i.test(t.url)?q:y,a=new URL(t.url),i=t.params;i instanceof Object&&Object.keys(i).forEach(n=>a.searchParams.set(n,i[n]));const f=t.method==="HEAD";return new Promise(n=>{const d=b.request(a,{headers:t.headers,method:t.method,timeout:t.timeout>0?t.timeout:void 0},function(e){const p=[];e.on("data",h=>p.push(h)),e.on("end",()=>{const h=Object.fromEntries(Object.entries(e.headers).map(([g,m])=>[g.toLowerCase(),Array.isArray(m)?m.join(","):m]));n({url:a.toString(),method:t.method,status:e.statusCode||-1,statusText:e.statusMessage||"Unknown",headers:h,body:f?"":Buffer.concat(p).toString("utf-8")})})});d.on("error",e=>{n({url:a.toString(),method:t.method,status:-1,statusText:e.name||"Unknown",body:e.message})}),d.on("timeout",()=>{n({url:a.toString(),method:t.method,status:-1,statusText:"Timeout",body:""})}),t.body&&d.write(t.body),d.end()})};function l(s){return new r.NetRequestHandler(R,s)}const o=l(),j=o.setConfig,O=o.head,S=o.get,T=o.post,U=o.del,C=o.put,x=o.patch;exports.version=r.version;exports.NetRequest=l;exports.del=U;exports.get=S;exports.head=O;exports.patch=x;exports.post=T;exports.put=C;exports.setGlobalConfig=j;
|
package/dist/node.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import l from "node:http";
|
|
2
2
|
import y from "node:https";
|
|
3
|
-
import { h as R, r as g, c as q,
|
|
4
|
-
import { v as F } from "./version-
|
|
5
|
-
const
|
|
6
|
-
return R(await g(
|
|
7
|
-
},
|
|
3
|
+
import { h as R, r as g, c as q, U as w, N as x } from "./version-D5ZPd9sj.js";
|
|
4
|
+
import { v as F } from "./version-D5ZPd9sj.js";
|
|
5
|
+
const U = async function(s, a, u) {
|
|
6
|
+
return R(await g(j, s, a, u), s, a, u);
|
|
7
|
+
}, j = async function(s, a, u) {
|
|
8
8
|
const t = await q(s, a, u);
|
|
9
9
|
if (!w(t.url))
|
|
10
10
|
return {
|
|
@@ -62,12 +62,12 @@ const j = async function(s, a, u) {
|
|
|
62
62
|
}), t.body && c.write(t.body), c.end();
|
|
63
63
|
});
|
|
64
64
|
};
|
|
65
|
-
function
|
|
66
|
-
return new x(
|
|
65
|
+
function O(s) {
|
|
66
|
+
return new x(U, s);
|
|
67
67
|
}
|
|
68
|
-
const o =
|
|
68
|
+
const o = O(), L = o.setConfig, N = o.head, S = o.get, A = o.post, H = o.del, k = o.put, P = o.patch;
|
|
69
69
|
export {
|
|
70
|
-
|
|
70
|
+
O as NetRequest,
|
|
71
71
|
H as del,
|
|
72
72
|
S as get,
|
|
73
73
|
N as head,
|