@byted-apaas/server-sdk-node 0.0.1-beta.3

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.
Files changed (163) hide show
  1. package/LICENSE +7 -0
  2. package/NOTICE +3 -0
  3. package/README.md +1 -0
  4. package/application/application.d.ts +27 -0
  5. package/application/application.js +2 -0
  6. package/application/application.ts +40 -0
  7. package/application/function/function.d.ts +14 -0
  8. package/application/function/function.js +21 -0
  9. package/application/function/function.ts +37 -0
  10. package/application/impl/common.d.ts +2 -0
  11. package/application/impl/common.js +50 -0
  12. package/application/impl/common.ts +50 -0
  13. package/application/impl/impl.d.ts +16 -0
  14. package/application/impl/impl.js +38 -0
  15. package/application/impl/impl.ts +48 -0
  16. package/constants/constants.d.ts +10 -0
  17. package/constants/constants.js +15 -0
  18. package/constants/constants.ts +15 -0
  19. package/context/context.d.ts +74 -0
  20. package/context/context.js +25 -0
  21. package/context/context.ts +130 -0
  22. package/context/db/db.d.ts +73 -0
  23. package/context/db/db.js +4 -0
  24. package/context/db/db.ts +80 -0
  25. package/context/db/impl/IObject.d.ts +251 -0
  26. package/context/db/impl/IObject.js +5 -0
  27. package/context/db/impl/IObject.ts +247 -0
  28. package/context/db/impl/db.d.ts +61 -0
  29. package/context/db/impl/db.js +86 -0
  30. package/context/db/impl/db.ts +95 -0
  31. package/context/db/impl/object.d.ts +92 -0
  32. package/context/db/impl/object.js +524 -0
  33. package/context/db/impl/object.ts +631 -0
  34. package/context/db/impl/oql/ioql.d.ts +6 -0
  35. package/context/db/impl/oql/ioql.js +4 -0
  36. package/context/db/impl/oql/ioql.ts +9 -0
  37. package/context/db/impl/oql/oql.d.ts +8 -0
  38. package/context/db/impl/oql/oql.js +21 -0
  39. package/context/db/impl/oql/oql.ts +25 -0
  40. package/context/db/impl/order.d.ts +9 -0
  41. package/context/db/impl/order.js +15 -0
  42. package/context/db/impl/order.ts +19 -0
  43. package/context/db/impl/propertiesStore.d.ts +8 -0
  44. package/context/db/impl/propertiesStore.js +29 -0
  45. package/context/db/impl/propertiesStore.ts +31 -0
  46. package/context/db/impl/queryBuilder.d.ts +29 -0
  47. package/context/db/impl/queryBuilder.js +78 -0
  48. package/context/db/impl/queryBuilder.ts +106 -0
  49. package/context/db/impl/transaction/index.d.ts +20 -0
  50. package/context/db/impl/transaction/index.js +277 -0
  51. package/context/db/impl/transaction/index.ts +340 -0
  52. package/context/db/impl/transaction/operation.d.ts +27 -0
  53. package/context/db/impl/transaction/operation.js +69 -0
  54. package/context/db/impl/transaction/operation.ts +72 -0
  55. package/context/db/impl/transaction.d.ts +67 -0
  56. package/context/db/impl/transaction.js +4 -0
  57. package/context/db/impl/transaction.ts +79 -0
  58. package/context/globalConfig/globalConfig.d.ts +7 -0
  59. package/context/globalConfig/globalConfig.js +16 -0
  60. package/context/globalConfig/globalConfig.ts +14 -0
  61. package/context/metadata/components/common.d.ts +6 -0
  62. package/context/metadata/components/common.js +17 -0
  63. package/context/metadata/components/common.ts +22 -0
  64. package/context/metadata/components/components.d.ts +12 -0
  65. package/context/metadata/components/components.js +19 -0
  66. package/context/metadata/components/components.ts +22 -0
  67. package/context/metadata/components/desktop/list.d.ts +16 -0
  68. package/context/metadata/components/desktop/list.js +402 -0
  69. package/context/metadata/components/desktop/list.ts +457 -0
  70. package/context/metadata/components/desktop/recordDetail.d.ts +11 -0
  71. package/context/metadata/components/desktop/recordDetail.js +53 -0
  72. package/context/metadata/components/desktop/recordDetail.ts +67 -0
  73. package/context/metadata/components/mobile/list.d.ts +24 -0
  74. package/context/metadata/components/mobile/list.js +145 -0
  75. package/context/metadata/components/mobile/list.ts +179 -0
  76. package/context/metadata/metadata.d.ts +61 -0
  77. package/context/metadata/metadata.js +103 -0
  78. package/context/metadata/metadata.ts +178 -0
  79. package/context/metadata/objects/fields.d.ts +130 -0
  80. package/context/metadata/objects/fields.js +334 -0
  81. package/context/metadata/objects/fields.ts +457 -0
  82. package/context/metadata/objects/fields.util.d.ts +40 -0
  83. package/context/metadata/objects/fields.util.js +319 -0
  84. package/context/metadata/objects/fields.util.ts +360 -0
  85. package/context/metadata/objects/objects.d.ts +11 -0
  86. package/context/metadata/objects/objects.js +20 -0
  87. package/context/metadata/objects/objects.ts +30 -0
  88. package/context/metadata/types/common.d.ts +6 -0
  89. package/context/metadata/types/common.js +9 -0
  90. package/context/metadata/types/common.ts +13 -0
  91. package/context/metadata/types/components.d.ts +90 -0
  92. package/context/metadata/types/components.js +4 -0
  93. package/context/metadata/types/components.ts +108 -0
  94. package/context/metadata/types/objects.d.ts +226 -0
  95. package/context/metadata/types/objects.js +4 -0
  96. package/context/metadata/types/objects.ts +254 -0
  97. package/context/msg/msg.d.ts +38 -0
  98. package/context/msg/msg.js +35 -0
  99. package/context/msg/msg.ts +52 -0
  100. package/context/resources/IResources.d.ts +66 -0
  101. package/context/resources/IResources.js +2 -0
  102. package/context/resources/IResources.ts +73 -0
  103. package/context/resources/impl/resources.d.ts +42 -0
  104. package/context/resources/impl/resources.js +150 -0
  105. package/context/resources/impl/resources.ts +173 -0
  106. package/context/tasks/tasks.d.ts +33 -0
  107. package/context/tasks/tasks.js +139 -0
  108. package/context/tasks/tasks.ts +159 -0
  109. package/data/index.d.ts +27 -0
  110. package/data/index.js +4 -0
  111. package/data/index.ts +30 -0
  112. package/hooks/api.d.ts +61 -0
  113. package/hooks/api.js +327 -0
  114. package/hooks/api.ts +341 -0
  115. package/hooks/hooks.d.ts +1 -0
  116. package/hooks/hooks.js +88 -0
  117. package/hooks/hooks.ts +100 -0
  118. package/kunlun/kunlun.d.ts +55 -0
  119. package/kunlun/kunlun.js +58 -0
  120. package/kunlun/kunlun.ts +72 -0
  121. package/kunlun/operator/IOperator.d.ts +158 -0
  122. package/kunlun/operator/IOperator.js +4 -0
  123. package/kunlun/operator/IOperator.ts +166 -0
  124. package/kunlun/operator/impl/expression.d.ts +47 -0
  125. package/kunlun/operator/impl/expression.js +56 -0
  126. package/kunlun/operator/impl/expression.ts +74 -0
  127. package/kunlun/operator/impl/logic.d.ts +50 -0
  128. package/kunlun/operator/impl/logic.js +509 -0
  129. package/kunlun/operator/impl/logic.ts +598 -0
  130. package/kunlun/operator/impl/logicV2.d.ts +58 -0
  131. package/kunlun/operator/impl/logicV2.js +200 -0
  132. package/kunlun/operator/impl/logicV2.ts +254 -0
  133. package/kunlun/operator/impl/operator.d.ts +179 -0
  134. package/kunlun/operator/impl/operator.js +222 -0
  135. package/kunlun/operator/impl/operator.ts +258 -0
  136. package/kunlun/operator/impl/operatorV2.d.ts +180 -0
  137. package/kunlun/operator/impl/operatorV2.js +216 -0
  138. package/kunlun/operator/impl/operatorV2.ts +249 -0
  139. package/lib/core.d.ts +4 -0
  140. package/lib/core.js +19 -0
  141. package/lib/core.ts +7 -0
  142. package/package.json +50 -0
  143. package/request/common.d.ts +13 -0
  144. package/request/common.js +87 -0
  145. package/request/common.ts +91 -0
  146. package/request/constants.d.ts +10 -0
  147. package/request/constants.js +25 -0
  148. package/request/constants.ts +25 -0
  149. package/request/faasinfra.d.ts +8 -0
  150. package/request/faasinfra.js +358 -0
  151. package/request/faasinfra.ts +393 -0
  152. package/request/innerapi.d.ts +67 -0
  153. package/request/innerapi.js +1412 -0
  154. package/request/innerapi.ts +1648 -0
  155. package/request/interface.d.ts +95 -0
  156. package/request/interface.js +41 -0
  157. package/request/interface.ts +169 -0
  158. package/request/openapi.d.ts +69 -0
  159. package/request/openapi.js +1014 -0
  160. package/request/openapi.ts +1223 -0
  161. package/types/types.d.ts +79 -0
  162. package/types/types.js +4 -0
  163. package/types/types.ts +108 -0
