@yeepay/client-utils 2.0.1 → 2.0.2
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 +10 -10
- package/dist/index.d.ts +10 -10
- package/dist/index.js +12 -12
- package/dist/index.mjs +12 -12
- package/package.json +16 -16
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import * as axios from 'axios';
|
|
2
1
|
import { AxiosResponse, InternalAxiosRequestConfig } from 'axios';
|
|
3
2
|
|
|
4
3
|
declare function getQueryObject(url?: string): Record<string, string>;
|
|
@@ -10,16 +9,17 @@ interface ServiceFactoryOptions {
|
|
|
10
9
|
code?: string | number;
|
|
11
10
|
}
|
|
12
11
|
interface ServiceFactoryCallbacks {
|
|
13
|
-
successCallback
|
|
14
|
-
failCallback
|
|
15
|
-
unauthorizedCallback
|
|
16
|
-
forbiddenCallback
|
|
17
|
-
notfoundCallback
|
|
18
|
-
requestInterceptor
|
|
19
|
-
responseInterceptor
|
|
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
|
|
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): any;
|
|
22
|
+
declare function serviceFactory(options: ServiceFactoryOptions, ...callbacks: ServiceFactoryCallbacksCompatible): any;
|
|
23
23
|
|
|
24
24
|
declare function getToken(): string | undefined;
|
|
25
25
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import * as axios from 'axios';
|
|
2
1
|
import { AxiosResponse, InternalAxiosRequestConfig } from 'axios';
|
|
3
2
|
|
|
4
3
|
declare function getQueryObject(url?: string): Record<string, string>;
|
|
@@ -10,16 +9,17 @@ interface ServiceFactoryOptions {
|
|
|
10
9
|
code?: string | number;
|
|
11
10
|
}
|
|
12
11
|
interface ServiceFactoryCallbacks {
|
|
13
|
-
successCallback
|
|
14
|
-
failCallback
|
|
15
|
-
unauthorizedCallback
|
|
16
|
-
forbiddenCallback
|
|
17
|
-
notfoundCallback
|
|
18
|
-
requestInterceptor
|
|
19
|
-
responseInterceptor
|
|
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
|
|
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): any;
|
|
22
|
+
declare function serviceFactory(options: ServiceFactoryOptions, ...callbacks: ServiceFactoryCallbacksCompatible): any;
|
|
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(
|
|
95
|
-
if (typeof
|
|
94
|
+
function compatibleCallback(compatibleCallbacks = []) {
|
|
95
|
+
if (Array.isArray(compatibleCallbacks) && compatibleCallbacks.length && typeof compatibleCallbacks[0] === "function") {
|
|
96
96
|
return {
|
|
97
|
-
successCallback:
|
|
98
|
-
failCallback: compatibleCallbacks[
|
|
99
|
-
unauthorizedCallback: compatibleCallbacks[
|
|
100
|
-
forbiddenCallback: compatibleCallbacks[
|
|
101
|
-
notfoundCallback: compatibleCallbacks[
|
|
102
|
-
requestInterceptor: compatibleCallbacks[
|
|
103
|
-
responseInterceptor: compatibleCallbacks[
|
|
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
|
|
106
|
+
return compatibleCallbacks[0];
|
|
107
107
|
}
|
|
108
108
|
}
|
|
109
|
-
function serviceFactory(options, callbacks
|
|
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
|
|
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(
|
|
55
|
-
if (typeof
|
|
54
|
+
function compatibleCallback(compatibleCallbacks = []) {
|
|
55
|
+
if (Array.isArray(compatibleCallbacks) && compatibleCallbacks.length && typeof compatibleCallbacks[0] === "function") {
|
|
56
56
|
return {
|
|
57
|
-
successCallback:
|
|
58
|
-
failCallback: compatibleCallbacks[
|
|
59
|
-
unauthorizedCallback: compatibleCallbacks[
|
|
60
|
-
forbiddenCallback: compatibleCallbacks[
|
|
61
|
-
notfoundCallback: compatibleCallbacks[
|
|
62
|
-
requestInterceptor: compatibleCallbacks[
|
|
63
|
-
responseInterceptor: compatibleCallbacks[
|
|
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
|
|
66
|
+
return compatibleCallbacks[0];
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
|
-
function serviceFactory(options, callbacks
|
|
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
|
|
85
|
+
} = compatibleCallback(callbacks);
|
|
86
86
|
const service = axios.create({
|
|
87
87
|
baseURL: baseUrl,
|
|
88
88
|
timeout,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yeepay/client-utils",
|
|
3
|
-
"version": "2.0.
|
|
4
|
-
"packageManager": "pnpm@8.
|
|
3
|
+
"version": "2.0.2",
|
|
4
|
+
"packageManager": "pnpm@8.15.6",
|
|
5
5
|
"description": "shared utilities for yeepay client packages",
|
|
6
6
|
"author": "Angus Yang",
|
|
7
7
|
"homepage": "http://gitlab.yeepay.com/ued/client-utils#readme",
|
|
@@ -11,8 +11,8 @@
|
|
|
11
11
|
],
|
|
12
12
|
"exports": {
|
|
13
13
|
".": {
|
|
14
|
-
"import": "./dist/index.
|
|
15
|
-
"require": "./dist/index.
|
|
14
|
+
"import": "./dist/index.mjs",
|
|
15
|
+
"require": "./dist/index.js"
|
|
16
16
|
}
|
|
17
17
|
},
|
|
18
18
|
"main": "./dist/index.js",
|
|
@@ -21,24 +21,24 @@
|
|
|
21
21
|
"dist"
|
|
22
22
|
],
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@imyangyong/utils": "^0.
|
|
24
|
+
"@imyangyong/utils": "^0.6.0",
|
|
25
25
|
"apollo-boost": "^0.4.9",
|
|
26
|
-
"axios": "^1.6.
|
|
27
|
-
"graphql": "^
|
|
28
|
-
"js-cookie": "^
|
|
29
|
-
"unfetch": "^
|
|
26
|
+
"axios": "^1.6.8",
|
|
27
|
+
"graphql": "^16.8.1",
|
|
28
|
+
"js-cookie": "^3.0.5",
|
|
29
|
+
"unfetch": "^5.0.0"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@antfu/ni": "^0.21.12",
|
|
33
33
|
"@types/js-cookie": "^3.0.6",
|
|
34
|
-
"@yeepay/eslint-config": "^1.
|
|
35
|
-
"bumpp": "^9.
|
|
34
|
+
"@yeepay/eslint-config": "^1.5.0",
|
|
35
|
+
"bumpp": "^9.4.0",
|
|
36
36
|
"eslint-plugin-format": "^0.1.0",
|
|
37
|
-
"lint-staged": "^15.2.
|
|
38
|
-
"simple-git-hooks": "^2.
|
|
39
|
-
"tsup": "^8.0.
|
|
40
|
-
"typescript": "^5.
|
|
41
|
-
"vitest": "^1.0
|
|
37
|
+
"lint-staged": "^15.2.2",
|
|
38
|
+
"simple-git-hooks": "^2.11.1",
|
|
39
|
+
"tsup": "^8.0.2",
|
|
40
|
+
"typescript": "^5.4.3",
|
|
41
|
+
"vitest": "^1.4.0"
|
|
42
42
|
},
|
|
43
43
|
"simple-git-hooks": {
|
|
44
44
|
"pre-commit": "pnpm lint-staged"
|