@seayoo-web/request 1.7.0 → 1.7.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/README.md +3 -3
- package/dist/inc/request.fetch.d.ts +7 -0
- package/dist/inc/{request.browser.d.ts → request.xhr.d.ts} +9 -8
- package/dist/inc/type.d.ts +5 -1
- package/dist/index.cjs +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +107 -135
- package/dist/node.cjs +1 -1
- package/dist/node.js +38 -36
- package/dist/request.fetch-BtrGinni.cjs +1 -0
- package/dist/request.fetch-DlebtNMD.js +40 -0
- package/dist/{version-DOOsgzgL.js → version-BLZ49ejb.js} +267 -256
- package/dist/version-BZ8fy-0W.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
|
@@ -261,9 +261,9 @@ status 表示网络错误或者http 状态码错误时重试;
|
|
|
261
261
|
|
|
262
262
|
### errorHandler
|
|
263
263
|
|
|
264
|
-
类型:null | ((status: number, method: string, url: string) => void)
|
|
264
|
+
类型:null | ((status: number, method: string, url: string, rawError?: Error | ProgressEvent) => void)
|
|
265
265
|
|
|
266
|
-
说明:全局错误处理函数,仅仅在 http status 错误时触发,通常用于检查 401
|
|
266
|
+
说明:全局错误处理函数,仅仅在 http status 错误时触发,通常用于检查 401 未登录状态进行跳转登录,其中 rawError 为请求工具的原始错误,可用以进行 Sentry 信息上报;
|
|
267
267
|
|
|
268
268
|
### responseHandler
|
|
269
269
|
|
|
@@ -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/inc/type.d.ts
CHANGED
|
@@ -59,6 +59,8 @@ export interface IOtherRequestOptions {
|
|
|
59
59
|
}
|
|
60
60
|
/** 对外工具接口的请求配置 */
|
|
61
61
|
export type IRequestOptions = IBaseRequestOptions & IRetryRequestOptions & IOtherRequestOptions;
|
|
62
|
+
/** 请求的原始错误信息 */
|
|
63
|
+
type ERequestRawError = Error | ProgressEvent;
|
|
62
64
|
/** 全局默认配置 */
|
|
63
65
|
export type IRequestGlobalConfig = {
|
|
64
66
|
/**
|
|
@@ -85,7 +87,7 @@ export type IRequestGlobalConfig = {
|
|
|
85
87
|
body?: IBaseRequestBody;
|
|
86
88
|
}) => MaybePromise<void | string>);
|
|
87
89
|
/** 全局错误处理函数,仅仅在 statusCode 错误时触发 */
|
|
88
|
-
errorHandler?: null | ((status: number, method: string, url: string) => void);
|
|
90
|
+
errorHandler?: null | ((status: number, method: string, url: string, rawError?: ERequestRawError) => void);
|
|
89
91
|
/** 全局响应处理函数,任意状态都会触发 */
|
|
90
92
|
responseHandler?: null | ((result: IResponseResult, method: string, url: string) => void);
|
|
91
93
|
/** 全局消息提示函数 */
|
|
@@ -156,6 +158,8 @@ export interface IRequestBaseResponse {
|
|
|
156
158
|
headers?: Record<string, string | undefined>;
|
|
157
159
|
/** 响应体,如果网络错误或 204/202,则返回空或错误信息 */
|
|
158
160
|
body: string;
|
|
161
|
+
/** 原始的请求错误信息,仅当请求失败时有值,用以进行错误上报用 */
|
|
162
|
+
rawError?: ERequestRawError;
|
|
159
163
|
}
|
|
160
164
|
/** 对外工具接口的返回内容 */
|
|
161
165
|
export interface IResponseResult<T = unknown> {
|
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-BZ8fy-0W.cjs"),y=require("./request.fetch-BtrGinni.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",g=>{f(),u({url:a,method:r,status:-1,statusText:"Failed",body:"",rawError:g})},!0),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 E(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 C=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=E;exports.patch=D;exports.post=j;exports.put=L;exports.setGlobalConfig=S;exports.upload=C;
|
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,126 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { g as z, v as
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import { h as w, r as E, R as y, c as q, U as p, A as T, S as R, N as H } from "./version-BLZ49ejb.js";
|
|
2
|
+
import { g as z, v as I } from "./version-BLZ49ejb.js";
|
|
3
|
+
import { f as x } from "./request.fetch-DlebtNMD.js";
|
|
4
|
+
const C = async function(t, a, e) {
|
|
5
|
+
return w(await E(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 q(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
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
58
|
+
s.addEventListener(
|
|
59
|
+
"error",
|
|
60
|
+
(f) => {
|
|
61
|
+
u(), d({
|
|
62
|
+
url: o,
|
|
63
|
+
method: r,
|
|
64
|
+
status: -1,
|
|
65
|
+
statusText: "Failed",
|
|
66
|
+
body: "",
|
|
67
|
+
rawError: f
|
|
68
|
+
});
|
|
69
|
+
},
|
|
70
|
+
!0
|
|
71
|
+
), s.addEventListener("abort", () => {
|
|
72
|
+
u(), d({
|
|
73
|
+
url: o,
|
|
72
74
|
method: r,
|
|
73
75
|
status: -1,
|
|
74
76
|
statusText: "Aborted",
|
|
75
77
|
body: ""
|
|
76
78
|
});
|
|
77
|
-
}), Object.entries(
|
|
78
|
-
|
|
79
|
-
}),
|
|
79
|
+
}), Object.entries(n.headers).forEach(([f, g]) => {
|
|
80
|
+
s.setRequestHeader(f, g);
|
|
81
|
+
}), 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
82
|
});
|
|
81
83
|
};
|
|
82
|
-
function
|
|
83
|
-
const
|
|
84
|
-
if (!
|
|
85
|
-
return
|
|
86
|
-
const e =
|
|
84
|
+
function U(t) {
|
|
85
|
+
const a = {};
|
|
86
|
+
if (!t)
|
|
87
|
+
return a;
|
|
88
|
+
const e = t.getAllResponseHeaders();
|
|
87
89
|
return e && e !== "null" && e.replace(/\r/g, "").split(`
|
|
88
|
-
`).forEach((
|
|
89
|
-
const r =
|
|
90
|
+
`).forEach((n) => {
|
|
91
|
+
const r = n.trim();
|
|
90
92
|
if (!r)
|
|
91
93
|
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);
|
|
94
|
+
const i = r.split(":"), o = i[0].trim();
|
|
95
|
+
o && (a[o] = (i[1] || "").trim());
|
|
96
|
+
}), a;
|
|
125
97
|
}
|
|
126
|
-
async function k(
|
|
127
|
-
const
|
|
98
|
+
async function k(t, a, e = {}) {
|
|
99
|
+
const n = window;
|
|
128
100
|
"callback" in e || (e.callback = "jsonxData" + Math.random().toString(16).slice(2));
|
|
129
101
|
const r = e.callback + "";
|
|
130
|
-
if (!
|
|
102
|
+
if (!t)
|
|
131
103
|
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
|
-
|
|
104
|
+
const i = p(t, e, !0);
|
|
105
|
+
return new Promise((o) => {
|
|
106
|
+
n[r] = function(d) {
|
|
107
|
+
if (r in window && delete n[r], a(d))
|
|
108
|
+
return d;
|
|
109
|
+
console.warn("response type check faild", t, d), o(null);
|
|
110
|
+
}, T(i).catch(function() {
|
|
111
|
+
o(null), delete n[r];
|
|
140
112
|
});
|
|
141
113
|
});
|
|
142
114
|
}
|
|
143
|
-
async function
|
|
144
|
-
const
|
|
145
|
-
return "var" in e || (e.var = "jsonxData" + Math.random().toString(16).slice(2)),
|
|
146
|
-
const r =
|
|
147
|
-
return
|
|
115
|
+
async function A(t, a, e = {}) {
|
|
116
|
+
const n = window;
|
|
117
|
+
return "var" in e || (e.var = "jsonxData" + Math.random().toString(16).slice(2)), t ? await T(p(t, e, !0)).then(() => {
|
|
118
|
+
const r = n[e.var + ""];
|
|
119
|
+
return a(r) ? r : (console.warn("response type check faild", t, r), null);
|
|
148
120
|
}).catch(() => null) : null;
|
|
149
121
|
}
|
|
150
|
-
const D = async function(
|
|
151
|
-
return await
|
|
122
|
+
const D = async function(t, a, e) {
|
|
123
|
+
return await S(t, a, e, {
|
|
152
124
|
baseURL: l.getConfig("baseURL"),
|
|
153
125
|
logHandler: l.getConfig("logHandler"),
|
|
154
126
|
errorHandler: l.getConfig("errorHandler"),
|
|
@@ -157,24 +129,24 @@ const D = async function(n, o, e) {
|
|
|
157
129
|
responseHandler: l.getConfig("responseHandler")
|
|
158
130
|
});
|
|
159
131
|
};
|
|
160
|
-
function
|
|
161
|
-
if (!
|
|
132
|
+
function L(t) {
|
|
133
|
+
if (!R.window)
|
|
162
134
|
throw new Error("Default Module Only Support In Browser");
|
|
163
|
-
return
|
|
135
|
+
return R.fetch ? new H(x, t) : new H(C, t);
|
|
164
136
|
}
|
|
165
|
-
const l =
|
|
137
|
+
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
138
|
export {
|
|
167
|
-
|
|
139
|
+
L as NetRequest,
|
|
168
140
|
B as del,
|
|
169
|
-
|
|
141
|
+
M as get,
|
|
170
142
|
z as getResponseRulesDescription,
|
|
171
|
-
|
|
143
|
+
P as head,
|
|
172
144
|
k as jsonp,
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
145
|
+
A as jsonx,
|
|
146
|
+
X as patch,
|
|
147
|
+
N as post,
|
|
148
|
+
F as put,
|
|
149
|
+
O as setGlobalConfig,
|
|
178
150
|
D as upload,
|
|
179
|
-
|
|
151
|
+
I as version
|
|
180
152
|
};
|
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"),o=require("./version-BZ8fy-0W.cjs"),g=require("./request.fetch-BtrGinni.cjs"),w=async function(s,u,c){return o.handleResponse(await o.retryRequest(S,s,u,c),s,u,c)},S=async function(s,u,c){const t=await o.convertOptions(s,u,c);if(!o.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(e){const p=[];e.on("data",h=>p.push(h)),e.on("end",()=>{const h=o.fromEntries(Object.entries(e.headers).map(([b,m])=>[b.toLowerCase(),Array.isArray(m)?m.join(","):m]));r({url:a.toString(),method:t.method,status:e.statusCode||-1,statusText:e.statusMessage||"Unknown",headers:h,body:q?"":Buffer.concat(p).toString("utf-8")})})});d.on("error",e=>{r({url:a.toString(),method:t.method,status:-1,statusText:e.name||"Unknown",body:e.message,rawError:e})}),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 o.Support.fetch?new o.NetRequestHandler(g.fetchRequest,s):new o.NetRequestHandler(w,s)}const n=l(),T=n.setConfig,j=n.head,C=n.get,E=n.post,N=n.del,O=n.put,U=n.patch;exports.version=o.version;exports.NetRequest=l;exports.del=N;exports.get=C;exports.head=j;exports.patch=U;exports.post=E;exports.put=O;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 w, r as q, c as g, D as x, f as S, S as E, N as p } from "./version-BLZ49ejb.js";
|
|
4
|
+
import { v as z } from "./version-BLZ49ejb.js";
|
|
5
|
+
import { f as T } from "./request.fetch-DlebtNMD.js";
|
|
6
|
+
const U = async function(o, a, u) {
|
|
7
|
+
return w(await q(j, o, a, u), o, a, u);
|
|
8
|
+
}, j = 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,12 +16,12 @@ const U = async function(s, a, u) {
|
|
|
15
16
|
headers: {},
|
|
16
17
|
body: ""
|
|
17
18
|
};
|
|
18
|
-
const
|
|
19
|
-
d instanceof Object && Object.keys(d).forEach((
|
|
20
|
-
const
|
|
21
|
-
return new Promise((
|
|
22
|
-
const c =
|
|
23
|
-
|
|
19
|
+
const f = /^https:\/\//i.test(t.url) ? R : y, n = new URL(t.url), d = t.params;
|
|
20
|
+
d instanceof Object && Object.keys(d).forEach((r) => n.searchParams.set(r, d[r]));
|
|
21
|
+
const b = t.method === "HEAD";
|
|
22
|
+
return new Promise((r) => {
|
|
23
|
+
const c = f.request(
|
|
24
|
+
n,
|
|
24
25
|
{
|
|
25
26
|
headers: t.headers,
|
|
26
27
|
method: t.method,
|
|
@@ -29,31 +30,32 @@ 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
|
-
url:
|
|
36
|
+
r({
|
|
37
|
+
url: n.toString(),
|
|
37
38
|
method: t.method,
|
|
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
|
}
|
|
45
46
|
);
|
|
46
47
|
c.on("error", (e) => {
|
|
47
|
-
|
|
48
|
-
url:
|
|
48
|
+
r({
|
|
49
|
+
url: n.toString(),
|
|
49
50
|
method: t.method,
|
|
50
51
|
status: -1,
|
|
51
52
|
statusText: e.name || "Unknown",
|
|
52
|
-
body: e.message
|
|
53
|
+
body: e.message,
|
|
54
|
+
rawError: e
|
|
53
55
|
});
|
|
54
56
|
}), c.on("timeout", () => {
|
|
55
|
-
|
|
56
|
-
url:
|
|
57
|
+
r({
|
|
58
|
+
url: n.toString(),
|
|
57
59
|
method: t.method,
|
|
58
60
|
status: -1,
|
|
59
61
|
statusText: "Timeout",
|
|
@@ -62,18 +64,18 @@ const U = async function(s, a, u) {
|
|
|
62
64
|
}), t.body && c.write(t.body), c.end();
|
|
63
65
|
});
|
|
64
66
|
};
|
|
65
|
-
function C(
|
|
66
|
-
return new T(U,
|
|
67
|
+
function C(o) {
|
|
68
|
+
return E.fetch ? new p(T, o) : new p(U, o);
|
|
67
69
|
}
|
|
68
|
-
const
|
|
70
|
+
const s = C(), H = s.setConfig, k = s.head, D = s.get, P = s.post, B = s.del, F = s.put, G = s.patch;
|
|
69
71
|
export {
|
|
70
72
|
C as NetRequest,
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
73
|
+
B as del,
|
|
74
|
+
D as get,
|
|
75
|
+
k as head,
|
|
76
|
+
G as patch,
|
|
77
|
+
P as post,
|
|
78
|
+
F as put,
|
|
79
|
+
H as setGlobalConfig,
|
|
80
|
+
z as version
|
|
79
81
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const s=require("./version-BZ8fy-0W.cjs"),b=async function(r,o,n){return s.handleResponse(await s.retryRequest(m,r,o,n),r,o,n)},m=async function(r,o,n){const t=await s.convertOptions(r,o,n),i=new URL(t.url),d=t.params;d instanceof Object&&Object.keys(d).forEach(a=>i.searchParams.set(a,d[a]));const e=s.Support.AbortController?new AbortController:null;function u(){e&&!e.signal.aborted&&e.abort()}t.abort&&t.abort.addEventListener("abort",u);const c=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 a=>({url:i.toString(),method:t.method,status:a.status,statusText:a.statusText,headers:s.fromEntries([...a.headers.entries()]),body:t.method==="HEAD"?"":await a.text()})).catch(a=>({url:i.toString(),method:t.method,status:-1,statusText:e!=null&&e.signal.aborted?"Aborted":"NetworkError",body:String(a),rawError:e!=null&&e.signal.aborted?void 0:a})).finally(()=>{c!==null&&clearTimeout(c),t.abort&&t.abort.removeEventListener("abort",u)})};exports.fetchRequest=b;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { h, r as b, c as m, S as l, f } from "./version-BLZ49ejb.js";
|
|
2
|
+
const g = async function(s, r, o) {
|
|
3
|
+
return h(await b(w, s, r, o), s, r, o);
|
|
4
|
+
}, w = async function(s, r, o) {
|
|
5
|
+
const t = await m(s, r, 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 = l.AbortController ? new AbortController() : null;
|
|
8
|
+
function d() {
|
|
9
|
+
e && !e.signal.aborted && e.abort();
|
|
10
|
+
}
|
|
11
|
+
t.abort && t.abort.addEventListener("abort", d);
|
|
12
|
+
const u = t.timeout > 0 ? setTimeout(d, t.timeout) : null, c = 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(c).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
|
+
rawError: e != null && e.signal.aborted ? void 0 : a
|
|
34
|
+
})).finally(() => {
|
|
35
|
+
u !== null && clearTimeout(u), t.abort && t.abort.removeEventListener("abort", d);
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
export {
|
|
39
|
+
g as f
|
|
40
|
+
};
|