@byted-apaas/server-sdk-node 1.0.12 → 1.0.15

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.
@@ -9,6 +9,7 @@ const common = require("@byted-apaas/server-common-node");
9
9
  const constants_2 = require("./constants");
10
10
  const constants_3 = require("@byted-apaas/server-common-node/constants/constants");
11
11
  const common_1 = require("./common");
12
+ const utils_1 = require("@byted-apaas/server-common-node/utils/utils");
12
13
  const nodeCls = require("node-cls");
13
14
  const fs = require('fs');
14
15
  const path = require('path');
@@ -33,7 +34,7 @@ async function updateWorkflowVariables(ctx, instanceId, variables, variableTypes
33
34
  await openapi.doRequest(null, urlPath, options);
34
35
  }
35
36
  exports.updateWorkflowVariables = updateWorkflowVariables;
36
- async function createRecordBySync(objectApiName, record) {
37
+ async function createRecordBySync(objectApiName, record, authType) {
37
38
  // 1.check
38
39
  if (!objectApiName) {
39
40
  throw new exceptions.InvalidParamError("objectApiName is empty");
@@ -47,6 +48,11 @@ async function createRecordBySync(objectApiName, record) {
47
48
  "operator": utils.getUserIDFromCtx(),
48
49
  "data": record,
49
50
  };
51
+ authType = (0, utils_1.formatAuthType)(authType);
52
+ options.headers["User"] = utils.getUserIDFromCtx() + "";
53
+ if (authType) {
54
+ options.headers[constants_3.AuthTypeHttpHeader] = authType;
55
+ }
50
56
  let task_id = utils.getTriggerTaskID();
51
57
  if (task_id) {
52
58
  options.json["task_id"] = task_id;
@@ -60,7 +66,7 @@ async function createRecordBySync(objectApiName, record) {
60
66
  }
61
67
  return data;
62
68
  }
63
- async function updateRecordBySync(objectApiName, recordID, record) {
69
+ async function updateRecordBySync(objectApiName, recordID, record, authType) {
64
70
  // 1.check
65
71
  if (!objectApiName) {
66
72
  throw new exceptions.InvalidParamError("objectApiName is empty");
@@ -75,13 +81,18 @@ async function updateRecordBySync(objectApiName, recordID, record) {
75
81
  "record_id": recordID,
76
82
  "data": record,
77
83
  };
84
+ authType = (0, utils_1.formatAuthType)(authType);
85
+ options.headers["User"] = utils.getUserIDFromCtx() + "";
86
+ if (authType) {
87
+ options.headers[constants_3.AuthTypeHttpHeader] = authType;
88
+ }
78
89
  let task_id = utils.getTriggerTaskID();
79
90
  if (task_id) {
80
91
  options.json["task_id"] = task_id;
81
92
  }
82
93
  return openapi.doRequest(null, urlPath, options);
83
94
  }
84
- async function deleteRecordBySync(objectApiName, recordID) {
95
+ async function deleteRecordBySync(objectApiName, recordID, authType) {
85
96
  // 1.check
86
97
  if (!objectApiName) {
87
98
  throw new exceptions.InvalidParamError("objectApiName is empty");
@@ -95,13 +106,18 @@ async function deleteRecordBySync(objectApiName, recordID) {
95
106
  "operator": utils.getUserIDFromCtx(),
96
107
  "record_id": recordID,
97
108
  };
109
+ authType = (0, utils_1.formatAuthType)(authType);
110
+ options.headers["User"] = utils.getUserIDFromCtx() + "";
111
+ if (authType) {
112
+ options.headers[constants_3.AuthTypeHttpHeader] = authType;
113
+ }
98
114
  let task_id = utils.getTriggerTaskID();
99
115
  if (task_id) {
100
116
  options.json["task_id"] = task_id;
101
117
  }
102
118
  return openapi.doRequest(null, urlPath, options);
103
119
  }
104
- async function createRecordsByAsync(objectApiName, records) {
120
+ async function createRecordsByAsync(objectApiName, records, authType) {
105
121
  // 1.获取 options
106
122
  let options = commonHttp.getOptions(null, openapiHttpPath.createRecordsByAsyncV2);
107
123
  let urlPath = options._reqPath.replace(replaceKeys.namespace, await (0, common_1.getNamespaceForOpenAndFaaSSDK)());
@@ -111,13 +127,18 @@ async function createRecordsByAsync(objectApiName, records) {
111
127
  "operator": utils.getUserIDFromCtx(),
112
128
  "data": records,
113
129
  };
130
+ authType = (0, utils_1.formatAuthType)(authType);
131
+ options.headers["User"] = utils.getUserIDFromCtx() + "";
132
+ if (authType) {
133
+ options.headers[constants_3.AuthTypeHttpHeader] = authType;
134
+ }
114
135
  let task_id = utils.getTriggerTaskID();
115
136
  if (task_id) {
116
137
  options.json["automation_task_id"] = task_id;
117
138
  }
118
139
  return openapi.doRequest(null, urlPath, options);
119
140
  }
120
- async function updateRecordsByAsync(objectApiName, recordMap) {
141
+ async function updateRecordsByAsync(objectApiName, recordMap, authType) {
121
142
  // 1.获取 options
122
143
  let options = commonHttp.getOptions(null, openapiHttpPath.updateRecordsByAsyncV2);
123
144
  let urlPath = options._reqPath.replace(replaceKeys.namespace, await (0, common_1.getNamespaceForOpenAndFaaSSDK)());
@@ -127,13 +148,18 @@ async function updateRecordsByAsync(objectApiName, recordMap) {
127
148
  "operator": utils.getUserIDFromCtx(),
128
149
  "data": recordMap,
129
150
  };
151
+ authType = (0, utils_1.formatAuthType)(authType);
152
+ options.headers["User"] = utils.getUserIDFromCtx() + "";
153
+ if (authType) {
154
+ options.headers[constants_3.AuthTypeHttpHeader] = authType;
155
+ }
130
156
  let task_id = utils.getTriggerTaskID();
131
157
  if (task_id) {
132
158
  options.json["automation_task_id"] = task_id;
133
159
  }
134
160
  return openapi.doRequest(null, urlPath, options);
135
161
  }
136
- async function deleteRecordsByAsync(objectApiName, recordIDs) {
162
+ async function deleteRecordsByAsync(objectApiName, recordIDs, authType) {
137
163
  // 1.获取 options
138
164
  let options = commonHttp.getOptions(null, openapiHttpPath.deleteRecordsByAsyncV2);
139
165
  let urlPath = options._reqPath.replace(replaceKeys.namespace, await (0, common_1.getNamespaceForOpenAndFaaSSDK)());
@@ -143,13 +169,18 @@ async function deleteRecordsByAsync(objectApiName, recordIDs) {
143
169
  "operator": utils.getUserIDFromCtx(),
144
170
  "record_id_list": recordIDs,
145
171
  };
172
+ authType = (0, utils_1.formatAuthType)(authType);
173
+ options.headers["User"] = utils.getUserIDFromCtx() + "";
174
+ if (authType) {
175
+ options.headers[constants_3.AuthTypeHttpHeader] = authType;
176
+ }
146
177
  let task_id = utils.getTriggerTaskID();
147
178
  if (task_id) {
148
179
  options.json["automation_task_id"] = task_id;
149
180
  }
150
181
  return openapi.doRequest(null, urlPath, options);
151
182
  }
152
- async function createRecordsBySync(objectApiName, records) {
183
+ async function createRecordsBySync(objectApiName, records, authType) {
153
184
  // 1.获取 options
154
185
  let options = commonHttp.getOptions(null, openapiHttpPath.mCreateRecordsBySyncV2);
155
186
  let urlPath = options._reqPath.replace(replaceKeys.namespace, await (0, common_1.getNamespaceForOpenAndFaaSSDK)());
@@ -160,13 +191,18 @@ async function createRecordsBySync(objectApiName, records) {
160
191
  "set_system_mod": 2,
161
192
  "data": records,
162
193
  };
194
+ authType = (0, utils_1.formatAuthType)(authType);
195
+ options.headers["User"] = utils.getUserIDFromCtx() + "";
196
+ if (authType) {
197
+ options.headers[constants_3.AuthTypeHttpHeader] = authType;
198
+ }
163
199
  let task_id = utils.getTriggerTaskID();
164
200
  if (task_id) {
165
201
  options.json["automation_task_id"] = task_id;
166
202
  }
167
203
  return openapi.doRequest(null, urlPath, options);
168
204
  }
169
- async function updateRecordsBySync(objectApiName, recordMap) {
205
+ async function updateRecordsBySync(objectApiName, recordMap, authType) {
170
206
  // 1.获取 options
171
207
  let options = commonHttp.getOptions(null, openapiHttpPath.mUpdateRecordsBySyncV2);
172
208
  let urlPath = options._reqPath.replace(replaceKeys.namespace, await (0, common_1.getNamespaceForOpenAndFaaSSDK)());
@@ -177,13 +213,18 @@ async function updateRecordsBySync(objectApiName, recordMap) {
177
213
  "set_system_mod": 2,
178
214
  "data": recordMap,
179
215
  };
216
+ authType = (0, utils_1.formatAuthType)(authType);
217
+ options.headers["User"] = utils.getUserIDFromCtx() + "";
218
+ if (authType) {
219
+ options.headers[constants_3.AuthTypeHttpHeader] = authType;
220
+ }
180
221
  let task_id = utils.getTriggerTaskID();
181
222
  if (task_id) {
182
223
  options.json["automation_task_id"] = task_id;
183
224
  }
184
225
  return openapi.doRequest(null, urlPath, options);
185
226
  }
186
- async function deleteRecordsBySync(objectApiName, recordIDs) {
227
+ async function deleteRecordsBySync(objectApiName, recordIDs, authType) {
187
228
  // 1.获取 options
188
229
  let options = commonHttp.getOptions(null, openapiHttpPath.mDeleteRecordsBySyncV2);
189
230
  let urlPath = options._reqPath.replace(replaceKeys.namespace, await (0, common_1.getNamespaceForOpenAndFaaSSDK)());
@@ -194,6 +235,11 @@ async function deleteRecordsBySync(objectApiName, recordIDs) {
194
235
  "set_system_mod": 2,
195
236
  "record_id_list": recordIDs,
196
237
  };
238
+ authType = (0, utils_1.formatAuthType)(authType);
239
+ options.headers["User"] = utils.getUserIDFromCtx() + "";
240
+ if (authType) {
241
+ options.headers[constants_3.AuthTypeHttpHeader] = authType;
242
+ }
197
243
  let task_id = utils.getTriggerTaskID();
198
244
  if (task_id) {
199
245
  options.json["automation_task_id"] = task_id;
@@ -215,7 +261,7 @@ function handleResponse(data, needCount) {
215
261
  return [];
216
262
  }
217
263
  }
218
- async function getRecordsOrCountByCriterion(objectApiName, criterion, order, ignoreBackLookupField, fieldApiNames, offset, limit, needCount) {
264
+ async function getRecordsOrCountByCriterion(objectApiName, criterion, order, ignoreBackLookupField, fieldApiNames, offset, limit, needCount, authType) {
219
265
  if (limit > 10000) {
220
266
  limit = 10000;
221
267
  }
@@ -238,6 +284,11 @@ async function getRecordsOrCountByCriterion(objectApiName, criterion, order, ign
238
284
  "need_filter_user_permission": false,
239
285
  "need_total_count": needCount,
240
286
  };
287
+ authType = (0, utils_1.formatAuthType)(authType);
288
+ options.headers["User"] = utils.getUserIDFromCtx() + "";
289
+ if (authType) {
290
+ options.headers[constants_3.AuthTypeHttpHeader] = authType;
291
+ }
241
292
  let data = await openapi.doRequest(null, urlPath, options);
242
293
  return handleResponse(data, needCount);
243
294
  }
@@ -484,7 +535,7 @@ async function terminateWorkflowInstance(workflowInstanceId, operator, reason) {
484
535
  };
485
536
  await openapi.doRequest(null, urlPath, options);
486
537
  }
487
- async function modifyRecordsWithTransaction(placeholders, operations) {
538
+ async function modifyRecordsWithTransaction(placeholders, operations, authType) {
488
539
  // 1.获取 options
489
540
  let options = commonHttp.getOptions(null, openapiHttpPath.modifyRecordsWithTransaction);
490
541
  let urlPath = options._reqPath.replace(replaceKeys.namespace, await (0, common_1.getNamespaceForOpenAndFaaSSDK)());
@@ -495,6 +546,11 @@ async function modifyRecordsWithTransaction(placeholders, operations) {
495
546
  "operatorId": utils.getUserIDFromCtx(),
496
547
  "setSystemField": 1,
497
548
  };
549
+ authType = (0, utils_1.formatAuthType)(authType);
550
+ options.headers["User"] = utils.getUserIDFromCtx() + "";
551
+ if (authType) {
552
+ options.headers[constants_3.AuthTypeHttpHeader] = authType;
553
+ }
498
554
  let taskId = utils.getTriggerTaskID();
499
555
  if (taskId) {
500
556
  options.json["taskId"] = taskId;
@@ -508,7 +564,6 @@ async function modifyRecordsWithTransaction(placeholders, operations) {
508
564
  }
509
565
  return retPlaceholders;
510
566
  }
511
- ;
512
567
  async function getGlobalConfigByKey(key) {
513
568
  // 1.获取 options
514
569
  let options = commonHttp.getOptions(null, openapiHttpPath.getAllGlobalConfigs);
@@ -536,7 +591,7 @@ async function getGlobalConfigByKey(key) {
536
591
  }
537
592
  throw new exceptions.InvalidParamError(`undefined global variable (${key})`);
538
593
  }
539
- async function oql(oql, args, namedArgs) {
594
+ async function oql(oql, args, namedArgs, authType) {
540
595
  // 1.获取 options
541
596
  let options = commonHttp.getOptions(null, constants_2.openapiHttpPath.oql);
542
597
  let urlPath = options._reqPath.replace(replaceKeys.namespace, await (0, common_1.getNamespaceForOpenAndFaaSSDK)());
@@ -547,6 +602,11 @@ async function oql(oql, args, namedArgs) {
547
602
  "namedArgs": namedArgs,
548
603
  "compat": true,
549
604
  };
605
+ authType = (0, utils_1.formatAuthType)(authType);
606
+ options.headers["User"] = utils.getUserIDFromCtx() + "";
607
+ if (authType) {
608
+ options.headers[constants_3.AuthTypeHttpHeader] = authType;
609
+ }
550
610
  let result = await openapi.doRequest(null, urlPath, options);
551
611
  if (result && result.rows) {
552
612
  return result.rows;
@@ -715,25 +775,25 @@ class RequestHttp {
715
775
  }
716
776
  updateWorkflowVariables(ctx, instanceId, variables, variableTypes) {
717
777
  }
718
- createRecordBySync(objectApiName, record) {
778
+ createRecordBySync(objectApiName, record, authType) {
719
779
  }
720
- updateRecordBySync(objectApiName, recordID, record) {
780
+ updateRecordBySync(objectApiName, recordID, record, authType) {
721
781
  }
722
- deleteRecordBySync(objectApiName, recordID) {
782
+ deleteRecordBySync(objectApiName, recordID, authType) {
723
783
  }
724
- createRecordsByAsync(objectApiName, records) {
784
+ createRecordsByAsync(objectApiName, records, authType) {
725
785
  }
726
- updateRecordsByAsync(objectApiName, recordMap) {
786
+ updateRecordsByAsync(objectApiName, recordMap, authType) {
727
787
  }
728
- deleteRecordsByAsync(objectApiName, recordIDs) {
788
+ deleteRecordsByAsync(objectApiName, recordIDs, authType) {
729
789
  }
730
- createRecordsBySync(objectApiName, records) {
790
+ createRecordsBySync(objectApiName, records, authType) {
731
791
  }
732
- updateRecordsBySync(objectApiName, recordMap) {
792
+ updateRecordsBySync(objectApiName, recordMap, authType) {
733
793
  }
734
- deleteRecordsBySync(objectApiName, recordIDs) {
794
+ deleteRecordsBySync(objectApiName, recordIDs, authType) {
735
795
  }
736
- getRecordsOrCountByCriterion(objectApiName, criterion, order, ignoreBackLookupField, fieldApiNames, offset, limit, needCount) {
796
+ getRecordsOrCountByCriterion(objectApiName, criterion, order, ignoreBackLookupField, fieldApiNames, offset, limit, needCount, authType) {
737
797
  }
738
798
  uploadFile(data, expire) {
739
799
  return null;
@@ -756,13 +816,13 @@ class RequestHttp {
756
816
  }
757
817
  terminateWorkflowInstance(workflowInstanceId, operator, reason) {
758
818
  }
759
- modifyRecordsWithTransaction(placeholders, operations) {
819
+ modifyRecordsWithTransaction(placeholders, operations, authType) {
760
820
  return null;
761
821
  }
762
822
  getGlobalConfigByKey(key) {
763
823
  return null;
764
824
  }
765
- oql(oql, args, namedArgs) {
825
+ oql(oql, args, namedArgs, authType) {
766
826
  }
767
827
  async invokeFuncSync(idOrName, params) {
768
828
  return await invokeFuncSync(idOrName, params);