@byted-apaas/server-sdk-node 1.1.19 → 1.1.20-beta.1

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.
@@ -5,6 +5,8 @@ import { IDBGetter } from './db/db';
5
5
  import { Context as CommonContext } from '@byted-apaas/server-common-node';
6
6
  import { IMetaData } from './metadata/metadata';
7
7
  import { _IIntegration } from './integration/IIntegration';
8
+ import { TaskCenter } from "./task/taskCenter";
9
+ import { PushCenter } from "./push/pushCenter";
8
10
  export declare class Context<T, mt, cf, gv> extends CommonContext implements IContext<T, mt, cf, gv> {
9
11
  /**
10
12
  * 操作数据库中的记录数据
@@ -33,6 +35,11 @@ export declare class Context<T, mt, cf, gv> extends CommonContext implements ICo
33
35
  * 向消息中心推送及更新消息
34
36
  */
35
37
  msg: Message;
38
+ taskCenter: TaskCenter;
39
+ /**
40
+ * 推送中心
41
+ */
42
+ pushCenter: PushCenter;
36
43
  /**
37
44
  * 根据 apiName 获取对应的全局变量
38
45
  * @param apiName 全局变量的 API Name
@@ -0,0 +1,42 @@
1
+ export interface _ReceiverInfo {
2
+ receiver_id: string;
3
+ receiver_id_type?: string;
4
+ tags?: Map<string, string>;
5
+ variables?: _Variable[];
6
+ extra?: Map<string, string>;
7
+ }
8
+ export interface _Variable {
9
+ key: string;
10
+ value?: string;
11
+ }
12
+ /**
13
+ * 推送中心类
14
+ */
15
+ export declare class PushCenter {
16
+ /**
17
+ * 批量发布消息
18
+ * @param receiverInfos 接收者信息
19
+ * @param channelIDs 管道ID
20
+ * @param template 模版
21
+ * @param batchNo 批量编号
22
+ * @param senderID 发送者ID
23
+ * @param senderIDType 发送者ID类型
24
+ * @param subBatchNo 批量子编号
25
+ * @param tags 标签信息
26
+ * @param extra 扩展信息
27
+ */
28
+ sendMessageBatch(receiverInfos: _ReceiverInfo[], channelIDs: string[], template: string, batchNo: string, senderID: string, senderIDType: string, subBatchNo?: string, tags?: Map<string, string>, extra?: Map<string, string>): Promise<any>;
29
+ /**
30
+ * 批量获取消息状态
31
+ * @param batchNo 批量编号
32
+ * @param tags 标签列表
33
+ */
34
+ getMessageBatchStatus(batchNo: string, tags?: Map<string, string>): Promise<any>;
35
+ /**
36
+ * 获取消息状态
37
+ * @param batchNo 批量编号
38
+ * @param receiverIDs 接收者ID列表
39
+ * @param tags 标签列表
40
+ */
41
+ getMessageStatus(batchNo: string, receiverIDs?: string[], tags?: Map<string, string>): Promise<any>;
42
+ }
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ // Copyright 2022 ByteDance Ltd. and/or its affiliates
3
+ // SPDX-License-Identifier: MIT
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.PushCenter = void 0;
6
+ const Request = require("../../request/interface");
7
+ /**
8
+ * 推送中心类
9
+ */
10
+ class PushCenter {
11
+ /**
12
+ * 批量发布消息
13
+ * @param receiverInfos 接收者信息
14
+ * @param channelIDs 管道ID
15
+ * @param template 模版
16
+ * @param batchNo 批量编号
17
+ * @param senderID 发送者ID
18
+ * @param senderIDType 发送者ID类型
19
+ * @param subBatchNo 批量子编号
20
+ * @param tags 标签信息
21
+ * @param extra 扩展信息
22
+ */
23
+ async sendMessageBatch(receiverInfos, channelIDs, template, batchNo, senderID, senderIDType, subBatchNo, tags, extra) {
24
+ return await Request.GetInstance().sendMessageBatch(receiverInfos, channelIDs, template, batchNo, senderID, senderIDType, subBatchNo, tags, extra);
25
+ }
26
+ ;
27
+ /**
28
+ * 批量获取消息状态
29
+ * @param batchNo 批量编号
30
+ * @param tags 标签列表
31
+ */
32
+ async getMessageBatchStatus(batchNo, tags) {
33
+ return await Request.GetInstance().getMessageBatchStatus(batchNo, tags);
34
+ }
35
+ ;
36
+ /**
37
+ * 获取消息状态
38
+ * @param batchNo 批量编号
39
+ * @param receiverIDs 接收者ID列表
40
+ * @param tags 标签列表
41
+ */
42
+ async getMessageStatus(batchNo, receiverIDs, tags) {
43
+ return await Request.GetInstance().getMessageStatus(batchNo, receiverIDs, tags);
44
+ }
45
+ ;
46
+ }
47
+ exports.PushCenter = PushCenter;
@@ -0,0 +1,32 @@
1
+ export interface _Task {
2
+ task_id?: string;
3
+ apaas_record?: _APaaSRecord;
4
+ }
5
+ export interface _APaaSRecord {
6
+ object_id?: string;
7
+ object_api_name?: string;
8
+ record_id?: string;
9
+ record_data?: string;
10
+ }
11
+ /**
12
+ * 任务中心类
13
+ */
14
+ export declare class TaskCenter {
15
+ /**
16
+ * 推送任务
17
+ * @param tasks 任务
18
+ * @param cacheDuration 缓存时长
19
+ */
20
+ syncTasks(tasks?: _Task[], cacheDuration?: number): Promise<any>;
21
+ /**
22
+ * 查询任务详情(从缓存)
23
+ * @param task 任务
24
+ */
25
+ getTaskDetail(task?: _Task): Promise<any>;
26
+ /**
27
+ * 刷新任务详情缓存
28
+ * @param tasks 任务
29
+ * @param cacheDuration 缓存时长
30
+ */
31
+ refreshTasksCache(tasks?: _Task[], cacheDuration?: number): Promise<any>;
32
+ }
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ // Copyright 2022 ByteDance Ltd. and/or its affiliates
3
+ // SPDX-License-Identifier: MIT
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.TaskCenter = void 0;
6
+ const Request = require("../../request/interface");
7
+ /**
8
+ * 任务中心类
9
+ */
10
+ class TaskCenter {
11
+ /**
12
+ * 推送任务
13
+ * @param tasks 任务
14
+ * @param cacheDuration 缓存时长
15
+ */
16
+ async syncTasks(tasks, cacheDuration) {
17
+ return await Request.GetInstance().syncTasks(tasks, cacheDuration);
18
+ }
19
+ ;
20
+ /**
21
+ * 查询任务详情(从缓存)
22
+ * @param task 任务
23
+ */
24
+ async getTaskDetail(task) {
25
+ return await Request.GetInstance().getTaskDetail(task);
26
+ }
27
+ ;
28
+ /**
29
+ * 刷新任务详情缓存
30
+ * @param tasks 任务
31
+ * @param cacheDuration 缓存时长
32
+ */
33
+ async refreshTasksCache(tasks, cacheDuration) {
34
+ return await Request.GetInstance().refreshTasksCache(tasks, cacheDuration);
35
+ }
36
+ ;
37
+ }
38
+ exports.TaskCenter = TaskCenter;
@@ -6,6 +6,8 @@ import { Flow } from './application/flow/flow';
6
6
  import { _Resources } from '../context/resources/impl/resources';
7
7
  import { Message } from '../context/msg/msg';
8
8
  import { _IIntegration } from '../context/integration/IIntegration';
9
+ import { TaskCenter } from "../context/task/taskCenter";
10
+ import { PushCenter } from "../context/push/pushCenter";
9
11
  declare global {
10
12
  export namespace application {
11
13
  /**
@@ -30,6 +32,14 @@ declare global {
30
32
  /**
31
33
  * metadataV3 接口
32
34
  */
35
+ /**
36
+ * 消息中心
37
+ */
38
+ let taskCenter: TaskCenter;
39
+ /**
40
+ * 推送中心
41
+ */
42
+ let pushCenter: PushCenter;
33
43
  /**
34
44
  * 常量
35
45
  */
package/hooks/hooks.js CHANGED
@@ -11,6 +11,8 @@ const common_1 = require("../request/common");
11
11
  const integration_1 = require("../context/integration/impl/integration");
12
12
  const metadataApi = require("../context/metadata/metadata");
13
13
  const flow_1 = require("../global/application/flow/flow");
14
+ const taskCenter_1 = require("../context/task/taskCenter");
15
+ const pushCenter_1 = require("../context/push/pushCenter");
14
16
  /**
15
17
  * 根据 key 获取对应的全局变量
16
18
  * @param key 全局变量的 key
@@ -57,6 +59,8 @@ function mountContext(context, logger, requireFunc) {
57
59
  context.function = api.getFunctionSync(context, logger);
58
60
  context.tasks = new tasks_1.Tasks(context.function);
59
61
  context.msg = new msg_1.Message();
62
+ context.taskCenter = new taskCenter_1.TaskCenter();
63
+ context.pushCenter = new pushCenter_1.PushCenter();
60
64
  context.resources = new resources_1._Resources();
61
65
  context.integration = new integration_1._Integration();
62
66
  context.getVar = getVar;
@@ -83,6 +87,8 @@ function mountApplication(context) {
83
87
  global.application.publicAPI.method = server_common_node_1.utils.getHttpMethod();
84
88
  global.application.publicAPI.headers = server_common_node_1.utils.getHttpHeaders();
85
89
  global.application.msg = new msg_1.Message();
90
+ global.application.taskCenter = new taskCenter_1.TaskCenter();
91
+ global.application.pushCenter = new pushCenter_1.PushCenter();
86
92
  global.application.resources = new resources_1._Resources();
87
93
  global.application.metadata = metadataApi.metadata(context);
88
94
  // (global as any).application.metadataV3 = metadataApi.metadataV3(context);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@byted-apaas/server-sdk-node",
3
- "version": "1.1.19",
3
+ "version": "1.1.20-beta.1",
4
4
  "description": "aPaaS Server SDK",
5
5
  "author": "zhouwexin <zhouwexin@bytedance.com>",
6
6
  "homepage": "",
@@ -13,7 +13,7 @@
13
13
  "clean": "tsc --build --clean && rm -rf **/*.js.map"
14
14
  },
15
15
  "dependencies": {
16
- "@byted-apaas/server-common-node": "^2.0.13",
16
+ "@byted-apaas/server-common-node": "^2.0.19-beta.1",
17
17
  "@jorgeferrero/stream-to-buffer": "^2.0.6",
18
18
  "dayjs": "^1.9.6",
19
19
  "form-data": "^3.0.0",
@@ -66,6 +66,12 @@ export interface IInnerAPIBaseRequest {
66
66
  downloadFileByToken: (fileToken: string, filePath?: string) => Promise<Buffer | undefined>;
67
67
  createMessage: (msg: any) => Promise<number>;
68
68
  updateMessage: (msgId: number, msg: any) => Promise<void>;
69
+ syncTasks: (tasks: any, cacheDuration: number) => Promise<number>;
70
+ getTaskDetail: (task: any) => Promise<any>;
71
+ refreshTasksCache: (tasks: any, cacheDuration: number) => Promise<number>;
72
+ sendMessageBatch: (receiverInfos: any, channelIDs: string[], template: string, batchNo: string, senderID: string, senderIDType: string, subBatchNo?: string, tags?: Map<string, string>, extra?: Map<string, string>) => Promise<string>;
73
+ getMessageBatchStatus: (batchNo: string, tags?: Map<string, string>) => Promise<any>;
74
+ getMessageStatus: (batchNo: string, receiverIDs?: string[], tags?: Map<string, string>) => Promise<any>;
69
75
  getFields: (objectApiName: string) => Promise<any>;
70
76
  getField: (objectApiName: string, fieldApiName: string) => Promise<any>;
71
77
  terminateWorkflowInstance: (workflowInstanceId: number, operator: number, reason: string) => Promise<void>;
@@ -33,6 +33,12 @@ export declare class RequestHttp implements IInnerAPIRequest {
33
33
  downloadFileByToken(fileToken: string, filePath?: string): Promise<Buffer | undefined>;
34
34
  createMessage(msg: any): Promise<number>;
35
35
  updateMessage(msgId: number, msg: any): Promise<void>;
36
+ syncTasks(tasks: any, cacheDuration: number): Promise<any>;
37
+ getTaskDetail(task: any): Promise<any>;
38
+ sendMessageBatch(receiverInfos: any, channelIDs: string[], template: string, batchNo: string, senderID: string, senderIDType: string, subBatchNo?: string, tags?: Map<string, string>, extra?: Map<string, string>): Promise<string>;
39
+ getMessageBatchStatus(batchNo: string, tags?: Map<string, string>): Promise<any>;
40
+ getMessageStatus(batchNo: string, receiverIDs?: string[], tags?: Map<string, string>): Promise<any>;
41
+ refreshTasksCache(cacheDuration: number, tasks: any): Promise<any>;
36
42
  getFields(objectApiName: string): any;
37
43
  getField(objectApiName: string, fieldApiName: string): any;
38
44
  terminateWorkflowInstance(workflowInstanceId: number, operator: number, reason: string): any;
@@ -1039,6 +1039,12 @@ class RequestHttp {
1039
1039
  this.openSDKUploadFile = openSDKUploadFile;
1040
1040
  this.openSDKUploadAvatar = openSDKUploadAvatar;
1041
1041
  this.openSDKDownloadAvatar = openSDKDownloadAvatar;
1042
+ this.syncTasks = syncTasks;
1043
+ this.getTaskDetail = getTaskDetail;
1044
+ this.refreshTasksCache = refreshTasksCache;
1045
+ this.sendMessageBatch = sendMessageBatch;
1046
+ this.getMessageBatchStatus = getMessageBatchStatus;
1047
+ this.getMessageStatus = getMessageStatus;
1042
1048
  }
1043
1049
  updateWorkflowVariables(ctx, instanceId, variables, variableTypes) {
1044
1050
  }
@@ -1097,6 +1103,24 @@ class RequestHttp {
1097
1103
  updateMessage(msgId, msg) {
1098
1104
  return null;
1099
1105
  }
1106
+ syncTasks(tasks, cacheDuration) {
1107
+ return null;
1108
+ }
1109
+ getTaskDetail(task) {
1110
+ return null;
1111
+ }
1112
+ sendMessageBatch(receiverInfos, channelIDs, template, batchNo, senderID, senderIDType, subBatchNo, tags, extra) {
1113
+ return null;
1114
+ }
1115
+ getMessageBatchStatus(batchNo, tags) {
1116
+ return null;
1117
+ }
1118
+ getMessageStatus(batchNo, receiverIDs, tags) {
1119
+ return null;
1120
+ }
1121
+ refreshTasksCache(cacheDuration, tasks) {
1122
+ return null;
1123
+ }
1100
1124
  getFields(objectApiName) {
1101
1125
  }
1102
1126
  getField(objectApiName, fieldApiName) {
@@ -1522,3 +1546,64 @@ async function getDefaultIntegrationTenantAccessToken() {
1522
1546
  appId: res.appId,
1523
1547
  };
1524
1548
  }
1549
+ async function syncTasks(tasks, cacheDuration) {
1550
+ let options = commonHttp.getOptions(null, openapiHttpPath.taskCenterSyncTasks);
1551
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await (0, common_1.getNamespaceForOpenAndFaaSSDK)());
1552
+ options.json = {
1553
+ 'tasks': tasks,
1554
+ 'cache_duration': cacheDuration,
1555
+ };
1556
+ return await openapi.doRequest(null, urlPath, options);
1557
+ }
1558
+ async function getTaskDetail(task) {
1559
+ let options = commonHttp.getOptions(null, openapiHttpPath.taskCenterGetTaskDetail);
1560
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await (0, common_1.getNamespaceForOpenAndFaaSSDK)());
1561
+ options.json = {
1562
+ 'task': task,
1563
+ };
1564
+ return await openapi.doRequest(null, urlPath, options);
1565
+ }
1566
+ async function refreshTasksCache(tasks, cacheDuration) {
1567
+ let options = commonHttp.getOptions(null, openapiHttpPath.taskCenterRefreshTasksCache);
1568
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await (0, common_1.getNamespaceForOpenAndFaaSSDK)());
1569
+ options.json = {
1570
+ 'tasks': tasks,
1571
+ 'cache_duration': cacheDuration,
1572
+ };
1573
+ return await openapi.doRequest(null, urlPath, options);
1574
+ }
1575
+ async function sendMessageBatch(receiverInfos, channelIDs, template, batchNo, senderID, senderIDType, subBatchNo, tags, extra) {
1576
+ let options = commonHttp.getOptions(null, openapiHttpPath.pushCenterSendMessageBatch);
1577
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await (0, common_1.getNamespaceForOpenAndFaaSSDK)());
1578
+ options.json = {
1579
+ 'receiver_infos': receiverInfos,
1580
+ 'channel_ids': channelIDs,
1581
+ 'template': template,
1582
+ 'batch_no': batchNo,
1583
+ 'sender_id': senderID,
1584
+ 'sender_id_type': senderIDType,
1585
+ 'sub_batch_no': subBatchNo,
1586
+ 'tags': tags,
1587
+ 'extra': extra,
1588
+ };
1589
+ return await openapi.doRequest(null, urlPath, options);
1590
+ }
1591
+ async function getMessageBatchStatus(batchNo, tags) {
1592
+ let options = commonHttp.getOptions(null, openapiHttpPath.pushCenterGetMessageBatchStatus);
1593
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await (0, common_1.getNamespaceForOpenAndFaaSSDK)());
1594
+ options.json = {
1595
+ 'batch_no': batchNo,
1596
+ 'tags': tags,
1597
+ };
1598
+ return await openapi.doRequest(null, urlPath, options);
1599
+ }
1600
+ async function getMessageStatus(batchNo, receiverIDs, tags) {
1601
+ let options = commonHttp.getOptions(null, openapiHttpPath.pushCenterGetMessageStatus);
1602
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await (0, common_1.getNamespaceForOpenAndFaaSSDK)());
1603
+ options.json = {
1604
+ 'batch_no': batchNo,
1605
+ 'receiver_ids': receiverIDs,
1606
+ 'tags': tags,
1607
+ };
1608
+ return await openapi.doRequest(null, urlPath, options);
1609
+ }