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