apaas-oapi-client 0.1.17 → 0.1.19

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/UserManual.md CHANGED
@@ -456,7 +456,7 @@ console.log('Items:', items);
456
456
 
457
457
  ```JavaScript
458
458
  const res = await client.page.detail({
459
- page_id: 'appPage_aadd64dlqamdo'
459
+ page_id: 'appPage_page'
460
460
  });
461
461
  console.log(res);
462
462
  ```
@@ -465,14 +465,14 @@ console.log(res);
465
465
 
466
466
  ```JavaScript
467
467
  const res = await client.page.url({
468
- page_id: 'appPage_aadd64dlqamdo',
469
- pageParams: { var_EzpvJsER: '1234567890' },
468
+ page_id: 'appPage_page',
469
+ pageParams: { var_page: '1234567890' },
470
470
  parentPageParams: {
471
- navId: 'aadd64bapmic2',
472
- pageApiName: 'page_aaddmtkqgicbg'
471
+ navId: 'page_nav_id',
472
+ pageApiName: 'page_name'
473
473
  },
474
- navId: 'aadd64bapmic2',
475
- tabId: 'tab_legqch3h'
474
+ navId: 'page_nav_id',
475
+ tabId: 'tab_id'
476
476
  });
477
477
  console.log(res);
478
478
  // 返回: { code: "0", msg: "success", data: { link: "https://..." } }
@@ -510,7 +510,53 @@ console.log(res);
510
510
 
511
511
  ***
512
512
 
513
+ <br>
513
514
 
515
+ # **🔄 自动化流程模块**
516
+
517
+ ## **V1 版本 - 执行流程**
518
+
519
+ ```JavaScript
520
+ const res = await client.automation.v1.execute({
521
+ flow_api_name: 'automation_cd05fdab67d',
522
+ operator: {
523
+ _id: 100,
524
+ email: 'sample@feishu.cn'
525
+ },
526
+ params: {
527
+ varRecord_ab67d031d44: {
528
+ _id: 100
529
+ }
530
+ }
531
+ });
532
+ console.log(res);
533
+ // 返回: { code: "0", msg: "success", data: { errMsg, executionId, status, data, errCode } }
534
+ ```
535
+
536
+ ## **V2 版本 - 执行流程**
537
+
538
+ V2 版本支持流程重新提交功能。
539
+
540
+ ```JavaScript
541
+ const res = await client.automation.v2.execute({
542
+ flow_api_name: 'automation_a9ec6ee5fb1',
543
+ operator: {
544
+ _id: 100,
545
+ email: 'sample@feishu.cn'
546
+ },
547
+ params: {
548
+ storeId: 100
549
+ },
550
+ is_resubmit: true,
551
+ pre_instance_id: '1835957428957195'
552
+ });
553
+ console.log(res);
554
+ // 返回: { code: "0", msg: "success", data: { errMsg, executionId, status, data, errCode } }
555
+ ```
556
+
557
+ ***
558
+
559
+ <br>
514
560
 
515
561
  # **☁️ 云函数模块**
516
562
 
@@ -524,7 +570,7 @@ console.log(res);
524
570
 
525
571
  ***
526
572
 
527
-
573
+ <br>
528
574
 
529
575
  ## **🛠️ 高级**
530
576
 
package/dist/index.d.ts CHANGED
@@ -463,6 +463,49 @@ declare class Client {
463
463
  }>;
464
464
  };
465
465
  };
466
+ /**
467
+ * 自动化流程模块
468
+ */
469
+ automation: {
470
+ /**
471
+ * V1 版本
472
+ */
473
+ v1: {
474
+ /**
475
+ * 执行流程
476
+ * @param params 请求参数 { flow_api_name: string, operator: { _id: number, email: string }, params: any }
477
+ * @returns 接口返回结果
478
+ */
479
+ execute: (params: {
480
+ flow_api_name: string;
481
+ operator: {
482
+ _id: number;
483
+ email: string;
484
+ };
485
+ params: any;
486
+ }) => Promise<any>;
487
+ };
488
+ /**
489
+ * V2 版本
490
+ */
491
+ v2: {
492
+ /**
493
+ * 执行流程
494
+ * @param params 请求参数 { flow_api_name: string, operator: { _id: number, email: string }, params: any, is_resubmit?: boolean, pre_instance_id?: string }
495
+ * @returns 接口返回结果
496
+ */
497
+ execute: (params: {
498
+ flow_api_name: string;
499
+ operator: {
500
+ _id: number;
501
+ email: string;
502
+ };
503
+ params: any;
504
+ is_resubmit?: boolean;
505
+ pre_instance_id?: string;
506
+ }) => Promise<any>;
507
+ };
508
+ };
466
509
  }
467
510
  export declare const apaas: {
468
511
  Client: typeof Client;
package/dist/index.js CHANGED
@@ -935,6 +935,74 @@ class Client {
935
935
  }
936
936
  }
937
937
  };
938
+ /**
939
+ * 自动化流程模块
940
+ */
941
+ this.automation = {
942
+ /**
943
+ * V1 版本
944
+ */
945
+ v1: {
946
+ /**
947
+ * 执行流程
948
+ * @param params 请求参数 { flow_api_name: string, operator: { _id: number, email: string }, params: any }
949
+ * @returns 接口返回结果
950
+ */
951
+ execute: async (params) => {
952
+ const { flow_api_name, operator, params: flowParams } = params;
953
+ await this.ensureTokenValid();
954
+ const url = `/api/flow/v1/namespaces/${this.namespace}/flows/${flow_api_name}/execute`;
955
+ this.log(LoggerLevel.info, `[automation.v1.execute] Executing flow: ${flow_api_name}`);
956
+ const res = await this.axiosInstance.post(url, {
957
+ operator,
958
+ params: flowParams
959
+ }, {
960
+ headers: {
961
+ Authorization: `${this.accessToken}`,
962
+ 'Content-Type': 'application/json'
963
+ }
964
+ });
965
+ this.log(LoggerLevel.debug, `[automation.v1.execute] Flow executed: ${flow_api_name}, code=${res.data.code}`);
966
+ this.log(LoggerLevel.trace, `[automation.v1.execute] Response: ${JSON.stringify(res.data)}`);
967
+ return res.data;
968
+ }
969
+ },
970
+ /**
971
+ * V2 版本
972
+ */
973
+ v2: {
974
+ /**
975
+ * 执行流程
976
+ * @param params 请求参数 { flow_api_name: string, operator: { _id: number, email: string }, params: any, is_resubmit?: boolean, pre_instance_id?: string }
977
+ * @returns 接口返回结果
978
+ */
979
+ execute: async (params) => {
980
+ const { flow_api_name, operator, params: flowParams, is_resubmit, pre_instance_id } = params;
981
+ await this.ensureTokenValid();
982
+ const url = `/v2/namespaces/${this.namespace}/flows/${flow_api_name}/execute`;
983
+ this.log(LoggerLevel.info, `[automation.v2.execute] Executing flow: ${flow_api_name}`);
984
+ const requestData = {
985
+ operator,
986
+ params: flowParams
987
+ };
988
+ if (is_resubmit !== undefined) {
989
+ requestData.is_resubmit = is_resubmit;
990
+ }
991
+ if (pre_instance_id) {
992
+ requestData.pre_instance_id = pre_instance_id;
993
+ }
994
+ const res = await this.axiosInstance.post(url, requestData, {
995
+ headers: {
996
+ Authorization: `${this.accessToken}`,
997
+ 'Content-Type': 'application/json'
998
+ }
999
+ });
1000
+ this.log(LoggerLevel.debug, `[automation.v2.execute] Flow executed: ${flow_api_name}, code=${res.data.code}`);
1001
+ this.log(LoggerLevel.trace, `[automation.v2.execute] Response: ${JSON.stringify(res.data)}`);
1002
+ return res.data;
1003
+ }
1004
+ }
1005
+ };
938
1006
  this.clientId = options.clientId;
939
1007
  this.clientSecret = options.clientSecret;
940
1008
  this.namespace = options.namespace;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "apaas-oapi-client",
3
- "version": "0.1.17",
3
+ "version": "0.1.19",
4
4
  "main": "dist/index.js",
5
5
  "exports": {
6
6
  ".": "./dist/index.js",
package/src/index.ts CHANGED
@@ -1298,6 +1298,98 @@ class Client {
1298
1298
  }
1299
1299
  }
1300
1300
  };
1301
+
1302
+ /**
1303
+ * 自动化流程模块
1304
+ */
1305
+ public automation = {
1306
+ /**
1307
+ * V1 版本
1308
+ */
1309
+ v1: {
1310
+ /**
1311
+ * 执行流程
1312
+ * @param params 请求参数 { flow_api_name: string, operator: { _id: number, email: string }, params: any }
1313
+ * @returns 接口返回结果
1314
+ */
1315
+ execute: async (params: { flow_api_name: string; operator: { _id: number; email: string }; params: any }): Promise<any> => {
1316
+ const { flow_api_name, operator, params: flowParams } = params;
1317
+ await this.ensureTokenValid();
1318
+
1319
+ const url = `/api/flow/v1/namespaces/${this.namespace}/flows/${flow_api_name}/execute`;
1320
+
1321
+ this.log(LoggerLevel.info, `[automation.v1.execute] Executing flow: ${flow_api_name}`);
1322
+
1323
+ const res = await this.axiosInstance.post(
1324
+ url,
1325
+ {
1326
+ operator,
1327
+ params: flowParams
1328
+ },
1329
+ {
1330
+ headers: {
1331
+ Authorization: `${this.accessToken}`,
1332
+ 'Content-Type': 'application/json'
1333
+ }
1334
+ }
1335
+ );
1336
+
1337
+ this.log(LoggerLevel.debug, `[automation.v1.execute] Flow executed: ${flow_api_name}, code=${res.data.code}`);
1338
+ this.log(LoggerLevel.trace, `[automation.v1.execute] Response: ${JSON.stringify(res.data)}`);
1339
+
1340
+ return res.data;
1341
+ }
1342
+ },
1343
+
1344
+ /**
1345
+ * V2 版本
1346
+ */
1347
+ v2: {
1348
+ /**
1349
+ * 执行流程
1350
+ * @param params 请求参数 { flow_api_name: string, operator: { _id: number, email: string }, params: any, is_resubmit?: boolean, pre_instance_id?: string }
1351
+ * @returns 接口返回结果
1352
+ */
1353
+ execute: async (params: {
1354
+ flow_api_name: string;
1355
+ operator: { _id: number; email: string };
1356
+ params: any;
1357
+ is_resubmit?: boolean;
1358
+ pre_instance_id?: string;
1359
+ }): Promise<any> => {
1360
+ const { flow_api_name, operator, params: flowParams, is_resubmit, pre_instance_id } = params;
1361
+ await this.ensureTokenValid();
1362
+
1363
+ const url = `/v2/namespaces/${this.namespace}/flows/${flow_api_name}/execute`;
1364
+
1365
+ this.log(LoggerLevel.info, `[automation.v2.execute] Executing flow: ${flow_api_name}`);
1366
+
1367
+ const requestData: any = {
1368
+ operator,
1369
+ params: flowParams
1370
+ };
1371
+
1372
+ if (is_resubmit !== undefined) {
1373
+ requestData.is_resubmit = is_resubmit;
1374
+ }
1375
+ if (pre_instance_id) {
1376
+ requestData.pre_instance_id = pre_instance_id;
1377
+ }
1378
+
1379
+ const res = await this.axiosInstance.post(url, requestData, {
1380
+ headers: {
1381
+ Authorization: `${this.accessToken}`,
1382
+ 'Content-Type': 'application/json'
1383
+ }
1384
+ });
1385
+
1386
+ this.log(LoggerLevel.debug, `[automation.v2.execute] Flow executed: ${flow_api_name}, code=${res.data.code}`);
1387
+ this.log(LoggerLevel.trace, `[automation.v2.execute] Response: ${JSON.stringify(res.data)}`);
1388
+
1389
+ return res.data;
1390
+ }
1391
+ }
1392
+ };
1301
1393
  }
1302
1394
 
1303
1395
  export const apaas = {
@@ -1,568 +0,0 @@
1
- # 背景
2
-
3
- aPaaS 平台有完整的 Open API 能力,但是目前这些能力全都以单独接口的形式提供给开发者,不方便开发者调试和调用。
4
- 在此背景下,我们在一店一群项目的基础上,封装 aPaaS 平台 RESTful API 的 Node.js SDK,简化接口调用,内置限流与 token 缓存功能。
5
-
6
- ## ✨ **功能特性**
7
-
8
- - ✅ 获取 accessToken,自动管理 token 有效期
9
-
10
- - ✅ record 单条查询、批量查询(支持分页迭代)
11
-
12
- - ✅ record 单条创建、批量创建(支持分页迭代)
13
-
14
- - ✅ record 单条更新、批量更新
15
-
16
- - ✅ record 单条删除、批量删除
17
-
18
- - ✅ 内置 Bottleneck 限流器,基于 API 接口配置限流规则
19
-
20
- - ✅ 自定义日志等级
21
-
22
- - ……
23
-
24
-
25
- <br>
26
-
27
- <br>
28
-
29
- **📦 安装**
30
-
31
- ```Bash
32
- npm install apaas-oapi-client
33
- # or
34
- yarn add apaas-oapi-client
35
- ```
36
-
37
- ***
38
-
39
- <br>
40
-
41
- # **🚀 快速开始**
42
-
43
- ```JavaScript
44
- const { apaas } = require('apaas-oapi-client');
45
-
46
- async function main() {
47
- const client = new apaas.Client({
48
- clientId: 'your_client_id',
49
- clientSecret: 'your_client_secret',
50
- namespace: 'app_xxx'
51
- });
52
-
53
- await client.init();
54
- client.setLoggerLevel(3); // 设置日志等级 (0-5)
55
-
56
- console.log('Access Token:', client.token);
57
- console.log('Namespace:', client.currentNamespace);
58
- }
59
-
60
- main();
61
- ```
62
-
63
- ***
64
-
65
- <br>
66
-
67
- ## **🔐 认证**
68
-
69
- ### **初始化 Client**
70
-
71
- | **参数** | **类型** | **说明** |
72
- | :-- | :-- | :-- |
73
- | clientId | string | 应用 clientId |
74
- | clientSecret | string | 应用 clientSecret |
75
- | namespace | string | 命名空间 |
76
- | disableTokenCache | boolean | 是否禁用 token 缓存,默认 false |
77
-
78
- ***
79
-
80
- <br>
81
-
82
- ## **📝 日志等级**
83
-
84
- 可调用 setLoggerLevel(level) 设置日志等级。
85
-
86
- | **Level** | **名称** | **说明** |
87
- | :-- | :-- | :-- |
88
- | 0 | fatal | 严重错误 |
89
- | 1 | error | 错误 |
90
- | 2 | warn | 警告 |
91
- | 3 | info | 信息(默认) |
92
- | 4 | debug | 调试信息 |
93
- | 5 | trace | 追踪 |
94
-
95
- ***
96
-
97
- <br>
98
-
99
- # 💾 **数据模块**
100
-
101
- ## **📋 对象列表接口**
102
-
103
- ### **获取所有对象(数据表)**
104
-
105
- ```JavaScript
106
- const res = await client.object.list({
107
- offset: 0,
108
- limit: 100,
109
- filter: {
110
- type: 'custom',
111
- quickQuery: 'store'
112
- }
113
- });
114
- console.log(res);
115
- ```
116
-
117
- ***
118
-
119
- ## **🔍 查询接口**
120
-
121
- 查询条件请根据实际需求自行拼装。详情参考 API 接口文档示例。
122
-
123
- ### **单条查询**
124
-
125
- ```JavaScript
126
- const res = await client.object.search.record({
127
- object_name: 'object_store',
128
- record_id: 'your_record_id',
129
- select: ['field1', 'field2']
130
- });
131
- console.log(res);
132
- ```
133
-
134
- ***
135
-
136
- ### **批量查询**
137
-
138
- 每次查询最多返回 100 条记录。
139
-
140
- ```JavaScript
141
- const res = await client.object.search.records({
142
- object_name: 'object_store',
143
- data: {
144
- need_total_count: true,
145
- page_size: 100,
146
- offset: 0
147
- }
148
- });
149
- console.log(res);
150
- ```
151
-
152
- ***
153
-
154
- ### **分页查询所有记录**
155
-
156
- 在上一个请求的基础上,封装每次查询最多返回 100 条记录。
157
-
158
- ```JavaScript
159
- const { total, items } = await client.object.search.recordsWithIterator({
160
- object_name: 'object_store',
161
- data: {
162
- need_total_count: true,
163
- page_size: 100,
164
- offset: 0
165
- }
166
- });
167
-
168
- console.log('Total:', total);
169
- console.log('Items:', items);
170
- ```
171
-
172
- ***
173
-
174
- <br>
175
-
176
-
177
- ***
178
-
179
- ## **➕ 创建接口**
180
-
181
- ### **单条创建**
182
-
183
- ```JavaScript
184
- const res = await client.object.create.record({
185
- object_name: 'object_event_log',
186
- record: {
187
- name: 'Sample text',
188
- content: 'Sample text'
189
- }
190
- });
191
- console.log(res);
192
- ```
193
-
194
- ### **批量创建**
195
-
196
- > ⚠️ 每次最多创建 100 条,SDK 已自动分组限流
197
-
198
- ```JavaScript
199
- const { total, items } = await client.object.create.recordsWithIterator({
200
- object_name: 'object_event_log',
201
- records: [
202
- { name: 'Sample text 1', content: 'Sample text 1' },
203
- { name: 'Sample text 2', content: 'Sample text 2' }
204
- ]
205
- });
206
- console.log('Total:', total);
207
- console.log('Items:', items);
208
- ```
209
-
210
-
211
- <br>
212
- ## **✏️ 更新接口**
213
-
214
- ### **单条更新**
215
-
216
- ```JavaScript
217
- const res = await client.object.update.record({
218
- object_name: 'object_store',
219
- record_id: 'your_record_id',
220
- record: { field1: 'newValue' }
221
- });
222
- console.log(res);
223
- ```
224
-
225
- ***
226
-
227
- ### **批量更新**
228
-
229
- > ⚠️ 每次最多更新 100 条,SDK 已自动分组限流
230
-
231
- ```JavaScript
232
- const res = await client.object.update.recordsBatchUpdate({
233
- object_name: 'object_store',
234
- records: [
235
- { _id: 'id1', field1: 'value1' },
236
- { _id: 'id2', field1: 'value2' }
237
- ]
238
- });
239
- console.log(res);
240
- ```
241
-
242
- ***
243
-
244
- <br>
245
-
246
- ## **🗑️ 删除接口**
247
-
248
- ### **单条删除**
249
-
250
- ```JavaScript
251
- const res = await client.object.delete.record({
252
- object_name: 'object_store',
253
- record_id: 'your_record_id'
254
- });
255
- console.log(res);
256
- ```
257
-
258
- ***
259
-
260
- ### **批量删除**
261
-
262
- > ⚠️ 每次最多删除 100 条,SDK 已自动分组限流
263
-
264
- ```JavaScript
265
- const res = await client.object.delete.recordsBatchDelete({
266
- object_name: 'object_store',
267
- ids: ['id1', 'id2', 'id3']
268
- });
269
- console.log(res);
270
- ```
271
-
272
- ***
273
-
274
- <br>
275
-
276
- ## **📊 对象元数据接口**
277
-
278
- ### **获取指定对象字段元数据**
279
-
280
- ```JavaScript
281
- const res = await client.object.metadata.field({
282
- object_name: '_user',
283
- field_name: '_id'
284
- });
285
- console.log(res);
286
- ```
287
-
288
- ### **获取指定对象所有字段信息**
289
-
290
- ```JavaScript
291
- const res = await client.object.metadata.fields({
292
- object_name: 'object_store'
293
- });
294
- console.log(res);
295
- ```
296
-
297
- ***
298
-
299
- <br>
300
-
301
- # **📎 附件模块**
302
-
303
- ## **文件操作**
304
-
305
- ### **上传文件**
306
-
307
- ```JavaScript
308
- const fs = require('fs');
309
-
310
- const res = await client.attachment.file.upload({
311
- file: fs.createReadStream('/path/to/file.zip')
312
- });
313
- console.log(res);
314
- // 返回: { code: "0", msg: "success", data: { fileId, type, name, size } }
315
- ```
316
-
317
- ### **下载文件**
318
-
319
- ```JavaScript
320
- const fileData = await client.attachment.file.download({
321
- file_id: '625d2f602af94d46972073db32a99ed2'
322
- });
323
- // 返回文件二进制流
324
- ```
325
-
326
- ### **删除文件**
327
-
328
- ```JavaScript
329
- const res = await client.attachment.file.delete({
330
- file_id: '625d2f602af94d46972073db32a99ed2'
331
- });
332
- console.log(res);
333
- ```
334
-
335
- ## **头像图片操作**
336
-
337
- ### **上传头像图片**
338
-
339
- ```JavaScript
340
- const fs = require('fs');
341
-
342
- const res = await client.attachment.avatar.upload({
343
- image: fs.createReadStream('/path/to/avatar.jpg')
344
- });
345
- console.log(res);
346
- ```
347
-
348
- ### **下载头像图片**
349
-
350
- ```JavaScript
351
- const imageData = await client.attachment.avatar.download({
352
- image_id: 'c70d03b21d3c40468ee710d984cfb7a8_o'
353
- });
354
- // 返回图片二进制流
355
- ```
356
-
357
- ***
358
-
359
- <br>
360
-
361
- # **💽 全局数据模块**
362
-
363
- ## **全局选项**
364
-
365
- ### **查询全局选项详情**
366
-
367
- ```JavaScript
368
- const res = await client.global.options.detail({
369
- api_name: 'global_option_abc'
370
- });
371
- console.log(res);
372
- ```
373
-
374
- ### **查询全局选项列表**
375
-
376
- ```JavaScript
377
- const res = await client.global.options.list({
378
- limit: 10,
379
- offset: 0,
380
- filter: { quickQuery: 'Sample Text' }
381
- });
382
- console.log(res);
383
- ```
384
-
385
- ### **分页查询所有全局选项**
386
-
387
- ```JavaScript
388
- const { total, items } = await client.global.options.listWithIterator({
389
- limit: 100,
390
- filter: { quickQuery: 'Sample Text' }
391
- });
392
- console.log('Total:', total);
393
- console.log('Items:', items);
394
- ```
395
-
396
- ## **环境变量**
397
-
398
- ### **查询环境变量详情**
399
-
400
- ```JavaScript
401
- const res = await client.global.variables.detail({
402
- api_name: 'global_variable_abc'
403
- });
404
- console.log(res);
405
- ```
406
-
407
- ### **查询环境变量列表**
408
-
409
- ```JavaScript
410
- const res = await client.global.variables.list({
411
- limit: 10,
412
- offset: 0,
413
- filter: { quickQuery: 'Sample Text' }
414
- });
415
- console.log(res);
416
- ```
417
-
418
- ### **分页查询所有环境变量**
419
-
420
- ```JavaScript
421
- const { total, items } = await client.global.variables.listWithIterator({
422
- limit: 100,
423
- filter: { quickQuery: 'Sample Text' }
424
- });
425
- console.log('Total:', total);
426
- console.log('Items:', items);
427
- ```
428
-
429
- ***
430
-
431
- <br>
432
-
433
- # **📄 页面模块**
434
-
435
- ### **获取所有页面**
436
-
437
- ```JavaScript
438
- const res = await client.page.list({
439
- limit: 10,
440
- offset: 0
441
- });
442
- console.log(res);
443
- ```
444
-
445
- ### **分页查询所有页面**
446
-
447
- ```JavaScript
448
- const { total, items } = await client.page.listWithIterator({
449
- limit: 100
450
- });
451
- console.log('Total:', total);
452
- console.log('Items:', items);
453
- ```
454
-
455
- ### **获取页面详情**
456
-
457
- ```JavaScript
458
- const res = await client.page.detail({
459
- page_id: 'appPage_aadd64dlqamdo'
460
- });
461
- console.log(res);
462
- ```
463
-
464
- ### **获取页面访问地址**
465
-
466
- ```JavaScript
467
- const res = await client.page.url({
468
- page_id: 'appPage_aadd64dlqamdo',
469
- pageParams: { var_EzpvJsER: '1234567890' },
470
- parentPageParams: {
471
- navId: 'aadd64bapmic2',
472
- pageApiName: 'page_aaddmtkqgicbg'
473
- },
474
- navId: 'aadd64bapmic2',
475
- tabId: 'tab_legqch3h'
476
- });
477
- console.log(res);
478
- // 返回: { code: "0", msg: "success", data: { link: "https://..." } }
479
- ```
480
-
481
- ***
482
-
483
- <br>
484
-
485
- # **🏢 部门模块**
486
-
487
- ## **部门 ID 交换**
488
-
489
- ### **单个部门 ID 交换**
490
-
491
- ```JavaScript
492
- const res = await client.department.exchange({
493
- department_id_type: 'external_department_id',
494
- department_id: 'Y806608904'
495
- });
496
- console.log(res);
497
- ```
498
-
499
- ### **批量部门 ID 交换**
500
-
501
- 每次最多 100 个,SDK 已自动拆分限流。
502
-
503
- ```JavaScript
504
- const res = await client.department.batchExchange({
505
- department_id_type: 'external_department_id',
506
- department_ids: ['id1', 'id2', 'id3']
507
- });
508
- console.log(res);
509
- ```
510
-
511
- ***
512
-
513
- <br>
514
-
515
- # **☁️ 云函数模块**
516
-
517
- ```JavaScript
518
- const res = await client.function.invoke({
519
- name: 'StoreMemberUpdate',
520
- params: { key: 'value' }
521
- });
522
- console.log(res);
523
- ```
524
-
525
- ***
526
-
527
- <br>
528
-
529
- ## **🛠️ 高级**
530
-
531
- ### **获取当前 token**
532
-
533
- ```JavaScript
534
- console.log(client.token);
535
- ```
536
-
537
- ### **获取 token 过期时间**
538
-
539
- ```JavaScript
540
- console.log(client.tokenExpireTime); // 返回剩余秒数
541
- ```
542
-
543
- ### **获取当前 namespace**
544
-
545
- ```JavaScript
546
- console.log(client.currentNamespace);
547
- ```
548
-
549
- ***
550
-
551
- <br>
552
-
553
- ## **💡 备注**
554
-
555
- - 本 SDK 默认使用 [axios](https://www.npmjs.com/package/axios) 请求。
556
-
557
- - 内置 [bottleneck](https://www.npmjs.com/package/bottleneck) 进行请求限流。
558
-
559
- - 日志打印默认使用 console.log 并带时间戳,可通过 setLoggerLevel 动态控制输出等级。
560
-
561
-
562
- ***
563
-
564
- <br>
565
-
566
- > 由 [aPaaS OAPI Client SDK](https://www.npmjs.com/package/apaas-oapi-client) 提供支持,如有问题请提交 Issue 反馈。
567
-
568
- ---