@ningboyz/apis 1.8.15 → 1.8.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ningboyz/apis",
3
- "version": "1.8.15",
3
+ "version": "1.8.16",
4
4
  "private": false,
5
5
  "description": "宁波甬政请求库",
6
6
  "author": "nbyt-syq",
@@ -17,7 +17,7 @@
17
17
  "registry": "https://registry.npmjs.org/"
18
18
  },
19
19
  "dependencies": {
20
- "@ningboyz/types": "1.8.15",
20
+ "@ningboyz/types": "1.8.16",
21
21
  "axios": "1.8.4",
22
22
  "lodash": "^4.17.21"
23
23
  },
package/packages/axios.ts CHANGED
@@ -12,16 +12,23 @@ export interface IAxiosConfig {
12
12
  interceptorsRequest?: (request: InternalAxiosRequestConfig<any>) => InternalAxiosRequestConfig<any>;
13
13
  interceptorsResponse?: (response: AxiosResponse<any>) => AxiosResponse<any>;
14
14
  loseTokenState?: () => void;
15
+ /** 不需要拼接 /gapi 前缀的模块(如 tyc),传 true 时请求地址原样使用 */
16
+ noPrefix?: boolean;
15
17
  }
16
18
 
17
19
  class HttpRequest {
18
20
  private instance: AxiosInstance;
19
21
  private readonly API_PREFIX: string = "/gapi";
20
22
  private readonly JAVA_API_PREFIX: string = "/japi";
23
+ private readonly noPrefix: boolean;
21
24
  private readonly METHOD_GET: string = "GET";
22
25
  private readonly METHOD_POST: string = "POST";
23
26
 
24
27
  private getRequestUrl(url: string) {
28
+ /** 不需要前缀的模块(如 tyc)直接返回原地址 */
29
+ if (this.noPrefix) {
30
+ return url;
31
+ }
25
32
  if (url.startsWith(this.API_PREFIX) || url.startsWith(this.JAVA_API_PREFIX)) {
26
33
  return url;
27
34
  }
@@ -34,7 +41,8 @@ class HttpRequest {
34
41
  }
35
42
 
36
43
  constructor(config: IAxiosConfig) {
37
- const { baseURL, timeout = 60000, getUserInfo, interceptorsRequest, interceptorsResponse, loseTokenState } = config;
44
+ const { baseURL, timeout = 60000, getUserInfo, interceptorsRequest, interceptorsResponse, loseTokenState, noPrefix = false } = config;
45
+ this.noPrefix = noPrefix;
38
46
  this.instance = axios.create({
39
47
  baseURL,
40
48
  timeout
@@ -57,7 +57,7 @@ class TycRequest {
57
57
  public sync: SyncRequest;
58
58
 
59
59
  constructor(config: IAxiosConfig) {
60
- const request = createRequest(config);
60
+ const request = createRequest({ ...config, noPrefix: true });
61
61
  this.profile = new ProfileRequest(request);
62
62
  this.baseInfo = new BaseInfoRequest(request);
63
63
  this.staff = new StaffRequest(request);