@vef-framework/core 2.0.4 → 2.0.6
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/cjs/api/client.cjs +1 -171
- package/dist/cjs/api/constants.cjs +1 -13
- package/dist/cjs/api/helpers.cjs +1 -12
- package/dist/cjs/api/index.cjs +1 -14
- package/dist/cjs/auth/helpers.cjs +1 -19
- package/dist/cjs/auth/index.cjs +1 -10
- package/dist/cjs/common/index.cjs +1 -3
- package/dist/cjs/context/api-client.cjs +1 -25
- package/dist/cjs/context/app.cjs +1 -15
- package/dist/cjs/context/context-selector.cjs +1 -65
- package/dist/cjs/context/disabled.cjs +1 -15
- package/dist/cjs/context/index.cjs +1 -19
- package/dist/cjs/dnd/index.cjs +1 -102
- package/dist/cjs/http/client.cjs +1 -445
- package/dist/cjs/http/errors.cjs +1 -23
- package/dist/cjs/http/helpers.cjs +1 -17
- package/dist/cjs/http/index.cjs +1 -17
- package/dist/cjs/immer/index.cjs +1 -40
- package/dist/cjs/index.cjs +1 -306
- package/dist/cjs/motion/features.cjs +1 -13
- package/dist/cjs/motion/index.cjs +1 -48
- package/dist/cjs/motion/motion-provider.cjs +1 -29
- package/dist/cjs/query/constants.cjs +1 -8
- package/dist/cjs/query/helpers.cjs +1 -67
- package/dist/cjs/query/hooks.cjs +1 -52
- package/dist/cjs/query/index.cjs +1 -20
- package/dist/cjs/state/index.cjs +1 -41
- package/dist/cjs/state-machine/index.cjs +1 -35
- package/dist/cjs/store/bound.cjs +1 -42
- package/dist/cjs/store/index.cjs +1 -20
- package/dist/cjs/store/unbound.cjs +2 -73
- package/dist/cjs/store/use-deep.cjs +1 -17
- package/dist/es/api/client.js +72 -90
- package/dist/es/api/constants.js +7 -8
- package/dist/es/api/helpers.js +6 -7
- package/dist/es/api/index.js +8 -4
- package/dist/es/auth/helpers.js +9 -14
- package/dist/es/auth/index.js +4 -2
- package/dist/es/common/index.js +1 -1
- package/dist/es/context/api-client.js +16 -17
- package/dist/es/context/app.js +8 -9
- package/dist/es/context/context-selector.js +30 -39
- package/dist/es/context/disabled.js +9 -9
- package/dist/es/context/index.js +13 -5
- package/dist/es/dnd/index.js +30 -7
- package/dist/es/http/client.js +173 -253
- package/dist/es/http/errors.js +6 -9
- package/dist/es/http/helpers.js +10 -10
- package/dist/es/http/index.js +11 -4
- package/dist/es/immer/index.js +15 -8
- package/dist/es/index.js +122 -43
- package/dist/es/motion/features.js +4 -2
- package/dist/es/motion/index.js +11 -5
- package/dist/es/motion/motion-provider.js +15 -17
- package/dist/es/query/constants.js +4 -4
- package/dist/es/query/helpers.js +40 -45
- package/dist/es/query/hooks.js +29 -20
- package/dist/es/query/index.js +14 -4
- package/dist/es/state/index.js +11 -2
- package/dist/es/state-machine/index.js +14 -11
- package/dist/es/store/bound.js +24 -26
- package/dist/es/store/index.js +11 -5
- package/dist/es/store/unbound.js +44 -63
- package/dist/es/store/use-deep.js +10 -11
- package/package.json +3 -3
package/dist/es/context/index.js
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export {
|
|
1
|
+
import { ApiClientProvider as o, useApiClient as t } from "./api-client.js";
|
|
2
|
+
import { AppContextProvider as p, useAppContext as x } from "./app.js";
|
|
3
|
+
import { createContextWithSelector as l } from "./context-selector.js";
|
|
4
|
+
import { DisabledProvider as s, useDisabled as C } from "./disabled.js";
|
|
5
|
+
export {
|
|
6
|
+
o as ApiClientProvider,
|
|
7
|
+
p as AppContextProvider,
|
|
8
|
+
s as DisabledProvider,
|
|
9
|
+
l as createContextWithSelector,
|
|
10
|
+
t as useApiClient,
|
|
11
|
+
x as useAppContext,
|
|
12
|
+
C as useDisabled
|
|
13
|
+
};
|
package/dist/es/dnd/index.js
CHANGED
|
@@ -1,7 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export {
|
|
1
|
+
import { AxisModifier as o, RestrictToHorizontalAxis as a, RestrictToVerticalAxis as t, SnapModifier as s, restrictShapeToBoundingRectangle as i } from "@dnd-kit/abstract/modifiers";
|
|
2
|
+
import { RestrictToElement as m, RestrictToWindow as D } from "@dnd-kit/dom/modifiers";
|
|
3
|
+
import { arrayMove as n, move as l, arraySwap as x, swap as f } from "@dnd-kit/helpers";
|
|
4
|
+
import { DragDropProvider as b, DragOverlay as d, KeyboardSensor as v, PointerSensor as y, useDragDropMonitor as S, useDraggable as u, useDroppable as w } from "@dnd-kit/react";
|
|
5
|
+
import { useSortable as R } from "@dnd-kit/react/sortable";
|
|
6
|
+
import { DragDropContext as I, Draggable as M, Droppable as P } from "@hello-pangea/dnd";
|
|
7
|
+
export {
|
|
8
|
+
o as AxisModifier,
|
|
9
|
+
I as DragDropContext,
|
|
10
|
+
b as DragDropProvider,
|
|
11
|
+
d as DragOverlay,
|
|
12
|
+
M as Draggable,
|
|
13
|
+
P as Droppable,
|
|
14
|
+
v as KeyboardSensor,
|
|
15
|
+
y as PointerSensor,
|
|
16
|
+
m as RestrictToElement,
|
|
17
|
+
a as RestrictToHorizontalAxis,
|
|
18
|
+
t as RestrictToVerticalAxis,
|
|
19
|
+
D as RestrictToWindow,
|
|
20
|
+
s as SnapModifier,
|
|
21
|
+
n as moveArrayItem,
|
|
22
|
+
l as moveDragItem,
|
|
23
|
+
i as restrictShapeToBoundingRectangle,
|
|
24
|
+
x as swapArrayItem,
|
|
25
|
+
f as swapDragItem,
|
|
26
|
+
S as useDragDropMonitor,
|
|
27
|
+
u as useDraggable,
|
|
28
|
+
w as useDroppable,
|
|
29
|
+
R as useSortable
|
|
30
|
+
};
|
package/dist/es/http/client.js
CHANGED
|
@@ -1,66 +1,59 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const pathParamRegex = /:(?<key>\w+)/g;
|
|
7
|
-
const filenameRegex = /filename[^;=\n]*=(?<name>(?<quote>['"]).*?\2|[^;\n]*)/;
|
|
8
|
-
const skipAuthenticationHeader = "X-Skip-Authentication";
|
|
9
|
-
const skipAuthenticationValue = "1";
|
|
10
|
-
class HttpClient {
|
|
1
|
+
import { encodeQueryString as m, isArray as k, isNullish as y, isFunction as d, isString as $ } from "@vef-framework/shared";
|
|
2
|
+
import R, { CanceledError as C } from "axios";
|
|
3
|
+
import { BusinessError as T } from "./errors.js";
|
|
4
|
+
const w = /:(?<key>\w+)/g, b = /filename[^;=\n]*=(?<name>(?<quote>['"]).*?\2|[^;\n]*)/, g = "X-Skip-Authentication", E = "1";
|
|
5
|
+
class O {
|
|
11
6
|
/**
|
|
12
7
|
* The axios instance.
|
|
13
8
|
*/
|
|
14
|
-
#
|
|
9
|
+
#e;
|
|
15
10
|
/**
|
|
16
11
|
* The http client options.
|
|
17
12
|
*/
|
|
18
|
-
#
|
|
13
|
+
#s;
|
|
19
14
|
/**
|
|
20
15
|
* Indicates whether a token refresh is in progress.
|
|
21
16
|
*/
|
|
22
|
-
#
|
|
17
|
+
#t = !1;
|
|
23
18
|
/**
|
|
24
19
|
* Queue of pending requests waiting for token refresh to complete.
|
|
25
20
|
*/
|
|
26
|
-
#
|
|
27
|
-
constructor(
|
|
28
|
-
this.#
|
|
21
|
+
#n = [];
|
|
22
|
+
constructor(e) {
|
|
23
|
+
this.#s = e;
|
|
29
24
|
const {
|
|
30
|
-
baseUrl,
|
|
31
|
-
timeout = 1e3 * 30
|
|
32
|
-
} =
|
|
33
|
-
this.#
|
|
34
|
-
baseURL:
|
|
35
|
-
allowAbsoluteUrls:
|
|
36
|
-
timeout,
|
|
25
|
+
baseUrl: s,
|
|
26
|
+
timeout: n = 1e3 * 30
|
|
27
|
+
} = e;
|
|
28
|
+
this.#e = R.create({
|
|
29
|
+
baseURL: s,
|
|
30
|
+
allowAbsoluteUrls: !0,
|
|
31
|
+
timeout: n,
|
|
37
32
|
headers: {
|
|
38
33
|
"Content-Type": "application/json"
|
|
39
34
|
},
|
|
40
|
-
paramsSerializer: (
|
|
41
|
-
|
|
35
|
+
paramsSerializer: (t) => m(
|
|
36
|
+
t,
|
|
42
37
|
{
|
|
43
38
|
arrayFormat: "repeat",
|
|
44
|
-
skipNulls:
|
|
39
|
+
skipNulls: !0,
|
|
45
40
|
charset: "utf-8"
|
|
46
41
|
}
|
|
47
42
|
),
|
|
48
43
|
responseType: "json",
|
|
49
44
|
responseEncoding: "utf-8",
|
|
50
|
-
validateStatus(
|
|
51
|
-
return
|
|
45
|
+
validateStatus(t) {
|
|
46
|
+
return t >= 200 && t < 300;
|
|
52
47
|
},
|
|
53
|
-
withCredentials:
|
|
48
|
+
withCredentials: !1,
|
|
54
49
|
timeoutErrorMessage: "请求超时"
|
|
55
|
-
});
|
|
56
|
-
this.initInterceptors();
|
|
50
|
+
}), this.initInterceptors();
|
|
57
51
|
}
|
|
58
52
|
initInterceptors() {
|
|
59
|
-
this.#
|
|
53
|
+
this.#e.interceptors.request.use(
|
|
60
54
|
this.handleRequest.bind(this),
|
|
61
55
|
this.handleRequestError.bind(this)
|
|
62
|
-
)
|
|
63
|
-
this.#axiosInstance.interceptors.response.use(
|
|
56
|
+
), this.#e.interceptors.response.use(
|
|
64
57
|
this.handleResponse.bind(this),
|
|
65
58
|
this.handleResponseError.bind(this)
|
|
66
59
|
);
|
|
@@ -72,11 +65,8 @@ class HttpClient {
|
|
|
72
65
|
* @param target - The target.
|
|
73
66
|
* @returns The result.
|
|
74
67
|
*/
|
|
75
|
-
isBelongsTo(
|
|
76
|
-
|
|
77
|
-
return target.includes(code);
|
|
78
|
-
}
|
|
79
|
-
return code === target;
|
|
68
|
+
isBelongsTo(e, s) {
|
|
69
|
+
return k(s) ? s.includes(e) : e === s;
|
|
80
70
|
}
|
|
81
71
|
/**
|
|
82
72
|
* Handle the request.
|
|
@@ -84,38 +74,22 @@ class HttpClient {
|
|
|
84
74
|
* @param config - The axios request config.
|
|
85
75
|
* @returns The axios request config.
|
|
86
76
|
*/
|
|
87
|
-
async handleRequest(
|
|
88
|
-
const
|
|
89
|
-
if (this.#
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
throw new Error("登录已过期, 请重新登录");
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
if (skipAuthentication) {
|
|
98
|
-
delete config.headers[skipAuthenticationHeader];
|
|
99
|
-
} else {
|
|
100
|
-
await this.setAccessToken(config);
|
|
101
|
-
}
|
|
102
|
-
this.replacePathParams(config);
|
|
103
|
-
return config;
|
|
77
|
+
async handleRequest(e) {
|
|
78
|
+
const s = e.headers[g] === E;
|
|
79
|
+
if (this.#t && !s && !await new Promise((t) => {
|
|
80
|
+
this.#n.push(t);
|
|
81
|
+
}))
|
|
82
|
+
throw new Error("登录已过期, 请重新登录");
|
|
83
|
+
return s ? delete e.headers[g] : await this.setAccessToken(e), this.replacePathParams(e), e;
|
|
104
84
|
}
|
|
105
85
|
/**
|
|
106
86
|
* Handle the request error.
|
|
107
87
|
*
|
|
108
88
|
* @param error - The axios error.
|
|
109
89
|
*/
|
|
110
|
-
handleRequestError(
|
|
111
|
-
const { showErrorMessage } = this.#
|
|
112
|
-
|
|
113
|
-
if (showErrorMessage) {
|
|
114
|
-
showErrorMessage(`发起请求失败: ${message || "未知错误"}`);
|
|
115
|
-
} else {
|
|
116
|
-
console.error(`[HttpClient] ❌ 发起请求失败: ${message || "未知错误"}`);
|
|
117
|
-
}
|
|
118
|
-
return Promise.reject(error);
|
|
90
|
+
handleRequestError(e) {
|
|
91
|
+
const { showErrorMessage: s } = this.#s, n = e instanceof Error ? e.message : String(e);
|
|
92
|
+
return s ? s(`发起请求失败: ${n || "未知错误"}`) : console.error(`[HttpClient] ❌ 发起请求失败: ${n || "未知错误"}`), Promise.reject(e);
|
|
119
93
|
}
|
|
120
94
|
/**
|
|
121
95
|
* Handle the response.
|
|
@@ -123,117 +97,85 @@ class HttpClient {
|
|
|
123
97
|
* @param response - The axios response.
|
|
124
98
|
* @returns The axios response.
|
|
125
99
|
*/
|
|
126
|
-
handleResponse(
|
|
100
|
+
handleResponse(e) {
|
|
127
101
|
const {
|
|
128
|
-
showWarningMessage,
|
|
129
|
-
okCode = 0
|
|
130
|
-
} = this.#
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
}
|
|
139
|
-
if (showWarningMessage) {
|
|
140
|
-
showWarningMessage(message);
|
|
141
|
-
} else {
|
|
142
|
-
console.warn(`[HttpClient] ⚠️ [${response.config.method}: ${response.config.url}] 返回错误: ${message}`);
|
|
143
|
-
}
|
|
144
|
-
throw new BusinessError(code, message, data);
|
|
102
|
+
showWarningMessage: s,
|
|
103
|
+
okCode: n = 0
|
|
104
|
+
} = this.#s, {
|
|
105
|
+
code: t,
|
|
106
|
+
message: o,
|
|
107
|
+
data: r
|
|
108
|
+
} = e.data;
|
|
109
|
+
if (this.isBelongsTo(t, n))
|
|
110
|
+
return e;
|
|
111
|
+
throw s ? s(o) : console.warn(`[HttpClient] ⚠️ [${e.config.method}: ${e.config.url}] 返回错误: ${o}`), new T(t, o, r);
|
|
145
112
|
}
|
|
146
113
|
/**
|
|
147
114
|
* Handle the response error.
|
|
148
115
|
*
|
|
149
116
|
* @param error - The axios error.
|
|
150
117
|
*/
|
|
151
|
-
async handleResponseError(
|
|
118
|
+
async handleResponseError(e) {
|
|
152
119
|
const {
|
|
153
|
-
showInfoMessage,
|
|
154
|
-
showWarningMessage,
|
|
155
|
-
showErrorMessage,
|
|
156
|
-
tokenExpiredCode = []
|
|
157
|
-
} = this.#
|
|
158
|
-
if (
|
|
159
|
-
if (
|
|
160
|
-
const { method, url } =
|
|
161
|
-
console.warn(`[HttpClient] ⚠️ [${
|
|
120
|
+
showInfoMessage: s,
|
|
121
|
+
showWarningMessage: n,
|
|
122
|
+
showErrorMessage: t,
|
|
123
|
+
tokenExpiredCode: o = []
|
|
124
|
+
} = this.#s;
|
|
125
|
+
if (e instanceof C) {
|
|
126
|
+
if (e.response) {
|
|
127
|
+
const { method: i, url: c } = e.response.config;
|
|
128
|
+
console.warn(`[HttpClient] ⚠️ [${i}: ${c}] 被取消`);
|
|
162
129
|
}
|
|
163
130
|
return;
|
|
164
131
|
}
|
|
165
|
-
const { response } =
|
|
166
|
-
if (
|
|
132
|
+
const { response: r } = e;
|
|
133
|
+
if (r) {
|
|
167
134
|
const {
|
|
168
|
-
status,
|
|
169
|
-
config,
|
|
170
|
-
data
|
|
171
|
-
} =
|
|
172
|
-
|
|
173
|
-
const requestInfo = `[${config.method}: ${config.url}]`;
|
|
174
|
-
switch (status) {
|
|
135
|
+
status: i,
|
|
136
|
+
config: c,
|
|
137
|
+
data: l
|
|
138
|
+
} = r, { code: p, message: a } = l, h = `[${c.method}: ${c.url}]`;
|
|
139
|
+
switch (i) {
|
|
175
140
|
case 401: {
|
|
176
|
-
if (this.isBelongsTo(
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
await this.retryRequest(config);
|
|
141
|
+
if (this.isBelongsTo(p, o)) {
|
|
142
|
+
if (await this.tryRefreshToken()) {
|
|
143
|
+
await this.retryRequest(c);
|
|
180
144
|
return;
|
|
181
145
|
}
|
|
182
|
-
const
|
|
183
|
-
|
|
184
|
-
showInfoMessage(expiredMessage);
|
|
185
|
-
} else {
|
|
186
|
-
console.info(`[HttpClient] ℹ️ ${expiredMessage}`);
|
|
187
|
-
}
|
|
146
|
+
const f = "登录已过期, 请重新登录";
|
|
147
|
+
s ? s(f) : console.info(`[HttpClient] ℹ️ ${f}`);
|
|
188
148
|
}
|
|
189
|
-
await this.#
|
|
149
|
+
await this.#s.onUnauthenticated?.();
|
|
190
150
|
break;
|
|
191
151
|
}
|
|
192
152
|
case 403: {
|
|
193
|
-
|
|
194
|
-
console.warn(`[HttpClient] ⚠️ ${requestInfo} 访问被拒绝: ${message}`);
|
|
195
|
-
await this.#options.onAccessDenied?.();
|
|
153
|
+
n?.(`${a}, 请联系管理员为您开通`), console.warn(`[HttpClient] ⚠️ ${h} 访问被拒绝: ${a}`), await this.#s.onAccessDenied?.();
|
|
196
154
|
break;
|
|
197
155
|
}
|
|
198
156
|
case 400: {
|
|
199
|
-
|
|
200
|
-
showWarningMessage(message);
|
|
201
|
-
} else {
|
|
202
|
-
console.warn(`[HttpClient] ⚠️ ${requestInfo} 参数错误: ${message}`);
|
|
203
|
-
}
|
|
157
|
+
n ? n(a) : console.warn(`[HttpClient] ⚠️ ${h} 参数错误: ${a}`);
|
|
204
158
|
break;
|
|
205
159
|
}
|
|
206
|
-
default:
|
|
207
|
-
|
|
208
|
-
showErrorMessage(message);
|
|
209
|
-
} else {
|
|
210
|
-
console.error(`[HttpClient] ❌ ${requestInfo} 返回错误: ${message}`);
|
|
211
|
-
}
|
|
212
|
-
}
|
|
160
|
+
default:
|
|
161
|
+
t ? t(a) : console.error(`[HttpClient] ❌ ${h} 返回错误: ${a}`);
|
|
213
162
|
}
|
|
214
163
|
} else {
|
|
215
|
-
const
|
|
216
|
-
|
|
217
|
-
showErrorMessage(errorMessage);
|
|
218
|
-
} else {
|
|
219
|
-
console.error(`[HttpClient] ❌ ${errorMessage}`);
|
|
220
|
-
}
|
|
164
|
+
const i = `请求失败: ${e.message || "未知错误"}`;
|
|
165
|
+
t ? t(i) : console.error(`[HttpClient] ❌ ${i}`);
|
|
221
166
|
}
|
|
222
|
-
throw
|
|
167
|
+
throw e;
|
|
223
168
|
}
|
|
224
169
|
/**
|
|
225
170
|
* Injects access token into request Authorization header.
|
|
226
171
|
*
|
|
227
172
|
* @param config - The axios request config.
|
|
228
173
|
*/
|
|
229
|
-
async setAccessToken(
|
|
230
|
-
const { getAuthTokens } = this.#
|
|
231
|
-
if (
|
|
232
|
-
const
|
|
233
|
-
|
|
234
|
-
if (accessToken) {
|
|
235
|
-
config.headers.Authorization = `Bearer ${accessToken}`;
|
|
236
|
-
}
|
|
174
|
+
async setAccessToken(e) {
|
|
175
|
+
const { getAuthTokens: s } = this.#s;
|
|
176
|
+
if (s) {
|
|
177
|
+
const t = (await s())?.accessToken;
|
|
178
|
+
t && (e.headers.Authorization = `Bearer ${t}`);
|
|
237
179
|
}
|
|
238
180
|
}
|
|
239
181
|
/**
|
|
@@ -242,23 +184,14 @@ class HttpClient {
|
|
|
242
184
|
* @param config - The axios request config.
|
|
243
185
|
* @returns The axios request config.
|
|
244
186
|
*/
|
|
245
|
-
replacePathParams(
|
|
246
|
-
const { url, params = {} } =
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
const value = params[key];
|
|
254
|
-
if (isNullish(value)) {
|
|
255
|
-
console.warn(`[HttpClient] ⚠️ 接口: ${url} 路径参数 ${key} 在查询参数中为空, 请检查`);
|
|
256
|
-
return "unknown";
|
|
257
|
-
}
|
|
258
|
-
return value;
|
|
259
|
-
});
|
|
260
|
-
}
|
|
261
|
-
return config;
|
|
187
|
+
replacePathParams(e) {
|
|
188
|
+
const { url: s, params: n = {} } = e;
|
|
189
|
+
return s && w.test(s) && (e.url = s.replaceAll(w, (t, o) => {
|
|
190
|
+
if (!Object.hasOwn(n, o))
|
|
191
|
+
return console.warn(`[HttpClient] ⚠️ 接口: ${s} 路径参数 ${o} 未在查询参数中定义, 请检查`), "unknown";
|
|
192
|
+
const r = n[o];
|
|
193
|
+
return y(r) ? (console.warn(`[HttpClient] ⚠️ 接口: ${s} 路径参数 ${o} 在查询参数中为空, 请检查`), "unknown") : r;
|
|
194
|
+
})), e;
|
|
262
195
|
}
|
|
263
196
|
/**
|
|
264
197
|
* Try to refresh the token using the provided refresh callback.
|
|
@@ -267,32 +200,27 @@ class HttpClient {
|
|
|
267
200
|
*/
|
|
268
201
|
async tryRefreshToken() {
|
|
269
202
|
const {
|
|
270
|
-
getAuthTokens,
|
|
271
|
-
refreshToken,
|
|
272
|
-
setAuthTokens
|
|
273
|
-
} = this.#
|
|
274
|
-
if (!
|
|
275
|
-
return
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
let success = false;
|
|
203
|
+
getAuthTokens: e,
|
|
204
|
+
refreshToken: s,
|
|
205
|
+
setAuthTokens: n
|
|
206
|
+
} = this.#s;
|
|
207
|
+
if (!e || !s || !n)
|
|
208
|
+
return !1;
|
|
209
|
+
this.#t = !0;
|
|
210
|
+
let t = !1;
|
|
279
211
|
try {
|
|
280
|
-
const
|
|
281
|
-
if (!
|
|
282
|
-
return
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
return
|
|
287
|
-
} catch (error) {
|
|
288
|
-
console.error(`[HttpClient] ❌ 刷新令牌失败: ${error}`);
|
|
289
|
-
return false;
|
|
212
|
+
const o = await e();
|
|
213
|
+
if (!o)
|
|
214
|
+
return !1;
|
|
215
|
+
const r = await s(o);
|
|
216
|
+
return await n(Object.freeze(r)), t = !0;
|
|
217
|
+
} catch (o) {
|
|
218
|
+
return console.error(`[HttpClient] ❌ 刷新令牌失败: ${o}`), !1;
|
|
290
219
|
} finally {
|
|
291
|
-
this.#
|
|
292
|
-
for (const
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
this.#waitingQueue = [];
|
|
220
|
+
this.#t = !1;
|
|
221
|
+
for (const o of this.#n)
|
|
222
|
+
o(t);
|
|
223
|
+
this.#n = [];
|
|
296
224
|
}
|
|
297
225
|
}
|
|
298
226
|
/**
|
|
@@ -301,10 +229,9 @@ class HttpClient {
|
|
|
301
229
|
* @param config - The axios request config.
|
|
302
230
|
* @returns The axios response.
|
|
303
231
|
*/
|
|
304
|
-
async retryRequest(
|
|
305
|
-
const
|
|
306
|
-
await this.setAccessToken(
|
|
307
|
-
return this.#axiosInstance(newConfig);
|
|
232
|
+
async retryRequest(e) {
|
|
233
|
+
const s = { ...e };
|
|
234
|
+
return await this.setAccessToken(s), this.#e(s);
|
|
308
235
|
}
|
|
309
236
|
/**
|
|
310
237
|
* Get the resource.
|
|
@@ -313,12 +240,11 @@ class HttpClient {
|
|
|
313
240
|
* @param options - The options for the request.
|
|
314
241
|
* @returns The response data.
|
|
315
242
|
*/
|
|
316
|
-
async get(
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
);
|
|
321
|
-
return response.data;
|
|
243
|
+
async get(e, s) {
|
|
244
|
+
return (await this.#e.get(
|
|
245
|
+
e,
|
|
246
|
+
s
|
|
247
|
+
)).data;
|
|
322
248
|
}
|
|
323
249
|
/**
|
|
324
250
|
* Post the resource.
|
|
@@ -327,14 +253,13 @@ class HttpClient {
|
|
|
327
253
|
* @param options - The options for the request.
|
|
328
254
|
* @returns The response data.
|
|
329
255
|
*/
|
|
330
|
-
async post(
|
|
331
|
-
const { data, ...
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
);
|
|
337
|
-
return response.data;
|
|
256
|
+
async post(e, s) {
|
|
257
|
+
const { data: n, ...t } = s ?? {};
|
|
258
|
+
return (await this.#e.post(
|
|
259
|
+
e,
|
|
260
|
+
n,
|
|
261
|
+
t
|
|
262
|
+
)).data;
|
|
338
263
|
}
|
|
339
264
|
/**
|
|
340
265
|
* Update the resource.
|
|
@@ -343,14 +268,13 @@ class HttpClient {
|
|
|
343
268
|
* @param options - The options for the request.
|
|
344
269
|
* @returns The response data.
|
|
345
270
|
*/
|
|
346
|
-
async put(
|
|
347
|
-
const { data, ...
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
);
|
|
353
|
-
return response.data;
|
|
271
|
+
async put(e, s) {
|
|
272
|
+
const { data: n, ...t } = s ?? {};
|
|
273
|
+
return (await this.#e.put(
|
|
274
|
+
e,
|
|
275
|
+
n,
|
|
276
|
+
t
|
|
277
|
+
)).data;
|
|
354
278
|
}
|
|
355
279
|
/**
|
|
356
280
|
* Delete the resource.
|
|
@@ -359,12 +283,11 @@ class HttpClient {
|
|
|
359
283
|
* @param options - The options for the request.
|
|
360
284
|
* @returns The response data.
|
|
361
285
|
*/
|
|
362
|
-
async delete(
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
);
|
|
367
|
-
return response.data;
|
|
286
|
+
async delete(e, s) {
|
|
287
|
+
return (await this.#e.delete(
|
|
288
|
+
e,
|
|
289
|
+
s
|
|
290
|
+
)).data;
|
|
368
291
|
}
|
|
369
292
|
/**
|
|
370
293
|
* Upload the file.
|
|
@@ -373,21 +296,20 @@ class HttpClient {
|
|
|
373
296
|
* @param options - The options for the request.
|
|
374
297
|
* @returns The response data.
|
|
375
298
|
*/
|
|
376
|
-
async upload(
|
|
299
|
+
async upload(e, s) {
|
|
377
300
|
const {
|
|
378
|
-
data,
|
|
379
|
-
onProgress,
|
|
380
|
-
...
|
|
381
|
-
} =
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
301
|
+
data: n,
|
|
302
|
+
onProgress: t,
|
|
303
|
+
...o
|
|
304
|
+
} = s ?? {};
|
|
305
|
+
return (await this.#e.postForm(
|
|
306
|
+
e,
|
|
307
|
+
n,
|
|
385
308
|
{
|
|
386
|
-
...
|
|
387
|
-
onUploadProgress:
|
|
309
|
+
...o,
|
|
310
|
+
onUploadProgress: d(t) ? t : void 0
|
|
388
311
|
}
|
|
389
|
-
);
|
|
390
|
-
return response.data;
|
|
312
|
+
)).data;
|
|
391
313
|
}
|
|
392
314
|
/**
|
|
393
315
|
* Download the file.
|
|
@@ -396,44 +318,42 @@ class HttpClient {
|
|
|
396
318
|
* @param options - The options for the request.
|
|
397
319
|
* @returns The response data.
|
|
398
320
|
*/
|
|
399
|
-
async download(
|
|
321
|
+
async download(e, s) {
|
|
400
322
|
const {
|
|
401
|
-
onProgress,
|
|
402
|
-
filename,
|
|
403
|
-
...
|
|
404
|
-
} =
|
|
405
|
-
|
|
406
|
-
url,
|
|
323
|
+
onProgress: n,
|
|
324
|
+
filename: t,
|
|
325
|
+
...o
|
|
326
|
+
} = s ?? {}, { data: r, headers: i } = await this.#e.get(
|
|
327
|
+
e,
|
|
407
328
|
{
|
|
408
|
-
...
|
|
329
|
+
...o,
|
|
409
330
|
responseType: "blob",
|
|
410
331
|
responseEncoding: "binary",
|
|
411
|
-
onDownloadProgress:
|
|
332
|
+
onDownloadProgress: d(n) ? n : void 0
|
|
412
333
|
}
|
|
413
334
|
);
|
|
414
335
|
try {
|
|
415
|
-
const
|
|
416
|
-
throw new Error(
|
|
336
|
+
const l = JSON.parse(await r.text());
|
|
337
|
+
throw new Error(l.message);
|
|
417
338
|
} catch {
|
|
418
339
|
}
|
|
419
|
-
const
|
|
420
|
-
if (
|
|
421
|
-
const
|
|
422
|
-
if (
|
|
423
|
-
const { name } =
|
|
424
|
-
const original = decodeURIComponent(name);
|
|
425
|
-
const objectUrl = URL.createObjectURL(data);
|
|
340
|
+
const c = i["content-disposition"];
|
|
341
|
+
if ($(c)) {
|
|
342
|
+
const l = b.exec(c);
|
|
343
|
+
if (l && l.groups) {
|
|
344
|
+
const { name: p } = l.groups, a = decodeURIComponent(p), h = URL.createObjectURL(r);
|
|
426
345
|
try {
|
|
427
|
-
const
|
|
428
|
-
|
|
429
|
-
a.download = isFunction(filename) ? filename(original) : filename ?? original;
|
|
430
|
-
a.click();
|
|
346
|
+
const u = document.createElement("a");
|
|
347
|
+
u.href = h, u.download = d(t) ? t(a) : t ?? a, u.click();
|
|
431
348
|
} finally {
|
|
432
|
-
URL.revokeObjectURL(
|
|
349
|
+
URL.revokeObjectURL(h);
|
|
433
350
|
}
|
|
434
351
|
}
|
|
435
352
|
}
|
|
436
353
|
}
|
|
437
354
|
}
|
|
438
|
-
|
|
439
|
-
|
|
355
|
+
export {
|
|
356
|
+
O as HttpClient,
|
|
357
|
+
g as skipAuthenticationHeader,
|
|
358
|
+
E as skipAuthenticationValue
|
|
359
|
+
};
|