apaas-oapi-client 0.1.15 → 0.1.16
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 +13 -0
- package/dist/index.js +95 -78
- package/package.json +1 -1
- package/src/index.ts +100 -78
package/dist/index.d.ts
CHANGED
|
@@ -69,6 +69,19 @@ declare class Client {
|
|
|
69
69
|
* 对象模块
|
|
70
70
|
*/
|
|
71
71
|
object: {
|
|
72
|
+
/**
|
|
73
|
+
* 列出所有对象(数据表)
|
|
74
|
+
* @param params 请求参数 { offset, filter?, limit }
|
|
75
|
+
* @returns 接口返回结果
|
|
76
|
+
*/
|
|
77
|
+
list: (params: {
|
|
78
|
+
offset: number;
|
|
79
|
+
filter?: {
|
|
80
|
+
type?: string;
|
|
81
|
+
quickQuery?: string;
|
|
82
|
+
};
|
|
83
|
+
limit: number;
|
|
84
|
+
}) => Promise<any>;
|
|
72
85
|
metadata: {
|
|
73
86
|
/**
|
|
74
87
|
* 获取指定对象下指定字段的元数据
|
package/dist/index.js
CHANGED
|
@@ -59,6 +59,27 @@ class Client {
|
|
|
59
59
|
* 对象模块
|
|
60
60
|
*/
|
|
61
61
|
this.object = {
|
|
62
|
+
/**
|
|
63
|
+
* 列出所有对象(数据表)
|
|
64
|
+
* @param params 请求参数 { offset, filter?, limit }
|
|
65
|
+
* @returns 接口返回结果
|
|
66
|
+
*/
|
|
67
|
+
list: async (params) => {
|
|
68
|
+
const { offset, filter, limit } = params;
|
|
69
|
+
await this.ensureTokenValid();
|
|
70
|
+
const url = `/api/data/v1/namespaces/${this.namespace}/meta/objects/list`;
|
|
71
|
+
this.log(LoggerLevel.debug, `[object.list] Fetching objects list: offset=${offset}, limit=${limit}`);
|
|
72
|
+
const requestData = { offset, limit };
|
|
73
|
+
if (filter) {
|
|
74
|
+
requestData.filter = filter;
|
|
75
|
+
}
|
|
76
|
+
const res = await this.axiosInstance.post(url, requestData, {
|
|
77
|
+
headers: { Authorization: `${this.accessToken}` }
|
|
78
|
+
});
|
|
79
|
+
this.log(LoggerLevel.debug, `[object.list] Objects list fetched successfully: code=${res.data.code}`);
|
|
80
|
+
this.log(LoggerLevel.trace, `[object.list] Response: ${JSON.stringify(res.data)}`);
|
|
81
|
+
return res.data;
|
|
82
|
+
},
|
|
62
83
|
metadata: {
|
|
63
84
|
/**
|
|
64
85
|
* 获取指定对象下指定字段的元数据
|
|
@@ -70,12 +91,12 @@ class Client {
|
|
|
70
91
|
const { object_name, field_name } = params;
|
|
71
92
|
await this.ensureTokenValid();
|
|
72
93
|
const url = `/api/data/v1/namespaces/${this.namespace}/meta/objects/${object_name}/fields/${field_name}`;
|
|
73
|
-
this.log(LoggerLevel.debug, `[
|
|
94
|
+
this.log(LoggerLevel.debug, `[object.metadata.field] Fetching field metadata: ${object_name}.${field_name}`);
|
|
74
95
|
const res = await this.axiosInstance.get(url, {
|
|
75
96
|
headers: { Authorization: `${this.accessToken}` }
|
|
76
97
|
});
|
|
77
|
-
this.log(LoggerLevel.debug, `[
|
|
78
|
-
this.log(LoggerLevel.trace, `[
|
|
98
|
+
this.log(LoggerLevel.debug, `[object.metadata.field] Field metadata fetched: ${object_name}.${field_name}, code=${res.data.code}`);
|
|
99
|
+
this.log(LoggerLevel.trace, `[object.metadata.field] Response: ${JSON.stringify(res.data)}`);
|
|
79
100
|
return res.data;
|
|
80
101
|
},
|
|
81
102
|
/**
|
|
@@ -88,12 +109,12 @@ class Client {
|
|
|
88
109
|
const { object_name } = params;
|
|
89
110
|
await this.ensureTokenValid();
|
|
90
111
|
const url = `/api/data/v1/namespaces/${this.namespace}/meta/objects/${object_name}`;
|
|
91
|
-
this.log(LoggerLevel.debug, `[
|
|
112
|
+
this.log(LoggerLevel.debug, `[object.metadata.fields] Fetching all fields metadata: ${object_name}`);
|
|
92
113
|
const res = await this.axiosInstance.get(url, {
|
|
93
114
|
headers: { Authorization: `${this.accessToken}` }
|
|
94
115
|
});
|
|
95
|
-
this.log(LoggerLevel.debug, `[
|
|
96
|
-
this.log(LoggerLevel.trace, `[
|
|
116
|
+
this.log(LoggerLevel.debug, `[object.metadata.fields] All fields metadata fetched: ${object_name}, code=${res.data.code}`);
|
|
117
|
+
this.log(LoggerLevel.trace, `[object.metadata.fields] Response: ${JSON.stringify(res.data)}`);
|
|
97
118
|
return res.data;
|
|
98
119
|
}
|
|
99
120
|
},
|
|
@@ -107,12 +128,12 @@ class Client {
|
|
|
107
128
|
record: async (params) => {
|
|
108
129
|
const { object_name, record_id, select } = params;
|
|
109
130
|
const url = `/v1/data/namespaces/${this.namespace}/objects/${object_name}/records/${record_id}`;
|
|
110
|
-
this.log(LoggerLevel.info, `[
|
|
131
|
+
this.log(LoggerLevel.info, `[object.search.record] Querying record: ${record_id}`);
|
|
111
132
|
const res = await functionLimiter(async () => {
|
|
112
133
|
await this.ensureTokenValid();
|
|
113
134
|
const response = await this.axiosInstance.post(url, { select }, { headers: { Authorization: `${this.accessToken}` } });
|
|
114
|
-
this.log(LoggerLevel.debug, `[
|
|
115
|
-
this.log(LoggerLevel.trace, `[
|
|
135
|
+
this.log(LoggerLevel.debug, `[object.search.record] Record queried: ${object_name}.${record_id}, code=${response.data.code}`);
|
|
136
|
+
this.log(LoggerLevel.trace, `[object.search.record] Response: ${JSON.stringify(response.data)}`);
|
|
116
137
|
return response.data;
|
|
117
138
|
});
|
|
118
139
|
return res;
|
|
@@ -131,9 +152,8 @@ class Client {
|
|
|
131
152
|
const res = await this.axiosInstance.post(url, data, {
|
|
132
153
|
headers: { Authorization: `${this.accessToken}` }
|
|
133
154
|
});
|
|
134
|
-
this.log(LoggerLevel.
|
|
135
|
-
this.log(LoggerLevel.
|
|
136
|
-
this.log(LoggerLevel.trace, `[批量查询记录] 🔍 查询 object_name=${object_name}, 调用完成, 返回信息: ${JSON.stringify(res.data)}`);
|
|
155
|
+
this.log(LoggerLevel.debug, `[object.search.records] Records queried: ${object_name}, code=${res.data.code}, total=${((_b = (_a = res.data) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.total) || 'unknown'}`);
|
|
156
|
+
this.log(LoggerLevel.trace, `[object.search.records] Response: ${JSON.stringify(res.data)}`);
|
|
137
157
|
return res.data;
|
|
138
158
|
},
|
|
139
159
|
/**
|
|
@@ -165,16 +185,15 @@ class Client {
|
|
|
165
185
|
if (page === 1) {
|
|
166
186
|
total = res.data.total || 0;
|
|
167
187
|
totalPages = Math.ceil(total / pageSize);
|
|
168
|
-
this.log(LoggerLevel.info, `[
|
|
188
|
+
this.log(LoggerLevel.info, `[object.search.recordsWithIterator] Starting paginated query: ${object_name}, total=${total}, pages=${totalPages}`);
|
|
169
189
|
}
|
|
170
190
|
nextPageToken = res.data.next_page_token;
|
|
171
191
|
const padLength = totalPages.toString().length;
|
|
172
192
|
const pageStr = page.toString().padStart(padLength, '0');
|
|
173
193
|
const totalPagesStr = totalPages.toString().padStart(padLength, '0');
|
|
174
|
-
this.log(LoggerLevel.info, `[
|
|
175
|
-
this.log(LoggerLevel.debug, `[
|
|
176
|
-
this.log(LoggerLevel.
|
|
177
|
-
this.log(LoggerLevel.trace, `[批量查询记录] 🔍 第 ${page} 页查询结果: ${JSON.stringify((_b = res.data) === null || _b === void 0 ? void 0 : _b.items)}`);
|
|
194
|
+
this.log(LoggerLevel.info, `[object.search.recordsWithIterator] Page completed: [${pageStr}/${totalPagesStr}]`);
|
|
195
|
+
this.log(LoggerLevel.debug, `[object.search.recordsWithIterator] Page ${page} details: items=${(_a = res.data.items) === null || _a === void 0 ? void 0 : _a.length}, nextToken=${nextPageToken || 'none'}`);
|
|
196
|
+
this.log(LoggerLevel.trace, `[object.search.recordsWithIterator] Page ${page} data: ${JSON.stringify((_b = res.data) === null || _b === void 0 ? void 0 : _b.items)}`);
|
|
178
197
|
return res;
|
|
179
198
|
});
|
|
180
199
|
} while (nextPageToken);
|
|
@@ -191,15 +210,15 @@ class Client {
|
|
|
191
210
|
record: async (params) => {
|
|
192
211
|
const { object_name, record } = params;
|
|
193
212
|
const url = `/v1/data/namespaces/${this.namespace}/objects/${object_name}/records`;
|
|
194
|
-
this.log(LoggerLevel.info, `[
|
|
213
|
+
this.log(LoggerLevel.info, `[object.create.record] Creating record in: ${object_name}`);
|
|
195
214
|
const res = await functionLimiter(async () => {
|
|
196
215
|
await this.ensureTokenValid();
|
|
197
216
|
const response = await this.axiosInstance.post(url, { record }, {
|
|
198
217
|
headers: { Authorization: `${this.accessToken}` }
|
|
199
218
|
});
|
|
200
|
-
this.log(LoggerLevel.info, `[
|
|
201
|
-
this.log(LoggerLevel.debug, `[
|
|
202
|
-
this.log(LoggerLevel.trace, `[
|
|
219
|
+
this.log(LoggerLevel.info, `[object.create.record] Record created: ${object_name}`);
|
|
220
|
+
this.log(LoggerLevel.debug, `[object.create.record] Record created: ${object_name}, code=${response.data.code}`);
|
|
221
|
+
this.log(LoggerLevel.trace, `[object.create.record] Response: ${JSON.stringify(response.data)}`);
|
|
203
222
|
return response.data;
|
|
204
223
|
});
|
|
205
224
|
return res;
|
|
@@ -217,9 +236,9 @@ class Client {
|
|
|
217
236
|
const res = await this.axiosInstance.post(url, { records }, {
|
|
218
237
|
headers: { Authorization: `${this.accessToken}` }
|
|
219
238
|
});
|
|
220
|
-
this.log(LoggerLevel.info, `[
|
|
221
|
-
this.log(LoggerLevel.debug, `[
|
|
222
|
-
this.log(LoggerLevel.trace, `[
|
|
239
|
+
this.log(LoggerLevel.info, `[object.create.records] Creating ${records.length} records in: ${object_name}`);
|
|
240
|
+
this.log(LoggerLevel.debug, `[object.create.records] Records created: ${object_name}, code=${res.data.code}`);
|
|
241
|
+
this.log(LoggerLevel.trace, `[object.create.records] Response: ${JSON.stringify(res.data)}`);
|
|
223
242
|
return res.data;
|
|
224
243
|
},
|
|
225
244
|
/**
|
|
@@ -238,12 +257,10 @@ class Client {
|
|
|
238
257
|
for (let i = 0; i < records.length; i += chunkSize) {
|
|
239
258
|
chunks.push(records.slice(i, i + chunkSize));
|
|
240
259
|
}
|
|
241
|
-
this.log(LoggerLevel.debug, `[
|
|
242
|
-
this.log(LoggerLevel.trace, `[批量创建记录] ➕ 总共 ${records.length} 条记录, 拆分为 ${chunks.length} 组, 每组最多 ${chunkSize} 条`);
|
|
260
|
+
this.log(LoggerLevel.debug, `[object.create.recordsWithIterator] Chunking ${records.length} records into ${chunks.length} groups of ${chunkSize}`);
|
|
243
261
|
for (const [index, chunk] of chunks.entries()) {
|
|
244
262
|
page += 1;
|
|
245
|
-
this.log(LoggerLevel.debug, `[
|
|
246
|
-
this.log(LoggerLevel.trace, `[批量创建记录] ➕ 开始创建第 ${index + 1} 组, 共 ${chunk.length} 条`);
|
|
263
|
+
this.log(LoggerLevel.debug, `[object.create.recordsWithIterator] Processing chunk ${index + 1}/${chunks.length}: ${chunk.length} records`);
|
|
247
264
|
await functionLimiter(async () => {
|
|
248
265
|
const res = await this.object.create.records({
|
|
249
266
|
object_name,
|
|
@@ -252,9 +269,9 @@ class Client {
|
|
|
252
269
|
if (res.data && Array.isArray(res.data.items)) {
|
|
253
270
|
results = results.concat(res.data.items);
|
|
254
271
|
}
|
|
255
|
-
this.log(LoggerLevel.info, `[
|
|
256
|
-
this.log(LoggerLevel.debug, `[
|
|
257
|
-
this.log(LoggerLevel.trace, `[
|
|
272
|
+
this.log(LoggerLevel.info, `[object.create.recordsWithIterator] Chunk ${page} completed: ${object_name}, created=${res.data.items.length}`);
|
|
273
|
+
this.log(LoggerLevel.debug, `[object.create.recordsWithIterator] Chunk ${page} result: ${object_name}, code=${res.data.code}`);
|
|
274
|
+
this.log(LoggerLevel.trace, `[object.create.recordsWithIterator] Chunk ${page} data: ${JSON.stringify(res.data.items)}`);
|
|
258
275
|
return res;
|
|
259
276
|
});
|
|
260
277
|
}
|
|
@@ -271,13 +288,13 @@ class Client {
|
|
|
271
288
|
record: async (params) => {
|
|
272
289
|
const { object_name, record_id, record } = params;
|
|
273
290
|
const url = `/v1/data/namespaces/${this.namespace}/objects/${object_name}/records/${record_id}`;
|
|
274
|
-
this.log(LoggerLevel.info, `[
|
|
291
|
+
this.log(LoggerLevel.info, `[object.update.record] Updating record: ${record_id}`);
|
|
275
292
|
const res = await functionLimiter(async () => {
|
|
276
293
|
await this.ensureTokenValid();
|
|
277
294
|
const response = await this.axiosInstance.patch(url, { record }, { headers: { Authorization: `${this.accessToken}` } });
|
|
278
|
-
this.log(LoggerLevel.info, `[
|
|
279
|
-
this.log(LoggerLevel.debug, `[
|
|
280
|
-
this.log(LoggerLevel.trace, `[
|
|
295
|
+
this.log(LoggerLevel.info, `[object.update.record] Record updated: ${object_name}.${record_id}`);
|
|
296
|
+
this.log(LoggerLevel.debug, `[object.update.record] Record updated: ${object_name}.${record_id}, code=${response.data.code}`);
|
|
297
|
+
this.log(LoggerLevel.trace, `[object.update.record] Response: ${JSON.stringify(response.data)}`);
|
|
281
298
|
return response.data;
|
|
282
299
|
});
|
|
283
300
|
return res;
|
|
@@ -291,11 +308,11 @@ class Client {
|
|
|
291
308
|
records: async (params) => {
|
|
292
309
|
const { object_name, records } = params;
|
|
293
310
|
const url = `/v1/data/namespaces/${this.namespace}/objects/${object_name}/records/records_batch`;
|
|
294
|
-
this.log(LoggerLevel.info, `[
|
|
311
|
+
this.log(LoggerLevel.info, `[object.update.records] Updating ${records.length} records`);
|
|
295
312
|
const response = await this.axiosInstance.patch(url, { records }, { headers: { Authorization: `${this.accessToken}` } });
|
|
296
|
-
this.log(LoggerLevel.info, `[
|
|
297
|
-
this.log(LoggerLevel.debug, `[
|
|
298
|
-
this.log(LoggerLevel.trace, `[
|
|
313
|
+
this.log(LoggerLevel.info, `[object.update.records] Records updated: ${object_name}`);
|
|
314
|
+
this.log(LoggerLevel.debug, `[object.update.records] Records updated: ${object_name}, code=${response.data.code}`);
|
|
315
|
+
this.log(LoggerLevel.trace, `[object.update.records] Response: ${JSON.stringify(response.data)}`);
|
|
299
316
|
return response.data;
|
|
300
317
|
},
|
|
301
318
|
/**
|
|
@@ -312,17 +329,15 @@ class Client {
|
|
|
312
329
|
for (let i = 0; i < records.length; i += chunkSize) {
|
|
313
330
|
chunks.push(records.slice(i, i + chunkSize));
|
|
314
331
|
}
|
|
315
|
-
this.log(LoggerLevel.debug, `[
|
|
316
|
-
this.log(LoggerLevel.trace, `[批量更新记录] 💾 总共 ${records.length} 条记录, 拆分为 ${chunks.length} 组, 每组最多 ${chunkSize} 条`);
|
|
332
|
+
this.log(LoggerLevel.debug, `[object.update.recordsWithIterator] Chunking ${records.length} records into ${chunks.length} groups of ${chunkSize}`);
|
|
317
333
|
const results = [];
|
|
318
334
|
for (const [index, chunk] of chunks.entries()) {
|
|
319
|
-
this.log(LoggerLevel.debug, `[
|
|
320
|
-
this.log(LoggerLevel.trace, `[批量更新记录] 💾 开始更新第 ${index + 1} 组, 共 ${chunk.length} 条`);
|
|
335
|
+
this.log(LoggerLevel.debug, `[object.update.recordsWithIterator] Processing chunk ${index + 1}/${chunks.length}: ${chunk.length} records`);
|
|
321
336
|
const res = await functionLimiter(async () => {
|
|
322
337
|
await this.ensureTokenValid();
|
|
323
338
|
const response = await this.axiosInstance.patch(url, { records: chunk }, { headers: { Authorization: `${this.accessToken}` } });
|
|
324
|
-
this.log(LoggerLevel.debug, `[
|
|
325
|
-
this.log(LoggerLevel.trace, `[
|
|
339
|
+
this.log(LoggerLevel.debug, `[object.update.recordsWithIterator] Chunk ${index + 1} completed: ${object_name}, code=${response.data.code}`);
|
|
340
|
+
this.log(LoggerLevel.trace, `[object.update.recordsWithIterator] Chunk ${index + 1} response: ${JSON.stringify(response.data)}`);
|
|
326
341
|
return response.data;
|
|
327
342
|
});
|
|
328
343
|
results.push(res);
|
|
@@ -340,13 +355,15 @@ class Client {
|
|
|
340
355
|
record: async (params) => {
|
|
341
356
|
const { object_name, record_id } = params;
|
|
342
357
|
const url = `/v1/data/namespaces/${this.namespace}/objects/${object_name}/records/${record_id}`;
|
|
343
|
-
this.log(LoggerLevel.
|
|
358
|
+
this.log(LoggerLevel.info, `[object.delete.record] Deleting record: ${object_name}.${record_id}`);
|
|
344
359
|
const res = await functionLimiter(async () => {
|
|
345
360
|
await this.ensureTokenValid();
|
|
346
361
|
const response = await this.axiosInstance.delete(url, {
|
|
347
362
|
headers: { Authorization: `${this.accessToken}` }
|
|
348
363
|
});
|
|
349
|
-
this.log(LoggerLevel.info, `[
|
|
364
|
+
this.log(LoggerLevel.info, `[object.delete.record] Record deleted: ${object_name}.${record_id}`);
|
|
365
|
+
this.log(LoggerLevel.debug, `[object.delete.record] Record deleted: ${object_name}.${record_id}, code=${response.data.code}`);
|
|
366
|
+
this.log(LoggerLevel.trace, `[object.delete.record] Response: ${JSON.stringify(response.data)}`);
|
|
350
367
|
return response.data;
|
|
351
368
|
});
|
|
352
369
|
return res;
|
|
@@ -360,16 +377,16 @@ class Client {
|
|
|
360
377
|
records: async (params) => {
|
|
361
378
|
const { object_name, ids } = params;
|
|
362
379
|
const url = `/v1/data/namespaces/${this.namespace}/objects/${object_name}/records_batch`;
|
|
363
|
-
this.log(LoggerLevel.info, `[
|
|
380
|
+
this.log(LoggerLevel.info, `[object.delete.records] Deleting ${ids.length} records from: ${object_name}`);
|
|
364
381
|
const res = await functionLimiter(async () => {
|
|
365
382
|
await this.ensureTokenValid();
|
|
366
383
|
const response = await this.axiosInstance.delete(url, {
|
|
367
384
|
data: { ids },
|
|
368
385
|
headers: { Authorization: `${this.accessToken}`, 'Content-Type': 'application/json' }
|
|
369
386
|
});
|
|
370
|
-
this.log(LoggerLevel.info, `[
|
|
371
|
-
this.log(LoggerLevel.debug, `[
|
|
372
|
-
this.log(LoggerLevel.trace, `[
|
|
387
|
+
this.log(LoggerLevel.info, `[object.delete.records] Records deleted: ${object_name}, count=${ids.length}`);
|
|
388
|
+
this.log(LoggerLevel.debug, `[object.delete.records] Records deleted: ${object_name}, count=${ids.length}, code=${response.data.code}`);
|
|
389
|
+
this.log(LoggerLevel.trace, `[object.delete.records] Response: ${JSON.stringify(response.data)}`);
|
|
373
390
|
return response.data;
|
|
374
391
|
});
|
|
375
392
|
return res;
|
|
@@ -388,18 +405,18 @@ class Client {
|
|
|
388
405
|
for (let i = 0; i < ids.length; i += chunkSize) {
|
|
389
406
|
chunks.push(ids.slice(i, i + chunkSize));
|
|
390
407
|
}
|
|
391
|
-
this.log(LoggerLevel.debug, `[
|
|
408
|
+
this.log(LoggerLevel.debug, `[object.delete.recordsWithIterator] Chunking ${ids.length} records into ${chunks.length} groups of ${chunkSize}`);
|
|
392
409
|
const results = [];
|
|
393
410
|
for (const [index, chunk] of chunks.entries()) {
|
|
394
|
-
this.log(LoggerLevel.info, `[
|
|
411
|
+
this.log(LoggerLevel.info, `[object.delete.recordsWithIterator] Processing chunk ${index + 1}/${chunks.length}: ${chunk.length} records`);
|
|
395
412
|
const res = await functionLimiter(async () => {
|
|
396
413
|
await this.ensureTokenValid();
|
|
397
414
|
const response = await this.axiosInstance.delete(url, {
|
|
398
415
|
headers: { Authorization: `${this.accessToken}` },
|
|
399
416
|
data: { ids: chunk }
|
|
400
417
|
});
|
|
401
|
-
this.log(LoggerLevel.debug, `[
|
|
402
|
-
this.log(LoggerLevel.trace, `[
|
|
418
|
+
this.log(LoggerLevel.debug, `[object.delete.recordsWithIterator] Chunk ${index + 1} completed: code=${response.data.code}`);
|
|
419
|
+
this.log(LoggerLevel.trace, `[object.delete.recordsWithIterator] Chunk ${index + 1} response: ${JSON.stringify(response.data)}`);
|
|
403
420
|
return response.data;
|
|
404
421
|
});
|
|
405
422
|
results.push(res);
|
|
@@ -424,7 +441,7 @@ class Client {
|
|
|
424
441
|
// - 'external_department_id' (外部平台 department_id, 无固定格式)
|
|
425
442
|
// - 'external_open_department_id' (以 'oc_' 开头的 open_department_id)
|
|
426
443
|
const url = '/api/integration/v2/feishu/getDepartments';
|
|
427
|
-
this.log(LoggerLevel.info, `[
|
|
444
|
+
this.log(LoggerLevel.info, `[department.exchange] Exchanging department ID: ${department_id}`);
|
|
428
445
|
const res = await functionLimiter(async () => {
|
|
429
446
|
await this.ensureTokenValid();
|
|
430
447
|
const response = await this.axiosInstance.post(url, {
|
|
@@ -433,8 +450,8 @@ class Client {
|
|
|
433
450
|
}, {
|
|
434
451
|
headers: { Authorization: `${this.accessToken}` }
|
|
435
452
|
});
|
|
436
|
-
this.log(LoggerLevel.debug, `[
|
|
437
|
-
this.log(LoggerLevel.
|
|
453
|
+
this.log(LoggerLevel.debug, `[department.exchange] Department ID exchanged: ${department_id}, code=${response.data.code}`);
|
|
454
|
+
this.log(LoggerLevel.trace, `[department.exchange] Response: ${JSON.stringify(response.data)}`);
|
|
438
455
|
return response.data.data[0]; // 返回第一个元素
|
|
439
456
|
});
|
|
440
457
|
return res;
|
|
@@ -456,10 +473,10 @@ class Client {
|
|
|
456
473
|
for (let i = 0; i < department_ids.length; i += chunkSize) {
|
|
457
474
|
chunks.push(department_ids.slice(i, i + chunkSize));
|
|
458
475
|
}
|
|
459
|
-
this.log(LoggerLevel.info, `[
|
|
476
|
+
this.log(LoggerLevel.info, `[department.batchExchange] Chunking ${department_ids.length} department IDs into ${chunks.length} groups of ${chunkSize}`);
|
|
460
477
|
const results = [];
|
|
461
478
|
for (const [index, chunk] of chunks.entries()) {
|
|
462
|
-
this.log(LoggerLevel.info, `[
|
|
479
|
+
this.log(LoggerLevel.info, `[department.batchExchange] Processing chunk ${index + 1}/${chunks.length}: ${chunk.length} IDs`);
|
|
463
480
|
const res = await functionLimiter(async () => {
|
|
464
481
|
await this.ensureTokenValid();
|
|
465
482
|
const response = await this.axiosInstance.post(url, {
|
|
@@ -468,8 +485,8 @@ class Client {
|
|
|
468
485
|
}, {
|
|
469
486
|
headers: { Authorization: `${this.accessToken}` }
|
|
470
487
|
});
|
|
471
|
-
this.log(LoggerLevel.debug, `[
|
|
472
|
-
this.log(LoggerLevel.trace, `[
|
|
488
|
+
this.log(LoggerLevel.debug, `[department.batchExchange] Chunk ${index + 1} completed: code=${response.data.code}`);
|
|
489
|
+
this.log(LoggerLevel.trace, `[department.batchExchange] Chunk ${index + 1} response: ${JSON.stringify(response.data)}`);
|
|
473
490
|
return response.data.data;
|
|
474
491
|
});
|
|
475
492
|
results.push(...res);
|
|
@@ -490,15 +507,15 @@ class Client {
|
|
|
490
507
|
const { name, params: functionParams } = params;
|
|
491
508
|
await this.ensureTokenValid();
|
|
492
509
|
const url = `/api/cloudfunction/v1/namespaces/${this.namespace}/invoke/${name}`;
|
|
493
|
-
this.log(LoggerLevel.info, `[
|
|
510
|
+
this.log(LoggerLevel.info, `[function.invoke] Invoking cloud function: ${name}`);
|
|
494
511
|
const res = await this.axiosInstance.post(url, { params: functionParams }, {
|
|
495
512
|
headers: {
|
|
496
513
|
Authorization: `${this.accessToken}`,
|
|
497
514
|
'Content-Type': 'application/json'
|
|
498
515
|
}
|
|
499
516
|
});
|
|
500
|
-
this.log(LoggerLevel.debug, `[
|
|
501
|
-
this.log(LoggerLevel.trace, `[
|
|
517
|
+
this.log(LoggerLevel.debug, `[function.invoke] Cloud function invoked: ${name}, code=${res.data.code}`);
|
|
518
|
+
this.log(LoggerLevel.trace, `[function.invoke] Response: ${JSON.stringify(res.data)}`);
|
|
502
519
|
return res.data;
|
|
503
520
|
}
|
|
504
521
|
};
|
|
@@ -510,7 +527,7 @@ class Client {
|
|
|
510
527
|
baseURL: 'https://ae-openapi.feishu.cn',
|
|
511
528
|
headers: { 'Content-Type': 'application/json' }
|
|
512
529
|
});
|
|
513
|
-
this.log(LoggerLevel.info, '[client] initialized');
|
|
530
|
+
this.log(LoggerLevel.info, '[client] Client initialized successfully');
|
|
514
531
|
}
|
|
515
532
|
/**
|
|
516
533
|
* 设置日志等级
|
|
@@ -518,7 +535,7 @@ class Client {
|
|
|
518
535
|
*/
|
|
519
536
|
setLoggerLevel(level) {
|
|
520
537
|
this.loggerLevel = level;
|
|
521
|
-
this.log(LoggerLevel.info, `[logger]
|
|
538
|
+
this.log(LoggerLevel.info, `[logger] Log level set to ${LoggerLevel[level]}`);
|
|
522
539
|
}
|
|
523
540
|
/**
|
|
524
541
|
* 日志打印方法
|
|
@@ -537,7 +554,7 @@ class Client {
|
|
|
537
554
|
*/
|
|
538
555
|
async init() {
|
|
539
556
|
await this.ensureTokenValid();
|
|
540
|
-
this.log(LoggerLevel.info, '[client] ready');
|
|
557
|
+
this.log(LoggerLevel.info, '[client] Client initialized and ready');
|
|
541
558
|
}
|
|
542
559
|
/**
|
|
543
560
|
* 获取 accessToken
|
|
@@ -549,30 +566,30 @@ class Client {
|
|
|
549
566
|
clientSecret: this.clientSecret
|
|
550
567
|
});
|
|
551
568
|
if (res.data.code !== '0') {
|
|
552
|
-
this.log(LoggerLevel.error, `[
|
|
569
|
+
this.log(LoggerLevel.error, `[auth] Failed to fetch access token: ${res.data.msg}`);
|
|
553
570
|
throw new Error(`获取 accessToken 失败: ${res.data.msg}`);
|
|
554
571
|
}
|
|
555
572
|
this.accessToken = res.data.data.accessToken;
|
|
556
573
|
this.expireTime = res.data.data.expireTime;
|
|
557
|
-
this.log(LoggerLevel.info, '[
|
|
574
|
+
this.log(LoggerLevel.info, '[auth] Access token refreshed successfully');
|
|
558
575
|
}
|
|
559
576
|
/**
|
|
560
577
|
* 确保 token 有效, 若过期则刷新
|
|
561
578
|
*/
|
|
562
579
|
async ensureTokenValid() {
|
|
563
580
|
if (this.disableTokenCache) {
|
|
564
|
-
this.log(LoggerLevel.debug, '[
|
|
581
|
+
this.log(LoggerLevel.debug, '[auth] Token cache disabled, refreshing token');
|
|
565
582
|
await this.getAccessToken();
|
|
566
583
|
return;
|
|
567
584
|
}
|
|
568
585
|
if (!this.accessToken || !this.expireTime) {
|
|
569
|
-
this.log(LoggerLevel.debug, '[
|
|
586
|
+
this.log(LoggerLevel.debug, '[auth] No token cached, fetching new token');
|
|
570
587
|
await this.getAccessToken();
|
|
571
588
|
return;
|
|
572
589
|
}
|
|
573
590
|
const now = dayjs().valueOf();
|
|
574
591
|
if (now + 60 * 1000 > this.expireTime) {
|
|
575
|
-
this.log(LoggerLevel.debug, '[
|
|
592
|
+
this.log(LoggerLevel.debug, '[auth] Token expired, refreshing');
|
|
576
593
|
await this.getAccessToken();
|
|
577
594
|
}
|
|
578
595
|
}
|
|
@@ -588,25 +605,25 @@ class Client {
|
|
|
588
605
|
*/
|
|
589
606
|
get tokenExpireTime() {
|
|
590
607
|
if (!this.accessToken || !this.expireTime) {
|
|
591
|
-
this.log(LoggerLevel.warn, '[
|
|
608
|
+
this.log(LoggerLevel.warn, '[auth] No valid token available');
|
|
592
609
|
return null;
|
|
593
610
|
}
|
|
594
611
|
const now = dayjs().valueOf();
|
|
595
612
|
const remainMs = this.expireTime - now;
|
|
596
613
|
if (remainMs <= 0) {
|
|
597
|
-
this.log(LoggerLevel.warn, '[
|
|
614
|
+
this.log(LoggerLevel.warn, '[auth] Token has expired');
|
|
598
615
|
return 0;
|
|
599
616
|
}
|
|
600
617
|
const remainSeconds = Math.floor(remainMs / 1000);
|
|
601
|
-
this.log(LoggerLevel.debug, `[
|
|
602
|
-
this.log(LoggerLevel.trace, `[
|
|
618
|
+
this.log(LoggerLevel.debug, `[auth] Token expires in ${remainSeconds} seconds`);
|
|
619
|
+
this.log(LoggerLevel.trace, `[auth] Token expiry details: remaining=${remainSeconds}s, expireTime=${this.expireTime}, now=${now}`);
|
|
603
620
|
return remainSeconds;
|
|
604
621
|
}
|
|
605
622
|
/**
|
|
606
623
|
* 获取当前 namespace
|
|
607
624
|
*/
|
|
608
625
|
get currentNamespace() {
|
|
609
|
-
this.log(LoggerLevel.debug,
|
|
626
|
+
this.log(LoggerLevel.debug, `[namespace] Current namespace: ${this.namespace}`);
|
|
610
627
|
return this.namespace;
|
|
611
628
|
}
|
|
612
629
|
}
|
package/package.json
CHANGED
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]
|
|
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, `[
|
|
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, '[
|
|
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, '[
|
|
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, '[
|
|
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, '[
|
|
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, '[
|
|
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, '[
|
|
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, `[
|
|
162
|
-
this.log(LoggerLevel.trace, `[
|
|
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,
|
|
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, `[
|
|
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, `[
|
|
197
|
-
this.log(LoggerLevel.trace, `[
|
|
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, `[
|
|
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, `[
|
|
219
|
-
this.log(LoggerLevel.trace, `[
|
|
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, `[
|
|
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, `[
|
|
243
|
-
this.log(LoggerLevel.trace, `[
|
|
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.
|
|
268
|
-
this.log(LoggerLevel.
|
|
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, `[
|
|
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, `[
|
|
318
|
-
this.log(LoggerLevel.debug, `[
|
|
319
|
-
this.log(LoggerLevel.
|
|
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, `[
|
|
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, `[
|
|
355
|
-
this.log(LoggerLevel.debug, `[
|
|
356
|
-
this.log(LoggerLevel.trace, `[
|
|
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, `[
|
|
385
|
-
this.log(LoggerLevel.debug, `[
|
|
386
|
-
this.log(LoggerLevel.trace, `[
|
|
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, `[
|
|
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, `[
|
|
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, `[
|
|
429
|
-
this.log(LoggerLevel.debug, `[
|
|
430
|
-
this.log(LoggerLevel.trace, `[
|
|
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, `[
|
|
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, `[
|
|
459
|
-
this.log(LoggerLevel.debug, `[
|
|
460
|
-
this.log(LoggerLevel.trace, `[
|
|
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, `[
|
|
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, `[
|
|
482
|
-
this.log(LoggerLevel.debug, `[
|
|
483
|
-
this.log(LoggerLevel.trace, `[
|
|
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, `[
|
|
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, `[
|
|
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, `[
|
|
518
|
-
this.log(LoggerLevel.trace, `[
|
|
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.
|
|
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, `[
|
|
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, `[
|
|
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, `[
|
|
577
|
-
this.log(LoggerLevel.debug, `[
|
|
578
|
-
this.log(LoggerLevel.trace, `[
|
|
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, `[
|
|
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, `[
|
|
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, `[
|
|
617
|
-
this.log(LoggerLevel.trace, `[
|
|
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, `[
|
|
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, `[
|
|
664
|
-
this.log(LoggerLevel.
|
|
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, `[
|
|
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, `[
|
|
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, `[
|
|
712
|
-
this.log(LoggerLevel.trace, `[
|
|
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, `[
|
|
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,8 +770,8 @@ class Client {
|
|
|
748
770
|
}
|
|
749
771
|
);
|
|
750
772
|
|
|
751
|
-
this.log(LoggerLevel.debug, `[
|
|
752
|
-
this.log(LoggerLevel.trace, `[
|
|
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)}`);
|
|
753
775
|
|
|
754
776
|
return res.data;
|
|
755
777
|
}
|