apaas-oapi-client 0.1.20 → 0.1.23
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.js
CHANGED
|
@@ -165,35 +165,44 @@ class Client {
|
|
|
165
165
|
recordsWithIterator: async (params) => {
|
|
166
166
|
const { object_name, data } = params;
|
|
167
167
|
let results = [];
|
|
168
|
-
let nextPageToken =
|
|
168
|
+
let nextPageToken = undefined;
|
|
169
169
|
let total = 0;
|
|
170
170
|
let page = 0;
|
|
171
171
|
let totalPages = 0;
|
|
172
172
|
const pageSize = data.page_size || 100;
|
|
173
173
|
do {
|
|
174
174
|
await functionLimiter(async () => {
|
|
175
|
-
var _a, _b;
|
|
176
|
-
const mergedData = { ...data
|
|
175
|
+
var _a, _b, _c, _d;
|
|
176
|
+
const mergedData = { ...data };
|
|
177
|
+
if (nextPageToken) {
|
|
178
|
+
mergedData.page_token = nextPageToken;
|
|
179
|
+
}
|
|
177
180
|
const res = await this.object.search.records({
|
|
178
181
|
object_name,
|
|
179
182
|
data: mergedData
|
|
180
183
|
});
|
|
184
|
+
if (res.code !== '0') {
|
|
185
|
+
this.log(LoggerLevel.error, `[object.search.recordsWithIterator] Error querying records: code=${res.code}, msg=${res.msg}`);
|
|
186
|
+
throw new Error(res.msg || `Query failed with code ${res.code}`);
|
|
187
|
+
}
|
|
181
188
|
page += 1;
|
|
182
189
|
if (res.data && Array.isArray(res.data.items)) {
|
|
183
190
|
results = results.concat(res.data.items);
|
|
184
191
|
}
|
|
192
|
+
if (res.data && (res.data.total !== undefined && res.data.total !== null)) {
|
|
193
|
+
total = res.data.total;
|
|
194
|
+
}
|
|
185
195
|
if (page === 1) {
|
|
186
|
-
total = res.data.total || 0;
|
|
187
196
|
totalPages = Math.ceil(total / pageSize);
|
|
188
197
|
this.log(LoggerLevel.info, `[object.search.recordsWithIterator] Starting paginated query: ${object_name}, total=${total}, pages=${totalPages}`);
|
|
189
198
|
}
|
|
190
|
-
nextPageToken = res.data.next_page_token;
|
|
199
|
+
nextPageToken = (_a = res.data) === null || _a === void 0 ? void 0 : _a.next_page_token;
|
|
191
200
|
const padLength = totalPages.toString().length;
|
|
192
201
|
const pageStr = page.toString().padStart(padLength, '0');
|
|
193
202
|
const totalPagesStr = totalPages.toString().padStart(padLength, '0');
|
|
194
203
|
this.log(LoggerLevel.info, `[object.search.recordsWithIterator] Page completed: [${pageStr}/${totalPagesStr}]`);
|
|
195
|
-
this.log(LoggerLevel.debug, `[object.search.recordsWithIterator] Page ${page} details: items=${(
|
|
196
|
-
this.log(LoggerLevel.trace, `[object.search.recordsWithIterator] Page ${page} data: ${JSON.stringify((
|
|
204
|
+
this.log(LoggerLevel.debug, `[object.search.recordsWithIterator] Page ${page} details: items=${(_c = (_b = res.data) === null || _b === void 0 ? void 0 : _b.items) === null || _c === void 0 ? void 0 : _c.length}, nextToken=${nextPageToken || 'none'}`);
|
|
205
|
+
this.log(LoggerLevel.trace, `[object.search.recordsWithIterator] Page ${page} data: ${JSON.stringify((_d = res.data) === null || _d === void 0 ? void 0 : _d.items)}`);
|
|
197
206
|
return res;
|
|
198
207
|
});
|
|
199
208
|
} while (nextPageToken);
|
|
@@ -249,6 +258,15 @@ class Client {
|
|
|
249
258
|
*/
|
|
250
259
|
recordsWithIterator: async (params) => {
|
|
251
260
|
const { object_name, records } = params;
|
|
261
|
+
// 参数校验
|
|
262
|
+
if (!records || !Array.isArray(records)) {
|
|
263
|
+
this.log(LoggerLevel.error, '[object.create.recordsWithIterator] Invalid records parameter: must be a non-empty array');
|
|
264
|
+
throw new Error('参数 records 必须是一个数组');
|
|
265
|
+
}
|
|
266
|
+
if (records.length === 0) {
|
|
267
|
+
this.log(LoggerLevel.warn, '[object.create.recordsWithIterator] Empty records array provided, returning empty result');
|
|
268
|
+
return { total: 0, items: [] };
|
|
269
|
+
}
|
|
252
270
|
let results = [];
|
|
253
271
|
let total = records.length;
|
|
254
272
|
const chunkSize = 100;
|
|
@@ -262,16 +280,24 @@ class Client {
|
|
|
262
280
|
page += 1;
|
|
263
281
|
this.log(LoggerLevel.debug, `[object.create.recordsWithIterator] Processing chunk ${index + 1}/${chunks.length}: ${chunk.length} records`);
|
|
264
282
|
await functionLimiter(async () => {
|
|
283
|
+
var _a, _b, _c;
|
|
265
284
|
const res = await this.object.create.records({
|
|
266
285
|
object_name,
|
|
267
286
|
records: chunk
|
|
268
287
|
});
|
|
288
|
+
if (res.code !== '0') {
|
|
289
|
+
this.log(LoggerLevel.error, `[object.create.recordsWithIterator] Error creating records: code=${res.code}, msg=${res.msg}`);
|
|
290
|
+
// Should we throw? Probably yes, to stop partial creation or notify user.
|
|
291
|
+
// But maybe user wants partial success?
|
|
292
|
+
// Given other methods throw, I'll throw here too.
|
|
293
|
+
throw new Error(res.msg || `Creation failed with code ${res.code}`);
|
|
294
|
+
}
|
|
269
295
|
if (res.data && Array.isArray(res.data.items)) {
|
|
270
296
|
results = results.concat(res.data.items);
|
|
271
297
|
}
|
|
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.
|
|
274
|
-
this.log(LoggerLevel.trace, `[object.create.recordsWithIterator] Chunk ${page} data: ${JSON.stringify(res.data.items)}`);
|
|
298
|
+
this.log(LoggerLevel.info, `[object.create.recordsWithIterator] Chunk ${page} completed: ${object_name}, created=${(_b = (_a = res.data) === null || _a === void 0 ? void 0 : _a.items) === null || _b === void 0 ? void 0 : _b.length}`);
|
|
299
|
+
this.log(LoggerLevel.debug, `[object.create.recordsWithIterator] Chunk ${page} result: ${object_name}, code=${res.code}`);
|
|
300
|
+
this.log(LoggerLevel.trace, `[object.create.recordsWithIterator] Chunk ${page} data: ${JSON.stringify((_c = res.data) === null || _c === void 0 ? void 0 : _c.items)}`);
|
|
275
301
|
return res;
|
|
276
302
|
});
|
|
277
303
|
}
|
|
@@ -327,6 +353,15 @@ class Client {
|
|
|
327
353
|
*/
|
|
328
354
|
recordsWithIterator: async (params) => {
|
|
329
355
|
const { object_name, records } = params;
|
|
356
|
+
// 参数校验
|
|
357
|
+
if (!records || !Array.isArray(records)) {
|
|
358
|
+
this.log(LoggerLevel.error, '[object.update.recordsWithIterator] Invalid records parameter: must be a non-empty array');
|
|
359
|
+
throw new Error('参数 records 必须是一个数组');
|
|
360
|
+
}
|
|
361
|
+
if (records.length === 0) {
|
|
362
|
+
this.log(LoggerLevel.warn, '[object.update.recordsWithIterator] Empty records array provided, returning empty result');
|
|
363
|
+
return [];
|
|
364
|
+
}
|
|
330
365
|
const url = `/v1/data/namespaces/${this.namespace}/objects/${object_name}/records_batch`;
|
|
331
366
|
const chunkSize = 100;
|
|
332
367
|
const chunks = [];
|
|
@@ -403,6 +438,15 @@ class Client {
|
|
|
403
438
|
*/
|
|
404
439
|
recordsWithIterator: async (params) => {
|
|
405
440
|
const { object_name, ids } = params;
|
|
441
|
+
// 参数校验
|
|
442
|
+
if (!ids || !Array.isArray(ids)) {
|
|
443
|
+
this.log(LoggerLevel.error, '[object.delete.recordsWithIterator] Invalid ids parameter: must be a non-empty array');
|
|
444
|
+
throw new Error('参数 ids 必须是一个数组');
|
|
445
|
+
}
|
|
446
|
+
if (ids.length === 0) {
|
|
447
|
+
this.log(LoggerLevel.warn, '[object.delete.recordsWithIterator] Empty ids array provided, returning empty result');
|
|
448
|
+
return [];
|
|
449
|
+
}
|
|
406
450
|
const url = `/v1/data/namespaces/${this.namespace}/objects/${object_name}/records_batch`;
|
|
407
451
|
const chunkSize = 100;
|
|
408
452
|
const chunks = [];
|
|
@@ -456,7 +500,11 @@ class Client {
|
|
|
456
500
|
});
|
|
457
501
|
this.log(LoggerLevel.debug, `[department.exchange] Department ID exchanged: ${department_id}, code=${response.data.code}`);
|
|
458
502
|
this.log(LoggerLevel.trace, `[department.exchange] Response: ${JSON.stringify(response.data)}`);
|
|
459
|
-
|
|
503
|
+
if (response.data.code !== '0') {
|
|
504
|
+
this.log(LoggerLevel.error, `[department.exchange] Error exchanging department: code=${response.data.code}, msg=${response.data.msg}`);
|
|
505
|
+
throw new Error(response.data.msg || `Exchange failed with code ${response.data.code}`);
|
|
506
|
+
}
|
|
507
|
+
return response.data.data && response.data.data[0]; // 返回第一个元素
|
|
460
508
|
});
|
|
461
509
|
return res;
|
|
462
510
|
},
|
|
@@ -471,6 +519,15 @@ class Client {
|
|
|
471
519
|
// - 'department_id' (如 "1758534140403815")
|
|
472
520
|
// - 'external_department_id' (外部平台 department_id, 无固定格式)
|
|
473
521
|
// - 'external_open_department_id' (以 'oc_' 开头的 open_department_id)
|
|
522
|
+
// 参数校验
|
|
523
|
+
if (!department_ids || !Array.isArray(department_ids)) {
|
|
524
|
+
this.log(LoggerLevel.error, '[department.batchExchange] Invalid department_ids parameter: must be a non-empty array');
|
|
525
|
+
throw new Error('参数 department_ids 必须是一个数组');
|
|
526
|
+
}
|
|
527
|
+
if (department_ids.length === 0) {
|
|
528
|
+
this.log(LoggerLevel.warn, '[department.batchExchange] Empty department_ids array provided, returning empty result');
|
|
529
|
+
return [];
|
|
530
|
+
}
|
|
474
531
|
const url = '/api/integration/v2/feishu/getDepartments';
|
|
475
532
|
const chunkSize = 100;
|
|
476
533
|
const chunks = [];
|
|
@@ -491,7 +548,11 @@ class Client {
|
|
|
491
548
|
});
|
|
492
549
|
this.log(LoggerLevel.debug, `[department.batchExchange] Chunk ${index + 1} completed: code=${response.data.code}`);
|
|
493
550
|
this.log(LoggerLevel.trace, `[department.batchExchange] Chunk ${index + 1} response: ${JSON.stringify(response.data)}`);
|
|
494
|
-
|
|
551
|
+
if (response.data.code !== '0') {
|
|
552
|
+
this.log(LoggerLevel.error, `[department.batchExchange] Error exchanging departments: code=${response.data.code}, msg=${response.data.msg}`);
|
|
553
|
+
throw new Error(response.data.msg || `Exchange failed with code ${response.data.code}`);
|
|
554
|
+
}
|
|
555
|
+
return response.data.data || [];
|
|
495
556
|
});
|
|
496
557
|
results.push(...res);
|
|
497
558
|
}
|
|
@@ -562,14 +623,18 @@ class Client {
|
|
|
562
623
|
let totalPages = 0;
|
|
563
624
|
do {
|
|
564
625
|
await functionLimiter(async () => {
|
|
565
|
-
var _a, _b;
|
|
626
|
+
var _a, _b, _c, _d;
|
|
566
627
|
const res = await this.page.list({ limit, offset });
|
|
628
|
+
if (res.code !== '0') {
|
|
629
|
+
this.log(LoggerLevel.error, `[page.listWithIterator] Error fetching pages: code=${res.code}, msg=${res.msg}`);
|
|
630
|
+
throw new Error(res.msg || `Fetch failed with code ${res.code}`);
|
|
631
|
+
}
|
|
567
632
|
page += 1;
|
|
568
633
|
if (res.data && Array.isArray(res.data.items)) {
|
|
569
634
|
results = results.concat(res.data.items);
|
|
570
635
|
}
|
|
571
636
|
if (page === 1) {
|
|
572
|
-
total = res.data.total || 0;
|
|
637
|
+
total = ((_a = res.data) === null || _a === void 0 ? void 0 : _a.total) || 0;
|
|
573
638
|
totalPages = Math.ceil(total / limit);
|
|
574
639
|
this.log(LoggerLevel.info, `[page.listWithIterator] Starting paginated query: total=${total}, pages=${totalPages}`);
|
|
575
640
|
}
|
|
@@ -578,8 +643,8 @@ class Client {
|
|
|
578
643
|
const pageStr = page.toString().padStart(padLength, '0');
|
|
579
644
|
const totalPagesStr = totalPages.toString().padStart(padLength, '0');
|
|
580
645
|
this.log(LoggerLevel.info, `[page.listWithIterator] Page completed: [${pageStr}/${totalPagesStr}]`);
|
|
581
|
-
this.log(LoggerLevel.debug, `[page.listWithIterator] Page ${page} details: items=${(
|
|
582
|
-
this.log(LoggerLevel.trace, `[page.listWithIterator] Page ${page} data: ${JSON.stringify((
|
|
646
|
+
this.log(LoggerLevel.debug, `[page.listWithIterator] Page ${page} details: items=${(_c = (_b = res.data) === null || _b === void 0 ? void 0 : _b.items) === null || _c === void 0 ? void 0 : _c.length}, offset=${offset}`);
|
|
647
|
+
this.log(LoggerLevel.trace, `[page.listWithIterator] Page ${page} data: ${JSON.stringify((_d = res.data) === null || _d === void 0 ? void 0 : _d.items)}`);
|
|
583
648
|
return res;
|
|
584
649
|
});
|
|
585
650
|
} while (results.length < total);
|
|
@@ -819,18 +884,22 @@ class Client {
|
|
|
819
884
|
let totalPages = 0;
|
|
820
885
|
do {
|
|
821
886
|
await functionLimiter(async () => {
|
|
822
|
-
var _a, _b;
|
|
887
|
+
var _a, _b, _c, _d;
|
|
823
888
|
const requestParams = { limit, offset };
|
|
824
889
|
if (filter) {
|
|
825
890
|
requestParams.filter = filter;
|
|
826
891
|
}
|
|
827
892
|
const res = await this.global.options.list(requestParams);
|
|
893
|
+
if (res.code !== '0') {
|
|
894
|
+
this.log(LoggerLevel.error, `[global.options.listWithIterator] Error fetching global options: code=${res.code}, msg=${res.msg}`);
|
|
895
|
+
throw new Error(res.msg || `Fetch failed with code ${res.code}`);
|
|
896
|
+
}
|
|
828
897
|
page += 1;
|
|
829
898
|
if (res.data && Array.isArray(res.data.items)) {
|
|
830
899
|
results = results.concat(res.data.items);
|
|
831
900
|
}
|
|
832
901
|
if (page === 1) {
|
|
833
|
-
total = res.data.total || 0;
|
|
902
|
+
total = ((_a = res.data) === null || _a === void 0 ? void 0 : _a.total) || 0;
|
|
834
903
|
totalPages = Math.ceil(total / limit);
|
|
835
904
|
this.log(LoggerLevel.info, `[global.options.listWithIterator] Starting paginated query: total=${total}, pages=${totalPages}`);
|
|
836
905
|
}
|
|
@@ -839,8 +908,8 @@ class Client {
|
|
|
839
908
|
const pageStr = page.toString().padStart(padLength, '0');
|
|
840
909
|
const totalPagesStr = totalPages.toString().padStart(padLength, '0');
|
|
841
910
|
this.log(LoggerLevel.info, `[global.options.listWithIterator] Page completed: [${pageStr}/${totalPagesStr}]`);
|
|
842
|
-
this.log(LoggerLevel.debug, `[global.options.listWithIterator] Page ${page} details: items=${(
|
|
843
|
-
this.log(LoggerLevel.trace, `[global.options.listWithIterator] Page ${page} data: ${JSON.stringify((
|
|
911
|
+
this.log(LoggerLevel.debug, `[global.options.listWithIterator] Page ${page} details: items=${(_c = (_b = res.data) === null || _b === void 0 ? void 0 : _b.items) === null || _c === void 0 ? void 0 : _c.length}, offset=${offset}`);
|
|
912
|
+
this.log(LoggerLevel.trace, `[global.options.listWithIterator] Page ${page} data: ${JSON.stringify((_d = res.data) === null || _d === void 0 ? void 0 : _d.items)}`);
|
|
844
913
|
return res;
|
|
845
914
|
});
|
|
846
915
|
} while (results.length < total);
|
|
@@ -910,18 +979,22 @@ class Client {
|
|
|
910
979
|
let totalPages = 0;
|
|
911
980
|
do {
|
|
912
981
|
await functionLimiter(async () => {
|
|
913
|
-
var _a, _b;
|
|
982
|
+
var _a, _b, _c, _d;
|
|
914
983
|
const requestParams = { limit, offset };
|
|
915
984
|
if (filter) {
|
|
916
985
|
requestParams.filter = filter;
|
|
917
986
|
}
|
|
918
987
|
const res = await this.global.variables.list(requestParams);
|
|
988
|
+
if (res.code !== '0') {
|
|
989
|
+
this.log(LoggerLevel.error, `[global.variables.listWithIterator] Error fetching global variables: code=${res.code}, msg=${res.msg}`);
|
|
990
|
+
throw new Error(res.msg || `Fetch failed with code ${res.code}`);
|
|
991
|
+
}
|
|
919
992
|
page += 1;
|
|
920
993
|
if (res.data && Array.isArray(res.data.items)) {
|
|
921
994
|
results = results.concat(res.data.items);
|
|
922
995
|
}
|
|
923
996
|
if (page === 1) {
|
|
924
|
-
total = res.data.total || 0;
|
|
997
|
+
total = ((_a = res.data) === null || _a === void 0 ? void 0 : _a.total) || 0;
|
|
925
998
|
totalPages = Math.ceil(total / limit);
|
|
926
999
|
this.log(LoggerLevel.info, `[global.variables.listWithIterator] Starting paginated query: total=${total}, pages=${totalPages}`);
|
|
927
1000
|
}
|
|
@@ -930,8 +1003,8 @@ class Client {
|
|
|
930
1003
|
const pageStr = page.toString().padStart(padLength, '0');
|
|
931
1004
|
const totalPagesStr = totalPages.toString().padStart(padLength, '0');
|
|
932
1005
|
this.log(LoggerLevel.info, `[global.variables.listWithIterator] Page completed: [${pageStr}/${totalPagesStr}]`);
|
|
933
|
-
this.log(LoggerLevel.debug, `[global.variables.listWithIterator] Page ${page} details: items=${(
|
|
934
|
-
this.log(LoggerLevel.trace, `[global.variables.listWithIterator] Page ${page} data: ${JSON.stringify((
|
|
1006
|
+
this.log(LoggerLevel.debug, `[global.variables.listWithIterator] Page ${page} details: items=${(_c = (_b = res.data) === null || _b === void 0 ? void 0 : _b.items) === null || _c === void 0 ? void 0 : _c.length}, offset=${offset}`);
|
|
1007
|
+
this.log(LoggerLevel.trace, `[global.variables.listWithIterator] Page ${page} data: ${JSON.stringify((_d = res.data) === null || _d === void 0 ? void 0 : _d.items)}`);
|
|
935
1008
|
return res;
|
|
936
1009
|
});
|
|
937
1010
|
} while (results.length < total);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "apaas-oapi-client",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.23",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./dist/index.js",
|
|
@@ -11,8 +11,9 @@
|
|
|
11
11
|
"scripts": {
|
|
12
12
|
"build": "rollup -c",
|
|
13
13
|
"test": "jest",
|
|
14
|
+
"test:manual": "tsx test/test.ts",
|
|
14
15
|
"dev": "ts-node src/index.ts",
|
|
15
|
-
"release": "npm run build &&
|
|
16
|
+
"release": "npm run build && npm version patch && git push origin main --follow-tags"
|
|
16
17
|
},
|
|
17
18
|
"keywords": [],
|
|
18
19
|
"author": "",
|
package/src/index.ts
CHANGED
|
@@ -305,7 +305,7 @@ class Client {
|
|
|
305
305
|
const { object_name, data } = params;
|
|
306
306
|
|
|
307
307
|
let results: any[] = [];
|
|
308
|
-
let nextPageToken: string | undefined =
|
|
308
|
+
let nextPageToken: string | undefined = undefined;
|
|
309
309
|
let total = 0;
|
|
310
310
|
let page = 0;
|
|
311
311
|
let totalPages = 0;
|
|
@@ -314,33 +314,44 @@ class Client {
|
|
|
314
314
|
|
|
315
315
|
do {
|
|
316
316
|
const pageRes = await functionLimiter(async () => {
|
|
317
|
-
const mergedData = { ...data
|
|
317
|
+
const mergedData: any = { ...data };
|
|
318
|
+
if (nextPageToken) {
|
|
319
|
+
mergedData.page_token = nextPageToken;
|
|
320
|
+
}
|
|
318
321
|
|
|
319
322
|
const res = await this.object.search.records({
|
|
320
323
|
object_name,
|
|
321
324
|
data: mergedData
|
|
322
325
|
});
|
|
323
326
|
|
|
327
|
+
if (res.code !== '0') {
|
|
328
|
+
this.log(LoggerLevel.error, `[object.search.recordsWithIterator] Error querying records: code=${res.code}, msg=${res.msg}`);
|
|
329
|
+
throw new Error(res.msg || `Query failed with code ${res.code}`);
|
|
330
|
+
}
|
|
331
|
+
|
|
324
332
|
page += 1;
|
|
325
333
|
|
|
326
334
|
if (res.data && Array.isArray(res.data.items)) {
|
|
327
335
|
results = results.concat(res.data.items);
|
|
328
336
|
}
|
|
329
337
|
|
|
338
|
+
if (res.data && (res.data.total !== undefined && res.data.total !== null)) {
|
|
339
|
+
total = res.data.total;
|
|
340
|
+
}
|
|
341
|
+
|
|
330
342
|
if (page === 1) {
|
|
331
|
-
total = res.data.total || 0;
|
|
332
343
|
totalPages = Math.ceil(total / pageSize);
|
|
333
344
|
this.log(LoggerLevel.info, `[object.search.recordsWithIterator] Starting paginated query: ${object_name}, total=${total}, pages=${totalPages}`);
|
|
334
345
|
}
|
|
335
346
|
|
|
336
|
-
nextPageToken = res.data
|
|
347
|
+
nextPageToken = res.data?.next_page_token;
|
|
337
348
|
|
|
338
349
|
const padLength = totalPages.toString().length;
|
|
339
350
|
const pageStr = page.toString().padStart(padLength, '0');
|
|
340
351
|
const totalPagesStr = totalPages.toString().padStart(padLength, '0');
|
|
341
352
|
|
|
342
353
|
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
|
|
354
|
+
this.log(LoggerLevel.debug, `[object.search.recordsWithIterator] Page ${page} details: items=${res.data?.items?.length}, nextToken=${nextPageToken || 'none'}`);
|
|
344
355
|
this.log(LoggerLevel.trace, `[object.search.recordsWithIterator] Page ${page} data: ${JSON.stringify(res.data?.items)}`);
|
|
345
356
|
|
|
346
357
|
return res;
|
|
@@ -420,6 +431,17 @@ class Client {
|
|
|
420
431
|
recordsWithIterator: async (params: { object_name: string; records: any[] }): Promise<{ total: number; items: any[] }> => {
|
|
421
432
|
const { object_name, records } = params;
|
|
422
433
|
|
|
434
|
+
// 参数校验
|
|
435
|
+
if (!records || !Array.isArray(records)) {
|
|
436
|
+
this.log(LoggerLevel.error, '[object.create.recordsWithIterator] Invalid records parameter: must be a non-empty array');
|
|
437
|
+
throw new Error('参数 records 必须是一个数组');
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
if (records.length === 0) {
|
|
441
|
+
this.log(LoggerLevel.warn, '[object.create.recordsWithIterator] Empty records array provided, returning empty result');
|
|
442
|
+
return { total: 0, items: [] };
|
|
443
|
+
}
|
|
444
|
+
|
|
423
445
|
let results: any[] = [];
|
|
424
446
|
let total = records.length;
|
|
425
447
|
const chunkSize = 100;
|
|
@@ -443,13 +465,21 @@ class Client {
|
|
|
443
465
|
records: chunk
|
|
444
466
|
});
|
|
445
467
|
|
|
468
|
+
if (res.code !== '0') {
|
|
469
|
+
this.log(LoggerLevel.error, `[object.create.recordsWithIterator] Error creating records: code=${res.code}, msg=${res.msg}`);
|
|
470
|
+
// Should we throw? Probably yes, to stop partial creation or notify user.
|
|
471
|
+
// But maybe user wants partial success?
|
|
472
|
+
// Given other methods throw, I'll throw here too.
|
|
473
|
+
throw new Error(res.msg || `Creation failed with code ${res.code}`);
|
|
474
|
+
}
|
|
475
|
+
|
|
446
476
|
if (res.data && Array.isArray(res.data.items)) {
|
|
447
477
|
results = results.concat(res.data.items);
|
|
448
478
|
}
|
|
449
479
|
|
|
450
|
-
this.log(LoggerLevel.info, `[object.create.recordsWithIterator] Chunk ${page} completed: ${object_name}, created=${res.data
|
|
451
|
-
this.log(LoggerLevel.debug, `[object.create.recordsWithIterator] Chunk ${page} result: ${object_name}, code=${res.
|
|
452
|
-
this.log(LoggerLevel.trace, `[object.create.recordsWithIterator] Chunk ${page} data: ${JSON.stringify(res.data
|
|
480
|
+
this.log(LoggerLevel.info, `[object.create.recordsWithIterator] Chunk ${page} completed: ${object_name}, created=${res.data?.items?.length}`);
|
|
481
|
+
this.log(LoggerLevel.debug, `[object.create.recordsWithIterator] Chunk ${page} result: ${object_name}, code=${res.code}`);
|
|
482
|
+
this.log(LoggerLevel.trace, `[object.create.recordsWithIterator] Chunk ${page} data: ${JSON.stringify(res.data?.items)}`);
|
|
453
483
|
|
|
454
484
|
return res;
|
|
455
485
|
});
|
|
@@ -521,6 +551,18 @@ class Client {
|
|
|
521
551
|
*/
|
|
522
552
|
recordsWithIterator: async (params: { object_name: string; records: any[] }): Promise<any[]> => {
|
|
523
553
|
const { object_name, records } = params;
|
|
554
|
+
|
|
555
|
+
// 参数校验
|
|
556
|
+
if (!records || !Array.isArray(records)) {
|
|
557
|
+
this.log(LoggerLevel.error, '[object.update.recordsWithIterator] Invalid records parameter: must be a non-empty array');
|
|
558
|
+
throw new Error('参数 records 必须是一个数组');
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
if (records.length === 0) {
|
|
562
|
+
this.log(LoggerLevel.warn, '[object.update.recordsWithIterator] Empty records array provided, returning empty result');
|
|
563
|
+
return [];
|
|
564
|
+
}
|
|
565
|
+
|
|
524
566
|
const url = `/v1/data/namespaces/${this.namespace}/objects/${object_name}/records_batch`;
|
|
525
567
|
|
|
526
568
|
const chunkSize = 100;
|
|
@@ -619,6 +661,18 @@ class Client {
|
|
|
619
661
|
*/
|
|
620
662
|
recordsWithIterator: async (params: { object_name: string; ids: string[] }): Promise<any[]> => {
|
|
621
663
|
const { object_name, ids } = params;
|
|
664
|
+
|
|
665
|
+
// 参数校验
|
|
666
|
+
if (!ids || !Array.isArray(ids)) {
|
|
667
|
+
this.log(LoggerLevel.error, '[object.delete.recordsWithIterator] Invalid ids parameter: must be a non-empty array');
|
|
668
|
+
throw new Error('参数 ids 必须是一个数组');
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
if (ids.length === 0) {
|
|
672
|
+
this.log(LoggerLevel.warn, '[object.delete.recordsWithIterator] Empty ids array provided, returning empty result');
|
|
673
|
+
return [];
|
|
674
|
+
}
|
|
675
|
+
|
|
622
676
|
const url = `/v1/data/namespaces/${this.namespace}/objects/${object_name}/records_batch`;
|
|
623
677
|
|
|
624
678
|
const chunkSize = 100;
|
|
@@ -690,7 +744,13 @@ class Client {
|
|
|
690
744
|
|
|
691
745
|
this.log(LoggerLevel.debug, `[department.exchange] Department ID exchanged: ${department_id}, code=${response.data.code}`);
|
|
692
746
|
this.log(LoggerLevel.trace, `[department.exchange] Response: ${JSON.stringify(response.data)}`);
|
|
693
|
-
|
|
747
|
+
|
|
748
|
+
if (response.data.code !== '0') {
|
|
749
|
+
this.log(LoggerLevel.error, `[department.exchange] Error exchanging department: code=${response.data.code}, msg=${response.data.msg}`);
|
|
750
|
+
throw new Error(response.data.msg || `Exchange failed with code ${response.data.code}`);
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
return response.data.data && response.data.data[0]; // 返回第一个元素
|
|
694
754
|
});
|
|
695
755
|
|
|
696
756
|
return res;
|
|
@@ -708,6 +768,17 @@ class Client {
|
|
|
708
768
|
// - 'external_department_id' (外部平台 department_id, 无固定格式)
|
|
709
769
|
// - 'external_open_department_id' (以 'oc_' 开头的 open_department_id)
|
|
710
770
|
|
|
771
|
+
// 参数校验
|
|
772
|
+
if (!department_ids || !Array.isArray(department_ids)) {
|
|
773
|
+
this.log(LoggerLevel.error, '[department.batchExchange] Invalid department_ids parameter: must be a non-empty array');
|
|
774
|
+
throw new Error('参数 department_ids 必须是一个数组');
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
if (department_ids.length === 0) {
|
|
778
|
+
this.log(LoggerLevel.warn, '[department.batchExchange] Empty department_ids array provided, returning empty result');
|
|
779
|
+
return [];
|
|
780
|
+
}
|
|
781
|
+
|
|
711
782
|
const url = '/api/integration/v2/feishu/getDepartments';
|
|
712
783
|
|
|
713
784
|
const chunkSize = 100;
|
|
@@ -738,7 +809,13 @@ class Client {
|
|
|
738
809
|
|
|
739
810
|
this.log(LoggerLevel.debug, `[department.batchExchange] Chunk ${index + 1} completed: code=${response.data.code}`);
|
|
740
811
|
this.log(LoggerLevel.trace, `[department.batchExchange] Chunk ${index + 1} response: ${JSON.stringify(response.data)}`);
|
|
741
|
-
|
|
812
|
+
|
|
813
|
+
if (response.data.code !== '0') {
|
|
814
|
+
this.log(LoggerLevel.error, `[department.batchExchange] Error exchanging departments: code=${response.data.code}, msg=${response.data.msg}`);
|
|
815
|
+
throw new Error(response.data.msg || `Exchange failed with code ${response.data.code}`);
|
|
816
|
+
}
|
|
817
|
+
|
|
818
|
+
return response.data.data || [];
|
|
742
819
|
});
|
|
743
820
|
|
|
744
821
|
results.push(...res);
|
|
@@ -835,6 +912,11 @@ class Client {
|
|
|
835
912
|
const pageRes = await functionLimiter(async () => {
|
|
836
913
|
const res = await this.page.list({ limit, offset });
|
|
837
914
|
|
|
915
|
+
if (res.code !== '0') {
|
|
916
|
+
this.log(LoggerLevel.error, `[page.listWithIterator] Error fetching pages: code=${res.code}, msg=${res.msg}`);
|
|
917
|
+
throw new Error(res.msg || `Fetch failed with code ${res.code}`);
|
|
918
|
+
}
|
|
919
|
+
|
|
838
920
|
page += 1;
|
|
839
921
|
|
|
840
922
|
if (res.data && Array.isArray(res.data.items)) {
|
|
@@ -842,7 +924,7 @@ class Client {
|
|
|
842
924
|
}
|
|
843
925
|
|
|
844
926
|
if (page === 1) {
|
|
845
|
-
total = res.data
|
|
927
|
+
total = res.data?.total || 0;
|
|
846
928
|
totalPages = Math.ceil(total / limit);
|
|
847
929
|
this.log(LoggerLevel.info, `[page.listWithIterator] Starting paginated query: total=${total}, pages=${totalPages}`);
|
|
848
930
|
}
|
|
@@ -854,7 +936,7 @@ class Client {
|
|
|
854
936
|
const totalPagesStr = totalPages.toString().padStart(padLength, '0');
|
|
855
937
|
|
|
856
938
|
this.log(LoggerLevel.info, `[page.listWithIterator] Page completed: [${pageStr}/${totalPagesStr}]`);
|
|
857
|
-
this.log(LoggerLevel.debug, `[page.listWithIterator] Page ${page} details: items=${res.data
|
|
939
|
+
this.log(LoggerLevel.debug, `[page.listWithIterator] Page ${page} details: items=${res.data?.items?.length}, offset=${offset}`);
|
|
858
940
|
this.log(LoggerLevel.trace, `[page.listWithIterator] Page ${page} data: ${JSON.stringify(res.data?.items)}`);
|
|
859
941
|
|
|
860
942
|
return res;
|
|
@@ -1160,6 +1242,11 @@ class Client {
|
|
|
1160
1242
|
|
|
1161
1243
|
const res = await this.global.options.list(requestParams);
|
|
1162
1244
|
|
|
1245
|
+
if (res.code !== '0') {
|
|
1246
|
+
this.log(LoggerLevel.error, `[global.options.listWithIterator] Error fetching global options: code=${res.code}, msg=${res.msg}`);
|
|
1247
|
+
throw new Error(res.msg || `Fetch failed with code ${res.code}`);
|
|
1248
|
+
}
|
|
1249
|
+
|
|
1163
1250
|
page += 1;
|
|
1164
1251
|
|
|
1165
1252
|
if (res.data && Array.isArray(res.data.items)) {
|
|
@@ -1167,7 +1254,7 @@ class Client {
|
|
|
1167
1254
|
}
|
|
1168
1255
|
|
|
1169
1256
|
if (page === 1) {
|
|
1170
|
-
total = res.data
|
|
1257
|
+
total = res.data?.total || 0;
|
|
1171
1258
|
totalPages = Math.ceil(total / limit);
|
|
1172
1259
|
this.log(LoggerLevel.info, `[global.options.listWithIterator] Starting paginated query: total=${total}, pages=${totalPages}`);
|
|
1173
1260
|
}
|
|
@@ -1179,7 +1266,7 @@ class Client {
|
|
|
1179
1266
|
const totalPagesStr = totalPages.toString().padStart(padLength, '0');
|
|
1180
1267
|
|
|
1181
1268
|
this.log(LoggerLevel.info, `[global.options.listWithIterator] Page completed: [${pageStr}/${totalPagesStr}]`);
|
|
1182
|
-
this.log(LoggerLevel.debug, `[global.options.listWithIterator] Page ${page} details: items=${res.data
|
|
1269
|
+
this.log(LoggerLevel.debug, `[global.options.listWithIterator] Page ${page} details: items=${res.data?.items?.length}, offset=${offset}`);
|
|
1183
1270
|
this.log(LoggerLevel.trace, `[global.options.listWithIterator] Page ${page} data: ${JSON.stringify(res.data?.items)}`);
|
|
1184
1271
|
|
|
1185
1272
|
return res;
|
|
@@ -1274,6 +1361,11 @@ class Client {
|
|
|
1274
1361
|
|
|
1275
1362
|
const res = await this.global.variables.list(requestParams);
|
|
1276
1363
|
|
|
1364
|
+
if (res.code !== '0') {
|
|
1365
|
+
this.log(LoggerLevel.error, `[global.variables.listWithIterator] Error fetching global variables: code=${res.code}, msg=${res.msg}`);
|
|
1366
|
+
throw new Error(res.msg || `Fetch failed with code ${res.code}`);
|
|
1367
|
+
}
|
|
1368
|
+
|
|
1277
1369
|
page += 1;
|
|
1278
1370
|
|
|
1279
1371
|
if (res.data && Array.isArray(res.data.items)) {
|
|
@@ -1281,7 +1373,7 @@ class Client {
|
|
|
1281
1373
|
}
|
|
1282
1374
|
|
|
1283
1375
|
if (page === 1) {
|
|
1284
|
-
total = res.data
|
|
1376
|
+
total = res.data?.total || 0;
|
|
1285
1377
|
totalPages = Math.ceil(total / limit);
|
|
1286
1378
|
this.log(LoggerLevel.info, `[global.variables.listWithIterator] Starting paginated query: total=${total}, pages=${totalPages}`);
|
|
1287
1379
|
}
|
|
@@ -1293,7 +1385,7 @@ class Client {
|
|
|
1293
1385
|
const totalPagesStr = totalPages.toString().padStart(padLength, '0');
|
|
1294
1386
|
|
|
1295
1387
|
this.log(LoggerLevel.info, `[global.variables.listWithIterator] Page completed: [${pageStr}/${totalPagesStr}]`);
|
|
1296
|
-
this.log(LoggerLevel.debug, `[global.variables.listWithIterator] Page ${page} details: items=${res.data
|
|
1388
|
+
this.log(LoggerLevel.debug, `[global.variables.listWithIterator] Page ${page} details: items=${res.data?.items?.length}, offset=${offset}`);
|
|
1297
1389
|
this.log(LoggerLevel.trace, `[global.variables.listWithIterator] Page ${page} data: ${JSON.stringify(res.data?.items)}`);
|
|
1298
1390
|
|
|
1299
1391
|
return res;
|
|
File without changes
|
|
File without changes
|
|
File without changes
|