@byted-apaas/server-sdk-node 1.0.14 → 1.0.16

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
  /**
@@ -233,6 +249,16 @@ export interface _IKQuery<T> {
233
249
  * 设置查询条件
234
250
  */
235
251
  where(): Omit<_IKQuery<T>, 'findAll'>;
252
+ /**
253
+ * 模糊查询:与 where 之间是与关系
254
+ * @param keyword 模糊查询的关键字,必填且不可以为空串
255
+ * @param fieldAPINames 『可搜索字段』的字段列表,不可为空
256
+ * @example
257
+ * ```
258
+ * context.db.object("_user").fuzzySearch("张三", ["_name"]).find()
259
+ * ```
260
+ */
261
+ fuzzySearch(keyword: string, fieldAPINames: string[]): Omit<_IKQuery<T>, 'findAll'>;
236
262
  /**
237
263
  * 指定分页查询的数量
238
264
  * @param limit 分页查询的数量
@@ -261,4 +287,12 @@ export interface _IKQuery<T> {
261
287
  * ```
262
288
  */
263
289
  count(): Promise<number>;
290
+ /**
291
+ * 用户级鉴权
292
+ */
293
+ useUserAuth(): this;
294
+ /**
295
+ * 系统级鉴权
296
+ */
297
+ useSystemAuth(): this;
264
298
  }
@@ -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>[]>;
@@ -65,15 +72,19 @@ declare class _KObjectQuery<T> implements _IKQuery<T> {
65
72
  select<K extends keyof T>(...fieldApiNames: K[]): _KQuery<T>;
66
73
  where(conditionMap: _WhereCond<T>): _KQuery<T>;
67
74
  where(): _KQuery<T>;
75
+ fuzzySearch(keyword: string, fieldAPINames: string[]): _KQuery<T>;
68
76
  limit(limit: number): _KQuery<T>;
69
77
  offset(offset: number): _KQuery<T>;
70
78
  count(): Promise<number>;
79
+ useSystemAuth(): this;
80
+ useUserAuth(): this;
71
81
  }
72
82
  /**
73
83
  * _KQuery is kunlun query implement, implements ORM operations.
74
84
  */
