@byted-apaas/server-sdk-node 1.0.14 → 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.
package/README.md CHANGED
@@ -1,7 +1,27 @@
1
1
  ## aPaaS @byted-apaas/server-sdk-node 版本说明:
2
2
 
3
3
  -------
4
- ### 版本:1.0.13|兼容升级
4
+ ### 版本:1.0.15|兼容升级
5
+ 新功能:数据操作接口支持指定鉴权身份
6
+ - 不指定: 访问数据模型时, 权限 1.0 应用默认使用系统身份鉴权, 权限 2.0 应用默认使用用户身份鉴权
7
+ - useUserAuth(): 访问数据模型时, 使用用户身份鉴权
8
+ - useSystemAuth(): 访问数据模型时, 使用系统身份鉴权
9
+ ```js
10
+ // 示例
11
+ await context.db.object("obj").findOne();
12
+ await context.db.object("obj").useUserAuth().findOne();
13
+ await context.db.object("obj").useSystemAuth().findOne();
14
+
15
+ await context.db.newTransaction().object("obj").commit();
16
+ await context.db.newTransaction().useUserAuth().object("obj").commit();
17
+ await context.db.newTransaction().useSystemAuth().object("obj").commit();
18
+
19
+ await context.db.oql("SELECT _id FROM obj").execute();
20
+ await context.db.oql("SELECT _id FROM obj").useUserAuth().execute();
21
+ await context.db.oql("SELECT _id FROM obj").useSystemAuth().execute();
22
+ ```
23
+
24
+ ### 版本:1.0.14|兼容升级
5
25
  新功能:支持流式查询 findStream
6
26
  ```js
7
27
  await context.db.object("_user").findStream(async (records) => {
@@ -86,6 +86,14 @@ export interface _IKSyncEndpoint<T> {
86
86
  * @paramExample [{_id: 1001, _name: "John", gender: "male"}, {_id: 1002, _name: "Alis", gender: "female"}]
87
87
  */
88
88
  batchUpdate(recordMapList: _Cond<T>[]): Promise<void>;
89
+ /**
90
+ * 用户级鉴权
91
+ */
92
+ useUserAuth(): this;
93
+ /**
94
+ * 系统级鉴权
95
+ */
96
+ useSystemAuth(): this;
89
97
  }
90
98
  export interface _IKAsyncEndpoint<T> {
91
99
  /**
@@ -118,6 +126,14 @@ export interface _IKAsyncEndpoint<T> {
118
126
  batchUpdateAsync(recordMapList: _Cond<T>[]): Promise<{
119
127
  taskID: number;
120
128
  }>;
129
+ /**
130
+ * 用户级鉴权
131
+ */
132
+ useUserAuth(): this;
133
+ /**
134
+ * 系统级鉴权
135
+ */
136
+ useSystemAuth(): this;
121
137
  }
122
138
  export interface _IKQuery<T> {
123
139
  /**
@@ -261,4 +277,12 @@ export interface _IKQuery<T> {
261
277
  * ```
262
278
  */
263
279
  count(): Promise<number>;
280
+ /**
281
+ * 用户级鉴权
282
+ */
283
+ useUserAuth(): this;
284
+ /**
285
+ * 系统级鉴权
286
+ */
287
+ useSystemAuth(): this;
264
288
  }
