apaas-oapi-client 0.1.8 → 0.1.10

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/index.d.ts CHANGED
@@ -3,20 +3,20 @@ import { LoggerLevel } from './logger';
3
3
  * Client 初始化配置
4
4
  */
5
5
  interface ClientOptions {
6
- /** 命名空间,例如 app_xxx */
6
+ /** 命名空间, 例如 app_xxx */
7
7
  namespace: string;
8
8
  /** 应用 clientId */
9
9
  clientId: string;
10
10
  /** 应用 clientSecret */
11
11
  clientSecret: string;
12
- /** 是否禁用 token 缓存,每次调用强制刷新 token,默认 false */
12
+ /** 是否禁用 token 缓存, 每次调用强制刷新 token, 默认 false */
13
13
  disableTokenCache?: boolean;
14
14
  }
15
15
  /**
16
16
  * records_query 接口请求参数
17
17
  */
18
18
  interface RecordsQueryParams {
19
- /** 对象名称,例如 object_store */
19
+ /** 对象名称, 例如 object_store */
20
20
  object_name: string;
21
21
  /** 请求体数据 */
22
22
  data: any;
@@ -50,7 +50,7 @@ declare class Client {
50
50
  */
51
51
  private log;
52
52
  /**
53
- * 初始化 client,自动获取 token
53
+ * 初始化 client, 自动获取 token
54
54
  */
55
55
  init(): Promise<void>;
56
56
  /**
@@ -58,7 +58,7 @@ declare class Client {
58
58
  */
59
59
  private getAccessToken;
60
60
  /**
61
- * 确保 token 有效,若过期则刷新
61
+ * 确保 token 有效, 若过期则刷新
62
62
  */
63
63
  private ensureTokenValid;
64
64
  /**
package/dist/index.js CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  var dayjs = require('dayjs');
4
4
  var axios = require('axios');
5
+ var Bottleneck = require('bottleneck');
5
6
 
6
7
  /**
7
8
  * 日志等级枚举
@@ -16,7 +17,32 @@ var LoggerLevel;
16
17
  LoggerLevel[LoggerLevel["trace"] = 5] = "trace";
17
18
  })(LoggerLevel || (LoggerLevel = {}));
18
19
 
19
- const { functionLimiter } = require('./limiter');
20
+ /**
21
+ * 默认 apaas 限流配置
22
+ */
23
+ const apaasLimiterOptions = {
24
+ minTime: 200, // 每秒最多发起 5 个数据库操作
25
+ reservoir: 20, // 最多同时查询 50 个数据库操作
26
+ reservoirRefreshAmount: 20, // 每次查询完毕后,重置为 50 个数据库操作
27
+ reservoirRefreshInterval: 1000 // 重置时间间隔为 1 秒
28
+ };
29
+ /**
30
+ * 创建限流器
31
+ * @param fn 被限流函数
32
+ * @param options 自定义限流配置
33
+ * @returns 包装后的限流函数
34
+ */
35
+ async function functionLimiter(fn, options = {}) {
36
+ const limiter = new Bottleneck({
37
+ minTime: options.minTime || apaasLimiterOptions.minTime,
38
+ reservoir: options.reservoir || apaasLimiterOptions.reservoir,
39
+ reservoirRefreshAmount: options.reservoirRefreshAmount || apaasLimiterOptions.reservoirRefreshAmount,
40
+ reservoirRefreshInterval: options.reservoirRefreshInterval || apaasLimiterOptions.reservoirRefreshInterval
41
+ });
42
+ const wrapped = limiter.wrap(fn);
43
+ return wrapped();
44
+ }
45
+
20
46
  /**
21
47
  * aPaaS OpenAPI 客户端
22
48
  */
@@ -43,12 +69,12 @@ class Client {
43
69
  const { object_name, field_name } = params;
44
70
  await this.ensureTokenValid();
45
71
  const url = `/api/data/v1/namespaces/${this.namespace}/meta/objects/${object_name}/fields/${field_name}`;
46
- this.log(LoggerLevel.debug, `[对象字段查询] 📄 开始获取字段元数据 object_name=${object_name}, field_name=${field_name}`);
72
+ this.log(LoggerLevel.debug, `[对象字段查询] 📄 开始获取字段元数据, object_name=${object_name}, field_name=${field_name}`);
47
73
  const res = await this.axiosInstance.get(url, {
48
74
  headers: { Authorization: `${this.accessToken}` }
49
75
  });
50
- this.log(LoggerLevel.debug, `[对象字段查询] 📄 调用完成,返回状态=${res.data.code}`);
51
- this.log(LoggerLevel.trace, `[对象字段查询] 📄 调用完成,返回信息=${JSON.stringify(res.data)}`);
76
+ this.log(LoggerLevel.debug, `[对象字段查询] 📄 object_name=${object_name}, field_name=${field_name}, 调用完成, 返回状态=${res.data.code}`);
77
+ this.log(LoggerLevel.trace, `[对象字段查询] 📄 object_name=${object_name}, field_name=${field_name}, 返回信息=${JSON.stringify(res.data)}`);
52
78
  return res.data;
53
79
  },
54
80
  /**
@@ -64,8 +90,8 @@ class Client {
64
90
  const res = await this.axiosInstance.get(url, {
65
91
  headers: { Authorization: `${this.accessToken}` }
66
92
  });
67
- this.log(LoggerLevel.debug, `[对象字段查询] 📄 调用完成,返回状态=${res.data.code}`);
68
- this.log(LoggerLevel.trace, `[对象字段查询] 📄 调用完成,返回信息=${JSON.stringify(res.data)}`);
93
+ this.log(LoggerLevel.debug, `[对象字段查询] 📄 object_name=${object_name}, 调用完成, 返回状态=${res.data.code}`);
94
+ this.log(LoggerLevel.trace, `[对象字段查询] 📄 object_name=${object_name}, 调用完成, 返回信息=${JSON.stringify(res.data)}`);
69
95
  return res.data;
70
96
  }
71
97
  },
@@ -82,8 +108,8 @@ class Client {
82
108
  const res = await functionLimiter(async () => {
83
109
  await this.ensureTokenValid();
84
110
  const response = await this.axiosInstance.post(url, { select }, { headers: { Authorization: `${this.accessToken}` } });
85
- this.log(LoggerLevel.debug, `[单条查询记录] 🔍 查询 record_id: ${record_id} 调用完成,返回状态: ${response.data.code}`);
86
- this.log(LoggerLevel.trace, `[单条查询记录] 🔍 查询 record_id: ${record_id} 调用完成,返回信息: ${JSON.stringify(response.data)}`);
111
+ this.log(LoggerLevel.debug, `[单条查询记录] 🔍 查询 object_name=${object_name}, record_id: ${record_id} 调用完成, 返回状态: ${response.data.code}`);
112
+ this.log(LoggerLevel.trace, `[单条查询记录] 🔍 查询 object_name=${object_name}, record_id: ${record_id} 调用完成, 返回信息: ${JSON.stringify(response.data)}`);
87
113
  return response.data;
88
114
  });
89
115
  return res;
@@ -102,8 +128,8 @@ class Client {
102
128
  headers: { Authorization: `${this.accessToken}` }
103
129
  });
104
130
  this.log(LoggerLevel.info, `[批量查询记录] 🔍 接口调用完成`);
105
- this.log(LoggerLevel.debug, `[批量查询记录] 🔍 调用完成,返回状态: ${res.data.code},返回数据总数${((_b = (_a = res.data) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.total) || 'unknown'}`);
106
- this.log(LoggerLevel.trace, `[批量查询记录] 🔍 调用完成,返回信息: ${JSON.stringify(res.data)}`);
131
+ this.log(LoggerLevel.debug, `[批量查询记录] 🔍 查询 object_name=${object_name}, 调用完成, 返回状态: ${res.data.code}, 返回数据总数${((_b = (_a = res.data) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.total) || 'unknown'}`);
132
+ this.log(LoggerLevel.trace, `[批量查询记录] 🔍 查询 object_name=${object_name}, 调用完成, 返回信息: ${JSON.stringify(res.data)}`);
107
133
  return res.data;
108
134
  },
109
135
  /**
@@ -130,11 +156,11 @@ class Client {
130
156
  }
131
157
  if (page === 1) {
132
158
  total = res.data.total || 0;
133
- this.log(LoggerLevel.info, '[批量查询记录] 🔍 接口返回 total:', total);
159
+ this.log(LoggerLevel.info, '[批量查询记录] 🔍 查询object_name=${object_name}, 接口返回 total:', total);
134
160
  }
135
161
  nextPageToken = res.data.next_page_token;
136
- this.log(LoggerLevel.debug, `[批量查询记录] 🔍 第 ${page} 页查询,nextPageToken: ${nextPageToken || ''}`);
137
- this.log(LoggerLevel.debug, `[批量查询记录] 🔍 第 ${page} 页查询完成,items.length: ${res.data.items.length}`);
162
+ this.log(LoggerLevel.debug, `[批量查询记录] 🔍 第 ${page} 页查询, nextPageToken: ${nextPageToken || ''}`);
163
+ this.log(LoggerLevel.debug, `[批量查询记录] 🔍 第 ${page} 页查询完成, items.length: ${res.data.items.length}`);
138
164
  this.log(LoggerLevel.trace, `[批量查询记录] 🔍 第 ${page} 页查询结果: ${JSON.stringify(res.data.items)}`);
139
165
  return res;
140
166
  });
@@ -157,9 +183,9 @@ class Client {
157
183
  const response = await this.axiosInstance.post(url, { record }, {
158
184
  headers: { Authorization: `${this.accessToken}` }
159
185
  });
160
- this.log(LoggerLevel.info, `[单条创建记录] ➕ 向对象 ${object_name} 内创建记录,调用完成`);
161
- this.log(LoggerLevel.debug, `[单条创建记录] ➕ 向对象 ${object_name} 内创建数据,调用完成,返回状态: ${response.data.code}`);
162
- this.log(LoggerLevel.trace, `[单条创建记录] ➕ 向对象 ${object_name} 内创建数据,调用完成,返回信息: ${JSON.stringify(response.data)}`);
186
+ this.log(LoggerLevel.info, `[单条创建记录] ➕ 向对象 ${object_name} 内创建记录, 调用完成`);
187
+ this.log(LoggerLevel.debug, `[单条创建记录] ➕ 向对象 ${object_name} 内创建数据, 调用完成, 返回状态: ${response.data.code}`);
188
+ this.log(LoggerLevel.trace, `[单条创建记录] ➕ 向对象 ${object_name} 内创建数据, 调用完成, 返回信息: ${JSON.stringify(response.data)}`);
163
189
  return response.data;
164
190
  });
165
191
  return res;
@@ -177,8 +203,8 @@ class Client {
177
203
  headers: { Authorization: `${this.accessToken}` }
178
204
  });
179
205
  this.log(LoggerLevel.info, `[批量创建记录] ➕ 开始向对象 ${object_name} 批量创建记录`);
180
- this.log(LoggerLevel.debug, `[批量创建记录] ➕ 向对象 ${object_name} 批量创建记录,调用完成,返回状态: ${res.data.code}`);
181
- this.log(LoggerLevel.trace, `[批量创建记录] ➕ 向对象 ${object_name} 批量创建记录,调用完成,返回信息: ${JSON.stringify(res.data)}`);
206
+ this.log(LoggerLevel.debug, `[批量创建记录] ➕ 向对象 ${object_name} 批量创建记录, 调用完成, 返回状态: ${res.data.code}`);
207
+ this.log(LoggerLevel.trace, `[批量创建记录] ➕ 向对象 ${object_name} 批量创建记录, 调用完成, 返回信息: ${JSON.stringify(res.data)}`);
182
208
  return res.data;
183
209
  },
184
210
  /**
@@ -196,12 +222,12 @@ class Client {
196
222
  for (let i = 0; i < records.length; i += chunkSize) {
197
223
  chunks.push(records.slice(i, i + chunkSize));
198
224
  }
199
- this.log(LoggerLevel.debug, `[批量创建记录] ➕ 总共 ${records.length} 条记录,拆分为 ${chunks.length} 组,每组最多 ${chunkSize} 条`);
200
- this.log(LoggerLevel.trace, `[批量创建记录] ➕ 总共 ${records.length} 条记录,拆分为 ${chunks.length} 组,每组最多 ${chunkSize} 条`);
225
+ this.log(LoggerLevel.debug, `[批量创建记录] ➕ 总共 ${records.length} 条记录, 拆分为 ${chunks.length} 组, 每组最多 ${chunkSize} 条`);
226
+ this.log(LoggerLevel.trace, `[批量创建记录] ➕ 总共 ${records.length} 条记录, 拆分为 ${chunks.length} 组, 每组最多 ${chunkSize} 条`);
201
227
  for (const [index, chunk] of chunks.entries()) {
202
228
  page += 1;
203
- this.log(LoggerLevel.debug, `[批量创建记录] ➕ 开始创建第 ${index + 1} 组,共 ${chunk.length} 条`);
204
- this.log(LoggerLevel.trace, `[批量创建记录] ➕ 开始创建第 ${index + 1} 组,共 ${chunk.length} 条`);
229
+ this.log(LoggerLevel.debug, `[批量创建记录] ➕ 开始创建第 ${index + 1} 组, ${chunk.length} 条`);
230
+ this.log(LoggerLevel.trace, `[批量创建记录] ➕ 开始创建第 ${index + 1} 组, ${chunk.length} 条`);
205
231
  await functionLimiter(async () => {
206
232
  const res = await this.object.create.records({
207
233
  object_name,
@@ -210,9 +236,9 @@ class Client {
210
236
  if (res.data && Array.isArray(res.data.items)) {
211
237
  results = results.concat(res.data.items);
212
238
  }
213
- this.log(LoggerLevel.info, `[批量创建记录] ➕ 创建第 ${page} 页数据,调用完成,创建数量: ${res.data.items.length}`);
214
- this.log(LoggerLevel.debug, `[批量创建记录] ➕ 创建第 ${page} 页页数据,调用完成,返回状态: ${res.data.code}`);
215
- this.log(LoggerLevel.trace, `[批量创建记录] ➕ 创建第 ${page} 页页数据,调用结果: ${JSON.stringify(res.data.items)}`);
239
+ this.log(LoggerLevel.info, `[批量创建记录] ➕ 创建 object_name=${object_name}, 第 ${page} 页数据, 调用完成, 创建数量: ${res.data.items.length}`);
240
+ this.log(LoggerLevel.debug, `[批量创建记录] ➕ 创建 object_name=${object_name}, 第 ${page} 页页数据, 调用完成, 返回状态: ${res.data.code}`);
241
+ this.log(LoggerLevel.trace, `[批量创建记录] ➕ 创建 object_name=${object_name}, 第 ${page} 页页数据, 调用结果: ${JSON.stringify(res.data.items)}`);
216
242
  return res;
217
243
  });
218
244
  }
@@ -232,9 +258,9 @@ class Client {
232
258
  const res = await functionLimiter(async () => {
233
259
  await this.ensureTokenValid();
234
260
  const response = await this.axiosInstance.patch(url, { record }, { headers: { Authorization: `${this.accessToken}` } });
235
- this.log(LoggerLevel.info, `[单条更新记录] 💾 更新 record_id: ${record_id} 调用完成`);
236
- this.log(LoggerLevel.debug, `[单条更新记录] 💾 更新 record_id: ${record_id} 调用完成,返回状态: ${response.data.code}`);
237
- this.log(LoggerLevel.trace, `[单条更新记录] 💾 更新 record_id: ${record_id} 调用完成,返回信息: ${JSON.stringify(response.data)}`);
261
+ this.log(LoggerLevel.info, `[单条更新记录] 💾 更新 object_name=${object_name}, record_id: ${record_id} 调用完成`);
262
+ this.log(LoggerLevel.debug, `[单条更新记录] 💾 更新 object_name=${object_name}, record_id: ${record_id} 调用完成, 返回状态: ${response.data.code}`);
263
+ this.log(LoggerLevel.trace, `[单条更新记录] 💾 更新 object_name=${object_name}, record_id: ${record_id} 调用完成, 返回信息: ${JSON.stringify(response.data)}`);
238
264
  return response.data;
239
265
  });
240
266
  return res;
@@ -252,17 +278,17 @@ class Client {
252
278
  for (let i = 0; i < records.length; i += chunkSize) {
253
279
  chunks.push(records.slice(i, i + chunkSize));
254
280
  }
255
- this.log(LoggerLevel.debug, `[批量更新记录] 💾 总共 ${records.length} 条记录,拆分为 ${chunks.length} 组,每组最多 ${chunkSize} 条`);
256
- this.log(LoggerLevel.trace, `[批量更新记录] 💾 总共 ${records.length} 条记录,拆分为 ${chunks.length} 组,每组最多 ${chunkSize} 条`);
281
+ this.log(LoggerLevel.debug, `[批量更新记录] 💾 总共 ${records.length} 条记录, 拆分为 ${chunks.length} 组, 每组最多 ${chunkSize} 条`);
282
+ this.log(LoggerLevel.trace, `[批量更新记录] 💾 总共 ${records.length} 条记录, 拆分为 ${chunks.length} 组, 每组最多 ${chunkSize} 条`);
257
283
  const results = [];
258
284
  for (const [index, chunk] of chunks.entries()) {
259
- this.log(LoggerLevel.debug, `[批量更新记录] 💾 开始更新第 ${index + 1} 组,共 ${chunk.length} 条`);
260
- this.log(LoggerLevel.trace, `[批量更新记录] 💾 开始更新第 ${index + 1} 组,共 ${chunk.length} 条`);
285
+ this.log(LoggerLevel.debug, `[批量更新记录] 💾 开始更新第 ${index + 1} 组, ${chunk.length} 条`);
286
+ this.log(LoggerLevel.trace, `[批量更新记录] 💾 开始更新第 ${index + 1} 组, ${chunk.length} 条`);
261
287
  const res = await functionLimiter(async () => {
262
288
  await this.ensureTokenValid();
263
289
  const response = await this.axiosInstance.patch(url, { records: chunk }, { headers: { Authorization: `${this.accessToken}` } });
264
- this.log(LoggerLevel.debug, `[批量更新记录] 💾 更新第 ${index + 1} 组调用完成,返回状态: ${JSON.stringify(response.data)}`);
265
- this.log(LoggerLevel.trace, `[批量更新记录] 💾 更新第 ${index + 1} 组调用完成,返回信息: ${response.data}`);
290
+ this.log(LoggerLevel.debug, `[批量更新记录] 💾 更新 object_name=${object_name}, 第 ${index + 1} 组调用完成, 返回状态: ${JSON.stringify(response.data)}`);
291
+ this.log(LoggerLevel.trace, `[批量更新记录] 💾 更新 object_name=${object_name}, 第 ${index + 1} 组调用完成, 返回信息: ${response.data}`);
266
292
  return response.data;
267
293
  });
268
294
  results.push(res);
@@ -279,13 +305,13 @@ class Client {
279
305
  record: async (params) => {
280
306
  const { object_name, record_id } = params;
281
307
  const url = `/v1/data/namespaces/${this.namespace}/objects/${object_name}/records/${record_id}`;
282
- this.log(LoggerLevel.trace, `[单条删除记录] 🗑️ 开始删除 record_id: ${record_id}`);
308
+ this.log(LoggerLevel.trace, `[单条删除记录] 🗑️ object_name=${object_name}, 开始删除 record_id: ${record_id}`);
283
309
  const res = await functionLimiter(async () => {
284
310
  await this.ensureTokenValid();
285
311
  const response = await this.axiosInstance.delete(url, {
286
312
  headers: { Authorization: `${this.accessToken}` }
287
313
  });
288
- this.log(LoggerLevel.info, `[单条删除记录] 🗑️ 删除 record_id: ${record_id} 调用完成,返回信息: ${JSON.stringify(response.data)}`);
314
+ this.log(LoggerLevel.info, `[单条删除记录] 🗑️ 删除 object_name=${object_name}, record_id: ${record_id} 调用完成, 返回信息: ${JSON.stringify(response.data)}`);
289
315
  return response.data;
290
316
  });
291
317
  return res;
@@ -303,18 +329,18 @@ class Client {
303
329
  for (let i = 0; i < ids.length; i += chunkSize) {
304
330
  chunks.push(ids.slice(i, i + chunkSize));
305
331
  }
306
- this.log(LoggerLevel.debug, `[批量删除记录] 🗑️ 总共 ${ids.length} 条记录,拆分为 ${chunks.length} 组,每组最多 ${chunkSize} 条`);
332
+ this.log(LoggerLevel.debug, `[批量删除记录] 🗑️ 总共 ${ids.length} 条记录, 拆分为 ${chunks.length} 组, 每组最多 ${chunkSize} 条`);
307
333
  const results = [];
308
334
  for (const [index, chunk] of chunks.entries()) {
309
- this.log(LoggerLevel.info, `[批量删除记录] 🗑️ 开始删除第 ${index + 1} 组,共 ${chunk.length} 条`);
335
+ this.log(LoggerLevel.info, `[批量删除记录] 🗑️ 开始删除第 ${index + 1} 组, ${chunk.length} 条`);
310
336
  const res = await functionLimiter(async () => {
311
337
  await this.ensureTokenValid();
312
338
  const response = await this.axiosInstance.delete(url, {
313
339
  headers: { Authorization: `${this.accessToken}` },
314
340
  data: { ids: chunk }
315
341
  });
316
- this.log(LoggerLevel.debug, `[批量删除记录] 🗑️ 第 ${index + 1} 组删除完成,返回状态: ${response.data.code}`);
317
- this.log(LoggerLevel.trace, `[批量删除记录] 🗑️ 第 ${index + 1} 组删除完成,返回信息: ${JSON.stringify(response.data)}`);
342
+ this.log(LoggerLevel.debug, `[批量删除记录] 🗑️ 第 ${index + 1} 组删除完成, 返回状态: ${response.data.code}`);
343
+ this.log(LoggerLevel.trace, `[批量删除记录] 🗑️ 第 ${index + 1} 组删除完成, 返回信息: ${JSON.stringify(response.data)}`);
318
344
  return response.data;
319
345
  });
320
346
  results.push(res);
@@ -336,7 +362,7 @@ class Client {
336
362
  const { department_id_type, department_id } = params;
337
363
  // department_id_type 可选值:
338
364
  // - 'department_id' (如 "1758534140403815")
339
- // - 'external_department_id' (外部平台 department_id,无固定格式)
365
+ // - 'external_department_id' (外部平台 department_id, 无固定格式)
340
366
  // - 'external_open_department_id' (以 'oc_' 开头的 open_department_id)
341
367
  const url = '/api/integration/v2/feishu/getDepartments';
342
368
  this.log(LoggerLevel.info, `[部门ID交换] 🔄 开始交换单个部门 ID: ${department_id}`);
@@ -348,8 +374,8 @@ class Client {
348
374
  }, {
349
375
  headers: { Authorization: `${this.accessToken}` }
350
376
  });
351
- this.log(LoggerLevel.debug, `[部门ID交换] 🔄 交换部门 ID: ${department_id} 调用完成,返回状态: ${response.data.code}`);
352
- this.log(LoggerLevel.debug, `[部门ID交换] 🔄 交换部门 ID: ${department_id} 调用完成,返回信息: ${JSON.stringify(response.data)}`);
377
+ this.log(LoggerLevel.debug, `[部门ID交换] 🔄 交换部门 ID: ${department_id} 调用完成, 返回状态: ${response.data.code}`);
378
+ this.log(LoggerLevel.debug, `[部门ID交换] 🔄 交换部门 ID: ${department_id} 调用完成, 返回信息: ${JSON.stringify(response.data)}`);
353
379
  return response.data.data[0]; // 返回第一个元素
354
380
  });
355
381
  return res;
@@ -363,7 +389,7 @@ class Client {
363
389
  const { department_id_type, department_ids } = params;
364
390
  // department_id_type 可选值:
365
391
  // - 'department_id' (如 "1758534140403815")
366
- // - 'external_department_id' (外部平台 department_id,无固定格式)
392
+ // - 'external_department_id' (外部平台 department_id, 无固定格式)
367
393
  // - 'external_open_department_id' (以 'oc_' 开头的 open_department_id)
368
394
  const url = '/api/integration/v2/feishu/getDepartments';
369
395
  const chunkSize = 100;
@@ -371,10 +397,10 @@ class Client {
371
397
  for (let i = 0; i < department_ids.length; i += chunkSize) {
372
398
  chunks.push(department_ids.slice(i, i + chunkSize));
373
399
  }
374
- this.log(LoggerLevel.info, `[批量部门ID交换] 🔄 总共 ${department_ids.length} 个部门 ID,拆分为 ${chunks.length} 组,每组最多 ${chunkSize} 个`);
400
+ this.log(LoggerLevel.info, `[批量部门ID交换] 🔄 总共 ${department_ids.length} 个部门 ID, 拆分为 ${chunks.length} 组, 每组最多 ${chunkSize} 个`);
375
401
  const results = [];
376
402
  for (const [index, chunk] of chunks.entries()) {
377
- this.log(LoggerLevel.info, `[批量部门ID交换] 🔄 开始交换第 ${index + 1} 组,共 ${chunk.length} 个`);
403
+ this.log(LoggerLevel.info, `[批量部门ID交换] 🔄 开始交换第 ${index + 1} 组, ${chunk.length} 个`);
378
404
  const res = await functionLimiter(async () => {
379
405
  await this.ensureTokenValid();
380
406
  const response = await this.axiosInstance.post(url, {
@@ -383,8 +409,8 @@ class Client {
383
409
  }, {
384
410
  headers: { Authorization: `${this.accessToken}` }
385
411
  });
386
- this.log(LoggerLevel.debug, `[批量部门ID交换] 🔄 交换第 ${index + 1} 组调用完成,返回状态: ${response.data.code}`);
387
- this.log(LoggerLevel.trace, `[批量部门ID交换] 🔄 交换第 ${index + 1} 组调用完成,返回信息: ${JSON.stringify(response.data)}`);
412
+ this.log(LoggerLevel.debug, `[批量部门ID交换] 🔄 交换第 ${index + 1} 组调用完成, 返回状态: ${response.data.code}`);
413
+ this.log(LoggerLevel.trace, `[批量部门ID交换] 🔄 交换第 ${index + 1} 组调用完成, 返回信息: ${JSON.stringify(response.data)}`);
388
414
  return response.data.data;
389
415
  });
390
416
  results.push(...res);
@@ -412,8 +438,8 @@ class Client {
412
438
  'Content-Type': 'application/json'
413
439
  }
414
440
  });
415
- this.log(LoggerLevel.debug, `[调用云函数] ☁️ 云函数 ${name} 调用完成,返回状态: code=${res.data.code}`);
416
- this.log(LoggerLevel.trace, `[调用云函数] ☁️ 云函数 ${name} 调用完成,返回信息: code=${JSON.stringify(res.data)}`);
441
+ this.log(LoggerLevel.debug, `[调用云函数] ☁️ 云函数 ${name} 调用完成, 返回状态: code=${res.data.code}`);
442
+ this.log(LoggerLevel.trace, `[调用云函数] ☁️ 云函数 ${name} 调用完成, 返回信息: code=${JSON.stringify(res.data)}`);
417
443
  return res.data;
418
444
  }
419
445
  };
@@ -448,7 +474,7 @@ class Client {
448
474
  }
449
475
  }
450
476
  /**
451
- * 初始化 client,自动获取 token
477
+ * 初始化 client, 自动获取 token
452
478
  */
453
479
  async init() {
454
480
  await this.ensureTokenValid();
@@ -472,7 +498,7 @@ class Client {
472
498
  this.log(LoggerLevel.info, '[client] token refreshed');
473
499
  }
474
500
  /**
475
- * 确保 token 有效,若过期则刷新
501
+ * 确保 token 有效, 若过期则刷新
476
502
  */
477
503
  async ensureTokenValid() {
478
504
  if (this.disableTokenCache) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "apaas-oapi-client",
3
- "version": "0.1.8",
3
+ "version": "0.1.10",
4
4
  "main": "dist/index.js",
5
5
  "exports": {
6
6
  ".": "./dist/index.js",
package/src/index.ts CHANGED
@@ -1,19 +1,19 @@
1
1
  import dayjs from 'dayjs';
2
2
  import axios, { AxiosInstance } from 'axios';
3
3
  import { LoggerLevel } from './logger';
4
- const { functionLimiter } = require('./limiter');
4
+ import { functionLimiter } from './limiter';
5
5
 
6
6
  /**
7
7
  * Client 初始化配置
8
8
  */
9
9
  interface ClientOptions {
10
- /** 命名空间,例如 app_xxx */
10
+ /** 命名空间, 例如 app_xxx */
11
11
  namespace: string;
12
12
  /** 应用 clientId */
13
13
  clientId: string;
14
14
  /** 应用 clientSecret */
15
15
  clientSecret: string;
16
- /** 是否禁用 token 缓存,每次调用强制刷新 token,默认 false */
16
+ /** 是否禁用 token 缓存, 每次调用强制刷新 token, 默认 false */
17
17
  disableTokenCache?: boolean;
18
18
  }
19
19
 
@@ -33,7 +33,7 @@ interface TokenResponse {
33
33
  * records_query 接口请求参数
34
34
  */
35
35
  interface RecordsQueryParams {
36
- /** 对象名称,例如 object_store */
36
+ /** 对象名称, 例如 object_store */
37
37
  object_name: string;
38
38
  /** 请求体数据 */
39
39
  data: any;
@@ -92,7 +92,7 @@ class Client {
92
92
  }
93
93
  }
94
94
  /**
95
- * 初始化 client,自动获取 token
95
+ * 初始化 client, 自动获取 token
96
96
  */
97
97
  async init() {
98
98
  await this.ensureTokenValid();
@@ -120,7 +120,7 @@ class Client {
120
120
  }
121
121
 
122
122
  /**
123
- * 确保 token 有效,若过期则刷新
123
+ * 确保 token 有效, 若过期则刷新
124
124
  */
125
125
  private async ensureTokenValid() {
126
126
  if (this.disableTokenCache) {
@@ -172,14 +172,14 @@ class Client {
172
172
  await this.ensureTokenValid();
173
173
  const url = `/api/data/v1/namespaces/${this.namespace}/meta/objects/${object_name}/fields/${field_name}`;
174
174
 
175
- this.log(LoggerLevel.debug, `[对象字段查询] 📄 开始获取字段元数据 object_name=${object_name}, field_name=${field_name}`);
175
+ this.log(LoggerLevel.debug, `[对象字段查询] 📄 开始获取字段元数据, object_name=${object_name}, field_name=${field_name}`);
176
176
 
177
177
  const res = await this.axiosInstance.get(url, {
178
178
  headers: { Authorization: `${this.accessToken}` }
179
179
  });
180
180
 
181
- this.log(LoggerLevel.debug, `[对象字段查询] 📄 调用完成,返回状态=${res.data.code}`);
182
- this.log(LoggerLevel.trace, `[对象字段查询] 📄 调用完成,返回信息=${JSON.stringify(res.data)}`);
181
+ this.log(LoggerLevel.debug, `[对象字段查询] 📄 object_name=${object_name}, field_name=${field_name}, 调用完成, 返回状态=${res.data.code}`);
182
+ this.log(LoggerLevel.trace, `[对象字段查询] 📄 object_name=${object_name}, field_name=${field_name}, 返回信息=${JSON.stringify(res.data)}`);
183
183
  return res.data;
184
184
  },
185
185
 
@@ -199,8 +199,8 @@ class Client {
199
199
  headers: { Authorization: `${this.accessToken}` }
200
200
  });
201
201
 
202
- this.log(LoggerLevel.debug, `[对象字段查询] 📄 调用完成,返回状态=${res.data.code}`);
203
- this.log(LoggerLevel.trace, `[对象字段查询] 📄 调用完成,返回信息=${JSON.stringify(res.data)}`);
202
+ this.log(LoggerLevel.debug, `[对象字段查询] 📄 object_name=${object_name}, 调用完成, 返回状态=${res.data.code}`);
203
+ this.log(LoggerLevel.trace, `[对象字段查询] 📄 object_name=${object_name}, 调用完成, 返回信息=${JSON.stringify(res.data)}`);
204
204
  return res.data;
205
205
  }
206
206
  },
@@ -222,8 +222,8 @@ class Client {
222
222
 
223
223
  const response = await this.axiosInstance.post(url, { select }, { headers: { Authorization: `${this.accessToken}` } });
224
224
 
225
- this.log(LoggerLevel.debug, `[单条查询记录] 🔍 查询 record_id: ${record_id} 调用完成,返回状态: ${response.data.code}`);
226
- this.log(LoggerLevel.trace, `[单条查询记录] 🔍 查询 record_id: ${record_id} 调用完成,返回信息: ${JSON.stringify(response.data)}`);
225
+ this.log(LoggerLevel.debug, `[单条查询记录] 🔍 查询 object_name=${object_name}, record_id: ${record_id} 调用完成, 返回状态: ${response.data.code}`);
226
+ this.log(LoggerLevel.trace, `[单条查询记录] 🔍 查询 object_name=${object_name}, record_id: ${record_id} 调用完成, 返回信息: ${JSON.stringify(response.data)}`);
227
227
 
228
228
  return response.data;
229
229
  });
@@ -247,8 +247,8 @@ class Client {
247
247
  });
248
248
 
249
249
  this.log(LoggerLevel.info, `[批量查询记录] 🔍 接口调用完成`);
250
- this.log(LoggerLevel.debug, `[批量查询记录] 🔍 调用完成,返回状态: ${res.data.code},返回数据总数${res.data?.data?.total || 'unknown'}`);
251
- this.log(LoggerLevel.trace, `[批量查询记录] 🔍 调用完成,返回信息: ${JSON.stringify(res.data)}`);
250
+ this.log(LoggerLevel.debug, `[批量查询记录] 🔍 查询 object_name=${object_name}, 调用完成, 返回状态: ${res.data.code}, 返回数据总数${res.data?.data?.total || 'unknown'}`);
251
+ this.log(LoggerLevel.trace, `[批量查询记录] 🔍 查询 object_name=${object_name}, 调用完成, 返回信息: ${JSON.stringify(res.data)}`);
252
252
  return res.data;
253
253
  },
254
254
 
@@ -282,13 +282,13 @@ class Client {
282
282
 
283
283
  if (page === 1) {
284
284
  total = res.data.total || 0;
285
- this.log(LoggerLevel.info, '[批量查询记录] 🔍 接口返回 total:', total);
285
+ this.log(LoggerLevel.info, '[批量查询记录] 🔍 查询object_name=${object_name}, 接口返回 total:', total);
286
286
  }
287
287
 
288
288
  nextPageToken = res.data.next_page_token;
289
289
 
290
- this.log(LoggerLevel.debug, `[批量查询记录] 🔍 第 ${page} 页查询,nextPageToken: ${nextPageToken || ''}`);
291
- this.log(LoggerLevel.debug, `[批量查询记录] 🔍 第 ${page} 页查询完成,items.length: ${res.data.items.length}`);
290
+ this.log(LoggerLevel.debug, `[批量查询记录] 🔍 第 ${page} 页查询, nextPageToken: ${nextPageToken || ''}`);
291
+ this.log(LoggerLevel.debug, `[批量查询记录] 🔍 第 ${page} 页查询完成, items.length: ${res.data.items.length}`);
292
292
  this.log(LoggerLevel.trace, `[批量查询记录] 🔍 第 ${page} 页查询结果: ${JSON.stringify(res.data.items)}`);
293
293
  return res;
294
294
  });
@@ -321,9 +321,9 @@ class Client {
321
321
  }
322
322
  );
323
323
 
324
- this.log(LoggerLevel.info, `[单条创建记录] ➕ 向对象 ${object_name} 内创建记录,调用完成`);
325
- this.log(LoggerLevel.debug, `[单条创建记录] ➕ 向对象 ${object_name} 内创建数据,调用完成,返回状态: ${response.data.code}`);
326
- this.log(LoggerLevel.trace, `[单条创建记录] ➕ 向对象 ${object_name} 内创建数据,调用完成,返回信息: ${JSON.stringify(response.data)}`);
324
+ this.log(LoggerLevel.info, `[单条创建记录] ➕ 向对象 ${object_name} 内创建记录, 调用完成`);
325
+ this.log(LoggerLevel.debug, `[单条创建记录] ➕ 向对象 ${object_name} 内创建数据, 调用完成, 返回状态: ${response.data.code}`);
326
+ this.log(LoggerLevel.trace, `[单条创建记录] ➕ 向对象 ${object_name} 内创建数据, 调用完成, 返回信息: ${JSON.stringify(response.data)}`);
327
327
 
328
328
  return response.data;
329
329
  });
