@bettergi/utils 0.1.20 → 0.1.21

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/README.md CHANGED
@@ -126,22 +126,32 @@ await assertRegionDisappearing(findButton, "点击购买按钮超时", () => fin
126
126
  > 对常见鼠标操作的封装,如鼠标的平滑移动、鼠标滚轮滚动、鼠标拖拽等。
127
127
 
128
128
  ```ts
129
- // 鼠标从 (745, 610) 平滑自然地移动 (1920, 1080)
130
- await naturalMouseMove(745, 610, 1920, 1080);
129
+ // 鼠标沿路径点移动并拖拽
130
+ await mouseMoveAlongWaypoints(
131
+ [
132
+ { x: 100, y: 100 },
133
+ { x: 200, y: 200 },
134
+ { x: 300, y: 300 }
135
+ ],
136
+ { shouldDrag: true }
137
+ );
131
138
 
132
139
  // 鼠标从 (745, 610) 拖拽到 (1280, 610)
133
140
  await mouseDrag(745, 610, 1280, 610);
134
141
 
142
+ // 鼠标从 (745, 610) 平滑自然地移动 (1920, 1080)
143
+ await naturalMouseMove(745, 610, 1920, 1080);
144
+
135
145
  // 鼠标滚轮向上滚动 175 像素
136
146
  await mouseScrollUp(175);
137
147
 
138
148
  // 鼠标滚轮向下滚动 175 像素
139
149
  await mouseScrollDown(175);
140
150
 
141
- // 鼠标滚轮向上滚动 99 行,行高 175(默认: 背包物品行高)
151
+ // 鼠标滚轮向上滚动 99 行(默认: 175为背包物品行高)
142
152
  await mouseScrollUpLines(99);
143
153
 
144
- // 鼠标滚轮向下滚动 1 行,行高 115(自定义: 商店物品行高)
154
+ // 鼠标滚轮向下滚动 1 行(自定义: 115为商店物品行高)
145
155
  await mouseScrollDownLines(1, 115);
146
156
  ```
147
157
 
@@ -201,12 +211,14 @@ tracker.complete(`任务完成`);
201
211
 
202
212
  ```ts
203
213
  // 发送 GET 请求获取响应体内容
204
- const body1 = await getForBody("https://example.com/", undefined, { "User-Agent": "BetterGI" });
205
- log.info(`GET 请求响应体内容${body1}`);
214
+ const body1 = await getForBody("https://jsonplaceholder.typicode.com/todos/1");
206
215
 
207
216
  // 发送 POST 请求获取响应体内容
208
- const body2 = await postForBody("https://example.com/", undefined, { "User-Agent": "BetterGI" });
209
- log.info(`POST 请求响应体内容${body2}`);
217
+ const body2 = await postForBody("https://jsonplaceholder.typicode.com/posts", {
218
+ title: "foo",
219
+ body: "bar",
220
+ userId: 1
221
+ });
210
222
  ```
211
223
 
212
224
  ### 文件操作
package/dist/http.d.ts CHANGED
@@ -2,24 +2,24 @@
2
2
  * 发送 HTTP 请求,获取响应体内容
3
3
  * @param method 请求方法
4
4
  * @param url 请求 URL
5
- * @param body 请求体
5
+ * @param body 请求体(UTF-8 编码)
6
6
  * @param headers 请求头
7
7
  * @returns 响应体内容
8
8
  */
9
- export declare const requestForBody: (method: Parameters<typeof http.request>[0], url: string, body?: string, headers?: Record<string, any>) => Promise<string>;
9
+ export declare const requestForBody: (method: Parameters<typeof http.request>[0], url: string, body?: string | object, headers?: Record<string, any>) => Promise<string>;
10
10
  /**
11
11
  * 发送 HTTP GET 请求,获取响应体内容
12
12
  * @param url 请求 URL
13
- * @param body 请求体
13
+ * @param body 请求体(UTF-8 编码)
14
14
  * @param headers 请求头
15
15
  * @returns 响应体内容
16
16
  */
17
- export declare const getForBody: (url: string, body?: string, headers?: Record<string, any>) => Promise<string>;
17
+ export declare const getForBody: (url: string, body?: string | object, headers?: Record<string, any>) => Promise<string>;
18
18
  /**
19
19
  * 发送 HTTP POST 请求,获取响应体内容
20
20
  * @param url 请求 URL
21
- * @param body 请求体
21
+ * @param body 请求体(UTF-8 编码)
22
22
  * @param headers 请求头
23
23
  * @returns 响应体内容
24
24
  */
25
- export declare const postForBody: (url: string, body?: string, headers?: Record<string, any>) => Promise<string>;
25
+ export declare const postForBody: (url: string, body?: string | object, headers?: Record<string, any>) => Promise<string>;
package/dist/http.js CHANGED
@@ -2,33 +2,37 @@
2
2
  * 发送 HTTP 请求,获取响应体内容
3
3
  * @param method 请求方法
4
4
  * @param url 请求 URL
5
- * @param body 请求体
5
+ * @param body 请求体(UTF-8 编码)
6
6
  * @param headers 请求头
7
7
  * @returns 响应体内容
8
8
  */
9
9
  export const requestForBody = async (method, url, body, headers) => {
10
- const resp = await http.request(method, url, body ?? "null", headers ? JSON.stringify(headers) : "null");
10
+ if (body && typeof body === "object") {
11
+ body = JSON.stringify(body);
12
+ headers = { ...headers, "Content-Type": "application/json" };
13
+ }
14
+ const resp = await http.request(method, url, body ?? null, headers ? JSON.stringify(headers) : null);
11
15
  if (resp.status_code >= 200 && resp.status_code < 400) {
12
16
  return resp.body;
13
17
  }
14
18
  else {
15
- throw new Error(`HTTP request failed with status ${resp.status_code}`);
19
+ throw new Error(`HTTP request failed with status ${resp.status_code}: ${resp.body}`);
16
20
  }
17
21
  };
18
22
  /**
19
23
  * 发送 HTTP GET 请求,获取响应体内容
20
24
  * @param url 请求 URL
21
- * @param body 请求体
25
+ * @param body 请求体(UTF-8 编码)
22
26
  * @param headers 请求头
23
27
  * @returns 响应体内容
24
28
  */
25
- export const getForBody = async (url, body, headers) => {
29
+ export const getForBody = (url, body, headers) => {
26
30
  return requestForBody("GET", url, body, headers);
27
31
  };
28
32
  /**
29
33
  * 发送 HTTP POST 请求,获取响应体内容
30
34
  * @param url 请求 URL
31
- * @param body 请求体
35
+ * @param body 请求体(UTF-8 编码)
32
36
  * @param headers 请求头
33
37
  * @returns 响应体内容
34
38
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bettergi/utils",
3
- "version": "0.1.20",
3
+ "version": "0.1.21",
4
4
  "description": "开发 BetterGI 脚本常用工具集",
5
5
  "type": "module",
6
6
  "author": "Bread Grocery<https://github.com/breadgrocery>",