@@ -23,6 +23,7 @@ export declare class _KApplicationObject<T> {
23
23
  declare class _KObjectSync<T> implements _IKSyncEndpoint<T> {
24
24
  apiName: string;
25
25
  appCtx: AppCtx;
26
+ authType: string;
26
27
  create(recordMap: _Cond<T>): Promise<{
27
28
  _id: number;
28
29
  }>;
@@ -34,9 +35,12 @@ declare class _KObjectSync<T> implements _IKSyncEndpoint<T> {
34
35
  batchDelete(recordIdList: number[]): Promise<void>;
35
36
  batchDelete(recordList: _Cond<T>[]): Promise<void>;
36
37
  batchUpdate(recordMapList: _Cond<T>[]): Promise<void>;
38
+ useUserAuth(): this;
39
+ useSystemAuth(): this;
37
40
  }
38
41
  declare class _KObjectAsync<T> implements _IKAsyncEndpoint<T> {
39
42
  apiName: string;
43
+ authType: string;
40
44
  batchCreateAsync(recordMapList: _Cond<T>[]): Promise<{
41
45
  taskID: number;
42
46
  }>;
@@ -49,10 +53,13 @@ declare class _KObjectAsync<T> implements _IKAsyncEndpoint<T> {
49
53
  batchUpdateAsync(recordMapList: _Cond<T>[]): Promise<{
50
54
  taskID: number;
51
55
  }>;
56
+ useUserAuth(): this;
57
+ useSystemAuth(): this;
52
58
  }
53
59
  declare class _KObjectQuery<T> implements _IKQuery<T> {
54
60
  apiName: string;
55
61
  appCtx: AppCtx;
62
+ authType: string;
56
63
  find(): Promise<_Record<T>[]>;
57
64
  findOne(): Promise<_Record<T>>;
58
65
  findAll(): Promise<_Record<T>[]>;
@@ -68,12 +75,15 @@ declare class _KObjectQuery<T> implements _IKQuery<T> {
68
75
  limit(limit: number): _KQuery<T>;
69
76
  offset(offset: number): _KQuery<T>;
70
77
  count(): Promise<number>;
78
+ useSystemAuth(): this;
79
+ useUserAuth(): this;
71
80
  }
72
81
  /**
73
82
  * _KQuery is kunlun query implement, implements ORM operations.
74
83
  */
75
84
  declare class _KQuery<T> implements _IKQuery<T> {
76
- constructor(objectApiName: string, appCtx?: AppCtx);
85
+ private authType;
86
+ constructor(objectApiName: string, appCtx?: AppCtx, authType?: string);
77
87
  find(): Promise<_Record<T>[]>;
78
88
  findOne(): Promise<_Record<T>>;
79
89
  /**
@@ -96,5 +106,7 @@ declare class _KQuery<T> implements _IKQuery<T> {
96
106
  offset(offset: number): this;
97
107
  count(): Promise<number>;
98
108
  private findPreCheck;
109
+ useSystemAuth(): this;
110
+ useUserAuth(): this;
99
111
  }
100
112
  export {};
@@ -12,6 +12,7 @@ const propertiesStore_1 = require("./propertiesStore");
12
12
  const common_1 = require("../../../application/impl/common");
13
13
  const logicV2_1 = require("../../../kunlun/operator/impl/logicV2");
14
14
  const operator_1 = require("../../../kunlun/operator/impl/operator");
15
+ const constants_1 = require("@byted-apaas/server-common-node/constants/constants");
15
16
  const queryPropertiesStore = new propertiesStore_1.default();
16
17
  // _KObject will be Mixin with [_KObjectSync, _KObjectAsync, _KObjectQuery]
17
18
  class _KObject {
@@ -52,7 +53,7 @@ class _KObjectSync {
52
53
  return await Request.GetInstance().openSDKCreateRecordBySync(this.apiName, recordMap);
53
54
  });
54
55
  }
55
- return await Request.GetInstance().createRecordBySync(this.apiName, recordMap);
56
+ return await Request.GetInstance().createRecordBySync(this.apiName, recordMap, this.authType);
56
57
  }
57
58
  ;
58
59
  async delete(recordOrRecordID) {
@@ -79,7 +80,7 @@ class _KObjectSync {
79
80
  return await Request.GetInstance().openSDKDeleteRecordBySync(this.apiName, recordID);
80
81
  });
81
82
  }
82
- return await Request.GetInstance().deleteRecordBySync(this.apiName, recordID);
83
+ return await Request.GetInstance().deleteRecordBySync(this.apiName, recordID, this.authType);
83
84
  }
84
85
  throw new server_common_node_1.exceptions.InvalidParamError("record must be number or object");
85
86
  }
@@ -115,7 +116,7 @@ class _KObjectSync {
115
116
  return await Request.GetInstance().openSDKUpdateRecordBySync(this.apiName, recordID, record);
116
117
  });
117
118
  }
118
- return await Request.GetInstance().updateRecordBySync(this.apiName, recordID, record);
119
+ return await Request.GetInstance().updateRecordBySync(this.apiName, recordID, record, this.authType);
119
120
  }
120
121
  ;
121
122
  // batch sync
@@ -135,7 +136,7 @@ class _KObjectSync {
135
136
  let data = (this.appCtx && this.appCtx.mode == 'openSDK') ?
136
137
  await (0, common_1.runCtxForOpenSDK)(this.appCtx, async () => {
137
138
  return await Request.GetInstance().openSDKCreateRecordsBySync(this.apiName, recordMapList);
138
- }) : await Request.GetInstance().createRecordsBySync(this.apiName, recordMapList);
139
+ }) : await Request.GetInstance().createRecordsBySync(this.apiName, recordMapList, this.authType);
139
140
  // todo: 确定函数返回值
140
141
  if (!(data instanceof Array) && data["record_ids"]) {
141
142
  return data["record_ids"];
@@ -169,7 +170,7 @@ class _KObjectSync {
169
170
  return await Request.GetInstance().openSDKDeleteRecordsBySync(this.apiName, recordIDs);
170
171
  });
171
172
  }
172
- return await Request.GetInstance().deleteRecordsBySync(this.apiName, recordIDs);
173
+ return await Request.GetInstance().deleteRecordsBySync(this.apiName, recordIDs, this.authType);
173
174
  }
174
175
  async batchUpdate(recordMapList) {
175
176
  // 参数校验、组装
@@ -193,9 +194,17 @@ class _KObjectSync {
193
194
  return await Request.GetInstance().openSDKUpdateRecordsBySync(this.apiName, recordMapList);
194
195
  });
195
196
  }
196
- return await Request.GetInstance().updateRecordsBySync(this.apiName, recordMap);
197
+ return await Request.GetInstance().updateRecordsBySync(this.apiName, recordMap, this.authType);
197
198
  }
198
199
  ;
200
+ useUserAuth() {
201
+ this.authType = constants_1.AuthTypeUser;
202
+ return this;
203
+ }
204
+ useSystemAuth() {
205
+ this.authType = constants_1.AuthTypeSystem;
206
+ return this;
207
+ }
199
208
  }
200
209
  class _KObjectAsync {
201
210
  constructor() {
@@ -221,7 +230,7 @@ class _KObjectAsync {
221
230
  if (server_common_node_1.utils.stringify(recordMapList).length > 50 * 1024 * 1024) {
222
231
  throw new server_common_node_1.exceptions.InvalidParamError("parameter records size exceeds 50MB");
223
232
  }
224
- return await Request.GetInstance().createRecordsByAsync(this.apiName, recordMapList);
233
+ return await Request.GetInstance().createRecordsByAsync(this.apiName, recordMapList, this.authType);
225
234
  }
226
235
  ;
227
236
  async batchDeleteAsync(recordOrIDList) {
@@ -250,7 +259,7 @@ class _KObjectAsync {
250
259
  if (server_common_node_1.utils.stringify(recordIDs).length > 50 * 1024 * 1024) {
251
260
  throw new server_common_node_1.exceptions.InvalidParamError("parameter records size exceeds 50MB");
252
261
  }
253
- return await Request.GetInstance().deleteRecordsByAsync(this.apiName, recordIDs);
262
+ return await Request.GetInstance().deleteRecordsByAsync(this.apiName, recordIDs, this.authType);
254
263
  }
255
264
  async batchUpdateAsync(recordMapList) {
256
265
  // 参数校验、组装
@@ -280,9 +289,17 @@ class _KObjectAsync {
280
289
  if (server_common_node_1.utils.stringify(recordMap).length > 50 * 1024 * 1024) {
281
290
  throw new server_common_node_1.exceptions.InvalidParamError("parameter records size exceeds 50MB");
282
291
  }
283
- return await Request.GetInstance().updateRecordsByAsync(this.apiName, recordMap);
292
+ return await Request.GetInstance().updateRecordsByAsync(this.apiName, recordMap, this.authType);
284
293
  }
285
294
  ;
295
+ useUserAuth() {
296
+ this.authType = constants_1.AuthTypeUser;
297
+ return this;
298
+ }
299
+ useSystemAuth() {
300
+ this.authType = constants_1.AuthTypeSystem;
301
+ return this;
302
+ }
286
303
  }
287
304
  class _KObjectQuery {
288
305
  constructor() {
@@ -290,15 +307,15 @@ class _KObjectQuery {
290
307
  }
291
308
  // find, findOne
292
309
  async find() {
293
- return new _KQuery(this.apiName, this.appCtx).find();
310
+ return new _KQuery(this.apiName, this.appCtx, this.authType).find();
294
311
  }
295
312
  ;
296
313
  async findOne() {
297
- return new _KQuery(this.apiName, this.appCtx).findOne();
314
+ return new _KQuery(this.apiName, this.appCtx, this.authType).findOne();
298
315
  }
299
316
  ;
300
317
  async findAll() {
301
- return new _KQuery(this.apiName, this.appCtx).findAll();
318
+ return new _KQuery(this.apiName, this.appCtx, this.authType).findAll();
302
319
  }
303
320
  ;
304
321
  async findStream(handler) {
@@ -306,42 +323,52 @@ class _KObjectQuery {
306
323
  }
307
324
  orderBy(fieldApiNames, ...restFieldApiNames) {
308
325
  fieldApiNames = !fieldApiNames ? [] : fieldApiNames;
309
- return new _KQuery(this.apiName, this.appCtx).orderBy(server_common_node_1.utils.argsToList(fieldApiNames, restFieldApiNames));
326
+ return new _KQuery(this.apiName, this.appCtx, this.authType).orderBy(server_common_node_1.utils.argsToList(fieldApiNames, restFieldApiNames));
310
327
  }
311
328
  orderByDesc(fieldApiNames, ...restFieldApiNames) {
312
329
  fieldApiNames = !fieldApiNames ? [] : fieldApiNames;
313
- return new _KQuery(this.apiName, this.appCtx).orderByDesc(server_common_node_1.utils.argsToList(fieldApiNames, restFieldApiNames));
330
+ return new _KQuery(this.apiName, this.appCtx, this.authType).orderByDesc(server_common_node_1.utils.argsToList(fieldApiNames, restFieldApiNames));
314
331
  }
315
332
  select(fieldApiNames, ...restFieldApiNames) {
316
333
  fieldApiNames = !fieldApiNames ? [] : fieldApiNames;
317
- return new _KQuery(this.apiName, this.appCtx).select(server_common_node_1.utils.argsToList(fieldApiNames, restFieldApiNames));
334
+ return new _KQuery(this.apiName, this.appCtx, this.authType).select(server_common_node_1.utils.argsToList(fieldApiNames, restFieldApiNames));
318
335
  }
319
336
  where(conditionMap) {
320
337
  if (!conditionMap) {
321
- return new _KQuery(this.apiName, this.appCtx).where();
338
+ return new _KQuery(this.apiName, this.appCtx, this.authType).where();
322
339
  }
323
- return new _KQuery(this.apiName, this.appCtx).where(conditionMap);
340
+ return new _KQuery(this.apiName, this.appCtx, this.authType).where(conditionMap);
324
341
  }
325
342
  // limit, offset, count
326
343
  limit(limit) {
327
- return new _KQuery(this.apiName, this.appCtx).limit(limit);
344
+ return new _KQuery(this.apiName, this.appCtx, this.authType).limit(limit);
328
345
  }
329
346
  ;
330
347
  offset(offset) {
331
- return new _KQuery(this.apiName, this.appCtx).offset(offset);
348
+ return new _KQuery(this.apiName, this.appCtx, this.authType).offset(offset);
332
349
  }
333
350
  ;
334
351
  async count() {
335
- return new _KQuery(this.apiName, this.appCtx).count();
352
+ return new _KQuery(this.apiName, this.appCtx, this.authType).count();
336
353
  }
337
354
  ;
355
+ useSystemAuth() {
356
+ this.authType = constants_1.AuthTypeSystem;
357
+ return this;
358
+ }
359
+ useUserAuth() {
360
+ this.authType = constants_1.AuthTypeUser;
361
+ return this;
362
+ }
338
363
  }
339
364
  /**
340
365
  * _KQuery is kunlun query implement, implements ORM operations.
341
366
  */
342
367
  class _KQuery {
343
- // 使用请求上下文和对象 Api Name 进行初始化
344
- constructor(objectApiName, appCtx = null) {
368
+ constructor(objectApiName, appCtx = null, authType = null) {
369
+ if (authType) {
370
+ this.authType = authType;
371
+ }
345
372
  if (!objectApiName) {
346
373
  throw new server_common_node_1.exceptions.InvalidParamError("objectApiName is empty");
347
374
  }
@@ -370,7 +397,7 @@ class _KQuery {
370
397
  }
371
398
  else {
372
399
  const criterion = (0, logic_1.buildCriterion)(queryBuilder.getLogic(), apiName);
373
- return await Request.GetInstance().getRecordsOrCountByCriterion(apiName, await (0, logic_1.handleCriterion)(criterion), queryBuilder.getOrder(), false, queryBuilder.getSelect(), queryBuilder.getOffset(), queryBuilder.getLimit(), false);
400
+ return await Request.GetInstance().getRecordsOrCountByCriterion(apiName, await (0, logic_1.handleCriterion)(criterion), queryBuilder.getOrder(), false, queryBuilder.getSelect(), queryBuilder.getOffset(), queryBuilder.getLimit(), false, this.authType);
374
401
  }
375
402
  }
376
403
  ;
@@ -455,7 +482,7 @@ class _KQuery {
455
482
  }
456
483
  else {
457
484
  let criterion = (0, logic_1.buildCriterion)(queryBuilder.getLogic(), apiName, maxId);
458
- rs = await Request.GetInstance().getRecordsOrCountByCriterion(apiName, await (0, logic_1.handleCriterion)(criterion), [new order_1.Order("_id", "asc")], false, queryBuilder.getSelect(), 0, newLimit, false);
485
+ rs = await Request.GetInstance().getRecordsOrCountByCriterion(apiName, await (0, logic_1.handleCriterion)(criterion), [new order_1.Order("_id", "asc")], false, queryBuilder.getSelect(), 0, newLimit, false, this.authType);
459
486
  }
460
487
  queryCount += rs.length;
461
488
  rs.forEach((r) => {
@@ -525,7 +552,7 @@ class _KQuery {
525
552
  }
526
553
  else {
527
554
  let criterion = (0, logic_1.buildCriterion)(queryBuilder.getLogic(), apiName, maxId);
528
- rs = await Request.GetInstance().getRecordsOrCountByCriterion(apiName, await (0, logic_1.handleCriterion)(criterion), orders, false, selectFields, i, newLimit, false);
555
+ rs = await Request.GetInstance().getRecordsOrCountByCriterion(apiName, await (0, logic_1.handleCriterion)(criterion), orders, false, selectFields, i, newLimit, false, this.authType);
529
556
  }
530
557
  queryCount += rs.length;
531
558
  try {
@@ -563,7 +590,7 @@ class _KQuery {
563
590
  }
564
591
  else {
565
592
  let criterion = (0, logic_1.buildCriterion)(queryBuilder.getLogic(), apiName, maxId);
566
- rs = await Request.GetInstance().getRecordsOrCountByCriterion(apiName, await (0, logic_1.handleCriterion)(criterion), [new order_1.Order("_id", "asc")], false, queryBuilder.getSelect(), 0, queryBuilder_1.defaultLimit, false);
593
+ rs = await Request.GetInstance().getRecordsOrCountByCriterion(apiName, await (0, logic_1.handleCriterion)(criterion), [new order_1.Order("_id", "asc")], false, queryBuilder.getSelect(), 0, queryBuilder_1.defaultLimit, false, this.authType);
567
594
  }
568
595
  rs.forEach((r) => {
569
596
  maxId = r._id > maxId ? r._id : maxId;
@@ -675,7 +702,7 @@ class _KQuery {
675
702
  }
676
703
  else {
677
704
  let criterion = (0, logic_1.buildCriterion)(queryBuilder.getLogic(), apiName);
678
- return await Request.GetInstance().getRecordsOrCountByCriterion(apiName, await (0, logic_1.handleCriterion)(criterion), queryBuilder.getOrder(), false, queryBuilder.getSelect(), queryBuilder.getOffset(), queryBuilder.getLimit(), true);
705
+ return await Request.GetInstance().getRecordsOrCountByCriterion(apiName, await (0, logic_1.handleCriterion)(criterion), queryBuilder.getOrder(), false, queryBuilder.getSelect(), queryBuilder.getOffset(), queryBuilder.getLimit(), true, this.authType);
679
706
  }
680
707
  }
681
708
  ;
@@ -693,6 +720,14 @@ class _KQuery {
693
720
  throw new server_common_node_1.exceptions.InvalidParamError(`limit(${limit}) < 1`);
694
721
  }
695
722
  }
723
+ useSystemAuth() {
724
+ this.authType = constants_1.AuthTypeSystem;
725
+ return this;
726
+ }
727
+ useUserAuth() {
728
+ this.authType = constants_1.AuthTypeUser;
729
+ return this;
730
+ }
696
731
  }
697
732
  function applyMixins(derivedCtor, constructors) {
698
733
  constructors.forEach((baseCtor) => {
@@ -3,4 +3,12 @@ export interface IOql {
3
3
  * 执行 OQL
4
4
  */
5
5
  execute(): Promise<any | any[]>;
6
+ /**
7
+ * 用户级鉴权
8
+ */
9
+ useUserAuth(): IOql;
10
+ /**
11
+ * 系统级鉴权
12
+ */
13
+ useSystemAuth(): IOql;
6
14
  }
@@ -3,7 +3,10 @@ export declare class Oql implements IOql {
3
3
  oql: string;
4
4
  params: any[];
5
5
  namedParams: Record<string, any>;
6
+ authType: string;
6
7
  constructor(oql: string);
7
8
  constructor(oql: string, namedArgs: Record<string, any>);
8
9
  execute(): Promise<any[]>;
10
+ useSystemAuth(): IOql;
11
+ useUserAuth(): IOql;
9
12
  }
@@ -4,6 +4,7 @@
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
5
  exports.Oql = void 0;
6
6
  const Request = require("../../../../request/interface");
7
+ const constants_1 = require("@byted-apaas/server-common-node/constants/constants");
7
8
  class Oql {
8
9
  constructor(oql, namedArgs) {
9
10
  this.oql = oql;
@@ -15,11 +16,19 @@ class Oql {
15
16
  }
16
17
  }
17
18
  async execute() {
18
- let records = await Request.GetInstance().oql(this.oql, this.params, this.namedParams);
19
+ let records = await Request.GetInstance().oql(this.oql, this.params, this.namedParams, this.authType);
19
20
  if (records && Array.isArray(records)) {
20
21
  return records;
21
22
  }
22
23
  return [];
23
24
  }
25
+ useSystemAuth() {
26
+ this.authType = constants_1.AuthTypeSystem;
27
+ return this;
28
+ }
29
+ useUserAuth() {
30
+ this.authType = constants_1.AuthTypeUser;
31
+ return this;
32
+ }
24
33
  }
25
34
  exports.Oql = Oql;
@@ -11,10 +11,13 @@ export declare class Transaction<T, mt> implements ITransaction<mt>, ITransactio
11
11
  operations: TransactionOperation[];
12
12
  uuid2result: Record<string, uuidOrRecordIDResult>;
13
13
  isCommit: boolean;
14
+ authType: string;
14
15
  batchResults: (string | number)[][];
15
16
  constructor(objectApiName: string);
16
17
  currentObject(): TransactionObject<mt[currentObjApiName]>;
17
18
  object<T extends keyof mt>(objectApiName: T): TransactionObject<mt[T]>;
18
19
  commit(): Promise<void>;
20
+ useSystemAuth(): this;
21
+ useUserAuth(): this;
19
22
  }
20
23
  export {};
@@ -6,6 +6,7 @@ exports.Transaction = void 0;
6
6
  const server_common_node_1 = require("@byted-apaas/server-common-node");
7
7
  const Request = require("../../../../request/interface");
8
8
  const operation_1 = require("./operation");
9
+ const constants_1 = require("@byted-apaas/server-common-node/constants/constants");
9
10
  const assert = require('assert');
10
11
  const { v4: uuidv4 } = require("uuid");
11
12
  class Transaction {
@@ -216,7 +217,7 @@ class Transaction {
216
217
  if (!this.operations || this.operations.length === 0) {
217
218
  return;
218
219
  }
219
- let uuid2recordId = await Request.GetInstance().modifyRecordsWithTransaction(this.placeholders, this.operations);
220
+ let uuid2recordId = await Request.GetInstance().modifyRecordsWithTransaction(this.placeholders, this.operations, this.authType);
220
221
  if (!uuid2recordId) {
221
222
  throw new server_common_node_1.exceptions.InternalError("uuid2recordId is empty");
222
223
  }
@@ -255,6 +256,14 @@ class Transaction {
255
256
  }
256
257
  }
257
258
  }
259
+ useSystemAuth() {
260
+ this.authType = constants_1.AuthTypeSystem;
261
+ return this;
262
+ }
263
+ useUserAuth() {
264
+ this.authType = constants_1.AuthTypeUser;
265
+ return this;
266
+ }
258
267
  }
259
268
  exports.Transaction = Transaction;
260
269
  function deepEqualExceptID(left, right) {
@@ -13,6 +13,14 @@ export interface ITransaction<mt> {
13
13
  * 提交事务
14
14
  */
15
15
  commit(): Promise<void>;
16
+ /**
17
+ * 用户级鉴权
18
+ */
19
+ useUserAuth(): this;
20
+ /**
21
+ * 系统级鉴权
22
+ */
23
+ useSystemAuth(): this;
16
24
  }
17
25
  export interface ITransactionWithCurrentObject<mt> {
18
26
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@byted-apaas/server-sdk-node",
3
- "version": "1.0.14",
3
+ "version": "1.0.15",
4
4
  "description": "aPaaS Server SDK",
5
5
  "author": "zhouwexin <zhouwexin@bytedance.com>",
6
6
  "homepage": "",
@@ -12,7 +12,7 @@
12
12
  "pre-build": "rm -rf build && tsc"
13
13
  },
14
14
  "dependencies": {
15
- "@byted-apaas/server-common-node": "^1.0.12",
15
+ "@byted-apaas/server-common-node": "^1.0.13",
16
16
  "@jorgeferrero/stream-to-buffer": "^2.0.6",
17
17
  "dayjs": "^1.9.6",
18
18
  "form-data": "^3.0.0",
@@ -8,16 +8,16 @@ import { ExecutionInfo, ExecutionResult, RevokeExecutionOptions } from "@byted-a
8
8
  import { AppCtx } from "../application/application";
9
9
  export declare class RequestRpc implements IInnerAPIRequest {
10
10
  constructor();
11
- createRecordBySync(objectApiName: string, record: object): any;
12
- updateRecordBySync(objectApiName: string, recordID: number, record: object): any;
13
- deleteRecordBySync(objectApiName: string, recordID: number): any;
14
- createRecordsByAsync(objectApiName: string, records: object[]): any;
15
- updateRecordsByAsync(objectApiName: string, recordMap: Record<number, object>): any;
16
- deleteRecordsByAsync(objectApiName: string, recordIDs: number[]): any;
17
- createRecordsBySync(objectApiName: string, records: object[]): any;
18
- updateRecordsBySync(objectApiName: string, recordMap: Record<number, object>): any;
19
- deleteRecordsBySync(objectApiName: string, recordIDs: number[]): any;
20
- getRecordsOrCountByCriterion(objectApiName: string, criterion: string | Criterion, order: Order[], ignoreBackLookupField: boolean, fieldApiNames: string[], offset: number, limit: number, needCount: boolean): any;
11
+ createRecordBySync(objectApiName: string, record: object, authType: string): any;
12
+ updateRecordBySync(objectApiName: string, recordID: number, record: object, authType: string): any;
13
+ deleteRecordBySync(objectApiName: string, recordID: number, authType: string): any;
14
+ createRecordsByAsync(objectApiName: string, records: object[], authType: string): any;
15
+ updateRecordsByAsync(objectApiName: string, recordMap: Record<number, object>, authType: string): any;
16
+ deleteRecordsByAsync(objectApiName: string, recordIDs: number[], authType: string): any;
17
+ createRecordsBySync(objectApiName: string, records: object[], authType: string): any;
18
+ updateRecordsBySync(objectApiName: string, recordMap: Record<number, object>, authType: string): any;
19
+ deleteRecordsBySync(objectApiName: string, recordIDs: number[], authType: string): any;
20
+ getRecordsOrCountByCriterion(objectApiName: string, criterion: string | Criterion, order: Order[], ignoreBackLookupField: boolean, fieldApiNames: string[], offset: number, limit: number, needCount: boolean, authType: string): any;
21
21
  updateWorkflowVariables(ctx: any, instanceId: number, variables: object, variableTypes: object): Promise<void>;
22
22
  uploadFile(data: Stream, expire: number): Promise<UploadFileResp>;
23
23
  downloadFileByID(fileID: string, filePath?: string): Promise<Buffer | void>;
@@ -27,9 +27,9 @@ export declare class RequestRpc implements IInnerAPIRequest {
27
27
  getFields(objectApiName: string): Promise<any>;
28
28
  getField(objectApiName: string, fieldApiName: string): Promise<any>;
29
29
  terminateWorkflowInstance(workflowInstanceId: number, operator: number, reason: string): Promise<void>;
30
- modifyRecordsWithTransaction(placeholders: Record<string, number>, operations: object[]): Promise<Map<string, number>>;
30
+ modifyRecordsWithTransaction(placeholders: Record<string, number>, operations: object[], authType: string): Promise<Map<string, number>>;
31
31
  getGlobalConfigByKey<valueT>(key: string): Promise<valueT>;
32
- oql(oql: string, args: any[], namedArgs: Record<string, any>): Promise<string | any[]>;
32
+ oql(oql: string, args: any[], namedArgs: Record<string, any>, authType: string): Promise<string | any[]>;
33
33
  invokeFuncSync(idOrName: {
34
34
  APIId?: string;
35
35
  APIName?: string;
@@ -14,10 +14,10 @@ const utils = common.utils;
14
14
  const fs = require("fs");
15
15
  const checkUtils = common.checkUtils;
16
16
  const path = require('path');
17
- async function pre(isTransUser) {
17
+ async function pre(isTransUser, authType) {
18
18
  let ctx;
19
19
  try {
20
- ctx = await rpc.rebuildRpcCtx(isTransUser);
20
+ ctx = await rpc.rebuildRpcCtx(isTransUser, authType);
21
21
  }
22
22
  catch (err) {
23
23
  throw new exceptions.InternalError(`RebuildRpcCtx failed: ${err.message}`);
@@ -33,19 +33,19 @@ function post(baseResp) {
33
33
  if (baseResp.StatusMessage !== "") {
34
34
  msg = baseResp.StatusMessage;
35
35
  }
36
- if (baseResp.extra["is_system_error"] === "true") {
36
+ if (baseResp.extra.get("is_system_error") === "true") {
37
37
  throw new exceptions.InternalError(`${msg} [${baseResp.KStatusCode}]`);
38
38
  }
39
39
  throw new exceptions.InvalidParamError(`${msg} [${baseResp.KStatusCode}]`);
40
40
  }
41
41
  }
42
- async function createRecordBySync(objectApiName, record) {
42
+ async function createRecordBySync(objectApiName, record, authType) {
43
43
  // 1.check
44
44
  if (!objectApiName) {
45
45
  throw new exceptions.InvalidParamError("objectApiName is empty");
46
46
  }
47
47
  // 2.前置处理
48
- let ctx = await pre();
48
+ let ctx = await pre(true, authType);
49
49
  // 3.构造 params
50
50
  let param = {};
51
51
  let task_id = utils.getTriggerTaskID();
@@ -68,13 +68,13 @@ async function createRecordBySync(objectApiName, record) {
68
68
  post(resp.BaseResp);
69
69
  return { _id: Number(resp.RecordID) };
70
70
  }
71
- async function updateRecordBySync(objectApiName, recordID, record) {
71
+ async function updateRecordBySync(objectApiName, recordID, record, authType) {
72
72
  // 1.check
73
73
  if (!objectApiName) {
74
74
  throw new exceptions.InvalidParamError("objectApiName is empty");
75
75
  }
76
76
  // 2.前置处理
77
- let ctx = await pre();
77
+ let ctx = await pre(true, authType);
78
78
  // 3.构造 params
79
79
  let param = {};
80
80
  let task_id = utils.getTriggerTaskID();
@@ -98,13 +98,13 @@ async function updateRecordBySync(objectApiName, recordID, record) {
98
98
  post(resp.BaseResp);
99
99
  return;
100
100
  }
101
- async function deleteRecordBySync(objectApiName, recordID) {
101
+ async function deleteRecordBySync(objectApiName, recordID, authType) {
102
102
  // 1.check
103
103
  if (!objectApiName) {
104
104
  throw new exceptions.InvalidParamError("objectApiName is empty");
105
105
  }
106
106
  // 2.前置处理
107
- let ctx = await pre();
107
+ let ctx = await pre(true, authType);
108
108
  // 3.构造 params
109
109
  let param = {};
110
110
  let task_id = utils.getTriggerTaskID();
@@ -127,13 +127,13 @@ async function deleteRecordBySync(objectApiName, recordID) {
127
127
  post(resp.BaseResp);
128
128
  return;
129
129
  }
130
- async function createRecordsByAsync(objectApiName, records) {
130
+ async function createRecordsByAsync(objectApiName, records, authType) {
131
131
  // 1.check
132
132
  if (!objectApiName) {
133
133
  throw new exceptions.InvalidParamError("objectApiName is empty");
134
134
  }
135
135
  // 2.前置处理
136
- let ctx = await pre();
136
+ let ctx = await pre(true, authType);
137
137
  // 3.构造 params
138
138
  let param = {};
139
139
  let task_id = utils.getTriggerTaskID();
@@ -156,13 +156,13 @@ async function createRecordsByAsync(objectApiName, records) {
156
156
  post(resp.BaseResp);
157
157
  return { taskID: Number(resp.TaskID) };
158
158
  }
159
- async function updateRecordsByAsync(objectApiName, recordMap) {
159
+ async function updateRecordsByAsync(objectApiName, recordMap, authType) {
160
160
  // 1.check
161
161
  if (!objectApiName) {
162
162
  throw new exceptions.InvalidParamError("objectApiName is empty");
163
163
  }
164
164
  // 2.前置处理
165
- let ctx = await pre();
165
+ let ctx = await pre(true, authType);
166
166
  // 3.构造 params
167
167
  let param = {};
168
168
  let task_id = utils.getTriggerTaskID();
@@ -185,13 +185,13 @@ async function updateRecordsByAsync(objectApiName, recordMap) {
185
185
  post(resp.BaseResp);
186
186
  return { taskID: Number(resp.TaskID) };
187
187
  }
188
- async function deleteRecordsByAsync(objectApiName, recordIDs) {
188
+ async function deleteRecordsByAsync(objectApiName, recordIDs, authType) {
189
189
  // 1.check
190
190
  if (!objectApiName) {
191
191
  throw new exceptions.InvalidParamError("objectApiName is empty");
192
192
  }
193
193
  // 2.前置处理
194
- let ctx = await pre();
194
+ let ctx = await pre(true, authType);
195
195
  // 3.构造 params
196
196
  let param = {};
197
197
  let task_id = utils.getTriggerTaskID();
@@ -218,13 +218,13 @@ async function deleteRecordsByAsync(objectApiName, recordIDs) {
218
218
  post(resp.BaseResp);
219
219
  return { taskID: Number(resp.TaskID) };
220
220
  }
221
- async function createRecordsBySync(objectApiName, records) {
221
+ async function createRecordsBySync(objectApiName, records, authType) {
222
222
  // 1.check
223
223
  if (!objectApiName) {
224
224
  throw new exceptions.InvalidParamError("objectApiName is empty");
225
225
  }
226
226
  // 2.前置处理
227
- let ctx = await pre();
227
+ let ctx = await pre(true, authType);
228
228
  // 3.构造 params
229
229
  let param = {};
230
230
  let task_id = utils.getTriggerTaskID();
@@ -247,25 +247,25 @@ async function createRecordsBySync(objectApiName, records) {
247
247
  // 5.后置处理
248
248
  post(resp.BaseResp);
249
249
  let recordIDList = new Array();
250
- let errMap = new Map();
250
+ let errMap = {};
251
251
  resp.RecordIDs.forEach((v, idx) => {
252
252
  recordIDList.push(Number(v));
253
253
  });
254
254
  resp.ErrMap.forEach((v, k) => {
255
- errMap.set(Number(k), v);
255
+ errMap[Number(k)] = v;
256
256
  });
257
257
  return {
258
258
  record_ids: recordIDList,
259
259
  err_map: errMap
260
260
  };
261
261
  }
262
- async function updateRecordsBySync(objectApiName, recordMap) {
262
+ async function updateRecordsBySync(objectApiName, recordMap, authType) {
263
263
  // 1.check
264
264
  if (!objectApiName) {
265
265
  throw new exceptions.InvalidParamError("objectApiName is empty");
266
266
  }
267
267
  // 2.前置处理
268
- let ctx = await pre();
268
+ let ctx = await pre(true, authType);
269
269
  // 3.构造 params
270
270
  let param = {};
271
271
  let task_id = utils.getTriggerTaskID();
@@ -287,19 +287,19 @@ async function updateRecordsBySync(objectApiName, recordMap) {
287
287
  }
288
288
  // 5.后置处理
289
289
  post(resp.BaseResp);
290
- let errMap = new Map();
290
+ let errMap = {};
291
291
  resp.ErrMap.forEach((v, k) => {
292
- errMap.set(Number(k), v);
292
+ errMap[Number(k)] = v;
293
293
  });
294
294
  return { err_map: errMap };
295
295
  }
296
- async function deleteRecordsBySync(objectApiName, recordIDs) {
296
+ async function deleteRecordsBySync(objectApiName, recordIDs, authType) {
297
297
  // 1.check
298
298
  if (!objectApiName) {
299
299
  throw new exceptions.InvalidParamError("objectApiName is empty");
300
300
  }
301
301
  // 2.前置处理
302
- let ctx = await pre();
302
+ let ctx = await pre(true, authType);
303
303
  // 3.构造 params
304
304
  let param = {};
305
305
  let task_id = utils.getTriggerTaskID();
@@ -325,13 +325,13 @@ async function deleteRecordsBySync(objectApiName, recordIDs) {
325
325
  }
326
326
  // 5.后置处理
327
327
  post(resp.BaseResp);
328
- let errMap = new Map();
328
+ let errMap = {};
329
329
  resp.ErrMap.forEach((v, k) => {
330
- errMap.set(Number(k), v);
330
+ errMap[Number(k)] = v;
331
331
  });
332
332
  return { err_map: errMap };
333
333
  }
334
- async function getRecordsOrCountByCriterion(objectApiName, criterion, order, ignoreBackLookupField, fieldApiNames, offset, limit, needCount) {
334
+ async function getRecordsOrCountByCriterion(objectApiName, criterion, order, ignoreBackLookupField, fieldApiNames, offset, limit, needCount, authType) {
335
335
  if (limit > 10000) {
336
336
  limit = 10000;
337
337
  }
@@ -340,7 +340,7 @@ async function getRecordsOrCountByCriterion(objectApiName, criterion, order, ign
340
340
  throw new exceptions.InvalidParamError("objectApiName is empty");
341
341
  }
342
342
  // 2.前置处理
343
- let ctx = await pre();
343
+ let ctx = await pre(true, authType);
344
344
  // 3.构造 params
345
345
  let param = {};
346
346
  let orders = new Array();
@@ -713,7 +713,7 @@ async function terminateWorkflowInstance(workflowInstanceId, operator, reason) {
713
713
  // 5. deal with response
714
714
  post(resp.BaseResp);
715
715
  }
716
- async function modifyRecordsWithTransaction(placeholders, operations) {
716
+ async function modifyRecordsWithTransaction(placeholders, operations, authType) {
717
717
  // 1. prepare args
718
718
  // TODO: change placeholders type
719
719
  let ph = new Map();
@@ -733,7 +733,7 @@ async function modifyRecordsWithTransaction(placeholders, operations) {
733
733
  param.TaskID = BigInt(taskID);
734
734
  }
735
735
  // 3. prepare request
736
- let ctx = await pre();
736
+ let ctx = await pre(true, authType);
737
737
  // 4. do request
738
738
  let resp;
739
739
  try {
@@ -782,7 +782,7 @@ async function getGlobalConfigByKey(key) {
782
782
  }
783
783
  throw new exceptions.InvalidParamError(`undefined global variable (${key})`);
784
784
  }
785
- async function oql(oql, args, namedArgs) {
785
+ async function oql(oql, args, namedArgs, authType) {
786
786
  // 1. build parameters
787
787
  const queryData = JSON.stringify({
788
788
  "query": oql,
@@ -795,7 +795,7 @@ async function oql(oql, args, namedArgs) {
795
795
  param.Namespace = await (0, common_1.getNamespaceForOpenAndFaaSSDK)();
796
796
  param.QueryData = Buffer.from(queryData);
797
797
  // 3. prepare request
798
- let ctx = await pre();
798
+ let ctx = await pre(true, authType);
799
799
  // 4. do request
800
800
  let resp;
801
801
  try {
@@ -1096,25 +1096,25 @@ class RequestRpc {
1096
1096
  this.openSDKUploadAvatar = openSDKUploadAvatar;
1097
1097
  this.openSDKDownloadAvatar = openSDKDownloadAvatar;
1098
1098
  }
1099
- createRecordBySync(objectApiName, record) {
1099
+ createRecordBySync(objectApiName, record, authType) {
1100
1100
  }
1101
- updateRecordBySync(objectApiName, recordID, record) {
1101
+ updateRecordBySync(objectApiName, recordID, record, authType) {
1102
1102
  }
1103
- deleteRecordBySync(objectApiName, recordID) {
1103
+ deleteRecordBySync(objectApiName, recordID, authType) {
1104
1104
  }
1105
- createRecordsByAsync(objectApiName, records) {
1105
+ createRecordsByAsync(objectApiName, records, authType) {
1106
1106
  }
1107
- updateRecordsByAsync(objectApiName, recordMap) {
1107
+ updateRecordsByAsync(objectApiName, recordMap, authType) {
1108
1108
  }
1109
- deleteRecordsByAsync(objectApiName, recordIDs) {
1109
+ deleteRecordsByAsync(objectApiName, recordIDs, authType) {
1110
1110
  }
1111
- createRecordsBySync(objectApiName, records) {
1111
+ createRecordsBySync(objectApiName, records, authType) {
1112
1112
  }
1113
- updateRecordsBySync(objectApiName, recordMap) {
1113
+ updateRecordsBySync(objectApiName, recordMap, authType) {
1114
1114
  }
1115
- deleteRecordsBySync(objectApiName, recordIDs) {
1115
+ deleteRecordsBySync(objectApiName, recordIDs, authType) {
1116
1116
  }
1117
- getRecordsOrCountByCriterion(objectApiName, criterion, order, ignoreBackLookupField, fieldApiNames, offset, limit, needCount) {
1117
+ getRecordsOrCountByCriterion(objectApiName, criterion, order, ignoreBackLookupField, fieldApiNames, offset, limit, needCount, authType) {
1118
1118
  }
1119
1119
  async updateWorkflowVariables(ctx, instanceId, variables, variableTypes) {
1120
1120
  }
@@ -1139,13 +1139,13 @@ class RequestRpc {
1139
1139
  }
1140
1140
  async terminateWorkflowInstance(workflowInstanceId, operator, reason) {
1141
1141
  }
1142
- async modifyRecordsWithTransaction(placeholders, operations) {
1142
+ async modifyRecordsWithTransaction(placeholders, operations, authType) {
1143
1143
  return null;
1144
1144
  }
1145
1145
  async getGlobalConfigByKey(key) {
1146
1146
  return null;
1147
1147
  }
1148
- async oql(oql, args, namedArgs) {
1148
+ async oql(oql, args, namedArgs, authType) {
1149
1149
  return [];
1150
1150
  }
1151
1151
  async invokeFuncSync(idOrName, params) {
@@ -32,16 +32,16 @@ export type OpenSDKGetRecordsReq = {
32
32
  export interface IInnerAPIRequest extends IInnerAPIBaseRequest, IInnerAPIOpenSDKRequest {
33
33
  }
34
34
  export interface IInnerAPIBaseRequest {
35
- createRecordBySync(objectApiName: string, record: object): any;
36
- updateRecordBySync(objectApiName: string, recordID: number, record: object): any;
37
- deleteRecordBySync(objectApiName: string, recordID: number): any;
38
- createRecordsByAsync(objectApiName: string, records: object[]): any;
39
- updateRecordsByAsync(objectApiName: string, recordMap: Record<number, object>): any;
40
- deleteRecordsByAsync(objectApiName: string, recordIDs: number[]): any;
41
- createRecordsBySync(objectApiName: string, records: object[]): any;
42
- updateRecordsBySync(objectApiName: string, recordMap: Record<number, object>): any;
43
- deleteRecordsBySync(objectApiName: string, recordIDs: number[]): any;
44
- getRecordsOrCountByCriterion(objectApiName: string, criterion: string | Criterion, order: Order[], ignoreBackLookupField: boolean, fieldApiNames: string[], offset: number, limit: number, needCount: boolean): any;
35
+ createRecordBySync(objectApiName: string, record: object, authType: string): any;
36
+ updateRecordBySync(objectApiName: string, recordID: number, record: object, authType: string): any;
37
+ deleteRecordBySync(objectApiName: string, recordID: number, authType: string): any;
38
+ createRecordsByAsync(objectApiName: string, records: object[], authType: string): any;
39
+ updateRecordsByAsync(objectApiName: string, recordMap: Record<number, object>, authType: string): any;
40
+ deleteRecordsByAsync(objectApiName: string, recordIDs: number[], authType: string): any;
41
+ createRecordsBySync(objectApiName: string, records: object[], authType: string): any;
42
+ updateRecordsBySync(objectApiName: string, recordMap: Record<number, object>, authType: string): any;
43
+ deleteRecordsBySync(objectApiName: string, recordIDs: number[], authType: string): any;
44
+ getRecordsOrCountByCriterion(objectApiName: string, criterion: string | Criterion, order: Order[], ignoreBackLookupField: boolean, fieldApiNames: string[], offset: number, limit: number, needCount: boolean, authType: string): any;
45
45
  updateWorkflowVariables(ctx: any, instanceId: number, variables: object, variableTypes: object): Promise<void>;
46
46
  uploadFile(data: Stream, expire: number): Promise<UploadFileResp>;
47
47
  downloadFileByID(fileID: string, filePath?: string): Promise<Buffer | void>;
@@ -51,9 +51,9 @@ export interface IInnerAPIBaseRequest {
51
51
  getFields(objectApiName: string): Promise<any>;
52
52
  getField(objectApiName: string, fieldApiName: string): Promise<any>;
53
53
  terminateWorkflowInstance(workflowInstanceId: number, operator: number, reason: string): Promise<void>;
54
- modifyRecordsWithTransaction(placeholders: Record<string, number>, operations: object[]): Promise<Map<string, number>>;
54
+ modifyRecordsWithTransaction(placeholders: Record<string, number>, operations: object[], authType: string): Promise<Map<string, number>>;
55
55
  getGlobalConfigByKey<valueT>(key: string): Promise<valueT>;
56
- oql(oql: string, args: any[], namedArgs: Record<string, any>): Promise<string | any[]>;
56
+ oql(oql: string, args: any[], namedArgs: Record<string, any>, authType: string): Promise<string | any[]>;
57
57
  invokeFuncSync(idOrName: {
58
58
  APIId?: string;
59
59
  APIName?: string;
@@ -10,16 +10,16 @@ export declare function updateWorkflowVariables(ctx: any, instanceId: number, va
10
10
  export declare class RequestHttp implements IInnerAPIRequest {
11
11
  constructor();
12
12
  updateWorkflowVariables(ctx: any, instanceId: number, variables: object, variableTypes: object): any;
13
- createRecordBySync(objectApiName: string, record: object): any;
14
- updateRecordBySync(objectApiName: string, recordID: number, record: object): any;
15
- deleteRecordBySync(objectApiName: string, recordID: number): any;
16
- createRecordsByAsync(objectApiName: string, records: object[]): any;
17
- updateRecordsByAsync(objectApiName: string, recordMap: Record<number, object>): any;
18
- deleteRecordsByAsync(objectApiName: string, recordIDs: number[]): any;
19
- createRecordsBySync(objectApiName: string, records: object[]): any;
20
- updateRecordsBySync(objectApiName: string, recordMap: Record<number, object>): any;
21
- deleteRecordsBySync(objectApiName: string, recordIDs: number[]): any;
22
- getRecordsOrCountByCriterion(objectApiName: string, criterion: string | Criterion, order: Order[], ignoreBackLookupField: boolean, fieldApiNames: string[], offset: number, limit: number, needCount: boolean): any;
13
+ createRecordBySync(objectApiName: string, record: object, authType: string): any;
14
+ updateRecordBySync(objectApiName: string, recordID: number, record: object, authType: string): any;
15
+ deleteRecordBySync(objectApiName: string, recordID: number, authType: string): any;
16
+ createRecordsByAsync(objectApiName: string, records: object[], authType: string): any;
17
+ updateRecordsByAsync(objectApiName: string, recordMap: Record<number, object>, authType: string): any;
18
+ deleteRecordsByAsync(objectApiName: string, recordIDs: number[], authType: string): any;
19
+ createRecordsBySync(objectApiName: string, records: object[], authType: string): any;
20
+ updateRecordsBySync(objectApiName: string, recordMap: Record<number, object>, authType: string): any;
21
+ deleteRecordsBySync(objectApiName: string, recordIDs: number[], authType: string): any;
22
+ getRecordsOrCountByCriterion(objectApiName: string, criterion: string | Criterion, order: Order[], ignoreBackLookupField: boolean, fieldApiNames: string[], offset: number, limit: number, needCount: boolean, authType: string): any;
23
23
  uploadFile(data: Stream, expire: number): Promise<UploadFileResp>;
24
24
  downloadFileByID(fileID: string, filePath?: string): Promise<void | Buffer>;
25
25
  downloadFileByToken(fileToken: string, filePath?: string): Promise<Buffer | void>;
@@ -28,9 +28,9 @@ export declare class RequestHttp implements IInnerAPIRequest {
28
28
  getFields(objectApiName: string): any;
29
29
  getField(objectApiName: string, fieldApiName: string): any;
30
30
  terminateWorkflowInstance(workflowInstanceId: number, operator: number, reason: string): any;
31
- modifyRecordsWithTransaction(placeholders: Record<string, number>, operations: object[]): Promise<Map<string, number>>;
31
+ modifyRecordsWithTransaction(placeholders: Record<string, number>, operations: object[], authType: string): Promise<Map<string, number>>;
32
32
  getGlobalConfigByKey<valueT>(key: string): Promise<valueT>;
33
- oql(oql: string, args: any[], namedArgs: Record<string, any>): any;
33
+ oql(oql: string, args: any[], namedArgs: Record<string, any>, authType: string): any;
34
34
  invokeFuncSync(idOrName: {
35
35
  APIId?: string;
36
36
  APIName?: string;
@@ -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);