@andbridge/glowpod 1.2.0 → 1.2.2
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/build/glowpod.mjs +76 -0
- package/package.json +5 -5
- package/build/glowpod.esm.js +0 -1
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import e from "axios";
|
|
2
|
+
|
|
3
|
+
class a {
|
|
4
|
+
instance;
|
|
5
|
+
constructor(a) {
|
|
6
|
+
this.instance = e.create(a);
|
|
7
|
+
}
|
|
8
|
+
getInstance=() => this.instance;
|
|
9
|
+
Get=async e => this.instance({
|
|
10
|
+
method: "GET",
|
|
11
|
+
url: e.url,
|
|
12
|
+
params: e.params,
|
|
13
|
+
headers: {
|
|
14
|
+
...e.headers
|
|
15
|
+
},
|
|
16
|
+
...e.others
|
|
17
|
+
});
|
|
18
|
+
Put=async e => this.instance({
|
|
19
|
+
method: "PUT",
|
|
20
|
+
url: e.url,
|
|
21
|
+
data: e.params,
|
|
22
|
+
headers: {
|
|
23
|
+
...e.headers
|
|
24
|
+
},
|
|
25
|
+
...e.others
|
|
26
|
+
});
|
|
27
|
+
Delete=async e => this.instance({
|
|
28
|
+
method: "DELETE",
|
|
29
|
+
url: e.url,
|
|
30
|
+
params: e.params,
|
|
31
|
+
headers: {
|
|
32
|
+
...e.headers
|
|
33
|
+
},
|
|
34
|
+
...e.others
|
|
35
|
+
});
|
|
36
|
+
Post=async e => this.instance({
|
|
37
|
+
method: "POST",
|
|
38
|
+
url: e.url,
|
|
39
|
+
data: e.params,
|
|
40
|
+
headers: {
|
|
41
|
+
...e.headers
|
|
42
|
+
},
|
|
43
|
+
...e.others
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const s = 200, t = 299, r = ({instance: e, authFailedCaller: a = () => {}, networkSuccessCode: r = 200, authFailedCode: o = 401, networkFailedCaller: n = () => {}, serverKillCaller: d = () => {}, responseStruct: c = {
|
|
48
|
+
codeName: "code",
|
|
49
|
+
messageName: "message",
|
|
50
|
+
dataName: "data"
|
|
51
|
+
}, setHeaders: l = async e => {}}) => {
|
|
52
|
+
let i = null, h = !0;
|
|
53
|
+
const u = e => (i && clearTimeout(i), i = setTimeout(() => {
|
|
54
|
+
if (h) return e.status <= s && e.status >= t ? d(e) : e.data?.[c.codeName] == o ? a(e.data) : e.data?.[c.codeName] != r ? n(e.data) : d(e);
|
|
55
|
+
}, 0), () => h = !1);
|
|
56
|
+
e.interceptors.request.use(async e => (e.headers && await (l?.(e.headers)), e), e => (console.log("请求错误拦截器:", e),
|
|
57
|
+
u(e), Promise.reject(e))), e.interceptors.response.use(e => {
|
|
58
|
+
if ("blob" === e.config.responseType) return e;
|
|
59
|
+
if (e.data?.[c.codeName] === r) return e.data?.[c.dataName];
|
|
60
|
+
{
|
|
61
|
+
const a = u(e);
|
|
62
|
+
throw {
|
|
63
|
+
...e,
|
|
64
|
+
hiddenDefaultErrorHandler: a
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
}, e => {
|
|
68
|
+
const a = u(e);
|
|
69
|
+
throw {
|
|
70
|
+
...e,
|
|
71
|
+
hiddenDefaultErrorHandler: a
|
|
72
|
+
};
|
|
73
|
+
});
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
export { a as GlowPod, r as setupInterceptors };
|
package/package.json
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@andbridge/glowpod",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.2",
|
|
4
4
|
"description": "A axios-based HTTP client library",
|
|
5
5
|
"main": "build/glowpod.js",
|
|
6
|
-
"module": "build/glowpod.
|
|
6
|
+
"module": "build/glowpod.mjs",
|
|
7
7
|
"types": "build/glowpod.d.ts",
|
|
8
8
|
"files": [
|
|
9
9
|
"build"
|
|
10
10
|
],
|
|
11
11
|
"exports": {
|
|
12
12
|
".": {
|
|
13
|
-
"import": "./build/glowpod.
|
|
13
|
+
"import": "./build/glowpod.mjs",
|
|
14
14
|
"require": "./build/glowpod.js",
|
|
15
15
|
"types": "./build/glowpod.d.ts"
|
|
16
16
|
}
|
|
@@ -31,10 +31,10 @@
|
|
|
31
31
|
"@rollup/plugin-babel": "^6.1.0",
|
|
32
32
|
"@rollup/plugin-commonjs": "^29.0.0",
|
|
33
33
|
"@rollup/plugin-node-resolve": "^16.0.3",
|
|
34
|
+
"@rollup/plugin-terser": "^1.0.0",
|
|
34
35
|
"@rollup/plugin-typescript": "^12.3.0",
|
|
35
|
-
"rollup": "^4.53.2",
|
|
36
|
-
"rollup-plugin-terser": "^7.0.2",
|
|
37
36
|
"@types/node": "^22.15.0",
|
|
37
|
+
"rollup": "^4.53.2",
|
|
38
38
|
"tslib": "^2.8.1",
|
|
39
39
|
"typescript": "~5.9.3"
|
|
40
40
|
},
|
package/build/glowpod.esm.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import e from"axios";class a{instance;constructor(a){this.instance=e.create(a)}getInstance=()=>this.instance;Get=async e=>this.instance({method:"GET",url:e.url,params:e.params,headers:{...e.headers},...e.others});Put=async e=>this.instance({method:"PUT",url:e.url,data:e.params,headers:{...e.headers},...e.others});Delete=async e=>this.instance({method:"DELETE",url:e.url,params:e.params,headers:{...e.headers},...e.others});Post=async e=>this.instance({method:"POST",url:e.url,data:e.params,headers:{...e.headers},...e.others})}const s=200,t=299,r=({instance:e,authFailedCaller:a=()=>{},networkSuccessCode:r=200,authFailedCode:o=401,networkFailedCaller:n=()=>{},serverKillCaller:d=()=>{},responseStruct:c={codeName:"code",messageName:"message",dataName:"data"},setHeaders:l=async e=>{}})=>{let i=null,h=!0;const u=e=>(i&&clearTimeout(i),i=setTimeout(()=>{if(h)return e.status<=s&&e.status>=t?d(e):e.data?.[c.codeName]==o?a(e.data):e.data?.[c.codeName]!=r?n(e.data):d(e)},0),()=>h=!1);e.interceptors.request.use(async e=>(e.headers&&await(l?.(e.headers)),e),e=>(console.log("请求错误拦截器:",e),u(e),Promise.reject(e))),e.interceptors.response.use(e=>{if("blob"===e.config.responseType)return e;if(e.data?.[c.codeName]===r)return e.data?.[c.dataName];{const a=u(e);throw{...e,hiddenDefaultErrorHandler:a}}},e=>{const a=u(e);throw{...e,hiddenDefaultErrorHandler:a}})};export{a as GlowPod,r as setupInterceptors};
|