@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.
Files changed (152) hide show
  1. package/dist/cjs/_internal/_rolldown/runtime.cjs +1 -0
  2. package/dist/cjs/ai/index.cjs +1 -0
  3. package/dist/cjs/api/client.cjs +1 -1
  4. package/dist/cjs/api/constants.cjs +1 -1
  5. package/dist/cjs/api/helpers.cjs +1 -1
  6. package/dist/cjs/api/index.cjs +1 -1
  7. package/dist/cjs/auth/helpers.cjs +1 -1
  8. package/dist/cjs/auth/index.cjs +1 -1
  9. package/dist/cjs/context/api-client.cjs +1 -1
  10. package/dist/cjs/context/app.cjs +1 -1
  11. package/dist/cjs/context/context-selector.cjs +1 -1
  12. package/dist/cjs/context/disabled.cjs +1 -1
  13. package/dist/cjs/context/index.cjs +1 -1
  14. package/dist/cjs/dnd/index.cjs +1 -1
  15. package/dist/cjs/http/client.cjs +1 -1
  16. package/dist/cjs/http/constants.cjs +1 -0
  17. package/dist/cjs/http/errors.cjs +1 -1
  18. package/dist/cjs/http/helpers.cjs +1 -1
  19. package/dist/cjs/http/index.cjs +1 -1
  20. package/dist/cjs/immer/index.cjs +1 -1
  21. package/dist/cjs/index.cjs +1 -1
  22. package/dist/cjs/motion/features.cjs +1 -1
  23. package/dist/cjs/motion/index.cjs +1 -1
  24. package/dist/cjs/motion/motion-provider.cjs +1 -1
  25. package/dist/cjs/query/constants.cjs +1 -1
  26. package/dist/cjs/query/helpers.cjs +1 -1
  27. package/dist/cjs/query/hooks.cjs +1 -1
  28. package/dist/cjs/query/index.cjs +1 -1
  29. package/dist/cjs/sse/client.cjs +1 -0
  30. package/dist/cjs/sse/helpers.cjs +1 -0
  31. package/dist/cjs/sse/index.cjs +1 -0
  32. package/dist/cjs/state/index.cjs +1 -1
  33. package/dist/cjs/state-machine/index.cjs +1 -1
  34. package/dist/cjs/store/bound.cjs +1 -1
  35. package/dist/cjs/store/index.cjs +1 -1
  36. package/dist/cjs/store/unbound.cjs +1 -3
  37. package/dist/cjs/store/use-deep.cjs +1 -1
  38. package/dist/es/ai/index.js +3 -0
  39. package/dist/es/api/client.js +72 -147
  40. package/dist/es/api/constants.js +14 -7
  41. package/dist/es/api/helpers.js +7 -6
  42. package/dist/es/api/index.js +4 -8
  43. package/dist/es/auth/helpers.js +9 -9
  44. package/dist/es/auth/index.js +2 -4
  45. package/dist/es/context/api-client.js +21 -17
  46. package/dist/es/context/app.js +8 -8
  47. package/dist/es/context/context-selector.js +38 -50
  48. package/dist/es/context/disabled.js +9 -9
  49. package/dist/es/context/index.js +5 -13
  50. package/dist/es/dnd/index.js +8 -30
  51. package/dist/es/http/client.js +186 -359
  52. package/dist/es/http/constants.js +5 -0
  53. package/dist/es/http/errors.js +10 -15
  54. package/dist/es/http/helpers.js +8 -11
  55. package/dist/es/http/index.js +5 -11
  56. package/dist/es/immer/index.js +6 -15
  57. package/dist/es/index.js +27 -122
  58. package/dist/es/motion/features.js +3 -4
  59. package/dist/es/motion/index.js +5 -11
  60. package/dist/es/motion/motion-provider.js +22 -21
  61. package/dist/es/query/constants.js +5 -4
  62. package/dist/es/query/helpers.js +40 -54
  63. package/dist/es/query/hooks.js +18 -28
  64. package/dist/es/query/index.js +4 -14
  65. package/dist/es/sse/client.js +121 -0
  66. package/dist/es/sse/helpers.js +8 -0
  67. package/dist/es/sse/index.js +3 -0
  68. package/dist/es/state/index.js +3 -11
  69. package/dist/es/state-machine/index.js +13 -14
  70. package/dist/es/store/bound.js +18 -33
  71. package/dist/es/store/index.js +6 -11
  72. package/dist/es/store/unbound.js +43 -50
  73. package/dist/es/store/use-deep.js +12 -11
  74. package/dist/types/ai/index.d.ts +6 -0
  75. package/dist/types/api/client.d.ts +15 -35
  76. package/dist/types/api/constants.d.ts +7 -3
  77. package/dist/types/api/index.d.ts +1 -1
  78. package/dist/types/auth/helpers.d.ts +5 -5
  79. package/dist/types/auth/index.d.ts +2 -2
  80. package/dist/types/common/index.d.ts +1 -1
  81. package/dist/types/common/types.d.ts +3 -0
  82. package/dist/types/context/api-client.d.ts +9 -10
  83. package/dist/types/context/app.d.ts +9 -1
  84. package/dist/types/context/context-selector.d.ts +7 -19
  85. package/dist/types/context/disabled.d.ts +2 -2
  86. package/dist/types/context/index.d.ts +3 -2
  87. package/dist/types/context/types.d.ts +0 -1
  88. package/dist/types/dnd/index.d.ts +4 -2
  89. package/dist/types/http/client.d.ts +39 -71
  90. package/dist/types/http/constants.d.ts +24 -0
  91. package/dist/types/http/index.d.ts +2 -1
  92. package/dist/types/index.d.ts +4 -2
  93. package/dist/types/motion/index.d.ts +2 -2
  94. package/dist/types/motion/motion-provider.d.ts +8 -3
  95. package/dist/types/query/helpers.d.ts +1 -4
  96. package/dist/types/query/hooks.d.ts +6 -45
  97. package/dist/types/query/types.d.ts +12 -12
  98. package/dist/types/src/ai/index.d.ts +6 -0
  99. package/dist/types/src/api/client.d.ts +55 -0
  100. package/dist/types/src/api/constants.d.ts +12 -0
  101. package/dist/types/src/api/helpers.d.ts +9 -0
  102. package/dist/types/src/api/index.d.ts +4 -0
  103. package/dist/types/src/api/types.d.ts +48 -0
  104. package/dist/types/src/auth/helpers.d.ts +11 -0
  105. package/dist/types/src/auth/index.d.ts +2 -0
  106. package/dist/types/src/auth/types.d.ts +1 -0
  107. package/dist/types/src/common/index.d.ts +1 -0
  108. package/dist/types/src/common/types.d.ts +98 -0
  109. package/dist/types/src/context/api-client.d.ts +17 -0
  110. package/dist/types/src/context/app.d.ts +12 -0
  111. package/dist/types/src/context/context-selector.d.ts +32 -0
  112. package/dist/types/src/context/disabled.d.ts +9 -0
  113. package/dist/types/src/context/index.d.ts +6 -0
  114. package/dist/types/src/context/types.d.ts +26 -0
  115. package/dist/types/src/dnd/index.d.ts +8 -0
  116. package/dist/types/src/http/client.d.ts +112 -0
  117. package/dist/types/src/http/constants.d.ts +24 -0
  118. package/dist/types/src/http/errors.d.ts +14 -0
  119. package/dist/types/src/http/helpers.d.ts +17 -0
  120. package/dist/types/src/http/index.d.ts +5 -0
  121. package/dist/types/src/http/types.d.ts +101 -0
  122. package/dist/types/src/immer/index.d.ts +2 -0
  123. package/dist/types/src/index.d.ts +16 -0
  124. package/dist/types/src/motion/features.d.ts +1 -0
  125. package/dist/types/src/motion/index.d.ts +4 -0
  126. package/dist/types/src/motion/motion-provider.d.ts +10 -0
  127. package/dist/types/src/query/constants.d.ts +1 -0
  128. package/dist/types/src/query/helpers.d.ts +7 -0
  129. package/dist/types/src/query/hooks.d.ts +27 -0
  130. package/dist/types/src/query/index.d.ts +4 -0
  131. package/dist/types/src/query/types.d.ts +51 -0
  132. package/dist/types/src/sse/client.d.ts +16 -0
  133. package/dist/types/src/sse/helpers.d.ts +9 -0
  134. package/dist/types/src/sse/index.d.ts +3 -0
  135. package/dist/types/src/sse/types.d.ts +98 -0
  136. package/dist/types/src/state/index.d.ts +1 -0
  137. package/dist/types/src/state-machine/index.d.ts +15 -0
  138. package/dist/types/src/store/bound.d.ts +28 -0
  139. package/dist/types/src/store/index.d.ts +5 -0
  140. package/dist/types/src/store/types.d.ts +50 -0
  141. package/dist/types/src/store/unbound.d.ts +26 -0
  142. package/dist/types/src/store/use-deep.d.ts +8 -0
  143. package/dist/types/sse/client.d.ts +16 -0
  144. package/dist/types/sse/helpers.d.ts +9 -0
  145. package/dist/types/sse/index.d.ts +3 -0
  146. package/dist/types/sse/types.d.ts +98 -0
  147. package/dist/types/state-machine/index.d.ts +2 -1
  148. package/dist/types/store/unbound.d.ts +6 -6
  149. package/dist/types/store/use-deep.d.ts +4 -3
  150. package/package.json +18 -16
  151. package/dist/cjs/common/index.cjs +0 -1
  152. package/dist/es/common/index.js +0 -1
