@seayoo-web/request 1.5.6 → 1.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,8 @@
1
+ export declare const Support: {
2
+ fetch: boolean;
3
+ window: boolean;
4
+ FormData: boolean;
5
+ Blob: boolean;
6
+ wx: boolean;
7
+ TextDecoder: boolean;
8
+ };
@@ -15,8 +15,9 @@ export declare const xhRequest: NetRequestAgent;
15
15
  /**
16
16
  * 上传文件,支持进度信息和多文件上传,不抛错,限制在浏览器中使用,不支持重试
17
17
  */
18
- export declare function xhrUpload(url: string, files: Record<string, Blob>, options?: Omit<IRequestOptions, keyof XHRequestOptions | keyof IRetryRequestOptions> & Omit<XHRequestOptions, "body"> & {
18
+ export declare function xhrUpload(url: string, files: Record<string, Blob> | Blob, options?: Omit<IRequestOptions, keyof XHRequestOptions | keyof IRetryRequestOptions> & Omit<XHRequestOptions, "body" | "method"> & {
19
19
  body?: Record<string, unknown>;
20
+ method?: "POST" | "PUT";
20
21
  },
21
22
  /** 全局配置中独有的配置,以受全局配置控制 */
22
23
  config?: Omit<IRequestGlobalConfig, keyof IRequestOptions>): Promise<IResponseResult>;
package/dist/index.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("./version-nbk4F2gf.cjs"),H=async function(n,o,t){const e=await c.convertOptions(n,o,t),r=new URL(e.url),i=e.params;i instanceof Object&&Object.keys(i).forEach(a=>r.searchParams.set(a,i[a]));const s=new AbortController;function l(){s.signal.aborted||s.abort()}e.abort&&e.abort.addEventListener("abort",l);const b=e.timeout>0?setTimeout(l,e.timeout):null,f=new Request(r,{method:e.method,headers:new Headers(e.headers),body:e.body,credentials:e.credentials,signal:s.signal,redirect:"follow"});return await fetch(f).then(async a=>({url:r.toString(),method:e.method,status:a.status,statusText:a.statusText,headers:Object.fromEntries(a.headers.entries()),body:e.method==="HEAD"?"":await a.text()})).catch(a=>({url:r.toString(),method:e.method,status:-1,statusText:s.signal.aborted?"Aborted":"NetworkError",body:String(a)})).finally(()=>{b!==null&&clearTimeout(b),e.abort&&e.abort.removeEventListener("abort",l)})},m=async function(n,o,t){const e={...await c.convertOptions(n,o,t),onUploadProgress:t==null?void 0:t.onUploadProgress},r=e.method,i=e.onUploadProgress||c.Lt,s=c.Ct(e.url,e.params);return await new Promise(l=>{let b=1;function f(g){b=g.total,i({total:g.total,loaded:g.loaded})}let a=null,p=!1;const h=function(){p||(d.abort(),p=!0)};function w(){a!==null&&clearTimeout(a),e.abort&&e.abort.removeEventListener("abort",h)}const d=new XMLHttpRequest;d.open(r,s,!0),d.upload.addEventListener("progress",f),d.addEventListener("load",()=>{w(),i({loaded:b,total:b}),l({url:s,method:r,status:d.status,statusText:d.statusText,headers:T(d),body:r==="HEAD"?"":d.responseText})}),d.addEventListener("error",()=>{w(),l({url:s,method:r,status:-1,statusText:"Failed",body:""})}),d.addEventListener("abort",()=>{w(),l({url:s,method:r,status:-1,statusText:"Aborted",body:""})}),Object.entries(e.headers).forEach(([g,R])=>{d.setRequestHeader(g,R)}),e.credentials==="include"&&(d.withCredentials=!0),d.send(e.body||void 0),e.abort&&e.abort.addEventListener("abort",h),e.timeout>0&&(a=setTimeout(h,e.timeout))})};function T(n){const o={};if(!n)return o;const t=n.getAllResponseHeaders();return t&&t!=="null"&&t.replace(/\r/g,"").split(`
2
- `).forEach(e=>{const r=e.trim();if(!r)return;const i=r.split(":"),s=i[0].trim();s&&(o[s]=(i[1]||"").trim())}),o}const q=async function(n,o,t){return c.handleResponse(await c.retryRequest(H,n,o,t),n,o,t)},E=async function(n,o,t){return c.handleResponse(await c.retryRequest(m,n,o,t),n,o,t)};async function x(n,o,t,e){const r=new FormData,i=t==null?void 0:t.body,s={...o};i instanceof Object&&Object.entries(i).forEach(([f,a])=>{a instanceof Blob?s[f]=a:Array.isArray(a)?a.forEach((p,h)=>{r.append(`${f}[${h}]`,String(p))}):r.append(f,String(a))});for(const f in s)r.append(f,s[f]);const l=new c.RequestGlobalConfig(e),b=await m(n,l,{...t,method:"POST",body:r});return c.handleResponse(b,n,l,t)}async function C(n,o,t={}){const e=window;"callback"in t||(t.callback="jsonxData"+Math.random().toString(16).slice(2));const r=t.callback+"";if(!n)return null;const i=c.Ct(n,t,!0);return new Promise(s=>{e[r]=function(l){if(r in window&&delete e[r],o(l))return l;console.warn("response type check faild",n,l),s(null)},c.on(i).catch(function(){s(null),delete e[r]})})}async function v(n,o,t={}){const e=window;return"var"in t||(t.var="jsonxData"+Math.random().toString(16).slice(2)),n?await c.on(c.Ct(n,t,!0)).then(()=>{const r=e[t.var+""];return o(r)?r:(console.warn("response type check faild",n,r),null)}).catch(()=>null):null}const L=async function(n,o,t){return await x(n,o,t,{baseURL:u.getConfig("baseURL"),logHandler:u.getConfig("logHandler"),errorHandler:u.getConfig("errorHandler"),requestTransformer:u.getConfig("requestTransformer"),messageHandler:u.getConfig("messageHandler"),responseHandler:u.getConfig("responseHandler")})};function y(n){if("window"in globalThis)return"fetch"in window?new c.NetRequestHandler(q,n):new c.NetRequestHandler(E,n);throw new Error("Default Module Only Support In Browser")}const u=y(),j=u.setConfig,S=u.head,O=u.get,U=u.post,D=u.del,k=u.put,A=u.patch;exports.getResponseRulesDescription=c.getResponseRulesDescription;exports.version=c.version;exports.NetRequest=y;exports.del=D;exports.get=O;exports.head=S;exports.jsonp=C;exports.jsonx=v;exports.patch=A;exports.post=U;exports.put=k;exports.setGlobalConfig=j;exports.upload=L;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("./version-yl6932gU.cjs"),E=async function(n,o,t){const e=await a.convertOptions(n,o,t),r=new URL(e.url),i=e.params;i instanceof Object&&Object.keys(i).forEach(s=>r.searchParams.set(s,i[s]));const c=new AbortController;function l(){c.signal.aborted||c.abort()}e.abort&&e.abort.addEventListener("abort",l);const b=e.timeout>0?setTimeout(l,e.timeout):null,h=new Request(r,{method:e.method,headers:new Headers(e.headers),body:e.body,credentials:e.credentials,signal:c.signal,redirect:"follow"});return await fetch(h).then(async s=>({url:r.toString(),method:e.method,status:s.status,statusText:s.statusText,headers:Object.fromEntries(s.headers.entries()),body:e.method==="HEAD"?"":await s.text()})).catch(s=>({url:r.toString(),method:e.method,status:-1,statusText:c.signal.aborted?"Aborted":"NetworkError",body:String(s)})).finally(()=>{b!==null&&clearTimeout(b),e.abort&&e.abort.removeEventListener("abort",l)})},p=async function(n,o,t){const e={...await a.convertOptions(n,o,t),onUploadProgress:t==null?void 0:t.onUploadProgress},r=e.method,i=e.onUploadProgress||a.Vt,c=a.Et(e.url,e.params);return await new Promise(l=>{let b=1;function h(m){b=m.total,i({total:m.total,loaded:m.loaded})}let s=null,f=!1;const g=function(){f||(d.abort(),f=!0)};function w(){s!==null&&clearTimeout(s),e.abort&&e.abort.removeEventListener("abort",g)}const d=new XMLHttpRequest;d.open(r,c,!0),d.upload.addEventListener("progress",h),d.addEventListener("load",()=>{w(),i({loaded:b,total:b}),l({url:c,method:r,status:d.status,statusText:d.statusText,headers:T(d),body:r==="HEAD"?"":d.responseText})}),d.addEventListener("error",()=>{w(),l({url:c,method:r,status:-1,statusText:"Failed",body:""})}),d.addEventListener("abort",()=>{w(),l({url:c,method:r,status:-1,statusText:"Aborted",body:""})}),Object.entries(e.headers).forEach(([m,R])=>{d.setRequestHeader(m,R)}),e.credentials==="include"&&(d.withCredentials=!0),d.send(e.body||void 0),e.abort&&e.abort.addEventListener("abort",g),e.timeout>0&&(s=setTimeout(g,e.timeout))})};function T(n){const o={};if(!n)return o;const t=n.getAllResponseHeaders();return t&&t!=="null"&&t.replace(/\r/g,"").split(`
2
+ `).forEach(e=>{const r=e.trim();if(!r)return;const i=r.split(":"),c=i[0].trim();c&&(o[c]=(i[1]||"").trim())}),o}const q=async function(n,o,t){return a.handleResponse(await a.retryRequest(E,n,o,t),n,o,t)},H=async function(n,o,t){return a.handleResponse(await a.retryRequest(p,n,o,t),n,o,t)};async function x(n,o,t,e){const r=t==null?void 0:t.body,i=(t==null?void 0:t.method)==="PUT"?"PUT":"POST";if(o instanceof Blob){const s=new a.RequestGlobalConfig(e),f=await p(n,s,{...t,method:i,body:o});return a.handleResponse(f,n,s,t)}const c=new FormData,l={...o};r instanceof Object&&Object.entries(r).forEach(([s,f])=>{f instanceof Blob?l[s]=f:Array.isArray(f)?f.forEach((g,w)=>{c.append(`${s}[${w}]`,String(g))}):c.append(s,String(f))});for(const s in l)c.append(s,l[s]);const b=new a.RequestGlobalConfig(e),h=await p(n,b,{...t,method:i,body:c});return a.handleResponse(h,n,b,t)}async function S(n,o,t={}){const e=window;"callback"in t||(t.callback="jsonxData"+Math.random().toString(16).slice(2));const r=t.callback+"";if(!n)return null;const i=a.Et(n,t,!0);return new Promise(c=>{e[r]=function(l){if(r in window&&delete e[r],o(l))return l;console.warn("response type check faild",n,l),c(null)},a.he(i).catch(function(){c(null),delete e[r]})})}async function v(n,o,t={}){const e=window;return"var"in t||(t.var="jsonxData"+Math.random().toString(16).slice(2)),n?await a.he(a.Et(n,t,!0)).then(()=>{const r=e[t.var+""];return o(r)?r:(console.warn("response type check faild",n,r),null)}).catch(()=>null):null}const j=async function(n,o,t){return await x(n,o,t,{baseURL:u.getConfig("baseURL"),logHandler:u.getConfig("logHandler"),errorHandler:u.getConfig("errorHandler"),requestTransformer:u.getConfig("requestTransformer"),messageHandler:u.getConfig("messageHandler"),responseHandler:u.getConfig("responseHandler")})};function y(n){if(!a.Support.window)throw new Error("Default Module Only Support In Browser");return a.Support.fetch?new a.NetRequestHandler(q,n):new a.NetRequestHandler(H,n)}const u=y(),C=u.setConfig,L=u.head,U=u.get,O=u.post,P=u.del,D=u.put,k=u.patch;exports.getResponseRulesDescription=a.getResponseRulesDescription;exports.version=a.version;exports.NetRequest=y;exports.del=P;exports.get=U;exports.head=L;exports.jsonp=S;exports.jsonx=v;exports.patch=k;exports.post=O;exports.put=D;exports.setGlobalConfig=C;exports.upload=j;
package/dist/index.js CHANGED
@@ -1,83 +1,83 @@
1
- import { c as R, C as w, L, h as p, r as E, R as q, o as H, N as y } from "./version-DCu7OI8o.js";
2
- import { g as J, v as K } from "./version-DCu7OI8o.js";
3
- const C = async function(n, o, e) {
4
- const t = await R(n, o, e), r = new URL(t.url), c = t.params;
5
- c instanceof Object && Object.keys(c).forEach((s) => r.searchParams.set(s, c[s]));
6
- const a = new AbortController();
7
- function i() {
8
- a.signal.aborted || a.abort();
1
+ import { c as H, E as p, V as S, h as w, r as x, R, a as q, S as E, N as T } from "./version-D5ZPd9sj.js";
2
+ import { g as J, v as K } from "./version-D5ZPd9sj.js";
3
+ const U = async function(n, o, e) {
4
+ const t = await H(n, o, e), r = new URL(t.url), l = t.params;
5
+ l instanceof Object && Object.keys(l).forEach((a) => r.searchParams.set(a, l[a]));
6
+ const s = new AbortController();
7
+ function c() {
8
+ s.signal.aborted || s.abort();
9
9
  }
10
- t.abort && t.abort.addEventListener("abort", i);
11
- const f = t.timeout > 0 ? setTimeout(i, t.timeout) : null, u = new Request(r, {
10
+ t.abort && t.abort.addEventListener("abort", c);
11
+ const f = t.timeout > 0 ? setTimeout(c, t.timeout) : null, b = new Request(r, {
12
12
  method: t.method,
13
13
  headers: new Headers(t.headers),
14
14
  body: t.body,
15
15
  credentials: t.credentials,
16
- signal: a.signal,
16
+ signal: s.signal,
17
17
  redirect: "follow"
18
18
  });
19
- return await fetch(u).then(async (s) => ({
19
+ return await fetch(b).then(async (a) => ({
20
20
  url: r.toString(),
21
21
  method: t.method,
22
- status: s.status,
23
- statusText: s.statusText,
24
- headers: Object.fromEntries(s.headers.entries()),
25
- body: t.method === "HEAD" ? "" : await s.text()
26
- })).catch((s) => ({
22
+ status: a.status,
23
+ statusText: a.statusText,
24
+ headers: Object.fromEntries(a.headers.entries()),
25
+ body: t.method === "HEAD" ? "" : await a.text()
26
+ })).catch((a) => ({
27
27
  url: r.toString(),
28
28
  method: t.method,
29
29
  status: -1,
30
- statusText: a.signal.aborted ? "Aborted" : "NetworkError",
31
- body: String(s)
30
+ statusText: s.signal.aborted ? "Aborted" : "NetworkError",
31
+ body: String(a)
32
32
  })).finally(() => {
33
- f !== null && clearTimeout(f), t.abort && t.abort.removeEventListener("abort", i);
33
+ f !== null && clearTimeout(f), t.abort && t.abort.removeEventListener("abort", c);
34
34
  });
35
- }, T = async function(n, o, e) {
35
+ }, y = async function(n, o, e) {
36
36
  const t = {
37
- ...await R(n, o, e),
37
+ ...await H(n, o, e),
38
38
  onUploadProgress: e == null ? void 0 : e.onUploadProgress
39
- }, r = t.method, c = t.onUploadProgress || L, a = w(t.url, t.params);
40
- return await new Promise((i) => {
39
+ }, r = t.method, l = t.onUploadProgress || S, s = p(t.url, t.params);
40
+ return await new Promise((c) => {
41
41
  let f = 1;
42
- function u(h) {
43
- f = h.total, c({ total: h.total, loaded: h.loaded });
42
+ function b(m) {
43
+ f = m.total, l({ total: m.total, loaded: m.loaded });
44
44
  }
45
- let s = null, g = !1;
46
- const b = function() {
47
- g || (l.abort(), g = !0);
45
+ let a = null, u = !1;
46
+ const h = function() {
47
+ u || (i.abort(), u = !0);
48
48
  };
49
- function m() {
50
- s !== null && clearTimeout(s), t.abort && t.abort.removeEventListener("abort", b);
49
+ function g() {
50
+ a !== null && clearTimeout(a), t.abort && t.abort.removeEventListener("abort", h);
51
51
  }
52
- const l = new XMLHttpRequest();
53
- l.open(r, a, !0), l.upload.addEventListener("progress", u), l.addEventListener("load", () => {
54
- m(), c({ loaded: f, total: f }), i({
55
- url: a,
52
+ const i = new XMLHttpRequest();
53
+ i.open(r, s, !0), i.upload.addEventListener("progress", b), i.addEventListener("load", () => {
54
+ g(), l({ loaded: f, total: f }), c({
55
+ url: s,
56
56
  method: r,
57
- status: l.status,
58
- statusText: l.statusText,
59
- headers: v(l),
60
- body: r === "HEAD" ? "" : l.responseText
57
+ status: i.status,
58
+ statusText: i.statusText,
59
+ headers: v(i),
60
+ body: r === "HEAD" ? "" : i.responseText
61
61
  });
62
- }), l.addEventListener("error", () => {
63
- m(), i({
64
- url: a,
62
+ }), i.addEventListener("error", () => {
63
+ g(), c({
64
+ url: s,
65
65
  method: r,
66
66
  status: -1,
67
67
  statusText: "Failed",
68
68
  body: ""
69
69
  });
70
- }), l.addEventListener("abort", () => {
71
- m(), i({
72
- url: a,
70
+ }), i.addEventListener("abort", () => {
71
+ g(), c({
72
+ url: s,
73
73
  method: r,
74
74
  status: -1,
75
75
  statusText: "Aborted",
76
76
  body: ""
77
77
  });
78
- }), Object.entries(t.headers).forEach(([h, x]) => {
79
- l.setRequestHeader(h, x);
80
- }), t.credentials === "include" && (l.withCredentials = !0), l.send(t.body || void 0), t.abort && t.abort.addEventListener("abort", b), t.timeout > 0 && (s = setTimeout(b, t.timeout));
78
+ }), Object.entries(t.headers).forEach(([m, L]) => {
79
+ i.setRequestHeader(m, L);
80
+ }), t.credentials === "include" && (i.withCredentials = !0), i.send(t.body || void 0), t.abort && t.abort.addEventListener("abort", h), t.timeout > 0 && (a = setTimeout(h, t.timeout));
81
81
  });
82
82
  };
83
83
  function v(n) {
@@ -90,30 +90,39 @@ function v(n) {
90
90
  const r = t.trim();
91
91
  if (!r)
92
92
  return;
93
- const c = r.split(":"), a = c[0].trim();
94
- a && (o[a] = (c[1] || "").trim());
93
+ const l = r.split(":"), s = l[0].trim();
94
+ s && (o[s] = (l[1] || "").trim());
95
95
  }), o;
96
96
  }
97
- const S = async function(n, o, e) {
98
- return p(await E(C, n, o, e), n, o, e);
97
+ const C = async function(n, o, e) {
98
+ return w(await x(U, n, o, e), n, o, e);
99
99
  }, j = async function(n, o, e) {
100
- return p(await E(T, n, o, e), n, o, e);
100
+ return w(await x(y, n, o, e), n, o, e);
101
101
  };
102
- async function U(n, o, e, t) {
103
- const r = new FormData(), c = e == null ? void 0 : e.body, a = { ...o };
104
- c instanceof Object && Object.entries(c).forEach(([u, s]) => {
105
- s instanceof Blob ? a[u] = s : Array.isArray(s) ? s.forEach((g, b) => {
106
- r.append(`${u}[${b}]`, String(g));
107
- }) : r.append(u, String(s));
102
+ async function O(n, o, e, t) {
103
+ const r = e == null ? void 0 : e.body, l = (e == null ? void 0 : e.method) === "PUT" ? "PUT" : "POST";
104
+ if (o instanceof Blob) {
105
+ const a = new R(t), u = await y(n, a, {
106
+ ...e,
107
+ method: l,
108
+ body: o
109
+ });
110
+ return w(u, n, a, e);
111
+ }
112
+ const s = new FormData(), c = { ...o };
113
+ r instanceof Object && Object.entries(r).forEach(([a, u]) => {
114
+ u instanceof Blob ? c[a] = u : Array.isArray(u) ? u.forEach((h, g) => {
115
+ s.append(`${a}[${g}]`, String(h));
116
+ }) : s.append(a, String(u));
108
117
  });
109
- for (const u in a)
110
- r.append(u, a[u]);
111
- const i = new q(t), f = await T(n, i, {
118
+ for (const a in c)
119
+ s.append(a, c[a]);
120
+ const f = new R(t), b = await y(n, f, {
112
121
  ...e,
113
- method: "POST",
114
- body: r
122
+ method: l,
123
+ body: s
115
124
  });
116
- return p(f, n, i, e);
125
+ return w(b, n, f, e);
117
126
  }
118
127
  async function A(n, o, e = {}) {
119
128
  const t = window;
@@ -121,26 +130,26 @@ async function A(n, o, e = {}) {
121
130
  const r = e.callback + "";
122
131
  if (!n)
123
132
  return null;
124
- const c = w(n, e, !0);
125
- return new Promise((a) => {
126
- t[r] = function(i) {
127
- if (r in window && delete t[r], o(i))
128
- return i;
129
- console.warn("response type check faild", n, i), a(null);
130
- }, H(c).catch(function() {
131
- a(null), delete t[r];
133
+ const l = p(n, e, !0);
134
+ return new Promise((s) => {
135
+ t[r] = function(c) {
136
+ if (r in window && delete t[r], o(c))
137
+ return c;
138
+ console.warn("response type check faild", n, c), s(null);
139
+ }, q(l).catch(function() {
140
+ s(null), delete t[r];
132
141
  });
133
142
  });
134
143
  }
135
144
  async function D(n, o, e = {}) {
136
145
  const t = window;
137
- return "var" in e || (e.var = "jsonxData" + Math.random().toString(16).slice(2)), n ? await H(w(n, e, !0)).then(() => {
146
+ return "var" in e || (e.var = "jsonxData" + Math.random().toString(16).slice(2)), n ? await q(p(n, e, !0)).then(() => {
138
147
  const r = t[e.var + ""];
139
148
  return o(r) ? r : (console.warn("response type check faild", n, r), null);
140
149
  }).catch(() => null) : null;
141
150
  }
142
- const P = async function(n, o, e) {
143
- return await U(n, o, e, {
151
+ const M = async function(n, o, e) {
152
+ return await O(n, o, e, {
144
153
  baseURL: d.getConfig("baseURL"),
145
154
  logHandler: d.getConfig("logHandler"),
146
155
  errorHandler: d.getConfig("errorHandler"),
@@ -149,24 +158,24 @@ const P = async function(n, o, e) {
149
158
  responseHandler: d.getConfig("responseHandler")
150
159
  });
151
160
  };
152
- function O(n) {
153
- if ("window" in globalThis)
154
- return "fetch" in window ? new y(S, n) : new y(j, n);
155
- throw new Error("Default Module Only Support In Browser");
161
+ function P(n) {
162
+ if (!E.window)
163
+ throw new Error("Default Module Only Support In Browser");
164
+ return E.fetch ? new T(C, n) : new T(j, n);
156
165
  }
157
- const d = O(), M = d.setConfig, N = d.head, F = d.get, X = d.post, B = d.del, G = d.put, I = d.patch;
166
+ const d = P(), N = d.setConfig, F = d.head, B = d.get, X = d.post, G = d.del, I = d.put, V = d.patch;
158
167
  export {
159
- O as NetRequest,
160
- B as del,
161
- F as get,
168
+ P as NetRequest,
169
+ G as del,
170
+ B as get,
162
171
  J as getResponseRulesDescription,
163
- N as head,
172
+ F as head,
164
173
  A as jsonp,
165
174
  D as jsonx,
166
- I as patch,
175
+ V as patch,
167
176
  X as post,
168
- G as put,
169
- M as setGlobalConfig,
170
- P as upload,
177
+ I as put,
178
+ N as setGlobalConfig,
179
+ M as upload,
171
180
  K as version
172
181
  };
package/dist/node.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const y=require("node:http"),q=require("node:https"),r=require("./version-nbk4F2gf.cjs"),R=async function(s,u,c){return r.handleResponse(await r.retryRequest(w,s,u,c),s,u,c)},w=async function(s,u,c){const t=await r.convertOptions(s,u,c);if(!r.R(t.url))return{url:t.url,method:t.method,status:-1,statusText:"URLFormatError",headers:{},body:""};const b=/^https:\/\//i.test(t.url)?q: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=b.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=Object.fromEntries(Object.entries(e.headers).map(([g,m])=>[g.toLowerCase(),Array.isArray(m)?m.join(","):m]));n({url:a.toString(),method:t.method,status:e.statusCode||-1,statusText:e.statusMessage||"Unknown",headers:h,body:f?"":Buffer.concat(p).toString("utf-8")})})});d.on("error",e=>{n({url:a.toString(),method:t.method,status:-1,statusText:e.name||"Unknown",body:e.message})}),d.on("timeout",()=>{n({url:a.toString(),method:t.method,status:-1,statusText:"Timeout",body:""})}),t.body&&d.write(t.body),d.end()})};function l(s){return new r.NetRequestHandler(R,s)}const o=l(),j=o.setConfig,O=o.head,S=o.get,T=o.post,C=o.del,U=o.put,x=o.patch;exports.version=r.version;exports.NetRequest=l;exports.del=C;exports.get=S;exports.head=O;exports.patch=x;exports.post=T;exports.put=U;exports.setGlobalConfig=j;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const y=require("node:http"),q=require("node:https"),r=require("./version-yl6932gU.cjs"),R=async function(s,u,c){return r.handleResponse(await r.retryRequest(w,s,u,c),s,u,c)},w=async function(s,u,c){const t=await r.convertOptions(s,u,c);if(!r.U(t.url))return{url:t.url,method:t.method,status:-1,statusText:"URLFormatError",headers:{},body:""};const b=/^https:\/\//i.test(t.url)?q: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=b.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=Object.fromEntries(Object.entries(e.headers).map(([g,m])=>[g.toLowerCase(),Array.isArray(m)?m.join(","):m]));n({url:a.toString(),method:t.method,status:e.statusCode||-1,statusText:e.statusMessage||"Unknown",headers:h,body:f?"":Buffer.concat(p).toString("utf-8")})})});d.on("error",e=>{n({url:a.toString(),method:t.method,status:-1,statusText:e.name||"Unknown",body:e.message})}),d.on("timeout",()=>{n({url:a.toString(),method:t.method,status:-1,statusText:"Timeout",body:""})}),t.body&&d.write(t.body),d.end()})};function l(s){return new r.NetRequestHandler(R,s)}const o=l(),j=o.setConfig,O=o.head,S=o.get,T=o.post,U=o.del,C=o.put,x=o.patch;exports.version=r.version;exports.NetRequest=l;exports.del=U;exports.get=S;exports.head=O;exports.patch=x;exports.post=T;exports.put=C;exports.setGlobalConfig=j;
package/dist/node.js CHANGED
@@ -1,10 +1,10 @@
1
1
  import l from "node:http";
2
2
  import y from "node:https";
3
- import { h as R, r as g, c as q, a as w, N as x } from "./version-DCu7OI8o.js";
4
- import { v as F } from "./version-DCu7OI8o.js";
5
- const j = async function(s, a, u) {
6
- return R(await g(O, s, a, u), s, a, u);
7
- }, O = async function(s, a, u) {
3
+ import { h as R, r as g, c as q, U as w, N as x } from "./version-D5ZPd9sj.js";
4
+ import { v as F } from "./version-D5ZPd9sj.js";
5
+ const U = async function(s, a, u) {
6
+ return R(await g(j, s, a, u), s, a, u);
7
+ }, j = async function(s, a, u) {
8
8
  const t = await q(s, a, u);
9
9
  if (!w(t.url))
10
10
  return {
@@ -62,12 +62,12 @@ const j = async function(s, a, u) {
62
62
  }), t.body && c.write(t.body), c.end();
63
63
  });
64
64
  };
65
- function T(s) {
66
- return new x(j, s);
65
+ function O(s) {
66
+ return new x(U, s);
67
67
  }
68
- const o = T(), L = o.setConfig, N = o.head, S = o.get, A = o.post, H = o.del, k = o.put, P = o.patch;
68
+ const o = O(), L = o.setConfig, N = o.head, S = o.get, A = o.post, H = o.del, k = o.put, P = o.patch;
69
69
  export {
70
- T as NetRequest,
70
+ O as NetRequest,
71
71
  H as del,
72
72
  S as get,
73
73
  N as head,