├── .gitignore ├── .npmignore ├── src ├── config │ ├── requestdata │ │ ├── IGetData.ts │ │ ├── IPutData.ts │ │ ├── IPostData.ts │ │ ├── IDeleteData.ts │ │ └── IPatchData.ts │ ├── IFormParamType.ts │ ├── IUrlSearchParamType.ts │ ├── IFormData.ts │ ├── builder │ │ ├── PutBuilder.ts │ │ ├── PostBuilder.ts │ │ ├── DeleteBuilder.ts │ │ ├── GetBuilder.ts │ │ ├── PatchBuilder.ts │ │ ├── AbstractUrlSearchAndFormDataBuilder.ts │ │ └── AbstractBuilder.ts │ └── IConfig.ts ├── actuator │ ├── message │ │ ├── IErrorMessage.ts │ │ └── ErrorMessage.ts │ ├── IRequest.ts │ ├── IRequestActuator.ts │ ├── method │ │ ├── GetRequestActuator.ts │ │ ├── PutRequestActuator.ts │ │ ├── DeleteRequestActuator.ts │ │ ├── PatchRequestActuator.ts │ │ └── PostRequestActuator.ts │ ├── RequestActuator.ts │ ├── distribution │ │ └── Distribution.ts │ └── AbstractRequestActuator.ts ├── factory │ ├── IAxiosInstanceConfig.ts │ ├── AxiosInstanceFactory.ts │ └── AxiosInstanceFactoryBuilder.ts ├── interceptor │ ├── response │ │ └── IResponseInterceptor.ts │ └── request │ │ └── IRequestInterceptor.ts ├── index.ts ├── HelpConfig.ts └── Http.ts ├── types ├── config │ ├── requestdata │ │ ├── IGetData.d.ts │ │ ├── IPutData.d.ts │ │ ├── IPostData.d.ts │ │ ├── IDeleteData.d.ts │ │ └── IPatchData.d.ts │ ├── IFormParamType.d.ts │ ├── IUrlSearchParamType.d.ts │ ├── IFormData.d.ts │ ├── builder │ │ ├── PostBuilder.d.ts │ │ ├── PutBuilder.d.ts │ │ ├── DeleteBuilder.d.ts │ │ ├── GetBuilder.d.ts │ │ ├── PatchBuilder.d.ts │ │ ├── AbstractUrlSearchAndFormDataBuilder.d.ts │ │ └── AbstractBuilder.d.ts │ └── IConfig.d.ts ├── actuator │ ├── message │ │ ├── IErrorMessage.d.ts │ │ └── ErrorMessage.d.ts │ ├── IRequest.d.ts │ ├── IRequestActuator.d.ts │ ├── distribution │ │ └── Distribution.d.ts │ ├── RequestActuator.d.ts │ ├── method │ │ ├── GetRequestActuator.d.ts │ │ ├── PutRequestActuator.d.ts │ │ ├── DeleteRequestActuator.d.ts │ │ ├── PatchRequestActuator.d.ts │ │ └── PostRequestActuator.d.ts │ └── AbstractRequestActuator.d.ts ├── factory │ ├── IAxiosInstanceConfig.d.ts │ ├── AxiosInstanceFactory.d.ts │ └── AxiosInstanceFactoryBuilder.d.ts ├── interceptor │ ├── response │ │ └── IResponseInterceptor.d.ts │ └── request │ │ └── IRequestInterceptor.d.ts ├── HelpConfig.d.ts ├── index.d.ts └── Http.d.ts ├── dist ├── actuator │ ├── IRequest.js │ ├── IRequest.js.map │ ├── IRequestActuator.js │ ├── message │ │ ├── IErrorMessage.js │ │ ├── IErrorMessage.js.map │ │ ├── ErrorMessage.js.map │ │ └── ErrorMessage.js │ ├── IRequestActuator.js.map │ ├── method │ │ ├── GetRequestActuator.js.map │ │ ├── GetRequestActuator.js │ │ ├── PutRequestActuator.js.map │ │ ├── DeleteRequestActuator.js.map │ │ ├── PatchRequestActuator.js.map │ │ ├── PutRequestActuator.js │ │ ├── DeleteRequestActuator.js │ │ ├── PatchRequestActuator.js │ │ ├── PostRequestActuator.js.map │ │ └── PostRequestActuator.js │ ├── distribution │ │ ├── Distribution.js.map │ │ └── Distribution.js │ ├── AbstractRequestActuator.js.map │ ├── RequestActuator.js.map │ ├── AbstractRequestActuator.js │ └── RequestActuator.js ├── config │ ├── IFormData.js │ ├── IFormData.js.map │ ├── IFormParamType.js │ ├── requestdata │ │ ├── IGetData.js │ │ ├── IPostData.js │ │ ├── IPutData.js │ │ ├── IDeleteData.js │ │ ├── IPatchData.js │ │ ├── IGetData.js.map │ │ ├── IPutData.js.map │ │ ├── IPatchData.js.map │ │ ├── IPostData.js.map │ │ └── IDeleteData.js.map │ ├── IFormParamType.js.map │ ├── IUrlSearchParamType.js │ ├── IUrlSearchParamType.js.map │ ├── builder │ │ ├── GetBuilder.js.map │ │ ├── PutBuilder.js.map │ │ ├── PostBuilder.js.map │ │ ├── DeleteBuilder.js.map │ │ ├── PatchBuilder.js.map │ │ ├── AbstractUrlSearchAndFormDataBuilder.js.map │ │ ├── GetBuilder.js │ │ ├── PutBuilder.js │ │ ├── PostBuilder.js │ │ ├── DeleteBuilder.js │ │ ├── AbstractBuilder.js.map │ │ ├── PatchBuilder.js │ │ ├── AbstractBuilder.js │ │ └── AbstractUrlSearchAndFormDataBuilder.js │ ├── IConfig.js.map │ └── IConfig.js ├── factory │ ├── IAxiosInstanceConfig.js │ ├── IAxiosInstanceConfig.js.map │ ├── AxiosInstanceFactory.js.map │ ├── AxiosInstanceFactoryBuilder.js.map │ ├── AxiosInstanceFactory.js │ └── AxiosInstanceFactoryBuilder.js ├── interceptor │ ├── request │ │ ├── IRequestInterceptor.js │ │ └── IRequestInterceptor.js.map │ └── response │ │ ├── IResponseInterceptor.js │ │ └── IResponseInterceptor.js.map ├── HelpConfig.js.map ├── index.js.map ├── index.js ├── HelpConfig.js ├── Http.js.map └── Http.js ├── test ├── test.html └── test.js ├── .github ├── workflows │ ├── build_when_new_tag.yml │ └── main.yml └── dependabot.yml ├── webpack.config.js ├── tsconfig.json ├── package.json ├── README.md └── LICENSE /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | .idea/ 3 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | test/ 2 | .idea/ 3 | src/ 4 | tsconfig.json 5 | webpack.config.js 6 | -------------------------------------------------------------------------------- /src/config/requestdata/IGetData.ts: -------------------------------------------------------------------------------- 1 | export default interface IGetData { 2 | 3 | } -------------------------------------------------------------------------------- /types/config/requestdata/IGetData.d.ts: -------------------------------------------------------------------------------- 1 | export default interface IGetData { 2 | } 3 | -------------------------------------------------------------------------------- /src/config/IFormParamType.ts: -------------------------------------------------------------------------------- 1 | export default interface IFormParamType { 2 | [index: string]: string | Blob 3 | } -------------------------------------------------------------------------------- /src/config/IUrlSearchParamType.ts: -------------------------------------------------------------------------------- 1 | export default interface IUrlSearchParamType { 2 | [index: string]: string 3 | } -------------------------------------------------------------------------------- /types/config/IFormParamType.d.ts: -------------------------------------------------------------------------------- 1 | export default interface IFormParamType { 2 | [index: string]: string | Blob; 3 | } 4 | -------------------------------------------------------------------------------- /types/config/IUrlSearchParamType.d.ts: -------------------------------------------------------------------------------- 1 | export default interface IUrlSearchParamType { 2 | [index: string]: string; 3 | } 4 | -------------------------------------------------------------------------------- /src/actuator/message/IErrorMessage.ts: -------------------------------------------------------------------------------- 1 | export default interface IErrorMessage { 2 | showErrorToast(title: string, msg: any): void; 3 | } -------------------------------------------------------------------------------- /dist/actuator/IRequest.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | //# sourceMappingURL=IRequest.js.map -------------------------------------------------------------------------------- /dist/config/IFormData.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | //# sourceMappingURL=IFormData.js.map -------------------------------------------------------------------------------- /dist/config/IFormData.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"IFormData.js","sourceRoot":"","sources":["../../src/config/IFormData.ts"],"names":[],"mappings":""} -------------------------------------------------------------------------------- /src/config/IFormData.ts: -------------------------------------------------------------------------------- 1 | export default interface IFormData { 2 | param: FormData, 3 | uploadProgress?: (progress: number) => void 4 | } 5 | -------------------------------------------------------------------------------- /types/actuator/message/IErrorMessage.d.ts: -------------------------------------------------------------------------------- 1 | export default interface IErrorMessage { 2 | showErrorToast(title: string, msg: any): void; 3 | } 4 | -------------------------------------------------------------------------------- /dist/actuator/IRequest.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"IRequest.js","sourceRoot":"","sources":["../../src/actuator/IRequest.ts"],"names":[],"mappings":""} -------------------------------------------------------------------------------- /types/config/IFormData.d.ts: -------------------------------------------------------------------------------- 1 | export default interface IFormData { 2 | param: FormData; 3 | uploadProgress?: (progress: number) => void; 4 | } 5 | -------------------------------------------------------------------------------- /dist/config/IFormParamType.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | //# sourceMappingURL=IFormParamType.js.map -------------------------------------------------------------------------------- /dist/config/requestdata/IGetData.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | //# sourceMappingURL=IGetData.js.map -------------------------------------------------------------------------------- /dist/config/requestdata/IPostData.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | //# sourceMappingURL=IPostData.js.map -------------------------------------------------------------------------------- /dist/config/requestdata/IPutData.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | //# sourceMappingURL=IPutData.js.map -------------------------------------------------------------------------------- /dist/actuator/IRequestActuator.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | //# sourceMappingURL=IRequestActuator.js.map -------------------------------------------------------------------------------- /dist/config/IFormParamType.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"IFormParamType.js","sourceRoot":"","sources":["../../src/config/IFormParamType.ts"],"names":[],"mappings":""} -------------------------------------------------------------------------------- /dist/config/requestdata/IDeleteData.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | //# sourceMappingURL=IDeleteData.js.map -------------------------------------------------------------------------------- /dist/config/requestdata/IPatchData.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | //# sourceMappingURL=IPatchData.js.map -------------------------------------------------------------------------------- /dist/actuator/message/IErrorMessage.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | //# sourceMappingURL=IErrorMessage.js.map -------------------------------------------------------------------------------- /dist/config/IUrlSearchParamType.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | //# sourceMappingURL=IUrlSearchParamType.js.map -------------------------------------------------------------------------------- /src/factory/IAxiosInstanceConfig.ts: -------------------------------------------------------------------------------- 1 | import {AxiosRequestConfig} from "axios"; 2 | 3 | export default interface IAxiosInstanceConfig extends AxiosRequestConfig { 4 | } -------------------------------------------------------------------------------- /dist/actuator/IRequestActuator.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"IRequestActuator.js","sourceRoot":"","sources":["../../src/actuator/IRequestActuator.ts"],"names":[],"mappings":""} -------------------------------------------------------------------------------- /dist/config/requestdata/IGetData.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"IGetData.js","sourceRoot":"","sources":["../../../src/config/requestdata/IGetData.ts"],"names":[],"mappings":""} -------------------------------------------------------------------------------- /dist/config/requestdata/IPutData.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"IPutData.js","sourceRoot":"","sources":["../../../src/config/requestdata/IPutData.ts"],"names":[],"mappings":""} -------------------------------------------------------------------------------- /dist/factory/IAxiosInstanceConfig.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | //# sourceMappingURL=IAxiosInstanceConfig.js.map -------------------------------------------------------------------------------- /types/factory/IAxiosInstanceConfig.d.ts: -------------------------------------------------------------------------------- 1 | import { AxiosRequestConfig } from "axios"; 2 | export default interface IAxiosInstanceConfig extends AxiosRequestConfig { 3 | } 4 | -------------------------------------------------------------------------------- /dist/config/IUrlSearchParamType.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"IUrlSearchParamType.js","sourceRoot":"","sources":["../../src/config/IUrlSearchParamType.ts"],"names":[],"mappings":""} -------------------------------------------------------------------------------- /dist/config/requestdata/IPatchData.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"IPatchData.js","sourceRoot":"","sources":["../../../src/config/requestdata/IPatchData.ts"],"names":[],"mappings":""} -------------------------------------------------------------------------------- /dist/config/requestdata/IPostData.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"IPostData.js","sourceRoot":"","sources":["../../../src/config/requestdata/IPostData.ts"],"names":[],"mappings":""} -------------------------------------------------------------------------------- /dist/actuator/message/IErrorMessage.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"IErrorMessage.js","sourceRoot":"","sources":["../../../src/actuator/message/IErrorMessage.ts"],"names":[],"mappings":""} -------------------------------------------------------------------------------- /dist/config/requestdata/IDeleteData.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"IDeleteData.js","sourceRoot":"","sources":["../../../src/config/requestdata/IDeleteData.ts"],"names":[],"mappings":""} -------------------------------------------------------------------------------- /dist/factory/IAxiosInstanceConfig.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"IAxiosInstanceConfig.js","sourceRoot":"","sources":["../../src/factory/IAxiosInstanceConfig.ts"],"names":[],"mappings":""} -------------------------------------------------------------------------------- /dist/interceptor/request/IRequestInterceptor.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | //# sourceMappingURL=IRequestInterceptor.js.map -------------------------------------------------------------------------------- /dist/interceptor/response/IResponseInterceptor.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | //# sourceMappingURL=IResponseInterceptor.js.map -------------------------------------------------------------------------------- /dist/interceptor/request/IRequestInterceptor.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"IRequestInterceptor.js","sourceRoot":"","sources":["../../../src/interceptor/request/IRequestInterceptor.ts"],"names":[],"mappings":""} -------------------------------------------------------------------------------- /dist/interceptor/response/IResponseInterceptor.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"IResponseInterceptor.js","sourceRoot":"","sources":["../../../src/interceptor/response/IResponseInterceptor.ts"],"names":[],"mappings":""} -------------------------------------------------------------------------------- /src/actuator/IRequest.ts: -------------------------------------------------------------------------------- 1 | import IConfig, {HttpRequestMethods} from "../config/IConfig"; 2 | 3 | export default interface IRequest { 4 | url: string, 5 | method: HttpRequestMethods, 6 | config: IConfig 7 | } -------------------------------------------------------------------------------- /test/test.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Title 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /types/actuator/IRequest.d.ts: -------------------------------------------------------------------------------- 1 | import IConfig, { HttpRequestMethods } from "../config/IConfig"; 2 | export default interface IRequest { 3 | url: string; 4 | method: HttpRequestMethods; 5 | config: IConfig; 6 | } 7 | -------------------------------------------------------------------------------- /types/config/builder/PostBuilder.d.ts: -------------------------------------------------------------------------------- 1 | import AbstractUrlSearchAndFormDataBuilder from "./AbstractUrlSearchAndFormDataBuilder"; 2 | export default class PostBuilder extends AbstractUrlSearchAndFormDataBuilder { 3 | constructor(url: string); 4 | } 5 | -------------------------------------------------------------------------------- /types/config/builder/PutBuilder.d.ts: -------------------------------------------------------------------------------- 1 | import AbstractUrlSearchAndFormDataBuilder from "./AbstractUrlSearchAndFormDataBuilder"; 2 | export default class PutBuilder extends AbstractUrlSearchAndFormDataBuilder { 3 | constructor(url: string); 4 | } 5 | -------------------------------------------------------------------------------- /types/config/builder/DeleteBuilder.d.ts: -------------------------------------------------------------------------------- 1 | import AbstractUrlSearchAndFormDataBuilder from "./AbstractUrlSearchAndFormDataBuilder"; 2 | export default class DeleteBuilder extends AbstractUrlSearchAndFormDataBuilder { 3 | constructor(url: string); 4 | } 5 | -------------------------------------------------------------------------------- /types/config/builder/GetBuilder.d.ts: -------------------------------------------------------------------------------- 1 | import AbstractBuilder from "./AbstractBuilder"; 2 | import IGetData from "../requestdata/IGetData"; 3 | export default class GetBuilder extends AbstractBuilder implements IGetData { 4 | constructor(url: string); 5 | } 6 | -------------------------------------------------------------------------------- /src/interceptor/response/IResponseInterceptor.ts: -------------------------------------------------------------------------------- 1 | import {AxiosResponse} from "axios"; 2 | 3 | export default interface IResponseInterceptor { 4 | onFulfilled?: (response: AxiosResponse) => AxiosResponse | Promise; 5 | 6 | onRejected?: (error: any) => any; 7 | } -------------------------------------------------------------------------------- /types/interceptor/response/IResponseInterceptor.d.ts: -------------------------------------------------------------------------------- 1 | import { AxiosResponse } from "axios"; 2 | export default interface IResponseInterceptor { 3 | onFulfilled?: (response: AxiosResponse) => AxiosResponse | Promise; 4 | onRejected?: (error: any) => any; 5 | } 6 | -------------------------------------------------------------------------------- /src/interceptor/request/IRequestInterceptor.ts: -------------------------------------------------------------------------------- 1 | import {AxiosRequestConfig} from "axios"; 2 | 3 | export default interface IRequestInterceptor { 4 | onFulfilled?: (value: AxiosRequestConfig) => AxiosRequestConfig | Promise; 5 | 6 | onRejected?: (error: any) => any; 7 | } -------------------------------------------------------------------------------- /types/interceptor/request/IRequestInterceptor.d.ts: -------------------------------------------------------------------------------- 1 | import { AxiosRequestConfig } from "axios"; 2 | export default interface IRequestInterceptor { 3 | onFulfilled?: (value: AxiosRequestConfig) => AxiosRequestConfig | Promise; 4 | onRejected?: (error: any) => any; 5 | } 6 | -------------------------------------------------------------------------------- /dist/config/builder/GetBuilder.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"GetBuilder.js","sourceRoot":"","sources":["../../../src/config/builder/GetBuilder.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,sEAAgD;AAChD,sCAA8C;AAG9C;IAAwC,8BAAe;IACnD,oBAAY,GAAW;eACnB,kBAAM,4BAAkB,CAAC,GAAG,EAAE,GAAG,CAAC;IACtC,CAAC;IACL,iBAAC;AAAD,CAAC,AAJD,CAAwC,yBAAe,GAItD"} -------------------------------------------------------------------------------- /dist/config/builder/PutBuilder.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"PutBuilder.js","sourceRoot":"","sources":["../../../src/config/builder/PutBuilder.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,8GAAwF;AACxF,sCAA8C;AAE9C;IAAwC,8BAAmC;IACvE,oBAAY,GAAW;eACnB,kBAAM,4BAAkB,CAAC,GAAG,EAAE,GAAG,CAAC;IACtC,CAAC;IACL,iBAAC;AAAD,CAAC,AAJD,CAAwC,6CAAmC,GAI1E"} -------------------------------------------------------------------------------- /dist/config/builder/PostBuilder.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"PostBuilder.js","sourceRoot":"","sources":["../../../src/config/builder/PostBuilder.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,sCAA8C;AAC9C,8GAAwF;AAExF;IAAyC,+BAAmC;IACxE,qBAAY,GAAW;eACnB,kBAAM,4BAAkB,CAAC,IAAI,EAAE,GAAG,CAAC;IACvC,CAAC;IACL,kBAAC;AAAD,CAAC,AAJD,CAAyC,6CAAmC,GAI3E"} -------------------------------------------------------------------------------- /dist/config/builder/DeleteBuilder.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"DeleteBuilder.js","sourceRoot":"","sources":["../../../src/config/builder/DeleteBuilder.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,8GAAwF;AACxF,sCAA8C;AAE9C;IAA2C,iCAAmC;IAC1E,uBAAY,GAAW;eACnB,kBAAM,4BAAkB,CAAC,MAAM,EAAE,GAAG,CAAC;IACzC,CAAC;IACL,oBAAC;AAAD,CAAC,AAJD,CAA2C,6CAAmC,GAI7E"} -------------------------------------------------------------------------------- /src/config/builder/PutBuilder.ts: -------------------------------------------------------------------------------- 1 | import AbstractUrlSearchAndFormDataBuilder from "./AbstractUrlSearchAndFormDataBuilder"; 2 | import {HttpRequestMethods} from "../IConfig"; 3 | 4 | export default class PutBuilder extends AbstractUrlSearchAndFormDataBuilder { 5 | constructor(url: string) { 6 | super(HttpRequestMethods.PUT, url); 7 | } 8 | } -------------------------------------------------------------------------------- /src/config/builder/PostBuilder.ts: -------------------------------------------------------------------------------- 1 | import {HttpRequestMethods} from "../IConfig"; 2 | import AbstractUrlSearchAndFormDataBuilder from "./AbstractUrlSearchAndFormDataBuilder"; 3 | 4 | export default class PostBuilder extends AbstractUrlSearchAndFormDataBuilder { 5 | constructor(url: string) { 6 | super(HttpRequestMethods.POST, url); 7 | } 8 | } -------------------------------------------------------------------------------- /src/config/builder/DeleteBuilder.ts: -------------------------------------------------------------------------------- 1 | import AbstractUrlSearchAndFormDataBuilder from "./AbstractUrlSearchAndFormDataBuilder"; 2 | import {HttpRequestMethods} from "../IConfig"; 3 | 4 | export default class DeleteBuilder extends AbstractUrlSearchAndFormDataBuilder { 5 | constructor(url: string) { 6 | super(HttpRequestMethods.DELETE, url); 7 | } 8 | } -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | import Http from "./Http"; 2 | import HelpConfig from "./HelpConfig"; 3 | 4 | export const Get = Http.Get; 5 | export const Post = Http.Post; 6 | export const Delete = Http.Delete; 7 | export const Patch = Http.Patch; 8 | export const Put = Http.Put; 9 | export const Download = Http.Download; 10 | export const AxiosHelperConfig = HelpConfig; -------------------------------------------------------------------------------- /src/config/builder/GetBuilder.ts: -------------------------------------------------------------------------------- 1 | import AbstractBuilder from "./AbstractBuilder"; 2 | import {HttpRequestMethods} from "../IConfig"; 3 | import IGetData from "../requestdata/IGetData"; 4 | 5 | export default class GetBuilder extends AbstractBuilder implements IGetData { 6 | constructor(url: string) { 7 | super(HttpRequestMethods.GET, url); 8 | } 9 | } -------------------------------------------------------------------------------- /types/config/builder/PatchBuilder.d.ts: -------------------------------------------------------------------------------- 1 | import AbstractUrlSearchAndFormDataBuilder from "./AbstractUrlSearchAndFormDataBuilder"; 2 | import IPatchData from "../requestdata/IPatchData"; 3 | export default class PatchBuilder extends AbstractUrlSearchAndFormDataBuilder implements IPatchData { 4 | constructor(url: string); 5 | withJson(param: Object): this; 6 | } 7 | -------------------------------------------------------------------------------- /src/actuator/IRequestActuator.ts: -------------------------------------------------------------------------------- 1 | import {AxiosInstance, AxiosResponse} from "axios"; 2 | import IRequest from "./IRequest"; 3 | import {HttpRequestMethods} from "../config/IConfig"; 4 | 5 | export default interface IRequestActuator { 6 | canInvoke(method: HttpRequestMethods): boolean; 7 | 8 | invoke(instance: AxiosInstance, request: IRequest): Promise; 9 | } -------------------------------------------------------------------------------- /types/actuator/IRequestActuator.d.ts: -------------------------------------------------------------------------------- 1 | import { AxiosInstance, AxiosResponse } from "axios"; 2 | import IRequest from "./IRequest"; 3 | import { HttpRequestMethods } from "../config/IConfig"; 4 | export default interface IRequestActuator { 5 | canInvoke(method: HttpRequestMethods): boolean; 6 | invoke(instance: AxiosInstance, request: IRequest): Promise; 7 | } 8 | -------------------------------------------------------------------------------- /dist/HelpConfig.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"HelpConfig.js","sourceRoot":"","sources":["../src/HelpConfig.ts"],"names":[],"mappings":";;;;;AACA,sGAAgF;AAChF,iFAA2D;AAE3D;IAAA;IAQA,CAAC;IAHG,sBAAW,0BAAY;aAAvB,UAAwB,QAAuB;YAC3C,sBAAY,CAAC,YAAY,GAAG,QAAQ,CAAC;QACzC,CAAC;;;OAAA;IANM,+BAAoB,GAAG,IAAI,qCAA2B,EAAE,CAAC;IAEzD,wBAAa,GAAG,sBAAY,CAAC,OAAO,CAAC;IAKhD,iBAAC;CAAA,AARD,IAQC;kBARoB,UAAU"} -------------------------------------------------------------------------------- /dist/index.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;AAAA,gDAA0B;AAC1B,4DAAsC;AAEzB,QAAA,GAAG,GAAG,cAAI,CAAC,GAAG,CAAC;AACf,QAAA,IAAI,GAAG,cAAI,CAAC,IAAI,CAAC;AACjB,QAAA,MAAM,GAAG,cAAI,CAAC,MAAM,CAAC;AACrB,QAAA,KAAK,GAAG,cAAI,CAAC,KAAK,CAAC;AACnB,QAAA,GAAG,GAAG,cAAI,CAAC,GAAG,CAAC;AACf,QAAA,QAAQ,GAAG,cAAI,CAAC,QAAQ,CAAC;AACzB,QAAA,iBAAiB,GAAG,oBAAU,CAAC"} -------------------------------------------------------------------------------- /types/actuator/distribution/Distribution.d.ts: -------------------------------------------------------------------------------- 1 | import { HttpRequestMethods } from "../../config/IConfig"; 2 | import { AxiosInstance, AxiosResponse } from "axios"; 3 | import IRequest from "../IRequest"; 4 | export default class Distribution { 5 | private readonly method; 6 | constructor(method: HttpRequestMethods); 7 | distribution(instance: AxiosInstance, request: IRequest): Promise; 8 | } 9 | -------------------------------------------------------------------------------- /.github/workflows/build_when_new_tag.yml: -------------------------------------------------------------------------------- 1 | name: Build When New Tag 2 | on: 3 | push: 4 | tags: 5 | - 'v*' 6 | jobs: 7 | build: 8 | runs-on: ubuntu-latest 9 | steps: 10 | - uses: actions/checkout@v2 11 | - name: Npm Install And Build 12 | uses: actions/setup-node@v2 13 | with: 14 | node-version: '14' 15 | - run: npm install 16 | - run: npm run build 17 | -------------------------------------------------------------------------------- /src/config/requestdata/IPutData.ts: -------------------------------------------------------------------------------- 1 | import IFormParamType from "../IFormParamType"; 2 | import AbstractBuilder from "../builder/AbstractBuilder"; 3 | import IUrlSearchParamType from "../IUrlSearchParamType"; 4 | 5 | export default interface IPutData { 6 | withFormData(params: IFormParamType, uploadProgress?: (progress: number) => void): AbstractBuilder, 7 | 8 | withURLSearchParams(params: IUrlSearchParamType): AbstractBuilder 9 | } -------------------------------------------------------------------------------- /types/config/requestdata/IPutData.d.ts: -------------------------------------------------------------------------------- 1 | import IFormParamType from "../IFormParamType"; 2 | import AbstractBuilder from "../builder/AbstractBuilder"; 3 | import IUrlSearchParamType from "../IUrlSearchParamType"; 4 | export default interface IPutData { 5 | withFormData(params: IFormParamType, uploadProgress?: (progress: number) => void): AbstractBuilder; 6 | withURLSearchParams(params: IUrlSearchParamType): AbstractBuilder; 7 | } 8 | -------------------------------------------------------------------------------- /dist/actuator/method/GetRequestActuator.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"GetRequestActuator.js","sourceRoot":"","sources":["../../../src/actuator/method/GetRequestActuator.ts"],"names":[],"mappings":";;AAGA,gDAAwD;AAExD;IAAA;IAQA,CAAC;IAPG,sCAAS,GAAT,UAAU,MAA0B;QAChC,OAAO,MAAM,KAAK,4BAAkB,CAAC,GAAG,CAAC;IAC7C,CAAC;IAED,mCAAM,GAAN,UAAO,QAAuB,EAAE,OAAiB;QAC7C,OAAO,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IACrC,CAAC;IACL,yBAAC;AAAD,CAAC,AARD,IAQC"} -------------------------------------------------------------------------------- /src/config/requestdata/IPostData.ts: -------------------------------------------------------------------------------- 1 | import IFormParamType from "../IFormParamType"; 2 | import AbstractBuilder from "../builder/AbstractBuilder"; 3 | import IUrlSearchParamType from "../IUrlSearchParamType"; 4 | 5 | export default interface IPostData { 6 | withFormData(params: IFormParamType, uploadProgress?: (progress: number) => void): AbstractBuilder, 7 | 8 | withURLSearchParams(params: IUrlSearchParamType): AbstractBuilder 9 | } -------------------------------------------------------------------------------- /types/config/requestdata/IPostData.d.ts: -------------------------------------------------------------------------------- 1 | import IFormParamType from "../IFormParamType"; 2 | import AbstractBuilder from "../builder/AbstractBuilder"; 3 | import IUrlSearchParamType from "../IUrlSearchParamType"; 4 | export default interface IPostData { 5 | withFormData(params: IFormParamType, uploadProgress?: (progress: number) => void): AbstractBuilder; 6 | withURLSearchParams(params: IUrlSearchParamType): AbstractBuilder; 7 | } 8 | -------------------------------------------------------------------------------- /src/config/requestdata/IDeleteData.ts: -------------------------------------------------------------------------------- 1 | import IFormParamType from "../IFormParamType"; 2 | import AbstractBuilder from "../builder/AbstractBuilder"; 3 | import IUrlSearchParamType from "../IUrlSearchParamType"; 4 | 5 | export default interface IDeleteData { 6 | withFormData(params: IFormParamType, uploadProgress?: (progress: number) => void): AbstractBuilder, 7 | 8 | withURLSearchParams(params: IUrlSearchParamType): AbstractBuilder 9 | } -------------------------------------------------------------------------------- /types/config/requestdata/IDeleteData.d.ts: -------------------------------------------------------------------------------- 1 | import IFormParamType from "../IFormParamType"; 2 | import AbstractBuilder from "../builder/AbstractBuilder"; 3 | import IUrlSearchParamType from "../IUrlSearchParamType"; 4 | export default interface IDeleteData { 5 | withFormData(params: IFormParamType, uploadProgress?: (progress: number) => void): AbstractBuilder; 6 | withURLSearchParams(params: IUrlSearchParamType): AbstractBuilder; 7 | } 8 | -------------------------------------------------------------------------------- /dist/config/IConfig.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"IConfig.js","sourceRoot":"","sources":["../../src/config/IConfig.ts"],"names":[],"mappings":";;AAyBA,IAAY,kBAMX;AAND,WAAY,kBAAkB;IAC1B,yDAAG,CAAA;IACH,2DAAI,CAAA;IACJ,+DAAM,CAAA;IACN,yDAAG,CAAA;IACH,6DAAK,CAAA;AACT,CAAC,EANW,kBAAkB,GAAlB,0BAAkB,KAAlB,0BAAkB,QAM7B;AAED,IAAY,QAKX;AALD,WAAY,QAAQ;IAChB,uCAAI,CAAA;IACJ,iDAAS,CAAA;IACT,+DAAgB,CAAA;IAChB,uCAAI,CAAA;AACR,CAAC,EALW,QAAQ,GAAR,gBAAQ,KAAR,gBAAQ,QAKnB"} -------------------------------------------------------------------------------- /types/HelpConfig.d.ts: -------------------------------------------------------------------------------- 1 | import IErrorMessage from "./actuator/message/IErrorMessage"; 2 | import AxiosInstanceFactoryBuilder from "./factory/AxiosInstanceFactoryBuilder"; 3 | import ErrorMessage from "./actuator/message/ErrorMessage"; 4 | export default class HelpConfig { 5 | static axiosInstanceBuilder: AxiosInstanceFactoryBuilder; 6 | static onceMsgFinish: typeof ErrorMessage.showOff; 7 | static set errorMsgImpl(errorMsg: IErrorMessage); 8 | } 9 | -------------------------------------------------------------------------------- /types/index.d.ts: -------------------------------------------------------------------------------- 1 | import Http from "./Http"; 2 | import HelpConfig from "./HelpConfig"; 3 | export declare const Get: typeof Http.Get; 4 | export declare const Post: typeof Http.Post; 5 | export declare const Delete: typeof Http.Delete; 6 | export declare const Patch: typeof Http.Patch; 7 | export declare const Put: typeof Http.Put; 8 | export declare const Download: typeof Http.Download; 9 | export declare const AxiosHelperConfig: typeof HelpConfig; 10 | -------------------------------------------------------------------------------- /types/actuator/RequestActuator.d.ts: -------------------------------------------------------------------------------- 1 | import AbstractRequestActuator from "./AbstractRequestActuator"; 2 | import { AxiosError, AxiosResponse } from "axios"; 3 | import IRequest from "./IRequest"; 4 | export default class RequestActuator extends AbstractRequestActuator { 5 | constructor(request: IRequest); 6 | protected onResponse(response: AxiosResponse): void; 7 | protected onError(error: AxiosError): void; 8 | protected onAfter(): void; 9 | } 10 | -------------------------------------------------------------------------------- /types/actuator/method/GetRequestActuator.d.ts: -------------------------------------------------------------------------------- 1 | import IRequestActuator from "../IRequestActuator"; 2 | import { AxiosInstance, AxiosResponse } from "axios"; 3 | import IRequest from "../IRequest"; 4 | import { HttpRequestMethods } from "../../config/IConfig"; 5 | export default class GetRequestActuator implements IRequestActuator { 6 | canInvoke(method: HttpRequestMethods): boolean; 7 | invoke(instance: AxiosInstance, request: IRequest): Promise; 8 | } 9 | -------------------------------------------------------------------------------- /types/actuator/method/PutRequestActuator.d.ts: -------------------------------------------------------------------------------- 1 | import IRequestActuator from "../IRequestActuator"; 2 | import { AxiosInstance, AxiosResponse } from "axios"; 3 | import IRequest from "../IRequest"; 4 | import { HttpRequestMethods } from "../../config/IConfig"; 5 | export default class PutRequestActuator implements IRequestActuator { 6 | canInvoke(method: HttpRequestMethods): boolean; 7 | invoke(instance: AxiosInstance, request: IRequest): Promise; 8 | } 9 | -------------------------------------------------------------------------------- /types/actuator/method/DeleteRequestActuator.d.ts: -------------------------------------------------------------------------------- 1 | import IRequestActuator from "../IRequestActuator"; 2 | import { AxiosInstance, AxiosResponse } from "axios"; 3 | import IRequest from "../IRequest"; 4 | import { HttpRequestMethods } from "../../config/IConfig"; 5 | export default class DeleteRequestActuator implements IRequestActuator { 6 | canInvoke(method: HttpRequestMethods): boolean; 7 | invoke(instance: AxiosInstance, request: IRequest): Promise; 8 | } 9 | -------------------------------------------------------------------------------- /types/actuator/method/PatchRequestActuator.d.ts: -------------------------------------------------------------------------------- 1 | import IRequestActuator from "../IRequestActuator"; 2 | import { AxiosInstance, AxiosResponse } from "axios"; 3 | import IRequest from "../IRequest"; 4 | import { HttpRequestMethods } from "../../config/IConfig"; 5 | export default class PatchRequestActuator implements IRequestActuator { 6 | canInvoke(method: HttpRequestMethods): boolean; 7 | invoke(instance: AxiosInstance, request: IRequest): Promise; 8 | } 9 | -------------------------------------------------------------------------------- /types/actuator/method/PostRequestActuator.d.ts: -------------------------------------------------------------------------------- 1 | import IRequestActuator from "../IRequestActuator"; 2 | import { AxiosInstance, AxiosResponse } from "axios"; 3 | import IRequest from "../IRequest"; 4 | import { HttpRequestMethods } from "../../config/IConfig"; 5 | export default class PostRequestActuator implements IRequestActuator { 6 | canInvoke(method: HttpRequestMethods): boolean; 7 | invoke(instance: AxiosInstance, request: IRequest): Promise; 8 | } 9 | -------------------------------------------------------------------------------- /types/config/requestdata/IPatchData.d.ts: -------------------------------------------------------------------------------- 1 | import IFormParamType from "../IFormParamType"; 2 | import AbstractBuilder from "../builder/AbstractBuilder"; 3 | import IUrlSearchParamType from "../IUrlSearchParamType"; 4 | export default interface IPatchData { 5 | withFormData(params: IFormParamType, uploadProgress?: (progress: number) => void): AbstractBuilder; 6 | withURLSearchParams(params: IUrlSearchParamType): AbstractBuilder; 7 | withJson(param: Object): AbstractBuilder; 8 | } 9 | -------------------------------------------------------------------------------- /src/config/requestdata/IPatchData.ts: -------------------------------------------------------------------------------- 1 | import IFormParamType from "../IFormParamType"; 2 | import AbstractBuilder from "../builder/AbstractBuilder"; 3 | import IUrlSearchParamType from "../IUrlSearchParamType"; 4 | 5 | export default interface IPatchData { 6 | withFormData(params: IFormParamType, uploadProgress?: (progress: number) => void): AbstractBuilder, 7 | 8 | withURLSearchParams(params: IUrlSearchParamType): AbstractBuilder, 9 | 10 | withJson(param: Object): AbstractBuilder 11 | } -------------------------------------------------------------------------------- /dist/config/builder/PatchBuilder.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"PatchBuilder.js","sourceRoot":"","sources":["../../../src/config/builder/PatchBuilder.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,8GAAwF;AAExF,sCAAwD;AAExD;IAA0C,gCAAmC;IACzE,sBAAY,GAAW;eACnB,kBAAM,4BAAkB,CAAC,KAAK,EAAE,GAAG,CAAC;IACxC,CAAC;IAED,+BAAQ,GAAR,UAAS,KAAa;QAClB,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,GAAG,kBAAQ,CAAC,IAAI,CAAC;QACtC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC;QAC9B,OAAO,IAAI,CAAC;IAChB,CAAC;IACL,mBAAC;AAAD,CAAC,AAVD,CAA0C,6CAAmC,GAU5E"} -------------------------------------------------------------------------------- /types/actuator/message/ErrorMessage.d.ts: -------------------------------------------------------------------------------- 1 | import IErrorMessage from "./IErrorMessage"; 2 | export default class ErrorMessage { 3 | private static errorMsg?; 4 | private static isShow; 5 | static set errorMsgImpl(errorMsg: IErrorMessage); 6 | static showOff(): void; 7 | static isImplements(): boolean; 8 | static autoShowErrorMsg(title: string, msg: any, once?: boolean): void; 9 | static showErrorMsg(title: string, msg: any): void; 10 | static showOnceErrorMsg(title: string, msg: any): void; 11 | } 12 | -------------------------------------------------------------------------------- /src/HelpConfig.ts: -------------------------------------------------------------------------------- 1 | import IErrorMessage from "./actuator/message/IErrorMessage"; 2 | import AxiosInstanceFactoryBuilder from "./factory/AxiosInstanceFactoryBuilder"; 3 | import ErrorMessage from "./actuator/message/ErrorMessage"; 4 | 5 | export default class HelpConfig { 6 | static axiosInstanceBuilder = new AxiosInstanceFactoryBuilder(); 7 | 8 | static onceMsgFinish = ErrorMessage.showOff; 9 | 10 | static set errorMsgImpl(errorMsg: IErrorMessage) { 11 | ErrorMessage.errorMsgImpl = errorMsg; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /types/actuator/AbstractRequestActuator.d.ts: -------------------------------------------------------------------------------- 1 | import { AxiosError, AxiosInstance, AxiosResponse } from 'axios'; 2 | import IRequest from "./IRequest"; 3 | export default abstract class AbstractRequestActuator { 4 | protected readonly instance: AxiosInstance; 5 | protected readonly request: IRequest; 6 | protected constructor(request: IRequest); 7 | private distribution; 8 | protected abstract onResponse(response: AxiosResponse): void; 9 | protected abstract onError(error: AxiosError): void; 10 | protected abstract onAfter(): void; 11 | } 12 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | # To get started with Dependabot version updates, you'll need to specify which 2 | # package ecosystems to update and where the package manifests are located. 3 | # Please see the documentation for all configuration options: 4 | # https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates 5 | 6 | version: 2 7 | updates: 8 | - package-ecosystem: "npm" # See documentation for possible values 9 | directory: "/" # Location of package manifests 10 | schedule: 11 | interval: "daily" 12 | open-pull-requests-limit: 20 13 | -------------------------------------------------------------------------------- /src/actuator/method/GetRequestActuator.ts: -------------------------------------------------------------------------------- 1 | import IRequestActuator from "../IRequestActuator"; 2 | import {AxiosInstance, AxiosResponse} from "axios"; 3 | import IRequest from "../IRequest"; 4 | import {HttpRequestMethods} from "../../config/IConfig"; 5 | 6 | export default class GetRequestActuator implements IRequestActuator { 7 | canInvoke(method: HttpRequestMethods): boolean { 8 | return method === HttpRequestMethods.GET; 9 | } 10 | 11 | invoke(instance: AxiosInstance, request: IRequest): Promise { 12 | return instance.get(request.url); 13 | } 14 | } -------------------------------------------------------------------------------- /src/config/builder/PatchBuilder.ts: -------------------------------------------------------------------------------- 1 | import AbstractUrlSearchAndFormDataBuilder from "./AbstractUrlSearchAndFormDataBuilder"; 2 | import IPatchData from "../requestdata/IPatchData"; 3 | import {DataType, HttpRequestMethods} from "../IConfig"; 4 | 5 | export default class PatchBuilder extends AbstractUrlSearchAndFormDataBuilder implements IPatchData { 6 | constructor(url: string) { 7 | super(HttpRequestMethods.PATCH, url); 8 | } 9 | 10 | withJson(param: Object) { 11 | this.config.data.type = DataType.JSON; 12 | this.config.data.json = param; 13 | return this; 14 | } 15 | } -------------------------------------------------------------------------------- /webpack.config.js: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | const HtmlWebpackPlugin = require("html-webpack-plugin"); 3 | const {CleanWebpackPlugin} = require("clean-webpack-plugin"); 4 | 5 | module.exports = { 6 | mode: "none", 7 | entry: './test/test.js', 8 | output: { 9 | filename: '[name].bundle.js', 10 | path: path.resolve(__dirname, 'build') 11 | }, 12 | devServer: { 13 | static: "./build" 14 | }, 15 | plugins: [ 16 | new HtmlWebpackPlugin({ 17 | template: 'test/test.html' 18 | }), 19 | new CleanWebpackPlugin(), 20 | ] 21 | }; -------------------------------------------------------------------------------- /types/factory/AxiosInstanceFactory.d.ts: -------------------------------------------------------------------------------- 1 | import { AxiosInstance } from "axios"; 2 | import IRequestInterceptor from "../interceptor/request/IRequestInterceptor"; 3 | import IResponseInterceptor from "../interceptor/response/IResponseInterceptor"; 4 | import IAxiosInstanceConfig from "./IAxiosInstanceConfig"; 5 | export default class AxiosInstanceFactory { 6 | private static _instance; 7 | static init(config: IAxiosInstanceConfig): void; 8 | static set requestInterceptor(req: IRequestInterceptor); 9 | static set responseInterceptor(req: IResponseInterceptor); 10 | static get instance(): AxiosInstance; 11 | } 12 | -------------------------------------------------------------------------------- /types/factory/AxiosInstanceFactoryBuilder.d.ts: -------------------------------------------------------------------------------- 1 | import IRequestInterceptor from "../interceptor/request/IRequestInterceptor"; 2 | import IResponseInterceptor from "../interceptor/response/IResponseInterceptor"; 3 | export default class AxiosInstanceFactoryBuilder { 4 | private _requestInterceptor?; 5 | private _responseInterceptor?; 6 | private _timeOut; 7 | requestInterceptor(value: IRequestInterceptor): AxiosInstanceFactoryBuilder; 8 | responseInterceptor(value: IResponseInterceptor): AxiosInstanceFactoryBuilder; 9 | timeOut(value: number): AxiosInstanceFactoryBuilder; 10 | build(): void; 11 | } 12 | -------------------------------------------------------------------------------- /types/Http.d.ts: -------------------------------------------------------------------------------- 1 | import GetBuilder from "./config/builder/GetBuilder"; 2 | import PostBuilder from "./config/builder/PostBuilder"; 3 | import PatchBuilder from "./config/builder/PatchBuilder"; 4 | import DeleteBuilder from "./config/builder/DeleteBuilder"; 5 | import PutBuilder from "./config/builder/PutBuilder"; 6 | export default class Http { 7 | static Get(url: string): GetBuilder; 8 | static Post(url: string): PostBuilder; 9 | static Delete(url: string): DeleteBuilder; 10 | static Patch(url: string): PatchBuilder; 11 | static Put(url: string): PutBuilder; 12 | static Download(url: string, fileName: (fileName: any) => string): void; 13 | } 14 | -------------------------------------------------------------------------------- /dist/actuator/method/GetRequestActuator.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | var IConfig_1 = require("../../config/IConfig"); 4 | var GetRequestActuator = (function () { 5 | function GetRequestActuator() { 6 | } 7 | GetRequestActuator.prototype.canInvoke = function (method) { 8 | return method === IConfig_1.HttpRequestMethods.GET; 9 | }; 10 | GetRequestActuator.prototype.invoke = function (instance, request) { 11 | return instance.get(request.url); 12 | }; 13 | return GetRequestActuator; 14 | }()); 15 | exports.default = GetRequestActuator; 16 | //# sourceMappingURL=GetRequestActuator.js.map -------------------------------------------------------------------------------- /types/config/builder/AbstractUrlSearchAndFormDataBuilder.d.ts: -------------------------------------------------------------------------------- 1 | import AbstractBuilder from "./AbstractBuilder"; 2 | import IFormParamType from "../IFormParamType"; 3 | import IUrlSearchParamType from "../IUrlSearchParamType"; 4 | import IPostData from "../requestdata/IPostData"; 5 | import IDeleteData from "../requestdata/IDeleteData"; 6 | import IPutData from "../requestdata/IPutData"; 7 | export default abstract class AbstractUrlSearchAndFormDataBuilder extends AbstractBuilder implements IPostData, IDeleteData, IPutData { 8 | withFormData(params: IFormParamType, uploadProgress?: (progress: number) => void): this; 9 | withURLSearchParams(params: IUrlSearchParamType): this; 10 | } 11 | -------------------------------------------------------------------------------- /dist/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __importDefault = (this && this.__importDefault) || function (mod) { 3 | return (mod && mod.__esModule) ? mod : { "default": mod }; 4 | }; 5 | Object.defineProperty(exports, "__esModule", { value: true }); 6 | var Http_1 = __importDefault(require("./Http")); 7 | var HelpConfig_1 = __importDefault(require("./HelpConfig")); 8 | exports.Get = Http_1.default.Get; 9 | exports.Post = Http_1.default.Post; 10 | exports.Delete = Http_1.default.Delete; 11 | exports.Patch = Http_1.default.Patch; 12 | exports.Put = Http_1.default.Put; 13 | exports.Download = Http_1.default.Download; 14 | exports.AxiosHelperConfig = HelpConfig_1.default; 15 | //# sourceMappingURL=index.js.map -------------------------------------------------------------------------------- /dist/factory/AxiosInstanceFactory.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"AxiosInstanceFactory.js","sourceRoot":"","sources":["../../src/factory/AxiosInstanceFactory.ts"],"names":[],"mappings":";;;;;AAAA,gDAA2C;AAK3C;IAAA;IAkBA,CAAC;IAfU,yBAAI,GAAX,UAAY,MAA4B;QACpC,oBAAoB,CAAC,SAAS,GAAG,eAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAC1D,CAAC;IAED,sBAAW,0CAAkB;aAA7B,UAA8B,GAAwB;YAClD,oBAAoB,CAAC,SAAS,CAAC,YAAY,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,WAAW,EAAE,GAAG,CAAC,UAAU,CAAC,CAAA;QAC5F,CAAC;;;OAAA;IAED,sBAAW,2CAAmB;aAA9B,UAA+B,GAAyB;YACpD,oBAAoB,CAAC,SAAS,CAAC,YAAY,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,WAAW,EAAE,GAAG,CAAC,UAAU,CAAC,CAAA;QAC7F,CAAC;;;OAAA;IAED,sBAAW,gCAAQ;aAAnB;YACI,OAAO,oBAAoB,CAAC,SAAS,CAAC;QAC1C,CAAC;;;OAAA;IACL,2BAAC;AAAD,CAAC,AAlBD,IAkBC"} -------------------------------------------------------------------------------- /types/config/builder/AbstractBuilder.d.ts: -------------------------------------------------------------------------------- 1 | import { AxiosError, AxiosResponse } from "axios"; 2 | import IConfig, { HttpRequestMethods } from "../IConfig"; 3 | export default abstract class AbstractBuilder { 4 | private readonly method; 5 | private readonly url; 6 | protected config: IConfig; 7 | protected constructor(method: HttpRequestMethods, url: string); 8 | withSuccessCode(code: number): this; 9 | withEnableErrorMsg(enable: boolean): this; 10 | withErrorStartMsg(msg: string): this; 11 | withOnceMsg(): this; 12 | withErrorHandle(func: (error: AxiosError) => void): this; 13 | do(response: (response: AxiosResponse) => void): this; 14 | doAfter(after: () => void): this; 15 | } 16 | -------------------------------------------------------------------------------- /dist/actuator/method/PutRequestActuator.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"PutRequestActuator.js","sourceRoot":"","sources":["../../../src/actuator/method/PutRequestActuator.ts"],"names":[],"mappings":";;AAGA,gDAAwD;AAExD;IAAA;IAcA,CAAC;IAbG,sCAAS,GAAT,UAAU,MAA0B;QAChC,OAAO,MAAM,KAAK,4BAAkB,CAAC,GAAG,CAAC;IAC7C,CAAC;IAED,mCAAM,GAAN,UAAO,QAAuB,EAAE,OAAiB;QAC7C,IAAI,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,cAAc,EAAE;YACpC,OAAO,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;SACxE;aAAM,IAAI,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE;YACjC,OAAO,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,EAAC,OAAO,EAAE,EAAC,cAAc,EAAE,qBAAqB,EAAC,EAAC,CAAC,CAAC;SACxH;aAAM;YACH,OAAO,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;SACpC;IACL,CAAC;IACL,yBAAC;AAAD,CAAC,AAdD,IAcC"} -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "experimentalDecorators": true, 4 | "module": "commonjs", 5 | "target": "ES5", 6 | "esModuleInterop": true, 7 | "noImplicitAny": true, 8 | "removeComments": true, 9 | "strict": true, 10 | // 自动创建类型声明文件 11 | "declaration": true, 12 | "declarationDir": "types/", 13 | "preserveConstEnums": true, 14 | // 出错时不编译成JS文件 15 | "noEmitOnError": true, 16 | "sourceMap": true, 17 | "outDir": "dist/", 18 | "lib": [ 19 | "DOM", 20 | "ES2015", 21 | "ES2016", 22 | "ES2017", 23 | "ES2018", 24 | "ES2019", 25 | "ESNext" 26 | ] 27 | }, 28 | "include": [ 29 | "src/**/*" 30 | ], 31 | "exclude": [ 32 | "node_modules", 33 | "**/*.spec.ts", 34 | "test" 35 | ] 36 | } 37 | -------------------------------------------------------------------------------- /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | # This is a basic workflow to help you get started with Actions 2 | 3 | name: CI 4 | 5 | # Controls when the workflow will run 6 | on: 7 | # Triggers the workflow on push or pull request events but only for the master branch 8 | push: 9 | branches: [ master ] 10 | pull_request: 11 | branches: [ master ] 12 | 13 | # Allows you to run this workflow manually from the Actions tab 14 | workflow_dispatch: 15 | 16 | # A workflow run is made up of one or more jobs that can run sequentially or in parallel 17 | jobs: 18 | build: 19 | runs-on: ubuntu-latest 20 | steps: 21 | - uses: actions/checkout@v2 22 | - name: Npm Install And Build 23 | uses: actions/setup-node@v2 24 | with: 25 | node-version: '14' 26 | - run: npm install 27 | - run: npm run build 28 | -------------------------------------------------------------------------------- /dist/actuator/method/DeleteRequestActuator.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"DeleteRequestActuator.js","sourceRoot":"","sources":["../../../src/actuator/method/DeleteRequestActuator.ts"],"names":[],"mappings":";;AAGA,gDAAwD;AAExD;IAAA;IAiBA,CAAC;IAhBG,yCAAS,GAAT,UAAU,MAA0B;QAChC,OAAO,MAAM,KAAK,4BAAkB,CAAC,MAAM,CAAC;IAChD,CAAC;IAED,sCAAM,GAAN,UAAO,QAAuB,EAAE,OAAiB;QAC7C,IAAI,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,cAAc,EAAE;YACpC,OAAO,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,EAAC,IAAI,EAAE,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,cAAc,EAAC,CAAC,CAAC;SACnF;aAAM,IAAI,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE;YACjC,OAAO,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE;gBAChC,IAAI,EAAE,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK;gBACpC,OAAO,EAAE,EAAC,cAAc,EAAE,qBAAqB,EAAC;aACnD,CAAC,CAAC;SACN;aAAM;YACH,OAAO,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;SACvC;IACL,CAAC;IACL,4BAAC;AAAD,CAAC,AAjBD,IAiBC"} -------------------------------------------------------------------------------- /dist/factory/AxiosInstanceFactoryBuilder.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"AxiosInstanceFactoryBuilder.js","sourceRoot":"","sources":["../../src/factory/AxiosInstanceFactoryBuilder.ts"],"names":[],"mappings":";;;;;AAEA,gFAA0D;AAE1D;IAAA;QAGY,aAAQ,GAAG,IAAI,GAAG,EAAE,CAAC;IA0BjC,CAAC;IAxBG,wDAAkB,GAAlB,UAAmB,KAA0B;QACzC,IAAI,CAAC,mBAAmB,GAAG,KAAK,CAAC;QACjC,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,yDAAmB,GAAnB,UAAoB,KAA2B;QAC3C,IAAI,CAAC,oBAAoB,GAAG,KAAK,CAAC;QAClC,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,6CAAO,GAAP,UAAQ,KAAa;QACjB,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC;QACtB,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,2CAAK,GAAL;QACI,8BAAoB,CAAC,IAAI,CAAC,EAAC,OAAO,EAAE,IAAI,CAAC,QAAQ,EAAC,CAAC,CAAC;QACpD,IAAI,IAAI,CAAC,mBAAmB,EAAE;YAC1B,8BAAoB,CAAC,kBAAkB,GAAG,IAAI,CAAC,mBAAmB,CAAC;SACtE;QACD,IAAI,IAAI,CAAC,oBAAoB,EAAE;YAC3B,8BAAoB,CAAC,mBAAmB,GAAG,IAAI,CAAC,oBAAoB,CAAC;SACxE;IACL,CAAC;IACL,kCAAC;AAAD,CAAC,AA7BD,IA6BC"} -------------------------------------------------------------------------------- /src/config/IConfig.ts: -------------------------------------------------------------------------------- 1 | import {AxiosError, AxiosResponse} from "axios"; 2 | import IFormData from "./IFormData"; 3 | 4 | export default interface IConfig { 5 | success: { 6 | code: number 7 | }, 8 | errorMsg: { 9 | enable: boolean, 10 | startStr: string, 11 | once: boolean, 12 | handleFun?: (error: AxiosError) => void 13 | }, 14 | data: { 15 | type: DataType, 16 | form?: IFormData, 17 | urlSearchParam?: URLSearchParams, 18 | json?: Object 19 | }, 20 | request: { 21 | do: (response: AxiosResponse) => void, 22 | after?: () => void 23 | } 24 | } 25 | 26 | export enum HttpRequestMethods { 27 | GET, 28 | POST, 29 | DELETE, 30 | PUT, 31 | PATCH 32 | } 33 | 34 | export enum DataType { 35 | NONE, 36 | FORM_DATA, 37 | URL_SEARCH_PARAM, 38 | JSON 39 | } 40 | -------------------------------------------------------------------------------- /types/config/IConfig.d.ts: -------------------------------------------------------------------------------- 1 | import { AxiosError, AxiosResponse } from "axios"; 2 | import IFormData from "./IFormData"; 3 | export default interface IConfig { 4 | success: { 5 | code: number; 6 | }; 7 | errorMsg: { 8 | enable: boolean; 9 | startStr: string; 10 | once: boolean; 11 | handleFun?: (error: AxiosError) => void; 12 | }; 13 | data: { 14 | type: DataType; 15 | form?: IFormData; 16 | urlSearchParam?: URLSearchParams; 17 | json?: Object; 18 | }; 19 | request: { 20 | do: (response: AxiosResponse) => void; 21 | after?: () => void; 22 | }; 23 | } 24 | export declare enum HttpRequestMethods { 25 | GET = 0, 26 | POST = 1, 27 | DELETE = 2, 28 | PUT = 3, 29 | PATCH = 4 30 | } 31 | export declare enum DataType { 32 | NONE = 0, 33 | FORM_DATA = 1, 34 | URL_SEARCH_PARAM = 2, 35 | JSON = 3 36 | } 37 | -------------------------------------------------------------------------------- /dist/actuator/method/PatchRequestActuator.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"PatchRequestActuator.js","sourceRoot":"","sources":["../../../src/actuator/method/PatchRequestActuator.ts"],"names":[],"mappings":";;AAGA,gDAAwD;AAExD;IAAA;IAgBA,CAAC;IAfG,wCAAS,GAAT,UAAU,MAA0B;QAChC,OAAO,MAAM,KAAK,4BAAkB,CAAC,KAAK,CAAC;IAC/C,CAAC;IAED,qCAAM,GAAN,UAAO,QAAuB,EAAE,OAAiB;QAC7C,IAAI,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,cAAc,EAAE;YACpC,OAAO,QAAQ,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;SAC1E;aAAM,IAAI,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE;YACjC,OAAO,QAAQ,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,EAAC,OAAO,EAAE,EAAC,cAAc,EAAE,qBAAqB,EAAC,EAAC,CAAC,CAAC;SAC1H;aAAM,IAAI,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE;YACjC,OAAO,QAAQ,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;SAC/D;aAAM;YACH,OAAO,QAAQ,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;SACtC;IACL,CAAC;IACL,2BAAC;AAAD,CAAC,AAhBD,IAgBC"} -------------------------------------------------------------------------------- /src/actuator/method/PutRequestActuator.ts: -------------------------------------------------------------------------------- 1 | import IRequestActuator from "../IRequestActuator"; 2 | import {AxiosInstance, AxiosResponse} from "axios"; 3 | import IRequest from "../IRequest"; 4 | import {HttpRequestMethods} from "../../config/IConfig"; 5 | 6 | export default class PutRequestActuator implements IRequestActuator { 7 | canInvoke(method: HttpRequestMethods): boolean { 8 | return method === HttpRequestMethods.PUT; 9 | } 10 | 11 | invoke(instance: AxiosInstance, request: IRequest): Promise { 12 | if (request.config.data.urlSearchParam) { 13 | return instance.put(request.url, request.config.data.urlSearchParam); 14 | } else if (request.config.data.form) { 15 | return instance.put(request.url, request.config.data.form.param, {headers: {'content-type': 'multipart/form-data'}}); 16 | } else { 17 | return instance.put(request.url); 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /dist/config/IConfig.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | var HttpRequestMethods; 4 | (function (HttpRequestMethods) { 5 | HttpRequestMethods[HttpRequestMethods["GET"] = 0] = "GET"; 6 | HttpRequestMethods[HttpRequestMethods["POST"] = 1] = "POST"; 7 | HttpRequestMethods[HttpRequestMethods["DELETE"] = 2] = "DELETE"; 8 | HttpRequestMethods[HttpRequestMethods["PUT"] = 3] = "PUT"; 9 | HttpRequestMethods[HttpRequestMethods["PATCH"] = 4] = "PATCH"; 10 | })(HttpRequestMethods = exports.HttpRequestMethods || (exports.HttpRequestMethods = {})); 11 | var DataType; 12 | (function (DataType) { 13 | DataType[DataType["NONE"] = 0] = "NONE"; 14 | DataType[DataType["FORM_DATA"] = 1] = "FORM_DATA"; 15 | DataType[DataType["URL_SEARCH_PARAM"] = 2] = "URL_SEARCH_PARAM"; 16 | DataType[DataType["JSON"] = 3] = "JSON"; 17 | })(DataType = exports.DataType || (exports.DataType = {})); 18 | //# sourceMappingURL=IConfig.js.map -------------------------------------------------------------------------------- /dist/actuator/distribution/Distribution.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"Distribution.js","sourceRoot":"","sources":["../../../src/actuator/distribution/Distribution.ts"],"names":[],"mappings":";;;;;AAAA,gDAAwD;AAGxD,oFAA8D;AAC9D,sFAAgE;AAChE,0FAAoE;AACpE,wFAAkE;AAClE,oFAA8D;AAE9D;IAGI,sBAAY,MAA0B;QAClC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACzB,CAAC;IAED,mCAAY,GAAZ,UAAa,QAAuB,EAAE,OAAiB;QACnD,QAAQ,IAAI,CAAC,MAAM,EAAE;YACjB,KAAK,4BAAkB,CAAC,GAAG,CAAC,CAAC;gBACzB,OAAO,IAAI,4BAAkB,EAAE,CAAC,MAAM,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;aAC7D;YACD,KAAK,4BAAkB,CAAC,IAAI,CAAC,CAAC;gBAC1B,OAAO,IAAI,6BAAmB,EAAE,CAAC,MAAM,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;aAC9D;YACD,KAAK,4BAAkB,CAAC,MAAM,CAAC,CAAC;gBAC5B,OAAO,IAAI,+BAAqB,EAAE,CAAC,MAAM,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;aAChE;YACD,KAAK,4BAAkB,CAAC,KAAK,CAAC,CAAC;gBAC3B,OAAO,IAAI,8BAAoB,EAAE,CAAC,MAAM,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;aAC/D;YACD,KAAK,4BAAkB,CAAC,GAAG,CAAC,CAAC;gBACzB,OAAO,IAAI,4BAAkB,EAAE,CAAC,MAAM,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;aAC7D;SACJ;IACL,CAAC;IACL,mBAAC;AAAD,CAAC,AA1BD,IA0BC"} -------------------------------------------------------------------------------- /dist/actuator/message/ErrorMessage.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"ErrorMessage.js","sourceRoot":"","sources":["../../../src/actuator/message/ErrorMessage.ts"],"names":[],"mappings":";;AAEA;IAAA;IAoCA,CAAC;IAhCG,sBAAW,4BAAY;aAAvB,UAAwB,QAAuB;YAC3C,YAAY,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACrC,CAAC;;;OAAA;IAEM,oBAAO,GAAd;QACI,YAAY,CAAC,MAAM,GAAG,KAAK,CAAC;IAChC,CAAC;IAEM,yBAAY,GAAnB;QACI,OAAO,YAAY,CAAC,QAAQ,KAAK,SAAS,CAAC;IAC/C,CAAC;IAEM,6BAAgB,GAAvB,UAAwB,KAAa,EAAE,GAAQ,EAAE,IAAqB;QAArB,qBAAA,EAAA,YAAqB;QAClE,IAAI,IAAI,EAAE;YACN,YAAY,CAAC,gBAAgB,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;SAC7C;aAAM;YACH,YAAY,CAAC,YAAY,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;SACzC;IACL,CAAC;IAEM,yBAAY,GAAnB,UAAoB,KAAa,EAAE,GAAQ;;QACvC,MAAA,YAAY,CAAC,QAAQ,0CAAE,cAAc,CAAC,KAAK,EAAE,GAAG,EAAE;IACtD,CAAC;IAEM,6BAAgB,GAAvB,UAAwB,KAAa,EAAE,GAAQ;QAC3C,IAAI,YAAY,CAAC,MAAM,EAAE;YACrB,OAAO;SACV;aAAM;YACH,YAAY,CAAC,YAAY,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;YACtC,YAAY,CAAC,MAAM,GAAG,IAAI,CAAC;SAC9B;IACL,CAAC;IAjCc,mBAAM,GAAG,KAAK,CAAC;IAkClC,mBAAC;CAAA,AApCD,IAoCC;kBApCoB,YAAY"} -------------------------------------------------------------------------------- /src/factory/AxiosInstanceFactory.ts: -------------------------------------------------------------------------------- 1 | import Axios, {AxiosInstance} from "axios"; 2 | import IRequestInterceptor from "../interceptor/request/IRequestInterceptor"; 3 | import IResponseInterceptor from "../interceptor/response/IResponseInterceptor"; 4 | import IAxiosInstanceConfig from "./IAxiosInstanceConfig"; 5 | 6 | export default class AxiosInstanceFactory { 7 | private static _instance: AxiosInstance; 8 | 9 | static init(config: IAxiosInstanceConfig) { 10 | AxiosInstanceFactory._instance = Axios.create(config); 11 | } 12 | 13 | static set requestInterceptor(req: IRequestInterceptor) { 14 | AxiosInstanceFactory._instance.interceptors.request.use(req.onFulfilled, req.onRejected) 15 | } 16 | 17 | static set responseInterceptor(req: IResponseInterceptor) { 18 | AxiosInstanceFactory._instance.interceptors.response.use(req.onFulfilled, req.onRejected) 19 | } 20 | 21 | static get instance() { 22 | return AxiosInstanceFactory._instance; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /dist/HelpConfig.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __importDefault = (this && this.__importDefault) || function (mod) { 3 | return (mod && mod.__esModule) ? mod : { "default": mod }; 4 | }; 5 | Object.defineProperty(exports, "__esModule", { value: true }); 6 | var AxiosInstanceFactoryBuilder_1 = __importDefault(require("./factory/AxiosInstanceFactoryBuilder")); 7 | var ErrorMessage_1 = __importDefault(require("./actuator/message/ErrorMessage")); 8 | var HelpConfig = (function () { 9 | function HelpConfig() { 10 | } 11 | Object.defineProperty(HelpConfig, "errorMsgImpl", { 12 | set: function (errorMsg) { 13 | ErrorMessage_1.default.errorMsgImpl = errorMsg; 14 | }, 15 | enumerable: true, 16 | configurable: true 17 | }); 18 | HelpConfig.axiosInstanceBuilder = new AxiosInstanceFactoryBuilder_1.default(); 19 | HelpConfig.onceMsgFinish = ErrorMessage_1.default.showOff; 20 | return HelpConfig; 21 | }()); 22 | exports.default = HelpConfig; 23 | //# sourceMappingURL=HelpConfig.js.map -------------------------------------------------------------------------------- /src/actuator/method/DeleteRequestActuator.ts: -------------------------------------------------------------------------------- 1 | import IRequestActuator from "../IRequestActuator"; 2 | import {AxiosInstance, AxiosResponse} from "axios"; 3 | import IRequest from "../IRequest"; 4 | import {HttpRequestMethods} from "../../config/IConfig"; 5 | 6 | export default class DeleteRequestActuator implements IRequestActuator { 7 | canInvoke(method: HttpRequestMethods): boolean { 8 | return method === HttpRequestMethods.DELETE; 9 | } 10 | 11 | invoke(instance: AxiosInstance, request: IRequest): Promise { 12 | if (request.config.data.urlSearchParam) { 13 | return instance.delete(request.url, {data: request.config.data.urlSearchParam}); 14 | } else if (request.config.data.form) { 15 | return instance.delete(request.url, { 16 | data: request.config.data.form.param, 17 | headers: {'content-type': 'multipart/form-data'} 18 | }); 19 | } else { 20 | return instance.delete(request.url); 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /dist/actuator/method/PutRequestActuator.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | var IConfig_1 = require("../../config/IConfig"); 4 | var PutRequestActuator = (function () { 5 | function PutRequestActuator() { 6 | } 7 | PutRequestActuator.prototype.canInvoke = function (method) { 8 | return method === IConfig_1.HttpRequestMethods.PUT; 9 | }; 10 | PutRequestActuator.prototype.invoke = function (instance, request) { 11 | if (request.config.data.urlSearchParam) { 12 | return instance.put(request.url, request.config.data.urlSearchParam); 13 | } 14 | else if (request.config.data.form) { 15 | return instance.put(request.url, request.config.data.form.param, { headers: { 'content-type': 'multipart/form-data' } }); 16 | } 17 | else { 18 | return instance.put(request.url); 19 | } 20 | }; 21 | return PutRequestActuator; 22 | }()); 23 | exports.default = PutRequestActuator; 24 | //# sourceMappingURL=PutRequestActuator.js.map -------------------------------------------------------------------------------- /src/actuator/method/PatchRequestActuator.ts: -------------------------------------------------------------------------------- 1 | import IRequestActuator from "../IRequestActuator"; 2 | import {AxiosInstance, AxiosResponse} from "axios"; 3 | import IRequest from "../IRequest"; 4 | import {HttpRequestMethods} from "../../config/IConfig"; 5 | 6 | export default class PatchRequestActuator implements IRequestActuator { 7 | canInvoke(method: HttpRequestMethods): boolean { 8 | return method === HttpRequestMethods.PATCH; 9 | } 10 | 11 | invoke(instance: AxiosInstance, request: IRequest): Promise { 12 | if (request.config.data.urlSearchParam) { 13 | return instance.patch(request.url, request.config.data.urlSearchParam); 14 | } else if (request.config.data.form) { 15 | return instance.patch(request.url, request.config.data.form.param, {headers: {'content-type': 'multipart/form-data'}}); 16 | } else if (request.config.data.json) { 17 | return instance.patch(request.url, request.config.data.json) 18 | } else { 19 | return instance.patch(request.url); 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /dist/actuator/AbstractRequestActuator.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"AbstractRequestActuator.js","sourceRoot":"","sources":["../../src/actuator/AbstractRequestActuator.ts"],"names":[],"mappings":";;;;;AAEA,yFAAmE;AACnE,6EAAuD;AACvD,wEAAkD;AAKlD;IAII,iCAAsB,OAAiB;QACnC,IAAI,CAAC,QAAQ,GAAG,8BAAoB,CAAC,QAAQ,CAAC;QAC9C,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,YAAY,EAAE,CAAC;IACxB,CAAC;IAEO,8CAAY,GAApB;QAAA,iBAkBC;QAjBG,IAAI,sBAAY,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC;aAChC,YAAY,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,OAAO,CAAC;aACzC,IAAI,CAAC,UAAA,QAAQ;YACV,IAAI,QAAQ,CAAC,MAAM,KAAK,KAAI,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE;gBACtD,KAAI,CAAC,UAAU,CAAC,IAAI,CAAC,KAAI,EAAE,QAAQ,CAAC,CAAC;aACxC;iBAAM;gBACH,IAAI,sBAAY,CAAC,YAAY,EAAE,IAAI,KAAI,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,EAAE;oBACpE,sBAAY,CAAC,gBAAgB,CAAC,KAAI,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC,IAAI,EAAE,KAAI,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAA;iBACzH;aACJ;QACL,CAAC,CAAC;aACD,KAAK,CAAC,UAAA,KAAK;YACR,KAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAI,EAAE,KAAK,CAAC,CAAC;QACnC,CAAC,CAAC;aACD,IAAI,CAAC;YACF,KAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAI,CAAC,CAAC;QAC5B,CAAC,CAAC,CAAA;IACV,CAAC;IAOL,8BAAC;AAAD,CAAC,AAnCD,IAmCC"} -------------------------------------------------------------------------------- /dist/actuator/method/DeleteRequestActuator.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | var IConfig_1 = require("../../config/IConfig"); 4 | var DeleteRequestActuator = (function () { 5 | function DeleteRequestActuator() { 6 | } 7 | DeleteRequestActuator.prototype.canInvoke = function (method) { 8 | return method === IConfig_1.HttpRequestMethods.DELETE; 9 | }; 10 | DeleteRequestActuator.prototype.invoke = function (instance, request) { 11 | if (request.config.data.urlSearchParam) { 12 | return instance.delete(request.url, { data: request.config.data.urlSearchParam }); 13 | } 14 | else if (request.config.data.form) { 15 | return instance.delete(request.url, { 16 | data: request.config.data.form.param, 17 | headers: { 'content-type': 'multipart/form-data' } 18 | }); 19 | } 20 | else { 21 | return instance.delete(request.url); 22 | } 23 | }; 24 | return DeleteRequestActuator; 25 | }()); 26 | exports.default = DeleteRequestActuator; 27 | //# sourceMappingURL=DeleteRequestActuator.js.map -------------------------------------------------------------------------------- /dist/config/builder/AbstractUrlSearchAndFormDataBuilder.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"AbstractUrlSearchAndFormDataBuilder.js","sourceRoot":"","sources":["../../../src/config/builder/AbstractUrlSearchAndFormDataBuilder.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,sEAAgD;AAEhD,sCAAoC;AAMpC;IAA0E,uDAAe;IAAzF;;IA0BA,CAAC;IAzBG,0DAAY,GAAZ,UAAa,MAAsB,EAAE,cAA2C;QAC5E,IAAI,KAAK,GAAG,IAAI,QAAQ,EAAE,CAAC;QAC3B,KAAK,IAAI,CAAC,IAAI,MAAM,EAAE;YAClB,IAAI,MAAM,CAAC,cAAc,CAAC,CAAC,CAAC,EAAE;gBAC1B,IAAI,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;gBAClB,KAAK,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;aACtB;SACJ;QACD,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,GAAG,kBAAQ,CAAC,SAAS,CAAC;QAC3C,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,GAAG,EAAC,KAAK,OAAA,EAAE,cAAc,gBAAA,EAAC,CAAC;QAChD,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,iEAAmB,GAAnB,UAAoB,MAA2B;QAC3C,IAAI,KAAK,GAAG,IAAI,eAAe,EAAE,CAAC;QAClC,KAAK,IAAI,CAAC,IAAI,MAAM,EAAE;YAClB,IAAI,MAAM,CAAC,cAAc,CAAC,CAAC,CAAC,EAAE;gBAC1B,IAAI,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;gBAClB,KAAK,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;aACtB;SACJ;QACD,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,GAAG,kBAAQ,CAAC,gBAAgB,CAAC;QAClD,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,cAAc,GAAG,KAAK,CAAC;QACxC,OAAO,IAAI,CAAC;IAChB,CAAC;IACL,0CAAC;AAAD,CAAC,AA1BD,CAA0E,yBAAe,GA0BxF"} -------------------------------------------------------------------------------- /src/actuator/message/ErrorMessage.ts: -------------------------------------------------------------------------------- 1 | import IErrorMessage from "./IErrorMessage"; 2 | 3 | export default class ErrorMessage { 4 | private static errorMsg?: IErrorMessage; 5 | private static isShow = false; 6 | 7 | static set errorMsgImpl(errorMsg: IErrorMessage) { 8 | ErrorMessage.errorMsg = errorMsg; 9 | } 10 | 11 | static showOff() { 12 | ErrorMessage.isShow = false; 13 | } 14 | 15 | static isImplements(): boolean { 16 | return ErrorMessage.errorMsg !== undefined; 17 | } 18 | 19 | static autoShowErrorMsg(title: string, msg: any, once: boolean = false) { 20 | if (once) { 21 | ErrorMessage.showOnceErrorMsg(title, msg); 22 | } else { 23 | ErrorMessage.showErrorMsg(title, msg); 24 | } 25 | } 26 | 27 | static showErrorMsg(title: string, msg: any) { 28 | ErrorMessage.errorMsg?.showErrorToast(title, msg); 29 | } 30 | 31 | static showOnceErrorMsg(title: string, msg: any) { 32 | if (ErrorMessage.isShow) { 33 | return; 34 | } else { 35 | ErrorMessage.showErrorMsg(title, msg); 36 | ErrorMessage.isShow = true; 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@itning/axios-helper", 3 | "version": "1.1.2", 4 | "main": "dist/index.js", 5 | "typings": "types/index.d.ts", 6 | "files": [ 7 | "dist", 8 | "types" 9 | ], 10 | "scripts": { 11 | "build": "tsc --build tsconfig.json", 12 | "test": "webpack-dev-server" 13 | }, 14 | "description": "This lib will help you better use axios", 15 | "keywords": [ 16 | "axios", 17 | "util", 18 | "helper" 19 | ], 20 | "repository": { 21 | "url": "https://github.com/itning/axios-helper", 22 | "type": "git" 23 | }, 24 | "bugs": { 25 | "url": "https://github.com/itning/axios-helper/issues" 26 | }, 27 | "homepage": "https://github.com/itning/axios-helper#readme", 28 | "author": { 29 | "url": "https://github.com/itning", 30 | "name": "itning", 31 | "email": "itning@itning.top" 32 | }, 33 | "license": "Apache-2.0", 34 | "dependencies": { 35 | "axios": "^1.0.0" 36 | }, 37 | "devDependencies": { 38 | "clean-webpack-plugin": "^4.0.0", 39 | "html-webpack-plugin": "^5.5.0", 40 | "typescript": "^4.4.4", 41 | "webpack": "^5.60.0", 42 | "webpack-cli": "^5.0.0", 43 | "webpack-dev-server": "^4.3.1" 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /dist/actuator/method/PatchRequestActuator.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | var IConfig_1 = require("../../config/IConfig"); 4 | var PatchRequestActuator = (function () { 5 | function PatchRequestActuator() { 6 | } 7 | PatchRequestActuator.prototype.canInvoke = function (method) { 8 | return method === IConfig_1.HttpRequestMethods.PATCH; 9 | }; 10 | PatchRequestActuator.prototype.invoke = function (instance, request) { 11 | if (request.config.data.urlSearchParam) { 12 | return instance.patch(request.url, request.config.data.urlSearchParam); 13 | } 14 | else if (request.config.data.form) { 15 | return instance.patch(request.url, request.config.data.form.param, { headers: { 'content-type': 'multipart/form-data' } }); 16 | } 17 | else if (request.config.data.json) { 18 | return instance.patch(request.url, request.config.data.json); 19 | } 20 | else { 21 | return instance.patch(request.url); 22 | } 23 | }; 24 | return PatchRequestActuator; 25 | }()); 26 | exports.default = PatchRequestActuator; 27 | //# sourceMappingURL=PatchRequestActuator.js.map -------------------------------------------------------------------------------- /dist/actuator/method/PostRequestActuator.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"PostRequestActuator.js","sourceRoot":"","sources":["../../../src/actuator/method/PostRequestActuator.ts"],"names":[],"mappings":";;AAGA,gDAAwD;AAExD;IAAA;IA0BA,CAAC;IAzBG,uCAAS,GAAT,UAAU,MAA0B;QAChC,OAAO,MAAM,KAAK,4BAAkB,CAAC,IAAI,CAAC;IAC9C,CAAC;IAED,oCAAM,GAAN,UAAO,QAAuB,EAAE,OAAiB;QAC7C,IAAI,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,cAAc,EAAE;YACpC,OAAO,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;SACzE;aAAM,IAAI,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE;YACjC,IAAI,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE;gBACzC,IAAM,gBAAc,GAAG,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC;gBAC/D,IAAM,MAAM,GAAuB;oBAC/B,OAAO,EAAE,EAAC,cAAc,EAAE,qBAAqB,EAAC;oBAChD,gBAAgB,EAAE,UAAC,aAAkB;wBACjC,IAAI,QAAQ,GAAG,aAAa,CAAC,MAAM,GAAG,aAAa,CAAC,KAAK,GAAG,GAAG,GAAG,CAAC,CAAC;wBACpE,gBAAc,CAAC,QAAQ,CAAC,CAAC;oBAC7B,CAAC;iBACJ,CAAC;gBACF,OAAO,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;aAC7E;iBAAM;gBACH,OAAO,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,EAAC,OAAO,EAAE,EAAC,cAAc,EAAE,qBAAqB,EAAC,EAAC,CAAC,CAAC;aACzH;SACJ;aAAM;YACH,OAAO,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;SACrC;IACL,CAAC;IACL,0BAAC;AAAD,CAAC,AA1BD,IA0BC"} -------------------------------------------------------------------------------- /dist/actuator/RequestActuator.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"RequestActuator.js","sourceRoot":"","sources":["../../src/actuator/RequestActuator.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,sFAAgE;AAGhE,wEAAkD;AAElD;IAA6C,mCAAuB;IAChE,yBAAY,OAAiB;eACzB,kBAAM,OAAO,CAAC;IAClB,CAAC;IAES,oCAAU,GAApB,UAAqB,QAAuB;QACxC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;IACxD,CAAC;IAES,iCAAO,GAAjB,UAAkB,KAAiB;QAC/B,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE;YACjB,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACpB,IAAI,sBAAY,CAAC,YAAY,EAAE,EAAE;gBAC7B,sBAAY,CAAC,gBAAgB,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,EAAE,KAAK,CAAC,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;aAC1H;YACD,OAAO;SACV;QACD,IAAI,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,EAAE;YACrC,IAAI,sBAAY,CAAC,YAAY,EAAE,EAAE;gBAC7B,sBAAY,CAAC,gBAAgB,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,EAAE,KAAK,CAAC,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;aAChI;YACD,IAAI,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,SAAS,EAAE;gBACxC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;aAC5D;SACJ;IACL,CAAC;IAES,iCAAO,GAAjB;QACI,IAAI,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE;YACnC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;SAC/C;IACL,CAAC;IACL,sBAAC;AAAD,CAAC,AAhCD,CAA6C,iCAAuB,GAgCnE"} -------------------------------------------------------------------------------- /src/factory/AxiosInstanceFactoryBuilder.ts: -------------------------------------------------------------------------------- 1 | import IRequestInterceptor from "../interceptor/request/IRequestInterceptor"; 2 | import IResponseInterceptor from "../interceptor/response/IResponseInterceptor"; 3 | import AxiosInstanceFactory from "./AxiosInstanceFactory"; 4 | 5 | export default class AxiosInstanceFactoryBuilder { 6 | private _requestInterceptor?: IRequestInterceptor; 7 | private _responseInterceptor?: IResponseInterceptor; 8 | private _timeOut = 1000 * 12; 9 | 10 | requestInterceptor(value: IRequestInterceptor): AxiosInstanceFactoryBuilder { 11 | this._requestInterceptor = value; 12 | return this; 13 | } 14 | 15 | responseInterceptor(value: IResponseInterceptor): AxiosInstanceFactoryBuilder { 16 | this._responseInterceptor = value; 17 | return this; 18 | } 19 | 20 | timeOut(value: number): AxiosInstanceFactoryBuilder { 21 | this._timeOut = value; 22 | return this; 23 | } 24 | 25 | build() { 26 | AxiosInstanceFactory.init({timeout: this._timeOut}); 27 | if (this._requestInterceptor) { 28 | AxiosInstanceFactory.requestInterceptor = this._requestInterceptor; 29 | } 30 | if (this._responseInterceptor) { 31 | AxiosInstanceFactory.responseInterceptor = this._responseInterceptor; 32 | } 33 | } 34 | } -------------------------------------------------------------------------------- /dist/config/builder/GetBuilder.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __extends = (this && this.__extends) || (function () { 3 | var extendStatics = function (d, b) { 4 | extendStatics = Object.setPrototypeOf || 5 | ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || 6 | function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; 7 | return extendStatics(d, b); 8 | }; 9 | return function (d, b) { 10 | extendStatics(d, b); 11 | function __() { this.constructor = d; } 12 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); 13 | }; 14 | })(); 15 | var __importDefault = (this && this.__importDefault) || function (mod) { 16 | return (mod && mod.__esModule) ? mod : { "default": mod }; 17 | }; 18 | Object.defineProperty(exports, "__esModule", { value: true }); 19 | var AbstractBuilder_1 = __importDefault(require("./AbstractBuilder")); 20 | var IConfig_1 = require("../IConfig"); 21 | var GetBuilder = (function (_super) { 22 | __extends(GetBuilder, _super); 23 | function GetBuilder(url) { 24 | return _super.call(this, IConfig_1.HttpRequestMethods.GET, url) || this; 25 | } 26 | return GetBuilder; 27 | }(AbstractBuilder_1.default)); 28 | exports.default = GetBuilder; 29 | //# sourceMappingURL=GetBuilder.js.map -------------------------------------------------------------------------------- /dist/Http.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"Http.js","sourceRoot":"","sources":["../src/Http.ts"],"names":[],"mappings":";;;;;AAAA,2EAAqD;AACrD,6EAAuD;AACvD,+EAAyD;AACzD,iFAA2D;AAC3D,2EAAqD;AACrD,wFAAkE;AAClE,iFAA2D;AAE3D;IAAA;IA0CA,CAAC;IAzCU,QAAG,GAAV,UAAW,GAAW;QAClB,OAAO,IAAI,oBAAU,CAAC,GAAG,CAAC,CAAC;IAC/B,CAAC;IAEM,SAAI,GAAX,UAAY,GAAW;QACnB,OAAO,IAAI,qBAAW,CAAC,GAAG,CAAC,CAAC;IAChC,CAAC;IAEM,WAAM,GAAb,UAAc,GAAW;QACrB,OAAO,IAAI,uBAAa,CAAC,GAAG,CAAC,CAAC;IAClC,CAAC;IAEM,UAAK,GAAZ,UAAa,GAAW;QACpB,OAAO,IAAI,sBAAY,CAAC,GAAG,CAAC,CAAC;IACjC,CAAC;IAEM,QAAG,GAAV,UAAW,GAAW;QAClB,OAAO,IAAI,oBAAU,CAAC,GAAG,CAAC,CAAC;IAC/B,CAAC;IAEM,aAAQ,GAAf,UAAgB,GAAW,EAAE,QAAmC;QAC5D,8BAAoB,CAAC,QAAQ;aACxB,GAAG,CAAC,GAAG,EAAE;YACN,YAAY,EAAE,MAAM;SACvB,CAAC,CAAC,IAAI,CAAC,UAAA,QAAQ;YAChB,IAAI,GAAG,GAAG,MAAM,CAAC,GAAG,CAAC,eAAe,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;YACpD,IAAI,CAAC,GAAG,QAAQ,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC;YACpC,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;YAC7B,CAAC,CAAC,IAAI,GAAG,GAAG,CAAC;YACb,CAAC,CAAC,QAAQ,GAAG,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;YACxC,CAAC,CAAC,KAAK,EAAE,CAAC;YACV,MAAM,CAAC,GAAG,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC;QACpC,CAAC,CAAC,CAAC,KAAK,CAAC,UAAA,KAAK;YACV,IAAI,KAAK,CAAC,QAAQ,KAAK,SAAS,EAAE;gBAC9B,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;gBACpB,IAAI,sBAAY,CAAC,YAAY,EAAE,EAAE;oBAC7B,sBAAY,CAAC,YAAY,CAAC,OAAO,EAAE,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC;iBACxD;aACJ;QACL,CAAC,CAAC,CAAC;IACP,CAAC;IACL,WAAC;AAAD,CAAC,AA1CD,IA0CC"} -------------------------------------------------------------------------------- /dist/config/builder/PutBuilder.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __extends = (this && this.__extends) || (function () { 3 | var extendStatics = function (d, b) { 4 | extendStatics = Object.setPrototypeOf || 5 | ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || 6 | function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; 7 | return extendStatics(d, b); 8 | }; 9 | return function (d, b) { 10 | extendStatics(d, b); 11 | function __() { this.constructor = d; } 12 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); 13 | }; 14 | })(); 15 | var __importDefault = (this && this.__importDefault) || function (mod) { 16 | return (mod && mod.__esModule) ? mod : { "default": mod }; 17 | }; 18 | Object.defineProperty(exports, "__esModule", { value: true }); 19 | var AbstractUrlSearchAndFormDataBuilder_1 = __importDefault(require("./AbstractUrlSearchAndFormDataBuilder")); 20 | var IConfig_1 = require("../IConfig"); 21 | var PutBuilder = (function (_super) { 22 | __extends(PutBuilder, _super); 23 | function PutBuilder(url) { 24 | return _super.call(this, IConfig_1.HttpRequestMethods.PUT, url) || this; 25 | } 26 | return PutBuilder; 27 | }(AbstractUrlSearchAndFormDataBuilder_1.default)); 28 | exports.default = PutBuilder; 29 | //# sourceMappingURL=PutBuilder.js.map -------------------------------------------------------------------------------- /dist/config/builder/PostBuilder.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __extends = (this && this.__extends) || (function () { 3 | var extendStatics = function (d, b) { 4 | extendStatics = Object.setPrototypeOf || 5 | ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || 6 | function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; 7 | return extendStatics(d, b); 8 | }; 9 | return function (d, b) { 10 | extendStatics(d, b); 11 | function __() { this.constructor = d; } 12 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); 13 | }; 14 | })(); 15 | var __importDefault = (this && this.__importDefault) || function (mod) { 16 | return (mod && mod.__esModule) ? mod : { "default": mod }; 17 | }; 18 | Object.defineProperty(exports, "__esModule", { value: true }); 19 | var IConfig_1 = require("../IConfig"); 20 | var AbstractUrlSearchAndFormDataBuilder_1 = __importDefault(require("./AbstractUrlSearchAndFormDataBuilder")); 21 | var PostBuilder = (function (_super) { 22 | __extends(PostBuilder, _super); 23 | function PostBuilder(url) { 24 | return _super.call(this, IConfig_1.HttpRequestMethods.POST, url) || this; 25 | } 26 | return PostBuilder; 27 | }(AbstractUrlSearchAndFormDataBuilder_1.default)); 28 | exports.default = PostBuilder; 29 | //# sourceMappingURL=PostBuilder.js.map -------------------------------------------------------------------------------- /dist/config/builder/DeleteBuilder.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __extends = (this && this.__extends) || (function () { 3 | var extendStatics = function (d, b) { 4 | extendStatics = Object.setPrototypeOf || 5 | ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || 6 | function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; 7 | return extendStatics(d, b); 8 | }; 9 | return function (d, b) { 10 | extendStatics(d, b); 11 | function __() { this.constructor = d; } 12 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); 13 | }; 14 | })(); 15 | var __importDefault = (this && this.__importDefault) || function (mod) { 16 | return (mod && mod.__esModule) ? mod : { "default": mod }; 17 | }; 18 | Object.defineProperty(exports, "__esModule", { value: true }); 19 | var AbstractUrlSearchAndFormDataBuilder_1 = __importDefault(require("./AbstractUrlSearchAndFormDataBuilder")); 20 | var IConfig_1 = require("../IConfig"); 21 | var DeleteBuilder = (function (_super) { 22 | __extends(DeleteBuilder, _super); 23 | function DeleteBuilder(url) { 24 | return _super.call(this, IConfig_1.HttpRequestMethods.DELETE, url) || this; 25 | } 26 | return DeleteBuilder; 27 | }(AbstractUrlSearchAndFormDataBuilder_1.default)); 28 | exports.default = DeleteBuilder; 29 | //# sourceMappingURL=DeleteBuilder.js.map -------------------------------------------------------------------------------- /dist/config/builder/AbstractBuilder.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"AbstractBuilder.js","sourceRoot":"","sources":["../../../src/config/builder/AbstractBuilder.ts"],"names":[],"mappings":";;;;;AACA,sCAAiE;AACjE,mFAA6D;AAE7D;IAsBI,yBAAsB,MAA0B,EAAE,GAAW;QAlBnD,WAAM,GAAY;YACxB,IAAI,EAAE;gBACF,IAAI,EAAE,kBAAQ,CAAC,IAAI;aACtB;YACD,OAAO,EAAE;gBACL,EAAE,EAAE;gBACJ,CAAC;aACJ;YACD,QAAQ,EAAE;gBACN,IAAI,EAAE,KAAK;gBACX,MAAM,EAAE,IAAI;gBACZ,QAAQ,EAAE,IAAI;aACjB;YACD,OAAO,EAAE;gBACL,IAAI,EAAE,GAAG;aACZ;SACJ,CAAC;QAGE,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;IACnB,CAAC;IAED,yCAAe,GAAf,UAAgB,IAAY;QACxB,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC;QAChC,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,4CAAkB,GAAlB,UAAmB,MAAe;QAC9B,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,GAAG,MAAM,CAAC;QACrC,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,2CAAiB,GAAjB,UAAkB,GAAW;QACzB,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,GAAG,GAAG,CAAC;QACpC,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,qCAAW,GAAX;QACI,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,GAAG,IAAI,CAAC;QACjC,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,yCAAe,GAAf,UAAgB,IAAiC;QAC7C,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,SAAS,GAAG,IAAI,CAAC;QACtC,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,4BAAE,GAAF,UAAG,QAA2C;QAC1C,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,GAAG,QAAQ,CAAC;QAClC,IAAI,yBAAe,CAAC,EAAC,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAC,CAAC,CAAC;QAC/E,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,iCAAO,GAAP,UAAQ,KAAiB;QACrB,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,GAAG,KAAK,CAAC;QAClC,OAAO,IAAI,CAAC;IAChB,CAAC;IACL,sBAAC;AAAD,CAAC,AA9DD,IA8DC"} -------------------------------------------------------------------------------- /src/config/builder/AbstractUrlSearchAndFormDataBuilder.ts: -------------------------------------------------------------------------------- 1 | import AbstractBuilder from "./AbstractBuilder"; 2 | import IFormParamType from "../IFormParamType"; 3 | import {DataType} from "../IConfig"; 4 | import IUrlSearchParamType from "../IUrlSearchParamType"; 5 | import IPostData from "../requestdata/IPostData"; 6 | import IDeleteData from "../requestdata/IDeleteData"; 7 | import IPutData from "../requestdata/IPutData"; 8 | 9 | export default abstract class AbstractUrlSearchAndFormDataBuilder extends AbstractBuilder implements IPostData, IDeleteData, IPutData { 10 | withFormData(params: IFormParamType, uploadProgress?: (progress: number) => void) { 11 | let param = new FormData(); 12 | for (let p in params) { 13 | if (params.hasOwnProperty(p)) { 14 | let v = params[p]; 15 | param.append(p, v); 16 | } 17 | } 18 | this.config.data.type = DataType.FORM_DATA; 19 | this.config.data.form = {param, uploadProgress}; 20 | return this; 21 | } 22 | 23 | withURLSearchParams(params: IUrlSearchParamType) { 24 | let param = new URLSearchParams(); 25 | for (let p in params) { 26 | if (params.hasOwnProperty(p)) { 27 | let v = params[p]; 28 | param.append(p, v); 29 | } 30 | } 31 | this.config.data.type = DataType.URL_SEARCH_PARAM; 32 | this.config.data.urlSearchParam = param; 33 | return this; 34 | } 35 | } -------------------------------------------------------------------------------- /dist/factory/AxiosInstanceFactory.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __importDefault = (this && this.__importDefault) || function (mod) { 3 | return (mod && mod.__esModule) ? mod : { "default": mod }; 4 | }; 5 | Object.defineProperty(exports, "__esModule", { value: true }); 6 | var axios_1 = __importDefault(require("axios")); 7 | var AxiosInstanceFactory = (function () { 8 | function AxiosInstanceFactory() { 9 | } 10 | AxiosInstanceFactory.init = function (config) { 11 | AxiosInstanceFactory._instance = axios_1.default.create(config); 12 | }; 13 | Object.defineProperty(AxiosInstanceFactory, "requestInterceptor", { 14 | set: function (req) { 15 | AxiosInstanceFactory._instance.interceptors.request.use(req.onFulfilled, req.onRejected); 16 | }, 17 | enumerable: true, 18 | configurable: true 19 | }); 20 | Object.defineProperty(AxiosInstanceFactory, "responseInterceptor", { 21 | set: function (req) { 22 | AxiosInstanceFactory._instance.interceptors.response.use(req.onFulfilled, req.onRejected); 23 | }, 24 | enumerable: true, 25 | configurable: true 26 | }); 27 | Object.defineProperty(AxiosInstanceFactory, "instance", { 28 | get: function () { 29 | return AxiosInstanceFactory._instance; 30 | }, 31 | enumerable: true, 32 | configurable: true 33 | }); 34 | return AxiosInstanceFactory; 35 | }()); 36 | exports.default = AxiosInstanceFactory; 37 | //# sourceMappingURL=AxiosInstanceFactory.js.map -------------------------------------------------------------------------------- /src/actuator/RequestActuator.ts: -------------------------------------------------------------------------------- 1 | import AbstractRequestActuator from "./AbstractRequestActuator"; 2 | import {AxiosError, AxiosResponse} from "axios"; 3 | import IRequest from "./IRequest"; 4 | import ErrorMessage from "./message/ErrorMessage"; 5 | 6 | export default class RequestActuator extends AbstractRequestActuator { 7 | constructor(request: IRequest) { 8 | super(request); 9 | } 10 | 11 | protected onResponse(response: AxiosResponse): void { 12 | this.request.config.request.do.call(null, response); 13 | } 14 | 15 | protected onError(error: AxiosError): void { 16 | if (!error.response) { 17 | console.warn(error); 18 | if (ErrorMessage.isImplements()) { 19 | ErrorMessage.autoShowErrorMsg(this.request.config.errorMsg.startStr, error.message, this.request.config.errorMsg.once); 20 | } 21 | return; 22 | } 23 | if (this.request.config.errorMsg.enable) { 24 | if (ErrorMessage.isImplements()) { 25 | ErrorMessage.autoShowErrorMsg(this.request.config.errorMsg.startStr, error.response.data, this.request.config.errorMsg.once); 26 | } 27 | if (this.request.config.errorMsg.handleFun) { 28 | this.request.config.errorMsg.handleFun.call(null, error); 29 | } 30 | } 31 | } 32 | 33 | protected onAfter(): void { 34 | if (this.request.config.request.after) { 35 | this.request.config.request.after.call(null) 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /dist/actuator/message/ErrorMessage.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | var ErrorMessage = (function () { 4 | function ErrorMessage() { 5 | } 6 | Object.defineProperty(ErrorMessage, "errorMsgImpl", { 7 | set: function (errorMsg) { 8 | ErrorMessage.errorMsg = errorMsg; 9 | }, 10 | enumerable: true, 11 | configurable: true 12 | }); 13 | ErrorMessage.showOff = function () { 14 | ErrorMessage.isShow = false; 15 | }; 16 | ErrorMessage.isImplements = function () { 17 | return ErrorMessage.errorMsg !== undefined; 18 | }; 19 | ErrorMessage.autoShowErrorMsg = function (title, msg, once) { 20 | if (once === void 0) { once = false; } 21 | if (once) { 22 | ErrorMessage.showOnceErrorMsg(title, msg); 23 | } 24 | else { 25 | ErrorMessage.showErrorMsg(title, msg); 26 | } 27 | }; 28 | ErrorMessage.showErrorMsg = function (title, msg) { 29 | var _a; 30 | (_a = ErrorMessage.errorMsg) === null || _a === void 0 ? void 0 : _a.showErrorToast(title, msg); 31 | }; 32 | ErrorMessage.showOnceErrorMsg = function (title, msg) { 33 | if (ErrorMessage.isShow) { 34 | return; 35 | } 36 | else { 37 | ErrorMessage.showErrorMsg(title, msg); 38 | ErrorMessage.isShow = true; 39 | } 40 | }; 41 | ErrorMessage.isShow = false; 42 | return ErrorMessage; 43 | }()); 44 | exports.default = ErrorMessage; 45 | //# sourceMappingURL=ErrorMessage.js.map -------------------------------------------------------------------------------- /dist/factory/AxiosInstanceFactoryBuilder.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __importDefault = (this && this.__importDefault) || function (mod) { 3 | return (mod && mod.__esModule) ? mod : { "default": mod }; 4 | }; 5 | Object.defineProperty(exports, "__esModule", { value: true }); 6 | var AxiosInstanceFactory_1 = __importDefault(require("./AxiosInstanceFactory")); 7 | var AxiosInstanceFactoryBuilder = (function () { 8 | function AxiosInstanceFactoryBuilder() { 9 | this._timeOut = 1000 * 12; 10 | } 11 | AxiosInstanceFactoryBuilder.prototype.requestInterceptor = function (value) { 12 | this._requestInterceptor = value; 13 | return this; 14 | }; 15 | AxiosInstanceFactoryBuilder.prototype.responseInterceptor = function (value) { 16 | this._responseInterceptor = value; 17 | return this; 18 | }; 19 | AxiosInstanceFactoryBuilder.prototype.timeOut = function (value) { 20 | this._timeOut = value; 21 | return this; 22 | }; 23 | AxiosInstanceFactoryBuilder.prototype.build = function () { 24 | AxiosInstanceFactory_1.default.init({ timeout: this._timeOut }); 25 | if (this._requestInterceptor) { 26 | AxiosInstanceFactory_1.default.requestInterceptor = this._requestInterceptor; 27 | } 28 | if (this._responseInterceptor) { 29 | AxiosInstanceFactory_1.default.responseInterceptor = this._responseInterceptor; 30 | } 31 | }; 32 | return AxiosInstanceFactoryBuilder; 33 | }()); 34 | exports.default = AxiosInstanceFactoryBuilder; 35 | //# sourceMappingURL=AxiosInstanceFactoryBuilder.js.map -------------------------------------------------------------------------------- /src/actuator/distribution/Distribution.ts: -------------------------------------------------------------------------------- 1 | import {HttpRequestMethods} from "../../config/IConfig"; 2 | import {AxiosInstance, AxiosResponse} from "axios"; 3 | import IRequest from "../IRequest"; 4 | import GetRequestActuator from "../method/GetRequestActuator"; 5 | import PostRequestActuator from "../method/PostRequestActuator"; 6 | import DeleteRequestActuator from "../method/DeleteRequestActuator"; 7 | import PatchRequestActuator from "../method/PatchRequestActuator"; 8 | import PutRequestActuator from "../method/PutRequestActuator"; 9 | 10 | export default class Distribution { 11 | private readonly method: HttpRequestMethods; 12 | 13 | constructor(method: HttpRequestMethods) { 14 | this.method = method; 15 | } 16 | 17 | distribution(instance: AxiosInstance, request: IRequest): Promise { 18 | switch (this.method) { 19 | case HttpRequestMethods.GET: { 20 | return new GetRequestActuator().invoke(instance, request); 21 | } 22 | case HttpRequestMethods.POST: { 23 | return new PostRequestActuator().invoke(instance, request); 24 | } 25 | case HttpRequestMethods.DELETE: { 26 | return new DeleteRequestActuator().invoke(instance, request); 27 | } 28 | case HttpRequestMethods.PATCH: { 29 | return new PatchRequestActuator().invoke(instance, request); 30 | } 31 | case HttpRequestMethods.PUT: { 32 | return new PutRequestActuator().invoke(instance, request); 33 | } 34 | } 35 | } 36 | } -------------------------------------------------------------------------------- /dist/config/builder/PatchBuilder.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __extends = (this && this.__extends) || (function () { 3 | var extendStatics = function (d, b) { 4 | extendStatics = Object.setPrototypeOf || 5 | ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || 6 | function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; 7 | return extendStatics(d, b); 8 | }; 9 | return function (d, b) { 10 | extendStatics(d, b); 11 | function __() { this.constructor = d; } 12 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); 13 | }; 14 | })(); 15 | var __importDefault = (this && this.__importDefault) || function (mod) { 16 | return (mod && mod.__esModule) ? mod : { "default": mod }; 17 | }; 18 | Object.defineProperty(exports, "__esModule", { value: true }); 19 | var AbstractUrlSearchAndFormDataBuilder_1 = __importDefault(require("./AbstractUrlSearchAndFormDataBuilder")); 20 | var IConfig_1 = require("../IConfig"); 21 | var PatchBuilder = (function (_super) { 22 | __extends(PatchBuilder, _super); 23 | function PatchBuilder(url) { 24 | return _super.call(this, IConfig_1.HttpRequestMethods.PATCH, url) || this; 25 | } 26 | PatchBuilder.prototype.withJson = function (param) { 27 | this.config.data.type = IConfig_1.DataType.JSON; 28 | this.config.data.json = param; 29 | return this; 30 | }; 31 | return PatchBuilder; 32 | }(AbstractUrlSearchAndFormDataBuilder_1.default)); 33 | exports.default = PatchBuilder; 34 | //# sourceMappingURL=PatchBuilder.js.map -------------------------------------------------------------------------------- /src/actuator/method/PostRequestActuator.ts: -------------------------------------------------------------------------------- 1 | import IRequestActuator from "../IRequestActuator"; 2 | import {AxiosInstance, AxiosRequestConfig, AxiosResponse} from "axios"; 3 | import IRequest from "../IRequest"; 4 | import {HttpRequestMethods} from "../../config/IConfig"; 5 | 6 | export default class PostRequestActuator implements IRequestActuator { 7 | canInvoke(method: HttpRequestMethods): boolean { 8 | return method === HttpRequestMethods.POST; 9 | } 10 | 11 | invoke(instance: AxiosInstance, request: IRequest): Promise { 12 | if (request.config.data.urlSearchParam) { 13 | return instance.post(request.url, request.config.data.urlSearchParam); 14 | } else if (request.config.data.form) { 15 | if (request.config.data.form.uploadProgress) { 16 | const uploadProgress = request.config.data.form.uploadProgress; 17 | const config: AxiosRequestConfig = { 18 | headers: {'content-type': 'multipart/form-data'}, 19 | onUploadProgress: (progressEvent: any) => { 20 | let progress = progressEvent.loaded / progressEvent.total * 100 | 0; 21 | uploadProgress(progress); 22 | } 23 | }; 24 | return instance.post(request.url, request.config.data.form.param, config); 25 | } else { 26 | return instance.post(request.url, request.config.data.form.param, {headers: {'content-type': 'multipart/form-data'}}); 27 | } 28 | } else { 29 | return instance.post(request.url); 30 | } 31 | } 32 | } -------------------------------------------------------------------------------- /dist/actuator/method/PostRequestActuator.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | var IConfig_1 = require("../../config/IConfig"); 4 | var PostRequestActuator = (function () { 5 | function PostRequestActuator() { 6 | } 7 | PostRequestActuator.prototype.canInvoke = function (method) { 8 | return method === IConfig_1.HttpRequestMethods.POST; 9 | }; 10 | PostRequestActuator.prototype.invoke = function (instance, request) { 11 | if (request.config.data.urlSearchParam) { 12 | return instance.post(request.url, request.config.data.urlSearchParam); 13 | } 14 | else if (request.config.data.form) { 15 | if (request.config.data.form.uploadProgress) { 16 | var uploadProgress_1 = request.config.data.form.uploadProgress; 17 | var config = { 18 | headers: { 'content-type': 'multipart/form-data' }, 19 | onUploadProgress: function (progressEvent) { 20 | var progress = progressEvent.loaded / progressEvent.total * 100 | 0; 21 | uploadProgress_1(progress); 22 | } 23 | }; 24 | return instance.post(request.url, request.config.data.form.param, config); 25 | } 26 | else { 27 | return instance.post(request.url, request.config.data.form.param, { headers: { 'content-type': 'multipart/form-data' } }); 28 | } 29 | } 30 | else { 31 | return instance.post(request.url); 32 | } 33 | }; 34 | return PostRequestActuator; 35 | }()); 36 | exports.default = PostRequestActuator; 37 | //# sourceMappingURL=PostRequestActuator.js.map -------------------------------------------------------------------------------- /src/actuator/AbstractRequestActuator.ts: -------------------------------------------------------------------------------- 1 | import {AxiosError, AxiosInstance, AxiosResponse} from 'axios' 2 | import IRequest from "./IRequest"; 3 | import AxiosInstanceFactory from "../factory/AxiosInstanceFactory"; 4 | import Distribution from "./distribution/Distribution"; 5 | import ErrorMessage from "./message/ErrorMessage"; 6 | 7 | /** 8 | * 请求执行器 9 | */ 10 | export default abstract class AbstractRequestActuator { 11 | protected readonly instance: AxiosInstance; 12 | protected readonly request: IRequest; 13 | 14 | protected constructor(request: IRequest) { 15 | this.instance = AxiosInstanceFactory.instance; 16 | this.request = request; 17 | this.distribution(); 18 | } 19 | 20 | private distribution(): void { 21 | new Distribution(this.request.method) 22 | .distribution(this.instance, this.request) 23 | .then(response => { 24 | if (response.status === this.request.config.success.code) { 25 | this.onResponse.call(this, response); 26 | } else { 27 | if (ErrorMessage.isImplements() && this.request.config.errorMsg.enable) { 28 | ErrorMessage.autoShowErrorMsg(this.request.config.errorMsg.startStr, response.data, this.request.config.errorMsg.once) 29 | } 30 | } 31 | }) 32 | .catch(error => { 33 | this.onError.call(this, error); 34 | }) 35 | .then(() => { 36 | this.onAfter.call(this); 37 | }) 38 | } 39 | 40 | protected abstract onResponse(response: AxiosResponse): void; 41 | 42 | protected abstract onError(error: AxiosError): void 43 | 44 | protected abstract onAfter(): void; 45 | } 46 | -------------------------------------------------------------------------------- /src/Http.ts: -------------------------------------------------------------------------------- 1 | import GetBuilder from "./config/builder/GetBuilder"; 2 | import PostBuilder from "./config/builder/PostBuilder"; 3 | import PatchBuilder from "./config/builder/PatchBuilder"; 4 | import DeleteBuilder from "./config/builder/DeleteBuilder"; 5 | import PutBuilder from "./config/builder/PutBuilder"; 6 | import AxiosInstanceFactory from "./factory/AxiosInstanceFactory"; 7 | import ErrorMessage from "./actuator/message/ErrorMessage"; 8 | 9 | export default class Http { 10 | static Get(url: string) { 11 | return new GetBuilder(url); 12 | } 13 | 14 | static Post(url: string) { 15 | return new PostBuilder(url); 16 | } 17 | 18 | static Delete(url: string) { 19 | return new DeleteBuilder(url); 20 | } 21 | 22 | static Patch(url: string) { 23 | return new PatchBuilder(url); 24 | } 25 | 26 | static Put(url: string) { 27 | return new PutBuilder(url); 28 | } 29 | 30 | static Download(url: string, fileName: (fileName: any) => string) { 31 | AxiosInstanceFactory.instance 32 | .get(url, { 33 | responseType: 'blob' //指定返回数据的格式为blob 34 | }).then(response => { 35 | let url = window.URL.createObjectURL(response.data); 36 | let a = document.createElement("a"); 37 | document.body.appendChild(a); 38 | a.href = url; 39 | a.download = fileName(response.headers); 40 | a.click(); 41 | window.URL.revokeObjectURL(url); 42 | }).catch(error => { 43 | if (error.response !== undefined) { 44 | console.warn(error); 45 | if (ErrorMessage.isImplements()) { 46 | ErrorMessage.showErrorMsg("下载失败:", error.toString()); 47 | } 48 | } 49 | }); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /dist/actuator/AbstractRequestActuator.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __importDefault = (this && this.__importDefault) || function (mod) { 3 | return (mod && mod.__esModule) ? mod : { "default": mod }; 4 | }; 5 | Object.defineProperty(exports, "__esModule", { value: true }); 6 | var AxiosInstanceFactory_1 = __importDefault(require("../factory/AxiosInstanceFactory")); 7 | var Distribution_1 = __importDefault(require("./distribution/Distribution")); 8 | var ErrorMessage_1 = __importDefault(require("./message/ErrorMessage")); 9 | var AbstractRequestActuator = (function () { 10 | function AbstractRequestActuator(request) { 11 | this.instance = AxiosInstanceFactory_1.default.instance; 12 | this.request = request; 13 | this.distribution(); 14 | } 15 | AbstractRequestActuator.prototype.distribution = function () { 16 | var _this = this; 17 | new Distribution_1.default(this.request.method) 18 | .distribution(this.instance, this.request) 19 | .then(function (response) { 20 | if (response.status === _this.request.config.success.code) { 21 | _this.onResponse.call(_this, response); 22 | } 23 | else { 24 | if (ErrorMessage_1.default.isImplements() && _this.request.config.errorMsg.enable) { 25 | ErrorMessage_1.default.autoShowErrorMsg(_this.request.config.errorMsg.startStr, response.data, _this.request.config.errorMsg.once); 26 | } 27 | } 28 | }) 29 | .catch(function (error) { 30 | _this.onError.call(_this, error); 31 | }) 32 | .then(function () { 33 | _this.onAfter.call(_this); 34 | }); 35 | }; 36 | return AbstractRequestActuator; 37 | }()); 38 | exports.default = AbstractRequestActuator; 39 | //# sourceMappingURL=AbstractRequestActuator.js.map -------------------------------------------------------------------------------- /src/config/builder/AbstractBuilder.ts: -------------------------------------------------------------------------------- 1 | import {AxiosError, AxiosResponse} from "axios"; 2 | import IConfig, {DataType, HttpRequestMethods} from "../IConfig"; 3 | import RequestActuator from "../../actuator/RequestActuator"; 4 | 5 | export default abstract class AbstractBuilder { 6 | private readonly method: HttpRequestMethods; 7 | private readonly url: string; 8 | 9 | protected config: IConfig = { 10 | data: { 11 | type: DataType.NONE 12 | }, 13 | request: { 14 | do: () => { 15 | } 16 | }, 17 | errorMsg: { 18 | once: false, 19 | enable: true, 20 | startStr: '错误' 21 | }, 22 | success: { 23 | code: 200 24 | } 25 | }; 26 | 27 | protected constructor(method: HttpRequestMethods, url: string) { 28 | this.method = method; 29 | this.url = url; 30 | } 31 | 32 | withSuccessCode(code: number) { 33 | this.config.success.code = code; 34 | return this; 35 | } 36 | 37 | withEnableErrorMsg(enable: boolean) { 38 | this.config.errorMsg.enable = enable; 39 | return this; 40 | } 41 | 42 | withErrorStartMsg(msg: string) { 43 | this.config.errorMsg.startStr = msg; 44 | return this; 45 | } 46 | 47 | withOnceMsg() { 48 | this.config.errorMsg.once = true; 49 | return this; 50 | } 51 | 52 | withErrorHandle(func: (error: AxiosError) => void) { 53 | this.config.errorMsg.handleFun = func; 54 | return this; 55 | } 56 | 57 | do(response: (response: AxiosResponse) => void) { 58 | this.config.request.do = response; 59 | new RequestActuator({method: this.method, url: this.url, config: this.config}); 60 | return this; 61 | } 62 | 63 | doAfter(after: () => void) { 64 | this.config.request.after = after; 65 | return this; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /dist/actuator/distribution/Distribution.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __importDefault = (this && this.__importDefault) || function (mod) { 3 | return (mod && mod.__esModule) ? mod : { "default": mod }; 4 | }; 5 | Object.defineProperty(exports, "__esModule", { value: true }); 6 | var IConfig_1 = require("../../config/IConfig"); 7 | var GetRequestActuator_1 = __importDefault(require("../method/GetRequestActuator")); 8 | var PostRequestActuator_1 = __importDefault(require("../method/PostRequestActuator")); 9 | var DeleteRequestActuator_1 = __importDefault(require("../method/DeleteRequestActuator")); 10 | var PatchRequestActuator_1 = __importDefault(require("../method/PatchRequestActuator")); 11 | var PutRequestActuator_1 = __importDefault(require("../method/PutRequestActuator")); 12 | var Distribution = (function () { 13 | function Distribution(method) { 14 | this.method = method; 15 | } 16 | Distribution.prototype.distribution = function (instance, request) { 17 | switch (this.method) { 18 | case IConfig_1.HttpRequestMethods.GET: { 19 | return new GetRequestActuator_1.default().invoke(instance, request); 20 | } 21 | case IConfig_1.HttpRequestMethods.POST: { 22 | return new PostRequestActuator_1.default().invoke(instance, request); 23 | } 24 | case IConfig_1.HttpRequestMethods.DELETE: { 25 | return new DeleteRequestActuator_1.default().invoke(instance, request); 26 | } 27 | case IConfig_1.HttpRequestMethods.PATCH: { 28 | return new PatchRequestActuator_1.default().invoke(instance, request); 29 | } 30 | case IConfig_1.HttpRequestMethods.PUT: { 31 | return new PutRequestActuator_1.default().invoke(instance, request); 32 | } 33 | } 34 | }; 35 | return Distribution; 36 | }()); 37 | exports.default = Distribution; 38 | //# sourceMappingURL=Distribution.js.map -------------------------------------------------------------------------------- /dist/config/builder/AbstractBuilder.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __importDefault = (this && this.__importDefault) || function (mod) { 3 | return (mod && mod.__esModule) ? mod : { "default": mod }; 4 | }; 5 | Object.defineProperty(exports, "__esModule", { value: true }); 6 | var IConfig_1 = require("../IConfig"); 7 | var RequestActuator_1 = __importDefault(require("../../actuator/RequestActuator")); 8 | var AbstractBuilder = (function () { 9 | function AbstractBuilder(method, url) { 10 | this.config = { 11 | data: { 12 | type: IConfig_1.DataType.NONE 13 | }, 14 | request: { 15 | do: function () { 16 | } 17 | }, 18 | errorMsg: { 19 | once: false, 20 | enable: true, 21 | startStr: '错误' 22 | }, 23 | success: { 24 | code: 200 25 | } 26 | }; 27 | this.method = method; 28 | this.url = url; 29 | } 30 | AbstractBuilder.prototype.withSuccessCode = function (code) { 31 | this.config.success.code = code; 32 | return this; 33 | }; 34 | AbstractBuilder.prototype.withEnableErrorMsg = function (enable) { 35 | this.config.errorMsg.enable = enable; 36 | return this; 37 | }; 38 | AbstractBuilder.prototype.withErrorStartMsg = function (msg) { 39 | this.config.errorMsg.startStr = msg; 40 | return this; 41 | }; 42 | AbstractBuilder.prototype.withOnceMsg = function () { 43 | this.config.errorMsg.once = true; 44 | return this; 45 | }; 46 | AbstractBuilder.prototype.withErrorHandle = function (func) { 47 | this.config.errorMsg.handleFun = func; 48 | return this; 49 | }; 50 | AbstractBuilder.prototype.do = function (response) { 51 | this.config.request.do = response; 52 | new RequestActuator_1.default({ method: this.method, url: this.url, config: this.config }); 53 | return this; 54 | }; 55 | AbstractBuilder.prototype.doAfter = function (after) { 56 | this.config.request.after = after; 57 | return this; 58 | }; 59 | return AbstractBuilder; 60 | }()); 61 | exports.default = AbstractBuilder; 62 | //# sourceMappingURL=AbstractBuilder.js.map -------------------------------------------------------------------------------- /dist/Http.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __importDefault = (this && this.__importDefault) || function (mod) { 3 | return (mod && mod.__esModule) ? mod : { "default": mod }; 4 | }; 5 | Object.defineProperty(exports, "__esModule", { value: true }); 6 | var GetBuilder_1 = __importDefault(require("./config/builder/GetBuilder")); 7 | var PostBuilder_1 = __importDefault(require("./config/builder/PostBuilder")); 8 | var PatchBuilder_1 = __importDefault(require("./config/builder/PatchBuilder")); 9 | var DeleteBuilder_1 = __importDefault(require("./config/builder/DeleteBuilder")); 10 | var PutBuilder_1 = __importDefault(require("./config/builder/PutBuilder")); 11 | var AxiosInstanceFactory_1 = __importDefault(require("./factory/AxiosInstanceFactory")); 12 | var ErrorMessage_1 = __importDefault(require("./actuator/message/ErrorMessage")); 13 | var Http = (function () { 14 | function Http() { 15 | } 16 | Http.Get = function (url) { 17 | return new GetBuilder_1.default(url); 18 | }; 19 | Http.Post = function (url) { 20 | return new PostBuilder_1.default(url); 21 | }; 22 | Http.Delete = function (url) { 23 | return new DeleteBuilder_1.default(url); 24 | }; 25 | Http.Patch = function (url) { 26 | return new PatchBuilder_1.default(url); 27 | }; 28 | Http.Put = function (url) { 29 | return new PutBuilder_1.default(url); 30 | }; 31 | Http.Download = function (url, fileName) { 32 | AxiosInstanceFactory_1.default.instance 33 | .get(url, { 34 | responseType: 'blob' 35 | }).then(function (response) { 36 | var url = window.URL.createObjectURL(response.data); 37 | var a = document.createElement("a"); 38 | document.body.appendChild(a); 39 | a.href = url; 40 | a.download = fileName(response.headers); 41 | a.click(); 42 | window.URL.revokeObjectURL(url); 43 | }).catch(function (error) { 44 | if (error.response !== undefined) { 45 | console.warn(error); 46 | if (ErrorMessage_1.default.isImplements()) { 47 | ErrorMessage_1.default.showErrorMsg("下载失败:", error.toString()); 48 | } 49 | } 50 | }); 51 | }; 52 | return Http; 53 | }()); 54 | exports.default = Http; 55 | //# sourceMappingURL=Http.js.map -------------------------------------------------------------------------------- /dist/config/builder/AbstractUrlSearchAndFormDataBuilder.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __extends = (this && this.__extends) || (function () { 3 | var extendStatics = function (d, b) { 4 | extendStatics = Object.setPrototypeOf || 5 | ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || 6 | function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; 7 | return extendStatics(d, b); 8 | }; 9 | return function (d, b) { 10 | extendStatics(d, b); 11 | function __() { this.constructor = d; } 12 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); 13 | }; 14 | })(); 15 | var __importDefault = (this && this.__importDefault) || function (mod) { 16 | return (mod && mod.__esModule) ? mod : { "default": mod }; 17 | }; 18 | Object.defineProperty(exports, "__esModule", { value: true }); 19 | var AbstractBuilder_1 = __importDefault(require("./AbstractBuilder")); 20 | var IConfig_1 = require("../IConfig"); 21 | var AbstractUrlSearchAndFormDataBuilder = (function (_super) { 22 | __extends(AbstractUrlSearchAndFormDataBuilder, _super); 23 | function AbstractUrlSearchAndFormDataBuilder() { 24 | return _super !== null && _super.apply(this, arguments) || this; 25 | } 26 | AbstractUrlSearchAndFormDataBuilder.prototype.withFormData = function (params, uploadProgress) { 27 | var param = new FormData(); 28 | for (var p in params) { 29 | if (params.hasOwnProperty(p)) { 30 | var v = params[p]; 31 | param.append(p, v); 32 | } 33 | } 34 | this.config.data.type = IConfig_1.DataType.FORM_DATA; 35 | this.config.data.form = { param: param, uploadProgress: uploadProgress }; 36 | return this; 37 | }; 38 | AbstractUrlSearchAndFormDataBuilder.prototype.withURLSearchParams = function (params) { 39 | var param = new URLSearchParams(); 40 | for (var p in params) { 41 | if (params.hasOwnProperty(p)) { 42 | var v = params[p]; 43 | param.append(p, v); 44 | } 45 | } 46 | this.config.data.type = IConfig_1.DataType.URL_SEARCH_PARAM; 47 | this.config.data.urlSearchParam = param; 48 | return this; 49 | }; 50 | return AbstractUrlSearchAndFormDataBuilder; 51 | }(AbstractBuilder_1.default)); 52 | exports.default = AbstractUrlSearchAndFormDataBuilder; 53 | //# sourceMappingURL=AbstractUrlSearchAndFormDataBuilder.js.map -------------------------------------------------------------------------------- /dist/actuator/RequestActuator.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __extends = (this && this.__extends) || (function () { 3 | var extendStatics = function (d, b) { 4 | extendStatics = Object.setPrototypeOf || 5 | ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || 6 | function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; 7 | return extendStatics(d, b); 8 | }; 9 | return function (d, b) { 10 | extendStatics(d, b); 11 | function __() { this.constructor = d; } 12 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); 13 | }; 14 | })(); 15 | var __importDefault = (this && this.__importDefault) || function (mod) { 16 | return (mod && mod.__esModule) ? mod : { "default": mod }; 17 | }; 18 | Object.defineProperty(exports, "__esModule", { value: true }); 19 | var AbstractRequestActuator_1 = __importDefault(require("./AbstractRequestActuator")); 20 | var ErrorMessage_1 = __importDefault(require("./message/ErrorMessage")); 21 | var RequestActuator = (function (_super) { 22 | __extends(RequestActuator, _super); 23 | function RequestActuator(request) { 24 | return _super.call(this, request) || this; 25 | } 26 | RequestActuator.prototype.onResponse = function (response) { 27 | this.request.config.request.do.call(null, response); 28 | }; 29 | RequestActuator.prototype.onError = function (error) { 30 | if (!error.response) { 31 | console.warn(error); 32 | if (ErrorMessage_1.default.isImplements()) { 33 | ErrorMessage_1.default.autoShowErrorMsg(this.request.config.errorMsg.startStr, error.message, this.request.config.errorMsg.once); 34 | } 35 | return; 36 | } 37 | if (this.request.config.errorMsg.enable) { 38 | if (ErrorMessage_1.default.isImplements()) { 39 | ErrorMessage_1.default.autoShowErrorMsg(this.request.config.errorMsg.startStr, error.response.data, this.request.config.errorMsg.once); 40 | } 41 | if (this.request.config.errorMsg.handleFun) { 42 | this.request.config.errorMsg.handleFun.call(null, error); 43 | } 44 | } 45 | }; 46 | RequestActuator.prototype.onAfter = function () { 47 | if (this.request.config.request.after) { 48 | this.request.config.request.after.call(null); 49 | } 50 | }; 51 | return RequestActuator; 52 | }(AbstractRequestActuator_1.default)); 53 | exports.default = RequestActuator; 54 | //# sourceMappingURL=RequestActuator.js.map -------------------------------------------------------------------------------- /test/test.js: -------------------------------------------------------------------------------- 1 | import {AxiosHelperConfig, Post} from "../dist" 2 | 3 | AxiosHelperConfig.errorMsgImpl = { 4 | showErrorToast(title, data) { 5 | console.log(title + data.msg); 6 | setTimeout(() => { 7 | AxiosHelperConfig.onceMsgFinish(); 8 | console.log('one message show finish') 9 | }, 2000); 10 | } 11 | }; 12 | 13 | AxiosHelperConfig.axiosInstanceBuilder 14 | .requestInterceptor({ 15 | onFulfilled: value => { 16 | value.headers = {"Accept": "application/json"}; 17 | return value; 18 | }, 19 | onRejected: error => { 20 | return Promise.reject(error); 21 | } 22 | }) 23 | .responseInterceptor({ 24 | onFulfilled: response => { 25 | return Promise.resolve(response); 26 | }, 27 | onRejected: error => { 28 | if (error.response === undefined) { 29 | return Promise.reject(error); 30 | } 31 | if (error.response.status) { 32 | switch (error.response.status) { 33 | case 401: 34 | setTimeout(() => { 35 | window.location.href = "/login"; 36 | }, 2000); 37 | return; 38 | case 403: 39 | console.warn('权限不足'); 40 | break; 41 | case 404: 42 | console.warn('请求URL不存在'); 43 | break; 44 | case 500: 45 | console.warn('服务器错误'); 46 | break; 47 | case 503: 48 | console.warn('服务器错误'); 49 | break; 50 | default: 51 | console.warn(error); 52 | } 53 | return Promise.reject(error); 54 | } 55 | } 56 | }) 57 | .build(); 58 | 59 | (() => { 60 | /* Get("http://localhost:8888/security/login") 61 | .withSuccessCode(100) 62 | .withEnableErrorMsg(true) 63 | .withOnceMsg() 64 | .do(response => { 65 | console.log(response) 66 | }) 67 | .doAfter(() => { 68 | console.log("after") 69 | });*/ 70 | 71 | Post("http://localhost:8888/security/login") 72 | .withURLSearchParams({username: "a", password: 'aa'}) 73 | .withOnceMsg() 74 | .withSuccessCode(200) 75 | .withEnableErrorMsg(true) 76 | .do(response => { 77 | console.log(response) 78 | }) 79 | .doAfter(() => { 80 | console.log("after1") 81 | }); 82 | 83 | Post("http://localhost:8888/security/login") 84 | .withURLSearchParams({username: "a", password: 'aa'}) 85 | .withSuccessCode(200) 86 | .withOnceMsg() 87 | .withEnableErrorMsg(true) 88 | .do(response => { 89 | console.log(response) 90 | }) 91 | .doAfter(() => { 92 | console.log("after2") 93 | }); 94 | 95 | document.getElementById('req').addEventListener('click', () => { 96 | Post("http://localhost:8888/security/login") 97 | .withURLSearchParams({username: "a", password: 'aa'}) 98 | .withSuccessCode(200) 99 | .withOnceMsg() 100 | .withEnableErrorMsg(true) 101 | .do(response => { 102 | console.log(response) 103 | }) 104 | .doAfter(() => { 105 | console.log("after") 106 | }); 107 | }); 108 | /* 109 | Patch("http://localhost:8888/a") 110 | .withJson({a: 1}) 111 | .do(response => { 112 | console.log(response) 113 | })*/ 114 | })(); 115 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Axios Helper Lib 2 | 3 | [![GitHub stars](https://img.shields.io/github/stars/itning/axios-helper.svg?style=social&label=Stars)](https://github.com/itning/axios-helper/stargazers) 4 | [![GitHub forks](https://img.shields.io/github/forks/itning/axios-helper.svg?style=social&label=Fork)](https://github.com/itning/axios-helper/network/members) 5 | [![GitHub watchers](https://img.shields.io/github/watchers/itning/axios-helper.svg?style=social&label=Watch)](https://github.com/itning/axios-helper/watchers) 6 | [![GitHub followers](https://img.shields.io/github/followers/itning.svg?style=social&label=Follow)](https://github.com/itning?tab=followers) 7 | 8 | [![GitHub issues](https://img.shields.io/github/issues/itning/axios-helper.svg)](https://github.com/itning/axios-helper/issues) 9 | [![GitHub license](https://img.shields.io/github/license/itning/axios-helper.svg)](https://github.com/itning/axios-helper/blob/master/LICENSE) 10 | [![GitHub last commit](https://img.shields.io/github/last-commit/itning/axios-helper.svg)](https://github.com/itning/axios-helper/commits) 11 | [![GitHub release](https://img.shields.io/github/release/itning/axios-helper.svg)](https://github.com/itning/axios-helper/releases) 12 | [![npm version](https://badge.fury.io/js/%40itning%2Faxios-helper.svg)](https://badge.fury.io/js/%40itning%2Faxios-helper) 13 | [![npm downloads](https://img.shields.io/npm/dw/@itning/axios-helper)](https://www.npmjs.com/package/@itning/axios-helper) 14 | [![GitHub repo size in bytes](https://img.shields.io/github/repo-size/itning/axios-helper.svg)](https://github.com/itning/axios-helper) 15 | [![HitCount](https://hitcount.itning.com?u=itning&r=axios-helper)](https://github.com/itning/axios-helper) 16 | [![language](https://img.shields.io/badge/language-TypeScript-green.svg)](https://github.com/itning/axios-helper) 17 | 18 | - How to use this lib ? 19 | 20 | ```shell 21 | npm i @itning/axios-helper 22 | ``` 23 | 24 | ```javascript 25 | import {AxiosHelperConfig, Patch} from "@itning/axios-helper"; 26 | // Config message toast when net error. 27 | AxiosHelperConfig.errorMsgImpl = { 28 | showErrorToast(title, data) { 29 | console.log(title + data.msg); 30 | setTimeout(() => { 31 | AxiosHelperConfig.onceMsgFinish(); 32 | console.log('one message show finish') 33 | }, 2000); 34 | } 35 | }; 36 | // Config interceptor for each request or response. 37 | AxiosHelperConfig.axiosInstanceBuilder 38 | .requestInterceptor({ 39 | onFulfilled: request => { 40 | 41 | }, 42 | onRejected: error => { 43 | 44 | } 45 | }) 46 | .responseInterceptor({ 47 | onFulfilled: response => { 48 | 49 | }, 50 | onRejected: error => { 51 | 52 | } 53 | }) 54 | .build(); 55 | // You can use this api to send http patch request. 56 | // Other http request 57 | //Get("http://api.localhost.com") 58 | //Delete("http://api.localhost.com") 59 | //Post("http://api.localhost.com") 60 | //Put("http://api.localhost.com") 61 | Patch("http://api.localhost.com") 62 | // Config http success code,default 200. 63 | .withSuccessCode(200) 64 | // Config whether to open error message, defalut true. 65 | .withEnableErrorMsg(false) 66 | // Config error message title, defalut '错误'. 67 | .withErrorStartMsg("") 68 | // Invoke function when error happen. 69 | .withErrorHandle((error) => { 70 | 71 | }) 72 | // Only show once msg 73 | .withOnceMsg() 74 | // Send http request with form data. 75 | .withFormData({"id": "1"}) 76 | // Send http request with url search param data. 77 | .withURLSearchParams({}) 78 | // Send http request with json data. 79 | .withJson({1: 1}) 80 | // When server response received will call this function. 81 | // Must call this function and will send http request. 82 | .do(response => { 83 | 84 | }) 85 | // When do function invoked. 86 | .doAfter(() => { 87 | 88 | }); 89 | ``` 90 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright 2020 itning 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | --------------------------------------------------------------------------------