@byted-apaas/server-sdk-node 1.1.23 → 1.1.24-beta.0

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 (131) hide show
  1. package/application/application.d.ts +33 -0
  2. package/application/application.js +2 -0
  3. package/application/function/function.d.ts +14 -0
  4. package/application/function/function.js +20 -0
  5. package/application/impl/common.d.ts +2 -0
  6. package/application/impl/common.js +52 -0
  7. package/application/impl/impl.d.ts +19 -0
  8. package/application/impl/impl.js +45 -0
  9. package/common/structs.d.ts +15 -0
  10. package/common/structs.js +21 -0
  11. package/constants/constants.d.ts +13 -0
  12. package/constants/constants.js +18 -0
  13. package/context/context.d.ts +44 -0
  14. package/context/context.js +25 -0
  15. package/context/db/db.d.ts +110 -0
  16. package/context/db/db.js +2 -0
  17. package/context/db/impl/IObject.d.ts +303 -0
  18. package/context/db/impl/IObject.js +5 -0
  19. package/context/db/impl/IObjectV3.d.ts +239 -0
  20. package/context/db/impl/IObjectV3.js +5 -0
  21. package/context/db/impl/db.d.ts +62 -0
  22. package/context/db/impl/db.js +84 -0
  23. package/context/db/impl/dbV3.d.ts +35 -0
  24. package/context/db/impl/dbV3.js +50 -0
  25. package/context/db/impl/object.d.ts +123 -0
  26. package/context/db/impl/object.js +1008 -0
  27. package/context/db/impl/oql/ioql.d.ts +14 -0
  28. package/context/db/impl/oql/ioql.js +4 -0
  29. package/context/db/impl/oql/oql.d.ts +14 -0
  30. package/context/db/impl/oql/oql.js +39 -0
  31. package/context/db/impl/order.d.ts +9 -0
  32. package/context/db/impl/order.js +15 -0
  33. package/context/db/impl/propertiesStore.d.ts +8 -0
  34. package/context/db/impl/propertiesStore.js +29 -0
  35. package/context/db/impl/queryBuilder.d.ts +33 -0
  36. package/context/db/impl/queryBuilder.js +72 -0
  37. package/context/db/impl/transaction/index.d.ts +25 -0
  38. package/context/db/impl/transaction/index.js +300 -0
  39. package/context/db/impl/transaction/operation.d.ts +27 -0
  40. package/context/db/impl/transaction/operation.js +69 -0
  41. package/context/db/impl/transaction.d.ts +70 -0
  42. package/context/db/impl/transaction.js +4 -0
  43. package/context/globalConfig/globalConfig.d.ts +7 -0
  44. package/context/globalConfig/globalConfig.js +16 -0
  45. package/context/integration/IIntegration.d.ts +30 -0
  46. package/context/integration/IIntegration.js +4 -0
  47. package/context/integration/impl/integration.d.ts +16 -0
  48. package/context/integration/impl/integration.js +62 -0
  49. package/context/metadata/components/common.d.ts +6 -0
  50. package/context/metadata/components/common.js +17 -0
  51. package/context/metadata/components/components.d.ts +12 -0
  52. package/context/metadata/components/components.js +19 -0
  53. package/context/metadata/components/desktop/list.d.ts +16 -0
  54. package/context/metadata/components/desktop/list.js +402 -0
  55. package/context/metadata/components/desktop/recordDetail.d.ts +11 -0
  56. package/context/metadata/components/desktop/recordDetail.js +53 -0
  57. package/context/metadata/components/mobile/list.d.ts +24 -0
  58. package/context/metadata/components/mobile/list.js +145 -0
  59. package/context/metadata/metadata.d.ts +63 -0
  60. package/context/metadata/metadata.js +125 -0
  61. package/context/metadata/objects/fields.d.ts +158 -0
  62. package/context/metadata/objects/fields.js +369 -0
  63. package/context/metadata/objects/fields.util.d.ts +52 -0
  64. package/context/metadata/objects/fields.util.js +420 -0
  65. package/context/metadata/objects/fieldsV3.d.ts +159 -0
  66. package/context/metadata/objects/fieldsV3.js +369 -0
  67. package/context/metadata/objects/objects.d.ts +11 -0
  68. package/context/metadata/objects/objects.js +20 -0
  69. package/context/metadata/types/common.d.ts +11 -0
  70. package/context/metadata/types/common.js +33 -0
  71. package/context/metadata/types/components.d.ts +90 -0
  72. package/context/metadata/types/components.js +4 -0
  73. package/context/metadata/types/objects.d.ts +246 -0
  74. package/context/metadata/types/objects.js +4 -0
  75. package/context/metadata/types/objectsV3.d.ts +128 -0
  76. package/context/metadata/types/objectsV3.js +4 -0
  77. package/context/msg/msg.d.ts +38 -0
  78. package/context/msg/msg.js +35 -0
  79. package/context/resources/IResources.d.ts +68 -0
  80. package/context/resources/IResources.js +2 -0
  81. package/context/resources/impl/resources.d.ts +42 -0
  82. package/context/resources/impl/resources.js +161 -0
  83. package/context/tasks/tasks.d.ts +33 -0
  84. package/context/tasks/tasks.js +139 -0
  85. package/data/index.d.ts +27 -0
  86. package/data/index.js +4 -0
  87. package/global/application/flow/flow.d.ts +99 -0
  88. package/global/application/flow/flow.js +8 -0
  89. package/global/application/flow/impl/flow.d.ts +20 -0
  90. package/global/application/flow/impl/flow.js +56 -0
  91. package/global/application/globalVar/globalVar.d.ts +7 -0
  92. package/global/application/globalVar/globalVar.js +2 -0
  93. package/global/global.d.ts +70 -0
  94. package/global/global.js +3 -0
  95. package/hooks/api.d.ts +65 -0
  96. package/hooks/api.js +347 -0
  97. package/hooks/hooks.d.ts +1 -0
  98. package/hooks/hooks.js +107 -0
  99. package/kunlun/kunlun.d.ts +55 -0
  100. package/kunlun/kunlun.js +58 -0
  101. package/kunlun/operator/IOperator.d.ts +158 -0
  102. package/kunlun/operator/IOperator.js +4 -0
  103. package/kunlun/operator/impl/expression.d.ts +75 -0
  104. package/kunlun/operator/impl/expression.js +96 -0
  105. package/kunlun/operator/impl/logic.d.ts +68 -0
  106. package/kunlun/operator/impl/logic.js +573 -0
  107. package/kunlun/operator/impl/logicV2.d.ts +59 -0
  108. package/kunlun/operator/impl/logicV2.js +197 -0
  109. package/kunlun/operator/impl/operator.d.ts +179 -0
  110. package/kunlun/operator/impl/operator.js +222 -0
  111. package/kunlun/operator/impl/operatorV2.d.ts +180 -0
  112. package/kunlun/operator/impl/operatorV2.js +216 -0
  113. package/lib/core.d.ts +4 -0
  114. package/lib/core.js +19 -0
  115. package/package.json +1 -1
  116. package/request/common.d.ts +13 -0
  117. package/request/common.js +88 -0
  118. package/request/constants.d.ts +12 -0
  119. package/request/constants.js +29 -0
  120. package/request/faasinfra.d.ts +8 -0
  121. package/request/faasinfra.js +146 -0
  122. package/request/interface.d.ts +121 -0
  123. package/request/interface.js +30 -0
  124. package/request/openapi.d.ts +84 -0
  125. package/request/openapi.js +1533 -0
  126. package/request/structs.d.ts +99 -0
  127. package/request/structs.js +15 -0
  128. package/types/types.d.ts +79 -0
  129. package/types/types.js +4 -0
  130. package/version/version.d.ts +2 -0
  131. package/version/version.js +8 -0
