@seayoo-web/request 1.7.0 → 1.7.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/README.md +1 -1
- package/dist/inc/request.fetch.d.ts +7 -0
- package/dist/inc/{request.browser.d.ts → request.xhr.d.ts} +9 -8
- package/dist/index.cjs +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +97 -130
- package/dist/node.cjs +1 -1
- package/dist/node.js +28 -27
- package/dist/request.fetch-CaHYPyjf.cjs +1 -0
- package/dist/request.fetch-DnbU5fqv.js +39 -0
- package/dist/{version-DOOsgzgL.js → version-C-bTPkwR.js} +266 -255
- package/dist/version-Cx7ZvtPo.cjs +2 -0
- package/dist/version.d.ts +1 -1
- package/dist/wx.cjs +1 -1
- package/dist/wx.js +2 -2
- package/package.json +3 -3
- package/dist/inc/core.fetch.d.ts +0 -5
- package/dist/inc/core.xhr.d.ts +0 -11
- package/dist/version-CCXW7_VI.cjs +0 -2
package/README.md
CHANGED
|
@@ -321,7 +321,7 @@ status 表示网络错误或者http 状态码错误时重试;
|
|
|
321
321
|
|
|
322
322
|
- 当请求结束时无效;
|
|
323
323
|
- 仅浏览器环境有效,
|
|
324
|
-
- 不支持 AbortSignal 的浏览器可以引入 https://www.npmjs.com/package/abortcontroller-polyfill
|
|
324
|
+
- 不支持 AbortSignal 的浏览器可以引入 https://www.npmjs.com/package/abortcontroller-polyfill 或 https://polyfill.io/v3/polyfill.min.js?features=AbortController
|
|
325
325
|
|
|
326
326
|
### message
|
|
327
327
|
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import type { NetRequestAgent, IRequestGlobalConfig, IRequestOptions, IResponseResult, IRetryRequestOptions, IBaseRequestOptions } from "./type";
|
|
2
|
+
/** 进度回调函数配置 */
|
|
3
|
+
interface XHRequestOptions extends IBaseRequestOptions {
|
|
4
|
+
onUploadProgress?: (progress: {
|
|
5
|
+
total: number;
|
|
6
|
+
loaded: number;
|
|
7
|
+
}) => void;
|
|
8
|
+
}
|
|
9
9
|
/**
|
|
10
10
|
* 基于 xmlHttpRequest 的网络请求包装函数
|
|
11
11
|
*
|
|
@@ -21,3 +21,4 @@ export declare function xhrUpload(url: string, files: Record<string, Blob> | Blo
|
|
|
21
21
|
},
|
|
22
22
|
/** 全局配置中独有的配置,以受全局配置控制 */
|
|
23
23
|
config?: Omit<IRequestGlobalConfig, keyof IRequestOptions>): Promise<IResponseResult>;
|
|
24
|
+
export {};
|
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
2
|
-
`).forEach(
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("./version-Cx7ZvtPo.cjs"),y=require("./request.fetch-CaHYPyjf.cjs"),m=async function(t,o,e){return s.handleResponse(await s.retryRequest(w,t,o,e),t,o,e)};async function q(t,o,e,n){const r=e==null?void 0:e.body,d=(e==null?void 0:e.method)==="PUT"?"PUT":"POST";if(o instanceof Blob){const l=new s.RequestGlobalConfig(n),f=await w(t,l,{...e,method:d,body:o});return s.handleResponse(f,t,l,e)}const a=new FormData,u={...o};r instanceof Object&&Object.entries(r).forEach(([l,f])=>{f instanceof Blob?u[l]=f:Array.isArray(f)?f.forEach((c,g)=>{a.append(`${l}[${g}]`,String(c))}):a.append(l,String(f))});for(const l in u)a.append(l,u[l]);const b=new s.RequestGlobalConfig(n),p=await w(t,b,{...e,method:d,body:a});return s.handleResponse(p,t,b,e)}const w=async function(t,o,e){const n=await s.convertOptions(t,o,e),r=n.method,d=e==null?void 0:e.onUploadProgress,a=s.Ut(n.url,n.params);return await new Promise(u=>{let b=null,p=!1;const l=function(){p||(c.abort(),p=!0)};function f(){b!==null&&clearTimeout(b),n.abort&&n.abort.removeEventListener("abort",l)}const c=new XMLHttpRequest;if(c.open(r,a,!0),d){let g=1;c.upload.addEventListener("progress",h=>{g=h.total,d({total:h.total,loaded:h.loaded})}),c.addEventListener("load",()=>{f(),d({loaded:g,total:g}),u({url:a,method:r,status:c.status,statusText:c.statusText,headers:H(c),body:r==="HEAD"?"":c.responseText})})}c.addEventListener("error",()=>{f(),u({url:a,method:r,status:-1,statusText:"Failed",body:""})}),c.addEventListener("abort",()=>{f(),u({url:a,method:r,status:-1,statusText:"Aborted",body:""})}),Object.entries(n.headers).forEach(([g,h])=>{c.setRequestHeader(g,h)}),n.credentials==="include"&&(c.withCredentials=!0),c.send(n.body||void 0),n.abort&&n.abort.addEventListener("abort",l),n.timeout>0&&(b=setTimeout(l,n.timeout))})};function H(t){const o={};if(!t)return o;const e=t.getAllResponseHeaders();return e&&e!=="null"&&e.replace(/\r/g,"").split(`
|
|
2
|
+
`).forEach(n=>{const r=n.trim();if(!r)return;const d=r.split(":"),a=d[0].trim();a&&(o[a]=(d[1]||"").trim())}),o}async function T(t,o,e={}){const n=window;"callback"in e||(e.callback="jsonxData"+Math.random().toString(16).slice(2));const r=e.callback+"";if(!t)return null;const d=s.Ut(t,e,!0);return new Promise(a=>{n[r]=function(u){if(r in window&&delete n[r],o(u))return u;console.warn("response type check faild",t,u),a(null)},s.Ae(d).catch(function(){a(null),delete n[r]})})}async function C(t,o,e={}){const n=window;return"var"in e||(e.var="jsonxData"+Math.random().toString(16).slice(2)),t?await s.Ae(s.Ut(t,e,!0)).then(()=>{const r=n[e.var+""];return o(r)?r:(console.warn("response type check faild",t,r),null)}).catch(()=>null):null}const E=async function(t,o,e){return await q(t,o,e,{baseURL:i.getConfig("baseURL"),logHandler:i.getConfig("logHandler"),errorHandler:i.getConfig("errorHandler"),requestTransformer:i.getConfig("requestTransformer"),messageHandler:i.getConfig("messageHandler"),responseHandler:i.getConfig("responseHandler")})};function R(t){if(!s.Support.window)throw new Error("Default Module Only Support In Browser");return s.Support.fetch?new s.NetRequestHandler(y.fetchRequest,t):new s.NetRequestHandler(m,t)}const i=R(),S=i.setConfig,x=i.head,U=i.get,j=i.post,v=i.del,L=i.put,D=i.patch;exports.getResponseRulesDescription=s.getResponseRulesDescription;exports.version=s.version;exports.NetRequest=R;exports.del=v;exports.get=U;exports.head=x;exports.jsonp=T;exports.jsonx=C;exports.patch=D;exports.post=j;exports.put=L;exports.setGlobalConfig=S;exports.upload=E;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { xhrUpload } from "./inc/request.browser";
|
|
2
1
|
import { NetRequestHandler } from "./inc/main";
|
|
2
|
+
import { xhrUpload } from "./inc/request.xhr";
|
|
3
3
|
import type { IRequestGlobalConfig } from "./inc/type";
|
|
4
4
|
export * from "./version";
|
|
5
5
|
export { jsonp, jsonx } from "./inc/jsonp";
|
|
@@ -10,7 +10,7 @@ export type { IRequestOptions, IRequestGlobalConfig, IResponseRule, IResponseRes
|
|
|
10
10
|
*/
|
|
11
11
|
export declare const upload: (url: string, files: Parameters<typeof xhrUpload>[1], options?: Parameters<typeof xhrUpload>[2]) => ReturnType<typeof xhrUpload>;
|
|
12
12
|
/**
|
|
13
|
-
*
|
|
13
|
+
* 创建新的实例空间,配置和缓存跟全局默认实例是隔离的,仅支持在浏览器环境使用
|
|
14
14
|
*/
|
|
15
15
|
export declare function NetRequest(config?: IRequestGlobalConfig): NetRequestHandler;
|
|
16
16
|
/**
|
package/dist/index.js
CHANGED
|
@@ -1,154 +1,121 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { g as z, v as
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import { h as w, r as q, R as y, c as x, U as p, A as T, S as R, N as H } from "./version-C-bTPkwR.js";
|
|
2
|
+
import { g as z, v as I } from "./version-C-bTPkwR.js";
|
|
3
|
+
import { f as E } from "./request.fetch-DnbU5fqv.js";
|
|
4
|
+
const C = async function(t, a, e) {
|
|
5
|
+
return w(await q(m, t, a, e), t, a, e);
|
|
6
|
+
};
|
|
7
|
+
async function S(t, a, e, n) {
|
|
8
|
+
const r = e == null ? void 0 : e.body, i = (e == null ? void 0 : e.method) === "PUT" ? "PUT" : "POST";
|
|
9
|
+
if (a instanceof Blob) {
|
|
10
|
+
const c = new y(n), u = await m(t, c, {
|
|
11
|
+
...e,
|
|
12
|
+
method: i,
|
|
13
|
+
body: a
|
|
14
|
+
});
|
|
15
|
+
return w(u, t, c, e);
|
|
9
16
|
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
credentials: t.credentials,
|
|
16
|
-
signal: a == null ? void 0 : a.signal,
|
|
17
|
-
redirect: "follow"
|
|
17
|
+
const o = new FormData(), d = { ...a };
|
|
18
|
+
r instanceof Object && Object.entries(r).forEach(([c, u]) => {
|
|
19
|
+
u instanceof Blob ? d[c] = u : Array.isArray(u) ? u.forEach((s, f) => {
|
|
20
|
+
o.append(`${c}[${f}]`, String(s));
|
|
21
|
+
}) : o.append(c, String(u));
|
|
18
22
|
});
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
body: t.method === "HEAD" ? "" : await s.text()
|
|
26
|
-
})).catch((s) => ({
|
|
27
|
-
url: r.toString(),
|
|
28
|
-
method: t.method,
|
|
29
|
-
status: -1,
|
|
30
|
-
statusText: a != null && a.signal.aborted ? "Aborted" : "NetworkError",
|
|
31
|
-
body: String(s)
|
|
32
|
-
})).finally(() => {
|
|
33
|
-
f !== null && clearTimeout(f), t.abort && t.abort.removeEventListener("abort", i);
|
|
23
|
+
for (const c in d)
|
|
24
|
+
o.append(c, d[c]);
|
|
25
|
+
const b = new y(n), h = await m(t, b, {
|
|
26
|
+
...e,
|
|
27
|
+
method: i,
|
|
28
|
+
body: o
|
|
34
29
|
});
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
30
|
+
return w(h, t, b, e);
|
|
31
|
+
}
|
|
32
|
+
const m = async function(t, a, e) {
|
|
33
|
+
const n = await x(t, a, e), r = n.method, i = e == null ? void 0 : e.onUploadProgress, o = p(n.url, n.params);
|
|
34
|
+
return await new Promise((d) => {
|
|
35
|
+
let b = null, h = !1;
|
|
36
|
+
const c = function() {
|
|
37
|
+
h || (s.abort(), h = !0);
|
|
41
38
|
};
|
|
42
39
|
function u() {
|
|
43
|
-
|
|
40
|
+
b !== null && clearTimeout(b), n.abort && n.abort.removeEventListener("abort", c);
|
|
44
41
|
}
|
|
45
|
-
const
|
|
46
|
-
if (
|
|
47
|
-
let
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}),
|
|
51
|
-
u(),
|
|
52
|
-
url:
|
|
42
|
+
const s = new XMLHttpRequest();
|
|
43
|
+
if (s.open(r, o, !0), i) {
|
|
44
|
+
let f = 1;
|
|
45
|
+
s.upload.addEventListener("progress", (g) => {
|
|
46
|
+
f = g.total, i({ total: g.total, loaded: g.loaded });
|
|
47
|
+
}), s.addEventListener("load", () => {
|
|
48
|
+
u(), i({ loaded: f, total: f }), d({
|
|
49
|
+
url: o,
|
|
53
50
|
method: r,
|
|
54
|
-
status:
|
|
55
|
-
statusText:
|
|
56
|
-
headers:
|
|
57
|
-
body: r === "HEAD" ? "" :
|
|
51
|
+
status: s.status,
|
|
52
|
+
statusText: s.statusText,
|
|
53
|
+
headers: U(s),
|
|
54
|
+
body: r === "HEAD" ? "" : s.responseText
|
|
58
55
|
});
|
|
59
56
|
});
|
|
60
57
|
}
|
|
61
|
-
|
|
62
|
-
u(),
|
|
63
|
-
url:
|
|
58
|
+
s.addEventListener("error", () => {
|
|
59
|
+
u(), d({
|
|
60
|
+
url: o,
|
|
64
61
|
method: r,
|
|
65
62
|
status: -1,
|
|
66
63
|
statusText: "Failed",
|
|
67
64
|
body: ""
|
|
68
65
|
});
|
|
69
|
-
}),
|
|
70
|
-
u(),
|
|
71
|
-
url:
|
|
66
|
+
}), s.addEventListener("abort", () => {
|
|
67
|
+
u(), d({
|
|
68
|
+
url: o,
|
|
72
69
|
method: r,
|
|
73
70
|
status: -1,
|
|
74
71
|
statusText: "Aborted",
|
|
75
72
|
body: ""
|
|
76
73
|
});
|
|
77
|
-
}), Object.entries(
|
|
78
|
-
|
|
79
|
-
}),
|
|
74
|
+
}), Object.entries(n.headers).forEach(([f, g]) => {
|
|
75
|
+
s.setRequestHeader(f, g);
|
|
76
|
+
}), n.credentials === "include" && (s.withCredentials = !0), s.send(n.body || void 0), n.abort && n.abort.addEventListener("abort", c), n.timeout > 0 && (b = setTimeout(c, n.timeout));
|
|
80
77
|
});
|
|
81
78
|
};
|
|
82
|
-
function
|
|
83
|
-
const
|
|
84
|
-
if (!
|
|
85
|
-
return
|
|
86
|
-
const e =
|
|
79
|
+
function U(t) {
|
|
80
|
+
const a = {};
|
|
81
|
+
if (!t)
|
|
82
|
+
return a;
|
|
83
|
+
const e = t.getAllResponseHeaders();
|
|
87
84
|
return e && e !== "null" && e.replace(/\r/g, "").split(`
|
|
88
|
-
`).forEach((
|
|
89
|
-
const r =
|
|
85
|
+
`).forEach((n) => {
|
|
86
|
+
const r = n.trim();
|
|
90
87
|
if (!r)
|
|
91
88
|
return;
|
|
92
|
-
const
|
|
93
|
-
|
|
94
|
-
}),
|
|
95
|
-
}
|
|
96
|
-
const v = async function(n, o, e) {
|
|
97
|
-
return m(await H(L, n, o, e), n, o, e);
|
|
98
|
-
}, C = async function(n, o, e) {
|
|
99
|
-
return m(await H(y, n, o, e), n, o, e);
|
|
100
|
-
};
|
|
101
|
-
async function U(n, o, e, t) {
|
|
102
|
-
const r = e == null ? void 0 : e.body, c = (e == null ? void 0 : e.method) === "PUT" ? "PUT" : "POST";
|
|
103
|
-
if (o instanceof Blob) {
|
|
104
|
-
const s = new R(t), u = await y(n, s, {
|
|
105
|
-
...e,
|
|
106
|
-
method: c,
|
|
107
|
-
body: o
|
|
108
|
-
});
|
|
109
|
-
return m(u, n, s, e);
|
|
110
|
-
}
|
|
111
|
-
const a = new FormData(), i = { ...o };
|
|
112
|
-
r instanceof Object && Object.entries(r).forEach(([s, u]) => {
|
|
113
|
-
u instanceof Blob ? i[s] = u : Array.isArray(u) ? u.forEach((d, b) => {
|
|
114
|
-
a.append(`${s}[${b}]`, String(d));
|
|
115
|
-
}) : a.append(s, String(u));
|
|
116
|
-
});
|
|
117
|
-
for (const s in i)
|
|
118
|
-
a.append(s, i[s]);
|
|
119
|
-
const f = new R(t), h = await y(n, f, {
|
|
120
|
-
...e,
|
|
121
|
-
method: c,
|
|
122
|
-
body: a
|
|
123
|
-
});
|
|
124
|
-
return m(h, n, f, e);
|
|
89
|
+
const i = r.split(":"), o = i[0].trim();
|
|
90
|
+
o && (a[o] = (i[1] || "").trim());
|
|
91
|
+
}), a;
|
|
125
92
|
}
|
|
126
|
-
async function k(
|
|
127
|
-
const
|
|
93
|
+
async function k(t, a, e = {}) {
|
|
94
|
+
const n = window;
|
|
128
95
|
"callback" in e || (e.callback = "jsonxData" + Math.random().toString(16).slice(2));
|
|
129
96
|
const r = e.callback + "";
|
|
130
|
-
if (!
|
|
97
|
+
if (!t)
|
|
131
98
|
return null;
|
|
132
|
-
const
|
|
133
|
-
return new Promise((
|
|
134
|
-
|
|
135
|
-
if (r in window && delete
|
|
136
|
-
return
|
|
137
|
-
console.warn("response type check faild",
|
|
138
|
-
},
|
|
139
|
-
|
|
99
|
+
const i = p(t, e, !0);
|
|
100
|
+
return new Promise((o) => {
|
|
101
|
+
n[r] = function(d) {
|
|
102
|
+
if (r in window && delete n[r], a(d))
|
|
103
|
+
return d;
|
|
104
|
+
console.warn("response type check faild", t, d), o(null);
|
|
105
|
+
}, T(i).catch(function() {
|
|
106
|
+
o(null), delete n[r];
|
|
140
107
|
});
|
|
141
108
|
});
|
|
142
109
|
}
|
|
143
|
-
async function
|
|
144
|
-
const
|
|
145
|
-
return "var" in e || (e.var = "jsonxData" + Math.random().toString(16).slice(2)),
|
|
146
|
-
const r =
|
|
147
|
-
return
|
|
110
|
+
async function A(t, a, e = {}) {
|
|
111
|
+
const n = window;
|
|
112
|
+
return "var" in e || (e.var = "jsonxData" + Math.random().toString(16).slice(2)), t ? await T(p(t, e, !0)).then(() => {
|
|
113
|
+
const r = n[e.var + ""];
|
|
114
|
+
return a(r) ? r : (console.warn("response type check faild", t, r), null);
|
|
148
115
|
}).catch(() => null) : null;
|
|
149
116
|
}
|
|
150
|
-
const D = async function(
|
|
151
|
-
return await
|
|
117
|
+
const D = async function(t, a, e) {
|
|
118
|
+
return await S(t, a, e, {
|
|
152
119
|
baseURL: l.getConfig("baseURL"),
|
|
153
120
|
logHandler: l.getConfig("logHandler"),
|
|
154
121
|
errorHandler: l.getConfig("errorHandler"),
|
|
@@ -157,24 +124,24 @@ const D = async function(n, o, e) {
|
|
|
157
124
|
responseHandler: l.getConfig("responseHandler")
|
|
158
125
|
});
|
|
159
126
|
};
|
|
160
|
-
function
|
|
161
|
-
if (!
|
|
127
|
+
function L(t) {
|
|
128
|
+
if (!R.window)
|
|
162
129
|
throw new Error("Default Module Only Support In Browser");
|
|
163
|
-
return
|
|
130
|
+
return R.fetch ? new H(E, t) : new H(C, t);
|
|
164
131
|
}
|
|
165
|
-
const l =
|
|
132
|
+
const l = L(), O = l.setConfig, P = l.head, M = l.get, N = l.post, B = l.del, F = l.put, X = l.patch;
|
|
166
133
|
export {
|
|
167
|
-
|
|
134
|
+
L as NetRequest,
|
|
168
135
|
B as del,
|
|
169
|
-
|
|
136
|
+
M as get,
|
|
170
137
|
z as getResponseRulesDescription,
|
|
171
|
-
|
|
138
|
+
P as head,
|
|
172
139
|
k as jsonp,
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
140
|
+
A as jsonx,
|
|
141
|
+
X as patch,
|
|
142
|
+
N as post,
|
|
143
|
+
F as put,
|
|
144
|
+
O as setGlobalConfig,
|
|
178
145
|
D as upload,
|
|
179
|
-
|
|
146
|
+
I as version
|
|
180
147
|
};
|
package/dist/node.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const y=require("node:http"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const y=require("node:http"),R=require("node:https"),e=require("./version-Cx7ZvtPo.cjs"),g=require("./request.fetch-CaHYPyjf.cjs"),w=async function(s,u,c){return e.handleResponse(await e.retryRequest(S,s,u,c),s,u,c)},S=async function(s,u,c){const t=await e.convertOptions(s,u,c);if(!e.D(t.url))return{url:t.url,method:t.method,status:-1,statusText:"URLFormatError",headers:{},body:""};const f=/^https:\/\//i.test(t.url)?R:y,a=new URL(t.url),i=t.params;i instanceof Object&&Object.keys(i).forEach(r=>a.searchParams.set(r,i[r]));const q=t.method==="HEAD";return new Promise(r=>{const d=f.request(a,{headers:t.headers,method:t.method,timeout:t.timeout>0?t.timeout:void 0},function(o){const p=[];o.on("data",h=>p.push(h)),o.on("end",()=>{const h=e.fromEntries(Object.entries(o.headers).map(([b,m])=>[b.toLowerCase(),Array.isArray(m)?m.join(","):m]));r({url:a.toString(),method:t.method,status:o.statusCode||-1,statusText:o.statusMessage||"Unknown",headers:h,body:q?"":Buffer.concat(p).toString("utf-8")})})});d.on("error",o=>{r({url:a.toString(),method:t.method,status:-1,statusText:o.name||"Unknown",body:o.message})}),d.on("timeout",()=>{r({url:a.toString(),method:t.method,status:-1,statusText:"Timeout",body:""})}),t.body&&d.write(t.body),d.end()})};function l(s){return e.Support.fetch?new e.NetRequestHandler(g.fetchRequest,s):new e.NetRequestHandler(w,s)}const n=l(),T=n.setConfig,j=n.head,C=n.get,N=n.post,O=n.del,U=n.put,x=n.patch;exports.version=e.version;exports.NetRequest=l;exports.del=O;exports.get=C;exports.head=j;exports.patch=x;exports.post=N;exports.put=U;exports.setGlobalConfig=T;
|
package/dist/node.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import { h as
|
|
4
|
-
import { v as
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import y from "node:http";
|
|
2
|
+
import R from "node:https";
|
|
3
|
+
import { h as q, r as w, c as g, D as x, f as S, S as T, N as p } from "./version-C-bTPkwR.js";
|
|
4
|
+
import { v as z } from "./version-C-bTPkwR.js";
|
|
5
|
+
import { f as U } from "./request.fetch-DnbU5fqv.js";
|
|
6
|
+
const j = async function(o, a, u) {
|
|
7
|
+
return q(await w(C, o, a, u), o, a, u);
|
|
8
|
+
}, C = async function(o, a, u) {
|
|
9
|
+
const t = await g(o, a, u);
|
|
10
|
+
if (!x(t.url))
|
|
10
11
|
return {
|
|
11
12
|
url: t.url,
|
|
12
13
|
method: t.method,
|
|
@@ -15,11 +16,11 @@ const U = async function(s, a, u) {
|
|
|
15
16
|
headers: {},
|
|
16
17
|
body: ""
|
|
17
18
|
};
|
|
18
|
-
const
|
|
19
|
+
const f = /^https:\/\//i.test(t.url) ? R : y, r = new URL(t.url), d = t.params;
|
|
19
20
|
d instanceof Object && Object.keys(d).forEach((n) => r.searchParams.set(n, d[n]));
|
|
20
|
-
const
|
|
21
|
+
const b = t.method === "HEAD";
|
|
21
22
|
return new Promise((n) => {
|
|
22
|
-
const c =
|
|
23
|
+
const c = f.request(
|
|
23
24
|
r,
|
|
24
25
|
{
|
|
25
26
|
headers: t.headers,
|
|
@@ -29,8 +30,8 @@ const U = async function(s, a, u) {
|
|
|
29
30
|
function(e) {
|
|
30
31
|
const h = [];
|
|
31
32
|
e.on("data", (i) => h.push(i)), e.on("end", () => {
|
|
32
|
-
const i =
|
|
33
|
-
Object.entries(e.headers).map(([
|
|
33
|
+
const i = S(
|
|
34
|
+
Object.entries(e.headers).map(([l, m]) => [l.toLowerCase(), Array.isArray(m) ? m.join(",") : m])
|
|
34
35
|
);
|
|
35
36
|
n({
|
|
36
37
|
url: r.toString(),
|
|
@@ -38,7 +39,7 @@ const U = async function(s, a, u) {
|
|
|
38
39
|
status: e.statusCode || -1,
|
|
39
40
|
statusText: e.statusMessage || "Unknown",
|
|
40
41
|
headers: i,
|
|
41
|
-
body:
|
|
42
|
+
body: b ? "" : Buffer.concat(h).toString("utf-8")
|
|
42
43
|
});
|
|
43
44
|
});
|
|
44
45
|
}
|
|
@@ -62,18 +63,18 @@ const U = async function(s, a, u) {
|
|
|
62
63
|
}), t.body && c.write(t.body), c.end();
|
|
63
64
|
});
|
|
64
65
|
};
|
|
65
|
-
function
|
|
66
|
-
return new
|
|
66
|
+
function E(o) {
|
|
67
|
+
return T.fetch ? new p(U, o) : new p(j, o);
|
|
67
68
|
}
|
|
68
|
-
const
|
|
69
|
+
const s = E(), H = s.setConfig, k = s.head, D = s.get, P = s.post, B = s.del, F = s.put, G = s.patch;
|
|
69
70
|
export {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
71
|
+
E as NetRequest,
|
|
72
|
+
B as del,
|
|
73
|
+
D as get,
|
|
74
|
+
k as head,
|
|
75
|
+
G as patch,
|
|
76
|
+
P as post,
|
|
77
|
+
F as put,
|
|
78
|
+
H as setGlobalConfig,
|
|
79
|
+
z as version
|
|
79
80
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const s=require("./version-Cx7ZvtPo.cjs"),b=async function(o,a,n){return s.handleResponse(await s.retryRequest(l,o,a,n),o,a,n)},l=async function(o,a,n){const t=await s.convertOptions(o,a,n),i=new URL(t.url),c=t.params;c instanceof Object&&Object.keys(c).forEach(r=>i.searchParams.set(r,c[r]));const e=s.Support.AbortController?new AbortController:null;function u(){e&&!e.signal.aborted&&e.abort()}t.abort&&t.abort.addEventListener("abort",u);const d=t.timeout>0?setTimeout(u,t.timeout):null,h=new Request(i,{method:t.method,headers:Object.keys(t.headers).length>0?new Headers(t.headers):void 0,body:t.body,credentials:t.credentials,signal:e==null?void 0:e.signal,redirect:"follow"});return await fetch(h).then(async r=>({url:i.toString(),method:t.method,status:r.status,statusText:r.statusText,headers:s.fromEntries([...r.headers.entries()]),body:t.method==="HEAD"?"":await r.text()})).catch(r=>({url:i.toString(),method:t.method,status:-1,statusText:e!=null&&e.signal.aborted?"Aborted":"NetworkError",body:String(r)})).finally(()=>{d!==null&&clearTimeout(d),t.abort&&t.abort.removeEventListener("abort",u)})};exports.fetchRequest=b;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { h, r as b, c as l, S as m, f } from "./version-C-bTPkwR.js";
|
|
2
|
+
const p = async function(r, s, o) {
|
|
3
|
+
return h(await b(w, r, s, o), r, s, o);
|
|
4
|
+
}, w = async function(r, s, o) {
|
|
5
|
+
const t = await l(r, s, o), n = new URL(t.url), i = t.params;
|
|
6
|
+
i instanceof Object && Object.keys(i).forEach((a) => n.searchParams.set(a, i[a]));
|
|
7
|
+
const e = m.AbortController ? new AbortController() : null;
|
|
8
|
+
function c() {
|
|
9
|
+
e && !e.signal.aborted && e.abort();
|
|
10
|
+
}
|
|
11
|
+
t.abort && t.abort.addEventListener("abort", c);
|
|
12
|
+
const d = t.timeout > 0 ? setTimeout(c, t.timeout) : null, u = new Request(n, {
|
|
13
|
+
method: t.method,
|
|
14
|
+
headers: Object.keys(t.headers).length > 0 ? new Headers(t.headers) : void 0,
|
|
15
|
+
body: t.body,
|
|
16
|
+
credentials: t.credentials,
|
|
17
|
+
signal: e == null ? void 0 : e.signal,
|
|
18
|
+
redirect: "follow"
|
|
19
|
+
});
|
|
20
|
+
return await fetch(u).then(async (a) => ({
|
|
21
|
+
url: n.toString(),
|
|
22
|
+
method: t.method,
|
|
23
|
+
status: a.status,
|
|
24
|
+
statusText: a.statusText,
|
|
25
|
+
headers: f([...a.headers.entries()]),
|
|
26
|
+
body: t.method === "HEAD" ? "" : await a.text()
|
|
27
|
+
})).catch((a) => ({
|
|
28
|
+
url: n.toString(),
|
|
29
|
+
method: t.method,
|
|
30
|
+
status: -1,
|
|
31
|
+
statusText: e != null && e.signal.aborted ? "Aborted" : "NetworkError",
|
|
32
|
+
body: String(a)
|
|
33
|
+
})).finally(() => {
|
|
34
|
+
d !== null && clearTimeout(d), t.abort && t.abort.removeEventListener("abort", c);
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
export {
|
|
38
|
+
p as f
|
|
39
|
+
};
|