@vef-framework/core 2.0.11 → 2.1.0
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/_internal/_rolldown/runtime.cjs +1 -0
- package/dist/cjs/ai/index.cjs +1 -0
- package/dist/cjs/api/client.cjs +1 -1
- package/dist/cjs/api/constants.cjs +1 -1
- package/dist/cjs/api/helpers.cjs +1 -1
- package/dist/cjs/api/index.cjs +1 -1
- package/dist/cjs/auth/helpers.cjs +1 -1
- package/dist/cjs/auth/index.cjs +1 -1
- package/dist/cjs/context/api-client.cjs +1 -1
- package/dist/cjs/context/app.cjs +1 -1
- package/dist/cjs/context/context-selector.cjs +1 -1
- package/dist/cjs/context/disabled.cjs +1 -1
- package/dist/cjs/context/index.cjs +1 -1
- package/dist/cjs/dnd/index.cjs +1 -1
- package/dist/cjs/http/client.cjs +1 -1
- package/dist/cjs/http/constants.cjs +1 -0
- package/dist/cjs/http/errors.cjs +1 -1
- package/dist/cjs/http/helpers.cjs +1 -1
- package/dist/cjs/http/index.cjs +1 -1
- package/dist/cjs/immer/index.cjs +1 -1
- package/dist/cjs/index.cjs +1 -1
- package/dist/cjs/motion/features.cjs +1 -1
- package/dist/cjs/motion/index.cjs +1 -1
- package/dist/cjs/motion/motion-provider.cjs +1 -1
- package/dist/cjs/query/constants.cjs +1 -1
- package/dist/cjs/query/helpers.cjs +1 -1
- package/dist/cjs/query/hooks.cjs +1 -1
- package/dist/cjs/query/index.cjs +1 -1
- package/dist/cjs/sse/client.cjs +1 -0
- package/dist/cjs/sse/helpers.cjs +1 -0
- package/dist/cjs/sse/index.cjs +1 -0
- package/dist/cjs/state/index.cjs +1 -1
- package/dist/cjs/state-machine/index.cjs +1 -1
- package/dist/cjs/store/bound.cjs +1 -1
- package/dist/cjs/store/index.cjs +1 -1
- package/dist/cjs/store/unbound.cjs +1 -3
- package/dist/cjs/store/use-deep.cjs +1 -1
- package/dist/es/ai/index.js +3 -0
- package/dist/es/api/client.js +72 -147
- package/dist/es/api/constants.js +14 -7
- package/dist/es/api/helpers.js +7 -6
- package/dist/es/api/index.js +4 -8
- package/dist/es/auth/helpers.js +9 -9
- package/dist/es/auth/index.js +2 -4
- package/dist/es/context/api-client.js +21 -17
- package/dist/es/context/app.js +8 -8
- package/dist/es/context/context-selector.js +38 -50
- package/dist/es/context/disabled.js +9 -9
- package/dist/es/context/index.js +5 -13
- package/dist/es/dnd/index.js +8 -30
- package/dist/es/http/client.js +186 -359
- package/dist/es/http/constants.js +5 -0
- package/dist/es/http/errors.js +10 -15
- package/dist/es/http/helpers.js +8 -11
- package/dist/es/http/index.js +5 -11
- package/dist/es/immer/index.js +6 -15
- package/dist/es/index.js +27 -122
- package/dist/es/motion/features.js +3 -4
- package/dist/es/motion/index.js +5 -11
- package/dist/es/motion/motion-provider.js +22 -21
- package/dist/es/query/constants.js +5 -4
- package/dist/es/query/helpers.js +40 -54
- package/dist/es/query/hooks.js +18 -28
- package/dist/es/query/index.js +4 -14
- package/dist/es/sse/client.js +121 -0
- package/dist/es/sse/helpers.js +8 -0
- package/dist/es/sse/index.js +3 -0
- package/dist/es/state/index.js +3 -11
- package/dist/es/state-machine/index.js +13 -14
- package/dist/es/store/bound.js +18 -33
- package/dist/es/store/index.js +6 -11
- package/dist/es/store/unbound.js +43 -50
- package/dist/es/store/use-deep.js +12 -11
- package/dist/types/ai/index.d.ts +6 -0
- package/dist/types/api/client.d.ts +15 -35
- package/dist/types/api/constants.d.ts +7 -3
- package/dist/types/api/index.d.ts +1 -1
- package/dist/types/auth/helpers.d.ts +5 -5
- package/dist/types/auth/index.d.ts +2 -2
- package/dist/types/common/index.d.ts +1 -1
- package/dist/types/common/types.d.ts +3 -0
- package/dist/types/context/api-client.d.ts +9 -10
- package/dist/types/context/app.d.ts +9 -1
- package/dist/types/context/context-selector.d.ts +7 -19
- package/dist/types/context/disabled.d.ts +2 -2
- package/dist/types/context/index.d.ts +3 -2
- package/dist/types/context/types.d.ts +0 -1
- package/dist/types/dnd/index.d.ts +4 -2
- package/dist/types/http/client.d.ts +39 -71
- package/dist/types/http/constants.d.ts +24 -0
- package/dist/types/http/index.d.ts +2 -1
- package/dist/types/index.d.ts +4 -2
- package/dist/types/motion/index.d.ts +2 -2
- package/dist/types/motion/motion-provider.d.ts +8 -3
- package/dist/types/query/helpers.d.ts +1 -4
- package/dist/types/query/hooks.d.ts +6 -45
- package/dist/types/query/types.d.ts +12 -12
- package/dist/types/src/ai/index.d.ts +6 -0
- package/dist/types/src/api/client.d.ts +55 -0
- package/dist/types/src/api/constants.d.ts +12 -0
- package/dist/types/src/api/helpers.d.ts +9 -0
- package/dist/types/src/api/index.d.ts +4 -0
- package/dist/types/src/api/types.d.ts +48 -0
- package/dist/types/src/auth/helpers.d.ts +11 -0
- package/dist/types/src/auth/index.d.ts +2 -0
- package/dist/types/src/auth/types.d.ts +1 -0
- package/dist/types/src/common/index.d.ts +1 -0
- package/dist/types/src/common/types.d.ts +98 -0
- package/dist/types/src/context/api-client.d.ts +17 -0
- package/dist/types/src/context/app.d.ts +12 -0
- package/dist/types/src/context/context-selector.d.ts +32 -0
- package/dist/types/src/context/disabled.d.ts +9 -0
- package/dist/types/src/context/index.d.ts +6 -0
- package/dist/types/src/context/types.d.ts +26 -0
- package/dist/types/src/dnd/index.d.ts +8 -0
- package/dist/types/src/http/client.d.ts +112 -0
- package/dist/types/src/http/constants.d.ts +24 -0
- package/dist/types/src/http/errors.d.ts +14 -0
- package/dist/types/src/http/helpers.d.ts +17 -0
- package/dist/types/src/http/index.d.ts +5 -0
- package/dist/types/src/http/types.d.ts +101 -0
- package/dist/types/src/immer/index.d.ts +2 -0
- package/dist/types/src/index.d.ts +16 -0
- package/dist/types/src/motion/features.d.ts +1 -0
- package/dist/types/src/motion/index.d.ts +4 -0
- package/dist/types/src/motion/motion-provider.d.ts +10 -0
- package/dist/types/src/query/constants.d.ts +1 -0
- package/dist/types/src/query/helpers.d.ts +7 -0
- package/dist/types/src/query/hooks.d.ts +27 -0
- package/dist/types/src/query/index.d.ts +4 -0
- package/dist/types/src/query/types.d.ts +51 -0
- package/dist/types/src/sse/client.d.ts +16 -0
- package/dist/types/src/sse/helpers.d.ts +9 -0
- package/dist/types/src/sse/index.d.ts +3 -0
- package/dist/types/src/sse/types.d.ts +98 -0
- package/dist/types/src/state/index.d.ts +1 -0
- package/dist/types/src/state-machine/index.d.ts +15 -0
- package/dist/types/src/store/bound.d.ts +28 -0
- package/dist/types/src/store/index.d.ts +5 -0
- package/dist/types/src/store/types.d.ts +50 -0
- package/dist/types/src/store/unbound.d.ts +26 -0
- package/dist/types/src/store/use-deep.d.ts +8 -0
- package/dist/types/sse/client.d.ts +16 -0
- package/dist/types/sse/helpers.d.ts +9 -0
- package/dist/types/sse/index.d.ts +3 -0
- package/dist/types/sse/types.d.ts +98 -0
- package/dist/types/state-machine/index.d.ts +2 -1
- package/dist/types/store/unbound.d.ts +6 -6
- package/dist/types/store/use-deep.d.ts +4 -3
- package/package.json +18 -16
- package/dist/cjs/common/index.cjs +0 -1
- package/dist/es/common/index.js +0 -1
package/dist/es/http/client.js
CHANGED
|
@@ -1,360 +1,187 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
import { BusinessError as
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
* @param config - The axios request config.
|
|
186
|
-
* @returns The axios request config.
|
|
187
|
-
*/
|
|
188
|
-
replacePathParams(e) {
|
|
189
|
-
const { url: s, params: n = {} } = e;
|
|
190
|
-
return s && w.test(s) && (e.url = s.replaceAll(w, (t, o) => {
|
|
191
|
-
if (!Object.hasOwn(n, o))
|
|
192
|
-
return console.warn(`[HttpClient] ⚠️ 接口: ${s} 路径参数 ${o} 未在查询参数中定义, 请检查`), "unknown";
|
|
193
|
-
const r = n[o];
|
|
194
|
-
return $(r) ? (console.warn(`[HttpClient] ⚠️ 接口: ${s} 路径参数 ${o} 在查询参数中为空, 请检查`), "unknown") : r;
|
|
195
|
-
})), e;
|
|
196
|
-
}
|
|
197
|
-
/**
|
|
198
|
-
* Try to refresh the token using the provided refresh callback.
|
|
199
|
-
*
|
|
200
|
-
* @returns True if token refresh succeeded, false otherwise.
|
|
201
|
-
*/
|
|
202
|
-
async tryRefreshToken() {
|
|
203
|
-
const {
|
|
204
|
-
getAuthTokens: e,
|
|
205
|
-
refreshToken: s,
|
|
206
|
-
setAuthTokens: n
|
|
207
|
-
} = this.#s;
|
|
208
|
-
if (!e || !s || !n)
|
|
209
|
-
return !1;
|
|
210
|
-
this.#t = !0;
|
|
211
|
-
let t = !1;
|
|
212
|
-
try {
|
|
213
|
-
const o = await e();
|
|
214
|
-
if (!o)
|
|
215
|
-
return !1;
|
|
216
|
-
const r = await s(o);
|
|
217
|
-
return await n(Object.freeze(r)), t = !0;
|
|
218
|
-
} catch (o) {
|
|
219
|
-
return console.error(`[HttpClient] ❌ 刷新令牌失败: ${o}`), !1;
|
|
220
|
-
} finally {
|
|
221
|
-
this.#t = !1;
|
|
222
|
-
for (const o of this.#n)
|
|
223
|
-
o(t);
|
|
224
|
-
this.#n = [];
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
/**
|
|
228
|
-
* Retry the request.
|
|
229
|
-
*
|
|
230
|
-
* @param config - The axios request config.
|
|
231
|
-
* @returns The axios response.
|
|
232
|
-
*/
|
|
233
|
-
async retryRequest(e) {
|
|
234
|
-
const s = { ...e };
|
|
235
|
-
return await this.setAccessToken(s), this.#e(s);
|
|
236
|
-
}
|
|
237
|
-
/**
|
|
238
|
-
* Get the resource.
|
|
239
|
-
*
|
|
240
|
-
* @param url - The url.
|
|
241
|
-
* @param options - The options for the request.
|
|
242
|
-
* @returns The response data.
|
|
243
|
-
*/
|
|
244
|
-
async get(e, s) {
|
|
245
|
-
return (await this.#e.get(
|
|
246
|
-
e,
|
|
247
|
-
s
|
|
248
|
-
)).data;
|
|
249
|
-
}
|
|
250
|
-
/**
|
|
251
|
-
* Post the resource.
|
|
252
|
-
*
|
|
253
|
-
* @param url - The url.
|
|
254
|
-
* @param options - The options for the request.
|
|
255
|
-
* @returns The response data.
|
|
256
|
-
*/
|
|
257
|
-
async post(e, s) {
|
|
258
|
-
const { data: n, ...t } = s ?? {};
|
|
259
|
-
return (await this.#e.post(
|
|
260
|
-
e,
|
|
261
|
-
n,
|
|
262
|
-
t
|
|
263
|
-
)).data;
|
|
264
|
-
}
|
|
265
|
-
/**
|
|
266
|
-
* Update the resource.
|
|
267
|
-
*
|
|
268
|
-
* @param url - The url.
|
|
269
|
-
* @param options - The options for the request.
|
|
270
|
-
* @returns The response data.
|
|
271
|
-
*/
|
|
272
|
-
async put(e, s) {
|
|
273
|
-
const { data: n, ...t } = s ?? {};
|
|
274
|
-
return (await this.#e.put(
|
|
275
|
-
e,
|
|
276
|
-
n,
|
|
277
|
-
t
|
|
278
|
-
)).data;
|
|
279
|
-
}
|
|
280
|
-
/**
|
|
281
|
-
* Delete the resource.
|
|
282
|
-
*
|
|
283
|
-
* @param url - The url.
|
|
284
|
-
* @param options - The options for the request.
|
|
285
|
-
* @returns The response data.
|
|
286
|
-
*/
|
|
287
|
-
async delete(e, s) {
|
|
288
|
-
return (await this.#e.delete(
|
|
289
|
-
e,
|
|
290
|
-
s
|
|
291
|
-
)).data;
|
|
292
|
-
}
|
|
293
|
-
/**
|
|
294
|
-
* Upload the file.
|
|
295
|
-
*
|
|
296
|
-
* @param url - The url.
|
|
297
|
-
* @param options - The options for the request.
|
|
298
|
-
* @returns The response data.
|
|
299
|
-
*/
|
|
300
|
-
async upload(e, s) {
|
|
301
|
-
const {
|
|
302
|
-
data: n,
|
|
303
|
-
onProgress: t,
|
|
304
|
-
...o
|
|
305
|
-
} = s ?? {};
|
|
306
|
-
return (await this.#e.postForm(
|
|
307
|
-
e,
|
|
308
|
-
n,
|
|
309
|
-
{
|
|
310
|
-
...o,
|
|
311
|
-
onUploadProgress: d(t) ? t : void 0
|
|
312
|
-
}
|
|
313
|
-
)).data;
|
|
314
|
-
}
|
|
315
|
-
/**
|
|
316
|
-
* Download the file.
|
|
317
|
-
*
|
|
318
|
-
* @param url - The url.
|
|
319
|
-
* @param options - The options for the request.
|
|
320
|
-
* @returns The response data.
|
|
321
|
-
*/
|
|
322
|
-
async download(e, s) {
|
|
323
|
-
const {
|
|
324
|
-
onProgress: n,
|
|
325
|
-
filename: t,
|
|
326
|
-
...o
|
|
327
|
-
} = s ?? {}, { data: r, headers: i } = await this.#e.get(
|
|
328
|
-
e,
|
|
329
|
-
{
|
|
330
|
-
...o,
|
|
331
|
-
responseType: "blob",
|
|
332
|
-
responseEncoding: "binary",
|
|
333
|
-
onDownloadProgress: d(n) ? n : void 0
|
|
334
|
-
}
|
|
335
|
-
);
|
|
336
|
-
try {
|
|
337
|
-
const l = JSON.parse(await r.text());
|
|
338
|
-
throw new Error(l.message);
|
|
339
|
-
} catch {
|
|
340
|
-
}
|
|
341
|
-
const c = i["content-disposition"];
|
|
342
|
-
if (R(c)) {
|
|
343
|
-
const l = E.exec(c);
|
|
344
|
-
if (l && l.groups) {
|
|
345
|
-
const { name: p } = l.groups, a = decodeURIComponent(p), u = URL.createObjectURL(r);
|
|
346
|
-
try {
|
|
347
|
-
const h = document.createElement("a");
|
|
348
|
-
h.href = u, h.download = d(t) ? t(a) : t ?? a, h.click();
|
|
349
|
-
} finally {
|
|
350
|
-
URL.revokeObjectURL(u);
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
export {
|
|
357
|
-
q as HttpClient,
|
|
358
|
-
g as skipAuthenticationHeader,
|
|
359
|
-
A as skipAuthenticationValue
|
|
1
|
+
/*! @vef-framework/core v2.1.0 made by Venus | 2026-03-27T07:13:02.254Z */
|
|
2
|
+
import { CONTENT_DISPOSITION_FILENAME_REGEX as e, DEFAULT_TIMEOUT as t, PATH_PARAM_REGEX as n, SKIP_AUTH_HEADER as r } from "./constants.js";
|
|
3
|
+
import { BusinessError as i } from "./errors.js";
|
|
4
|
+
import { encodeQueryString as a, isArray as o, isFunction as s, isNullish as c, isString as l } from "@vef-framework/shared";
|
|
5
|
+
import u, { CanceledError as d } from "axios";
|
|
6
|
+
//#region src/http/client.ts
|
|
7
|
+
var f = class {
|
|
8
|
+
#e;
|
|
9
|
+
#t;
|
|
10
|
+
#n = !1;
|
|
11
|
+
#r = [];
|
|
12
|
+
constructor(e) {
|
|
13
|
+
this.#t = e;
|
|
14
|
+
let { baseUrl: n, timeout: r = t } = e;
|
|
15
|
+
this.#e = u.create({
|
|
16
|
+
baseURL: n,
|
|
17
|
+
allowAbsoluteUrls: !0,
|
|
18
|
+
timeout: r,
|
|
19
|
+
headers: { "Content-Type": "application/json" },
|
|
20
|
+
paramsSerializer: (e) => a(e, {
|
|
21
|
+
arrayFormat: "repeat",
|
|
22
|
+
skipNulls: !0,
|
|
23
|
+
charset: "utf-8"
|
|
24
|
+
}),
|
|
25
|
+
responseType: "json",
|
|
26
|
+
responseEncoding: "utf-8",
|
|
27
|
+
validateStatus: (e) => e >= 200 && e < 300,
|
|
28
|
+
withCredentials: !1,
|
|
29
|
+
timeoutErrorMessage: "请求超时"
|
|
30
|
+
}), this.initInterceptors();
|
|
31
|
+
}
|
|
32
|
+
initInterceptors() {
|
|
33
|
+
this.#e.interceptors.request.use(this.handleRequest.bind(this), this.handleRequestError.bind(this)), this.#e.interceptors.response.use(this.handleResponse.bind(this), this.handleResponseError.bind(this));
|
|
34
|
+
}
|
|
35
|
+
matchesCode(e, t) {
|
|
36
|
+
return o(t) ? t.includes(e) : e === t;
|
|
37
|
+
}
|
|
38
|
+
async handleRequest(e) {
|
|
39
|
+
let t = e.headers[r] === "1";
|
|
40
|
+
if (this.#n && !t && !await new Promise((e) => {
|
|
41
|
+
this.#r.push(e);
|
|
42
|
+
})) throw Error("登录已过期, 请重新登录");
|
|
43
|
+
return t ? delete e.headers[r] : await this.injectAccessToken(e), this.replacePathParams(e), e;
|
|
44
|
+
}
|
|
45
|
+
handleRequestError(e) {
|
|
46
|
+
let { showErrorMessage: t } = this.#t, n = `发起请求失败: ${(e instanceof Error ? e.message : String(e)) || "未知错误"}`;
|
|
47
|
+
return t ? t(n) : console.error(`[HttpClient] ${n}`), Promise.reject(e);
|
|
48
|
+
}
|
|
49
|
+
handleResponse(e) {
|
|
50
|
+
let { showWarningMessage: t, okCode: n = 0 } = this.#t, { code: r, message: a, data: o } = e.data;
|
|
51
|
+
if (this.matchesCode(r, n)) return e;
|
|
52
|
+
throw t ? t(a) : console.warn(`[HttpClient] [${e.config.method}: ${e.config.url}] 返回错误: ${a}`), new i(r, a, o);
|
|
53
|
+
}
|
|
54
|
+
async handleResponseError(e) {
|
|
55
|
+
if (e instanceof d) {
|
|
56
|
+
if (e.response) {
|
|
57
|
+
let { method: t, url: n } = e.response.config;
|
|
58
|
+
console.warn(`[HttpClient] [${t}: ${n}] 被取消`);
|
|
59
|
+
}
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
let { response: t } = e;
|
|
63
|
+
if (!t) throw this.logError(`请求失败: ${e.message || "未知错误"}`), e;
|
|
64
|
+
let { status: n, config: r, data: i } = t, { code: a, message: o } = i, s = `[${r.method}: ${r.url}]`;
|
|
65
|
+
switch (n) {
|
|
66
|
+
case 400:
|
|
67
|
+
this.logWarning(o, `${s} 参数错误: ${o}`);
|
|
68
|
+
break;
|
|
69
|
+
case 401:
|
|
70
|
+
await this.handleUnauthorized(e, a, s);
|
|
71
|
+
break;
|
|
72
|
+
case 403:
|
|
73
|
+
this.#t.showWarningMessage?.(`${o}, 请联系管理员为您开通`), console.warn(`[HttpClient] ${s} 访问被拒绝: ${o}`), await this.#t.onAccessDenied?.();
|
|
74
|
+
break;
|
|
75
|
+
default: this.logError(o, `${s} 返回错误: ${o}`);
|
|
76
|
+
}
|
|
77
|
+
throw e;
|
|
78
|
+
}
|
|
79
|
+
async handleUnauthorized(e, t, n) {
|
|
80
|
+
let { tokenExpiredCode: r = [] } = this.#t;
|
|
81
|
+
if (!this.matchesCode(t, r)) {
|
|
82
|
+
await this.#t.onUnauthenticated?.();
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
if (this.#n) throw e;
|
|
86
|
+
if (await this.tryRefreshToken()) return this.retryRequest(e.response.config);
|
|
87
|
+
this.logInfo("登录已过期, 请重新登录"), await this.#t.onUnauthenticated?.();
|
|
88
|
+
}
|
|
89
|
+
logInfo(e) {
|
|
90
|
+
this.#t.showInfoMessage ? this.#t.showInfoMessage(e) : console.info(`[HttpClient] ${e}`);
|
|
91
|
+
}
|
|
92
|
+
logWarning(e, t) {
|
|
93
|
+
this.#t.showWarningMessage ? this.#t.showWarningMessage(e) : console.warn(`[HttpClient] ${t ?? e}`);
|
|
94
|
+
}
|
|
95
|
+
logError(e, t) {
|
|
96
|
+
this.#t.showErrorMessage ? this.#t.showErrorMessage(e) : console.error(`[HttpClient] ${t ?? e}`);
|
|
97
|
+
}
|
|
98
|
+
async injectAccessToken(e) {
|
|
99
|
+
let { getAuthTokens: t } = this.#t;
|
|
100
|
+
if (!t) return;
|
|
101
|
+
let n = await t();
|
|
102
|
+
n?.accessToken && (e.headers.Authorization = `Bearer ${n.accessToken}`);
|
|
103
|
+
}
|
|
104
|
+
replacePathParams(e) {
|
|
105
|
+
let { url: t, params: r = {} } = e;
|
|
106
|
+
!t || !n.test(t) || (n.lastIndex = 0, e.url = t.replaceAll(n, (e, n) => {
|
|
107
|
+
if (!Object.hasOwn(r, n)) return console.warn(`[HttpClient] 接口: ${t} 路径参数 ${n} 未在查询参数中定义, 请检查`), "unknown";
|
|
108
|
+
let i = r[n];
|
|
109
|
+
return c(i) ? (console.warn(`[HttpClient] 接口: ${t} 路径参数 ${n} 在查询参数中为空, 请检查`), "unknown") : String(i);
|
|
110
|
+
}));
|
|
111
|
+
}
|
|
112
|
+
async ensureTokenRefreshed(e = !0) {
|
|
113
|
+
if (this.#n) return new Promise((e) => {
|
|
114
|
+
this.#r.push(e);
|
|
115
|
+
});
|
|
116
|
+
let t = await this.tryRefreshToken();
|
|
117
|
+
return !t && e && await this.#t.onUnauthenticated?.(), t;
|
|
118
|
+
}
|
|
119
|
+
async tryRefreshToken() {
|
|
120
|
+
let { getAuthTokens: e, refreshToken: t, setAuthTokens: n } = this.#t;
|
|
121
|
+
if (!e || !t || !n) return !1;
|
|
122
|
+
this.#n = !0;
|
|
123
|
+
let r = !1;
|
|
124
|
+
try {
|
|
125
|
+
let i = await e();
|
|
126
|
+
if (!i) return !1;
|
|
127
|
+
let a = await t(i);
|
|
128
|
+
return await n(Object.freeze(a)), r = !0, !0;
|
|
129
|
+
} catch (e) {
|
|
130
|
+
return console.error(`[HttpClient] 刷新令牌失败: ${e}`), !1;
|
|
131
|
+
} finally {
|
|
132
|
+
this.#n = !1;
|
|
133
|
+
for (let e of this.#r) e(r);
|
|
134
|
+
this.#r = [];
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
async retryRequest(e) {
|
|
138
|
+
let t = { ...e };
|
|
139
|
+
return await this.injectAccessToken(t), this.#e(t);
|
|
140
|
+
}
|
|
141
|
+
async get(e, t) {
|
|
142
|
+
return (await this.#e.get(e, t)).data;
|
|
143
|
+
}
|
|
144
|
+
async post(e, t) {
|
|
145
|
+
let { data: n, ...r } = t ?? {};
|
|
146
|
+
return (await this.#e.post(e, n, r)).data;
|
|
147
|
+
}
|
|
148
|
+
async put(e, t) {
|
|
149
|
+
let { data: n, ...r } = t ?? {};
|
|
150
|
+
return (await this.#e.put(e, n, r)).data;
|
|
151
|
+
}
|
|
152
|
+
async delete(e, t) {
|
|
153
|
+
return (await this.#e.delete(e, t)).data;
|
|
154
|
+
}
|
|
155
|
+
async upload(e, t) {
|
|
156
|
+
let { data: n, onProgress: r, ...i } = t ?? {};
|
|
157
|
+
return (await this.#e.postForm(e, n, {
|
|
158
|
+
...i,
|
|
159
|
+
onUploadProgress: s(r) ? r : void 0
|
|
160
|
+
})).data;
|
|
161
|
+
}
|
|
162
|
+
async download(t, n) {
|
|
163
|
+
let { onProgress: r, filename: i, ...a } = n ?? {}, { data: o, headers: c } = await this.#e.get(t, {
|
|
164
|
+
...a,
|
|
165
|
+
responseType: "blob",
|
|
166
|
+
responseEncoding: "binary",
|
|
167
|
+
onDownloadProgress: s(r) ? r : void 0
|
|
168
|
+
});
|
|
169
|
+
try {
|
|
170
|
+
let e = JSON.parse(await o.text());
|
|
171
|
+
throw Error(e.message);
|
|
172
|
+
} catch {}
|
|
173
|
+
let u = c["content-disposition"];
|
|
174
|
+
if (!l(u)) return;
|
|
175
|
+
let d = e.exec(u);
|
|
176
|
+
if (!d?.groups?.name) return;
|
|
177
|
+
let f = decodeURIComponent(d.groups.name), p = URL.createObjectURL(o);
|
|
178
|
+
try {
|
|
179
|
+
let e = document.createElement("a");
|
|
180
|
+
e.href = p, e.download = s(i) ? i(f) : i ?? f, e.click();
|
|
181
|
+
} finally {
|
|
182
|
+
URL.revokeObjectURL(p);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
360
185
|
};
|
|
186
|
+
//#endregion
|
|
187
|
+
export { f as HttpClient };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/*! @vef-framework/core v2.1.0 made by Venus | 2026-03-27T07:13:02.254Z */
|
|
2
|
+
//#region src/http/constants.ts
|
|
3
|
+
var e = "__vef_http_client_key", t = /:(?<key>\w+)/g, n = /filename[^;=\n]*=(?<name>(?<quote>['"]).*?\2|[^;\n]*)/, r = "X-Skip-Authentication", i = "1", a = 3e4;
|
|
4
|
+
//#endregion
|
|
5
|
+
export { n as CONTENT_DISPOSITION_FILENAME_REGEX, a as DEFAULT_TIMEOUT, e as HTTP_CLIENT_KEY, t as PATH_PARAM_REGEX, r as SKIP_AUTH_HEADER, i as SKIP_AUTH_VALUE };
|
package/dist/es/http/errors.js
CHANGED
|
@@ -1,16 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
data;
|
|
10
|
-
constructor(s, r, e) {
|
|
11
|
-
super(r), this.name = "BusinessError", this.code = s, this.data = e;
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
export {
|
|
15
|
-
o as BusinessError
|
|
1
|
+
/*! @vef-framework/core v2.1.0 made by Venus | 2026-03-27T07:13:02.254Z */
|
|
2
|
+
//#region src/http/errors.ts
|
|
3
|
+
var e = class extends Error {
|
|
4
|
+
code;
|
|
5
|
+
data;
|
|
6
|
+
constructor(e, t, n) {
|
|
7
|
+
super(t), this.name = "BusinessError", this.code = e, this.data = n;
|
|
8
|
+
}
|
|
16
9
|
};
|
|
10
|
+
//#endregion
|
|
11
|
+
export { e as BusinessError };
|
package/dist/es/http/helpers.js
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
/*! @vef-framework/core v2.1.0 made by Venus | 2026-03-27T07:13:02.254Z */
|
|
2
|
+
import "./errors.js";
|
|
3
|
+
import { HttpClient as e } from "./client.js";
|
|
4
|
+
//#region src/http/helpers.ts
|
|
5
|
+
function t(t) {
|
|
6
|
+
return Object.freeze(new e(t));
|
|
5
7
|
}
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}
|
|
9
|
-
export {
|
|
10
|
-
o as createHttpClient,
|
|
11
|
-
s as isBusinessError
|
|
12
|
-
};
|
|
8
|
+
//#endregion
|
|
9
|
+
export { t as createHttpClient };
|
package/dist/es/http/index.js
CHANGED
|
@@ -1,11 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
r as HttpClient,
|
|
7
|
-
a as createHttpClient,
|
|
8
|
-
u as isBusinessError,
|
|
9
|
-
i as skipAuthenticationHeader,
|
|
10
|
-
o as skipAuthenticationValue
|
|
11
|
-
};
|
|
1
|
+
/*! @vef-framework/core v2.1.0 made by Venus | 2026-03-27T07:13:02.254Z */
|
|
2
|
+
import "./constants.js";
|
|
3
|
+
import "./errors.js";
|
|
4
|
+
import "./client.js";
|
|
5
|
+
import "./helpers.js";
|
package/dist/es/immer/index.js
CHANGED
|
@@ -1,15 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
import { applyPatches as
|
|
3
|
-
import { useImmer as
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
t
|
|
7
|
-
export {
|
|
8
|
-
c as applyPatches,
|
|
9
|
-
m as currentState,
|
|
10
|
-
p as originalState,
|
|
11
|
-
u as produce,
|
|
12
|
-
i as produceWithPatches,
|
|
13
|
-
n as useImmer,
|
|
14
|
-
f as useImmerReducer
|
|
15
|
-
};
|
|
1
|
+
/*! @vef-framework/core v2.1.0 made by Venus | 2026-03-27T07:13:02.254Z */
|
|
2
|
+
import { applyPatches as e, current as t, enableMapSet as n, enablePatches as r, original as i, produce as a, produceWithPatches as o, setAutoFreeze as s } from "immer";
|
|
3
|
+
import { useImmer as c, useImmerReducer as l } from "use-immer";
|
|
4
|
+
n(), r(), s(!1);
|
|
5
|
+
//#endregion
|
|
6
|
+
export { e as applyPatches, t as currentState, i as originalState, a as produce, o as produceWithPatches, c as useImmer, l as useImmerReducer };
|