@@ -0,0 +1,1533 @@
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 utils_1 = require("@byted-apaas/server-common-node/utils/utils");
13
+ const permissionUtils = require("@byted-apaas/server-common-node/utils/permissionUtils");
14
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
15
+ const { URLSearchParams } = require('url'); //nolint:byted_s_ts_no_require_imports
16
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
17
+ const nodeCls = require('node-cls'); //nolint:byted_s_ts_no_require_imports
18
+ const fs = require('fs');
19
+ const path = require('path');
20
+ const commonHttp = common.http;
21
+ const openapi = common.http.openapi;
22
+ const openapiHttpPath = common.http.openapiHttpPath;
23
+ const replaceKeys = common.http.replaceKeys;
24
+ const exceptions = common.exceptions;
25
+ const fieldType = common.fieldType;
26
+ const utils = common.utils;
27
+ const checkUtils = common.checkUtils;
28
+ async function updateWorkflowVariables(ctx, instanceId, variables, variableTypes) {
29
+ let options = commonHttp.getOptions(null, openapiHttpPath.workflowUpdateVariablesV2);
30
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await (0, common_1.getNamespaceForOpenAndFaaSSDK)());
31
+ // 2.请求
32
+ options.json = {
33
+ 'operator': -1,
34
+ 'workflowInstanceID': instanceId,
35
+ 'variables': JSON.parse(variables),
36
+ 'variableTypes': JSON.parse(variableTypes),
37
+ };
38
+ await openapi.doRequest(null, urlPath, options);
39
+ }
40
+ exports.updateWorkflowVariables = updateWorkflowVariables;
41
+ async function createRecordBySync(objectApiName, record, authType) {
42
+ // 1.check
43
+ if (!objectApiName) {
44
+ throw new exceptions.InvalidParamError('objectApiName is empty');
45
+ }
46
+ // 2.获取 options
47
+ let options = commonHttp.getOptions(null, openapiHttpPath.createRecordBySyncV2);
48
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await (0, common_1.getNamespaceForOpenAndFaaSSDK)());
49
+ urlPath = urlPath.replace(replaceKeys.objectApiName, objectApiName);
50
+ // 3.请求
51
+ options.json = {
52
+ 'operator': utils.getUserIDFromCtx(),
53
+ 'data': record,
54
+ };
55
+ authType = (0, utils_1.formatAuthType)(authType);
56
+ options.headers.User = String(utils.getUserIDFromCtx());
57
+ if (authType) {
58
+ options.headers[constants_3.AuthTypeHttpHeader] = authType;
59
+ }
60
+ const task_id = utils.getTriggerTaskID();
61
+ if (task_id) {
62
+ options.json.task_id = task_id;
63
+ }
64
+ let data = await openapi.doRequest(null, urlPath, options);
65
+ if (data && data.record_id) {
66
+ return { _id: data.record_id };
67
+ }
68
+ if (data && data.recordID) {
69
+ return { _id: data.recordID };
70
+ }
71
+ return data;
72
+ }
73
+ async function createRecordBySyncV3(objectApiName, record, authType) {
74
+ // 1.check
75
+ if (!objectApiName) {
76
+ throw new exceptions.InvalidParamError('objectApiName is empty');
77
+ }
78
+ // 2.获取 options
79
+ let options = commonHttp.getOptions(null, openapiHttpPath.createRecordBySyncV3);
80
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await (0, common_1.getNamespaceForOpenAndFaaSSDK)());
81
+ urlPath = urlPath.replace(replaceKeys.objectApiName, objectApiName);
82
+ // 3.请求
83
+ options.json = {
84
+ 'data_version': 'v3',
85
+ record,
86
+ };
87
+ authType = (0, utils_1.formatAuthType)(authType);
88
+ options.headers.User = String(utils.getUserIDFromCtx());
89
+ if (authType) {
90
+ options.headers[constants_3.AuthTypeHttpHeader] = authType;
91
+ }
92
+ const task_id = utils.getTriggerTaskID();
93
+ if (task_id) {
94
+ options.json.task_id = task_id;
95
+ }
96
+ const data = await openapi.doRequest(null, urlPath, options);
97
+ if (data && data.record_id) {
98
+ return { _id: data.record_id };
99
+ }
100
+ if (data && data.recordID) {
101
+ return { _id: data.recordID };
102
+ }
103
+ return data;
104
+ }
105
+ async function updateRecordBySync(objectApiName, recordID, record, authType) {
106
+ // 1.check
107
+ if (!objectApiName) {
108
+ throw new exceptions.InvalidParamError('objectApiName is empty');
109
+ }
110
+ // 2.获取 options
111
+ let options = commonHttp.getOptions(null, openapiHttpPath.updateRecordBySyncV2);
112
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await (0, common_1.getNamespaceForOpenAndFaaSSDK)());
113
+ urlPath = urlPath.replace(replaceKeys.objectApiName, objectApiName);
114
+ // 3.请求
115
+ options.json = {
116
+ 'operator': utils.getUserIDFromCtx(),
117
+ 'record_id': recordID,
118
+ 'data': record,
119
+ };
120
+ authType = (0, utils_1.formatAuthType)(authType);
121
+ options.headers.User = String(utils.getUserIDFromCtx());
122
+ if (authType) {
123
+ options.headers[constants_3.AuthTypeHttpHeader] = authType;
124
+ }
125
+ const task_id = utils.getTriggerTaskID();
126
+ if (task_id) {
127
+ options.json.task_id = task_id;
128
+ }
129
+ return openapi.doRequest(null, urlPath, options);
130
+ }
131
+ async function updateRecordBySyncV3(objectApiName, recordID, record, authType) {
132
+ // 1.check
133
+ if (!objectApiName) {
134
+ throw new exceptions.InvalidParamError('objectApiName is empty');
135
+ }
136
+ // 2.获取 options
137
+ let options = commonHttp.getOptions(null, openapiHttpPath.updateRecordBySyncV3);
138
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await (0, common_1.getNamespaceForOpenAndFaaSSDK)());
139
+ urlPath = urlPath.replace(replaceKeys.objectApiName, objectApiName);
140
+ urlPath = urlPath.replace(replaceKeys.recordID, recordID);
141
+ // 3.请求
142
+ options.json = {
143
+ 'record': record,
144
+ "data_version": 'v3',
145
+ };
146
+ authType = (0, utils_1.formatAuthType)(authType);
147
+ options.headers.User = String(utils.getUserIDFromCtx());
148
+ if (authType) {
149
+ options.headers[constants_3.AuthTypeHttpHeader] = authType;
150
+ }
151
+ const task_id = utils.getTriggerTaskID();
152
+ if (task_id) {
153
+ options.json.task_id = task_id;
154
+ }
155
+ return openapi.doRequest(null, urlPath, options);
156
+ }
157
+ async function deleteRecordBySync(objectApiName, recordID, authType) {
158
+ // 1.check
159
+ if (!objectApiName) {
160
+ throw new exceptions.InvalidParamError('objectApiName is empty');
161
+ }
162
+ // 2.获取 options
163
+ let options = commonHttp.getOptions(null, openapiHttpPath.deleteRecordBySyncV2);
164
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await (0, common_1.getNamespaceForOpenAndFaaSSDK)());
165
+ urlPath = urlPath.replace(replaceKeys.objectApiName, objectApiName);
166
+ // 3.请求
167
+ options.json = {
168
+ 'operator': utils.getUserIDFromCtx(),
169
+ 'record_id': recordID,
170
+ };
171
+ authType = (0, utils_1.formatAuthType)(authType);
172
+ options.headers.User = String(utils.getUserIDFromCtx());
173
+ if (authType) {
174
+ options.headers[constants_3.AuthTypeHttpHeader] = authType;
175
+ }
176
+ const task_id = utils.getTriggerTaskID();
177
+ if (task_id) {
178
+ options.json.task_id = task_id;
179
+ }
180
+ return openapi.doRequest(null, urlPath, options);
181
+ }
182
+ async function deleteRecordBySyncV3(objectApiName, recordID, authType) {
183
+ // 1.check
184
+ if (!objectApiName) {
185
+ throw new exceptions.InvalidParamError('objectApiName is empty');
186
+ }
187
+ // 2.获取 options
188
+ let options = commonHttp.getOptions(null, openapiHttpPath.deleteRecordBySyncV3);
189
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await (0, common_1.getNamespaceForOpenAndFaaSSDK)());
190
+ urlPath = urlPath.replace(replaceKeys.objectApiName, objectApiName);
191
+ urlPath = urlPath.replace(replaceKeys.recordID, recordID);
192
+ authType = (0, utils_1.formatAuthType)(authType);
193
+ options.headers.User = String(utils.getUserIDFromCtx());
194
+ if (authType) {
195
+ options.headers[constants_3.AuthTypeHttpHeader] = authType;
196
+ }
197
+ const task_id = utils.getTriggerTaskID();
198
+ if (task_id) {
199
+ options.json.task_id = task_id;
200
+ }
201
+ return openapi.doRequest(null, urlPath, options);
202
+ }
203
+ async function createRecordsByAsync(objectApiName, records, authType) {
204
+ // 1.获取 options
205
+ let options = commonHttp.getOptions(null, openapiHttpPath.createRecordsByAsyncV2);
206
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await (0, common_1.getNamespaceForOpenAndFaaSSDK)());
207
+ urlPath = urlPath.replace(replaceKeys.objectApiName, objectApiName);
208
+ // 2.请求
209
+ options.json = {
210
+ 'operator': utils.getUserIDFromCtx(),
211
+ 'data': records,
212
+ };
213
+ authType = (0, utils_1.formatAuthType)(authType);
214
+ options.headers.User = String(utils.getUserIDFromCtx());
215
+ if (authType) {
216
+ options.headers[constants_3.AuthTypeHttpHeader] = authType;
217
+ }
218
+ const task_id = utils.getTriggerTaskID();
219
+ if (task_id) {
220
+ options.json.automation_task_id = task_id;
221
+ }
222
+ return openapi.doRequest(null, urlPath, options);
223
+ }
224
+ async function updateRecordsByAsync(objectApiName, recordMap, authType) {
225
+ // 1.获取 options
226
+ let options = commonHttp.getOptions(null, openapiHttpPath.updateRecordsByAsyncV2);
227
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await (0, common_1.getNamespaceForOpenAndFaaSSDK)());
228
+ urlPath = urlPath.replace(replaceKeys.objectApiName, objectApiName);
229
+ // 2.请求
230
+ options.json = {
231
+ 'operator': utils.getUserIDFromCtx(),
232
+ 'data': recordMap,
233
+ };
234
+ authType = (0, utils_1.formatAuthType)(authType);
235
+ options.headers.User = String(utils.getUserIDFromCtx());
236
+ if (authType) {
237
+ options.headers[constants_3.AuthTypeHttpHeader] = authType;
238
+ }
239
+ const task_id = utils.getTriggerTaskID();
240
+ if (task_id) {
241
+ options.json.automation_task_id = task_id;
242
+ }
243
+ return openapi.doRequest(null, urlPath, options);
244
+ }
245
+ async function deleteRecordsByAsync(objectApiName, recordIDs, authType) {
246
+ // 1.获取 options
247
+ let options = commonHttp.getOptions(null, openapiHttpPath.deleteRecordsByAsyncV2);
248
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await (0, common_1.getNamespaceForOpenAndFaaSSDK)());
249
+ urlPath = urlPath.replace(replaceKeys.objectApiName, objectApiName);
250
+ // 2.请求
251
+ options.json = {
252
+ 'operator': utils.getUserIDFromCtx(),
253
+ 'record_id_list': recordIDs,
254
+ };
255
+ authType = (0, utils_1.formatAuthType)(authType);
256
+ options.headers.User = String(utils.getUserIDFromCtx());
257
+ if (authType) {
258
+ options.headers[constants_3.AuthTypeHttpHeader] = authType;
259
+ }
260
+ const task_id = utils.getTriggerTaskID();
261
+ if (task_id) {
262
+ options.json.automation_task_id = task_id;
263
+ }
264
+ return openapi.doRequest(null, urlPath, options);
265
+ }
266
+ async function createRecordsBySync(objectApiName, records, authType) {
267
+ // 1.获取 options
268
+ let options = commonHttp.getOptions(null, openapiHttpPath.mCreateRecordsBySyncV2);
269
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await (0, common_1.getNamespaceForOpenAndFaaSSDK)());
270
+ urlPath = urlPath.replace(replaceKeys.objectApiName, objectApiName);
271
+ // 2.请求
272
+ options.json = {
273
+ 'operator': utils.getUserIDFromCtx(),
274
+ 'set_system_mod': 2,
275
+ 'data': records,
276
+ };
277
+ authType = (0, utils_1.formatAuthType)(authType);
278
+ options.headers.User = String(utils.getUserIDFromCtx());
279
+ if (authType) {
280
+ options.headers[constants_3.AuthTypeHttpHeader] = authType;
281
+ }
282
+ const task_id = utils.getTriggerTaskID();
283
+ if (task_id) {
284
+ options.json.automation_task_id = task_id;
285
+ }
286
+ return openapi.doRequest(null, urlPath, options);
287
+ }
288
+ async function createRecordsBySyncV3(objectApiName, records, authType) {
289
+ // 1.获取 options
290
+ const options = commonHttp.getOptions(null, openapiHttpPath.createRecordsBySyncV3);
291
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await (0, common_1.getNamespaceForOpenAndFaaSSDK)());
292
+ urlPath = urlPath.replace(replaceKeys.objectApiName, objectApiName);
293
+ // 2.请求
294
+ options.json = {
295
+ records,
296
+ 'data_version': 'v3',
297
+ };
298
+ authType = (0, utils_1.formatAuthType)(authType);
299
+ options.headers.User = String(utils.getUserIDFromCtx());
300
+ if (authType) {
301
+ options.headers[constants_3.AuthTypeHttpHeader] = authType;
302
+ }
303
+ const task_id = utils.getTriggerTaskID();
304
+ if (task_id) {
305
+ options.json.automation_task_id = task_id;
306
+ }
307
+ return openapi.doRequest(null, urlPath, options);
308
+ }
309
+ async function updateRecordsBySync(objectApiName, recordMap, authType) {
310
+ // 1.获取 options
311
+ let options = commonHttp.getOptions(null, openapiHttpPath.mUpdateRecordsBySyncV2);
312
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await (0, common_1.getNamespaceForOpenAndFaaSSDK)());
313
+ urlPath = urlPath.replace(replaceKeys.objectApiName, objectApiName);
314
+ // 2.请求
315
+ options.json = {
316
+ 'operator': utils.getUserIDFromCtx(),
317
+ 'set_system_mod': 2,
318
+ 'data': recordMap,
319
+ };
320
+ authType = (0, utils_1.formatAuthType)(authType);
321
+ options.headers.User = String(utils.getUserIDFromCtx());
322
+ if (authType) {
323
+ options.headers[constants_3.AuthTypeHttpHeader] = authType;
324
+ }
325
+ const task_id = utils.getTriggerTaskID();
326
+ if (task_id) {
327
+ options.json.automation_task_id = task_id;
328
+ }
329
+ const resp = await openapi.doRequest(null, urlPath, options);
330
+ if (!resp || !resp.err_map) {
331
+ return undefined;
332
+ }
333
+ const errMap = {};
334
+ for (let recordID of Object.keys(resp.err_map)) {
335
+ errMap[Number(recordID)] = resp.err_map[recordID];
336
+ }
337
+ return errMap;
338
+ }
339
+ async function updateRecordsBySyncV3(objectApiName, records, authType) {
340
+ // 1.获取 options
341
+ let options = commonHttp.getOptions(null, openapiHttpPath.updateRecordsBySyncV3);
342
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await (0, common_1.getNamespaceForOpenAndFaaSSDK)());
343
+ urlPath = urlPath.replace(replaceKeys.objectApiName, objectApiName);
344
+ // 2.请求
345
+ options.json = {
346
+ records,
347
+ 'data_version': 'v3',
348
+ };
349
+ authType = (0, utils_1.formatAuthType)(authType);
350
+ options.headers.User = String(utils.getUserIDFromCtx());
351
+ if (authType) {
352
+ options.headers[constants_3.AuthTypeHttpHeader] = authType;
353
+ }
354
+ const task_id = utils.getTriggerTaskID();
355
+ if (task_id) {
356
+ options.json.automation_task_id = task_id;
357
+ }
358
+ const resp = await openapi.doRequest(null, urlPath, options);
359
+ if (!resp || !resp.err_map) {
360
+ return undefined;
361
+ }
362
+ const errMap = {};
363
+ for (let recordID of Object.keys(resp.err_map)) {
364
+ errMap[String(recordID)] = resp.err_map[recordID];
365
+ }
366
+ return errMap;
367
+ }
368
+ async function deleteRecordsBySync(objectApiName, recordIDs, authType) {
369
+ // 1.获取 options
370
+ let options = commonHttp.getOptions(null, openapiHttpPath.mDeleteRecordsBySyncV2);
371
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await (0, common_1.getNamespaceForOpenAndFaaSSDK)());
372
+ urlPath = urlPath.replace(replaceKeys.objectApiName, objectApiName);
373
+ // 2.请求
374
+ options.json = {
375
+ 'operator': utils.getUserIDFromCtx(),
376
+ 'set_system_mod': 2,
377
+ 'record_id_list': recordIDs,
378
+ };
379
+ authType = (0, utils_1.formatAuthType)(authType);
380
+ options.headers.User = String(utils.getUserIDFromCtx());
381
+ if (authType) {
382
+ options.headers[constants_3.AuthTypeHttpHeader] = authType;
383
+ }
384
+ const task_id = utils.getTriggerTaskID();
385
+ if (task_id) {
386
+ options.json.automation_task_id = task_id;
387
+ }
388
+ const resp = await openapi.doRequest(null, urlPath, options);
389
+ if (!resp || !resp.err_map) {
390
+ return undefined;
391
+ }
392
+ const errMap = {};
393
+ for (let recordID of Object.keys(resp.err_map)) {
394
+ errMap[Number(recordID)] = resp.err_map[recordID];
395
+ }
396
+ return errMap;
397
+ }
398
+ async function deleteRecordsBySyncV3(objectApiName, recordIDs, authType) {
399
+ // 1.获取 options
400
+ const options = commonHttp.getOptions(null, openapiHttpPath.deleteRecordsBySyncV3);
401
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await (0, common_1.getNamespaceForOpenAndFaaSSDK)());
402
+ urlPath = urlPath.replace(replaceKeys.objectApiName, objectApiName);
403
+ // 2.请求
404
+ options.json = {
405
+ 'ids': recordIDs,
406
+ 'data_version': 'v3',
407
+ };
408
+ authType = (0, utils_1.formatAuthType)(authType);
409
+ options.headers.User = String(utils.getUserIDFromCtx());
410
+ if (authType) {
411
+ options.headers[constants_3.AuthTypeHttpHeader] = authType;
412
+ }
413
+ const task_id = utils.getTriggerTaskID();
414
+ if (task_id) {
415
+ options.json.automation_task_id = task_id;
416
+ }
417
+ const resp = await openapi.doRequest(null, urlPath, options);
418
+ if (!resp || !resp.err_map) {
419
+ return undefined;
420
+ }
421
+ const errMap = {};
422
+ for (let recordID of Object.keys(resp.err_map)) {
423
+ errMap[Number(recordID)] = resp.err_map[recordID];
424
+ }
425
+ return errMap;
426
+ }
427
+ function handleResponse(objectAPIName, data, needCount) {
428
+ // 返回数据的特殊处理
429
+ if (needCount) {
430
+ if (checkUtils.isObject(data) && data.total) {
431
+ return data.total;
432
+ }
433
+ return 0;
434
+ }
435
+ else {
436
+ if (checkUtils.isObject(data) && (data.data_list || data.items)) {
437
+ let records = data.data_list;
438
+ if (data.items) {
439
+ records = data.items;
440
+ }
441
+ if (data.unauthPermissionInfo && data.unauthPermissionInfo.UnauthFieldSlice) {
442
+ permissionUtils.appendUnauthFieldRecordList(objectAPIName, records, data.unauthPermissionInfo.UnauthFieldSlice, true);
443
+ }
444
+ if (data.unauth_permission_info && data.unauth_permission_info.unauth_field_slice) {
445
+ permissionUtils.appendUnauthFieldRecordList(objectAPIName, records, data.unauth_permission_info.unauth_field_slice, true);
446
+ }
447
+ return records;
448
+ }
449
+ return [];
450
+ }
451
+ }
452
+ async function getRecordsOrCountByCriterion(objectApiName, criterion, fuzzySearch, order, ignoreBackLookupField, fieldApiNames, offset, limit, needCount, authType) {
453
+ // 1.check
454
+ if (!objectApiName) {
455
+ throw new exceptions.InternalError('objectApiName is empty');
456
+ }
457
+ // 2.获取 options
458
+ let options = commonHttp.getOptions(null, needCount ? openapiHttpPath.mGetCountByCriterionV2 : openapiHttpPath.mGetRecordByCriterionV2);
459
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await (0, common_1.getNamespaceForOpenAndFaaSSDK)());
460
+ urlPath = urlPath.replace(replaceKeys.objectApiName, objectApiName);
461
+ if (needCount) {
462
+ fieldApiNames = ['_id'];
463
+ }
464
+ if (typeof criterion === 'string') {
465
+ criterion = JSON.parse(criterion);
466
+ }
467
+ // 3.请求
468
+ options.json = {
469
+ criterion,
470
+ order,
471
+ 'ignore_back_lookup_field': ignoreBackLookupField,
472
+ 'field_api_names': fieldApiNames,
473
+ offset,
474
+ limit,
475
+ 'need_filter_user_permission': false,
476
+ 'need_total_count': needCount,
477
+ fuzzySearch,
478
+ // 只返回 slice 结果,使用 SliceResult
479
+ // 只返回 map 结果,使用 MapResult
480
+ // 分不清场景可以用 BothResult,性能较差,建议区分场景
481
+ // 0 表示不返回 unauth field 任何数据; 1 表示两者都返回;2 表示仅返回 slice;3 表示仅返回 map
482
+ 'process_auth_field_type': 2,
483
+ };
484
+ authType = (0, utils_1.formatAuthType)(authType);
485
+ options.headers.User = String(utils.getUserIDFromCtx());
486
+ if (authType) {
487
+ options.headers[constants_3.AuthTypeHttpHeader] = authType;
488
+ }
489
+ const data = await openapi.doRequest(null, urlPath, options);
490
+ return handleResponse(objectApiName, data, needCount);
491
+ }
492
+ async function getRecordsV3OrCountByCriterion(objectApiName, criterion, quickQuery, quickQueryFields, order, fieldApiNames, offset, limit, needCount, authType) {
493
+ // 1.check
494
+ if (!objectApiName) {
495
+ throw new exceptions.InternalError('objectApiName is empty');
496
+ }
497
+ // 2.获取 options
498
+ let options = commonHttp.getOptions(null, openapiHttpPath.mGetRecordsV3OrCounByCriterion);
499
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await (0, common_1.getNamespaceForOpenAndFaaSSDK)());
500
+ urlPath = urlPath.replace(replaceKeys.objectApiName, objectApiName);
501
+ if (needCount) {
502
+ fieldApiNames = ['_id'];
503
+ }
504
+ if (typeof criterion === 'string') {
505
+ criterion = JSON.parse(criterion);
506
+ }
507
+ // 3.请求
508
+ options.json = {
509
+ 'page_size': limit,
510
+ 'offset': offset,
511
+ 'select': fieldApiNames,
512
+ 'order_by': order,
513
+ 'need_total_count': needCount,
514
+ 'filter': criterion,
515
+ 'quick_query': quickQuery,
516
+ 'quick_query_fields': quickQueryFields,
517
+ // 只返回 slice 结果,使用 SliceResult
518
+ // 只返回 map 结果,使用 MapResult
519
+ // 分不清场景可以用 BothResult,性能较差,建议区分场景
520
+ // 0 表示不返回 unauth field 任何数据; 1 表示两者都返回;2 表示仅返回 slice;3 表示仅返回 map
521
+ 'process_auth_field_type': 2,
522
+ 'data_version': 'v3',
523
+ };
524
+ authType = (0, utils_1.formatAuthType)(authType);
525
+ options.headers.User = String(utils.getUserIDFromCtx());
526
+ if (authType) {
527
+ options.headers[constants_3.AuthTypeHttpHeader] = authType;
528
+ }
529
+ const data = await openapi.doRequest(null, urlPath, options);
530
+ return handleResponse(objectApiName, data, needCount);
531
+ }
532
+ /**
533
+ * 上传文件
534
+ *
535
+ * @param datas:filePath;Stream
536
+ * @param expire:过期时间,单位秒
537
+ * @param fileName:文件名
538
+ * @returns {Promise<*|string>}
539
+ */
540
+ async function uploadFile(datas, expire = 0, fileName) {
541
+ let formData = new FormData();
542
+ if (fileName) {
543
+ formData.append('file', datas, fileName);
544
+ }
545
+ else {
546
+ formData.append('file', datas);
547
+ }
548
+ formData.append('expireSeconds', expire.toString());
549
+ formData.append('ignoreUserId', 'true');
550
+ let formHeaders = formData.getHeaders();
551
+ // 1.获取config
552
+ let options = commonHttp.getOptions(null, openapiHttpPath.uploadAttachment);
553
+ let urlPath = options._reqPath;
554
+ options.responseType = 'buffer';
555
+ for (let key of Object.keys(formHeaders)) {
556
+ options.headers[key] = formHeaders[key];
557
+ }
558
+ options.body = formData;
559
+ // 2.请求
560
+ return await openapi.doRequest(null, urlPath, options);
561
+ }
562
+ async function downloadFileByID(id, filePath) {
563
+ // 1.获取 options
564
+ let options = commonHttp.getOptions(null, openapiHttpPath.downloadFile);
565
+ let urlPath = options._reqPath.replace(replaceKeys.fileID, id);
566
+ options.responseType = 'buffer';
567
+ // 2.请求
568
+ let data = await openapi.doRequest(null, urlPath, options);
569
+ // 3.写入文件
570
+ data = Buffer.from(data, 'binary');
571
+ if (filePath) {
572
+ checkUtils.checkFile(filePath);
573
+ utils.mkdirs(path.dirname(filePath));
574
+ fs.writeFileSync(filePath, data);
575
+ return undefined;
576
+ }
577
+ return data;
578
+ }
579
+ async function downloadFileByToken(fileToken, filePath) {
580
+ // 1.获取 options
581
+ let options = commonHttp.getOptions(null, openapiHttpPath.downloadAttachment);
582
+ let urlPath = options._reqPath + `?token=${fileToken}`;
583
+ options.responseType = 'buffer';
584
+ // 2.请求
585
+ let data = await openapi.doRequest(null, urlPath, options);
586
+ // 3.写入文件
587
+ data = Buffer.from(data, 'binary');
588
+ if (filePath) {
589
+ checkUtils.checkFile(filePath);
590
+ utils.mkdirs(path.dirname(filePath));
591
+ fs.writeFileSync(filePath, data);
592
+ return undefined;
593
+ }
594
+ return data;
595
+ }
596
+ async function mGetFileToken(ids) {
597
+ // 1.获取 options
598
+ let options = commonHttp.getOptions(null, constants_2.openapiHttpPath.getBatchAttachmentToken);
599
+ let urlPath = options._reqPath;
600
+ // 2.请求
601
+ options.json = {
602
+ attachmentIds: ids
603
+ };
604
+ let res = await openapi.doRequest(null, urlPath, options);
605
+ if (!res || !res.tokens) {
606
+ throw new exceptions.InternalError(`mGetFileToken result is empty`);
607
+ }
608
+ return res.tokens;
609
+ }
610
+ async function createMessage(msg) {
611
+ // 1.解析参数 icon/receiverIds/percent
612
+ if (!msg.icon) {
613
+ throw new exceptions.InvalidParamError(`parameter icon is required!`);
614
+ }
615
+ if (typeof (msg.icon) != 'string') {
616
+ throw new exceptions.InvalidParamError(`Invalid format of parameter icon, icon should be string.`);
617
+ }
618
+ let params = {};
619
+ const modelKeySearchData = { 'icon_type': msg.icon };
620
+ const receiverIds = msg.target_users || [];
621
+ if (!(receiverIds instanceof Array)) {
622
+ throw new exceptions.InvalidParamError(`Invalid format of parameter target_users, target_users should be array.`);
623
+ }
624
+ if (receiverIds.length === 0) {
625
+ throw new exceptions.InvalidParamError(`parameter target_users is required!`);
626
+ }
627
+ const percent = msg.percent;
628
+ if (percent !== undefined && percent !== null) {
629
+ if (typeof (percent) !== 'number') {
630
+ throw new exceptions.InvalidParamError('Invalid format of parameter percent, percent should be number.');
631
+ }
632
+ if (percent < 0 || percent > 100) {
633
+ throw new exceptions.InvalidParamError('Invalid value of parameter percent, the value should be in range [0, 100].');
634
+ }
635
+ else {
636
+ modelKeySearchData.percent = JSON.stringify(percent);
637
+ }
638
+ }
639
+ // kunlun类型
640
+ if (checkUtils.isObject(msg)) {
641
+ for (let key of Object.keys(msg)) {
642
+ if (fieldType.isKFieldType(msg[key])) {
643
+ // instanceof 改动6
644
+ // if (msg[key] instanceof fieldType.Multilingual) {
645
+ if (fieldType.isKFieldTypeMultilingual((msg[key]))) {
646
+ let value = JSON.stringify(msg[key].toJSON());
647
+ params[key] = JSON.stringify({ value });
648
+ }
649
+ else {
650
+ params[key] = JSON.stringify(msg[key].toJSON());
651
+ }
652
+ }
653
+ else {
654
+ params[key] = JSON.stringify(msg[key]);
655
+ }
656
+ }
657
+ }
658
+ // 2.获取 options
659
+ let options = commonHttp.getOptions(null, openapiHttpPath.createMessage);
660
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await (0, common_1.getNamespaceForOpenAndFaaSSDK)());
661
+ // 3.请求
662
+ options.json = {
663
+ 'NotifyModelKey': constants_1.notifyModel.key,
664
+ 'ReceiverIDs': receiverIds,
665
+ 'ParamsRawData': params,
666
+ 'Percent': percent,
667
+ 'ModelKeySearchData': modelKeySearchData,
668
+ };
669
+ let res = await openapi.doRequest(null, urlPath, options);
670
+ return Number(res.taskID);
671
+ }
672
+ async function updateMessage(msgId, msg) {
673
+ // 1.解析参数 msgId/icon/percent
674
+ if (!msgId) {
675
+ throw new exceptions.InvalidParamError(`parameter msgId is required!`);
676
+ }
677
+ if (typeof (msgId) != 'number') {
678
+ throw new exceptions.InvalidParamError(`Invalid format of parameter msgId, msgId should be number.`);
679
+ }
680
+ if (!msg.icon) {
681
+ throw new exceptions.InvalidParamError(`parameter icon is required!`);
682
+ }
683
+ if (typeof (msg.icon) != 'string') {
684
+ throw new exceptions.InvalidParamError(`Invalid format of parameter icon, icon should be string.`);
685
+ }
686
+ let params = {};
687
+ const modelKeySearchData = { 'icon_type': msg.icon };
688
+ const percent = msg.percent;
689
+ if (percent !== undefined && percent !== null) {
690
+ if (typeof (percent) !== 'number') {
691
+ throw new exceptions.InvalidParamError('Invalid format of parameter percent, percent should be number.');
692
+ }
693
+ if (percent < 0 || percent > 100) {
694
+ throw new exceptions.InvalidParamError('Invalid value of parameter percent in message ${msgId}, the value should be in range [0, 100].');
695
+ }
696
+ else {
697
+ modelKeySearchData.percent = JSON.stringify(percent);
698
+ }
699
+ }
700
+ // kunlun类型
701
+ if (checkUtils.isObject(msg)) {
702
+ for (let key of Object.keys(msg)) {
703
+ if (fieldType.isKFieldType(msg[key])) {
704
+ // instanceof 改动7
705
+ // if (msg[key] instanceof fieldType.Multilingual) {
706
+ if (fieldType.isKFieldTypeMultilingual(msg[key])) {
707
+ let value = JSON.stringify(msg[key].toJSON());
708
+ params[key] = JSON.stringify({ value });
709
+ }
710
+ else {
711
+ params[key] = JSON.stringify(msg[key].toJSON());
712
+ }
713
+ }
714
+ else {
715
+ params[key] = JSON.stringify(msg[key]);
716
+ }
717
+ }
718
+ }
719
+ // 2.获取 options
720
+ let options = commonHttp.getOptions(null, openapiHttpPath.updateMessage);
721
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await (0, common_1.getNamespaceForOpenAndFaaSSDK)());
722
+ // 3.请求
723
+ options.json = {
724
+ 'TaskID': msgId,
725
+ 'Percent': percent,
726
+ 'NotifyModelKey': constants_1.notifyModel.key,
727
+ 'ParamsRawData': params,
728
+ 'IsBackground': true,
729
+ 'ModelKeySearchData': modelKeySearchData,
730
+ };
731
+ return await openapi.doRequest(null, urlPath, options);
732
+ }
733
+ async function getFields(objectApiName) {
734
+ // 1.check
735
+ if (!objectApiName) {
736
+ throw new exceptions.InvalidParamError('objectApiName is empty');
737
+ }
738
+ // 2.获取config
739
+ let options = commonHttp.getOptions(null, openapiHttpPath.getFieldsV5);
740
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await (0, common_1.getNamespaceForOpenAndFaaSSDK)());
741
+ urlPath = urlPath.replace(replaceKeys.objectApiName, objectApiName);
742
+ let obj = await openapi.doRequest(null, urlPath, options);
743
+ if (!obj || !obj.fields) {
744
+ return [];
745
+ }
746
+ return obj.fields;
747
+ }
748
+ async function getField(objectApiName, fieldApiName) {
749
+ // 1.check
750
+ if (!objectApiName) {
751
+ throw new exceptions.InternalError('objectApiName is empty');
752
+ }
753
+ if (!fieldApiName) {
754
+ throw new exceptions.InternalError('fieldApiName is empty');
755
+ }
756
+ // 2.获取 options
757
+ let options = commonHttp.getOptions(null, openapiHttpPath.getFieldV5);
758
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await (0, common_1.getNamespaceForOpenAndFaaSSDK)());
759
+ urlPath = urlPath.replace(replaceKeys.objectApiName, objectApiName);
760
+ urlPath = urlPath.replace(replaceKeys.fieldApiName, fieldApiName);
761
+ // 3.请求
762
+ return await openapi.doRequest(null, urlPath, options);
763
+ }
764
+ async function terminateWorkflowInstance(workflowInstanceId, operator, reason) {
765
+ // 1.check
766
+ if (typeof (workflowInstanceId) !== 'number') {
767
+ throw new exceptions.InvalidParamError(`The type of workflowInstanceId should be number, but ${typeof (workflowInstanceId)}.`);
768
+ }
769
+ // 2.获取 options
770
+ let options = commonHttp.getOptions(null, openapiHttpPath.terminateWorkflowInstance);
771
+ let urlPath = options._reqPath;
772
+ // 3.请求
773
+ options.json = {
774
+ 'workflowInstanceID': workflowInstanceId,
775
+ operator,
776
+ reason,
777
+ };
778
+ await openapi.doRequest(null, urlPath, options);
779
+ }
780
+ async function modifyRecordsWithTransaction(placeholders, operations, authType, version) {
781
+ // 1.获取 options
782
+ let options = commonHttp.getOptions(null, openapiHttpPath.modifyRecordsWithTransaction);
783
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await (0, common_1.getNamespaceForOpenAndFaaSSDK)());
784
+ // 2.请求
785
+ options.json = {
786
+ placeholders,
787
+ operations,
788
+ 'operatorId': utils.getUserIDFromCtx(),
789
+ 'setSystemField': 1,
790
+ };
791
+ if (version === 'v3') {
792
+ options.json['dataVersion'] = version;
793
+ }
794
+ authType = (0, utils_1.formatAuthType)(authType);
795
+ options.headers.User = String(utils.getUserIDFromCtx());
796
+ if (authType) {
797
+ options.headers[constants_3.AuthTypeHttpHeader] = authType;
798
+ }
799
+ let taskId = utils.getTriggerTaskID();
800
+ if (taskId) {
801
+ options.json.taskId = taskId;
802
+ }
803
+ let result = await openapi.doRequest(null, urlPath, options);
804
+ let retPlaceholders = new Map();
805
+ if (result && result.placeholders) {
806
+ for (let key of Object.keys(result.placeholders)) {
807
+ retPlaceholders.set(key, result.placeholders[key]);
808
+ }
809
+ }
810
+ return retPlaceholders;
811
+ }
812
+ async function getGlobalConfigByKey(key) {
813
+ // 1.获取 options
814
+ let options = commonHttp.getOptions(null, openapiHttpPath.getAllGlobalConfigs);
815
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await (0, common_1.getNamespaceForOpenAndFaaSSDK)());
816
+ // 2.请求
817
+ let pageSize = 100, offset = 0;
818
+ for (let i = 0;; i++) {
819
+ options.json = {
820
+ 'biz_type': 'GlobalVariables',
821
+ 'used_by': 'UsedBySystem',
822
+ 'filter': {
823
+ 'offset': pageSize * i,
824
+ 'limit': pageSize,
825
+ },
826
+ };
827
+ let data = await openapi.doRequest(null, urlPath, options);
828
+ for (let config of data.configs) {
829
+ if (config.key === key) {
830
+ return config.value;
831
+ }
832
+ }
833
+ if (data.configs.length < pageSize) {
834
+ break;
835
+ }
836
+ }
837
+ throw new exceptions.InvalidParamError(`undefined global variable (${key})`);
838
+ }
839
+ async function oql(oql, args, namedArgs, authType) {
840
+ // 1.获取 options
841
+ let options = commonHttp.getOptions(null, constants_2.openapiHttpPath.oql);
842
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await (0, common_1.getNamespaceForOpenAndFaaSSDK)());
843
+ // 2.请求
844
+ options.json = {
845
+ 'query': oql,
846
+ args,
847
+ namedArgs,
848
+ 'compat': true,
849
+ 'unauthFields': true,
850
+ };
851
+ authType = (0, utils_1.formatAuthType)(authType);
852
+ options.headers.User = String(utils.getUserIDFromCtx());
853
+ if (authType) {
854
+ if (authType === constants_3.AuthTypeUser || authType === constants_3.AuthTypeMixUserSystem) {
855
+ // select 鉴权,where、groupBy、orderBy 不鉴权
856
+ authType = constants_3.AuthTypeMixUserSystem;
857
+ }
858
+ options.headers[constants_3.AuthTypeHttpHeader] = authType;
859
+ }
860
+ try {
861
+ let result = await openapi.doRequest(null, urlPath, options);
862
+ if (result && result.rows) {
863
+ permissionUtils.appendUnauthFieldRecordList("", result.rows, result.unauth_field_slice, true);
864
+ return result.rows;
865
+ }
866
+ }
867
+ catch (e) {
868
+ if (e.message.includes("TimeoutError")) {
869
+ throw new exceptions.CallOpenapiError(`OQL timeout, please check the query statement and the execution time of the query statement.`);
870
+ }
871
+ throw e;
872
+ }
873
+ return [];
874
+ }
875
+ async function openSDKCreateRecordBySync(objectApiName, record) {
876
+ // 1.获取 options
877
+ let options = commonHttp.getOptions(null, openapiHttpPath.openSDKCreateRecord);
878
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await (0, common_1.getNamespaceForOpenAndFaaSSDK)());
879
+ urlPath = urlPath.replace(replaceKeys.objectApiName, objectApiName);
880
+ // 2.请求
881
+ options.json = record;
882
+ return await openapi.doRequest(null, urlPath, options);
883
+ }
884
+ async function openSDKUpdateRecordBySync(objectApiName, recordID, record) {
885
+ // 1.获取 options
886
+ let options = commonHttp.getOptions(null, openapiHttpPath.openSDKUpdateRecord);
887
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await (0, common_1.getNamespaceForOpenAndFaaSSDK)());
888
+ urlPath = urlPath.replace(replaceKeys.objectApiName, objectApiName);
889
+ urlPath = urlPath.replace(replaceKeys.recordID, recordID.toString());
890
+ // 2.请求
891
+ options.json = record;
892
+ return await openapi.doRequest(null, urlPath, options);
893
+ }
894
+ ;
895
+ async function openSDKDeleteRecordBySync(objectApiName, recordID) {
896
+ // 1.获取 options
897
+ let options = commonHttp.getOptions(null, openapiHttpPath.openSDKDeleteRecord);
898
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await (0, common_1.getNamespaceForOpenAndFaaSSDK)());
899
+ urlPath = urlPath.replace(replaceKeys.objectApiName, objectApiName);
900
+ urlPath = urlPath.replace(replaceKeys.recordID, recordID.toString());
901
+ // 2.请求
902
+ return await openapi.doRequest(null, urlPath, options);
903
+ }
904
+ ;
905
+ async function openSDKCreateRecordsBySync(objectApiName, records) {
906
+ // 1.获取 options
907
+ let options = commonHttp.getOptions(null, openapiHttpPath.openSDKBatchCreateRecord);
908
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await (0, common_1.getNamespaceForOpenAndFaaSSDK)());
909
+ urlPath = urlPath.replace(replaceKeys.objectApiName, objectApiName);
910
+ // 2.请求
911
+ options.json = { records: records };
912
+ return await openapi.doRequest(null, urlPath, options);
913
+ }
914
+ ;
915
+ async function openSDKUpdateRecordsBySync(objectApiName, records) {
916
+ // 1.获取 options
917
+ let options = commonHttp.getOptions(null, openapiHttpPath.openSDKBatchUpdateRecord);
918
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await (0, common_1.getNamespaceForOpenAndFaaSSDK)());
919
+ urlPath = urlPath.replace(replaceKeys.objectApiName, objectApiName);
920
+ // 2.请求
921
+ options.json = { records: records };
922
+ return await openapi.doRequest(null, urlPath, options);
923
+ }
924
+ ;
925
+ async function openSDKDeleteRecordsBySync(objectApiName, recordIDs) {
926
+ // 1.获取 options
927
+ let options = commonHttp.getOptions(null, openapiHttpPath.openSDKBatchDeleteRecord);
928
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await (0, common_1.getNamespaceForOpenAndFaaSSDK)());
929
+ urlPath = urlPath.replace(replaceKeys.objectApiName, objectApiName);
930
+ // 2.请求
931
+ options.json = { _ids: recordIDs };
932
+ return await openapi.doRequest(null, urlPath, options);
933
+ }
934
+ ;
935
+ async function openSDKGetRecords(objectApiName, param) {
936
+ // 1.获取 options
937
+ let options = commonHttp.getOptions(null, openapiHttpPath.openSDKGetRecords);
938
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await (0, common_1.getNamespaceForOpenAndFaaSSDK)());
939
+ urlPath = urlPath.replace(replaceKeys.objectApiName, objectApiName);
940
+ if (param.limit <= 0 || param.limit > 10000) {
941
+ param.limit = 10000;
942
+ }
943
+ // 2.请求
944
+ options.json = param;
945
+ const data = await openapi.doRequest(null, urlPath, options);
946
+ if (param.count) {
947
+ return data.total;
948
+ }
949
+ else {
950
+ return data.records;
951
+ }
952
+ }
953
+ async function openSDKUploadFile(fileName, data) {
954
+ // 1.获取 options
955
+ let options = commonHttp.getOptions(null, openapiHttpPath.openSDKUploadFile);
956
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await (0, common_1.getNamespaceForOpenAndFaaSSDK)());
957
+ let formData = new FormData();
958
+ formData.append('file', data);
959
+ formData.append('ignoreUserId', 'true');
960
+ let formHeaders = formData.getHeaders();
961
+ options.responseType = 'buffer';
962
+ for (let key of Object.keys(formHeaders)) {
963
+ options.headers[key] = formHeaders[key];
964
+ }
965
+ options.body = formData;
966
+ // 2.请求
967
+ return await openapi.doRequest(null, urlPath, options);
968
+ }
969
+ async function openSDKUploadAvatar(fileName, data) {
970
+ // 1.获取 options
971
+ let options = commonHttp.getOptions(null, openapiHttpPath.openSDKUploadAvatar);
972
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await (0, common_1.getNamespaceForOpenAndFaaSSDK)());
973
+ let formData = new FormData();
974
+ formData.append('file', data);
975
+ formData.append('ignoreUserId', 'true');
976
+ let formHeaders = formData.getHeaders();
977
+ options.responseType = 'buffer';
978
+ for (let key of Object.keys(formHeaders)) {
979
+ options.headers[key] = formHeaders[key];
980
+ }
981
+ options.body = formData;
982
+ // 2.请求
983
+ return await openapi.doRequest(null, urlPath, options);
984
+ }
985
+ async function openSDKDownloadAvatar(imageID) {
986
+ // 1.获取 options
987
+ let options = commonHttp.getOptions(null, openapiHttpPath.openSDKDownloadAvatar);
988
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await (0, common_1.getNamespaceForOpenAndFaaSSDK)());
989
+ urlPath = urlPath.replace(replaceKeys.fileID, imageID);
990
+ options.responseType = 'buffer';
991
+ // 2.请求
992
+ let data = await openapi.doRequest(null, urlPath, options);
993
+ // 3.写入文件
994
+ data = Buffer.from(data, 'binary');
995
+ return data;
996
+ }
997
+ class RequestHttp {
998
+ constructor() {
999
+ this.updateWorkflowVariables = updateWorkflowVariables;
1000
+ this.createRecordBySync = createRecordBySync;
1001
+ this.createRecordBySyncV3 = createRecordBySyncV3;
1002
+ this.updateRecordBySync = updateRecordBySync;
1003
+ this.updateRecordBySyncV3 = updateRecordBySyncV3;
1004
+ this.deleteRecordBySync = deleteRecordBySync;
1005
+ this.deleteRecordBySyncV3 = deleteRecordBySyncV3;
1006
+ this.createRecordsByAsync = createRecordsByAsync;
1007
+ this.updateRecordsByAsync = updateRecordsByAsync;
1008
+ this.deleteRecordsByAsync = deleteRecordsByAsync;
1009
+ this.createRecordsBySync = createRecordsBySync;
1010
+ this.createRecordsBySyncV3 = createRecordsBySyncV3;
1011
+ this.updateRecordsBySync = updateRecordsBySync;
1012
+ this.updateRecordsBySyncV3 = updateRecordsBySyncV3;
1013
+ this.deleteRecordsBySync = deleteRecordsBySync;
1014
+ this.deleteRecordsBySyncV3 = deleteRecordsBySyncV3;
1015
+ this.getRecordsOrCountByCriterion = getRecordsOrCountByCriterion;
1016
+ this.getRecordsV3OrCounByCriterion = getRecordsV3OrCountByCriterion;
1017
+ this.uploadFile = uploadFile;
1018
+ this.downloadFileByID = downloadFileByID;
1019
+ this.downloadFileByToken = downloadFileByToken;
1020
+ this.mGetFileToken = mGetFileToken;
1021
+ this.createMessage = createMessage;
1022
+ this.updateMessage = updateMessage;
1023
+ this.getFields = getFields;
1024
+ this.getField = getField;
1025
+ this.terminateWorkflowInstance = terminateWorkflowInstance;
1026
+ this.modifyRecordsWithTransaction = modifyRecordsWithTransaction;
1027
+ this.getGlobalConfigByKey = getGlobalConfigByKey;
1028
+ this.oql = oql;
1029
+ this.getIntegrationAppAccessToken = getIntegrationAppAccessToken;
1030
+ this.getIntegrationTenantAccessToken = getIntegrationTenantAccessToken;
1031
+ this.getDefaultIntegrationAppAccessToken = getDefaultIntegrationAppAccessToken;
1032
+ this.getDefaultIntegrationTenantAccessToken = getDefaultIntegrationTenantAccessToken;
1033
+ // TODO: open sdk api test
1034
+ this.openSDKCreateRecordBySync = openSDKCreateRecordBySync;
1035
+ this.openSDKUpdateRecordBySync = openSDKUpdateRecordBySync;
1036
+ this.openSDKDeleteRecordBySync = openSDKDeleteRecordBySync;
1037
+ this.openSDKCreateRecordsBySync = openSDKCreateRecordsBySync;
1038
+ this.openSDKUpdateRecordsBySync = openSDKUpdateRecordsBySync;
1039
+ this.openSDKDeleteRecordsBySync = openSDKDeleteRecordsBySync;
1040
+ this.openSDKGetRecords = openSDKGetRecords;
1041
+ this.openSDKUploadFile = openSDKUploadFile;
1042
+ this.openSDKUploadAvatar = openSDKUploadAvatar;
1043
+ this.openSDKDownloadAvatar = openSDKDownloadAvatar;
1044
+ }
1045
+ updateWorkflowVariables(ctx, instanceId, variables, variableTypes) {
1046
+ }
1047
+ createRecordBySync(objectApiName, record, authType) {
1048
+ }
1049
+ createRecordBySyncV3(objectApiName, record, authType) {
1050
+ }
1051
+ updateRecordBySync(objectApiName, recordID, record, authType) {
1052
+ }
1053
+ updateRecordBySyncV3(objectApiName, recordID, record, authType) {
1054
+ }
1055
+ deleteRecordBySync(objectApiName, recordID, authType) {
1056
+ }
1057
+ deleteRecordBySyncV3(objectApiName, recordID, authType) {
1058
+ }
1059
+ createRecordsByAsync(objectApiName, records, authType) {
1060
+ }
1061
+ updateRecordsByAsync(objectApiName, recordMap, authType) {
1062
+ }
1063
+ deleteRecordsByAsync(objectApiName, recordIDs, authType) {
1064
+ }
1065
+ createRecordsBySync(objectApiName, records, authType) {
1066
+ }
1067
+ createRecordsBySyncV3(objectApiName, records, authType) {
1068
+ }
1069
+ updateRecordsBySync(objectApiName, recordMap, authType) {
1070
+ return new Promise(undefined);
1071
+ }
1072
+ updateRecordsBySyncV3(objectApiName, records, authType) {
1073
+ return new Promise(undefined);
1074
+ }
1075
+ deleteRecordsBySync(objectApiName, recordIDs, authType) {
1076
+ return new Promise(undefined);
1077
+ }
1078
+ deleteRecordsBySyncV3(objectApiName, recordIDs, authType) {
1079
+ return new Promise(undefined);
1080
+ }
1081
+ getRecordsOrCountByCriterion(objectApiName, criterion, order, fuzzySearch, ignoreBackLookupField, fieldApiNames, offset, limit, needCount, authType) {
1082
+ }
1083
+ getRecordsV3OrCounByCriterion(objectApiName, criterion, quickQuery, quickQueryFields, order, fieldApiNames, offset, limit, needCount, authType) {
1084
+ }
1085
+ uploadFile(data, expire, fileName) {
1086
+ return null;
1087
+ }
1088
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
1089
+ downloadFileByID(fileID, filePath) {
1090
+ return null;
1091
+ }
1092
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
1093
+ downloadFileByToken(fileToken, filePath) {
1094
+ return null;
1095
+ }
1096
+ createMessage(msg) {
1097
+ return null;
1098
+ }
1099
+ updateMessage(msgId, msg) {
1100
+ return null;
1101
+ }
1102
+ getFields(objectApiName) {
1103
+ }
1104
+ getField(objectApiName, fieldApiName) {
1105
+ }
1106
+ terminateWorkflowInstance(workflowInstanceId, operator, reason) {
1107
+ }
1108
+ async modifyRecordsWithTransaction(placeholders, operations, authType, version) {
1109
+ return new Promise(undefined);
1110
+ }
1111
+ getGlobalConfigByKey(key) {
1112
+ return null;
1113
+ }
1114
+ oql(oql, args, namedArgs, authType) {
1115
+ }
1116
+ async invokeFuncSync(idOrName, params) {
1117
+ return await invokeFuncSync(idOrName, params);
1118
+ }
1119
+ async invokeFuncWithAuth(idOrName, params) {
1120
+ return await invokeFuncWithAuth(idOrName, params);
1121
+ }
1122
+ async createAsyncTaskV1(idOrName, params) {
1123
+ return await createAsyncTaskV1(idOrName, params);
1124
+ }
1125
+ async createAsyncTaskV2(name, params) {
1126
+ return await createAsyncTaskV2(name, params);
1127
+ }
1128
+ async getExecutionUserTaskInfo(executionId) {
1129
+ return await getExecutionUserTaskInfo(executionId);
1130
+ }
1131
+ async executeFlow(apiName, options, async) {
1132
+ return await executeFlow(apiName, options, async);
1133
+ }
1134
+ async revokeExecution(executionId, revokeOptions) {
1135
+ return await revokeExecution(executionId, revokeOptions);
1136
+ }
1137
+ async getExecutionInfo(executionId) {
1138
+ return await getExecutionInfo(executionId);
1139
+ }
1140
+ async getTenantInfo(appCtx) {
1141
+ return await appCtx.credential.getTenantInfo();
1142
+ }
1143
+ mGetFileToken(ids) {
1144
+ return null;
1145
+ }
1146
+ async getIntegrationAppAccessToken(apiName) {
1147
+ return null;
1148
+ }
1149
+ async getIntegrationTenantAccessToken(apiName) {
1150
+ return null;
1151
+ }
1152
+ async getDefaultIntegrationAppAccessToken() {
1153
+ return null;
1154
+ }
1155
+ async getDefaultIntegrationTenantAccessToken() {
1156
+ return null;
1157
+ }
1158
+ // open sdk empty implement
1159
+ openSDKCreateRecordBySync(objectApiName, record) {
1160
+ }
1161
+ ;
1162
+ openSDKUpdateRecordBySync(objectApiName, recordID, record) {
1163
+ }
1164
+ ;
1165
+ openSDKDeleteRecordBySync(objectApiName, recordID) {
1166
+ }
1167
+ ;
1168
+ openSDKCreateRecordsBySync(objectApiName, records) {
1169
+ }
1170
+ ;
1171
+ openSDKUpdateRecordsBySync(objectApiName, recordMap) {
1172
+ }
1173
+ ;
1174
+ openSDKDeleteRecordsBySync(objectApiName, recordIDs) {
1175
+ }
1176
+ ;
1177
+ openSDKGetRecords(objectApiName, param) {
1178
+ return null;
1179
+ }
1180
+ ;
1181
+ openSDKUploadFile(fileName, data) {
1182
+ }
1183
+ ;
1184
+ openSDKUploadAvatar(fileName, data) {
1185
+ }
1186
+ ;
1187
+ openSDKDownloadAvatar(imageID) {
1188
+ return null;
1189
+ }
1190
+ ;
1191
+ async getApprovalInstanceList(params) {
1192
+ let options = commonHttp.getOptions(null, constants_2.openapiHttpPath.getApprovalInstanceList);
1193
+ let urlPath = options._reqPath;
1194
+ // 设置参数
1195
+ const searchParams = {};
1196
+ if (params && params.startTime && params.startTime > 0) {
1197
+ searchParams.start_time = params.startTime;
1198
+ }
1199
+ if (params && params.endTime && params.endTime > 0) {
1200
+ searchParams.end_time = params.endTime;
1201
+ }
1202
+ if (params && params.pageSize && params.pageSize > 0) {
1203
+ searchParams.page_size = params.pageSize;
1204
+ }
1205
+ if (params && params.pageToken) {
1206
+ searchParams.page_token = params.pageToken;
1207
+ }
1208
+ options.searchParams = searchParams;
1209
+ // 发起请求
1210
+ let resp = await openapi.doRequest(null, urlPath, options);
1211
+ // 应答
1212
+ return {
1213
+ approvalInstanceIds: resp.approval_instance_ids,
1214
+ pageToken: resp.page_token,
1215
+ count: resp.count,
1216
+ hasMore: resp.has_more,
1217
+ };
1218
+ }
1219
+ async getApprovalInstance(params) {
1220
+ let options = commonHttp.getOptions(null, constants_2.openapiHttpPath.getApprovalInstance);
1221
+ let urlPath = options._reqPath.replace(replaceKeys.id, String(params.approvalInstanceId));
1222
+ // 设置参数
1223
+ const searchParams = new URLSearchParams();
1224
+ if (params && params.includeContent) {
1225
+ searchParams.append('includes', 'ApprovalComment_Content');
1226
+ }
1227
+ if (params && params.includeFormData) {
1228
+ searchParams.append('includes', 'ApprovalTask_FormData');
1229
+ }
1230
+ urlPath = urlPath + '?' + searchParams.toString();
1231
+ // 发起请求
1232
+ let resp = await openapi.doRequest(null, urlPath, options);
1233
+ if (!resp || !resp.approval_instance) {
1234
+ return undefined;
1235
+ }
1236
+ // 处理应答
1237
+ const approvalInstance = resp.approval_instance;
1238
+ const result = {
1239
+ id: approvalInstance.id,
1240
+ label: approvalInstance.label,
1241
+ initiator: approvalInstance.initiator,
1242
+ instanceStartTime: approvalInstance.instance_start_time,
1243
+ status: approvalInstance.status,
1244
+ tasks: [],
1245
+ comments: [],
1246
+ };
1247
+ if (approvalInstance.tasks && Array.isArray(approvalInstance.tasks)) {
1248
+ for (let task of approvalInstance.tasks) {
1249
+ result.tasks.push({
1250
+ id: task.id,
1251
+ taskType: task.task_type,
1252
+ taskStatus: task.task_status,
1253
+ taskStartTime: task.task_start_time,
1254
+ taskEndTime: task.task_end_time,
1255
+ formData: task.form_data,
1256
+ approvalLogic: task.approval_logic,
1257
+ approvers: task.approvers,
1258
+ assigners: task.assigners,
1259
+ taskURL: task.task_url,
1260
+ });
1261
+ }
1262
+ }
1263
+ if (approvalInstance.comments && Array.isArray(approvalInstance.comments)) {
1264
+ for (let comment of approvalInstance.comments) {
1265
+ result.comments.push({
1266
+ id: comment.id,
1267
+ commenter: comment.commenter,
1268
+ content: comment.content,
1269
+ createAt: comment.create_at,
1270
+ updateAt: comment.update_at,
1271
+ });
1272
+ }
1273
+ }
1274
+ return result;
1275
+ }
1276
+ }
1277
+ exports.RequestHttp = RequestHttp;
1278
+ async function invokeFuncWithAuth(idOrName, params) {
1279
+ let options = commonHttp.getOptions(null, openapiHttpPath.invokeFuncWithAuthInnerAPI);
1280
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await (0, common_1.getNamespaceForOpenAndFaaSSDK)());
1281
+ urlPath = urlPath.replace(replaceKeys.apiName, idOrName.APIName);
1282
+ options.headers.User = utils.getUserIDFromCtx();
1283
+ options.json = {
1284
+ params,
1285
+ 'context': getTriggerCtx(),
1286
+ };
1287
+ if (!idOrName.isInvokeByAPIName) {
1288
+ options.json.apiID = idOrName.APIId;
1289
+ }
1290
+ let res = await openapi.doRequest(null, urlPath, options);
1291
+ if (!res || !res.result) {
1292
+ throw new exceptions.InternalError(`result is empty`);
1293
+ }
1294
+ let result;
1295
+ try {
1296
+ result = JSON.parse(res.result);
1297
+ }
1298
+ catch (e) {
1299
+ throw new exceptions.InternalError(`JSON parse failed for ${res.result}`);
1300
+ }
1301
+ if (!result || result.code !== '0') {
1302
+ throw new exceptions.InvalidParamError(`result is invalid for code: ${result ? result.code : ''} msg: ${result ? result.msg : ''}`);
1303
+ }
1304
+ return result.data;
1305
+ }
1306
+ async function invokeFuncSync(idOrName, params) {
1307
+ let options = commonHttp.getOptions(null, openapiHttpPath.invokeFuncSyncInnerAPI);
1308
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await (0, common_1.getNamespaceForOpenAndFaaSSDK)());
1309
+ options.headers.User = utils.getUserIDFromCtx();
1310
+ options.json = {
1311
+ 'params': JSON.stringify(params),
1312
+ 'context': JSON.stringify(getTriggerCtx()),
1313
+ 'triggerType': utils.getTriggerType(),
1314
+ };
1315
+ // 相等时,表示是新版本函数的场景
1316
+ if (idOrName.isInvokeByAPIName) {
1317
+ options.json.apiAlias = idOrName.APIName;
1318
+ options.json.function_name = '';
1319
+ }
1320
+ else {
1321
+ options.json.function_name = idOrName.APIId;
1322
+ options.json.apiAlias = '';
1323
+ }
1324
+ let res = await openapi.doRequest(null, urlPath, options);
1325
+ if (!res) {
1326
+ throw new exceptions.InternalError(`InvokeFuncSync result is empty`);
1327
+ }
1328
+ if (res && res.code === '0') {
1329
+ return res.data;
1330
+ }
1331
+ throw new exceptions.BaseError(res.code, res.msg);
1332
+ }
1333
+ async function createAsyncTaskV1(idOrName, params) {
1334
+ // attention: 异步任务接口存在先后区别,接口版本号不一致需 check,v1->v2
1335
+ let options = commonHttp.getOptions(null, openapiHttpPath.createAsyncTaskInnerAPIV2);
1336
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await (0, common_1.getNamespaceForOpenAndFaaSSDK)());
1337
+ options.headers.User = utils.getUserIDFromCtx();
1338
+ options.json = {
1339
+ 'params': JSON.stringify(params),
1340
+ 'context': JSON.stringify(getTriggerCtx()),
1341
+ 'triggerType': utils.getTriggerType(),
1342
+ };
1343
+ // 相等时,表示是新版本函数的场景
1344
+ if (idOrName.isInvokeByAPIName) {
1345
+ options.json.apiAlias = idOrName.APIName;
1346
+ options.json.function_name = ''; // required
1347
+ }
1348
+ else {
1349
+ options.json.function_name = idOrName.APIId;
1350
+ }
1351
+ let res = await openapi.doRequest(null, urlPath, options);
1352
+ if (res && res.task_id) {
1353
+ return res.task_id;
1354
+ }
1355
+ throw new exceptions.InternalError(`createAsyncTaskV1 result is empty`);
1356
+ }
1357
+ async function createAsyncTaskV2(APIName, params) {
1358
+ // attention: 异步任务接口存在先后区别,接口版本号不一致需 check,v2->v1
1359
+ let options = commonHttp.getOptions(null, openapiHttpPath.createAsyncTaskInnerAPIV1);
1360
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await (0, common_1.getNamespaceForOpenAndFaaSSDK)());
1361
+ let triggerCtx = {}, taskID = utils.getTriggerTaskID();
1362
+ if (taskID) {
1363
+ triggerCtx[constants_3.headers.triggerTaskId] = taskID;
1364
+ }
1365
+ let temp = utils.getDistributedHandleMask();
1366
+ if (temp) {
1367
+ triggerCtx[constants_3.headers.distributedHandleMask] = temp;
1368
+ }
1369
+ let reqCtx = nodeCls.get(constants_3.headers.loopCtxKey);
1370
+ if (checkLoopCtx(reqCtx)) {
1371
+ triggerCtx[constants_3.headers.loopMasks] = reqCtx.loopMasks;
1372
+ }
1373
+ options.headers.User = utils.getUserIDFromCtx();
1374
+ options.json = {
1375
+ 'apiAlias': APIName,
1376
+ 'params': JSON.stringify(params),
1377
+ 'context': JSON.stringify(getTriggerCtx()),
1378
+ 'triggerType': utils.getTriggerType(),
1379
+ 'extra': (0, common_1.getDebugExtraInfo)(),
1380
+ };
1381
+ let res = await openapi.doRequest(null, urlPath, options);
1382
+ if (res && res.task_id) {
1383
+ return res.task_id;
1384
+ }
1385
+ throw new exceptions.InternalError(`createAsyncTaskV2 result is empty`);
1386
+ }
1387
+ function checkLoopCtx(reqCtx) {
1388
+ return reqCtx && reqCtx.loopMasks && Array.isArray(reqCtx.loopMasks);
1389
+ }
1390
+ function getTriggerCtx() {
1391
+ let triggerCtx = {}, taskID = utils.getTriggerTaskID();
1392
+ if (taskID) {
1393
+ triggerCtx[constants_3.headers.triggerTaskId] = taskID;
1394
+ }
1395
+ let temp = utils.getDistributedHandleMask();
1396
+ if (temp) {
1397
+ triggerCtx[constants_3.headers.distributedHandleMask] = temp;
1398
+ }
1399
+ let reqCtx = nodeCls.get(constants_3.headers.loopCtxKey);
1400
+ if (checkLoopCtx(reqCtx)) {
1401
+ triggerCtx[constants_3.headers.loopMasks] = reqCtx.loopMasks;
1402
+ }
1403
+ return triggerCtx;
1404
+ }
1405
+ async function getExecutionUserTaskInfo(executionId) {
1406
+ if (!executionId) {
1407
+ throw new exceptions.InvalidParamError('executionId is empty');
1408
+ }
1409
+ let options = commonHttp.getOptions(null, constants_2.openapiHttpPath.getExecutionUserTaskInfo);
1410
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await (0, common_1.getNamespaceForOpenAndFaaSSDK)()).replace(replaceKeys.id, `${executionId}`);
1411
+ urlPath += `?operator=${utils.getUserIDFromCtx()}`;
1412
+ options.headers.User = utils.getUserIDFromCtx();
1413
+ let res = await openapi.doRequest(null, urlPath, options);
1414
+ if (!res) {
1415
+ throw new exceptions.InternalError('getExecutionUserTaskInfo result is empty');
1416
+ }
1417
+ return res.taskList;
1418
+ }
1419
+ exports.getExecutionUserTaskInfo = getExecutionUserTaskInfo;
1420
+ async function executeFlow(apiName, option, async) {
1421
+ if (!apiName) {
1422
+ throw new exceptions.InvalidParamError(`flow apiName is empty`);
1423
+ }
1424
+ let options = commonHttp.getOptions(null, constants_2.openapiHttpPath.executeFlow);
1425
+ const urlPath = options._reqPath.replace(replaceKeys.namespace, await (0, common_1.getNamespaceForOpenAndFaaSSDK)()).replace(replaceKeys.apiName, apiName);
1426
+ options.headers.User = utils.getUserIDFromCtx();
1427
+ options.json = {
1428
+ 'operator': utils.getUserIDFromCtx(),
1429
+ 'variables': (0, common_1.transMapToFlowVariable)(option.params),
1430
+ 'loopMasks': utils.getLoopMasks(),
1431
+ };
1432
+ if (async !== undefined) {
1433
+ options.json['async'] = async;
1434
+ }
1435
+ let res = await openapi.doRequest(null, urlPath, options);
1436
+ return {
1437
+ executionId: res.executionId,
1438
+ status: res.status,
1439
+ data: (0, common_1.transFlowVariableToMap)(res.outParams),
1440
+ errCode: res.errCode ? res.errCode : undefined,
1441
+ errMsg: res.errMsg ? res.errMsg : undefined,
1442
+ };
1443
+ }
1444
+ exports.executeFlow = executeFlow;
1445
+ async function revokeExecution(executionId, revokeOptions) {
1446
+ if (!executionId) {
1447
+ throw new exceptions.InvalidParamError(`executionId is empty`);
1448
+ }
1449
+ let options = commonHttp.getOptions(null, constants_2.openapiHttpPath.revokeExecution);
1450
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await (0, common_1.getNamespaceForOpenAndFaaSSDK)()).replace(replaceKeys.id, `${executionId}`);
1451
+ options.headers.User = utils.getUserIDFromCtx();
1452
+ let reason = undefined;
1453
+ if (revokeOptions && revokeOptions.reason) {
1454
+ reason = {
1455
+ en_US: revokeOptions.reason.en_US,
1456
+ zh_CN: revokeOptions.reason.zh_CN
1457
+ };
1458
+ }
1459
+ options.json = {
1460
+ 'operator': utils.getUserIDFromCtx(),
1461
+ reason,
1462
+ };
1463
+ return await openapi.doRequest(null, urlPath, options);
1464
+ }
1465
+ exports.revokeExecution = revokeExecution;
1466
+ async function getExecutionInfo(executionId) {
1467
+ if (!executionId) {
1468
+ throw new exceptions.InvalidParamError(`executionId is empty`);
1469
+ }
1470
+ let options = commonHttp.getOptions(null, constants_2.openapiHttpPath.getExecutionInfo);
1471
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await (0, common_1.getNamespaceForOpenAndFaaSSDK)()).replace(replaceKeys.id, `${executionId}`);
1472
+ urlPath += `?operator=${utils.getUserIDFromCtx()}`;
1473
+ options.headers.User = utils.getUserIDFromCtx();
1474
+ let res = await openapi.doRequest(null, urlPath, options);
1475
+ if (!res || !res.executionInfo) {
1476
+ throw new exceptions.InternalError(`getExecutionInfo result is empty`);
1477
+ }
1478
+ return {
1479
+ status: res.executionInfo.status,
1480
+ data: (0, common_1.transFlowVariableToMap)(res.executionInfo.outParams),
1481
+ errCode: res.executionInfo.errCode ? res.executionInfo.errCode : undefined,
1482
+ errMsg: res.executionInfo.errMsg ? res.executionInfo.errMsg : undefined,
1483
+ };
1484
+ }
1485
+ exports.getExecutionInfo = getExecutionInfo;
1486
+ async function getIntegrationAppAccessToken(apiName) {
1487
+ // 1.check
1488
+ if (!apiName) {
1489
+ throw new exceptions.InvalidParamError('apiName is empty');
1490
+ }
1491
+ let options = commonHttp.getOptions(null, openapiHttpPath.getIntegrationAppAccessTokenAPI);
1492
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await (0, common_1.getNamespaceForOpenAndFaaSSDK)()).replace(replaceKeys.apiName, `${apiName}`);
1493
+ let res = await openapi.doRequest(null, urlPath, options);
1494
+ return {
1495
+ expire: res.expire,
1496
+ appAccessToken: res.appAccessToken,
1497
+ appId: res.appId,
1498
+ };
1499
+ }
1500
+ async function getIntegrationTenantAccessToken(apiName) {
1501
+ // 1.check
1502
+ if (!apiName) {
1503
+ throw new exceptions.InvalidParamError('apiName is empty');
1504
+ }
1505
+ let options = commonHttp.getOptions(null, openapiHttpPath.getIntegrationTenantAccessTokenAPI);
1506
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await (0, common_1.getNamespaceForOpenAndFaaSSDK)()).replace(replaceKeys.apiName, `${apiName}`);
1507
+ let res = await openapi.doRequest(null, urlPath, options);
1508
+ return {
1509
+ expire: res.expire,
1510
+ tenantAccessToken: res.tenantAccessToken,
1511
+ appId: res.appId,
1512
+ };
1513
+ }
1514
+ async function getDefaultIntegrationAppAccessToken() {
1515
+ let options = commonHttp.getOptions(null, openapiHttpPath.getDefaultIntegrationAppAccessTokenAPI);
1516
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await (0, common_1.getNamespaceForOpenAndFaaSSDK)());
1517
+ let res = await openapi.doRequest(null, urlPath, options);
1518
+ return {
1519
+ expire: res.expire,
1520
+ appAccessToken: res.appAccessToken,
1521
+ appId: res.appId,
1522
+ };
1523
+ }
1524
+ async function getDefaultIntegrationTenantAccessToken() {
1525
+ let options = commonHttp.getOptions(null, openapiHttpPath.getDefaultIntegrationTenantAccessTokenAPI);
1526
+ let urlPath = options._reqPath.replace(replaceKeys.namespace, await (0, common_1.getNamespaceForOpenAndFaaSSDK)());
1527
+ let res = await openapi.doRequest(null, urlPath, options);
1528
+ return {
1529
+ expire: res.expire,
1530
+ tenantAccessToken: res.tenantAccessToken,
1531
+ appId: res.appId,
1532
+ };
1533
+ }