@openuverse/uvapi 0.0.0-stage → 1.1.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.
Files changed (137) hide show
  1. package/README.md +3871 -3
  2. package/dist/_virtual/_commonjsHelpers.js +6 -0
  3. package/dist/_virtual/index.js +4 -0
  4. package/dist/api/RestAPIClient.d.ts +191 -0
  5. package/dist/api/RestAPIClient.js +328 -0
  6. package/dist/api/WebSocketClient.d.ts +174 -0
  7. package/dist/api/WebSocketClient.js +277 -0
  8. package/dist/api/index.d.ts +6 -0
  9. package/dist/api/modules/index.d.ts +2 -0
  10. package/dist/api/modules/task.d.ts +124 -0
  11. package/dist/api/modules/task.js +121 -0
  12. package/dist/api/modules/user.d.ts +114 -0
  13. package/dist/api/modules/user.js +113 -0
  14. package/dist/config/index.d.ts +120 -0
  15. package/dist/config/index.js +112 -0
  16. package/dist/hooks/index.d.ts +1 -0
  17. package/dist/hooks/useAttributeMonitor.d.ts +45 -0
  18. package/dist/hooks/useAttributeMonitor.js +115 -0
  19. package/dist/index.d.ts +20 -0
  20. package/dist/index.js +93 -0
  21. package/dist/locale/de-DE.d.ts +18 -0
  22. package/dist/locale/de-DE.js +20 -0
  23. package/dist/locale/en-US.d.ts +18 -0
  24. package/dist/locale/en-US.js +20 -0
  25. package/dist/locale/es-ES.d.ts +18 -0
  26. package/dist/locale/es-ES.js +20 -0
  27. package/dist/locale/fr-FR.d.ts +18 -0
  28. package/dist/locale/fr-FR.js +20 -0
  29. package/dist/locale/id-ID.d.ts +18 -0
  30. package/dist/locale/id-ID.js +20 -0
  31. package/dist/locale/index.d.ts +19 -0
  32. package/dist/locale/index.js +70 -0
  33. package/dist/locale/ja-JP.d.ts +18 -0
  34. package/dist/locale/ja-JP.js +20 -0
  35. package/dist/locale/ko-KR.d.ts +18 -0
  36. package/dist/locale/ko-KR.js +20 -0
  37. package/dist/locale/pl-PL.d.ts +18 -0
  38. package/dist/locale/pl-PL.js +20 -0
  39. package/dist/locale/pt-BR.d.ts +18 -0
  40. package/dist/locale/pt-BR.js +20 -0
  41. package/dist/locale/ru-RU.d.ts +18 -0
  42. package/dist/locale/ru-RU.js +20 -0
  43. package/dist/locale/th-TH.d.ts +18 -0
  44. package/dist/locale/th-TH.js +20 -0
  45. package/dist/locale/zh-CN.d.ts +18 -0
  46. package/dist/locale/zh-CN.js +20 -0
  47. package/dist/locale/zh-TW.d.ts +18 -0
  48. package/dist/locale/zh-TW.js +20 -0
  49. package/dist/node_modules/@msgpack/msgpack/dist.esm/CachedKeyDecoder.js +38 -0
  50. package/dist/node_modules/@msgpack/msgpack/dist.esm/DecodeError.js +14 -0
  51. package/dist/node_modules/@msgpack/msgpack/dist.esm/Decoder.js +474 -0
  52. package/dist/node_modules/@msgpack/msgpack/dist.esm/Encoder.js +232 -0
  53. package/dist/node_modules/@msgpack/msgpack/dist.esm/ExtData.js +8 -0
  54. package/dist/node_modules/@msgpack/msgpack/dist.esm/ExtensionCodec.js +46 -0
  55. package/dist/node_modules/@msgpack/msgpack/dist.esm/decode.js +7 -0
  56. package/dist/node_modules/@msgpack/msgpack/dist.esm/encode.js +7 -0
  57. package/dist/node_modules/@msgpack/msgpack/dist.esm/timestamp.js +66 -0
  58. package/dist/node_modules/@msgpack/msgpack/dist.esm/utils/int.js +24 -0
  59. package/dist/node_modules/@msgpack/msgpack/dist.esm/utils/prettyByte.js +6 -0
  60. package/dist/node_modules/@msgpack/msgpack/dist.esm/utils/typedArrays.js +9 -0
  61. package/dist/node_modules/@msgpack/msgpack/dist.esm/utils/utf8.js +93 -0
  62. package/dist/node_modules/axios/index.js +38 -0
  63. package/dist/node_modules/axios/lib/adapters/adapters.js +55 -0
  64. package/dist/node_modules/axios/lib/adapters/fetch.js +169 -0
  65. package/dist/node_modules/axios/lib/adapters/xhr.js +72 -0
  66. package/dist/node_modules/axios/lib/axios.js +46 -0
  67. package/dist/node_modules/axios/lib/cancel/CancelToken.js +77 -0
  68. package/dist/node_modules/axios/lib/cancel/CanceledError.js +11 -0
  69. package/dist/node_modules/axios/lib/cancel/isCancel.js +6 -0
  70. package/dist/node_modules/axios/lib/core/Axios.js +136 -0
  71. package/dist/node_modules/axios/lib/core/AxiosError.js +56 -0
  72. package/dist/node_modules/axios/lib/core/AxiosHeaders.js +181 -0
  73. package/dist/node_modules/axios/lib/core/InterceptorManager.js +58 -0
  74. package/dist/node_modules/axios/lib/core/buildFullPath.js +9 -0
  75. package/dist/node_modules/axios/lib/core/dispatchRequest.js +31 -0
  76. package/dist/node_modules/axios/lib/core/mergeConfig.js +70 -0
  77. package/dist/node_modules/axios/lib/core/settle.js +14 -0
  78. package/dist/node_modules/axios/lib/core/transformData.js +13 -0
  79. package/dist/node_modules/axios/lib/defaults/index.js +89 -0
  80. package/dist/node_modules/axios/lib/defaults/transitional.js +8 -0
  81. package/dist/node_modules/axios/lib/env/data.js +4 -0
  82. package/dist/node_modules/axios/lib/helpers/AxiosURLSearchParams.js +33 -0
  83. package/dist/node_modules/axios/lib/helpers/HttpStatusCode.js +71 -0
  84. package/dist/node_modules/axios/lib/helpers/bind.js +8 -0
  85. package/dist/node_modules/axios/lib/helpers/buildURL.js +23 -0
  86. package/dist/node_modules/axios/lib/helpers/combineURLs.js +6 -0
  87. package/dist/node_modules/axios/lib/helpers/composeSignals.js +30 -0
  88. package/dist/node_modules/axios/lib/helpers/cookies.js +32 -0
  89. package/dist/node_modules/axios/lib/helpers/formDataToJSON.js +31 -0
  90. package/dist/node_modules/axios/lib/helpers/isAbsoluteURL.js +6 -0
  91. package/dist/node_modules/axios/lib/helpers/isAxiosError.js +7 -0
  92. package/dist/node_modules/axios/lib/helpers/isURLSameOrigin.js +8 -0
  93. package/dist/node_modules/axios/lib/helpers/null.js +4 -0
  94. package/dist/node_modules/axios/lib/helpers/parseHeaders.js +30 -0
  95. package/dist/node_modules/axios/lib/helpers/parseProtocol.js +7 -0
  96. package/dist/node_modules/axios/lib/helpers/progressEventReducer.js +35 -0
  97. package/dist/node_modules/axios/lib/helpers/resolveConfig.js +33 -0
  98. package/dist/node_modules/axios/lib/helpers/speedometer.js +19 -0
  99. package/dist/node_modules/axios/lib/helpers/spread.js +8 -0
  100. package/dist/node_modules/axios/lib/helpers/throttle.js +15 -0
  101. package/dist/node_modules/axios/lib/helpers/toFormData.js +85 -0
  102. package/dist/node_modules/axios/lib/helpers/toURLEncodedForm.js +14 -0
  103. package/dist/node_modules/axios/lib/helpers/trackStream.js +63 -0
  104. package/dist/node_modules/axios/lib/helpers/validator.js +54 -0
  105. package/dist/node_modules/axios/lib/platform/browser/classes/Blob.js +4 -0
  106. package/dist/node_modules/axios/lib/platform/browser/classes/FormData.js +4 -0
  107. package/dist/node_modules/axios/lib/platform/browser/classes/URLSearchParams.js +5 -0
  108. package/dist/node_modules/axios/lib/platform/browser/index.js +15 -0
  109. package/dist/node_modules/axios/lib/platform/common/utils.js +9 -0
  110. package/dist/node_modules/axios/lib/platform/index.js +9 -0
  111. package/dist/node_modules/axios/lib/utils.js +237 -0
  112. package/dist/node_modules/postcss-pxtorem/index.js +109 -0
  113. package/dist/node_modules/postcss-pxtorem/lib/filter-prop-list.js +13 -0
  114. package/dist/node_modules/postcss-pxtorem/lib/pixel-unit-regex.js +7 -0
  115. package/dist/node_modules/postcss-pxtorem/lib/type.js +14 -0
  116. package/dist/preload/index.d.ts +125 -0
  117. package/dist/preload/index.js +79 -0
  118. package/dist/store/index.d.ts +1 -0
  119. package/dist/store/storeFactory.d.ts +584 -0
  120. package/dist/store/storeFactory.js +216 -0
  121. package/dist/theme/index.d.ts +1 -0
  122. package/dist/theme/index.js +14 -0
  123. package/dist/types/index.d.ts +57 -0
  124. package/dist/types/uVerseAPI.d.ts +67 -0
  125. package/dist/utils/_internal.d.ts +14 -0
  126. package/dist/utils/_internal.js +72 -0
  127. package/dist/utils/constance.d.ts +16 -0
  128. package/dist/utils/constance.js +7 -0
  129. package/dist/utils/index.d.ts +79 -0
  130. package/dist/utils/index.js +96 -0
  131. package/dist/utils/logger.d.ts +118 -0
  132. package/dist/utils/logger.js +170 -0
  133. package/dist/utils/px2rem/remAdapter.d.ts +17 -0
  134. package/dist/utils/px2rem/remAdapter.js +62 -0
  135. package/dist/utils/px2rem/vite.d.ts +14 -0
  136. package/dist/utils/px2rem/vite.js +33 -0
  137. package/package.json +102 -4
