@andbridge/glowpod 1.2.5 → 1.2.6

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,2 @@
1
+ export declare const encrypt: <T>(key: string, data: T) => Promise<string>;
2
+ export declare const decrypt: (key: string, encrypted: string) => Promise<any>;
@@ -1,3 +1,4 @@
1
1
  export { Core as GlowPod } from "./core/core";
2
2
  export * from "./interceptors/interceptors";
3
+ export { encrypt, decrypt } from "./crypto/crypto";
3
4
  export type { GlowPodRequestError } from "./model/model";
package/build/glowpod.js CHANGED
@@ -1 +1 @@
1
- "use strict";var e=require("axios");const a=200,s=299;exports.GlowPod=class{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})},exports.setupInterceptors=({instance:e,authFailedCaller:t=()=>{},networkSuccessCode:r=200,authFailedCode:n=401,networkFailedCaller:o=()=>{},serverKillCaller:d=()=>{},responseStruct:c={codeName:"code",messageName:"message",dataName:"data"},setHeaders:i=async e=>{}})=>{let l=null,h=!0;const u=e=>(l&&clearTimeout(l),l=setTimeout(()=>{if(h)return e.status<=a&&e.status>=s?d(e):e.data?.[c.codeName]==n?t(e.data):e.data?.[c.codeName]!=r?o(e.data):d(e)},0),()=>h=!1);e.interceptors.request.use(async e=>(e.headers&&await(i?.(e.headers)),e),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}})};
1
+ "use strict";var e=require("axios"),t=require("crypto-js");const r=async(e,r)=>{try{return((e,r)=>""+t.AES.encrypt(e,t.enc.Utf8.parse(r),{mode:t.mode.ECB,padding:t.pad.Pkcs7}))(JSON.stringify(r,null,2).replace(/"(\w+)":/g,'"$1" :'),e)}catch(e){throw Error("加密失败")}},a=async(e,r)=>{try{const a=((e,r)=>t.AES.decrypt(e,t.enc.Utf8.parse(r),{mode:t.mode.ECB,padding:t.pad.Pkcs7}).toString(t.enc.Utf8))(r,e);return JSON.parse(a)}catch(e){throw Error("解密失败")}};exports.GlowPod=class{instance;constructor(t){this.instance=e.create(t)}getInstance=()=>this.instance;Get=async e=>this.instance({method:"GET",url:e.url,params:e.params,headers:{...e.headers},...e.others,encryptKey:e.encryptKey});Put=async e=>this.instance({method:"PUT",url:e.url,data:e.params,headers:{...e.headers},...e.others,encryptKey:e.encryptKey});Delete=async e=>this.instance({method:"DELETE",url:e.url,params:e.params,headers:{...e.headers},...e.others,encryptKey:e.encryptKey});Post=async e=>this.instance({method:"POST",url:e.url,data:e.params,headers:{...e.headers},...e.others,encryptKey:e.encryptKey})},exports.decrypt=a,exports.encrypt=r,exports.setupInterceptors=({instance:e,authFailedCaller:t=()=>{},networkSuccessCode:s=200,authFailedCode:n=401,networkFailedCaller:o=()=>{},serverKillCaller:c=()=>{},responseStruct:i={codeName:"code",messageName:"message",dataName:"data"},setHeaders:d=async e=>{},beforeRequest:l,afterResponse:u})=>{let h=null,y=!0;const m=e=>(h&&clearTimeout(h),h=setTimeout(()=>{if(y)return e.status>200||299>e.status?e.data?.[i.codeName]==n?t(e.data):e.data?.[i.codeName]!=s?o(e.data):c(e):c(e)},0),()=>y=!1);e.interceptors.request.use(async e=>{e.headers&&await(d?.(e.headers));const t=e.encryptKey;if(t){const a=e.method?.toUpperCase();if("POST"===a||"PUT"===a)null!=e.data&&(e.data=await r(t,e.data));else if(null!=e.params){const a=await r(t,e.params);e.params={data:a}}}return l?l(e):e},e=>(m(e),Promise.reject(e))),e.interceptors.response.use(async e=>{const t=e.config.encryptKey;if(t&&"blob"!==e.config.responseType&&"string"==typeof e.data&&(e.data=await a(t,e.data)),u){const t=await u(e);if(void 0!==t)return t}if("blob"===e.config.responseType)return e;if(e.data?.[i.codeName]===s)return e.data?.[i.dataName];{const t=m(e);throw{...e,hiddenDefaultErrorHandler:t}}},e=>{const t=m(e);throw{...e,hiddenDefaultErrorHandler:t}})};
package/build/glowpod.mjs CHANGED
@@ -1 +1 @@
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:n=401,networkFailedCaller:o=()=>{},serverKillCaller:d=()=>{},responseStruct:c={codeName:"code",messageName:"message",dataName:"data"},setHeaders:i=async e=>{}})=>{let l=null,h=!0;const u=e=>(l&&clearTimeout(l),l=setTimeout(()=>{if(h)return e.status<=s&&e.status>=t?d(e):e.data?.[c.codeName]==n?a(e.data):e.data?.[c.codeName]!=r?o(e.data):d(e)},0),()=>h=!1);e.interceptors.request.use(async e=>(e.headers&&await(i?.(e.headers)),e),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};
1
+ import e from"axios";import t from"crypto-js";class r{instance;constructor(t){this.instance=e.create(t)}getInstance=()=>this.instance;Get=async e=>this.instance({method:"GET",url:e.url,params:e.params,headers:{...e.headers},...e.others,encryptKey:e.encryptKey});Put=async e=>this.instance({method:"PUT",url:e.url,data:e.params,headers:{...e.headers},...e.others,encryptKey:e.encryptKey});Delete=async e=>this.instance({method:"DELETE",url:e.url,params:e.params,headers:{...e.headers},...e.others,encryptKey:e.encryptKey});Post=async e=>this.instance({method:"POST",url:e.url,data:e.params,headers:{...e.headers},...e.others,encryptKey:e.encryptKey})}const a=async(e,r)=>{try{return((e,r)=>""+t.AES.encrypt(e,t.enc.Utf8.parse(r),{mode:t.mode.ECB,padding:t.pad.Pkcs7}))(JSON.stringify(r,null,2).replace(/"(\w+)":/g,'"$1" :'),e)}catch(e){throw Error("加密失败")}},s=async(e,r)=>{try{const a=((e,r)=>t.AES.decrypt(e,t.enc.Utf8.parse(r),{mode:t.mode.ECB,padding:t.pad.Pkcs7}).toString(t.enc.Utf8))(r,e);return JSON.parse(a)}catch(e){throw Error("解密失败")}},n=({instance:e,authFailedCaller:t=()=>{},networkSuccessCode:r=200,authFailedCode:n=401,networkFailedCaller:o=()=>{},serverKillCaller:c=()=>{},responseStruct:i={codeName:"code",messageName:"message",dataName:"data"},setHeaders:d=async e=>{},beforeRequest:l,afterResponse:u})=>{let h=null,y=!0;const m=e=>(h&&clearTimeout(h),h=setTimeout(()=>{if(y)return e.status>200||299>e.status?e.data?.[i.codeName]==n?t(e.data):e.data?.[i.codeName]!=r?o(e.data):c(e):c(e)},0),()=>y=!1);e.interceptors.request.use(async e=>{e.headers&&await(d?.(e.headers));const t=e.encryptKey;if(t){const r=e.method?.toUpperCase();if("POST"===r||"PUT"===r)null!=e.data&&(e.data=await a(t,e.data));else if(null!=e.params){const r=await a(t,e.params);e.params={data:r}}}return l?l(e):e},e=>(m(e),Promise.reject(e))),e.interceptors.response.use(async e=>{const t=e.config.encryptKey;if(t&&"blob"!==e.config.responseType&&"string"==typeof e.data&&(e.data=await s(t,e.data)),u){const t=await u(e);if(void 0!==t)return t}if("blob"===e.config.responseType)return e;if(e.data?.[i.codeName]===r)return e.data?.[i.dataName];{const t=m(e);throw{...e,hiddenDefaultErrorHandler:t}}},e=>{const t=m(e);throw{...e,hiddenDefaultErrorHandler:t}})};export{r as GlowPod,s as decrypt,a as encrypt,n as setupInterceptors};
@@ -1 +1 @@
1
- !function(e,a){"object"==typeof exports&&"undefined"!=typeof module?a(exports,require("axios")):"function"==typeof define&&define.amd?define(["exports","axios"],a):a((e="undefined"!=typeof globalThis?globalThis:e||self).GlowPod={},e.axios)}(this,function(e,a){"use strict";const t=200,s=299;e.GlowPod=class{instance;constructor(e){this.instance=a.create(e)}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})},e.setupInterceptors=({instance:e,authFailedCaller:a=()=>{},networkSuccessCode:r=200,authFailedCode:o=401,networkFailedCaller:n=()=>{},serverKillCaller:d=()=>{},responseStruct:i={codeName:"code",messageName:"message",dataName:"data"},setHeaders:c=async e=>{}})=>{let l=null,u=!0;const h=e=>(l&&clearTimeout(l),l=setTimeout(()=>{if(u)return e.status<=t&&e.status>=s?d(e):e.data?.[i.codeName]==o?a(e.data):e.data?.[i.codeName]!=r?n(e.data):d(e)},0),()=>u=!1);e.interceptors.request.use(async e=>(e.headers&&await(c?.(e.headers)),e),e=>(h(e),Promise.reject(e))),e.interceptors.response.use(e=>{if("blob"===e.config.responseType)return e;if(e.data?.[i.codeName]===r)return e.data?.[i.dataName];{const a=h(e);throw{...e,hiddenDefaultErrorHandler:a}}},e=>{const a=h(e);throw{...e,hiddenDefaultErrorHandler:a}})}});
1
+ var e,t;e=this,t=function(e,t,r){"use strict";const a=async(e,t)=>{try{return((e,t)=>""+r.AES.encrypt(e,r.enc.Utf8.parse(t),{mode:r.mode.ECB,padding:r.pad.Pkcs7}))(JSON.stringify(t,null,2).replace(/"(\w+)":/g,'"$1" :'),e)}catch(e){throw Error("加密失败")}},s=async(e,t)=>{try{const a=((e,t)=>r.AES.decrypt(e,r.enc.Utf8.parse(t),{mode:r.mode.ECB,padding:r.pad.Pkcs7}).toString(r.enc.Utf8))(t,e);return JSON.parse(a)}catch(e){throw Error("解密失败")}};e.GlowPod=class{instance;constructor(e){this.instance=t.create(e)}getInstance=()=>this.instance;Get=async e=>this.instance({method:"GET",url:e.url,params:e.params,headers:{...e.headers},...e.others,encryptKey:e.encryptKey});Put=async e=>this.instance({method:"PUT",url:e.url,data:e.params,headers:{...e.headers},...e.others,encryptKey:e.encryptKey});Delete=async e=>this.instance({method:"DELETE",url:e.url,params:e.params,headers:{...e.headers},...e.others,encryptKey:e.encryptKey});Post=async e=>this.instance({method:"POST",url:e.url,data:e.params,headers:{...e.headers},...e.others,encryptKey:e.encryptKey})},e.decrypt=s,e.encrypt=a,e.setupInterceptors=({instance:e,authFailedCaller:t=()=>{},networkSuccessCode:r=200,authFailedCode:n=401,networkFailedCaller:o=()=>{},serverKillCaller:i=()=>{},responseStruct:c={codeName:"code",messageName:"message",dataName:"data"},setHeaders:d=async e=>{},beforeRequest:l,afterResponse:u})=>{let h=null,y=!0;const f=e=>(h&&clearTimeout(h),h=setTimeout(()=>{if(y)return e.status>200||299>e.status?e.data?.[c.codeName]==n?t(e.data):e.data?.[c.codeName]!=r?o(e.data):i(e):i(e)},0),()=>y=!1);e.interceptors.request.use(async e=>{e.headers&&await(d?.(e.headers));const t=e.encryptKey;if(t){const r=e.method?.toUpperCase();if("POST"===r||"PUT"===r)null!=e.data&&(e.data=await a(t,e.data));else if(null!=e.params){const r=await a(t,e.params);e.params={data:r}}}return l?l(e):e},e=>(f(e),Promise.reject(e))),e.interceptors.response.use(async e=>{const t=e.config.encryptKey;if(t&&"blob"!==e.config.responseType&&"string"==typeof e.data&&(e.data=await s(t,e.data)),u){const t=await u(e);if(void 0!==t)return t}if("blob"===e.config.responseType)return e;if(e.data?.[c.codeName]===r)return e.data?.[c.dataName];{const t=f(e);throw{...e,hiddenDefaultErrorHandler:t}}},e=>{const t=f(e);throw{...e,hiddenDefaultErrorHandler:t}})}},"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("axios"),require("crypto-js")):"function"==typeof define&&define.amd?define(["exports","axios","crypto-js"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).GlowPod={},e.axios,e.CryptoJS);
@@ -15,9 +15,11 @@ import type { InterceptorsOptions } from "../model/model";
15
15
  * @param options.responseStruct.messageName 消息字段名,默认为"message"
