@ks-web/use 0.0.7 → 0.0.9

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/dist/index.cjs.js CHANGED
@@ -4962,13 +4962,16 @@ var getErrorsTips = {
4962
4962
  };
4963
4963
  function ksResponseInterceptor(res) {
4964
4964
  if (res.data && String(res.data.code) === "0") {
4965
- return res.data.data;
4965
+ return res;
4966
4966
  }
4967
- const { tips } = res.config.userConfig || {};
4968
- let { msg = res.message || res.msg } = res.data || {};
4969
- const errorTips = getErrorsTips[msg];
4970
- if (tips !== false && msg) {
4971
- (0, import_ks.showToast)(errorTips || msg);
4967
+ try {
4968
+ const { tips } = res.config.userConfig || {};
4969
+ let { msg = res.message || res.msg } = res.data || {};
4970
+ const errorTips = getErrorsTips[msg];
4971
+ if (tips !== false && msg) {
4972
+ (0, import_ks.showToast)(errorTips || msg);
4973
+ }
4974
+ } catch (e) {
4972
4975
  }
4973
4976
  return Promise.reject(res);
4974
4977
  }
@@ -5026,7 +5029,9 @@ function createCasHeaders(opt) {
5026
5029
  sign: _getSign(),
5027
5030
  format: "JSON",
5028
5031
  timestamp: now,
5029
- "x-webtrace-id": _getXWebTraceId(user.id, menu.id, now)
5032
+ "x-webtrace-id": _getXWebTraceId(user.id, menu.id, now),
5033
+ webTraceId: `${user.id}-${now}-${_random(4)}-${menu.id || "xxxx"}`,
5034
+ "X-menu-id": menu.id
5030
5035
  };
5031
5036
  return _headers;
5032
5037
  }
@@ -4944,13 +4944,16 @@ var getErrorsTips = {
4944
4944
  };
4945
4945
  function ksResponseInterceptor(res) {
4946
4946
  if (res.data && String(res.data.code) === "0") {
4947
- return res.data.data;
4947
+ return res;
4948
4948
  }
4949
- const { tips } = res.config.userConfig || {};
4950
- let { msg = res.message || res.msg } = res.data || {};
4951
- const errorTips = getErrorsTips[msg];
4952
- if (tips !== false && msg) {
4953
- showToast(errorTips || msg);
4949
+ try {
4950
+ const { tips } = res.config.userConfig || {};
4951
+ let { msg = res.message || res.msg } = res.data || {};
4952
+ const errorTips = getErrorsTips[msg];
4953
+ if (tips !== false && msg) {
4954
+ showToast(errorTips || msg);
4955
+ }
4956
+ } catch (e) {
4954
4957
  }
4955
4958
  return Promise.reject(res);
4956
4959
  }
@@ -5008,7 +5011,9 @@ function createCasHeaders(opt) {
5008
5011
  sign: _getSign(),
5009
5012
  format: "JSON",
5010
5013
  timestamp: now,
5011
- "x-webtrace-id": _getXWebTraceId(user.id, menu.id, now)
5014
+ "x-webtrace-id": _getXWebTraceId(user.id, menu.id, now),
5015
+ webTraceId: `${user.id}-${now}-${_random(4)}-${menu.id || "xxxx"}`,
5016
+ "X-menu-id": menu.id
5012
5017
  };
5013
5018
  return _headers;
5014
5019
  }
