@seayoo-web/request 1.7.0 → 1.7.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.
package/README.md CHANGED
@@ -321,7 +321,7 @@ status 表示网络错误或者http 状态码错误时重试;
321
321
 
322
322
  - 当请求结束时无效;
323
323
  - 仅浏览器环境有效,
324
- - 不支持 AbortSignal 的浏览器可以引入 https://www.npmjs.com/package/abortcontroller-polyfill
324
+ - 不支持 AbortSignal 的浏览器可以引入 https://www.npmjs.com/package/abortcontroller-polyfill 或 https://polyfill.io/v3/polyfill.min.js?features=AbortController
325
325
 
326
326
  ### message
327
327
 
@@ -0,0 +1,7 @@
1
+ import type { NetRequestAgent } from "./type";
2
+ /**
3
+ * 基于 fetch 的网络请求包装函数,文件上传不支持进度,需要进度请使用 upload 方法
4
+ *
5
+ * 在浏览器或支持 fetch 的 Node 环境均可以使用
6
+ */
7
+ export declare const fetchRequest: NetRequestAgent;
@@ -1,11 +1,11 @@
1
- import { type XHRequestOptions } from "./core.xhr";
2
- import type { NetRequestAgent, IRequestGlobalConfig, IRequestOptions, IResponseResult, IRetryRequestOptions } from "./type";
3
- /**
4
- * 基于 fetch 的网络请求包装函数,文件上传不支持进度,需要进度请使用 upload 方法
5
- *
6
- * 该方法必定 resolve,限制在浏览器环境中使用
7
- */
8
- export declare const fetchRequest: NetRequestAgent;
1
+ import type { NetRequestAgent, IRequestGlobalConfig, IRequestOptions, IResponseResult, IRetryRequestOptions, IBaseRequestOptions } from "./type";
2
+ /** 进度回调函数配置 */
3
+ interface XHRequestOptions extends IBaseRequestOptions {
4
+ onUploadProgress?: (progress: {
5
+ total: number;
6
+ loaded: number;
7
+ }) => void;
8
+ }
9
9
  /**
10
10
  * 基于 xmlHttpRequest 的网络请求包装函数
11
11
  *
@@ -21,3 +21,4 @@ export declare function xhrUpload(url: string, files: Record<string, Blob> | Blo
21
21
  },
22
22
  /** 全局配置中独有的配置,以受全局配置控制 */
23
23
  config?: Omit<IRequestGlobalConfig, keyof IRequestOptions>): Promise<IResponseResult>;
