@byted-apaas/server-sdk-node 1.1.13-beta.2 → 1.1.13-beta.4

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.
@@ -1,4 +1,4 @@
1
- import { BaseFieldType, FieldType, FilterType, SortConditionType, SubOptionType } from '../types/objects';
1
+ import { BaseFieldType, CriterionType, FieldType, FilterType, RegionFilterType, SortConditionType, SubOptionType } from '../types/objects';
2
2
  import { I18ns } from '../types/common';
3
3
  declare class MetadataField {
4
4
  type: string;
@@ -36,6 +36,18 @@ declare class Number extends MetadataField {
36
36
  decimalPlacesNumber: number;
37
37
  constructor(field: FieldType);
38
38
  }
39
+ declare class Bigint extends MetadataField {
40
+ required: boolean;
41
+ unique: boolean;
42
+ constructor(field: FieldType);
43
+ }
44
+ declare class Decimal extends MetadataField {
45
+ required: boolean;
46
+ unique: boolean;
47
+ displayAsPercentage: boolean;
48
+ decimalPlacesNumber: number;
49
+ constructor(field: FieldType);
50
+ }
39
51
  declare class KDate extends MetadataField {
40
52
  required: boolean;
41
53
  constructor(field: FieldType);
@@ -100,6 +112,22 @@ declare class ReferenceField extends MetadataField {
100
112
  fieldApiName: string;
101
113
  constructor(field: FieldType);
102
114
  }
115
+ declare class Rollup extends MetadataField {
116
+ rollupType: string;
117
+ rollupObjectApiName: string;
118
+ rollupFieldApiName: string;
119
+ rollupLookupFieldApiName: string;
120
+ filter: CriterionType;
121
+ constructor(field: FieldType);
122
+ }
123
+ declare class Region extends MetadataField {
124
+ required: boolean;
125
+ multiple: boolean;
126
+ optionLevel: boolean;
127
+ strictLevel: number;
128
+ filter: RegionFilterType[];
129
+ constructor(field: FieldType);
130
+ }
103
131
  declare class File extends MetadataField {
104
132
  required: boolean;
105
133
  multiple: boolean;
@@ -127,4 +155,4 @@ declare class ExtractSingleRecord extends MetadataField {
127
155
  declare function parseFields(inputFields: Record<string, any>): BaseFieldType[];
128
156
  declare function parseField(field: FieldType): BaseFieldType;
129
157
  declare function getFieldClass(field: FieldType): any;
130
- export { KText as Text, Multilingual, Number, KDate as Date, DateTime, Option, Email, MobileNumber, Boolean, AvatarOrLogo, Lookup, Formula, AutoID, ReferenceField, File, BackLookup, CompositeType, ExtractSingleRecord, RichText, parseFields, parseField, getFieldClass, };
158
+ export { KText as Text, Multilingual, Number, KDate as Date, DateTime, Option, Email, MobileNumber, Boolean, AvatarOrLogo, Lookup, Formula, AutoID, ReferenceField, File, BackLookup, CompositeType, ExtractSingleRecord, RichText, Bigint, Decimal, Region, Rollup, parseFields, parseField, getFieldClass, };
@@ -2,7 +2,7 @@
2
2
  // Copyright 2022 ByteDance Ltd. and/or its affiliates
3
3
  // SPDX-License-Identifier: MIT
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.getFieldClass = exports.parseField = exports.parseFields = exports.RichText = exports.ExtractSingleRecord = exports.CompositeType = exports.BackLookup = exports.File = exports.ReferenceField = exports.AutoID = exports.Formula = exports.Lookup = exports.AvatarOrLogo = exports.Boolean = exports.MobileNumber = exports.Email = exports.Option = exports.DateTime = exports.Date = exports.Number = exports.Multilingual = exports.Text = void 0;
5
+ exports.getFieldClass = exports.parseField = exports.parseFields = exports.Rollup = exports.Region = exports.Decimal = exports.Bigint = exports.RichText = exports.ExtractSingleRecord = exports.CompositeType = exports.BackLookup = exports.File = exports.ReferenceField = exports.AutoID = exports.Formula = exports.Lookup = exports.AvatarOrLogo = exports.Boolean = exports.MobileNumber = exports.Email = exports.Option = exports.DateTime = exports.Date = exports.Number = exports.Multilingual = exports.Text = void 0;
6
6
  const fieldsUtil = require("./fields.util");
7
7
  class MetadataField {
8
8
  constructor(type, field) {
@@ -65,6 +65,30 @@ class Number extends MetadataField {
65
65
  }
66
66
  }
67
67
  exports.Number = Number;
68
+ class Bigint extends MetadataField {
69
+ constructor(field) {
70
+ if (!field) {
71
+ return;
72
+ }
73
+ super('bigint', field);
74
+ this.required = field.required;
75
+ this.unique = fieldsUtil.getUnique(field);
76
+ }
77
+ }
78
+ exports.Bigint = Bigint;
79
+ class Decimal extends MetadataField {
80
+ constructor(field) {
81
+ if (!field) {
82
+ return;
83
+ }
84
+ super('decimal', field);
85
+ this.required = field.required;
86
+ this.unique = fieldsUtil.getUnique(field);
87
+ this.displayAsPercentage = fieldsUtil.getDisplayAsPercentage(field);
88
+ this.decimalPlacesNumber = fieldsUtil.getDecimalPlaces(field);
89
+ }
90
+ }
91
+ exports.Decimal = Decimal;
68
92
  class KDate extends MetadataField {
69
93
  constructor(field) {
70
94
  if (!field) {
@@ -198,6 +222,34 @@ class ReferenceField extends MetadataField {
198
222
  }
199
223
  }
200
224
  exports.ReferenceField = ReferenceField;
225
+ class Rollup extends MetadataField {
226
+ constructor(field) {
227
+ if (!field) {
228
+ return;
229
+ }
230
+ super('rollup', field);
231
+ this.rollupType = fieldsUtil.getRollupType(field);
232
+ this.rollupObjectApiName = fieldsUtil.getRollupObjectApiName(field);
233
+ this.rollupFieldApiName = fieldsUtil.getRollupFieldApiName(field);
234
+ this.rollupLookupFieldApiName = fieldsUtil.getRollupLookupFieldApiName(field);
235
+ this.filter = fieldsUtil.getRollupFilter(field);
236
+ }
237
+ }
238
+ exports.Rollup = Rollup;
239
+ class Region extends MetadataField {
240
+ constructor(field) {
241
+ if (!field) {
242
+ return;
243
+ }
244
+ super('region', field);
245
+ this.required = field.required;
246
+ this.multiple = fieldsUtil.getSettingsMultiple(field);
247
+ this.optionLevel = fieldsUtil.getRegionOptionLevel(field);
248
+ this.strictLevel = fieldsUtil.getRegionStrictLeve(field);
249
+ this.filter = fieldsUtil.getRegionSettingsFilter(field);
250
+ }
251
+ }
252
+ exports.Region = Region;
201
253
  class File extends MetadataField {
202
254
  constructor(field) {
203
255
  if (!field) {
@@ -310,25 +362,8 @@ const type2fieldType = {
310
362
  'attachment': File,
311
363
  'back_lookup': BackLookup,
312
364
  'richText': RichText,
313
- };
314
- const fieldTypeMap = {
315
- 'text': 'text',
316
- 'multilingual': 'multilingual',
317
- 'number': 'float',
318
- 'date': 'date',
319
- 'dateTime': 'datetime',
320
- 'option': 'enum',
321
- 'email': 'email',
322
- 'mobileNumber': 'phone',
323
- 'boolean': 'boolean',
324
- 'avatarOrLogo': 'avatar',
325
- 'lookup': 'lookup',
326
- 'formula': 'formula',
327
- 'autoId': 'auto_number',
328
- 'referenceField': 'reference_field',
329
- 'file': 'attachment',
330
- 'backLookup': 'back_lookup',
331
- 'compositeType': 'compositeType',
332
- 'extractSingleRecord': 'compositeType',
333
- 'richText': 'richText',
365
+ 'bigint': Bigint,
366
+ 'decimal': Decimal,
367
+ 'rollup': Rollup,
368
+ 'region': Region,
334
369
  };
@@ -1,4 +1,4 @@
1
- import { FieldType, FilterType, SortConditionType, SubOptionType } from '../types/objects';
1
+ import { CriterionType, FieldType, FilterType, RegionFilterType, SortConditionType, SubOptionType } from '../types/objects';
2
2
  import { I18ns } from '../types/common';
3
3
  declare function getUnique(field: FieldType): boolean;
4
4
  declare function getCaseSensitive(field: FieldType): boolean;
@@ -35,6 +35,14 @@ declare function getSettingsMultiple(field: FieldType): boolean;
35
35
  declare function getCompositeTypeApiName(field: FieldType): string;
36
36
  declare function getCompositeTypeSubFields(field: FieldType): object[];
37
37
  declare function getSettingsFilter(field: FieldType): FilterType[];
38
+ export declare function getRegionSettingsFilter(field: FieldType): RegionFilterType[];
38
39
  declare function getSettingsSort(field: FieldType): SortConditionType[];
39
40
  declare function getRecordPosition(field: FieldType): number;
41
+ export declare function getRollupType(field: FieldType): string;
42
+ export declare function getRollupObjectApiName(field: FieldType): string;
43
+ export declare function getRollupFieldApiName(field: FieldType): string;
44
+ export declare function getRollupLookupFieldApiName(field: FieldType): string;
45
+ export declare function getRegionOptionLevel(field: FieldType): boolean;
46
+ export declare function getRegionStrictLeve(field: FieldType): number;
47
+ export declare function getRollupFilter(field: FieldType): CriterionType;
40
48
  export { getUnique, getCaseSensitive, getMultiline, getMaxLength, getRegexpExpression, getRegexpErrMsg, getDisplayAsPercentage, getDecimalPlaces, getMultiple, getOptionSource, getGlobalOptionApiName, getOptionList, getDescriptionWhenTrue, getDescriptionWhenFalse, getDefaultValue, getDisplayStyle, getLookupRefObjectApiName, getLookupIsHierarchy, getLookupDisplayStyle, getReturnType, getFormula, getGenerateMethod, getDigitsNumber, getPrefix, getSuffix, getReferenceObjectApiName, getReferenceFieldApiName, getFileMultiple, getFileTypes, getBackLookupObjectApiName, getBackLookupFieldApiName, getSettingsMultiple, getCompositeTypeApiName, getCompositeTypeSubFields, getSettingsFilter, getSettingsSort, getRecordPosition, };
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getRecordPosition = exports.getSettingsSort = exports.getSettingsFilter = exports.getCompositeTypeSubFields = exports.getCompositeTypeApiName = exports.getSettingsMultiple = exports.getBackLookupFieldApiName = exports.getBackLookupObjectApiName = exports.getFileTypes = exports.getFileMultiple = exports.getReferenceFieldApiName = exports.getReferenceObjectApiName = exports.getSuffix = exports.getPrefix = exports.getDigitsNumber = exports.getGenerateMethod = exports.getFormula = exports.getReturnType = exports.getLookupDisplayStyle = exports.getLookupIsHierarchy = exports.getLookupRefObjectApiName = exports.getDisplayStyle = exports.getDefaultValue = exports.getDescriptionWhenFalse = exports.getDescriptionWhenTrue = exports.getOptionList = exports.getGlobalOptionApiName = exports.getOptionSource = exports.getMultiple = exports.getDecimalPlaces = exports.getDisplayAsPercentage = exports.getRegexpErrMsg = exports.getRegexpExpression = exports.getMaxLength = exports.getMultiline = exports.getCaseSensitive = exports.getUnique = void 0;
3
+ exports.getRecordPosition = exports.getSettingsSort = exports.getSettingsFilter = exports.getCompositeTypeSubFields = exports.getCompositeTypeApiName = exports.getSettingsMultiple = exports.getBackLookupFieldApiName = exports.getBackLookupObjectApiName = exports.getFileTypes = exports.getFileMultiple = exports.getReferenceFieldApiName = exports.getReferenceObjectApiName = exports.getSuffix = exports.getPrefix = exports.getDigitsNumber = exports.getGenerateMethod = exports.getFormula = exports.getReturnType = exports.getLookupDisplayStyle = exports.getLookupIsHierarchy = exports.getLookupRefObjectApiName = exports.getDisplayStyle = exports.getDefaultValue = exports.getDescriptionWhenFalse = exports.getDescriptionWhenTrue = exports.getOptionList = exports.getGlobalOptionApiName = exports.getOptionSource = exports.getMultiple = exports.getDecimalPlaces = exports.getDisplayAsPercentage = exports.getRegexpErrMsg = exports.getRegexpExpression = exports.getMaxLength = exports.getMultiline = exports.getCaseSensitive = exports.getUnique = exports.getRollupFilter = exports.getRegionStrictLeve = exports.getRegionOptionLevel = exports.getRollupLookupFieldApiName = exports.getRollupFieldApiName = exports.getRollupObjectApiName = exports.getRollupType = exports.getRegionSettingsFilter = void 0;
4
4
  const common = require("@byted-apaas/server-common-node");
5
5
  const common_1 = require("../types/common");
6
6
  const commonConstants = common.constants;
@@ -283,6 +283,13 @@ function getSettingsFilter(field) {
283
283
  return [];
284
284
  }
285
285
  exports.getSettingsFilter = getSettingsFilter;
286
+ function getRegionSettingsFilter(field) {
287
+ if (field && field.type && field.type.settings && !(0, common_1.isNullOrUndefined)(field.type.settings.filter)) {
288
+ return field.type.settings.filter;
289
+ }
290
+ return [];
291
+ }
292
+ exports.getRegionSettingsFilter = getRegionSettingsFilter;
286
293
  // TODO 结构转换
287
294
  function getSettingsSort(field) {
288
295
  let res = [];
@@ -317,3 +324,55 @@ function getRecordPosition(field) {
317
324
  return pos;
318
325
  }
319
326
  exports.getRecordPosition = getRecordPosition;
327
+ function getRollupType(field) {
328
+ if (field && field.type && field.type.settings && field.type.settings.rollup_function_type) {
329
+ return field.type.settings.rollup_function_type;
330
+ }
331
+ return "";
332
+ }
333
+ exports.getRollupType = getRollupType;
334
+ function getRollupObjectApiName(field) {
335
+ if (field && field.type && field.type.settings && field.type.settings.rolluped_object && field.type.settings.rolluped_object.api_alias) {
336
+ return field.type.settings.rolluped_object.api_alias;
337
+ }
338
+ return "";
339
+ }
340
+ exports.getRollupObjectApiName = getRollupObjectApiName;
341
+ function getRollupFieldApiName(field) {
342
+ if (field && field.type && field.type.settings && field.type.settings.rolluped_field && field.type.settings.rolluped_field.api_alias) {
343
+ return field.type.settings.rolluped_field.api_alias;
344
+ }
345
+ return "";
346
+ }
347
+ exports.getRollupFieldApiName = getRollupFieldApiName;
348
+ function getRollupLookupFieldApiName(field) {
349
+ if (field && field.type && field.type.settings && field.type.settings.rolluped_lookup_field && field.type.settings.rolluped_lookup_field.api_alias) {
350
+ return field.type.settings.rolluped_lookup_field.api_alias;
351
+ }
352
+ return "";
353
+ }
354
+ exports.getRollupLookupFieldApiName = getRollupLookupFieldApiName;
355
+ function getRegionOptionLevel(field) {
356
+ if (field && field.type && field.type.settings && field.type.settings.hasLevelStrict) {
357
+ return field.type.settings.hasLevelStrict;
358
+ }
359
+ return undefined;
360
+ }
361
+ exports.getRegionOptionLevel = getRegionOptionLevel;
362
+ function getRegionStrictLeve(field) {
363
+ if (field && field.type && field.type.settings && field.type.settings.strictLevel) {
364
+ return field.type.settings.strictLevel;
365
+ }
366
+ return undefined;
367
+ }
368
+ exports.getRegionStrictLeve = getRegionStrictLeve;
369
+ function getRollupFilter(field) {
370
+ if (field && field.type && field.type.settings && field.type.settings.rollup_range_filter) {
371
+ return {
372
+ conditions: field.type.settings.rollup_range_filter.conditions,
373
+ logic: field.type.settings.rollup_range_filter.logic
374
+ };
375
+ }
376
+ return undefined;
377
+ }
378
+ exports.getRollupFilter = getRollupFilter;
@@ -79,7 +79,7 @@ type ConditionType = {
79
79
  valueType: ('reference' | 'specified');
80
80
  right: (object | string);
81
81
  };
82
- type CriterionType = {
82
+ export type CriterionType = {
83
83
  conditions: ConditionType[];
84
84
  logic: string;
85
85
  };
@@ -90,6 +90,13 @@ export type FilterType = {
90
90
  criterion: CriterionType;
91
91
  errorMsg: I18ns;
92
92
  };
93
+ export type RegionFilterType = {
94
+ id: string;
95
+ label: string;
96
+ errorMessage: I18ns;
97
+ recordFilter: CriterionType;
98
+ precondition: object;
99
+ };
93
100
  export interface Lookup extends BaseFieldType {
94
101
  required: boolean;
95
102
  multiple: boolean;
@@ -213,6 +220,19 @@ export type FieldType = {
213
220
  'type': string;
214
221
  };
215
222
  'is_extract': boolean;
223
+ 'rollup_function_type': string;
224
+ 'rolluped_object': {
225
+ 'api_alias': string;
226
+ };
227
+ 'rolluped_field': {
228
+ 'api_alias': string;
229
+ };
230
+ 'rolluped_lookup_field': {
231
+ 'api_alias': string;
232
+ };
233
+ 'rollup_range_filter': CriterionType;
234
+ 'hasLevelStrict': boolean;
235
+ 'strictLevel': number;
216
236
  };
217
237
  };
218
238
  'unique_type': number;
@@ -1,3 +1,5 @@
1
+ import { IApprovalInstance, IApprovalInstanceListOptions, IApprovalInstanceList, IGetApprovalInstanceOptions } from '../../../request/structs';
2
+ export declare function NewFlow(): Flow;
1
3
  export interface Flow {
2
4
  /**
3
5
  * 获取流程实例人工任务详情列表
@@ -25,6 +27,17 @@ export interface Flow {
25
27
  * @constructor
26
28
  */
27
29
  getExecutionInfo: (executionId: number) => Promise<ExecutionInfo>;
30
+ /**
31
+ * 获取审批实例列表
32
+ * @param options 请求参数,可选
33
+ */
34
+ getApprovalInstanceList: (options?: IApprovalInstanceListOptions) => Promise<IApprovalInstanceList>;
35
+ /**
36
+ * 获取审批实例详情
37
+ * @param approvalInstanceId 实例ID
38
+ * @param option 请求参数,可选
39
+ */
40
+ getApprovalInstance: (options: IGetApprovalInstanceOptions) => Promise<IApprovalInstance>;
28
41
  }
29
42
  export interface Execution {
30
43
  /**
@@ -1,2 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NewFlow = void 0;
4
+ const flow_1 = require("./impl/flow");
5
+ function NewFlow() {
6
+ return new flow_1.Flow();
7
+ }
8
+ exports.NewFlow = NewFlow;
@@ -0,0 +1,10 @@
1
+ import { Flow as IFlow, ExecuteOptions, ExecutionResult, ExecutionInfo, FlowTaskInfo, RevokeExecutionOptions } from '../flow';
2
+ import { IApprovalInstance, IApprovalInstanceList, IApprovalInstanceListOptions, IGetApprovalInstanceOptions } from "../../../../request/structs";
3
+ export declare class Flow implements IFlow {
4
+ execute(APIName: string, options: ExecuteOptions | undefined): Promise<ExecutionResult>;
5
+ getExecutionInfo(executionId: number): Promise<ExecutionInfo>;
6
+ getExecutionUserTaskInfo(executionId: number): Promise<FlowTaskInfo[]>;
7
+ revokeExecution(executionId: number, options: RevokeExecutionOptions): Promise<void>;
8
+ getApprovalInstanceList(options?: IApprovalInstanceListOptions): Promise<IApprovalInstanceList>;
9
+ getApprovalInstance(options: IGetApprovalInstanceOptions): Promise<IApprovalInstance>;
10
+ }
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Flow = void 0;
4
+ const exceptions_1 = require("@byted-apaas/server-common-node/utils/exceptions");
5
+ const Request = require("../../../../request/interface");
6
+ const server_common_node_1 = require("@byted-apaas/server-common-node");
7
+ class Flow {
8
+ async execute(APIName, options) {
9
+ if (!APIName || typeof APIName !== 'string') {
10
+ throw new exceptions_1.InvalidParamError(`param's type (${APIName}) need string, but is ${typeof APIName}`);
11
+ }
12
+ if (options && options.params && server_common_node_1.checkUtils.isNotObject(options.params)) {
13
+ throw new exceptions_1.InvalidParamError(`options.params's type (${options}) need object, but is ${Array.isArray(options) ? 'array' : typeof options.params}`);
14
+ }
15
+ if (!options) {
16
+ options = {};
17
+ }
18
+ return await Request.GetInstance().executeFlow(APIName, options);
19
+ }
20
+ async getExecutionInfo(executionId) {
21
+ if (!executionId || typeof executionId !== 'number') {
22
+ throw new exceptions_1.InvalidParamError(`param's type (${executionId}) is not matched to number, but is ${typeof executionId}`);
23
+ }
24
+ return await Request.GetInstance().getExecutionInfo(executionId);
25
+ }
26
+ async getExecutionUserTaskInfo(executionId) {
27
+ if (!executionId || typeof executionId !== 'number') {
28
+ throw new exceptions_1.InvalidParamError(`param's type (${executionId}) need number, but is ${typeof executionId}`);
29
+ }
30
+ return await Request.GetInstance().getExecutionUserTaskInfo(BigInt(executionId));
31
+ }
32
+ async revokeExecution(executionId, options) {
33
+ if (!executionId || typeof executionId !== 'number') {
34
+ throw new exceptions_1.InvalidParamError(`param's type (${executionId}) is need number, but is ${typeof executionId}`);
35
+ }
36
+ return await Request.GetInstance().revokeExecution(executionId, options);
37
+ }
38
+ async getApprovalInstanceList(options) {
39
+ return await Request.GetInstance().getApprovalInstanceList(options);
40
+ }
41
+ async getApprovalInstance(options) {
42
+ if (!options || !options.approvalInstanceId) {
43
+ throw new exceptions_1.InvalidParamError(`required parameter approvalInstanceId is empty`);
44
+ }
45
+ if (typeof options.approvalInstanceId !== 'number') {
46
+ throw new exceptions_1.InvalidParamError(`param's type (${options.approvalInstanceId}) is need number, but is ${typeof options.approvalInstanceId}`);
47
+ }
48
+ return await Request.GetInstance().getApprovalInstance(options);
49
+ }
50
+ }
51
+ exports.Flow = Flow;
package/hooks/hooks.js CHANGED
@@ -10,6 +10,7 @@ const db_1 = require("../context/db/impl/db");
10
10
  const common_1 = require("../request/common");
11
11
  const integration_1 = require("../context/integration/impl/integration");
12
12
  const metadataApi = require("../context/metadata/metadata");
13
+ const flow_1 = require("../global/application/flow/flow");
13
14
  /**
14
15
  * 根据 key 获取对应的全局变量
15
16
  * @param key 全局变量的 key
@@ -94,12 +95,7 @@ function mountApplication(context) {
94
95
  }
95
96
  global.application.constants.metaType = metadataApi.metaType();
96
97
  // flow
97
- global.application.flow = ({
98
- getExecutionUserTaskInfo: api.mockGetExecutionUserTaskInfo(),
99
- execute: api.mockExecuteFlow(),
100
- revokeExecution: api.mockRevokeExecution(),
101
- getExecutionInfo: api.mockGetExecutionInfo(),
102
- });
98
+ global.application.flow = (0, flow_1.NewFlow)();
103
99
  // operator
104
100
  global.application.operator = new operator_1.Operator();
105
101
  global.application.integration = new integration_1._Integration();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@byted-apaas/server-sdk-node",
3
- "version": "1.1.13-beta.2",
3
+ "version": "1.1.13-beta.4",
4
4
  "description": "aPaaS Server SDK",
5
5
  "author": "zhouwexin <zhouwexin@bytedance.com>",
6
6
  "homepage": "",
@@ -13,7 +13,7 @@
13
13
  "clean": "tsc --build --clean && rm -rf **/*.js.map"
14
14
  },
15
15
  "dependencies": {
16
- "@byted-apaas/server-common-node": "^2.0.0-beta.2",
16
+ "@byted-apaas/server-common-node": "^2.0.1-beta.4",
17
17
  "@jorgeferrero/stream-to-buffer": "^2.0.6",
18
18
  "dayjs": "^1.9.6",
19
19
  "form-data": "^3.0.0",
@@ -24,10 +24,12 @@
24
24
  "@types/google-protobuf": "^3.15.6",
25
25
  "@types/mocha": "^9.0.0",
26
26
  "@types/node-fetch": "^2.6.2",
27
+ "@types/sinon": "^17.0.2",
27
28
  "axios": "^0.21.0",
28
29
  "madge": "^3.12.0",
29
30
  "mocha": "^9.1.3",
30
- "node-cls": "^1.0.7"
31
+ "node-cls": "^1.0.7",
32
+ "sinon": "^17.0.1"
31
33
  },
32
34
  "mocha": {
33
35
  "color": true,
@@ -39,4 +41,4 @@
39
41
  ],
40
42
  "timeout": 20000
41
43
  }
42
- }
44
+ }
@@ -7,4 +7,6 @@ export declare const openapiHttpPath: {
7
7
  executeFlow: PostHttpConfig;
8
8
  revokeExecution: PostHttpConfig;
9
9
  getExecutionInfo: GetHttpConfig;
10
+ getApprovalInstanceList: GetHttpConfig;
11
+ getApprovalInstance: GetHttpConfig;
10
12
  };
@@ -13,6 +13,8 @@ exports.metricsMethodKeys = {
13
13
  getExecutionInfo: 'openapi_getExecutionInfo',
14
14
  revokeExecution: 'openapi_revokeExecution',
15
15
  executeFlow: 'openapi_executeFlow',
16
+ getApprovalInstanceList: 'openapi_getApprovalInstanceList',
17
+ getApprovalInstance: 'openapi_getApprovalInstance',
16
18
  };
17
19
  exports.openapiHttpPath = {
18
20
  getBatchAttachmentToken: new config_1.PostHttpConfig(`/attachment/v1/getBatchAttachmentToken`, exports.metricsMethodKeys.getBatchAttachmentToken),
@@ -22,4 +24,6 @@ exports.openapiHttpPath = {
22
24
  executeFlow: new config_1.PostHttpConfig(`/api/flow/v1/namespaces/${constants_1.replaceKeys.namespace}/flows/${constants_1.replaceKeys.apiName}/execute`, exports.metricsMethodKeys.executeFlow),
23
25
  revokeExecution: new config_1.PostHttpConfig(`/api/flow/v1/namespaces/${constants_1.replaceKeys.namespace}/executions/${constants_1.replaceKeys.id}/revoke`, exports.metricsMethodKeys.revokeExecution),
24
26
  getExecutionInfo: new config_1.GetHttpConfig(`/api/flow/v1/namespaces/${constants_1.replaceKeys.namespace}/executions/${constants_1.replaceKeys.id}/detail`, exports.metricsMethodKeys.getExecutionInfo),
27
+ getApprovalInstanceList: new config_1.GetHttpConfig(`/api/approval/v1/approval_instances/listids`, exports.metricsMethodKeys.getApprovalInstanceList),
28
+ getApprovalInstance: new config_1.GetHttpConfig(`/api/approval/v1/approval_instances/${constants_1.replaceKeys.id}`, exports.metricsMethodKeys.getApprovalInstance),
25
29
  };
@@ -5,6 +5,7 @@ import { Stream } from 'stream';
5
5
  import { ExecutionInfo, ExecutionResult, RevokeExecutionOptions } from '@byted-apaas/server-common-node/context/workflow/workflow';
6
6
  import { AppCtx } from '../application/application';
7
7
  import { Order } from '../context/db/impl/order';
8
+ import { IApprovalInstance, IApprovalInstanceList, IApprovalInstanceListOptions, IGetApprovalInstanceOptions } from "./structs";
8
9
  export declare function GetHttpInstance(): IInnerAPIRequest;
9
10
  export declare function GetInstance(): IInnerAPIRequest;
10
11
  export declare function GetFaaSInfraInstance(): IFaaSInfraRequest;
@@ -85,6 +86,8 @@ export interface IInnerAPIBaseRequest {
85
86
  getIntegrationTenantAccessToken: (apiName: string) => Promise<TenantAccessToken>;
86
87
  getDefaultIntegrationAppAccessToken: () => Promise<AppAccessToken>;
87
88
  getDefaultIntegrationTenantAccessToken: () => Promise<TenantAccessToken>;
89
+ getApprovalInstanceList: (options?: IApprovalInstanceListOptions) => Promise<IApprovalInstanceList>;
90
+ getApprovalInstance: (options: IGetApprovalInstanceOptions) => Promise<IApprovalInstance>;
88
91
  }
89
92
  export interface IInnerAPIOpenSDKRequest {
90
93
  openSDKCreateRecordBySync: (objectApiName: string, record: object) => any;
@@ -6,6 +6,7 @@ import { Criterion } from '../kunlun/operator/impl/logic';
6
6
  import { IInnerAPIRequest, OpenSDKGetRecordsReq, UploadFileResp } from './interface';
7
7
  import { ExecutionInfo, ExecutionResult, RevokeExecutionOptions } from '@byted-apaas/server-common-node/context/workflow/workflow';
8
8
  import { AppCtx } from '../application/application';
9
+ import { IApprovalInstance, IApprovalInstanceListOptions, IApprovalInstanceList, IGetApprovalInstanceOptions } from "./structs";
9
10
  export declare function updateWorkflowVariables(ctx: any, instanceId: number, variables: object, variableTypes: object): Promise<void>;
10
11
  export declare class RequestHttp implements IInnerAPIRequest {
11
12
  constructor();
@@ -67,6 +68,8 @@ export declare class RequestHttp implements IInnerAPIRequest {
67
68
  openSDKUploadFile(fileName: string, data: Buffer): any;
68
69
  openSDKUploadAvatar(fileName: string, data: Buffer): any;
69
70
  openSDKDownloadAvatar(imageID: string): Promise<Buffer>;
71
+ getApprovalInstanceList(params?: IApprovalInstanceListOptions): Promise<IApprovalInstanceList>;
72
+ getApprovalInstance(params: IGetApprovalInstanceOptions): Promise<IApprovalInstance>;
70
73
  }
71
74
  export declare function getExecutionUserTaskInfo(executionId: bigint): Promise<any>;
72
75
  export declare function executeFlow(APIName: string, option: any): Promise<ExecutionResult>;
@@ -292,6 +292,9 @@ async function getRecordsOrCountByCriterion(objectApiName, criterion, fuzzySearc
292
292
  let options = commonHttp.getOptions(null, needCount ? openapiHttpPath.mGetCountByCriterionV2 : openapiHttpPath.mGetRecordByCriterionV2);
293
293
  let urlPath = options._reqPath.replace(replaceKeys.namespace, await (0, common_1.getNamespaceForOpenAndFaaSSDK)());
294
294
  urlPath = urlPath.replace(replaceKeys.objectApiName, objectApiName);
295
+ if (needCount) {
296
+ fieldApiNames = ['_id'];
297
+ }
295
298
  // 3.请求
296
299
  options.json = {
297
300
  'criterion': JSON.parse(criterion),
@@ -829,10 +832,10 @@ class RequestHttp {
829
832
  createRecordsBySync(objectApiName, records, authType) {
830
833
  }
831
834
  updateRecordsBySync(objectApiName, recordMap, authType) {
832
- return undefined;
835
+ return new Promise(undefined);
833
836
  }
834
837
  deleteRecordsBySync(objectApiName, recordIDs, authType) {
835
- return undefined;
838
+ return new Promise(undefined);
836
839
  }
837
840
  getRecordsOrCountByCriterion(objectApiName, criterion, order, fuzzySearch, ignoreBackLookupField, fieldApiNames, offset, limit, needCount, authType) {
838
841
  }
@@ -859,8 +862,8 @@ class RequestHttp {
859
862
  }
860
863
  terminateWorkflowInstance(workflowInstanceId, operator, reason) {
861
864
  }
862
- modifyRecordsWithTransaction(placeholders, operations, authType) {
863
- return null;
865
+ async modifyRecordsWithTransaction(placeholders, operations, authType) {
866
+ return new Promise(undefined);
864
867
  }
865
868
  getGlobalConfigByKey(key) {
866
869
  return null;
@@ -942,6 +945,94 @@ class RequestHttp {
942
945
  return null;
943
946
  }
944
947
  ;
948
+ async getApprovalInstanceList(params) {
949
+ let options = commonHttp.getOptions(null, constants_2.openapiHttpPath.getApprovalInstanceList);
950
+ let urlPath = options._reqPath;
951
+ // 设置参数
952
+ const searchParams = {};
953
+ if (params && params.startTime && params.startTime > 0) {
954
+ searchParams.start_time = params.startTime;
955
+ }
956
+ if (params && params.endTime && params.endTime > 0) {
957
+ searchParams.end_time = params.endTime;
958
+ }
959
+ if (params && params.limit && params.limit > 0) {
960
+ searchParams.limit = params.limit;
961
+ }
962
+ if (params && params.pageToken) {
963
+ searchParams.page_token = params.pageToken;
964
+ }
965
+ options.searchParams = searchParams;
966
+ // 发起请求
967
+ let resp = await openapi.doRequest(null, urlPath, options);
968
+ // 应答
969
+ return {
970
+ approvalInstanceIds: resp.approval_instance_ids,
971
+ pageToken: resp.page_token,
972
+ count: resp.count,
973
+ hasMore: resp.has_more,
974
+ };
975
+ }
976
+ async getApprovalInstance(params) {
977
+ let options = commonHttp.getOptions(null, constants_2.openapiHttpPath.getApprovalInstance);
978
+ let urlPath = options._reqPath.replace(replaceKeys.id, String(params.approvalInstanceId));
979
+ // 设置参数
980
+ const searchParams = {
981
+ includes: "",
982
+ };
983
+ const includes = [];
984
+ if (params && params.includeContent) {
985
+ includes.push('ApprovalComment_Content');
986
+ }
987
+ if (params && params.includeFormData) {
988
+ includes.push('ApprovalTask_FormData');
989
+ }
990
+ searchParams.includes = includes.join(",");
991
+ options.searchParams = searchParams;
992
+ // 发起请求
993
+ let resp = await openapi.doRequest(null, urlPath, options);
994
+ if (!resp || !resp.approval_instance) {
995
+ return undefined;
996
+ }
997
+ // 处理应答
998
+ const approvalInstance = resp.approval_instance;
999
+ const result = {
1000
+ id: approvalInstance.id,
1001
+ label: approvalInstance.label,
1002
+ initiator: approvalInstance.initiator,
1003
+ instanceStartTime: approvalInstance.instance_start_time,
1004
+ status: approvalInstance.status,
1005
+ tasks: [],
1006
+ comments: [],
1007
+ };
1008
+ if (!approvalInstance.tasks && Array.isArray(approvalInstance.tasks)) {
1009
+ for (let task of approvalInstance.tasks) {
1010
+ result.tasks.push({
1011
+ id: task.id,
1012
+ taskStatus: task.task_status,
1013
+ taskStartTime: task.task_start_time,
1014
+ taskEndTime: task.task_end_time,
1015
+ formData: task.form_data,
1016
+ approvalLogic: task.approval_logic,
1017
+ approvers: task.approvers,
1018
+ assigners: task.assigners,
1019
+ taskURL: task.task_url,
1020
+ });
1021
+ }
1022
+ }
1023
+ if (!approvalInstance.comments && Array.isArray(approvalInstance.comments)) {
1024
+ for (let comment of approvalInstance.comments) {
1025
+ result.comments.push({
1026
+ id: comment.id,
1027
+ commenter: comment.commenter,
1028
+ content: comment.content,
1029
+ createAt: comment.create_at,
1030
+ updateAt: comment.update_at,
1031
+ });
1032
+ }
1033
+ }
1034
+ return result;
1035
+ }
945
1036
  }
946
1037
  exports.RequestHttp = RequestHttp;
947
1038
  async function invokeFuncWithAuth(idOrName, params) {
@@ -0,0 +1,97 @@
1
+ export interface IApprovalInstanceListReq {
2
+ start_time?: number;
3
+ end_time?: number;
4
+ limit?: number;
5
+ page_token?: string;
6
+ }
7
+ export interface IGetApprovalInstanceListResp {
8
+ approval_instance_ids: number[];
9
+ page_token: string;
10
+ count: number;
11
+ has_more: boolean;
12
+ }
13
+ export interface IGetApprovalInstanceResp {
14
+ approval_instance: {
15
+ id: number;
16
+ label: Record<string, string>;
17
+ initiator: number;
18
+ instance_start_time: number;
19
+ status: string;
20
+ tasks: {
21
+ id: number;
22
+ task_status: string;
23
+ task_start_time: number;
24
+ task_end_time: number;
25
+ form_data: string;
26
+ approval_logic: string;
27
+ approvers: number[];
28
+ assigners: number[];
29
+ task_url: string;
30
+ }[];
31
+ comments: {
32
+ id: number;
33
+ commenter: number;
34
+ content: string;
35
+ create_at: number;
36
+ update_at: number;
37
+ }[];
38
+ };
39
+ }
40
+ export interface IApprovalInstanceReq {
41
+ includes: string;
42
+ }
43
+ export interface IApprovalInstanceListOptions {
44
+ startTime?: number;
45
+ endTime?: number;
46
+ limit?: number;
47
+ pageToken?: string;
48
+ }
49
+ export interface IApprovalInstanceList {
50
+ approvalInstanceIds: number[];
51
+ pageToken: string;
52
+ count: number;
53
+ hasMore: boolean;
54
+ }
55
+ export declare enum ApprovalInstanceStatus {
56
+ IN_PROCESS = "in_process",
57
+ AGREED = "agreed",
58
+ INPROCESS = "rejected",
59
+ CANCELED = "canceled",
60
+ FAILED = "failed",
61
+ COMPLETED = "completed",
62
+ UNSTARTED = "unstarted",
63
+ AUTO_END = "auto_end",
64
+ TERMINATED = "terminated"
65
+ }
66
+ export interface IApprovalInstance {
67
+ id: number;
68
+ label: Record<string, string>;
69
+ initiator: number;
70
+ instanceStartTime: number;
71
+ status: string;
72
+ tasks: IApprovalTask[];
73
+ comments: IApprovalComment[];
74
+ }
75
+ export interface IApprovalComment {
76
+ id: number;
77
+ commenter: number;
78
+ content: string;
79
+ createAt: number;
80
+ updateAt: number;
81
+ }
82
+ export interface IApprovalTask {
83
+ id: number;
84
+ taskStatus: string;
85
+ taskStartTime: number;
86
+ taskEndTime: number;
87
+ formData: string;
88
+ approvalLogic: string;
89
+ approvers: number[];
90
+ assigners: number[];
91
+ taskURL: string;
92
+ }
93
+ export interface IGetApprovalInstanceOptions {
94
+ approvalInstanceId: number;
95
+ includeFormData?: boolean;
96
+ includeContent?: boolean;
97
+ }
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ApprovalInstanceStatus = void 0;
4
+ var ApprovalInstanceStatus;
5
+ (function (ApprovalInstanceStatus) {
6
+ ApprovalInstanceStatus["IN_PROCESS"] = "in_process";
7
+ ApprovalInstanceStatus["AGREED"] = "agreed";
8
+ ApprovalInstanceStatus["INPROCESS"] = "rejected";
9
+ ApprovalInstanceStatus["CANCELED"] = "canceled";
10
+ ApprovalInstanceStatus["FAILED"] = "failed";
11
+ ApprovalInstanceStatus["COMPLETED"] = "completed";
12
+ ApprovalInstanceStatus["UNSTARTED"] = "unstarted";
13
+ ApprovalInstanceStatus["AUTO_END"] = "auto_end";
14
+ ApprovalInstanceStatus["TERMINATED"] = "terminated";
15
+ })(ApprovalInstanceStatus = exports.ApprovalInstanceStatus || (exports.ApprovalInstanceStatus = {}));