@yeepay/client-utils 2.0.1 → 2.0.3

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.d.mts CHANGED
@@ -1,5 +1,4 @@
1
- import * as axios from 'axios';
2
- import { AxiosResponse, InternalAxiosRequestConfig } from 'axios';
1
+ import { AxiosInstance, AxiosResponse, InternalAxiosRequestConfig } from 'axios';
3
2
 
4
3
  declare function getQueryObject(url?: string): Record<string, string>;
5
4
 
@@ -10,16 +9,17 @@ interface ServiceFactoryOptions {
10
9
  code?: string | number;
11
10
  }
12
11
  interface ServiceFactoryCallbacks {
13
- successCallback: (response: AxiosResponse<any>) => any;
14
- failCallback: (error: any) => any;
15
- unauthorizedCallback: (response: AxiosResponse<any>) => any;
16
- forbiddenCallback: (response: AxiosResponse<any> | any) => any;
17
- notfoundCallback: (response: AxiosResponse<any> | any) => any;
18
- requestInterceptor: (config: InternalAxiosRequestConfig) => InternalAxiosRequestConfig;
19
- responseInterceptor: (response: AxiosResponse<any>) => AxiosResponse<any>;
12
+ successCallback?: (response: AxiosResponse<any>) => any;
13
+ failCallback?: (error: any) => any;
14
+ unauthorizedCallback?: (response: AxiosResponse<any>) => any;
15
+ forbiddenCallback?: (response: AxiosResponse<any> | any) => any;
16
+ notfoundCallback?: (response: AxiosResponse<any> | any) => any;
17
+ requestInterceptor?: (config: InternalAxiosRequestConfig) => InternalAxiosRequestConfig;
18
+ responseInterceptor?: (response: AxiosResponse<any>) => AxiosResponse<any>;
20
19
  }
21
- type ServiceFactoryCallbacksCompatible = [ServiceFactoryCallbacks['failCallback']?, ServiceFactoryCallbacks['unauthorizedCallback']?, ServiceFactoryCallbacks['forbiddenCallback']?, ServiceFactoryCallbacks['notfoundCallback']?, ServiceFactoryCallbacks['requestInterceptor']?, ServiceFactoryCallbacks['responseInterceptor']?];
22
- declare function serviceFactory(options: ServiceFactoryOptions, callbacks?: ServiceFactoryCallbacks['successCallback'], ...compatibleCallbacks: ServiceFactoryCallbacksCompatible): axios.AxiosInstance;
20
+ type ServiceFactoryCallbacksCompatible = [ServiceFactoryCallbacks['successCallback']?, ServiceFactoryCallbacks['failCallback']?, ServiceFactoryCallbacks['unauthorizedCallback']?, ServiceFactoryCallbacks['forbiddenCallback']?, ServiceFactoryCallbacks['notfoundCallback']?, ServiceFactoryCallbacks['requestInterceptor']?, ServiceFactoryCallbacks['responseInterceptor']?];
21
+ declare function serviceFactory(options: ServiceFactoryOptions, callbacks: ServiceFactoryCallbacks): AxiosInstance;
22
+ declare function serviceFactory(options: ServiceFactoryOptions, ...callbacks: ServiceFactoryCallbacksCompatible): AxiosInstance;
23
23
 
24
24
  declare function getToken(): string | undefined;