@@ -0,0 +1,1014 @@
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.getExecutionInfo = exports.revokeExecution = exports.executeFlow = exports.getExecutionUserTaskInfo = exports.RequestHttp = exports.updateWorkflowVariables = void 0;
6
+ const FormData = require("form-data");
7
+ const constants_1 = require("../constants/constants");
8
+ const common = require("@byted-apaas/server-common-node");
9
+ const constants_2 = require("./constants");
10
+ const constants_3 = require("@byted-apaas/server-common-node/constants/constants");
11
+ const common_1 = require("./common");
12
+ const nodeCls = require("node-cls");
13
+ const fs = require('fs');
14
+ const path = require('path');
15
+ const commonHttp = common.http;
16
+ const openapi = common.http.openapi;
17
+ const openapiHttpPath = common.http.openapiHttpPath;
18
+ const replaceKeys = common.http.replaceKeys;
19
+ const exceptions = common.exceptions;
20
+ const fieldType = common.fieldType;
21
+ const utils = common.utils;
22
+ const checkUtils = common.checkUtils;
23
+ async function updateWorkflowVariables(ctx, instanceId, variables, variableTypes) {
24
+ let options = commonHttp.getOptions(null, openapiHttpPath.workflowUpdateVariablesV2);
25
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await (0, common_1.getNamespaceForOpenAndFaaSSDK)());
26
+ // 2.请求
27
+ options.json = {
28
+ "operator": -1,
29
+ "workflowInstanceID": instanceId,
30
+ "variables": JSON.parse(variables),
31
+ "variableTypes": JSON.parse(variableTypes),
32
+ };
33
+ await openapi.doRequest(null, urlPath, options);
34
+ }
35
+ exports.updateWorkflowVariables = updateWorkflowVariables;
36
+ async function createRecordBySync(objectApiName, record) {
37
+ // 1.check
38
+ if (!objectApiName) {
39
+ throw new exceptions.InvalidParamError("objectApiName is empty");
40
+ }
41
+ // 2.获取 options
42
+ let options = commonHttp.getOptions(null, openapiHttpPath.createRecordBySyncV2);
43
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await (0, common_1.getNamespaceForOpenAndFaaSSDK)());
44
+ urlPath = urlPath.replace(replaceKeys.objectApiName, objectApiName);
45
+ // 3.请求
46
+ options.json = {
47
+ "operator": -1,
48
+ "data": record,
49
+ };
50
+ let task_id = utils.getTriggerTaskID();
51
+ if (task_id) {
52
+ options.json["task_id"] = task_id;
53
+ }
54
+ let data = await openapi.doRequest(null, urlPath, options);
55
+ if (data && data.record_id) {
56
+ return { _id: data.record_id };
57
+ }
58
+ if (data && data.recordID) {
59
+ return { _id: data.recordID };
60
+ }
61
+ return data;
62
+ }
63
+ async function updateRecordBySync(objectApiName, recordID, record) {
64
+ // 1.check
65
+ if (!objectApiName) {
66
+ throw new exceptions.InvalidParamError("objectApiName is empty");
67
+ }
68
+ // 2.获取 options
69
+ let options = commonHttp.getOptions(null, openapiHttpPath.updateRecordBySyncV2);
70
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await (0, common_1.getNamespaceForOpenAndFaaSSDK)());
71
+ urlPath = urlPath.replace(replaceKeys.objectApiName, objectApiName);
72
+ // 3.请求
73
+ options.json = {
74
+ "operator": -1,
75
+ "record_id": recordID,
76
+ "data": record,
77
+ };
78
+ let task_id = utils.getTriggerTaskID();
79
+ if (task_id) {
80
+ options.json["task_id"] = task_id;
81
+ }
82
+ return openapi.doRequest(null, urlPath, options);
83
+ }
84
+ async function deleteRecordBySync(objectApiName, recordID) {
85
+ // 1.check
86
+ if (!objectApiName) {
87
+ throw new exceptions.InvalidParamError("objectApiName is empty");
88
+ }
89
+ // 2.获取 options
90
+ let options = commonHttp.getOptions(null, openapiHttpPath.deleteRecordBySyncV2);
91
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await (0, common_1.getNamespaceForOpenAndFaaSSDK)());
92
+ urlPath = urlPath.replace(replaceKeys.objectApiName, objectApiName);
93
+ // 3.请求
94
+ options.json = {
95
+ "operator": -1,
96
+ "record_id": recordID,
97
+ };
98
+ let task_id = utils.getTriggerTaskID();
99
+ if (task_id) {
100
+ options.json["task_id"] = task_id;
101
+ }
102
+ return openapi.doRequest(null, urlPath, options);
103
+ }
104
+ async function createRecordsByAsync(objectApiName, records) {
105
+ // 1.获取 options
106
+ let options = commonHttp.getOptions(null, openapiHttpPath.createRecordsByAsyncV2);
107
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await (0, common_1.getNamespaceForOpenAndFaaSSDK)());
108
+ urlPath = urlPath.replace(replaceKeys.objectApiName, objectApiName);
109
+ // 2.请求
110
+ options.json = {
111
+ "operator": -1,
112
+ "data": records,
113
+ };
114
+ let task_id = utils.getTriggerTaskID();
115
+ if (task_id) {
116
+ options.json["automation_task_id"] = task_id;
117
+ }
118
+ return openapi.doRequest(null, urlPath, options);
119
+ }
120
+ async function updateRecordsByAsync(objectApiName, recordMap) {
121
+ // 1.获取 options
122
+ let options = commonHttp.getOptions(null, openapiHttpPath.updateRecordsByAsyncV2);
123
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await (0, common_1.getNamespaceForOpenAndFaaSSDK)());
124
+ urlPath = urlPath.replace(replaceKeys.objectApiName, objectApiName);
125
+ // 2.请求
126
+ options.json = {
127
+ "operator": -1,
128
+ "data": recordMap,
129
+ };
130
+ let task_id = utils.getTriggerTaskID();
131
+ if (task_id) {
132
+ options.json["automation_task_id"] = task_id;
133
+ }
134
+ return openapi.doRequest(null, urlPath, options);
135
+ }
136
+ async function deleteRecordsByAsync(objectApiName, recordIDs) {
137
+ // 1.获取 options
138
+ let options = commonHttp.getOptions(null, openapiHttpPath.deleteRecordsByAsyncV2);
139
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await (0, common_1.getNamespaceForOpenAndFaaSSDK)());
140
+ urlPath = urlPath.replace(replaceKeys.objectApiName, objectApiName);
141
+ // 2.请求
142
+ options.json = {
143
+ "operator": -1,
144
+ "record_id_list": recordIDs,
145
+ };
146
+ let task_id = utils.getTriggerTaskID();
147
+ if (task_id) {
148
+ options.json["automation_task_id"] = task_id;
149
+ }
150
+ return openapi.doRequest(null, urlPath, options);
151
+ }
152
+ async function createRecordsBySync(objectApiName, records) {
153
+ // 1.获取 options
154
+ let options = commonHttp.getOptions(null, openapiHttpPath.mCreateRecordsBySyncV2);
155
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await (0, common_1.getNamespaceForOpenAndFaaSSDK)());
156
+ urlPath = urlPath.replace(replaceKeys.objectApiName, objectApiName);
157
+ // 2.请求
158
+ options.json = {
159
+ "operator": -1,
160
+ "data": records,
161
+ };
162
+ let task_id = utils.getTriggerTaskID();
163
+ if (task_id) {
164
+ options.json["automation_task_id"] = task_id;
165
+ }
166
+ return openapi.doRequest(null, urlPath, options);
167
+ }
168
+ async function updateRecordsBySync(objectApiName, recordMap) {
169
+ // 1.获取 options
170
+ let options = commonHttp.getOptions(null, openapiHttpPath.mUpdateRecordsBySyncV2);
171
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await (0, common_1.getNamespaceForOpenAndFaaSSDK)());
172
+ urlPath = urlPath.replace(replaceKeys.objectApiName, objectApiName);
173
+ // 2.请求
174
+ options.json = {
175
+ "operator": -1,
176
+ "data": recordMap,
177
+ };
178
+ let task_id = utils.getTriggerTaskID();
179
+ if (task_id) {
180
+ options.json["automation_task_id"] = task_id;
181
+ }
182
+ return openapi.doRequest(null, urlPath, options);
183
+ }
184
+ async function deleteRecordsBySync(objectApiName, recordIDs) {
185
+ // 1.获取 options
186
+ let options = commonHttp.getOptions(null, openapiHttpPath.mDeleteRecordsBySyncV2);
187
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await (0, common_1.getNamespaceForOpenAndFaaSSDK)());
188
+ urlPath = urlPath.replace(replaceKeys.objectApiName, objectApiName);
189
+ // 2.请求
190
+ options.json = {
191
+ "operator": -1,
192
+ "record_id_list": recordIDs,
193
+ };
194
+ let task_id = utils.getTriggerTaskID();
195
+ if (task_id) {
196
+ options.json["automation_task_id"] = task_id;
197
+ }
198
+ return openapi.doRequest(null, urlPath, options);
199
+ }
200
+ function handleResponse(data, needCount) {
201
+ // 返回数据的特殊处理
202
+ if (needCount) {
203
+ if (checkUtils.isObject(data) && data["total"]) {
204
+ return data["total"];
205
+ }
206
+ return 0;
207
+ }
208
+ else {
209
+ if (checkUtils.isObject(data) && data["data_list"]) {
210
+ return data["data_list"];
211
+ }
212
+ return [];
213
+ }
214
+ }
215
+ async function getRecordsOrCountByCriterion(objectApiName, criterion, order, ignoreBackLookupField, fieldApiNames, offset, limit, needCount) {
216
+ if (limit > 1000) {
217
+ limit = 1000;
218
+ }
219
+ // 1.check
220
+ if (!objectApiName) {
221
+ throw new exceptions.InternalError("objectApiName is empty");
222
+ }
223
+ // 2.获取 options
224
+ let options = commonHttp.getOptions(null, needCount ? openapiHttpPath.mGetCountByCriterionV2 : openapiHttpPath.mGetRecordByCriterionV2);
225
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await (0, common_1.getNamespaceForOpenAndFaaSSDK)());
226
+ urlPath = urlPath.replace(replaceKeys.objectApiName, objectApiName);
227
+ // 3.请求
228
+ options.json = {
229
+ "criterion": JSON.parse(criterion),
230
+ "order": order,
231
+ "ignore_back_lookup_field": ignoreBackLookupField,
232
+ "field_api_names": fieldApiNames,
233
+ "offset": offset,
234
+ "limit": limit,
235
+ "need_filter_user_permission": false,
236
+ "need_total_count": needCount,
237
+ };
238
+ let data = await openapi.doRequest(null, urlPath, options);
239
+ return handleResponse(data, needCount);
240
+ }
241
+ /**
242
+ * 上传文件
243
+ *
244
+ * @param ctx
245
+ * @param datas:filePath;Stream
246
+ * @param expire(seconds)
247
+ * @returns {Promise<*|string>}
248
+ */
249
+ async function uploadFile(datas, expire = 0) {
250
+ let formData = new FormData();
251
+ formData.append('file', datas);
252
+ formData.append('expireSeconds', expire.toString());
253
+ formData.append('ignoreUserId', 'true');
254
+ let formHeaders = formData.getHeaders();
255
+ // 1.获取config
256
+ let options = commonHttp.getOptions(null, openapiHttpPath.uploadAttachment);
257
+ let urlPath = options._reqPath;
258
+ options.responseType = 'buffer';
259
+ for (let key of Object.keys(formHeaders)) {
260
+ options.headers[key] = formHeaders[key];
261
+ }
262
+ options.body = formData;
263
+ // 2.请求
264
+ return await openapi.doRequest(null, urlPath, options);
265
+ }
266
+ async function downloadFileByID(id, filePath) {
267
+ // 1.获取 options
268
+ let options = commonHttp.getOptions(null, openapiHttpPath.downloadFile);
269
+ let urlPath = options._reqPath.replace(replaceKeys.fileID, id);
270
+ options.responseType = "buffer";
271
+ // 2.请求
272
+ let data = await openapi.doRequest(null, urlPath, options);
273
+ // 3.写入文件
274
+ data = Buffer.from(data, 'binary');
275
+ if (filePath) {
276
+ checkUtils.checkFile(filePath);
277
+ utils.mkdirs(path.dirname(filePath));
278
+ fs.writeFileSync(filePath, data);
279
+ return;
280
+ }
281
+ return data;
282
+ }
283
+ async function downloadFileByToken(fileToken, filePath) {
284
+ // 1.获取 options
285
+ let options = commonHttp.getOptions(null, openapiHttpPath.downloadAttachment);
286
+ let urlPath = options._reqPath + `?token=${fileToken}`;
287
+ options.responseType = "buffer";
288
+ // 2.请求
289
+ let data = await openapi.doRequest(null, urlPath, options);
290
+ // 3.写入文件
291
+ data = Buffer.from(data, 'binary');
292
+ if (filePath) {
293
+ checkUtils.checkFile(filePath);
294
+ utils.mkdirs(path.dirname(filePath));
295
+ fs.writeFileSync(filePath, data);
296
+ return;
297
+ }
298
+ return data;
299
+ }
300
+ async function mGetFileToken(ids) {
301
+ // 1.获取 options
302
+ let options = commonHttp.getOptions(null, constants_2.openapiHttpPath.getBatchAttachmentToken);
303
+ let urlPath = options._reqPath;
304
+ // 2.请求
305
+ options.json = {
306
+ attachmentIds: ids
307
+ };
308
+ return await openapi.doRequest(null, urlPath, options);
309
+ }
310
+ async function createMessage(msg) {
311
+ // 1.解析参数 icon/receiverIds/percent
312
+ if (!msg.icon) {
313
+ throw new exceptions.InvalidParamError(`parameter icon is required!`);
314
+ }
315
+ if (typeof (msg.icon) != 'string') {
316
+ throw new exceptions.InvalidParamError(`Invalid format of parameter icon, icon should be string.`);
317
+ }
318
+ let params = {};
319
+ let modelKeySearchData = { "icon_type": msg.icon };
320
+ let receiverIds = msg["target_users"] || [];
321
+ if (!(receiverIds instanceof Array)) {
322
+ throw new exceptions.InvalidParamError(`Invalid format of parameter target_users, target_users should be array.`);
323
+ }
324
+ if (receiverIds.length === 0) {
325
+ throw new exceptions.InvalidParamError(`parameter target_users is required!`);
326
+ }
327
+ let percent = msg["percent"];
328
+ if (percent !== undefined && percent !== null) {
329
+ if (typeof (percent) != 'number') {
330
+ throw new exceptions.InvalidParamError(`Invalid format of parameter percent, percent should be number.`);
331
+ }
332
+ if (percent < 0 || percent > 100) {
333
+ throw new exceptions.InvalidParamError(`Invalid value of parameter percent, the value should be in range [0, 100].`);
334
+ }
335
+ else {
336
+ modelKeySearchData["percent"] = JSON.stringify(percent);
337
+ }
338
+ }
339
+ // kunlun类型
340
+ if (checkUtils.isObject(msg)) {
341
+ for (let key of Object.keys(msg)) {
342
+ if (fieldType.isKFieldType(msg[key])) {
343
+ // instanceof 改动6
344
+ // if (msg[key] instanceof fieldType.Multilingual) {
345
+ if (fieldType.isKFieldTypeMultilingual((msg[key]))) {
346
+ let value = JSON.stringify(msg[key].toJSON());
347
+ params[key] = JSON.stringify({ "value": value });
348
+ }
349
+ else {
350
+ params[key] = JSON.stringify(msg[key].toJSON());
351
+ }
352
+ }
353
+ else {
354
+ params[key] = JSON.stringify(msg[key]);
355
+ }
356
+ }
357
+ }
358
+ // 2.获取 options
359
+ let options = commonHttp.getOptions(null, openapiHttpPath.createMessage);
360
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await (0, common_1.getNamespaceForOpenAndFaaSSDK)());
361
+ // 3.请求
362
+ options.json = {
363
+ "NotifyModelKey": constants_1.notifyModel.key,
364
+ "ReceiverIDs": receiverIds,
365
+ "ParamsRawData": params,
366
+ "Percent": percent,
367
+ "ModelKeySearchData": modelKeySearchData
368
+ };
369
+ let res = await openapi.doRequest(null, urlPath, options);
370
+ return Number(res.taskID);
371
+ }
372
+ async function updateMessage(msgId, msg) {
373
+ // 1.解析参数 msgId/icon/percent
374
+ if (!msgId) {
375
+ throw new exceptions.InvalidParamError(`parameter msgId is required!`);
376
+ }
377
+ if (typeof (msgId) != 'number') {
378
+ throw new exceptions.InvalidParamError(`Invalid format of parameter msgId, msgId should be number.`);
379
+ }
380
+ if (!msg.icon) {
381
+ throw new exceptions.InvalidParamError(`parameter icon is required!`);
382
+ }
383
+ if (typeof (msg.icon) != 'string') {
384
+ throw new exceptions.InvalidParamError(`Invalid format of parameter icon, icon should be string.`);
385
+ }
386
+ let params = {};
387
+ let modelKeySearchData = { "icon_type": msg.icon };
388
+ let percent = msg["percent"];
389
+ if (percent !== undefined && percent !== null) {
390
+ if (typeof (percent) != 'number') {
391
+ throw new exceptions.InvalidParamError(`Invalid format of parameter percent, percent should be number.`);
392
+ }
393
+ if (percent < 0 || percent > 100) {
394
+ throw new exceptions.InvalidParamError(`Invalid value of parameter percent in message ${msgId}, the value should be in range [0, 100].`);
395
+ }
396
+ else {
397
+ modelKeySearchData["percent"] = JSON.stringify(percent);
398
+ }
399
+ }
400
+ // kunlun类型
401
+ if (checkUtils.isObject(msg)) {
402
+ for (let key of Object.keys(msg)) {
403
+ if (fieldType.isKFieldType(msg[key])) {
404
+ // instanceof 改动7
405
+ // if (msg[key] instanceof fieldType.Multilingual) {
406
+ if (fieldType.isKFieldTypeMultilingual(msg[key])) {
407
+ let value = JSON.stringify(msg[key].toJSON());
408
+ params[key] = JSON.stringify({ "value": value });
409
+ }
410
+ else {
411
+ params[key] = JSON.stringify(msg[key].toJSON());
412
+ }
413
+ }
414
+ else {
415
+ params[key] = JSON.stringify(msg[key]);
416
+ }
417
+ }
418
+ }
419
+ // 2.获取 options
420
+ let options = commonHttp.getOptions(null, openapiHttpPath.updateMessage);
421
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await (0, common_1.getNamespaceForOpenAndFaaSSDK)());
422
+ // 3.请求
423
+ options.json = {
424
+ "TaskID": msgId,
425
+ "Percent": percent,
426
+ "NotifyModelKey": constants_1.notifyModel.key,
427
+ "ParamsRawData": params,
428
+ "IsBackground": true,
429
+ "ModelKeySearchData": modelKeySearchData
430
+ };
431
+ return await openapi.doRequest(null, urlPath, options);
432
+ }
433
+ async function getFields(objectApiName) {
434
+ // 1.check
435
+ if (!objectApiName) {
436
+ throw new exceptions.InvalidParamError("objectApiName is empty");
437
+ }
438
+ // 2.获取config
439
+ let options = commonHttp.getOptions(null, openapiHttpPath.getFieldsV5);
440
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await (0, common_1.getNamespaceForOpenAndFaaSSDK)());
441
+ urlPath = urlPath.replace(replaceKeys.objectApiName, objectApiName);
442
+ let obj = await openapi.doRequest(null, urlPath, options);
443
+ if (!obj || !obj.fields) {
444
+ return [];
445
+ }
446
+ return obj.fields;
447
+ }
448
+ async function getField(objectApiName, fieldApiName) {
449
+ // 1.check
450
+ if (!objectApiName) {
451
+ throw new exceptions.InternalError("objectApiName is empty");
452
+ }
453
+ if (!fieldApiName) {
454
+ throw new exceptions.InternalError("fieldApiName is empty");
455
+ }
456
+ // 2.获取 options
457
+ let options = commonHttp.getOptions(null, openapiHttpPath.getFieldV5);
458
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await (0, common_1.getNamespaceForOpenAndFaaSSDK)());
459
+ urlPath = urlPath.replace(replaceKeys.objectApiName, objectApiName);
460
+ urlPath = urlPath.replace(replaceKeys.fieldApiName, fieldApiName);
461
+ // 3.请求
462
+ return await openapi.doRequest(null, urlPath, options);
463
+ }
464
+ async function terminateWorkflowInstance(workflowInstanceId, operator, reason) {
465
+ // 1.check
466
+ if (typeof (workflowInstanceId) !== "number") {
467
+ throw new exceptions.InvalidParamError(`The type of workflowInstanceId should be number, but ${typeof (workflowInstanceId)}.`);
468
+ }
469
+ // 2.获取 options
470
+ let options = commonHttp.getOptions(null, openapiHttpPath.terminateWorkflowInstance);
471
+ let urlPath = options._reqPath;
472
+ // 3.请求
473
+ options.json = {
474
+ "workflowInstanceID": workflowInstanceId,
475
+ "operator": operator,
476
+ "reason": reason,
477
+ };
478
+ await openapi.doRequest(null, urlPath, options);
479
+ }
480
+ async function modifyRecordsWithTransaction(placeholders, operations) {
481
+ // 1.获取 options
482
+ let options = commonHttp.getOptions(null, openapiHttpPath.modifyRecordsWithTransaction);
483
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await (0, common_1.getNamespaceForOpenAndFaaSSDK)());
484
+ // 2.请求
485
+ options.json = {
486
+ "placeholders": placeholders,
487
+ "operations": operations,
488
+ "operatorId": -1,
489
+ };
490
+ let taskId = utils.getTriggerTaskID();
491
+ if (taskId) {
492
+ options.json["taskId"] = taskId;
493
+ }
494
+ let result = await openapi.doRequest(null, urlPath, options);
495
+ let retPlaceholders = new Map();
496
+ if (result && result.placeholders) {
497
+ for (let key of Object.keys(result.placeholders)) {
498
+ retPlaceholders.set(key, result.placeholders[key]);
499
+ }
500
+ }
501
+ return retPlaceholders;
502
+ }
503
+ ;
504
+ async function getGlobalConfigByKey(key) {
505
+ // 1.获取 options
506
+ let options = commonHttp.getOptions(null, openapiHttpPath.getAllGlobalConfigs);
507
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await (0, common_1.getNamespaceForOpenAndFaaSSDK)());
508
+ // 2.请求
509
+ let pageSize = 100, offset = 0;
510
+ for (let i = 0;; i++) {
511
+ options.json = {
512
+ "biz_type": "GlobalVariables",
513
+ "used_by": "UsedBySystem",
514
+ "filter": {
515
+ "offset": offset * i,
516
+ "limit": pageSize
517
+ },
518
+ };
519
+ let data = await openapi.doRequest(null, urlPath, options);
520
+ for (let config of data.configs) {
521
+ if (config.key === key) {
522
+ return config.value;
523
+ }
524
+ }
525
+ if (data.configs.length < pageSize) {
526
+ break;
527
+ }
528
+ }
529
+ throw new exceptions.InvalidParamError(`undefined global variable (${key})`);
530
+ }
531
+ async function oql(oql, args, namedArgs) {
532
+ // 1.获取 options
533
+ let options = commonHttp.getOptions(null, constants_2.openapiHttpPath.oql);
534
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await (0, common_1.getNamespaceForOpenAndFaaSSDK)());
535
+ // 2.请求
536
+ options.json = {
537
+ "query": oql,
538
+ "args": args,
539
+ "namedArgs": namedArgs,
540
+ "compat": true,
541
+ };
542
+ let result = await openapi.doRequest(null, urlPath, options);
543
+ if (result && result.rows) {
544
+ return result.rows;
545
+ }
546
+ return [];
547
+ }
548
+ async function openSDKCreateRecordBySync(objectApiName, record) {
549
+ // 1.获取 options
550
+ let options = commonHttp.getOptions(null, openapiHttpPath.openSDKCreateRecord);
551
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await (0, common_1.getNamespaceForOpenAndFaaSSDK)());
552
+ urlPath = urlPath.replace(replaceKeys.objectApiName, objectApiName);
553
+ // 2.请求
554
+ options.json = record;
555
+ return await openapi.doRequest(null, urlPath, options);
556
+ }
557
+ ;
558
+ async function openSDKUpdateRecordBySync(objectApiName, recordID, record) {
559
+ // 1.获取 options
560
+ let options = commonHttp.getOptions(null, openapiHttpPath.openSDKUpdateRecord);
561
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await (0, common_1.getNamespaceForOpenAndFaaSSDK)());
562
+ urlPath = urlPath.replace(replaceKeys.objectApiName, objectApiName);
563
+ urlPath = urlPath.replace(replaceKeys.recordID, recordID.toString());
564
+ // 2.请求
565
+ options.json = record;
566
+ return await openapi.doRequest(null, urlPath, options);
567
+ }
568
+ ;
569
+ async function openSDKDeleteRecordBySync(objectApiName, recordID) {
570
+ // 1.获取 options
571
+ let options = commonHttp.getOptions(null, openapiHttpPath.openSDKDeleteRecord);
572
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await (0, common_1.getNamespaceForOpenAndFaaSSDK)());
573
+ urlPath = urlPath.replace(replaceKeys.objectApiName, objectApiName);
574
+ urlPath = urlPath.replace(replaceKeys.recordID, recordID.toString());
575
+ // 2.请求
576
+ return await openapi.doRequest(null, urlPath, options);
577
+ }
578
+ ;
579
+ async function openSDKCreateRecordsBySync(objectApiName, records) {
580
+ // 1.获取 options
581
+ let options = commonHttp.getOptions(null, openapiHttpPath.openSDKBatchCreateRecord);
582
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await (0, common_1.getNamespaceForOpenAndFaaSSDK)());
583
+ urlPath = urlPath.replace(replaceKeys.objectApiName, objectApiName);
584
+ // 2.请求
585
+ options.json = records;
586
+ return await openapi.doRequest(null, urlPath, options);
587
+ }
588
+ ;
589
+ async function openSDKUpdateRecordsBySync(objectApiName, records) {
590
+ // 1.获取 options
591
+ let options = commonHttp.getOptions(null, openapiHttpPath.openSDKBatchUpdateRecord);
592
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await (0, common_1.getNamespaceForOpenAndFaaSSDK)());
593
+ urlPath = urlPath.replace(replaceKeys.objectApiName, objectApiName);
594
+ // 2.请求
595
+ options.json = records;
596
+ return await openapi.doRequest(null, urlPath, options);
597
+ }
598
+ ;
599
+ async function openSDKDeleteRecordsBySync(objectApiName, recordIDs) {
600
+ // 1.获取 options
601
+ let options = commonHttp.getOptions(null, openapiHttpPath.openSDKBatchDeleteRecord);
602
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await (0, common_1.getNamespaceForOpenAndFaaSSDK)());
603
+ urlPath = urlPath.replace(replaceKeys.objectApiName, objectApiName);
604
+ // 2.请求
605
+ options.json = recordIDs;
606
+ return await openapi.doRequest(null, urlPath, options);
607
+ }
608
+ ;
609
+ async function openSDKGetRecords(objectApiName, param) {
610
+ // 1.获取 options
611
+ let options = commonHttp.getOptions(null, openapiHttpPath.openSDKGetRecords);
612
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await (0, common_1.getNamespaceForOpenAndFaaSSDK)());
613
+ urlPath = urlPath.replace(replaceKeys.objectApiName, objectApiName);
614
+ if (param.limit <= 0 || param.limit > 200) {
615
+ param.limit = 200;
616
+ }
617
+ // 2.请求
618
+ options.json = param;
619
+ const data = await openapi.doRequest(null, urlPath, options);
620
+ if (param.count) {
621
+ return JSON.parse(data.records);
622
+ }
623
+ else {
624
+ return data.total;
625
+ }
626
+ }
627
+ async function openSDKUploadFile(fileName, data) {
628
+ // 1.获取 options
629
+ let options = commonHttp.getOptions(null, openapiHttpPath.openSDKUploadFile);
630
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await (0, common_1.getNamespaceForOpenAndFaaSSDK)());
631
+ let formData = new FormData();
632
+ formData.append('file', data);
633
+ formData.append('ignoreUserId', 'true');
634
+ let formHeaders = formData.getHeaders();
635
+ options.responseType = 'buffer';
636
+ for (let key of Object.keys(formHeaders)) {
637
+ options.headers[key] = formHeaders[key];
638
+ }
639
+ options.body = formData;
640
+ // 2.请求
641
+ return await openapi.doRequest(null, urlPath, options);
642
+ }
643
+ async function openSDKUploadAvatar(fileName, data) {
644
+ // 1.获取 options
645
+ let options = commonHttp.getOptions(null, openapiHttpPath.openSDKUploadAvatar);
646
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await (0, common_1.getNamespaceForOpenAndFaaSSDK)());
647
+ let formData = new FormData();
648
+ formData.append('file', data);
649
+ formData.append('ignoreUserId', 'true');
650
+ let formHeaders = formData.getHeaders();
651
+ options.responseType = 'buffer';
652
+ for (let key of Object.keys(formHeaders)) {
653
+ options.headers[key] = formHeaders[key];
654
+ }
655
+ options.body = formData;
656
+ // 2.请求
657
+ return await openapi.doRequest(null, urlPath, options);
658
+ }
659
+ async function openSDKDownloadAvatar(imageID) {
660
+ // 1.获取 options
661
+ let options = commonHttp.getOptions(null, openapiHttpPath.openSDKDownloadAvatar);
662
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await (0, common_1.getNamespaceForOpenAndFaaSSDK)());
663
+ urlPath = urlPath.replace(replaceKeys.fileID, imageID);
664
+ // 2.请求
665
+ let data = await openapi.doRequest(null, urlPath, options);
666
+ // 3.写入文件
667
+ data = Buffer.from(data, 'binary');
668
+ return data;
669
+ }
670
+ class RequestHttp {
671
+ constructor() {
672
+ this.updateWorkflowVariables = updateWorkflowVariables;
673
+ this.createRecordBySync = createRecordBySync;
674
+ this.updateRecordBySync = updateRecordBySync;
675
+ this.deleteRecordBySync = deleteRecordBySync;
676
+ this.createRecordsByAsync = createRecordsByAsync;
677
+ this.updateRecordsByAsync = updateRecordsByAsync;
678
+ this.deleteRecordsByAsync = deleteRecordsByAsync;
679
+ this.createRecordsBySync = createRecordsBySync;
680
+ this.updateRecordsBySync = updateRecordsBySync;
681
+ this.deleteRecordsBySync = deleteRecordsBySync;
682
+ this.getRecordsOrCountByCriterion = getRecordsOrCountByCriterion;
683
+ this.uploadFile = uploadFile;
684
+ this.downloadFileByID = downloadFileByID;
685
+ this.downloadFileByToken = downloadFileByToken;
686
+ this.createMessage = createMessage;
687
+ this.updateMessage = updateMessage;
688
+ this.getFields = getFields;
689
+ this.getField = getField;
690
+ this.terminateWorkflowInstance = terminateWorkflowInstance;
691
+ this.modifyRecordsWithTransaction = modifyRecordsWithTransaction;
692
+ this.getGlobalConfigByKey = getGlobalConfigByKey;
693
+ this.oql = oql;
694
+ // TODO: open sdk api test
695
+ this.openSDKCreateRecordBySync = openSDKCreateRecordBySync;
696
+ this.openSDKUpdateRecordBySync = openSDKUpdateRecordBySync;
697
+ this.openSDKDeleteRecordBySync = openSDKDeleteRecordBySync;
698
+ this.openSDKCreateRecordsBySync = openSDKCreateRecordsBySync;
699
+ this.openSDKUpdateRecordsBySync = openSDKUpdateRecordsBySync;
700
+ this.openSDKDeleteRecordsBySync = openSDKDeleteRecordsBySync;
701
+ this.openSDKGetRecords = openSDKGetRecords;
702
+ this.openSDKUploadFile = openSDKUploadFile;
703
+ this.openSDKUploadAvatar = openSDKUploadAvatar;
704
+ this.openSDKDownloadAvatar = openSDKDownloadAvatar;
705
+ }
706
+ updateWorkflowVariables(ctx, instanceId, variables, variableTypes) {
707
+ }
708
+ createRecordBySync(objectApiName, record) {
709
+ }
710
+ updateRecordBySync(objectApiName, recordID, record) {
711
+ }
712
+ deleteRecordBySync(objectApiName, recordID) {
713
+ }
714
+ createRecordsByAsync(objectApiName, records) {
715
+ }
716
+ updateRecordsByAsync(objectApiName, recordMap) {
717
+ }
718
+ deleteRecordsByAsync(objectApiName, recordIDs) {
719
+ }
720
+ createRecordsBySync(objectApiName, records) {
721
+ }
722
+ updateRecordsBySync(objectApiName, recordMap) {
723
+ }
724
+ deleteRecordsBySync(objectApiName, recordIDs) {
725
+ }
726
+ getRecordsOrCountByCriterion(objectApiName, criterion, order, ignoreBackLookupField, fieldApiNames, offset, limit, needCount) {
727
+ }
728
+ uploadFile(data, expire) {
729
+ return null;
730
+ }
731
+ downloadFileByID(fileID, filePath) {
732
+ return null;
733
+ }
734
+ downloadFileByToken(fileToken, filePath) {
735
+ return null;
736
+ }
737
+ createMessage(msg) {
738
+ return null;
739
+ }
740
+ updateMessage(msgId, msg) {
741
+ return null;
742
+ }
743
+ getFields(objectApiName) {
744
+ }
745
+ getField(objectApiName, fieldApiName) {
746
+ }
747
+ terminateWorkflowInstance(workflowInstanceId, operator, reason) {
748
+ }
749
+ modifyRecordsWithTransaction(placeholders, operations) {
750
+ return null;
751
+ }
752
+ getGlobalConfigByKey(key) {
753
+ return null;
754
+ }
755
+ oql(oql, args, namedArgs) {
756
+ }
757
+ async invokeFuncSync(idOrName, params) {
758
+ return await invokeFuncSync(idOrName, params);
759
+ }
760
+ async invokeFuncWithAuth(idOrName, params) {
761
+ return await invokeFuncWithAuth(idOrName, params);
762
+ }
763
+ async createAsyncTaskV1(idOrName, params) {
764
+ return await createAsyncTaskV1(idOrName, params);
765
+ }
766
+ async createAsyncTaskV2(name, params) {
767
+ return await createAsyncTaskV2(name, params);
768
+ }
769
+ async getExecutionUserTaskInfo(executionId) {
770
+ return await getExecutionUserTaskInfo(executionId);
771
+ }
772
+ async executeFlow(APIName, options) {
773
+ return await executeFlow(APIName, options);
774
+ }
775
+ async revokeExecution(executionId, revokeOptions) {
776
+ return await revokeExecution(executionId, revokeOptions);
777
+ }
778
+ async getExecutionInfo(executionId) {
779
+ return await getExecutionInfo(executionId);
780
+ }
781
+ async getTenantInfo(appCtx) {
782
+ return await appCtx.credential.getTenantInfo();
783
+ }
784
+ // open sdk empty implement
785
+ openSDKCreateRecordBySync(objectApiName, record) {
786
+ }
787
+ ;
788
+ openSDKUpdateRecordBySync(objectApiName, recordID, record) {
789
+ }
790
+ ;
791
+ openSDKDeleteRecordBySync(objectApiName, recordID) {
792
+ }
793
+ ;
794
+ openSDKCreateRecordsBySync(objectApiName, records) {
795
+ }
796
+ ;
797
+ openSDKUpdateRecordsBySync(objectApiName, recordMap) {
798
+ }
799
+ ;
800
+ openSDKDeleteRecordsBySync(objectApiName, recordIDs) {
801
+ }
802
+ ;
803
+ openSDKGetRecords(objectApiName, param) {
804
+ return null;
805
+ }
806
+ ;
807
+ openSDKUploadFile(fileName, data) {
808
+ }
809
+ ;
810
+ openSDKUploadAvatar(fileName, data) {
811
+ }
812
+ ;
813
+ openSDKDownloadAvatar(imageID) {
814
+ return null;
815
+ }
816
+ ;
817
+ }
818
+ exports.RequestHttp = RequestHttp;
819
+ async function invokeFuncWithAuth(idOrName, params) {
820
+ let options = commonHttp.getOptions(null, openapiHttpPath.invokeFuncWithAuthInnerAPI);
821
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await (0, common_1.getNamespaceForOpenAndFaaSSDK)());
822
+ urlPath = urlPath.replace(replaceKeys.apiName, idOrName.APIName);
823
+ options.headers["User"] = utils.getUserIDFromCtx();
824
+ options.json = {
825
+ "params": params,
826
+ "context": getTriggerCtx(),
827
+ };
828
+ if (!idOrName.isInvokeByAPIName) {
829
+ options.json.apiID = idOrName.APIId;
830
+ }
831
+ let res = await openapi.doRequest(null, urlPath, options);
832
+ if (!res || !res.result) {
833
+ throw new exceptions.InternalError(`result is empty`);
834
+ }
835
+ let result;
836
+ try {
837
+ result = JSON.parse(res.result);
838
+ }
839
+ catch (e) {
840
+ throw new exceptions.InternalError(`JSON parse failed for ${res.result}`);
841
+ }
842
+ if (!result || result.code !== "0") {
843
+ throw new exceptions.InvalidParamError(`result is invalid for code: ${result ? result.code : ""} msg: ${result ? result.msg : ""}`);
844
+ }
845
+ return result.data;
846
+ }
847
+ async function invokeFuncSync(idOrName, params) {
848
+ let options = commonHttp.getOptions(null, openapiHttpPath.invokeFuncSyncInnerAPI);
849
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await (0, common_1.getNamespaceForOpenAndFaaSSDK)());
850
+ options.headers["User"] = utils.getUserIDFromCtx();
851
+ options.json = {
852
+ "params": JSON.stringify(params),
853
+ "context": JSON.stringify(getTriggerCtx()),
854
+ "triggerType": utils.getTriggerType(),
855
+ };
856
+ // 相等时,表示是新版本函数的场景
857
+ if (idOrName.isInvokeByAPIName) {
858
+ options.json.apiAlias = idOrName.APIName;
859
+ options.json.function_name = "";
860
+ }
861
+ else {
862
+ options.json.function_name = idOrName.APIId;
863
+ options.json.apiAlias = "";
864
+ }
865
+ let res = await openapi.doRequest(null, urlPath, options);
866
+ if (res && res.code === "0") {
867
+ return res.data;
868
+ }
869
+ throw new exceptions.InternalError(`invokeFuncSync result.code(${res.code}) is invalid`);
870
+ }
871
+ async function createAsyncTaskV1(idOrName, params) {
872
+ let options = commonHttp.getOptions(null, openapiHttpPath.createAsyncTaskInnerAPIV1);
873
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await (0, common_1.getNamespaceForOpenAndFaaSSDK)());
874
+ options.headers["User"] = utils.getUserIDFromCtx();
875
+ options.json = {
876
+ "params": JSON.stringify(params),
877
+ "context": JSON.stringify(getTriggerCtx()),
878
+ "triggerType": utils.getTriggerType(),
879
+ };
880
+ // 相等时,表示是新版本函数的场景
881
+ if (idOrName.isInvokeByAPIName) {
882
+ options.json.apiAlias = idOrName.APIName;
883
+ options.json.function_name = ""; // required
884
+ }
885
+ else {
886
+ options.json.function_name = idOrName.APIId;
887
+ }
888
+ let res = await openapi.doRequest(null, urlPath, options);
889
+ if (res && res.task_id) {
890
+ return res.task_id;
891
+ }
892
+ throw new exceptions.InternalError(`createAsyncTaskV1 result is empty`);
893
+ }
894
+ async function createAsyncTaskV2(APIName, params) {
895
+ let options = commonHttp.getOptions(null, openapiHttpPath.createAsyncTaskInnerAPIV2);
896
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await (0, common_1.getNamespaceForOpenAndFaaSSDK)());
897
+ let triggerCtx = {}, taskID = utils.getTriggerTaskID();
898
+ if (taskID) {
899
+ triggerCtx[constants_3.headers.triggerTaskId] = taskID;
900
+ }
901
+ let temp = utils.getDistributedHandleMask();
902
+ if (temp) {
903
+ triggerCtx[constants_3.headers.distributedHandleMask] = temp;
904
+ }
905
+ let reqCtx = nodeCls.get(constants_3.headers.loopCtxKey);
906
+ if (checkLoopCtx(reqCtx)) {
907
+ triggerCtx[constants_3.headers.loopMasks] = reqCtx.loopMasks;
908
+ }
909
+ options.headers["User"] = utils.getUserIDFromCtx();
910
+ options.json = {
911
+ "apiAlias": APIName,
912
+ "params": JSON.stringify(params),
913
+ "context": JSON.stringify(getTriggerCtx()),
914
+ "triggerType": utils.getTriggerType(),
915
+ "extra": (0, common_1.getDebugExtraInfo)()
916
+ };
917
+ let res = await openapi.doRequest(null, urlPath, options);
918
+ if (res && res.task_id) {
919
+ return res.task_id;
920
+ }
921
+ throw new exceptions.InternalError(`createAsyncTaskV2 result is empty`);
922
+ }
923
+ function checkLoopCtx(reqCtx) {
924
+ return reqCtx && reqCtx.loopMasks && Array.isArray(reqCtx.loopMasks);
925
+ }
926
+ function getTriggerCtx() {
927
+ let triggerCtx = {}, taskID = utils.getTriggerTaskID();
928
+ if (taskID) {
929
+ triggerCtx[constants_3.headers.triggerTaskId] = taskID;
930
+ }
931
+ let temp = utils.getDistributedHandleMask();
932
+ if (temp) {
933
+ triggerCtx[constants_3.headers.distributedHandleMask] = temp;
934
+ }
935
+ let reqCtx = nodeCls.get(constants_3.headers.loopCtxKey);
936
+ if (checkLoopCtx(reqCtx)) {
937
+ triggerCtx[constants_3.headers.loopMasks] = reqCtx.loopMasks;
938
+ }
939
+ return triggerCtx;
940
+ }
941
+ async function getExecutionUserTaskInfo(executionId) {
942
+ if (!executionId) {
943
+ throw new exceptions.InvalidParamError(`executionId is empty`);
944
+ }
945
+ let options = commonHttp.getOptions(null, constants_2.openapiHttpPath.getExecutionUserTaskInfo);
946
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await (0, common_1.getNamespaceForOpenAndFaaSSDK)()).replace(replaceKeys.id, `${executionId}`);
947
+ urlPath += `?operator=${utils.getUserIDFromCtx()}`;
948
+ let res = await openapi.doRequest(null, urlPath, options);
949
+ if (!res) {
950
+ throw new exceptions.InternalError(`getExecutionUserTaskInfo result is empty`);
951
+ }
952
+ return res.taskList;
953
+ }
954
+ exports.getExecutionUserTaskInfo = getExecutionUserTaskInfo;
955
+ async function executeFlow(APIName, option) {
956
+ if (!APIName) {
957
+ throw new exceptions.InvalidParamError(`flow apiName is empty`);
958
+ }
959
+ let options = commonHttp.getOptions(null, constants_2.openapiHttpPath.executeFlow);
960
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await (0, common_1.getNamespaceForOpenAndFaaSSDK)()).replace(replaceKeys.apiName, APIName);
961
+ options.json = {
962
+ "operator": utils.getUserIDFromCtx(),
963
+ "variables": (0, common_1.transMapToFlowVariable)(option.params),
964
+ "loopMasks": utils.getLoopMasks(),
965
+ };
966
+ let res = await openapi.doRequest(null, urlPath, options);
967
+ return {
968
+ executionId: res.executionId,
969
+ status: res.status,
970
+ data: (0, common_1.transFlowVariableToMap)(res.outParams),
971
+ errCode: res.errCode ? res.errCode : undefined,
972
+ errMsg: res.errMsg ? res.errMsg : undefined,
973
+ };
974
+ }
975
+ exports.executeFlow = executeFlow;
976
+ async function revokeExecution(executionId, revokeOptions) {
977
+ if (!executionId) {
978
+ throw new exceptions.InvalidParamError(`executionId is empty`);
979
+ }
980
+ let options = commonHttp.getOptions(null, constants_2.openapiHttpPath.revokeExecution);
981
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await (0, common_1.getNamespaceForOpenAndFaaSSDK)()).replace(replaceKeys.id, `${executionId}`);
982
+ let reason = undefined;
983
+ if (revokeOptions && revokeOptions.reason) {
984
+ reason = {
985
+ en_US: revokeOptions.reason.en_US,
986
+ zh_CN: revokeOptions.reason.zh_CN
987
+ };
988
+ }
989
+ options.json = {
990
+ "operator": utils.getUserIDFromCtx(),
991
+ "reason": reason,
992
+ };
993
+ return await openapi.doRequest(null, urlPath, options);
994
+ }
995
+ exports.revokeExecution = revokeExecution;
996
+ async function getExecutionInfo(executionId) {
997
+ if (!executionId) {
998
+ throw new exceptions.InvalidParamError(`executionId is empty`);
999
+ }
1000
+ let options = commonHttp.getOptions(null, constants_2.openapiHttpPath.getExecutionInfo);
1001
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await (0, common_1.getNamespaceForOpenAndFaaSSDK)()).replace(replaceKeys.id, `${executionId}`);
1002
+ urlPath += `?operator=${utils.getUserIDFromCtx()}`;
1003
+ let res = await openapi.doRequest(null, urlPath, options);
1004
+ if (!res || !res.executionInfo) {
1005
+ throw new exceptions.InternalError(`getExecutionInfo result is empty`);
1006
+ }
1007
+ return {
1008
+ status: res.executionInfo.status,
1009
+ data: (0, common_1.transFlowVariableToMap)(res.executionInfo.outParams),
1010
+ errCode: res.executionInfo.errCode ? res.executionInfo.errCode : undefined,
1011
+ errMsg: res.executionInfo.errMsg ? res.executionInfo.errMsg : undefined,
1012
+ };
1013
+ }
1014
+ exports.getExecutionInfo = getExecutionInfo;