16
16
  * @param options.responseStruct.dataName 数据字段名,默认为"data"
17
17
  * @param options.setHeaders 动态设置请求头
18
+ * @param options.beforeRequest 请求前钩子,可在发送前修改config
19
+ * @param options.afterResponse 响应后钩子,可在业务处理前修改response
18
20
  * @returns void
19
21
  */
20
- export declare const setupInterceptors: ({ instance, authFailedCaller, networkSuccessCode, authFailedCode, networkFailedCaller, serverKillCaller, responseStruct, setHeaders, }: InterceptorsOptions & {
22
+ export declare const setupInterceptors: ({ instance, authFailedCaller, networkSuccessCode, authFailedCode, networkFailedCaller, serverKillCaller, responseStruct, setHeaders, beforeRequest, afterResponse, }: InterceptorsOptions & {
21
23
  instance: AxiosInstance;
22
24
  setHeaders?: (headers: AxiosRequestHeaders) => Promise<void>;
23
25
  networkFailedCaller?: (error: AxiosResponse["data"]) => void;
@@ -1,4 +1,4 @@
1
- import type { AxiosError, AxiosResponse, RawAxiosRequestHeaders } from "axios";
1
+ import type { AxiosError, AxiosResponse, RawAxiosRequestHeaders, InternalAxiosRequestConfig } from "axios";
2
2
  import { AxiosHeaders } from "axios";
3
3
  export interface Options {
4
4
  url: string;
@@ -6,6 +6,7 @@ export interface Options {
6
6
  [key: string]: string;
7
7
  } & RawAxiosRequestHeaders) | AxiosHeaders;
8
8
  params?: {} | null;
9
+ encryptKey?: string;
9
10
  [key: string]: any;
10
11
  }
11
12
  export type GlowPodRequestError<T = any, D = any, H = {}> = {
@@ -21,4 +22,6 @@ export type InterceptorsOptions = {
21
22
  messageName: string;
22
23
  dataName: string;
23
24
  };
25
+ beforeRequest?: (config: InternalAxiosRequestConfig) => Promise<InternalAxiosRequestConfig>;
26
+ afterResponse?: (response: AxiosResponse) => Promise<any>;
24
27
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@andbridge/glowpod",
3
- "version": "1.2.5",
3
+ "version": "1.2.6",
4
4
  "description": "A axios-based HTTP client library",
5
5
  "main": "build/glowpod.js",
6
6
  "module": "build/glowpod.mjs",
@@ -39,7 +39,20 @@
39
39
  "typescript": "~5.9.3"
40
40
  },
41
41
  "dependencies": {
42
- "axios": "^1.13.2"
42
+ "axios": "^1.15.0",
43
+ "crypto-js": "^4.2.0"
44
+ },
45
+ "peerDependencies": {
46
+ "axios": "^1.15.0",
47
+ "crypto-js": "^4.2.0"
48
+ },
49
+ "peerDependenciesMeta": {
50
+ "axios": {
51
+ "optional": false
52
+ },
53
+ "crypto-js": {
54
+ "optional": false
55
+ }
43
56
  },
44
57
  "repository": {
45
58
  "type": "git",