25
25
  /**
package/dist/index.d.ts CHANGED
@@ -1,5 +1,4 @@
1
- import * as axios from 'axios';
2
- import { AxiosResponse, InternalAxiosRequestConfig } from 'axios';
1
+ import { AxiosInstance, AxiosResponse, InternalAxiosRequestConfig } from 'axios';
3
2
 
4
3
  declare function getQueryObject(url?: string): Record<string, string>;
5
4
 
@@ -10,16 +9,17 @@ interface ServiceFactoryOptions {
10
9
  code?: string | number;
11
10
  }
12
11
  interface ServiceFactoryCallbacks {
13
- successCallback: (response: AxiosResponse<any>) => any;
14
- failCallback: (error: any) => any;
15
- unauthorizedCallback: (response: AxiosResponse<any>) => any;
16
- forbiddenCallback: (response: AxiosResponse<any> | any) => any;
17
- notfoundCallback: (response: AxiosResponse<any> | any) => any;
18
- requestInterceptor: (config: InternalAxiosRequestConfig) => InternalAxiosRequestConfig;
19
- responseInterceptor: (response: AxiosResponse<any>) => AxiosResponse<any>;
12
+ successCallback?: (response: AxiosResponse<any>) => any;
13
+ failCallback?: (error: any) => any;
14
+ unauthorizedCallback?: (response: AxiosResponse<any>) => any;
15
+ forbiddenCallback?: (response: AxiosResponse<any> | any) => any;
16
+ notfoundCallback?: (response: AxiosResponse<any> | any) => any;
17
+ requestInterceptor?: (config: InternalAxiosRequestConfig) => InternalAxiosRequestConfig;
18
+ responseInterceptor?: (response: AxiosResponse<any>) => AxiosResponse<any>;
20
19
  }
21
- type ServiceFactoryCallbacksCompatible = [ServiceFactoryCallbacks['failCallback']?, ServiceFactoryCallbacks['unauthorizedCallback']?, ServiceFactoryCallbacks['forbiddenCallback']?, ServiceFactoryCallbacks['notfoundCallback']?, ServiceFactoryCallbacks['requestInterceptor']?, ServiceFactoryCallbacks['responseInterceptor']?];
22
- declare function serviceFactory(options: ServiceFactoryOptions, callbacks?: ServiceFactoryCallbacks['successCallback'], ...compatibleCallbacks: ServiceFactoryCallbacksCompatible): axios.AxiosInstance;
20
+ type ServiceFactoryCallbacksCompatible = [ServiceFactoryCallbacks['successCallback']?, ServiceFactoryCallbacks['failCallback']?, ServiceFactoryCallbacks['unauthorizedCallback']?, ServiceFactoryCallbacks['forbiddenCallback']?, ServiceFactoryCallbacks['notfoundCallback']?, ServiceFactoryCallbacks['requestInterceptor']?, ServiceFactoryCallbacks['responseInterceptor']?];
21
+ declare function serviceFactory(options: ServiceFactoryOptions, callbacks: ServiceFactoryCallbacks): AxiosInstance;
22
+ declare function serviceFactory(options: ServiceFactoryOptions, ...callbacks: ServiceFactoryCallbacksCompatible): AxiosInstance;
23
23
 
24
24
  declare function getToken(): string | undefined;
25
25
  /**
package/dist/index.js CHANGED
@@ -91,22 +91,22 @@ function verifySuccessCode(code, customCode) {
91
91
  return (0, import_utils2.toArray)(customCode).includes(code) || !code;
92
92
  return code === 0 || code === "0" || code === "000000" || code === 200 || !code;
93
93
  }
94
- function compatibleCallback(callbacks, compatibleCallbacks = []) {
95
- if (typeof callbacks === "function" || !callbacks) {
94
+ function compatibleCallback(compatibleCallbacks = []) {
95
+ if (Array.isArray(compatibleCallbacks) && compatibleCallbacks.length && typeof compatibleCallbacks[0] === "function") {
96
96
  return {
97
- successCallback: callbacks || (() => ({})),
98
- failCallback: compatibleCallbacks[0] || (() => ({})),
99
- unauthorizedCallback: compatibleCallbacks[1] || (() => ({})),
100
- forbiddenCallback: compatibleCallbacks[2] || (() => ({})),
101
- notfoundCallback: compatibleCallbacks[3] || (() => ({})),
102
- requestInterceptor: compatibleCallbacks[4] || ((c) => c),
103
- responseInterceptor: compatibleCallbacks[5] || ((r) => r)
97
+ successCallback: compatibleCallbacks[0] || (() => ({})),
98
+ failCallback: compatibleCallbacks[1] || (() => ({})),
99
+ unauthorizedCallback: compatibleCallbacks[2] || (() => ({})),
100
+ forbiddenCallback: compatibleCallbacks[3] || (() => ({})),
101
+ notfoundCallback: compatibleCallbacks[4] || (() => ({})),
102
+ requestInterceptor: compatibleCallbacks[5] || ((c) => c),
103
+ responseInterceptor: compatibleCallbacks[6] || ((r) => r)
104
104
  };
105
105
  } else {
106
- return callbacks;
106
+ return compatibleCallbacks[0];
107
107
  }
108
108
  }
109
- function serviceFactory(options, callbacks, ...compatibleCallbacks) {
109
+ function serviceFactory(options, ...callbacks) {
110
110
  const {
111
111
  baseUrl = "/",
112
112
  timeout = 12e5,
@@ -122,7 +122,7 @@ function serviceFactory(options, callbacks, ...compatibleCallbacks) {
122
122
  notfoundCallback = (_response) => ({}),
123
123
  requestInterceptor = (c) => c,
124
124
  responseInterceptor = (r) => r
125
- } = compatibleCallback(callbacks, compatibleCallbacks);
125
+ } = compatibleCallback(callbacks);
126
126
  const service = import_axios.default.create({
127
127
  baseURL: baseUrl,
128
128
  timeout,
package/dist/index.mjs CHANGED
@@ -51,22 +51,22 @@ function verifySuccessCode(code, customCode) {
51
51
  return toArray(customCode).includes(code) || !code;
52
52
  return code === 0 || code === "0" || code === "000000" || code === 200 || !code;
53
53
  }
54
- function compatibleCallback(callbacks, compatibleCallbacks = []) {
55
- if (typeof callbacks === "function" || !callbacks) {
54
+ function compatibleCallback(compatibleCallbacks = []) {
55
+ if (Array.isArray(compatibleCallbacks) && compatibleCallbacks.length && typeof compatibleCallbacks[0] === "function") {
56
56
  return {
57
- successCallback: callbacks || (() => ({})),
58
- failCallback: compatibleCallbacks[0] || (() => ({})),
59
- unauthorizedCallback: compatibleCallbacks[1] || (() => ({})),
60
- forbiddenCallback: compatibleCallbacks[2] || (() => ({})),
61
- notfoundCallback: compatibleCallbacks[3] || (() => ({})),
62
- requestInterceptor: compatibleCallbacks[4] || ((c) => c),
63
- responseInterceptor: compatibleCallbacks[5] || ((r) => r)
57
+ successCallback: compatibleCallbacks[0] || (() => ({})),
58
+ failCallback: compatibleCallbacks[1] || (() => ({})),
59
+ unauthorizedCallback: compatibleCallbacks[2] || (() => ({})),
60
+ forbiddenCallback: compatibleCallbacks[3] || (() => ({})),
61
+ notfoundCallback: compatibleCallbacks[4] || (() => ({})),
62
+ requestInterceptor: compatibleCallbacks[5] || ((c) => c),
63
+ responseInterceptor: compatibleCallbacks[6] || ((r) => r)
64
64
  };
65
65
  } else {
66
- return callbacks;
66
+ return compatibleCallbacks[0];
67
67
  }
68
68
  }
69
- function serviceFactory(options, callbacks, ...compatibleCallbacks) {
69
+ function serviceFactory(options, ...callbacks) {
70
70
  const {
71
71
  baseUrl = "/",
72
72
  timeout = 12e5,
@@ -82,7 +82,7 @@ function serviceFactory(options, callbacks, ...compatibleCallbacks) {
82
82
  notfoundCallback = (_response) => ({}),
83
83
  requestInterceptor = (c) => c,
84
84
  responseInterceptor = (r) => r
85
- } = compatibleCallback(callbacks, compatibleCallbacks);
85
+ } = compatibleCallback(callbacks);
86
86
  const service = axios.create({
87
87
  baseURL: baseUrl,
88
88
  timeout,
package/package.json CHANGED
@@ -1,7 +1,6 @@
1
1
  {
2
2
  "name": "@yeepay/client-utils",
3
- "version": "2.0.1",
4
- "packageManager": "pnpm@8.12.1",
3
+ "version": "2.0.3",
5
4
  "description": "shared utilities for yeepay client packages",
6
5
  "author": "Angus Yang",
7
6
  "homepage": "http://gitlab.yeepay.com/ued/client-utils#readme",
@@ -11,8 +10,8 @@
11
10
  ],
12
11
  "exports": {
13
12
  ".": {
14
- "import": "./dist/index.js",
15
- "require": "./dist/index.cjs"
13
+ "import": "./dist/index.mjs",
14
+ "require": "./dist/index.js"
16
15
  }
17
16
  },
18
17
  "main": "./dist/index.js",
@@ -21,24 +20,24 @@
21
20
  "dist"
22
21
  ],
23
22
  "dependencies": {
24
- "@imyangyong/utils": "^0.4.1",
23
+ "@imyangyong/utils": "^0.6.0",
25
24
  "apollo-boost": "^0.4.9",
26
- "axios": "^1.6.3",
27
- "graphql": "^15.6.0",
28
- "js-cookie": "^2.2.1",
29
- "unfetch": "^4.2.0"
25
+ "axios": "^1.6.8",
26
+ "graphql": "^16.8.1",
27
+ "js-cookie": "^3.0.5",
28
+ "unfetch": "^5.0.0"
30
29
  },
31
30
  "devDependencies": {
32
31
  "@antfu/ni": "^0.21.12",
33
32
  "@types/js-cookie": "^3.0.6",
34
- "@yeepay/eslint-config": "^1.4.0",
35
- "bumpp": "^9.2.1",
33
+ "@yeepay/eslint-config": "^1.5.0",
34
+ "bumpp": "^9.4.0",
36
35
  "eslint-plugin-format": "^0.1.0",
37
- "lint-staged": "^15.2.0",
38
- "simple-git-hooks": "^2.9.0",
39
- "tsup": "^8.0.1",
40
- "typescript": "^5.3.3",
41
- "vitest": "^1.0.4"
36
+ "lint-staged": "^15.2.2",
37
+ "simple-git-hooks": "^2.11.1",
38
+ "tsup": "^8.0.2",
39
+ "typescript": "^5.4.3",
40
+ "vitest": "^1.4.0"
42
41
  },
43
42
  "simple-git-hooks": {
44
43
  "pre-commit": "pnpm lint-staged"