@byted-apaas/server-sdk-node 1.0.10 → 1.0.12
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/context/resources/impl/resources.js +12 -1
- package/package.json +2 -2
- package/request/innerapi.d.ts +1 -0
- package/request/innerapi.js +38 -10
- package/request/interface.d.ts +1 -0
- package/request/openapi.d.ts +1 -0
- package/request/openapi.js +23 -11
|
@@ -105,7 +105,18 @@ class _KunlunFile {
|
|
|
105
105
|
if (typeof (fileTokenOrInfo.id) !== "string") {
|
|
106
106
|
throw new exceptions.InvalidParamError(`The type of fileInfo.id should be string, but ${typeof (fileTokenOrInfo)}`);
|
|
107
107
|
}
|
|
108
|
-
|
|
108
|
+
let tokenListStr = await Request.GetInstance().mGetFileToken([fileTokenOrInfo.id]);
|
|
109
|
+
let id2token;
|
|
110
|
+
try {
|
|
111
|
+
id2token = JSON.parse(tokenListStr);
|
|
112
|
+
}
|
|
113
|
+
catch (err) {
|
|
114
|
+
throw new exceptions.InternalError(`parse mGetFileToken resp failed: ${err.message}`);
|
|
115
|
+
}
|
|
116
|
+
if (!id2token[fileTokenOrInfo.id]) {
|
|
117
|
+
throw new exceptions.InternalError(`id (${fileTokenOrInfo.id})'s token is empty`);
|
|
118
|
+
}
|
|
119
|
+
return await Request.GetInstance().downloadFileByToken(id2token[fileTokenOrInfo.id], filePath);
|
|
109
120
|
}
|
|
110
121
|
else {
|
|
111
122
|
throw new exceptions.InvalidParamError(`The type of first param should be string or object, but ${typeof (fileTokenOrInfo)}`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@byted-apaas/server-sdk-node",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.12",
|
|
4
4
|
"description": "aPaaS Server SDK",
|
|
5
5
|
"author": "zhouwexin <zhouwexin@bytedance.com>",
|
|
6
6
|
"homepage": "",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"pre-build": "rm -rf build && tsc"
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@byted-apaas/server-common-node": "^1.0.
|
|
15
|
+
"@byted-apaas/server-common-node": "^1.0.12",
|
|
16
16
|
"@jorgeferrero/stream-to-buffer": "^2.0.6",
|
|
17
17
|
"dayjs": "^1.9.6",
|
|
18
18
|
"form-data": "^3.0.0",
|
package/request/innerapi.d.ts
CHANGED
|
@@ -51,6 +51,7 @@ export declare class RequestRpc implements IInnerAPIRequest {
|
|
|
51
51
|
revokeExecution(executionId: number, revokeOptions: RevokeExecutionOptions): Promise<void>;
|
|
52
52
|
getExecutionInfo(executionId: number): Promise<ExecutionInfo>;
|
|
53
53
|
getTenantInfo(appCtx: AppCtx): Promise<any>;
|
|
54
|
+
mGetFileToken(ids: string[]): Promise<string>;
|
|
54
55
|
openSDKCreateRecordBySync(objectApiName: string, record: object): any;
|
|
55
56
|
openSDKUpdateRecordBySync(objectApiName: string, recordID: number, record: object): any;
|
|
56
57
|
openSDKDeleteRecordBySync(objectApiName: string, recordID: number): any;
|
package/request/innerapi.js
CHANGED
|
@@ -52,7 +52,7 @@ async function createRecordBySync(objectApiName, record) {
|
|
|
52
52
|
param.Namespace = await (0, common_1.getNamespaceForOpenAndFaaSSDK)();
|
|
53
53
|
param.ObjectAPIAlias = objectApiName;
|
|
54
54
|
param.Data = utils.stringify(record);
|
|
55
|
-
param.Operator = BigInt(
|
|
55
|
+
param.Operator = BigInt(utils.getUserIDFromCtx());
|
|
56
56
|
if (task_id) {
|
|
57
57
|
param.TaskID = BigInt(task_id);
|
|
58
58
|
}
|
|
@@ -82,7 +82,7 @@ async function updateRecordBySync(objectApiName, recordID, record) {
|
|
|
82
82
|
param.ObjectAPIAlias = objectApiName;
|
|
83
83
|
param.RecordID = BigInt(recordID);
|
|
84
84
|
param.Data = utils.stringify(record);
|
|
85
|
-
param.Operator = BigInt(
|
|
85
|
+
param.Operator = BigInt(utils.getUserIDFromCtx());
|
|
86
86
|
if (task_id) {
|
|
87
87
|
param.TaskID = BigInt(task_id);
|
|
88
88
|
}
|
|
@@ -111,7 +111,7 @@ async function deleteRecordBySync(objectApiName, recordID) {
|
|
|
111
111
|
param.Namespace = await (0, common_1.getNamespaceForOpenAndFaaSSDK)();
|
|
112
112
|
param.ObjectAPIAlias = objectApiName;
|
|
113
113
|
param.RecordID = BigInt(recordID);
|
|
114
|
-
param.Operator = BigInt(
|
|
114
|
+
param.Operator = BigInt(utils.getUserIDFromCtx());
|
|
115
115
|
if (task_id) {
|
|
116
116
|
param.TaskID = BigInt(task_id);
|
|
117
117
|
}
|
|
@@ -140,7 +140,7 @@ async function createRecordsByAsync(objectApiName, records) {
|
|
|
140
140
|
param.Namespace = await (0, common_1.getNamespaceForOpenAndFaaSSDK)();
|
|
141
141
|
param.ObjectAPIAlias = objectApiName;
|
|
142
142
|
param.Data = utils.stringify(records);
|
|
143
|
-
param.OperatorID = BigInt(
|
|
143
|
+
param.OperatorID = BigInt(utils.getUserIDFromCtx());
|
|
144
144
|
if (task_id) {
|
|
145
145
|
param.AutomationTaskID = BigInt(task_id);
|
|
146
146
|
}
|
|
@@ -169,7 +169,7 @@ async function updateRecordsByAsync(objectApiName, recordMap) {
|
|
|
169
169
|
param.Namespace = await (0, common_1.getNamespaceForOpenAndFaaSSDK)();
|
|
170
170
|
param.ObjectAPIAlias = objectApiName;
|
|
171
171
|
param.Data = utils.stringify(recordMap);
|
|
172
|
-
param.OperatorID = BigInt(
|
|
172
|
+
param.OperatorID = BigInt(utils.getUserIDFromCtx());
|
|
173
173
|
if (task_id) {
|
|
174
174
|
param.AutomationTaskID = BigInt(task_id);
|
|
175
175
|
}
|
|
@@ -202,7 +202,7 @@ async function deleteRecordsByAsync(objectApiName, recordIDs) {
|
|
|
202
202
|
param.Namespace = await (0, common_1.getNamespaceForOpenAndFaaSSDK)();
|
|
203
203
|
param.ObjectAPIAlias = objectApiName;
|
|
204
204
|
param.RecordIDList = recordIDList;
|
|
205
|
-
param.OperatorID = BigInt(
|
|
205
|
+
param.OperatorID = BigInt(utils.getUserIDFromCtx());
|
|
206
206
|
if (task_id) {
|
|
207
207
|
param.AutomationTaskID = BigInt(task_id);
|
|
208
208
|
}
|
|
@@ -231,7 +231,8 @@ async function createRecordsBySync(objectApiName, records) {
|
|
|
231
231
|
param.Namespace = await (0, common_1.getNamespaceForOpenAndFaaSSDK)();
|
|
232
232
|
param.ObjectAPIAlias = objectApiName;
|
|
233
233
|
param.Data = utils.stringify(records);
|
|
234
|
-
param.OperatorID = BigInt(
|
|
234
|
+
param.OperatorID = BigInt(utils.getUserIDFromCtx());
|
|
235
|
+
param.SetSystemField = 2;
|
|
235
236
|
if (task_id) {
|
|
236
237
|
param.AutomationTaskID = BigInt(task_id);
|
|
237
238
|
}
|
|
@@ -271,7 +272,8 @@ async function updateRecordsBySync(objectApiName, recordMap) {
|
|
|
271
272
|
param.Namespace = await (0, common_1.getNamespaceForOpenAndFaaSSDK)();
|
|
272
273
|
param.ObjectAPIAlias = objectApiName;
|
|
273
274
|
param.Data = utils.stringify(recordMap);
|
|
274
|
-
param.OperatorID = BigInt(
|
|
275
|
+
param.OperatorID = BigInt(utils.getUserIDFromCtx());
|
|
276
|
+
param.SetSystemField = 2;
|
|
275
277
|
if (task_id) {
|
|
276
278
|
param.AutomationTaskID = BigInt(task_id);
|
|
277
279
|
}
|
|
@@ -308,7 +310,8 @@ async function deleteRecordsBySync(objectApiName, recordIDs) {
|
|
|
308
310
|
param.Namespace = await (0, common_1.getNamespaceForOpenAndFaaSSDK)();
|
|
309
311
|
param.ObjectAPIAlias = objectApiName;
|
|
310
312
|
param.RecordIDs = recordIDList;
|
|
311
|
-
param.OperatorID = BigInt(
|
|
313
|
+
param.OperatorID = BigInt(utils.getUserIDFromCtx());
|
|
314
|
+
param.SetSystemField = 2;
|
|
312
315
|
if (task_id) {
|
|
313
316
|
param.AutomationTaskID = BigInt(task_id);
|
|
314
317
|
}
|
|
@@ -481,6 +484,22 @@ async function downloadFileByToken(fileToken, filePath) {
|
|
|
481
484
|
return resp.Data;
|
|
482
485
|
}
|
|
483
486
|
}
|
|
487
|
+
async function mGetFileToken(ids) {
|
|
488
|
+
// 1. params
|
|
489
|
+
let param = {};
|
|
490
|
+
param.AttachmentIDs = ids;
|
|
491
|
+
// 2. prepare request
|
|
492
|
+
let ctx = await pre();
|
|
493
|
+
// 3. do request
|
|
494
|
+
let resp;
|
|
495
|
+
try {
|
|
496
|
+
resp = await rpc.getInnerAPICli().GetAttachmentTokens(ctx, param);
|
|
497
|
+
}
|
|
498
|
+
catch (err) {
|
|
499
|
+
throw new exceptions.InternalError(`Call InnerAPI failed: ${err.message}`);
|
|
500
|
+
}
|
|
501
|
+
return resp.Tokens;
|
|
502
|
+
}
|
|
484
503
|
async function createMessage(msg) {
|
|
485
504
|
// 1. prepare args
|
|
486
505
|
if (!msg.icon) {
|
|
@@ -707,7 +726,8 @@ async function modifyRecordsWithTransaction(placeholders, operations) {
|
|
|
707
726
|
param.Placeholders = ph;
|
|
708
727
|
// TODO: change operations type
|
|
709
728
|
param.Operations = operations;
|
|
710
|
-
param.OperatorID = BigInt(
|
|
729
|
+
param.OperatorID = BigInt(utils.getUserIDFromCtx());
|
|
730
|
+
param.SetSystemField = 1;
|
|
711
731
|
const taskID = utils.getTriggerTaskID();
|
|
712
732
|
if (taskID) {
|
|
713
733
|
param.TaskID = BigInt(taskID);
|
|
@@ -1055,6 +1075,7 @@ class RequestRpc {
|
|
|
1055
1075
|
this.uploadFile = uploadFile;
|
|
1056
1076
|
this.downloadFileByID = downloadFileByID;
|
|
1057
1077
|
this.downloadFileByToken = downloadFileByToken;
|
|
1078
|
+
this.mGetFileToken = mGetFileToken;
|
|
1058
1079
|
this.createMessage = createMessage;
|
|
1059
1080
|
this.updateMessage = updateMessage;
|
|
1060
1081
|
this.getFields = getFields;
|
|
@@ -1154,6 +1175,9 @@ class RequestRpc {
|
|
|
1154
1175
|
async getTenantInfo(appCtx) {
|
|
1155
1176
|
return await appCtx.credential.getTenantInfo();
|
|
1156
1177
|
}
|
|
1178
|
+
async mGetFileToken(ids) {
|
|
1179
|
+
return null;
|
|
1180
|
+
}
|
|
1157
1181
|
// open sdk empty implement
|
|
1158
1182
|
openSDKCreateRecordBySync(objectApiName, record) {
|
|
1159
1183
|
}
|
|
@@ -1333,6 +1357,10 @@ async function getExecutionUserTaskInfo(executionId) {
|
|
|
1333
1357
|
exports.getExecutionUserTaskInfo = getExecutionUserTaskInfo;
|
|
1334
1358
|
async function invokeFuncSync(idOrName, params) {
|
|
1335
1359
|
let ctx = await pre(true);
|
|
1360
|
+
// 兼容 params 不传的情况
|
|
1361
|
+
if (params === undefined) {
|
|
1362
|
+
params = {};
|
|
1363
|
+
}
|
|
1336
1364
|
let param = {};
|
|
1337
1365
|
param.Namespace = await (0, common_1.getNamespaceForOpenAndFaaSSDK)();
|
|
1338
1366
|
if (idOrName.isInvokeByAPIName) {
|
package/request/interface.d.ts
CHANGED
|
@@ -70,6 +70,7 @@ export interface IInnerAPIBaseRequest {
|
|
|
70
70
|
revokeExecution(executionId: number, revokeOptions: RevokeExecutionOptions): Promise<void>;
|
|
71
71
|
getExecutionInfo(executionId: number): Promise<ExecutionInfo>;
|
|
72
72
|
getTenantInfo(appCtx: AppCtx): Promise<any>;
|
|
73
|
+
mGetFileToken(ids: string[]): Promise<string>;
|
|
73
74
|
}
|
|
74
75
|
export interface IInnerAPIOpenSDKRequest {
|
|
75
76
|
openSDKCreateRecordBySync(objectApiName: string, record: object): any;
|
package/request/openapi.d.ts
CHANGED
|
@@ -52,6 +52,7 @@ export declare class RequestHttp implements IInnerAPIRequest {
|
|
|
52
52
|
revokeExecution(executionId: number, revokeOptions: RevokeExecutionOptions): Promise<void>;
|
|
53
53
|
getExecutionInfo(executionId: number): Promise<ExecutionInfo>;
|
|
54
54
|
getTenantInfo(appCtx: AppCtx): Promise<any>;
|
|
55
|
+
mGetFileToken(ids: string[]): Promise<string>;
|
|
55
56
|
openSDKCreateRecordBySync(objectApiName: string, record: object): any;
|
|
56
57
|
openSDKUpdateRecordBySync(objectApiName: string, recordID: number, record: object): any;
|
|
57
58
|
openSDKDeleteRecordBySync(objectApiName: string, recordID: number): any;
|
package/request/openapi.js
CHANGED
|
@@ -44,7 +44,7 @@ async function createRecordBySync(objectApiName, record) {
|
|
|
44
44
|
urlPath = urlPath.replace(replaceKeys.objectApiName, objectApiName);
|
|
45
45
|
// 3.请求
|
|
46
46
|
options.json = {
|
|
47
|
-
"operator":
|
|
47
|
+
"operator": utils.getUserIDFromCtx(),
|
|
48
48
|
"data": record,
|
|
49
49
|
};
|
|
50
50
|
let task_id = utils.getTriggerTaskID();
|
|
@@ -71,7 +71,7 @@ async function updateRecordBySync(objectApiName, recordID, record) {
|
|
|
71
71
|
urlPath = urlPath.replace(replaceKeys.objectApiName, objectApiName);
|
|
72
72
|
// 3.请求
|
|
73
73
|
options.json = {
|
|
74
|
-
"operator":
|
|
74
|
+
"operator": utils.getUserIDFromCtx(),
|
|
75
75
|
"record_id": recordID,
|
|
76
76
|
"data": record,
|
|
77
77
|
};
|
|
@@ -92,7 +92,7 @@ async function deleteRecordBySync(objectApiName, recordID) {
|
|
|
92
92
|
urlPath = urlPath.replace(replaceKeys.objectApiName, objectApiName);
|
|
93
93
|
// 3.请求
|
|
94
94
|
options.json = {
|
|
95
|
-
"operator":
|
|
95
|
+
"operator": utils.getUserIDFromCtx(),
|
|
96
96
|
"record_id": recordID,
|
|
97
97
|
};
|
|
98
98
|
let task_id = utils.getTriggerTaskID();
|
|
@@ -108,7 +108,7 @@ async function createRecordsByAsync(objectApiName, records) {
|
|
|
108
108
|
urlPath = urlPath.replace(replaceKeys.objectApiName, objectApiName);
|
|
109
109
|
// 2.请求
|
|
110
110
|
options.json = {
|
|
111
|
-
"operator":
|
|
111
|
+
"operator": utils.getUserIDFromCtx(),
|
|
112
112
|
"data": records,
|
|
113
113
|
};
|
|
114
114
|
let task_id = utils.getTriggerTaskID();
|
|
@@ -124,7 +124,7 @@ async function updateRecordsByAsync(objectApiName, recordMap) {
|
|
|
124
124
|
urlPath = urlPath.replace(replaceKeys.objectApiName, objectApiName);
|
|
125
125
|
// 2.请求
|
|
126
126
|
options.json = {
|
|
127
|
-
"operator":
|
|
127
|
+
"operator": utils.getUserIDFromCtx(),
|
|
128
128
|
"data": recordMap,
|
|
129
129
|
};
|
|
130
130
|
let task_id = utils.getTriggerTaskID();
|
|
@@ -140,7 +140,7 @@ async function deleteRecordsByAsync(objectApiName, recordIDs) {
|
|
|
140
140
|
urlPath = urlPath.replace(replaceKeys.objectApiName, objectApiName);
|
|
141
141
|
// 2.请求
|
|
142
142
|
options.json = {
|
|
143
|
-
"operator":
|
|
143
|
+
"operator": utils.getUserIDFromCtx(),
|
|
144
144
|
"record_id_list": recordIDs,
|
|
145
145
|
};
|
|
146
146
|
let task_id = utils.getTriggerTaskID();
|
|
@@ -156,7 +156,8 @@ async function createRecordsBySync(objectApiName, records) {
|
|
|
156
156
|
urlPath = urlPath.replace(replaceKeys.objectApiName, objectApiName);
|
|
157
157
|
// 2.请求
|
|
158
158
|
options.json = {
|
|
159
|
-
"operator":
|
|
159
|
+
"operator": utils.getUserIDFromCtx(),
|
|
160
|
+
"set_system_mod": 2,
|
|
160
161
|
"data": records,
|
|
161
162
|
};
|
|
162
163
|
let task_id = utils.getTriggerTaskID();
|
|
@@ -172,7 +173,8 @@ async function updateRecordsBySync(objectApiName, recordMap) {
|
|
|
172
173
|
urlPath = urlPath.replace(replaceKeys.objectApiName, objectApiName);
|
|
173
174
|
// 2.请求
|
|
174
175
|
options.json = {
|
|
175
|
-
"operator":
|
|
176
|
+
"operator": utils.getUserIDFromCtx(),
|
|
177
|
+
"set_system_mod": 2,
|
|
176
178
|
"data": recordMap,
|
|
177
179
|
};
|
|
178
180
|
let task_id = utils.getTriggerTaskID();
|
|
@@ -188,7 +190,8 @@ async function deleteRecordsBySync(objectApiName, recordIDs) {
|
|
|
188
190
|
urlPath = urlPath.replace(replaceKeys.objectApiName, objectApiName);
|
|
189
191
|
// 2.请求
|
|
190
192
|
options.json = {
|
|
191
|
-
"operator":
|
|
193
|
+
"operator": utils.getUserIDFromCtx(),
|
|
194
|
+
"set_system_mod": 2,
|
|
192
195
|
"record_id_list": recordIDs,
|
|
193
196
|
};
|
|
194
197
|
let task_id = utils.getTriggerTaskID();
|
|
@@ -305,7 +308,11 @@ async function mGetFileToken(ids) {
|
|
|
305
308
|
options.json = {
|
|
306
309
|
attachmentIds: ids
|
|
307
310
|
};
|
|
308
|
-
|
|
311
|
+
let res = await openapi.doRequest(null, urlPath, options);
|
|
312
|
+
if (!res || !res.tokens) {
|
|
313
|
+
throw new exceptions.InternalError(`mGetFileToken result is empty`);
|
|
314
|
+
}
|
|
315
|
+
return res.tokens;
|
|
309
316
|
}
|
|
310
317
|
async function createMessage(msg) {
|
|
311
318
|
// 1.解析参数 icon/receiverIds/percent
|
|
@@ -485,7 +492,8 @@ async function modifyRecordsWithTransaction(placeholders, operations) {
|
|
|
485
492
|
options.json = {
|
|
486
493
|
"placeholders": placeholders,
|
|
487
494
|
"operations": operations,
|
|
488
|
-
"operatorId":
|
|
495
|
+
"operatorId": utils.getUserIDFromCtx(),
|
|
496
|
+
"setSystemField": 1,
|
|
489
497
|
};
|
|
490
498
|
let taskId = utils.getTriggerTaskID();
|
|
491
499
|
if (taskId) {
|
|
@@ -684,6 +692,7 @@ class RequestHttp {
|
|
|
684
692
|
this.uploadFile = uploadFile;
|
|
685
693
|
this.downloadFileByID = downloadFileByID;
|
|
686
694
|
this.downloadFileByToken = downloadFileByToken;
|
|
695
|
+
this.mGetFileToken = mGetFileToken;
|
|
687
696
|
this.createMessage = createMessage;
|
|
688
697
|
this.updateMessage = updateMessage;
|
|
689
698
|
this.getFields = getFields;
|
|
@@ -782,6 +791,9 @@ class RequestHttp {
|
|
|
782
791
|
async getTenantInfo(appCtx) {
|
|
783
792
|
return await appCtx.credential.getTenantInfo();
|
|
784
793
|
}
|
|
794
|
+
mGetFileToken(ids) {
|
|
795
|
+
return null;
|
|
796
|
+
}
|
|
785
797
|
// open sdk empty implement
|
|
786
798
|
openSDKCreateRecordBySync(objectApiName, record) {
|
|
787
799
|
}
|