24
+ export {};
package/dist/index.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("./version-CCXW7_VI.cjs"),y=async function(n,s,t){const e=await c.convertOptions(n,s,t),r=new URL(e.url),i=e.params;i instanceof Object&&Object.keys(i).forEach(a=>r.searchParams.set(a,i[a]));const o=c.Support.AbortController?new AbortController:null;function l(){o&&!o.signal.aborted&&o.abort()}e.abort&&e.abort.addEventListener("abort",l);const b=e.timeout>0?setTimeout(l,e.timeout):null,g=new Request(r,{method:e.method,headers:Object.keys(e.headers).length>0?new Headers(e.headers):void 0,body:e.body,credentials:e.credentials,signal:o==null?void 0:o.signal,redirect:"follow"});return await fetch(g).then(async a=>({url:r.toString(),method:e.method,status:a.status,statusText:a.statusText,headers:c.fromEntries([...a.headers.entries()]),body:e.method==="HEAD"?"":await a.text()})).catch(a=>({url:r.toString(),method:e.method,status:-1,statusText:o!=null&&o.signal.aborted?"Aborted":"NetworkError",body:String(a)})).finally(()=>{b!==null&&clearTimeout(b),e.abort&&e.abort.removeEventListener("abort",l)})},m=async function(n,s,t){const e=await c.convertOptions(n,s,t),r=e.method,i=t==null?void 0:t.onUploadProgress,o=c.Ut(e.url,e.params);return await new Promise(l=>{let b=null,g=!1;const a=function(){g||(d.abort(),g=!0)};function f(){b!==null&&clearTimeout(b),e.abort&&e.abort.removeEventListener("abort",a)}const d=new XMLHttpRequest;if(d.open(r,o,!0),i){let h=1;d.upload.addEventListener("progress",w=>{h=w.total,i({total:w.total,loaded:w.loaded})}),d.addEventListener("load",()=>{f(),i({loaded:h,total:h}),l({url:o,method:r,status:d.status,statusText:d.statusText,headers:R(d),body:r==="HEAD"?"":d.responseText})})}d.addEventListener("error",()=>{f(),l({url:o,method:r,status:-1,statusText:"Failed",body:""})}),d.addEventListener("abort",()=>{f(),l({url:o,method:r,status:-1,statusText:"Aborted",body:""})}),Object.entries(e.headers).forEach(([h,w])=>{d.setRequestHeader(h,w)}),e.credentials==="include"&&(d.withCredentials=!0),d.send(e.body||void 0),e.abort&&e.abort.addEventListener("abort",a),e.timeout>0&&(b=setTimeout(a,e.timeout))})};function R(n){const s={};if(!n)return s;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(":"),o=i[0].trim();o&&(s[o]=(i[1]||"").trim())}),s}const T=async function(n,s,t){return c.handleResponse(await c.retryRequest(y,n,s,t),n,s,t)},q=async function(n,s,t){return c.handleResponse(await c.retryRequest(m,n,s,t),n,s,t)};async function H(n,s,t,e){const r=t==null?void 0:t.body,i=(t==null?void 0:t.method)==="PUT"?"PUT":"POST";if(s instanceof Blob){const a=new c.RequestGlobalConfig(e),f=await m(n,a,{...t,method:i,body:s});return c.handleResponse(f,n,a,t)}const o=new FormData,l={...s};r instanceof Object&&Object.entries(r).forEach(([a,f])=>{f instanceof Blob?l[a]=f:Array.isArray(f)?f.forEach((d,h)=>{o.append(`${a}[${h}]`,String(d))}):o.append(a,String(f))});for(const a in l)o.append(a,l[a]);const b=new c.RequestGlobalConfig(e),g=await m(n,b,{...t,method:i,body:o});return c.handleResponse(g,n,b,t)}async function E(n,s,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.Ut(n,t,!0);return new Promise(o=>{e[r]=function(l){if(r in window&&delete e[r],s(l))return l;console.warn("response type check faild",n,l),o(null)},c.Ae(i).catch(function(){o(null),delete e[r]})})}async function S(n,s,t={}){const e=window;return"var"in t||(t.var="jsonxData"+Math.random().toString(16).slice(2)),n?await c.Ae(c.Ut(n,t,!0)).then(()=>{const r=e[t.var+""];return s(r)?r:(console.warn("response type check faild",n,r),null)}).catch(()=>null):null}const v=async function(n,s,t){return await H(n,s,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 p(n){if(!c.Support.window)throw new Error("Default Module Only Support In Browser");return c.Support.fetch?new c.NetRequestHandler(T,n):new c.NetRequestHandler(q,n)}const u=p(),x=u.setConfig,C=u.head,j=u.get,L=u.post,U=u.del,A=u.put,O=u.patch;exports.getResponseRulesDescription=c.getResponseRulesDescription;exports.version=c.version;exports.NetRequest=p;exports.del=U;exports.get=j;exports.head=C;exports.jsonp=E;exports.jsonx=S;exports.patch=O;exports.post=L;exports.put=A;exports.setGlobalConfig=x;exports.upload=v;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("./version-Cx7ZvtPo.cjs"),y=require("./request.fetch-CaHYPyjf.cjs"),m=async function(t,o,e){return s.handleResponse(await s.retryRequest(w,t,o,e),t,o,e)};async function q(t,o,e,n){const r=e==null?void 0:e.body,d=(e==null?void 0:e.method)==="PUT"?"PUT":"POST";if(o instanceof Blob){const l=new s.RequestGlobalConfig(n),f=await w(t,l,{...e,method:d,body:o});return s.handleResponse(f,t,l,e)}const a=new FormData,u={...o};r instanceof Object&&Object.entries(r).forEach(([l,f])=>{f instanceof Blob?u[l]=f:Array.isArray(f)?f.forEach((c,g)=>{a.append(`${l}[${g}]`,String(c))}):a.append(l,String(f))});for(const l in u)a.append(l,u[l]);const b=new s.RequestGlobalConfig(n),p=await w(t,b,{...e,method:d,body:a});return s.handleResponse(p,t,b,e)}const w=async function(t,o,e){const n=await s.convertOptions(t,o,e),r=n.method,d=e==null?void 0:e.onUploadProgress,a=s.Ut(n.url,n.params);return await new Promise(u=>{let b=null,p=!1;const l=function(){p||(c.abort(),p=!0)};function f(){b!==null&&clearTimeout(b),n.abort&&n.abort.removeEventListener("abort",l)}const c=new XMLHttpRequest;if(c.open(r,a,!0),d){let g=1;c.upload.addEventListener("progress",h=>{g=h.total,d({total:h.total,loaded:h.loaded})}),c.addEventListener("load",()=>{f(),d({loaded:g,total:g}),u({url:a,method:r,status:c.status,statusText:c.statusText,headers:H(c),body:r==="HEAD"?"":c.responseText})})}c.addEventListener("error",()=>{f(),u({url:a,method:r,status:-1,statusText:"Failed",body:""})}),c.addEventListener("abort",()=>{f(),u({url:a,method:r,status:-1,statusText:"Aborted",body:""})}),Object.entries(n.headers).forEach(([g,h])=>{c.setRequestHeader(g,h)}),n.credentials==="include"&&(c.withCredentials=!0),c.send(n.body||void 0),n.abort&&n.abort.addEventListener("abort",l),n.timeout>0&&(b=setTimeout(l,n.timeout))})};function H(t){const o={};if(!t)return o;const e=t.getAllResponseHeaders();return e&&e!=="null"&&e.replace(/\r/g,"").split(`
2
+ `).forEach(n=>{const r=n.trim();if(!r)return;const d=r.split(":"),a=d[0].trim();a&&(o[a]=(d[1]||"").trim())}),o}async function T(t,o,e={}){const n=window;"callback"in e||(e.callback="jsonxData"+Math.random().toString(16).slice(2));const r=e.callback+"";if(!t)return null;const d=s.Ut(t,e,!0);return new Promise(a=>{n[r]=function(u){if(r in window&&delete n[r],o(u))return u;console.warn("response type check faild",t,u),a(null)},s.Ae(d).catch(function(){a(null),delete n[r]})})}async function C(t,o,e={}){const n=window;return"var"in e||(e.var="jsonxData"+Math.random().toString(16).slice(2)),t?await s.Ae(s.Ut(t,e,!0)).then(()=>{const r=n[e.var+""];return o(r)?r:(console.warn("response type check faild",t,r),null)}).catch(()=>null):null}const E=async function(t,o,e){return await q(t,o,e,{baseURL:i.getConfig("baseURL"),logHandler:i.getConfig("logHandler"),errorHandler:i.getConfig("errorHandler"),requestTransformer:i.getConfig("requestTransformer"),messageHandler:i.getConfig("messageHandler"),responseHandler:i.getConfig("responseHandler")})};function R(t){if(!s.Support.window)throw new Error("Default Module Only Support In Browser");return s.Support.fetch?new s.NetRequestHandler(y.fetchRequest,t):new s.NetRequestHandler(m,t)}const i=R(),S=i.setConfig,x=i.head,U=i.get,j=i.post,v=i.del,L=i.put,D=i.patch;exports.getResponseRulesDescription=s.getResponseRulesDescription;exports.version=s.version;exports.NetRequest=R;exports.del=v;exports.get=U;exports.head=x;exports.jsonp=T;exports.jsonx=C;exports.patch=D;exports.post=j;exports.put=L;exports.setGlobalConfig=S;exports.upload=E;
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { xhrUpload } from "./inc/request.browser";
2
1
  import { NetRequestHandler } from "./inc/main";
2
+ import { xhrUpload } from "./inc/request.xhr";
3
3
  import type { IRequestGlobalConfig } from "./inc/type";
4
4
  export * from "./version";
5
5
  export { jsonp, jsonx } from "./inc/jsonp";
@@ -10,7 +10,7 @@ export type { IRequestOptions, IRequestGlobalConfig, IResponseRule, IResponseRes
10
10
  */
11
11
  export declare const upload: (url: string, files: Parameters<typeof xhrUpload>[1], options?: Parameters<typeof xhrUpload>[2]) => ReturnType<typeof xhrUpload>;
12
12
  /**
13
- * 创建新的实例空间,配置和缓存跟全局默认实例是隔离的
13
+ * 创建新的实例空间,配置和缓存跟全局默认实例是隔离的,仅支持在浏览器环境使用
14
14
  */
15
15
  export declare function NetRequest(config?: IRequestGlobalConfig): NetRequestHandler;
16
16
  /**
package/dist/index.js CHANGED
@@ -1,154 +1,121 @@
1
- import { c as E, S as w, f as q, U as p, h as m, r as H, R, A as x, N as T } from "./version-DOOsgzgL.js";
2
- import { g as z, v as J } from "./version-DOOsgzgL.js";
3
- const L = async function(n, o, e) {
4
- const t = await E(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 = w.AbortController ? new AbortController() : null;
7
- function i() {
8
- a && !a.signal.aborted && a.abort();
1
+ import { h as w, r as q, R as y, c as x, U as p, A as T, S as R, N as H } from "./version-C-bTPkwR.js";
2
+ import { g as z, v as I } from "./version-C-bTPkwR.js";
3
+ import { f as E } from "./request.fetch-DnbU5fqv.js";
4
+ const C = async function(t, a, e) {
5
+ return w(await q(m, t, a, e), t, a, e);
6
+ };
7
+ async function S(t, a, e, n) {
8
+ const r = e == null ? void 0 : e.body, i = (e == null ? void 0 : e.method) === "PUT" ? "PUT" : "POST";
9
+ if (a instanceof Blob) {
10
+ const c = new y(n), u = await m(t, c, {
11
+ ...e,
12
+ method: i,
13
+ body: a
14
+ });
15
+ return w(u, t, c, e);
9
16
  }
10
- t.abort && t.abort.addEventListener("abort", i);
11
- const f = t.timeout > 0 ? setTimeout(i, t.timeout) : null, h = new Request(r, {
12
- method: t.method,
13
- headers: Object.keys(t.headers).length > 0 ? new Headers(t.headers) : void 0,
14
- body: t.body,
15
- credentials: t.credentials,
16
- signal: a == null ? void 0 : a.signal,
17
- redirect: "follow"
17
+ const o = new FormData(), d = { ...a };
18
+ r instanceof Object && Object.entries(r).forEach(([c, u]) => {
19
+ u instanceof Blob ? d[c] = u : Array.isArray(u) ? u.forEach((s, f) => {
20
+ o.append(`${c}[${f}]`, String(s));
21
+ }) : o.append(c, String(u));
18
22
  });
19
- return await fetch(h).then(async (s) => ({
20
- url: r.toString(),
21
- method: t.method,
22
- status: s.status,
23
- statusText: s.statusText,
24
- headers: q([...s.headers.entries()]),
25
- body: t.method === "HEAD" ? "" : await s.text()
26
- })).catch((s) => ({
27
- url: r.toString(),
28
- method: t.method,
29
- status: -1,
30
- statusText: a != null && a.signal.aborted ? "Aborted" : "NetworkError",
31
- body: String(s)
32
- })).finally(() => {
33
- f !== null && clearTimeout(f), t.abort && t.abort.removeEventListener("abort", i);
23
+ for (const c in d)
24
+ o.append(c, d[c]);
25
+ const b = new y(n), h = await m(t, b, {
26
+ ...e,
27
+ method: i,
28
+ body: o
34
29
  });
35
- }, y = async function(n, o, e) {
36
- const t = await E(n, o, e), r = t.method, c = e == null ? void 0 : e.onUploadProgress, a = p(t.url, t.params);
37
- return await new Promise((i) => {
38
- let f = null, h = !1;
39
- const s = function() {
40
- h || (d.abort(), h = !0);
30
+ return w(h, t, b, e);
31
+ }
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, o = p(n.url, n.params);
34
+ return await new Promise((d) => {
35
+ let b = null, h = !1;
36
+ const c = function() {
37
+ h || (s.abort(), h = !0);
41
38
  };
42
39
  function u() {
43
- f !== null && clearTimeout(f), t.abort && t.abort.removeEventListener("abort", s);
40
+ b !== null && clearTimeout(b), n.abort && n.abort.removeEventListener("abort", c);
44
41
  }
45
- const d = new XMLHttpRequest();
46
- if (d.open(r, a, !0), c) {
47
- let b = 1;
48
- d.upload.addEventListener("progress", (g) => {
49
- b = g.total, c({ total: g.total, loaded: g.loaded });
50
- }), d.addEventListener("load", () => {
51
- u(), c({ loaded: b, total: b }), i({
52
- url: a,
42
+ const s = new XMLHttpRequest();
43
+ if (s.open(r, o, !0), i) {
44
+ let f = 1;
45
+ s.upload.addEventListener("progress", (g) => {
46
+ f = g.total, i({ total: g.total, loaded: g.loaded });
47
+ }), s.addEventListener("load", () => {
48
+ u(), i({ loaded: f, total: f }), d({
49
+ url: o,
53
50
  method: r,
54
- status: d.status,
55
- statusText: d.statusText,
56
- headers: S(d),
57
- body: r === "HEAD" ? "" : d.responseText
51
+ status: s.status,
52
+ statusText: s.statusText,
53
+ headers: U(s),
54
+ body: r === "HEAD" ? "" : s.responseText
58
55
  });
59
56
  });
60
57
  }
61
- d.addEventListener("error", () => {
62
- u(), i({
63
- url: a,
58
+ s.addEventListener("error", () => {
59
+ u(), d({
60
+ url: o,
64
61
  method: r,
65
62
  status: -1,
66
63
  statusText: "Failed",
67
64
  body: ""
68
65
  });
69
- }), d.addEventListener("abort", () => {
70
- u(), i({
71
- url: a,
66
+ }), s.addEventListener("abort", () => {
67
+ u(), d({
68
+ url: o,
72
69
  method: r,
73
70
  status: -1,
74
71
  statusText: "Aborted",
75
72
  body: ""
76
73
  });
77
- }), Object.entries(t.headers).forEach(([b, g]) => {
78
- d.setRequestHeader(b, g);
79
- }), t.credentials === "include" && (d.withCredentials = !0), d.send(t.body || void 0), t.abort && t.abort.addEventListener("abort", s), t.timeout > 0 && (f = setTimeout(s, t.timeout));
74
+ }), Object.entries(n.headers).forEach(([f, g]) => {
75
+ s.setRequestHeader(f, g);
76
+ }), n.credentials === "include" && (s.withCredentials = !0), s.send(n.body || void 0), n.abort && n.abort.addEventListener("abort", c), n.timeout > 0 && (b = setTimeout(c, n.timeout));
80
77
  });
81
78
  };
82
- function S(n) {
83
- const o = {};
84
- if (!n)
85
- return o;
86
- const e = n.getAllResponseHeaders();
79
+ function U(t) {
80
+ const a = {};
81
+ if (!t)
82
+ return a;
83
+ const e = t.getAllResponseHeaders();
87
84
  return e && e !== "null" && e.replace(/\r/g, "").split(`
88
- `).forEach((t) => {
89
- const r = t.trim();
85
+ `).forEach((n) => {
86
+ const r = n.trim();
90
87
  if (!r)
91
88
  return;
92
- const c = r.split(":"), a = c[0].trim();
93
- a && (o[a] = (c[1] || "").trim());
94
- }), o;
95
- }
96
- const v = async function(n, o, e) {
97
- return m(await H(L, n, o, e), n, o, e);
98
- }, C = async function(n, o, e) {
99
- return m(await H(y, n, o, e), n, o, e);
100
- };
101
- async function U(n, o, e, t) {
102
- const r = e == null ? void 0 : e.body, c = (e == null ? void 0 : e.method) === "PUT" ? "PUT" : "POST";
103
- if (o instanceof Blob) {
104
- const s = new R(t), u = await y(n, s, {
105
- ...e,
106
- method: c,
107
- body: o
108
- });
109
- return m(u, n, s, e);
110
- }
111
- const a = new FormData(), i = { ...o };
112
- r instanceof Object && Object.entries(r).forEach(([s, u]) => {
113
- u instanceof Blob ? i[s] = u : Array.isArray(u) ? u.forEach((d, b) => {
114
- a.append(`${s}[${b}]`, String(d));
115
- }) : a.append(s, String(u));
116
- });
117
- for (const s in i)
118
- a.append(s, i[s]);
119
- const f = new R(t), h = await y(n, f, {
120
- ...e,
121
- method: c,
122
- body: a
123
- });
124
- return m(h, n, f, e);
89
+ const i = r.split(":"), o = i[0].trim();
90
+ o && (a[o] = (i[1] || "").trim());
91
+ }), a;
125
92
  }
126
- async function k(n, o, e = {}) {
127
- const t = window;
93
+ async function k(t, a, e = {}) {
94
+ const n = window;
128
95
  "callback" in e || (e.callback = "jsonxData" + Math.random().toString(16).slice(2));
129
96
  const r = e.callback + "";
130
- if (!n)
97
+ if (!t)
131
98
  return null;
132
- const c = p(n, e, !0);
133
- return new Promise((a) => {
134
- t[r] = function(i) {
135
- if (r in window && delete t[r], o(i))
136
- return i;
137
- console.warn("response type check faild", n, i), a(null);
138
- }, x(c).catch(function() {
139
- a(null), delete t[r];
99
+ const i = p(t, e, !0);
100
+ return new Promise((o) => {
101
+ n[r] = function(d) {
102
+ if (r in window && delete n[r], a(d))
103
+ return d;
104
+ console.warn("response type check faild", t, d), o(null);
105
+ }, T(i).catch(function() {
106
+ o(null), delete n[r];
140
107
  });
141
108
  });
142
109
  }
143
- async function O(n, o, e = {}) {
144
- const t = window;
145
- return "var" in e || (e.var = "jsonxData" + Math.random().toString(16).slice(2)), n ? await x(p(n, e, !0)).then(() => {
146
- const r = t[e.var + ""];
147
- return o(r) ? r : (console.warn("response type check faild", n, r), null);
110
+ async function A(t, a, e = {}) {
111
+ const n = window;
112
+ return "var" in e || (e.var = "jsonxData" + Math.random().toString(16).slice(2)), t ? await T(p(t, e, !0)).then(() => {
113
+ const r = n[e.var + ""];
114
+ return a(r) ? r : (console.warn("response type check faild", t, r), null);
148
115
  }).catch(() => null) : null;
149
116
  }
150
- const D = async function(n, o, e) {
151
- return await U(n, o, e, {
117
+ const D = async function(t, a, e) {
118
+ return await S(t, a, e, {
152
119
  baseURL: l.getConfig("baseURL"),
153
120
  logHandler: l.getConfig("logHandler"),
154
121
  errorHandler: l.getConfig("errorHandler"),
@@ -157,24 +124,24 @@ const D = async function(n, o, e) {
157
124
  responseHandler: l.getConfig("responseHandler")
158
125
  });
159
126
  };
160
- function A(n) {
161
- if (!w.window)
127
+ function L(t) {
128
+ if (!R.window)
162
129
  throw new Error("Default Module Only Support In Browser");
163
- return w.fetch ? new T(v, n) : new T(C, n);
130
+ return R.fetch ? new H(E, t) : new H(C, t);
164
131
  }
165
- const l = A(), P = l.setConfig, M = l.head, N = l.get, F = l.post, B = l.del, X = l.put, G = l.patch;
132
+ const l = L(), O = l.setConfig, P = l.head, M = l.get, N = l.post, B = l.del, F = l.put, X = l.patch;
166
133
  export {
167
- A as NetRequest,
134
+ L as NetRequest,
168
135
  B as del,
169
- N as get,
136
+ M as get,
170
137
  z as getResponseRulesDescription,
171
- M as head,
138
+ P as head,
172
139
  k as jsonp,
173
- O as jsonx,
174
- G as patch,
175
- F as post,
176
- X as put,
177
- P as setGlobalConfig,
140
+ A as jsonx,
141
+ X as patch,
142
+ N as post,
143
+ F as put,
144
+ O as setGlobalConfig,
178
145
  D as upload,
179
- J as version
146
+ I as version
180
147
  };
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"),o=require("./version-CCXW7_VI.cjs"),R=async function(n,u,c){return o.handleResponse(await o.retryRequest(w,n,u,c),n,u,c)},w=async function(n,u,c){const t=await o.convertOptions(n,u,c);if(!o.D(t.url))return{url:t.url,method:t.method,status:-1,statusText:"URLFormatError",headers:{},body:""};const f=/^https:\/\//i.test(t.url)?q:y,a=new URL(t.url),i=t.params;i instanceof Object&&Object.keys(i).forEach(r=>a.searchParams.set(r,i[r]));const b=t.method==="HEAD";return new Promise(r=>{const d=f.request(a,{headers:t.headers,method:t.method,timeout:t.timeout>0?t.timeout:void 0},function(e){const p=[];e.on("data",h=>p.push(h)),e.on("end",()=>{const h=o.fromEntries(Object.entries(e.headers).map(([g,m])=>[g.toLowerCase(),Array.isArray(m)?m.join(","):m]));r({url:a.toString(),method:t.method,status:e.statusCode||-1,statusText:e.statusMessage||"Unknown",headers:h,body:b?"":Buffer.concat(p).toString("utf-8")})})});d.on("error",e=>{r({url:a.toString(),method:t.method,status:-1,statusText:e.name||"Unknown",body:e.message})}),d.on("timeout",()=>{r({url:a.toString(),method:t.method,status:-1,statusText:"Timeout",body:""})}),t.body&&d.write(t.body),d.end()})};function l(n){return new o.NetRequestHandler(R,n)}const s=l(),S=s.setConfig,T=s.head,j=s.get,C=s.post,O=s.del,U=s.put,x=s.patch;exports.version=o.version;exports.NetRequest=l;exports.del=O;exports.get=j;exports.head=T;exports.patch=x;exports.post=C;exports.put=U;exports.setGlobalConfig=S;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const y=require("node:http"),R=require("node:https"),e=require("./version-Cx7ZvtPo.cjs"),g=require("./request.fetch-CaHYPyjf.cjs"),w=async function(s,u,c){return e.handleResponse(await e.retryRequest(S,s,u,c),s,u,c)},S=async function(s,u,c){const t=await e.convertOptions(s,u,c);if(!e.D(t.url))return{url:t.url,method:t.method,status:-1,statusText:"URLFormatError",headers:{},body:""};const f=/^https:\/\//i.test(t.url)?R:y,a=new URL(t.url),i=t.params;i instanceof Object&&Object.keys(i).forEach(r=>a.searchParams.set(r,i[r]));const q=t.method==="HEAD";return new Promise(r=>{const d=f.request(a,{headers:t.headers,method:t.method,timeout:t.timeout>0?t.timeout:void 0},function(o){const p=[];o.on("data",h=>p.push(h)),o.on("end",()=>{const h=e.fromEntries(Object.entries(o.headers).map(([b,m])=>[b.toLowerCase(),Array.isArray(m)?m.join(","):m]));r({url:a.toString(),method:t.method,status:o.statusCode||-1,statusText:o.statusMessage||"Unknown",headers:h,body:q?"":Buffer.concat(p).toString("utf-8")})})});d.on("error",o=>{r({url:a.toString(),method:t.method,status:-1,statusText:o.name||"Unknown",body:o.message})}),d.on("timeout",()=>{r({url:a.toString(),method:t.method,status:-1,statusText:"Timeout",body:""})}),t.body&&d.write(t.body),d.end()})};function l(s){return e.Support.fetch?new e.NetRequestHandler(g.fetchRequest,s):new e.NetRequestHandler(w,s)}const n=l(),T=n.setConfig,j=n.head,C=n.get,N=n.post,O=n.del,U=n.put,x=n.patch;exports.version=e.version;exports.NetRequest=l;exports.del=O;exports.get=C;exports.head=j;exports.patch=x;exports.post=N;exports.put=U;exports.setGlobalConfig=T;
package/dist/node.js CHANGED
@@ -1,12 +1,13 @@
1
- import l from "node:http";
2
- import y from "node:https";
3
- import { h as R, r as g, c as q, D as w, f as x, N as T } from "./version-DOOsgzgL.js";
4
- import { v as G } from "./version-DOOsgzgL.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
- const t = await q(s, a, u);
9
- if (!w(t.url))
1
+ import y from "node:http";
2
+ import R from "node:https";
3
+ import { h as q, r as w, c as g, D as x, f as S, S as T, N as p } from "./version-C-bTPkwR.js";
4
+ import { v as z } from "./version-C-bTPkwR.js";
5
+ import { f as U } from "./request.fetch-DnbU5fqv.js";
6
+ const j = async function(o, a, u) {
7
+ return q(await w(C, o, a, u), o, a, u);
8
+ }, C = async function(o, a, u) {
9
+ const t = await g(o, a, u);
10
+ if (!x(t.url))
10
11
  return {
11
12
  url: t.url,
12
13
  method: t.method,
@@ -15,11 +16,11 @@ const U = async function(s, a, u) {
15
16
  headers: {},
16
17
  body: ""
17
18
  };
18
- const p = /^https:\/\//i.test(t.url) ? y : l, r = new URL(t.url), d = t.params;
19
+ const f = /^https:\/\//i.test(t.url) ? R : y, r = new URL(t.url), d = t.params;
19
20
  d instanceof Object && Object.keys(d).forEach((n) => r.searchParams.set(n, d[n]));
20
- const f = t.method === "HEAD";
21
+ const b = t.method === "HEAD";
21
22
  return new Promise((n) => {
22
- const c = p.request(
23
+ const c = f.request(
23
24
  r,
24
25
  {
25
26
  headers: t.headers,
@@ -29,8 +30,8 @@ const U = async function(s, a, u) {
29
30
  function(e) {
30
31
  const h = [];
31
32
  e.on("data", (i) => h.push(i)), e.on("end", () => {
32
- const i = x(
33
- Object.entries(e.headers).map(([b, m]) => [b.toLowerCase(), Array.isArray(m) ? m.join(",") : m])
33
+ const i = S(
34
+ Object.entries(e.headers).map(([l, m]) => [l.toLowerCase(), Array.isArray(m) ? m.join(",") : m])
34
35
  );
35
36
  n({
36
37
  url: r.toString(),
@@ -38,7 +39,7 @@ const U = async function(s, a, u) {
38
39
  status: e.statusCode || -1,
39
40
  statusText: e.statusMessage || "Unknown",
40
41
  headers: i,
41
- body: f ? "" : Buffer.concat(h).toString("utf-8")
42
+ body: b ? "" : Buffer.concat(h).toString("utf-8")
42
43
  });
43
44
  });
44
45
  }
@@ -62,18 +63,18 @@ const U = async function(s, a, u) {
62
63
  }), t.body && c.write(t.body), c.end();
63
64
  });
64
65
  };
65
- function C(s) {
66
- return new T(U, s);
66
+ function E(o) {
67
+ return T.fetch ? new p(U, o) : new p(j, o);
67
68
  }
68
- const o = C(), O = o.setConfig, S = o.head, A = o.get, H = o.post, k = o.del, D = o.put, P = o.patch;
69
+ const s = E(), H = s.setConfig, k = s.head, D = s.get, P = s.post, B = s.del, F = s.put, G = s.patch;
69
70
  export {
70
- C as NetRequest,
71
- k as del,
72
- A as get,
73
- S as head,
74
- P as patch,
75
- H as post,
76
- D as put,
77
- O as setGlobalConfig,
78
- G as version
71
+ E as NetRequest,
72
+ B as del,
73
+ D as get,
74
+ k as head,
75
+ G as patch,
76
+ P as post,
77
+ F as put,
78
+ H as setGlobalConfig,
79
+ z as version
79
80
  };
@@ -0,0 +1 @@
1
+ "use strict";const s=require("./version-Cx7ZvtPo.cjs"),b=async function(o,a,n){return s.handleResponse(await s.retryRequest(l,o,a,n),o,a,n)},l=async function(o,a,n){const t=await s.convertOptions(o,a,n),i=new URL(t.url),c=t.params;c instanceof Object&&Object.keys(c).forEach(r=>i.searchParams.set(r,c[r]));const e=s.Support.AbortController?new AbortController:null;function u(){e&&!e.signal.aborted&&e.abort()}t.abort&&t.abort.addEventListener("abort",u);const d=t.timeout>0?setTimeout(u,t.timeout):null,h=new Request(i,{method:t.method,headers:Object.keys(t.headers).length>0?new Headers(t.headers):void 0,body:t.body,credentials:t.credentials,signal:e==null?void 0:e.signal,redirect:"follow"});return await fetch(h).then(async r=>({url:i.toString(),method:t.method,status:r.status,statusText:r.statusText,headers:s.fromEntries([...r.headers.entries()]),body:t.method==="HEAD"?"":await r.text()})).catch(r=>({url:i.toString(),method:t.method,status:-1,statusText:e!=null&&e.signal.aborted?"Aborted":"NetworkError",body:String(r)})).finally(()=>{d!==null&&clearTimeout(d),t.abort&&t.abort.removeEventListener("abort",u)})};exports.fetchRequest=b;
@@ -0,0 +1,39 @@
1
+ import { h, r as b, c as l, S as m, f } from "./version-C-bTPkwR.js";
2
+ const p = async function(r, s, o) {
3
+ return h(await b(w, r, s, o), r, s, o);
4
+ }, w = async function(r, s, o) {
5
+ const t = await l(r, s, o), n = new URL(t.url), i = t.params;
6
+ i instanceof Object && Object.keys(i).forEach((a) => n.searchParams.set(a, i[a]));
7
+ const e = m.AbortController ? new AbortController() : null;
8
+ function c() {
9
+ e && !e.signal.aborted && e.abort();
10
+ }
11
+ t.abort && t.abort.addEventListener("abort", c);
12
+ const d = t.timeout > 0 ? setTimeout(c, t.timeout) : null, u = new Request(n, {
13
+ method: t.method,
14
+ headers: Object.keys(t.headers).length > 0 ? new Headers(t.headers) : void 0,
15
+ body: t.body,
16
+ credentials: t.credentials,
17
+ signal: e == null ? void 0 : e.signal,
18
+ redirect: "follow"
19
+ });
20
+ return await fetch(u).then(async (a) => ({
21
+ url: n.toString(),
22
+ method: t.method,
23
+ status: a.status,
24
+ statusText: a.statusText,
25
+ headers: f([...a.headers.entries()]),
26
+ body: t.method === "HEAD" ? "" : await a.text()
27
+ })).catch((a) => ({
28
+ url: n.toString(),
29
+ method: t.method,
30
+ status: -1,
31
+ statusText: e != null && e.signal.aborted ? "Aborted" : "NetworkError",
32
+ body: String(a)
33
+ })).finally(() => {
34
+ d !== null && clearTimeout(d), t.abort && t.abort.removeEventListener("abort", c);
35
+ });
36
+ };
37
+ export {
38
+ p as f
39
+ };