@seayoo-web/request 3.1.3 → 3.1.5

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 CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("./retry-8pExkGke.cjs"),q=require("./request.fetch-COXrFv2v.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,d=(e==null?void 0:e.method)==="PUT"?"PUT":"POST";if(s instanceof Blob){const u=new o.RequestGlobalConfig(n),g=await R(t,u,{...e,method:d,body:s});return o.handleResponse(g,t,u,e)}const c=new FormData,f={...s};r instanceof Object&&Object.entries(r).forEach(([u,g])=>{g instanceof Blob?f[u]=g:Array.isArray(g)?g.forEach((a,i)=>{c.append(`${u}[${i}]`,String(a))}):c.append(u,String(g))});for(const u in f)c.append(u,f[u]);const b=new o.RequestGlobalConfig(n),w=await R(t,b,{...e,method:d,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,d=e==null?void 0:e.onUploadProgress,c=o.ge(n.url,n.params);return await new Promise(f=>{let b=null,w=!1;const u=function(){w||(a.abort(),w=!0)};function g(){b!==null&&clearTimeout(b),n.abort&&n.abort.removeEventListener("abort",u)}const a=new XMLHttpRequest;if(a.open(r,c,!0),d){let i=1;a.upload.addEventListener("progress",h=>{i=h.total,d({total:h.total,loaded:h.loaded})}),a.addEventListener("load",()=>{d({loaded:i,total:i})})}a.addEventListener("load",()=>{const i=a.status;g(),f({url:c,method:r,status:i,statusText:a.statusText,headers:E(a),body:r==="HEAD"||i===204?"":a.responseText})}),a.addEventListener("error",i=>{g(),f({url:c,method:r,status:a.status||-1,statusText:a.statusText||o.RequestInternalError.NetworkError,body:"",rawError:i})},!0),a.addEventListener("abort",()=>{g(),f({url:c,method:r,status:0,statusText:o.RequestInternalError.Aborted,body:""})}),Object.entries(n.headers).forEach(([i,h])=>{a.setRequestHeader(i,h)}),n.credentials==="include"&&(a.withCredentials=!0),a.send(n.body||void 0),n.abort&&n.abort.addEventListener("abort",u),n.timeout>0&&(b=setTimeout(u,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 d=r.split(":"),c=d[0].trim();c&&(s[c]=(d[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 d=o.ge(t,e,!0);return new Promise(c=>{n[r]=function(f){if(r in window&&delete n[r],s(f))return f;console.warn("response type check failed",t,f),c(null)},o.ce(d).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.ce(o.ge(t,e,!0)).then(()=>{const r=n[e.var+""];return s(r)?r:(console.warn("response type check failed",t,r),null)}).catch(()=>null):null}const j=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.jt.window)throw new Error("Default Module Only Support In Browser");return o.jt.fetch?new o.NetRequestHandler(q.fetchRequest,t):new o.NetRequestHandler(y,t)}const l=p(),x=l.setConfig,C=l.request,L=l.head,S=l.get,k=l.post,v=l.del,D=l.put,U=l.patch;exports.RequestInternalError=o.RequestInternalError;exports.getResponseRulesDescription=o.getResponseRulesDescription;exports.NetRequest=p;exports.del=v;exports.get=S;exports.head=L;exports.jsonp=H;exports.jsonx=T;exports.patch=U;exports.post=k;exports.put=D;exports.request=C;exports.setGlobalConfig=x;exports.upload=j;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("./retry-8pExkGke.cjs"),m=require("./request.fetch-hlpQxV81.cjs"),y=async function(t,s,e){return r.handleResponse(await r.retryRequest(p,t,s,e),t,s,e)};async function E(t,s,e,n){const o=e==null?void 0:e.body,i=(e==null?void 0:e.method)==="PUT"?"PUT":"POST";if(s instanceof Blob){const u=new r.RequestGlobalConfig(n),f=await p(t,u,{...e,method:i,body:s});return r.handleResponse(f,t,u,e)}const c=new FormData,d={...s};o instanceof Object&&Object.entries(o).forEach(([u,f])=>{f instanceof Blob?d[u]=f:Array.isArray(f)?f.forEach((a,h)=>{c.append(`${u}[${h}]`,String(a))}):c.append(u,String(f))});for(const u in d)c.append(u,d[u]);const b=new r.RequestGlobalConfig(n),R=await p(t,b,{...e,method:i,body:c});return r.handleResponse(R,t,b,e)}const p=async function(t,s,e){const n=await r.convertOptions(t,s,e),o=n.method,i=e==null?void 0:e.onUploadProgress,c=r.ge(n.url,n.params);return await new Promise(d=>{let b=null,R=!1;const u=function(){R||(a.abort(),R=!0)};function f(){b!==null&&clearTimeout(b),n.abort&&n.abort.removeEventListener("abort",u)}const a=new XMLHttpRequest;let h=!1;if(a.open(o,c,!0),i){let g=1;a.upload.addEventListener("progress",w=>{g=w.total,i({total:w.total,loaded:w.loaded})}),a.addEventListener("load",()=>{i({loaded:g,total:g})})}a.addEventListener("load",()=>{const g=a.status;f(),d({url:c,method:o,status:g,statusText:a.statusText,headers:T(a),body:o==="HEAD"||g===204?"":a.responseText})}),a.addEventListener("error",g=>{f(),d({url:c,method:o,status:a.status||-1,statusText:a.statusText||r.RequestInternalError.NetworkError,body:"",rawError:g})},!0),a.addEventListener("abort",()=>{f(),d({url:c,method:o,status:h?-1:0,statusText:h?r.RequestInternalError.Timeout:r.RequestInternalError.Aborted,body:""})}),Object.entries(n.headers).forEach(([g,w])=>{a.setRequestHeader(g,w)}),n.credentials==="include"&&(a.withCredentials=!0),a.send(n.body||void 0),n.abort&&n.abort.addEventListener("abort",u),n.timeout>0&&(b=setTimeout(function(){h=!0,u()},n.timeout))})};function T(t){const s={};if(!t)return s;const e=t.getAllResponseHeaders();return e&&e!=="null"&&e.replace(/\r/g,"").split(`
2
+ `).forEach(n=>{const o=n.trim();if(!o)return;const i=o.split(":"),c=i[0].trim();c&&(s[c]=(i[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 o=e.callback+"";if(!t)return null;const i=r.ge(t,e,!0);return new Promise(c=>{n[o]=function(d){if(o in window&&delete n[o],s(d))return d;console.warn("response type check failed",t,d),c(null)},r.ce(i).catch(function(){c(null),delete n[o]})})}async function j(t,s,e={}){const n=window;return"var"in e||(e.var="jsonxData"+Math.random().toString(16).slice(2)),t?await r.ce(r.ge(t,e,!0)).then(()=>{const o=n[e.var+""];return s(o)?o:(console.warn("response type check failed",t,o),null)}).catch(()=>null):null}const x=async function(t,s,e){return await E(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 q(t){if(!r.jt.window)throw new Error("Default Module Only Support In Browser");return r.jt.fetch?new r.NetRequestHandler(m.fetchRequest,t):new r.NetRequestHandler(y,t)}const l=q(),C=l.setConfig,L=l.request,S=l.head,k=l.get,v=l.post,D=l.del,U=l.put,O=l.patch;exports.RequestInternalError=r.RequestInternalError;exports.getResponseRulesDescription=r.getResponseRulesDescription;exports.NetRequest=q;exports.del=D;exports.get=k;exports.head=S;exports.jsonp=H;exports.jsonx=j;exports.patch=O;exports.post=v;exports.put=U;exports.request=L;exports.setGlobalConfig=C;exports.upload=x;
package/dist/index.js CHANGED
@@ -1,91 +1,94 @@
1
- import { h as w, r as T, R as y, c as x, g as p, a as R, b as q, j as E, N as H } from "./retry-_AqXIa5P.js";
2
- import { d as J } from "./retry-_AqXIa5P.js";
3
- import { f as C } from "./request.fetch-Cuk4gO1S.js";
4
- const L = async function(t, a, e) {
5
- return w(await T(m, t, a, e), t, a, e);
1
+ import { h as p, r as x, R as T, c as C, g as R, a as m, b as q, j as E, N as H } from "./retry-_AqXIa5P.js";
2
+ import { d as K } from "./retry-_AqXIa5P.js";
3
+ import { f as L } from "./request.fetch-1poQOlEV.js";
4
+ const j = async function(t, a, e) {
5
+ return p(await x(y, t, a, e), t, a, e);
6
6
  };
7
- async function j(t, a, e, n) {
8
- const r = e == null ? void 0 : e.body, d = (e == null ? void 0 : e.method) === "PUT" ? "PUT" : "POST";
7
+ async function k(t, a, e, n) {
8
+ const r = e == null ? void 0 : e.body, i = (e == null ? void 0 : e.method) === "PUT" ? "PUT" : "POST";
9
9
  if (a instanceof Blob) {
10
- const l = new y(n), f = await m(t, l, {
10
+ const l = new T(n), u = await y(t, l, {
11
11
  ...e,
12
- method: d,
12
+ method: i,
13
13
  body: a
14
14
  });
15
- return w(f, t, l, e);
15
+ return p(u, t, l, e);
16
16
  }
17
- const s = new FormData(), u = { ...a };
18
- r instanceof Object && Object.entries(r).forEach(([l, f]) => {
19
- f instanceof Blob ? u[l] = f : Array.isArray(f) ? f.forEach((o, i) => {
20
- s.append(`${l}[${i}]`, String(o));
21
- }) : s.append(l, String(f));
17
+ const s = new FormData(), d = { ...a };
18
+ r instanceof Object && Object.entries(r).forEach(([l, u]) => {
19
+ u instanceof Blob ? d[l] = u : Array.isArray(u) ? u.forEach((o, g) => {
20
+ s.append(`${l}[${g}]`, String(o));
21
+ }) : s.append(l, String(u));
22
22
  });
23
- for (const l in u)
24
- s.append(l, u[l]);
25
- const b = new y(n), h = await m(t, b, {
23
+ for (const l in d)
24
+ s.append(l, d[l]);
25
+ const b = new T(n), w = await y(t, b, {
26
26
  ...e,
27
- method: d,
27
+ method: i,
28
28
  body: s
29
29
  });
30
- return w(h, t, b, e);
30
+ return p(w, t, b, e);
31
31
  }
32
- const m = async function(t, a, e) {
33
- const n = await x(t, a, e), r = n.method, d = e == null ? void 0 : e.onUploadProgress, s = p(n.url, n.params);
34
- return await new Promise((u) => {
35
- let b = null, h = !1;
32
+ const y = async function(t, a, e) {
33
+ const n = await C(t, a, e), r = n.method, i = e == null ? void 0 : e.onUploadProgress, s = R(n.url, n.params);
34
+ return await new Promise((d) => {
35
+ let b = null, w = !1;
36
36
  const l = function() {
37
- h || (o.abort(), h = !0);
37
+ w || (o.abort(), w = !0);
38
38
  };
39
- function f() {
39
+ function u() {
40
40
  b !== null && clearTimeout(b), n.abort && n.abort.removeEventListener("abort", l);
41
41
  }
42
42
  const o = new XMLHttpRequest();
43
- if (o.open(r, s, !0), d) {
44
- let i = 1;
45
- o.upload.addEventListener("progress", (g) => {
46
- i = g.total, d({ total: g.total, loaded: g.loaded });
43
+ let g = !1;
44
+ if (o.open(r, s, !0), i) {
45
+ let f = 1;
46
+ o.upload.addEventListener("progress", (h) => {
47
+ f = h.total, i({ total: h.total, loaded: h.loaded });
47
48
  }), o.addEventListener("load", () => {
48
- d({ loaded: i, total: i });
49
+ i({ loaded: f, total: f });
49
50
  });
50
51
  }
51
52
  o.addEventListener("load", () => {
52
- const i = o.status;
53
- f(), u({
53
+ const f = o.status;
54
+ u(), d({
54
55
  url: s,
55
56
  method: r,
56
- status: i,
57
+ status: f,
57
58
  statusText: o.statusText,
58
- headers: k(o),
59
- body: r === "HEAD" || i === 204 ? "" : o.responseText
59
+ headers: S(o),
60
+ body: r === "HEAD" || f === 204 ? "" : o.responseText
60
61
  });
61
62
  }), o.addEventListener(
62
63
  "error",
63
- (i) => {
64
- f(), u({
64
+ (f) => {
65
+ u(), d({
65
66
  url: s,
66
67
  method: r,
67
68
  status: o.status || -1,
68
- statusText: o.statusText || R.NetworkError,
69
+ statusText: o.statusText || m.NetworkError,
69
70
  body: "",
70
- rawError: i
71
+ rawError: f
71
72
  });
72
73
  },
73
74
  !0
74
75
  ), o.addEventListener("abort", () => {
75
- f(), u({
76
+ u(), d({
76
77
  url: s,
77
78
  method: r,
78
- status: 0,
79
+ status: g ? -1 : 0,
79
80
  // 设置为 0 可以防止自动重试的默认策略
80
- statusText: R.Aborted,
81
+ statusText: g ? m.Timeout : m.Aborted,
81
82
  body: ""
82
83
  });
83
- }), Object.entries(n.headers).forEach(([i, g]) => {
84
- o.setRequestHeader(i, g);
85
- }), 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
+ }), Object.entries(n.headers).forEach(([f, h]) => {
85
+ o.setRequestHeader(f, h);
86
+ }), n.credentials === "include" && (o.withCredentials = !0), o.send(n.body || void 0), n.abort && n.abort.addEventListener("abort", l), n.timeout > 0 && (b = setTimeout(function() {
87
+ g = !0, l();
88
+ }, n.timeout));
86
89
  });
87
90
  };
88
- function k(t) {
91
+ function S(t) {
89
92
  const a = {};
90
93
  if (!t)
91
94
  return a;
@@ -95,36 +98,36 @@ function k(t) {
95
98
  const r = n.trim();
96
99
  if (!r)
97
100
  return;
98
- const d = r.split(":"), s = d[0].trim();
99
- s && (a[s] = (d[1] || "").trim());
101
+ const i = r.split(":"), s = i[0].trim();
102
+ s && (a[s] = (i[1] || "").trim());
100
103
  }), a;
101
104
  }
102
- async function D(t, a, e = {}) {
105
+ async function O(t, a, e = {}) {
103
106
  const n = window;
104
107
  "callback" in e || (e.callback = "jsonxData" + Math.random().toString(16).slice(2));
105
108
  const r = e.callback + "";
106
109
  if (!t)
107
110
  return null;
108
- const d = p(t, e, !0);
111
+ const i = R(t, e, !0);
109
112
  return new Promise((s) => {
110
- n[r] = function(u) {
111
- if (r in window && delete n[r], a(u))
112
- return u;
113
- console.warn("response type check failed", t, u), s(null);
114
- }, q(d).catch(function() {
113
+ n[r] = function(d) {
114
+ if (r in window && delete n[r], a(d))
115
+ return d;
116
+ console.warn("response type check failed", t, d), s(null);
117
+ }, q(i).catch(function() {
115
118
  s(null), delete n[r];
116
119
  });
117
120
  });
118
121
  }
119
- async function O(t, a, e = {}) {
122
+ async function P(t, a, e = {}) {
120
123
  const n = window;
121
- return "var" in e || (e.var = "jsonxData" + Math.random().toString(16).slice(2)), t ? await q(p(t, e, !0)).then(() => {
124
+ return "var" in e || (e.var = "jsonxData" + Math.random().toString(16).slice(2)), t ? await q(R(t, e, !0)).then(() => {
122
125
  const r = n[e.var + ""];
123
126
  return a(r) ? r : (console.warn("response type check failed", t, r), null);
124
127
  }).catch(() => null) : null;
125
128
  }
126
- const P = async function(t, a, e) {
127
- return await j(t, a, e, {
129
+ const A = async function(t, a, e) {
130
+ return await k(t, a, e, {
128
131
  baseURL: c.getConfig("baseURL"),
129
132
  logHandler: c.getConfig("logHandler"),
130
133
  errorHandler: c.getConfig("errorHandler"),
@@ -133,25 +136,25 @@ const P = async function(t, a, e) {
133
136
  responseHandler: c.getConfig("responseHandler")
134
137
  });
135
138
  };
136
- function S(t) {
139
+ function U(t) {
137
140
  if (!E.window)
138
141
  throw new Error("Default Module Only Support In Browser");
139
- return E.fetch ? new H(C, t) : new H(L, t);
142
+ return E.fetch ? new H(L, t) : new H(j, t);
140
143
  }
141
- const c = S(), A = c.setConfig, M = c.request, N = c.head, B = c.get, X = c.post, F = c.del, G = c.put, I = c.patch;
144
+ const c = U(), M = c.setConfig, N = c.request, B = c.head, X = c.get, F = c.post, G = c.del, I = c.put, $ = c.patch;
142
145
  export {
143
- S as NetRequest,
144
- R as RequestInternalError,
145
- F as del,
146
- B as get,
147
- J as getResponseRulesDescription,
148
- N as head,
149
- D as jsonp,
150
- O as jsonx,
151
- I as patch,
152
- X as post,
153
- G as put,
154
- M as request,
155
- A as setGlobalConfig,
156
- P as upload
146
+ U as NetRequest,
147
+ m as RequestInternalError,
148
+ G as del,
149
+ X as get,
150
+ K as getResponseRulesDescription,
151
+ B as head,
152
+ O as jsonp,
153
+ P as jsonx,
154
+ $ as patch,
155
+ F as post,
156
+ I as put,
157
+ N as request,
158
+ M as setGlobalConfig,
159
+ A as upload
157
160
  };
package/dist/node.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./retry-8pExkGke.cjs"),y=require("./request.fetch-COXrFv2v.cjs"),b=require("node:http"),g=require("node:https"),E=async function(r,a,c){return e.handleResponse(await e.retryRequest(w,r,a,c),r,a,c)},w=async function(r,a,c){const t=await e.convertOptions(r,a,c);if(!e.At(t.url))return{url:t.url,method:t.method,status:-1,statusText:e.RequestInternalError.URLFormatError,headers:{},body:""};const R=/^https:\/\//i.test(t.url)?g:b,u=new URL(t.url),i=t.params;i instanceof Object&&Object.keys(i).forEach(n=>u.searchParams.set(n,i[n]));const q=t.method==="HEAD";return new Promise(n=>{const d=R.request(u,{headers:t.headers,method:t.method,timeout:t.timeout>0?t.timeout:void 0},function(o){const m=[];o.on("data",h=>m.push(h)),o.on("end",()=>{const h=e.fromEntries(Object.entries(o.headers).map(([f,l])=>[f.toLowerCase(),Array.isArray(l)?l.join(","):l]));n({url:u.toString(),method:t.method,status:o.statusCode||-1,statusText:o.statusMessage||e.RequestInternalError.Unknown,headers:h,body:q||o.statusCode===204?"":Buffer.concat(m).toString("utf-8")})})});d.on("error",o=>{n({url:u.toString(),method:t.method,status:-1,statusText:e.RequestInternalError.NetworkError,body:"",rawError:o})}),d.on("timeout",()=>{n({url:u.toString(),method:t.method,status:-1,statusText:e.RequestInternalError.Timeout,body:""})}),t.body&&d.write(t.body),d.end()})};function p(r){return e.jt.fetch?new e.NetRequestHandler(y.fetchRequest,r):new e.NetRequestHandler(E,r)}const s=p(),j=s.setConfig,C=s.head,I=s.get,N=s.post,S=s.del,T=s.put,O=s.patch;exports.RequestInternalError=e.RequestInternalError;exports.getResponseRulesDescription=e.getResponseRulesDescription;exports.NetRequest=p;exports.del=S;exports.get=I;exports.head=C;exports.patch=O;exports.post=N;exports.put=T;exports.setGlobalConfig=j;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./retry-8pExkGke.cjs"),y=require("./request.fetch-hlpQxV81.cjs"),b=require("node:http"),g=require("node:https"),E=async function(r,a,c){return e.handleResponse(await e.retryRequest(w,r,a,c),r,a,c)},w=async function(r,a,c){const t=await e.convertOptions(r,a,c);if(!e.At(t.url))return{url:t.url,method:t.method,status:-1,statusText:e.RequestInternalError.URLFormatError,headers:{},body:""};const R=/^https:\/\//i.test(t.url)?g:b,u=new URL(t.url),i=t.params;i instanceof Object&&Object.keys(i).forEach(n=>u.searchParams.set(n,i[n]));const q=t.method==="HEAD";return new Promise(n=>{const d=R.request(u,{headers:t.headers,method:t.method,timeout:t.timeout>0?t.timeout:void 0},function(o){const m=[];o.on("data",h=>m.push(h)),o.on("end",()=>{const h=e.fromEntries(Object.entries(o.headers).map(([f,l])=>[f.toLowerCase(),Array.isArray(l)?l.join(","):l]));n({url:u.toString(),method:t.method,status:o.statusCode||-1,statusText:o.statusMessage||e.RequestInternalError.Unknown,headers:h,body:q||o.statusCode===204?"":Buffer.concat(m).toString("utf-8")})})});d.on("error",o=>{n({url:u.toString(),method:t.method,status:-1,statusText:e.RequestInternalError.NetworkError,body:"",rawError:o})}),d.on("timeout",()=>{n({url:u.toString(),method:t.method,status:-1,statusText:e.RequestInternalError.Timeout,body:""})}),t.body&&d.write(t.body),d.end()})};function p(r){return e.jt.fetch?new e.NetRequestHandler(y.fetchRequest,r):new e.NetRequestHandler(E,r)}const s=p(),j=s.setConfig,C=s.head,I=s.get,N=s.post,S=s.del,T=s.put,O=s.patch;exports.RequestInternalError=e.RequestInternalError;exports.getResponseRulesDescription=e.getResponseRulesDescription;exports.NetRequest=p;exports.del=S;exports.get=I;exports.head=C;exports.patch=O;exports.post=N;exports.put=T;exports.setGlobalConfig=j;
package/dist/node.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { h as b, r as q, c as w, A as g, a as d, f as E, N as f, j } from "./retry-_AqXIa5P.js";
2
2
  import { d as J } from "./retry-_AqXIa5P.js";
3
- import { f as x } from "./request.fetch-Cuk4gO1S.js";
3
+ import { f as x } from "./request.fetch-1poQOlEV.js";
4
4
  import A from "node:http";
5
5
  import C from "node:https";
6
6
  const N = async function(o, a, u) {
@@ -1,15 +1,18 @@
1
- import { h as m, r as w, c as y, j as E, f as R, a as b } from "./retry-_AqXIa5P.js";
1
+ import { h as w, r as y, c as E, j as T, f as R, a as c } from "./retry-_AqXIa5P.js";
2
2
  const x = async function(s, o, n) {
3
- return m(await w(g, s, o, n), s, o, n);
3
+ return w(await y(g, s, o, n), s, o, n);
4
4
  }, g = async function(s, o, n) {
5
- const t = await y(s, o, n), i = new URL(t.url), c = t.params;
6
- c instanceof Object && Object.keys(c).forEach((e) => i.searchParams.set(e, c[e]));
7
- const r = E.AbortController ? new AbortController() : null;
5
+ const t = await E(s, o, n), i = new URL(t.url), u = t.params;
6
+ u instanceof Object && Object.keys(u).forEach((e) => i.searchParams.set(e, u[e]));
7
+ const r = T.AbortController ? new AbortController() : null;
8
8
  function d() {
9
9
  r && !r.signal.aborted && r.abort();
10
10
  }
11
11
  t.abort && t.abort.addEventListener("abort", d);
12
- const h = t.timeout > 0 ? setTimeout(d, t.timeout) : null, l = t.method === "HEAD";
12
+ let b = !1;
13
+ const l = t.timeout > 0 ? setTimeout(function() {
14
+ b = !0, d();
15
+ }, t.timeout) : null, f = t.method === "HEAD";
13
16
  return await fetch(i, {
14
17
  method: t.method,
15
18
  headers: Object.keys(t.headers).length > 0 ? new Headers(t.headers) : void 0,
@@ -24,21 +27,21 @@ const x = async function(s, o, n) {
24
27
  status: e.status,
25
28
  statusText: e.statusText,
26
29
  headers: R([...e.headers.entries()])
27
- }, u = l || e.status === 204 ? "" : await e.text().catch((f) => f);
28
- return u instanceof Error ? { ...a, body: "", statusText: b.Unknown, rawError: u } : { ...a, body: u };
30
+ }, h = f || e.status === 204 ? "" : await e.text().catch((m) => m);
31
+ return h instanceof Error ? { ...a, body: "", statusText: c.Unknown, rawError: h } : { ...a, body: h };
29
32
  }).catch((e) => {
30
33
  const a = r == null ? void 0 : r.signal.aborted;
31
34
  return {
32
35
  url: i.toString(),
33
36
  method: t.method,
34
- status: a ? 0 : -1,
37
+ status: a && !b ? 0 : -1,
35
38
  // 设置为 0 可以防止自动重试的默认策略
36
- statusText: a ? b.Aborted : b.NetworkError,
39
+ statusText: b ? c.Timeout : a ? c.Aborted : c.NetworkError,
37
40
  body: "",
38
41
  rawError: e
39
42
  };
40
43
  }).finally(() => {
41
- h !== null && clearTimeout(h), t.abort && t.abort.removeEventListener("abort", d);
44
+ l !== null && clearTimeout(l), t.abort && t.abort.removeEventListener("abort", d);
42
45
  });
43
46
  };
44
47
  export {
@@ -0,0 +1 @@
1
+ "use strict";const s=require("./retry-8pExkGke.cjs"),E=async function(n,a,i){return s.handleResponse(await s.retryRequest(w,n,a,i),n,a,i)},w=async function(n,a,i){const t=await s.convertOptions(n,a,i),u=new URL(t.url),c=t.params;c instanceof Object&&Object.keys(c).forEach(e=>u.searchParams.set(e,c[e]));const r=s.jt.AbortController?new AbortController:null;function d(){r&&!r.signal.aborted&&r.abort()}t.abort&&t.abort.addEventListener("abort",d);let l=!1;const h=t.timeout>0?setTimeout(function(){l=!0,d()},t.timeout):null,f=t.method==="HEAD";return await fetch(u,{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 o={url:u.toString(),method:t.method,status:e.status,statusText:e.statusText,headers:s.fromEntries([...e.headers.entries()])},b=f||e.status===204?"":await e.text().catch(m=>m);return b instanceof Error?{...o,body:"",statusText:s.RequestInternalError.Unknown,rawError:b}:{...o,body:b}}).catch(e=>{const o=r==null?void 0:r.signal.aborted;return{url:u.toString(),method:t.method,status:o&&!l?0:-1,statusText:l?s.RequestInternalError.Timeout:o?s.RequestInternalError.Aborted:s.RequestInternalError.NetworkError,body:"",rawError:e}}).finally(()=>{h!==null&&clearTimeout(h),t.abort&&t.abort.removeEventListener("abort",d)})};exports.fetchRequest=E;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seayoo-web/request",
3
- "version": "3.1.3",
3
+ "version": "3.1.5",
4
4
  "description": "request tools for seayoo web",
5
5
  "type": "module",
6
6
  "source": "./src/index.ts",
@@ -17,6 +17,7 @@ export declare const RequestInternalError: {
17
17
  /** url 格式错误 */
18
18
  readonly URLFormatError: "URLFormatError";
19
19
  };
20
+ export type RequestInternalError = (typeof RequestInternalError)[keyof typeof RequestInternalError];
20
21
  /** 通用网络请求工具的基本配置 */
21
22
  export interface IBaseRequestOptions {
22
23
  /** 网络请求方法,默认 GET */
@@ -44,7 +45,7 @@ export interface IBaseRequestOptions {
44
45
  }
45
46
  /** 重试请求的配置参数,暂不支持全局配置 */
46
47
  export interface IRetryRequestOptions {
47
- /** 错误时重试的次数,不能超过 10 */
48
+ /** 错误时重试的次数,不能超过 10 次,默认不重试 */
48
49
  maxRetry?: number;
49
50
  /** 重试策略:默认 network,可选 status 或者指定特殊的 status 或自定义检查 */
50
51
  retryResolve?: IRetryResolve;
@@ -1 +0,0 @@
1
- "use strict";const s=require("./retry-8pExkGke.cjs"),m=async function(a,n,i){return s.handleResponse(await s.retryRequest(w,a,n,i),a,n,i)},w=async function(a,n,i){const t=await s.convertOptions(a,n,i),c=new URL(t.url),u=t.params;u instanceof Object&&Object.keys(u).forEach(e=>c.searchParams.set(e,u[e]));const r=s.jt.AbortController?new AbortController:null;function d(){r&&!r.signal.aborted&&r.abort()}t.abort&&t.abort.addEventListener("abort",d);const h=t.timeout>0?setTimeout(d,t.timeout):null,l=t.method==="HEAD";return await fetch(c,{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 o={url:c.toString(),method:t.method,status:e.status,statusText:e.statusText,headers:s.fromEntries([...e.headers.entries()])},b=l||e.status===204?"":await e.text().catch(f=>f);return b instanceof Error?{...o,body:"",statusText:s.RequestInternalError.Unknown,rawError:b}:{...o,body:b}}).catch(e=>{const o=r==null?void 0:r.signal.aborted;return{url:c.toString(),method:t.method,status:o?0:-1,statusText:o?s.RequestInternalError.Aborted:s.RequestInternalError.NetworkError,body:"",rawError:e}}).finally(()=>{h!==null&&clearTimeout(h),t.abort&&t.abort.removeEventListener("abort",d)})};exports.fetchRequest=m;