@byted-apaas/server-sdk-node 1.1.11 → 1.1.12-beta.13

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 (122) hide show
  1. package/application/application.js +0 -1
  2. package/application/function/function.js +0 -1
  3. package/application/impl/common.js +0 -1
  4. package/application/impl/impl.js +0 -1
  5. package/common/structs.js +0 -1
  6. package/constants/constants.js +0 -1
  7. package/context/context.js +0 -1
  8. package/context/db/db.js +0 -1
  9. package/context/db/impl/IObject.js +0 -1
  10. package/context/db/impl/db.js +0 -1
  11. package/context/db/impl/object.js +0 -1
  12. package/context/db/impl/oql/ioql.js +0 -1
  13. package/context/db/impl/oql/oql.js +0 -1
  14. package/context/db/impl/order.js +0 -1
  15. package/context/db/impl/propertiesStore.js +0 -1
  16. package/context/db/impl/queryBuilder.js +0 -1
  17. package/context/db/impl/transaction/index.js +0 -1
  18. package/context/db/impl/transaction/operation.js +0 -1
  19. package/context/db/impl/transaction.js +0 -1
  20. package/context/globalConfig/globalConfig.js +0 -1
  21. package/context/integration/IIntegration.js +0 -1
  22. package/context/integration/impl/integration.js +0 -1
  23. package/context/metadata/components/common.js +0 -1
  24. package/context/metadata/components/components.js +0 -1
  25. package/context/metadata/components/desktop/list.js +0 -1
  26. package/context/metadata/components/desktop/recordDetail.js +0 -1
  27. package/context/metadata/components/mobile/list.js +0 -1
  28. package/context/metadata/metadata.js +0 -1
  29. package/context/metadata/objects/fields.js +0 -1
  30. package/context/metadata/objects/fields.util.js +0 -1
  31. package/context/metadata/objects/objects.js +0 -1
  32. package/context/metadata/types/common.js +0 -1
  33. package/context/metadata/types/components.js +0 -1
  34. package/context/metadata/types/objects.js +0 -1
  35. package/context/msg/msg.js +0 -1
  36. package/context/resources/IResources.js +0 -1
  37. package/context/resources/impl/resources.js +0 -1
  38. package/context/tasks/tasks.js +0 -1
  39. package/data/index.js +0 -1
  40. package/global/application/flow/flow.js +0 -1
  41. package/global/application/globalVar/globalVar.js +0 -1
  42. package/global/global.js +0 -1
  43. package/hooks/api.js +0 -1
  44. package/hooks/hooks.js +0 -1
  45. package/kunlun/kunlun.js +0 -1
  46. package/kunlun/operator/IOperator.js +0 -1
  47. package/kunlun/operator/impl/expression.js +0 -1
  48. package/kunlun/operator/impl/logic.js +0 -1
  49. package/kunlun/operator/impl/logicV2.js +0 -1
  50. package/kunlun/operator/impl/operator.js +0 -1
  51. package/kunlun/operator/impl/operatorV2.js +0 -1
  52. package/lib/core.js +0 -1
  53. package/package.json +4 -3
  54. package/request/common.js +0 -1
  55. package/request/constants.js +0 -1
  56. package/request/faasinfra.js +0 -1
  57. package/request/interface.js +4 -16
  58. package/request/openapi.js +0 -1
  59. package/types/types.js +0 -1
  60. package/version/version.d.ts +2 -0
  61. package/version/version.js +8 -0
  62. package/application/application.js.map +0 -1
  63. package/application/function/function.js.map +0 -1
  64. package/application/impl/common.js.map +0 -1
  65. package/application/impl/impl.js.map +0 -1
  66. package/common/structs.js.map +0 -1
  67. package/constants/constants.js.map +0 -1
  68. package/context/context.js.map +0 -1
  69. package/context/db/db.js.map +0 -1
  70. package/context/db/impl/IObject.js.map +0 -1
  71. package/context/db/impl/db.js.map +0 -1
  72. package/context/db/impl/object.js.map +0 -1
  73. package/context/db/impl/oql/ioql.js.map +0 -1
  74. package/context/db/impl/oql/oql.js.map +0 -1
  75. package/context/db/impl/order.js.map +0 -1
  76. package/context/db/impl/propertiesStore.js.map +0 -1
  77. package/context/db/impl/queryBuilder.js.map +0 -1
  78. package/context/db/impl/transaction/index.js.map +0 -1
  79. package/context/db/impl/transaction/operation.js.map +0 -1
  80. package/context/db/impl/transaction.js.map +0 -1
  81. package/context/globalConfig/globalConfig.js.map +0 -1
  82. package/context/integration/IIntegration.js.map +0 -1
  83. package/context/integration/impl/integration.js.map +0 -1
  84. package/context/metadata/components/common.js.map +0 -1
  85. package/context/metadata/components/components.js.map +0 -1
  86. package/context/metadata/components/desktop/list.js.map +0 -1
  87. package/context/metadata/components/desktop/recordDetail.js.map +0 -1
  88. package/context/metadata/components/mobile/list.js.map +0 -1
  89. package/context/metadata/metadata.js.map +0 -1
  90. package/context/metadata/objects/fields.js.map +0 -1
  91. package/context/metadata/objects/fields.util.js.map +0 -1
  92. package/context/metadata/objects/objects.js.map +0 -1
  93. package/context/metadata/types/common.js.map +0 -1
  94. package/context/metadata/types/components.js.map +0 -1
  95. package/context/metadata/types/objects.js.map +0 -1
  96. package/context/msg/msg.js.map +0 -1
  97. package/context/resources/IResources.js.map +0 -1
  98. package/context/resources/impl/resources.js.map +0 -1
  99. package/context/tasks/tasks.js.map +0 -1
  100. package/data/index.js.map +0 -1
  101. package/global/application/flow/flow.js.map +0 -1
  102. package/global/application/globalVar/globalVar.js.map +0 -1
  103. package/global/global.js.map +0 -1
  104. package/hooks/api.js.map +0 -1
  105. package/hooks/hooks.js.map +0 -1
  106. package/kunlun/kunlun.js.map +0 -1
  107. package/kunlun/operator/IOperator.js.map +0 -1
  108. package/kunlun/operator/impl/expression.js.map +0 -1
  109. package/kunlun/operator/impl/logic.js.map +0 -1
  110. package/kunlun/operator/impl/logicV2.js.map +0 -1
  111. package/kunlun/operator/impl/operator.js.map +0 -1
  112. package/kunlun/operator/impl/operatorV2.js.map +0 -1
  113. package/lib/core.js.map +0 -1
  114. package/request/common.js.map +0 -1
  115. package/request/constants.js.map +0 -1
  116. package/request/faasinfra.js.map +0 -1
  117. package/request/innerapi.d.ts +0 -72
  118. package/request/innerapi.js +0 -1595
  119. package/request/innerapi.js.map +0 -1
  120. package/request/interface.js.map +0 -1
  121. package/request/openapi.js.map +0 -1
  122. package/types/types.js.map +0 -1
