@honor-claw/yoyo 1.1.2 → 1.1.4-beta.1
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/index.ts +25 -25
- package/package.json +5 -5
- package/src/apis/claw-cloud.ts +124 -124
- package/src/apis/helpers.ts +10 -10
- package/src/apis/honor-auth.ts +158 -158
- package/src/apis/http-client.ts +239 -239
- package/src/apis/index.ts +8 -8
- package/src/apis/types.ts +77 -73
- package/src/cloud-channel/channel.ts +117 -117
- package/src/cloud-channel/client.ts +3 -3
- package/src/cloud-channel/index.ts +4 -4
- package/src/cloud-channel/message-handler.ts +50 -42
- package/src/cloud-channel/session-manager.ts +14 -9
- package/src/cloud-channel/types.ts +115 -115
- package/src/commands/env/impl.ts +58 -58
- package/src/commands/env/index.ts +1 -1
- package/src/commands/index.ts +30 -30
- package/src/commands/login/impl.ts +30 -30
- package/src/commands/login/index.ts +1 -1
- package/src/commands/logout/index.ts +1 -1
- package/src/commands/status/index.ts +194 -194
- package/src/gateway-client/client.ts +90 -90
- package/src/gateway-client/device/auth.ts +57 -57
- package/src/gateway-client/device/builder.ts +105 -105
- package/src/gateway-client/device/helpers.ts +40 -40
- package/src/gateway-client/device/identity.ts +251 -251
- package/src/gateway-client/device/index.ts +40 -40
- package/src/gateway-client/device/types.ts +57 -57
- package/src/gateway-client/index.ts +5 -5
- package/src/gateway-client/protocol-client.ts +49 -34
- package/src/honor-auth/browser.ts +2 -2
- package/src/honor-auth/callback-server.ts +109 -109
- package/src/honor-auth/cloud.ts +57 -57
- package/src/honor-auth/config.ts +43 -43
- package/src/honor-auth/index.ts +3 -3
- package/src/honor-auth/token-manager.ts +90 -90
- package/src/honor-auth/types.ts +50 -50
- package/src/index.ts +10 -10
- package/src/modules/claw-configs/config-manager.ts +409 -409
- package/src/modules/claw-configs/hosts.ts +48 -48
- package/src/modules/claw-configs/index.ts +8 -8
- package/src/modules/claw-configs/provider.ts +394 -394
- package/src/modules/claw-configs/types.ts +34 -34
- package/src/modules/device/device-info.ts +1 -1
- package/src/modules/device/index.ts +3 -3
- package/src/modules/device/providers/base.ts +32 -32
- package/src/modules/device/providers/pad.ts +107 -107
- package/src/modules/device/providers/windows.ts +130 -130
- package/src/modules/device/registry.ts +48 -43
- package/src/modules/login/impl.ts +31 -26
- package/src/modules/login/index.ts +6 -6
- package/src/schemas.ts +23 -23
- package/src/services/connection/impl.ts +339 -339
- package/src/services/connection/status-tracker/events.ts +127 -127
- package/src/services/connection/status-tracker/index.ts +31 -31
- package/src/services/connection/status-tracker/storage.ts +133 -133
- package/src/services/connection/status-tracker/tracker.ts +370 -370
- package/src/services/connection/status-tracker/types.ts +131 -131
- package/src/services/connection/types.ts +20 -20
- package/src/types.ts +64 -64
- package/src/utils/id.ts +8 -8
- package/src/utils/jwt.ts +37 -37
- package/src/utils/logger.ts +20 -20
- package/src/utils/proxy.ts +58 -58
- package/src/utils/version.ts +29 -29
- package/src/utils/ws.ts +21 -21
package/src/apis/http-client.ts
CHANGED
|
@@ -1,239 +1,239 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* HTTP 请求客户端封装
|
|
3
|
-
* 基于 undici 实现
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { request, type Dispatcher, ProxyAgent } from "undici";
|
|
7
|
-
import { getProxyUrl, shouldUseProxy } from "../utils/proxy.js";
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* HTTP 客户端配置
|
|
11
|
-
*/
|
|
12
|
-
export interface HttpClientOptions {
|
|
13
|
-
defaultHeaders?: Record<string, string>;
|
|
14
|
-
defaultTimeout?: number;
|
|
15
|
-
/**
|
|
16
|
-
* 代理地址,例如:http://127.0.0.1:7890
|
|
17
|
-
* 如果不设置,则使用环境变量 HTTP_PROXY 或 HTTPS_PROXY
|
|
18
|
-
*/
|
|
19
|
-
proxy?: string;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* HTTP 请求配置
|
|
24
|
-
*/
|
|
25
|
-
export interface HttpRequestConfig {
|
|
26
|
-
url: string;
|
|
27
|
-
method?: "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
|
|
28
|
-
headers?: Record<string, string>;
|
|
29
|
-
body?: string | object | null;
|
|
30
|
-
timeout?: number;
|
|
31
|
-
query?: Record<string, string | number | boolean | undefined>;
|
|
32
|
-
/**
|
|
33
|
-
* 是否禁用代理(默认 false)
|
|
34
|
-
*/
|
|
35
|
-
disableProxy?: boolean;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* HTTP 响应
|
|
40
|
-
*/
|
|
41
|
-
export interface HttpResponse<T = unknown> {
|
|
42
|
-
data: T;
|
|
43
|
-
status: number;
|
|
44
|
-
headers: Record<string, string | string[] | undefined>;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* HTTP 错误
|
|
49
|
-
*/
|
|
50
|
-
export class HttpError extends Error {
|
|
51
|
-
constructor(public status: number, public data: unknown, message: string) {
|
|
52
|
-
super(message);
|
|
53
|
-
this.name = "HttpError";
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* HTTP 客户端类
|
|
59
|
-
*/
|
|
60
|
-
export class HttpClient {
|
|
61
|
-
private baseUrl: string;
|
|
62
|
-
private defaultHeaders: Record<string, string>;
|
|
63
|
-
private defaultTimeout: number;
|
|
64
|
-
private proxyAgent?: ProxyAgent;
|
|
65
|
-
|
|
66
|
-
constructor(baseUrl: string, options?: HttpClientOptions) {
|
|
67
|
-
this.baseUrl = baseUrl.replace(/\/$/, "");
|
|
68
|
-
this.defaultHeaders = options?.defaultHeaders || {};
|
|
69
|
-
this.defaultTimeout = options?.defaultTimeout || 30000;
|
|
70
|
-
|
|
71
|
-
// 初始化代理 agent,使用统一的代理配置获取逻辑
|
|
72
|
-
const proxyUrl = getProxyUrl(options?.proxy);
|
|
73
|
-
|
|
74
|
-
if (proxyUrl) {
|
|
75
|
-
this.proxyAgent = new ProxyAgent(proxyUrl);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* 执行 HTTP 请求
|
|
81
|
-
*/
|
|
82
|
-
async request<T = unknown>(
|
|
83
|
-
config: HttpRequestConfig
|
|
84
|
-
): Promise<HttpResponse<T>> {
|
|
85
|
-
const {
|
|
86
|
-
method = "GET",
|
|
87
|
-
headers = {},
|
|
88
|
-
body,
|
|
89
|
-
timeout = this.defaultTimeout,
|
|
90
|
-
query,
|
|
91
|
-
} = config;
|
|
92
|
-
|
|
93
|
-
// 构建 URL
|
|
94
|
-
let url = config.url;
|
|
95
|
-
if (!url.startsWith("http://") && !url.startsWith("https://")) {
|
|
96
|
-
url = `${this.baseUrl}${url.startsWith("/") ? "" : "/"}${url}`;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
// 添加查询参数
|
|
100
|
-
if (query && Object.keys(query).length > 0) {
|
|
101
|
-
const params = new URLSearchParams();
|
|
102
|
-
Object.entries(query).forEach(([key, value]) => {
|
|
103
|
-
if (value !== undefined) {
|
|
104
|
-
params.append(key, String(value));
|
|
105
|
-
}
|
|
106
|
-
});
|
|
107
|
-
const queryString = params.toString();
|
|
108
|
-
if (queryString) {
|
|
109
|
-
url += (url.includes("?") ? "&" : "?") + queryString;
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
// 合并请求头
|
|
114
|
-
const mergedHeaders: Record<string, string> = {
|
|
115
|
-
...this.defaultHeaders,
|
|
116
|
-
...headers,
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
// 设置 Content-Type
|
|
120
|
-
if (body && !mergedHeaders["Content-Type"]) {
|
|
121
|
-
mergedHeaders["Content-Type"] = "application/json";
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
// 准备请求体
|
|
125
|
-
let requestBody: string | undefined;
|
|
126
|
-
if (body !== null && body !== undefined) {
|
|
127
|
-
if (typeof body === "string") {
|
|
128
|
-
requestBody = body;
|
|
129
|
-
} else {
|
|
130
|
-
requestBody = JSON.stringify(body);
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
try {
|
|
135
|
-
const dispatcher: Dispatcher = shouldUseProxy(
|
|
136
|
-
getProxyUrl(),
|
|
137
|
-
config.disableProxy
|
|
138
|
-
) && this.proxyAgent
|
|
139
|
-
? this.proxyAgent
|
|
140
|
-
: undefined;
|
|
141
|
-
|
|
142
|
-
const response = await request(url, {
|
|
143
|
-
method,
|
|
144
|
-
headers: mergedHeaders as HeadersInit,
|
|
145
|
-
body: requestBody,
|
|
146
|
-
headersTimeout: timeout,
|
|
147
|
-
bodyTimeout: timeout,
|
|
148
|
-
dispatcher,
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
// 读取响应体
|
|
152
|
-
const responseBody = await response.body.text();
|
|
153
|
-
let data: T;
|
|
154
|
-
|
|
155
|
-
try {
|
|
156
|
-
data = responseBody ? JSON.parse(responseBody) : ({} as T);
|
|
157
|
-
} catch {
|
|
158
|
-
data = responseBody as unknown as T;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
// 检查响应状态
|
|
162
|
-
if (response.statusCode >= 200 && response.statusCode < 300) {
|
|
163
|
-
return {
|
|
164
|
-
data,
|
|
165
|
-
status: response.statusCode,
|
|
166
|
-
headers: response.headers as Record<
|
|
167
|
-
string,
|
|
168
|
-
string | string[] | undefined
|
|
169
|
-
>,
|
|
170
|
-
};
|
|
171
|
-
} else {
|
|
172
|
-
throw new HttpError(
|
|
173
|
-
response.statusCode,
|
|
174
|
-
data,
|
|
175
|
-
`HTTP request failed with status ${response.statusCode}`
|
|
176
|
-
);
|
|
177
|
-
}
|
|
178
|
-
} catch (error) {
|
|
179
|
-
if (error instanceof HttpError) {
|
|
180
|
-
throw error;
|
|
181
|
-
}
|
|
182
|
-
throw new Error(
|
|
183
|
-
`HTTP request failed: ${
|
|
184
|
-
error instanceof Error ? error.message : String(error)
|
|
185
|
-
}`
|
|
186
|
-
);
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
/**
|
|
191
|
-
* GET 请求
|
|
192
|
-
*/
|
|
193
|
-
async get<T = unknown>(
|
|
194
|
-
url: string,
|
|
195
|
-
config?: Omit<HttpRequestConfig, "url" | "method">
|
|
196
|
-
): Promise<HttpResponse<T>> {
|
|
197
|
-
return this.request<T>({ ...config, url, method: "GET" });
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
/**
|
|
201
|
-
* POST 请求
|
|
202
|
-
*/
|
|
203
|
-
async post<T = unknown>(
|
|
204
|
-
url: string,
|
|
205
|
-
config?: Omit<HttpRequestConfig, "url" | "method">
|
|
206
|
-
): Promise<HttpResponse<T>> {
|
|
207
|
-
return this.request<T>({ ...config, url, method: "POST" });
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
/**
|
|
211
|
-
* PUT 请求
|
|
212
|
-
*/
|
|
213
|
-
async put<T = unknown>(
|
|
214
|
-
url: string,
|
|
215
|
-
config?: Omit<HttpRequestConfig, "url" | "method">
|
|
216
|
-
): Promise<HttpResponse<T>> {
|
|
217
|
-
return this.request<T>({ ...config, url, method: "PUT" });
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
/**
|
|
221
|
-
* DELETE 请求
|
|
222
|
-
*/
|
|
223
|
-
async delete<T = unknown>(
|
|
224
|
-
url: string,
|
|
225
|
-
config?: Omit<HttpRequestConfig, "url" | "method">
|
|
226
|
-
): Promise<HttpResponse<T>> {
|
|
227
|
-
return this.request<T>({ ...config, url, method: "DELETE" });
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
/**
|
|
231
|
-
* PATCH 请求
|
|
232
|
-
*/
|
|
233
|
-
async patch<T = unknown>(
|
|
234
|
-
url: string,
|
|
235
|
-
config?: Omit<HttpRequestConfig, "url" | "method">
|
|
236
|
-
): Promise<HttpResponse<T>> {
|
|
237
|
-
return this.request<T>({ ...config, url, method: "PATCH" });
|
|
238
|
-
}
|
|
239
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* HTTP 请求客户端封装
|
|
3
|
+
* 基于 undici 实现
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { request, type Dispatcher, ProxyAgent } from "undici";
|
|
7
|
+
import { getProxyUrl, shouldUseProxy } from "../utils/proxy.js";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* HTTP 客户端配置
|
|
11
|
+
*/
|
|
12
|
+
export interface HttpClientOptions {
|
|
13
|
+
defaultHeaders?: Record<string, string>;
|
|
14
|
+
defaultTimeout?: number;
|
|
15
|
+
/**
|
|
16
|
+
* 代理地址,例如:http://127.0.0.1:7890
|
|
17
|
+
* 如果不设置,则使用环境变量 HTTP_PROXY 或 HTTPS_PROXY
|
|
18
|
+
*/
|
|
19
|
+
proxy?: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* HTTP 请求配置
|
|
24
|
+
*/
|
|
25
|
+
export interface HttpRequestConfig {
|
|
26
|
+
url: string;
|
|
27
|
+
method?: "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
|
|
28
|
+
headers?: Record<string, string>;
|
|
29
|
+
body?: string | object | null;
|
|
30
|
+
timeout?: number;
|
|
31
|
+
query?: Record<string, string | number | boolean | undefined>;
|
|
32
|
+
/**
|
|
33
|
+
* 是否禁用代理(默认 false)
|
|
34
|
+
*/
|
|
35
|
+
disableProxy?: boolean;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* HTTP 响应
|
|
40
|
+
*/
|
|
41
|
+
export interface HttpResponse<T = unknown> {
|
|
42
|
+
data: T;
|
|
43
|
+
status: number;
|
|
44
|
+
headers: Record<string, string | string[] | undefined>;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* HTTP 错误
|
|
49
|
+
*/
|
|
50
|
+
export class HttpError extends Error {
|
|
51
|
+
constructor(public status: number, public data: unknown, message: string) {
|
|
52
|
+
super(message);
|
|
53
|
+
this.name = "HttpError";
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* HTTP 客户端类
|
|
59
|
+
*/
|
|
60
|
+
export class HttpClient {
|
|
61
|
+
private baseUrl: string;
|
|
62
|
+
private defaultHeaders: Record<string, string>;
|
|
63
|
+
private defaultTimeout: number;
|
|
64
|
+
private proxyAgent?: ProxyAgent;
|
|
65
|
+
|
|
66
|
+
constructor(baseUrl: string, options?: HttpClientOptions) {
|
|
67
|
+
this.baseUrl = baseUrl.replace(/\/$/, "");
|
|
68
|
+
this.defaultHeaders = options?.defaultHeaders || {};
|
|
69
|
+
this.defaultTimeout = options?.defaultTimeout || 30000;
|
|
70
|
+
|
|
71
|
+
// 初始化代理 agent,使用统一的代理配置获取逻辑
|
|
72
|
+
const proxyUrl = getProxyUrl(options?.proxy);
|
|
73
|
+
|
|
74
|
+
if (proxyUrl) {
|
|
75
|
+
this.proxyAgent = new ProxyAgent(proxyUrl);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* 执行 HTTP 请求
|
|
81
|
+
*/
|
|
82
|
+
async request<T = unknown>(
|
|
83
|
+
config: HttpRequestConfig
|
|
84
|
+
): Promise<HttpResponse<T>> {
|
|
85
|
+
const {
|
|
86
|
+
method = "GET",
|
|
87
|
+
headers = {},
|
|
88
|
+
body,
|
|
89
|
+
timeout = this.defaultTimeout,
|
|
90
|
+
query,
|
|
91
|
+
} = config;
|
|
92
|
+
|
|
93
|
+
// 构建 URL
|
|
94
|
+
let url = config.url;
|
|
95
|
+
if (!url.startsWith("http://") && !url.startsWith("https://")) {
|
|
96
|
+
url = `${this.baseUrl}${url.startsWith("/") ? "" : "/"}${url}`;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// 添加查询参数
|
|
100
|
+
if (query && Object.keys(query).length > 0) {
|
|
101
|
+
const params = new URLSearchParams();
|
|
102
|
+
Object.entries(query).forEach(([key, value]) => {
|
|
103
|
+
if (value !== undefined) {
|
|
104
|
+
params.append(key, String(value));
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
const queryString = params.toString();
|
|
108
|
+
if (queryString) {
|
|
109
|
+
url += (url.includes("?") ? "&" : "?") + queryString;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// 合并请求头
|
|
114
|
+
const mergedHeaders: Record<string, string> = {
|
|
115
|
+
...this.defaultHeaders,
|
|
116
|
+
...headers,
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
// 设置 Content-Type
|
|
120
|
+
if (body && !mergedHeaders["Content-Type"]) {
|
|
121
|
+
mergedHeaders["Content-Type"] = "application/json";
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// 准备请求体
|
|
125
|
+
let requestBody: string | undefined;
|
|
126
|
+
if (body !== null && body !== undefined) {
|
|
127
|
+
if (typeof body === "string") {
|
|
128
|
+
requestBody = body;
|
|
129
|
+
} else {
|
|
130
|
+
requestBody = JSON.stringify(body);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
try {
|
|
135
|
+
const dispatcher: Dispatcher = shouldUseProxy(
|
|
136
|
+
getProxyUrl(),
|
|
137
|
+
config.disableProxy
|
|
138
|
+
) && this.proxyAgent
|
|
139
|
+
? this.proxyAgent
|
|
140
|
+
: undefined;
|
|
141
|
+
|
|
142
|
+
const response = await request(url, {
|
|
143
|
+
method,
|
|
144
|
+
headers: mergedHeaders as HeadersInit,
|
|
145
|
+
body: requestBody,
|
|
146
|
+
headersTimeout: timeout,
|
|
147
|
+
bodyTimeout: timeout,
|
|
148
|
+
dispatcher,
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
// 读取响应体
|
|
152
|
+
const responseBody = await response.body.text();
|
|
153
|
+
let data: T;
|
|
154
|
+
|
|
155
|
+
try {
|
|
156
|
+
data = responseBody ? JSON.parse(responseBody) : ({} as T);
|
|
157
|
+
} catch {
|
|
158
|
+
data = responseBody as unknown as T;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// 检查响应状态
|
|
162
|
+
if (response.statusCode >= 200 && response.statusCode < 300) {
|
|
163
|
+
return {
|
|
164
|
+
data,
|
|
165
|
+
status: response.statusCode,
|
|
166
|
+
headers: response.headers as Record<
|
|
167
|
+
string,
|
|
168
|
+
string | string[] | undefined
|
|
169
|
+
>,
|
|
170
|
+
};
|
|
171
|
+
} else {
|
|
172
|
+
throw new HttpError(
|
|
173
|
+
response.statusCode,
|
|
174
|
+
data,
|
|
175
|
+
`HTTP request failed with status ${response.statusCode}`
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
} catch (error) {
|
|
179
|
+
if (error instanceof HttpError) {
|
|
180
|
+
throw error;
|
|
181
|
+
}
|
|
182
|
+
throw new Error(
|
|
183
|
+
`HTTP request failed: ${
|
|
184
|
+
error instanceof Error ? error.message : String(error)
|
|
185
|
+
}`
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* GET 请求
|
|
192
|
+
*/
|
|
193
|
+
async get<T = unknown>(
|
|
194
|
+
url: string,
|
|
195
|
+
config?: Omit<HttpRequestConfig, "url" | "method">
|
|
196
|
+
): Promise<HttpResponse<T>> {
|
|
197
|
+
return this.request<T>({ ...config, url, method: "GET" });
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* POST 请求
|
|
202
|
+
*/
|
|
203
|
+
async post<T = unknown>(
|
|
204
|
+
url: string,
|
|
205
|
+
config?: Omit<HttpRequestConfig, "url" | "method">
|
|
206
|
+
): Promise<HttpResponse<T>> {
|
|
207
|
+
return this.request<T>({ ...config, url, method: "POST" });
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* PUT 请求
|
|
212
|
+
*/
|
|
213
|
+
async put<T = unknown>(
|
|
214
|
+
url: string,
|
|
215
|
+
config?: Omit<HttpRequestConfig, "url" | "method">
|
|
216
|
+
): Promise<HttpResponse<T>> {
|
|
217
|
+
return this.request<T>({ ...config, url, method: "PUT" });
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* DELETE 请求
|
|
222
|
+
*/
|
|
223
|
+
async delete<T = unknown>(
|
|
224
|
+
url: string,
|
|
225
|
+
config?: Omit<HttpRequestConfig, "url" | "method">
|
|
226
|
+
): Promise<HttpResponse<T>> {
|
|
227
|
+
return this.request<T>({ ...config, url, method: "DELETE" });
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* PATCH 请求
|
|
232
|
+
*/
|
|
233
|
+
async patch<T = unknown>(
|
|
234
|
+
url: string,
|
|
235
|
+
config?: Omit<HttpRequestConfig, "url" | "method">
|
|
236
|
+
): Promise<HttpResponse<T>> {
|
|
237
|
+
return this.request<T>({ ...config, url, method: "PATCH" });
|
|
238
|
+
}
|
|
239
|
+
}
|
package/src/apis/index.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Claw Cloud API 模块
|
|
3
|
-
*/
|
|
4
|
-
export { createClawCloudClient, ClawCloudClient } from './claw-cloud.js';
|
|
5
|
-
export { HttpClient, HttpError, type HttpRequestConfig, type HttpResponse } from './http-client.js';
|
|
6
|
-
export { createHonorAuthClient, HonorAuthClient } from './honor-auth.js';
|
|
7
|
-
export * from './types.js';
|
|
8
|
-
export * from './helpers.js';
|
|
1
|
+
/**
|
|
2
|
+
* Claw Cloud API 模块
|
|
3
|
+
*/
|
|
4
|
+
export { createClawCloudClient, ClawCloudClient } from './claw-cloud.js';
|
|
5
|
+
export { HttpClient, HttpError, type HttpRequestConfig, type HttpResponse } from './http-client.js';
|
|
6
|
+
export { createHonorAuthClient, HonorAuthClient } from './honor-auth.js';
|
|
7
|
+
export * from './types.js';
|
|
8
|
+
export * from './helpers.js';
|
package/src/apis/types.ts
CHANGED
|
@@ -1,73 +1,77 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 设备注册接口相关类型定义
|
|
3
|
-
*/
|
|
4
|
-
import type { ClawDeviceInfo, DeviceRole } from "../types.js";
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* 设备注册请求体
|
|
8
|
-
*/
|
|
9
|
-
export interface DeviceRegistryRequest {
|
|
10
|
-
businessTag: "YOYO_CLAW";
|
|
11
|
-
role: DeviceRole;
|
|
12
|
-
deviceInfo: Omit<ClawDeviceInfo, "role"
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
"x-
|
|
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
|
-
"x-
|
|
73
|
-
|
|
1
|
+
/**
|
|
2
|
+
* 设备注册接口相关类型定义
|
|
3
|
+
*/
|
|
4
|
+
import type { ClawDeviceInfo, DeviceRole } from "../types.js";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* 设备注册请求体
|
|
8
|
+
*/
|
|
9
|
+
export interface DeviceRegistryRequest {
|
|
10
|
+
businessTag: "YOYO_CLAW";
|
|
11
|
+
role: DeviceRole;
|
|
12
|
+
deviceInfo: Omit<ClawDeviceInfo, "role"> & {
|
|
13
|
+
manufacture: string;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface HttpApiWrapper<T = unknown> {
|
|
18
|
+
code: string;
|
|
19
|
+
success: boolean;
|
|
20
|
+
cnMessage: string;
|
|
21
|
+
data?: T;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* 设备注册响应体
|
|
26
|
+
*/
|
|
27
|
+
export type DeviceRegistryResponse = HttpApiWrapper;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* 设备注册请求头
|
|
31
|
+
*/
|
|
32
|
+
export interface DeviceRegistryHeaders {
|
|
33
|
+
"x-trace-id": string;
|
|
34
|
+
"x-udid"?: string;
|
|
35
|
+
"x-device-id"?: string;
|
|
36
|
+
/**
|
|
37
|
+
* token信息
|
|
38
|
+
*/
|
|
39
|
+
"x-jwt-token"?: string;
|
|
40
|
+
/**
|
|
41
|
+
* 用户id加密后的信息
|
|
42
|
+
*/
|
|
43
|
+
authorization?: string;
|
|
44
|
+
/**
|
|
45
|
+
* 端用,claw侧不需要
|
|
46
|
+
*/
|
|
47
|
+
// authorization?: string;
|
|
48
|
+
// debug mode
|
|
49
|
+
"x-agw-userId"?: string;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* 用户登出请求体
|
|
54
|
+
*/
|
|
55
|
+
export interface UserLogoutRequest {
|
|
56
|
+
businessTag: "YOYO_CLAW";
|
|
57
|
+
deviceInfo: Omit<ClawDeviceInfo, "role"> & {
|
|
58
|
+
manufacture: string;
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* 用户登出响应体
|
|
64
|
+
*/
|
|
65
|
+
export type UserLogoutResponse = HttpApiWrapper;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* 用户登出请求头
|
|
69
|
+
*/
|
|
70
|
+
export interface UserLogoutHeaders {
|
|
71
|
+
"x-trace-id": string;
|
|
72
|
+
"x-udid"?: string;
|
|
73
|
+
"x-device-id"?: string;
|
|
74
|
+
"x-jwt-token"?: string;
|
|
75
|
+
authorization?: string;
|
|
76
|
+
"x-agw-userId"?: string;
|
|
77
|
+
}
|