@@ -351,8 +351,8 @@ class Client {
351
351
  );
352
352
 
353
353
  this.log(LoggerLevel.info, `[批量创建记录] ➕ 开始向对象 ${object_name} 批量创建记录`);
354
- this.log(LoggerLevel.debug, `[批量创建记录] ➕ 向对象 ${object_name} 批量创建记录,调用完成,返回状态: ${res.data.code}`);
355
- this.log(LoggerLevel.trace, `[批量创建记录] ➕ 向对象 ${object_name} 批量创建记录,调用完成,返回信息: ${JSON.stringify(res.data)}`);
354
+ this.log(LoggerLevel.debug, `[批量创建记录] ➕ 向对象 ${object_name} 批量创建记录, 调用完成, 返回状态: ${res.data.code}`);
355
+ this.log(LoggerLevel.trace, `[批量创建记录] ➕ 向对象 ${object_name} 批量创建记录, 调用完成, 返回信息: ${JSON.stringify(res.data)}`);
356
356
  return res.data;
357
357
  },
358
358
 
@@ -374,14 +374,14 @@ class Client {
374
374
  chunks.push(records.slice(i, i + chunkSize));
375
375
  }
376
376
 
377
- this.log(LoggerLevel.debug, `[批量创建记录] ➕ 总共 ${records.length} 条记录,拆分为 ${chunks.length} 组,每组最多 ${chunkSize} 条`);
378
- this.log(LoggerLevel.trace, `[批量创建记录] ➕ 总共 ${records.length} 条记录,拆分为 ${chunks.length} 组,每组最多 ${chunkSize} 条`);
377
+ this.log(LoggerLevel.debug, `[批量创建记录] ➕ 总共 ${records.length} 条记录, 拆分为 ${chunks.length} 组, 每组最多 ${chunkSize} 条`);
378
+ this.log(LoggerLevel.trace, `[批量创建记录] ➕ 总共 ${records.length} 条记录, 拆分为 ${chunks.length} 组, 每组最多 ${chunkSize} 条`);
379
379
 
