apaas-oapi-client 0.1.14 → 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 +105 -85
- package/package.json +1 -1
- package/src/index.ts +110 -86
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
|
/**
|
|
@@ -148,14 +168,15 @@ class Client {
|
|
|
148
168
|
let nextPageToken = '';
|
|
149
169
|
let total = 0;
|
|
150
170
|
let page = 0;
|
|
151
|
-
|
|
171
|
+
let totalPages = 0;
|
|
172
|
+
const pageSize = data.page_size || 100;
|
|
152
173
|
do {
|
|
153
174
|
await functionLimiter(async () => {
|
|
154
|
-
var _a, _b
|
|
175
|
+
var _a, _b;
|
|
155
176
|
const mergedData = { ...data, page_token: nextPageToken || '' };
|
|
156
|
-
await this.
|
|
157
|
-
|
|
158
|
-
|
|
177
|
+
const res = await this.object.search.records({
|
|
178
|
+
object_name,
|
|
179
|
+
data: mergedData
|
|
159
180
|
});
|
|
160
181
|
page += 1;
|
|
161
182
|
if (res.data && Array.isArray(res.data.items)) {
|
|
@@ -163,15 +184,16 @@ class Client {
|
|
|
163
184
|
}
|
|
164
185
|
if (page === 1) {
|
|
165
186
|
total = res.data.total || 0;
|
|
166
|
-
|
|
187
|
+
totalPages = Math.ceil(total / pageSize);
|
|
188
|
+
this.log(LoggerLevel.info, `[object.search.recordsWithIterator] Starting paginated query: ${object_name}, total=${total}, pages=${totalPages}`);
|
|
167
189
|
}
|
|
168
|
-
const totalPages = Math.ceil(total / (data.page_size || 100));
|
|
169
|
-
const padLength = String(totalPages).length;
|
|
170
|
-
this.log(LoggerLevel.info, `[批量查询记录] 🔍 [${String(page).padStart(padLength, '0')}/${totalPages}] 接口调用完成`);
|
|
171
|
-
this.log(LoggerLevel.debug, `[批量查询记录] 🔍 第 ${page} 页查询, nextPageToken: ${((_a = res.data) === null || _a === void 0 ? void 0 : _a.next_page_token) || ''}`);
|
|
172
|
-
this.log(LoggerLevel.debug, `[批量查询记录] 🔍 第 ${page} 页查询完成, items.length: ${(_b = res.data.items) === null || _b === void 0 ? void 0 : _b.length}`);
|
|
173
|
-
this.log(LoggerLevel.trace, `[批量查询记录] 🔍 第 ${page} 页查询结果: ${JSON.stringify((_c = res.data) === null || _c === void 0 ? void 0 : _c.items)}`);
|
|
174
190
|
nextPageToken = res.data.next_page_token;
|
|
191
|
+
const padLength = totalPages.toString().length;
|
|
192
|
+
const pageStr = page.toString().padStart(padLength, '0');
|
|
193
|
+
const totalPagesStr = totalPages.toString().padStart(padLength, '0');
|
|
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)}`);
|
|
175
197
|
return res;
|
|
176
198
|
});
|
|
177
199
|
} while (nextPageToken);
|
|
@@ -188,15 +210,15 @@ class Client {
|
|
|
188
210
|
record: async (params) => {
|
|
189
211
|
const { object_name, record } = params;
|
|
190
212
|
const url = `/v1/data/namespaces/${this.namespace}/objects/${object_name}/records`;
|
|
191
|
-
this.log(LoggerLevel.info, `[
|
|
213
|
+
this.log(LoggerLevel.info, `[object.create.record] Creating record in: ${object_name}`);
|
|
192
214
|
const res = await functionLimiter(async () => {
|
|
193
215
|
await this.ensureTokenValid();
|
|
194
216
|
const response = await this.axiosInstance.post(url, { record }, {
|
|
195
217
|
headers: { Authorization: `${this.accessToken}` }
|
|
196
218
|
});
|
|
197
|
-
this.log(LoggerLevel.info, `[
|
|
198
|
-
this.log(LoggerLevel.debug, `[
|
|
199
|
-
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)}`);
|
|
200
222
|
return response.data;
|
|
201
223
|
});
|
|
202
224
|
return res;
|
|
@@ -214,9 +236,9 @@ class Client {
|
|
|
214
236
|
const res = await this.axiosInstance.post(url, { records }, {
|
|
215
237
|
headers: { Authorization: `${this.accessToken}` }
|
|
216
238
|
});
|
|
217
|
-
this.log(LoggerLevel.info, `[
|
|
218
|
-
this.log(LoggerLevel.debug, `[
|
|
219
|
-
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)}`);
|
|
220
242
|
return res.data;
|
|
221
243
|
},
|
|
222
244
|
/**
|
|
@@ -235,12 +257,10 @@ class Client {
|
|
|
235
257
|
for (let i = 0; i < records.length; i += chunkSize) {
|
|
236
258
|
chunks.push(records.slice(i, i + chunkSize));
|
|
237
259
|
}
|
|
238
|
-
this.log(LoggerLevel.debug, `[
|
|
239
|
-
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}`);
|
|
240
261
|
for (const [index, chunk] of chunks.entries()) {
|
|
241
262
|
page += 1;
|
|
242
|
-
this.log(LoggerLevel.debug, `[
|
|
243
|
-
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`);
|
|
244
264
|
await functionLimiter(async () => {
|
|
245
265
|
const res = await this.object.create.records({
|
|
246
266
|
object_name,
|
|
@@ -249,9 +269,9 @@ class Client {
|
|
|
249
269
|
if (res.data && Array.isArray(res.data.items)) {
|
|
250
270
|
results = results.concat(res.data.items);
|
|
251
271
|
}
|
|
252
|
-
this.log(LoggerLevel.info, `[
|
|
253
|
-
this.log(LoggerLevel.debug, `[
|
|
254
|
-
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)}`);
|
|
255
275
|
return res;
|
|
256
276
|
});
|
|
257
277
|
}
|
|
@@ -268,13 +288,13 @@ class Client {
|
|
|
268
288
|
record: async (params) => {
|
|
269
289
|
const { object_name, record_id, record } = params;
|
|
270
290
|
const url = `/v1/data/namespaces/${this.namespace}/objects/${object_name}/records/${record_id}`;
|
|
271
|
-
this.log(LoggerLevel.info, `[
|
|
291
|
+
this.log(LoggerLevel.info, `[object.update.record] Updating record: ${record_id}`);
|
|
272
292
|
const res = await functionLimiter(async () => {
|
|
273
293
|
await this.ensureTokenValid();
|
|
274
294
|
const response = await this.axiosInstance.patch(url, { record }, { headers: { Authorization: `${this.accessToken}` } });
|
|
275
|
-
this.log(LoggerLevel.info, `[
|
|
276
|
-
this.log(LoggerLevel.debug, `[
|
|
277
|
-
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)}`);
|
|
278
298
|
return response.data;
|
|
279
299
|
});
|
|
280
300
|
return res;
|
|
@@ -288,11 +308,11 @@ class Client {
|
|
|
288
308
|
records: async (params) => {
|
|
289
309
|
const { object_name, records } = params;
|
|
290
310
|
const url = `/v1/data/namespaces/${this.namespace}/objects/${object_name}/records/records_batch`;
|
|
291
|
-
this.log(LoggerLevel.info, `[
|
|
311
|
+
this.log(LoggerLevel.info, `[object.update.records] Updating ${records.length} records`);
|
|
292
312
|
const response = await this.axiosInstance.patch(url, { records }, { headers: { Authorization: `${this.accessToken}` } });
|
|
293
|
-
this.log(LoggerLevel.info, `[
|
|
294
|
-
this.log(LoggerLevel.debug, `[
|
|
295
|
-
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)}`);
|
|
296
316
|
return response.data;
|
|
297
317
|
},
|
|
298
318
|
/**
|
|
@@ -309,17 +329,15 @@ class Client {
|
|
|
309
329
|
for (let i = 0; i < records.length; i += chunkSize) {
|
|
310
330
|
chunks.push(records.slice(i, i + chunkSize));
|
|
311
331
|
}
|
|
312
|
-
this.log(LoggerLevel.debug, `[
|
|
313
|
-
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}`);
|
|
314
333
|
const results = [];
|
|
315
334
|
for (const [index, chunk] of chunks.entries()) {
|
|
316
|
-
this.log(LoggerLevel.debug, `[
|
|
317
|
-
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`);
|
|
318
336
|
const res = await functionLimiter(async () => {
|
|
319
337
|
await this.ensureTokenValid();
|
|
320
338
|
const response = await this.axiosInstance.patch(url, { records: chunk }, { headers: { Authorization: `${this.accessToken}` } });
|
|
321
|
-
this.log(LoggerLevel.debug, `[
|
|
322
|
-
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)}`);
|
|
323
341
|
return response.data;
|
|
324
342
|
});
|
|
325
343
|
results.push(res);
|
|
@@ -337,13 +355,15 @@ class Client {
|
|
|
337
355
|
record: async (params) => {
|
|
338
356
|
const { object_name, record_id } = params;
|
|
339
357
|
const url = `/v1/data/namespaces/${this.namespace}/objects/${object_name}/records/${record_id}`;
|
|
340
|
-
this.log(LoggerLevel.
|
|
358
|
+
this.log(LoggerLevel.info, `[object.delete.record] Deleting record: ${object_name}.${record_id}`);
|
|
341
359
|
const res = await functionLimiter(async () => {
|
|
342
360
|
await this.ensureTokenValid();
|
|
343
361
|
const response = await this.axiosInstance.delete(url, {
|
|
344
362
|
headers: { Authorization: `${this.accessToken}` }
|
|
345
363
|
});
|
|
346
|
-
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)}`);
|
|
347
367
|
return response.data;
|
|
348
368
|
});
|
|
349
369
|
return res;
|
|
@@ -357,16 +377,16 @@ class Client {
|
|
|
357
377
|
records: async (params) => {
|
|
358
378
|
const { object_name, ids } = params;
|
|
359
379
|
const url = `/v1/data/namespaces/${this.namespace}/objects/${object_name}/records_batch`;
|
|
360
|
-
this.log(LoggerLevel.info, `[
|
|
380
|
+
this.log(LoggerLevel.info, `[object.delete.records] Deleting ${ids.length} records from: ${object_name}`);
|
|
361
381
|
const res = await functionLimiter(async () => {
|
|
362
382
|
await this.ensureTokenValid();
|
|
363
383
|
const response = await this.axiosInstance.delete(url, {
|
|
364
384
|
data: { ids },
|
|
365
385
|
headers: { Authorization: `${this.accessToken}`, 'Content-Type': 'application/json' }
|
|
366
386
|
});
|
|
367
|
-
this.log(LoggerLevel.info, `[
|
|
368
|
-
this.log(LoggerLevel.debug, `[
|
|
369
|
-
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)}`);
|
|
370
390
|
return response.data;
|
|
371
391
|
});
|
|
372
392
|
return res;
|
|
@@ -385,18 +405,18 @@ class Client {
|
|
|
385
405
|
for (let i = 0; i < ids.length; i += chunkSize) {
|
|
386
406
|
chunks.push(ids.slice(i, i + chunkSize));
|
|
387
407
|
}
|
|
388
|
-
this.log(LoggerLevel.debug, `[
|
|
408
|
+
this.log(LoggerLevel.debug, `[object.delete.recordsWithIterator] Chunking ${ids.length} records into ${chunks.length} groups of ${chunkSize}`);
|
|
389
409
|
const results = [];
|
|
390
410
|
for (const [index, chunk] of chunks.entries()) {
|
|
391
|
-
this.log(LoggerLevel.info, `[
|
|
411
|
+
this.log(LoggerLevel.info, `[object.delete.recordsWithIterator] Processing chunk ${index + 1}/${chunks.length}: ${chunk.length} records`);
|
|
392
412
|
const res = await functionLimiter(async () => {
|
|
393
413
|
await this.ensureTokenValid();
|
|
394
414
|
const response = await this.axiosInstance.delete(url, {
|
|
395
415
|
headers: { Authorization: `${this.accessToken}` },
|
|
396
416
|
data: { ids: chunk }
|
|
397
417
|
});
|
|
398
|
-
this.log(LoggerLevel.debug, `[
|
|
399
|
-
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)}`);
|
|
400
420
|
return response.data;
|
|
401
421
|
});
|
|
402
422
|
results.push(res);
|
|
@@ -421,7 +441,7 @@ class Client {
|
|
|
421
441
|
// - 'external_department_id' (外部平台 department_id, 无固定格式)
|
|
422
442
|
// - 'external_open_department_id' (以 'oc_' 开头的 open_department_id)
|
|
423
443
|
const url = '/api/integration/v2/feishu/getDepartments';
|
|
424
|
-
this.log(LoggerLevel.info, `[
|
|
444
|
+
this.log(LoggerLevel.info, `[department.exchange] Exchanging department ID: ${department_id}`);
|
|
425
445
|
const res = await functionLimiter(async () => {
|
|
426
446
|
await this.ensureTokenValid();
|
|
427
447
|
const response = await this.axiosInstance.post(url, {
|
|
@@ -430,8 +450,8 @@ class Client {
|
|
|
430
450
|
}, {
|
|
431
451
|
headers: { Authorization: `${this.accessToken}` }
|
|
432
452
|
});
|
|
433
|
-
this.log(LoggerLevel.debug, `[
|
|
434
|
-
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)}`);
|
|
435
455
|
return response.data.data[0]; // 返回第一个元素
|
|
436
456
|
});
|
|
437
457
|
return res;
|
|
@@ -453,10 +473,10 @@ class Client {
|
|
|
453
473
|
for (let i = 0; i < department_ids.length; i += chunkSize) {
|
|
454
474
|
chunks.push(department_ids.slice(i, i + chunkSize));
|
|
455
475
|
}
|
|
456
|
-
this.log(LoggerLevel.info, `[
|
|
476
|
+
this.log(LoggerLevel.info, `[department.batchExchange] Chunking ${department_ids.length} department IDs into ${chunks.length} groups of ${chunkSize}`);
|
|
457
477
|
const results = [];
|
|
458
478
|
for (const [index, chunk] of chunks.entries()) {
|
|
459
|
-
this.log(LoggerLevel.info, `[
|
|
479
|
+
this.log(LoggerLevel.info, `[department.batchExchange] Processing chunk ${index + 1}/${chunks.length}: ${chunk.length} IDs`);
|
|
460
480
|
const res = await functionLimiter(async () => {
|
|
461
481
|
await this.ensureTokenValid();
|
|
462
482
|
const response = await this.axiosInstance.post(url, {
|
|
@@ -465,8 +485,8 @@ class Client {
|
|
|
465
485
|
}, {
|
|
466
486
|
headers: { Authorization: `${this.accessToken}` }
|
|
467
487
|
});
|
|
468
|
-
this.log(LoggerLevel.debug, `[
|
|
469
|
-
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)}`);
|
|
470
490
|
return response.data.data;
|
|
471
491
|
});
|
|
472
492
|
results.push(...res);
|
|
@@ -487,15 +507,15 @@ class Client {
|
|
|
487
507
|
const { name, params: functionParams } = params;
|
|
488
508
|
await this.ensureTokenValid();
|
|
489
509
|
const url = `/api/cloudfunction/v1/namespaces/${this.namespace}/invoke/${name}`;
|
|
490
|
-
this.log(LoggerLevel.info, `[
|
|
510
|
+
this.log(LoggerLevel.info, `[function.invoke] Invoking cloud function: ${name}`);
|
|
491
511
|
const res = await this.axiosInstance.post(url, { params: functionParams }, {
|
|
492
512
|
headers: {
|
|
493
513
|
Authorization: `${this.accessToken}`,
|
|
494
514
|
'Content-Type': 'application/json'
|
|
495
515
|
}
|
|
496
516
|
});
|
|
497
|
-
this.log(LoggerLevel.debug, `[
|
|
498
|
-
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)}`);
|
|
499
519
|
return res.data;
|
|
500
520
|
}
|
|
501
521
|
};
|
|
@@ -507,7 +527,7 @@ class Client {
|
|
|
507
527
|
baseURL: 'https://ae-openapi.feishu.cn',
|
|
508
528
|
headers: { 'Content-Type': 'application/json' }
|
|
509
529
|
});
|
|
510
|
-
this.log(LoggerLevel.info, '[client] initialized');
|
|
530
|
+
this.log(LoggerLevel.info, '[client] Client initialized successfully');
|
|
511
531
|
}
|
|
512
532
|
/**
|
|
513
533
|
* 设置日志等级
|
|
@@ -515,7 +535,7 @@ class Client {
|
|
|
515
535
|
*/
|
|
516
536
|
setLoggerLevel(level) {
|
|
517
537
|
this.loggerLevel = level;
|
|
518
|
-
this.log(LoggerLevel.info, `[logger]
|
|
538
|
+
this.log(LoggerLevel.info, `[logger] Log level set to ${LoggerLevel[level]}`);
|
|
519
539
|
}
|
|
520
540
|
/**
|
|
521
541
|
* 日志打印方法
|
|
@@ -534,7 +554,7 @@ class Client {
|
|
|
534
554
|
*/
|
|
535
555
|
async init() {
|
|
536
556
|
await this.ensureTokenValid();
|
|
537
|
-
this.log(LoggerLevel.info, '[client] ready');
|
|
557
|
+
this.log(LoggerLevel.info, '[client] Client initialized and ready');
|
|
538
558
|
}
|
|
539
559
|
/**
|
|
540
560
|
* 获取 accessToken
|
|
@@ -546,30 +566,30 @@ class Client {
|
|
|
546
566
|
clientSecret: this.clientSecret
|
|
547
567
|
});
|
|
548
568
|
if (res.data.code !== '0') {
|
|
549
|
-
this.log(LoggerLevel.error, `[
|
|
569
|
+
this.log(LoggerLevel.error, `[auth] Failed to fetch access token: ${res.data.msg}`);
|
|
550
570
|
throw new Error(`获取 accessToken 失败: ${res.data.msg}`);
|
|
551
571
|
}
|
|
552
572
|
this.accessToken = res.data.data.accessToken;
|
|
553
573
|
this.expireTime = res.data.data.expireTime;
|
|
554
|
-
this.log(LoggerLevel.info, '[
|
|
574
|
+
this.log(LoggerLevel.info, '[auth] Access token refreshed successfully');
|
|
555
575
|
}
|
|
556
576
|
/**
|
|
557
577
|
* 确保 token 有效, 若过期则刷新
|
|
558
578
|
*/
|
|
559
579
|
async ensureTokenValid() {
|
|
560
580
|
if (this.disableTokenCache) {
|
|
561
|
-
this.log(LoggerLevel.debug, '[
|
|
581
|
+
this.log(LoggerLevel.debug, '[auth] Token cache disabled, refreshing token');
|
|
562
582
|
await this.getAccessToken();
|
|
563
583
|
return;
|
|
564
584
|
}
|
|
565
585
|
if (!this.accessToken || !this.expireTime) {
|
|
566
|
-
this.log(LoggerLevel.debug, '[
|
|
586
|
+
this.log(LoggerLevel.debug, '[auth] No token cached, fetching new token');
|
|
567
587
|
await this.getAccessToken();
|
|
568
588
|
return;
|
|
569
589
|
}
|
|
570
590
|
const now = dayjs().valueOf();
|
|
571
591
|
if (now + 60 * 1000 > this.expireTime) {
|
|
572
|
-
this.log(LoggerLevel.debug, '[
|
|
592
|
+
this.log(LoggerLevel.debug, '[auth] Token expired, refreshing');
|
|
573
593
|
await this.getAccessToken();
|
|
574
594
|
}
|
|
575
595
|
}
|
|
@@ -585,25 +605,25 @@ class Client {
|
|
|
585
605
|
*/
|
|
586
606
|
get tokenExpireTime() {
|
|
587
607
|
if (!this.accessToken || !this.expireTime) {
|
|
588
|
-
this.log(LoggerLevel.warn, '[
|
|
608
|
+
this.log(LoggerLevel.warn, '[auth] No valid token available');
|
|
589
609
|
return null;
|
|
590
610
|
}
|
|
591
611
|
const now = dayjs().valueOf();
|
|
592
612
|
const remainMs = this.expireTime - now;
|
|
593
613
|
if (remainMs <= 0) {
|
|
594
|
-
this.log(LoggerLevel.warn, '[
|
|
614
|
+
this.log(LoggerLevel.warn, '[auth] Token has expired');
|
|
595
615
|
return 0;
|
|
596
616
|
}
|
|
597
617
|
const remainSeconds = Math.floor(remainMs / 1000);
|
|
598
|
-
this.log(LoggerLevel.debug, `[
|
|
599
|
-
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}`);
|
|
600
620
|
return remainSeconds;
|
|
601
621
|
}
|
|
602
622
|
/**
|
|
603
623
|
* 获取当前 namespace
|
|
604
624
|
*/
|
|
605
625
|
get currentNamespace() {
|
|
606
|
-
this.log(LoggerLevel.debug,
|
|
626
|
+
this.log(LoggerLevel.debug, `[namespace] Current namespace: ${this.namespace}`);
|
|
607
627
|
return this.namespace;
|
|
608
628
|
}
|
|
609
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
|
|
|
@@ -283,17 +308,17 @@ class Client {
|
|
|
283
308
|
let nextPageToken: string | undefined = '';
|
|
284
309
|
let total = 0;
|
|
285
310
|
let page = 0;
|
|
311
|
+
let totalPages = 0;
|
|
286
312
|
|
|
287
|
-
const
|
|
313
|
+
const pageSize = data.page_size || 100;
|
|
288
314
|
|
|
289
315
|
do {
|
|
290
316
|
const pageRes = await functionLimiter(async () => {
|
|
291
317
|
const mergedData = { ...data, page_token: nextPageToken || '' };
|
|
292
318
|
|
|
293
|
-
await this.
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
headers: { Authorization: `${this.accessToken}` }
|
|
319
|
+
const res = await this.object.search.records({
|
|
320
|
+
object_name,
|
|
321
|
+
data: mergedData
|
|
297
322
|
});
|
|
298
323
|
|
|
299
324
|
page += 1;
|
|
@@ -304,18 +329,19 @@ class Client {
|
|
|
304
329
|
|
|
305
330
|
if (page === 1) {
|
|
306
331
|
total = res.data.total || 0;
|
|
307
|
-
|
|
332
|
+
totalPages = Math.ceil(total / pageSize);
|
|
333
|
+
this.log(LoggerLevel.info, `[object.search.recordsWithIterator] Starting paginated query: ${object_name}, total=${total}, pages=${totalPages}`);
|
|
308
334
|
}
|
|
309
335
|
|
|
310
|
-
|
|
311
|
-
const padLength = String(totalPages).length;
|
|
336
|
+
nextPageToken = res.data.next_page_token;
|
|
312
337
|
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
this.log(LoggerLevel.trace, `[批量查询记录] 🔍 第 ${page} 页查询结果: ${JSON.stringify(res.data?.items)}`);
|
|
338
|
+
const padLength = totalPages.toString().length;
|
|
339
|
+
const pageStr = page.toString().padStart(padLength, '0');
|
|
340
|
+
const totalPagesStr = totalPages.toString().padStart(padLength, '0');
|
|
317
341
|
|
|
318
|
-
|
|
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)}`);
|
|
319
345
|
|
|
320
346
|
return res;
|
|
321
347
|
});
|
|
@@ -336,7 +362,7 @@ class Client {
|
|
|
336
362
|
const { object_name, record } = params;
|
|
337
363
|
const url = `/v1/data/namespaces/${this.namespace}/objects/${object_name}/records`;
|
|
338
364
|
|
|
339
|
-
this.log(LoggerLevel.info, `[
|
|
365
|
+
this.log(LoggerLevel.info, `[object.create.record] Creating record in: ${object_name}`);
|
|
340
366
|
|
|
341
367
|
const res = await functionLimiter(async () => {
|
|
342
368
|
await this.ensureTokenValid();
|
|
@@ -349,9 +375,9 @@ class Client {
|
|
|
349
375
|
}
|
|
350
376
|
);
|
|
351
377
|
|
|
352
|
-
this.log(LoggerLevel.info, `[
|
|
353
|
-
this.log(LoggerLevel.debug, `[
|
|
354
|
-
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)}`);
|
|
355
381
|
|
|
356
382
|
return response.data;
|
|
357
383
|
});
|
|
@@ -379,9 +405,9 @@ class Client {
|
|
|
379
405
|
}
|
|
380
406
|
);
|
|
381
407
|
|
|
382
|
-
this.log(LoggerLevel.info, `[
|
|
383
|
-
this.log(LoggerLevel.debug, `[
|
|
384
|
-
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)}`);
|
|
385
411
|
return res.data;
|
|
386
412
|
},
|
|
387
413
|
|
|
@@ -404,14 +430,12 @@ class Client {
|
|
|
404
430
|
chunks.push(records.slice(i, i + chunkSize));
|
|
405
431
|
}
|
|
406
432
|
|
|
407
|
-
this.log(LoggerLevel.debug, `[
|
|
408
|
-
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}`);
|
|
409
434
|
|
|
410
435
|
for (const [index, chunk] of chunks.entries()) {
|
|
411
436
|
page += 1;
|
|
412
437
|
|
|
413
|
-
this.log(LoggerLevel.debug, `[
|
|
414
|
-
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`);
|
|
415
439
|
|
|
416
440
|
const pageRes = await functionLimiter(async () => {
|
|
417
441
|
const res = await this.object.create.records({
|
|
@@ -423,9 +447,9 @@ class Client {
|
|
|
423
447
|
results = results.concat(res.data.items);
|
|
424
448
|
}
|
|
425
449
|
|
|
426
|
-
this.log(LoggerLevel.info, `[
|
|
427
|
-
this.log(LoggerLevel.debug, `[
|
|
428
|
-
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)}`);
|
|
429
453
|
|
|
430
454
|
return res;
|
|
431
455
|
});
|
|
@@ -446,16 +470,16 @@ class Client {
|
|
|
446
470
|
const { object_name, record_id, record } = params;
|
|
447
471
|
const url = `/v1/data/namespaces/${this.namespace}/objects/${object_name}/records/${record_id}`;
|
|
448
472
|
|
|
449
|
-
this.log(LoggerLevel.info, `[
|
|
473
|
+
this.log(LoggerLevel.info, `[object.update.record] Updating record: ${record_id}`);
|
|
450
474
|
|
|
451
475
|
const res = await functionLimiter(async () => {
|
|
452
476
|
await this.ensureTokenValid();
|
|
453
477
|
|
|
454
478
|
const response = await this.axiosInstance.patch(url, { record }, { headers: { Authorization: `${this.accessToken}` } });
|
|
455
479
|
|
|
456
|
-
this.log(LoggerLevel.info, `[
|
|
457
|
-
this.log(LoggerLevel.debug, `[
|
|
458
|
-
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)}`);
|
|
459
483
|
return response.data;
|
|
460
484
|
});
|
|
461
485
|
|
|
@@ -472,13 +496,13 @@ class Client {
|
|
|
472
496
|
const { object_name, records } = params;
|
|
473
497
|
const url = `/v1/data/namespaces/${this.namespace}/objects/${object_name}/records/records_batch`;
|
|
474
498
|
|
|
475
|
-
this.log(LoggerLevel.info, `[
|
|
499
|
+
this.log(LoggerLevel.info, `[object.update.records] Updating ${records.length} records`);
|
|
476
500
|
|
|
477
501
|
const response = await this.axiosInstance.patch(url, { records }, { headers: { Authorization: `${this.accessToken}` } });
|
|
478
502
|
|
|
479
|
-
this.log(LoggerLevel.info, `[
|
|
480
|
-
this.log(LoggerLevel.debug, `[
|
|
481
|
-
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)}`);
|
|
482
506
|
|
|
483
507
|
return response.data;
|
|
484
508
|
},
|
|
@@ -499,21 +523,19 @@ class Client {
|
|
|
499
523
|
chunks.push(records.slice(i, i + chunkSize));
|
|
500
524
|
}
|
|
501
525
|
|
|
502
|
-
this.log(LoggerLevel.debug, `[
|
|
503
|
-
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}`);
|
|
504
527
|
|
|
505
528
|
const results: any[] = [];
|
|
506
529
|
for (const [index, chunk] of chunks.entries()) {
|
|
507
|
-
this.log(LoggerLevel.debug, `[
|
|
508
|
-
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`);
|
|
509
531
|
|
|
510
532
|
const res = await functionLimiter(async () => {
|
|
511
533
|
await this.ensureTokenValid();
|
|
512
534
|
|
|
513
535
|
const response = await this.axiosInstance.patch(url, { records: chunk }, { headers: { Authorization: `${this.accessToken}` } });
|
|
514
536
|
|
|
515
|
-
this.log(LoggerLevel.debug, `[
|
|
516
|
-
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)}`);
|
|
517
539
|
return response.data;
|
|
518
540
|
});
|
|
519
541
|
|
|
@@ -535,7 +557,7 @@ class Client {
|
|
|
535
557
|
const { object_name, record_id } = params;
|
|
536
558
|
const url = `/v1/data/namespaces/${this.namespace}/objects/${object_name}/records/${record_id}`;
|
|
537
559
|
|
|
538
|
-
this.log(LoggerLevel.
|
|
560
|
+
this.log(LoggerLevel.info, `[object.delete.record] Deleting record: ${object_name}.${record_id}`);
|
|
539
561
|
|
|
540
562
|
const res = await functionLimiter(async () => {
|
|
541
563
|
await this.ensureTokenValid();
|
|
@@ -544,7 +566,9 @@ class Client {
|
|
|
544
566
|
headers: { Authorization: `${this.accessToken}` }
|
|
545
567
|
});
|
|
546
568
|
|
|
547
|
-
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)}`);
|
|
548
572
|
return response.data;
|
|
549
573
|
});
|
|
550
574
|
|
|
@@ -561,7 +585,7 @@ class Client {
|
|
|
561
585
|
const { object_name, ids } = params;
|
|
562
586
|
const url = `/v1/data/namespaces/${this.namespace}/objects/${object_name}/records_batch`;
|
|
563
587
|
|
|
564
|
-
this.log(LoggerLevel.info, `[
|
|
588
|
+
this.log(LoggerLevel.info, `[object.delete.records] Deleting ${ids.length} records from: ${object_name}`);
|
|
565
589
|
|
|
566
590
|
const res = await functionLimiter(async () => {
|
|
567
591
|
await this.ensureTokenValid();
|
|
@@ -571,9 +595,9 @@ class Client {
|
|
|
571
595
|
headers: { Authorization: `${this.accessToken}`, 'Content-Type': 'application/json' }
|
|
572
596
|
});
|
|
573
597
|
|
|
574
|
-
this.log(LoggerLevel.info, `[
|
|
575
|
-
this.log(LoggerLevel.debug, `[
|
|
576
|
-
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)}`);
|
|
577
601
|
|
|
578
602
|
return response.data;
|
|
579
603
|
});
|
|
@@ -597,11 +621,11 @@ class Client {
|
|
|
597
621
|
chunks.push(ids.slice(i, i + chunkSize));
|
|
598
622
|
}
|
|
599
623
|
|
|
600
|
-
this.log(LoggerLevel.debug, `[
|
|
624
|
+
this.log(LoggerLevel.debug, `[object.delete.recordsWithIterator] Chunking ${ids.length} records into ${chunks.length} groups of ${chunkSize}`);
|
|
601
625
|
|
|
602
626
|
const results: any[] = [];
|
|
603
627
|
for (const [index, chunk] of chunks.entries()) {
|
|
604
|
-
this.log(LoggerLevel.info, `[
|
|
628
|
+
this.log(LoggerLevel.info, `[object.delete.recordsWithIterator] Processing chunk ${index + 1}/${chunks.length}: ${chunk.length} records`);
|
|
605
629
|
|
|
606
630
|
const res = await functionLimiter(async () => {
|
|
607
631
|
await this.ensureTokenValid();
|
|
@@ -611,8 +635,8 @@ class Client {
|
|
|
611
635
|
data: { ids: chunk }
|
|
612
636
|
});
|
|
613
637
|
|
|
614
|
-
this.log(LoggerLevel.debug, `[
|
|
615
|
-
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)}`);
|
|
616
640
|
return response.data;
|
|
617
641
|
});
|
|
618
642
|
|
|
@@ -642,7 +666,7 @@ class Client {
|
|
|
642
666
|
|
|
643
667
|
const url = '/api/integration/v2/feishu/getDepartments';
|
|
644
668
|
|
|
645
|
-
this.log(LoggerLevel.info, `[
|
|
669
|
+
this.log(LoggerLevel.info, `[department.exchange] Exchanging department ID: ${department_id}`);
|
|
646
670
|
|
|
647
671
|
const res = await functionLimiter(async () => {
|
|
648
672
|
await this.ensureTokenValid();
|
|
@@ -658,8 +682,8 @@ class Client {
|
|
|
658
682
|
}
|
|
659
683
|
);
|
|
660
684
|
|
|
661
|
-
this.log(LoggerLevel.debug, `[
|
|
662
|
-
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)}`);
|
|
663
687
|
return response.data.data[0]; // 返回第一个元素
|
|
664
688
|
});
|
|
665
689
|
|
|
@@ -686,11 +710,11 @@ class Client {
|
|
|
686
710
|
chunks.push(department_ids.slice(i, i + chunkSize));
|
|
687
711
|
}
|
|
688
712
|
|
|
689
|
-
this.log(LoggerLevel.info, `[
|
|
713
|
+
this.log(LoggerLevel.info, `[department.batchExchange] Chunking ${department_ids.length} department IDs into ${chunks.length} groups of ${chunkSize}`);
|
|
690
714
|
|
|
691
715
|
const results: any[] = [];
|
|
692
716
|
for (const [index, chunk] of chunks.entries()) {
|
|
693
|
-
this.log(LoggerLevel.info, `[
|
|
717
|
+
this.log(LoggerLevel.info, `[department.batchExchange] Processing chunk ${index + 1}/${chunks.length}: ${chunk.length} IDs`);
|
|
694
718
|
|
|
695
719
|
const res = await functionLimiter(async () => {
|
|
696
720
|
await this.ensureTokenValid();
|
|
@@ -706,8 +730,8 @@ class Client {
|
|
|
706
730
|
}
|
|
707
731
|
);
|
|
708
732
|
|
|
709
|
-
this.log(LoggerLevel.debug, `[
|
|
710
|
-
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)}`);
|
|
711
735
|
return response.data.data;
|
|
712
736
|
});
|
|
713
737
|
|
|
@@ -733,7 +757,7 @@ class Client {
|
|
|
733
757
|
|
|
734
758
|
const url = `/api/cloudfunction/v1/namespaces/${this.namespace}/invoke/${name}`;
|
|
735
759
|
|
|
736
|
-
this.log(LoggerLevel.info, `[
|
|
760
|
+
this.log(LoggerLevel.info, `[function.invoke] Invoking cloud function: ${name}`);
|
|
737
761
|
|
|
738
762
|
const res = await this.axiosInstance.post(
|
|
739
763
|
url,
|
|
@@ -746,8 +770,8 @@ class Client {
|
|
|
746
770
|
}
|
|
747
771
|
);
|
|
748
772
|
|
|
749
|
-
this.log(LoggerLevel.debug, `[
|
|
750
|
-
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)}`);
|
|
751
775
|
|
|
752
776
|
return res.data;
|
|
753
777
|
}
|