@@ -0,0 +1,6 @@
1
+ function e(t) {
2
+ return t && t.__esModule && Object.prototype.hasOwnProperty.call(t, "default") ? t.default : t;
3
+ }
4
+ export {
5
+ e as getDefaultExportFromCjs
6
+ };
@@ -0,0 +1,4 @@
1
+ var o = { exports: {} };
2
+ export {
3
+ o as __module
4
+ };
@@ -0,0 +1,191 @@
1
+ import { AxiosInstance, AxiosRequestConfig } from 'axios';
2
+ import { App } from 'vue';
3
+ /**
4
+ * 请求元数据接口
5
+ */
6
+ export interface RequestMetadata {
7
+ suppressError?: boolean;
8
+ }
9
+ /**
10
+ * REST API 配置接口
11
+ */
12
+ export interface RestAPIConfig {
13
+ baseURL?: string;
14
+ timeout?: number;
15
+ apiVersion?: string;
16
+ workerId?: string;
17
+ headers?: Record<string, string>;
18
+ urlType?: 'path' | 'header';
19
+ }
20
+ /**
21
+ * 成功响应接口
22
+ */
23
+ export interface Response<T> {
24
+ status: 'success';
25
+ result: T;
26
+ timestamp: string | number;
27
+ }
28
+ /**
29
+ * 错误响应接口
30
+ */
31
+ export interface ErrorResponse<T> {
32
+ status: 'error';
33
+ code: string;
34
+ error_tpye: string;
35
+ message: string;
36
+ timestamp: string | number;
37
+ result?: T;
38
+ originError?: Error;
39
+ }
40
+ /**
41
+ * REST API 客户端类
42
+ * 提供了统一的 HTTP 请求封装,包括请求/响应拦截、错误处理、Token 管理等功能
43
+ */
44
+ export declare class RestAPIClient {
45
+ protected readonly appId: string;
46
+ protected readonly app: App | null;
47
+ protected readonly workerId: string;
48
+ protected readonly apiVersion: string;
49
+ protected readonly urlType: 'path' | 'header';
50
+ protected readonly pathPrefix: string;
51
+ protected readonly axiosInstance: AxiosInstance;
52
+ protected readonly requestInterceptor: number;
53
+ protected readonly responseInterceptor: number;
54
+ /**
55
+ * 构造函数 - 创建 REST API 客户端实例
56
+ * @param config - REST API 配置对象,包括 baseURL、timeout、headers 等
57
+ *
58
+ * @remarks
59
+ * 如果 config 和全局配置中都未指定 baseURL,则默认使用当前访问路径的 9898 端口。
60
+ * 例如:访问 `http://localhost:3000` 时,默认 baseURL 为 `http://localhost:9898`
61
+ */
62
+ constructor(config?: RestAPIConfig);
63
+ /**
64
+ * 设置请求头
65
+ * 根据 urlType 配置,在请求头中添加 API 版本和 Worker ID
66
+ * @param config - Axios 请求配置对象
67
+ * @private
68
+ */
69
+ private setHeader;
70
+ /**
71
+ * 统一处理请求错误
72
+ * 根据不同的错误类型和 HTTP 状态码,显示相应的错误提示信息,并返回统一的错误格式
73
+ * @param error - Axios 错误对象
74
+ * @param suppressError - 是否抑制错误提示,默认为 false
75
+ * @returns 返回符合 ErrorResponse 格式的错误对象
76
+ * @private
77
+ */
78
+ private handleError;
79
+ /**
80
+ * 发起通用 HTTP 请求
81
+ * @template T - 响应数据中 result 的类型
82
+ * @template D - 请求数据类型
83
+ * @param config - Axios 请求配置对象
84
+ * @returns 返回包含响应数据的 Promise 对象
85
+ */
86
+ request<T = any, D = any>(config: AxiosRequestConfig<D>): Promise<Response<T>>;
87
+ /**
88
+ * 发起 GET 请求
89
+ * @template T - 响应数据中 result 的类型
90
+ * @param url - 请求的 URL 地址
91
+ * @param config - 可选的 Axios 请求配置对象
92
+ * @returns 返回包含响应数据的 Promise 对象
93
+ */
94
+ get<T = any>(url: string, config?: AxiosRequestConfig): Promise<Response<T>>;
95
+ /**
96
+ * 发起 POST 请求
97
+ * @template T - 响应数据中 result 的类型
98
+ * @template D - 请求数据类型
99
+ * @param url - 请求的 URL 地址
100
+ * @param data - 可选的请求体数据
101
+ * @param config - 可选的 Axios 请求配置对象
102
+ * @returns 返回包含响应数据的 Promise 对象
103
+ */
104
+ post<T = any, D = any>(url: string, data?: D, config?: AxiosRequestConfig<D>): Promise<Response<T>>;
105
+ /**
106
+ * 发起 PUT 请求
107
+ * @template T - 响应数据中 result 的类型
108
+ * @template D - 请求数据类型
109
+ * @param url - 请求的 URL 地址
110
+ * @param data - 可选的请求体数据
111
+ * @param config - 可选的 Axios 请求配置对象
112
+ * @returns 返回包含响应数据的 Promise 对象
113
+ */
114
+ put<T = any, D = any>(url: string, data?: D, config?: AxiosRequestConfig<D>): Promise<Response<T>>;
115
+ /**
116
+ * 发起 DELETE 请求
117
+ * @template T - 响应数据中 result 的类型
118
+ * @param url - 请求的 URL 地址
119
+ * @param config - 可选的 Axios 请求配置对象
120
+ * @returns 返回包含响应数据的 Promise 对象
121
+ */
122
+ delete<T = any>(url: string, config?: AxiosRequestConfig): Promise<Response<T>>;
123
+ /**
124
+ * 获取 Axios 实例
125
+ * 返回内部的 Axios 实例,用于需要直接操作 Axios 的场景
126
+ * @returns 返回 Axios 实例对象
127
+ */
128
+ getAxiosInstance(): AxiosInstance;
129
+ /**
130
+ * 移除请求拦截器
131
+ * 移除在构造函数中注册的请求拦截器
132
+ */
133
+ removeRequestInterceptor(): void;
134
+ /**
135
+ * 移除响应拦截器
136
+ * 移除在构造函数中注册的响应拦截器
137
+ */
138
+ removeResponseInterceptor(): void;
139
+ /*********************************** 业务接口封装 **********************************/
140
+ /**
141
+ * 执行业务 Action 操作
142
+ * 向指定的 action 名称发送 POST 请求
143
+ * @template T - 响应数据中 result 的类型
144
+ * @template D - 请求数据类型
145
+ * @param actionName - Action 名称
146
+ * @param data - 可选的请求体数据
147
+ * @param config - 可选的 Axios 请求配置对象
148
+ * @returns 返回包含响应数据的 Promise 对象
149
+ */
150
+ action<T = any, D = any>(actionName: string, data?: D, config?: AxiosRequestConfig<D>): Promise<Response<T>>;
151
+ /**
152
+ * 获取所有属性
153
+ * 获取 Worker 的所有属性信息
154
+ * @template T - 响应数据中 result 的类型
155
+ * @returns 返回包含所有属性数据的 Promise 对象
156
+ * @deprecated 不建议使用此方法,请使用 action 方法替代
157
+ */
158
+ getAttributes<T = any>(): Promise<Response<T>>;
159
+ /**
160
+ * 获取单个属性
161
+ * 根据属性名称获取指定的属性值
162
+ * @template T - 响应数据中 result 的类型
163
+ * @param attributeName - 属性名称
164
+ * @returns 返回包含指定属性数据的 Promise 对象
165
+ * @deprecated 不建议使用此方法,请使用 action 方法替代
166
+ */
167
+ getAttribute<T = any>(attributeName: string): Promise<Response<T>>;
168
+ /**
169
+ * 批量设置属性
170
+ * 一次性设置多个属性值
171
+ * @template T - 响应数据中 result 的类型
172
+ * @template D - 请求数据类型
173
+ * @param data - 包含多个属性的数据对象
174
+ * @param config - 可选的 Axios 请求配置对象
175
+ * @returns 返回包含响应数据的 Promise 对象
176
+ * @deprecated 不建议使用此方法,请使用 action 方法替代
177
+ */
178
+ setAttributes<T = any, D = any>(data: D, config?: AxiosRequestConfig<D>): Promise<Response<T>>;
179
+ /**
180
+ * 设置单个属性
181
+ * 根据属性名称设置指定的属性值
182
+ * @template T - 响应数据中 result 的类型
183
+ * @template D - 请求数据类型
184
+ * @param attributeName - 属性名称
185
+ * @param data - 属性值数据
186
+ * @param config - 可选的 Axios 请求配置对象
187
+ * @returns 返回包含响应数据的 Promise 对象
188
+ * @deprecated 不建议使用此方法,请使用 action 方法替代
189
+ */
190
+ setAttribute<T = any, D = any>(attributeName: string, data: D, config?: AxiosRequestConfig<D>): Promise<Response<T>>;
191
+ }
@@ -0,0 +1,328 @@
1
+ import "../node_modules/axios/index.js";
2
+ import { encode as P } from "../node_modules/@msgpack/msgpack/dist.esm/encode.js";
3
+ import { decode as $ } from "../node_modules/@msgpack/msgpack/dist.esm/decode.js";
4
+ import { globalConfig as h, restConfig as k } from "../config/index.js";
5
+ import { getLocalStorage as w } from "../utils/index.js";
6
+ import { MessagePlugin as m } from "@openuverse/rdesign";
7
+ import { TOKEN_KEY as T } from "../utils/constance.js";
8
+ import g from "../node_modules/axios/lib/axios.js";
9
+ import { logger as p } from "../utils/logger.js";
10
+ class V {
11
+ /**
12
+ * 构造函数 - 创建 REST API 客户端实例
13
+ * @param config - REST API 配置对象,包括 baseURL、timeout、headers 等
14
+ *
15
+ * @remarks
16
+ * 如果 config 和全局配置中都未指定 baseURL,则默认使用当前访问路径的 9898 端口。
17
+ * 例如:访问 `http://localhost:3000` 时,默认 baseURL 为 `http://localhost:9898`
18
+ */
19
+ constructor(e) {
20
+ this.appId = h.getAppId(), this.app = h.getApp();
21
+ const a = k.getConfig();
22
+ this.apiVersion = (e == null ? void 0 : e.apiVersion) || a.apiVersion || "v1", this.workerId = (e == null ? void 0 : e.workerId) || a.workerId || this.appId, this.urlType = (e == null ? void 0 : e.urlType) || a.urlType || "header", this.pathPrefix = this.urlType === "path" ? `/${this.apiVersion}/workers/${this.workerId}` : "/workers";
23
+ const r = () => {
24
+ var o, i;
25
+ const t = (o = window.uVerseAPI) == null ? void 0 : o.serverConfig;
26
+ if (t) {
27
+ const n = t.protocol || "http", d = t.hostname || "localhost", l = t.port || 9898;
28
+ return `${n}://${d}:${l}`;
29
+ }
30
+ const s = (i = window.location) == null ? void 0 : i.hostname;
31
+ return s && s !== "" && s !== "localhost" ? `${window.location.protocol}//${s}:9898` : "http://localhost:9898";
32
+ }, u = (e == null ? void 0 : e.baseURL) || a.baseURL || r();
33
+ this.axiosInstance = g.create({
34
+ baseURL: u,
35
+ timeout: (e == null ? void 0 : e.timeout) || a.timeout,
36
+ responseType: "arraybuffer",
37
+ headers: {
38
+ "Content-Type": "application/octet-stream",
39
+ Accept: "application/octet-stream",
40
+ ...a.headers || {},
41
+ ...(e == null ? void 0 : e.headers) || {}
42
+ }
43
+ }), p.debug(
44
+ `[uv-api] RestAPIClient 创建: workerId=${this.workerId}, baseURL=${u}, urlType=${this.urlType}`
45
+ ), this.requestInterceptor = this.axiosInstance.interceptors.request.use(
46
+ (t) => {
47
+ var s;
48
+ try {
49
+ const o = w(T), i = o ? JSON.parse(o) : null, n = (i == null ? void 0 : i.token) || "Bearer your-token";
50
+ t.headers.Authorization = n;
51
+ } catch (o) {
52
+ p.debug("[uv-api] 解析用户信息失败:", o), t.headers.Authorization = "Bearer your-token";
53
+ }
54
+ this.setHeader(t);
55
+ try {
56
+ p.debug(`[uv-api] API请求: ${(s = t.method) == null ? void 0 : s.toUpperCase()} ${t.url}`), p.debug("[uv-api] API请求数据:", t.data);
57
+ const o = P(t.data || {});
58
+ t.data = o;
59
+ } catch (o) {
60
+ p.debug("[uv-api] 请求参数编码失败:", o);
61
+ const i = o instanceof Error ? o : new Error(String(o));
62
+ return Promise.reject(i);
63
+ }
64
+ return t;
65
+ },
66
+ (t) => {
67
+ p.debug("[uv-api] 请求拦截器错误:", t);
68
+ const s = t instanceof Error ? t : new Error(String(t));
69
+ return Promise.reject(s);
70
+ }
71
+ ), this.responseInterceptor = this.axiosInstance.interceptors.response.use(
72
+ async (t) => {
73
+ var o, i, n, d, l, _, E, b, I, R;
74
+ p.debug(`[uv-api] API响应: ${t.status} ${t.config.url}`);
75
+ let s = t.data;
76
+ try {
77
+ s = $(s), p.debug("[uv-api] MessagePack响应数据解码成功", s);
78
+ } catch (c) {
79
+ p.debug("[uv-api] MessagePack响应数据解码失败:", c);
80
+ const v = (o = t.config.metadata) == null ? void 0 : o.suppressError, A = ((d = (i = this.app) == null ? void 0 : (n = i.config.globalProperties).$t) == null ? void 0 : d.call(n, "uverse_uv_api.decode_error")) || "MessagePack decode failed";
81
+ v || m.error(A, void 0, (l = h.getApp()) == null ? void 0 : l._context);
82
+ const y = {
83
+ status: "error",
84
+ code: "MESSAGEPACK_DECODE_ERROR",
85
+ error_tpye: "DECODE",
86
+ message: A,
87
+ timestamp: Date.now(),
88
+ originError: c instanceof Error ? c : new Error(String(c))
89
+ };
90
+ return Promise.reject(y);
91
+ }
92
+ if (s && typeof s == "object" && "status" in s) {
93
+ if (s.status === "success")
94
+ return s;
95
+ if (s.status !== "success") {
96
+ const c = s, v = (_ = t.config.metadata) == null ? void 0 : _.suppressError;
97
+ return p.debug(
98
+ `[uv-api] 业务错误: ${t.config.url} [${c.code}] ${c.message}`
99
+ ), v || m.error(
100
+ c.message || ((I = (E = this.app) == null ? void 0 : (b = E.config.globalProperties).$t) == null ? void 0 : I.call(b, "uverse_uv_api.request_failed")) || "Request failed",
101
+ void 0,
102
+ (R = h.getApp()) == null ? void 0 : R._context
103
+ ), Promise.reject(c);
104
+ }
105
+ }
106
+ return s;
107
+ },
108
+ (t) => {
109
+ var o, i;
110
+ if (t && typeof t == "object" && t.status !== "success")
111
+ return Promise.reject(t);
112
+ const s = (i = (o = t == null ? void 0 : t.config) == null ? void 0 : o.metadata) == null ? void 0 : i.suppressError;
113
+ return Promise.reject(this.handleError(t, s));
114
+ }
115
+ );
116
+ }
117
+ /**
118
+ * 设置请求头
119
+ * 根据 urlType 配置,在请求头中添加 API 版本和 Worker ID
120
+ * @param config - Axios 请求配置对象
121
+ * @private
122
+ */
123
+ setHeader(e) {
124
+ var a;
125
+ this.urlType === "header" && (e.headers || (e.headers = {}), e.headers["X-UV-API-Version"] = this.apiVersion, e.headers["X-UV-Worker-ID"] = this.workerId), (a = e.headers) != null && a["X-UV-Action-Timeout"] && (e.timeout = Number(e.headers["X-UV-Action-Timeout"]) + 2e3);
126
+ }
127
+ /**
128
+ * 统一处理请求错误
129
+ * 根据不同的错误类型和 HTTP 状态码,显示相应的错误提示信息,并返回统一的错误格式
130
+ * @param error - Axios 错误对象
131
+ * @param suppressError - 是否抑制错误提示,默认为 false
132
+ * @returns 返回符合 ErrorResponse 格式的错误对象
133
+ * @private
134
+ */
135
+ handleError(e, a = !1) {
136
+ var o, i, n, d, l;
137
+ p.debug(`[uv-api] API请求失败: ${(o = e.config) == null ? void 0 : o.url}`, e);
138
+ const r = (i = this.app) == null ? void 0 : i.config.globalProperties.$t;
139
+ let u = "UNKNOWN_ERROR", t = (r == null ? void 0 : r("uverse_uv_api.unknown_error")) ?? "Unknown error", s = "UNKNOWN";
140
+ if (g.isCancel(e))
141
+ u = "REQUEST_CANCELLED", t = "", s = "CANCELLED";
142
+ else if (!e.response)
143
+ s = "NETWORK", e.code === "ECONNABORTED" ? (u = "REQUEST_TIMEOUT", t = (r == null ? void 0 : r("uverse_uv_api.request_timeout")) ?? "Request timeout") : (u = "NETWORK_ERROR", t = (r == null ? void 0 : r("uverse_uv_api.network_error")) ?? "Network error"), a || m.error(t, void 0, (n = h.getApp()) == null ? void 0 : n._context);
144
+ else {
145
+ s = "HTTP";
146
+ const { status: _ } = e.response;
147
+ switch (_) {
148
+ case 401:
149
+ u = "UNAUTHORIZED", t = (r == null ? void 0 : r("uverse_uv_api.login_expired")) ?? "Login expired, please login again", localStorage.removeItem(T), p.debug(`[uv-api] 收到 401,TOKEN 已清除,触发接口: ${(d = e.config) == null ? void 0 : d.url}`);
150
+ break;
151
+ case 403:
152
+ u = "FORBIDDEN", t = (r == null ? void 0 : r("uverse_uv_api.permission_denied")) ?? "Permission denied, cannot access this resource";
153
+ break;
154
+ case 404:
155
+ u = "NOT_FOUND", t = (r == null ? void 0 : r("uverse_uv_api.resource_not_found")) ?? "Resource not found";
156
+ break;
157
+ case 429:
158
+ u = "TOO_MANY_REQUESTS", t = (r == null ? void 0 : r("uverse_uv_api.too_many_requests")) ?? "Request too frequent, please try again later";
159
+ break;
160
+ case 500:
161
+ u = "INTERNAL_SERVER_ERROR", t = (r == null ? void 0 : r("uverse_uv_api.server_error")) ?? "Server error, please try again later";
162
+ break;
163
+ case 502:
164
+ u = "BAD_GATEWAY", t = (r == null ? void 0 : r("uverse_uv_api.gateway_error")) ?? "Gateway error, please try again later";
165
+ break;
166
+ case 503:
167
+ u = "SERVICE_UNAVAILABLE", t = (r == null ? void 0 : r("uverse_uv_api.service_unavailable")) ?? "Service temporarily unavailable, please try again later";
168
+ break;
169
+ case 504:
170
+ u = "GATEWAY_TIMEOUT", t = (r == null ? void 0 : r("uverse_uv_api.gateway_timeout")) ?? "Gateway timeout, please try again later";
171
+ break;
172
+ default:
173
+ u = `HTTP_${_}`, t = (e.response.statusText || (r == null ? void 0 : r("uverse_uv_api.request_failed"))) ?? "Request failed";
174
+ break;
175
+ }
176
+ t && !a && m.error(t, void 0, (l = h.getApp()) == null ? void 0 : l._context);
177
+ }
178
+ return {
179
+ status: "error",
180
+ code: u,
181
+ error_tpye: s,
182
+ message: t,
183
+ timestamp: Date.now(),
184
+ originError: e
185
+ };
186
+ }
187
+ /**
188
+ * 发起通用 HTTP 请求
189
+ * @template T - 响应数据中 result 的类型
190
+ * @template D - 请求数据类型
191
+ * @param config - Axios 请求配置对象
192
+ * @returns 返回包含响应数据的 Promise 对象
193
+ */
194
+ request(e) {
195
+ return this.axiosInstance.request(e);
196
+ }
197
+ /**
198
+ * 发起 GET 请求
199
+ * @template T - 响应数据中 result 的类型
200
+ * @param url - 请求的 URL 地址
201
+ * @param config - 可选的 Axios 请求配置对象
202
+ * @returns 返回包含响应数据的 Promise 对象
203
+ */
204
+ get(e, a) {
205
+ return this.axiosInstance.get(e, a);
206
+ }
207
+ /**
208
+ * 发起 POST 请求
209
+ * @template T - 响应数据中 result 的类型
210
+ * @template D - 请求数据类型
211
+ * @param url - 请求的 URL 地址
212
+ * @param data - 可选的请求体数据
213
+ * @param config - 可选的 Axios 请求配置对象
214
+ * @returns 返回包含响应数据的 Promise 对象
215
+ */
216
+ async post(e, a, r) {
217
+ return this.axiosInstance.post(e, a, r);
218
+ }
219
+ /**
220
+ * 发起 PUT 请求
221
+ * @template T - 响应数据中 result 的类型
222
+ * @template D - 请求数据类型
223
+ * @param url - 请求的 URL 地址
224
+ * @param data - 可选的请求体数据
225
+ * @param config - 可选的 Axios 请求配置对象
226
+ * @returns 返回包含响应数据的 Promise 对象
227
+ */
228
+ put(e, a, r) {
229
+ return this.axiosInstance.put(e, a, r);
230
+ }
231
+ /**
232
+ * 发起 DELETE 请求
233
+ * @template T - 响应数据中 result 的类型
234
+ * @param url - 请求的 URL 地址
235
+ * @param config - 可选的 Axios 请求配置对象
236
+ * @returns 返回包含响应数据的 Promise 对象
237
+ */
238
+ delete(e, a) {
239
+ return this.axiosInstance.delete(e, a);
240
+ }
241
+ /**
242
+ * 获取 Axios 实例
243
+ * 返回内部的 Axios 实例,用于需要直接操作 Axios 的场景
244
+ * @returns 返回 Axios 实例对象
245
+ */
246
+ getAxiosInstance() {
247
+ return this.axiosInstance;
248
+ }
249
+ /**
250
+ * 移除请求拦截器
251
+ * 移除在构造函数中注册的请求拦截器
252
+ */
253
+ removeRequestInterceptor() {
254
+ this.axiosInstance.interceptors.request.eject(this.requestInterceptor);
255
+ }
256
+ /**
257
+ * 移除响应拦截器
258
+ * 移除在构造函数中注册的响应拦截器
259
+ */
260
+ removeResponseInterceptor() {
261
+ this.axiosInstance.interceptors.response.eject(this.responseInterceptor);
262
+ }
263
+ /*********************************** 业务接口封装 **********************************/
264
+ /**
265
+ * 执行业务 Action 操作
266
+ * 向指定的 action 名称发送 POST 请求
267
+ * @template T - 响应数据中 result 的类型
268
+ * @template D - 请求数据类型
269
+ * @param actionName - Action 名称
270
+ * @param data - 可选的请求体数据
271
+ * @param config - 可选的 Axios 请求配置对象
272
+ * @returns 返回包含响应数据的 Promise 对象
273
+ */
274
+ action(e, a, r) {
275
+ return this.post(`${this.pathPrefix}/${e}`, a, r);
276
+ }
277
+ /**
278
+ * 获取所有属性
279
+ * 获取 Worker 的所有属性信息
280
+ * @template T - 响应数据中 result 的类型
281
+ * @returns 返回包含所有属性数据的 Promise 对象
282
+ * @deprecated 不建议使用此方法,请使用 action 方法替代
283
+ */
284
+ getAttributes() {
285
+ return this.post(`${this.pathPrefix}/attributes`);
286
+ }
287
+ /**
288
+ * 获取单个属性
289
+ * 根据属性名称获取指定的属性值
290
+ * @template T - 响应数据中 result 的类型
291
+ * @param attributeName - 属性名称
292
+ * @returns 返回包含指定属性数据的 Promise 对象
293
+ * @deprecated 不建议使用此方法,请使用 action 方法替代
294
+ */
295
+ getAttribute(e) {
296
+ return this.post(`${this.pathPrefix}/attributes/${e}`);
297
+ }
298
+ /**
299
+ * 批量设置属性
300
+ * 一次性设置多个属性值
301
+ * @template T - 响应数据中 result 的类型
302
+ * @template D - 请求数据类型
303
+ * @param data - 包含多个属性的数据对象
304
+ * @param config - 可选的 Axios 请求配置对象
305
+ * @returns 返回包含响应数据的 Promise 对象
306
+ * @deprecated 不建议使用此方法,请使用 action 方法替代
307
+ */
308
+ setAttributes(e, a) {
309
+ return this.post(`${this.pathPrefix}/attributes`, e, a);
310
+ }
311
+ /**
312
+ * 设置单个属性
313
+ * 根据属性名称设置指定的属性值
314
+ * @template T - 响应数据中 result 的类型
315
+ * @template D - 请求数据类型
316
+ * @param attributeName - 属性名称
317
+ * @param data - 属性值数据
318
+ * @param config - 可选的 Axios 请求配置对象
319
+ * @returns 返回包含响应数据的 Promise 对象
320
+ * @deprecated 不建议使用此方法,请使用 action 方法替代
321
+ */
322
+ setAttribute(e, a, r) {
323
+ return this.post(`${this.pathPrefix}/attributes/${e}`, a, r);
324
+ }
325
+ }
326
+ export {
327
+ V as RestAPIClient
328
+ };