apaas-oapi-client 0.1.15 → 0.1.17

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/src/index.ts CHANGED
@@ -56,7 +56,7 @@ class Client {
56
56
  baseURL: 'https://ae-openapi.feishu.cn',
57
57
  headers: { 'Content-Type': 'application/json' }
58
58
  });
59
- this.log(LoggerLevel.info, '[client] initialized');
59
+ this.log(LoggerLevel.info, '[client] Client initialized successfully');
60
60
  }
61
61
 
62
62
  /**
@@ -65,7 +65,7 @@ class Client {
65
65
  */
66
66
  setLoggerLevel(level: LoggerLevel) {
67
67
  this.loggerLevel = level;
68
- this.log(LoggerLevel.info, `[logger] logger level set to ${LoggerLevel[level]}`);
68
+ this.log(LoggerLevel.info, `[logger] Log level set to ${LoggerLevel[level]}`);
69
69
  }
70
70
 
71
71
  /**
@@ -86,7 +86,7 @@ class Client {
86
86
  */
87
87
  async init() {
88
88
  await this.ensureTokenValid();
89
- this.log(LoggerLevel.info, '[client] ready');
89
+ this.log(LoggerLevel.info, '[client] Client initialized and ready');
90
90
  }
91
91
 
92
92
  /**
@@ -100,13 +100,13 @@ class Client {
100
100
  });
101
101
 
102
102
  if (res.data.code !== '0') {
103
- this.log(LoggerLevel.error, `[fetch token] 获取 accessToken 失败: ${res.data.msg}`);
103
+ this.log(LoggerLevel.error, `[auth] Failed to fetch access token: ${res.data.msg}`);
104
104
  throw new Error(`获取 accessToken 失败: ${res.data.msg}`);
105
105
  }
106
106
 
107
107
  this.accessToken = res.data.data.accessToken;
108
108
  this.expireTime = res.data.data.expireTime;
109
- this.log(LoggerLevel.info, '[client] token refreshed');
109
+ this.log(LoggerLevel.info, '[auth] Access token refreshed successfully');
110
110
  }
111
111
 
112
112
  /**
@@ -114,20 +114,20 @@ class Client {
114
114
  */
115
115
  private async ensureTokenValid() {
116
116
  if (this.disableTokenCache) {
117
- this.log(LoggerLevel.debug, '[client] token cache disabled, refreshing token');
117
+ this.log(LoggerLevel.debug, '[auth] Token cache disabled, refreshing token');
118
118
  await this.getAccessToken();
119
119
  return;
120
120
  }
121
121
 
122
122
  if (!this.accessToken || !this.expireTime) {
123
- this.log(LoggerLevel.debug, '[client] no token cached, fetching new token');
123
+ this.log(LoggerLevel.debug, '[auth] No token cached, fetching new token');
124
124
  await this.getAccessToken();
125
125
  return;
126
126
  }
127
127
 
128
128
  const now = dayjs().valueOf();
129
129
  if (now + 60 * 1000 > this.expireTime) {
130
- this.log(LoggerLevel.debug, '[client] token expired, refreshing');
130
+ this.log(LoggerLevel.debug, '[auth] Token expired, refreshing');
131
131
  await this.getAccessToken();
132
132
  }
133
133
  }