75
85
  declare class _KQuery<T> implements _IKQuery<T> {
76
- constructor(objectApiName: string, appCtx?: AppCtx);
86
+ private authType;
87
+ constructor(objectApiName: string, appCtx?: AppCtx, authType?: string);
77
88
  find(): Promise<_Record<T>[]>;
78
89
  findOne(): Promise<_Record<T>>;
79
90
  /**
@@ -92,9 +103,12 @@ declare class _KQuery<T> implements _IKQuery<T> {
92
103
  select<K extends keyof T>(...fieldApiNames: K[]): this;
93
104
  where(conditionMap: _WhereCond<T>): this;
94
105
  where(): this;
106
+ fuzzySearch(keyword: string, fieldAPINames: string[]): this;
95
107
  limit(limit: number): this;
96
108
  offset(offset: number): this;
97
109
  count(): Promise<number>;
98
110
  private findPreCheck;
111
+ useSystemAuth(): this;
112
+ useUserAuth(): this;
99
113
  }
100
114
  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,55 @@ 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);
341
+ }
342
+ fuzzySearch(keyword, fieldAPINames) {
343
+ return new _KQuery(this.apiName, this.appCtx).fuzzySearch(keyword, fieldAPINames);
324
344
  }
325
345
  // limit, offset, count
326
346
  limit(limit) {
327
- return new _KQuery(this.apiName, this.appCtx).limit(limit);
347
+ return new _KQuery(this.apiName, this.appCtx, this.authType).limit(limit);
328
348
  }
329
349
  ;
330
350
  offset(offset) {
331
- return new _KQuery(this.apiName, this.appCtx).offset(offset);
351
+ return new _KQuery(this.apiName, this.appCtx, this.authType).offset(offset);
332
352
  }
333
353
  ;
334
354
  async count() {
335
- return new _KQuery(this.apiName, this.appCtx).count();
355
+ return new _KQuery(this.apiName, this.appCtx, this.authType).count();
336
356
  }
337
357
  ;
358
+ useSystemAuth() {
359
+ this.authType = constants_1.AuthTypeSystem;
360
+ return this;
361
+ }
362
+ useUserAuth() {
363
+ this.authType = constants_1.AuthTypeUser;
364
+ return this;
365
+ }
338
366
  }
339
367
  /**
340
368
  * _KQuery is kunlun query implement, implements ORM operations.
341
369
  */
342
370
  class _KQuery {
343
- // 使用请求上下文和对象 Api Name 进行初始化
344
- constructor(objectApiName, appCtx = null) {
371
+ constructor(objectApiName, appCtx = null, authType = null) {
372
+ if (authType) {
373
+ this.authType = authType;
374
+ }
345
375
  if (!objectApiName) {
346
376
  throw new server_common_node_1.exceptions.InvalidParamError("objectApiName is empty");
347
377
  }
@@ -370,7 +400,7 @@ class _KQuery {
370
400
  }
371
401
  else {
372
402
  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);
403
+ return await Request.GetInstance().getRecordsOrCountByCriterion(apiName, await (0, logic_1.handleCriterion)(criterion), queryBuilder.fuzzySearch, queryBuilder.getOrder(), false, queryBuilder.getSelect(), queryBuilder.getOffset(), queryBuilder.getLimit(), false, this.authType);
374
404
  }
375
405
  }
376
406
  ;
@@ -455,7 +485,7 @@ class _KQuery {
455
485
  }
456
486
  else {
457
487
  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);
488
+ rs = await Request.GetInstance().getRecordsOrCountByCriterion(apiName, await (0, logic_1.handleCriterion)(criterion), queryBuilder.fuzzySearch, [new order_1.Order("_id", "asc")], false, queryBuilder.getSelect(), 0, newLimit, false, this.authType);
459
489
  }
460
490
  queryCount += rs.length;
461
491
  rs.forEach((r) => {
@@ -525,7 +555,7 @@ class _KQuery {
525
555
  }
526
556
  else {
527
557
  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);
558
+ rs = await Request.GetInstance().getRecordsOrCountByCriterion(apiName, await (0, logic_1.handleCriterion)(criterion), queryBuilder.fuzzySearch, orders, false, selectFields, i, newLimit, false, this.authType);
529
559
  }
530
560
  queryCount += rs.length;
531
561
  try {
@@ -563,7 +593,8 @@ class _KQuery {
563
593
  }
564
594
  else {
565
595
  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);
596
+ rs = await Request.GetInstance().getRecordsOrCountByCriterion(apiName, await (0, logic_1.handleCriterion)(criterion), null, // FindAll 不再迭代
597
+ [new order_1.Order("_id", "asc")], false, queryBuilder.getSelect(), 0, queryBuilder_1.defaultLimit, false, this.authType);
567
598
  }
568
599
  rs.forEach((r) => {
569
600
  maxId = r._id > maxId ? r._id : maxId;
@@ -633,6 +664,26 @@ class _KQuery {
633
664
  }
634
665
  return this;
635
666
  }
667
+ fuzzySearch(keyword, fieldAPINames) {
668
+ const { queryBuilder, queryV2 } = queryPropertiesStore.get(this);
669
+ if (queryV2) {
670
+ throw new server_common_node_1.exceptions.InvalidParamError(`OpenSDK does not implement FuzzySearch`);
671
+ }
672
+ if (queryBuilder.fuzzySearch) {
673
+ throw new server_common_node_1.exceptions.InvalidParamError(`FuzzySearch can only be called once`);
674
+ }
675
+ if (!keyword) {
676
+ throw new server_common_node_1.exceptions.InvalidParamError(`FuzzySearch's keyword can not be empty`);
677
+ }
678
+ if (!fieldAPINames || fieldAPINames.length === 0) {
679
+ throw new server_common_node_1.exceptions.InvalidParamError(`FuzzySearch's fieldAPINames can not be empty`);
680
+ }
681
+ queryBuilder.fuzzySearch = {
682
+ keyword: keyword,
683
+ fieldAPINames: fieldAPINames,
684
+ };
685
+ return this;
686
+ }
636
687
  limit(limit) {
637
688
  const { queryBuilder, queryV2 } = queryPropertiesStore.get(this);
638
689
  limit = Number(limit);
@@ -675,7 +726,7 @@ class _KQuery {
675
726
  }
676
727
  else {
677
728
  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);
729
+ return await Request.GetInstance().getRecordsOrCountByCriterion(apiName, await (0, logic_1.handleCriterion)(criterion), queryBuilder.fuzzySearch, queryBuilder.getOrder(), false, queryBuilder.getSelect(), queryBuilder.getOffset(), queryBuilder.getLimit(), true, this.authType);
679
730
  }
680
731
  }
681
732
  ;
@@ -693,6 +744,14 @@ class _KQuery {
693
744
  throw new server_common_node_1.exceptions.InvalidParamError(`limit(${limit}) < 1`);
694
745
  }
695
746
  }
747
+ useSystemAuth() {
748
+ this.authType = constants_1.AuthTypeSystem;
749
+ return this;
750
+ }
751
+ useUserAuth() {
752
+ this.authType = constants_1.AuthTypeUser;
753
+ return this;
754
+ }
696
755
  }
