@andbridge/glowpod 1.0.10 → 1.1.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/build/glowpod.esm.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"axios";class
|
|
1
|
+
import e from"axios";class a{constructor(a){this.getInstance=()=>this.instance,this.Get=e=>this.instance({method:"GET",url:e.url,params:e.params,headers:{...e.headers},...e.others}),this.Put=e=>this.instance({method:"PUT",url:e.url,params:e.params,headers:{...e.headers},...e.others}),this.Delete=e=>this.instance({method:"DELETE",url:e.url,params:e.params,headers:{...e.headers},...e.others}),this.Post=e=>this.instance({method:"POST",url:e.url,data:e.params,headers:{...e.headers},...e.others}),this.instance=e.create(a)}}const s=()=>{},t=()=>{console.log("请配置全局错误处理")},r=()=>{},o=200,d=299,n=({instance:e,authFailedCaller:a=s,networkSuccessCode:n=200,authFailedCode:i=401,networkFailedCaller:h=t,serverKillCaller:l=r,responseStruct:c={codeName:"code",messageName:"message",dataName:"data"},setHeaders:u=e=>{}})=>{let m=null,p=!0;const f=e=>(m&&clearTimeout(m),m=setTimeout(()=>{if(p)return e.status<=o&&e.status>=d?l():e.data?.[c.codeName]==i?a():e.data?.[c.codeName]!=n?h(e.data):void 0},0),()=>p=!1);e.interceptors.request.use(async e=>(e.headers&&u?.(e.headers),e),e=>(console.log("请求错误拦截器:",e),f(e),Promise.reject(e))),e.interceptors.response.use(e=>{if("blob"===e.config.responseType)return e;if(e.data?.[c.codeName]===n)return e.data?.[c.dataName];{const a=f(e);throw{...e,hiddenDefaultErrorHandler:a}}},e=>{const a=f(e);throw{...e,hiddenDefaultErrorHandler:a}})};export{a as GlowPod,n as setupInterceptors};
|
package/build/glowpod.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e=require("axios");const
|
|
1
|
+
"use strict";var e=require("axios");const s=()=>{},t=()=>{console.log("请配置全局错误处理")},a=()=>{},r=200,o=299;exports.GlowPod=class{constructor(s){this.getInstance=()=>this.instance,this.Get=e=>this.instance({method:"GET",url:e.url,params:e.params,headers:{...e.headers},...e.others}),this.Put=e=>this.instance({method:"PUT",url:e.url,params:e.params,headers:{...e.headers},...e.others}),this.Delete=e=>this.instance({method:"DELETE",url:e.url,params:e.params,headers:{...e.headers},...e.others}),this.Post=e=>this.instance({method:"POST",url:e.url,data:e.params,headers:{...e.headers},...e.others}),this.instance=e.create(s)}},exports.setupInterceptors=({instance:e,authFailedCaller:d=s,networkSuccessCode:n=200,authFailedCode:i=401,networkFailedCaller:h=t,serverKillCaller:l=a,responseStruct:c={codeName:"code",messageName:"message",dataName:"data"},setHeaders:u=e=>{}})=>{let m=null,p=!0;const N=e=>(m&&clearTimeout(m),m=setTimeout(()=>{if(p)return e.status<=r&&e.status>=o?l():e.data?.[c.codeName]==i?d():e.data?.[c.codeName]!=n?h(e.data):void 0},0),()=>p=!1);e.interceptors.request.use(async e=>(e.headers&&u?.(e.headers),e),e=>(console.log("请求错误拦截器:",e),N(e),Promise.reject(e))),e.interceptors.response.use(e=>{if("blob"===e.config.responseType)return e;if(e.data?.[c.codeName]===n)return e.data?.[c.dataName];{const s=N(e);throw{...e,hiddenDefaultErrorHandler:s}}},e=>{const s=N(e);throw{...e,hiddenDefaultErrorHandler:s}})};
|
package/build/glowpod.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("axios")):"function"==typeof define&&define.amd?define(["exports","axios"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).GlowPod={},e.axios)}(this,function(e,t){"use strict";const s=()=>{},a=()=>{console.log("请配置全局错误处理")},r=()=>{},o=200,n=299;e.GlowPod=class{constructor(e){this.getInstance=()=>this.instance,this.Get=e=>this.instance({method:"GET",url:e.url,params:e.params,headers:{...e.headers},...e.others}),this.Put=e=>this.instance({method:"PUT",url:e.url,params:e.params,headers:{...e.headers},...e.others}),this.Delete=e=>this.instance({method:"DELETE",url:e.url,params:e.params,headers:{...e.headers},...e.others}),this.Post=e=>this.instance({method:"POST",url:e.url,data:e.params,headers:{...e.headers},...e.others}),this.instance=t.create(e)}},e.setupInterceptors=({instance:e,
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("axios")):"function"==typeof define&&define.amd?define(["exports","axios"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).GlowPod={},e.axios)}(this,function(e,t){"use strict";const s=()=>{},a=()=>{console.log("请配置全局错误处理")},r=()=>{},o=200,n=299;e.GlowPod=class{constructor(e){this.getInstance=()=>this.instance,this.Get=e=>this.instance({method:"GET",url:e.url,params:e.params,headers:{...e.headers},...e.others}),this.Put=e=>this.instance({method:"PUT",url:e.url,params:e.params,headers:{...e.headers},...e.others}),this.Delete=e=>this.instance({method:"DELETE",url:e.url,params:e.params,headers:{...e.headers},...e.others}),this.Post=e=>this.instance({method:"POST",url:e.url,data:e.params,headers:{...e.headers},...e.others}),this.instance=t.create(e)}},e.setupInterceptors=({instance:e,authFailedCaller:t=s,networkSuccessCode:d=200,authFailedCode:i=401,networkFailedCaller:l=a,serverKillCaller:c=r,responseStruct:h={codeName:"code",messageName:"message",dataName:"data"},setHeaders:u=e=>{}})=>{let m=null,p=!0;const f=e=>(m&&clearTimeout(m),m=setTimeout(()=>{if(p)return e.status<=o&&e.status>=n?c():e.data?.[h.codeName]==i?t():e.data?.[h.codeName]!=d?l(e.data):void 0},0),()=>p=!1);e.interceptors.request.use(async e=>(e.headers&&u?.(e.headers),e),e=>(console.log("请求错误拦截器:",e),f(e),Promise.reject(e))),e.interceptors.response.use(e=>{if("blob"===e.config.responseType)return e;if(e.data?.[h.codeName]===d)return e.data?.[h.dataName];{const t=f(e);throw{...e,hiddenDefaultErrorHandler:t}}},e=>{const t=f(e);throw{...e,hiddenDefaultErrorHandler:t}})}});
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { AxiosInstance } from "axios";
|
|
1
|
+
import { AxiosInstance, AxiosRequestHeaders } from "axios";
|
|
2
2
|
import { InterceptorsOptions } from "../model/model";
|
|
3
3
|
/**
|
|
4
4
|
* 设置拦截器
|
|
5
5
|
* @param instance 实例
|
|
6
6
|
* @param options 拦截器配置选项
|
|
7
7
|
* @param options.instance axios实例
|
|
8
|
-
* @param options.authTokenStorageName 认证令牌存储名称,默认为"token"
|
|
9
8
|
* @param options.authFailedCaller 认证失败回调函数
|
|
10
9
|
* @param options.networkSuccessCode 网络请求成功状态码,默认为200
|
|
11
10
|
* @param options.authFailedCode 认证失败状态码,默认为401
|
|
@@ -15,8 +14,10 @@ import { InterceptorsOptions } from "../model/model";
|
|
|
15
14
|
* @param options.responseStruct.codeName 状态码字段名,默认为"code"
|
|
16
15
|
* @param options.responseStruct.messageName 消息字段名,默认为"message"
|
|
17
16
|
* @param options.responseStruct.dataName 数据字段名,默认为"data"
|
|
17
|
+
* @param options.setHeaders 动态设置请求头
|
|
18
18
|
* @returns void
|
|
19
19
|
*/
|
|
20
|
-
export declare const setupInterceptors: ({ instance,
|
|
20
|
+
export declare const setupInterceptors: ({ instance, authFailedCaller, networkSuccessCode, authFailedCode, networkFailedCaller, serverKillCaller, responseStruct, setHeaders, }: InterceptorsOptions & {
|
|
21
21
|
instance: AxiosInstance;
|
|
22
|
+
setHeaders?: (headers: AxiosRequestHeaders) => void;
|
|
22
23
|
}) => void;
|
package/build/model/model.d.ts
CHANGED
|
@@ -13,7 +13,6 @@ export type GlowPodRequestError<T = any, D = any, H = {}> = ({
|
|
|
13
13
|
hiddenDefaultErrorHandler(): void;
|
|
14
14
|
});
|
|
15
15
|
export type InterceptorsOptions = {
|
|
16
|
-
authTokenStorageName?: string;
|
|
17
16
|
networkSuccessCode?: number;
|
|
18
17
|
authFailedCode?: number;
|
|
19
18
|
authFailedCaller?: Function;
|