@@ -1,1595 +0,0 @@
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.getExecutionUserTaskInfo = exports.getExecutionInfo = exports.revokeExecution = exports.RequestRpc = void 0;
6
- const common = require("@byted-apaas/server-common-node");
7
- const stream_to_buffer_1 = require("@jorgeferrero/stream-to-buffer");
8
- const constants_1 = require("../constants/constants");
9
- const common_1 = require("./common");
10
- const exceptions_1 = require("@byted-apaas/server-common-node/utils/exceptions");
11
- const fs = require("fs");
12
- const path = require("path");
13
- const permissionUtils = require("@byted-apaas/server-common-node/utils/permissionUtils");
14
- const constants_2 = require("@byted-apaas/server-common-node/constants/constants");
15
- const utils_1 = require("@byted-apaas/server-common-node/utils/utils");
16
- const rpc = common.rpc;
17
- const exceptions = common.exceptions;
18
- const utils = common.utils;
19
- const checkUtils = common.checkUtils;
20
- async function pre(isTransUser, authType) {
21
- let ctx;
22
- try {
23
- ctx = await rpc.rebuildRpcCtx(isTransUser, authType);
24
- }
25
- catch (err) {
26
- throw new exceptions.InternalError(`RebuildRpcCtx failed: ${err.message}: ${err.stack}`);
27
- }
28
- return ctx;
29
- }
30
- function post(baseResp) {
31
- if (!baseResp) {
32
- throw new exceptions.InternalError(`Call InnerAPI resp is empty`);
33
- }
34
- if (baseResp.KStatusCode !== '') {
35
- let code = baseResp.KStatusCode;
36
- let msg = baseResp.KStatusMessage;
37
- if (baseResp.StatusMessage !== '') {
38
- msg = baseResp.StatusMessage;
39
- }
40
- throw new exceptions.BaseError(code, msg);
41
- }
42
- }
43
- async function createRecordBySync(objectApiName, record, authType) {
44
- // 1.check
45
- if (!objectApiName) {
46
- throw new exceptions.InvalidParamError('objectApiName is empty');
47
- }
48
- // 2.前置处理
49
- authType = (0, utils_1.formatAuthType)(authType);
50
- let ctx = await pre(true, authType);
51
- // 3.构造 params
52
- let param = {};
53
- let task_id = utils.getTriggerTaskID();
54
- param.Namespace = await (0, common_1.getNamespaceForOpenAndFaaSSDK)();
55
- param.ObjectAPIAlias = objectApiName;
56
- param.Data = utils.stringify(record);
57
- param.Operator = BigInt(utils.getUserIDFromCtx());
58
- if (task_id) {
59
- param.TaskID = BigInt(task_id);
60
- }
61
- // 4.发起请求
62
- let resp;
63
- try {
64
- resp = await rpc.getInnerAPICli().CreateRecordBySync(ctx, param);
65
- }
66
- catch (err) {
67
- throw new exceptions.InternalError(`Call InnerAPI failed: ${err.message}`);
68
- }
69
- // 5.后置处理
70
- post(resp.BaseResp);
71
- return { _id: Number(resp.RecordID) };
72
- }
73
- async function updateRecordBySync(objectApiName, recordID, record, authType) {
74
- // 1.check
75
- if (!objectApiName) {
76
- throw new exceptions.InvalidParamError('objectApiName is empty');
77
- }
78
- // 2.前置处理
79
- authType = (0, utils_1.formatAuthType)(authType);
80
- let ctx = await pre(true, authType);
81
- // 3.构造 params
82
- let param = {};
83
- let task_id = utils.getTriggerTaskID();
84
- param.Namespace = await (0, common_1.getNamespaceForOpenAndFaaSSDK)();
85
- param.ObjectAPIAlias = objectApiName;
86
- param.RecordID = BigInt(recordID);
87
- param.Data = utils.stringify(record);
88
- param.Operator = BigInt(utils.getUserIDFromCtx());
89
- if (task_id) {
90
- param.TaskID = BigInt(task_id);
91
- }
92
- // 4.发起请求
93
- let resp;
94
- try {
95
- resp = await rpc.getInnerAPICli().UpdateRecordBySync(ctx, param);
96
- }
97
- catch (err) {
98
- throw new exceptions.InternalError(`Call InnerAPI failed: ${err.message}`);
99
- }
100
- // 5.后置处理
101
- post(resp.BaseResp);
102
- return;
103
- }
104
- async function deleteRecordBySync(objectApiName, recordID, authType) {
105
- // 1.check
106
- if (!objectApiName) {
107
- throw new exceptions.InvalidParamError('objectApiName is empty');
108
- }
109
- // 2.前置处理
110
- authType = (0, utils_1.formatAuthType)(authType);
111
- let ctx = await pre(true, authType);
112
- // 3.构造 params
113
- let param = {};
114
- let task_id = utils.getTriggerTaskID();
115
- param.Namespace = await (0, common_1.getNamespaceForOpenAndFaaSSDK)();
116
- param.ObjectAPIAlias = objectApiName;
117
- param.RecordID = BigInt(recordID);
118
- param.Operator = BigInt(utils.getUserIDFromCtx());
119
- if (task_id) {
120
- param.TaskID = BigInt(task_id);
121
- }
122
- // 4.发起请求
123
- let resp;
124
- try {
125
- resp = await rpc.getInnerAPICli().DeleteRecordBySync(ctx, param);
126
- }
127
- catch (err) {
128
- throw new exceptions.InternalError(`Call InnerAPI failed: ${err.message}`);
129
- }
130
- // 5.后置处理
131
- post(resp.BaseResp);
132
- return;
133
- }
134
- async function createRecordsByAsync(objectApiName, records, authType) {
135
- // 1.check
136
- if (!objectApiName) {
137
- throw new exceptions.InvalidParamError('objectApiName is empty');
138
- }
139
- // 2.前置处理
140
- authType = (0, utils_1.formatAuthType)(authType);
141
- let ctx = await pre(true, authType);
142
- // 3.构造 params
143
- let param = {};
144
- let task_id = utils.getTriggerTaskID();
145
- param.Namespace = await (0, common_1.getNamespaceForOpenAndFaaSSDK)();
146
- param.ObjectAPIAlias = objectApiName;
147
- param.Data = utils.stringify(records);
148
- param.OperatorID = BigInt(utils.getUserIDFromCtx());
149
- if (task_id) {
150
- param.AutomationTaskID = BigInt(task_id);
151
- }
152
- // 4.发起请求
153
- let resp;
154
- try {
155
- resp = await rpc.getInnerAPICli().BatchCreateRecordByAsync(ctx, param);
156
- }
157
- catch (err) {
158
- throw new exceptions.InternalError(`Call InnerAPI failed: ${err.message}`);
159
- }
160
- // 5.后置处理
161
- post(resp.BaseResp);
162
- return { taskID: Number(resp.TaskID) };
163
- }
164
- async function updateRecordsByAsync(objectApiName, recordMap, authType) {
165
- // 1.check
166
- if (!objectApiName) {
167
- throw new exceptions.InvalidParamError('objectApiName is empty');
168
- }
169
- // 2.前置处理
170
- authType = (0, utils_1.formatAuthType)(authType);
171
- let ctx = await pre(true, authType);
172
- // 3.构造 params
173
- let param = {};
174
- let task_id = utils.getTriggerTaskID();
175
- param.Namespace = await (0, common_1.getNamespaceForOpenAndFaaSSDK)();
176
- param.ObjectAPIAlias = objectApiName;
177
- param.Data = utils.stringify(recordMap);
178
- param.OperatorID = BigInt(utils.getUserIDFromCtx());
179
- if (task_id) {
180
- param.AutomationTaskID = BigInt(task_id);
181
- }
182
- // 4.发起请求
183
- let resp;
184
- try {
185
- resp = await rpc.getInnerAPICli().BatchUpdateRecordByAsync(ctx, param);
186
- }
187
- catch (err) {
188
- throw new exceptions.InternalError(`Call InnerAPI failed: ${err.message}`);
189
- }
190
- // 5.后置处理
191
- post(resp.BaseResp);
192
- return { taskID: Number(resp.TaskID) };
193
- }
194
- async function deleteRecordsByAsync(objectApiName, recordIDs, authType) {
195
- // 1.check
196
- if (!objectApiName) {
197
- throw new exceptions.InvalidParamError('objectApiName is empty');
198
- }
199
- // 2.前置处理
200
- authType = (0, utils_1.formatAuthType)(authType);
201
- let ctx = await pre(true, authType);
202
- // 3.构造 params
203
- let param = {};
204
- let task_id = utils.getTriggerTaskID();
205
- let recordIDList = new Array();
206
- recordIDs.forEach((v, idx) => {
207
- recordIDList.push(BigInt(v));
208
- });
209
- param.Namespace = await (0, common_1.getNamespaceForOpenAndFaaSSDK)();
210
- param.ObjectAPIAlias = objectApiName;
211
- param.RecordIDList = recordIDList;
212
- param.OperatorID = BigInt(utils.getUserIDFromCtx());
213
- if (task_id) {
214
- param.AutomationTaskID = BigInt(task_id);
215
- }
216
- // 4.发起请求
217
- let resp;
218
- try {
219
- resp = await rpc.getInnerAPICli().BatchDeleteRecordByAsync(ctx, param);
220
- }
221
- catch (err) {
222
- throw new exceptions.InternalError(`Call InnerAPI failed: ${err.message}`);
223
- }
224
- // 5.后置处理
225
- post(resp.BaseResp);
226
- return { taskID: Number(resp.TaskID) };
227
- }
228
- async function createRecordsBySync(objectApiName, records, authType) {
229
- // 1.check
230
- if (!objectApiName) {
231
- throw new exceptions.InvalidParamError('objectApiName is empty');
232
- }
233
- // 2.前置处理
234
- authType = (0, utils_1.formatAuthType)(authType);
235
- let ctx = await pre(true, authType);
236
- // 3.构造 params
237
- let param = {};
238
- let task_id = utils.getTriggerTaskID();
239
- param.Namespace = await (0, common_1.getNamespaceForOpenAndFaaSSDK)();
240
- param.ObjectAPIAlias = objectApiName;
241
- param.Data = utils.stringify(records);
242
- param.OperatorID = BigInt(utils.getUserIDFromCtx());
243
- param.SetSystemField = 2;
244
- if (task_id) {
245
- param.AutomationTaskID = BigInt(task_id);
246
- }
247
- // 4.发起请求
248
- let resp;
249
- try {
250
- resp = await rpc.getInnerAPICli().BatchCreateRecordBySync(ctx, param);
251
- }
252
- catch (err) {
253
- throw new exceptions.InternalError(`Call InnerAPI failed: ${err.message}`);
254
- }
255
- // 5.后置处理
256
- post(resp.BaseResp);
257
- let recordIDList = new Array();
258
- const errMap = {};
259
- resp.RecordIDs.forEach((v, idx) => {
260
- recordIDList.push(Number(v));
261
- });
262
- resp.ErrMap.forEach((v, k) => {
263
- errMap[Number(k)] = v;
264
- });
265
- return {
266
- record_ids: recordIDList,
267
- err_map: errMap
268
- };
269
- }
270
- async function updateRecordsBySync(objectApiName, recordMap, authType) {
271
- // 1.check
272
- if (!objectApiName) {
273
- throw new exceptions.InvalidParamError('objectApiName is empty');
274
- }
275
- // 2.前置处理
276
- authType = (0, utils_1.formatAuthType)(authType);
277
- let ctx = await pre(true, authType);
278
- // 3.构造 params
279
- let param = {};
280
- let task_id = utils.getTriggerTaskID();
281
- param.Namespace = await (0, common_1.getNamespaceForOpenAndFaaSSDK)();
282
- param.ObjectAPIAlias = objectApiName;
283
- param.Data = utils.stringify(recordMap);
284
- param.OperatorID = BigInt(utils.getUserIDFromCtx());
285
- param.SetSystemField = 2;
286
- if (task_id) {
287
- param.AutomationTaskID = BigInt(task_id);
288
- }
289
- // 4.发起请求
290
- let resp;
291
- try {
292
- resp = await rpc.getInnerAPICli().BatchUpdateRecordBySync(ctx, param);
293
- }
294
- catch (err) {
295
- throw new exceptions.InternalError(`Call InnerAPI failed: ${err.message}`);
296
- }
297
- // 5.后置处理
298
- post(resp.BaseResp);
299
- if (!resp || !resp.ErrMap) {
300
- return undefined;
301
- }
302
- const errMap = {};
303
- resp.ErrMap.forEach((v, k) => {
304
- errMap[Number(k)] = v;
305
- });
306
- return errMap;
307
- }
308
- async function deleteRecordsBySync(objectApiName, recordIDs, authType) {
309
- // 1.check
310
- if (!objectApiName) {
311
- throw new exceptions.InvalidParamError('objectApiName is empty');
312
- }
313
- // 2.前置处理
314
- authType = (0, utils_1.formatAuthType)(authType);
315
- let ctx = await pre(true, authType);
316
- // 3.构造 params
317
- let param = {};
318
- let task_id = utils.getTriggerTaskID();
319
- let recordIDList = new Array();
320
- recordIDs.forEach((v, idx) => {
321
- recordIDList.push(BigInt(v));
322
- });
323
- param.Namespace = await (0, common_1.getNamespaceForOpenAndFaaSSDK)();
324
- param.ObjectAPIAlias = objectApiName;
325
- param.RecordIDs = recordIDList;
326
- param.OperatorID = BigInt(utils.getUserIDFromCtx());
327
- param.SetSystemField = 2;
328
- if (task_id) {
329
- param.AutomationTaskID = BigInt(task_id);
330
- }
331
- // 4.发起请求
332
- let resp;
333
- try {
334
- resp = await rpc.getInnerAPICli().BatchDeleteRecordBySync(ctx, param);
335
- }
336
- catch (err) {
337
- throw new exceptions.InternalError(`Call InnerAPI failed: ${err.message}`);
338
- }
339
- // 5.后置处理
340
- post(resp.BaseResp);
341
- if (!resp || !resp.ErrMap) {
342
- return undefined;
343
- }
344
- const errMap = {};
345
- resp.ErrMap.forEach((v, k) => {
346
- errMap[Number(k)] = v;
347
- });
348
- return errMap;
349
- }
350
- async function getRecordsOrCountByCriterion(objectApiName, criterion, fuzzySearch, order, ignoreBackLookupField, fieldApiNames, offset, limit, needCount, authType) {
351
- // 1.check
352
- if (!objectApiName) {
353
- throw new exceptions.InvalidParamError('objectApiName is empty');
354
- }
355
- // 2.前置处理
356
- authType = (0, utils_1.formatAuthType)(authType);
357
- let ctx = await pre(true, authType);
358
- // 3.构造 params
359
- let param = {};
360
- let orders = new Array();
361
- order.forEach((v, idx) => {
362
- orders.push({
363
- field: v.field,
364
- type: v.type,
365
- direction: v.direction,
366
- });
367
- });
368
- param.Namespace = await (0, common_1.getNamespaceForOpenAndFaaSSDK)();
369
- param.ObjectAPIAlias = objectApiName;
370
- param.Criterion = criterion;
371
- param.Order = orders;
372
- param.IgnoreBackLookupField = ignoreBackLookupField;
373
- param.Limit = BigInt(limit);
374
- param.offset = BigInt(offset);
375
- param.FieldAPIAPIAliases = fieldApiNames;
376
- param.NeedFilterUserPermission = false;
377
- param.NeedTotalCount = needCount;
378
- param.FuzzySearch = fuzzySearch;
379
- // 只返回 slice 结果,使用 SliceResult
380
- // 只返回 map 结果,使用 MapResult
381
- // 分不清场景可以用 BothResult,性能较差,建议区分场景
382
- // 0 表示不返回 unauth field 任何数据; 1 表示两者都返回;2 表示仅返回 slice;3 表示仅返回 map
383
- param.ProcessAuthFieldType = 2;
384
- // 4.发起请求
385
- let resp;
386
- try {
387
- resp = await rpc.getInnerAPICli().BatchGetRecordWithCriterionV3(ctx, param);
388
- }
389
- catch (err) {
390
- throw new exceptions.InternalError(`Call InnerAPI failed: ${err.message}`);
391
- }
392
- // 5.后置处理
393
- post(resp.BaseResp);
394
- if (needCount) {
395
- return Number(resp.Total);
396
- }
397
- else {
398
- const records = JSON.parse(resp.DataList);
399
- if (resp.UnauthPermissionInfo && resp.UnauthPermissionInfo.unauth_field_slice) {
400
- permissionUtils.appendUnauthFieldRecordList(objectApiName, records, resp.UnauthPermissionInfo.unauth_field_slice, true);
401
- }
402
- return records;
403
- }
404
- }
405
- async function updateWorkflowVariables(iCtx, instanceId, variables, variableTypes) {
406
- // 1.前置处理
407
- let ctx = await pre();
408
- // 2.构造 params
409
- let param = {};
410
- param.NameSpace = await (0, common_1.getNamespaceForOpenAndFaaSSDK)();
411
- param.WorkflowInstanceID = BigInt(instanceId);
412
- param.Variables = variables;
413
- // 3.发起请求
414
- let resp;
415
- try {
416
- resp = await rpc.getInnerAPICli().UpdateVariablesByAPIAlias(ctx, param);
417
- }
418
- catch (err) {
419
- throw new exceptions.InternalError(`Call InnerAPI failed: ${err.message}`);
420
- }
421
- // 4.后置处理
422
- post(resp.BaseResp);
423
- return;
424
- }
425
- async function uploadFile(data, expire, fileName) {
426
- // 1.前置处理
427
- let ctx = await pre();
428
- // 2.构造 params
429
- let param = {};
430
- param.Data = await (0, stream_to_buffer_1.streamToBuffer)(data);
431
- param.Name = 'file';
432
- if (fileName) {
433
- param.Name = fileName;
434
- }
435
- param.EncryptType = 1;
436
- param.PermissionConf = {
437
- PermissionType: '',
438
- PermissionInfo: '',
439
- IgnoreUserID: true
440
- };
441
- if (expire) {
442
- param.ExpireSecond = expire;
443
- }
444
- // 3.发起请求
445
- let resp;
446
- try {
447
- resp = await rpc.getInnerAPICli().UploadAttachmentForRPC(ctx, param);
448
- }
449
- catch (err) {
450
- throw new exceptions.InternalError(`Call InnerAPI failed: ${err.message}`);
451
- }
452
- // 4.后置处理
453
- post(resp.BaseResp);
454
- return {
455
- id: resp.ID,
456
- token: resp.Token,
457
- size: resp.Size,
458
- mime_type: resp.MimeType,
459
- name: resp.Filename,
460
- };
461
- }
462
- async function downloadFileByID(fileID, filePath) {
463
- // 1. build parameters
464
- let param = {};
465
- param.FileID = fileID;
466
- // 2. prepare request
467
- let ctx = await pre();
468
- // 3. do request
469
- let resp;
470
- try {
471
- resp = await rpc.getInnerAPICli().DownloadFile(ctx, param);
472
- }
473
- catch (err) {
474
- throw new exceptions.InternalError(`Call InnerAPI failed: ${err.message}`);
475
- }
476
- // 4. deal with response
477
- post(resp.BaseResp);
478
- if (filePath) {
479
- checkUtils.checkFile(filePath);
480
- utils.mkdirs(path.dirname(filePath));
481
- fs.writeFileSync(filePath, resp.Data);
482
- return undefined;
483
- }
484
- else {
485
- return resp.Data;
486
- }
487
- }
488
- async function downloadFileByToken(fileToken, filePath) {
489
- // 1. build parameters
490
- let param = {};
491
- param.Token = fileToken;
492
- // 2. prepare request
493
- let ctx = await pre();
494
- // 3. do request
495
- let resp;
496
- try {
497
- resp = await rpc.getInnerAPICli().DownloadAttachment(ctx, param);
498
- }
499
- catch (err) {
500
- throw new exceptions.InternalError(`Call InnerAPI failed: ${err.message}`);
501
- }
502
- // 4. deal with response
503
- post(resp.BaseResp);
504
- if (filePath) {
505
- checkUtils.checkFile(filePath);
506
- utils.mkdirs(path.dirname(filePath));
507
- fs.writeFileSync(filePath, resp.Data);
508
- return undefined;
509
- }
510
- else {
511
- return resp.Data;
512
- }
513
- }
514
- async function mGetFileToken(ids) {
515
- // 1. params
516
- let param = {};
517
- param.AttachmentIDs = ids;
518
- // 2. prepare request
519
- let ctx = await pre();
520
- // 3. do request
521
- let resp;
522
- try {
523
- resp = await rpc.getInnerAPICli().GetAttachmentTokens(ctx, param);
524
- }
525
- catch (err) {
526
- throw new exceptions.InternalError(`Call InnerAPI failed: ${err.message}`);
527
- }
528
- return resp.Tokens;
529
- }
530
- async function createMessage(msg) {
531
- // 1. prepare args
532
- if (!msg.icon) {
533
- throw new exceptions.InvalidParamError(`parameter icon is required!`);
534
- }
535
- if (typeof (msg.icon) !== 'string') {
536
- throw new exceptions.InvalidParamError(`Invalid format of parameter icon, icon should be string.`);
537
- }
538
- let params = {};
539
- const modelKeySearchData = new Map().set('icon_type', msg.icon);
540
- const receiverIds = msg.target_users || [];
541
- if (!(receiverIds instanceof Array)) {
542
- throw new exceptions.InvalidParamError(`Invalid format of parameter target_users, target_users should be array.`);
543
- }
544
- if (receiverIds.length === 0) {
545
- throw new exceptions.InvalidParamError(`parameter target_users is required!`);
546
- }
547
- const percent = msg.percent;
548
- if (percent !== undefined && percent !== null) {
549
- if (typeof (percent) !== 'number') {
550
- throw new exceptions.InvalidParamError(`Invalid format of parameter percent, percent should be number.`);
551
- }
552
- if (percent < 0 || percent > 100) {
553
- throw new exceptions.InvalidParamError(`Invalid value of parameter percent, the value should be in range [0, 100].`);
554
- }
555
- else {
556
- modelKeySearchData.set('percent', JSON.stringify(percent));
557
- }
558
- }
559
- // kunlun类型
560
- if (common.checkUtils.isObject(msg)) {
561
- for (let key of Object.keys(msg)) {
562
- if (common.fieldType.isKFieldType(msg[key])) {
563
- // instanceof 改动6
564
- // if (msg[key] instanceof fieldType.Multilingual) {
565
- if (common.fieldType.isKFieldTypeMultilingual((msg[key]))) {
566
- let value = JSON.stringify(msg[key].toJSON());
567
- params[key] = JSON.stringify({ value });
568
- }
569
- else {
570
- params[key] = JSON.stringify(msg[key].toJSON());
571
- }
572
- }
573
- else {
574
- params[key] = JSON.stringify(msg[key]);
575
- }
576
- }
577
- }
578
- // 2. prepare for request
579
- let ctx = await pre();
580
- // 3. build parameters
581
- let param = {};
582
- param.NameSpace = await (0, common_1.getNamespaceForOpenAndFaaSSDK)();
583
- param.NotifyModelKey = constants_1.notifyModel.key;
584
- param.ReceiverIDs = receiverIds;
585
- param.ParamsRawData = params;
586
- param.Percent = percent;
587
- param.ModelKeySearchData = modelKeySearchData;
588
- // 4. do request
589
- let resp;
590
- try {
591
- resp = await rpc.getInnerAPICli().CreateNotifyTask(ctx, param);
592
- }
593
- catch (err) {
594
- throw new exceptions.InternalError(`Call InnerAPI failed: ${err.message}`);
595
- }
596
- // 5. deal with response
597
- post(resp.BaseResp);
598
- return Number(resp.TaskID);
599
- }
600
- async function updateMessage(msgId, msg) {
601
- // 1. prepare args
602
- if (!msgId) {
603
- throw new exceptions.InvalidParamError(`parameter msgId is required!`);
604
- }
605
- if (typeof (msgId) != 'number') {
606
- throw new exceptions.InvalidParamError(`Invalid format of parameter msgId, msgId should be number.`);
607
- }
608
- if (!msg.icon) {
609
- throw new exceptions.InvalidParamError(`parameter icon is required!`);
610
- }
611
- if (typeof (msg.icon) != 'string') {
612
- throw new exceptions.InvalidParamError(`Invalid format of parameter icon, icon should be string.`);
613
- }
614
- let params = new Map();
615
- const modelKeySearchData = new Map().set('icon_type', msg.icon);
616
- const percent = msg.percent;
617
- if (percent !== undefined && percent !== null) {
618
- if (typeof (percent) !== 'number') {
619
- throw new exceptions.InvalidParamError(`Invalid format of parameter percent, percent should be number.`);
620
- }
621
- if (percent < 0 || percent > 100) {
622
- throw new exceptions.InvalidParamError(`Invalid value of parameter percent in message ${msgId}, the value should be in range [0, 100].`);
623
- }
624
- else {
625
- modelKeySearchData.set('percent', JSON.stringify(percent));
626
- }
627
- }
628
- // kunlun类型
629
- if (common.checkUtils.isObject(msg)) {
630
- for (let key of Object.keys(msg)) {
631
- if (common.fieldType.isKFieldType(msg[key])) {
632
- // instanceof 改动7
633
- // if (msg[key] instanceof fieldType.Multilingual) {
634
- if (common.fieldType.isKFieldTypeMultilingual(msg[key])) {
635
- let value = JSON.stringify(msg[key].toJSON());
636
- params.set(key, JSON.stringify({ value }));
637
- }
638
- else {
639
- params.set(key, JSON.stringify(msg[key].toJSON()));
640
- }
641
- }
642
- else {
643
- params.set(key, JSON.stringify(msg[key]));
644
- }
645
- }
646
- }
647
- // 2. prepare for request
648
- let ctx = await pre();
649
- // 3. build parameters
650
- let param = {};
651
- param.NameSpace = await (0, common_1.getNamespaceForOpenAndFaaSSDK)();
652
- param.TaskID = BigInt(msgId);
653
- param.NotifyModelKey = constants_1.notifyModel.key;
654
- param.ParamsRawData = params;
655
- param.Percent = percent;
656
- param.ModelKeySearchData = modelKeySearchData;
657
- param.IsBackground = true;
658
- // 4. do request
659
- let resp;
660
- try {
661
- resp = await rpc.getInnerAPICli().UpdateNotifyTask(ctx, param);
662
- }
663
- catch (err) {
664
- throw new exceptions.InternalError(`Call InnerAPI failed: ${err.message}`);
665
- }
666
- // 5. deal with response
667
- post(resp.BaseResp);
668
- }
669
- async function getFields(objectApiName) {
670
- // 1. prepare request
671
- let ctx = await pre();
672
- // 2. build parameters
673
- let param = {};
674
- param.Namespace = await (0, common_1.getNamespaceForOpenAndFaaSSDK)();
675
- param.ObjectAPIName = objectApiName;
676
- // 3. do request
677
- let resp;
678
- try {
679
- resp = await rpc.getInnerAPICli().GetObjectFields(ctx, param);
680
- }
681
- catch (err) {
682
- throw new exceptions.InternalError(`Call InnerAPI getFields failed: ${err.message}`);
683
- }
684
- // 4.后置处理
685
- post(resp.BaseResp);
686
- let result = {};
687
- try {
688
- result = JSON.parse(resp.Data);
689
- }
690
- catch (e) {
691
- throw new exceptions.InternalError(`JSON parse failed: ${e.message}`);
692
- }
693
- return result ? result.fields : [];
694
- }
695
- async function getField(objectApiName, fieldApiName) {
696
- // 1. prepare request
697
- let ctx = await pre();
698
- // 2. build parameters
699
- let param = {};
700
- param.Namespace = await (0, common_1.getNamespaceForOpenAndFaaSSDK)();
701
- param.ObjectAPIName = objectApiName;
702
- param.FieldAPIName = fieldApiName;
703
- // 3. do request
704
- let resp;
705
- try {
706
- resp = await rpc.getInnerAPICli().GetObjectField(ctx, param);
707
- }
708
- catch (err) {
709
- throw new exceptions.InternalError(`Call InnerAPI failed: ${err.message}`);
710
- }
711
- // 4. deal with response
712
- post(resp.BaseResp);
713
- try {
714
- return JSON.parse(resp.Data);
715
- }
716
- catch (e) {
717
- throw new exceptions.InternalError(`JSON parse failed: ${e.message}`);
718
- }
719
- }
720
- async function terminateWorkflowInstance(workflowInstanceId, operator, reason) {
721
- // 1. prepare args
722
- if (typeof (workflowInstanceId) !== 'number') {
723
- throw new exceptions.InvalidParamError(`The type of workflowInstanceId should be number, but ${typeof (workflowInstanceId)}.`);
724
- }
725
- // 2. prepare request
726
- let ctx = await pre();
727
- // 3. build parameters
728
- let param = {};
729
- param.WorkflowInstanceID = BigInt(workflowInstanceId);
730
- param.Operator = BigInt(operator);
731
- param.Reason = reason;
732
- // 4. do request
733
- let resp;
734
- try {
735
- resp = await rpc.getInnerAPICli().TerminateWorkflowInstance(ctx, param);
736
- }
737
- catch (err) {
738
- throw new exceptions.InternalError(`Call InnerAPI failed: ${err.message}`);
739
- }
740
- // 5. deal with response
741
- post(resp.BaseResp);
742
- }
743
- async function modifyRecordsWithTransaction(placeholders, operations, authType) {
744
- // 1. prepare args
745
- // TODO: change placeholders type
746
- let ph = new Map();
747
- for (let key of Object.keys(placeholders)) {
748
- ph.set(key, BigInt(placeholders[key]));
749
- }
750
- // 2. build parameters
751
- let param = {};
752
- param.Namespace = await (0, common_1.getNamespaceForOpenAndFaaSSDK)();
753
- param.Placeholders = ph;
754
- // TODO: change operations type
755
- param.Operations = operations;
756
- param.OperatorID = BigInt(utils.getUserIDFromCtx());
757
- param.SetSystemField = 1;
758
- const taskID = utils.getTriggerTaskID();
759
- if (taskID) {
760
- param.TaskID = BigInt(taskID);
761
- }
762
- // 3. prepare request
763
- authType = (0, utils_1.formatAuthType)(authType);
764
- let ctx = await pre(true, authType);
765
- // 4. do request
766
- let resp;
767
- try {
768
- resp = await rpc.getInnerAPICli().ModifyRecordsWithTX(ctx, param);
769
- }
770
- catch (err) {
771
- throw new exceptions.InternalError(`Call InnerAPI failed: ${err.message}`);
772
- }
773
- // 5. deal with response
774
- post(resp.BaseResp);
775
- return resp.Placeholders;
776
- }
777
- async function getGlobalConfigByKey(key) {
778
- // 1. prepare request
779
- let ctx = await pre();
780
- // 2. get all global configs by page
781
- let pageSize = 100, offset = 0;
782
- for (let i = 0;; i++) {
783
- let param = {};
784
- param.NameSpace = await (0, common_1.getNamespaceForOpenAndFaaSSDK)();
785
- param.BizType = 'GlobalVariables';
786
- param.UsedBy = 'UsedBySystem';
787
- param.Filter = {
788
- Offset: BigInt(offset * i),
789
- Limit: BigInt(pageSize),
790
- };
791
- // 3. do request
792
- let resp;
793
- try {
794
- resp = await rpc.getInnerAPICli().GetAllConfig(ctx, param);
795
- }
796
- catch (err) {
797
- throw new exceptions.InternalError(`Call InnerAPI failed: ${err.message}`);
798
- }
799
- post(resp.BaseResp);
800
- // 4. find the config
801
- for (let config of resp.Configs) {
802
- if (config.Key === key) {
803
- return config.Value;
804
- }
805
- }
806
- // 5. check if there is next page
807
- if (resp.Configs.length < 100) {
808
- break;
809
- }
810
- }
811
- throw new exceptions.InvalidParamError(`undefined global variable (${key})`);
812
- }
813
- async function oql(oql, args, namedArgs, authType) {
814
- // 1. build parameters
815
- const queryData = JSON.stringify({
816
- 'query': oql,
817
- args,
818
- namedArgs,
819
- 'compat': true,
820
- 'unauthFields': true,
821
- });
822
- // 2. prepare args
823
- let param = {};
824
- param.Namespace = await (0, common_1.getNamespaceForOpenAndFaaSSDK)();
825
- param.QueryData = Buffer.from(queryData);
826
- // 3. prepare request
827
- authType = (0, utils_1.formatAuthType)(authType);
828
- if (authType === constants_2.AuthTypeUser || authType == constants_2.AuthTypeMixUserSystem) {
829
- authType = constants_2.AuthTypeMixUserSystem;
830
- }
831
- let ctx = await pre(true, authType);
832
- // 4. do request
833
- let resp;
834
- try {
835
- resp = await rpc.getInnerAPICli().QueryRecordsByOQL(ctx, param);
836
- }
837
- catch (err) {
838
- throw new exceptions.InternalError(`Call InnerAPI failed: ${err.message}`);
839
- }
840
- // 5. deal with response
841
- post(resp.BaseResp);
842
- try {
843
- const records = JSON.parse(resp.Rows ? resp.Rows : '[]');
844
- permissionUtils.appendUnauthFieldRecordList("", records, resp.UnauthFieldSlice, true);
845
- return records;
846
- }
847
- catch (e) {
848
- throw new exceptions.InternalError(`oql result parse failed: ${e.message}`);
849
- }
850
- }
851
- async function openSDKCreateRecordBySync(objectApiName, record) {
852
- // 1. prepare args
853
- if (typeof (objectApiName) !== 'string') {
854
- throw new exceptions.InvalidParamError(`The type of objectApiName should be string, but ${typeof (objectApiName)}.`);
855
- }
856
- // 2. prepare request
857
- let ctx = await pre();
858
- // 3. build parameters
859
- let param = {};
860
- param.Namespace = await (0, common_1.getNamespaceForOpenAndFaaSSDK)();
861
- param.ObjectAPIName = objectApiName;
862
- param.Record = record;
863
- // 4. do request
864
- let resp;
865
- try {
866
- resp = await rpc.getInnerAPICli().CreateRecord(ctx, param);
867
- }
868
- catch (err) {
869
- throw new exceptions.InternalError(`Call InnerAPI failed: ${err.message}`);
870
- }
871
- // 5. deal with response
872
- post(resp.BaseResp);
873
- }
874
- async function openSDKUpdateRecordBySync(objectApiName, recordID, record) {
875
- // 1. prepare args
876
- if (typeof (objectApiName) !== 'string') {
877
- throw new exceptions.InvalidParamError(`The type of objectApiName should be string, but ${typeof (objectApiName)}.`);
878
- }
879
- if (typeof (recordID) !== 'number') {
880
- throw new exceptions.InvalidParamError(`The type of recordID should be number, but ${typeof (recordID)}.`);
881
- }
882
- // 2. prepare request
883
- let ctx = await pre();
884
- // 3. build parameters
885
- let param = {};
886
- param.Namespace = await (0, common_1.getNamespaceForOpenAndFaaSSDK)();
887
- param.ObjectAPIName = objectApiName;
888
- param.RecordID = BigInt(recordID);
889
- param.Record = record;
890
- // 4. do request
891
- let resp;
892
- try {
893
- resp = await rpc.getInnerAPICli().UpdateRecord(ctx, param);
894
- }
895
- catch (err) {
896
- throw new exceptions.InternalError(`Call InnerAPI failed: ${err.message}`);
897
- }
898
- // 5. deal with response
899
- post(resp.BaseResp);
900
- }
901
- async function openSDKDeleteRecordBySync(objectApiName, recordID) {
902
- // 1. prepare args
903
- if (typeof (objectApiName) !== 'string') {
904
- throw new exceptions.InvalidParamError(`The type of objectApiName should be string, but ${typeof (objectApiName)}.`);
905
- }
906
- if (typeof (recordID) !== 'number') {
907
- throw new exceptions.InvalidParamError(`The type of recordID should be number, but ${typeof (recordID)}.`);
908
- }
909
- // 2. prepare request
910
- let ctx = await pre();
911
- // 3. build parameters
912
- let param = {};
913
- param.Namespace = await (0, common_1.getNamespaceForOpenAndFaaSSDK)();
914
- param.ObjectAPIName = objectApiName;
915
- param.RecordID = BigInt(recordID);
916
- // 4. do request
917
- let resp;
918
- try {
919
- resp = await rpc.getInnerAPICli().DeleteRecord(ctx, param);
920
- }
921
- catch (err) {
922
- throw new exceptions.InternalError(`Call InnerAPI failed: ${err.message}`);
923
- }
924
- // 5. deal with response
925
- post(resp.BaseResp);
926
- }
927
- async function openSDKCreateRecordsBySync(objectApiName, records) {
928
- // 1. prepare args
929
- if (typeof (objectApiName) !== 'string') {
930
- throw new exceptions.InvalidParamError(`The type of objectApiName should be string, but ${typeof (objectApiName)}.`);
931
- }
932
- // 2. prepare request
933
- let ctx = await pre();
934
- // 3. build parameters
935
- let param = {};
936
- param.Namespace = await (0, common_1.getNamespaceForOpenAndFaaSSDK)();
937
- param.ObjectAPIName = objectApiName;
938
- param.Records = records;
939
- // 4. do request
940
- let resp;
941
- try {
942
- resp = await rpc.getInnerAPICli().BatchCreateRecords(ctx, param);
943
- }
944
- catch (err) {
945
- throw new exceptions.InternalError(`Call InnerAPI failed: ${err.message}`);
946
- }
947
- // 5. deal with response
948
- post(resp.BaseResp);
949
- }
950
- async function openSDKUpdateRecordsBySync(objectApiName, recordMap) {
951
- // 1. prepare args
952
- if (typeof (objectApiName) !== 'string') {
953
- throw new exceptions.InvalidParamError(`The type of objectApiName should be string, but ${typeof (objectApiName)}.`);
954
- }
955
- // 2. prepare request
956
- let ctx = await pre();
957
- // 3. build parameters
958
- let param = {};
959
- param.Namespace = await (0, common_1.getNamespaceForOpenAndFaaSSDK)();
960
- param.ObjectAPIName = objectApiName;
961
- param.RecordMap = recordMap;
962
- // 4. do request
963
- let resp;
964
- try {
965
- resp = await rpc.getInnerAPICli().BatchUpdateRecords(ctx, param);
966
- }
967
- catch (err) {
968
- throw new exceptions.InternalError(`Call InnerAPI failed: ${err.message}`);
969
- }
970
- // 5. deal with response
971
- post(resp.BaseResp);
972
- }
973
- async function openSDKDeleteRecordsBySync(objectApiName, recordIDs) {
974
- // 1. prepare args
975
- if (typeof (objectApiName) !== 'string') {
976
- throw new exceptions.InvalidParamError(`The type of objectApiName should be string, but ${typeof (objectApiName)}.`);
977
- }
978
- // 2. prepare request
979
- let ctx = await pre();
980
- // 3. build parameters
981
- let param = {};
982
- param.Namespace = await (0, common_1.getNamespaceForOpenAndFaaSSDK)();
983
- param.ObjectAPIName = objectApiName;
984
- param.RecordIDs = recordIDs;
985
- // 4. do request
986
- let resp;
987
- try {
988
- resp = await rpc.getInnerAPICli().BatchDeleteRecords(ctx, param);
989
- }
990
- catch (err) {
991
- throw new exceptions.InternalError(`Call InnerAPI failed: ${err.message}`);
992
- }
993
- // 5. deal with response
994
- post(resp.BaseResp);
995
- }
996
- async function openSDKGetRecords(objectApiName, param) {
997
- // 1. prepare args
998
- if (param.limit <= 0 || param.limit > 10000) {
999
- param.limit = 10000;
1000
- }
1001
- let req;
1002
- req.ObjectAPIAlias = objectApiName;
1003
- req.Filter = JSON.stringify(param.filter);
1004
- req.Limit = BigInt(param.limit);
1005
- req.Offset = BigInt(param.offset);
1006
- req.FiledAPIAlias = param.fields;
1007
- req.NeedTotalCount = param.count;
1008
- let sortList = [];
1009
- if (param.sort) {
1010
- param.sort.forEach((sort) => {
1011
- sortList.push({
1012
- FieldApiAlias: sort.field,
1013
- Type: sort.type,
1014
- Direction: sort.direction,
1015
- });
1016
- });
1017
- }
1018
- req.Sort = sortList;
1019
- // 2. prepare request
1020
- let ctx = await pre();
1021
- // 3. do request
1022
- let resp;
1023
- try {
1024
- resp = await rpc.getInnerAPICli().GetRecordList(ctx, req);
1025
- }
1026
- catch (err) {
1027
- throw new exceptions.InternalError(`Call InnerAPI failed: ${err.message}`);
1028
- }
1029
- // 4. deal with response
1030
- post(resp.BaseResp);
1031
- // 5. return result
1032
- if (param.count) {
1033
- return resp.Total;
1034
- }
1035
- else {
1036
- return resp.Data;
1037
- }
1038
- }
1039
- ;
1040
- async function openSDKUploadFile(fileName, data) {
1041
- // 1. prepare args
1042
- let param;
1043
- param.Name = fileName;
1044
- param.EncryptType = 1; // no encrypt
1045
- param.Data = data;
1046
- // 2. prepare request
1047
- let ctx = await pre();
1048
- // 3. do request
1049
- let resp;
1050
- try {
1051
- resp = await rpc.getAttachmentCli().UploadFileForRPC(ctx, param);
1052
- }
1053
- catch (err) {
1054
- throw new exceptions.InternalError(`Call Attachment failed: ${err.message}`);
1055
- }
1056
- // 4. deal with response
1057
- post(resp.BaseResp);
1058
- return resp;
1059
- }
1060
- async function openSDKUploadAvatar(fileName, data) {
1061
- // 1. prepare args
1062
- let param;
1063
- param.EncryptType = 1; // no encrypt
1064
- param.Data = data;
1065
- // 2. prepare request
1066
- let ctx = await pre();
1067
- // 3. do request
1068
- let resp;
1069
- try {
1070
- resp = await rpc.getAttachmentCli().UploadAvatarForRPC(ctx, param);
1071
- }
1072
- catch (err) {
1073
- throw new exceptions.InternalError(`Call Attachment failed: ${err.message}`);
1074
- }
1075
- // 4. deal with response
1076
- post(resp.BaseResp);
1077
- return resp;
1078
- }
1079
- async function openSDKDownloadAvatar(imageID) {
1080
- // 1. prepare args
1081
- let param;
1082
- param.ImageID = imageID;
1083
- // 2. prepare request
1084
- let ctx = await pre();
1085
- // 3. do request
1086
- let resp;
1087
- try {
1088
- resp = await rpc.getAttachmentCli().DownloadAvatarForRPC(ctx, param);
1089
- }
1090
- catch (err) {
1091
- throw new exceptions.InternalError(`Call Attachment failed: ${err.message}`);
1092
- }
1093
- // 4. deal with response
1094
- post(resp.BaseResp);
1095
- return resp.Data;
1096
- }
1097
- class RequestRpc {
1098
- constructor() {
1099
- this.updateWorkflowVariables = updateWorkflowVariables;
1100
- this.createRecordBySync = createRecordBySync;
1101
- this.updateRecordBySync = updateRecordBySync;
1102
- this.deleteRecordBySync = deleteRecordBySync;
1103
- this.createRecordsByAsync = createRecordsByAsync;
1104
- this.updateRecordsByAsync = updateRecordsByAsync;
1105
- this.deleteRecordsByAsync = deleteRecordsByAsync;
1106
- this.createRecordsBySync = createRecordsBySync;
1107
- this.updateRecordsBySync = updateRecordsBySync;
1108
- this.deleteRecordsBySync = deleteRecordsBySync;
1109
- this.getRecordsOrCountByCriterion = getRecordsOrCountByCriterion;
1110
- this.uploadFile = uploadFile;
1111
- this.downloadFileByID = downloadFileByID;
1112
- this.downloadFileByToken = downloadFileByToken;
1113
- this.mGetFileToken = mGetFileToken;
1114
- this.createMessage = createMessage;
1115
- this.updateMessage = updateMessage;
1116
- this.getFields = getFields;
1117
- this.getField = getField;
1118
- this.terminateWorkflowInstance = terminateWorkflowInstance;
1119
- this.modifyRecordsWithTransaction = modifyRecordsWithTransaction;
1120
- this.getGlobalConfigByKey = getGlobalConfigByKey;
1121
- this.oql = oql;
1122
- this.getIntegrationAppAccessToken = getIntegrationAppAccessToken;
1123
- this.getIntegrationTenantAccessToken = getIntegrationTenantAccessToken;
1124
- this.getDefaultIntegrationAppAccessToken = getDefaultIntegrationAppAccessToken;
1125
- this.getDefaultIntegrationTenantAccessToken = getDefaultIntegrationTenantAccessToken;
1126
- // open sdk api
1127
- this.openSDKCreateRecordBySync = openSDKCreateRecordBySync;
1128
- this.openSDKUpdateRecordBySync = openSDKUpdateRecordBySync;
1129
- this.openSDKDeleteRecordBySync = openSDKDeleteRecordBySync;
1130
- this.openSDKCreateRecordsBySync = openSDKCreateRecordsBySync;
1131
- this.openSDKUpdateRecordsBySync = openSDKUpdateRecordsBySync;
1132
- this.openSDKDeleteRecordsBySync = openSDKDeleteRecordsBySync;
1133
- this.openSDKGetRecords = openSDKGetRecords;
1134
- this.openSDKUploadFile = openSDKUploadFile;
1135
- this.openSDKUploadAvatar = openSDKUploadAvatar;
1136
- this.openSDKDownloadAvatar = openSDKDownloadAvatar;
1137
- }
1138
- createRecordBySync(objectApiName, record, authType) {
1139
- }
1140
- updateRecordBySync(objectApiName, recordID, record, authType) {
1141
- }
1142
- deleteRecordBySync(objectApiName, recordID, authType) {
1143
- }
1144
- createRecordsByAsync(objectApiName, records, authType) {
1145
- }
1146
- updateRecordsByAsync(objectApiName, recordMap, authType) {
1147
- }
1148
- deleteRecordsByAsync(objectApiName, recordIDs, authType) {
1149
- }
1150
- createRecordsBySync(objectApiName, records, authType) {
1151
- }
1152
- updateRecordsBySync(objectApiName, recordMap, authType) {
1153
- return undefined;
1154
- }
1155
- deleteRecordsBySync(objectApiName, recordIDs, authType) {
1156
- return undefined;
1157
- }
1158
- getRecordsOrCountByCriterion(objectApiName, criterion, fuzzySearch, order, ignoreBackLookupField, fieldApiNames, offset, limit, needCount, authType) {
1159
- }
1160
- async updateWorkflowVariables(ctx, instanceId, variables, variableTypes) {
1161
- }
1162
- async uploadFile(data, expire) {
1163
- return null;
1164
- }
1165
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
1166
- async downloadFileByID(fileID, filePath) {
1167
- return null;
1168
- }
1169
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
1170
- async downloadFileByToken(fileToken, filePath) {
1171
- return null;
1172
- }
1173
- async createMessage(msg) {
1174
- return null;
1175
- }
1176
- async updateMessage(msgId, msg) {
1177
- return null;
1178
- }
1179
- async getFields(objectApiName) {
1180
- }
1181
- async getField(objectApiName, fieldApiName) {
1182
- }
1183
- async terminateWorkflowInstance(workflowInstanceId, operator, reason) {
1184
- }
1185
- async modifyRecordsWithTransaction(placeholders, operations, authType) {
1186
- return null;
1187
- }
1188
- async getGlobalConfigByKey(key) {
1189
- return null;
1190
- }
1191
- async oql(oql, args, namedArgs, authType) {
1192
- return [];
1193
- }
1194
- async invokeFuncSync(idOrName, params) {
1195
- return await invokeFuncSync(idOrName, params);
1196
- }
1197
- async invokeFuncWithAuth(idOrName, params) {
1198
- return await invokeFuncWithAuth(idOrName, params);
1199
- }
1200
- async createAsyncTaskV1(idOrName, params) {
1201
- return await createAsyncTaskV1(idOrName, params);
1202
- }
1203
- async createAsyncTaskV2(name, params) {
1204
- return await createAsyncTaskV2(name, params);
1205
- }
1206
- async getExecutionUserTaskInfo(executionId) {
1207
- return await getExecutionUserTaskInfo(executionId);
1208
- }
1209
- async executeFlow(APIName, options) {
1210
- return await executeFlow(APIName, options);
1211
- }
1212
- async revokeExecution(executionId, revokeOptions) {
1213
- return await revokeExecution(executionId, revokeOptions);
1214
- }
1215
- async getExecutionInfo(executionId) {
1216
- return await getExecutionInfo(executionId);
1217
- }
1218
- async getTenantInfo(appCtx) {
1219
- return await appCtx.credential.getTenantInfo();
1220
- }
1221
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
1222
- async mGetFileToken(ids) {
1223
- return null;
1224
- }
1225
- async getIntegrationAppAccessToken(apiName) {
1226
- return null;
1227
- }
1228
- async getIntegrationTenantAccessToken(apiName) {
1229
- return null;
1230
- }
1231
- async getDefaultIntegrationAppAccessToken() {
1232
- return null;
1233
- }
1234
- async getDefaultIntegrationTenantAccessToken() {
1235
- return null;
1236
- }
1237
- // open sdk empty implement
1238
- openSDKCreateRecordBySync(objectApiName, record) {
1239
- }
1240
- ;
1241
- openSDKUpdateRecordBySync(objectApiName, recordID, record) {
1242
- }
1243
- ;
1244
- openSDKDeleteRecordBySync(objectApiName, recordID) {
1245
- }
1246
- ;
1247
- openSDKCreateRecordsBySync(objectApiName, records) {
1248
- }
1249
- ;
1250
- openSDKUpdateRecordsBySync(objectApiName, recordMap) {
1251
- }
1252
- ;
1253
- openSDKDeleteRecordsBySync(objectApiName, recordIDs) {
1254
- }
1255
- ;
1256
- openSDKGetRecords(objectApiName, param) {
1257
- }
1258
- ;
1259
- openSDKUploadFile(fileName, data) {
1260
- }
1261
- ;
1262
- openSDKUploadAvatar(fileName, data) {
1263
- }
1264
- ;
1265
- openSDKDownloadAvatar(imageID) {
1266
- }
1267
- ;
1268
- }
1269
- exports.RequestRpc = RequestRpc;
1270
- async function invokeFuncWithAuth(idOrName, params) {
1271
- let ctx = await pre(true);
1272
- let param = {};
1273
- param.Namespace = await (0, common_1.getNamespaceForOpenAndFaaSSDK)();
1274
- if (idOrName.isInvokeByAPIName) {
1275
- param.ApiName = idOrName.APIName;
1276
- }
1277
- else {
1278
- param.ApiID = idOrName.APIId;
1279
- }
1280
- param.Params = JSON.stringify(params);
1281
- param.Context = JSON.stringify((0, common_1.getTriggerCtx)());
1282
- let resp = undefined;
1283
- try {
1284
- resp = await rpc.getInnerAPICli().InvokeFunctionWithAuth(ctx, param);
1285
- }
1286
- catch (err) {
1287
- throw new exceptions.InternalError(`Call InnerAPI failed: ${err.message}`);
1288
- }
1289
- post(resp.BaseResp);
1290
- let result;
1291
- try {
1292
- result = JSON.parse(resp.result);
1293
- }
1294
- catch (e) {
1295
- throw new exceptions.InternalError(`JSON parse failed for ${resp.result}`);
1296
- }
1297
- if (!result || result.code !== '0') {
1298
- throw new exceptions.InvalidParamError(`result is invalid for code: ${result ? result.code : ''} msg: ${result ? result.msg : ''}`);
1299
- }
1300
- return result.data;
1301
- }
1302
- async function executeFlow(APIName, options) {
1303
- let ctx = await pre();
1304
- let param = {};
1305
- param.NameSpace = await (0, common_1.getNamespaceForOpenAndFaaSSDK)();
1306
- param.Operator = BigInt(utils.getUserIDFromCtx());
1307
- param.FlowAPIName = APIName;
1308
- param.variables = JSON.stringify((0, common_1.transMapToFlowVariable)(options.params));
1309
- param.LoopMasks = utils.getLoopMasks();
1310
- let resp = undefined;
1311
- try {
1312
- resp = await rpc.getInnerAPICli().Execute(ctx, param);
1313
- }
1314
- catch (err) {
1315
- throw new exceptions.InternalError(`Call InnerAPI failed: ${err.message}`);
1316
- }
1317
- // 5.后置处理
1318
- post(resp.BaseResp);
1319
- let outParams = [];
1320
- try {
1321
- if (resp.OutParams) {
1322
- outParams = JSON.parse(resp.OutParams);
1323
- }
1324
- }
1325
- catch (e) {
1326
- throw new exceptions_1.InternalError(`Execute OutParams in Result is invalid (${resp.OutParams}), err: ${e.message}`);
1327
- }
1328
- return {
1329
- executionId: Number(resp.ExecutionID),
1330
- status: resp.Status,
1331
- data: (0, common_1.transFlowVariableToMap)(outParams),
1332
- errCode: resp.errCode ? resp.errCode : undefined,
1333
- errMsg: resp.errMsg ? resp.errMsg : undefined,
1334
- };
1335
- }
1336
- async function revokeExecution(executionId, revokeOptions) {
1337
- let ctx = await pre();
1338
- let param = {};
1339
- param.NameSpace = await (0, common_1.getNamespaceForOpenAndFaaSSDK)();
1340
- param.Operator = BigInt(utils.getUserIDFromCtx());
1341
- param.ExecutionID = BigInt(executionId);
1342
- let reason = undefined;
1343
- if (revokeOptions && revokeOptions.reason) {
1344
- reason = {
1345
- en_US: revokeOptions.reason.en_US,
1346
- zh_CN: revokeOptions.reason.zh_CN
1347
- };
1348
- }
1349
- param.Reason = reason;
1350
- let resp = undefined;
1351
- try {
1352
- resp = await rpc.getInnerAPICli().RevokeExecution(ctx, param);
1353
- }
1354
- catch (err) {
1355
- throw new exceptions.InternalError(`Call InnerAPI failed: ${err.message}`);
1356
- }
1357
- // 5.后置处理
1358
- post(resp.BaseResp);
1359
- }
1360
- exports.revokeExecution = revokeExecution;
1361
- async function getExecutionInfo(executionId) {
1362
- let ctx = await pre();
1363
- let param = {};
1364
- param.NameSpace = await (0, common_1.getNamespaceForOpenAndFaaSSDK)();
1365
- param.ExecutionID = BigInt(executionId);
1366
- param.Operator = BigInt(utils.getUserIDFromCtx());
1367
- let resp = undefined;
1368
- try {
1369
- resp = await rpc.getInnerAPICli().GetExecutionInfo(ctx, param);
1370
- }
1371
- catch (err) {
1372
- throw new exceptions.InternalError(`Call InnerAPI failed: ${err.message}`);
1373
- }
1374
- // 5.后置处理
1375
- post(resp.BaseResp);
1376
- if (!resp || !resp.ExecutionInfo) {
1377
- throw new exceptions_1.InternalError(`GetExecutionInfo Response is empty`);
1378
- }
1379
- let outParams = [];
1380
- try {
1381
- if (resp.ExecutionInfo.outParams) {
1382
- outParams = JSON.parse(resp.ExecutionInfo.outParams);
1383
- }
1384
- }
1385
- catch (e) {
1386
- throw new exceptions_1.InternalError(`GetExecutionInfo OutParams in Result is invalid (${resp.ExecutionInfo.outParams}), err: ${e.message}`);
1387
- }
1388
- return {
1389
- status: resp.ExecutionInfo.status,
1390
- data: (0, common_1.transFlowVariableToMap)(outParams),
1391
- errCode: resp.ExecutionInfo.errCode ? resp.ExecutionInfo.errCode : undefined,
1392
- errMsg: resp.ExecutionInfo.errMsg ? resp.ExecutionInfo.errMsg : undefined,
1393
- };
1394
- }
1395
- exports.getExecutionInfo = getExecutionInfo;
1396
- async function getExecutionUserTaskInfo(executionId) {
1397
- let ctx = await pre();
1398
- let param = {};
1399
- param.NameSpace = await (0, common_1.getNamespaceForOpenAndFaaSSDK)();
1400
- param.ExecutionID = BigInt(executionId);
1401
- param.Operator = BigInt(utils.getUserIDFromCtx());
1402
- let resp = undefined;
1403
- try {
1404
- resp = await rpc.getInnerAPICli().GetExecutionUserTaskInfo(ctx, param);
1405
- }
1406
- catch (err) {
1407
- throw new exceptions.InternalError(`Call InnerAPI failed: ${err.message}`);
1408
- }
1409
- // 5.后置处理
1410
- post(resp.BaseResp);
1411
- return resp.taskList;
1412
- }
1413
- exports.getExecutionUserTaskInfo = getExecutionUserTaskInfo;
1414
- async function invokeFuncSync(idOrName, params) {
1415
- let ctx = await pre(true);
1416
- // 兼容 params 不传的情况
1417
- if (params === undefined) {
1418
- params = {};
1419
- }
1420
- let param = {};
1421
- param.Namespace = await (0, common_1.getNamespaceForOpenAndFaaSSDK)();
1422
- if (idOrName.isInvokeByAPIName) {
1423
- param.FunctionName = '';
1424
- param.APIAlias = idOrName.APIName;
1425
- }
1426
- else {
1427
- param.FunctionName = idOrName.APIId;
1428
- param.APIAlias = '';
1429
- }
1430
- param.Params = JSON.stringify(params);
1431
- param.Context = JSON.stringify((0, common_1.getTriggerCtx)());
1432
- param.TriggerType = utils.getTriggerType();
1433
- let resp;
1434
- try {
1435
- resp = await rpc.getInnerAPICli().InvokeFuncSync(ctx, param);
1436
- }
1437
- catch (err) {
1438
- throw new exceptions.InternalError(`Call InnerAPI failed: ${err.message}`);
1439
- }
1440
- // 5.后置处理
1441
- post(resp.BaseResp);
1442
- let result = {};
1443
- try {
1444
- result = JSON.parse(resp.Result);
1445
- }
1446
- catch (e) {
1447
- throw new exceptions.InternalError(`Parse Result failed: ${e.message}`);
1448
- }
1449
- if (result && result.code === '0') {
1450
- return result.data;
1451
- }
1452
- throw new exceptions.BaseError(result.code, result.msg);
1453
- }
1454
- async function createAsyncTaskV1(idOrName, params) {
1455
- let ctx = await pre(true);
1456
- let param = {};
1457
- param.Namespace = await (0, common_1.getNamespaceForOpenAndFaaSSDK)();
1458
- if (idOrName.isInvokeByAPIName) {
1459
- param.Alias = idOrName.APIName;
1460
- param.Name = ''; // required
1461
- }
1462
- else {
1463
- param.Name = idOrName.APIId;
1464
- }
1465
- param.Params = JSON.stringify(params);
1466
- param.Context = JSON.stringify((0, common_1.getTriggerCtx)());
1467
- param.TriggerType = utils.getTriggerType();
1468
- let resp;
1469
- try {
1470
- resp = await rpc.getInnerAPICli().CreateAsyncTaskOld(ctx, param);
1471
- }
1472
- catch (err) {
1473
- throw new exceptions.InternalError(`Call InnerAPI failed: ${err.message}`);
1474
- }
1475
- // 5.后置处理
1476
- post(resp.BaseResp);
1477
- return Number(resp.TaskID);
1478
- }
1479
- async function createAsyncTaskV2(APIName, params) {
1480
- let ctx = await pre(true);
1481
- let param = {};
1482
- param.Namespace = await (0, common_1.getNamespaceForOpenAndFaaSSDK)();
1483
- param.APIAlias = APIName;
1484
- param.Params = JSON.stringify(params);
1485
- param.Context = JSON.stringify((0, common_1.getTriggerCtx)());
1486
- param.TriggerType = utils.getTriggerType();
1487
- param.Extra = (0, common_1.getDebugExtraInfo)();
1488
- let resp;
1489
- try {
1490
- resp = await rpc.getInnerAPICli().CreateAsyncTask(ctx, param);
1491
- }
1492
- catch (err) {
1493
- throw new exceptions.InternalError(`Call InnerAPI failed: ${err.message}`);
1494
- }
1495
- // 5.后置处理
1496
- post(resp.BaseResp);
1497
- return Number(resp.TaskID);
1498
- }
1499
- async function getIntegrationAppAccessToken(apiName) {
1500
- // 1.check
1501
- if (!apiName) {
1502
- throw new exceptions.InvalidParamError('apiName is empty');
1503
- }
1504
- // 2.前置处理
1505
- let ctx = await pre(true);
1506
- // 3.构造 params
1507
- let param = {};
1508
- param.APIName = apiName;
1509
- // 4.发起请求
1510
- let resp;
1511
- try {
1512
- resp = await rpc.getInnerAPICli().GetIntegrationAppAccessToken(ctx, param);
1513
- }
1514
- catch (err) {
1515
- throw new exceptions.InternalError(`Call InnerAPI failed: ${err.message}`);
1516
- }
1517
- // 5.后置处理
1518
- post(resp.BaseResp);
1519
- return {
1520
- expire: resp.Expire ? resp.Expire : undefined,
1521
- appAccessToken: resp.AppAccessToken ? resp.AppAccessToken : undefined,
1522
- appId: resp.AppID ? resp.AppID : undefined,
1523
- };
1524
- }
1525
- async function getIntegrationTenantAccessToken(apiName) {
1526
- // 1.check
1527
- if (!apiName) {
1528
- throw new exceptions.InvalidParamError('apiName is empty');
1529
- }
1530
- // 2.前置处理
1531
- let ctx = await pre(true);
1532
- // 3.构造 params
1533
- let param = {};
1534
- param.APIName = apiName;
1535
- // 4.发起请求
1536
- let resp;
1537
- try {
1538
- resp = await rpc.getInnerAPICli().GetIntegrationTenantAccessToken(ctx, param);
1539
- }
1540
- catch (err) {
1541
- throw new exceptions.InternalError(`Call InnerAPI failed: ${err.message}`);
1542
- }
1543
- // 5.后置处理
1544
- post(resp.BaseResp);
1545
- return {
1546
- expire: resp.Expire ? resp.Expire : undefined,
1547
- tenantAccessToken: resp.TenantAccessToken ? resp.TenantAccessToken : undefined,
1548
- appId: resp.AppID ? resp.AppID : undefined,
1549
- };
1550
- }
1551
- async function getDefaultIntegrationAppAccessToken() {
1552
- // 1.check
1553
- // 2.前置处理
1554
- let ctx = await pre(true);
1555
- // 3.构造 params
1556
- let param = {};
1557
- // 4.发起请求
1558
- let resp;
1559
- try {
1560
- resp = await rpc.getInnerAPICli().GetDefaultIntegrationAppAccessToken(ctx, param);
1561
- }
1562
- catch (err) {
1563
- throw new exceptions.InternalError(`Call InnerAPI failed: ${err.message}`);
1564
- }
1565
- // 5.后置处理
1566
- post(resp.BaseResp);
1567
- return {
1568
- expire: resp.Expire ? resp.Expire : undefined,
1569
- appAccessToken: resp.AppAccessToken ? resp.AppAccessToken : undefined,
1570
- appId: resp.AppID ? resp.AppID : undefined,
1571
- };
1572
- }
1573
- async function getDefaultIntegrationTenantAccessToken() {
1574
- // 1.check
1575
- // 2.前置处理
1576
- let ctx = await pre(true);
1577
- // 3.构造 params
1578
- let param = {};
1579
- // 4.发起请求
1580
- let resp;
1581
- try {
1582
- resp = await rpc.getInnerAPICli().GetDefaultIntegrationTenantAccessToken(ctx, param);
1583
- }
1584
- catch (err) {
1585
- throw new exceptions.InternalError(`Call InnerAPI failed: ${err.message}`);
1586
- }
1587
- // 5.后置处理
1588
- post(resp.BaseResp);
1589
- return {
1590
- expire: resp.Expire ? resp.Expire : undefined,
1591
- tenantAccessToken: resp.TenantAccessToken ? resp.TenantAccessToken : undefined,
1592
- appId: resp.AppID ? resp.AppID : undefined,
1593
- };
1594
- }
1595
- //# sourceMappingURL=innerapi.js.map