@@ -52,15 +52,15 @@ export declare function handleOptions(httpInstance: HttpClient, url: string, met
52
52
  formSerializer?: import("axios").FormSerializerOptions | undefined;
53
53
  userConfig: {
54
54
  baseURL?: string | undefined;
55
- headers?: Record<string, any> | undefined;
55
+ headers?: Record<string, any> | (Record<string, any> & import("axios").AxiosHeaders) | undefined;
56
56
  cancelToken?: CancelToken | import("axios").CancelTokenSource | undefined;
57
57
  ksAdapter?: boolean | undefined;
58
58
  failToast?: boolean | undefined;
59
59
  loading?: boolean | undefined;
60
60
  tips?: boolean | undefined;
61
61
  customHeaders?: boolean | undefined;
62
- onUploadProgress?: ((progressEvent: any) => void) | undefined;
63
- onDownloadProgress?: ((progressEvent: any) => void) | undefined;
62
+ onUploadProgress?: ((progressEvent: import("axios").AxiosProgressEvent) => void) | undefined;
63
+ onDownloadProgress?: ((progressEvent: import("axios").AxiosProgressEvent) => void) | undefined;
64
64
  options?: Record<string, any> | undefined;
65
65
  origin?: boolean | undefined;
66
66
  appKey?: string | number | undefined;
@@ -1,7 +1,7 @@
1
- import type { AxiosRequestTransformer, AxiosResponseTransformer, AxiosAdapter, AxiosRequestConfig, AxiosInstance, CancelToken, CancelTokenSource, Canceler, AxiosResponse } from 'axios';
2
- export interface HttpOptions {
1
+ import type { AxiosRequestTransformer, AxiosResponseTransformer, AxiosAdapter, AxiosRequestConfig, AxiosInstance, CancelToken, CancelTokenSource, Canceler, AxiosResponse, AxiosProgressEvent, AxiosHeaders } from 'axios';
2
+ export interface HttpOptions<D = any> {
3
3
  baseURL?: string;
4
- headers?: Record<string, any>;
4
+ headers?: AxiosHeaders | Record<string, D>;
5
5
  timeout?: number;
6
6
  adapter?: AxiosAdapter;
7
7
  transformRequest?: AxiosRequestTransformer;
@@ -17,18 +17,18 @@ export interface HttpOptions {
17
17
  casToken?: boolean;
18
18
  appKey?: string | number;
19
19
  }
20
- export interface RequestOptions {
20
+ export interface RequestOptions<D = any> {
21
21
  baseURL?: string;
22
- headers?: Record<string, any>;
22
+ headers?: Record<string, D>;
23
23
  cancelToken?: CancelToken | CancelTokenSource;
24
24
  ksAdapter?: boolean;
25
25
  failToast?: boolean;
26
26
  loading?: boolean;
27
27
  tips?: boolean;
28
28
  customHeaders?: boolean;
29
- onUploadProgress?: (progressEvent: any) => void;
30
- onDownloadProgress?: (progressEvent: any) => void;
31
- options?: Record<string, any>;
29
+ onUploadProgress?: (progressEvent: AxiosProgressEvent) => void;
30
+ onDownloadProgress?: (progressEvent: AxiosProgressEvent) => void;
31
+ options?: Record<string, D>;
32
32
  origin?: boolean;
33
33
  appKey?: string | number;
34
34
  }
@@ -13,6 +13,8 @@ export declare function createCasHeaders(opt: CasHeadersTransformOptions): {
13
13
  format: string;
14
14
  timestamp: number;
15
15
  'x-webtrace-id': string;
16
+ webTraceId: string;
17
+ 'X-menu-id': string;
16
18
  };
17
19
  export declare function casInterceptorResponse(response: AxiosResponse): AxiosResponse<any, any>;
18
20
  export declare function createKuaShengAdapter(config: InternalAxiosRequestConfig): AxiosPromise;
@@ -1,3 +1,4 @@
1
1
  import ksHttp from './http';
2
2
  export * from './openApi';
3
+ export * from './http/types';
3
4
  export { ksHttp };
@@ -2,10 +2,10 @@ import type { RequestOptions } from './http/types';
2
2
  export declare function useHttp(): {
3
3
  cancel: (message: string) => void;
4
4
  createCancelToken: () => import("./http/types").CancelTokenMap;
5
- $get: (url: string, appKey: string | number, data: any, config?: RequestOptions | undefined) => Promise<any>;
6
- $put: (url: string, appKey: string | number, data: any, config?: RequestOptions | undefined) => Promise<any>;
7
- $del: (url: string, appKey: string | number, data: any, config?: RequestOptions | undefined) => Promise<any>;
8
- $patch: (url: string, appKey: string | number, data: any, config?: RequestOptions | undefined) => Promise<any>;
9
- $post: (url: string, appKey: string | number, data: any, config?: RequestOptions | undefined) => Promise<any>;
10
- $http: (url: string, appKey: string | number, data: any, config?: RequestOptions | undefined) => Promise<any>;
5
+ $get: (url: string, appKey: string | number, data: any, config?: RequestOptions<any> | undefined) => Promise<any>;
6
+ $put: (url: string, appKey: string | number, data: any, config?: RequestOptions<any> | undefined) => Promise<any>;
7
+ $del: (url: string, appKey: string | number, data: any, config?: RequestOptions<any> | undefined) => Promise<any>;
8
+ $patch: (url: string, appKey: string | number, data: any, config?: RequestOptions<any> | undefined) => Promise<any>;
9
+ $post: (url: string, appKey: string | number, data: any, config?: RequestOptions<any> | undefined) => Promise<any>;
10
+ $http: (url: string, appKey: string | number, data: any, config?: RequestOptions<any> | undefined) => Promise<any>;
11
11
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ks-web/use",
3
- "version": "0.0.7",
3
+ "version": "0.0.9",
4
4
  "description": "Vant Composition API",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.esm.mjs",