697
756
  function applyMixins(derivedCtor, constructors) {
698
757
  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;
@@ -14,6 +14,7 @@ export declare class QueryBuilder {
14
14
  offset: number;
15
15
  order: Order[];
16
16
  logic: Logic;
17
+ fuzzySearch: object;
17
18
  constructor(objectApiName: string);
18
19
  addLogic(logic: Logic): void;
19
20
  getLogic(): Logic;
@@ -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.16",
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.14",
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, fuzzySearch: any, 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,22 +325,19 @@ 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) {
335
- if (limit > 10000) {
336
- limit = 10000;
337
- }
334
+ async function getRecordsOrCountByCriterion(objectApiName, criterion, fuzzySearch, order, ignoreBackLookupField, fieldApiNames, offset, limit, needCount, authType) {
338
335
  // 1.check
339
336
  if (!objectApiName) {
340
337
  throw new exceptions.InvalidParamError("objectApiName is empty");
341
338
  }
342
339
  // 2.前置处理
343
- let ctx = await pre();
340
+ let ctx = await pre(true, authType);
344
341
  // 3.构造 params
345
342
  let param = {};
346
343
  let orders = new Array();
@@ -361,6 +358,7 @@ async function getRecordsOrCountByCriterion(objectApiName, criterion, order, ign
361
358
  param.FieldAPIAPIAliases = fieldApiNames;
362
359
  param.NeedFilterUserPermission = false;
363
360
  param.NeedTotalCount = needCount;
361
+ param.FuzzySearch = fuzzySearch;
364
362
  // 4.发起请求
365
363
  let resp;
366
364
  try {
@@ -713,7 +711,7 @@ async function terminateWorkflowInstance(workflowInstanceId, operator, reason) {
713
711
  // 5. deal with response
714
712
  post(resp.BaseResp);
715
713
  }
716
- async function modifyRecordsWithTransaction(placeholders, operations) {
714
+ async function modifyRecordsWithTransaction(placeholders, operations, authType) {
717
715
  // 1. prepare args
718
716
  // TODO: change placeholders type
719
717
  let ph = new Map();
@@ -733,7 +731,7 @@ async function modifyRecordsWithTransaction(placeholders, operations) {
733
731
  param.TaskID = BigInt(taskID);
734
732
  }
735
733
  // 3. prepare request
736
- let ctx = await pre();
734
+ let ctx = await pre(true, authType);
737
735
  // 4. do request
738
736
  let resp;
739
737
  try {
@@ -782,7 +780,7 @@ async function getGlobalConfigByKey(key) {
782
780
  }
783
781
  throw new exceptions.InvalidParamError(`undefined global variable (${key})`);
784
782
  }
785
- async function oql(oql, args, namedArgs) {
783
+ async function oql(oql, args, namedArgs, authType) {
786
784
  // 1. build parameters
787
785
  const queryData = JSON.stringify({
788
786
  "query": oql,
@@ -795,7 +793,7 @@ async function oql(oql, args, namedArgs) {
795
793
  param.Namespace = await (0, common_1.getNamespaceForOpenAndFaaSSDK)();
796
794
  param.QueryData = Buffer.from(queryData);
797
795
  // 3. prepare request
798
- let ctx = await pre();
796
+ let ctx = await pre(true, authType);
799
797
  // 4. do request
800
798
  let resp;
801
799
  try {
@@ -1096,25 +1094,25 @@ class RequestRpc {
1096
1094
  this.openSDKUploadAvatar = openSDKUploadAvatar;
1097
1095
  this.openSDKDownloadAvatar = openSDKDownloadAvatar;
1098
1096
  }
1099
- createRecordBySync(objectApiName, record) {
1097
+ createRecordBySync(objectApiName, record, authType) {
1100
1098
  }
1101
- updateRecordBySync(objectApiName, recordID, record) {
1099
+ updateRecordBySync(objectApiName, recordID, record, authType) {
1102
1100
  }
1103
- deleteRecordBySync(objectApiName, recordID) {
1101
+ deleteRecordBySync(objectApiName, recordID, authType) {
1104
1102
  }
1105
- createRecordsByAsync(objectApiName, records) {
1103
+ createRecordsByAsync(objectApiName, records, authType) {
1106
1104
  }
1107
- updateRecordsByAsync(objectApiName, recordMap) {
1105
+ updateRecordsByAsync(objectApiName, recordMap, authType) {
1108
1106
  }
1109
- deleteRecordsByAsync(objectApiName, recordIDs) {
1107
+ deleteRecordsByAsync(objectApiName, recordIDs, authType) {
1110
1108
  }
1111
- createRecordsBySync(objectApiName, records) {
1109
+ createRecordsBySync(objectApiName, records, authType) {
1112
1110
  }
1113
- updateRecordsBySync(objectApiName, recordMap) {
1111
+ updateRecordsBySync(objectApiName, recordMap, authType) {
1114
1112
  }
1115
- deleteRecordsBySync(objectApiName, recordIDs) {
1113
+ deleteRecordsBySync(objectApiName, recordIDs, authType) {
1116
1114
  }
1117
- getRecordsOrCountByCriterion(objectApiName, criterion, order, ignoreBackLookupField, fieldApiNames, offset, limit, needCount) {
1115
+ getRecordsOrCountByCriterion(objectApiName, criterion, fuzzySearch, order, ignoreBackLookupField, fieldApiNames, offset, limit, needCount, authType) {
1118
1116
  }
1119
1117
  async updateWorkflowVariables(ctx, instanceId, variables, variableTypes) {
1120
1118
  }
@@ -1139,13 +1137,13 @@ class RequestRpc {
1139
1137
  }
1140
1138
  async terminateWorkflowInstance(workflowInstanceId, operator, reason) {
1141
1139
  }
1142
- async modifyRecordsWithTransaction(placeholders, operations) {
1140
+ async modifyRecordsWithTransaction(placeholders, operations, authType) {
1143
1141
  return null;
1144
1142
  }
1145
1143
  async getGlobalConfigByKey(key) {
1146
1144
  return null;
1147
1145
  }
1148
- async oql(oql, args, namedArgs) {
1146
+ async oql(oql, args, namedArgs, authType) {
1149
1147
  return [];
1150
1148
  }
1151
1149
  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, fuzzySearch: any, 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[], fuzzySearch: any, 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,10 +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) {
219
- if (limit > 10000) {
220
- limit = 10000;
221
- }
264
+ async function getRecordsOrCountByCriterion(objectApiName, criterion, fuzzySearch, order, ignoreBackLookupField, fieldApiNames, offset, limit, needCount, authType) {
222
265
  // 1.check
223
266
  if (!objectApiName) {
224
267
  throw new exceptions.InternalError("objectApiName is empty");
@@ -237,7 +280,13 @@ async function getRecordsOrCountByCriterion(objectApiName, criterion, order, ign
237
280
  "limit": limit,
238
281
  "need_filter_user_permission": false,
239
282
  "need_total_count": needCount,
283
+ "fuzzySearch": fuzzySearch,
240
284
  };
285
+ authType = (0, utils_1.formatAuthType)(authType);
286
+ options.headers["User"] = utils.getUserIDFromCtx() + "";
287
+ if (authType) {
288
+ options.headers[constants_3.AuthTypeHttpHeader] = authType;
289
+ }
241
290
  let data = await openapi.doRequest(null, urlPath, options);
242
291
  return handleResponse(data, needCount);
243
292
  }
@@ -484,7 +533,7 @@ async function terminateWorkflowInstance(workflowInstanceId, operator, reason) {
484
533
  };
485
534
  await openapi.doRequest(null, urlPath, options);
486
535
  }
487
- async function modifyRecordsWithTransaction(placeholders, operations) {
536
+ async function modifyRecordsWithTransaction(placeholders, operations, authType) {
488
537
  // 1.获取 options
489
538
  let options = commonHttp.getOptions(null, openapiHttpPath.modifyRecordsWithTransaction);
490
539
  let urlPath = options._reqPath.replace(replaceKeys.namespace, await (0, common_1.getNamespaceForOpenAndFaaSSDK)());
@@ -495,6 +544,11 @@ async function modifyRecordsWithTransaction(placeholders, operations) {
495
544
  "operatorId": utils.getUserIDFromCtx(),
496
545
  "setSystemField": 1,
497
546
  };
547
+ authType = (0, utils_1.formatAuthType)(authType);
548
+ options.headers["User"] = utils.getUserIDFromCtx() + "";
549
+ if (authType) {
550
+ options.headers[constants_3.AuthTypeHttpHeader] = authType;
551
+ }
498
552
  let taskId = utils.getTriggerTaskID();
499
553
  if (taskId) {
500
554
  options.json["taskId"] = taskId;
@@ -508,7 +562,6 @@ async function modifyRecordsWithTransaction(placeholders, operations) {
508
562
  }
509
563
  return retPlaceholders;
510
564
  }
511
- ;
512
565
  async function getGlobalConfigByKey(key) {
513
566
  // 1.获取 options
514
567
  let options = commonHttp.getOptions(null, openapiHttpPath.getAllGlobalConfigs);
@@ -536,7 +589,7 @@ async function getGlobalConfigByKey(key) {
536
589
  }
537
590
  throw new exceptions.InvalidParamError(`undefined global variable (${key})`);
538
591
  }
539
- async function oql(oql, args, namedArgs) {
592
+ async function oql(oql, args, namedArgs, authType) {
540
593
  // 1.获取 options
541
594
  let options = commonHttp.getOptions(null, constants_2.openapiHttpPath.oql);
542
595
  let urlPath = options._reqPath.replace(replaceKeys.namespace, await (0, common_1.getNamespaceForOpenAndFaaSSDK)());
@@ -547,6 +600,11 @@ async function oql(oql, args, namedArgs) {
547
600
  "namedArgs": namedArgs,
548
601
  "compat": true,
549
602
  };
603
+ authType = (0, utils_1.formatAuthType)(authType);
604
+ options.headers["User"] = utils.getUserIDFromCtx() + "";
605
+ if (authType) {
606
+ options.headers[constants_3.AuthTypeHttpHeader] = authType;
607
+ }
550
608
  let result = await openapi.doRequest(null, urlPath, options);
551
609
  if (result && result.rows) {
552
610
  return result.rows;
@@ -715,25 +773,25 @@ class RequestHttp {
715
773
  }
716
774
  updateWorkflowVariables(ctx, instanceId, variables, variableTypes) {
717
775
  }
718
- createRecordBySync(objectApiName, record) {
776
+ createRecordBySync(objectApiName, record, authType) {
719
777
  }
720
- updateRecordBySync(objectApiName, recordID, record) {
778
+ updateRecordBySync(objectApiName, recordID, record, authType) {
721
779
  }
722
- deleteRecordBySync(objectApiName, recordID) {
780
+ deleteRecordBySync(objectApiName, recordID, authType) {
723
781
  }
724
- createRecordsByAsync(objectApiName, records) {
782
+ createRecordsByAsync(objectApiName, records, authType) {
725
783
  }
726
- updateRecordsByAsync(objectApiName, recordMap) {
784
+ updateRecordsByAsync(objectApiName, recordMap, authType) {
727
785
  }
728
- deleteRecordsByAsync(objectApiName, recordIDs) {
786
+ deleteRecordsByAsync(objectApiName, recordIDs, authType) {
729
787
  }
730
- createRecordsBySync(objectApiName, records) {
788
+ createRecordsBySync(objectApiName, records, authType) {
731
789
  }
732
- updateRecordsBySync(objectApiName, recordMap) {
790
+ updateRecordsBySync(objectApiName, recordMap, authType) {
733
791
  }
734
- deleteRecordsBySync(objectApiName, recordIDs) {
792
+ deleteRecordsBySync(objectApiName, recordIDs, authType) {
735
793
  }
736
- getRecordsOrCountByCriterion(objectApiName, criterion, order, ignoreBackLookupField, fieldApiNames, offset, limit, needCount) {
794
+ getRecordsOrCountByCriterion(objectApiName, criterion, order, fuzzySearch, ignoreBackLookupField, fieldApiNames, offset, limit, needCount, authType) {
737
795
  }
738
796
  uploadFile(data, expire) {
739
797
  return null;
@@ -756,13 +814,13 @@ class RequestHttp {
756
814
  }
757
815
  terminateWorkflowInstance(workflowInstanceId, operator, reason) {
758
816
  }
759
- modifyRecordsWithTransaction(placeholders, operations) {
817
+ modifyRecordsWithTransaction(placeholders, operations, authType) {
760
818
  return null;
761
819
  }
762
820
  getGlobalConfigByKey(key) {
763
821
  return null;
764
822
  }
765
- oql(oql, args, namedArgs) {
823
+ oql(oql, args, namedArgs, authType) {
766
824
  }
767
825
  async invokeFuncSync(idOrName, params) {
768
826
  return await invokeFuncSync(idOrName, params);