@@ -1,360 +1,187 @@
1
- import { encodeQueryString as k, isArray as y, isNullish as $, isFunction as d, isString as R } from "@vef-framework/shared";
2
- import C, { CanceledError as T } from "axios";
3
- import { BusinessError as b } from "./errors.js";
4
- const w = /:(?<key>\w+)/g, E = /filename[^;=\n]*=(?<name>(?<quote>['"]).*?\2|[^;\n]*)/, g = "X-Skip-Authentication", A = "1";
5
- class q {
6
- /**
7
- * The axios instance.
8
- */
9
- #e;
10
- /**
11
- * The http client options.
12
- */
13
- #s;
14
- /**
15
- * Indicates whether a token refresh is in progress.
16
- */
17
- #t = !1;
18
- /**
19
- * Queue of pending requests waiting for token refresh to complete.
20
- */
21
- #n = [];
22
- constructor(e) {
23
- this.#s = e;
24
- const {
25
- baseUrl: s,
26
- timeout: n = 1e3 * 30
27
- } = e;
28
- this.#e = C.create({
29
- baseURL: s,
30
- allowAbsoluteUrls: !0,
31
- timeout: n,
32
- headers: {
33
- "Content-Type": "application/json"
34
- },
35
- paramsSerializer: (t) => k(
36
- t,
37
- {
38
- arrayFormat: "repeat",
39
- skipNulls: !0,
40
- charset: "utf-8"
41
- }
42
- ),
43
- responseType: "json",
44
- responseEncoding: "utf-8",
45
- validateStatus(t) {
46
- return t >= 200 && t < 300;
47
- },
48
- withCredentials: !1,
49
- timeoutErrorMessage: "请求超时"
50
- }), this.initInterceptors();
51
- }
52
- initInterceptors() {
53
- this.#e.interceptors.request.use(
54
- this.handleRequest.bind(this),
55
- this.handleRequestError.bind(this)
56
- ), this.#e.interceptors.response.use(
57
- this.handleResponse.bind(this),
58
- this.handleResponseError.bind(this)
59
- );
60
- }
61
- /**
62
- * Check if the code belongs to the target.
63
- *
64
- * @param code - The code.
65
- * @param target - The target.
66
- * @returns The result.
67
- */
68
- isBelongsTo(e, s) {
69
- return y(s) ? s.includes(e) : e === s;
70
- }
71
- /**
72
- * Handle the request.
73
- *
74
- * @param config - The axios request config.
75
- * @returns The axios request config.
76
- */
77
- async handleRequest(e) {
78
- const s = e.headers[g] === A;
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;
84
- }
85
- /**
86
- * Handle the request error.
87
- *
88
- * @param error - The axios error.
89
- */
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);
93
- }
94
- /**
95
- * Handle the response.
96
- *
97
- * @param response - The axios response.
98
- * @returns The axios response.
99
- */
100
- handleResponse(e) {
101
- const {
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 b(t, o, r);
112
- }
113
- /**
114
- * Handle the response error.
115
- *
116
- * @param error - The axios error.
117
- */
118
- async handleResponseError(e) {
119
- const {
120
- showInfoMessage: s,
121
- showWarningMessage: n,
122
- showErrorMessage: t,
123
- tokenExpiredCode: o = []
124
- } = this.#s;
125
- if (e instanceof T) {
126
- if (e.response) {
127
- const { method: i, url: c } = e.response.config;
128
- console.warn(`[HttpClient] ⚠️ [${i}: ${c}] 被取消`);
129
- }
130
- return;
131
- }
132
- const { response: r } = e;
133
- if (r) {
134
- const {
135
- status: i,
136
- config: c,
137
- data: l
138
- } = r, { code: p, message: a } = l, u = `[${c.method}: ${c.url}]`;
139
- switch (i) {
140
- case 401: {
141
- if (this.isBelongsTo(p, o)) {
142
- let h;
143
- if (this.#t ? h = await new Promise((m) => {
144
- this.#n.push(m);
145
- }) : h = await this.tryRefreshToken(), h)
146
- return this.retryRequest(c);
147
- const f = "登录已过期, 请重新登录";
148
- s ? s(f) : console.info(`[HttpClient] ℹ️ ${f}`);
149
- }
150
- await this.#s.onUnauthenticated?.();
151
- break;
152
- }
153
- case 403: {
154
- n?.(`${a}, 请联系管理员为您开通`), console.warn(`[HttpClient] ⚠️ ${u} 访问被拒绝: ${a}`), await this.#s.onAccessDenied?.();
155
- break;
156
- }
157
- case 400: {
158
- n ? n(a) : console.warn(`[HttpClient] ⚠️ ${u} 参数错误: ${a}`);
159
- break;
160
- }
161
- default:
162
- t ? t(a) : console.error(`[HttpClient] ❌ ${u} 返回错误: ${a}`);
163
- }
164
- } else {
165
- const i = `请求失败: ${e.message || "未知错误"}`;
166
- t ? t(i) : console.error(`[HttpClient] ❌ ${i}`);
167
- }
168
- throw e;
169
- }
170
- /**
171
- * Injects access token into request Authorization header.
172
- *
173
- * @param config - The axios request config.
174
- */
175
- async setAccessToken(e) {
176
- const { getAuthTokens: s } = this.#s;
177
- if (s) {
178
- const t = (await s())?.accessToken;
179
- t && (e.headers.Authorization = `Bearer ${t}`);
180
- }
181
- }
182
- /**
183
- * Replace the path parameters in the URL.
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 };
@@ -1,16 +1,11 @@
1
- class o extends Error {
2
- /**
3
- * The business error code from the API response.
4
- */
5
- code;
6
- /**
7
- * The original API response data.
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 };
@@ -1,12 +1,9 @@
1
- import { HttpClient as t } from "./client.js";
2
- import { BusinessError as e } from "./errors.js";
3
- function o(r) {
4
- return Object.freeze(new t(r));
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
- function s(r) {
7
- return r instanceof e;
8
- }
9
- export {
10
- o as createHttpClient,
11
- s as isBusinessError
12
- };
8
+ //#endregion
9
+ export { t as createHttpClient };
@@ -1,11 +1,5 @@
1
- import { HttpClient as r, skipAuthenticationHeader as i, skipAuthenticationValue as o } from "./client.js";
2
- import { BusinessError as n } from "./errors.js";
3
- import { createHttpClient as a, isBusinessError as u } from "./helpers.js";
4
- export {
5
- n as BusinessError,
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";
@@ -1,15 +1,6 @@
1
- import { enableMapSet as e, enablePatches as r, setAutoFreeze as t } from "immer";
2
- import { applyPatches as c, current as m, original as p, produce as u, produceWithPatches as i } from "immer";
3
- import { useImmer as n, useImmerReducer as f } from "use-immer";
4
- e();
5
- r();
6
- t(!1);
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 };