@seayoo-web/request 3.3.3 → 3.4.0
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.js +53 -53
- package/dist/node.js +17 -17
- package/dist/{request.fetch-CHbeHmeX.js → request.fetch-B3ED8nRu.js} +6 -6
- package/dist/retry-CdUkYrFw.js +606 -0
- package/dist/wx.js +23 -23
- package/package.json +2 -6
- package/dist/index.cjs +0 -2
- package/dist/node.cjs +0 -1
- package/dist/request.fetch-Ce3_4Yuj.cjs +0 -1
- package/dist/retry-BXoyQlSJ.js +0 -1191
- package/dist/retry-D_7OkloZ.cjs +0 -3
- package/dist/wx.cjs +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@seayoo-web/request",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.4.0",
|
|
4
4
|
"description": "request tools for seayoo web",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"source": "./src/index.ts",
|
|
@@ -12,27 +12,23 @@
|
|
|
12
12
|
".": {
|
|
13
13
|
"types": "./types/index.d.ts",
|
|
14
14
|
"import": "./dist/index.js",
|
|
15
|
-
"require": "./dist/index.cjs",
|
|
16
15
|
"default": "./dist/index.js"
|
|
17
16
|
},
|
|
18
17
|
"./node": {
|
|
19
18
|
"browser": null,
|
|
20
19
|
"types": "./types/node.d.ts",
|
|
21
20
|
"import": "./dist/node.js",
|
|
22
|
-
"require": "./dist/node.cjs",
|
|
23
21
|
"default": "./dist/node.cjs"
|
|
24
22
|
},
|
|
25
23
|
"./dist/node": {
|
|
26
24
|
"browser": null,
|
|
27
25
|
"types": "./types/node.d.ts",
|
|
28
26
|
"import": "./dist/node.js",
|
|
29
|
-
"require": "./dist/node.cjs",
|
|
30
27
|
"default": "./dist/node.cjs"
|
|
31
28
|
},
|
|
32
29
|
"./wx": {
|
|
33
30
|
"types": "./types/wx.d.ts",
|
|
34
31
|
"import": "./dist/wx.js",
|
|
35
|
-
"require": "./dist/wx.cjs",
|
|
36
32
|
"default": "./dist/wx.js"
|
|
37
33
|
}
|
|
38
34
|
},
|
|
@@ -60,7 +56,7 @@
|
|
|
60
56
|
"happy-dom": "^12.10.3",
|
|
61
57
|
"msw": "^2.7.0",
|
|
62
58
|
"vitest": "^3.0.5",
|
|
63
|
-
"@seayoo-web/utils": "^
|
|
59
|
+
"@seayoo-web/utils": "^4.0.1"
|
|
64
60
|
},
|
|
65
61
|
"scripts": {
|
|
66
62
|
"prebuild": "pnpm --F utils build",
|
package/dist/index.cjs
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("./retry-D_7OkloZ.cjs"),m=require("./request.fetch-Ce3_4Yuj.cjs"),y=async function(t,s,e){return r.handleResponse(await r.retryRequest(R,t,s,e),t,s,e)};async function E(t,s,e,n){const o=e?.body,u=e?.method==="PUT"?"PUT":"POST";if(s instanceof Blob){const l=new r.RequestGlobalConfig(n),f=await R(t,l,{...e,method:u,body:s});return r.handleResponse(f,t,l,e)}const c=new FormData,d={...s};o instanceof Object&&Object.entries(o).forEach(([l,f])=>{f instanceof Blob?d[l]=f:Array.isArray(f)?f.forEach((a,b)=>{c.append(`${l}[${b}]`,String(a))}):c.append(l,String(f))});for(const l in d)c.append(l,d[l]);const g=new r.RequestGlobalConfig(n),w=await R(t,g,{...e,method:u,body:c});return r.handleResponse(w,t,g,e)}const R=async function(t,s,e){const n=await r.convertOptions(t,s,e),o=n.method,u=e?.onUploadProgress,c=r.pe(n.url,n.params);return await new Promise(d=>{let g=null,w=!1;const l=function(){w||(a.abort(),w=!0)};function f(){g!==null&&clearTimeout(g),n.abort&&n.abort.removeEventListener("abort",l)}const a=new XMLHttpRequest;let b=!1;if(a.open(o,c,!0),u){let p=1;a.upload.addEventListener("progress",h=>{p=h.total,u({total:h.total,loaded:h.loaded})}),a.addEventListener("load",()=>{u({loaded:p,total:p})})}a.addEventListener("load",()=>{const p=a.status;f(),d({url:c,method:o,status:p,statusText:a.statusText,headers:T(a),body:o==="HEAD"||p===204?"":a.responseText})}),a.addEventListener("error",p=>{f(),d({url:c,method:o,status:a.status||-1,statusText:a.statusText||r.RequestInternalError.NetworkError,body:"",rawError:p})},!0),a.addEventListener("abort",()=>{f(),d({url:c,method:o,status:b?-1:0,statusText:b?r.RequestInternalError.Timeout:r.RequestInternalError.Aborted,body:""})}),Object.entries(n.headers).forEach(([p,h])=>{a.setRequestHeader(p,h)}),n.credentials==="include"&&(a.withCredentials=!0),a.send(n.body||void 0),n.abort&&n.abort.addEventListener("abort",l),n.timeout>0&&(g=setTimeout(function(){b=!0,l()},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 u=o.split(":"),c=u[0].trim();c&&(s[c]=(u[1]||"").trim())}),s}async function H(t,s,e={}){const n=window;"callback"in e||(e.callback="jsonxData"+Math.random().toString(16).slice(2));const o=e.callback+"";if(!t)return null;const u=r.pe(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(u).catch(function(){c(null),delete n[o]})})}async function x(t,s,e={}){const n=window;return"var"in e||(e.var="jsonxData"+Math.random().toString(16).slice(2)),t?await r.ce(r.pe(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 C=async function(t,s,e){return await E(t,s,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 q(t){if(!r.St.window)throw new Error("Default Module Only Support In Browser");return r.St.fetch?new r.NetRequestHandler(m.fetchRequest,t):new r.NetRequestHandler(y,t)}const i=q(),S=i.setConfig,j=i.request,L=i.head,k=i.get,v=i.post,D=i.del,U=i.put,O=i.patch;exports.RequestInternalError=r.RequestInternalError;exports.getResponseRulesDescription=r.getResponseRulesDescription;exports.NetRequest=q;exports.del=D;exports.get=k;exports.head=L;exports.jsonp=H;exports.jsonx=x;exports.patch=O;exports.post=v;exports.put=U;exports.request=j;exports.setGlobalConfig=S;exports.upload=C;
|
package/dist/node.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./retry-D_7OkloZ.cjs"),y=require("./request.fetch-Ce3_4Yuj.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.St.fetch?new e.NetRequestHandler(y.fetchRequest,r):new e.NetRequestHandler(E,r)}const s=p(),S=s.setConfig,C=s.head,I=s.get,N=s.post,T=s.del,j=s.put,O=s.patch;exports.RequestInternalError=e.RequestInternalError;exports.getResponseRulesDescription=e.getResponseRulesDescription;exports.NetRequest=p;exports.del=T;exports.get=I;exports.head=C;exports.patch=O;exports.post=N;exports.put=j;exports.setGlobalConfig=S;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";const r=require("./retry-D_7OkloZ.cjs"),E=async function(s,a,i){return r.handleResponse(await r.retryRequest(w,s,a,i),s,a,i)},w=async function(s,a,i){const t=await r.convertOptions(s,a,i),c=new URL(t.url),u=t.params;u instanceof Object&&Object.keys(u).forEach(e=>c.searchParams.set(e,u[e]));const o=r.St.AbortController?new AbortController:null;function l(){o&&!o.signal.aborted&&o.abort()}t.abort&&t.abort.addEventListener("abort",l);let d=!1;const h=t.timeout>0?setTimeout(function(){d=!0,l()},t.timeout):null,f=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:o?.signal,redirect:"follow"}).then(async e=>{const n={url:c.toString(),method:t.method,status:e.status,statusText:e.statusText,headers:r.fromEntries([...e.headers.entries()])},b=f||e.status===204?"":await e.text().catch(m=>m);return b instanceof Error?{...n,body:"",statusText:r.RequestInternalError.Unknown,rawError:b}:{...n,body:b}}).catch(e=>{const n=o?.signal.aborted;return{url:c.toString(),method:t.method,status:n&&!d?0:-1,statusText:d?r.RequestInternalError.Timeout:n?r.RequestInternalError.Aborted:r.RequestInternalError.NetworkError,body:"",rawError:e}}).finally(()=>{h!==null&&clearTimeout(h),t.abort&&t.abort.removeEventListener("abort",l)})};exports.fetchRequest=E;
|