@@ -145,7 +145,7 @@ class Client {
145
145
  */
146
146
  get tokenExpireTime() {
147
147
  if (!this.accessToken || !this.expireTime) {
148
- this.log(LoggerLevel.warn, '[client] no valid token');
148
+ this.log(LoggerLevel.warn, '[auth] No valid token available');
149
149
  return null;
150
150
  }
151
151
 
@@ -153,13 +153,13 @@ class Client {
153
153
  const remainMs = this.expireTime - now;
154
154
 
155
155
  if (remainMs <= 0) {
156
- this.log(LoggerLevel.warn, '[client] token expired');
156
+ this.log(LoggerLevel.warn, '[auth] Token has expired');
157
157
  return 0;
158
158
  }
159
159
 
160
160
  const remainSeconds = Math.floor(remainMs / 1000);
161
- this.log(LoggerLevel.debug, `[client] token expire time: ${remainSeconds} seconds remaining`);
162
- this.log(LoggerLevel.trace, `[client] token expire time: ${remainSeconds} seconds remaining, expireTime=${this.expireTime}, now=${now}`);
161
+ this.log(LoggerLevel.debug, `[auth] Token expires in ${remainSeconds} seconds`);
162
+ this.log(LoggerLevel.trace, `[auth] Token expiry details: remaining=${remainSeconds}s, expireTime=${this.expireTime}, now=${now}`);
163
163
  return remainSeconds;
164
164
  }
165
165
 
@@ -167,7 +167,7 @@ class Client {
167
167
  * 获取当前 namespace
168
168
  */
169
169
  get currentNamespace() {
170
- this.log(LoggerLevel.debug, `🏷️ [获取命名空间] 当前命名空间: ${this.namespace}`);
170
+ this.log(LoggerLevel.debug, `[namespace] Current namespace: ${this.namespace}`);
171
171
  return this.namespace;
172
172
  }
173
173
 
@@ -175,6 +175,32 @@ class Client {
175
175
  * 对象模块
176
176
  */
177
177
  public object = {
178
+ /**
179
+ * 列出所有对象(数据表)
180
+ * @param params 请求参数 { offset, filter?, limit }
181
+ * @returns 接口返回结果
182
+ */
183
+ list: async (params: { offset: number; filter?: { type?: string; quickQuery?: string }; limit: number }): Promise<any> => {
184
+ const { offset, filter, limit } = params;
185
+ await this.ensureTokenValid();
186
+ const url = `/api/data/v1/namespaces/${this.namespace}/meta/objects/list`;
187
+
188
+ this.log(LoggerLevel.debug, `[object.list] Fetching objects list: offset=${offset}, limit=${limit}`);
189
+
190
+ const requestData: any = { offset, limit };
191
+ if (filter) {
192
+ requestData.filter = filter;
193
+ }
194
+
195
+ const res = await this.axiosInstance.post(url, requestData, {
196
+ headers: { Authorization: `${this.accessToken}` }
197
+ });
198
+
199
+ this.log(LoggerLevel.debug, `[object.list] Objects list fetched successfully: code=${res.data.code}`);
200
+ this.log(LoggerLevel.trace, `[object.list] Response: ${JSON.stringify(res.data)}`);
201
+ return res.data;
202
+ },
203
+
178
204
  metadata: {
179
205
  /**
180
206
  * 获取指定对象下指定字段的元数据
@@ -187,14 +213,14 @@ class Client {
187
213
  await this.ensureTokenValid();
188
214
  const url = `/api/data/v1/namespaces/${this.namespace}/meta/objects/${object_name}/fields/${field_name}`;
189
215
 
190
- this.log(LoggerLevel.debug, `[对象字段查询] 📄 开始获取字段元数据, object_name=${object_name}, field_name=${field_name}`);
216
+ this.log(LoggerLevel.debug, `[object.metadata.field] Fetching field metadata: ${object_name}.${field_name}`);
191
217
 
192
218
  const res = await this.axiosInstance.get(url, {
193
219
  headers: { Authorization: `${this.accessToken}` }
194
220
  });
195
221
 
196
- this.log(LoggerLevel.debug, `[对象字段查询] 📄 object_name=${object_name}, field_name=${field_name}, 调用完成, 返回状态=${res.data.code}`);
197
- this.log(LoggerLevel.trace, `[对象字段查询] 📄 object_name=${object_name}, field_name=${field_name}, 返回信息=${JSON.stringify(res.data)}`);
222
+ this.log(LoggerLevel.debug, `[object.metadata.field] Field metadata fetched: ${object_name}.${field_name}, code=${res.data.code}`);
223
+ this.log(LoggerLevel.trace, `[object.metadata.field] Response: ${JSON.stringify(res.data)}`);
198
224
  return res.data;
199
225
  },
200
226
 
@@ -209,14 +235,14 @@ class Client {
209
235
  await this.ensureTokenValid();
210
236
  const url = `/api/data/v1/namespaces/${this.namespace}/meta/objects/${object_name}`;
211
237
 
212
- this.log(LoggerLevel.debug, `[对象字段查询] 📄 开始获取对象字段元数据 object_name=${object_name}`);
238
+ this.log(LoggerLevel.debug, `[object.metadata.fields] Fetching all fields metadata: ${object_name}`);
213
239
 
214
240
  const res = await this.axiosInstance.get(url, {
215
241
  headers: { Authorization: `${this.accessToken}` }
216
242
  });
217
243
 
218
- this.log(LoggerLevel.debug, `[对象字段查询] 📄 object_name=${object_name}, 调用完成, 返回状态=${res.data.code}`);
219
- this.log(LoggerLevel.trace, `[对象字段查询] 📄 object_name=${object_name}, 调用完成, 返回信息=${JSON.stringify(res.data)}`);
244
+ this.log(LoggerLevel.debug, `[object.metadata.fields] All fields metadata fetched: ${object_name}, code=${res.data.code}`);
245
+ this.log(LoggerLevel.trace, `[object.metadata.fields] Response: ${JSON.stringify(res.data)}`);
220
246
  return res.data;
221
247
  }
222
248
  },
@@ -232,15 +258,15 @@ class Client {
232
258
  const { object_name, record_id, select } = params;
233
259
  const url = `/v1/data/namespaces/${this.namespace}/objects/${object_name}/records/${record_id}`;
234
260
 
235
- this.log(LoggerLevel.info, `[单条查询记录] 🔍 开始查询 record_id: ${record_id}`);
261
+ this.log(LoggerLevel.info, `[object.search.record] Querying record: ${record_id}`);
236
262
 
237
263
  const res = await functionLimiter(async () => {
238
264
  await this.ensureTokenValid();
239
265
 
240
266
  const response = await this.axiosInstance.post(url, { select }, { headers: { Authorization: `${this.accessToken}` } });
241
267
 
242
- this.log(LoggerLevel.debug, `[单条查询记录] 🔍 查询 object_name=${object_name}, record_id: ${record_id} 调用完成, 返回状态: ${response.data.code}`);
243
- this.log(LoggerLevel.trace, `[单条查询记录] 🔍 查询 object_name=${object_name}, record_id: ${record_id} 调用完成, 返回信息: ${JSON.stringify(response.data)}`);
268
+ this.log(LoggerLevel.debug, `[object.search.record] Record queried: ${object_name}.${record_id}, code=${response.data.code}`);
269
+ this.log(LoggerLevel.trace, `[object.search.record] Response: ${JSON.stringify(response.data)}`);
244
270
 
245
271
  return response.data;
246
272
  });
@@ -264,9 +290,8 @@ class Client {
264
290
  headers: { Authorization: `${this.accessToken}` }
265
291
  });
266
292
 
267
- this.log(LoggerLevel.info, `[批量查询记录] 🔍 接口调用完成`);
268
- this.log(LoggerLevel.debug, `[批量查询记录] 🔍 查询 object_name=${object_name}, 调用完成, 返回状态: ${res.data.code}, 返回数据总数${res.data?.data?.total || 'unknown'}`);
269
- this.log(LoggerLevel.trace, `[批量查询记录] 🔍 查询 object_name=${object_name}, 调用完成, 返回信息: ${JSON.stringify(res.data)}`);
293
+ this.log(LoggerLevel.debug, `[object.search.records] Records queried: ${object_name}, code=${res.data.code}, total=${res.data?.data?.total || 'unknown'}`);
294
+ this.log(LoggerLevel.trace, `[object.search.records] Response: ${JSON.stringify(res.data)}`);
270
295
  return res.data;
271
296
  },
272
297
 
@@ -305,7 +330,7 @@ class Client {
305
330
  if (page === 1) {
306
331
  total = res.data.total || 0;
307
332
  totalPages = Math.ceil(total / pageSize);
308
- this.log(LoggerLevel.info, `[批量查询记录] 🔍 查询 object_name=${object_name}, 接口返回 total=${total}, 预计 ${totalPages} 页`);
333
+ this.log(LoggerLevel.info, `[object.search.recordsWithIterator] Starting paginated query: ${object_name}, total=${total}, pages=${totalPages}`);
309
334
  }
310
335
 
311
336
  nextPageToken = res.data.next_page_token;
@@ -314,10 +339,9 @@ class Client {
314
339
  const pageStr = page.toString().padStart(padLength, '0');
315
340
  const totalPagesStr = totalPages.toString().padStart(padLength, '0');
316
341
 
317
- this.log(LoggerLevel.info, `[批量查询记录] 🔍 [${pageStr}/${totalPagesStr}] 接口调用完成`);
318
- this.log(LoggerLevel.debug, `[批量查询记录] 🔍 ${page} 页查询, nextPageToken: ${nextPageToken || ''}`);
319
- this.log(LoggerLevel.debug, `[批量查询记录] 🔍 ${page} 页查询完成, items.length: ${res.data.items?.length}`);
320
- this.log(LoggerLevel.trace, `[批量查询记录] 🔍 第 ${page} 页查询结果: ${JSON.stringify(res.data?.items)}`);
342
+ this.log(LoggerLevel.info, `[object.search.recordsWithIterator] Page completed: [${pageStr}/${totalPagesStr}]`);
343
+ this.log(LoggerLevel.debug, `[object.search.recordsWithIterator] Page ${page} details: items=${res.data.items?.length}, nextToken=${nextPageToken || 'none'}`);
344
+ this.log(LoggerLevel.trace, `[object.search.recordsWithIterator] Page ${page} data: ${JSON.stringify(res.data?.items)}`);
321
345
 
322
346
  return res;
323
347
  });
@@ -338,7 +362,7 @@ class Client {
338
362
  const { object_name, record } = params;
339
363
  const url = `/v1/data/namespaces/${this.namespace}/objects/${object_name}/records`;
340
364
 
341
- this.log(LoggerLevel.info, `[单条创建记录] 开始向对象 ${object_name} 创建记录`);
365
+ this.log(LoggerLevel.info, `[object.create.record] Creating record in: ${object_name}`);
342
366
 
343
367
  const res = await functionLimiter(async () => {
344
368
  await this.ensureTokenValid();
@@ -351,9 +375,9 @@ class Client {
351
375
  }
352
376
  );
353
377
 
354
- this.log(LoggerLevel.info, `[单条创建记录] 向对象 ${object_name} 内创建记录, 调用完成`);
355
- this.log(LoggerLevel.debug, `[单条创建记录] 向对象 ${object_name} 内创建数据, 调用完成, 返回状态: ${response.data.code}`);
356
- this.log(LoggerLevel.trace, `[单条创建记录] 向对象 ${object_name} 内创建数据, 调用完成, 返回信息: ${JSON.stringify(response.data)}`);
378
+ this.log(LoggerLevel.info, `[object.create.record] Record created: ${object_name}`);
379
+ this.log(LoggerLevel.debug, `[object.create.record] Record created: ${object_name}, code=${response.data.code}`);
380
+ this.log(LoggerLevel.trace, `[object.create.record] Response: ${JSON.stringify(response.data)}`);
357
381
 
358
382
  return response.data;
359
383
  });
@@ -381,9 +405,9 @@ class Client {
381
405
  }
382
406
  );
383
407
 
384
- this.log(LoggerLevel.info, `[批量创建记录] 开始向对象 ${object_name} 批量创建记录`);
385
- this.log(LoggerLevel.debug, `[批量创建记录] 向对象 ${object_name} 批量创建记录, 调用完成, 返回状态: ${res.data.code}`);
386
- this.log(LoggerLevel.trace, `[批量创建记录] 向对象 ${object_name} 批量创建记录, 调用完成, 返回信息: ${JSON.stringify(res.data)}`);
408
+ this.log(LoggerLevel.info, `[object.create.records] Creating ${records.length} records in: ${object_name}`);
409
+ this.log(LoggerLevel.debug, `[object.create.records] Records created: ${object_name}, code=${res.data.code}`);
410
+ this.log(LoggerLevel.trace, `[object.create.records] Response: ${JSON.stringify(res.data)}`);
387
411
  return res.data;
388
412
  },
389
413
 
@@ -406,14 +430,12 @@ class Client {
406
430
  chunks.push(records.slice(i, i + chunkSize));
407
431
  }
408
432
 
409
- this.log(LoggerLevel.debug, `[批量创建记录] 总共 ${records.length} 条记录, 拆分为 ${chunks.length} 组, 每组最多 ${chunkSize} 条`);
410
- this.log(LoggerLevel.trace, `[批量创建记录] ➕ 总共 ${records.length} 条记录, 拆分为 ${chunks.length} 组, 每组最多 ${chunkSize} 条`);
433
+ this.log(LoggerLevel.debug, `[object.create.recordsWithIterator] Chunking ${records.length} records into ${chunks.length} groups of ${chunkSize}`);
411
434
 
412
435
  for (const [index, chunk] of chunks.entries()) {
413
436
  page += 1;
414
437
 
415
- this.log(LoggerLevel.debug, `[批量创建记录] 开始创建第 ${index + 1} 组, 共 ${chunk.length} 条`);
416
- this.log(LoggerLevel.trace, `[批量创建记录] ➕ 开始创建第 ${index + 1} 组, 共 ${chunk.length} 条`);
438
+ this.log(LoggerLevel.debug, `[object.create.recordsWithIterator] Processing chunk ${index + 1}/${chunks.length}: ${chunk.length} records`);
417
439
 
418
440
  const pageRes = await functionLimiter(async () => {
419
441
  const res = await this.object.create.records({
@@ -425,9 +447,9 @@ class Client {
425
447
  results = results.concat(res.data.items);
426
448
  }
427
449
 
428
- this.log(LoggerLevel.info, `[批量创建记录] 创建 object_name=${object_name}, ${page} 页数据, 调用完成, 创建数量: ${res.data.items.length}`);
429
- this.log(LoggerLevel.debug, `[批量创建记录] 创建 object_name=${object_name}, ${page} 页页数据, 调用完成, 返回状态: ${res.data.code}`);
430
- this.log(LoggerLevel.trace, `[批量创建记录] 创建 object_name=${object_name}, 第 ${page} 页页数据, 调用结果: ${JSON.stringify(res.data.items)}`);
450
+ this.log(LoggerLevel.info, `[object.create.recordsWithIterator] Chunk ${page} completed: ${object_name}, created=${res.data.items.length}`);
451
+ this.log(LoggerLevel.debug, `[object.create.recordsWithIterator] Chunk ${page} result: ${object_name}, code=${res.data.code}`);
452
+ this.log(LoggerLevel.trace, `[object.create.recordsWithIterator] Chunk ${page} data: ${JSON.stringify(res.data.items)}`);
431
453
 
432
454
  return res;
433
455
  });
@@ -448,16 +470,16 @@ class Client {
448
470
  const { object_name, record_id, record } = params;
449
471
  const url = `/v1/data/namespaces/${this.namespace}/objects/${object_name}/records/${record_id}`;
450
472
 
451
- this.log(LoggerLevel.info, `[单条更新记录] 💾 开始更新 record_id: ${record_id}`);
473
+ this.log(LoggerLevel.info, `[object.update.record] Updating record: ${record_id}`);
452
474
 
453
475
  const res = await functionLimiter(async () => {
454
476
  await this.ensureTokenValid();
455
477
 
456
478
  const response = await this.axiosInstance.patch(url, { record }, { headers: { Authorization: `${this.accessToken}` } });
457
479
 
458
- this.log(LoggerLevel.info, `[单条更新记录] 💾 更新 object_name=${object_name}, record_id: ${record_id} 调用完成`);
459
- this.log(LoggerLevel.debug, `[单条更新记录] 💾 更新 object_name=${object_name}, record_id: ${record_id} 调用完成, 返回状态: ${response.data.code}`);
460
- this.log(LoggerLevel.trace, `[单条更新记录] 💾 更新 object_name=${object_name}, record_id: ${record_id} 调用完成, 返回信息: ${JSON.stringify(response.data)}`);
480
+ this.log(LoggerLevel.info, `[object.update.record] Record updated: ${object_name}.${record_id}`);
481
+ this.log(LoggerLevel.debug, `[object.update.record] Record updated: ${object_name}.${record_id}, code=${response.data.code}`);
482
+ this.log(LoggerLevel.trace, `[object.update.record] Response: ${JSON.stringify(response.data)}`);
461
483
  return response.data;
462
484
  });
463
485
 
@@ -474,13 +496,13 @@ class Client {
474
496
  const { object_name, records } = params;
475
497
  const url = `/v1/data/namespaces/${this.namespace}/objects/${object_name}/records/records_batch`;
476
498
 
477
- this.log(LoggerLevel.info, `[多条更新记录] 💾 开始更新 ${records.length} 条数据`);
499
+ this.log(LoggerLevel.info, `[object.update.records] Updating ${records.length} records`);
478
500
 
479
501
  const response = await this.axiosInstance.patch(url, { records }, { headers: { Authorization: `${this.accessToken}` } });
480
502
 
481
- this.log(LoggerLevel.info, `[多条更新记录] 💾 更新 object_name=${object_name}, 调用完成`);
482
- this.log(LoggerLevel.debug, `[多条更新记录] 💾 更新 object_name=${object_name}, 调用完成, 返回状态: ${response.data.code}`);
483
- this.log(LoggerLevel.trace, `[多条更新记录] 💾 更新 object_name=${object_name}, 调用完成, 返回信息: ${JSON.stringify(response.data)}`);
503
+ this.log(LoggerLevel.info, `[object.update.records] Records updated: ${object_name}`);
504
+ this.log(LoggerLevel.debug, `[object.update.records] Records updated: ${object_name}, code=${response.data.code}`);
505
+ this.log(LoggerLevel.trace, `[object.update.records] Response: ${JSON.stringify(response.data)}`);
484
506
 
485
507
  return response.data;
486
508
  },
@@ -501,21 +523,19 @@ class Client {
501
523
  chunks.push(records.slice(i, i + chunkSize));
502
524
  }
503
525
 
504
- this.log(LoggerLevel.debug, `[批量更新记录] 💾 总共 ${records.length} 条记录, 拆分为 ${chunks.length} 组, 每组最多 ${chunkSize} 条`);
505
- this.log(LoggerLevel.trace, `[批量更新记录] 💾 总共 ${records.length} 条记录, 拆分为 ${chunks.length} 组, 每组最多 ${chunkSize} 条`);
526
+ this.log(LoggerLevel.debug, `[object.update.recordsWithIterator] Chunking ${records.length} records into ${chunks.length} groups of ${chunkSize}`);
506
527
 
507
528
  const results: any[] = [];
508
529
  for (const [index, chunk] of chunks.entries()) {
509
- this.log(LoggerLevel.debug, `[批量更新记录] 💾 开始更新第 ${index + 1} 组, 共 ${chunk.length} 条`);
510
- this.log(LoggerLevel.trace, `[批量更新记录] 💾 开始更新第 ${index + 1} 组, 共 ${chunk.length} 条`);
530
+ this.log(LoggerLevel.debug, `[object.update.recordsWithIterator] Processing chunk ${index + 1}/${chunks.length}: ${chunk.length} records`);
511
531
 
512
532
  const res = await functionLimiter(async () => {
513
533
  await this.ensureTokenValid();
514
534
 
515
535
  const response = await this.axiosInstance.patch(url, { records: chunk }, { headers: { Authorization: `${this.accessToken}` } });
516
536
 
517
- this.log(LoggerLevel.debug, `[批量更新记录] 💾 更新 object_name=${object_name}, 第 ${index + 1} 组调用完成, 返回状态: ${JSON.stringify(response.data)}`);
518
- this.log(LoggerLevel.trace, `[批量更新记录] 💾 更新 object_name=${object_name}, 第 ${index + 1} 组调用完成, 返回信息: ${response.data}`);
537
+ this.log(LoggerLevel.debug, `[object.update.recordsWithIterator] Chunk ${index + 1} completed: ${object_name}, code=${response.data.code}`);
538
+ this.log(LoggerLevel.trace, `[object.update.recordsWithIterator] Chunk ${index + 1} response: ${JSON.stringify(response.data)}`);
519
539
  return response.data;
520
540
  });
521
541
 
@@ -537,7 +557,7 @@ class Client {
537
557
  const { object_name, record_id } = params;
538
558
  const url = `/v1/data/namespaces/${this.namespace}/objects/${object_name}/records/${record_id}`;
539
559
 
540
- this.log(LoggerLevel.trace, `[单条删除记录] 🗑️ object_name=${object_name}, 开始删除 record_id: ${record_id}`);
560
+ this.log(LoggerLevel.info, `[object.delete.record] Deleting record: ${object_name}.${record_id}`);
541
561
 
542
562
  const res = await functionLimiter(async () => {
543
563
  await this.ensureTokenValid();
@@ -546,7 +566,9 @@ class Client {
546
566
  headers: { Authorization: `${this.accessToken}` }
547
567
  });
548
568
 
549
- this.log(LoggerLevel.info, `[单条删除记录] 🗑️ 删除 object_name=${object_name}, record_id: ${record_id} 调用完成, 返回信息: ${JSON.stringify(response.data)}`);
569
+ this.log(LoggerLevel.info, `[object.delete.record] Record deleted: ${object_name}.${record_id}`);
570
+ this.log(LoggerLevel.debug, `[object.delete.record] Record deleted: ${object_name}.${record_id}, code=${response.data.code}`);
571
+ this.log(LoggerLevel.trace, `[object.delete.record] Response: ${JSON.stringify(response.data)}`);
550
572
  return response.data;
551
573
  });
552
574
 
@@ -563,7 +585,7 @@ class Client {
563
585
  const { object_name, ids } = params;
564
586
  const url = `/v1/data/namespaces/${this.namespace}/objects/${object_name}/records_batch`;
565
587
 
566
- this.log(LoggerLevel.info, `[批量删除记录] 🗑️ 开始删除对象 ${object_name} ${ids.length} 条记录`);
588
+ this.log(LoggerLevel.info, `[object.delete.records] Deleting ${ids.length} records from: ${object_name}`);
567
589
 
568
590
  const res = await functionLimiter(async () => {
569
591
  await this.ensureTokenValid();
@@ -573,9 +595,9 @@ class Client {
573
595
  headers: { Authorization: `${this.accessToken}`, 'Content-Type': 'application/json' }
574
596
  });
575
597
 
576
- this.log(LoggerLevel.info, `[批量删除记录] 🗑️ 删除对象 ${object_name} 的 ${ids.length} 条记录记录, 调用完成`);
577
- this.log(LoggerLevel.debug, `[批量删除记录] 🗑️ 删除对象 ${object_name} 的 ${ids.length} 条记录记录, 调用完成,返回状态: ${response.data.code}`);
578
- this.log(LoggerLevel.trace, `[批量删除记录] 🗑️ 删除对象 ${object_name} 的 ${ids.length} 条记录记录, 调用完成,返回信息: ${JSON.stringify(response.data)}`);
598
+ this.log(LoggerLevel.info, `[object.delete.records] Records deleted: ${object_name}, count=${ids.length}`);
599
+ this.log(LoggerLevel.debug, `[object.delete.records] Records deleted: ${object_name}, count=${ids.length}, code=${response.data.code}`);
600
+ this.log(LoggerLevel.trace, `[object.delete.records] Response: ${JSON.stringify(response.data)}`);
579
601
 
580
602
  return response.data;
581
603
  });
@@ -599,11 +621,11 @@ class Client {
599
621
  chunks.push(ids.slice(i, i + chunkSize));
600
622
  }
601
623
 
602
- this.log(LoggerLevel.debug, `[批量删除记录] 🗑️ 总共 ${ids.length} 条记录, 拆分为 ${chunks.length} 组, 每组最多 ${chunkSize} 条`);
624
+ this.log(LoggerLevel.debug, `[object.delete.recordsWithIterator] Chunking ${ids.length} records into ${chunks.length} groups of ${chunkSize}`);
603
625
 
604
626
  const results: any[] = [];
605
627
  for (const [index, chunk] of chunks.entries()) {
606
- this.log(LoggerLevel.info, `[批量删除记录] 🗑️ 开始删除第 ${index + 1} 组, 共 ${chunk.length} 条`);
628
+ this.log(LoggerLevel.info, `[object.delete.recordsWithIterator] Processing chunk ${index + 1}/${chunks.length}: ${chunk.length} records`);
607
629
 
608
630
  const res = await functionLimiter(async () => {
609
631
  await this.ensureTokenValid();
@@ -613,8 +635,8 @@ class Client {
613
635
  data: { ids: chunk }
614
636
  });
615
637
 
616
- this.log(LoggerLevel.debug, `[批量删除记录] 🗑️ ${index + 1} 组删除完成, 返回状态: ${response.data.code}`);
617
- this.log(LoggerLevel.trace, `[批量删除记录] 🗑️ ${index + 1} 组删除完成, 返回信息: ${JSON.stringify(response.data)}`);
638
+ this.log(LoggerLevel.debug, `[object.delete.recordsWithIterator] Chunk ${index + 1} completed: code=${response.data.code}`);
639
+ this.log(LoggerLevel.trace, `[object.delete.recordsWithIterator] Chunk ${index + 1} response: ${JSON.stringify(response.data)}`);
618
640
  return response.data;
619
641
  });
620
642
 
@@ -644,7 +666,7 @@ class Client {
644
666
 
645
667
  const url = '/api/integration/v2/feishu/getDepartments';
646
668
 
647
- this.log(LoggerLevel.info, `[部门ID交换] 🔄 开始交换单个部门 ID: ${department_id}`);
669
+ this.log(LoggerLevel.info, `[department.exchange] Exchanging department ID: ${department_id}`);
648
670
 
649
671
  const res = await functionLimiter(async () => {
650
672
  await this.ensureTokenValid();
@@ -660,8 +682,8 @@ class Client {
660
682
  }
661
683
  );
662
684
 
663
- this.log(LoggerLevel.debug, `[部门ID交换] 🔄 交换部门 ID: ${department_id} 调用完成, 返回状态: ${response.data.code}`);
664
- this.log(LoggerLevel.debug, `[部门ID交换] 🔄 交换部门 ID: ${department_id} 调用完成, 返回信息: ${JSON.stringify(response.data)}`);
685
+ this.log(LoggerLevel.debug, `[department.exchange] Department ID exchanged: ${department_id}, code=${response.data.code}`);
686
+ this.log(LoggerLevel.trace, `[department.exchange] Response: ${JSON.stringify(response.data)}`);
665
687
  return response.data.data[0]; // 返回第一个元素
666
688
  });
667
689
 
@@ -688,11 +710,11 @@ class Client {
688
710
  chunks.push(department_ids.slice(i, i + chunkSize));
689
711
  }
690
712
 
691
- this.log(LoggerLevel.info, `[批量部门ID交换] 🔄 总共 ${department_ids.length} 个部门 ID, 拆分为 ${chunks.length} 组, 每组最多 ${chunkSize} 个`);
713
+ this.log(LoggerLevel.info, `[department.batchExchange] Chunking ${department_ids.length} department IDs into ${chunks.length} groups of ${chunkSize}`);
692
714
 
693
715
  const results: any[] = [];
694
716
  for (const [index, chunk] of chunks.entries()) {
695
- this.log(LoggerLevel.info, `[批量部门ID交换] 🔄 开始交换第 ${index + 1} 组, 共 ${chunk.length} 个`);
717
+ this.log(LoggerLevel.info, `[department.batchExchange] Processing chunk ${index + 1}/${chunks.length}: ${chunk.length} IDs`);
696
718
 
697
719
  const res = await functionLimiter(async () => {
698
720
  await this.ensureTokenValid();
@@ -708,8 +730,8 @@ class Client {
708
730
  }
709
731
  );
710
732
 
711
- this.log(LoggerLevel.debug, `[批量部门ID交换] 🔄 交换第 ${index + 1} 组调用完成, 返回状态: ${response.data.code}`);
712
- this.log(LoggerLevel.trace, `[批量部门ID交换] 🔄 交换第 ${index + 1} 组调用完成, 返回信息: ${JSON.stringify(response.data)}`);
733
+ this.log(LoggerLevel.debug, `[department.batchExchange] Chunk ${index + 1} completed: code=${response.data.code}`);
734
+ this.log(LoggerLevel.trace, `[department.batchExchange] Chunk ${index + 1} response: ${JSON.stringify(response.data)}`);
713
735
  return response.data.data;
714
736
  });
715
737
 
@@ -735,7 +757,7 @@ class Client {
735
757
 
736
758
  const url = `/api/cloudfunction/v1/namespaces/${this.namespace}/invoke/${name}`;
737
759
 
738
- this.log(LoggerLevel.info, `[调用云函数] ☁️ 云函数 ${name} 开始调用`);
760
+ this.log(LoggerLevel.info, `[function.invoke] Invoking cloud function: ${name}`);
739
761
 
740
762
  const res = await this.axiosInstance.post(
741
763
  url,
@@ -748,12 +770,534 @@ class Client {
748
770
  }
749
771
  );
750
772
 
751
- this.log(LoggerLevel.debug, `[调用云函数] ☁️ 云函数 ${name} 调用完成, 返回状态: code=${res.data.code}`);
752
- this.log(LoggerLevel.trace, `[调用云函数] ☁️ 云函数 ${name} 调用完成, 返回信息: code=${JSON.stringify(res.data)}`);
773
+ this.log(LoggerLevel.debug, `[function.invoke] Cloud function invoked: ${name}, code=${res.data.code}`);
774
+ this.log(LoggerLevel.trace, `[function.invoke] Response: ${JSON.stringify(res.data)}`);
775
+
776
+ return res.data;
777
+ }
778
+ };
779
+
780
+ /**
781
+ * 页面模块
782
+ */
783
+ public page = {
784
+ /**
785
+ * 获取所有页面
786
+ * @param params 请求参数 { limit: number (max 200), offset: number }
787
+ * @returns 接口返回结果
788
+ */
789
+ list: async (params: { limit: number; offset: number }): Promise<any> => {
790
+ const { limit, offset } = params;
791
+ await this.ensureTokenValid();
792
+
793
+ const url = `/api/builder/v1/namespaces/${this.namespace}/meta/pages`;
794
+
795
+ this.log(LoggerLevel.info, `[page.list] Fetching pages list: offset=${offset}, limit=${limit}`);
796
+
797
+ const res = await this.axiosInstance.post(
798
+ url,
799
+ { limit, offset },
800
+ {
801
+ headers: {
802
+ Authorization: `${this.accessToken}`,
803
+ 'Content-Type': 'application/json'
804
+ }
805
+ }
806
+ );
807
+
808
+ this.log(LoggerLevel.debug, `[page.list] Pages list fetched: code=${res.data.code}`);
809
+ this.log(LoggerLevel.trace, `[page.list] Response: ${JSON.stringify(res.data)}`);
810
+
811
+ return res.data;
812
+ },
813
+
814
+ /**
815
+ * 获取所有页面 - 支持自动分页,获取全部数据
816
+ * @description 该方法会自动处理分页,直到获取所有页面数据
817
+ * @param params 请求参数 { limit?: number }
818
+ * @returns { total, items }
819
+ */
820
+ listWithIterator: async (params?: { limit?: number }): Promise<{ total: number; items: any[] }> => {
821
+ const limit = params?.limit || 100;
822
+ let results: any[] = [];
823
+ let offset = 0;
824
+ let total = 0;
825
+ let page = 0;
826
+ let totalPages = 0;
827
+
828
+ do {
829
+ const pageRes = await functionLimiter(async () => {
830
+ const res = await this.page.list({ limit, offset });
831
+
832
+ page += 1;
833
+
834
+ if (res.data && Array.isArray(res.data.items)) {
835
+ results = results.concat(res.data.items);
836
+ }
837
+
838
+ if (page === 1) {
839
+ total = res.data.total || 0;
840
+ totalPages = Math.ceil(total / limit);
841
+ this.log(LoggerLevel.info, `[page.listWithIterator] Starting paginated query: total=${total}, pages=${totalPages}`);
842
+ }
843
+
844
+ offset += limit;
845
+
846
+ const padLength = totalPages.toString().length;
847
+ const pageStr = page.toString().padStart(padLength, '0');
848
+ const totalPagesStr = totalPages.toString().padStart(padLength, '0');
849
+
850
+ this.log(LoggerLevel.info, `[page.listWithIterator] Page completed: [${pageStr}/${totalPagesStr}]`);
851
+ this.log(LoggerLevel.debug, `[page.listWithIterator] Page ${page} details: items=${res.data.items?.length}, offset=${offset}`);
852
+ this.log(LoggerLevel.trace, `[page.listWithIterator] Page ${page} data: ${JSON.stringify(res.data?.items)}`);
853
+
854
+ return res;
855
+ });
856
+ } while (results.length < total);
857
+
858
+ return { total, items: results };
859
+ },
860
+
861
+ /**
862
+ * 获取页面详情
863
+ * @param params 请求参数 { page_id: string }
864
+ * @returns 接口返回结果
865
+ */
866
+ detail: async (params: { page_id: string }): Promise<any> => {
867
+ const { page_id } = params;
868
+ await this.ensureTokenValid();
869
+
870
+ const url = `/api/builder/v1/namespaces/${this.namespace}/meta/pages/${page_id}`;
871
+
872
+ this.log(LoggerLevel.info, `[page.detail] Fetching page detail: ${page_id}`);
873
+
874
+ const res = await this.axiosInstance.get(url, {
875
+ headers: {
876
+ Authorization: `${this.accessToken}`
877
+ }
878
+ });
879
+
880
+ this.log(LoggerLevel.debug, `[page.detail] Page detail fetched: ${page_id}, code=${res.data.code}`);
881
+ this.log(LoggerLevel.trace, `[page.detail] Response: ${JSON.stringify(res.data)}`);
882
+
883
+ return res.data;
884
+ },
885
+
886
+ /**
887
+ * 获取页面访问地址
888
+ * @param params 请求参数 { page_id: string, pageParams?: any, parentPageParams?: any, navId?: string, tabId?: string }
889
+ * @returns 接口返回结果
890
+ */
891
+ url: async (params: { page_id: string; pageParams?: any; parentPageParams?: any; navId?: string; tabId?: string }): Promise<any> => {
892
+ const { page_id, pageParams, parentPageParams, navId, tabId } = params;
893
+ await this.ensureTokenValid();
894
+
895
+ const url = `/api/builder/v1/namespaces/${this.namespace}/meta/pages/${page_id}/link`;
896
+
897
+ this.log(LoggerLevel.info, `[page.url] Fetching page URL: ${page_id}`);
898
+
899
+ const requestData: any = {};
900
+ if (pageParams) requestData.pageParams = pageParams;
901
+ if (parentPageParams) requestData.parentPageParams = parentPageParams;
902
+ if (navId) requestData.navId = navId;
903
+ if (tabId) requestData.tabId = tabId;
904
+
905
+ const res = await this.axiosInstance.post(url, requestData, {
906
+ headers: {
907
+ Authorization: `${this.accessToken}`,
908
+ 'Content-Type': 'application/json'
909
+ }
910
+ });
911
+
912
+ this.log(LoggerLevel.debug, `[page.url] Page URL fetched: ${page_id}, code=${res.data.code}`);
913
+ this.log(LoggerLevel.trace, `[page.url] Response: ${JSON.stringify(res.data)}`);
753
914
 
754
915
  return res.data;
755
916
  }
756
917
  };
918
+
919
+ /**
920
+ * 附件模块
921
+ */
922
+ public attachment = {
923
+ /**
924
+ * 文件操作
925
+ */
926
+ file: {
927
+ /**
928
+ * 上传文件
929
+ * @param params 请求参数 { file: any }
930
+ * @returns 接口返回结果
931
+ */
932
+ upload: async (params: { file: any }): Promise<any> => {
933
+ const { file } = params;
934
+ await this.ensureTokenValid();
935
+
936
+ const url = '/api/attachment/v1/files';
937
+
938
+ this.log(LoggerLevel.info, '[attachment.file.upload] Uploading file');
939
+
940
+ const FormData = require('form-data');
941
+ const formData = new FormData();
942
+ formData.append('file', file);
943
+
944
+ const res = await this.axiosInstance.post(url, formData, {
945
+ headers: {
946
+ Authorization: `${this.accessToken}`,
947
+ ...formData.getHeaders()
948
+ }
949
+ });
950
+
951
+ this.log(LoggerLevel.debug, `[attachment.file.upload] File uploaded: code=${res.data.code}`);
952
+ this.log(LoggerLevel.trace, `[attachment.file.upload] Response: ${JSON.stringify(res.data)}`);
953
+
954
+ return res.data;
955
+ },
956
+
957
+ /**
958
+ * 下载文件
959
+ * @param params 请求参数 { file_id: string }
960
+ * @returns 文件二进制流
961
+ */
962
+ download: async (params: { file_id: string }): Promise<any> => {
963
+ const { file_id } = params;
964
+ await this.ensureTokenValid();
965
+
966
+ const url = `/api/attachment/v1/files/${file_id}`;
967
+
968
+ this.log(LoggerLevel.info, `[attachment.file.download] Downloading file: ${file_id}`);
969
+
970
+ const res = await this.axiosInstance.get(url, {
971
+ headers: {
972
+ Authorization: `${this.accessToken}`
973
+ },
974
+ responseType: 'arraybuffer'
975
+ });
976
+
977
+ this.log(LoggerLevel.debug, `[attachment.file.download] File downloaded: ${file_id}`);
978
+
979
+ return res.data;
980
+ },
981
+
982
+ /**
983
+ * 删除文件
984
+ * @param params 请求参数 { file_id: string }
985
+ * @returns 接口返回结果
986
+ */
987
+ delete: async (params: { file_id: string }): Promise<any> => {
988
+ const { file_id } = params;
989
+ await this.ensureTokenValid();
990
+
991
+ const url = `/v1/files/${file_id}`;
992
+
993
+ this.log(LoggerLevel.info, `[attachment.file.delete] Deleting file: ${file_id}`);
994
+
995
+ const res = await this.axiosInstance.delete(url, {
996
+ headers: {
997
+ Authorization: `${this.accessToken}`
998
+ }
999
+ });
1000
+
1001
+ this.log(LoggerLevel.debug, `[attachment.file.delete] File deleted: ${file_id}, code=${res.data.code}`);
1002
+ this.log(LoggerLevel.trace, `[attachment.file.delete] Response: ${JSON.stringify(res.data)}`);
1003
+
1004
+ return res.data;
1005
+ }
1006
+ },
1007
+
1008
+ /**
1009
+ * 头像图片操作
1010
+ */
1011
+ avatar: {
1012
+ /**
1013
+ * 上传头像图片
1014
+ * @param params 请求参数 { image: any }
1015
+ * @returns 接口返回结果
1016
+ */
1017
+ upload: async (params: { image: any }): Promise<any> => {
1018
+ const { image } = params;
1019
+ await this.ensureTokenValid();
1020
+
1021
+ const url = '/api/attachment/v1/images';
1022
+
1023
+ this.log(LoggerLevel.info, '[attachment.avatar.upload] Uploading avatar image');
1024
+
1025
+ const FormData = require('form-data');
1026
+ const formData = new FormData();
1027
+ formData.append('image', image);
1028
+
1029
+ const res = await this.axiosInstance.post(url, formData, {
1030
+ headers: {
1031
+ Authorization: `${this.accessToken}`,
1032
+ ...formData.getHeaders()
1033
+ }
1034
+ });
1035
+
1036
+ this.log(LoggerLevel.debug, `[attachment.avatar.upload] Avatar image uploaded: code=${res.data.code}`);
1037
+ this.log(LoggerLevel.trace, `[attachment.avatar.upload] Response: ${JSON.stringify(res.data)}`);
1038
+
1039
+ return res.data;
1040
+ },
1041
+
1042
+ /**
1043
+ * 下载头像图片
1044
+ * @param params 请求参数 { image_id: string }
1045
+ * @returns 图片二进制流
1046
+ */
1047
+ download: async (params: { image_id: string }): Promise<any> => {
1048
+ const { image_id } = params;
1049
+ await this.ensureTokenValid();
1050
+
1051
+ const url = `/api/attachment/v1/images/${image_id}`;
1052
+
1053
+ this.log(LoggerLevel.info, `[attachment.avatar.download] Downloading avatar image: ${image_id}`);
1054
+
1055
+ const res = await this.axiosInstance.get(url, {
1056
+ headers: {
1057
+ Authorization: `${this.accessToken}`
1058
+ },
1059
+ responseType: 'arraybuffer'
1060
+ });
1061
+
1062
+ this.log(LoggerLevel.debug, `[attachment.avatar.download] Avatar image downloaded: ${image_id}`);
1063
+
1064
+ return res.data;
1065
+ }
1066
+ }
1067
+ };
1068
+
1069
+ /**
1070
+ * 全局数据模块
1071
+ */
1072
+ public global = {
1073
+ /**
1074
+ * 全局选项
1075
+ */
1076
+ options: {
1077
+ /**
1078
+ * 查询全局选项详情
1079
+ * @param params 请求参数 { api_name: string }
1080
+ * @returns 接口返回结果
1081
+ */
1082
+ detail: async (params: { api_name: string }): Promise<any> => {
1083
+ const { api_name } = params;
1084
+ await this.ensureTokenValid();
1085
+
1086
+ const url = `/api/data/v1/namespaces/${this.namespace}/globalOptions/${api_name}`;
1087
+
1088
+ this.log(LoggerLevel.info, `[global.options.detail] Fetching global option detail: ${api_name}`);
1089
+
1090
+ const res = await this.axiosInstance.get(url, {
1091
+ headers: {
1092
+ Authorization: `${this.accessToken}`
1093
+ }
1094
+ });
1095
+
1096
+ this.log(LoggerLevel.debug, `[global.options.detail] Global option detail fetched: ${api_name}, code=${res.data.code}`);
1097
+ this.log(LoggerLevel.trace, `[global.options.detail] Response: ${JSON.stringify(res.data)}`);
1098
+
1099
+ return res.data;
1100
+ },
1101
+
1102
+ /**
1103
+ * 查询全局选项列表
1104
+ * @param params 请求参数 { limit: number, offset: number, filter?: { quickQuery?: string } }
1105
+ * @returns 接口返回结果
1106
+ */
1107
+ list: async (params: { limit: number; offset: number; filter?: { quickQuery?: string } }): Promise<any> => {
1108
+ const { limit, offset, filter } = params;
1109
+ await this.ensureTokenValid();
1110
+
1111
+ const url = `/api/data/v1/namespaces/${this.namespace}/globalOptions/list`;
1112
+
1113
+ this.log(LoggerLevel.info, `[global.options.list] Fetching global options list: offset=${offset}, limit=${limit}`);
1114
+
1115
+ const requestData: any = { limit, offset };
1116
+ if (filter) {
1117
+ requestData.filter = filter;
1118
+ }
1119
+
1120
+ const res = await this.axiosInstance.post(url, requestData, {
1121
+ headers: {
1122
+ Authorization: `${this.accessToken}`,
1123
+ 'Content-Type': 'application/json'
1124
+ }
1125
+ });
1126
+
1127
+ this.log(LoggerLevel.debug, `[global.options.list] Global options list fetched: code=${res.data.code}`);
1128
+ this.log(LoggerLevel.trace, `[global.options.list] Response: ${JSON.stringify(res.data)}`);
1129
+
1130
+ return res.data;
1131
+ },
1132
+
1133
+ /**
1134
+ * 查询所有全局选项 - 支持自动分页,获取全部数据
1135
+ * @description 该方法会自动处理分页,直到获取所有全局选项数据
1136
+ * @param params 请求参数 { limit?: number, filter?: { quickQuery?: string } }
1137
+ * @returns { total, items }
1138
+ */
1139
+ listWithIterator: async (params?: { limit?: number; filter?: { quickQuery?: string } }): Promise<{ total: number; items: any[] }> => {
1140
+ const limit = params?.limit || 100;
1141
+ const filter = params?.filter;
1142
+ let results: any[] = [];
1143
+ let offset = 0;
1144
+ let total = 0;
1145
+ let page = 0;
1146
+ let totalPages = 0;
1147
+
1148
+ do {
1149
+ const pageRes = await functionLimiter(async () => {
1150
+ const requestParams: any = { limit, offset };
1151
+ if (filter) {
1152
+ requestParams.filter = filter;
1153
+ }
1154
+
1155
+ const res = await this.global.options.list(requestParams);
1156
+
1157
+ page += 1;
1158
+
1159
+ if (res.data && Array.isArray(res.data.items)) {
1160
+ results = results.concat(res.data.items);
1161
+ }
1162
+
1163
+ if (page === 1) {
1164
+ total = res.data.total || 0;
1165
+ totalPages = Math.ceil(total / limit);
1166
+ this.log(LoggerLevel.info, `[global.options.listWithIterator] Starting paginated query: total=${total}, pages=${totalPages}`);
1167
+ }
1168
+
1169
+ offset += limit;
1170
+
1171
+ const padLength = totalPages.toString().length;
1172
+ const pageStr = page.toString().padStart(padLength, '0');
1173
+ const totalPagesStr = totalPages.toString().padStart(padLength, '0');
1174
+
1175
+ this.log(LoggerLevel.info, `[global.options.listWithIterator] Page completed: [${pageStr}/${totalPagesStr}]`);
1176
+ this.log(LoggerLevel.debug, `[global.options.listWithIterator] Page ${page} details: items=${res.data.items?.length}, offset=${offset}`);
1177
+ this.log(LoggerLevel.trace, `[global.options.listWithIterator] Page ${page} data: ${JSON.stringify(res.data?.items)}`);
1178
+
1179
+ return res;
1180
+ });
1181
+ } while (results.length < total);
1182
+
1183
+ return { total, items: results };
1184
+ }
1185
+ },
1186
+
1187
+ /**
1188
+ * 环境变量
1189
+ */
1190
+ variables: {
1191
+ /**
1192
+ * 查询环境变量详情
1193
+ * @param params 请求参数 { api_name: string }
1194
+ * @returns 接口返回结果
1195
+ */
1196
+ detail: async (params: { api_name: string }): Promise<any> => {
1197
+ const { api_name } = params;
1198
+ await this.ensureTokenValid();
1199
+
1200
+ const url = `/api/data/v1/namespaces/${this.namespace}/globalVariables/${api_name}`;
1201
+
1202
+ this.log(LoggerLevel.info, `[global.variables.detail] Fetching global variable detail: ${api_name}`);
1203
+
1204
+ const res = await this.axiosInstance.get(url, {
1205
+ headers: {
1206
+ Authorization: `${this.accessToken}`
1207
+ }
1208
+ });
1209
+
1210
+ this.log(LoggerLevel.debug, `[global.variables.detail] Global variable detail fetched: ${api_name}, code=${res.data.code}`);
1211
+ this.log(LoggerLevel.trace, `[global.variables.detail] Response: ${JSON.stringify(res.data)}`);
1212
+
1213
+ return res.data;
1214
+ },
1215
+
1216
+ /**
1217
+ * 查询环境变量列表
1218
+ * @param params 请求参数 { limit: number, offset: number, filter?: { quickQuery?: string } }
1219
+ * @returns 接口返回结果
1220
+ */
1221
+ list: async (params: { limit: number; offset: number; filter?: { quickQuery?: string } }): Promise<any> => {
1222
+ const { limit, offset, filter } = params;
1223
+ await this.ensureTokenValid();
1224
+
1225
+ const url = `/api/data/v1/namespaces/${this.namespace}/globalVariables/list`;
1226
+
1227
+ this.log(LoggerLevel.info, `[global.variables.list] Fetching global variables list: offset=${offset}, limit=${limit}`);
1228
+
1229
+ const requestData: any = { limit, offset };
1230
+ if (filter) {
1231
+ requestData.filter = filter;
1232
+ }
1233
+
1234
+ const res = await this.axiosInstance.post(url, requestData, {
1235
+ headers: {
1236
+ Authorization: `${this.accessToken}`,
1237
+ 'Content-Type': 'application/json'
1238
+ }
1239
+ });
1240
+
1241
+ this.log(LoggerLevel.debug, `[global.variables.list] Global variables list fetched: code=${res.data.code}`);
1242
+ this.log(LoggerLevel.trace, `[global.variables.list] Response: ${JSON.stringify(res.data)}`);
1243
+
1244
+ return res.data;
1245
+ },
1246
+
1247
+ /**
1248
+ * 查询所有环境变量 - 支持自动分页,获取全部数据
1249
+ * @description 该方法会自动处理分页,直到获取所有环境变量数据
1250
+ * @param params 请求参数 { limit?: number, filter?: { quickQuery?: string } }
1251
+ * @returns { total, items }
1252
+ */
1253
+ listWithIterator: async (params?: { limit?: number; filter?: { quickQuery?: string } }): Promise<{ total: number; items: any[] }> => {
1254
+ const limit = params?.limit || 100;
1255
+ const filter = params?.filter;
1256
+ let results: any[] = [];
1257
+ let offset = 0;
1258
+ let total = 0;
1259
+ let page = 0;
1260
+ let totalPages = 0;
1261
+
1262
+ do {
1263
+ const pageRes = await functionLimiter(async () => {
1264
+ const requestParams: any = { limit, offset };
1265
+ if (filter) {
1266
+ requestParams.filter = filter;
1267
+ }
1268
+
1269
+ const res = await this.global.variables.list(requestParams);
1270
+
1271
+ page += 1;
1272
+
1273
+ if (res.data && Array.isArray(res.data.items)) {
1274
+ results = results.concat(res.data.items);
1275
+ }
1276
+
1277
+ if (page === 1) {
1278
+ total = res.data.total || 0;
1279
+ totalPages = Math.ceil(total / limit);
1280
+ this.log(LoggerLevel.info, `[global.variables.listWithIterator] Starting paginated query: total=${total}, pages=${totalPages}`);
1281
+ }
1282
+
1283
+ offset += limit;
1284
+
1285
+ const padLength = totalPages.toString().length;
1286
+ const pageStr = page.toString().padStart(padLength, '0');
1287
+ const totalPagesStr = totalPages.toString().padStart(padLength, '0');
1288
+
1289
+ this.log(LoggerLevel.info, `[global.variables.listWithIterator] Page completed: [${pageStr}/${totalPagesStr}]`);
1290
+ this.log(LoggerLevel.debug, `[global.variables.listWithIterator] Page ${page} details: items=${res.data.items?.length}, offset=${offset}`);
1291
+ this.log(LoggerLevel.trace, `[global.variables.listWithIterator] Page ${page} data: ${JSON.stringify(res.data?.items)}`);
1292
+
1293
+ return res;
1294
+ });
1295
+ } while (results.length < total);
1296
+
1297
+ return { total, items: results };
1298
+ }
1299
+ }
1300
+ };
757
1301
  }
758
1302
 
759
1303
  export const apaas = {