380
380
  for (const [index, chunk] of chunks.entries()) {
381
381
  page += 1;
382
382
 
383
- this.log(LoggerLevel.debug, `[批量创建记录] ➕ 开始创建第 ${index + 1} 组,共 ${chunk.length} 条`);
384
- this.log(LoggerLevel.trace, `[批量创建记录] ➕ 开始创建第 ${index + 1} 组,共 ${chunk.length} 条`);
383
+ this.log(LoggerLevel.debug, `[批量创建记录] ➕ 开始创建第 ${index + 1} 组, ${chunk.length} 条`);
384
+ this.log(LoggerLevel.trace, `[批量创建记录] ➕ 开始创建第 ${index + 1} 组, ${chunk.length} 条`);
385
385
 
386
386
  const pageRes = await functionLimiter(async () => {
387
387
  const res = await this.object.create.records({
@@ -393,9 +393,9 @@ class Client {
393
393
  results = results.concat(res.data.items);
394
394
  }
395
395
 
396
- this.log(LoggerLevel.info, `[批量创建记录] ➕ 创建第 ${page} 页数据,调用完成,创建数量: ${res.data.items.length}`);
397
- this.log(LoggerLevel.debug, `[批量创建记录] ➕ 创建第 ${page} 页页数据,调用完成,返回状态: ${res.data.code}`);
398
- this.log(LoggerLevel.trace, `[批量创建记录] ➕ 创建第 ${page} 页页数据,调用结果: ${JSON.stringify(res.data.items)}`);
396
+ this.log(LoggerLevel.info, `[批量创建记录] ➕ 创建 object_name=${object_name}, 第 ${page} 页数据, 调用完成, 创建数量: ${res.data.items.length}`);
397
+ this.log(LoggerLevel.debug, `[批量创建记录] ➕ 创建 object_name=${object_name}, 第 ${page} 页页数据, 调用完成, 返回状态: ${res.data.code}`);
398
+ this.log(LoggerLevel.trace, `[批量创建记录] ➕ 创建 object_name=${object_name}, 第 ${page} 页页数据, 调用结果: ${JSON.stringify(res.data.items)}`);
399
399
 
400
400
  return res;
401
401
  });
@@ -422,9 +422,9 @@ class Client {
422
422
 
423
423
  const response = await this.axiosInstance.patch(url, { record }, { headers: { Authorization: `${this.accessToken}` } });
424
424
 
425
- this.log(LoggerLevel.info, `[单条更新记录] 💾 更新 record_id: ${record_id} 调用完成`);
426
- this.log(LoggerLevel.debug, `[单条更新记录] 💾 更新 record_id: ${record_id} 调用完成,返回状态: ${response.data.code}`);
427
- this.log(LoggerLevel.trace, `[单条更新记录] 💾 更新 record_id: ${record_id} 调用完成,返回信息: ${JSON.stringify(response.data)}`);
425
+ this.log(LoggerLevel.info, `[单条更新记录] 💾 更新 object_name=${object_name}, record_id: ${record_id} 调用完成`);
426
+ this.log(LoggerLevel.debug, `[单条更新记录] 💾 更新 object_name=${object_name}, record_id: ${record_id} 调用完成, 返回状态: ${response.data.code}`);
427
+ this.log(LoggerLevel.trace, `[单条更新记录] 💾 更新 object_name=${object_name}, record_id: ${record_id} 调用完成, 返回信息: ${JSON.stringify(response.data)}`);
428
428
  return response.data;
429
429
  });
430
430
 
@@ -446,21 +446,21 @@ class Client {
446
446
  chunks.push(records.slice(i, i + chunkSize));
447
447
  }
448
448
 
449
- this.log(LoggerLevel.debug, `[批量更新记录] 💾 总共 ${records.length} 条记录,拆分为 ${chunks.length} 组,每组最多 ${chunkSize} 条`);
450
- this.log(LoggerLevel.trace, `[批量更新记录] 💾 总共 ${records.length} 条记录,拆分为 ${chunks.length} 组,每组最多 ${chunkSize} 条`);
449
+ this.log(LoggerLevel.debug, `[批量更新记录] 💾 总共 ${records.length} 条记录, 拆分为 ${chunks.length} 组, 每组最多 ${chunkSize} 条`);
450
+ this.log(LoggerLevel.trace, `[批量更新记录] 💾 总共 ${records.length} 条记录, 拆分为 ${chunks.length} 组, 每组最多 ${chunkSize} 条`);
451
451
 
452
452
  const results: any[] = [];
453
453
  for (const [index, chunk] of chunks.entries()) {
454
- this.log(LoggerLevel.debug, `[批量更新记录] 💾 开始更新第 ${index + 1} 组,共 ${chunk.length} 条`);
455
- this.log(LoggerLevel.trace, `[批量更新记录] 💾 开始更新第 ${index + 1} 组,共 ${chunk.length} 条`);
454
+ this.log(LoggerLevel.debug, `[批量更新记录] 💾 开始更新第 ${index + 1} 组, ${chunk.length} 条`);
455
+ this.log(LoggerLevel.trace, `[批量更新记录] 💾 开始更新第 ${index + 1} 组, ${chunk.length} 条`);
456
456
 
457
457
  const res = await functionLimiter(async () => {
458
458
  await this.ensureTokenValid();
459
459
 
460
460
  const response = await this.axiosInstance.patch(url, { records: chunk }, { headers: { Authorization: `${this.accessToken}` } });
461
461
 
462
- this.log(LoggerLevel.debug, `[批量更新记录] 💾 更新第 ${index + 1} 组调用完成,返回状态: ${JSON.stringify(response.data)}`);
463
- this.log(LoggerLevel.trace, `[批量更新记录] 💾 更新第 ${index + 1} 组调用完成,返回信息: ${response.data}`);
462
+ this.log(LoggerLevel.debug, `[批量更新记录] 💾 更新 object_name=${object_name}, 第 ${index + 1} 组调用完成, 返回状态: ${JSON.stringify(response.data)}`);
463
+ this.log(LoggerLevel.trace, `[批量更新记录] 💾 更新 object_name=${object_name}, 第 ${index + 1} 组调用完成, 返回信息: ${response.data}`);
464
464
  return response.data;
465
465
  });
466
466
 
@@ -481,7 +481,7 @@ class Client {
481
481
  const { object_name, record_id } = params;
482
482
  const url = `/v1/data/namespaces/${this.namespace}/objects/${object_name}/records/${record_id}`;
483
483
 
484
- this.log(LoggerLevel.trace, `[单条删除记录] 🗑️ 开始删除 record_id: ${record_id}`);
484
+ this.log(LoggerLevel.trace, `[单条删除记录] 🗑️ object_name=${object_name}, 开始删除 record_id: ${record_id}`);
485
485
 
486
486
  const res = await functionLimiter(async () => {
487
487
  await this.ensureTokenValid();
@@ -490,7 +490,7 @@ class Client {
490
490
  headers: { Authorization: `${this.accessToken}` }
491
491
  });
492
492
 
493
- this.log(LoggerLevel.info, `[单条删除记录] 🗑️ 删除 record_id: ${record_id} 调用完成,返回信息: ${JSON.stringify(response.data)}`);
493
+ this.log(LoggerLevel.info, `[单条删除记录] 🗑️ 删除 object_name=${object_name}, record_id: ${record_id} 调用完成, 返回信息: ${JSON.stringify(response.data)}`);
494
494
  return response.data;
495
495
  });
496
496
 
@@ -512,11 +512,11 @@ class Client {
512
512
  chunks.push(ids.slice(i, i + chunkSize));
513
513
  }
514
514
 
515
- this.log(LoggerLevel.debug, `[批量删除记录] 🗑️ 总共 ${ids.length} 条记录,拆分为 ${chunks.length} 组,每组最多 ${chunkSize} 条`);
515
+ this.log(LoggerLevel.debug, `[批量删除记录] 🗑️ 总共 ${ids.length} 条记录, 拆分为 ${chunks.length} 组, 每组最多 ${chunkSize} 条`);
516
516
 
517
517
  const results: any[] = [];
518
518
  for (const [index, chunk] of chunks.entries()) {
519
- this.log(LoggerLevel.info, `[批量删除记录] 🗑️ 开始删除第 ${index + 1} 组,共 ${chunk.length} 条`);
519
+ this.log(LoggerLevel.info, `[批量删除记录] 🗑️ 开始删除第 ${index + 1} 组, ${chunk.length} 条`);
520
520
 
521
521
  const res = await functionLimiter(async () => {
522
522
  await this.ensureTokenValid();
@@ -526,8 +526,8 @@ class Client {
526
526
  data: { ids: chunk }
527
527
  });
528
528
 
529
- this.log(LoggerLevel.debug, `[批量删除记录] 🗑️ 第 ${index + 1} 组删除完成,返回状态: ${response.data.code}`);
530
- this.log(LoggerLevel.trace, `[批量删除记录] 🗑️ 第 ${index + 1} 组删除完成,返回信息: ${JSON.stringify(response.data)}`);
529
+ this.log(LoggerLevel.debug, `[批量删除记录] 🗑️ 第 ${index + 1} 组删除完成, 返回状态: ${response.data.code}`);
530
+ this.log(LoggerLevel.trace, `[批量删除记录] 🗑️ 第 ${index + 1} 组删除完成, 返回信息: ${JSON.stringify(response.data)}`);
531
531
  return response.data;
532
532
  });
533
533
 
@@ -552,7 +552,7 @@ class Client {
552
552
  const { department_id_type, department_id } = params;
553
553
  // department_id_type 可选值:
554
554
  // - 'department_id' (如 "1758534140403815")
555
- // - 'external_department_id' (外部平台 department_id,无固定格式)
555
+ // - 'external_department_id' (外部平台 department_id, 无固定格式)
556
556
  // - 'external_open_department_id' (以 'oc_' 开头的 open_department_id)
557
557
 
558
558
  const url = '/api/integration/v2/feishu/getDepartments';
@@ -573,8 +573,8 @@ class Client {
573
573
  }
574
574
  );
575
575
 
576
- this.log(LoggerLevel.debug, `[部门ID交换] 🔄 交换部门 ID: ${department_id} 调用完成,返回状态: ${response.data.code}`);
577
- this.log(LoggerLevel.debug, `[部门ID交换] 🔄 交换部门 ID: ${department_id} 调用完成,返回信息: ${JSON.stringify(response.data)}`);
576
+ this.log(LoggerLevel.debug, `[部门ID交换] 🔄 交换部门 ID: ${department_id} 调用完成, 返回状态: ${response.data.code}`);
577
+ this.log(LoggerLevel.debug, `[部门ID交换] 🔄 交换部门 ID: ${department_id} 调用完成, 返回信息: ${JSON.stringify(response.data)}`);
578
578
  return response.data.data[0]; // 返回第一个元素
579
579
  });
580
580
 
@@ -590,7 +590,7 @@ class Client {
590
590
  const { department_id_type, department_ids } = params;
591
591
  // department_id_type 可选值:
592
592
  // - 'department_id' (如 "1758534140403815")
593
- // - 'external_department_id' (外部平台 department_id,无固定格式)
593
+ // - 'external_department_id' (外部平台 department_id, 无固定格式)
594
594
  // - 'external_open_department_id' (以 'oc_' 开头的 open_department_id)
595
595
 
596
596
  const url = '/api/integration/v2/feishu/getDepartments';
@@ -601,11 +601,11 @@ class Client {
601
601
  chunks.push(department_ids.slice(i, i + chunkSize));
602
602
  }
603
603
 
604
- this.log(LoggerLevel.info, `[批量部门ID交换] 🔄 总共 ${department_ids.length} 个部门 ID,拆分为 ${chunks.length} 组,每组最多 ${chunkSize} 个`);
604
+ this.log(LoggerLevel.info, `[批量部门ID交换] 🔄 总共 ${department_ids.length} 个部门 ID, 拆分为 ${chunks.length} 组, 每组最多 ${chunkSize} 个`);
605
605
 
606
606
  const results: any[] = [];
607
607
  for (const [index, chunk] of chunks.entries()) {
608
- this.log(LoggerLevel.info, `[批量部门ID交换] 🔄 开始交换第 ${index + 1} 组,共 ${chunk.length} 个`);
608
+ this.log(LoggerLevel.info, `[批量部门ID交换] 🔄 开始交换第 ${index + 1} 组, ${chunk.length} 个`);
609
609
 
610
610
  const res = await functionLimiter(async () => {
611
611
  await this.ensureTokenValid();
@@ -621,8 +621,8 @@ class Client {
621
621
  }
622
622
  );
623
623
 
624
- this.log(LoggerLevel.debug, `[批量部门ID交换] 🔄 交换第 ${index + 1} 组调用完成,返回状态: ${response.data.code}`);
625
- this.log(LoggerLevel.trace, `[批量部门ID交换] 🔄 交换第 ${index + 1} 组调用完成,返回信息: ${JSON.stringify(response.data)}`);
624
+ this.log(LoggerLevel.debug, `[批量部门ID交换] 🔄 交换第 ${index + 1} 组调用完成, 返回状态: ${response.data.code}`);
625
+ this.log(LoggerLevel.trace, `[批量部门ID交换] 🔄 交换第 ${index + 1} 组调用完成, 返回信息: ${JSON.stringify(response.data)}`);
626
626
  return response.data.data;
627
627
  });
628
628
 
@@ -661,8 +661,8 @@ class Client {
661
661
  }
662
662
  );
663
663
 
664
- this.log(LoggerLevel.debug, `[调用云函数] ☁️ 云函数 ${name} 调用完成,返回状态: code=${res.data.code}`);
665
- this.log(LoggerLevel.trace, `[调用云函数] ☁️ 云函数 ${name} 调用完成,返回信息: code=${JSON.stringify(res.data)}`);
664
+ this.log(LoggerLevel.debug, `[调用云函数] ☁️ 云函数 ${name} 调用完成, 返回状态: code=${res.data.code}`);
665
+ this.log(LoggerLevel.trace, `[调用云函数] ☁️ 云函数 ${name} 调用完成, 返回信息: code=${JSON.stringify(res.data)}`);
666
666
 
667
667
  return res.data;
668
668
  }