@seayoo-web/request 2.0.8 → 2.0.10
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.cjs +2 -2
- package/dist/index.js +56 -55
- package/dist/node.cjs +1 -1
- package/dist/node.js +28 -28
- package/dist/{request.fetch-DfFYJr1l.js → request.fetch-DR4KeRZ0.js} +14 -14
- package/dist/request.fetch-K4MJcDmZ.cjs +1 -0
- package/dist/{retry-CaBI_Pfh.js → type-CRH6iqXf.js} +162 -154
- package/dist/type-CrucJEBR.cjs +2 -0
- package/dist/wx.cjs +1 -1
- package/dist/wx.js +29 -29
- package/package.json +2 -2
- package/types/inc/request.fetch.d.ts +1 -1
- package/types/inc/request.node.d.ts +1 -1
- package/types/inc/request.wx.d.ts +1 -1
- package/types/inc/request.xhr.d.ts +1 -1
- package/types/inc/type.d.ts +12 -0
- package/types/inc/utils.d.ts +4 -0
- package/types/index.d.ts +1 -0
- package/dist/request.fetch-Dc_ujBlU.cjs +0 -1
- package/dist/retry-DrW-Az-k.cjs +0 -2
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
2
|
-
`).forEach(n=>{const r=n.trim();if(!r)return;const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("./type-CrucJEBR.cjs"),q=require("./request.fetch-K4MJcDmZ.cjs"),y=async function(t,s,e){return o.handleResponse(await o.retryRequest(R,t,s,e),t,s,e)};async function m(t,s,e,n){const r=e==null?void 0:e.body,u=(e==null?void 0:e.method)==="PUT"?"PUT":"POST";if(s instanceof Blob){const i=new o.RequestGlobalConfig(n),f=await R(t,i,{...e,method:u,body:s});return o.handleResponse(f,t,i,e)}const c=new FormData,d={...s};r instanceof Object&&Object.entries(r).forEach(([i,f])=>{f instanceof Blob?d[i]=f:Array.isArray(f)?f.forEach((a,g)=>{c.append(`${i}[${g}]`,String(a))}):c.append(i,String(f))});for(const i in d)c.append(i,d[i]);const b=new o.RequestGlobalConfig(n),w=await R(t,b,{...e,method:u,body:c});return o.handleResponse(w,t,b,e)}const R=async function(t,s,e){const n=await o.convertOptions(t,s,e),r=n.method,u=e==null?void 0:e.onUploadProgress,c=o.Dt(n.url,n.params);return await new Promise(d=>{let b=null,w=!1;const i=function(){w||(a.abort(),w=!0)};function f(){b!==null&&clearTimeout(b),n.abort&&n.abort.removeEventListener("abort",i)}const a=new XMLHttpRequest;if(a.open(r,c,!0),u){let g=1;a.upload.addEventListener("progress",h=>{g=h.total,u({total:h.total,loaded:h.loaded})}),a.addEventListener("load",()=>{u({loaded:g,total:g})})}a.addEventListener("load",()=>{f(),d({url:c,method:r,status:a.status,statusText:a.statusText,headers:E(a),body:r==="HEAD"?"":a.responseText})}),a.addEventListener("error",g=>{f(),d({url:c,method:r,status:-1,statusText:o.RequestInteralError.Unknown,body:"",rawError:g})},!0),a.addEventListener("abort",()=>{f(),d({url:c,method:r,status:-1,statusText:o.RequestInteralError.Aborted,body:""})}),Object.entries(n.headers).forEach(([g,h])=>{a.setRequestHeader(g,h)}),n.credentials==="include"&&(a.withCredentials=!0),a.send(n.body||void 0),n.abort&&n.abort.addEventListener("abort",i),n.timeout>0&&(b=setTimeout(i,n.timeout))})};function E(t){const s={};if(!t)return s;const e=t.getAllResponseHeaders();return e&&e!=="null"&&e.replace(/\r/g,"").split(`
|
|
2
|
+
`).forEach(n=>{const r=n.trim();if(!r)return;const u=r.split(":"),c=u[0].trim();c&&(s[c]=(u[1]||"").trim())}),s}async function H(t,s,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 u=o.Dt(t,e,!0);return new Promise(c=>{n[r]=function(d){if(r in window&&delete n[r],s(d))return d;console.warn("response type check faild",t,d),c(null)},o.Me(u).catch(function(){c(null),delete n[r]})})}async function T(t,s,e={}){const n=window;return"var"in e||(e.var="jsonxData"+Math.random().toString(16).slice(2)),t?await o.Me(o.Dt(t,e,!0)).then(()=>{const r=n[e.var+""];return s(r)?r:(console.warn("response type check faild",t,r),null)}).catch(()=>null):null}const C=async function(t,s,e){return await m(t,s,e,{baseURL:l.getConfig("baseURL"),logHandler:l.getConfig("logHandler"),errorHandler:l.getConfig("errorHandler"),requestTransformer:l.getConfig("requestTransformer"),messageHandler:l.getConfig("messageHandler"),responseHandler:l.getConfig("responseHandler")})};function p(t){if(!o.Kt.window)throw new Error("Default Module Only Support In Browser");return o.Kt.fetch?new o.NetRequestHandler(q.fetchRequest,t):new o.NetRequestHandler(y,t)}const l=p(),x=l.setConfig,D=l.request,j=l.head,L=l.get,S=l.post,U=l.del,k=l.put,v=l.patch;exports.RequestInteralError=o.RequestInteralError;exports.getResponseRulesDescription=o.getResponseRulesDescription;exports.NetRequest=p;exports.del=U;exports.get=L;exports.head=j;exports.jsonp=H;exports.jsonx=T;exports.patch=v;exports.post=S;exports.put=k;exports.request=D;exports.setGlobalConfig=x;exports.upload=C;
|
package/dist/index.js
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import { h as w, r as
|
|
2
|
-
import { g as
|
|
3
|
-
import { f as
|
|
4
|
-
const
|
|
5
|
-
return w(await
|
|
1
|
+
import { h as w, r as T, R as y, c as x, D as p, a as R, M as E, K as H, N as q } from "./type-CRH6iqXf.js";
|
|
2
|
+
import { g as z } from "./type-CRH6iqXf.js";
|
|
3
|
+
import { f as C } from "./request.fetch-DR4KeRZ0.js";
|
|
4
|
+
const L = async function(t, a, e) {
|
|
5
|
+
return w(await T(m, t, a, e), t, a, e);
|
|
6
6
|
};
|
|
7
|
-
async function
|
|
7
|
+
async function D(t, a, e, n) {
|
|
8
8
|
const r = e == null ? void 0 : e.body, i = (e == null ? void 0 : e.method) === "PUT" ? "PUT" : "POST";
|
|
9
|
-
if (
|
|
9
|
+
if (a instanceof Blob) {
|
|
10
10
|
const l = new y(n), u = await m(t, l, {
|
|
11
11
|
...e,
|
|
12
12
|
method: i,
|
|
13
|
-
body:
|
|
13
|
+
body: a
|
|
14
14
|
});
|
|
15
15
|
return w(u, t, l, e);
|
|
16
16
|
}
|
|
17
|
-
const s = new FormData(), d = { ...
|
|
17
|
+
const s = new FormData(), d = { ...a };
|
|
18
18
|
r instanceof Object && Object.entries(r).forEach(([l, u]) => {
|
|
19
|
-
u instanceof Blob ? d[l] = u : Array.isArray(u) ? u.forEach((
|
|
20
|
-
s.append(`${l}[${f}]`, String(
|
|
19
|
+
u instanceof Blob ? d[l] = u : Array.isArray(u) ? u.forEach((o, f) => {
|
|
20
|
+
s.append(`${l}[${f}]`, String(o));
|
|
21
21
|
}) : s.append(l, String(u));
|
|
22
22
|
});
|
|
23
23
|
for (const l in d)
|
|
@@ -29,64 +29,64 @@ async function L(t, o, e, n) {
|
|
|
29
29
|
});
|
|
30
30
|
return w(h, t, b, e);
|
|
31
31
|
}
|
|
32
|
-
const m = async function(t,
|
|
33
|
-
const n = await
|
|
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, s = p(n.url, n.params);
|
|
34
34
|
return await new Promise((d) => {
|
|
35
35
|
let b = null, h = !1;
|
|
36
36
|
const l = function() {
|
|
37
|
-
h || (
|
|
37
|
+
h || (o.abort(), h = !0);
|
|
38
38
|
};
|
|
39
39
|
function u() {
|
|
40
40
|
b !== null && clearTimeout(b), n.abort && n.abort.removeEventListener("abort", l);
|
|
41
41
|
}
|
|
42
|
-
const
|
|
43
|
-
if (
|
|
42
|
+
const o = new XMLHttpRequest();
|
|
43
|
+
if (o.open(r, s, !0), i) {
|
|
44
44
|
let f = 1;
|
|
45
|
-
|
|
45
|
+
o.upload.addEventListener("progress", (g) => {
|
|
46
46
|
f = g.total, i({ total: g.total, loaded: g.loaded });
|
|
47
|
-
}),
|
|
47
|
+
}), o.addEventListener("load", () => {
|
|
48
48
|
i({ loaded: f, total: f });
|
|
49
49
|
});
|
|
50
50
|
}
|
|
51
|
-
|
|
51
|
+
o.addEventListener("load", () => {
|
|
52
52
|
u(), d({
|
|
53
53
|
url: s,
|
|
54
54
|
method: r,
|
|
55
|
-
status:
|
|
56
|
-
statusText:
|
|
57
|
-
headers:
|
|
58
|
-
body: r === "HEAD" ? "" :
|
|
55
|
+
status: o.status,
|
|
56
|
+
statusText: o.statusText,
|
|
57
|
+
headers: U(o),
|
|
58
|
+
body: r === "HEAD" ? "" : o.responseText
|
|
59
59
|
});
|
|
60
|
-
}),
|
|
60
|
+
}), o.addEventListener(
|
|
61
61
|
"error",
|
|
62
62
|
(f) => {
|
|
63
63
|
u(), d({
|
|
64
64
|
url: s,
|
|
65
65
|
method: r,
|
|
66
66
|
status: -1,
|
|
67
|
-
statusText:
|
|
67
|
+
statusText: R.Unknown,
|
|
68
68
|
body: "",
|
|
69
69
|
rawError: f
|
|
70
70
|
});
|
|
71
71
|
},
|
|
72
72
|
!0
|
|
73
|
-
),
|
|
73
|
+
), o.addEventListener("abort", () => {
|
|
74
74
|
u(), d({
|
|
75
75
|
url: s,
|
|
76
76
|
method: r,
|
|
77
77
|
status: -1,
|
|
78
|
-
statusText:
|
|
78
|
+
statusText: R.Aborted,
|
|
79
79
|
body: ""
|
|
80
80
|
});
|
|
81
81
|
}), Object.entries(n.headers).forEach(([f, g]) => {
|
|
82
|
-
|
|
83
|
-
}), n.credentials === "include" && (
|
|
82
|
+
o.setRequestHeader(f, g);
|
|
83
|
+
}), n.credentials === "include" && (o.withCredentials = !0), o.send(n.body || void 0), n.abort && n.abort.addEventListener("abort", l), n.timeout > 0 && (b = setTimeout(l, n.timeout));
|
|
84
84
|
});
|
|
85
85
|
};
|
|
86
|
-
function
|
|
87
|
-
const
|
|
86
|
+
function U(t) {
|
|
87
|
+
const a = {};
|
|
88
88
|
if (!t)
|
|
89
|
-
return
|
|
89
|
+
return a;
|
|
90
90
|
const e = t.getAllResponseHeaders();
|
|
91
91
|
return e && e !== "null" && e.replace(/\r/g, "").split(`
|
|
92
92
|
`).forEach((n) => {
|
|
@@ -94,10 +94,10 @@ function S(t) {
|
|
|
94
94
|
if (!r)
|
|
95
95
|
return;
|
|
96
96
|
const i = r.split(":"), s = i[0].trim();
|
|
97
|
-
s && (
|
|
98
|
-
}),
|
|
97
|
+
s && (a[s] = (i[1] || "").trim());
|
|
98
|
+
}), a;
|
|
99
99
|
}
|
|
100
|
-
async function v(t,
|
|
100
|
+
async function v(t, a, e = {}) {
|
|
101
101
|
const n = window;
|
|
102
102
|
"callback" in e || (e.callback = "jsonxData" + Math.random().toString(16).slice(2));
|
|
103
103
|
const r = e.callback + "";
|
|
@@ -106,23 +106,23 @@ async function v(t, o, e = {}) {
|
|
|
106
106
|
const i = p(t, e, !0);
|
|
107
107
|
return new Promise((s) => {
|
|
108
108
|
n[r] = function(d) {
|
|
109
|
-
if (r in window && delete n[r],
|
|
109
|
+
if (r in window && delete n[r], a(d))
|
|
110
110
|
return d;
|
|
111
111
|
console.warn("response type check faild", t, d), s(null);
|
|
112
|
-
},
|
|
112
|
+
}, E(i).catch(function() {
|
|
113
113
|
s(null), delete n[r];
|
|
114
114
|
});
|
|
115
115
|
});
|
|
116
116
|
}
|
|
117
|
-
async function
|
|
117
|
+
async function M(t, a, e = {}) {
|
|
118
118
|
const n = window;
|
|
119
|
-
return "var" in e || (e.var = "jsonxData" + Math.random().toString(16).slice(2)), t ? await
|
|
119
|
+
return "var" in e || (e.var = "jsonxData" + Math.random().toString(16).slice(2)), t ? await E(p(t, e, !0)).then(() => {
|
|
120
120
|
const r = n[e.var + ""];
|
|
121
|
-
return
|
|
121
|
+
return a(r) ? r : (console.warn("response type check faild", t, r), null);
|
|
122
122
|
}).catch(() => null) : null;
|
|
123
123
|
}
|
|
124
|
-
const O = async function(t,
|
|
125
|
-
return await
|
|
124
|
+
const O = async function(t, a, e) {
|
|
125
|
+
return await D(t, a, e, {
|
|
126
126
|
baseURL: c.getConfig("baseURL"),
|
|
127
127
|
logHandler: c.getConfig("logHandler"),
|
|
128
128
|
errorHandler: c.getConfig("errorHandler"),
|
|
@@ -131,23 +131,24 @@ const O = async function(t, o, e) {
|
|
|
131
131
|
responseHandler: c.getConfig("responseHandler")
|
|
132
132
|
});
|
|
133
133
|
};
|
|
134
|
-
function
|
|
135
|
-
if (!
|
|
134
|
+
function k(t) {
|
|
135
|
+
if (!H.window)
|
|
136
136
|
throw new Error("Default Module Only Support In Browser");
|
|
137
|
-
return
|
|
137
|
+
return H.fetch ? new q(C, t) : new q(L, t);
|
|
138
138
|
}
|
|
139
|
-
const c =
|
|
139
|
+
const c = k(), P = c.setConfig, A = c.request, N = c.head, B = c.get, X = c.post, F = c.del, G = c.put, I = c.patch;
|
|
140
140
|
export {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
141
|
+
k as NetRequest,
|
|
142
|
+
R as RequestInteralError,
|
|
143
|
+
F as del,
|
|
144
|
+
B as get,
|
|
145
|
+
z as getResponseRulesDescription,
|
|
146
|
+
N as head,
|
|
146
147
|
v as jsonp,
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
148
|
+
M as jsonx,
|
|
149
|
+
I as patch,
|
|
150
|
+
X as post,
|
|
151
|
+
G as put,
|
|
151
152
|
A as request,
|
|
152
153
|
P as setGlobalConfig,
|
|
153
154
|
O as upload
|
package/dist/node.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./type-CrucJEBR.cjs"),b=require("./request.fetch-K4MJcDmZ.cjs"),y=require("node:http"),g=require("node:https"),w=async function(o,u,c){return e.handleResponse(await e.retryRequest(E,o,u,c),o,u,c)},E=async function(o,u,c){const t=await e.convertOptions(o,u,c);if(!e.Y(t.url))return{url:t.url,method:t.method,status:-1,statusText:e.RequestInteralError.URLFormatError,headers:{},body:""};const p=/^https:\/\//i.test(t.url)?g: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=p.request(a,{headers:t.headers,method:t.method,timeout:t.timeout>0?t.timeout:void 0},function(s){const l=[];s.on("data",h=>l.push(h)),s.on("end",()=>{const h=e.fromEntries(Object.entries(s.headers).map(([R,m])=>[R.toLowerCase(),Array.isArray(m)?m.join(","):m]));n({url:a.toString(),method:t.method,status:s.statusCode||-1,statusText:s.statusMessage||e.RequestInteralError.Unknown,headers:h,body:f?"":Buffer.concat(l).toString("utf-8")})})});d.on("error",s=>{n({url:a.toString(),method:t.method,status:-1,statusText:e.RequestInteralError.Unknown,body:"",rawError:s})}),d.on("timeout",()=>{n({url:a.toString(),method:t.method,status:-1,statusText:e.RequestInteralError.Timeout,body:""})}),t.body&&d.write(t.body),d.end()})};function q(o){return e.Kt.fetch?new e.NetRequestHandler(b.fetchRequest,o):new e.NetRequestHandler(w,o)}const r=q(),S=r.setConfig,T=r.head,j=r.get,C=r.post,N=r.del,O=r.put,U=r.patch;exports.NetRequest=q;exports.del=N;exports.get=j;exports.head=T;exports.patch=U;exports.post=C;exports.put=O;exports.setGlobalConfig=S;
|
package/dist/node.js
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
import { h as y, r as
|
|
2
|
-
import { f as
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
const
|
|
6
|
-
return y(await
|
|
7
|
-
},
|
|
1
|
+
import { h as y, r as q, c as w, Y as g, a as d, f as E, N as p, K as x } from "./type-CRH6iqXf.js";
|
|
2
|
+
import { f as T } from "./request.fetch-DR4KeRZ0.js";
|
|
3
|
+
import U from "node:http";
|
|
4
|
+
import j from "node:https";
|
|
5
|
+
const C = async function(e, a, u) {
|
|
6
|
+
return y(await q(L, e, a, u), e, a, u);
|
|
7
|
+
}, L = async function(e, a, u) {
|
|
8
8
|
const t = await w(e, a, u);
|
|
9
|
-
if (!
|
|
9
|
+
if (!g(t.url))
|
|
10
10
|
return {
|
|
11
11
|
url: t.url,
|
|
12
12
|
method: t.method,
|
|
13
13
|
status: -1,
|
|
14
|
-
statusText:
|
|
14
|
+
statusText: d.URLFormatError,
|
|
15
15
|
headers: {},
|
|
16
16
|
body: ""
|
|
17
17
|
};
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
const
|
|
18
|
+
const l = /^https:\/\//i.test(t.url) ? j : U, n = new URL(t.url), i = t.params;
|
|
19
|
+
i instanceof Object && Object.keys(i).forEach((r) => n.searchParams.set(r, i[r]));
|
|
20
|
+
const R = t.method === "HEAD";
|
|
21
21
|
return new Promise((r) => {
|
|
22
|
-
const c =
|
|
22
|
+
const c = l.request(
|
|
23
23
|
n,
|
|
24
24
|
{
|
|
25
25
|
headers: t.headers,
|
|
@@ -27,18 +27,18 @@ const U = async function(e, a, u) {
|
|
|
27
27
|
timeout: t.timeout > 0 ? t.timeout : void 0
|
|
28
28
|
},
|
|
29
29
|
function(o) {
|
|
30
|
-
const
|
|
31
|
-
o.on("data", (
|
|
32
|
-
const
|
|
33
|
-
Object.entries(o.headers).map(([
|
|
30
|
+
const f = [];
|
|
31
|
+
o.on("data", (m) => f.push(m)), o.on("end", () => {
|
|
32
|
+
const m = E(
|
|
33
|
+
Object.entries(o.headers).map(([b, h]) => [b.toLowerCase(), Array.isArray(h) ? h.join(",") : h])
|
|
34
34
|
);
|
|
35
35
|
r({
|
|
36
36
|
url: n.toString(),
|
|
37
37
|
method: t.method,
|
|
38
38
|
status: o.statusCode || -1,
|
|
39
|
-
statusText: o.statusMessage ||
|
|
40
|
-
headers:
|
|
41
|
-
body:
|
|
39
|
+
statusText: o.statusMessage || d.Unknown,
|
|
40
|
+
headers: m,
|
|
41
|
+
body: R ? "" : Buffer.concat(f).toString("utf-8")
|
|
42
42
|
});
|
|
43
43
|
});
|
|
44
44
|
}
|
|
@@ -48,7 +48,7 @@ const U = async function(e, a, u) {
|
|
|
48
48
|
url: n.toString(),
|
|
49
49
|
method: t.method,
|
|
50
50
|
status: -1,
|
|
51
|
-
statusText:
|
|
51
|
+
statusText: d.Unknown,
|
|
52
52
|
body: "",
|
|
53
53
|
rawError: o
|
|
54
54
|
});
|
|
@@ -57,23 +57,23 @@ const U = async function(e, a, u) {
|
|
|
57
57
|
url: n.toString(),
|
|
58
58
|
method: t.method,
|
|
59
59
|
status: -1,
|
|
60
|
-
statusText:
|
|
60
|
+
statusText: d.Timeout,
|
|
61
61
|
body: ""
|
|
62
62
|
});
|
|
63
63
|
}), t.body && c.write(t.body), c.end();
|
|
64
64
|
});
|
|
65
65
|
};
|
|
66
|
-
function
|
|
67
|
-
return
|
|
66
|
+
function N(e) {
|
|
67
|
+
return x.fetch ? new p(T, e) : new p(C, e);
|
|
68
68
|
}
|
|
69
|
-
const s =
|
|
69
|
+
const s = N(), k = s.setConfig, K = s.head, P = s.get, B = s.post, D = s.del, F = s.put, G = s.patch;
|
|
70
70
|
export {
|
|
71
|
-
|
|
71
|
+
N as NetRequest,
|
|
72
72
|
D as del,
|
|
73
73
|
P as get,
|
|
74
|
-
|
|
74
|
+
K as head,
|
|
75
75
|
G as patch,
|
|
76
76
|
B as post,
|
|
77
77
|
F as put,
|
|
78
|
-
|
|
78
|
+
k as setGlobalConfig
|
|
79
79
|
};
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { h as
|
|
2
|
-
const
|
|
3
|
-
return
|
|
4
|
-
},
|
|
5
|
-
const t = await
|
|
1
|
+
import { h as f, r as w, c as y, K as E, f as g, a as d } from "./type-CRH6iqXf.js";
|
|
2
|
+
const T = async function(r, o, n) {
|
|
3
|
+
return f(await w(x, r, o, n), r, o, n);
|
|
4
|
+
}, x = async function(r, o, n) {
|
|
5
|
+
const t = await y(r, o, n), s = new URL(t.url), i = t.params;
|
|
6
6
|
i instanceof Object && Object.keys(i).forEach((e) => s.searchParams.set(e, i[e]));
|
|
7
|
-
const a =
|
|
7
|
+
const a = E.AbortController ? new AbortController() : null;
|
|
8
8
|
function c() {
|
|
9
9
|
a && !a.signal.aborted && a.abort();
|
|
10
10
|
}
|
|
11
11
|
t.abort && t.abort.addEventListener("abort", c);
|
|
12
|
-
const
|
|
12
|
+
const h = t.timeout > 0 ? setTimeout(c, t.timeout) : null, l = t.method === "HEAD";
|
|
13
13
|
return await fetch(s, {
|
|
14
14
|
method: t.method,
|
|
15
15
|
headers: Object.keys(t.headers).length > 0 ? new Headers(t.headers) : void 0,
|
|
@@ -18,34 +18,34 @@ const x = async function(o, r, n) {
|
|
|
18
18
|
signal: a == null ? void 0 : a.signal,
|
|
19
19
|
redirect: "follow"
|
|
20
20
|
}).then(async (e) => {
|
|
21
|
-
const u =
|
|
21
|
+
const u = l ? "" : await e.text().catch((m) => m), b = g([...e.headers.entries()]);
|
|
22
22
|
return u instanceof Error ? {
|
|
23
23
|
url: s.toString(),
|
|
24
24
|
method: t.method,
|
|
25
25
|
status: e.status,
|
|
26
|
-
statusText: e.statusText ||
|
|
26
|
+
statusText: e.statusText || d.Unknown,
|
|
27
27
|
body: "",
|
|
28
|
-
headers:
|
|
28
|
+
headers: b,
|
|
29
29
|
rawError: u
|
|
30
30
|
} : {
|
|
31
31
|
url: s.toString(),
|
|
32
32
|
method: t.method,
|
|
33
33
|
status: e.status,
|
|
34
34
|
statusText: e.statusText,
|
|
35
|
-
headers:
|
|
35
|
+
headers: b,
|
|
36
36
|
body: u
|
|
37
37
|
};
|
|
38
38
|
}).catch((e) => ({
|
|
39
39
|
url: s.toString(),
|
|
40
40
|
method: t.method,
|
|
41
41
|
status: -1,
|
|
42
|
-
statusText: a != null && a.signal.aborted ?
|
|
42
|
+
statusText: a != null && a.signal.aborted ? d.Aborted : d.Unknown,
|
|
43
43
|
body: "",
|
|
44
44
|
rawError: e
|
|
45
45
|
})).finally(() => {
|
|
46
|
-
|
|
46
|
+
h !== null && clearTimeout(h), t.abort && t.abort.removeEventListener("abort", c);
|
|
47
47
|
});
|
|
48
48
|
};
|
|
49
49
|
export {
|
|
50
|
-
|
|
50
|
+
T as f
|
|
51
51
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const s=require("./type-CrucJEBR.cjs"),f=async function(o,n,i){return s.handleResponse(await s.retryRequest(w,o,n,i),o,n,i)},w=async function(o,n,i){const t=await s.convertOptions(o,n,i),a=new URL(t.url),u=t.params;u instanceof Object&&Object.keys(u).forEach(e=>a.searchParams.set(e,u[e]));const r=s.Kt.AbortController?new AbortController:null;function c(){r&&!r.signal.aborted&&r.abort()}t.abort&&t.abort.addEventListener("abort",c);const h=t.timeout>0?setTimeout(c,t.timeout):null,b=t.method==="HEAD";return await fetch(a,{method:t.method,headers:Object.keys(t.headers).length>0?new Headers(t.headers):void 0,body:t.body,credentials:t.credentials,signal:r==null?void 0:r.signal,redirect:"follow"}).then(async e=>{const d=b?"":await e.text().catch(m=>m),l=s.fromEntries([...e.headers.entries()]);return d instanceof Error?{url:a.toString(),method:t.method,status:e.status,statusText:e.statusText||s.RequestInteralError.Unknown,body:"",headers:l,rawError:d}:{url:a.toString(),method:t.method,status:e.status,statusText:e.statusText,headers:l,body:d}}).catch(e=>({url:a.toString(),method:t.method,status:-1,statusText:r!=null&&r.signal.aborted?s.RequestInteralError.Aborted:s.RequestInteralError.Unknown,body:"",rawError:e})).finally(()=>{h!==null&&clearTimeout(h),t.abort&&t.abort.removeEventListener("abort",c)})};exports.fetchRequest=f;
|