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